blob: 07030d99a91b9515f8628a1cf81f8e16a2ef62c3 [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 */
3953 public ComponentName getDeviceOwnerComponentOnAnyUser() {
3954 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false);
3955 }
3956
3957 private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) {
Makoto Onuki70f929e2015-11-11 12:40:15 -08003958 if (packageName == null) {
3959 return false;
Amith Yamasani71e6c692013-03-24 17:39:28 -07003960 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08003961 final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly);
Makoto Onuki70f929e2015-11-11 12:40:15 -08003962 if (deviceOwner == null) {
3963 return false;
3964 }
3965 return packageName.equals(deviceOwner.getPackageName());
Amith Yamasani71e6c692013-03-24 17:39:28 -07003966 }
3967
Makoto Onukic8a5a552015-11-19 14:29:12 -08003968 private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) {
3969 if (mService != null) {
3970 try {
3971 return mService.getDeviceOwnerComponent(callingUserOnly);
3972 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003973 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08003974 }
3975 }
3976 return null;
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003977 }
3978
Jason Monkb0dced82014-06-06 14:36:20 -04003979 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08003980 * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's
3981 * no device owner.
3982 *
3983 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07003984 *
3985 * @hide
3986 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08003987 public int getDeviceOwnerUserId() {
3988 if (mService != null) {
3989 try {
3990 return mService.getDeviceOwnerUserId();
3991 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003992 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08003993 }
3994 }
3995 return UserHandle.USER_NULL;
Makoto Onukia52562c2015-10-01 16:12:31 -07003996 }
3997
3998 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003999 * Clears the current device owner. The caller must be the device owner. This function should be
4000 * used cautiously as once it is called it cannot be undone. The device owner can only be set as
4001 * a part of device setup before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04004002 *
4003 * @param packageName The package name of the device owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004004 * @throws SecurityException if the caller is not in {@code packageName} or {@code packageName}
4005 * does not own the current device owner component.
Jason Monkb0dced82014-06-06 14:36:20 -04004006 */
Jason Monk94d2cf92014-06-18 09:53:34 -04004007 public void clearDeviceOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004008 throwIfParentInstance("clearDeviceOwnerApp");
Jason Monkb0dced82014-06-06 14:36:20 -04004009 if (mService != null) {
4010 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04004011 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04004012 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004013 throw re.rethrowFromSystemServer();
Jason Monkb0dced82014-06-06 14:36:20 -04004014 }
4015 }
4016 }
4017
Makoto Onukia52562c2015-10-01 16:12:31 -07004018 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08004019 * Returns the device owner package name, only if it's running on the calling user.
4020 *
4021 * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity.
Makoto Onukia52562c2015-10-01 16:12:31 -07004022 *
4023 * @hide
4024 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01004025 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004026 public @Nullable String getDeviceOwner() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004027 throwIfParentInstance("getDeviceOwner");
Makoto Onukic8a5a552015-11-19 14:29:12 -08004028 final ComponentName name = getDeviceOwnerComponentOnCallingUser();
4029 return name != null ? name.getPackageName() : null;
Makoto Onukia52562c2015-10-01 16:12:31 -07004030 }
4031
4032 /**
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004033 * Called by the system to find out whether the device is managed by a Device Owner.
Makoto Onukic8a5a552015-11-19 14:29:12 -08004034 *
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004035 * @return whether the device is managed by a Device Owner.
4036 * @throws SecurityException if the caller is not the device owner, does not hold the
4037 * MANAGE_USERS permission and is not the system.
Makoto Onukia52562c2015-10-01 16:12:31 -07004038 *
4039 * @hide
4040 */
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004041 @SystemApi
4042 @TestApi
Makoto Onukic8a5a552015-11-19 14:29:12 -08004043 public boolean isDeviceManaged() {
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004044 try {
4045 return mService.hasDeviceOwner();
4046 } catch (RemoteException re) {
4047 throw re.rethrowFromSystemServer();
4048 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08004049 }
4050
4051 /**
4052 * Returns the device owner name. Note this method *will* return the device owner
4053 * name when it's running on a different user.
4054 *
4055 * <p>Requires the MANAGE_USERS permission.
4056 *
4057 * @hide
4058 */
Makoto Onukia2b274b2016-01-19 13:26:02 -08004059 @SystemApi
Makoto Onukic8a5a552015-11-19 14:29:12 -08004060 public String getDeviceOwnerNameOnAnyUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004061 throwIfParentInstance("getDeviceOwnerNameOnAnyUser");
Amith Yamasani71e6c692013-03-24 17:39:28 -07004062 if (mService != null) {
4063 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07004064 return mService.getDeviceOwnerName();
Amith Yamasani71e6c692013-03-24 17:39:28 -07004065 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004066 throw re.rethrowFromSystemServer();
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004067 }
4068 }
4069 return null;
4070 }
Adam Connors776c5552014-01-09 10:42:56 +00004071
4072 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04004073 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004074 * @deprecated Do not use
4075 * @removed
Julia Reynolds20118f12015-02-11 12:34:08 -05004076 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004077 @Deprecated
Julia Reynolds20118f12015-02-11 12:34:08 -05004078 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004079 public @Nullable String getDeviceInitializerApp() {
Julia Reynolds20118f12015-02-11 12:34:08 -05004080 return null;
4081 }
4082
4083 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004084 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004085 * @deprecated Do not use
4086 * @removed
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004087 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004088 @Deprecated
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004089 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004090 public @Nullable ComponentName getDeviceInitializerComponent() {
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004091 return null;
4092 }
4093
Julia Reynolds20118f12015-02-11 12:34:08 -05004094 /**
Adam Connors776c5552014-01-09 10:42:56 +00004095 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004096 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304097 * Sets the given component as an active admin and registers the package as the profile
4098 * owner for this user. The package must already be installed and there shouldn't be
4099 * an existing profile owner registered for this user. Also, this method must be called
4100 * before the user setup has been completed.
4101 * <p>
4102 * This method can only be called by system apps that hold MANAGE_USERS permission and
4103 * MANAGE_DEVICE_ADMINS permission.
4104 * @param admin The component to register as an active admin and profile owner.
4105 * @param ownerName The user-visible name of the entity that is managing this user.
4106 * @return whether the admin was successfully registered as the profile owner.
4107 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
4108 * the user has already been set up.
4109 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07004110 @Deprecated
Justin Morey80440cc2014-07-24 09:16:35 -05004111 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07004112 public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304113 throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004114 throwIfParentInstance("setActiveProfileOwner");
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304115 if (mService != null) {
4116 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004117 final int myUserId = myUserId();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304118 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004119 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304120 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004121 throw re.rethrowFromSystemServer();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304122 }
4123 }
4124 return false;
4125 }
4126
4127 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004128 * Clears the active profile owner and removes all user restrictions. The caller must be from
4129 * the same package as the active profile owner for this user, otherwise a SecurityException
4130 * will be thrown.
4131 * <p>
4132 * This doesn't work for managed profile owners.
Makoto Onuki5bf68022016-01-27 13:49:19 -08004133 *
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004134 * @param admin The component to remove as the profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004135 * @throws SecurityException if {@code admin} is not an active profile owner.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004136 */
Robin Lee25e26452015-06-02 09:56:29 -07004137 public void clearProfileOwner(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004138 throwIfParentInstance("clearProfileOwner");
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004139 if (mService != null) {
4140 try {
4141 mService.clearProfileOwner(admin);
4142 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004143 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004144 }
4145 }
4146 }
4147
4148 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05004149 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07004150 * Checks whether the user was already setup.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004151 */
4152 public boolean hasUserSetupCompleted() {
4153 if (mService != null) {
4154 try {
4155 return mService.hasUserSetupCompleted();
4156 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004157 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004158 }
4159 }
4160 return true;
4161 }
4162
4163 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004164 * @hide
4165 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00004166 * already be installed. There must not already be a profile owner for this user.
4167 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
4168 * this method.
4169 * Calling this after the setup phase of the specified user has completed is allowed only if:
4170 * - the caller is SYSTEM_UID.
4171 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004172 * @param admin the component name to be registered as profile owner.
4173 * @param ownerName the human readable name of the organisation associated with this DPM.
4174 * @param userHandle the userId to set the profile owner for.
4175 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00004176 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
4177 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004178 */
Robin Lee25e26452015-06-02 09:56:29 -07004179 public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName,
Robin Leeddd553f2015-04-30 14:18:22 +01004180 int userHandle) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00004181 if (mService != null) {
4182 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004183 if (ownerName == null) {
4184 ownerName = "";
4185 }
4186 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00004187 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004188 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004189 }
4190 }
4191 return false;
4192 }
4193
4194 /**
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004195 * Sets the device owner information to be shown on the lock screen.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004196 * <p>
4197 * If the device owner information is {@code null} or empty then the device owner info is
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004198 * cleared and the user owner info is shown on the lock screen if it is set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004199 * <p>
4200 * If the device owner information contains only whitespaces then the message on the lock screen
4201 * will be blank and the user will not be allowed to change it.
4202 * <p>
4203 * If the device owner information needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00004204 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
4205 * and set a new version of this string accordingly.
4206 *
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004207 * @param admin The name of the admin component to check.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004208 * @param info Device owner information which will be displayed instead of the user owner info.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004209 * @throws SecurityException if {@code admin} is not a device owner.
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004210 */
Andrei Stingaceanu16187902016-03-21 15:44:45 +00004211 public void setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, CharSequence info) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004212 throwIfParentInstance("setDeviceOwnerLockScreenInfo");
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004213 if (mService != null) {
4214 try {
Andrei Stingaceanu16187902016-03-21 15:44:45 +00004215 mService.setDeviceOwnerLockScreenInfo(admin, info);
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004216 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004217 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004218 }
4219 }
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004220 }
4221
4222 /**
4223 * @return The device owner information. If it is not set returns {@code null}.
4224 */
Andrei Stingaceanu16187902016-03-21 15:44:45 +00004225 public CharSequence getDeviceOwnerLockScreenInfo() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004226 throwIfParentInstance("getDeviceOwnerLockScreenInfo");
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004227 if (mService != null) {
4228 try {
4229 return mService.getDeviceOwnerLockScreenInfo();
4230 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004231 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004232 }
4233 }
4234 return null;
4235 }
4236
4237 /**
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004238 * Called by device or profile owners to suspend packages for this user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004239 * <p>
4240 * A suspended package will not be able to start activities. Its notifications will be hidden,
4241 * it will not show up in recents, will not be able to show toasts or dialogs or ring the
4242 * device.
4243 * <p>
4244 * The package must already be installed. If the package is uninstalled while suspended the
4245 * package will no longer be suspended. The admin can block this by using
Kenny Guy871f3eb2016-03-09 20:06:16 +00004246 * {@link #setUninstallBlocked}.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004247 *
4248 * @param admin The name of the admin component to check.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004249 * @param packageNames The package names to suspend or unsuspend.
4250 * @param suspended If set to {@code true} than the packages will be suspended, if set to
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004251 * {@code false} the packages will be unsuspended.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004252 * @return an array of package names for which the suspended status is not set as requested in
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004253 * this method.
4254 * @throws SecurityException if {@code admin} is not a device or profile owner.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004255 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004256 public @NonNull String[] setPackagesSuspended(@NonNull ComponentName admin,
4257 @NonNull String[] packageNames, boolean suspended) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004258 throwIfParentInstance("setPackagesSuspended");
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004259 if (mService != null) {
4260 try {
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004261 return mService.setPackagesSuspended(admin, packageNames, suspended);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004262 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004263 throw re.rethrowFromSystemServer();
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004264 }
4265 }
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004266 return packageNames;
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004267 }
4268
4269 /**
4270 * Called by device or profile owners to determine if a package is suspended.
4271 *
4272 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4273 * @param packageName The name of the package to retrieve the suspended status of.
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00004274 * @return {@code true} if the package is suspended or {@code false} if the package is not
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004275 * suspended, could not be found or an error occurred.
4276 * @throws SecurityException if {@code admin} is not a device or profile owner.
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004277 * @throws NameNotFoundException if the package could not be found.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004278 */
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004279 public boolean isPackageSuspended(@NonNull ComponentName admin, String packageName)
4280 throws NameNotFoundException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004281 throwIfParentInstance("isPackageSuspended");
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004282 if (mService != null) {
4283 try {
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004284 return mService.isPackageSuspended(admin, packageName);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004285 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004286 throw e.rethrowFromSystemServer();
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004287 } catch (IllegalArgumentException ex) {
4288 throw new NameNotFoundException(packageName);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004289 }
4290 }
4291 return false;
4292 }
4293
4294 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004295 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
4296 * be used. Only the profile owner can call this.
4297 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01004298 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004299 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004300 * @throws SecurityException if {@code admin} is not a profile owner.
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004301 */
Robin Lee25e26452015-06-02 09:56:29 -07004302 public void setProfileEnabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004303 throwIfParentInstance("setProfileEnabled");
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004304 if (mService != null) {
4305 try {
4306 mService.setProfileEnabled(admin);
4307 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004308 throw e.rethrowFromSystemServer();
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004309 }
4310 }
4311 }
4312
4313 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004314 * Sets the name of the profile. In the device owner case it sets the name of the user which it
4315 * is called from. Only a profile owner or device owner can call this. If this is never called
4316 * by the profile or device owner, the name will be set to default values.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004317 *
4318 * @see #isProfileOwnerApp
4319 * @see #isDeviceOwnerApp
Robin Lee25e26452015-06-02 09:56:29 -07004320 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004321 * @param profileName The name of the profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004322 * @throws SecurityException if {@code admin} is not a device or profile owner.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004323 */
Robin Lee25e26452015-06-02 09:56:29 -07004324 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004325 throwIfParentInstance("setProfileName");
Jessica Hummel1333ea12014-06-23 11:20:10 +01004326 if (mService != null) {
4327 try {
Robin Lee25e26452015-06-02 09:56:29 -07004328 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07004329 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004330 throw e.rethrowFromSystemServer();
Fyodor Kupolov78f13142015-05-27 16:52:45 -07004331 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01004332 }
4333 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01004334
4335 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004336 * Used to determine if a particular package is registered as the profile owner for the
Makoto Onuki32b30572015-12-11 14:29:51 -08004337 * user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004338 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00004339 *
4340 * @param packageName The package name of the app to compare with the registered profile owner.
4341 * @return Whether or not the package is registered as the profile owner.
4342 */
4343 public boolean isProfileOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004344 throwIfParentInstance("isProfileOwnerApp");
Adam Connors776c5552014-01-09 10:42:56 +00004345 if (mService != null) {
4346 try {
Makoto Onuki90b89652016-01-28 14:44:18 -08004347 ComponentName profileOwner = mService.getProfileOwner(myUserId());
Nicolas Prevot90af6d72014-07-30 14:19:12 +01004348 return profileOwner != null
4349 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00004350 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004351 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004352 }
4353 }
4354 return false;
4355 }
4356
4357 /**
4358 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07004359 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00004360 * owner has been set for that user.
4361 * @throws IllegalArgumentException if the userId is invalid.
4362 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01004363 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004364 public @Nullable ComponentName getProfileOwner() throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004365 throwIfParentInstance("getProfileOwner");
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01004366 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
4367 }
4368
4369 /**
4370 * @see #getProfileOwner()
4371 * @hide
4372 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004373 public @Nullable ComponentName getProfileOwnerAsUser(final int userId)
4374 throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00004375 if (mService != null) {
4376 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01004377 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00004378 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004379 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004380 }
4381 }
4382 return null;
4383 }
4384
4385 /**
4386 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07004387 * @return the human readable name of the organisation associated with this DPM or {@code null}
4388 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00004389 * @throws IllegalArgumentException if the userId is invalid.
4390 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004391 public @Nullable String getProfileOwnerName() throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00004392 if (mService != null) {
4393 try {
4394 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
4395 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004396 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004397 }
4398 }
4399 return null;
4400 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004401
4402 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07004403 * @hide
Makoto Onukic8a5a552015-11-19 14:29:12 -08004404 * @param userId The user for whom to fetch the profile owner name, if any.
Amith Yamasani38f836b2014-08-20 14:51:15 -07004405 * @return the human readable name of the organisation associated with this profile owner or
4406 * null if one is not set.
4407 * @throws IllegalArgumentException if the userId is invalid.
4408 */
4409 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004410 public @Nullable String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004411 throwIfParentInstance("getProfileOwnerNameAsUser");
Amith Yamasani38f836b2014-08-20 14:51:15 -07004412 if (mService != null) {
4413 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02004414 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07004415 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004416 throw re.rethrowFromSystemServer();
Amith Yamasani38f836b2014-08-20 14:51:15 -07004417 }
4418 }
4419 return null;
4420 }
4421
4422 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004423 * Called by a profile owner or device owner to add a default intent handler activity for
4424 * intents that match a certain intent filter. This activity will remain the default intent
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004425 * handler even if the set of potential event handlers for the intent filter changes and if the
4426 * intent preferences are reset.
4427 * <p>
4428 * The default disambiguation mechanism takes over if the activity is not installed (anymore).
4429 * When the activity is (re)installed, it is automatically reset as default intent handler for
4430 * the filter.
4431 * <p>
4432 * The calling device admin must be a profile owner or device owner. If it is not, a security
4433 * exception will be thrown.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004434 *
4435 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4436 * @param filter The IntentFilter for which a default handler is added.
4437 * @param activity The Activity that is added as default intent handler.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004438 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004439 */
Robin Lee25e26452015-06-02 09:56:29 -07004440 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
4441 @NonNull ComponentName activity) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004442 throwIfParentInstance("addPersistentPreferredActivity");
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004443 if (mService != null) {
4444 try {
4445 mService.addPersistentPreferredActivity(admin, filter, activity);
4446 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004447 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004448 }
4449 }
4450 }
4451
4452 /**
4453 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00004454 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004455 * <p>
4456 * The calling device admin must be a profile owner. If it is not, a security exception will be
4457 * thrown.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004458 *
4459 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4460 * @param packageName The name of the package for which preferences are removed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004461 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004462 */
Robin Lee25e26452015-06-02 09:56:29 -07004463 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004464 String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004465 throwIfParentInstance("clearPackagePersistentPreferredActivities");
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004466 if (mService != null) {
4467 try {
4468 mService.clearPackagePersistentPreferredActivities(admin, packageName);
4469 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004470 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004471 }
4472 }
4473 }
Robin Lee66e5d962014-04-09 16:44:21 +01004474
4475 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00004476 * Called by a profile owner or device owner to grant permission to a package to manage
4477 * application restrictions for the calling user via {@link #setApplicationRestrictions} and
4478 * {@link #getApplicationRestrictions}.
4479 * <p>
4480 * This permission is persistent until it is later cleared by calling this method with a
4481 * {@code null} value or uninstalling the managing package.
Rubin Xuf03d0a62016-02-10 14:54:15 +00004482 * <p>
4483 * The supplied application restriction managing package must be installed when calling this
Victor Changcd14c0a2016-03-16 19:10:15 +00004484 * API, otherwise an {@link NameNotFoundException} will be thrown.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004485 *
4486 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4487 * @param packageName The package name which will be given access to application restrictions
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004488 * APIs. If {@code null} is given the current package will be cleared.
4489 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Changcd14c0a2016-03-16 19:10:15 +00004490 * @throws NameNotFoundException if {@code packageName} is not found
Esteban Talaverabf60f722015-12-10 16:26:44 +00004491 */
4492 public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin,
Victor Changcd14c0a2016-03-16 19:10:15 +00004493 @Nullable String packageName) throws NameNotFoundException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004494 throwIfParentInstance("setApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00004495 if (mService != null) {
4496 try {
Victor Changcd14c0a2016-03-16 19:10:15 +00004497 if (!mService.setApplicationRestrictionsManagingPackage(admin, packageName)) {
4498 throw new NameNotFoundException(packageName);
4499 }
Esteban Talaverabf60f722015-12-10 16:26:44 +00004500 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004501 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00004502 }
4503 }
4504 }
4505
4506 /**
4507 * Called by a profile owner or device owner to retrieve the application restrictions managing
4508 * package for the current user, or {@code null} if none is set.
4509 *
4510 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4511 * @return The package name allowed to manage application restrictions on the current user, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004512 * {@code null} if none is set.
4513 * @throws SecurityException if {@code admin} is not a device or profile owner.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004514 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004515 public @Nullable String getApplicationRestrictionsManagingPackage(
4516 @NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004517 throwIfParentInstance("getApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00004518 if (mService != null) {
4519 try {
4520 return mService.getApplicationRestrictionsManagingPackage(admin);
4521 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004522 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00004523 }
4524 }
4525 return null;
4526 }
4527
4528 /**
Esteban Talavera96895ca2016-03-16 12:00:40 +00004529 * Called by any application to find out whether it has been granted permission via
4530 * {@link #setApplicationRestrictionsManagingPackage} to manage application restrictions
4531 * for the calling user.
4532 *
4533 * <p>This is done by comparing the calling Linux uid with the uid of the package specified by
4534 * that method.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004535 */
4536 public boolean isCallerApplicationRestrictionsManagingPackage() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004537 throwIfParentInstance("isCallerApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00004538 if (mService != null) {
4539 try {
4540 return mService.isCallerApplicationRestrictionsManagingPackage();
4541 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004542 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00004543 }
4544 }
4545 return false;
4546 }
4547
4548 /**
4549 * Sets the application restrictions for a given target application running in the calling user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004550 * <p>
4551 * The caller must be a profile or device owner on that user, or the package allowed to manage
4552 * application restrictions via {@link #setApplicationRestrictionsManagingPackage}; otherwise a
4553 * security exception will be thrown.
4554 * <p>
4555 * The provided {@link Bundle} consists of key-value pairs, where the types of values may be:
Esteban Talavera6b8e0642015-08-10 17:26:04 +01004556 * <ul>
4557 * <li>{@code boolean}
4558 * <li>{@code int}
4559 * <li>{@code String} or {@code String[]}
4560 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
4561 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004562 * <p>
4563 * If the restrictions are not available yet, but may be applied in the near future, the caller
4564 * can notify the target application of that by adding
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00004565 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004566 * <p>
4567 * The application restrictions are only made visible to the target application via
4568 * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or device
4569 * owner, and the application restrictions managing package via
Esteban Talaverabf60f722015-12-10 16:26:44 +00004570 * {@link #getApplicationRestrictions}.
Robin Lee66e5d962014-04-09 16:44:21 +01004571 *
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07004572 * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
4573 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00004574 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004575 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01004576 * @param packageName The name of the package to update restricted settings for.
4577 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004578 * set of active restrictions.
4579 * @throws SecurityException if {@code admin} is not a device or profile owner.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004580 * @see #setApplicationRestrictionsManagingPackage
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00004581 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01004582 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07004583 @WorkerThread
Esteban Talaverabf60f722015-12-10 16:26:44 +00004584 public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01004585 Bundle settings) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004586 throwIfParentInstance("setApplicationRestrictions");
Robin Lee66e5d962014-04-09 16:44:21 +01004587 if (mService != null) {
4588 try {
4589 mService.setApplicationRestrictions(admin, packageName, settings);
4590 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004591 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01004592 }
4593 }
4594 }
4595
4596 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004597 * Sets a list of configuration features to enable for a TrustAgent component. This is meant to
4598 * be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all trust
4599 * agents but those enabled by this function call. If flag
Jim Millere303bf42014-08-26 17:12:29 -07004600 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004601 * <p>
4602 * The calling device admin must have requested
4603 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method;
4604 * if not, a security exception will be thrown.
Tony Mak089d8402016-04-05 17:42:55 +01004605 * <p>
4606 * This method can be called on the {@link DevicePolicyManager} instance returned by
4607 * {@link #getParentProfileInstance(ComponentName)} in order to set the configuration for
4608 * the parent profile.
Jim Miller604e7552014-07-18 19:00:02 -07004609 *
4610 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07004611 * @param target Component name of the agent to be enabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004612 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent will be
4613 * strictly disabled according to the state of the
4614 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
4615 * <p>
4616 * If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all
4617 * admins, then it's up to the TrustAgent itself to aggregate the values from all
4618 * device admins.
4619 * <p>
4620 * Consult documentation for the specific TrustAgent to determine legal options
4621 * parameters.
4622 * @throws SecurityException if {@code admin} is not an active administrator or does not use
4623 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES}
Jim Miller604e7552014-07-18 19:00:02 -07004624 */
Robin Lee25e26452015-06-02 09:56:29 -07004625 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
4626 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07004627 if (mService != null) {
4628 try {
Tony Mak089d8402016-04-05 17:42:55 +01004629 mService.setTrustAgentConfiguration(admin, target, configuration, mParentInstance);
Jim Miller604e7552014-07-18 19:00:02 -07004630 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004631 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07004632 }
4633 }
4634 }
4635
4636 /**
Jim Millere303bf42014-08-26 17:12:29 -07004637 * Gets configuration for the given trust agent based on aggregating all calls to
4638 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
4639 * all device admins.
Tony Mak089d8402016-04-05 17:42:55 +01004640 * <p>
4641 * This method can be called on the {@link DevicePolicyManager} instance returned by
4642 * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the configuration set
4643 * on the parent profile.
Jim Miller604e7552014-07-18 19:00:02 -07004644 *
Jim Millerb5db57a2015-01-14 18:17:19 -08004645 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
4646 * this function returns a list of configurations for all admins that declare
4647 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
4648 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
4649 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
4650 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07004651 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07004652 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07004653 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004654 public @Nullable List<PersistableBundle> getTrustAgentConfiguration(
4655 @Nullable ComponentName admin, @NonNull ComponentName agent) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004656 return getTrustAgentConfiguration(admin, agent, myUserId());
Jim Millere303bf42014-08-26 17:12:29 -07004657 }
4658
4659 /** @hide per-user version */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004660 public @Nullable List<PersistableBundle> getTrustAgentConfiguration(
4661 @Nullable ComponentName admin, @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07004662 if (mService != null) {
4663 try {
Tony Mak089d8402016-04-05 17:42:55 +01004664 return mService.getTrustAgentConfiguration(admin, agent, userHandle,
4665 mParentInstance);
Jim Miller604e7552014-07-18 19:00:02 -07004666 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004667 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07004668 }
4669 }
Jim Millere303bf42014-08-26 17:12:29 -07004670 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07004671 }
4672
4673 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004674 * Called by a profile owner of a managed profile to set whether caller-Id information from the
4675 * managed profile will be shown in the parent profile, for incoming calls.
4676 * <p>
4677 * The calling device admin must be a profile owner. If it is not, a security exception will be
4678 * thrown.
Adam Connors210fe212014-07-17 15:41:43 +01004679 *
Robin Lee25e26452015-06-02 09:56:29 -07004680 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01004681 * @param disabled If true caller-Id information in the managed profile is not displayed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004682 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors210fe212014-07-17 15:41:43 +01004683 */
Robin Lee25e26452015-06-02 09:56:29 -07004684 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004685 throwIfParentInstance("setCrossProfileCallerIdDisabled");
Adam Connors210fe212014-07-17 15:41:43 +01004686 if (mService != null) {
4687 try {
Robin Lee25e26452015-06-02 09:56:29 -07004688 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01004689 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004690 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01004691 }
4692 }
4693 }
4694
4695 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004696 * Called by a profile owner of a managed profile to determine whether or not caller-Id
4697 * information has been disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004698 * <p>
4699 * The calling device admin must be a profile owner. If it is not, a security exception will be
4700 * thrown.
Adam Connors210fe212014-07-17 15:41:43 +01004701 *
Robin Lee25e26452015-06-02 09:56:29 -07004702 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004703 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors210fe212014-07-17 15:41:43 +01004704 */
Robin Lee25e26452015-06-02 09:56:29 -07004705 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004706 throwIfParentInstance("getCrossProfileCallerIdDisabled");
Adam Connors210fe212014-07-17 15:41:43 +01004707 if (mService != null) {
4708 try {
Robin Lee25e26452015-06-02 09:56:29 -07004709 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01004710 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004711 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01004712 }
4713 }
4714 return false;
4715 }
4716
4717 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07004718 * Determine whether or not caller-Id information has been disabled.
4719 *
4720 * @param userHandle The user for whom to check the caller-id permission
4721 * @hide
4722 */
4723 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
4724 if (mService != null) {
4725 try {
4726 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
4727 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004728 throw e.rethrowFromSystemServer();
Amith Yamasani570002f2014-07-18 15:48:54 -07004729 }
4730 }
4731 return false;
4732 }
4733
4734 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004735 * Called by a profile owner of a managed profile to set whether contacts search from the
4736 * managed profile will be shown in the parent profile, for incoming calls.
4737 * <p>
4738 * The calling device admin must be a profile owner. If it is not, a security exception will be
4739 * thrown.
Victor Chang1060c6182016-01-04 20:16:23 +00004740 *
4741 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4742 * @param disabled If true contacts search in the managed profile is not displayed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004743 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Chang1060c6182016-01-04 20:16:23 +00004744 */
4745 public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin,
4746 boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004747 throwIfParentInstance("setCrossProfileContactsSearchDisabled");
Victor Chang1060c6182016-01-04 20:16:23 +00004748 if (mService != null) {
4749 try {
4750 mService.setCrossProfileContactsSearchDisabled(admin, disabled);
4751 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004752 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00004753 }
4754 }
4755 }
4756
4757 /**
4758 * Called by a profile owner of a managed profile to determine whether or not contacts search
4759 * has been disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004760 * <p>
4761 * The calling device admin must be a profile owner. If it is not, a security exception will be
4762 * thrown.
Victor Chang1060c6182016-01-04 20:16:23 +00004763 *
4764 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004765 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Chang1060c6182016-01-04 20:16:23 +00004766 */
4767 public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004768 throwIfParentInstance("getCrossProfileContactsSearchDisabled");
Victor Chang1060c6182016-01-04 20:16:23 +00004769 if (mService != null) {
4770 try {
4771 return mService.getCrossProfileContactsSearchDisabled(admin);
4772 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004773 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00004774 }
4775 }
4776 return false;
4777 }
4778
4779
4780 /**
4781 * Determine whether or not contacts search has been disabled.
4782 *
4783 * @param userHandle The user for whom to check the contacts search permission
4784 * @hide
4785 */
4786 public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) {
4787 if (mService != null) {
4788 try {
4789 return mService
4790 .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier());
4791 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004792 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00004793 }
4794 }
4795 return false;
4796 }
4797
4798 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004799 * Start Quick Contact on the managed profile for the user, if the policy allows.
Victor Chang97bdacc2016-01-21 22:24:11 +00004800 *
Makoto Onuki1040da12015-03-19 11:24:00 -07004801 * @hide
4802 */
4803 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
Victor Chang97bdacc2016-01-21 22:24:11 +00004804 boolean isContactIdIgnored, long directoryId, Intent originalIntent) {
Makoto Onuki1040da12015-03-19 11:24:00 -07004805 if (mService != null) {
4806 try {
Victor Chang97bdacc2016-01-21 22:24:11 +00004807 mService.startManagedQuickContact(actualLookupKey, actualContactId,
4808 isContactIdIgnored, directoryId, originalIntent);
Makoto Onuki1040da12015-03-19 11:24:00 -07004809 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004810 throw e.rethrowFromSystemServer();
Makoto Onuki1040da12015-03-19 11:24:00 -07004811 }
4812 }
4813 }
4814
4815 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004816 * Start Quick Contact on the managed profile for the user, if the policy allows.
Ricky Wai494b95d2015-11-20 16:07:15 +00004817 * @hide
4818 */
4819 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
4820 Intent originalIntent) {
Victor Chang97bdacc2016-01-21 22:24:11 +00004821 startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT,
Ricky Wai494b95d2015-11-20 16:07:15 +00004822 originalIntent);
4823 }
4824
4825 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004826 * Called by a profile owner of a managed profile to set whether bluetooth devices can access
4827 * enterprise contacts.
Ricky Wai778ba132015-03-31 14:21:22 +01004828 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004829 * The calling device admin must be a profile owner. If it is not, a security exception will be
4830 * thrown.
Ricky Wai778ba132015-03-31 14:21:22 +01004831 * <p>
4832 * This API works on managed profile only.
4833 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004834 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4835 * @param disabled If true, bluetooth devices cannot access enterprise contacts.
4836 * @throws SecurityException if {@code admin} is not a device or profile owner.
Ricky Wai778ba132015-03-31 14:21:22 +01004837 */
Robin Lee25e26452015-06-02 09:56:29 -07004838 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004839 throwIfParentInstance("setBluetoothContactSharingDisabled");
Ricky Wai778ba132015-03-31 14:21:22 +01004840 if (mService != null) {
4841 try {
Robin Lee25e26452015-06-02 09:56:29 -07004842 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01004843 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004844 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01004845 }
4846 }
4847 }
4848
4849 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004850 * Called by a profile owner of a managed profile to determine whether or not Bluetooth devices
4851 * cannot access enterprise contacts.
Ricky Wai778ba132015-03-31 14:21:22 +01004852 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004853 * The calling device admin must be a profile owner. If it is not, a security exception will be
4854 * thrown.
Ricky Wai778ba132015-03-31 14:21:22 +01004855 * <p>
4856 * This API works on managed profile only.
4857 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004858 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4859 * @throws SecurityException if {@code admin} is not a device or profile owner.
Ricky Wai778ba132015-03-31 14:21:22 +01004860 */
Robin Lee25e26452015-06-02 09:56:29 -07004861 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004862 throwIfParentInstance("getBluetoothContactSharingDisabled");
Ricky Wai778ba132015-03-31 14:21:22 +01004863 if (mService != null) {
4864 try {
Robin Lee25e26452015-06-02 09:56:29 -07004865 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01004866 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004867 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01004868 }
4869 }
4870 return true;
4871 }
4872
4873 /**
4874 * Determine whether or not Bluetooth devices cannot access contacts.
4875 * <p>
4876 * This API works on managed profile UserHandle only.
4877 *
4878 * @param userHandle The user for whom to check the caller-id permission
4879 * @hide
4880 */
4881 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
4882 if (mService != null) {
4883 try {
4884 return mService.getBluetoothContactSharingDisabledForUser(userHandle
4885 .getIdentifier());
4886 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004887 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01004888 }
4889 }
4890 return true;
4891 }
4892
4893 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004894 * Called by the profile owner of a managed profile so that some intents sent in the managed
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004895 * profile can also be resolved in the parent, or vice versa. Only activity intents are
4896 * supported.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00004897 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004898 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01004899 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004900 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01004901 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004902 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
4903 * @throws SecurityException if {@code admin} is not a device or profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004904 */
Robin Lee25e26452015-06-02 09:56:29 -07004905 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004906 throwIfParentInstance("addCrossProfileIntentFilter");
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004907 if (mService != null) {
4908 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01004909 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004910 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004911 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004912 }
4913 }
4914 }
4915
4916 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004917 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
4918 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01004919 * Only removes those that have been set by the profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004920 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004921 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004922 * @throws SecurityException if {@code admin} is not a device or profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004923 */
Robin Lee25e26452015-06-02 09:56:29 -07004924 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004925 throwIfParentInstance("clearCrossProfileIntentFilters");
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004926 if (mService != null) {
4927 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01004928 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004929 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004930 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004931 }
4932 }
4933 }
4934
4935 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004936 * Called by a profile or device owner to set the permitted accessibility services. When set by
4937 * a device owner or profile owner the restriction applies to all profiles of the user the
4938 * device owner or profile owner is an admin for. By default the user can use any accessiblity
4939 * service. When zero or more packages have been added, accessiblity services that are not in
4940 * the list and not part of the system can not be enabled by the user.
4941 * <p>
4942 * Calling with a null value for the list disables the restriction so that all services can be
4943 * used, calling with an empty list only allows the builtin system's services.
4944 * <p>
4945 * System accesibility services are always available to the user the list can't modify this.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004946 *
4947 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4948 * @param packageNames List of accessibility service package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004949 * @return true if setting the restriction succeeded. It fail if there is one or more non-system
4950 * accessibility services enabled, that are not in the list.
4951 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004952 */
Robin Lee25e26452015-06-02 09:56:29 -07004953 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004954 List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004955 throwIfParentInstance("setPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004956 if (mService != null) {
4957 try {
4958 return mService.setPermittedAccessibilityServices(admin, packageNames);
4959 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004960 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004961 }
4962 }
4963 return false;
4964 }
4965
4966 /**
4967 * Returns the list of permitted accessibility services set by this device or profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004968 * <p>
4969 * An empty list means no accessibility services except system services are allowed. Null means
4970 * all accessibility services are allowed.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004971 *
4972 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4973 * @return List of accessiblity service package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004974 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004975 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004976 public @Nullable List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004977 throwIfParentInstance("getPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004978 if (mService != null) {
4979 try {
4980 return mService.getPermittedAccessibilityServices(admin);
4981 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004982 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004983 }
4984 }
4985 return null;
4986 }
4987
4988 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00004989 * Called by the system to check if a specific accessibility service is disabled by admin.
4990 *
4991 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4992 * @param packageName Accessibility service package name that needs to be checked.
4993 * @param userHandle user id the admin is running as.
4994 * @return true if the accessibility service is permitted, otherwise false.
4995 *
4996 * @hide
4997 */
4998 public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin,
4999 @NonNull String packageName, int userHandle) {
5000 if (mService != null) {
5001 try {
5002 return mService.isAccessibilityServicePermittedByAdmin(admin, packageName,
5003 userHandle);
5004 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005005 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00005006 }
5007 }
5008 return false;
5009 }
5010
5011 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005012 * Returns the list of accessibility services permitted by the device or profiles
5013 * owners of this user.
5014 *
5015 * <p>Null means all accessibility services are allowed, if a non-null list is returned
5016 * it will contain the intersection of the permitted lists for any device or profile
5017 * owners that apply to this user. It will also include any system accessibility services.
5018 *
5019 * @param userId which user to check for.
5020 * @return List of accessiblity service package names.
5021 * @hide
5022 */
5023 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07005024 public @Nullable List<String> getPermittedAccessibilityServices(int userId) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005025 throwIfParentInstance("getPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005026 if (mService != null) {
5027 try {
5028 return mService.getPermittedAccessibilityServicesForUser(userId);
5029 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005030 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005031 }
5032 }
5033 return null;
5034 }
5035
5036 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005037 * Called by a profile or device owner to set the permitted input methods services. When set by
5038 * a device owner or profile owner the restriction applies to all profiles of the user the
5039 * device owner or profile owner is an admin for. By default the user can use any input method.
5040 * When zero or more packages have been added, input method that are not in the list and not
5041 * part of the system can not be enabled by the user. This method will fail if it is called for
5042 * a admin that is not for the foreground user or a profile of the foreground user.
5043 * <p>
5044 * Calling with a null value for the list disables the restriction so that all input methods can
5045 * be used, calling with an empty list disables all but the system's own input methods.
5046 * <p>
5047 * System input methods are always available to the user this method can't modify this.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005048 *
5049 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5050 * @param packageNames List of input method package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005051 * @return true if setting the restriction succeeded. It will fail if there are one or more
5052 * non-system input methods currently enabled that are not in the packageNames list.
5053 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005054 */
Robin Lee25e26452015-06-02 09:56:29 -07005055 public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005056 throwIfParentInstance("setPermittedInputMethods");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005057 if (mService != null) {
5058 try {
5059 return mService.setPermittedInputMethods(admin, packageNames);
5060 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005061 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005062 }
5063 }
5064 return false;
5065 }
5066
5067
5068 /**
5069 * Returns the list of permitted input methods set by this device or profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005070 * <p>
5071 * An empty list means no input methods except system input methods are allowed. Null means all
5072 * input methods are allowed.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005073 *
5074 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5075 * @return List of input method package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005076 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005077 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005078 public @Nullable List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005079 throwIfParentInstance("getPermittedInputMethods");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005080 if (mService != null) {
5081 try {
5082 return mService.getPermittedInputMethods(admin);
5083 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005084 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005085 }
5086 }
5087 return null;
5088 }
5089
5090 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00005091 * Called by the system to check if a specific input method is disabled by admin.
5092 *
5093 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5094 * @param packageName Input method package name that needs to be checked.
5095 * @param userHandle user id the admin is running as.
5096 * @return true if the input method is permitted, otherwise false.
5097 *
5098 * @hide
5099 */
5100 public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin,
5101 @NonNull String packageName, int userHandle) {
5102 if (mService != null) {
5103 try {
5104 return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle);
5105 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005106 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00005107 }
5108 }
5109 return false;
5110 }
5111
5112 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005113 * Returns the list of input methods permitted by the device or profiles
Makoto Onuki32b30572015-12-11 14:29:51 -08005114 * owners of the current user. (*Not* calling user, due to a limitation in InputMethodManager.)
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005115 *
5116 * <p>Null means all input methods are allowed, if a non-null list is returned
5117 * it will contain the intersection of the permitted lists for any device or profile
5118 * owners that apply to this user. It will also include any system input methods.
5119 *
5120 * @return List of input method package names.
5121 * @hide
5122 */
5123 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07005124 public @Nullable List<String> getPermittedInputMethodsForCurrentUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005125 throwIfParentInstance("getPermittedInputMethodsForCurrentUser");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005126 if (mService != null) {
5127 try {
5128 return mService.getPermittedInputMethodsForCurrentUser();
5129 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005130 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005131 }
5132 }
5133 return null;
5134 }
5135
5136 /**
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005137 * Called by a device owner to get the list of apps to keep around as APKs even if no user has
5138 * currently installed it.
5139 *
5140 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5141 *
5142 * @return List of package names to keep cached.
5143 * @hide
5144 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005145 public @Nullable List<String> getKeepUninstalledPackages(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005146 throwIfParentInstance("getKeepUninstalledPackages");
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005147 if (mService != null) {
5148 try {
5149 return mService.getKeepUninstalledPackages(admin);
5150 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005151 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005152 }
5153 }
5154 return null;
5155 }
5156
5157 /**
5158 * Called by a device owner to set a list of apps to keep around as APKs even if no user has
5159 * currently installed it.
5160 *
5161 * <p>Please note that setting this policy does not imply that specified apps will be
5162 * automatically pre-cached.</p>
5163 *
5164 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5165 * @param packageNames List of package names to keep cached.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005166 * @throws SecurityException if {@code admin} is not a device owner.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005167 * @hide
5168 */
5169 public void setKeepUninstalledPackages(@NonNull ComponentName admin,
5170 @NonNull List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005171 throwIfParentInstance("setKeepUninstalledPackages");
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005172 if (mService != null) {
5173 try {
5174 mService.setKeepUninstalledPackages(admin, packageNames);
5175 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005176 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005177 }
5178 }
5179 }
5180
5181 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04005182 * Called by a device owner to create a user with the specified name. The UserHandle returned
5183 * by this method should not be persisted as user handles are recycled as users are removed and
5184 * created. If you need to persist an identifier for this user, use
5185 * {@link UserManager#getSerialNumberForUser}.
5186 *
5187 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5188 * @param name the user's name
5189 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07005190 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
5191 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01005192 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005193 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01005194 * @removed From {@link android.os.Build.VERSION_CODES#N}
Julia Reynolds1e958392014-05-16 14:25:21 -04005195 */
Kenny Guy14f48e52015-06-29 15:12:36 +01005196 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07005197 public @Nullable UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04005198 return null;
5199 }
5200
5201 /**
Jason Monk03978a42014-06-10 15:05:30 -04005202 * Called by a device owner to create a user with the specified name. The UserHandle returned
5203 * by this method should not be persisted as user handles are recycled as users are removed and
5204 * created. If you need to persist an identifier for this user, use
5205 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
5206 * immediately.
5207 *
5208 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
5209 * as registered as an active admin on the new user. The profile owner package will be
5210 * installed on the new user if it already is installed on the device.
5211 *
5212 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
5213 * profileOwnerComponent when onEnable is called.
5214 *
5215 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5216 * @param name the user's name
5217 * @param ownerName the human readable name of the organisation associated with this DPM.
5218 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
5219 * the user.
5220 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
5221 * on the new user.
5222 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07005223 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
5224 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01005225 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005226 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01005227 * @removed From {@link android.os.Build.VERSION_CODES#N}
Jason Monk03978a42014-06-10 15:05:30 -04005228 */
Kenny Guy14f48e52015-06-29 15:12:36 +01005229 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07005230 public @Nullable UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
Robin Lee25e26452015-06-02 09:56:29 -07005231 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04005232 return null;
5233 }
5234
5235 /**
phweissa92e1212016-01-25 17:14:10 +01005236 * Flag used by {@link #createAndManageUser} to skip setup wizard after creating a new user.
phweiss343fb332016-01-25 14:48:59 +01005237 */
5238 public static final int SKIP_SETUP_WIZARD = 0x0001;
5239
5240 /**
Lenka Trochtovac8202c82016-01-26 15:11:09 +01005241 * Flag used by {@link #createAndManageUser} to specify that the user should be created
5242 * ephemeral.
5243 * @hide
5244 */
5245 public static final int MAKE_USER_EPHEMERAL = 0x0002;
5246
5247 /**
phweissa92e1212016-01-25 17:14:10 +01005248 * Called by a device owner to create a user with the specified name and a given component of
5249 * the calling package as profile owner. The UserHandle returned by this method should not be
5250 * persisted as user handles are recycled as users are removed and created. If you need to
5251 * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new
5252 * user will not be started in the background.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005253 * <p>
5254 * admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also a
5255 * DeviceAdminReceiver in the same package as admin, and will become the profile owner and will
5256 * be registered as an active admin on the new user. The profile owner package will be installed
5257 * on the new user.
5258 * <p>
5259 * If the adminExtras are not null, they will be stored on the device until the user is started
5260 * for the first time. Then the extras will be passed to the admin when onEnable is called.
phweiss343fb332016-01-25 14:48:59 +01005261 *
5262 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5263 * @param name The user's name.
phweissa92e1212016-01-25 17:14:10 +01005264 * @param profileOwner Which {@link DeviceAdminReceiver} will be profile owner. Has to be in the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005265 * same package as admin, otherwise no user is created and an
5266 * IllegalArgumentException is thrown.
phweiss343fb332016-01-25 14:48:59 +01005267 * @param adminExtras Extras that will be passed to onEnable of the admin receiver on the new
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005268 * user.
phweissa92e1212016-01-25 17:14:10 +01005269 * @param flags {@link #SKIP_SETUP_WIZARD} is supported.
phweiss343fb332016-01-25 14:48:59 +01005270 * @see UserHandle
5271 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
5272 * user could not be created.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005273 * @throws SecurityException if {@code admin} is not a device owner.
phweiss343fb332016-01-25 14:48:59 +01005274 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005275 public @Nullable UserHandle createAndManageUser(@NonNull ComponentName admin,
5276 @NonNull String name,
phweissa92e1212016-01-25 17:14:10 +01005277 @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras,
5278 int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005279 throwIfParentInstance("createAndManageUser");
phweiss343fb332016-01-25 14:48:59 +01005280 try {
phweissa92e1212016-01-25 17:14:10 +01005281 return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags);
phweiss343fb332016-01-25 14:48:59 +01005282 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005283 throw re.rethrowFromSystemServer();
phweiss343fb332016-01-25 14:48:59 +01005284 }
phweiss343fb332016-01-25 14:48:59 +01005285 }
5286
5287 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005288 * Called by a device owner to remove a user and all associated data. The primary user can not
5289 * be removed.
Julia Reynolds1e958392014-05-16 14:25:21 -04005290 *
5291 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5292 * @param userHandle the user to remove.
5293 * @return {@code true} if the user was removed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005294 * @throws SecurityException if {@code admin} is not a device owner.
Julia Reynolds1e958392014-05-16 14:25:21 -04005295 */
Robin Lee25e26452015-06-02 09:56:29 -07005296 public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005297 throwIfParentInstance("removeUser");
Julia Reynolds1e958392014-05-16 14:25:21 -04005298 try {
5299 return mService.removeUser(admin, userHandle);
5300 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005301 throw re.rethrowFromSystemServer();
Julia Reynolds1e958392014-05-16 14:25:21 -04005302 }
5303 }
5304
5305 /**
Jason Monk582d9112014-07-09 19:57:08 -04005306 * Called by a device owner to switch the specified user to the foreground.
5307 *
5308 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5309 * @param userHandle the user to switch to; null will switch to primary.
5310 * @return {@code true} if the switch was successful, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005311 * @throws SecurityException if {@code admin} is not a device owner.
Jason Monk582d9112014-07-09 19:57:08 -04005312 * @see Intent#ACTION_USER_FOREGROUND
5313 */
Robin Lee25e26452015-06-02 09:56:29 -07005314 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005315 throwIfParentInstance("switchUser");
Jason Monk582d9112014-07-09 19:57:08 -04005316 try {
5317 return mService.switchUser(admin, userHandle);
5318 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005319 throw re.rethrowFromSystemServer();
Jason Monk582d9112014-07-09 19:57:08 -04005320 }
5321 }
5322
5323 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00005324 * Retrieves the application restrictions for a given target application running in the calling
5325 * user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005326 * <p>
5327 * The caller must be a profile or device owner on that user, or the package allowed to manage
5328 * application restrictions via {@link #setApplicationRestrictionsManagingPackage}; otherwise a
5329 * security exception will be thrown.
Robin Lee66e5d962014-04-09 16:44:21 +01005330 *
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005331 * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
5332 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00005333 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005334 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01005335 * @param packageName The name of the package to fetch restricted settings of.
5336 * @return {@link Bundle} of settings corresponding to what was set last time
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005337 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty
5338 * {@link Bundle} if no restrictions have been set.
5339 * @throws SecurityException if {@code admin} is not a device or profile owner.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005340 * @see {@link #setApplicationRestrictionsManagingPackage}
Robin Lee66e5d962014-04-09 16:44:21 +01005341 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005342 @WorkerThread
Makoto Onuki408e8e42016-10-25 12:10:27 -07005343 public @NonNull Bundle getApplicationRestrictions(
5344 @Nullable ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005345 throwIfParentInstance("getApplicationRestrictions");
Robin Lee66e5d962014-04-09 16:44:21 +01005346 if (mService != null) {
5347 try {
5348 return mService.getApplicationRestrictions(admin, packageName);
5349 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005350 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01005351 }
5352 }
5353 return null;
5354 }
Amith Yamasanibe465322014-04-24 13:45:17 -07005355
5356 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05005357 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07005358 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005359 * The calling device admin must be a profile or device owner; if it is not, a security
5360 * exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07005361 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005362 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5363 * @param key The key of the restriction. See the constants in {@link android.os.UserManager}
5364 * for the list of keys.
5365 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanibe465322014-04-24 13:45:17 -07005366 */
Robin Lee25e26452015-06-02 09:56:29 -07005367 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005368 throwIfParentInstance("addUserRestriction");
Amith Yamasanibe465322014-04-24 13:45:17 -07005369 if (mService != null) {
5370 try {
5371 mService.setUserRestriction(admin, key, true);
5372 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005373 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07005374 }
5375 }
5376 }
5377
5378 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05005379 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07005380 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005381 * The calling device admin must be a profile or device owner; if it is not, a security
5382 * exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07005383 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005384 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5385 * @param key The key of the restriction. See the constants in {@link android.os.UserManager}
5386 * for the list of keys.
5387 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanibe465322014-04-24 13:45:17 -07005388 */
Robin Lee25e26452015-06-02 09:56:29 -07005389 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005390 throwIfParentInstance("clearUserRestriction");
Amith Yamasanibe465322014-04-24 13:45:17 -07005391 if (mService != null) {
5392 try {
5393 mService.setUserRestriction(admin, key, false);
5394 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005395 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07005396 }
5397 }
5398 }
Adam Connors010cfd42014-04-16 12:48:13 +01005399
5400 /**
Makoto Onuki3a3092f2015-10-30 11:07:51 -07005401 * Called by a profile or device owner to get user restrictions set with
5402 * {@link #addUserRestriction(ComponentName, String)}.
5403 * <p>
5404 * The target user may have more restrictions set by the system or other device owner / profile
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005405 * owner. To get all the user restrictions currently set, use
Makoto Onuki3a3092f2015-10-30 11:07:51 -07005406 * {@link UserManager#getUserRestrictions()}.
5407 *
5408 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005409 * @throws SecurityException if {@code admin} is not a device or profile owner.
Makoto Onuki3a3092f2015-10-30 11:07:51 -07005410 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005411 public @NonNull Bundle getUserRestrictions(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005412 throwIfParentInstance("getUserRestrictions");
Makoto Onuki3a3092f2015-10-30 11:07:51 -07005413 Bundle ret = null;
5414 if (mService != null) {
5415 try {
Sudheer Shanka549b9692016-03-30 17:12:07 -07005416 ret = mService.getUserRestrictions(admin);
5417 } catch (RemoteException e) {
5418 throw e.rethrowFromSystemServer();
5419 }
5420 }
5421 return ret == null ? new Bundle() : ret;
5422 }
5423
5424 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005425 * Called by profile or device owners to hide or unhide packages. When a package is hidden it is
5426 * unavailable for use, but the data and actual package file remain.
Julia Reynolds966881e2014-05-14 12:23:08 -04005427 *
5428 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005429 * @param packageName The name of the package to hide or unhide.
5430 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005431 * unhidden.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005432 * @return boolean Whether the hidden setting of the package was successfully updated.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005433 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds966881e2014-05-14 12:23:08 -04005434 */
Robin Lee25e26452015-06-02 09:56:29 -07005435 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005436 boolean hidden) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005437 throwIfParentInstance("setApplicationHidden");
Julia Reynolds966881e2014-05-14 12:23:08 -04005438 if (mService != null) {
5439 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005440 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04005441 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005442 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04005443 }
5444 }
5445 return false;
5446 }
5447
5448 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05005449 * Called by profile or device owners to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04005450 *
5451 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005452 * @param packageName The name of the package to retrieve the hidden status of.
5453 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005454 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds966881e2014-05-14 12:23:08 -04005455 */
Robin Lee25e26452015-06-02 09:56:29 -07005456 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005457 throwIfParentInstance("isApplicationHidden");
Julia Reynolds966881e2014-05-14 12:23:08 -04005458 if (mService != null) {
5459 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005460 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04005461 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005462 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04005463 }
5464 }
5465 return false;
5466 }
5467
5468 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05005469 * Called by profile or device owners to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005470 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00005471 *
5472 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Makoto Onuki32b30572015-12-11 14:29:51 -08005473 * @param packageName The package to be re-enabled in the calling profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005474 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors655be2a2014-07-14 09:01:25 +00005475 */
Robin Lee25e26452015-06-02 09:56:29 -07005476 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005477 throwIfParentInstance("enableSystemApp");
Adam Connors655be2a2014-07-14 09:01:25 +00005478 if (mService != null) {
5479 try {
5480 mService.enableSystemApp(admin, packageName);
5481 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005482 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00005483 }
5484 }
5485 }
5486
5487 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005488 * Called by profile or device owners to re-enable system apps by intent that were disabled by
5489 * default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00005490 *
5491 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5492 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005493 * intent will be re-enabled in the calling profile.
Adam Connors655be2a2014-07-14 09:01:25 +00005494 * @return int The number of activities that matched the intent and were installed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005495 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors655be2a2014-07-14 09:01:25 +00005496 */
Robin Lee25e26452015-06-02 09:56:29 -07005497 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005498 throwIfParentInstance("enableSystemApp");
Adam Connors655be2a2014-07-14 09:01:25 +00005499 if (mService != null) {
5500 try {
5501 return mService.enableSystemAppWithIntent(admin, intent);
5502 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005503 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00005504 }
5505 }
5506 return 0;
5507 }
5508
5509 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00005510 * Called by a device owner or profile owner to disable account management for a specific type
5511 * of account.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005512 * <p>
5513 * The calling device admin must be a device owner or profile owner. If it is not, a security
5514 * exception will be thrown.
5515 * <p>
5516 * When account management is disabled for an account type, adding or removing an account of
5517 * that type will not be possible.
5518 * <p>
5519 * From {@link android.os.Build.VERSION_CODES#N} the profile or device owner can still use
Benjamin Franzb6c0ce42015-11-05 10:06:51 +00005520 * {@link android.accounts.AccountManager} APIs to add or remove accounts when account
5521 * management for a specific type is disabled.
5522 *
Sander Alewijnse650c3342014-05-08 18:00:50 +01005523 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5524 * @param accountType For which account management is disabled or enabled.
5525 * @param disabled The boolean indicating that account management will be disabled (true) or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005526 * enabled (false).
5527 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnse650c3342014-05-08 18:00:50 +01005528 */
Robin Lee25e26452015-06-02 09:56:29 -07005529 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01005530 boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005531 throwIfParentInstance("setAccountManagementDisabled");
Sander Alewijnse650c3342014-05-08 18:00:50 +01005532 if (mService != null) {
5533 try {
5534 mService.setAccountManagementDisabled(admin, accountType, disabled);
5535 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005536 throw e.rethrowFromSystemServer();
Sander Alewijnse650c3342014-05-08 18:00:50 +01005537 }
5538 }
5539 }
5540
5541 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01005542 * Gets the array of accounts for which account management is disabled by the profile owner.
5543 *
5544 * <p> Account management can be disabled/enabled by calling
5545 * {@link #setAccountManagementDisabled}.
5546 *
5547 * @return a list of account types for which account management has been disabled.
5548 *
5549 * @see #setAccountManagementDisabled
5550 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005551 public @Nullable String[] getAccountTypesWithManagementDisabled() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005552 throwIfParentInstance("getAccountTypesWithManagementDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07005553 return getAccountTypesWithManagementDisabledAsUser(myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01005554 }
5555
5556 /**
5557 * @see #getAccountTypesWithManagementDisabled()
5558 * @hide
5559 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005560 public @Nullable String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01005561 if (mService != null) {
5562 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01005563 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01005564 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005565 throw e.rethrowFromSystemServer();
Sander Alewijnse5c02db62014-05-07 10:46:57 +01005566 }
5567 }
5568
5569 return null;
5570 }
justinzhang511e0d82014-03-24 16:09:24 -04005571
5572 /**
Jason Monkd7b86212014-06-16 13:15:38 -04005573 * Sets which packages may enter lock task mode.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005574 * <p>
5575 * Any packages that shares uid with an allowed package will also be allowed to activate lock
5576 * task. From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task
5577 * package list results in locked tasks belonging to those packages to be finished. This
5578 * function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04005579 *
Jason Monkd7b86212014-06-16 13:15:38 -04005580 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04005581 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005582 * @throws SecurityException if {@code admin} is not a device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04005583 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00005584 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
5585 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04005586 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04005587 */
Robin Lee25e26452015-06-02 09:56:29 -07005588 public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04005589 throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005590 throwIfParentInstance("setLockTaskPackages");
justinzhang511e0d82014-03-24 16:09:24 -04005591 if (mService != null) {
5592 try {
Jason Monk48aacba2014-08-13 16:29:08 -04005593 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04005594 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005595 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04005596 }
5597 }
5598 }
5599
5600 /**
Jason Monkd7b86212014-06-16 13:15:38 -04005601 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04005602 *
5603 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04005604 * @hide
5605 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005606 public @NonNull String[] getLockTaskPackages(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005607 throwIfParentInstance("getLockTaskPackages");
justinzhang511e0d82014-03-24 16:09:24 -04005608 if (mService != null) {
5609 try {
Jason Monk48aacba2014-08-13 16:29:08 -04005610 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04005611 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005612 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04005613 }
5614 }
5615 return null;
5616 }
5617
5618 /**
5619 * This function lets the caller know whether the given component is allowed to start the
5620 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04005621 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04005622 */
Jason Monkd7b86212014-06-16 13:15:38 -04005623 public boolean isLockTaskPermitted(String pkg) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005624 throwIfParentInstance("isLockTaskPermitted");
justinzhang511e0d82014-03-24 16:09:24 -04005625 if (mService != null) {
5626 try {
Jason Monkd7b86212014-06-16 13:15:38 -04005627 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04005628 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005629 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04005630 }
5631 }
5632 return false;
5633 }
Julia Reynoldsda551652014-05-14 17:15:16 -04005634
5635 /**
5636 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
5637 * 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 -07005638 * <p>
5639 * The settings that can be updated with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005640 * <ul>
5641 * <li>{@link Settings.Global#ADB_ENABLED}</li>
5642 * <li>{@link Settings.Global#AUTO_TIME}</li>
5643 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005644 * <li>{@link Settings.Global#DATA_ROAMING}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005645 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005646 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005647 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN} This setting is only available from
5648 * {@link android.os.Build.VERSION_CODES#M} onwards and can only be set if
5649 * {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
5650 * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li> This setting is only
5651 * available from {@link android.os.Build.VERSION_CODES#M} onwards.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005652 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005653 * <p>
5654 * Changing the following settings has no effect as of {@link android.os.Build.VERSION_CODES#M}:
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005655 * <ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005656 * <li>{@link Settings.Global#BLUETOOTH_ON}. Use
5657 * {@link android.bluetooth.BluetoothAdapter#enable()} and
5658 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005659 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005660 * <li>{@link Settings.Global#MODE_RINGER}. Use
5661 * {@link android.media.AudioManager#setRingerMode(int)} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005662 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005663 * <li>{@link Settings.Global#WIFI_ON}. Use
5664 * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005665 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04005666 *
5667 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5668 * @param setting The name of the setting to update.
5669 * @param value The value to update the setting to.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005670 * @throws SecurityException if {@code admin} is not a device owner.
Julia Reynoldsda551652014-05-14 17:15:16 -04005671 */
Robin Lee25e26452015-06-02 09:56:29 -07005672 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005673 throwIfParentInstance("setGlobalSetting");
Julia Reynoldsda551652014-05-14 17:15:16 -04005674 if (mService != null) {
5675 try {
5676 mService.setGlobalSetting(admin, setting, value);
5677 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005678 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04005679 }
5680 }
5681 }
5682
5683 /**
5684 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
5685 * that the value of the setting is in the correct form for the setting type should be performed
5686 * by the caller.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005687 * <p>
5688 * The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005689 * <ul>
5690 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07005691 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005692 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
5693 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005694 * <p>
5695 * A device owner can additionally update the following settings:
Julia Reynolds82735bc2014-09-04 16:43:30 -04005696 * <ul>
5697 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
5698 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005699 *
Julia Reynoldsda551652014-05-14 17:15:16 -04005700 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5701 * @param setting The name of the setting to update.
5702 * @param value The value to update the setting to.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005703 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynoldsda551652014-05-14 17:15:16 -04005704 */
Robin Lee25e26452015-06-02 09:56:29 -07005705 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005706 throwIfParentInstance("setSecureSetting");
Julia Reynoldsda551652014-05-14 17:15:16 -04005707 if (mService != null) {
5708 try {
5709 mService.setSecureSetting(admin, setting, value);
5710 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005711 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04005712 }
5713 }
5714 }
5715
Amith Yamasanif20d6402014-05-24 15:34:37 -07005716 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005717 * Designates a specific service component as the provider for making permission requests of a
5718 * local or remote administrator of the user.
Amith Yamasanif20d6402014-05-24 15:34:37 -07005719 * <p/>
5720 * Only a profile owner can designate the restrictions provider.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005721 *
Amith Yamasanif20d6402014-05-24 15:34:37 -07005722 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07005723 * @param provider The component name of the service that implements
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005724 * {@link RestrictionsReceiver}. If this param is null, it removes the restrictions
5725 * provider previously assigned.
5726 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanif20d6402014-05-24 15:34:37 -07005727 */
Robin Lee25e26452015-06-02 09:56:29 -07005728 public void setRestrictionsProvider(@NonNull ComponentName admin,
5729 @Nullable ComponentName provider) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005730 throwIfParentInstance("setRestrictionsProvider");
Amith Yamasanif20d6402014-05-24 15:34:37 -07005731 if (mService != null) {
5732 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07005733 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07005734 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005735 throw re.rethrowFromSystemServer();
Amith Yamasanif20d6402014-05-24 15:34:37 -07005736 }
5737 }
5738 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04005739
5740 /**
5741 * Called by profile or device owners to set the master volume mute on or off.
Nicolas Prevotaef3ce22016-09-22 12:00:25 +01005742 * This has no effect when set on a managed profile.
Julia Reynolds4a21b252014-06-04 11:11:43 -04005743 *
5744 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5745 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005746 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds4a21b252014-06-04 11:11:43 -04005747 */
Robin Lee25e26452015-06-02 09:56:29 -07005748 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005749 throwIfParentInstance("setMasterVolumeMuted");
Julia Reynolds4a21b252014-06-04 11:11:43 -04005750 if (mService != null) {
5751 try {
5752 mService.setMasterVolumeMuted(admin, on);
5753 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005754 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04005755 }
5756 }
5757 }
5758
5759 /**
5760 * Called by profile or device owners to check whether the master volume mute is on or off.
5761 *
5762 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5763 * @return {@code true} if master volume is muted, {@code false} if it's not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005764 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds4a21b252014-06-04 11:11:43 -04005765 */
Robin Lee25e26452015-06-02 09:56:29 -07005766 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005767 throwIfParentInstance("isMasterVolumeMuted");
Julia Reynolds4a21b252014-06-04 11:11:43 -04005768 if (mService != null) {
5769 try {
5770 return mService.isMasterVolumeMuted(admin);
5771 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005772 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04005773 }
5774 }
5775 return false;
5776 }
Kenny Guyc13053b2014-05-29 14:17:17 +01005777
5778 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005779 * Called by profile or device owners to change whether a user can uninstall a package.
Kenny Guyc13053b2014-05-29 14:17:17 +01005780 *
5781 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5782 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01005783 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005784 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyc13053b2014-05-29 14:17:17 +01005785 */
Robin Lee25e26452015-06-02 09:56:29 -07005786 public void setUninstallBlocked(@NonNull ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01005787 boolean uninstallBlocked) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005788 throwIfParentInstance("setUninstallBlocked");
Kenny Guyc13053b2014-05-29 14:17:17 +01005789 if (mService != null) {
5790 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01005791 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01005792 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005793 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01005794 }
5795 }
5796 }
5797
5798 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005799 * Check whether the user has been blocked by device policy from uninstalling a package.
Rubin Xua97855b2014-11-07 05:41:00 +00005800 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00005801 * <p>
5802 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005803 * behavior of this API is changed such that passing {@code null} as the {@code admin} parameter
5804 * will return if any admin has blocked the uninstallation. Before L MR1, passing {@code null}
5805 * will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01005806 *
Robin Lee25e26452015-06-02 09:56:29 -07005807 * @param admin The name of the admin component whose blocking policy will be checked, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005808 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01005809 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00005810 * @return true if uninstallation is blocked.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005811 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyc13053b2014-05-29 14:17:17 +01005812 */
Robin Lee25e26452015-06-02 09:56:29 -07005813 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005814 throwIfParentInstance("isUninstallBlocked");
Kenny Guyc13053b2014-05-29 14:17:17 +01005815 if (mService != null) {
5816 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01005817 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01005818 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005819 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01005820 }
5821 }
5822 return false;
5823 }
Svetoslav976e8bd2014-07-16 15:12:03 -07005824
5825 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005826 * Called by the profile owner of a managed profile to enable widget providers from a given
5827 * package to be available in the parent profile. As a result the user will be able to add
5828 * widgets from the white-listed package running under the profile to a widget host which runs
5829 * under the parent profile, for example the home screen. Note that a package may have zero or
5830 * more provider components, where each component provides a different widget type.
Svetoslav976e8bd2014-07-16 15:12:03 -07005831 * <p>
5832 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07005833 *
5834 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5835 * @param packageName The package from which widget providers are white-listed.
5836 * @return Whether the package was added.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005837 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07005838 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
5839 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
5840 */
Robin Lee25e26452015-06-02 09:56:29 -07005841 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005842 throwIfParentInstance("addCrossProfileWidgetProvider");
Svetoslav976e8bd2014-07-16 15:12:03 -07005843 if (mService != null) {
5844 try {
5845 return mService.addCrossProfileWidgetProvider(admin, packageName);
5846 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005847 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07005848 }
5849 }
5850 return false;
5851 }
5852
5853 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005854 * Called by the profile owner of a managed profile to disable widget providers from a given
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005855 * package to be available in the parent profile. For this method to take effect the package
5856 * should have been added via
5857 * {@link #addCrossProfileWidgetProvider( android.content.ComponentName, String)}.
Svetoslav976e8bd2014-07-16 15:12:03 -07005858 * <p>
5859 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07005860 *
5861 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005862 * @param packageName The package from which widget providers are no longer white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07005863 * @return Whether the package was removed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005864 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07005865 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
5866 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
5867 */
Esteban Talavera62399912016-01-11 15:37:55 +00005868 public boolean removeCrossProfileWidgetProvider(
5869 @NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005870 throwIfParentInstance("removeCrossProfileWidgetProvider");
Svetoslav976e8bd2014-07-16 15:12:03 -07005871 if (mService != null) {
5872 try {
5873 return mService.removeCrossProfileWidgetProvider(admin, packageName);
5874 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005875 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07005876 }
5877 }
5878 return false;
5879 }
5880
5881 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005882 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07005883 * available in the parent profile.
5884 *
5885 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5886 * @return The white-listed package list.
Svetoslav976e8bd2014-07-16 15:12:03 -07005887 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
5888 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005889 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07005890 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005891 public @NonNull List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005892 throwIfParentInstance("getCrossProfileWidgetProviders");
Svetoslav976e8bd2014-07-16 15:12:03 -07005893 if (mService != null) {
5894 try {
5895 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
5896 if (providers != null) {
5897 return providers;
5898 }
5899 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005900 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07005901 }
5902 }
5903 return Collections.emptyList();
5904 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005905
5906 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005907 * Called by profile or device owners to set the user's photo.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005908 *
5909 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5910 * @param icon the bitmap to set as the photo.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005911 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005912 */
Robin Lee25e26452015-06-02 09:56:29 -07005913 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005914 throwIfParentInstance("setUserIcon");
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005915 try {
5916 mService.setUserIcon(admin, icon);
5917 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005918 throw re.rethrowFromSystemServer();
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005919 }
5920 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04005921
5922 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01005923 * Called by device owners to set a local system update policy. When a new policy is set,
5924 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00005925 *
Robin Lee25e26452015-06-02 09:56:29 -07005926 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005927 * components in the device owner package can set system update policies and the most
5928 * recent policy takes effect.
Robin Lee25e26452015-06-02 09:56:29 -07005929 * @param policy the new policy, or {@code null} to clear the current policy.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005930 * @throws SecurityException if {@code admin} is not a device owner.
Rubin Xu5faad8e2015-04-20 17:43:48 +01005931 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00005932 */
Robin Lee25e26452015-06-02 09:56:29 -07005933 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005934 throwIfParentInstance("setSystemUpdatePolicy");
Rubin Xu8027a4f2015-03-10 17:52:37 +00005935 if (mService != null) {
5936 try {
Robin Lee25e26452015-06-02 09:56:29 -07005937 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00005938 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005939 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00005940 }
5941 }
5942 }
5943
5944 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01005945 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00005946 *
Robin Lee25e26452015-06-02 09:56:29 -07005947 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00005948 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005949 public @Nullable SystemUpdatePolicy getSystemUpdatePolicy() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005950 throwIfParentInstance("getSystemUpdatePolicy");
Rubin Xu8027a4f2015-03-10 17:52:37 +00005951 if (mService != null) {
5952 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01005953 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00005954 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005955 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00005956 }
5957 }
5958 return null;
5959 }
Benjamin Franze36087e2015-04-07 16:40:34 +01005960
5961 /**
5962 * Called by a device owner to disable the keyguard altogether.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005963 * <p>
5964 * Setting the keyguard to disabled has the same effect as choosing "None" as the screen lock
5965 * type. However, this call has no effect if a password, pin or pattern is currently set. If a
5966 * password, pin or pattern is set after the keyguard was disabled, the keyguard stops being
5967 * disabled.
Benjamin Franze36087e2015-04-07 16:40:34 +01005968 *
5969 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01005970 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01005971 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005972 * place. {@code true} otherwise.
5973 * @throws SecurityException if {@code admin} is not a device owner.
Benjamin Franze36087e2015-04-07 16:40:34 +01005974 */
Robin Lee25e26452015-06-02 09:56:29 -07005975 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005976 throwIfParentInstance("setKeyguardDisabled");
Benjamin Franze36087e2015-04-07 16:40:34 +01005977 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01005978 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01005979 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005980 throw re.rethrowFromSystemServer();
Benjamin Franze36087e2015-04-07 16:40:34 +01005981 }
5982 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00005983
5984 /**
Benjamin Franzbece8062015-05-06 12:14:31 +01005985 * Called by device owner to disable the status bar. Disabling the status bar blocks
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005986 * notifications, quick settings and other screen overlays that allow escaping from a single use
5987 * device.
Benjamin Franzea2ec972015-03-16 17:18:09 +00005988 *
5989 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01005990 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005991 * @return {@code false} if attempting to disable the status bar failed. {@code true} otherwise.
5992 * @throws SecurityException if {@code admin} is not a device owner.
Benjamin Franzea2ec972015-03-16 17:18:09 +00005993 */
Robin Lee25e26452015-06-02 09:56:29 -07005994 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005995 throwIfParentInstance("setStatusBarDisabled");
Benjamin Franzea2ec972015-03-16 17:18:09 +00005996 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01005997 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00005998 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005999 throw re.rethrowFromSystemServer();
Benjamin Franzea2ec972015-03-16 17:18:09 +00006000 }
6001 }
Rubin Xudc105cc2015-04-14 23:38:01 +01006002
6003 /**
6004 * Callable by the system update service to notify device owners about pending updates.
6005 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
6006 * permission.
6007 *
6008 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating
6009 * when the current pending update was first available. -1 if no update is available.
6010 * @hide
6011 */
6012 @SystemApi
6013 public void notifyPendingSystemUpdate(long updateReceivedTime) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006014 throwIfParentInstance("notifyPendingSystemUpdate");
Rubin Xudc105cc2015-04-14 23:38:01 +01006015 if (mService != null) {
6016 try {
6017 mService.notifyPendingSystemUpdate(updateReceivedTime);
6018 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006019 throw re.rethrowFromSystemServer();
Rubin Xudc105cc2015-04-14 23:38:01 +01006020 }
6021 }
6022 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04006023
6024 /**
Amith Yamasanid49489b2015-04-28 14:00:26 -07006025 * Called by profile or device owners to set the default response for future runtime permission
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006026 * requests by applications. The policy can allow for normal operation which prompts the user to
6027 * grant a permission, or can allow automatic granting or denying of runtime permission requests
6028 * by an application. This also applies to new permissions declared by app updates. When a
6029 * permission is denied or granted this way, the effect is equivalent to setting the permission
6030 * grant state via {@link #setPermissionGrantState}.
6031 * <p/>
6032 * As this policy only acts on runtime permission requests, it only applies to applications
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07006033 * built with a {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Benjamin Franz45dd6662015-07-08 14:24:14 +01006034 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07006035 * @param admin Which profile or device owner this request is associated with.
6036 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006037 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
6038 * @throws SecurityException if {@code admin} is not a device or profile owner.
Benjamin Franz45dd6662015-07-08 14:24:14 +01006039 * @see #setPermissionGrantState
Amith Yamasanid49489b2015-04-28 14:00:26 -07006040 */
Robin Lee25e26452015-06-02 09:56:29 -07006041 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006042 throwIfParentInstance("setPermissionPolicy");
Amith Yamasanid49489b2015-04-28 14:00:26 -07006043 try {
6044 mService.setPermissionPolicy(admin, policy);
6045 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006046 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07006047 }
6048 }
6049
6050 /**
6051 * Returns the current runtime permission policy set by the device or profile owner. The
6052 * default is {@link #PERMISSION_POLICY_PROMPT}.
6053 * @param admin Which profile or device owner this request is associated with.
6054 * @return the current policy for future permission requests.
6055 */
Esteban Talavera28b95702015-06-24 15:23:42 +01006056 public int getPermissionPolicy(ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006057 throwIfParentInstance("getPermissionPolicy");
Amith Yamasanid49489b2015-04-28 14:00:26 -07006058 try {
6059 return mService.getPermissionPolicy(admin);
6060 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006061 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07006062 }
6063 }
6064
6065 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006066 * Sets the grant state of a runtime permission for a specific application. The state can be
6067 * {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it through the UI,
6068 * {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission is denied and the user
6069 * cannot manage it through the UI, and {@link #PERMISSION_GRANT_STATE_GRANTED granted} in which
6070 * the permission is granted and the user cannot manage it through the UI. This might affect all
6071 * permissions in a group that the runtime permission belongs to. This method can only be called
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006072 * by a profile or device owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006073 * <p/>
6074 * Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not revoke
6075 * the permission. It retains the previous grant, if any.
6076 * <p/>
6077 * Permissions can be granted or revoked only for applications built with a
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07006078 * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07006079 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07006080 * @param admin Which profile or device owner this request is associated with.
6081 * @param packageName The application to grant or revoke a permission to.
6082 * @param permission The permission to grant or revoke.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006083 * @param grantState The permission grant state which is one of
6084 * {@link #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
6085 * {@link #PERMISSION_GRANT_STATE_GRANTED},
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006086 * @return whether the permission was successfully granted or revoked.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006087 * @throws SecurityException if {@code admin} is not a device or profile owner.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006088 * @see #PERMISSION_GRANT_STATE_DENIED
6089 * @see #PERMISSION_GRANT_STATE_DEFAULT
6090 * @see #PERMISSION_GRANT_STATE_GRANTED
Amith Yamasanid49489b2015-04-28 14:00:26 -07006091 */
Robin Lee25e26452015-06-02 09:56:29 -07006092 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006093 String permission, int grantState) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006094 throwIfParentInstance("setPermissionGrantState");
Amith Yamasanid49489b2015-04-28 14:00:26 -07006095 try {
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006096 return mService.setPermissionGrantState(admin, packageName, permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07006097 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006098 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07006099 }
6100 }
Amith Yamasani184b3752015-05-22 13:00:51 -07006101
6102 /**
6103 * Returns the current grant state of a runtime permission for a specific application.
6104 *
6105 * @param admin Which profile or device owner this request is associated with.
6106 * @param packageName The application to check the grant state for.
6107 * @param permission The permission to check for.
6108 * @return the current grant state specified by device policy. If the profile or device owner
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006109 * has not set a grant state, the return value is
6110 * {@link #PERMISSION_GRANT_STATE_DEFAULT}. This does not indicate whether or not the
6111 * permission is currently granted for the package.
6112 * <p/>
6113 * If a grant state was set by the profile or device owner, then the return value will
6114 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or
6115 * {@link #PERMISSION_GRANT_STATE_GRANTED}, which indicates if the permission is
6116 * currently denied or granted.
6117 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasani184b3752015-05-22 13:00:51 -07006118 * @see #setPermissionGrantState(ComponentName, String, String, int)
6119 * @see PackageManager#checkPermission(String, String)
6120 */
Robin Lee25e26452015-06-02 09:56:29 -07006121 public int getPermissionGrantState(@NonNull ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07006122 String permission) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006123 throwIfParentInstance("getPermissionGrantState");
Amith Yamasani184b3752015-05-22 13:00:51 -07006124 try {
6125 return mService.getPermissionGrantState(admin, packageName, permission);
6126 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006127 throw re.rethrowFromSystemServer();
Amith Yamasani184b3752015-05-22 13:00:51 -07006128 }
6129 }
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006130
6131 /**
6132 * Returns if provisioning a managed profile or device is possible or not.
6133 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
6134 * {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006135 * @return if provisioning a managed profile or device is possible or not.
6136 * @throws IllegalArgumentException if the supplied action is not valid.
6137 */
6138 public boolean isProvisioningAllowed(String action) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006139 throwIfParentInstance("isProvisioningAllowed");
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006140 try {
6141 return mService.isProvisioningAllowed(action);
6142 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006143 throw re.rethrowFromSystemServer();
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006144 }
6145 }
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006146
6147 /**
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00006148 * Checks if provisioning a managed profile or device is possible and returns one of the
6149 * {@link ProvisioningPreCondition}.
6150 *
6151 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
6152 * {@link #ACTION_PROVISION_MANAGED_PROFILE},
6153 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE},
6154 * {@link #ACTION_PROVISION_MANAGED_USER}
6155 * @hide
6156 */
6157 public @ProvisioningPreCondition int checkProvisioningPreCondition(String action) {
6158 try {
6159 return mService.checkProvisioningPreCondition(action);
6160 } catch (RemoteException re) {
6161 throw re.rethrowFromSystemServer();
6162 }
6163 }
6164
6165 /**
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006166 * Return if this user is a managed profile of another user. An admin can become the profile
6167 * owner of a managed profile with {@link #ACTION_PROVISION_MANAGED_PROFILE} and of a managed
Kenny Guyffa38402016-03-31 16:40:57 +01006168 * user with {@link #createAndManageUser}
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006169 * @param admin Which profile owner this request is associated with.
6170 * @return if this user is a managed profile of another user.
6171 */
6172 public boolean isManagedProfile(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006173 throwIfParentInstance("isManagedProfile");
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006174 try {
6175 return mService.isManagedProfile(admin);
6176 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006177 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006178 }
6179 }
6180
6181 /**
6182 * @hide
6183 * Return if this user is a system-only user. An admin can manage a device from a system only
6184 * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}.
6185 * @param admin Which device owner this request is associated with.
6186 * @return if this user is a system-only user.
6187 */
6188 public boolean isSystemOnlyUser(@NonNull ComponentName admin) {
6189 try {
6190 return mService.isSystemOnlyUser(admin);
6191 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006192 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006193 }
6194 }
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006195
6196 /**
6197 * Called by device owner to get the MAC address of the Wi-Fi device.
6198 *
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08006199 * @param admin Which device owner this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006200 * @return the MAC address of the Wi-Fi device, or null when the information is not available.
6201 * (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.)
6202 * <p>
6203 * The address will be in the {@code XX:XX:XX:XX:XX:XX} format.
6204 * @throws SecurityException if {@code admin} is not a device owner.
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006205 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006206 public @Nullable String getWifiMacAddress(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006207 throwIfParentInstance("getWifiMacAddress");
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006208 try {
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08006209 return mService.getWifiMacAddress(admin);
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006210 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006211 throw re.rethrowFromSystemServer();
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006212 }
6213 }
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00006214
6215 /**
Mahaver Chopra1216ae52016-03-11 15:39:48 +00006216 * Called by device owner to reboot the device. If there is an ongoing call on the device,
6217 * throws an {@link IllegalStateException}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006218 * @param admin Which device owner the request is associated with.
Mahaver Chopra1216ae52016-03-11 15:39:48 +00006219 * @throws IllegalStateException if device has an ongoing call.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006220 * @throws SecurityException if {@code admin} is not a device owner.
Mahaver Chopra1216ae52016-03-11 15:39:48 +00006221 * @see TelephonyManager#CALL_STATE_IDLE
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00006222 */
6223 public void reboot(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006224 throwIfParentInstance("reboot");
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00006225 try {
6226 mService.reboot(admin);
6227 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006228 throw re.rethrowFromSystemServer();
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00006229 }
6230 }
Kenny Guy06de4e72015-12-22 12:07:39 +00006231
6232 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006233 * Called by a device admin to set the short support message. This will be displayed to the user
6234 * in settings screens where funtionality has been disabled by the admin. The message should be
6235 * limited to a short statement such as "This setting is disabled by your administrator. Contact
6236 * someone@example.com for support." If the message is longer than 200 characters it may be
6237 * truncated.
6238 * <p>
6239 * If the short support message needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006240 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
6241 * and set a new version of this string accordingly.
6242 *
Kenny Guy06de4e72015-12-22 12:07:39 +00006243 * @see #setLongSupportMessage
Kenny Guy06de4e72015-12-22 12:07:39 +00006244 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006245 * @param message Short message to be displayed to the user in settings or null to clear the
6246 * existing message.
6247 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00006248 */
6249 public void setShortSupportMessage(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006250 @Nullable CharSequence message) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006251 throwIfParentInstance("setShortSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00006252 if (mService != null) {
6253 try {
6254 mService.setShortSupportMessage(admin, message);
6255 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006256 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006257 }
6258 }
6259 }
6260
6261 /**
6262 * Called by a device admin to get the short support message.
6263 *
6264 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006265 * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)} or
6266 * null if no message has been set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006267 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00006268 */
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006269 public CharSequence getShortSupportMessage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006270 throwIfParentInstance("getShortSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00006271 if (mService != null) {
6272 try {
6273 return mService.getShortSupportMessage(admin);
6274 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006275 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006276 }
6277 }
6278 return null;
6279 }
6280
6281 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006282 * Called by a device admin to set the long support message. This will be displayed to the user
6283 * in the device administators settings screen.
6284 * <p>
6285 * If the long support message needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006286 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
6287 * and set a new version of this string accordingly.
6288 *
Kenny Guy06de4e72015-12-22 12:07:39 +00006289 * @see #setShortSupportMessage
Kenny Guy06de4e72015-12-22 12:07:39 +00006290 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006291 * @param message Long message to be displayed to the user in settings or null to clear the
6292 * existing message.
6293 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00006294 */
6295 public void setLongSupportMessage(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006296 @Nullable CharSequence message) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006297 throwIfParentInstance("setLongSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00006298 if (mService != null) {
6299 try {
6300 mService.setLongSupportMessage(admin, message);
6301 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006302 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006303 }
6304 }
6305 }
6306
6307 /**
6308 * Called by a device admin to get the long support message.
6309 *
6310 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006311 * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)} or
6312 * null if no message has been set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006313 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00006314 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006315 public @Nullable CharSequence getLongSupportMessage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006316 throwIfParentInstance("getLongSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00006317 if (mService != null) {
6318 try {
6319 return mService.getLongSupportMessage(admin);
6320 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006321 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006322 }
6323 }
6324 return null;
6325 }
6326
6327 /**
6328 * Called by the system to get the short support message.
6329 *
6330 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6331 * @param userHandle user id the admin is running as.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006332 * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)}
Kenny Guy06de4e72015-12-22 12:07:39 +00006333 *
6334 * @hide
6335 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006336 public @Nullable CharSequence getShortSupportMessageForUser(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006337 int userHandle) {
Kenny Guy06de4e72015-12-22 12:07:39 +00006338 if (mService != null) {
6339 try {
6340 return mService.getShortSupportMessageForUser(admin, userHandle);
6341 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006342 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006343 }
6344 }
6345 return null;
6346 }
6347
6348
6349 /**
6350 * Called by the system to get the long support message.
6351 *
6352 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6353 * @param userHandle user id the admin is running as.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006354 * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)}
Kenny Guy06de4e72015-12-22 12:07:39 +00006355 *
6356 * @hide
6357 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006358 public @Nullable CharSequence getLongSupportMessageForUser(
6359 @NonNull ComponentName admin, int userHandle) {
Kenny Guy06de4e72015-12-22 12:07:39 +00006360 if (mService != null) {
6361 try {
6362 return mService.getLongSupportMessageForUser(admin, userHandle);
6363 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006364 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006365 }
6366 }
6367 return null;
6368 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006369
6370 /**
Esteban Talavera62399912016-01-11 15:37:55 +00006371 * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager}
6372 * whose calls act on the parent profile.
Benjamin Franz66b45f02016-04-05 19:12:39 +01006373 *
6374 * <p>The following methods are supported for the parent instance, all other methods will
6375 * throw a SecurityException when called on the parent instance:
6376 * <ul>
6377 * <li>{@link #getPasswordQuality}</li>
6378 * <li>{@link #setPasswordQuality}</li>
6379 * <li>{@link #getPasswordMinimumLength}</li>
6380 * <li>{@link #setPasswordMinimumLength}</li>
6381 * <li>{@link #getPasswordMinimumUpperCase}</li>
6382 * <li>{@link #setPasswordMinimumUpperCase}</li>
6383 * <li>{@link #getPasswordMinimumLowerCase}</li>
6384 * <li>{@link #setPasswordMinimumLowerCase}</li>
6385 * <li>{@link #getPasswordMinimumLetters}</li>
6386 * <li>{@link #setPasswordMinimumLetters}</li>
6387 * <li>{@link #getPasswordMinimumNumeric}</li>
6388 * <li>{@link #setPasswordMinimumNumeric}</li>
6389 * <li>{@link #getPasswordMinimumSymbols}</li>
6390 * <li>{@link #setPasswordMinimumSymbols}</li>
6391 * <li>{@link #getPasswordMinimumNonLetter}</li>
6392 * <li>{@link #setPasswordMinimumNonLetter}</li>
6393 * <li>{@link #getPasswordHistoryLength}</li>
6394 * <li>{@link #setPasswordHistoryLength}</li>
6395 * <li>{@link #getPasswordExpirationTimeout}</li>
6396 * <li>{@link #setPasswordExpirationTimeout}</li>
6397 * <li>{@link #getPasswordExpiration}</li>
Charles He8c760562016-10-25 16:36:53 +01006398 * <li>{@link #getPasswordMaximumLength}</li>
Benjamin Franz66b45f02016-04-05 19:12:39 +01006399 * <li>{@link #isActivePasswordSufficient}</li>
6400 * <li>{@link #getCurrentFailedPasswordAttempts}</li>
6401 * <li>{@link #getMaximumFailedPasswordsForWipe}</li>
6402 * <li>{@link #setMaximumFailedPasswordsForWipe}</li>
6403 * <li>{@link #getMaximumTimeToLock}</li>
6404 * <li>{@link #setMaximumTimeToLock}</li>
6405 * <li>{@link #lockNow}</li>
6406 * <li>{@link #getKeyguardDisabledFeatures}</li>
6407 * <li>{@link #setKeyguardDisabledFeatures}</li>
6408 * <li>{@link #getTrustAgentConfiguration}</li>
6409 * <li>{@link #setTrustAgentConfiguration}</li>
Michal Karpinskia20d8bb2016-11-23 12:09:08 +00006410 * <li>{@link #getRequiredStrongAuthTimeout}</li>
6411 * <li>{@link #setRequiredStrongAuthTimeout}</li>
Benjamin Franz66b45f02016-04-05 19:12:39 +01006412 * </ul>
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006413 *
6414 * @return a new instance of {@link DevicePolicyManager} that acts on the parent profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006415 * @throws SecurityException if {@code admin} is not a profile owner.
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006416 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006417 public @NonNull DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006418 throwIfParentInstance("getParentProfileInstance");
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006419 try {
6420 if (!mService.isManagedProfile(admin)) {
6421 throw new SecurityException("The current user does not have a parent profile.");
6422 }
Jeff Sharkey49ca5292016-05-10 12:54:45 -06006423 return new DevicePolicyManager(mContext, mService, true);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006424 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006425 throw e.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006426 }
6427 }
6428
6429 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00006430 * Called by device owner to control the security logging feature. Logging can only be
6431 * enabled on single user devices where the sole user is managed by the device owner.
6432 *
6433 * <p> Security logs contain various information intended for security auditing purposes.
6434 * See {@link SecurityEvent} for details.
6435 *
6436 * <p>There must be only one user on the device, managed by the device owner.
6437 * Otherwise a {@link SecurityException} will be thrown.
Michal Karpinskib58e4962016-03-01 14:55:10 +00006438 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006439 * @param admin Which device owner this request is associated with.
Michal Karpinski6235a942016-03-15 12:07:23 +00006440 * @param enabled whether security logging should be enabled or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006441 * @throws SecurityException if {@code admin} is not a device owner.
Michal Karpinski6235a942016-03-15 12:07:23 +00006442 * @see #retrieveSecurityLogs
6443 */
6444 public void setSecurityLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006445 throwIfParentInstance("setSecurityLoggingEnabled");
Michal Karpinski6235a942016-03-15 12:07:23 +00006446 try {
6447 mService.setSecurityLoggingEnabled(admin, enabled);
6448 } catch (RemoteException re) {
6449 throw re.rethrowFromSystemServer();
6450 }
6451 }
6452
6453 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00006454 * Return whether security logging is enabled or not by the device owner.
6455 *
6456 * <p>Can only be called by the device owner, otherwise a {@link SecurityException} will be
6457 * thrown.
6458 *
6459 * @param admin Which device owner this request is associated with.
6460 * @return {@code true} if security logging is enabled by device owner, {@code false} otherwise.
6461 * @throws SecurityException if {@code admin} is not a device owner.
6462 */
6463 public boolean isSecurityLoggingEnabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006464 throwIfParentInstance("isSecurityLoggingEnabled");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006465 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00006466 return mService.isSecurityLoggingEnabled(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006467 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006468 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006469 }
6470 }
6471
6472 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00006473 * Called by device owner to retrieve all new security logging entries since the last call to
6474 * this API after device boots.
6475 *
6476 * <p> Access to the logs is rate limited and it will only return new logs after the device
6477 * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}.
6478 *
6479 * <p>There must be only one user on the device, managed by the device owner.
6480 * Otherwise a {@link SecurityException} will be thrown.
Michal Karpinskib58e4962016-03-01 14:55:10 +00006481 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006482 * @param admin Which device owner this request is associated with.
Michal Karpinski6235a942016-03-15 12:07:23 +00006483 * @return the new batch of security logs which is a list of {@link SecurityEvent},
6484 * or {@code null} if rate limitation is exceeded or if logging is currently disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006485 * @throws SecurityException if {@code admin} is not a device owner.
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006486 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006487 public @Nullable List<SecurityEvent> retrieveSecurityLogs(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006488 throwIfParentInstance("retrieveSecurityLogs");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006489 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00006490 ParceledListSlice<SecurityEvent> list = mService.retrieveSecurityLogs(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006491 if (list != null) {
6492 return list.getList();
6493 } else {
6494 // Rate limit exceeded.
6495 return null;
6496 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006497 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006498 throw re.rethrowFromSystemServer();
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006499 }
6500 }
Benjamin Franz59720bb2016-01-18 15:26:11 +00006501
6502 /**
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00006503 * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent
6504 * profile.
6505 *
6506 * @hide
6507 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006508 public @NonNull DevicePolicyManager getParentProfileInstance(UserInfo uInfo) {
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00006509 mContext.checkSelfPermission(
6510 android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS);
6511 if (!uInfo.isManagedProfile()) {
6512 throw new SecurityException("The user " + uInfo.id
6513 + " does not have a parent profile.");
6514 }
Jeff Sharkey49ca5292016-05-10 12:54:45 -06006515 return new DevicePolicyManager(mContext, mService, true);
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00006516 }
6517
6518 /**
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006519 * Called by device owners to retrieve device logs from before the device's last reboot.
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006520 * <p>
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01006521 * <strong> This API is not supported on all devices. Calling this API on unsupported devices
6522 * will result in {@code null} being returned. The device logs are retrieved from a RAM region
6523 * which is not guaranteed to be corruption-free during power cycles, as a result be cautious
6524 * about data corruption when parsing. </strong>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006525 * <p>
6526 * There must be only one user on the device, managed by the device owner. Otherwise a
6527 * {@link SecurityException} will be thrown.
Michal Karpinskib58e4962016-03-01 14:55:10 +00006528 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006529 * @param admin Which device owner this request is associated with.
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01006530 * @return Device logs from before the latest reboot of the system, or {@code null} if this API
6531 * is not supported on the device.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006532 * @throws SecurityException if {@code admin} is not a device owner.
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006533 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006534 public @Nullable List<SecurityEvent> retrievePreRebootSecurityLogs(
6535 @NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006536 throwIfParentInstance("retrievePreRebootSecurityLogs");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006537 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00006538 ParceledListSlice<SecurityEvent> list = mService.retrievePreRebootSecurityLogs(admin);
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01006539 if (list != null) {
6540 return list.getList();
6541 } else {
6542 return null;
6543 }
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006544 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006545 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006546 }
6547 }
6548
6549 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006550 * Called by a profile owner of a managed profile to set the color used for customization. This
6551 * color is used as background color of the confirm credentials screen for that user. The
Clara Bayarri8d0bd7fa2016-03-30 14:59:58 +01006552 * default color is teal (#00796B).
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006553 * <p>
6554 * The confirm credentials screen can be created using
Benjamin Franz59720bb2016-01-18 15:26:11 +00006555 * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}.
6556 *
6557 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinski74cd7302016-04-12 15:17:36 +01006558 * @param color The 24bit (0xRRGGBB) representation of the color to be used.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006559 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz59720bb2016-01-18 15:26:11 +00006560 */
6561 public void setOrganizationColor(@NonNull ComponentName admin, int color) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006562 throwIfParentInstance("setOrganizationColor");
Benjamin Franz59720bb2016-01-18 15:26:11 +00006563 try {
Michal Karpinski74cd7302016-04-12 15:17:36 +01006564 // always enforce alpha channel to have 100% opacity
6565 color |= 0xFF000000;
Benjamin Franz59720bb2016-01-18 15:26:11 +00006566 mService.setOrganizationColor(admin, color);
6567 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006568 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00006569 }
6570 }
6571
6572 /**
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00006573 * @hide
6574 *
6575 * Sets the color used for customization.
6576 *
Michal Karpinski74cd7302016-04-12 15:17:36 +01006577 * @param color The 24bit (0xRRGGBB) representation of the color to be used.
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00006578 * @param userId which user to set the color to.
6579 * @RequiresPermission(allOf = {
6580 * Manifest.permission.MANAGE_USERS,
6581 * Manifest.permission.INTERACT_ACROSS_USERS_FULL})
6582 */
6583 public void setOrganizationColorForUser(@ColorInt int color, @UserIdInt int userId) {
6584 try {
Michal Karpinski74cd7302016-04-12 15:17:36 +01006585 // always enforce alpha channel to have 100% opacity
6586 color |= 0xFF000000;
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00006587 mService.setOrganizationColorForUser(color, userId);
6588 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006589 throw re.rethrowFromSystemServer();
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00006590 }
6591 }
6592
6593 /**
Benjamin Franz59720bb2016-01-18 15:26:11 +00006594 * Called by a profile owner of a managed profile to retrieve the color used for customization.
6595 * This color is used as background color of the confirm credentials screen for that user.
6596 *
6597 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinski74cd7302016-04-12 15:17:36 +01006598 * @return The 24bit (0xRRGGBB) representation of the color to be used.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006599 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz59720bb2016-01-18 15:26:11 +00006600 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01006601 public @ColorInt int getOrganizationColor(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006602 throwIfParentInstance("getOrganizationColor");
Benjamin Franz59720bb2016-01-18 15:26:11 +00006603 try {
6604 return mService.getOrganizationColor(admin);
6605 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006606 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00006607 }
6608 }
6609
6610 /**
6611 * @hide
6612 * Retrieve the customization color for a given user.
6613 *
6614 * @param userHandle The user id of the user we're interested in.
Michal Karpinski74cd7302016-04-12 15:17:36 +01006615 * @return The 24bit (0xRRGGBB) representation of the color to be used.
Benjamin Franz59720bb2016-01-18 15:26:11 +00006616 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01006617 public @ColorInt int getOrganizationColorForUser(int userHandle) {
Benjamin Franz59720bb2016-01-18 15:26:11 +00006618 try {
6619 return mService.getOrganizationColorForUser(userHandle);
6620 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006621 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00006622 }
6623 }
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006624
6625 /**
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01006626 * Called by the device owner or profile owner to set the name of the organization under
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006627 * management.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006628 * <p>
6629 * If the organization name needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006630 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
6631 * and set a new version of this string accordingly.
6632 *
6633 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6634 * @param title The organization name or {@code null} to clear a previously set name.
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01006635 * @throws SecurityException if {@code admin} is not a device or profile owner.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006636 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01006637 public void setOrganizationName(@NonNull ComponentName admin, @Nullable CharSequence title) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006638 throwIfParentInstance("setOrganizationName");
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006639 try {
6640 mService.setOrganizationName(admin, title);
6641 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006642 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006643 }
6644 }
6645
6646 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006647 * Called by a profile owner of a managed profile to retrieve the name of the organization under
6648 * management.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006649 *
6650 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6651 * @return The organization name or {@code null} if none is set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006652 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006653 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006654 public @Nullable CharSequence getOrganizationName(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006655 throwIfParentInstance("getOrganizationName");
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006656 try {
6657 return mService.getOrganizationName(admin);
6658 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006659 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006660 }
6661 }
6662
6663 /**
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01006664 * Called by the system to retrieve the name of the organization managing the device.
6665 *
6666 * @return The organization name or {@code null} if none is set.
6667 * @throws SecurityException if the caller is not the device owner, does not hold the
6668 * MANAGE_USERS permission and is not the system.
6669 *
6670 * @hide
6671 */
6672 @SystemApi
6673 @TestApi
6674 public @Nullable CharSequence getDeviceOwnerOrganizationName() {
6675 try {
6676 return mService.getDeviceOwnerOrganizationName();
6677 } catch (RemoteException re) {
6678 throw re.rethrowFromSystemServer();
6679 }
6680 }
6681
6682 /**
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006683 * Retrieve the default title message used in the confirm credentials screen for a given user.
6684 *
6685 * @param userHandle The user id of the user we're interested in.
6686 * @return The organization name or {@code null} if none is set.
6687 *
6688 * @hide
6689 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006690 public @Nullable CharSequence getOrganizationNameForUser(int userHandle) {
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006691 try {
6692 return mService.getOrganizationNameForUser(userHandle);
6693 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006694 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006695 }
6696 }
6697
6698 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00006699 * @return the {@link UserProvisioningState} for the current user - for unmanaged users will
6700 * return {@link #STATE_USER_UNMANAGED}
6701 * @hide
6702 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00006703 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00006704 @UserProvisioningState
6705 public int getUserProvisioningState() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006706 throwIfParentInstance("getUserProvisioningState");
Alan Treadwayafad8782016-01-19 15:15:08 +00006707 if (mService != null) {
6708 try {
6709 return mService.getUserProvisioningState();
6710 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006711 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00006712 }
6713 }
6714 return STATE_USER_UNMANAGED;
6715 }
6716
6717 /**
6718 * Set the {@link UserProvisioningState} for the supplied user, if they are managed.
6719 *
6720 * @param state to store
6721 * @param userHandle for user
6722 * @hide
6723 */
6724 public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) {
6725 if (mService != null) {
6726 try {
6727 mService.setUserProvisioningState(state, userHandle);
6728 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006729 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00006730 }
6731 }
6732 }
6733
6734 /**
Esteban Talaverac9bb3782016-11-11 15:41:14 +00006735 * Indicates the entity that controls the device or profile owner. Two users/profiles are
6736 * affiliated if the set of ids set by their device or profile owners intersect.
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006737 *
6738 * @param admin Which profile or device owner this request is associated with.
Esteban Talaverac9bb3782016-11-11 15:41:14 +00006739 * @param ids A list of opaque non-empty affiliation ids. Duplicate elements will be ignored.
6740 *
6741 * @throws NullPointerException if {@code ids} is null or contains null elements.
6742 * @throws IllegalArgumentException if {@code ids} contains an empty string.
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006743 */
Esteban Talaverac9bb3782016-11-11 15:41:14 +00006744 public void setAffiliationIds(@NonNull ComponentName admin, @NonNull List<String> ids) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006745 throwIfParentInstance("setAffiliationIds");
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006746 try {
Esteban Talaverac9bb3782016-11-11 15:41:14 +00006747 mService.setAffiliationIds(admin, ids);
6748 } catch (RemoteException e) {
6749 throw e.rethrowFromSystemServer();
6750 }
6751 }
6752
6753 /**
6754 * Returns the list of affiliation ids previously set via {@link #setAffiliationIds}, or an
6755 * empty list if none have been set.
6756 */
6757 public @NonNull List<String> getAffiliationIds(@NonNull ComponentName admin) {
6758 throwIfParentInstance("getAffiliationIds");
6759 try {
6760 return mService.getAffiliationIds(admin);
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006761 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006762 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006763 }
6764 }
6765
6766 /**
6767 * @hide
Esteban Talaverac9bb3782016-11-11 15:41:14 +00006768 * Returns whether this user/profile is affiliated with the device.
6769 * <p>
6770 * By definition, the user that the device owner runs on is always affiliated with the device.
6771 * Any other user/profile is considered affiliated with the device if the set specified by its
6772 * profile owner via {@link #setAffiliationIds} intersects with the device owner's.
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006773 *
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006774 */
6775 public boolean isAffiliatedUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006776 throwIfParentInstance("isAffiliatedUser");
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006777 try {
Esteban Talaverac9bb3782016-11-11 15:41:14 +00006778 return mService.isAffiliatedUser();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006779 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006780 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006781 }
6782 }
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08006783
6784 /**
6785 * @hide
6786 * Returns whether the uninstall for {@code packageName} for the current user is in queue
6787 * to be started
6788 * @param packageName the package to check for
6789 * @return whether the uninstall intent for {@code packageName} is pending
6790 */
6791 public boolean isUninstallInQueue(String packageName) {
6792 try {
6793 return mService.isUninstallInQueue(packageName);
6794 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006795 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08006796 }
6797 }
6798
6799 /**
6800 * @hide
6801 * @param packageName the package containing active DAs to be uninstalled
6802 */
6803 public void uninstallPackageWithActiveAdmins(String packageName) {
6804 try {
6805 mService.uninstallPackageWithActiveAdmins(packageName);
6806 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006807 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08006808 }
6809 }
Benjamin Franzbc33c822016-04-15 08:57:52 +01006810
Kenny Guy38dcca52016-04-19 13:09:18 +01006811 /**
6812 * @hide
6813 * Remove a test admin synchronously without sending it a broadcast about being removed.
6814 * If the admin is a profile owner or device owner it will still be removed.
6815 *
6816 * @param userHandle user id to remove the admin for.
6817 * @param admin The administration compononent to remove.
6818 * @throws SecurityException if the caller is not shell / root or the admin package
6819 * isn't a test application see {@link ApplicationInfo#FLAG_TEST_APP}.
6820 */
6821 public void forceRemoveActiveAdmin(ComponentName adminReceiver, int userHandle) {
6822 try {
6823 mService.forceRemoveActiveAdmin(adminReceiver, userHandle);
6824 } catch (RemoteException re) {
6825 throw re.rethrowFromSystemServer();
6826 }
6827 }
6828
Mahaver Chopra790d1982016-07-07 16:06:49 +01006829 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01006830 * Returns whether the device has been provisioned.
6831 *
6832 * <p>Not for use by third-party applications.
6833 *
Mahaver Chopra790d1982016-07-07 16:06:49 +01006834 * @hide
Mahaver Chopra790d1982016-07-07 16:06:49 +01006835 */
Lenka Trochtova5291ee72016-11-28 16:38:23 +01006836 @SystemApi
Mahaver Chopra790d1982016-07-07 16:06:49 +01006837 public boolean isDeviceProvisioned() {
6838 try {
6839 return mService.isDeviceProvisioned();
6840 } catch (RemoteException re) {
6841 throw re.rethrowFromSystemServer();
6842 }
6843 }
6844
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01006845 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01006846 * Writes that the provisioning configuration has been applied.
6847 *
6848 * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS}
6849 * permission.
6850 *
6851 * <p>Not for use by third-party applications.
6852 *
6853 * @hide
6854 */
6855 @SystemApi
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01006856 public void setDeviceProvisioningConfigApplied() {
6857 try {
6858 mService.setDeviceProvisioningConfigApplied();
6859 } catch (RemoteException re) {
6860 throw re.rethrowFromSystemServer();
6861 }
6862 }
6863
6864 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01006865 * Returns whether the provisioning configuration has been applied.
6866 *
6867 * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS} permission.
6868 *
6869 * <p>Not for use by third-party applications.
6870 *
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01006871 * @return whether the provisioning configuration has been applied.
Lenka Trochtova5291ee72016-11-28 16:38:23 +01006872 *
6873 * @hide
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01006874 */
Lenka Trochtova5291ee72016-11-28 16:38:23 +01006875 @SystemApi
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01006876 public boolean isDeviceProvisioningConfigApplied() {
6877 try {
6878 return mService.isDeviceProvisioningConfigApplied();
6879 } catch (RemoteException re) {
6880 throw re.rethrowFromSystemServer();
6881 }
6882 }
6883
Victor Chang9bfc65f2016-08-15 12:27:09 +01006884 /**
6885 * @hide
Victor Chang3577ed22016-08-25 18:49:26 +01006886 * Force update user setup completed status. This API has no effect on user build.
6887 * @throws {@link SecurityException} if the caller has no
6888 * {@link android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS} or the caller is
6889 * not {@link UserHandle.SYSTEM_USER}
Victor Chang9bfc65f2016-08-15 12:27:09 +01006890 */
6891 public void forceUpdateUserSetupComplete() {
6892 try {
6893 mService.forceUpdateUserSetupComplete();
6894 } catch (RemoteException re) {
6895 throw re.rethrowFromSystemServer();
6896 }
6897 }
6898
Benjamin Franzbc33c822016-04-15 08:57:52 +01006899 private void throwIfParentInstance(String functionName) {
6900 if (mParentInstance) {
6901 throw new SecurityException(functionName + " cannot be called on the parent instance");
6902 }
6903 }
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02006904
6905 /**
6906 * @hide
6907 * Enable backup service.
6908 * <p>This includes all backup and restore mechanisms.
6909 * Setting this to {@code false} will make backup service no-op or return empty results.
6910 *
6911 * <p>There must be only one user on the device, managed by the device owner.
6912 * Otherwise a {@link SecurityException} will be thrown.
6913 *
6914 * <p>Backup service is off by default when device owner is present.
6915 */
6916 public void setBackupServiceEnabled(@NonNull ComponentName admin, boolean enabled) {
6917 try {
6918 mService.setBackupServiceEnabled(admin, enabled);
6919 } catch (RemoteException re) {
6920 throw re.rethrowFromSystemServer();
6921 }
6922 }
6923
6924 /**
6925 * @hide
6926 * @return {@code true} if backup service is enabled, {@code false} otherwise.
6927 */
6928 public boolean isBackupServiceEnabled(@NonNull ComponentName admin) {
6929 try {
6930 return mService.isBackupServiceEnabled(admin);
6931 } catch (RemoteException re) {
6932 throw re.rethrowFromSystemServer();
6933 }
6934 }
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01006935
6936 /**
6937 * Called by a device owner to control the network logging feature. Logging can only be
6938 * enabled on single user devices where the sole user is managed by the device owner. If a new
6939 * user is added on the device, logging is disabled.
6940 *
6941 * <p> Network logs contain DNS lookup and connect() library call events.
6942 *
6943 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6944 * @param enabled whether network logging should be enabled or not.
6945 * @throws {@link SecurityException} if {@code admin} is not a device owner.
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01006946 * @see #retrieveNetworkLogs
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01006947 */
6948 public void setNetworkLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
6949 throwIfParentInstance("setNetworkLoggingEnabled");
6950 try {
6951 mService.setNetworkLoggingEnabled(admin, enabled);
6952 } catch (RemoteException re) {
6953 throw re.rethrowFromSystemServer();
6954 }
6955 }
6956
6957 /**
6958 * Return whether network logging is enabled by a device owner.
6959 *
phweissa4e169e2016-11-24 16:20:57 +01006960 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Can only
6961 * be {@code null} if the caller has MANAGE_USERS permission.
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01006962 * @return {@code true} if network logging is enabled by device owner, {@code false} otherwise.
phweissa4e169e2016-11-24 16:20:57 +01006963 * @throws {@link SecurityException} if {@code admin} is not a device owner and caller has
6964 * no MANAGE_USERS permission
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01006965 */
phweissa4e169e2016-11-24 16:20:57 +01006966 public boolean isNetworkLoggingEnabled(@Nullable ComponentName admin) {
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01006967 throwIfParentInstance("isNetworkLoggingEnabled");
6968 try {
6969 return mService.isNetworkLoggingEnabled(admin);
6970 } catch (RemoteException re) {
6971 throw re.rethrowFromSystemServer();
6972 }
6973 }
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01006974
6975 /**
Michal Karpinskia9ff2062016-11-03 15:46:17 +00006976 * Called by device owner to retrieve the most recent batch of network logging events.
6977 * A device owner has to provide a batchToken provided as part of
6978 * {@link DeviceAdminReceiver#onNetworkLogsAvailable} callback. If the token doesn't match the
6979 * token of the most recent available batch of logs, {@code null} will be returned.
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01006980 *
6981 * <p> {@link NetworkEvent} can be one of {@link DnsEvent} or {@link ConnectEvent}.
6982 *
6983 * <p> The list of network events is sorted chronologically, and contains at most 1200 events.
6984 *
6985 * <p> Access to the logs is rate limited and this method will only return a new batch of logs
6986 * after the device device owner has been notified via
6987 * {@link DeviceAdminReceiver#onNetworkLogsAvailable}.
6988 *
6989 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinskia9ff2062016-11-03 15:46:17 +00006990 * @param batchToken A token of the batch to retrieve
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01006991 * @return A new batch of network logs which is a list of {@link NetworkEvent}. Returns
Michal Karpinskia9ff2062016-11-03 15:46:17 +00006992 * {@code null} if the batch represented by batchToken is no longer available or if
6993 * logging is disabled.
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01006994 * @throws {@link SecurityException} if {@code admin} is not a device owner.
Michal Karpinskia9ff2062016-11-03 15:46:17 +00006995 * @see DeviceAdminReceiver#onNetworkLogsAvailable
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01006996 */
Michal Karpinskia9ff2062016-11-03 15:46:17 +00006997 public @Nullable List<NetworkEvent> retrieveNetworkLogs(@NonNull ComponentName admin,
6998 long batchToken) {
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01006999 throwIfParentInstance("retrieveNetworkLogs");
7000 try {
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007001 return mService.retrieveNetworkLogs(admin, batchToken);
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007002 } catch (RemoteException re) {
7003 throw re.rethrowFromSystemServer();
7004 }
7005 }
Tony Mak46aabe52016-11-14 12:53:06 +00007006
7007 /**
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007008 * Called by a device owner to bind to a service from a profile owner of a managed profile or
7009 * vice versa. See {@link #getBindDeviceAdminTargetUsers} for a definition of which
7010 * device/profile owners are allowed to bind to services of another profile/device owner.
7011 * <p>
Tony Mak46aabe52016-11-14 12:53:06 +00007012 * The service must be unexported. Note that the {@link Context} used to obtain this
7013 * {@link DevicePolicyManager} instance via {@link Context#getSystemService(Class)} will be used
7014 * to bind to the {@link android.app.Service}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007015 *
Tony Mak46aabe52016-11-14 12:53:06 +00007016 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7017 * @param serviceIntent Identifies the service to connect to. The Intent must specify either an
7018 * explicit component name or a package name to match an
7019 * {@link IntentFilter} published by a service.
7020 * @param conn Receives information as the service is started and stopped. This must be a
7021 * valid {@link ServiceConnection} object; it must not be {@code null}.
7022 * @param flags Operation options for the binding operation. See
7023 * {@link Context#bindService(Intent, ServiceConnection, int)}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007024 * @param targetUser Which user to bind to. Must be one of the users returned by
7025 * {@link #getBindDeviceAdminTargetUsers}, otherwise a {@link SecurityException} will
7026 * be thrown.
Tony Mak46aabe52016-11-14 12:53:06 +00007027 * @return If you have successfully bound to the service, {@code true} is returned;
7028 * {@code false} is returned if the connection is not made and you will not
7029 * receive the service object.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007030 *
Tony Mak46aabe52016-11-14 12:53:06 +00007031 * @see Context#bindService(Intent, ServiceConnection, int)
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007032 * @see #getBindDeviceAdminTargetUsers(ComponentName)
Tony Mak46aabe52016-11-14 12:53:06 +00007033 */
7034 public boolean bindDeviceAdminServiceAsUser(
7035 @NonNull ComponentName admin, Intent serviceIntent, @NonNull ServiceConnection conn,
7036 @Context.BindServiceFlags int flags, @NonNull UserHandle targetUser) {
7037 throwIfParentInstance("bindDeviceAdminServiceAsUser");
7038 // Keep this in sync with ContextImpl.bindServiceCommon.
7039 try {
7040 final IServiceConnection sd = mContext.getServiceDispatcher(conn, null, flags);
7041 serviceIntent.prepareToLeaveProcess(mContext);
7042 return mService.bindDeviceAdminServiceAsUser(admin,
7043 mContext.getIApplicationThread(), mContext.getActivityToken(), serviceIntent,
7044 sd, flags, targetUser.getIdentifier());
7045 } catch (RemoteException re) {
7046 throw re.rethrowFromSystemServer();
7047 }
7048 }
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007049
7050 /**
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007051 * Returns the list of target users that the calling device or profile owner can use when
7052 * calling {@link #bindDeviceAdminServiceAsUser}.
7053 * <p>
7054 * A device owner can bind to a service from a profile owner of a managed profile and
7055 * vice versa, provided that:
7056 * <ul>
7057 * <li>Both belong to the same package name.
7058 * <li>The managed profile is a profile of the user where the device owner is set.
7059 * See {@link UserManager#getUserProfiles()}
7060 * <li>Both users are affiliated.
7061 * STOPSHIP(b/32326223) Add reference to setAffiliationIds here once public.
7062 * </ul>
7063 */
7064 public @NonNull List<UserHandle> getBindDeviceAdminTargetUsers(@NonNull ComponentName admin) {
7065 throwIfParentInstance("getBindDeviceAdminTargetUsers");
7066 try {
7067 return mService.getBindDeviceAdminTargetUsers(admin);
7068 } catch (RemoteException re) {
7069 throw re.rethrowFromSystemServer();
7070 }
7071 }
7072
7073 /**
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007074 * Called by the system to get the time at which the device owner last retrieved security
7075 * logging entries.
7076 *
7077 * @return the time at which the device owner most recently retrieved security logging entries,
7078 * in milliseconds since epoch; -1 if security logging entries were never retrieved.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007079 * @throws SecurityException if the caller is not the device owner, does not hold the
7080 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007081 *
7082 * @hide
7083 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007084 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007085 public long getLastSecurityLogRetrievalTime() {
7086 try {
7087 return mService.getLastSecurityLogRetrievalTime();
7088 } catch (RemoteException re) {
7089 throw re.rethrowFromSystemServer();
7090 }
7091 }
7092
7093 /**
7094 * Called by the system to get the time at which the device owner last requested a bug report.
7095 *
7096 * @return the time at which the device owner most recently requested a bug report, in
7097 * milliseconds since epoch; -1 if a bug report was never requested.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007098 * @throws SecurityException if the caller is not the device owner, does not hold the
7099 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007100 *
7101 * @hide
7102 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007103 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007104 public long getLastBugReportRequestTime() {
7105 try {
7106 return mService.getLastBugReportRequestTime();
7107 } catch (RemoteException re) {
7108 throw re.rethrowFromSystemServer();
7109 }
7110 }
7111
7112 /**
7113 * Called by the system to get the time at which the device owner last retrieved network logging
7114 * events.
7115 *
7116 * @return the time at which the device owner most recently retrieved network logging events, in
7117 * milliseconds since epoch; -1 if network logging events were never retrieved.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007118 * @throws SecurityException if the caller is not the device owner, does not hold the
7119 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007120 *
7121 * @hide
7122 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007123 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007124 public long getLastNetworkLogRetrievalTime() {
7125 try {
7126 return mService.getLastNetworkLogRetrievalTime();
7127 } catch (RemoteException re) {
7128 throw re.rethrowFromSystemServer();
7129 }
7130 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08007131}