blob: 4df97d93e746643abb55cc0a415b6e2d38eb2820 [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>
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000154 * </ul>
Jessica Hummelf72078b2014-03-06 16:13:12 +0000155 *
Benjamin Franzea956242016-03-21 15:45:56 +0000156 * <p>When managed provisioning has completed, broadcasts are sent to the application specified
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000157 * in the provisioning intent. The
158 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the
159 * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in
160 * the primary profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100161 *
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000162 * <p>From version {@link android.os.Build.VERSION_CODES#O}, when managed provisioning has
163 * completed, along with the above broadcast, activity intent
164 * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the application specified in
165 * the provisioning intent.
166 *
Benjamin Franzea956242016-03-21 15:45:56 +0000167 * <p>If provisioning fails, the managedProfile is removed so the device returns to its
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100168 * previous state.
Alan Treadway4582f812015-07-28 11:49:35 +0100169 *
170 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
171 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
172 * the provisioning flow was successful, although this doesn't guarantee the full flow will
173 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
174 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000175 */
176 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
177 public static final String ACTION_PROVISION_MANAGED_PROFILE
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100178 = "android.app.action.PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000179
180 /**
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000181 * Activity action: Starts the provisioning flow which sets up a managed user.
182 *
183 * <p>This intent will typically be sent by a mobile device management application (MDM).
Makoto Onuki32b30572015-12-11 14:29:51 -0800184 * Provisioning configures the user as managed user and sets the MDM as the profile
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000185 * owner who has full control over the user. Provisioning can only happen before user setup has
186 * been completed. Use {@link #isProvisioningAllowed(String)} to check if provisioning is
187 * allowed.
188 *
Benjamin Franzea956242016-03-21 15:45:56 +0000189 * <p>The intent contains the following extras:
190 * <ul>
191 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
192 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
193 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
194 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
195 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
196 * </ul>
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000197 *
Benjamin Franzea956242016-03-21 15:45:56 +0000198 * <p>If provisioning fails, the device returns to its previous state.
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000199 *
200 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
201 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
202 * the provisioning flow was successful, although this doesn't guarantee the full flow will
203 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
204 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Benjamin Franzea956242016-03-21 15:45:56 +0000205 *
206 * @hide
Mahaver Chopra5e732562015-11-05 11:55:12 +0000207 */
208 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
209 public static final String ACTION_PROVISION_MANAGED_USER
210 = "android.app.action.PROVISION_MANAGED_USER";
211
212 /**
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100213 * Activity action: Starts the provisioning flow which sets up a managed device.
214 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
215 *
216 * <p> During device owner provisioning a device admin app is set as the owner of the device.
217 * A device owner has full control over the device. The device owner can not be modified by the
218 * user.
219 *
220 * <p> A typical use case would be a device that is owned by a company, but used by either an
221 * employee or client.
222 *
223 * <p> An intent with this action can be sent only on an unprovisioned device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000224 * It is possible to check if provisioning is allowed or not by querying the method
225 * {@link #isProvisioningAllowed(String)}.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100226 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000227 * <p>The intent contains the following extras:
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100228 * <ul>
229 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
230 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
231 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
Rubin Xua4f9dc12015-06-12 13:27:59 +0100232 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000233 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000234 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100235 * </ul>
236 *
Benjamin Franzea956242016-03-21 15:45:56 +0000237 * <p>When device owner provisioning has completed, an intent of the type
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100238 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
239 * device owner.
240 *
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000241 * <p>From version {@link android.os.Build.VERSION_CODES#O}, when device owner provisioning has
242 * completed, along with the above broadcast, activity intent
243 * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the device owner.
244 *
Benjamin Franzea956242016-03-21 15:45:56 +0000245 * <p>If provisioning fails, the device is factory reset.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100246 *
Alan Treadway4582f812015-07-28 11:49:35 +0100247 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
248 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
249 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
250 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100251 */
252 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
253 public static final String ACTION_PROVISION_MANAGED_DEVICE
254 = "android.app.action.PROVISION_MANAGED_DEVICE";
255
256 /**
Alan Treadway46dd4492015-11-09 13:57:19 +0000257 * Activity action: Starts the provisioning flow which sets up a managed device.
Steven Ng980a1b62016-02-02 17:43:18 +0000258 *
259 * <p>During device owner provisioning, a device admin app is downloaded and set as the owner of
260 * the device. A device owner has full control over the device. The device owner can not be
261 * modified by the user and the only way of resetting the device is via factory reset.
262 *
263 * <p>A typical use case would be a device that is owned by a company, but used by either an
264 * employee or client.
265 *
266 * <p>The provisioning message should be sent to an unprovisioned device.
267 *
268 * <p>Unlike {@link #ACTION_PROVISION_MANAGED_DEVICE}, the provisioning message can only be sent
269 * by a privileged app with the permission
270 * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE}.
271 *
272 * <p>The provisioning intent contains the following properties:
273 * <ul>
274 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
275 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
276 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
277 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
278 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
279 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
280 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
281 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
282 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
283 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
284 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
285 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
286 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
287 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
288 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
289 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li></ul>
290 *
291 * @hide
292 */
293 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
294 @SystemApi
295 public static final String ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE =
296 "android.app.action.PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE";
297
298 /**
299 * Activity action: Starts the provisioning flow which sets up a managed device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000300 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
301 *
302 * <p>NOTE: This is only supported on split system user devices, and puts the device into a
303 * management state that is distinct from that reached by
304 * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system
305 * user, and only has control over device-wide policies, not individual users and their data.
306 * The primary benefit is that multiple non-system users are supported when provisioning using
307 * this form of device management.
308 *
Benjamin Franzea956242016-03-21 15:45:56 +0000309 * <p>During device owner provisioning a device admin app is set as the owner of the device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000310 * A device owner has full control over the device. The device owner can not be modified by the
311 * user.
312 *
Benjamin Franzea956242016-03-21 15:45:56 +0000313 * <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 +0000314 * employee or client.
315 *
Benjamin Franzea956242016-03-21 15:45:56 +0000316 * <p>An intent with this action can be sent only on an unprovisioned device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000317 * It is possible to check if provisioning is allowed or not by querying the method
318 * {@link #isProvisioningAllowed(String)}.
319 *
320 * <p>The intent contains the following extras:
321 * <ul>
322 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
323 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
324 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
325 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Benjamin Franzea956242016-03-21 15:45:56 +0000326 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
327 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Alan Treadway46dd4492015-11-09 13:57:19 +0000328 * </ul>
329 *
Benjamin Franzea956242016-03-21 15:45:56 +0000330 * <p>When device owner provisioning has completed, an intent of the type
Alan Treadway46dd4492015-11-09 13:57:19 +0000331 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
332 * device owner.
333 *
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000334 * <p>From version {@link android.os.Build.VERSION_CODES#O}, when device owner provisioning has
335 * completed, along with the above broadcast, activity intent
336 * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the device owner.
337 *
Benjamin Franzea956242016-03-21 15:45:56 +0000338 * <p>If provisioning fails, the device is factory reset.
Alan Treadway46dd4492015-11-09 13:57:19 +0000339 *
340 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
341 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
342 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
343 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
344 *
345 * @hide
346 */
347 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
348 public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE
349 = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE";
350
351 /**
Alan Treadwayafad8782016-01-19 15:15:08 +0000352 * Activity action: Finalizes management provisioning, should be used after user-setup
353 * has been completed and {@link #getUserProvisioningState()} returns one of:
354 * <ul>
355 * <li>{@link #STATE_USER_SETUP_INCOMPLETE}</li>
356 * <li>{@link #STATE_USER_SETUP_COMPLETE}</li>
357 * <li>{@link #STATE_USER_PROFILE_COMPLETE}</li>
358 * </ul>
359 *
360 * @hide
361 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +0000362 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +0000363 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
364 public static final String ACTION_PROVISION_FINALIZATION
365 = "android.app.action.PROVISION_FINALIZATION";
366
367 /**
Michal Karpinskiba244092016-02-25 17:28:24 +0000368 * Action: Bugreport sharing with device owner has been accepted by the user.
369 *
370 * @hide
371 */
372 public static final String ACTION_BUGREPORT_SHARING_ACCEPTED =
373 "com.android.server.action.BUGREPORT_SHARING_ACCEPTED";
374
375 /**
376 * Action: Bugreport sharing with device owner has been declined by the user.
377 *
378 * @hide
379 */
380 public static final String ACTION_BUGREPORT_SHARING_DECLINED =
381 "com.android.server.action.BUGREPORT_SHARING_DECLINED";
382
383 /**
384 * Action: Bugreport has been collected and is dispatched to {@link DevicePolicyManagerService}.
385 *
386 * @hide
387 */
388 public static final String ACTION_REMOTE_BUGREPORT_DISPATCH =
389 "android.intent.action.REMOTE_BUGREPORT_DISPATCH";
390
391 /**
392 * Extra for shared bugreport's SHA-256 hash.
393 *
394 * @hide
395 */
396 public static final String EXTRA_REMOTE_BUGREPORT_HASH =
397 "android.intent.extra.REMOTE_BUGREPORT_HASH";
398
399 /**
400 * Extra for remote bugreport notification shown type.
401 *
402 * @hide
403 */
404 public static final String EXTRA_BUGREPORT_NOTIFICATION_TYPE =
405 "android.app.extra.bugreport_notification_type";
406
407 /**
408 * Notification type for a started remote bugreport flow.
409 *
410 * @hide
411 */
412 public static final int NOTIFICATION_BUGREPORT_STARTED = 1;
413
414 /**
415 * Notification type for a bugreport that has already been accepted to be shared, but is still
416 * being taken.
417 *
418 * @hide
419 */
420 public static final int NOTIFICATION_BUGREPORT_ACCEPTED_NOT_FINISHED = 2;
421
422 /**
423 * Notification type for a bugreport that has been taken and can be shared or declined.
424 *
425 * @hide
426 */
427 public static final int NOTIFICATION_BUGREPORT_FINISHED_NOT_ACCEPTED = 3;
428
429 /**
Michal Karpinski8f010dd2016-06-21 15:05:53 +0100430 * Default and maximum timeout in milliseconds after which unlocking with weak auth times out,
431 * i.e. the user has to use a strong authentication method like password, PIN or pattern.
432 *
433 * @hide
434 */
435 public static final long DEFAULT_STRONG_AUTH_TIMEOUT_MS = 72 * 60 * 60 * 1000; // 72h
436
437 /**
Rubin Xua4f9dc12015-06-12 13:27:59 +0100438 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100439 * allows a mobile device management application or NFC programmer application which starts
440 * managed provisioning to pass data to the management application instance after provisioning.
Rubin Xua4f9dc12015-06-12 13:27:59 +0100441 * <p>
442 * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that
443 * sends the intent to pass data to itself on the newly created profile.
444 * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same
445 * instance of the app on the primary user.
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100446 * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with
447 * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC
448 * message should contain a stringified {@link java.util.Properties} instance, whose string
449 * properties will be converted into a {@link android.os.PersistableBundle} and passed to the
450 * management application after provisioning.
451 *
Rubin Xua4f9dc12015-06-12 13:27:59 +0100452 * <p>
453 * In both cases the application receives the data in
Brian Carlstromf1fe51b2014-09-03 08:55:05 -0700454 * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action
455 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed
Rubin Xua4f9dc12015-06-12 13:27:59 +0100456 * during the managed provisioning.
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100457 */
458 public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE =
Esteban Talavera37f01842014-09-05 10:50:57 +0100459 "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE";
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100460
461 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100462 * A String extra holding the package name of the mobile device management application that
463 * will be set as the profile owner or device owner.
464 *
465 * <p>If an application starts provisioning directly via an intent with action
466 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
467 * application that started provisioning. The package will be set as profile owner in that case.
468 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000469 * <p>This package is set as device owner when device owner provisioning is started by an NFC
470 * message containing an NFC record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000471 *
472 * <p> When this extra is set, the application must have exactly one device admin receiver.
Robin Lee25e26452015-06-02 09:56:29 -0700473 * This receiver will be set as the profile or device owner and active admin.
Benjamin Franzea956242016-03-21 15:45:56 +0000474 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000475 * @see DeviceAdminReceiver
476 * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still
Nicolas Prevot8f78d6a2015-08-21 11:06:31 +0100477 * supported, but only if there is only one device admin receiver in the package that requires
478 * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000479 */
Nicolas Prevot18440252015-03-09 14:07:17 +0000480 @Deprecated
Jessica Hummelf72078b2014-03-06 16:13:12 +0000481 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100482 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000483
484 /**
Nicolas Prevot18440252015-03-09 14:07:17 +0000485 * A ComponentName extra indicating the device admin receiver of the mobile device management
486 * application that will be set as the profile owner or device owner and active admin.
487 *
488 * <p>If an application starts provisioning directly via an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100489 * {@link #ACTION_PROVISION_MANAGED_PROFILE} or
490 * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this
491 * component has to match the package name of the application that started provisioning.
Nicolas Prevot18440252015-03-09 14:07:17 +0000492 *
493 * <p>This component is set as device owner and active admin when device owner provisioning is
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100494 * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC
495 * message containing an NFC record with MIME type
Benjamin Franzea956242016-03-21 15:45:56 +0000496 * {@link #MIME_TYPE_PROVISIONING_NFC}. For the NFC record, the component name must be
Rubin Xu44ef750b2015-03-23 16:51:33 +0000497 * flattened to a string, via {@link ComponentName#flattenToShortString()}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000498 *
499 * @see DeviceAdminReceiver
500 */
501 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME
502 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME";
503
504 /**
Alexandra Gherghinaaaf2f3e2014-11-13 12:46:15 +0000505 * An {@link android.accounts.Account} extra holding the account to migrate during managed
506 * profile provisioning. If the account supplied is present in the primary user, it will be
507 * copied, along with its credentials to the managed profile and removed from the primary user.
508 *
509 * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}.
510 */
511
512 public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE
513 = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE";
514
515 /**
Jessica Hummele3da7902014-08-20 15:20:11 +0100516 * A String extra that, holds the email address of the account which a managed profile is
517 * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
518 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100519 *
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100520 * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}.
521 *
Jessica Hummele3da7902014-08-20 15:20:11 +0100522 * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning
523 * contains this extra, it is forwarded in the
524 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile
525 * device management application that was set as the profile owner during provisioning.
526 * It is usually used to avoid that the user has to enter their email address twice.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100527 */
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100528 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
529 = "android.app.extra.PROVISIONING_EMAIL_ADDRESS";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100530
531 /**
Nicolas Prevotcd2d8592015-11-23 13:27:21 +0000532 * A integer extra indicating the predominant color to show during the provisioning.
533 * Refer to {@link android.graphics.Color} for how the color is represented.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000534 *
535 * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or
536 * {@link #ACTION_PROVISION_MANAGED_DEVICE}.
537 */
538 public static final String EXTRA_PROVISIONING_MAIN_COLOR =
539 "android.app.extra.PROVISIONING_MAIN_COLOR";
540
541 /**
Sander Alewijnse8c411562014-11-12 18:03:11 +0000542 * A Boolean extra that can be used by the mobile device management application to skip the
Robin Lee25e26452015-06-02 09:56:29 -0700543 * disabling of system apps during provisioning when set to {@code true}.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000544 *
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100545 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
546 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000547 */
Sander Alewijnse5a144252014-11-18 13:25:04 +0000548 public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED =
549 "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED";
Sander Alewijnse8c411562014-11-12 18:03:11 +0000550
551 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100552 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
553 * will be set to.
554 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000555 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
556 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100557 */
558 public static final String EXTRA_PROVISIONING_TIME_ZONE
Esteban Talavera37f01842014-09-05 10:50:57 +0100559 = "android.app.extra.PROVISIONING_TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100560
561 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100562 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
563 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100564 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000565 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
566 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100567 */
568 public static final String EXTRA_PROVISIONING_LOCAL_TIME
Esteban Talavera37f01842014-09-05 10:50:57 +0100569 = "android.app.extra.PROVISIONING_LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100570
571 /**
572 * A String extra holding the {@link java.util.Locale} that the device will be set to.
573 * Format: xx_yy, where xx is the language code, and yy the country code.
574 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000575 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
576 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100577 */
578 public static final String EXTRA_PROVISIONING_LOCALE
Esteban Talavera37f01842014-09-05 10:50:57 +0100579 = "android.app.extra.PROVISIONING_LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100580
581 /**
582 * A String extra holding the ssid of the wifi network that should be used during nfc device
583 * owner provisioning for downloading the mobile device management application.
584 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000585 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
586 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100587 */
588 public static final String EXTRA_PROVISIONING_WIFI_SSID
Esteban Talavera37f01842014-09-05 10:50:57 +0100589 = "android.app.extra.PROVISIONING_WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100590
591 /**
592 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
593 * is hidden or not.
594 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000595 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
596 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100597 */
598 public static final String EXTRA_PROVISIONING_WIFI_HIDDEN
Esteban Talavera37f01842014-09-05 10:50:57 +0100599 = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100600
601 /**
602 * A String extra indicating the security type of the wifi network in
Mahaver Chopra76b08a92015-10-08 17:58:45 +0100603 * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or
604 * {@code WEP}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100605 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000606 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
607 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100608 */
609 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
Esteban Talavera37f01842014-09-05 10:50:57 +0100610 = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100611
612 /**
613 * A String extra holding the password of the wifi network in
614 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
615 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000616 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
617 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100618 */
619 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talavera37f01842014-09-05 10:50:57 +0100620 = "android.app.extra.PROVISIONING_WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100621
622 /**
623 * A String extra holding the proxy host for the wifi network in
624 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
625 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000626 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
627 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100628 */
629 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
Esteban Talavera37f01842014-09-05 10:50:57 +0100630 = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100631
632 /**
633 * An int extra holding the proxy port for the wifi network in
634 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
635 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000636 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
637 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100638 */
639 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
Esteban Talavera37f01842014-09-05 10:50:57 +0100640 = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100641
642 /**
643 * A String extra holding the proxy bypass for the wifi network in
644 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
645 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000646 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
647 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100648 */
649 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
Esteban Talavera37f01842014-09-05 10:50:57 +0100650 = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100651
652 /**
653 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
654 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
655 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000656 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
657 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100658 */
659 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
Esteban Talavera37f01842014-09-05 10:50:57 +0100660 = "android.app.extra.PROVISIONING_WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100661
662 /**
663 * A String extra holding a url that specifies the download location of the device admin
664 * package. When not provided it is assumed that the device admin package is already installed.
665 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000666 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
667 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100668 */
669 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talavera37f01842014-09-05 10:50:57 +0100670 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100671
672 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400673 * An int extra holding a minimum required version code for the device admin package. If the
674 * device admin is already installed on the device, it will only be re-downloaded from
675 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the
676 * installed package is less than this version code.
677 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400678 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400679 * provisioning via an NFC bump.
680 */
681 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE
682 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE";
683
684 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100685 * A String extra holding a http cookie header which should be used in the http request to the
686 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
687 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000688 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
689 * provisioning via an NFC bump.
Sander Alewijnse681bce92014-07-24 16:46:26 +0100690 */
691 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talavera37f01842014-09-05 10:50:57 +0100692 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100693
694 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100695 * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of
696 * the file at download location specified in
697 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100698 *
Benjamin Franzea956242016-03-21 15:45:56 +0000699 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} must be
700 * present. The provided checksum must match the checksum of the file at the download
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100701 * location. If the checksum doesn't match an error will be shown to the user and the user will
702 * be asked to factory reset the device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100703 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000704 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
705 * provisioning via an NFC bump.
Rubin Xud92e7572015-05-18 17:01:13 +0100706 *
707 * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP}
708 * and {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1} only SHA-1 hash is supported.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700709 * Starting from {@link android.os.Build.VERSION_CODES#M}, this parameter accepts SHA-256 in
Rubin Xud92e7572015-05-18 17:01:13 +0100710 * addition to SHA-1. Support for SHA-1 is likely to be removed in future OS releases.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100711 */
712 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100713 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100714
715 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100716 * A String extra holding the URL-safe base64 encoded SHA-256 checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100717 * android package archive at the download location specified in {@link
718 * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
719 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100720 * <p>The signatures of an android package archive can be obtained using
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100721 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
722 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
723 *
Benjamin Franzea956242016-03-21 15:45:56 +0000724 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} must be
725 * present. The provided checksum must match the checksum of any signature of the file at
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100726 * the download location. If the checksum does not match an error will be shown to the user and
727 * the user will be asked to factory reset the device.
728 *
729 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
730 * provisioning via an NFC bump.
731 */
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100732 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM
733 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM";
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100734
735 /**
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000736 * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile
737 * has completed successfully.
738 *
739 * <p>The broadcast is limited to the primary profile, to the app specified in the provisioning
Nicolas Prevotebe2d992015-05-12 18:14:53 -0700740 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000741 *
Ying Wang7f38aab2015-02-20 11:50:09 -0800742 * <p>This intent will contain the extra {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE} which
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000743 * corresponds to the account requested to be migrated at provisioning time, if any.
744 */
745 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
746 public static final String ACTION_MANAGED_PROFILE_PROVISIONED
747 = "android.app.action.MANAGED_PROFILE_PROVISIONED";
748
749 /**
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000750 * Activity action: This activity action is sent to indicate that provisioning of a managed
751 * profile or managed device has completed successfully. It'll be sent at the same time as
752 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast but this will be
753 * delivered faster as it's an activity intent.
754 *
755 * <p>The intent is only sent to the application on the profile that requested provisioning. In
756 * the device owner case the profile is the primary user.
757 *
758 * @see #ACTION_PROVISION_MANAGED_PROFILE
759 * @see #ACTION_PROVISION_MANAGED_DEVICE
760 */
761 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
762 public static final String ACTION_PROVISIONING_SUCCESSFUL =
763 "android.app.action.PROVISIONING_SUCCESSFUL";
764
765 /**
Benjamin Franzea956242016-03-21 15:45:56 +0000766 * A boolean extra indicating whether device encryption can be skipped as part of device owner
767 * or managed profile provisioning.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500768 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400769 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100770 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Benjamin Franzea956242016-03-21 15:45:56 +0000771 *
772 * <p>From {@link android.os.Build.VERSION_CODES#N} onwards, this is also supported for an
773 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500774 */
775 public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION =
776 "android.app.extra.PROVISIONING_SKIP_ENCRYPTION";
777
778 /**
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000779 * A {@link Uri} extra pointing to a logo image. This image will be shown during the
780 * provisioning. If this extra is not passed, a default image will be shown.
781 * <h5>The following URI schemes are accepted:</h5>
782 * <ul>
783 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
784 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
785 * </ul>
786 *
787 * <p> It is the responsability of the caller to provide an image with a reasonable
788 * pixed density for the device.
789 *
790 * <p> If a content: URI is passed, the intent should have the flag
791 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
792 * {@link android.content.ClipData} of the intent too.
793 *
794 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or
795 * {@link #ACTION_PROVISION_MANAGED_DEVICE}
796 */
797 public static final String EXTRA_PROVISIONING_LOGO_URI =
798 "android.app.extra.PROVISIONING_LOGO_URI";
799
800 /**
Alan Treadway94de8c82016-01-11 10:25:23 +0000801 * A boolean extra indicating if user setup should be skipped, for when provisioning is started
802 * during setup-wizard.
803 *
804 * <p>If unspecified, defaults to {@code true} to match the behavior in
805 * {@link android.os.Build.VERSION_CODES#M} and earlier.
806 *
Alan Treadway1a538d02016-01-18 16:42:30 +0000807 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or
808 * {@link #ACTION_PROVISION_MANAGED_USER}.
Alan Treadway94de8c82016-01-11 10:25:23 +0000809 *
810 * @hide
811 */
812 public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP =
813 "android.app.extra.PROVISIONING_SKIP_USER_SETUP";
814
815 /**
Victor Chang51d84f92016-11-16 12:22:56 +0000816 * A boolean extra indicating if the user consent steps from the provisioning flow should be
817 * skipped. If unspecified, defaults to {@code false}.
818 *
819 * It can only be used by an existing device owner trying to create a managed profile via
820 * {@link #ACTION_PROVISION_MANAGED_PROFILE}. Otherwise it is ignored.
821 */
822 public static final String EXTRA_PROVISIONING_SKIP_USER_CONSENT =
823 "android.app.extra.PROVISIONING_SKIP_USER_CONSENT";
824
825 /**
Benjamin Franzea956242016-03-21 15:45:56 +0000826 * This MIME type is used for starting the device owner provisioning.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100827 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400828 * <p>During device owner provisioning a device admin app is set as the owner of the device.
829 * A device owner has full control over the device. The device owner can not be modified by the
830 * user and the only way of resetting the device is if the device owner app calls a factory
831 * reset.
832 *
833 * <p> A typical use case would be a device that is owned by a company, but used by either an
834 * employee or client.
835 *
Benjamin Franzea956242016-03-21 15:45:56 +0000836 * <p> The NFC message must be sent to an unprovisioned device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100837 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000838 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100839 * contains the following properties:
840 * <ul>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400841 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
842 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100843 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400844 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100845 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
846 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
847 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
848 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
849 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
850 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
851 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
852 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
853 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
854 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100855 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
856 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from
857 * {@link android.os.Build.VERSION_CODES#M} </li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100858 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000859 * <p>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700860 * As of {@link android.os.Build.VERSION_CODES#M}, the properties should contain
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400861 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of
862 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only
863 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400864 */
865 public static final String MIME_TYPE_PROVISIONING_NFC
866 = "application/com.android.managedprovisioning";
867
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100868 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800869 * Activity action: ask the user to add a new device administrator to the system.
870 * The desired policy is the ComponentName of the policy in the
871 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
872 * bring the user through adding the device administrator to the system (or
873 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700874 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800875 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
876 * field to provide the user with additional explanation (in addition
877 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800878 *
879 * <p>If your administrator is already active, this will ordinarily return immediately (without
880 * user intervention). However, if your administrator has been updated and is requesting
881 * additional uses-policy flags, the user will be presented with the new list. New policies
882 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800883 */
884 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
885 public static final String ACTION_ADD_DEVICE_ADMIN
886 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700887
Dianne Hackbornd6847842010-01-12 18:14:19 -0800888 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700889 * @hide
890 * Activity action: ask the user to add a new device administrator as the profile owner
Amith Yamasani814e9872015-03-23 14:04:53 -0700891 * for this user. Only system apps can launch this intent.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700892 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700893 * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN}
894 * extra field. This will invoke a UI to bring the user through adding the profile owner admin
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700895 * to remotely control restrictions on the user.
896 *
Makoto Onukic8a5a552015-11-19 14:29:12 -0800897 * <p>The intent must be invoked via {@link Activity#startActivityForResult} to receive the
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700898 * result of whether or not the user approved the action. If approved, the result will
899 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
900 * as a profile owner.
901 *
902 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
903 * field to provide the user with additional explanation (in addition
904 * to your component's description) about what is being added.
905 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700906 * <p>If there is already a profile owner active or the caller is not a system app, the
907 * operation will return a failure result.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700908 */
909 @SystemApi
910 public static final String ACTION_SET_PROFILE_OWNER
911 = "android.app.action.SET_PROFILE_OWNER";
912
913 /**
914 * @hide
915 * Name of the profile owner admin that controls the user.
916 */
917 @SystemApi
918 public static final String EXTRA_PROFILE_OWNER_NAME
919 = "android.app.extra.PROFILE_OWNER_NAME";
920
921 /**
Nicolas Prevot00799002015-07-27 18:15:20 +0100922 * Broadcast action: send when any policy admin changes a policy.
Jim Miller284b62e2010-06-08 14:27:42 -0700923 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700924 *
Jim Miller284b62e2010-06-08 14:27:42 -0700925 * @hide
926 */
927 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
928 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
929
930 /**
Tony Mak1970f972016-08-30 17:41:48 +0100931 * Broadcast action: sent when the device owner is set, changed or cleared.
Nicolas Prevot00799002015-07-27 18:15:20 +0100932 *
933 * This broadcast is sent only to the primary user.
934 * @see #ACTION_PROVISION_MANAGED_DEVICE
935 */
936 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
937 public static final String ACTION_DEVICE_OWNER_CHANGED
938 = "android.app.action.DEVICE_OWNER_CHANGED";
939
940 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800941 * The ComponentName of the administrator component.
942 *
943 * @see #ACTION_ADD_DEVICE_ADMIN
944 */
945 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700946
Dianne Hackbornd6847842010-01-12 18:14:19 -0800947 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800948 * An optional CharSequence providing additional explanation for why the
949 * admin is being added.
950 *
951 * @see #ACTION_ADD_DEVICE_ADMIN
952 */
953 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700954
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800955 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700956 * Activity action: have the user enter a new password. This activity should
957 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
958 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
959 * enter a new password that meets the current requirements. You can use
960 * {@link #isActivePasswordSufficient()} to determine whether you need to
961 * have the user select a new password in order to meet the current
962 * constraints. Upon being resumed from this activity, you can check the new
963 * password characteristics to see if they are sufficient.
Benjamin Franzc9921092016-01-08 17:17:44 +0000964 *
965 * If the intent is launched from within a managed profile with a profile
966 * owner built against {@link android.os.Build.VERSION_CODES#M} or before,
967 * this will trigger entering a new password for the parent of the profile.
968 * For all other cases it will trigger entering a new password for the user
969 * or profile it is launched from.
Esteban Talaverac1c83592016-02-17 17:56:15 +0000970 *
971 * @see #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
Dianne Hackbornd6847842010-01-12 18:14:19 -0800972 */
973 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
974 public static final String ACTION_SET_NEW_PASSWORD
975 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700976
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000977 /**
Benjamin Franzc9921092016-01-08 17:17:44 +0000978 * Activity action: have the user enter a new password for the parent profile.
979 * If the intent is launched from within a managed profile, this will trigger
980 * entering a new password for the parent of the profile. In all other cases
981 * the behaviour is identical to {@link #ACTION_SET_NEW_PASSWORD}.
982 */
983 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
984 public static final String ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
985 = "android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD";
986
987 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000988 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
989 * the parent profile to access intents sent from the managed profile.
990 * That is, when an app in the managed profile calls
991 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
992 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000993 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100994 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000995
996 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000997 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
998 * the managed profile to access intents sent from the parent profile.
999 * That is, when an app in the parent profile calls
1000 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
1001 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001002 */
Nicolas Prevot86a96732014-09-08 12:13:05 +01001003 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001004
Dianne Hackbornd6847842010-01-12 18:14:19 -08001005 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01001006 * Broadcast action: notify that a new local system update policy has been set by the device
1007 * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00001008 */
1009 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Rubin Xu5faad8e2015-04-20 17:43:48 +01001010 public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED
1011 = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED";
Rubin Xu8027a4f2015-03-10 17:52:37 +00001012
Amith Yamasanid49489b2015-04-28 14:00:26 -07001013 /**
1014 * Permission policy to prompt user for new permission requests for runtime permissions.
1015 * Already granted or denied permissions are not affected by this.
1016 */
1017 public static final int PERMISSION_POLICY_PROMPT = 0;
1018
1019 /**
1020 * Permission policy to always grant new permission requests for runtime permissions.
1021 * Already granted or denied permissions are not affected by this.
1022 */
1023 public static final int PERMISSION_POLICY_AUTO_GRANT = 1;
1024
1025 /**
1026 * Permission policy to always deny new permission requests for runtime permissions.
1027 * Already granted or denied permissions are not affected by this.
1028 */
1029 public static final int PERMISSION_POLICY_AUTO_DENY = 2;
1030
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07001031 /**
1032 * Runtime permission state: The user can manage the permission
1033 * through the UI.
1034 */
1035 public static final int PERMISSION_GRANT_STATE_DEFAULT = 0;
1036
1037 /**
1038 * Runtime permission state: The permission is granted to the app
1039 * and the user cannot manage the permission through the UI.
1040 */
1041 public static final int PERMISSION_GRANT_STATE_GRANTED = 1;
1042
1043 /**
1044 * Runtime permission state: The permission is denied to the app
1045 * and the user cannot manage the permission through the UI.
1046 */
1047 public static final int PERMISSION_GRANT_STATE_DENIED = 2;
Rubin Xu8027a4f2015-03-10 17:52:37 +00001048
1049 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00001050 * No management for current user in-effect. This is the default.
1051 * @hide
1052 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001053 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001054 public static final int STATE_USER_UNMANAGED = 0;
1055
1056 /**
1057 * Management partially setup, user setup needs to be completed.
1058 * @hide
1059 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001060 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001061 public static final int STATE_USER_SETUP_INCOMPLETE = 1;
1062
1063 /**
1064 * Management partially setup, user setup completed.
1065 * @hide
1066 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001067 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001068 public static final int STATE_USER_SETUP_COMPLETE = 2;
1069
1070 /**
1071 * Management setup and active on current user.
1072 * @hide
1073 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001074 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001075 public static final int STATE_USER_SETUP_FINALIZED = 3;
1076
1077 /**
1078 * Management partially setup on a managed profile.
1079 * @hide
1080 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001081 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001082 public static final int STATE_USER_PROFILE_COMPLETE = 4;
1083
1084 /**
1085 * @hide
1086 */
1087 @IntDef({STATE_USER_UNMANAGED, STATE_USER_SETUP_INCOMPLETE, STATE_USER_SETUP_COMPLETE,
1088 STATE_USER_SETUP_FINALIZED, STATE_USER_PROFILE_COMPLETE})
1089 @Retention(RetentionPolicy.SOURCE)
1090 public @interface UserProvisioningState {}
1091
1092 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001093 * Return true if the given administrator component is currently active (enabled) in the system.
1094 *
1095 * @param admin The administrator component to check for.
1096 * @return {@code true} if {@code admin} is currently enabled in the system, {@code false}
1097 * otherwise
Dianne Hackbornd6847842010-01-12 18:14:19 -08001098 */
Robin Lee25e26452015-06-02 09:56:29 -07001099 public boolean isAdminActive(@NonNull ComponentName admin) {
Charles He8c760562016-10-25 16:36:53 +01001100 throwIfParentInstance("isAdminActive");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001101 return isAdminActiveAsUser(admin, myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001102 }
1103
1104 /**
1105 * @see #isAdminActive(ComponentName)
1106 * @hide
1107 */
Robin Lee25e26452015-06-02 09:56:29 -07001108 public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001109 if (mService != null) {
1110 try {
Robin Lee25e26452015-06-02 09:56:29 -07001111 return mService.isAdminActive(admin, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001112 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001113 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001114 }
1115 }
1116 return false;
1117 }
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001118 /**
1119 * Return true if the given administrator component is currently being removed
1120 * for the user.
1121 * @hide
1122 */
Robin Lee25e26452015-06-02 09:56:29 -07001123 public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) {
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001124 if (mService != null) {
1125 try {
Robin Lee25e26452015-06-02 09:56:29 -07001126 return mService.isRemovingAdmin(admin, userId);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001127 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001128 throw e.rethrowFromSystemServer();
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001129 }
1130 }
1131 return false;
1132 }
1133
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001134
Dianne Hackbornd6847842010-01-12 18:14:19 -08001135 /**
Robin Lee25e26452015-06-02 09:56:29 -07001136 * Return a list of all currently active device administrators' component
1137 * names. If there are no administrators {@code null} may be
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001138 * returned.
1139 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07001140 public @Nullable List<ComponentName> getActiveAdmins() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001141 throwIfParentInstance("getActiveAdmins");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001142 return getActiveAdminsAsUser(myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001143 }
1144
1145 /**
1146 * @see #getActiveAdmins()
1147 * @hide
1148 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07001149 public @Nullable List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001150 if (mService != null) {
1151 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001152 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001153 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001154 throw e.rethrowFromSystemServer();
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001155 }
1156 }
1157 return null;
1158 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001159
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001160 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001161 * Used by package administration code to determine if a package can be stopped
1162 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001163 * @hide
1164 */
1165 public boolean packageHasActiveAdmins(String packageName) {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001166 return packageHasActiveAdmins(packageName, myUserId());
1167 }
1168
1169 /**
1170 * Used by package administration code to determine if a package can be stopped
1171 * or uninstalled.
1172 * @hide
1173 */
1174 public boolean packageHasActiveAdmins(String packageName, int userId) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001175 if (mService != null) {
1176 try {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001177 return mService.packageHasActiveAdmins(packageName, userId);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001178 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001179 throw e.rethrowFromSystemServer();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001180 }
1181 }
1182 return false;
1183 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001184
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001185 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001186 * Remove a current administration component. This can only be called
1187 * by the application that owns the administration component; if you
1188 * try to remove someone else's component, a security exception will be
1189 * thrown.
Esteban Talavera552a5612016-02-19 17:02:24 +00001190 *
1191 * <p>Note that the operation is not synchronous and the admin might still be active (as
1192 * indicated by {@link #getActiveAdmins()}) by the time this method returns.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001193 *
1194 * @param admin The administration compononent to remove.
1195 * @throws SecurityException if the caller is not in the owner application of {@code admin}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001196 */
Robin Lee25e26452015-06-02 09:56:29 -07001197 public void removeActiveAdmin(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001198 throwIfParentInstance("removeActiveAdmin");
Dianne Hackbornd6847842010-01-12 18:14:19 -08001199 if (mService != null) {
1200 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001201 mService.removeActiveAdmin(admin, myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001202 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001203 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001204 }
1205 }
1206 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001207
Dianne Hackbornd6847842010-01-12 18:14:19 -08001208 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001209 * Returns true if an administrator has been granted a particular device policy. This can be
1210 * used to check whether the administrator was activated under an earlier set of policies, but
1211 * requires additional policies after an upgrade.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001212 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001213 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be an
1214 * active administrator, or an exception will be thrown.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001215 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001216 * @throws SecurityException if {@code admin} is not an active administrator.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001217 */
Robin Lee25e26452015-06-02 09:56:29 -07001218 public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001219 throwIfParentInstance("hasGrantedPolicy");
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001220 if (mService != null) {
1221 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001222 return mService.hasGrantedPolicy(admin, usesPolicy, myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001223 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001224 throw e.rethrowFromSystemServer();
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001225 }
1226 }
1227 return false;
1228 }
1229
1230 /**
Clara Bayarria1771112015-12-18 16:29:18 +00001231 * Returns true if the Profile Challenge is available to use for the given profile user.
1232 *
1233 * @hide
1234 */
1235 public boolean isSeparateProfileChallengeAllowed(int userHandle) {
1236 if (mService != null) {
1237 try {
1238 return mService.isSeparateProfileChallengeAllowed(userHandle);
1239 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001240 throw e.rethrowFromSystemServer();
Clara Bayarria1771112015-12-18 16:29:18 +00001241 }
1242 }
1243 return false;
1244 }
1245
1246 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001247 * Constant for {@link #setPasswordQuality}: the policy has no requirements
1248 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001249 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001250 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001251 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001252
Dianne Hackbornd6847842010-01-12 18:14:19 -08001253 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -07001254 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
1255 * recognition technology. This implies technologies that can recognize the identity of
1256 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
1257 * Note that quality constants are ordered so that higher values are more restrictive.
1258 */
1259 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
1260
1261 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001262 * Constant for {@link #setPasswordQuality}: the policy requires some kind
Benjamin Franzc6a96532015-06-16 11:23:38 +01001263 * of password or pattern, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001264 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001265 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001266 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001267
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001268 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001269 * Constant for {@link #setPasswordQuality}: the user must have entered a
1270 * password containing at least numeric characters. Note that quality
1271 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001272 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001273 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001274
Dianne Hackbornd6847842010-01-12 18:14:19 -08001275 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001276 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -08001277 * password containing at least numeric characters with no repeating (4444)
1278 * or ordered (1234, 4321, 2468) sequences. Note that quality
1279 * constants are ordered so that higher values are more restrictive.
1280 */
1281 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
1282
1283 /**
1284 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001285 * password containing at least alphabetic (or other symbol) characters.
1286 * Note that quality constants are ordered so that higher values are more
1287 * restrictive.
1288 */
1289 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001290
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001291 /**
1292 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001293 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001294 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001295 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001296 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001297 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001298
Dianne Hackbornd6847842010-01-12 18:14:19 -08001299 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001300 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001301 * password containing at least a letter, a numerical digit and a special
1302 * symbol, by default. With this password quality, passwords can be
1303 * restricted to contain various sets of characters, like at least an
1304 * uppercase letter, etc. These are specified using various methods,
1305 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
1306 * that quality constants are ordered so that higher values are more
1307 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001308 */
1309 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
1310
1311 /**
Oleksandr Peletskyi0fdcd3d2016-01-13 16:49:56 +01001312 * Constant for {@link #setPasswordQuality}: the user is not allowed to
1313 * modify password. In case this password quality is set, the password is
1314 * managed by a profile owner. The profile owner can set any password,
1315 * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note
1316 * that quality constants are ordered so that higher values are more
1317 * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is
1318 * the highest.
1319 * @hide
1320 */
1321 public static final int PASSWORD_QUALITY_MANAGED = 0x80000;
1322
1323 /**
Makoto Onuki5e7e06702016-09-01 18:02:01 -07001324 * @hide
1325 *
1326 * adb shell dpm set-{device,profile}-owner will normally not allow installing an owner to
1327 * a user with accounts. {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED}
1328 * and {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} are the account features
1329 * used by authenticator to exempt their accounts from this:
1330 *
1331 * <ul>
1332 * <li>Non-test-only DO/PO still can't be installed when there are accounts.
1333 * <p>In order to make an apk test-only, add android:testOnly="true" to the
1334 * &lt;application&gt; tag in the manifest.
1335 *
1336 * <li>Test-only DO/PO can be installed even when there are accounts, as long as all the
1337 * accounts have the {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} feature.
1338 * Some authenticators claim to have any features, so to detect it, we also check
1339 * {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} and disallow installing
1340 * if any of the accounts have it.
1341 * </ul>
1342 */
1343 public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED =
1344 "android.account.DEVICE_OR_PROFILE_OWNER_ALLOWED";
1345
1346 /** @hide See {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} */
1347 public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED =
1348 "android.account.DEVICE_OR_PROFILE_OWNER_DISALLOWED";
1349
1350 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001351 * Called by an application that is administering the device to set the password restrictions it
1352 * is imposing. After setting this, the user will not be able to enter a new password that is
1353 * not at least as restrictive as what has been set. Note that the current password will remain
1354 * until the user has set a new one, so the change does not take place immediately. To prompt
1355 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
Esteban Talaverac1c83592016-02-17 17:56:15 +00001356 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after calling this method.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001357 * <p>
1358 * Quality constants are ordered so that higher values are more restrictive; thus the highest
1359 * requested quality constant (between the policy set here, the user's preference, and any other
1360 * considerations) is the one that is in effect.
1361 * <p>
1362 * The calling device admin must have requested
1363 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1364 * not, a security exception will be thrown.
1365 * <p>
1366 * This method can be called on the {@link DevicePolicyManager} instance returned by
1367 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1368 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001369 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001370 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001371 * @param quality The new desired quality. One of {@link #PASSWORD_QUALITY_UNSPECIFIED},
1372 * {@link #PASSWORD_QUALITY_SOMETHING}, {@link #PASSWORD_QUALITY_NUMERIC},
1373 * {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC},
1374 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} or {@link #PASSWORD_QUALITY_COMPLEX}.
1375 * @throws SecurityException if {@code admin} is not an active administrator or if {@code admin}
1376 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Dianne Hackbornd6847842010-01-12 18:14:19 -08001377 */
Robin Lee25e26452015-06-02 09:56:29 -07001378 public void setPasswordQuality(@NonNull ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001379 if (mService != null) {
1380 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001381 mService.setPasswordQuality(admin, quality, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001382 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001383 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001384 }
1385 }
1386 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001387
Dianne Hackbornd6847842010-01-12 18:14:19 -08001388 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001389 * Retrieve the current minimum password quality for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01001390 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00001391 * a separate challenge are not taken into account.
1392 *
1393 * <p>This method can be called on the {@link DevicePolicyManager} instance
1394 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1395 * restrictions on the parent profile.
1396 *
Robin Lee25e26452015-06-02 09:56:29 -07001397 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001398 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001399 */
Robin Lee25e26452015-06-02 09:56:29 -07001400 public int getPasswordQuality(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001401 return getPasswordQuality(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001402 }
1403
1404 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001405 public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001406 if (mService != null) {
1407 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001408 return mService.getPasswordQuality(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001409 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001410 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001411 }
1412 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001413 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001414 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001415
Dianne Hackbornd6847842010-01-12 18:14:19 -08001416 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001417 * Called by an application that is administering the device to set the minimum allowed password
1418 * length. After setting this, the user will not be able to enter a new password that is not at
1419 * least as restrictive as what has been set. Note that the current password will remain until
1420 * the user has set a new one, so the change does not take place immediately. To prompt the user
1421 * for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
1422 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
1423 * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC}
1424 * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC},
1425 * {@link #PASSWORD_QUALITY_ALPHANUMERIC}, or {@link #PASSWORD_QUALITY_COMPLEX} with
1426 * {@link #setPasswordQuality}.
1427 * <p>
1428 * The calling device admin must have requested
1429 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1430 * not, a security exception will be thrown.
1431 * <p>
1432 * This method can be called on the {@link DevicePolicyManager} instance returned by
1433 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1434 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001435 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001436 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001437 * @param length The new desired minimum password length. A value of 0 means there is no
1438 * restriction.
1439 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1440 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Dianne Hackbornd6847842010-01-12 18:14:19 -08001441 */
Robin Lee25e26452015-06-02 09:56:29 -07001442 public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001443 if (mService != null) {
1444 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001445 mService.setPasswordMinimumLength(admin, length, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001446 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001447 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001448 }
1449 }
1450 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001451
Dianne Hackbornd6847842010-01-12 18:14:19 -08001452 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001453 * Retrieve the current minimum password length for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01001454 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00001455 * a separate challenge are not taken into account.
1456 *
1457 * <p>This method can be called on the {@link DevicePolicyManager} instance
1458 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1459 * restrictions on the parent profile.
1460 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001461 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001462 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001463 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001464 */
Robin Lee25e26452015-06-02 09:56:29 -07001465 public int getPasswordMinimumLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001466 return getPasswordMinimumLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001467 }
1468
1469 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001470 public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001471 if (mService != null) {
1472 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001473 return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001474 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001475 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001476 }
1477 }
1478 return 0;
1479 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001480
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001481 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001482 * Called by an application that is administering the device to set the minimum number of upper
1483 * case letters required in the password. After setting this, the user will not be able to enter
1484 * a new password that is not at least as restrictive as what has been set. Note that the
1485 * current password will remain until the user has set a new one, so the change does not take
1486 * place immediately. To prompt the user for a new password, use
1487 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
1488 * setting this value. This constraint is only imposed if the administrator has also requested
1489 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001490 * <p>
1491 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001492 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1493 * not, a security exception will be thrown.
1494 * <p>
1495 * This method can be called on the {@link DevicePolicyManager} instance returned by
1496 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1497 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001498 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001499 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1500 * @param length The new desired minimum number of upper case letters required in the password.
1501 * A value of 0 means there is no restriction.
1502 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1503 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001504 */
Robin Lee25e26452015-06-02 09:56:29 -07001505 public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001506 if (mService != null) {
1507 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001508 mService.setPasswordMinimumUpperCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001509 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001510 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001511 }
1512 }
1513 }
1514
1515 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001516 * Retrieve the current number of upper case letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01001517 * for a particular admin or all admins that set restrictions on this user and
Esteban Talaverac1c83592016-02-17 17:56:15 +00001518 * its participating profiles. Restrictions on profiles that have a separate challenge
1519 * are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001520 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001521 * {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001522 * and only applies when the password quality is
1523 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001524 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001525 * <p>This method can be called on the {@link DevicePolicyManager} instance
1526 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1527 * restrictions on the parent profile.
1528 *
Robin Lee25e26452015-06-02 09:56:29 -07001529 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001530 * aggregate all admins.
1531 * @return The minimum number of upper case letters required in the
1532 * password.
1533 */
Robin Lee25e26452015-06-02 09:56:29 -07001534 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001535 return getPasswordMinimumUpperCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001536 }
1537
1538 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001539 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001540 if (mService != null) {
1541 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001542 return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001543 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001544 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001545 }
1546 }
1547 return 0;
1548 }
1549
1550 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001551 * Called by an application that is administering the device to set the minimum number of lower
1552 * case letters required in the password. After setting this, the user will not be able to enter
1553 * a new password that is not at least as restrictive as what has been set. Note that the
1554 * current password will remain until the user has set a new one, so the change does not take
1555 * place immediately. To prompt the user for a new password, use
1556 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
1557 * setting this value. This constraint is only imposed if the administrator has also requested
1558 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001559 * <p>
1560 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001561 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1562 * not, a security exception will be thrown.
1563 * <p>
1564 * This method can be called on the {@link DevicePolicyManager} instance returned by
1565 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1566 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001567 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001568 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1569 * @param length The new desired minimum number of lower case letters required in the password.
1570 * A value of 0 means there is no restriction.
1571 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1572 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001573 */
Robin Lee25e26452015-06-02 09:56:29 -07001574 public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001575 if (mService != null) {
1576 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001577 mService.setPasswordMinimumLowerCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001578 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001579 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001580 }
1581 }
1582 }
1583
1584 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001585 * Retrieve the current number of lower case letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01001586 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00001587 * and its participating profiles. Restrictions on profiles that have
1588 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001589 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001590 * {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001591 * and only applies when the password quality is
1592 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001593 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001594 * <p>This method can be called on the {@link DevicePolicyManager} instance
1595 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1596 * restrictions on the parent profile.
1597 *
Robin Lee25e26452015-06-02 09:56:29 -07001598 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001599 * aggregate all admins.
1600 * @return The minimum number of lower case letters required in the
1601 * password.
1602 */
Robin Lee25e26452015-06-02 09:56:29 -07001603 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001604 return getPasswordMinimumLowerCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001605 }
1606
1607 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001608 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001609 if (mService != null) {
1610 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001611 return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001612 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001613 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001614 }
1615 }
1616 return 0;
1617 }
1618
1619 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001620 * Called by an application that is administering the device to set the minimum number of
1621 * letters required in the password. After setting this, the user will not be able to enter a
1622 * new password that is not at least as restrictive as what has been set. Note that the current
1623 * password will remain until the user has set a new one, so the change does not take place
1624 * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
1625 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
1626 * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1627 * {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001628 * <p>
1629 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001630 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1631 * not, a security exception will be thrown.
1632 * <p>
1633 * This method can be called on the {@link DevicePolicyManager} instance returned by
1634 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1635 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001636 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001637 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1638 * @param length The new desired minimum number of letters required in the password. A value of
1639 * 0 means there is no restriction.
1640 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1641 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001642 */
Robin Lee25e26452015-06-02 09:56:29 -07001643 public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001644 if (mService != null) {
1645 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001646 mService.setPasswordMinimumLetters(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001647 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001648 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001649 }
1650 }
1651 }
1652
1653 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001654 * Retrieve the current number of letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01001655 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00001656 * and its participating profiles. Restrictions on profiles that have
1657 * a separate challenge are not taken into account.
1658 * This is the same value as set by
1659 * {@link #setPasswordMinimumLetters(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001660 * and only applies when the password quality is
1661 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001662 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001663 * <p>This method can be called on the {@link DevicePolicyManager} instance
1664 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1665 * restrictions on the parent profile.
1666 *
Robin Lee25e26452015-06-02 09:56:29 -07001667 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001668 * aggregate all admins.
1669 * @return The minimum number of letters required in the password.
1670 */
Robin Lee25e26452015-06-02 09:56:29 -07001671 public int getPasswordMinimumLetters(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001672 return getPasswordMinimumLetters(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001673 }
1674
1675 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001676 public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001677 if (mService != null) {
1678 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001679 return mService.getPasswordMinimumLetters(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001680 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001681 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001682 }
1683 }
1684 return 0;
1685 }
1686
1687 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001688 * Called by an application that is administering the device to set the minimum number of
1689 * numerical digits required in the password. After setting this, the user will not be able to
1690 * enter a new password that is not at least as restrictive as what has been set. Note that the
1691 * current password will remain until the user has set a new one, so the change does not take
1692 * place immediately. To prompt the user for a new password, use
1693 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
1694 * setting this value. This constraint is only imposed if the administrator has also requested
1695 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001696 * <p>
1697 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001698 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1699 * not, a security exception will be thrown.
1700 * <p>
1701 * This method can be called on the {@link DevicePolicyManager} instance returned by
1702 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1703 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001704 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001705 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1706 * @param length The new desired minimum number of numerical digits required in the password. A
1707 * value of 0 means there is no restriction.
1708 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1709 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001710 */
Robin Lee25e26452015-06-02 09:56:29 -07001711 public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001712 if (mService != null) {
1713 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001714 mService.setPasswordMinimumNumeric(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001715 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001716 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001717 }
1718 }
1719 }
1720
1721 /**
1722 * Retrieve the current number of numerical digits required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01001723 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00001724 * and its participating profiles. Restrictions on profiles that have
1725 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001726 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001727 * {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001728 * and only applies when the password quality is
1729 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001730 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001731 * <p>This method can be called on the {@link DevicePolicyManager} instance
1732 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1733 * restrictions on the parent profile.
1734 *
Robin Lee25e26452015-06-02 09:56:29 -07001735 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001736 * aggregate all admins.
1737 * @return The minimum number of numerical digits required in the password.
1738 */
Robin Lee25e26452015-06-02 09:56:29 -07001739 public int getPasswordMinimumNumeric(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001740 return getPasswordMinimumNumeric(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001741 }
1742
1743 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001744 public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001745 if (mService != null) {
1746 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001747 return mService.getPasswordMinimumNumeric(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001748 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001749 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001750 }
1751 }
1752 return 0;
1753 }
1754
1755 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001756 * Called by an application that is administering the device to set the minimum number of
1757 * symbols required in the password. After setting this, the user will not be able to enter a
1758 * new password that is not at least as restrictive as what has been set. Note that the current
1759 * password will remain until the user has set a new one, so the change does not take place
1760 * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
1761 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
1762 * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1763 * {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001764 * <p>
1765 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001766 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1767 * not, a security exception will be thrown.
1768 * <p>
1769 * This method can be called on the {@link DevicePolicyManager} instance returned by
1770 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1771 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001772 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001773 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1774 * @param length The new desired minimum number of symbols required in the password. A value of
1775 * 0 means there is no restriction.
1776 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1777 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001778 */
Robin Lee25e26452015-06-02 09:56:29 -07001779 public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001780 if (mService != null) {
1781 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001782 mService.setPasswordMinimumSymbols(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001783 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001784 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001785 }
1786 }
1787 }
1788
1789 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001790 * Retrieve the current number of symbols required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01001791 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00001792 * and its participating profiles. Restrictions on profiles that have
1793 * a separate challenge are not taken into account. This is the same value as
1794 * set by {@link #setPasswordMinimumSymbols(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001795 * and only applies when the password quality is
1796 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001797 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001798 * <p>This method can be called on the {@link DevicePolicyManager} instance
1799 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1800 * restrictions on the parent profile.
1801 *
Robin Lee25e26452015-06-02 09:56:29 -07001802 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001803 * aggregate all admins.
1804 * @return The minimum number of symbols required in the password.
1805 */
Robin Lee25e26452015-06-02 09:56:29 -07001806 public int getPasswordMinimumSymbols(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001807 return getPasswordMinimumSymbols(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001808 }
1809
1810 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001811 public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001812 if (mService != null) {
1813 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001814 return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001815 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001816 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001817 }
1818 }
1819 return 0;
1820 }
1821
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001822 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001823 * Called by an application that is administering the device to set the minimum number of
1824 * non-letter characters (numerical digits or symbols) required in the password. After setting
1825 * this, the user will not be able to enter a new password that is not at least as restrictive
1826 * as what has been set. Note that the current password will remain until the user has set a new
1827 * one, so the change does not take place immediately. To prompt the user for a new password,
1828 * use {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
1829 * setting this value. This constraint is only imposed if the administrator has also requested
1830 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001831 * <p>
1832 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001833 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1834 * not, a security exception will be thrown.
1835 * <p>
1836 * This method can be called on the {@link DevicePolicyManager} instance returned by
1837 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1838 * profile.
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001839 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001840 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1841 * @param length The new desired minimum number of letters required in the password. A value of
1842 * 0 means there is no restriction.
1843 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1844 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001845 */
Robin Lee25e26452015-06-02 09:56:29 -07001846 public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001847 if (mService != null) {
1848 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001849 mService.setPasswordMinimumNonLetter(admin, length, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001850 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001851 throw e.rethrowFromSystemServer();
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001852 }
1853 }
1854 }
1855
1856 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001857 * Retrieve the current number of non-letter characters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01001858 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00001859 * and its participating profiles. Restrictions on profiles that have
1860 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001861 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001862 * {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001863 * and only applies when the password quality is
1864 * {@link #PASSWORD_QUALITY_COMPLEX}.
1865 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001866 * <p>This method can be called on the {@link DevicePolicyManager} instance
1867 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1868 * restrictions on the parent profile.
1869 *
Robin Lee25e26452015-06-02 09:56:29 -07001870 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001871 * aggregate all admins.
1872 * @return The minimum number of letters required in the password.
1873 */
Robin Lee25e26452015-06-02 09:56:29 -07001874 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001875 return getPasswordMinimumNonLetter(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001876 }
1877
1878 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001879 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001880 if (mService != null) {
1881 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001882 return mService.getPasswordMinimumNonLetter(admin, userHandle, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001883 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001884 throw e.rethrowFromSystemServer();
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001885 }
1886 }
1887 return 0;
1888 }
1889
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001890 /**
1891 * Called by an application that is administering the device to set the length of the password
1892 * history. After setting this, the user will not be able to enter a new password that is the
1893 * same as any password in the history. Note that the current password will remain until the
1894 * user has set a new one, so the change does not take place immediately. To prompt the user for
1895 * a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
1896 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
1897 * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC}
1898 * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX} {@link #PASSWORD_QUALITY_ALPHABETIC}, or
1899 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} with {@link #setPasswordQuality}.
1900 * <p>
1901 * The calling device admin must have requested
1902 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1903 * not, a security exception will be thrown.
1904 * <p>
1905 * This method can be called on the {@link DevicePolicyManager} instance returned by
1906 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1907 * profile.
1908 *
1909 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1910 * @param length The new desired length of password history. A value of 0 means there is no
1911 * restriction.
1912 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1913 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
1914 */
Robin Lee25e26452015-06-02 09:56:29 -07001915 public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001916 if (mService != null) {
1917 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001918 mService.setPasswordHistoryLength(admin, length, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001919 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001920 throw e.rethrowFromSystemServer();
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001921 }
1922 }
1923 }
1924
1925 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001926 * Called by a device admin to set the password expiration timeout. Calling this method will
1927 * restart the countdown for password expiration for the given admin, as will changing the
1928 * device password (for all admins).
1929 * <p>
1930 * The provided timeout is the time delta in ms and will be added to the current time. For
1931 * example, to have the password expire 5 days from now, timeout would be 5 * 86400 * 1000 =
1932 * 432000000 ms for timeout.
1933 * <p>
1934 * To disable password expiration, a value of 0 may be used for timeout.
1935 * <p>
1936 * The calling device admin must have requested
1937 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this method; if it has
1938 * not, a security exception will be thrown.
1939 * <p>
1940 * Note that setting the password will automatically reset the expiration time for all active
1941 * admins. Active admins do not need to explicitly call this method in that case.
1942 * <p>
1943 * This method can be called on the {@link DevicePolicyManager} instance returned by
1944 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1945 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001946 *
Jim Millera4e28d12010-11-08 16:15:47 -08001947 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001948 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0 means
1949 * there is no restriction (unlimited).
1950 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1951 * does not use {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD}
Jim Millera4e28d12010-11-08 16:15:47 -08001952 */
Robin Lee25e26452015-06-02 09:56:29 -07001953 public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) {
Jim Millera4e28d12010-11-08 16:15:47 -08001954 if (mService != null) {
1955 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001956 mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08001957 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001958 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08001959 }
1960 }
1961 }
1962
1963 /**
Jim Miller6b857682011-02-16 16:27:41 -08001964 * Get the password expiration timeout for the given admin. The expiration timeout is the
1965 * recurring expiration timeout provided in the call to
1966 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
Esteban Talaverac1c83592016-02-17 17:56:15 +00001967 * aggregate of all participating policy administrators if {@code admin} is null. Admins that
1968 * have set restrictions on profiles that have a separate challenge are not taken into account.
1969 *
1970 * <p>This method can be called on the {@link DevicePolicyManager} instance
1971 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1972 * restrictions on the parent profile.
Jim Millera4e28d12010-11-08 16:15:47 -08001973 *
Robin Lee25e26452015-06-02 09:56:29 -07001974 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001975 * @return The timeout for the given admin or the minimum of all timeouts
1976 */
Robin Lee25e26452015-06-02 09:56:29 -07001977 public long getPasswordExpirationTimeout(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001978 if (mService != null) {
1979 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001980 return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08001981 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001982 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08001983 }
1984 }
1985 return 0;
1986 }
1987
1988 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001989 * Get the current password expiration time for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01001990 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00001991 * a separate challenge are not taken into account. If admin is {@code null}, then a composite
1992 * of all expiration times is returned - which will be the minimum of all of them.
1993 *
1994 * <p>This method can be called on the {@link DevicePolicyManager} instance
1995 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1996 * the password expiration for the parent profile.
Jim Millera4e28d12010-11-08 16:15:47 -08001997 *
Robin Lee25e26452015-06-02 09:56:29 -07001998 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001999 * @return The password expiration time, in milliseconds since epoch.
Jim Millera4e28d12010-11-08 16:15:47 -08002000 */
Robin Lee25e26452015-06-02 09:56:29 -07002001 public long getPasswordExpiration(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08002002 if (mService != null) {
2003 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002004 return mService.getPasswordExpiration(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08002005 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002006 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08002007 }
2008 }
2009 return 0;
2010 }
2011
2012 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002013 * Retrieve the current password history length for a particular admin or all admins that
Rubin Xud3609d42016-07-13 18:32:57 +01002014 * set restrictions on this user and its participating profiles. Restrictions on profiles that
Esteban Talaverac1c83592016-02-17 17:56:15 +00002015 * have a separate challenge are not taken into account.
2016 *
2017 * <p>This method can be called on the {@link DevicePolicyManager} instance
2018 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2019 * restrictions on the parent profile.
2020 *
Robin Lee25e26452015-06-02 09:56:29 -07002021 * @param admin The name of the admin component to check, or {@code null} to aggregate
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002022 * all admins.
2023 * @return The length of the password history
2024 */
Robin Lee25e26452015-06-02 09:56:29 -07002025 public int getPasswordHistoryLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002026 return getPasswordHistoryLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002027 }
2028
2029 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002030 public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002031 if (mService != null) {
2032 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002033 return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002034 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002035 throw e.rethrowFromSystemServer();
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002036 }
2037 }
2038 return 0;
2039 }
2040
Dianne Hackbornd6847842010-01-12 18:14:19 -08002041 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08002042 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08002043 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08002044 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08002045 * @return Returns the maximum length that the user can enter.
2046 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08002047 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08002048 // Kind-of arbitrary.
2049 return 16;
2050 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002051
Dianne Hackborn254cb442010-01-27 19:23:59 -08002052 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002053 * Determine whether the current password the user has set is sufficient to meet the policy
2054 * requirements (e.g. quality, minimum length) that have been requested by the admins of this
2055 * user and its participating profiles. Restrictions on profiles that have a separate challenge
2056 * are not taken into account.
2057 * <p>
2058 * The calling device admin must have requested
2059 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2060 * not, a security exception will be thrown.
2061 * <p>
2062 * This method can be called on the {@link DevicePolicyManager} instance returned by
2063 * {@link #getParentProfileInstance(ComponentName)} in order to determine if the password set on
2064 * the parent profile is sufficient.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002065 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01002066 * @return Returns true if the password meets the current requirements, else false.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002067 * @throws SecurityException if the calling application does not own an active administrator
2068 * that uses {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002069 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002070 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002071 if (mService != null) {
2072 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00002073 return mService.isActivePasswordSufficient(myUserId(), mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002074 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002075 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002076 }
2077 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002078 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08002079 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002080
Dianne Hackbornd6847842010-01-12 18:14:19 -08002081 /**
Clara Bayarrid7693912016-01-22 17:26:31 +00002082 * Determine whether the current profile password the user has set is sufficient
Esteban Talaverac1c83592016-02-17 17:56:15 +00002083 * to meet the policy requirements (e.g. quality, minimum length) that have been
Clara Bayarrid7693912016-01-22 17:26:31 +00002084 * requested by the admins of the parent user and its profiles.
2085 *
2086 * @param userHandle the userId of the profile to check the password for.
2087 * @return Returns true if the password would meet the current requirements, else false.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002088 * @throws SecurityException if {@code userHandle} is not a managed profile.
Clara Bayarrid7693912016-01-22 17:26:31 +00002089 * @hide
2090 */
2091 public boolean isProfileActivePasswordSufficientForParent(int userHandle) {
2092 if (mService != null) {
2093 try {
2094 return mService.isProfileActivePasswordSufficientForParent(userHandle);
2095 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002096 throw e.rethrowFromSystemServer();
Clara Bayarrid7693912016-01-22 17:26:31 +00002097 }
2098 }
2099 return false;
2100 }
2101
2102 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002103 * Retrieve the number of times the user has failed at entering a password since that last
2104 * successful password entry.
2105 * <p>
2106 * This method can be called on the {@link DevicePolicyManager} instance returned by
2107 * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the number of failed
2108 * password attemts for the parent user.
2109 * <p>
2110 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN}
2111 * to be able to call this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002112 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002113 * @return The number of times user has entered an incorrect password since the last correct
2114 * password entry.
2115 * @throws SecurityException if the calling application does not own an active administrator
2116 * that uses {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002117 */
2118 public int getCurrentFailedPasswordAttempts() {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00002119 return getCurrentFailedPasswordAttempts(myUserId());
2120 }
2121
2122 /**
2123 * Retrieve the number of times the given user has failed at entering a
2124 * password since that last successful password entry.
2125 *
2126 * <p>The calling device admin must have requested
2127 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call this method; if it has
2128 * not and it is not the system uid, a security exception will be thrown.
2129 *
2130 * @hide
2131 */
2132 public int getCurrentFailedPasswordAttempts(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002133 if (mService != null) {
2134 try {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00002135 return mService.getCurrentFailedPasswordAttempts(userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002136 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002137 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002138 }
2139 }
2140 return -1;
2141 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002142
2143 /**
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002144 * Queries whether {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002145 *
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002146 * @return true if RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002147 * @hide
2148 */
2149 public boolean getDoNotAskCredentialsOnBoot() {
2150 if (mService != null) {
2151 try {
2152 return mService.getDoNotAskCredentialsOnBoot();
2153 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002154 throw e.rethrowFromSystemServer();
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002155 }
2156 }
2157 return false;
2158 }
2159
2160 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002161 * Setting this to a value greater than zero enables a built-in policy that will perform a
2162 * device or profile wipe after too many incorrect device-unlock passwords have been entered.
2163 * This built-in policy combines watching for failed passwords and wiping the device, and
2164 * requires that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002165 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002166 * <p>
2167 * To implement any other policy (e.g. wiping data for a particular application only, erasing or
2168 * revoking credentials, or reporting the failure to a server), you should implement
2169 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} instead. Do not
2170 * use this API, because if the maximum count is reached, the device or profile will be wiped
2171 * immediately, and your callback will not be invoked.
2172 * <p>
2173 * This method can be called on the {@link DevicePolicyManager} instance returned by
2174 * {@link #getParentProfileInstance(ComponentName)} in order to set a value on the parent
2175 * profile.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002176 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002177 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002178 * @param num The number of failed password attempts at which point the device or profile will
2179 * be wiped.
2180 * @throws SecurityException if {@code admin} is not an active administrator or does not use
2181 * both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
2182 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002183 */
Robin Lee25e26452015-06-02 09:56:29 -07002184 public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002185 if (mService != null) {
2186 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002187 mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002188 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002189 throw e.rethrowFromSystemServer();
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002190 }
2191 }
2192 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002193
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002194 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002195 * Retrieve the current maximum number of login attempts that are allowed before the device
Rubin Xud3609d42016-07-13 18:32:57 +01002196 * or profile is wiped, for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002197 * and its participating profiles. Restrictions on profiles that have a separate challenge are
2198 * not taken into account.
2199 *
2200 * <p>This method can be called on the {@link DevicePolicyManager} instance
2201 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2202 * the value for the parent profile.
2203 *
Robin Lee25e26452015-06-02 09:56:29 -07002204 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002205 * all admins.
2206 */
Robin Lee25e26452015-06-02 09:56:29 -07002207 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002208 return getMaximumFailedPasswordsForWipe(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002209 }
2210
2211 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002212 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08002213 if (mService != null) {
2214 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002215 return mService.getMaximumFailedPasswordsForWipe(
2216 admin, userHandle, mParentInstance);
Dianne Hackborn254cb442010-01-27 19:23:59 -08002217 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002218 throw e.rethrowFromSystemServer();
Dianne Hackborn254cb442010-01-27 19:23:59 -08002219 }
2220 }
2221 return 0;
2222 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002223
Dianne Hackborn254cb442010-01-27 19:23:59 -08002224 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002225 * Returns the profile with the smallest maximum failed passwords for wipe,
2226 * for the given user. So for primary user, it might return the primary or
2227 * a managed profile. For a secondary user, it would be the same as the
2228 * user passed in.
2229 * @hide Used only by Keyguard
2230 */
2231 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
2232 if (mService != null) {
2233 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002234 return mService.getProfileWithMinimumFailedPasswordsForWipe(
2235 userHandle, mParentInstance);
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002236 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002237 throw e.rethrowFromSystemServer();
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002238 }
2239 }
2240 return UserHandle.USER_NULL;
2241 }
2242
2243 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002244 * Flag for {@link #resetPassword}: don't allow other admins to change
2245 * the password again until the user has entered it.
2246 */
2247 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002248
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002249 /**
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002250 * Flag for {@link #resetPassword}: don't ask for user credentials on device boot.
2251 * If the flag is set, the device can be booted without asking for user password.
2252 * The absence of this flag does not change the current boot requirements. This flag
2253 * can be set by the device owner only. If the app is not the device owner, the flag
2254 * is ignored. Once the flag is set, it cannot be reverted back without resetting the
2255 * device to factory defaults.
2256 */
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002257 public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002;
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002258
2259 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002260 * Force a new device unlock password (the password needed to access the entire device, not for
2261 * individual accounts) on the user. This takes effect immediately.
2262 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002263 * <em>Note: This API has been limited as of {@link android.os.Build.VERSION_CODES#N} for
Makoto Onuki70f929e2015-11-11 12:40:15 -08002264 * device admins that are not device owner and not profile owner.
2265 * The password can now only be changed if there is currently no password set. Device owner
Ricky Wai977ade22016-05-24 15:02:41 +01002266 * and profile owner can still do this when user is unlocked and does not have a managed
2267 * profile.</em>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002268 * <p>
2269 * The given password must be sufficient for the current password quality and length constraints
2270 * as returned by {@link #getPasswordQuality(ComponentName)} and
2271 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then
2272 * it will be rejected and false returned. Note that the password may be a stronger quality
2273 * (containing alphanumeric characters when the requested quality is only numeric), in which
2274 * case the currently active quality will be increased to match.
2275 * <p>
2276 * Calling with a null or empty password will clear any existing PIN, pattern or password if the
Robin Leece5c4002016-03-23 17:05:03 +00002277 * current password constraints allow it. <em>Note: This will not work in
2278 * {@link android.os.Build.VERSION_CODES#N} and later for managed profiles, or for device admins
2279 * that are not device owner or profile owner. Once set, the password cannot be changed to null
2280 * or empty except by these admins.</em>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002281 * <p>
2282 * The calling device admin must have requested
2283 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call this method; if it has
2284 * not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002285 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01002286 * @param password The new password for the user. Null or empty clears the password.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002287 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002288 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
2289 * @return Returns true if the password was applied, or false if it is not acceptable for the
2290 * current constraints or if the user has not been decrypted yet.
2291 * @throws SecurityException if the calling application does not own an active administrator
2292 * that uses {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD}
Ricky Wai977ade22016-05-24 15:02:41 +01002293 * @throws IllegalStateException if the calling user is locked or has a managed profile.
Andrew Scull3f81f4e2016-07-29 16:29:58 +01002294 * @throws IllegalArgumentException if the password does not meet system requirements.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002295 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002296 public boolean resetPassword(String password, int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002297 throwIfParentInstance("resetPassword");
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002298 if (mService != null) {
2299 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002300 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002301 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002302 throw e.rethrowFromSystemServer();
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002303 }
2304 }
2305 return false;
2306 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002307
Dianne Hackbornd6847842010-01-12 18:14:19 -08002308 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002309 * Called by an application that is administering the device to set the maximum time for user
2310 * activity until the device will lock. This limits the length that the user can set. It takes
2311 * effect immediately.
2312 * <p>
2313 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
2314 * to be able to call this method; if it has not, a security exception will be thrown.
2315 * <p>
2316 * This method can be called on the {@link DevicePolicyManager} instance returned by
2317 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2318 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002319 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002320 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002321 * @param timeMs The new desired maximum time to lock in milliseconds. A value of 0 means there
2322 * is no restriction.
2323 * @throws SecurityException if {@code admin} is not an active administrator or it does not use
2324 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002325 */
Robin Lee25e26452015-06-02 09:56:29 -07002326 public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002327 if (mService != null) {
2328 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002329 mService.setMaximumTimeToLock(admin, timeMs, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002330 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002331 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002332 }
2333 }
2334 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002335
Dianne Hackbornd6847842010-01-12 18:14:19 -08002336 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002337 * Retrieve the current maximum time to unlock for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01002338 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00002339 * a separate challenge are not taken into account.
2340 *
2341 * <p>This method can be called on the {@link DevicePolicyManager} instance
2342 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2343 * restrictions on the parent profile.
2344 *
Robin Lee25e26452015-06-02 09:56:29 -07002345 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002346 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07002347 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07002348 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002349 */
Robin Lee25e26452015-06-02 09:56:29 -07002350 public long getMaximumTimeToLock(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002351 return getMaximumTimeToLock(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002352 }
2353
2354 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002355 public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002356 if (mService != null) {
2357 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002358 return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002359 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002360 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002361 }
2362 }
2363 return 0;
2364 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002365
Dianne Hackbornd6847842010-01-12 18:14:19 -08002366 /**
Ricky Wai035e9242016-03-18 16:43:31 +00002367 * Returns maximum time to lock that applied by all profiles in this user. We do this because we
2368 * do not have a separate timeout to lock for work challenge only.
2369 *
2370 * @hide
2371 */
2372 public long getMaximumTimeToLockForUserAndProfiles(int userHandle) {
2373 if (mService != null) {
2374 try {
2375 return mService.getMaximumTimeToLockForUserAndProfiles(userHandle);
2376 } catch (RemoteException e) {
2377 throw e.rethrowFromSystemServer();
2378 }
2379 }
2380 return 0;
2381 }
2382
2383 /**
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002384 * Called by a device/profile owner to set the timeout after which unlocking with secondary, non
2385 * strong auth (e.g. fingerprint, trust agents) times out, i.e. the user has to use a strong
2386 * authentication method like password, pin or pattern.
2387 *
2388 * <p>This timeout is used internally to reset the timer to require strong auth again after
2389 * specified timeout each time it has been successfully used.
2390 *
2391 * <p>Fingerprint can also be disabled altogether using {@link #KEYGUARD_DISABLE_FINGERPRINT}.
2392 *
2393 * <p>Trust agents can also be disabled altogether using {@link #KEYGUARD_DISABLE_TRUST_AGENTS}.
2394 *
2395 * <p>The calling device admin must be a device or profile owner. If it is not,
2396 * a {@link SecurityException} will be thrown.
2397 *
Michal Karpinski943aabd2016-10-06 11:09:25 +01002398 * <p>The calling device admin can verify the value it has set by calling
2399 * {@link #getRequiredStrongAuthTimeout(ComponentName)} and passing in its instance.
2400 *
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002401 * <p>This method can be called on the {@link DevicePolicyManager} instance returned by
2402 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2403 * profile.
2404 *
2405 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2406 * @param timeoutMs The new timeout, after which the user will have to unlock with strong
Michal Karpinski943aabd2016-10-06 11:09:25 +01002407 * authentication method. A value of 0 means the admin is not participating in
2408 * controlling the timeout.
2409 * The minimum and maximum timeouts are platform-defined and are typically 1 hour and
2410 * 72 hours, respectively. Though discouraged, the admin may choose to require strong
2411 * auth at all times using {@link #KEYGUARD_DISABLE_FINGERPRINT} and/or
2412 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002413 *
2414 * @throws SecurityException if {@code admin} is not a device or profile owner.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002415 */
2416 public void setRequiredStrongAuthTimeout(@NonNull ComponentName admin,
2417 long timeoutMs) {
2418 if (mService != null) {
2419 try {
2420 mService.setRequiredStrongAuthTimeout(admin, timeoutMs, mParentInstance);
2421 } catch (RemoteException e) {
2422 throw e.rethrowFromSystemServer();
2423 }
2424 }
2425 }
2426
2427 /**
2428 * Determine for how long the user will be able to use secondary, non strong auth for
2429 * authentication, since last strong method authentication (password, pin or pattern) was used.
2430 * After the returned timeout the user is required to use strong authentication method.
2431 *
2432 * <p>This method can be called on the {@link DevicePolicyManager} instance
2433 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2434 * restrictions on the parent profile.
2435 *
2436 * @param admin The name of the admin component to check, or {@code null} to aggregate
2437 * accross all participating admins.
Michal Karpinski943aabd2016-10-06 11:09:25 +01002438 * @return The timeout or 0 if not configured for the provided admin.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002439 */
2440 public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin) {
2441 return getRequiredStrongAuthTimeout(admin, myUserId());
2442 }
2443
2444 /** @hide per-user version */
2445 public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin, @UserIdInt int userId) {
2446 if (mService != null) {
2447 try {
2448 return mService.getRequiredStrongAuthTimeout(admin, userId, mParentInstance);
2449 } catch (RemoteException e) {
2450 throw e.rethrowFromSystemServer();
2451 }
2452 }
2453 return DEFAULT_STRONG_AUTH_TIMEOUT_MS;
2454 }
2455
2456 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002457 * Make the device lock immediately, as if the lock screen timeout has expired at the point of
2458 * this call.
2459 * <p>
2460 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
2461 * to be able to call this method; if it has not, a security exception will be thrown.
2462 * <p>
2463 * This method can be called on the {@link DevicePolicyManager} instance returned by
2464 * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002465 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002466 * @throws SecurityException if the calling application does not own an active administrator
2467 * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002468 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002469 public void lockNow() {
2470 if (mService != null) {
2471 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002472 mService.lockNow(mParentInstance);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002473 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002474 throw e.rethrowFromSystemServer();
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002475 }
2476 }
2477 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002478
Dianne Hackbornd6847842010-01-12 18:14:19 -08002479 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07002480 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002481 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07002482 */
2483 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
2484
2485 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002486 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
2487 * data.
2488 *
Paul Crowley2934b262014-12-02 11:21:13 +00002489 * <p>This flag may only be set by device owner admins; if it is set by
2490 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002491 */
2492 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
2493
2494 /**
Suprabh Shukla556b05a2016-08-10 15:49:24 -07002495 * Ask that all user data be wiped. If called as a secondary user, the user will be removed and
2496 * other users will remain unaffected. Calling from the primary user will cause the device to
2497 * reboot, erasing all device data - including all the secondary users and their data - while
2498 * booting up.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002499 * <p>
2500 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to
2501 * be able to call this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002502 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002503 * @param flags Bit mask of additional options: currently supported flags are
2504 * {@link #WIPE_EXTERNAL_STORAGE} and {@link #WIPE_RESET_PROTECTION_DATA}.
2505 * @throws SecurityException if the calling application does not own an active administrator
2506 * that uses {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002507 */
2508 public void wipeData(int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002509 throwIfParentInstance("wipeData");
Dianne Hackbornd6847842010-01-12 18:14:19 -08002510 if (mService != null) {
2511 try {
Makoto Onuki70f929e2015-11-11 12:40:15 -08002512 mService.wipeData(flags);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002513 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002514 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002515 }
2516 }
2517 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002518
Dianne Hackbornd6847842010-01-12 18:14:19 -08002519 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07002520 * Called by an application that is administering the device to set the
2521 * global proxy and exclusion list.
2522 * <p>
2523 * The calling device admin must have requested
2524 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
2525 * this method; if it has not, a security exception will be thrown.
2526 * Only the first device admin can set the proxy. If a second admin attempts
2527 * to set the proxy, the {@link ComponentName} of the admin originally setting the
Robin Lee25e26452015-06-02 09:56:29 -07002528 * proxy will be returned. If successful in setting the proxy, {@code null} will
Oscar Montemayor69238c62010-08-03 10:51:06 -07002529 * be returned.
2530 * The method can be called repeatedly by the device admin alrady setting the
2531 * proxy to update the proxy and exclusion list.
2532 *
Robin Lee25e26452015-06-02 09:56:29 -07002533 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Oscar Montemayor69238c62010-08-03 10:51:06 -07002534 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
2535 * Pass Proxy.NO_PROXY to reset the proxy.
2536 * @param exclusionList a list of domains to be excluded from the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07002537 * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName}
2538 * of the device admin that sets the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08002539 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07002540 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07002541 public @Nullable ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec,
Oscar Montemayor69238c62010-08-03 10:51:06 -07002542 List<String> exclusionList ) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002543 throwIfParentInstance("setGlobalProxy");
Oscar Montemayor69238c62010-08-03 10:51:06 -07002544 if (proxySpec == null) {
2545 throw new NullPointerException();
2546 }
2547 if (mService != null) {
2548 try {
2549 String hostSpec;
2550 String exclSpec;
2551 if (proxySpec.equals(Proxy.NO_PROXY)) {
2552 hostSpec = null;
2553 exclSpec = null;
2554 } else {
2555 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
2556 throw new IllegalArgumentException();
2557 }
2558 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
2559 String hostName = sa.getHostName();
2560 int port = sa.getPort();
2561 StringBuilder hostBuilder = new StringBuilder();
2562 hostSpec = hostBuilder.append(hostName)
2563 .append(":").append(Integer.toString(port)).toString();
2564 if (exclusionList == null) {
2565 exclSpec = "";
2566 } else {
2567 StringBuilder listBuilder = new StringBuilder();
2568 boolean firstDomain = true;
2569 for (String exclDomain : exclusionList) {
2570 if (!firstDomain) {
2571 listBuilder = listBuilder.append(",");
2572 } else {
2573 firstDomain = false;
2574 }
2575 listBuilder = listBuilder.append(exclDomain.trim());
2576 }
2577 exclSpec = listBuilder.toString();
2578 }
Yuhao Zheng90704842014-02-28 17:22:45 -08002579 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
2580 != android.net.Proxy.PROXY_VALID)
2581 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07002582 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002583 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07002584 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002585 throw e.rethrowFromSystemServer();
Oscar Montemayor69238c62010-08-03 10:51:06 -07002586 }
2587 }
2588 return null;
2589 }
2590
2591 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002592 * Set a network-independent global HTTP proxy. This is not normally what you want for typical
2593 * HTTP proxies - they are generally network dependent. However if you're doing something
2594 * unusual like general internal filtering this may be useful. On a private network where the
2595 * proxy is not accessible, you may break HTTP using this.
2596 * <p>
2597 * This method requires the caller to be the device owner.
2598 * <p>
2599 * This proxy is only a recommendation and it is possible that some apps will ignore it.
Jason Monk03bc9912014-05-13 09:44:57 -04002600 *
Jason Monk03bc9912014-05-13 09:44:57 -04002601 * @see ProxyInfo
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002602 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2603 * @param proxyInfo The a {@link ProxyInfo} object defining the new global HTTP proxy. A
2604 * {@code null} value will clear the global HTTP proxy.
2605 * @throws SecurityException if {@code admin} is not the device owner.
Jason Monk03bc9912014-05-13 09:44:57 -04002606 */
Robin Lee25e26452015-06-02 09:56:29 -07002607 public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo
2608 proxyInfo) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002609 throwIfParentInstance("setRecommendedGlobalProxy");
Jason Monk03bc9912014-05-13 09:44:57 -04002610 if (mService != null) {
2611 try {
2612 mService.setRecommendedGlobalProxy(admin, proxyInfo);
2613 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002614 throw e.rethrowFromSystemServer();
Jason Monk03bc9912014-05-13 09:44:57 -04002615 }
2616 }
2617 }
2618
2619 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07002620 * Returns the component name setting the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07002621 * @return ComponentName object of the device admin that set the global proxy, or {@code null}
2622 * if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08002623 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07002624 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07002625 public @Nullable ComponentName getGlobalProxyAdmin() {
Oscar Montemayor69238c62010-08-03 10:51:06 -07002626 if (mService != null) {
2627 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002628 return mService.getGlobalProxyAdmin(myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07002629 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002630 throw e.rethrowFromSystemServer();
Oscar Montemayor69238c62010-08-03 10:51:06 -07002631 }
2632 }
2633 return null;
2634 }
2635
2636 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002637 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002638 * indicating that encryption is not supported.
2639 */
2640 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
2641
2642 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002643 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002644 * indicating that encryption is supported, but is not currently active.
2645 */
2646 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
2647
2648 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002649 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002650 * indicating that encryption is not currently active, but is currently
2651 * being activated. This is only reported by devices that support
2652 * encryption of data and only when the storage is currently
2653 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
2654 * to become encrypted will never return this value.
2655 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002656 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002657
2658 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002659 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002660 * indicating that encryption is active.
Amith Yamasani75db1252016-07-11 14:41:01 -07002661 * <p>
2662 * Also see {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002663 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002664 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002665
2666 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002667 * Result code for {@link #getStorageEncryptionStatus}:
2668 * indicating that encryption is active, but an encryption key has not
2669 * been set by the user.
2670 */
2671 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
2672
2673 /**
Makoto Onukid4c9e542016-02-25 18:17:30 -08002674 * Result code for {@link #getStorageEncryptionStatus}:
Amith Yamasani75db1252016-07-11 14:41:01 -07002675 * indicating that encryption is active and the encryption key is tied to the user or profile.
2676 * <p>
2677 * This value is only returned to apps targeting API level 24 and above. For apps targeting
2678 * earlier API levels, {@link #ENCRYPTION_STATUS_ACTIVE} is returned, even if the
2679 * encryption key is specific to the user or profile.
Makoto Onukid4c9e542016-02-25 18:17:30 -08002680 */
2681 public static final int ENCRYPTION_STATUS_ACTIVE_PER_USER = 5;
2682
2683 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002684 * Activity action: begin the process of encrypting data on the device. This activity should
2685 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
2686 * After resuming from this activity, use {@link #getStorageEncryption}
2687 * to check encryption status. However, on some devices this activity may never return, as
2688 * it may trigger a reboot and in some cases a complete data wipe of the device.
2689 */
2690 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
2691 public static final String ACTION_START_ENCRYPTION
2692 = "android.app.action.START_ENCRYPTION";
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002693 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07002694 * Widgets are enabled in keyguard
2695 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002696 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07002697
2698 /**
Jim Miller50e62182014-04-23 17:25:00 -07002699 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07002700 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002701 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
2702
2703 /**
2704 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
2705 */
2706 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
2707
2708 /**
Jim Miller50e62182014-04-23 17:25:00 -07002709 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2710 */
2711 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
2712
2713 /**
2714 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2715 */
2716 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
2717
2718 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02002719 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07002720 * (e.g. PIN/Pattern/Password).
2721 */
2722 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
2723
2724 /**
Jim Miller06e34502014-07-17 14:46:05 -07002725 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
2726 */
2727 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
2728
2729 /**
Adrian Roos7f06eed2016-02-05 15:21:02 -08002730 * Disable text entry into notifications on secure keyguard screens (e.g. PIN/Pattern/Password).
2731 */
2732 public static final int KEYGUARD_DISABLE_REMOTE_INPUT = 1 << 6;
2733
2734 /**
Jim Miller35207742012-11-02 15:33:20 -07002735 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07002736 */
2737 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07002738
2739 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002740 * Called by an application that is administering the device to request that the storage system
2741 * be encrypted.
2742 * <p>
2743 * When multiple device administrators attempt to control device encryption, the most secure,
2744 * supported setting will always be used. If any device administrator requests device
2745 * encryption, it will be enabled; Conversely, if a device administrator attempts to disable
2746 * device encryption while another device administrator has enabled it, the call to disable will
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002747 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002748 * <p>
2749 * This policy controls encryption of the secure (application data) storage area. Data written
2750 * to other storage areas may or may not be encrypted, and this policy does not require or
2751 * control the encryption of any other storage areas. There is one exception: If
2752 * {@link android.os.Environment#isExternalStorageEmulated()} is {@code true}, then the
2753 * directory returned by {@link android.os.Environment#getExternalStorageDirectory()} must be
2754 * written to disk within the encrypted storage area.
2755 * <p>
2756 * Important Note: On some devices, it is possible to encrypt storage without requiring the user
2757 * to create a device PIN or Password. In this case, the storage is encrypted, but the
2758 * encryption key may not be fully secured. For maximum security, the administrator should also
2759 * require (and check for) a pattern, PIN, or password.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002760 *
2761 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2762 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08002763 * @return the new request status (for all active admins) - will be one of
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002764 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
2765 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
2766 * {@link #getStorageEncryptionStatus()} to query the actual device state.
2767 * @throws SecurityException if {@code admin} is not an active administrator or does not use
2768 * {@link DeviceAdminInfo#USES_ENCRYPTED_STORAGE}
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002769 */
Robin Lee25e26452015-06-02 09:56:29 -07002770 public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002771 throwIfParentInstance("setStorageEncryption");
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002772 if (mService != null) {
2773 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002774 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002775 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002776 throw e.rethrowFromSystemServer();
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002777 }
2778 }
2779 return ENCRYPTION_STATUS_UNSUPPORTED;
2780 }
2781
2782 /**
2783 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002784 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002785 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08002786 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
2787 * this will return the requested encryption setting as an aggregate of all active
2788 * administrators.
2789 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002790 */
Robin Lee25e26452015-06-02 09:56:29 -07002791 public boolean getStorageEncryption(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002792 throwIfParentInstance("getStorageEncryption");
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002793 if (mService != null) {
2794 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002795 return mService.getStorageEncryption(admin, myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002796 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002797 throw e.rethrowFromSystemServer();
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002798 }
2799 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08002800 return false;
2801 }
2802
2803 /**
2804 * Called by an application that is administering the device to
2805 * determine the current encryption status of the device.
Amith Yamasani75db1252016-07-11 14:41:01 -07002806 * <p>
Andy Stadler22dbfda2011-01-17 12:47:31 -08002807 * Depending on the returned status code, the caller may proceed in different
2808 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
2809 * storage system does not support encryption. If the
2810 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
2811 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00002812 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
2813 * storage system has enabled encryption but no password is set so further action
Amith Yamasani75db1252016-07-11 14:41:01 -07002814 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING},
2815 * {@link #ENCRYPTION_STATUS_ACTIVE} or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER},
2816 * no further action is required.
Andy Stadler22dbfda2011-01-17 12:47:31 -08002817 *
Robin Lee7e678712014-07-24 16:41:31 +01002818 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08002819 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00002820 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
Amith Yamasani75db1252016-07-11 14:41:01 -07002821 * {@link #ENCRYPTION_STATUS_ACTIVE}, or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08002822 */
2823 public int getStorageEncryptionStatus() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002824 throwIfParentInstance("getStorageEncryptionStatus");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002825 return getStorageEncryptionStatus(myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002826 }
2827
2828 /** @hide per-user version */
2829 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08002830 if (mService != null) {
2831 try {
Makoto Onukid4c9e542016-02-25 18:17:30 -08002832 return mService.getStorageEncryptionStatus(mContext.getPackageName(), userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08002833 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002834 throw e.rethrowFromSystemServer();
Andy Stadler22dbfda2011-01-17 12:47:31 -08002835 }
2836 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002837 return ENCRYPTION_STATUS_UNSUPPORTED;
2838 }
2839
2840 /**
Robin Lee2f7e1e42016-03-21 10:50:01 +00002841 * Mark a CA certificate as approved by the device user. This means that they have been notified
2842 * of the installation, were made aware of the risks, viewed the certificate and still wanted to
2843 * keep the certificate on the device.
2844 *
2845 * Calling with {@param approval} as {@code true} will cancel any ongoing warnings related to
2846 * this certificate.
2847 *
2848 * @hide
2849 */
2850 public boolean approveCaCert(String alias, int userHandle, boolean approval) {
2851 if (mService != null) {
2852 try {
2853 return mService.approveCaCert(alias, userHandle, approval);
2854 } catch (RemoteException e) {
2855 throw e.rethrowFromSystemServer();
2856 }
2857 }
2858 return false;
2859 }
2860
2861 /**
2862 * Check whether a CA certificate has been approved by the device user.
2863 *
2864 * @hide
2865 */
2866 public boolean isCaCertApproved(String alias, int userHandle) {
2867 if (mService != null) {
2868 try {
2869 return mService.isCaCertApproved(alias, userHandle);
2870 } catch (RemoteException e) {
2871 throw e.rethrowFromSystemServer();
2872 }
2873 }
2874 return false;
2875 }
2876
2877 /**
Robin Lee7e678712014-07-24 16:41:31 +01002878 * Installs the given certificate as a user CA.
2879 *
Robin Lee25e26452015-06-02 09:56:29 -07002880 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2881 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002882 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04002883 *
2884 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01002885 * interrupted, true otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002886 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
2887 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04002888 */
Robin Lee25e26452015-06-02 09:56:29 -07002889 public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002890 throwIfParentInstance("installCaCert");
Maggie Benthallda51e682013-08-08 22:35:44 -04002891 if (mService != null) {
2892 try {
Robin Lee7e678712014-07-24 16:41:31 +01002893 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04002894 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002895 throw e.rethrowFromSystemServer();
Maggie Benthallda51e682013-08-08 22:35:44 -04002896 }
2897 }
2898 return false;
2899 }
2900
2901 /**
Robin Lee7e678712014-07-24 16:41:31 +01002902 * Uninstalls the given certificate from trusted user CAs, if present.
2903 *
Robin Lee25e26452015-06-02 09:56:29 -07002904 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2905 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002906 * @param certBuffer encoded form of the certificate to remove.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002907 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
2908 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04002909 */
Robin Lee25e26452015-06-02 09:56:29 -07002910 public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002911 throwIfParentInstance("uninstallCaCert");
Maggie Benthallda51e682013-08-08 22:35:44 -04002912 if (mService != null) {
2913 try {
Robin Lee306fe082014-06-19 14:04:24 +00002914 final String alias = getCaCertAlias(certBuffer);
Robin Lee83881bd2015-06-09 16:04:38 -07002915 mService.uninstallCaCerts(admin, new String[] {alias});
Robin Lee306fe082014-06-19 14:04:24 +00002916 } catch (CertificateException e) {
2917 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002918 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002919 throw e.rethrowFromSystemServer();
Maggie Benthallda51e682013-08-08 22:35:44 -04002920 }
2921 }
2922 }
2923
2924 /**
Robin Lee7e678712014-07-24 16:41:31 +01002925 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
2926 * If a user has installed any certificates by other means than device policy these will be
2927 * included too.
2928 *
Robin Lee25e26452015-06-02 09:56:29 -07002929 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2930 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002931 * @return a List of byte[] arrays, each encoding one user CA certificate.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002932 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
2933 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04002934 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07002935 public @NonNull List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) {
2936 final List<byte[]> certs = new ArrayList<byte[]>();
Benjamin Franzbc33c822016-04-15 08:57:52 +01002937 throwIfParentInstance("getInstalledCaCerts");
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002938 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01002939 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002940 mService.enforceCanManageCaCerts(admin);
2941 final TrustedCertificateStore certStore = new TrustedCertificateStore();
2942 for (String alias : certStore.userAliases()) {
2943 try {
2944 certs.add(certStore.getCertificate(alias).getEncoded());
2945 } catch (CertificateException ce) {
2946 Log.w(TAG, "Could not encode certificate: " + alias, ce);
2947 }
2948 }
2949 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002950 throw re.rethrowFromSystemServer();
Robin Lee7e678712014-07-24 16:41:31 +01002951 }
2952 }
2953 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04002954 }
2955
2956 /**
Robin Lee7e678712014-07-24 16:41:31 +01002957 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
2958 * means other than device policy will also be removed, except for system CA certificates.
2959 *
Robin Lee25e26452015-06-02 09:56:29 -07002960 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2961 * {@code null} if calling from a delegated certificate installer.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002962 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
2963 * owner.
Robin Lee7e678712014-07-24 16:41:31 +01002964 */
Robin Lee25e26452015-06-02 09:56:29 -07002965 public void uninstallAllUserCaCerts(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002966 throwIfParentInstance("uninstallAllUserCaCerts");
Robin Lee7e678712014-07-24 16:41:31 +01002967 if (mService != null) {
Robin Lee83881bd2015-06-09 16:04:38 -07002968 try {
2969 mService.uninstallCaCerts(admin, new TrustedCertificateStore().userAliases()
2970 .toArray(new String[0]));
2971 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002972 throw re.rethrowFromSystemServer();
Robin Lee7e678712014-07-24 16:41:31 +01002973 }
2974 }
2975 }
2976
2977 /**
2978 * Returns whether this certificate is installed as a trusted CA.
2979 *
Robin Lee25e26452015-06-02 09:56:29 -07002980 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2981 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002982 * @param certBuffer encoded form of the certificate to look up.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002983 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
2984 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04002985 */
Robin Lee25e26452015-06-02 09:56:29 -07002986 public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002987 throwIfParentInstance("hasCaCertInstalled");
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002988 if (mService != null) {
2989 try {
2990 mService.enforceCanManageCaCerts(admin);
2991 return getCaCertAlias(certBuffer) != null;
2992 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002993 throw re.rethrowFromSystemServer();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002994 } catch (CertificateException ce) {
2995 Log.w(TAG, "Could not parse certificate", ce);
2996 }
Maggie Benthallda51e682013-08-08 22:35:44 -04002997 }
2998 return false;
2999 }
3000
3001 /**
Robin Leece3399f2016-02-24 12:08:32 +00003002 * Called by a device or profile owner, or delegated certificate installer, to install a
3003 * certificate and corresponding private key. All apps within the profile will be able to access
3004 * the certificate and use the private key, given direct user approval.
3005 *
3006 * <p>Access to the installed credentials will not be granted to the caller of this API without
3007 * direct user approval. This is for security - should a certificate installer become
3008 * compromised, certificates it had already installed will be protected.
3009 *
3010 * <p>If the installer must have access to the credentials, call
Rubin Xub4365912016-03-23 12:13:22 +00003011 * {@link #installKeyPair(ComponentName, PrivateKey, Certificate[], String, boolean)} instead.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003012 *
Robin Lee25e26452015-06-02 09:56:29 -07003013 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3014 * {@code null} if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003015 * @param privKey The private key to install.
3016 * @param cert The certificate to install.
3017 * @param alias The private key alias under which to install the certificate. If a certificate
3018 * with that alias already exists, it will be overwritten.
3019 * @return {@code true} if the keys were installed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003020 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3021 * owner.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003022 */
Robin Leefbc65642015-08-03 16:21:22 +01003023 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
3024 @NonNull Certificate cert, @NonNull String alias) {
Rubin Xub4365912016-03-23 12:13:22 +00003025 return installKeyPair(admin, privKey, new Certificate[] {cert}, alias, false);
Robin Leece3399f2016-02-24 12:08:32 +00003026 }
3027
3028 /**
3029 * Called by a device or profile owner, or delegated certificate installer, to install a
Rubin Xub4365912016-03-23 12:13:22 +00003030 * certificate chain and corresponding private key for the leaf certificate. All apps within the
3031 * profile will be able to access the certificate chain and use the private key, given direct
3032 * user approval.
Robin Leece3399f2016-02-24 12:08:32 +00003033 *
Robin Leea1b290e2016-03-09 14:38:36 +00003034 * <p>The caller of this API may grant itself access to the certificate and private key
3035 * immediately, without user approval. It is a best practice not to request this unless strictly
3036 * necessary since it opens up additional security vulnerabilities.
Robin Leece3399f2016-02-24 12:08:32 +00003037 *
3038 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Robin Leea1b290e2016-03-09 14:38:36 +00003039 * {@code null} if calling from a delegated certificate installer.
Robin Leece3399f2016-02-24 12:08:32 +00003040 * @param privKey The private key to install.
Rubin Xub4365912016-03-23 12:13:22 +00003041 * @param certs The certificate chain to install. The chain should start with the leaf
3042 * certificate and include the chain of trust in order. This will be returned by
3043 * {@link android.security.KeyChain#getCertificateChain}.
Robin Leece3399f2016-02-24 12:08:32 +00003044 * @param alias The private key alias under which to install the certificate. If a certificate
Robin Leea1b290e2016-03-09 14:38:36 +00003045 * with that alias already exists, it will be overwritten.
Robin Leece3399f2016-02-24 12:08:32 +00003046 * @param requestAccess {@code true} to request that the calling app be granted access to the
Robin Leea1b290e2016-03-09 14:38:36 +00003047 * credentials immediately. Otherwise, access to the credentials will be gated by user
3048 * approval.
Robin Leece3399f2016-02-24 12:08:32 +00003049 * @return {@code true} if the keys were installed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003050 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3051 * owner.
Rubin Xub4365912016-03-23 12:13:22 +00003052 * @see android.security.KeyChain#getCertificateChain
Robin Leece3399f2016-02-24 12:08:32 +00003053 */
3054 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
Rubin Xub4365912016-03-23 12:13:22 +00003055 @NonNull Certificate[] certs, @NonNull String alias, boolean requestAccess) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003056 throwIfParentInstance("installKeyPair");
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003057 try {
Rubin Xub4365912016-03-23 12:13:22 +00003058 final byte[] pemCert = Credentials.convertToPem(certs[0]);
3059 byte[] pemChain = null;
3060 if (certs.length > 1) {
3061 pemChain = Credentials.convertToPem(Arrays.copyOfRange(certs, 1, certs.length));
3062 }
Robin Lee0d5ccb72014-09-12 17:41:44 +01003063 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
3064 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
Rubin Xub4365912016-03-23 12:13:22 +00003065 return mService.installKeyPair(admin, pkcs8Key, pemCert, pemChain, alias,
3066 requestAccess);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003067 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003068 throw e.rethrowFromSystemServer();
Robin Lee0d5ccb72014-09-12 17:41:44 +01003069 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
3070 Log.w(TAG, "Failed to obtain private key material", e);
3071 } catch (CertificateException | IOException e) {
3072 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003073 }
3074 return false;
3075 }
3076
3077 /**
Robin Leea1b290e2016-03-09 14:38:36 +00003078 * Called by a device or profile owner, or delegated certificate installer, to remove a
3079 * certificate and private key pair installed under a given alias.
Robin Leefbc65642015-08-03 16:21:22 +01003080 *
3081 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Robin Leea1b290e2016-03-09 14:38:36 +00003082 * {@code null} if calling from a delegated certificate installer.
Robin Leefbc65642015-08-03 16:21:22 +01003083 * @param alias The private key alias under which the certificate is installed.
Robin Leea1b290e2016-03-09 14:38:36 +00003084 * @return {@code true} if the private key alias no longer exists, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003085 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3086 * owner.
Robin Leefbc65642015-08-03 16:21:22 +01003087 */
3088 public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003089 throwIfParentInstance("removeKeyPair");
Robin Leefbc65642015-08-03 16:21:22 +01003090 try {
3091 return mService.removeKeyPair(admin, alias);
3092 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003093 throw e.rethrowFromSystemServer();
Robin Leefbc65642015-08-03 16:21:22 +01003094 }
Robin Leefbc65642015-08-03 16:21:22 +01003095 }
3096
3097 /**
Robin Lee25e26452015-06-02 09:56:29 -07003098 * @return the alias of a given CA certificate in the certificate store, or {@code null} if it
Robin Lee306fe082014-06-19 14:04:24 +00003099 * doesn't exist.
3100 */
3101 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
3102 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
3103 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
3104 new ByteArrayInputStream(certBuffer));
3105 return new TrustedCertificateStore().getCertificateAlias(cert);
3106 }
3107
3108 /**
Rubin Xuec32b562015-03-03 17:34:05 +00003109 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01003110 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00003111 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01003112 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00003113 * <p>
3114 * Delegated certificate installer is a per-user state. The delegated access is persistent until
3115 * it is later cleared by calling this method with a null value or uninstallling the certificate
3116 * installer.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003117 * <p>
Rubin Xuf03d0a62016-02-10 14:54:15 +00003118 * <b>Note:</b>Starting from {@link android.os.Build.VERSION_CODES#N}, if the caller
3119 * application's target SDK version is {@link android.os.Build.VERSION_CODES#N} or newer, the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003120 * supplied certificate installer package must be installed when calling this API, otherwise an
3121 * {@link IllegalArgumentException} will be thrown.
Rubin Xuec32b562015-03-03 17:34:05 +00003122 *
Robin Lee25e26452015-06-02 09:56:29 -07003123 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xuec32b562015-03-03 17:34:05 +00003124 * @param installerPackage The package name of the certificate installer which will be given
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003125 * access. If {@code null} is given the current package will be cleared.
3126 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Rubin Xuec32b562015-03-03 17:34:05 +00003127 */
Robin Lee25e26452015-06-02 09:56:29 -07003128 public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String
3129 installerPackage) throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003130 throwIfParentInstance("setCertInstallerPackage");
Rubin Xuec32b562015-03-03 17:34:05 +00003131 if (mService != null) {
3132 try {
Robin Lee25e26452015-06-02 09:56:29 -07003133 mService.setCertInstallerPackage(admin, installerPackage);
Rubin Xuec32b562015-03-03 17:34:05 +00003134 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003135 throw e.rethrowFromSystemServer();
Rubin Xuec32b562015-03-03 17:34:05 +00003136 }
3137 }
3138 }
3139
3140 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003141 * Called by a profile owner or device owner to retrieve the certificate installer for the user.
3142 * null if none is set.
Rubin Xuec32b562015-03-03 17:34:05 +00003143 *
Robin Lee25e26452015-06-02 09:56:29 -07003144 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003145 * @return The package name of the current delegated certificate installer, or {@code null} if
3146 * none is set.
3147 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Rubin Xuec32b562015-03-03 17:34:05 +00003148 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003149 public @Nullable String getCertInstallerPackage(@NonNull ComponentName admin)
3150 throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003151 throwIfParentInstance("getCertInstallerPackage");
Rubin Xuec32b562015-03-03 17:34:05 +00003152 if (mService != null) {
3153 try {
Robin Lee25e26452015-06-02 09:56:29 -07003154 return mService.getCertInstallerPackage(admin);
Rubin Xuec32b562015-03-03 17:34:05 +00003155 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003156 throw e.rethrowFromSystemServer();
Rubin Xuec32b562015-03-03 17:34:05 +00003157 }
3158 }
3159 return null;
3160 }
3161
3162 /**
Robin Lee244ce8e2016-01-05 18:03:46 +00003163 * Called by a device or profile owner to configure an always-on VPN connection through a
Robin Leedc679712016-05-03 13:23:03 +01003164 * specific application for the current user.
3165 *
3166 * @deprecated this version only exists for compability with previous developer preview builds.
3167 * TODO: delete once there are no longer any live references.
3168 * @hide
3169 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07003170 @Deprecated
Robin Leedc679712016-05-03 13:23:03 +01003171 public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage)
3172 throws NameNotFoundException, UnsupportedOperationException {
3173 setAlwaysOnVpnPackage(admin, vpnPackage, /* lockdownEnabled */ true);
3174 }
3175
3176 /**
3177 * Called by a device or profile owner to configure an always-on VPN connection through a
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003178 * specific application for the current user. This connection is automatically granted and
3179 * persisted after a reboot.
3180 * <p>
3181 * The designated package should declare a {@link android.net.VpnService} in its manifest
3182 * guarded by {@link android.Manifest.permission#BIND_VPN_SERVICE}, otherwise the call will
3183 * fail.
Robin Lee244ce8e2016-01-05 18:03:46 +00003184 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003185 * @param vpnPackage The package name for an installed VPN app on the device, or {@code null} to
Robin Leedc679712016-05-03 13:23:03 +01003186 * remove an existing always-on VPN configuration.
3187 * @param lockdownEnabled {@code true} to disallow networking when the VPN is not connected or
3188 * {@code false} otherwise. This carries the risk that any failure of the VPN provider
3189 * could break networking for all apps. This has no effect when clearing.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003190 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Robin Leeee5eb932016-04-05 16:27:15 +01003191 * @throws NameNotFoundException if {@code vpnPackage} is not installed.
3192 * @throws UnsupportedOperationException if {@code vpnPackage} exists but does not support being
3193 * set as always-on, or if always-on VPN is not available.
Robin Lee244ce8e2016-01-05 18:03:46 +00003194 */
Robin Leedc679712016-05-03 13:23:03 +01003195 public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage,
3196 boolean lockdownEnabled)
Robin Leeee5eb932016-04-05 16:27:15 +01003197 throws NameNotFoundException, UnsupportedOperationException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003198 throwIfParentInstance("setAlwaysOnVpnPackage");
Robin Lee244ce8e2016-01-05 18:03:46 +00003199 if (mService != null) {
3200 try {
Robin Leedc679712016-05-03 13:23:03 +01003201 if (!mService.setAlwaysOnVpnPackage(admin, vpnPackage, lockdownEnabled)) {
Robin Leeee5eb932016-04-05 16:27:15 +01003202 throw new NameNotFoundException(vpnPackage);
3203 }
Robin Lee244ce8e2016-01-05 18:03:46 +00003204 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003205 throw e.rethrowFromSystemServer();
Robin Lee244ce8e2016-01-05 18:03:46 +00003206 }
3207 }
Robin Lee244ce8e2016-01-05 18:03:46 +00003208 }
3209
3210 /**
3211 * Called by a device or profile owner to read the name of the package administering an
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003212 * always-on VPN connection for the current user. If there is no such package, or the always-on
3213 * VPN is provided by the system instead of by an application, {@code null} will be returned.
Robin Lee244ce8e2016-01-05 18:03:46 +00003214 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003215 * @return Package name of VPN controller responsible for always-on VPN, or {@code null} if none
3216 * is set.
3217 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Robin Lee244ce8e2016-01-05 18:03:46 +00003218 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003219 public @Nullable String getAlwaysOnVpnPackage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003220 throwIfParentInstance("getAlwaysOnVpnPackage");
Robin Lee244ce8e2016-01-05 18:03:46 +00003221 if (mService != null) {
3222 try {
3223 return mService.getAlwaysOnVpnPackage(admin);
3224 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003225 throw e.rethrowFromSystemServer();
Robin Lee244ce8e2016-01-05 18:03:46 +00003226 }
3227 }
3228 return null;
3229 }
3230
3231 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003232 * Called by an application that is administering the device to disable all cameras on the
3233 * device, for this user. After setting this, no applications running as this user will be able
3234 * to access any cameras on the device.
3235 * <p>
3236 * If the caller is device owner, then the restriction will be applied to all users.
3237 * <p>
3238 * The calling device admin must have requested
3239 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call this method; if it has
3240 * not, a security exception will be thrown.
Ben Komalo2447edd2011-05-09 16:05:33 -07003241 *
3242 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3243 * @param disabled Whether or not the camera should be disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003244 * @throws SecurityException if {@code admin} is not an active administrator or does not use
3245 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA}.
Ben Komalo2447edd2011-05-09 16:05:33 -07003246 */
Robin Lee25e26452015-06-02 09:56:29 -07003247 public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003248 throwIfParentInstance("setCameraDisabled");
Ben Komalo2447edd2011-05-09 16:05:33 -07003249 if (mService != null) {
3250 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003251 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07003252 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003253 throw e.rethrowFromSystemServer();
Ben Komalo2447edd2011-05-09 16:05:33 -07003254 }
3255 }
3256 }
3257
3258 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07003259 * Determine whether or not the device's cameras have been disabled for this user,
Makoto Onuki32b30572015-12-11 14:29:51 -08003260 * either by the calling admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07003261 * @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 -07003262 * have disabled the camera
3263 */
Robin Lee25e26452015-06-02 09:56:29 -07003264 public boolean getCameraDisabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003265 throwIfParentInstance("getCameraDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003266 return getCameraDisabled(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003267 }
3268
3269 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003270 public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07003271 if (mService != null) {
3272 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003273 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07003274 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003275 throw e.rethrowFromSystemServer();
Ben Komalo2447edd2011-05-09 16:05:33 -07003276 }
3277 }
3278 return false;
3279 }
3280
3281 /**
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003282 * Called by a device owner to request a bugreport.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003283 * <p>
3284 * There must be only one user on the device, managed by the device owner. Otherwise a
3285 * {@link SecurityException} will be thrown.
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003286 *
3287 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003288 * @return {@code true} if the bugreport collection started successfully, or {@code false} if it
3289 * wasn't triggered because a previous bugreport operation is still active (either the
3290 * bugreport is still running or waiting for the user to share or decline)
3291 * @throws SecurityException if {@code admin} is not a device owner, or if there are users other
3292 * than the one managed by the device owner.
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003293 */
3294 public boolean requestBugreport(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003295 throwIfParentInstance("requestBugreport");
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003296 if (mService != null) {
3297 try {
3298 return mService.requestBugreport(admin);
3299 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003300 throw e.rethrowFromSystemServer();
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003301 }
3302 }
3303 return false;
3304 }
3305
3306 /**
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07003307 * Determine whether or not creating a guest user has been disabled for the device
3308 *
3309 * @hide
3310 */
3311 public boolean getGuestUserDisabled(@Nullable ComponentName admin) {
3312 // Currently guest users can always be created if multi-user is enabled
3313 // TODO introduce a policy for guest user creation
3314 return false;
3315 }
3316
3317 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01003318 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
3319 * screen capture also prevents the content from being shown on display devices that do not have
3320 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
3321 * secure surfaces and secure displays.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003322 * <p>
3323 * The calling device admin must be a device or profile owner. If it is not, a security
3324 * exception will be thrown.
3325 * <p>
3326 * From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also blocks
3327 * assist requests for all activities of the relevant user.
Benjamin Franzc200f442015-06-25 18:20:04 +01003328 *
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003329 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003330 * @param disabled Whether screen capture is disabled or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003331 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003332 */
Robin Lee25e26452015-06-02 09:56:29 -07003333 public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003334 throwIfParentInstance("setScreenCaptureDisabled");
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003335 if (mService != null) {
3336 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003337 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003338 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003339 throw e.rethrowFromSystemServer();
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003340 }
3341 }
3342 }
3343
3344 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08003345 * Determine whether or not screen capture has been disabled by the calling
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003346 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07003347 * @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 +01003348 * have disabled screen capture.
3349 */
Robin Lee25e26452015-06-02 09:56:29 -07003350 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003351 throwIfParentInstance("getScreenCaptureDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003352 return getScreenCaptureDisabled(admin, myUserId());
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003353 }
3354
3355 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003356 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003357 if (mService != null) {
3358 try {
3359 return mService.getScreenCaptureDisabled(admin, userHandle);
3360 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003361 throw e.rethrowFromSystemServer();
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003362 }
3363 }
3364 return false;
3365 }
3366
3367 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003368 * Called by a device owner to set whether auto time is required. If auto time is required the
3369 * user cannot set the date and time, but has to use network date and time.
3370 * <p>
3371 * Note: if auto time is required the user can still manually set the time zone.
3372 * <p>
3373 * The calling device admin must be a device owner. If it is not, a security exception will be
3374 * thrown.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003375 *
3376 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3377 * @param required Whether auto time is set required or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003378 * @throws SecurityException if {@code admin} is not a device owner.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003379 */
Robin Lee25e26452015-06-02 09:56:29 -07003380 public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003381 throwIfParentInstance("setAutoTimeRequired");
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003382 if (mService != null) {
3383 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003384 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003385 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003386 throw e.rethrowFromSystemServer();
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003387 }
3388 }
3389 }
3390
3391 /**
3392 * @return true if auto time is required.
3393 */
3394 public boolean getAutoTimeRequired() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003395 throwIfParentInstance("getAutoTimeRequired");
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003396 if (mService != null) {
3397 try {
3398 return mService.getAutoTimeRequired();
3399 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003400 throw e.rethrowFromSystemServer();
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003401 }
3402 }
3403 return false;
3404 }
3405
3406 /**
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003407 * Called by a device owner to set whether all users created on the device should be ephemeral.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003408 * <p>
3409 * The system user is exempt from this policy - it is never ephemeral.
3410 * <p>
3411 * The calling device admin must be the device owner. If it is not, a security exception will be
3412 * thrown.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003413 *
3414 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3415 * @param forceEphemeralUsers If true, all the existing users will be deleted and all
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003416 * subsequently created users will be ephemeral.
3417 * @throws SecurityException if {@code admin} is not a device owner.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003418 * @hide
3419 */
3420 public void setForceEphemeralUsers(
3421 @NonNull ComponentName admin, boolean forceEphemeralUsers) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003422 throwIfParentInstance("setForceEphemeralUsers");
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003423 if (mService != null) {
3424 try {
3425 mService.setForceEphemeralUsers(admin, forceEphemeralUsers);
3426 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003427 throw e.rethrowFromSystemServer();
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003428 }
3429 }
3430 }
3431
3432 /**
3433 * @return true if all users are created ephemeral.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003434 * @throws SecurityException if {@code admin} is not a device owner.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003435 * @hide
3436 */
3437 public boolean getForceEphemeralUsers(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003438 throwIfParentInstance("getForceEphemeralUsers");
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003439 if (mService != null) {
3440 try {
3441 return mService.getForceEphemeralUsers(admin);
3442 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003443 throw e.rethrowFromSystemServer();
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003444 }
3445 }
3446 return false;
3447 }
3448
3449 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07003450 * Called by an application that is administering the device to disable keyguard customizations,
3451 * such as widgets. After setting this, keyguard features will be disabled according to the
3452 * provided feature list.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003453 * <p>
3454 * The calling device admin must have requested
3455 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method;
3456 * if it has not, a security exception will be thrown.
3457 * <p>
3458 * Calling this from a managed profile before version {@link android.os.Build.VERSION_CODES#M}
3459 * will throw a security exception. From version {@link android.os.Build.VERSION_CODES#M} the
3460 * profile owner of a managed profile can set:
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003461 * <ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00003462 * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which affects the parent user, but only if there
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003463 * is no separate challenge set on the managed profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00003464 * <li>{@link #KEYGUARD_DISABLE_FINGERPRINT} which affects the managed profile challenge if
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003465 * there is one, or the parent user otherwise.
3466 * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} which affects notifications generated
3467 * by applications in the managed profile.
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003468 * </ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00003469 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} and {@link #KEYGUARD_DISABLE_FINGERPRINT} can also be
3470 * set on the {@link DevicePolicyManager} instance returned by
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003471 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
3472 * profile.
3473 * <p>
3474 * Requests to disable other features on a managed profile will be ignored.
3475 * <p>
3476 * The admin can check which features have been disabled by calling
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003477 * {@link #getKeyguardDisabledFeatures(ComponentName)}
Amith Yamasani242f4b12014-10-14 16:06:13 -07003478 *
Jim Millerb8ec4702012-08-31 17:19:10 -07003479 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07003480 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003481 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
3482 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS},
3483 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
3484 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS},
3485 * {@link #KEYGUARD_DISABLE_FINGERPRINT}, {@link #KEYGUARD_DISABLE_FEATURES_ALL}
3486 * @throws SecurityException if {@code admin} is not an active administrator or does not user
3487 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES}
Jim Millerb8ec4702012-08-31 17:19:10 -07003488 */
Robin Lee25e26452015-06-02 09:56:29 -07003489 public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07003490 if (mService != null) {
3491 try {
Esteban Talavera62399912016-01-11 15:37:55 +00003492 mService.setKeyguardDisabledFeatures(admin, which, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07003493 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003494 throw e.rethrowFromSystemServer();
Jim Millerb8ec4702012-08-31 17:19:10 -07003495 }
3496 }
3497 }
3498
3499 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08003500 * Determine whether or not features have been disabled in keyguard either by the calling
Rubin Xud3609d42016-07-13 18:32:57 +01003501 * admin, if specified, or all admins that set restrictions on this user and its participating
Esteban Talaverac1c83592016-02-17 17:56:15 +00003502 * profiles. Restrictions on profiles that have a separate challenge are not taken into account.
3503 *
3504 * <p>This method can be called on the {@link DevicePolicyManager} instance
3505 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
3506 * restrictions on the parent profile.
3507 *
Esteban Talavera62399912016-01-11 15:37:55 +00003508 * @param admin The name of the admin component to check, or {@code null} to check whether any
3509 * admins have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07003510 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
3511 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07003512 */
Robin Lee25e26452015-06-02 09:56:29 -07003513 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003514 return getKeyguardDisabledFeatures(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003515 }
3516
3517 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003518 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07003519 if (mService != null) {
3520 try {
Esteban Talavera62399912016-01-11 15:37:55 +00003521 return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07003522 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003523 throw e.rethrowFromSystemServer();
Jim Millerb8ec4702012-08-31 17:19:10 -07003524 }
3525 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07003526 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07003527 }
3528
3529 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08003530 * @hide
3531 */
Robin Lee25e26452015-06-02 09:56:29 -07003532 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
3533 int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003534 if (mService != null) {
3535 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01003536 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003537 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003538 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003539 }
3540 }
3541 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003542
Dianne Hackbornd6847842010-01-12 18:14:19 -08003543 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01003544 * @hide
3545 */
Robin Lee25e26452015-06-02 09:56:29 -07003546 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003547 setActiveAdmin(policyReceiver, refreshing, myUserId());
Jessica Hummel6d36b602014-04-04 12:42:17 +01003548 }
3549
3550 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08003551 * @hide
3552 */
Robin Lee25e26452015-06-02 09:56:29 -07003553 public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08003554 if (mService != null) {
3555 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003556 mService.getRemoveWarning(admin, result, myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08003557 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003558 throw e.rethrowFromSystemServer();
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08003559 }
3560 }
3561 }
3562
3563 /**
3564 * @hide
3565 */
Andrew Scull5f9e6f32016-08-02 14:22:17 +01003566 public void setActivePasswordState(PasswordMetrics metrics, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003567 if (mService != null) {
3568 try {
Andrew Scull5f9e6f32016-08-02 14:22:17 +01003569 mService.setActivePasswordState(metrics, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003570 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003571 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003572 }
3573 }
3574 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003575
Dianne Hackbornd6847842010-01-12 18:14:19 -08003576 /**
3577 * @hide
3578 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003579 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003580 if (mService != null) {
3581 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003582 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003583 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003584 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003585 }
3586 }
3587 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003588
Dianne Hackbornd6847842010-01-12 18:14:19 -08003589 /**
3590 * @hide
3591 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003592 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003593 if (mService != null) {
3594 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003595 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003596 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003597 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003598 }
3599 }
3600 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07003601
3602 /**
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003603 * @hide
3604 */
3605 public void reportFailedFingerprintAttempt(int userHandle) {
3606 if (mService != null) {
3607 try {
3608 mService.reportFailedFingerprintAttempt(userHandle);
3609 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003610 throw e.rethrowFromSystemServer();
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003611 }
3612 }
3613 }
3614
3615 /**
3616 * @hide
3617 */
3618 public void reportSuccessfulFingerprintAttempt(int userHandle) {
3619 if (mService != null) {
3620 try {
3621 mService.reportSuccessfulFingerprintAttempt(userHandle);
3622 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003623 throw e.rethrowFromSystemServer();
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003624 }
3625 }
3626 }
3627
3628 /**
Michal Karpinski31502d32016-01-25 16:43:07 +00003629 * Should be called when keyguard has been dismissed.
3630 * @hide
3631 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003632 public void reportKeyguardDismissed(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00003633 if (mService != null) {
3634 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003635 mService.reportKeyguardDismissed(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00003636 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003637 throw e.rethrowFromSystemServer();
Michal Karpinski31502d32016-01-25 16:43:07 +00003638 }
3639 }
3640 }
3641
3642 /**
3643 * Should be called when keyguard view has been shown to the user.
3644 * @hide
3645 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003646 public void reportKeyguardSecured(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00003647 if (mService != null) {
3648 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003649 mService.reportKeyguardSecured(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00003650 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003651 throw e.rethrowFromSystemServer();
Michal Karpinski31502d32016-01-25 16:43:07 +00003652 }
3653 }
3654 }
3655
3656 /**
Amith Yamasani71e6c692013-03-24 17:39:28 -07003657 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00003658 * Sets the given package as the device owner.
Makoto Onukia52562c2015-10-01 16:12:31 -07003659 * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name.
3660 * @param who the component name to be registered as device owner.
Amith Yamasani71e6c692013-03-24 17:39:28 -07003661 * @return whether the package was successfully registered as the device owner.
3662 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00003663 * @throws IllegalStateException If the preconditions mentioned are not met.
Amith Yamasani71e6c692013-03-24 17:39:28 -07003664 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003665 public boolean setDeviceOwner(ComponentName who) {
3666 return setDeviceOwner(who, null);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003667 }
3668
3669 /**
3670 * @hide
Makoto Onuki58b684f2015-09-04 10:48:16 -07003671 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003672 public boolean setDeviceOwner(ComponentName who, int userId) {
3673 return setDeviceOwner(who, null, userId);
Makoto Onuki58b684f2015-09-04 10:48:16 -07003674 }
3675
3676 /**
3677 * @hide
3678 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003679 public boolean setDeviceOwner(ComponentName who, String ownerName) {
3680 return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM);
Makoto Onuki58b684f2015-09-04 10:48:16 -07003681 }
3682
3683 /**
3684 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00003685 * Sets the given package as the device owner. The package must already be installed. There
3686 * must not already be a device owner.
3687 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
3688 * this method.
3689 * Calling this after the setup phase of the primary user has completed is allowed only if
3690 * the caller is the shell uid, and there are no additional users and no accounts.
Makoto Onukia52562c2015-10-01 16:12:31 -07003691 * @param who the component name to be registered as device owner.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003692 * @param ownerName the human readable name of the institution that owns this device.
Makoto Onuki58b684f2015-09-04 10:48:16 -07003693 * @param userId ID of the user on which the device owner runs.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003694 * @return whether the package was successfully registered as the device owner.
3695 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00003696 * @throws IllegalStateException If the preconditions mentioned are not met.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003697 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003698 public boolean setDeviceOwner(ComponentName who, String ownerName, int userId)
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003699 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07003700 if (mService != null) {
3701 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07003702 return mService.setDeviceOwner(who, ownerName, userId);
Amith Yamasani71e6c692013-03-24 17:39:28 -07003703 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003704 throw re.rethrowFromSystemServer();
Amith Yamasani71e6c692013-03-24 17:39:28 -07003705 }
3706 }
3707 return false;
3708 }
3709
3710 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003711 * Used to determine if a particular package has been registered as a Device Owner app.
3712 * A device owner app is a special device admin that cannot be deactivated by the user, once
Robin Lee25e26452015-06-02 09:56:29 -07003713 * activated as a device admin. It also cannot be uninstalled. To check whether a particular
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003714 * package is currently registered as the device owner app, pass in the package name from
3715 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
Robin Lee25e26452015-06-02 09:56:29 -07003716 * admin apps that want to check whether they are also registered as the device owner app. The
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003717 * exact mechanism by which a device admin app is registered as a device owner app is defined by
3718 * the setup process.
3719 * @param packageName the package name of the app, to compare with the registered device owner
3720 * app, if any.
Makoto Onukic8a5a552015-11-19 14:29:12 -08003721 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07003722 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003723 public boolean isDeviceOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003724 throwIfParentInstance("isDeviceOwnerApp");
Makoto Onukic8a5a552015-11-19 14:29:12 -08003725 return isDeviceOwnerAppOnCallingUser(packageName);
3726 }
3727
3728 /**
3729 * @return true if a package is registered as device owner, only when it's running on the
3730 * calling user.
3731 *
3732 * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity.
3733 * @hide
3734 */
3735 public boolean isDeviceOwnerAppOnCallingUser(String packageName) {
3736 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true);
3737 }
3738
3739 /**
3740 * @return true if a package is registered as device owner, even if it's running on a different
3741 * user.
3742 *
3743 * <p>Requires the MANAGE_USERS permission.
3744 *
3745 * @hide
3746 */
3747 public boolean isDeviceOwnerAppOnAnyUser(String packageName) {
3748 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false);
3749 }
3750
3751 /**
3752 * @return device owner component name, only when it's running on the calling user.
3753 *
3754 * @hide
3755 */
3756 public ComponentName getDeviceOwnerComponentOnCallingUser() {
3757 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true);
3758 }
3759
3760 /**
3761 * @return device owner component name, even if it's running on a different user.
3762 *
3763 * <p>Requires the MANAGE_USERS permission.
3764 *
3765 * @hide
3766 */
3767 public ComponentName getDeviceOwnerComponentOnAnyUser() {
3768 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false);
3769 }
3770
3771 private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) {
Makoto Onuki70f929e2015-11-11 12:40:15 -08003772 if (packageName == null) {
3773 return false;
Amith Yamasani71e6c692013-03-24 17:39:28 -07003774 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08003775 final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly);
Makoto Onuki70f929e2015-11-11 12:40:15 -08003776 if (deviceOwner == null) {
3777 return false;
3778 }
3779 return packageName.equals(deviceOwner.getPackageName());
Amith Yamasani71e6c692013-03-24 17:39:28 -07003780 }
3781
Makoto Onukic8a5a552015-11-19 14:29:12 -08003782 private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) {
3783 if (mService != null) {
3784 try {
3785 return mService.getDeviceOwnerComponent(callingUserOnly);
3786 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003787 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08003788 }
3789 }
3790 return null;
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003791 }
3792
Jason Monkb0dced82014-06-06 14:36:20 -04003793 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08003794 * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's
3795 * no device owner.
3796 *
3797 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07003798 *
3799 * @hide
3800 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08003801 public int getDeviceOwnerUserId() {
3802 if (mService != null) {
3803 try {
3804 return mService.getDeviceOwnerUserId();
3805 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003806 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08003807 }
3808 }
3809 return UserHandle.USER_NULL;
Makoto Onukia52562c2015-10-01 16:12:31 -07003810 }
3811
3812 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003813 * Clears the current device owner. The caller must be the device owner. This function should be
3814 * used cautiously as once it is called it cannot be undone. The device owner can only be set as
3815 * a part of device setup before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04003816 *
3817 * @param packageName The package name of the device owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003818 * @throws SecurityException if the caller is not in {@code packageName} or {@code packageName}
3819 * does not own the current device owner component.
Jason Monkb0dced82014-06-06 14:36:20 -04003820 */
Jason Monk94d2cf92014-06-18 09:53:34 -04003821 public void clearDeviceOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003822 throwIfParentInstance("clearDeviceOwnerApp");
Jason Monkb0dced82014-06-06 14:36:20 -04003823 if (mService != null) {
3824 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04003825 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04003826 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003827 throw re.rethrowFromSystemServer();
Jason Monkb0dced82014-06-06 14:36:20 -04003828 }
3829 }
3830 }
3831
Makoto Onukia52562c2015-10-01 16:12:31 -07003832 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08003833 * Returns the device owner package name, only if it's running on the calling user.
3834 *
3835 * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity.
Makoto Onukia52562c2015-10-01 16:12:31 -07003836 *
3837 * @hide
3838 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01003839 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07003840 public @Nullable String getDeviceOwner() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003841 throwIfParentInstance("getDeviceOwner");
Makoto Onukic8a5a552015-11-19 14:29:12 -08003842 final ComponentName name = getDeviceOwnerComponentOnCallingUser();
3843 return name != null ? name.getPackageName() : null;
Makoto Onukia52562c2015-10-01 16:12:31 -07003844 }
3845
3846 /**
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01003847 * Called by the system to find out whether the device is managed by a Device Owner.
Makoto Onukic8a5a552015-11-19 14:29:12 -08003848 *
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01003849 * @return whether the device is managed by a Device Owner.
3850 * @throws SecurityException if the caller is not the device owner, does not hold the
3851 * MANAGE_USERS permission and is not the system.
Makoto Onukia52562c2015-10-01 16:12:31 -07003852 *
3853 * @hide
3854 */
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01003855 @SystemApi
3856 @TestApi
Makoto Onukic8a5a552015-11-19 14:29:12 -08003857 public boolean isDeviceManaged() {
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01003858 try {
3859 return mService.hasDeviceOwner();
3860 } catch (RemoteException re) {
3861 throw re.rethrowFromSystemServer();
3862 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08003863 }
3864
3865 /**
3866 * Returns the device owner name. Note this method *will* return the device owner
3867 * name when it's running on a different user.
3868 *
3869 * <p>Requires the MANAGE_USERS permission.
3870 *
3871 * @hide
3872 */
Makoto Onukia2b274b2016-01-19 13:26:02 -08003873 @SystemApi
Makoto Onukic8a5a552015-11-19 14:29:12 -08003874 public String getDeviceOwnerNameOnAnyUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003875 throwIfParentInstance("getDeviceOwnerNameOnAnyUser");
Amith Yamasani71e6c692013-03-24 17:39:28 -07003876 if (mService != null) {
3877 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07003878 return mService.getDeviceOwnerName();
Amith Yamasani71e6c692013-03-24 17:39:28 -07003879 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003880 throw re.rethrowFromSystemServer();
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003881 }
3882 }
3883 return null;
3884 }
Adam Connors776c5552014-01-09 10:42:56 +00003885
3886 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04003887 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003888 * @deprecated Do not use
3889 * @removed
Julia Reynolds20118f12015-02-11 12:34:08 -05003890 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003891 @Deprecated
Julia Reynolds20118f12015-02-11 12:34:08 -05003892 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07003893 public @Nullable String getDeviceInitializerApp() {
Julia Reynolds20118f12015-02-11 12:34:08 -05003894 return null;
3895 }
3896
3897 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003898 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003899 * @deprecated Do not use
3900 * @removed
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003901 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003902 @Deprecated
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003903 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07003904 public @Nullable ComponentName getDeviceInitializerComponent() {
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003905 return null;
3906 }
3907
Julia Reynolds20118f12015-02-11 12:34:08 -05003908 /**
Adam Connors776c5552014-01-09 10:42:56 +00003909 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003910 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303911 * Sets the given component as an active admin and registers the package as the profile
3912 * owner for this user. The package must already be installed and there shouldn't be
3913 * an existing profile owner registered for this user. Also, this method must be called
3914 * before the user setup has been completed.
3915 * <p>
3916 * This method can only be called by system apps that hold MANAGE_USERS permission and
3917 * MANAGE_DEVICE_ADMINS permission.
3918 * @param admin The component to register as an active admin and profile owner.
3919 * @param ownerName The user-visible name of the entity that is managing this user.
3920 * @return whether the admin was successfully registered as the profile owner.
3921 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
3922 * the user has already been set up.
3923 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07003924 @Deprecated
Justin Morey80440cc2014-07-24 09:16:35 -05003925 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07003926 public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303927 throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003928 throwIfParentInstance("setActiveProfileOwner");
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303929 if (mService != null) {
3930 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003931 final int myUserId = myUserId();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303932 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003933 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303934 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003935 throw re.rethrowFromSystemServer();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303936 }
3937 }
3938 return false;
3939 }
3940
3941 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003942 * Clears the active profile owner and removes all user restrictions. The caller must be from
3943 * the same package as the active profile owner for this user, otherwise a SecurityException
3944 * will be thrown.
3945 * <p>
3946 * This doesn't work for managed profile owners.
Makoto Onuki5bf68022016-01-27 13:49:19 -08003947 *
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003948 * @param admin The component to remove as the profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003949 * @throws SecurityException if {@code admin} is not an active profile owner.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003950 */
Robin Lee25e26452015-06-02 09:56:29 -07003951 public void clearProfileOwner(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003952 throwIfParentInstance("clearProfileOwner");
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003953 if (mService != null) {
3954 try {
3955 mService.clearProfileOwner(admin);
3956 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003957 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003958 }
3959 }
3960 }
3961
3962 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05003963 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003964 * Checks whether the user was already setup.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003965 */
3966 public boolean hasUserSetupCompleted() {
3967 if (mService != null) {
3968 try {
3969 return mService.hasUserSetupCompleted();
3970 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003971 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003972 }
3973 }
3974 return true;
3975 }
3976
3977 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003978 * @hide
3979 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00003980 * already be installed. There must not already be a profile owner for this user.
3981 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
3982 * this method.
3983 * Calling this after the setup phase of the specified user has completed is allowed only if:
3984 * - the caller is SYSTEM_UID.
3985 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003986 * @param admin the component name to be registered as profile owner.
3987 * @param ownerName the human readable name of the organisation associated with this DPM.
3988 * @param userHandle the userId to set the profile owner for.
3989 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00003990 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
3991 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003992 */
Robin Lee25e26452015-06-02 09:56:29 -07003993 public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName,
Robin Leeddd553f2015-04-30 14:18:22 +01003994 int userHandle) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00003995 if (mService != null) {
3996 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003997 if (ownerName == null) {
3998 ownerName = "";
3999 }
4000 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00004001 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004002 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004003 }
4004 }
4005 return false;
4006 }
4007
4008 /**
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004009 * Sets the device owner information to be shown on the lock screen.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004010 * <p>
4011 * If the device owner information is {@code null} or empty then the device owner info is
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004012 * cleared and the user owner info is shown on the lock screen if it is set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004013 * <p>
4014 * If the device owner information contains only whitespaces then the message on the lock screen
4015 * will be blank and the user will not be allowed to change it.
4016 * <p>
4017 * If the device owner information needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00004018 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
4019 * and set a new version of this string accordingly.
4020 *
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004021 * @param admin The name of the admin component to check.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004022 * @param info Device owner information which will be displayed instead of the user owner info.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004023 * @throws SecurityException if {@code admin} is not a device owner.
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004024 */
Andrei Stingaceanu16187902016-03-21 15:44:45 +00004025 public void setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, CharSequence info) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004026 throwIfParentInstance("setDeviceOwnerLockScreenInfo");
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004027 if (mService != null) {
4028 try {
Andrei Stingaceanu16187902016-03-21 15:44:45 +00004029 mService.setDeviceOwnerLockScreenInfo(admin, info);
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004030 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004031 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004032 }
4033 }
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004034 }
4035
4036 /**
4037 * @return The device owner information. If it is not set returns {@code null}.
4038 */
Andrei Stingaceanu16187902016-03-21 15:44:45 +00004039 public CharSequence getDeviceOwnerLockScreenInfo() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004040 throwIfParentInstance("getDeviceOwnerLockScreenInfo");
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004041 if (mService != null) {
4042 try {
4043 return mService.getDeviceOwnerLockScreenInfo();
4044 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004045 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004046 }
4047 }
4048 return null;
4049 }
4050
4051 /**
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004052 * Called by device or profile owners to suspend packages for this user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004053 * <p>
4054 * A suspended package will not be able to start activities. Its notifications will be hidden,
4055 * it will not show up in recents, will not be able to show toasts or dialogs or ring the
4056 * device.
4057 * <p>
4058 * The package must already be installed. If the package is uninstalled while suspended the
4059 * package will no longer be suspended. The admin can block this by using
Kenny Guy871f3eb2016-03-09 20:06:16 +00004060 * {@link #setUninstallBlocked}.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004061 *
4062 * @param admin The name of the admin component to check.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004063 * @param packageNames The package names to suspend or unsuspend.
4064 * @param suspended If set to {@code true} than the packages will be suspended, if set to
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004065 * {@code false} the packages will be unsuspended.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004066 * @return an array of package names for which the suspended status is not set as requested in
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004067 * this method.
4068 * @throws SecurityException if {@code admin} is not a device or profile owner.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004069 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004070 public @NonNull String[] setPackagesSuspended(@NonNull ComponentName admin,
4071 @NonNull String[] packageNames, boolean suspended) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004072 throwIfParentInstance("setPackagesSuspended");
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004073 if (mService != null) {
4074 try {
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004075 return mService.setPackagesSuspended(admin, packageNames, suspended);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004076 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004077 throw re.rethrowFromSystemServer();
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004078 }
4079 }
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004080 return packageNames;
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004081 }
4082
4083 /**
4084 * Called by device or profile owners to determine if a package is suspended.
4085 *
4086 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4087 * @param packageName The name of the package to retrieve the suspended status of.
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00004088 * @return {@code true} if the package is suspended or {@code false} if the package is not
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004089 * suspended, could not be found or an error occurred.
4090 * @throws SecurityException if {@code admin} is not a device or profile owner.
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004091 * @throws NameNotFoundException if the package could not be found.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004092 */
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004093 public boolean isPackageSuspended(@NonNull ComponentName admin, String packageName)
4094 throws NameNotFoundException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004095 throwIfParentInstance("isPackageSuspended");
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004096 if (mService != null) {
4097 try {
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004098 return mService.isPackageSuspended(admin, packageName);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004099 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004100 throw e.rethrowFromSystemServer();
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004101 } catch (IllegalArgumentException ex) {
4102 throw new NameNotFoundException(packageName);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004103 }
4104 }
4105 return false;
4106 }
4107
4108 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004109 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
4110 * be used. Only the profile owner can call this.
4111 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01004112 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004113 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004114 * @throws SecurityException if {@code admin} is not a profile owner.
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004115 */
Robin Lee25e26452015-06-02 09:56:29 -07004116 public void setProfileEnabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004117 throwIfParentInstance("setProfileEnabled");
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004118 if (mService != null) {
4119 try {
4120 mService.setProfileEnabled(admin);
4121 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004122 throw e.rethrowFromSystemServer();
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004123 }
4124 }
4125 }
4126
4127 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004128 * Sets the name of the profile. In the device owner case it sets the name of the user which it
4129 * is called from. Only a profile owner or device owner can call this. If this is never called
4130 * by the profile or device owner, the name will be set to default values.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004131 *
4132 * @see #isProfileOwnerApp
4133 * @see #isDeviceOwnerApp
Robin Lee25e26452015-06-02 09:56:29 -07004134 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004135 * @param profileName The name of the profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004136 * @throws SecurityException if {@code admin} is not a device or profile owner.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004137 */
Robin Lee25e26452015-06-02 09:56:29 -07004138 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004139 throwIfParentInstance("setProfileName");
Jessica Hummel1333ea12014-06-23 11:20:10 +01004140 if (mService != null) {
4141 try {
Robin Lee25e26452015-06-02 09:56:29 -07004142 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07004143 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004144 throw e.rethrowFromSystemServer();
Fyodor Kupolov78f13142015-05-27 16:52:45 -07004145 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01004146 }
4147 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01004148
4149 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004150 * Used to determine if a particular package is registered as the profile owner for the
Makoto Onuki32b30572015-12-11 14:29:51 -08004151 * user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004152 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00004153 *
4154 * @param packageName The package name of the app to compare with the registered profile owner.
4155 * @return Whether or not the package is registered as the profile owner.
4156 */
4157 public boolean isProfileOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004158 throwIfParentInstance("isProfileOwnerApp");
Adam Connors776c5552014-01-09 10:42:56 +00004159 if (mService != null) {
4160 try {
Makoto Onuki90b89652016-01-28 14:44:18 -08004161 ComponentName profileOwner = mService.getProfileOwner(myUserId());
Nicolas Prevot90af6d72014-07-30 14:19:12 +01004162 return profileOwner != null
4163 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00004164 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004165 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004166 }
4167 }
4168 return false;
4169 }
4170
4171 /**
4172 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07004173 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00004174 * owner has been set for that user.
4175 * @throws IllegalArgumentException if the userId is invalid.
4176 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01004177 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004178 public @Nullable ComponentName getProfileOwner() throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004179 throwIfParentInstance("getProfileOwner");
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01004180 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
4181 }
4182
4183 /**
4184 * @see #getProfileOwner()
4185 * @hide
4186 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004187 public @Nullable ComponentName getProfileOwnerAsUser(final int userId)
4188 throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00004189 if (mService != null) {
4190 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01004191 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00004192 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004193 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004194 }
4195 }
4196 return null;
4197 }
4198
4199 /**
4200 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07004201 * @return the human readable name of the organisation associated with this DPM or {@code null}
4202 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00004203 * @throws IllegalArgumentException if the userId is invalid.
4204 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004205 public @Nullable String getProfileOwnerName() throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00004206 if (mService != null) {
4207 try {
4208 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
4209 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004210 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004211 }
4212 }
4213 return null;
4214 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004215
4216 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07004217 * @hide
Makoto Onukic8a5a552015-11-19 14:29:12 -08004218 * @param userId The user for whom to fetch the profile owner name, if any.
Amith Yamasani38f836b2014-08-20 14:51:15 -07004219 * @return the human readable name of the organisation associated with this profile owner or
4220 * null if one is not set.
4221 * @throws IllegalArgumentException if the userId is invalid.
4222 */
4223 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004224 public @Nullable String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004225 throwIfParentInstance("getProfileOwnerNameAsUser");
Amith Yamasani38f836b2014-08-20 14:51:15 -07004226 if (mService != null) {
4227 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02004228 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07004229 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004230 throw re.rethrowFromSystemServer();
Amith Yamasani38f836b2014-08-20 14:51:15 -07004231 }
4232 }
4233 return null;
4234 }
4235
4236 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004237 * Called by a profile owner or device owner to add a default intent handler activity for
4238 * intents that match a certain intent filter. This activity will remain the default intent
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004239 * handler even if the set of potential event handlers for the intent filter changes and if the
4240 * intent preferences are reset.
4241 * <p>
4242 * The default disambiguation mechanism takes over if the activity is not installed (anymore).
4243 * When the activity is (re)installed, it is automatically reset as default intent handler for
4244 * the filter.
4245 * <p>
4246 * The calling device admin must be a profile owner or device owner. If it is not, a security
4247 * exception will be thrown.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004248 *
4249 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4250 * @param filter The IntentFilter for which a default handler is added.
4251 * @param activity The Activity that is added as default intent handler.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004252 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004253 */
Robin Lee25e26452015-06-02 09:56:29 -07004254 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
4255 @NonNull ComponentName activity) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004256 throwIfParentInstance("addPersistentPreferredActivity");
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004257 if (mService != null) {
4258 try {
4259 mService.addPersistentPreferredActivity(admin, filter, activity);
4260 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004261 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004262 }
4263 }
4264 }
4265
4266 /**
4267 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00004268 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004269 * <p>
4270 * The calling device admin must be a profile owner. If it is not, a security exception will be
4271 * thrown.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004272 *
4273 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4274 * @param packageName The name of the package for which preferences are removed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004275 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004276 */
Robin Lee25e26452015-06-02 09:56:29 -07004277 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004278 String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004279 throwIfParentInstance("clearPackagePersistentPreferredActivities");
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004280 if (mService != null) {
4281 try {
4282 mService.clearPackagePersistentPreferredActivities(admin, packageName);
4283 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004284 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004285 }
4286 }
4287 }
Robin Lee66e5d962014-04-09 16:44:21 +01004288
4289 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00004290 * Called by a profile owner or device owner to grant permission to a package to manage
4291 * application restrictions for the calling user via {@link #setApplicationRestrictions} and
4292 * {@link #getApplicationRestrictions}.
4293 * <p>
4294 * This permission is persistent until it is later cleared by calling this method with a
4295 * {@code null} value or uninstalling the managing package.
Rubin Xuf03d0a62016-02-10 14:54:15 +00004296 * <p>
4297 * The supplied application restriction managing package must be installed when calling this
Victor Changcd14c0a2016-03-16 19:10:15 +00004298 * API, otherwise an {@link NameNotFoundException} will be thrown.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004299 *
4300 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4301 * @param packageName The package name which will be given access to application restrictions
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004302 * APIs. If {@code null} is given the current package will be cleared.
4303 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Changcd14c0a2016-03-16 19:10:15 +00004304 * @throws NameNotFoundException if {@code packageName} is not found
Esteban Talaverabf60f722015-12-10 16:26:44 +00004305 */
4306 public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin,
Victor Changcd14c0a2016-03-16 19:10:15 +00004307 @Nullable String packageName) throws NameNotFoundException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004308 throwIfParentInstance("setApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00004309 if (mService != null) {
4310 try {
Victor Changcd14c0a2016-03-16 19:10:15 +00004311 if (!mService.setApplicationRestrictionsManagingPackage(admin, packageName)) {
4312 throw new NameNotFoundException(packageName);
4313 }
Esteban Talaverabf60f722015-12-10 16:26:44 +00004314 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004315 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00004316 }
4317 }
4318 }
4319
4320 /**
4321 * Called by a profile owner or device owner to retrieve the application restrictions managing
4322 * package for the current user, or {@code null} if none is set.
4323 *
4324 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4325 * @return The package name allowed to manage application restrictions on the current user, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004326 * {@code null} if none is set.
4327 * @throws SecurityException if {@code admin} is not a device or profile owner.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004328 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004329 public @Nullable String getApplicationRestrictionsManagingPackage(
4330 @NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004331 throwIfParentInstance("getApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00004332 if (mService != null) {
4333 try {
4334 return mService.getApplicationRestrictionsManagingPackage(admin);
4335 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004336 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00004337 }
4338 }
4339 return null;
4340 }
4341
4342 /**
Esteban Talavera96895ca2016-03-16 12:00:40 +00004343 * Called by any application to find out whether it has been granted permission via
4344 * {@link #setApplicationRestrictionsManagingPackage} to manage application restrictions
4345 * for the calling user.
4346 *
4347 * <p>This is done by comparing the calling Linux uid with the uid of the package specified by
4348 * that method.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004349 */
4350 public boolean isCallerApplicationRestrictionsManagingPackage() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004351 throwIfParentInstance("isCallerApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00004352 if (mService != null) {
4353 try {
4354 return mService.isCallerApplicationRestrictionsManagingPackage();
4355 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004356 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00004357 }
4358 }
4359 return false;
4360 }
4361
4362 /**
4363 * Sets the application restrictions for a given target application running in the calling user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004364 * <p>
4365 * The caller must be a profile or device owner on that user, or the package allowed to manage
4366 * application restrictions via {@link #setApplicationRestrictionsManagingPackage}; otherwise a
4367 * security exception will be thrown.
4368 * <p>
4369 * The provided {@link Bundle} consists of key-value pairs, where the types of values may be:
Esteban Talavera6b8e0642015-08-10 17:26:04 +01004370 * <ul>
4371 * <li>{@code boolean}
4372 * <li>{@code int}
4373 * <li>{@code String} or {@code String[]}
4374 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
4375 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004376 * <p>
4377 * If the restrictions are not available yet, but may be applied in the near future, the caller
4378 * can notify the target application of that by adding
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00004379 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004380 * <p>
4381 * The application restrictions are only made visible to the target application via
4382 * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or device
4383 * owner, and the application restrictions managing package via
Esteban Talaverabf60f722015-12-10 16:26:44 +00004384 * {@link #getApplicationRestrictions}.
Robin Lee66e5d962014-04-09 16:44:21 +01004385 *
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07004386 * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
4387 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00004388 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004389 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01004390 * @param packageName The name of the package to update restricted settings for.
4391 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004392 * set of active restrictions.
4393 * @throws SecurityException if {@code admin} is not a device or profile owner.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004394 * @see #setApplicationRestrictionsManagingPackage
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00004395 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01004396 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07004397 @WorkerThread
Esteban Talaverabf60f722015-12-10 16:26:44 +00004398 public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01004399 Bundle settings) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004400 throwIfParentInstance("setApplicationRestrictions");
Robin Lee66e5d962014-04-09 16:44:21 +01004401 if (mService != null) {
4402 try {
4403 mService.setApplicationRestrictions(admin, packageName, settings);
4404 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004405 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01004406 }
4407 }
4408 }
4409
4410 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004411 * Sets a list of configuration features to enable for a TrustAgent component. This is meant to
4412 * be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all trust
4413 * agents but those enabled by this function call. If flag
Jim Millere303bf42014-08-26 17:12:29 -07004414 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004415 * <p>
4416 * The calling device admin must have requested
4417 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method;
4418 * if not, a security exception will be thrown.
Tony Mak089d8402016-04-05 17:42:55 +01004419 * <p>
4420 * This method can be called on the {@link DevicePolicyManager} instance returned by
4421 * {@link #getParentProfileInstance(ComponentName)} in order to set the configuration for
4422 * the parent profile.
Jim Miller604e7552014-07-18 19:00:02 -07004423 *
4424 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07004425 * @param target Component name of the agent to be enabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004426 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent will be
4427 * strictly disabled according to the state of the
4428 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
4429 * <p>
4430 * If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all
4431 * admins, then it's up to the TrustAgent itself to aggregate the values from all
4432 * device admins.
4433 * <p>
4434 * Consult documentation for the specific TrustAgent to determine legal options
4435 * parameters.
4436 * @throws SecurityException if {@code admin} is not an active administrator or does not use
4437 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES}
Jim Miller604e7552014-07-18 19:00:02 -07004438 */
Robin Lee25e26452015-06-02 09:56:29 -07004439 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
4440 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07004441 if (mService != null) {
4442 try {
Tony Mak089d8402016-04-05 17:42:55 +01004443 mService.setTrustAgentConfiguration(admin, target, configuration, mParentInstance);
Jim Miller604e7552014-07-18 19:00:02 -07004444 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004445 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07004446 }
4447 }
4448 }
4449
4450 /**
Jim Millere303bf42014-08-26 17:12:29 -07004451 * Gets configuration for the given trust agent based on aggregating all calls to
4452 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
4453 * all device admins.
Tony Mak089d8402016-04-05 17:42:55 +01004454 * <p>
4455 * This method can be called on the {@link DevicePolicyManager} instance returned by
4456 * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the configuration set
4457 * on the parent profile.
Jim Miller604e7552014-07-18 19:00:02 -07004458 *
Jim Millerb5db57a2015-01-14 18:17:19 -08004459 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
4460 * this function returns a list of configurations for all admins that declare
4461 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
4462 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
4463 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
4464 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07004465 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07004466 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07004467 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004468 public @Nullable List<PersistableBundle> getTrustAgentConfiguration(
4469 @Nullable ComponentName admin, @NonNull ComponentName agent) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004470 return getTrustAgentConfiguration(admin, agent, myUserId());
Jim Millere303bf42014-08-26 17:12:29 -07004471 }
4472
4473 /** @hide per-user version */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004474 public @Nullable List<PersistableBundle> getTrustAgentConfiguration(
4475 @Nullable ComponentName admin, @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07004476 if (mService != null) {
4477 try {
Tony Mak089d8402016-04-05 17:42:55 +01004478 return mService.getTrustAgentConfiguration(admin, agent, userHandle,
4479 mParentInstance);
Jim Miller604e7552014-07-18 19:00:02 -07004480 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004481 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07004482 }
4483 }
Jim Millere303bf42014-08-26 17:12:29 -07004484 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07004485 }
4486
4487 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004488 * Called by a profile owner of a managed profile to set whether caller-Id information from the
4489 * managed profile will be shown in the parent profile, for incoming calls.
4490 * <p>
4491 * The calling device admin must be a profile owner. If it is not, a security exception will be
4492 * thrown.
Adam Connors210fe212014-07-17 15:41:43 +01004493 *
Robin Lee25e26452015-06-02 09:56:29 -07004494 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01004495 * @param disabled If true caller-Id information in the managed profile is not displayed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004496 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors210fe212014-07-17 15:41:43 +01004497 */
Robin Lee25e26452015-06-02 09:56:29 -07004498 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004499 throwIfParentInstance("setCrossProfileCallerIdDisabled");
Adam Connors210fe212014-07-17 15:41:43 +01004500 if (mService != null) {
4501 try {
Robin Lee25e26452015-06-02 09:56:29 -07004502 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01004503 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004504 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01004505 }
4506 }
4507 }
4508
4509 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004510 * Called by a profile owner of a managed profile to determine whether or not caller-Id
4511 * information has been disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004512 * <p>
4513 * The calling device admin must be a profile owner. If it is not, a security exception will be
4514 * thrown.
Adam Connors210fe212014-07-17 15:41:43 +01004515 *
Robin Lee25e26452015-06-02 09:56:29 -07004516 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004517 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors210fe212014-07-17 15:41:43 +01004518 */
Robin Lee25e26452015-06-02 09:56:29 -07004519 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004520 throwIfParentInstance("getCrossProfileCallerIdDisabled");
Adam Connors210fe212014-07-17 15:41:43 +01004521 if (mService != null) {
4522 try {
Robin Lee25e26452015-06-02 09:56:29 -07004523 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01004524 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004525 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01004526 }
4527 }
4528 return false;
4529 }
4530
4531 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07004532 * Determine whether or not caller-Id information has been disabled.
4533 *
4534 * @param userHandle The user for whom to check the caller-id permission
4535 * @hide
4536 */
4537 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
4538 if (mService != null) {
4539 try {
4540 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
4541 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004542 throw e.rethrowFromSystemServer();
Amith Yamasani570002f2014-07-18 15:48:54 -07004543 }
4544 }
4545 return false;
4546 }
4547
4548 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004549 * Called by a profile owner of a managed profile to set whether contacts search from the
4550 * managed profile will be shown in the parent profile, for incoming calls.
4551 * <p>
4552 * The calling device admin must be a profile owner. If it is not, a security exception will be
4553 * thrown.
Victor Chang1060c6182016-01-04 20:16:23 +00004554 *
4555 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4556 * @param disabled If true contacts search in the managed profile is not displayed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004557 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Chang1060c6182016-01-04 20:16:23 +00004558 */
4559 public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin,
4560 boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004561 throwIfParentInstance("setCrossProfileContactsSearchDisabled");
Victor Chang1060c6182016-01-04 20:16:23 +00004562 if (mService != null) {
4563 try {
4564 mService.setCrossProfileContactsSearchDisabled(admin, disabled);
4565 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004566 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00004567 }
4568 }
4569 }
4570
4571 /**
4572 * Called by a profile owner of a managed profile to determine whether or not contacts search
4573 * has been disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004574 * <p>
4575 * The calling device admin must be a profile owner. If it is not, a security exception will be
4576 * thrown.
Victor Chang1060c6182016-01-04 20:16:23 +00004577 *
4578 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004579 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Chang1060c6182016-01-04 20:16:23 +00004580 */
4581 public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004582 throwIfParentInstance("getCrossProfileContactsSearchDisabled");
Victor Chang1060c6182016-01-04 20:16:23 +00004583 if (mService != null) {
4584 try {
4585 return mService.getCrossProfileContactsSearchDisabled(admin);
4586 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004587 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00004588 }
4589 }
4590 return false;
4591 }
4592
4593
4594 /**
4595 * Determine whether or not contacts search has been disabled.
4596 *
4597 * @param userHandle The user for whom to check the contacts search permission
4598 * @hide
4599 */
4600 public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) {
4601 if (mService != null) {
4602 try {
4603 return mService
4604 .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier());
4605 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004606 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00004607 }
4608 }
4609 return false;
4610 }
4611
4612 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004613 * Start Quick Contact on the managed profile for the user, if the policy allows.
Victor Chang97bdacc2016-01-21 22:24:11 +00004614 *
Makoto Onuki1040da12015-03-19 11:24:00 -07004615 * @hide
4616 */
4617 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
Victor Chang97bdacc2016-01-21 22:24:11 +00004618 boolean isContactIdIgnored, long directoryId, Intent originalIntent) {
Makoto Onuki1040da12015-03-19 11:24:00 -07004619 if (mService != null) {
4620 try {
Victor Chang97bdacc2016-01-21 22:24:11 +00004621 mService.startManagedQuickContact(actualLookupKey, actualContactId,
4622 isContactIdIgnored, directoryId, originalIntent);
Makoto Onuki1040da12015-03-19 11:24:00 -07004623 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004624 throw e.rethrowFromSystemServer();
Makoto Onuki1040da12015-03-19 11:24:00 -07004625 }
4626 }
4627 }
4628
4629 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004630 * Start Quick Contact on the managed profile for the user, if the policy allows.
Ricky Wai494b95d2015-11-20 16:07:15 +00004631 * @hide
4632 */
4633 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
4634 Intent originalIntent) {
Victor Chang97bdacc2016-01-21 22:24:11 +00004635 startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT,
Ricky Wai494b95d2015-11-20 16:07:15 +00004636 originalIntent);
4637 }
4638
4639 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004640 * Called by a profile owner of a managed profile to set whether bluetooth devices can access
4641 * enterprise contacts.
Ricky Wai778ba132015-03-31 14:21:22 +01004642 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004643 * The calling device admin must be a profile owner. If it is not, a security exception will be
4644 * thrown.
Ricky Wai778ba132015-03-31 14:21:22 +01004645 * <p>
4646 * This API works on managed profile only.
4647 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004648 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4649 * @param disabled If true, bluetooth devices cannot access enterprise contacts.
4650 * @throws SecurityException if {@code admin} is not a device or profile owner.
Ricky Wai778ba132015-03-31 14:21:22 +01004651 */
Robin Lee25e26452015-06-02 09:56:29 -07004652 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004653 throwIfParentInstance("setBluetoothContactSharingDisabled");
Ricky Wai778ba132015-03-31 14:21:22 +01004654 if (mService != null) {
4655 try {
Robin Lee25e26452015-06-02 09:56:29 -07004656 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01004657 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004658 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01004659 }
4660 }
4661 }
4662
4663 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004664 * Called by a profile owner of a managed profile to determine whether or not Bluetooth devices
4665 * cannot access enterprise contacts.
Ricky Wai778ba132015-03-31 14:21:22 +01004666 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004667 * The calling device admin must be a profile owner. If it is not, a security exception will be
4668 * thrown.
Ricky Wai778ba132015-03-31 14:21:22 +01004669 * <p>
4670 * This API works on managed profile only.
4671 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004672 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4673 * @throws SecurityException if {@code admin} is not a device or profile owner.
Ricky Wai778ba132015-03-31 14:21:22 +01004674 */
Robin Lee25e26452015-06-02 09:56:29 -07004675 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004676 throwIfParentInstance("getBluetoothContactSharingDisabled");
Ricky Wai778ba132015-03-31 14:21:22 +01004677 if (mService != null) {
4678 try {
Robin Lee25e26452015-06-02 09:56:29 -07004679 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01004680 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004681 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01004682 }
4683 }
4684 return true;
4685 }
4686
4687 /**
4688 * Determine whether or not Bluetooth devices cannot access contacts.
4689 * <p>
4690 * This API works on managed profile UserHandle only.
4691 *
4692 * @param userHandle The user for whom to check the caller-id permission
4693 * @hide
4694 */
4695 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
4696 if (mService != null) {
4697 try {
4698 return mService.getBluetoothContactSharingDisabledForUser(userHandle
4699 .getIdentifier());
4700 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004701 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01004702 }
4703 }
4704 return true;
4705 }
4706
4707 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004708 * Called by the profile owner of a managed profile so that some intents sent in the managed
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004709 * profile can also be resolved in the parent, or vice versa. Only activity intents are
4710 * supported.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00004711 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004712 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01004713 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004714 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01004715 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004716 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
4717 * @throws SecurityException if {@code admin} is not a device or profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004718 */
Robin Lee25e26452015-06-02 09:56:29 -07004719 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004720 throwIfParentInstance("addCrossProfileIntentFilter");
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004721 if (mService != null) {
4722 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01004723 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004724 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004725 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004726 }
4727 }
4728 }
4729
4730 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004731 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
4732 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01004733 * Only removes those that have been set by the profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004734 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004735 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004736 * @throws SecurityException if {@code admin} is not a device or profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004737 */
Robin Lee25e26452015-06-02 09:56:29 -07004738 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004739 throwIfParentInstance("clearCrossProfileIntentFilters");
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004740 if (mService != null) {
4741 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01004742 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004743 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004744 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004745 }
4746 }
4747 }
4748
4749 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004750 * Called by a profile or device owner to set the permitted accessibility services. When set by
4751 * a device owner or profile owner the restriction applies to all profiles of the user the
4752 * device owner or profile owner is an admin for. By default the user can use any accessiblity
4753 * service. When zero or more packages have been added, accessiblity services that are not in
4754 * the list and not part of the system can not be enabled by the user.
4755 * <p>
4756 * Calling with a null value for the list disables the restriction so that all services can be
4757 * used, calling with an empty list only allows the builtin system's services.
4758 * <p>
4759 * System accesibility services are always available to the user the list can't modify this.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004760 *
4761 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4762 * @param packageNames List of accessibility service package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004763 * @return true if setting the restriction succeeded. It fail if there is one or more non-system
4764 * accessibility services enabled, that are not in the list.
4765 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004766 */
Robin Lee25e26452015-06-02 09:56:29 -07004767 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004768 List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004769 throwIfParentInstance("setPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004770 if (mService != null) {
4771 try {
4772 return mService.setPermittedAccessibilityServices(admin, packageNames);
4773 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004774 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004775 }
4776 }
4777 return false;
4778 }
4779
4780 /**
4781 * Returns the list of permitted accessibility services set by this device or profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004782 * <p>
4783 * An empty list means no accessibility services except system services are allowed. Null means
4784 * all accessibility services are allowed.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004785 *
4786 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4787 * @return List of accessiblity service package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004788 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004789 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004790 public @Nullable List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004791 throwIfParentInstance("getPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004792 if (mService != null) {
4793 try {
4794 return mService.getPermittedAccessibilityServices(admin);
4795 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004796 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004797 }
4798 }
4799 return null;
4800 }
4801
4802 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00004803 * Called by the system to check if a specific accessibility service is disabled by admin.
4804 *
4805 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4806 * @param packageName Accessibility service package name that needs to be checked.
4807 * @param userHandle user id the admin is running as.
4808 * @return true if the accessibility service is permitted, otherwise false.
4809 *
4810 * @hide
4811 */
4812 public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin,
4813 @NonNull String packageName, int userHandle) {
4814 if (mService != null) {
4815 try {
4816 return mService.isAccessibilityServicePermittedByAdmin(admin, packageName,
4817 userHandle);
4818 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004819 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00004820 }
4821 }
4822 return false;
4823 }
4824
4825 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004826 * Returns the list of accessibility services permitted by the device or profiles
4827 * owners of this user.
4828 *
4829 * <p>Null means all accessibility services are allowed, if a non-null list is returned
4830 * it will contain the intersection of the permitted lists for any device or profile
4831 * owners that apply to this user. It will also include any system accessibility services.
4832 *
4833 * @param userId which user to check for.
4834 * @return List of accessiblity service package names.
4835 * @hide
4836 */
4837 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004838 public @Nullable List<String> getPermittedAccessibilityServices(int userId) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004839 throwIfParentInstance("getPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004840 if (mService != null) {
4841 try {
4842 return mService.getPermittedAccessibilityServicesForUser(userId);
4843 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004844 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004845 }
4846 }
4847 return null;
4848 }
4849
4850 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004851 * Called by a profile or device owner to set the permitted input methods services. When set by
4852 * a device owner or profile owner the restriction applies to all profiles of the user the
4853 * device owner or profile owner is an admin for. By default the user can use any input method.
4854 * When zero or more packages have been added, input method that are not in the list and not
4855 * part of the system can not be enabled by the user. This method will fail if it is called for
4856 * a admin that is not for the foreground user or a profile of the foreground user.
4857 * <p>
4858 * Calling with a null value for the list disables the restriction so that all input methods can
4859 * be used, calling with an empty list disables all but the system's own input methods.
4860 * <p>
4861 * System input methods are always available to the user this method can't modify this.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004862 *
4863 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4864 * @param packageNames List of input method package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004865 * @return true if setting the restriction succeeded. It will fail if there are one or more
4866 * non-system input methods currently enabled that are not in the packageNames list.
4867 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004868 */
Robin Lee25e26452015-06-02 09:56:29 -07004869 public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004870 throwIfParentInstance("setPermittedInputMethods");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004871 if (mService != null) {
4872 try {
4873 return mService.setPermittedInputMethods(admin, packageNames);
4874 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004875 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004876 }
4877 }
4878 return false;
4879 }
4880
4881
4882 /**
4883 * Returns the list of permitted input methods set by this device or profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004884 * <p>
4885 * An empty list means no input methods except system input methods are allowed. Null means all
4886 * input methods are allowed.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004887 *
4888 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4889 * @return List of input method package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004890 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004891 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004892 public @Nullable List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004893 throwIfParentInstance("getPermittedInputMethods");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004894 if (mService != null) {
4895 try {
4896 return mService.getPermittedInputMethods(admin);
4897 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004898 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004899 }
4900 }
4901 return null;
4902 }
4903
4904 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00004905 * Called by the system to check if a specific input method is disabled by admin.
4906 *
4907 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4908 * @param packageName Input method package name that needs to be checked.
4909 * @param userHandle user id the admin is running as.
4910 * @return true if the input method is permitted, otherwise false.
4911 *
4912 * @hide
4913 */
4914 public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin,
4915 @NonNull String packageName, int userHandle) {
4916 if (mService != null) {
4917 try {
4918 return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle);
4919 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004920 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00004921 }
4922 }
4923 return false;
4924 }
4925
4926 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004927 * Returns the list of input methods permitted by the device or profiles
Makoto Onuki32b30572015-12-11 14:29:51 -08004928 * owners of the current user. (*Not* calling user, due to a limitation in InputMethodManager.)
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004929 *
4930 * <p>Null means all input methods are allowed, if a non-null list is returned
4931 * it will contain the intersection of the permitted lists for any device or profile
4932 * owners that apply to this user. It will also include any system input methods.
4933 *
4934 * @return List of input method package names.
4935 * @hide
4936 */
4937 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004938 public @Nullable List<String> getPermittedInputMethodsForCurrentUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004939 throwIfParentInstance("getPermittedInputMethodsForCurrentUser");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004940 if (mService != null) {
4941 try {
4942 return mService.getPermittedInputMethodsForCurrentUser();
4943 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004944 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004945 }
4946 }
4947 return null;
4948 }
4949
4950 /**
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004951 * Called by a device owner to get the list of apps to keep around as APKs even if no user has
4952 * currently installed it.
4953 *
4954 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4955 *
4956 * @return List of package names to keep cached.
4957 * @hide
4958 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004959 public @Nullable List<String> getKeepUninstalledPackages(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004960 throwIfParentInstance("getKeepUninstalledPackages");
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004961 if (mService != null) {
4962 try {
4963 return mService.getKeepUninstalledPackages(admin);
4964 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004965 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004966 }
4967 }
4968 return null;
4969 }
4970
4971 /**
4972 * Called by a device owner to set a list of apps to keep around as APKs even if no user has
4973 * currently installed it.
4974 *
4975 * <p>Please note that setting this policy does not imply that specified apps will be
4976 * automatically pre-cached.</p>
4977 *
4978 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4979 * @param packageNames List of package names to keep cached.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004980 * @throws SecurityException if {@code admin} is not a device owner.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004981 * @hide
4982 */
4983 public void setKeepUninstalledPackages(@NonNull ComponentName admin,
4984 @NonNull List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004985 throwIfParentInstance("setKeepUninstalledPackages");
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004986 if (mService != null) {
4987 try {
4988 mService.setKeepUninstalledPackages(admin, packageNames);
4989 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004990 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004991 }
4992 }
4993 }
4994
4995 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04004996 * Called by a device owner to create a user with the specified name. The UserHandle returned
4997 * by this method should not be persisted as user handles are recycled as users are removed and
4998 * created. If you need to persist an identifier for this user, use
4999 * {@link UserManager#getSerialNumberForUser}.
5000 *
5001 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5002 * @param name the user's name
5003 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07005004 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
5005 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01005006 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005007 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01005008 * @removed From {@link android.os.Build.VERSION_CODES#N}
Julia Reynolds1e958392014-05-16 14:25:21 -04005009 */
Kenny Guy14f48e52015-06-29 15:12:36 +01005010 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07005011 public @Nullable UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04005012 return null;
5013 }
5014
5015 /**
Jason Monk03978a42014-06-10 15:05:30 -04005016 * Called by a device owner to create a user with the specified name. The UserHandle returned
5017 * by this method should not be persisted as user handles are recycled as users are removed and
5018 * created. If you need to persist an identifier for this user, use
5019 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
5020 * immediately.
5021 *
5022 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
5023 * as registered as an active admin on the new user. The profile owner package will be
5024 * installed on the new user if it already is installed on the device.
5025 *
5026 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
5027 * profileOwnerComponent when onEnable is called.
5028 *
5029 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5030 * @param name the user's name
5031 * @param ownerName the human readable name of the organisation associated with this DPM.
5032 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
5033 * the user.
5034 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
5035 * on the new user.
5036 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07005037 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
5038 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01005039 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005040 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01005041 * @removed From {@link android.os.Build.VERSION_CODES#N}
Jason Monk03978a42014-06-10 15:05:30 -04005042 */
Kenny Guy14f48e52015-06-29 15:12:36 +01005043 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07005044 public @Nullable UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
Robin Lee25e26452015-06-02 09:56:29 -07005045 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04005046 return null;
5047 }
5048
5049 /**
phweissa92e1212016-01-25 17:14:10 +01005050 * Flag used by {@link #createAndManageUser} to skip setup wizard after creating a new user.
phweiss343fb332016-01-25 14:48:59 +01005051 */
5052 public static final int SKIP_SETUP_WIZARD = 0x0001;
5053
5054 /**
Lenka Trochtovac8202c82016-01-26 15:11:09 +01005055 * Flag used by {@link #createAndManageUser} to specify that the user should be created
5056 * ephemeral.
5057 * @hide
5058 */
5059 public static final int MAKE_USER_EPHEMERAL = 0x0002;
5060
5061 /**
phweissa92e1212016-01-25 17:14:10 +01005062 * Called by a device owner to create a user with the specified name and a given component of
5063 * the calling package as profile owner. The UserHandle returned by this method should not be
5064 * persisted as user handles are recycled as users are removed and created. If you need to
5065 * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new
5066 * user will not be started in the background.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005067 * <p>
5068 * admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also a
5069 * DeviceAdminReceiver in the same package as admin, and will become the profile owner and will
5070 * be registered as an active admin on the new user. The profile owner package will be installed
5071 * on the new user.
5072 * <p>
5073 * If the adminExtras are not null, they will be stored on the device until the user is started
5074 * for the first time. Then the extras will be passed to the admin when onEnable is called.
phweiss343fb332016-01-25 14:48:59 +01005075 *
5076 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5077 * @param name The user's name.
phweissa92e1212016-01-25 17:14:10 +01005078 * @param profileOwner Which {@link DeviceAdminReceiver} will be profile owner. Has to be in the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005079 * same package as admin, otherwise no user is created and an
5080 * IllegalArgumentException is thrown.
phweiss343fb332016-01-25 14:48:59 +01005081 * @param adminExtras Extras that will be passed to onEnable of the admin receiver on the new
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005082 * user.
phweissa92e1212016-01-25 17:14:10 +01005083 * @param flags {@link #SKIP_SETUP_WIZARD} is supported.
phweiss343fb332016-01-25 14:48:59 +01005084 * @see UserHandle
5085 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
5086 * user could not be created.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005087 * @throws SecurityException if {@code admin} is not a device owner.
phweiss343fb332016-01-25 14:48:59 +01005088 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005089 public @Nullable UserHandle createAndManageUser(@NonNull ComponentName admin,
5090 @NonNull String name,
phweissa92e1212016-01-25 17:14:10 +01005091 @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras,
5092 int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005093 throwIfParentInstance("createAndManageUser");
phweiss343fb332016-01-25 14:48:59 +01005094 try {
phweissa92e1212016-01-25 17:14:10 +01005095 return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags);
phweiss343fb332016-01-25 14:48:59 +01005096 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005097 throw re.rethrowFromSystemServer();
phweiss343fb332016-01-25 14:48:59 +01005098 }
phweiss343fb332016-01-25 14:48:59 +01005099 }
5100
5101 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005102 * Called by a device owner to remove a user and all associated data. The primary user can not
5103 * be removed.
Julia Reynolds1e958392014-05-16 14:25:21 -04005104 *
5105 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5106 * @param userHandle the user to remove.
5107 * @return {@code true} if the user was removed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005108 * @throws SecurityException if {@code admin} is not a device owner.
Julia Reynolds1e958392014-05-16 14:25:21 -04005109 */
Robin Lee25e26452015-06-02 09:56:29 -07005110 public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005111 throwIfParentInstance("removeUser");
Julia Reynolds1e958392014-05-16 14:25:21 -04005112 try {
5113 return mService.removeUser(admin, userHandle);
5114 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005115 throw re.rethrowFromSystemServer();
Julia Reynolds1e958392014-05-16 14:25:21 -04005116 }
5117 }
5118
5119 /**
Jason Monk582d9112014-07-09 19:57:08 -04005120 * Called by a device owner to switch the specified user to the foreground.
5121 *
5122 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5123 * @param userHandle the user to switch to; null will switch to primary.
5124 * @return {@code true} if the switch was successful, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005125 * @throws SecurityException if {@code admin} is not a device owner.
Jason Monk582d9112014-07-09 19:57:08 -04005126 * @see Intent#ACTION_USER_FOREGROUND
5127 */
Robin Lee25e26452015-06-02 09:56:29 -07005128 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005129 throwIfParentInstance("switchUser");
Jason Monk582d9112014-07-09 19:57:08 -04005130 try {
5131 return mService.switchUser(admin, userHandle);
5132 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005133 throw re.rethrowFromSystemServer();
Jason Monk582d9112014-07-09 19:57:08 -04005134 }
5135 }
5136
5137 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00005138 * Retrieves the application restrictions for a given target application running in the calling
5139 * user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005140 * <p>
5141 * The caller must be a profile or device owner on that user, or the package allowed to manage
5142 * application restrictions via {@link #setApplicationRestrictionsManagingPackage}; otherwise a
5143 * security exception will be thrown.
Robin Lee66e5d962014-04-09 16:44:21 +01005144 *
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005145 * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
5146 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00005147 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005148 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01005149 * @param packageName The name of the package to fetch restricted settings of.
5150 * @return {@link Bundle} of settings corresponding to what was set last time
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005151 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty
5152 * {@link Bundle} if no restrictions have been set.
5153 * @throws SecurityException if {@code admin} is not a device or profile owner.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005154 * @see {@link #setApplicationRestrictionsManagingPackage}
Robin Lee66e5d962014-04-09 16:44:21 +01005155 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005156 @WorkerThread
Makoto Onuki408e8e42016-10-25 12:10:27 -07005157 public @NonNull Bundle getApplicationRestrictions(
5158 @Nullable ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005159 throwIfParentInstance("getApplicationRestrictions");
Robin Lee66e5d962014-04-09 16:44:21 +01005160 if (mService != null) {
5161 try {
5162 return mService.getApplicationRestrictions(admin, packageName);
5163 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005164 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01005165 }
5166 }
5167 return null;
5168 }
Amith Yamasanibe465322014-04-24 13:45:17 -07005169
5170 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05005171 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07005172 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005173 * The calling device admin must be a profile or device owner; if it is not, a security
5174 * exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07005175 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005176 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5177 * @param key The key of the restriction. See the constants in {@link android.os.UserManager}
5178 * for the list of keys.
5179 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanibe465322014-04-24 13:45:17 -07005180 */
Robin Lee25e26452015-06-02 09:56:29 -07005181 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005182 throwIfParentInstance("addUserRestriction");
Amith Yamasanibe465322014-04-24 13:45:17 -07005183 if (mService != null) {
5184 try {
5185 mService.setUserRestriction(admin, key, true);
5186 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005187 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07005188 }
5189 }
5190 }
5191
5192 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05005193 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07005194 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005195 * The calling device admin must be a profile or device owner; if it is not, a security
5196 * exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07005197 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005198 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5199 * @param key The key of the restriction. See the constants in {@link android.os.UserManager}
5200 * for the list of keys.
5201 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanibe465322014-04-24 13:45:17 -07005202 */
Robin Lee25e26452015-06-02 09:56:29 -07005203 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005204 throwIfParentInstance("clearUserRestriction");
Amith Yamasanibe465322014-04-24 13:45:17 -07005205 if (mService != null) {
5206 try {
5207 mService.setUserRestriction(admin, key, false);
5208 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005209 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07005210 }
5211 }
5212 }
Adam Connors010cfd42014-04-16 12:48:13 +01005213
5214 /**
Makoto Onuki3a3092f2015-10-30 11:07:51 -07005215 * Called by a profile or device owner to get user restrictions set with
5216 * {@link #addUserRestriction(ComponentName, String)}.
5217 * <p>
5218 * The target user may have more restrictions set by the system or other device owner / profile
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005219 * owner. To get all the user restrictions currently set, use
Makoto Onuki3a3092f2015-10-30 11:07:51 -07005220 * {@link UserManager#getUserRestrictions()}.
5221 *
5222 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005223 * @throws SecurityException if {@code admin} is not a device or profile owner.
Makoto Onuki3a3092f2015-10-30 11:07:51 -07005224 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005225 public @NonNull Bundle getUserRestrictions(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005226 throwIfParentInstance("getUserRestrictions");
Makoto Onuki3a3092f2015-10-30 11:07:51 -07005227 Bundle ret = null;
5228 if (mService != null) {
5229 try {
Sudheer Shanka549b9692016-03-30 17:12:07 -07005230 ret = mService.getUserRestrictions(admin);
5231 } catch (RemoteException e) {
5232 throw e.rethrowFromSystemServer();
5233 }
5234 }
5235 return ret == null ? new Bundle() : ret;
5236 }
5237
5238 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005239 * Called by profile or device owners to hide or unhide packages. When a package is hidden it is
5240 * unavailable for use, but the data and actual package file remain.
Julia Reynolds966881e2014-05-14 12:23:08 -04005241 *
5242 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005243 * @param packageName The name of the package to hide or unhide.
5244 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005245 * unhidden.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005246 * @return boolean Whether the hidden setting of the package was successfully updated.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005247 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds966881e2014-05-14 12:23:08 -04005248 */
Robin Lee25e26452015-06-02 09:56:29 -07005249 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005250 boolean hidden) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005251 throwIfParentInstance("setApplicationHidden");
Julia Reynolds966881e2014-05-14 12:23:08 -04005252 if (mService != null) {
5253 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005254 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04005255 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005256 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04005257 }
5258 }
5259 return false;
5260 }
5261
5262 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05005263 * Called by profile or device owners to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04005264 *
5265 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005266 * @param packageName The name of the package to retrieve the hidden status of.
5267 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005268 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds966881e2014-05-14 12:23:08 -04005269 */
Robin Lee25e26452015-06-02 09:56:29 -07005270 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005271 throwIfParentInstance("isApplicationHidden");
Julia Reynolds966881e2014-05-14 12:23:08 -04005272 if (mService != null) {
5273 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005274 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04005275 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005276 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04005277 }
5278 }
5279 return false;
5280 }
5281
5282 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05005283 * Called by profile or device owners to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005284 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00005285 *
5286 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Makoto Onuki32b30572015-12-11 14:29:51 -08005287 * @param packageName The package to be re-enabled in the calling profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005288 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors655be2a2014-07-14 09:01:25 +00005289 */
Robin Lee25e26452015-06-02 09:56:29 -07005290 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005291 throwIfParentInstance("enableSystemApp");
Adam Connors655be2a2014-07-14 09:01:25 +00005292 if (mService != null) {
5293 try {
5294 mService.enableSystemApp(admin, packageName);
5295 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005296 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00005297 }
5298 }
5299 }
5300
5301 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005302 * Called by profile or device owners to re-enable system apps by intent that were disabled by
5303 * default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00005304 *
5305 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5306 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005307 * intent will be re-enabled in the calling profile.
Adam Connors655be2a2014-07-14 09:01:25 +00005308 * @return int The number of activities that matched the intent and were installed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005309 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors655be2a2014-07-14 09:01:25 +00005310 */
Robin Lee25e26452015-06-02 09:56:29 -07005311 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005312 throwIfParentInstance("enableSystemApp");
Adam Connors655be2a2014-07-14 09:01:25 +00005313 if (mService != null) {
5314 try {
5315 return mService.enableSystemAppWithIntent(admin, intent);
5316 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005317 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00005318 }
5319 }
5320 return 0;
5321 }
5322
5323 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00005324 * Called by a device owner or profile owner to disable account management for a specific type
5325 * of account.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005326 * <p>
5327 * The calling device admin must be a device owner or profile owner. If it is not, a security
5328 * exception will be thrown.
5329 * <p>
5330 * When account management is disabled for an account type, adding or removing an account of
5331 * that type will not be possible.
5332 * <p>
5333 * From {@link android.os.Build.VERSION_CODES#N} the profile or device owner can still use
Benjamin Franzb6c0ce42015-11-05 10:06:51 +00005334 * {@link android.accounts.AccountManager} APIs to add or remove accounts when account
5335 * management for a specific type is disabled.
5336 *
Sander Alewijnse650c3342014-05-08 18:00:50 +01005337 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5338 * @param accountType For which account management is disabled or enabled.
5339 * @param disabled The boolean indicating that account management will be disabled (true) or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005340 * enabled (false).
5341 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnse650c3342014-05-08 18:00:50 +01005342 */
Robin Lee25e26452015-06-02 09:56:29 -07005343 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01005344 boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005345 throwIfParentInstance("setAccountManagementDisabled");
Sander Alewijnse650c3342014-05-08 18:00:50 +01005346 if (mService != null) {
5347 try {
5348 mService.setAccountManagementDisabled(admin, accountType, disabled);
5349 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005350 throw e.rethrowFromSystemServer();
Sander Alewijnse650c3342014-05-08 18:00:50 +01005351 }
5352 }
5353 }
5354
5355 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01005356 * Gets the array of accounts for which account management is disabled by the profile owner.
5357 *
5358 * <p> Account management can be disabled/enabled by calling
5359 * {@link #setAccountManagementDisabled}.
5360 *
5361 * @return a list of account types for which account management has been disabled.
5362 *
5363 * @see #setAccountManagementDisabled
5364 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005365 public @Nullable String[] getAccountTypesWithManagementDisabled() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005366 throwIfParentInstance("getAccountTypesWithManagementDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07005367 return getAccountTypesWithManagementDisabledAsUser(myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01005368 }
5369
5370 /**
5371 * @see #getAccountTypesWithManagementDisabled()
5372 * @hide
5373 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005374 public @Nullable String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01005375 if (mService != null) {
5376 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01005377 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01005378 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005379 throw e.rethrowFromSystemServer();
Sander Alewijnse5c02db62014-05-07 10:46:57 +01005380 }
5381 }
5382
5383 return null;
5384 }
justinzhang511e0d82014-03-24 16:09:24 -04005385
5386 /**
Jason Monkd7b86212014-06-16 13:15:38 -04005387 * Sets which packages may enter lock task mode.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005388 * <p>
5389 * Any packages that shares uid with an allowed package will also be allowed to activate lock
5390 * task. From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task
5391 * package list results in locked tasks belonging to those packages to be finished. This
5392 * function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04005393 *
Jason Monkd7b86212014-06-16 13:15:38 -04005394 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04005395 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005396 * @throws SecurityException if {@code admin} is not a device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04005397 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00005398 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
5399 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04005400 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04005401 */
Robin Lee25e26452015-06-02 09:56:29 -07005402 public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04005403 throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005404 throwIfParentInstance("setLockTaskPackages");
justinzhang511e0d82014-03-24 16:09:24 -04005405 if (mService != null) {
5406 try {
Jason Monk48aacba2014-08-13 16:29:08 -04005407 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04005408 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005409 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04005410 }
5411 }
5412 }
5413
5414 /**
Jason Monkd7b86212014-06-16 13:15:38 -04005415 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04005416 *
5417 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04005418 * @hide
5419 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005420 public @NonNull String[] getLockTaskPackages(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005421 throwIfParentInstance("getLockTaskPackages");
justinzhang511e0d82014-03-24 16:09:24 -04005422 if (mService != null) {
5423 try {
Jason Monk48aacba2014-08-13 16:29:08 -04005424 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04005425 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005426 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04005427 }
5428 }
5429 return null;
5430 }
5431
5432 /**
5433 * This function lets the caller know whether the given component is allowed to start the
5434 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04005435 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04005436 */
Jason Monkd7b86212014-06-16 13:15:38 -04005437 public boolean isLockTaskPermitted(String pkg) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005438 throwIfParentInstance("isLockTaskPermitted");
justinzhang511e0d82014-03-24 16:09:24 -04005439 if (mService != null) {
5440 try {
Jason Monkd7b86212014-06-16 13:15:38 -04005441 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04005442 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005443 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04005444 }
5445 }
5446 return false;
5447 }
Julia Reynoldsda551652014-05-14 17:15:16 -04005448
5449 /**
5450 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
5451 * 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 -07005452 * <p>
5453 * The settings that can be updated with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005454 * <ul>
5455 * <li>{@link Settings.Global#ADB_ENABLED}</li>
5456 * <li>{@link Settings.Global#AUTO_TIME}</li>
5457 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005458 * <li>{@link Settings.Global#DATA_ROAMING}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005459 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005460 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005461 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN} This setting is only available from
5462 * {@link android.os.Build.VERSION_CODES#M} onwards and can only be set if
5463 * {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
5464 * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li> This setting is only
5465 * available from {@link android.os.Build.VERSION_CODES#M} onwards.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005466 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005467 * <p>
5468 * Changing the following settings has no effect as of {@link android.os.Build.VERSION_CODES#M}:
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005469 * <ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005470 * <li>{@link Settings.Global#BLUETOOTH_ON}. Use
5471 * {@link android.bluetooth.BluetoothAdapter#enable()} and
5472 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005473 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005474 * <li>{@link Settings.Global#MODE_RINGER}. Use
5475 * {@link android.media.AudioManager#setRingerMode(int)} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005476 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005477 * <li>{@link Settings.Global#WIFI_ON}. Use
5478 * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005479 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04005480 *
5481 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5482 * @param setting The name of the setting to update.
5483 * @param value The value to update the setting to.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005484 * @throws SecurityException if {@code admin} is not a device owner.
Julia Reynoldsda551652014-05-14 17:15:16 -04005485 */
Robin Lee25e26452015-06-02 09:56:29 -07005486 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005487 throwIfParentInstance("setGlobalSetting");
Julia Reynoldsda551652014-05-14 17:15:16 -04005488 if (mService != null) {
5489 try {
5490 mService.setGlobalSetting(admin, setting, value);
5491 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005492 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04005493 }
5494 }
5495 }
5496
5497 /**
5498 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
5499 * that the value of the setting is in the correct form for the setting type should be performed
5500 * by the caller.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005501 * <p>
5502 * The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005503 * <ul>
5504 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07005505 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005506 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
5507 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005508 * <p>
5509 * A device owner can additionally update the following settings:
Julia Reynolds82735bc2014-09-04 16:43:30 -04005510 * <ul>
5511 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
5512 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005513 *
Julia Reynoldsda551652014-05-14 17:15:16 -04005514 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5515 * @param setting The name of the setting to update.
5516 * @param value The value to update the setting to.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005517 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynoldsda551652014-05-14 17:15:16 -04005518 */
Robin Lee25e26452015-06-02 09:56:29 -07005519 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005520 throwIfParentInstance("setSecureSetting");
Julia Reynoldsda551652014-05-14 17:15:16 -04005521 if (mService != null) {
5522 try {
5523 mService.setSecureSetting(admin, setting, value);
5524 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005525 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04005526 }
5527 }
5528 }
5529
Amith Yamasanif20d6402014-05-24 15:34:37 -07005530 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005531 * Designates a specific service component as the provider for making permission requests of a
5532 * local or remote administrator of the user.
Amith Yamasanif20d6402014-05-24 15:34:37 -07005533 * <p/>
5534 * Only a profile owner can designate the restrictions provider.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005535 *
Amith Yamasanif20d6402014-05-24 15:34:37 -07005536 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07005537 * @param provider The component name of the service that implements
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005538 * {@link RestrictionsReceiver}. If this param is null, it removes the restrictions
5539 * provider previously assigned.
5540 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanif20d6402014-05-24 15:34:37 -07005541 */
Robin Lee25e26452015-06-02 09:56:29 -07005542 public void setRestrictionsProvider(@NonNull ComponentName admin,
5543 @Nullable ComponentName provider) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005544 throwIfParentInstance("setRestrictionsProvider");
Amith Yamasanif20d6402014-05-24 15:34:37 -07005545 if (mService != null) {
5546 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07005547 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07005548 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005549 throw re.rethrowFromSystemServer();
Amith Yamasanif20d6402014-05-24 15:34:37 -07005550 }
5551 }
5552 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04005553
5554 /**
5555 * Called by profile or device owners to set the master volume mute on or off.
Nicolas Prevotaef3ce22016-09-22 12:00:25 +01005556 * This has no effect when set on a managed profile.
Julia Reynolds4a21b252014-06-04 11:11:43 -04005557 *
5558 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5559 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005560 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds4a21b252014-06-04 11:11:43 -04005561 */
Robin Lee25e26452015-06-02 09:56:29 -07005562 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005563 throwIfParentInstance("setMasterVolumeMuted");
Julia Reynolds4a21b252014-06-04 11:11:43 -04005564 if (mService != null) {
5565 try {
5566 mService.setMasterVolumeMuted(admin, on);
5567 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005568 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04005569 }
5570 }
5571 }
5572
5573 /**
5574 * Called by profile or device owners to check whether the master volume mute is on or off.
5575 *
5576 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5577 * @return {@code true} if master volume is muted, {@code false} if it's not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005578 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds4a21b252014-06-04 11:11:43 -04005579 */
Robin Lee25e26452015-06-02 09:56:29 -07005580 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005581 throwIfParentInstance("isMasterVolumeMuted");
Julia Reynolds4a21b252014-06-04 11:11:43 -04005582 if (mService != null) {
5583 try {
5584 return mService.isMasterVolumeMuted(admin);
5585 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005586 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04005587 }
5588 }
5589 return false;
5590 }
Kenny Guyc13053b2014-05-29 14:17:17 +01005591
5592 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005593 * Called by profile or device owners to change whether a user can uninstall a package.
Kenny Guyc13053b2014-05-29 14:17:17 +01005594 *
5595 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5596 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01005597 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005598 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyc13053b2014-05-29 14:17:17 +01005599 */
Robin Lee25e26452015-06-02 09:56:29 -07005600 public void setUninstallBlocked(@NonNull ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01005601 boolean uninstallBlocked) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005602 throwIfParentInstance("setUninstallBlocked");
Kenny Guyc13053b2014-05-29 14:17:17 +01005603 if (mService != null) {
5604 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01005605 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01005606 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005607 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01005608 }
5609 }
5610 }
5611
5612 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005613 * Check whether the user has been blocked by device policy from uninstalling a package.
Rubin Xua97855b2014-11-07 05:41:00 +00005614 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00005615 * <p>
5616 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005617 * behavior of this API is changed such that passing {@code null} as the {@code admin} parameter
5618 * will return if any admin has blocked the uninstallation. Before L MR1, passing {@code null}
5619 * will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01005620 *
Robin Lee25e26452015-06-02 09:56:29 -07005621 * @param admin The name of the admin component whose blocking policy will be checked, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005622 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01005623 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00005624 * @return true if uninstallation is blocked.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005625 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyc13053b2014-05-29 14:17:17 +01005626 */
Robin Lee25e26452015-06-02 09:56:29 -07005627 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005628 throwIfParentInstance("isUninstallBlocked");
Kenny Guyc13053b2014-05-29 14:17:17 +01005629 if (mService != null) {
5630 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01005631 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01005632 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005633 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01005634 }
5635 }
5636 return false;
5637 }
Svetoslav976e8bd2014-07-16 15:12:03 -07005638
5639 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005640 * Called by the profile owner of a managed profile to enable widget providers from a given
5641 * package to be available in the parent profile. As a result the user will be able to add
5642 * widgets from the white-listed package running under the profile to a widget host which runs
5643 * under the parent profile, for example the home screen. Note that a package may have zero or
5644 * more provider components, where each component provides a different widget type.
Svetoslav976e8bd2014-07-16 15:12:03 -07005645 * <p>
5646 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07005647 *
5648 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5649 * @param packageName The package from which widget providers are white-listed.
5650 * @return Whether the package was added.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005651 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07005652 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
5653 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
5654 */
Robin Lee25e26452015-06-02 09:56:29 -07005655 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005656 throwIfParentInstance("addCrossProfileWidgetProvider");
Svetoslav976e8bd2014-07-16 15:12:03 -07005657 if (mService != null) {
5658 try {
5659 return mService.addCrossProfileWidgetProvider(admin, packageName);
5660 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005661 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07005662 }
5663 }
5664 return false;
5665 }
5666
5667 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005668 * Called by the profile owner of a managed profile to disable widget providers from a given
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005669 * package to be available in the parent profile. For this method to take effect the package
5670 * should have been added via
5671 * {@link #addCrossProfileWidgetProvider( android.content.ComponentName, String)}.
Svetoslav976e8bd2014-07-16 15:12:03 -07005672 * <p>
5673 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07005674 *
5675 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005676 * @param packageName The package from which widget providers are no longer white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07005677 * @return Whether the package was removed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005678 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07005679 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
5680 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
5681 */
Esteban Talavera62399912016-01-11 15:37:55 +00005682 public boolean removeCrossProfileWidgetProvider(
5683 @NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005684 throwIfParentInstance("removeCrossProfileWidgetProvider");
Svetoslav976e8bd2014-07-16 15:12:03 -07005685 if (mService != null) {
5686 try {
5687 return mService.removeCrossProfileWidgetProvider(admin, packageName);
5688 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005689 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07005690 }
5691 }
5692 return false;
5693 }
5694
5695 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005696 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07005697 * available in the parent profile.
5698 *
5699 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5700 * @return The white-listed package list.
Svetoslav976e8bd2014-07-16 15:12:03 -07005701 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
5702 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005703 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07005704 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005705 public @NonNull List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005706 throwIfParentInstance("getCrossProfileWidgetProviders");
Svetoslav976e8bd2014-07-16 15:12:03 -07005707 if (mService != null) {
5708 try {
5709 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
5710 if (providers != null) {
5711 return providers;
5712 }
5713 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005714 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07005715 }
5716 }
5717 return Collections.emptyList();
5718 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005719
5720 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005721 * Called by profile or device owners to set the user's photo.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005722 *
5723 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5724 * @param icon the bitmap to set as the photo.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005725 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005726 */
Robin Lee25e26452015-06-02 09:56:29 -07005727 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005728 throwIfParentInstance("setUserIcon");
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005729 try {
5730 mService.setUserIcon(admin, icon);
5731 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005732 throw re.rethrowFromSystemServer();
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005733 }
5734 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04005735
5736 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01005737 * Called by device owners to set a local system update policy. When a new policy is set,
5738 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00005739 *
Robin Lee25e26452015-06-02 09:56:29 -07005740 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005741 * components in the device owner package can set system update policies and the most
5742 * recent policy takes effect.
Robin Lee25e26452015-06-02 09:56:29 -07005743 * @param policy the new policy, or {@code null} to clear the current policy.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005744 * @throws SecurityException if {@code admin} is not a device owner.
Rubin Xu5faad8e2015-04-20 17:43:48 +01005745 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00005746 */
Robin Lee25e26452015-06-02 09:56:29 -07005747 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005748 throwIfParentInstance("setSystemUpdatePolicy");
Rubin Xu8027a4f2015-03-10 17:52:37 +00005749 if (mService != null) {
5750 try {
Robin Lee25e26452015-06-02 09:56:29 -07005751 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00005752 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005753 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00005754 }
5755 }
5756 }
5757
5758 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01005759 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00005760 *
Robin Lee25e26452015-06-02 09:56:29 -07005761 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00005762 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005763 public @Nullable SystemUpdatePolicy getSystemUpdatePolicy() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005764 throwIfParentInstance("getSystemUpdatePolicy");
Rubin Xu8027a4f2015-03-10 17:52:37 +00005765 if (mService != null) {
5766 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01005767 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00005768 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005769 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00005770 }
5771 }
5772 return null;
5773 }
Benjamin Franze36087e2015-04-07 16:40:34 +01005774
5775 /**
5776 * Called by a device owner to disable the keyguard altogether.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005777 * <p>
5778 * Setting the keyguard to disabled has the same effect as choosing "None" as the screen lock
5779 * type. However, this call has no effect if a password, pin or pattern is currently set. If a
5780 * password, pin or pattern is set after the keyguard was disabled, the keyguard stops being
5781 * disabled.
Benjamin Franze36087e2015-04-07 16:40:34 +01005782 *
5783 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01005784 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01005785 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005786 * place. {@code true} otherwise.
5787 * @throws SecurityException if {@code admin} is not a device owner.
Benjamin Franze36087e2015-04-07 16:40:34 +01005788 */
Robin Lee25e26452015-06-02 09:56:29 -07005789 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005790 throwIfParentInstance("setKeyguardDisabled");
Benjamin Franze36087e2015-04-07 16:40:34 +01005791 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01005792 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01005793 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005794 throw re.rethrowFromSystemServer();
Benjamin Franze36087e2015-04-07 16:40:34 +01005795 }
5796 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00005797
5798 /**
Benjamin Franzbece8062015-05-06 12:14:31 +01005799 * Called by device owner to disable the status bar. Disabling the status bar blocks
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005800 * notifications, quick settings and other screen overlays that allow escaping from a single use
5801 * device.
Benjamin Franzea2ec972015-03-16 17:18:09 +00005802 *
5803 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01005804 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005805 * @return {@code false} if attempting to disable the status bar failed. {@code true} otherwise.
5806 * @throws SecurityException if {@code admin} is not a device owner.
Benjamin Franzea2ec972015-03-16 17:18:09 +00005807 */
Robin Lee25e26452015-06-02 09:56:29 -07005808 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005809 throwIfParentInstance("setStatusBarDisabled");
Benjamin Franzea2ec972015-03-16 17:18:09 +00005810 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01005811 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00005812 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005813 throw re.rethrowFromSystemServer();
Benjamin Franzea2ec972015-03-16 17:18:09 +00005814 }
5815 }
Rubin Xudc105cc2015-04-14 23:38:01 +01005816
5817 /**
5818 * Callable by the system update service to notify device owners about pending updates.
5819 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
5820 * permission.
5821 *
5822 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating
5823 * when the current pending update was first available. -1 if no update is available.
5824 * @hide
5825 */
5826 @SystemApi
5827 public void notifyPendingSystemUpdate(long updateReceivedTime) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005828 throwIfParentInstance("notifyPendingSystemUpdate");
Rubin Xudc105cc2015-04-14 23:38:01 +01005829 if (mService != null) {
5830 try {
5831 mService.notifyPendingSystemUpdate(updateReceivedTime);
5832 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005833 throw re.rethrowFromSystemServer();
Rubin Xudc105cc2015-04-14 23:38:01 +01005834 }
5835 }
5836 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04005837
5838 /**
Amith Yamasanid49489b2015-04-28 14:00:26 -07005839 * Called by profile or device owners to set the default response for future runtime permission
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005840 * requests by applications. The policy can allow for normal operation which prompts the user to
5841 * grant a permission, or can allow automatic granting or denying of runtime permission requests
5842 * by an application. This also applies to new permissions declared by app updates. When a
5843 * permission is denied or granted this way, the effect is equivalent to setting the permission
5844 * grant state via {@link #setPermissionGrantState}.
5845 * <p/>
5846 * As this policy only acts on runtime permission requests, it only applies to applications
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005847 * built with a {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Benjamin Franz45dd6662015-07-08 14:24:14 +01005848 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07005849 * @param admin Which profile or device owner this request is associated with.
5850 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005851 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
5852 * @throws SecurityException if {@code admin} is not a device or profile owner.
Benjamin Franz45dd6662015-07-08 14:24:14 +01005853 * @see #setPermissionGrantState
Amith Yamasanid49489b2015-04-28 14:00:26 -07005854 */
Robin Lee25e26452015-06-02 09:56:29 -07005855 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005856 throwIfParentInstance("setPermissionPolicy");
Amith Yamasanid49489b2015-04-28 14:00:26 -07005857 try {
5858 mService.setPermissionPolicy(admin, policy);
5859 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005860 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07005861 }
5862 }
5863
5864 /**
5865 * Returns the current runtime permission policy set by the device or profile owner. The
5866 * default is {@link #PERMISSION_POLICY_PROMPT}.
5867 * @param admin Which profile or device owner this request is associated with.
5868 * @return the current policy for future permission requests.
5869 */
Esteban Talavera28b95702015-06-24 15:23:42 +01005870 public int getPermissionPolicy(ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005871 throwIfParentInstance("getPermissionPolicy");
Amith Yamasanid49489b2015-04-28 14:00:26 -07005872 try {
5873 return mService.getPermissionPolicy(admin);
5874 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005875 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07005876 }
5877 }
5878
5879 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005880 * Sets the grant state of a runtime permission for a specific application. The state can be
5881 * {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it through the UI,
5882 * {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission is denied and the user
5883 * cannot manage it through the UI, and {@link #PERMISSION_GRANT_STATE_GRANTED granted} in which
5884 * the permission is granted and the user cannot manage it through the UI. This might affect all
5885 * permissions in a group that the runtime permission belongs to. This method can only be called
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005886 * by a profile or device owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005887 * <p/>
5888 * Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not revoke
5889 * the permission. It retains the previous grant, if any.
5890 * <p/>
5891 * Permissions can be granted or revoked only for applications built with a
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005892 * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07005893 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07005894 * @param admin Which profile or device owner this request is associated with.
5895 * @param packageName The application to grant or revoke a permission to.
5896 * @param permission The permission to grant or revoke.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005897 * @param grantState The permission grant state which is one of
5898 * {@link #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
5899 * {@link #PERMISSION_GRANT_STATE_GRANTED},
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005900 * @return whether the permission was successfully granted or revoked.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005901 * @throws SecurityException if {@code admin} is not a device or profile owner.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005902 * @see #PERMISSION_GRANT_STATE_DENIED
5903 * @see #PERMISSION_GRANT_STATE_DEFAULT
5904 * @see #PERMISSION_GRANT_STATE_GRANTED
Amith Yamasanid49489b2015-04-28 14:00:26 -07005905 */
Robin Lee25e26452015-06-02 09:56:29 -07005906 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005907 String permission, int grantState) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005908 throwIfParentInstance("setPermissionGrantState");
Amith Yamasanid49489b2015-04-28 14:00:26 -07005909 try {
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005910 return mService.setPermissionGrantState(admin, packageName, permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07005911 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005912 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07005913 }
5914 }
Amith Yamasani184b3752015-05-22 13:00:51 -07005915
5916 /**
5917 * Returns the current grant state of a runtime permission for a specific application.
5918 *
5919 * @param admin Which profile or device owner this request is associated with.
5920 * @param packageName The application to check the grant state for.
5921 * @param permission The permission to check for.
5922 * @return the current grant state specified by device policy. If the profile or device owner
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005923 * has not set a grant state, the return value is
5924 * {@link #PERMISSION_GRANT_STATE_DEFAULT}. This does not indicate whether or not the
5925 * permission is currently granted for the package.
5926 * <p/>
5927 * If a grant state was set by the profile or device owner, then the return value will
5928 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or
5929 * {@link #PERMISSION_GRANT_STATE_GRANTED}, which indicates if the permission is
5930 * currently denied or granted.
5931 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasani184b3752015-05-22 13:00:51 -07005932 * @see #setPermissionGrantState(ComponentName, String, String, int)
5933 * @see PackageManager#checkPermission(String, String)
5934 */
Robin Lee25e26452015-06-02 09:56:29 -07005935 public int getPermissionGrantState(@NonNull ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07005936 String permission) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005937 throwIfParentInstance("getPermissionGrantState");
Amith Yamasani184b3752015-05-22 13:00:51 -07005938 try {
5939 return mService.getPermissionGrantState(admin, packageName, permission);
5940 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005941 throw re.rethrowFromSystemServer();
Amith Yamasani184b3752015-05-22 13:00:51 -07005942 }
5943 }
Nicolas Prevot07387fe2015-10-30 17:53:30 +00005944
5945 /**
5946 * Returns if provisioning a managed profile or device is possible or not.
5947 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
5948 * {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Nicolas Prevot07387fe2015-10-30 17:53:30 +00005949 * @return if provisioning a managed profile or device is possible or not.
5950 * @throws IllegalArgumentException if the supplied action is not valid.
5951 */
5952 public boolean isProvisioningAllowed(String action) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005953 throwIfParentInstance("isProvisioningAllowed");
Nicolas Prevot07387fe2015-10-30 17:53:30 +00005954 try {
5955 return mService.isProvisioningAllowed(action);
5956 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005957 throw re.rethrowFromSystemServer();
Nicolas Prevot07387fe2015-10-30 17:53:30 +00005958 }
5959 }
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005960
5961 /**
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005962 * Return if this user is a managed profile of another user. An admin can become the profile
5963 * owner of a managed profile with {@link #ACTION_PROVISION_MANAGED_PROFILE} and of a managed
Kenny Guyffa38402016-03-31 16:40:57 +01005964 * user with {@link #createAndManageUser}
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005965 * @param admin Which profile owner this request is associated with.
5966 * @return if this user is a managed profile of another user.
5967 */
5968 public boolean isManagedProfile(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005969 throwIfParentInstance("isManagedProfile");
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005970 try {
5971 return mService.isManagedProfile(admin);
5972 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005973 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005974 }
5975 }
5976
5977 /**
5978 * @hide
5979 * Return if this user is a system-only user. An admin can manage a device from a system only
5980 * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}.
5981 * @param admin Which device owner this request is associated with.
5982 * @return if this user is a system-only user.
5983 */
5984 public boolean isSystemOnlyUser(@NonNull ComponentName admin) {
5985 try {
5986 return mService.isSystemOnlyUser(admin);
5987 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005988 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005989 }
5990 }
Makoto Onukia31ebbc2015-11-23 17:15:21 -08005991
5992 /**
5993 * Called by device owner to get the MAC address of the Wi-Fi device.
5994 *
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08005995 * @param admin Which device owner this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005996 * @return the MAC address of the Wi-Fi device, or null when the information is not available.
5997 * (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.)
5998 * <p>
5999 * The address will be in the {@code XX:XX:XX:XX:XX:XX} format.
6000 * @throws SecurityException if {@code admin} is not a device owner.
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006001 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006002 public @Nullable String getWifiMacAddress(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006003 throwIfParentInstance("getWifiMacAddress");
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006004 try {
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08006005 return mService.getWifiMacAddress(admin);
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006006 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006007 throw re.rethrowFromSystemServer();
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006008 }
6009 }
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00006010
6011 /**
Mahaver Chopra1216ae52016-03-11 15:39:48 +00006012 * Called by device owner to reboot the device. If there is an ongoing call on the device,
6013 * throws an {@link IllegalStateException}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006014 * @param admin Which device owner the request is associated with.
Mahaver Chopra1216ae52016-03-11 15:39:48 +00006015 * @throws IllegalStateException if device has an ongoing call.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006016 * @throws SecurityException if {@code admin} is not a device owner.
Mahaver Chopra1216ae52016-03-11 15:39:48 +00006017 * @see TelephonyManager#CALL_STATE_IDLE
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00006018 */
6019 public void reboot(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006020 throwIfParentInstance("reboot");
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00006021 try {
6022 mService.reboot(admin);
6023 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006024 throw re.rethrowFromSystemServer();
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00006025 }
6026 }
Kenny Guy06de4e72015-12-22 12:07:39 +00006027
6028 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006029 * Called by a device admin to set the short support message. This will be displayed to the user
6030 * in settings screens where funtionality has been disabled by the admin. The message should be
6031 * limited to a short statement such as "This setting is disabled by your administrator. Contact
6032 * someone@example.com for support." If the message is longer than 200 characters it may be
6033 * truncated.
6034 * <p>
6035 * If the short support message needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006036 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
6037 * and set a new version of this string accordingly.
6038 *
Kenny Guy06de4e72015-12-22 12:07:39 +00006039 * @see #setLongSupportMessage
Kenny Guy06de4e72015-12-22 12:07:39 +00006040 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006041 * @param message Short message to be displayed to the user in settings or null to clear the
6042 * existing message.
6043 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00006044 */
6045 public void setShortSupportMessage(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006046 @Nullable CharSequence message) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006047 throwIfParentInstance("setShortSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00006048 if (mService != null) {
6049 try {
6050 mService.setShortSupportMessage(admin, message);
6051 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006052 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006053 }
6054 }
6055 }
6056
6057 /**
6058 * Called by a device admin to get the short support message.
6059 *
6060 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006061 * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)} or
6062 * null if no message has been set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006063 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00006064 */
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006065 public CharSequence getShortSupportMessage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006066 throwIfParentInstance("getShortSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00006067 if (mService != null) {
6068 try {
6069 return mService.getShortSupportMessage(admin);
6070 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006071 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006072 }
6073 }
6074 return null;
6075 }
6076
6077 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006078 * Called by a device admin to set the long support message. This will be displayed to the user
6079 * in the device administators settings screen.
6080 * <p>
6081 * If the long support message needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006082 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
6083 * and set a new version of this string accordingly.
6084 *
Kenny Guy06de4e72015-12-22 12:07:39 +00006085 * @see #setShortSupportMessage
Kenny Guy06de4e72015-12-22 12:07:39 +00006086 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006087 * @param message Long message to be displayed to the user in settings or null to clear the
6088 * existing message.
6089 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00006090 */
6091 public void setLongSupportMessage(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006092 @Nullable CharSequence message) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006093 throwIfParentInstance("setLongSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00006094 if (mService != null) {
6095 try {
6096 mService.setLongSupportMessage(admin, message);
6097 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006098 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006099 }
6100 }
6101 }
6102
6103 /**
6104 * Called by a device admin to get the long support message.
6105 *
6106 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006107 * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)} or
6108 * null if no message has been set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006109 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00006110 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006111 public @Nullable CharSequence getLongSupportMessage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006112 throwIfParentInstance("getLongSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00006113 if (mService != null) {
6114 try {
6115 return mService.getLongSupportMessage(admin);
6116 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006117 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006118 }
6119 }
6120 return null;
6121 }
6122
6123 /**
6124 * Called by the system to get the short support message.
6125 *
6126 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6127 * @param userHandle user id the admin is running as.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006128 * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)}
Kenny Guy06de4e72015-12-22 12:07:39 +00006129 *
6130 * @hide
6131 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006132 public @Nullable CharSequence getShortSupportMessageForUser(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006133 int userHandle) {
Kenny Guy06de4e72015-12-22 12:07:39 +00006134 if (mService != null) {
6135 try {
6136 return mService.getShortSupportMessageForUser(admin, userHandle);
6137 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006138 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006139 }
6140 }
6141 return null;
6142 }
6143
6144
6145 /**
6146 * Called by the system to get the long support message.
6147 *
6148 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6149 * @param userHandle user id the admin is running as.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006150 * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)}
Kenny Guy06de4e72015-12-22 12:07:39 +00006151 *
6152 * @hide
6153 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006154 public @Nullable CharSequence getLongSupportMessageForUser(
6155 @NonNull ComponentName admin, int userHandle) {
Kenny Guy06de4e72015-12-22 12:07:39 +00006156 if (mService != null) {
6157 try {
6158 return mService.getLongSupportMessageForUser(admin, userHandle);
6159 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006160 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006161 }
6162 }
6163 return null;
6164 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006165
6166 /**
Esteban Talavera62399912016-01-11 15:37:55 +00006167 * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager}
6168 * whose calls act on the parent profile.
Benjamin Franz66b45f02016-04-05 19:12:39 +01006169 *
6170 * <p>The following methods are supported for the parent instance, all other methods will
6171 * throw a SecurityException when called on the parent instance:
6172 * <ul>
6173 * <li>{@link #getPasswordQuality}</li>
6174 * <li>{@link #setPasswordQuality}</li>
6175 * <li>{@link #getPasswordMinimumLength}</li>
6176 * <li>{@link #setPasswordMinimumLength}</li>
6177 * <li>{@link #getPasswordMinimumUpperCase}</li>
6178 * <li>{@link #setPasswordMinimumUpperCase}</li>
6179 * <li>{@link #getPasswordMinimumLowerCase}</li>
6180 * <li>{@link #setPasswordMinimumLowerCase}</li>
6181 * <li>{@link #getPasswordMinimumLetters}</li>
6182 * <li>{@link #setPasswordMinimumLetters}</li>
6183 * <li>{@link #getPasswordMinimumNumeric}</li>
6184 * <li>{@link #setPasswordMinimumNumeric}</li>
6185 * <li>{@link #getPasswordMinimumSymbols}</li>
6186 * <li>{@link #setPasswordMinimumSymbols}</li>
6187 * <li>{@link #getPasswordMinimumNonLetter}</li>
6188 * <li>{@link #setPasswordMinimumNonLetter}</li>
6189 * <li>{@link #getPasswordHistoryLength}</li>
6190 * <li>{@link #setPasswordHistoryLength}</li>
6191 * <li>{@link #getPasswordExpirationTimeout}</li>
6192 * <li>{@link #setPasswordExpirationTimeout}</li>
6193 * <li>{@link #getPasswordExpiration}</li>
Charles He8c760562016-10-25 16:36:53 +01006194 * <li>{@link #getPasswordMaximumLength}</li>
Benjamin Franz66b45f02016-04-05 19:12:39 +01006195 * <li>{@link #isActivePasswordSufficient}</li>
6196 * <li>{@link #getCurrentFailedPasswordAttempts}</li>
6197 * <li>{@link #getMaximumFailedPasswordsForWipe}</li>
6198 * <li>{@link #setMaximumFailedPasswordsForWipe}</li>
6199 * <li>{@link #getMaximumTimeToLock}</li>
6200 * <li>{@link #setMaximumTimeToLock}</li>
6201 * <li>{@link #lockNow}</li>
6202 * <li>{@link #getKeyguardDisabledFeatures}</li>
6203 * <li>{@link #setKeyguardDisabledFeatures}</li>
6204 * <li>{@link #getTrustAgentConfiguration}</li>
6205 * <li>{@link #setTrustAgentConfiguration}</li>
Michal Karpinskia20d8bb2016-11-23 12:09:08 +00006206 * <li>{@link #getRequiredStrongAuthTimeout}</li>
6207 * <li>{@link #setRequiredStrongAuthTimeout}</li>
Benjamin Franz66b45f02016-04-05 19:12:39 +01006208 * </ul>
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006209 *
6210 * @return a new instance of {@link DevicePolicyManager} that acts on the parent profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006211 * @throws SecurityException if {@code admin} is not a profile owner.
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006212 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006213 public @NonNull DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006214 throwIfParentInstance("getParentProfileInstance");
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006215 try {
6216 if (!mService.isManagedProfile(admin)) {
6217 throw new SecurityException("The current user does not have a parent profile.");
6218 }
Jeff Sharkey49ca5292016-05-10 12:54:45 -06006219 return new DevicePolicyManager(mContext, mService, true);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006220 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006221 throw e.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006222 }
6223 }
6224
6225 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00006226 * Called by device owner to control the security logging feature. Logging can only be
6227 * enabled on single user devices where the sole user is managed by the device owner.
6228 *
6229 * <p> Security logs contain various information intended for security auditing purposes.
6230 * See {@link SecurityEvent} for details.
6231 *
6232 * <p>There must be only one user on the device, managed by the device owner.
6233 * Otherwise a {@link SecurityException} will be thrown.
Michal Karpinskib58e4962016-03-01 14:55:10 +00006234 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006235 * @param admin Which device owner this request is associated with.
Michal Karpinski6235a942016-03-15 12:07:23 +00006236 * @param enabled whether security logging should be enabled or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006237 * @throws SecurityException if {@code admin} is not a device owner.
Michal Karpinski6235a942016-03-15 12:07:23 +00006238 * @see #retrieveSecurityLogs
6239 */
6240 public void setSecurityLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006241 throwIfParentInstance("setSecurityLoggingEnabled");
Michal Karpinski6235a942016-03-15 12:07:23 +00006242 try {
6243 mService.setSecurityLoggingEnabled(admin, enabled);
6244 } catch (RemoteException re) {
6245 throw re.rethrowFromSystemServer();
6246 }
6247 }
6248
6249 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00006250 * Return whether security logging is enabled or not by the device owner.
6251 *
6252 * <p>Can only be called by the device owner, otherwise a {@link SecurityException} will be
6253 * thrown.
6254 *
6255 * @param admin Which device owner this request is associated with.
6256 * @return {@code true} if security logging is enabled by device owner, {@code false} otherwise.
6257 * @throws SecurityException if {@code admin} is not a device owner.
6258 */
6259 public boolean isSecurityLoggingEnabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006260 throwIfParentInstance("isSecurityLoggingEnabled");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006261 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00006262 return mService.isSecurityLoggingEnabled(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006263 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006264 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006265 }
6266 }
6267
6268 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00006269 * Called by device owner to retrieve all new security logging entries since the last call to
6270 * this API after device boots.
6271 *
6272 * <p> Access to the logs is rate limited and it will only return new logs after the device
6273 * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}.
6274 *
6275 * <p>There must be only one user on the device, managed by the device owner.
6276 * Otherwise a {@link SecurityException} will be thrown.
Michal Karpinskib58e4962016-03-01 14:55:10 +00006277 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006278 * @param admin Which device owner this request is associated with.
Michal Karpinski6235a942016-03-15 12:07:23 +00006279 * @return the new batch of security logs which is a list of {@link SecurityEvent},
6280 * or {@code null} if rate limitation is exceeded or if logging is currently disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006281 * @throws SecurityException if {@code admin} is not a device owner.
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006282 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006283 public @Nullable List<SecurityEvent> retrieveSecurityLogs(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006284 throwIfParentInstance("retrieveSecurityLogs");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006285 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00006286 ParceledListSlice<SecurityEvent> list = mService.retrieveSecurityLogs(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006287 if (list != null) {
6288 return list.getList();
6289 } else {
6290 // Rate limit exceeded.
6291 return null;
6292 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006293 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006294 throw re.rethrowFromSystemServer();
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006295 }
6296 }
Benjamin Franz59720bb2016-01-18 15:26:11 +00006297
6298 /**
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00006299 * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent
6300 * profile.
6301 *
6302 * @hide
6303 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006304 public @NonNull DevicePolicyManager getParentProfileInstance(UserInfo uInfo) {
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00006305 mContext.checkSelfPermission(
6306 android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS);
6307 if (!uInfo.isManagedProfile()) {
6308 throw new SecurityException("The user " + uInfo.id
6309 + " does not have a parent profile.");
6310 }
Jeff Sharkey49ca5292016-05-10 12:54:45 -06006311 return new DevicePolicyManager(mContext, mService, true);
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00006312 }
6313
6314 /**
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006315 * Called by device owners to retrieve device logs from before the device's last reboot.
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006316 * <p>
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01006317 * <strong> This API is not supported on all devices. Calling this API on unsupported devices
6318 * will result in {@code null} being returned. The device logs are retrieved from a RAM region
6319 * which is not guaranteed to be corruption-free during power cycles, as a result be cautious
6320 * about data corruption when parsing. </strong>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006321 * <p>
6322 * There must be only one user on the device, managed by the device owner. Otherwise a
6323 * {@link SecurityException} will be thrown.
Michal Karpinskib58e4962016-03-01 14:55:10 +00006324 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006325 * @param admin Which device owner this request is associated with.
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01006326 * @return Device logs from before the latest reboot of the system, or {@code null} if this API
6327 * is not supported on the device.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006328 * @throws SecurityException if {@code admin} is not a device owner.
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006329 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006330 public @Nullable List<SecurityEvent> retrievePreRebootSecurityLogs(
6331 @NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006332 throwIfParentInstance("retrievePreRebootSecurityLogs");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006333 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00006334 ParceledListSlice<SecurityEvent> list = mService.retrievePreRebootSecurityLogs(admin);
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01006335 if (list != null) {
6336 return list.getList();
6337 } else {
6338 return null;
6339 }
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006340 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006341 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006342 }
6343 }
6344
6345 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006346 * Called by a profile owner of a managed profile to set the color used for customization. This
6347 * color is used as background color of the confirm credentials screen for that user. The
Clara Bayarri8d0bd7fa2016-03-30 14:59:58 +01006348 * default color is teal (#00796B).
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006349 * <p>
6350 * The confirm credentials screen can be created using
Benjamin Franz59720bb2016-01-18 15:26:11 +00006351 * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}.
6352 *
6353 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinski74cd7302016-04-12 15:17:36 +01006354 * @param color The 24bit (0xRRGGBB) representation of the color to be used.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006355 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz59720bb2016-01-18 15:26:11 +00006356 */
6357 public void setOrganizationColor(@NonNull ComponentName admin, int color) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006358 throwIfParentInstance("setOrganizationColor");
Benjamin Franz59720bb2016-01-18 15:26:11 +00006359 try {
Michal Karpinski74cd7302016-04-12 15:17:36 +01006360 // always enforce alpha channel to have 100% opacity
6361 color |= 0xFF000000;
Benjamin Franz59720bb2016-01-18 15:26:11 +00006362 mService.setOrganizationColor(admin, color);
6363 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006364 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00006365 }
6366 }
6367
6368 /**
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00006369 * @hide
6370 *
6371 * Sets the color used for customization.
6372 *
Michal Karpinski74cd7302016-04-12 15:17:36 +01006373 * @param color The 24bit (0xRRGGBB) representation of the color to be used.
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00006374 * @param userId which user to set the color to.
6375 * @RequiresPermission(allOf = {
6376 * Manifest.permission.MANAGE_USERS,
6377 * Manifest.permission.INTERACT_ACROSS_USERS_FULL})
6378 */
6379 public void setOrganizationColorForUser(@ColorInt int color, @UserIdInt int userId) {
6380 try {
Michal Karpinski74cd7302016-04-12 15:17:36 +01006381 // always enforce alpha channel to have 100% opacity
6382 color |= 0xFF000000;
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00006383 mService.setOrganizationColorForUser(color, userId);
6384 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006385 throw re.rethrowFromSystemServer();
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00006386 }
6387 }
6388
6389 /**
Benjamin Franz59720bb2016-01-18 15:26:11 +00006390 * Called by a profile owner of a managed profile to retrieve the color used for customization.
6391 * This color is used as background color of the confirm credentials screen for that user.
6392 *
6393 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinski74cd7302016-04-12 15:17:36 +01006394 * @return The 24bit (0xRRGGBB) representation of the color to be used.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006395 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz59720bb2016-01-18 15:26:11 +00006396 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01006397 public @ColorInt int getOrganizationColor(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006398 throwIfParentInstance("getOrganizationColor");
Benjamin Franz59720bb2016-01-18 15:26:11 +00006399 try {
6400 return mService.getOrganizationColor(admin);
6401 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006402 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00006403 }
6404 }
6405
6406 /**
6407 * @hide
6408 * Retrieve the customization color for a given user.
6409 *
6410 * @param userHandle The user id of the user we're interested in.
Michal Karpinski74cd7302016-04-12 15:17:36 +01006411 * @return The 24bit (0xRRGGBB) representation of the color to be used.
Benjamin Franz59720bb2016-01-18 15:26:11 +00006412 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01006413 public @ColorInt int getOrganizationColorForUser(int userHandle) {
Benjamin Franz59720bb2016-01-18 15:26:11 +00006414 try {
6415 return mService.getOrganizationColorForUser(userHandle);
6416 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006417 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00006418 }
6419 }
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006420
6421 /**
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006422 * Called by a profile owner of a managed profile to set the name of the organization under
6423 * management.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006424 * <p>
6425 * If the organization name needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006426 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
6427 * and set a new version of this string accordingly.
6428 *
6429 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6430 * @param title The organization name or {@code null} to clear a previously set name.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006431 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006432 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01006433 public void setOrganizationName(@NonNull ComponentName admin, @Nullable CharSequence title) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006434 throwIfParentInstance("setOrganizationName");
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006435 try {
6436 mService.setOrganizationName(admin, title);
6437 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006438 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006439 }
6440 }
6441
6442 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006443 * Called by a profile owner of a managed profile to retrieve the name of the organization under
6444 * management.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006445 *
6446 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6447 * @return The organization name or {@code null} if none is set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006448 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006449 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006450 public @Nullable CharSequence getOrganizationName(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006451 throwIfParentInstance("getOrganizationName");
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006452 try {
6453 return mService.getOrganizationName(admin);
6454 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006455 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006456 }
6457 }
6458
6459 /**
6460 * Retrieve the default title message used in the confirm credentials screen for a given user.
6461 *
6462 * @param userHandle The user id of the user we're interested in.
6463 * @return The organization name or {@code null} if none is set.
6464 *
6465 * @hide
6466 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006467 public @Nullable CharSequence getOrganizationNameForUser(int userHandle) {
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006468 try {
6469 return mService.getOrganizationNameForUser(userHandle);
6470 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006471 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006472 }
6473 }
6474
6475 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00006476 * @return the {@link UserProvisioningState} for the current user - for unmanaged users will
6477 * return {@link #STATE_USER_UNMANAGED}
6478 * @hide
6479 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00006480 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00006481 @UserProvisioningState
6482 public int getUserProvisioningState() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006483 throwIfParentInstance("getUserProvisioningState");
Alan Treadwayafad8782016-01-19 15:15:08 +00006484 if (mService != null) {
6485 try {
6486 return mService.getUserProvisioningState();
6487 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006488 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00006489 }
6490 }
6491 return STATE_USER_UNMANAGED;
6492 }
6493
6494 /**
6495 * Set the {@link UserProvisioningState} for the supplied user, if they are managed.
6496 *
6497 * @param state to store
6498 * @param userHandle for user
6499 * @hide
6500 */
6501 public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) {
6502 if (mService != null) {
6503 try {
6504 mService.setUserProvisioningState(state, userHandle);
6505 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006506 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00006507 }
6508 }
6509 }
6510
6511 /**
Esteban Talaverac9bb3782016-11-11 15:41:14 +00006512 * Indicates the entity that controls the device or profile owner. Two users/profiles are
6513 * affiliated if the set of ids set by their device or profile owners intersect.
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006514 *
6515 * @param admin Which profile or device owner this request is associated with.
Esteban Talaverac9bb3782016-11-11 15:41:14 +00006516 * @param ids A list of opaque non-empty affiliation ids. Duplicate elements will be ignored.
6517 *
6518 * @throws NullPointerException if {@code ids} is null or contains null elements.
6519 * @throws IllegalArgumentException if {@code ids} contains an empty string.
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006520 */
Esteban Talaverac9bb3782016-11-11 15:41:14 +00006521 public void setAffiliationIds(@NonNull ComponentName admin, @NonNull List<String> ids) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006522 throwIfParentInstance("setAffiliationIds");
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006523 try {
Esteban Talaverac9bb3782016-11-11 15:41:14 +00006524 mService.setAffiliationIds(admin, ids);
6525 } catch (RemoteException e) {
6526 throw e.rethrowFromSystemServer();
6527 }
6528 }
6529
6530 /**
6531 * Returns the list of affiliation ids previously set via {@link #setAffiliationIds}, or an
6532 * empty list if none have been set.
6533 */
6534 public @NonNull List<String> getAffiliationIds(@NonNull ComponentName admin) {
6535 throwIfParentInstance("getAffiliationIds");
6536 try {
6537 return mService.getAffiliationIds(admin);
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006538 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006539 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006540 }
6541 }
6542
6543 /**
6544 * @hide
Esteban Talaverac9bb3782016-11-11 15:41:14 +00006545 * Returns whether this user/profile is affiliated with the device.
6546 * <p>
6547 * By definition, the user that the device owner runs on is always affiliated with the device.
6548 * Any other user/profile is considered affiliated with the device if the set specified by its
6549 * profile owner via {@link #setAffiliationIds} intersects with the device owner's.
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006550 *
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006551 */
6552 public boolean isAffiliatedUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006553 throwIfParentInstance("isAffiliatedUser");
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006554 try {
Esteban Talaverac9bb3782016-11-11 15:41:14 +00006555 return mService.isAffiliatedUser();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006556 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006557 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006558 }
6559 }
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08006560
6561 /**
6562 * @hide
6563 * Returns whether the uninstall for {@code packageName} for the current user is in queue
6564 * to be started
6565 * @param packageName the package to check for
6566 * @return whether the uninstall intent for {@code packageName} is pending
6567 */
6568 public boolean isUninstallInQueue(String packageName) {
6569 try {
6570 return mService.isUninstallInQueue(packageName);
6571 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006572 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08006573 }
6574 }
6575
6576 /**
6577 * @hide
6578 * @param packageName the package containing active DAs to be uninstalled
6579 */
6580 public void uninstallPackageWithActiveAdmins(String packageName) {
6581 try {
6582 mService.uninstallPackageWithActiveAdmins(packageName);
6583 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006584 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08006585 }
6586 }
Benjamin Franzbc33c822016-04-15 08:57:52 +01006587
Kenny Guy38dcca52016-04-19 13:09:18 +01006588 /**
6589 * @hide
6590 * Remove a test admin synchronously without sending it a broadcast about being removed.
6591 * If the admin is a profile owner or device owner it will still be removed.
6592 *
6593 * @param userHandle user id to remove the admin for.
6594 * @param admin The administration compononent to remove.
6595 * @throws SecurityException if the caller is not shell / root or the admin package
6596 * isn't a test application see {@link ApplicationInfo#FLAG_TEST_APP}.
6597 */
6598 public void forceRemoveActiveAdmin(ComponentName adminReceiver, int userHandle) {
6599 try {
6600 mService.forceRemoveActiveAdmin(adminReceiver, userHandle);
6601 } catch (RemoteException re) {
6602 throw re.rethrowFromSystemServer();
6603 }
6604 }
6605
Mahaver Chopra790d1982016-07-07 16:06:49 +01006606 /**
6607 * @hide
6608 * @return whether {@link android.provider.Settings.Global#DEVICE_PROVISIONED} has ever been set
6609 * to 1.
6610 */
6611 public boolean isDeviceProvisioned() {
6612 try {
6613 return mService.isDeviceProvisioned();
6614 } catch (RemoteException re) {
6615 throw re.rethrowFromSystemServer();
6616 }
6617 }
6618
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01006619 /**
6620 * @hide
6621 * Writes that the provisioning configuration has been applied.
6622 */
6623 public void setDeviceProvisioningConfigApplied() {
6624 try {
6625 mService.setDeviceProvisioningConfigApplied();
6626 } catch (RemoteException re) {
6627 throw re.rethrowFromSystemServer();
6628 }
6629 }
6630
6631 /**
6632 * @hide
6633 * @return whether the provisioning configuration has been applied.
6634 */
6635 public boolean isDeviceProvisioningConfigApplied() {
6636 try {
6637 return mService.isDeviceProvisioningConfigApplied();
6638 } catch (RemoteException re) {
6639 throw re.rethrowFromSystemServer();
6640 }
6641 }
6642
Victor Chang9bfc65f2016-08-15 12:27:09 +01006643 /**
6644 * @hide
Victor Chang3577ed22016-08-25 18:49:26 +01006645 * Force update user setup completed status. This API has no effect on user build.
6646 * @throws {@link SecurityException} if the caller has no
6647 * {@link android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS} or the caller is
6648 * not {@link UserHandle.SYSTEM_USER}
Victor Chang9bfc65f2016-08-15 12:27:09 +01006649 */
6650 public void forceUpdateUserSetupComplete() {
6651 try {
6652 mService.forceUpdateUserSetupComplete();
6653 } catch (RemoteException re) {
6654 throw re.rethrowFromSystemServer();
6655 }
6656 }
6657
Benjamin Franzbc33c822016-04-15 08:57:52 +01006658 private void throwIfParentInstance(String functionName) {
6659 if (mParentInstance) {
6660 throw new SecurityException(functionName + " cannot be called on the parent instance");
6661 }
6662 }
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02006663
6664 /**
6665 * @hide
6666 * Enable backup service.
6667 * <p>This includes all backup and restore mechanisms.
6668 * Setting this to {@code false} will make backup service no-op or return empty results.
6669 *
6670 * <p>There must be only one user on the device, managed by the device owner.
6671 * Otherwise a {@link SecurityException} will be thrown.
6672 *
6673 * <p>Backup service is off by default when device owner is present.
6674 */
6675 public void setBackupServiceEnabled(@NonNull ComponentName admin, boolean enabled) {
6676 try {
6677 mService.setBackupServiceEnabled(admin, enabled);
6678 } catch (RemoteException re) {
6679 throw re.rethrowFromSystemServer();
6680 }
6681 }
6682
6683 /**
6684 * @hide
6685 * @return {@code true} if backup service is enabled, {@code false} otherwise.
6686 */
6687 public boolean isBackupServiceEnabled(@NonNull ComponentName admin) {
6688 try {
6689 return mService.isBackupServiceEnabled(admin);
6690 } catch (RemoteException re) {
6691 throw re.rethrowFromSystemServer();
6692 }
6693 }
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01006694
6695 /**
6696 * Called by a device owner to control the network logging feature. Logging can only be
6697 * enabled on single user devices where the sole user is managed by the device owner. If a new
6698 * user is added on the device, logging is disabled.
6699 *
6700 * <p> Network logs contain DNS lookup and connect() library call events.
6701 *
6702 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6703 * @param enabled whether network logging should be enabled or not.
6704 * @throws {@link SecurityException} if {@code admin} is not a device owner.
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01006705 * @see #retrieveNetworkLogs
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01006706 *
6707 * @hide
6708 */
6709 public void setNetworkLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
6710 throwIfParentInstance("setNetworkLoggingEnabled");
6711 try {
6712 mService.setNetworkLoggingEnabled(admin, enabled);
6713 } catch (RemoteException re) {
6714 throw re.rethrowFromSystemServer();
6715 }
6716 }
6717
6718 /**
6719 * Return whether network logging is enabled by a device owner.
6720 *
6721 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6722 * @return {@code true} if network logging is enabled by device owner, {@code false} otherwise.
6723 * @throws {@link SecurityException} if {@code admin} is not a device owner.
6724 *
6725 * @hide
6726 */
6727 public boolean isNetworkLoggingEnabled(@NonNull ComponentName admin) {
6728 throwIfParentInstance("isNetworkLoggingEnabled");
6729 try {
6730 return mService.isNetworkLoggingEnabled(admin);
6731 } catch (RemoteException re) {
6732 throw re.rethrowFromSystemServer();
6733 }
6734 }
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01006735
6736 /**
Michal Karpinskia9ff2062016-11-03 15:46:17 +00006737 * Called by device owner to retrieve the most recent batch of network logging events.
6738 * A device owner has to provide a batchToken provided as part of
6739 * {@link DeviceAdminReceiver#onNetworkLogsAvailable} callback. If the token doesn't match the
6740 * token of the most recent available batch of logs, {@code null} will be returned.
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01006741 *
6742 * <p> {@link NetworkEvent} can be one of {@link DnsEvent} or {@link ConnectEvent}.
6743 *
6744 * <p> The list of network events is sorted chronologically, and contains at most 1200 events.
6745 *
6746 * <p> Access to the logs is rate limited and this method will only return a new batch of logs
6747 * after the device device owner has been notified via
6748 * {@link DeviceAdminReceiver#onNetworkLogsAvailable}.
6749 *
6750 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinskia9ff2062016-11-03 15:46:17 +00006751 * @param batchToken A token of the batch to retrieve
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01006752 * @return A new batch of network logs which is a list of {@link NetworkEvent}. Returns
Michal Karpinskia9ff2062016-11-03 15:46:17 +00006753 * {@code null} if the batch represented by batchToken is no longer available or if
6754 * logging is disabled.
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01006755 * @throws {@link SecurityException} if {@code admin} is not a device owner.
Michal Karpinskia9ff2062016-11-03 15:46:17 +00006756 * @see DeviceAdminReceiver#onNetworkLogsAvailable
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01006757 *
6758 * @hide
6759 */
Michal Karpinskia9ff2062016-11-03 15:46:17 +00006760 public @Nullable List<NetworkEvent> retrieveNetworkLogs(@NonNull ComponentName admin,
6761 long batchToken) {
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01006762 throwIfParentInstance("retrieveNetworkLogs");
6763 try {
Michal Karpinskia9ff2062016-11-03 15:46:17 +00006764 return mService.retrieveNetworkLogs(admin, batchToken);
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01006765 } catch (RemoteException re) {
6766 throw re.rethrowFromSystemServer();
6767 }
6768 }
Tony Mak46aabe52016-11-14 12:53:06 +00006769
6770 /**
Esteban Talaverafc291bc2016-11-21 13:52:03 +00006771 * Called by a device owner to bind to a service from a profile owner of a managed profile or
6772 * vice versa. See {@link #getBindDeviceAdminTargetUsers} for a definition of which
6773 * device/profile owners are allowed to bind to services of another profile/device owner.
6774 * <p>
Tony Mak46aabe52016-11-14 12:53:06 +00006775 * The service must be unexported. Note that the {@link Context} used to obtain this
6776 * {@link DevicePolicyManager} instance via {@link Context#getSystemService(Class)} will be used
6777 * to bind to the {@link android.app.Service}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00006778 *
Tony Mak46aabe52016-11-14 12:53:06 +00006779 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6780 * @param serviceIntent Identifies the service to connect to. The Intent must specify either an
6781 * explicit component name or a package name to match an
6782 * {@link IntentFilter} published by a service.
6783 * @param conn Receives information as the service is started and stopped. This must be a
6784 * valid {@link ServiceConnection} object; it must not be {@code null}.
6785 * @param flags Operation options for the binding operation. See
6786 * {@link Context#bindService(Intent, ServiceConnection, int)}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00006787 * @param targetUser Which user to bind to. Must be one of the users returned by
6788 * {@link #getBindDeviceAdminTargetUsers}, otherwise a {@link SecurityException} will
6789 * be thrown.
Tony Mak46aabe52016-11-14 12:53:06 +00006790 * @return If you have successfully bound to the service, {@code true} is returned;
6791 * {@code false} is returned if the connection is not made and you will not
6792 * receive the service object.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00006793 *
Tony Mak46aabe52016-11-14 12:53:06 +00006794 * @see Context#bindService(Intent, ServiceConnection, int)
Esteban Talaverafc291bc2016-11-21 13:52:03 +00006795 * @see #getBindDeviceAdminTargetUsers(ComponentName)
Tony Mak46aabe52016-11-14 12:53:06 +00006796 */
6797 public boolean bindDeviceAdminServiceAsUser(
6798 @NonNull ComponentName admin, Intent serviceIntent, @NonNull ServiceConnection conn,
6799 @Context.BindServiceFlags int flags, @NonNull UserHandle targetUser) {
6800 throwIfParentInstance("bindDeviceAdminServiceAsUser");
6801 // Keep this in sync with ContextImpl.bindServiceCommon.
6802 try {
6803 final IServiceConnection sd = mContext.getServiceDispatcher(conn, null, flags);
6804 serviceIntent.prepareToLeaveProcess(mContext);
6805 return mService.bindDeviceAdminServiceAsUser(admin,
6806 mContext.getIApplicationThread(), mContext.getActivityToken(), serviceIntent,
6807 sd, flags, targetUser.getIdentifier());
6808 } catch (RemoteException re) {
6809 throw re.rethrowFromSystemServer();
6810 }
6811 }
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01006812
6813 /**
Esteban Talaverafc291bc2016-11-21 13:52:03 +00006814 * Returns the list of target users that the calling device or profile owner can use when
6815 * calling {@link #bindDeviceAdminServiceAsUser}.
6816 * <p>
6817 * A device owner can bind to a service from a profile owner of a managed profile and
6818 * vice versa, provided that:
6819 * <ul>
6820 * <li>Both belong to the same package name.
6821 * <li>The managed profile is a profile of the user where the device owner is set.
6822 * See {@link UserManager#getUserProfiles()}
6823 * <li>Both users are affiliated.
6824 * STOPSHIP(b/32326223) Add reference to setAffiliationIds here once public.
6825 * </ul>
6826 */
6827 public @NonNull List<UserHandle> getBindDeviceAdminTargetUsers(@NonNull ComponentName admin) {
6828 throwIfParentInstance("getBindDeviceAdminTargetUsers");
6829 try {
6830 return mService.getBindDeviceAdminTargetUsers(admin);
6831 } catch (RemoteException re) {
6832 throw re.rethrowFromSystemServer();
6833 }
6834 }
6835
6836 /**
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01006837 * Called by the system to get the time at which the device owner last retrieved security
6838 * logging entries.
6839 *
6840 * @return the time at which the device owner most recently retrieved security logging entries,
6841 * in milliseconds since epoch; -1 if security logging entries were never retrieved.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01006842 * @throws SecurityException if the caller is not the device owner, does not hold the
6843 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01006844 *
6845 * @hide
6846 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01006847 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01006848 public long getLastSecurityLogRetrievalTime() {
6849 try {
6850 return mService.getLastSecurityLogRetrievalTime();
6851 } catch (RemoteException re) {
6852 throw re.rethrowFromSystemServer();
6853 }
6854 }
6855
6856 /**
6857 * Called by the system to get the time at which the device owner last requested a bug report.
6858 *
6859 * @return the time at which the device owner most recently requested a bug report, in
6860 * milliseconds since epoch; -1 if a bug report was never requested.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01006861 * @throws SecurityException if the caller is not the device owner, does not hold the
6862 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01006863 *
6864 * @hide
6865 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01006866 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01006867 public long getLastBugReportRequestTime() {
6868 try {
6869 return mService.getLastBugReportRequestTime();
6870 } catch (RemoteException re) {
6871 throw re.rethrowFromSystemServer();
6872 }
6873 }
6874
6875 /**
6876 * Called by the system to get the time at which the device owner last retrieved network logging
6877 * events.
6878 *
6879 * @return the time at which the device owner most recently retrieved network logging events, in
6880 * milliseconds since epoch; -1 if network logging events were never retrieved.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01006881 * @throws SecurityException if the caller is not the device owner, does not hold the
6882 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01006883 *
6884 * @hide
6885 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01006886 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01006887 public long getLastNetworkLogRetrievalTime() {
6888 try {
6889 return mService.getLastNetworkLogRetrievalTime();
6890 } catch (RemoteException re) {
6891 throw re.rethrowFromSystemServer();
6892 }
6893 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08006894}