blob: 08832d1baa8b803c865588c3f9e9a828f6acbba0 [file] [log] [blame]
Dianne Hackbornd6847842010-01-12 18:14:19 -08001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Dianne Hackborn87bba1e2010-02-26 17:25:54 -080017package android.app.admin;
Dianne Hackbornd6847842010-01-12 18:14:19 -080018
Nicolas Prevot8f7698a2016-02-11 16:05:33 +000019import android.annotation.ColorInt;
Alan Treadwayafad8782016-01-19 15:15:08 +000020import android.annotation.IntDef;
Robin Lee25e26452015-06-02 09:56:29 -070021import android.annotation.NonNull;
22import android.annotation.Nullable;
Dianne Hackbornd6847842010-01-12 18:14:19 -080023import android.annotation.SdkConstant;
24import android.annotation.SdkConstant.SdkConstantType;
Justin Moreyb5deda72014-07-24 10:53:40 -050025import android.annotation.SystemApi;
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +010026import android.annotation.TestApi;
Nicolas Prevot8f7698a2016-02-11 16:05:33 +000027import android.annotation.UserIdInt;
Fyodor Kupolov4e9af062016-07-18 16:59:11 -070028import android.annotation.WorkerThread;
Jason Monkd7b86212014-06-16 13:15:38 -040029import android.app.Activity;
Tony Mak46aabe52016-11-14 12:53:06 +000030import android.app.IServiceConnection;
Michal Karpinski6235a942016-03-15 12:07:23 +000031import android.app.admin.SecurityLog.SecurityEvent;
Dianne Hackbornd6847842010-01-12 18:14:19 -080032import android.content.ComponentName;
33import android.content.Context;
Adam Connors010cfd42014-04-16 12:48:13 +010034import android.content.Intent;
Sander Alewijnsef475ca32014-02-17 15:13:58 +000035import android.content.IntentFilter;
Tony Mak46aabe52016-11-14 12:53:06 +000036import android.content.ServiceConnection;
Victor Chang98607132017-01-27 11:51:56 +000037import android.content.pm.ApplicationInfo;
Dianne Hackbornd6847842010-01-12 18:14:19 -080038import android.content.pm.PackageManager;
Victor Changcd14c0a2016-03-16 19:10:15 +000039import android.content.pm.PackageManager.NameNotFoundException;
Rubin Xuc3cd05f2016-01-11 12:11:35 +000040import android.content.pm.ParceledListSlice;
Sudheer Shanka978fc0d2016-01-28 13:51:10 +000041import android.content.pm.UserInfo;
Julia Reynoldsfca04ca2015-02-17 13:39:12 -050042import android.graphics.Bitmap;
Jason Monk03bc9912014-05-13 09:44:57 -040043import android.net.ProxyInfo;
Nicolas Prevot8b7991c2015-11-12 17:40:12 +000044import android.net.Uri;
Robin Lee66e5d962014-04-09 16:44:21 +010045import android.os.Bundle;
Victor Changc10f6692016-12-09 15:24:00 +000046import android.os.Parcelable;
Jim Millere303bf42014-08-26 17:12:29 -070047import android.os.PersistableBundle;
Adam Connors776c5552014-01-09 10:42:56 +000048import android.os.Process;
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080049import android.os.RemoteCallback;
Dianne Hackbornd6847842010-01-12 18:14:19 -080050import android.os.RemoteException;
Amith Yamasani599dd7c2012-09-14 23:20:08 -070051import android.os.UserHandle;
Julia Reynolds1e958392014-05-16 14:25:21 -040052import android.os.UserManager;
Ricky Wai494b95d2015-11-20 16:07:15 +000053import android.provider.ContactsContract.Directory;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000054import android.provider.Settings;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010055import android.security.Credentials;
Amith Yamasanid1d7c022014-08-19 17:03:41 -070056import android.service.restrictions.RestrictionsReceiver;
Mahaver Chopra1216ae52016-03-11 15:39:48 +000057import android.telephony.TelephonyManager;
Dianne Hackbornd6847842010-01-12 18:14:19 -080058import android.util.Log;
59
Makoto Onukicc4bbeb2015-09-17 10:28:24 -070060import com.android.internal.annotations.VisibleForTesting;
Maggie Benthallda51e682013-08-08 22:35:44 -040061import com.android.org.conscrypt.TrustedCertificateStore;
62
63import java.io.ByteArrayInputStream;
Dianne Hackbornd6847842010-01-12 18:14:19 -080064import java.io.IOException;
Alan Treadwayafad8782016-01-19 15:15:08 +000065import java.lang.annotation.Retention;
66import java.lang.annotation.RetentionPolicy;
Oscar Montemayor69238c62010-08-03 10:51:06 -070067import java.net.InetSocketAddress;
68import java.net.Proxy;
Robin Lee0d5ccb72014-09-12 17:41:44 +010069import java.security.KeyFactory;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000070import java.security.NoSuchAlgorithmException;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010071import java.security.PrivateKey;
72import java.security.cert.Certificate;
Maggie Benthallda51e682013-08-08 22:35:44 -040073import java.security.cert.CertificateException;
74import java.security.cert.CertificateFactory;
75import java.security.cert.X509Certificate;
Robin Lee0d5ccb72014-09-12 17:41:44 +010076import java.security.spec.InvalidKeySpecException;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000077import java.security.spec.PKCS8EncodedKeySpec;
Jim Miller604e7552014-07-18 19:00:02 -070078import java.util.ArrayList;
Rubin Xub4365912016-03-23 12:13:22 +000079import java.util.Arrays;
Svetoslav976e8bd2014-07-16 15:12:03 -070080import java.util.Collections;
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -080081import java.util.List;
Dianne Hackbornd6847842010-01-12 18:14:19 -080082
83/**
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000084 * Public interface for managing policies enforced on a device. Most clients of this class must be
Suprabh Shukla34d92ef2016-03-14 13:49:37 -070085 * registered with the system as a <a href="{@docRoot}guide/topics/admin/device-admin.html">device
86 * administrator</a>. Additionally, a device administrator may be registered as either a profile or
87 * device owner. A given method is accessible to all device administrators unless the documentation
88 * for that method specifies that it is restricted to either device or profile owners. Any
89 * application calling an api may only pass as an argument a device administrator component it
90 * owns. Otherwise, a {@link SecurityException} will be thrown.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080091 * <div class="special reference">
92 * <h3>Developer Guides</h3>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -070093 * <p>
94 * For more information about managing policies for device administration, read the <a href=
95 * "{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a> developer
96 * guide. </div>
Dianne Hackbornd6847842010-01-12 18:14:19 -080097 */
98public class DevicePolicyManager {
99 private static String TAG = "DevicePolicyManager";
Dianne Hackbornd6847842010-01-12 18:14:19 -0800100
101 private final Context mContext;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800102 private final IDevicePolicyManager mService;
Esteban Talavera62399912016-01-11 15:37:55 +0000103 private final boolean mParentInstance;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700104
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600105 /** @hide */
106 public DevicePolicyManager(Context context, IDevicePolicyManager service) {
107 this(context, service, false);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800108 }
109
Dianne Hackborn87bba1e2010-02-26 17:25:54 -0800110 /** @hide */
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700111 @VisibleForTesting
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600112 protected DevicePolicyManager(Context context, IDevicePolicyManager service,
113 boolean parentInstance) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700114 mContext = context;
115 mService = service;
Esteban Talavera62399912016-01-11 15:37:55 +0000116 mParentInstance = parentInstance;
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700117 }
118
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700119 /** @hide test will override it. */
120 @VisibleForTesting
121 protected int myUserId() {
122 return UserHandle.myUserId();
123 }
124
Dianne Hackbornd6847842010-01-12 18:14:19 -0800125 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +0000126 * Activity action: Starts the provisioning flow which sets up a managed profile.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000127 *
Jessica Hummel9da60392014-05-21 12:32:57 +0100128 * <p>A managed profile allows data separation for example for the usage of a
129 * device as a personal and corporate device. The user which provisioning is started from and
130 * the managed profile share a launcher.
131 *
Andrew Solovay27f53372015-03-02 16:37:59 -0800132 * <p>This intent will typically be sent by a mobile device management application (MDM).
133 * Provisioning adds a managed profile and sets the MDM as the profile owner who has full
134 * control over the profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100135 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000136 * <p>It is possible to check if provisioning is allowed or not by querying the method
137 * {@link #isProvisioningAllowed(String)}.
138 *
139 * <p>In version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this intent must contain the
Nicolas Prevot18440252015-03-09 14:07:17 +0000140 * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700141 * As of {@link android.os.Build.VERSION_CODES#M}, it should contain the extra
Nicolas Prevot18440252015-03-09 14:07:17 +0000142 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only
143 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000144 *
Benjamin Franzea956242016-03-21 15:45:56 +0000145 * <p>The intent may also contain the following extras:
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000146 * <ul>
Benjamin Franzea956242016-03-21 15:45:56 +0000147 * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, optional </li>
148 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional, supported from
149 * {@link android.os.Build.VERSION_CODES#N}</li>
150 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
151 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
152 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Victor Chang51d84f92016-11-16 12:22:56 +0000153 * <li>{@link #EXTRA_PROVISIONING_SKIP_USER_CONSENT}, optional</li>
Victor Chang89ee2792016-11-23 12:10:55 +0000154 * <li>{@link #EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION}, optional</li>
Victor Changc10f6692016-12-09 15:24:00 +0000155 * <li>{@link #EXTRA_PROVISIONING_DISCLAIMERS}, optional</li>
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000156 * </ul>
Jessica Hummelf72078b2014-03-06 16:13:12 +0000157 *
Benjamin Franzea956242016-03-21 15:45:56 +0000158 * <p>When managed provisioning has completed, broadcasts are sent to the application specified
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000159 * in the provisioning intent. The
160 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the
161 * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in
162 * the primary profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100163 *
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000164 * <p>From version {@link android.os.Build.VERSION_CODES#O}, when managed provisioning has
165 * completed, along with the above broadcast, activity intent
166 * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the application specified in
167 * the provisioning intent.
168 *
Benjamin Franzea956242016-03-21 15:45:56 +0000169 * <p>If provisioning fails, the managedProfile is removed so the device returns to its
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100170 * previous state.
Alan Treadway4582f812015-07-28 11:49:35 +0100171 *
172 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
173 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
174 * the provisioning flow was successful, although this doesn't guarantee the full flow will
175 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
176 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000177 */
178 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
179 public static final String ACTION_PROVISION_MANAGED_PROFILE
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100180 = "android.app.action.PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000181
182 /**
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000183 * Activity action: Starts the provisioning flow which sets up a managed user.
184 *
185 * <p>This intent will typically be sent by a mobile device management application (MDM).
Makoto Onuki32b30572015-12-11 14:29:51 -0800186 * Provisioning configures the user as managed user and sets the MDM as the profile
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000187 * owner who has full control over the user. Provisioning can only happen before user setup has
188 * been completed. Use {@link #isProvisioningAllowed(String)} to check if provisioning is
189 * allowed.
190 *
Benjamin Franzea956242016-03-21 15:45:56 +0000191 * <p>The intent contains the following extras:
192 * <ul>
193 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
194 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
195 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
196 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
197 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
198 * </ul>
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000199 *
Benjamin Franzea956242016-03-21 15:45:56 +0000200 * <p>If provisioning fails, the device returns to its previous state.
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000201 *
202 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
203 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
204 * the provisioning flow was successful, although this doesn't guarantee the full flow will
205 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
206 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Benjamin Franzea956242016-03-21 15:45:56 +0000207 *
208 * @hide
Mahaver Chopra5e732562015-11-05 11:55:12 +0000209 */
210 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
211 public static final String ACTION_PROVISION_MANAGED_USER
212 = "android.app.action.PROVISION_MANAGED_USER";
213
214 /**
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100215 * Activity action: Starts the provisioning flow which sets up a managed device.
216 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
217 *
218 * <p> During device owner provisioning a device admin app is set as the owner of the device.
219 * A device owner has full control over the device. The device owner can not be modified by the
220 * user.
221 *
222 * <p> A typical use case would be a device that is owned by a company, but used by either an
223 * employee or client.
224 *
225 * <p> An intent with this action can be sent only on an unprovisioned device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000226 * It is possible to check if provisioning is allowed or not by querying the method
227 * {@link #isProvisioningAllowed(String)}.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100228 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000229 * <p>The intent contains the following extras:
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100230 * <ul>
231 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
232 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
233 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
Rubin Xua4f9dc12015-06-12 13:27:59 +0100234 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000235 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000236 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Victor Changc10f6692016-12-09 15:24:00 +0000237 * <li>{@link #EXTRA_PROVISIONING_DISCLAIMERS}, optional</li>
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100238 * </ul>
239 *
Benjamin Franzea956242016-03-21 15:45:56 +0000240 * <p>When device owner provisioning has completed, an intent of the type
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100241 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
242 * device owner.
243 *
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000244 * <p>From version {@link android.os.Build.VERSION_CODES#O}, when device owner provisioning has
245 * completed, along with the above broadcast, activity intent
246 * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the device owner.
247 *
Benjamin Franzea956242016-03-21 15:45:56 +0000248 * <p>If provisioning fails, the device is factory reset.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100249 *
Alan Treadway4582f812015-07-28 11:49:35 +0100250 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
251 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
252 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
253 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100254 */
255 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
256 public static final String ACTION_PROVISION_MANAGED_DEVICE
257 = "android.app.action.PROVISION_MANAGED_DEVICE";
258
259 /**
Alan Treadway46dd4492015-11-09 13:57:19 +0000260 * Activity action: Starts the provisioning flow which sets up a managed device.
Steven Ng980a1b62016-02-02 17:43:18 +0000261 *
262 * <p>During device owner provisioning, a device admin app is downloaded and set as the owner of
263 * the device. A device owner has full control over the device. The device owner can not be
264 * modified by the user and the only way of resetting the device is via factory reset.
265 *
266 * <p>A typical use case would be a device that is owned by a company, but used by either an
267 * employee or client.
268 *
269 * <p>The provisioning message should be sent to an unprovisioned device.
270 *
271 * <p>Unlike {@link #ACTION_PROVISION_MANAGED_DEVICE}, the provisioning message can only be sent
272 * by a privileged app with the permission
273 * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE}.
274 *
275 * <p>The provisioning intent contains the following properties:
276 * <ul>
277 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
278 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
279 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
280 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Victor Chang38cfd9c2017-01-04 17:41:11 +0000281 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL}, optional</li>
282 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI}, optional</li>
Steven Ng980a1b62016-02-02 17:43:18 +0000283 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
284 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
285 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
286 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
287 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
288 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
289 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
290 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
291 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
292 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
293 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
Victor Chang38cfd9c2017-01-04 17:41:11 +0000294 * <li>{@link #EXTRA_PROVISIONING_SUPPORT_URL}, optional</li>
295 * <li>{@link #EXTRA_PROVISIONING_ORGANIZATION_NAME}, optional</li>
Steven Ng980a1b62016-02-02 17:43:18 +0000296 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li></ul>
297 *
298 * @hide
299 */
300 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
301 @SystemApi
302 public static final String ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE =
303 "android.app.action.PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE";
304
305 /**
306 * Activity action: Starts the provisioning flow which sets up a managed device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000307 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
308 *
309 * <p>NOTE: This is only supported on split system user devices, and puts the device into a
310 * management state that is distinct from that reached by
311 * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system
312 * user, and only has control over device-wide policies, not individual users and their data.
313 * The primary benefit is that multiple non-system users are supported when provisioning using
314 * this form of device management.
315 *
Benjamin Franzea956242016-03-21 15:45:56 +0000316 * <p>During device owner provisioning a device admin app is set as the owner of the device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000317 * A device owner has full control over the device. The device owner can not be modified by the
318 * user.
319 *
Benjamin Franzea956242016-03-21 15:45:56 +0000320 * <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 +0000321 * employee or client.
322 *
Benjamin Franzea956242016-03-21 15:45:56 +0000323 * <p>An intent with this action can be sent only on an unprovisioned device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000324 * It is possible to check if provisioning is allowed or not by querying the method
325 * {@link #isProvisioningAllowed(String)}.
326 *
327 * <p>The intent contains the following extras:
328 * <ul>
329 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
330 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
331 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
332 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Benjamin Franzea956242016-03-21 15:45:56 +0000333 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
334 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Alan Treadway46dd4492015-11-09 13:57:19 +0000335 * </ul>
336 *
Benjamin Franzea956242016-03-21 15:45:56 +0000337 * <p>When device owner provisioning has completed, an intent of the type
Alan Treadway46dd4492015-11-09 13:57:19 +0000338 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
339 * device owner.
340 *
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000341 * <p>From version {@link android.os.Build.VERSION_CODES#O}, when device owner provisioning has
342 * completed, along with the above broadcast, activity intent
343 * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the device owner.
344 *
Benjamin Franzea956242016-03-21 15:45:56 +0000345 * <p>If provisioning fails, the device is factory reset.
Alan Treadway46dd4492015-11-09 13:57:19 +0000346 *
347 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
348 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
349 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
350 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
351 *
352 * @hide
353 */
354 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
355 public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE
356 = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE";
357
358 /**
Alan Treadwayafad8782016-01-19 15:15:08 +0000359 * Activity action: Finalizes management provisioning, should be used after user-setup
360 * has been completed and {@link #getUserProvisioningState()} returns one of:
361 * <ul>
362 * <li>{@link #STATE_USER_SETUP_INCOMPLETE}</li>
363 * <li>{@link #STATE_USER_SETUP_COMPLETE}</li>
364 * <li>{@link #STATE_USER_PROFILE_COMPLETE}</li>
365 * </ul>
366 *
367 * @hide
368 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +0000369 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +0000370 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
371 public static final String ACTION_PROVISION_FINALIZATION
372 = "android.app.action.PROVISION_FINALIZATION";
373
374 /**
Michal Karpinskiba244092016-02-25 17:28:24 +0000375 * Action: Bugreport sharing with device owner has been accepted by the user.
376 *
377 * @hide
378 */
379 public static final String ACTION_BUGREPORT_SHARING_ACCEPTED =
380 "com.android.server.action.BUGREPORT_SHARING_ACCEPTED";
381
382 /**
383 * Action: Bugreport sharing with device owner has been declined by the user.
384 *
385 * @hide
386 */
387 public static final String ACTION_BUGREPORT_SHARING_DECLINED =
388 "com.android.server.action.BUGREPORT_SHARING_DECLINED";
389
390 /**
Esteban Talavera01576862016-12-15 11:16:44 +0000391 * Action: Bugreport has been collected and is dispatched to {@code DevicePolicyManagerService}.
Michal Karpinskiba244092016-02-25 17:28:24 +0000392 *
393 * @hide
394 */
395 public static final String ACTION_REMOTE_BUGREPORT_DISPATCH =
396 "android.intent.action.REMOTE_BUGREPORT_DISPATCH";
397
398 /**
399 * Extra for shared bugreport's SHA-256 hash.
400 *
401 * @hide
402 */
403 public static final String EXTRA_REMOTE_BUGREPORT_HASH =
404 "android.intent.extra.REMOTE_BUGREPORT_HASH";
405
406 /**
407 * Extra for remote bugreport notification shown type.
408 *
409 * @hide
410 */
411 public static final String EXTRA_BUGREPORT_NOTIFICATION_TYPE =
412 "android.app.extra.bugreport_notification_type";
413
414 /**
415 * Notification type for a started remote bugreport flow.
416 *
417 * @hide
418 */
419 public static final int NOTIFICATION_BUGREPORT_STARTED = 1;
420
421 /**
422 * Notification type for a bugreport that has already been accepted to be shared, but is still
423 * being taken.
424 *
425 * @hide
426 */
427 public static final int NOTIFICATION_BUGREPORT_ACCEPTED_NOT_FINISHED = 2;
428
429 /**
430 * Notification type for a bugreport that has been taken and can be shared or declined.
431 *
432 * @hide
433 */
434 public static final int NOTIFICATION_BUGREPORT_FINISHED_NOT_ACCEPTED = 3;
435
436 /**
Michal Karpinski8f010dd2016-06-21 15:05:53 +0100437 * Default and maximum timeout in milliseconds after which unlocking with weak auth times out,
438 * i.e. the user has to use a strong authentication method like password, PIN or pattern.
439 *
440 * @hide
441 */
442 public static final long DEFAULT_STRONG_AUTH_TIMEOUT_MS = 72 * 60 * 60 * 1000; // 72h
443
444 /**
Rubin Xua4f9dc12015-06-12 13:27:59 +0100445 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100446 * allows a mobile device management application or NFC programmer application which starts
447 * managed provisioning to pass data to the management application instance after provisioning.
Rubin Xua4f9dc12015-06-12 13:27:59 +0100448 * <p>
449 * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that
450 * sends the intent to pass data to itself on the newly created profile.
451 * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same
452 * instance of the app on the primary user.
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100453 * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with
454 * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC
455 * message should contain a stringified {@link java.util.Properties} instance, whose string
456 * properties will be converted into a {@link android.os.PersistableBundle} and passed to the
457 * management application after provisioning.
458 *
Rubin Xua4f9dc12015-06-12 13:27:59 +0100459 * <p>
460 * In both cases the application receives the data in
Brian Carlstromf1fe51b2014-09-03 08:55:05 -0700461 * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action
462 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed
Rubin Xua4f9dc12015-06-12 13:27:59 +0100463 * during the managed provisioning.
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100464 */
465 public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE =
Esteban Talavera37f01842014-09-05 10:50:57 +0100466 "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE";
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100467
468 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100469 * A String extra holding the package name of the mobile device management application that
470 * will be set as the profile owner or device owner.
471 *
472 * <p>If an application starts provisioning directly via an intent with action
473 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
474 * application that started provisioning. The package will be set as profile owner in that case.
475 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000476 * <p>This package is set as device owner when device owner provisioning is started by an NFC
477 * message containing an NFC record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000478 *
479 * <p> When this extra is set, the application must have exactly one device admin receiver.
Robin Lee25e26452015-06-02 09:56:29 -0700480 * This receiver will be set as the profile or device owner and active admin.
Benjamin Franzea956242016-03-21 15:45:56 +0000481 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000482 * @see DeviceAdminReceiver
483 * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still
Nicolas Prevot8f78d6a2015-08-21 11:06:31 +0100484 * supported, but only if there is only one device admin receiver in the package that requires
485 * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000486 */
Nicolas Prevot18440252015-03-09 14:07:17 +0000487 @Deprecated
Jessica Hummelf72078b2014-03-06 16:13:12 +0000488 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100489 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000490
491 /**
Nicolas Prevot18440252015-03-09 14:07:17 +0000492 * A ComponentName extra indicating the device admin receiver of the mobile device management
493 * application that will be set as the profile owner or device owner and active admin.
494 *
495 * <p>If an application starts provisioning directly via an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100496 * {@link #ACTION_PROVISION_MANAGED_PROFILE} or
497 * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this
498 * component has to match the package name of the application that started provisioning.
Nicolas Prevot18440252015-03-09 14:07:17 +0000499 *
500 * <p>This component is set as device owner and active admin when device owner provisioning is
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100501 * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC
502 * message containing an NFC record with MIME type
Benjamin Franzea956242016-03-21 15:45:56 +0000503 * {@link #MIME_TYPE_PROVISIONING_NFC}. For the NFC record, the component name must be
Rubin Xu44ef750b2015-03-23 16:51:33 +0000504 * flattened to a string, via {@link ComponentName#flattenToShortString()}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000505 *
506 * @see DeviceAdminReceiver
507 */
508 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME
509 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME";
510
511 /**
Alexandra Gherghinaaaf2f3e2014-11-13 12:46:15 +0000512 * An {@link android.accounts.Account} extra holding the account to migrate during managed
513 * profile provisioning. If the account supplied is present in the primary user, it will be
514 * copied, along with its credentials to the managed profile and removed from the primary user.
515 *
516 * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}.
517 */
518
519 public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE
520 = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE";
521
522 /**
Victor Changaa9cbc02016-12-05 20:50:57 +0000523 * Boolean extra to indicate that the migrated account should be kept. This is used in
524 * conjunction with {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}. If it's set to {@code true},
525 * the account will not be removed from the primary user after it is migrated to the newly
526 * created user or profile.
Victor Chang89ee2792016-11-23 12:10:55 +0000527 *
528 * <p> Defaults to {@code false}
529 *
Victor Changaa9cbc02016-12-05 20:50:57 +0000530 * <p> Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
531 * {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}
Victor Chang89ee2792016-11-23 12:10:55 +0000532 */
533 public static final String EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION
534 = "android.app.extra.PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION";
535
536 /**
Jessica Hummele3da7902014-08-20 15:20:11 +0100537 * A String extra that, holds the email address of the account which a managed profile is
538 * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
539 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100540 *
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100541 * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}.
542 *
Jessica Hummele3da7902014-08-20 15:20:11 +0100543 * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning
544 * contains this extra, it is forwarded in the
545 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile
546 * device management application that was set as the profile owner during provisioning.
547 * It is usually used to avoid that the user has to enter their email address twice.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100548 */
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100549 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
550 = "android.app.extra.PROVISIONING_EMAIL_ADDRESS";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100551
552 /**
Nicolas Prevotcd2d8592015-11-23 13:27:21 +0000553 * A integer extra indicating the predominant color to show during the provisioning.
554 * Refer to {@link android.graphics.Color} for how the color is represented.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000555 *
556 * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or
557 * {@link #ACTION_PROVISION_MANAGED_DEVICE}.
558 */
559 public static final String EXTRA_PROVISIONING_MAIN_COLOR =
560 "android.app.extra.PROVISIONING_MAIN_COLOR";
561
562 /**
Sander Alewijnse8c411562014-11-12 18:03:11 +0000563 * A Boolean extra that can be used by the mobile device management application to skip the
Robin Lee25e26452015-06-02 09:56:29 -0700564 * disabling of system apps during provisioning when set to {@code true}.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000565 *
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100566 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
567 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000568 */
Sander Alewijnse5a144252014-11-18 13:25:04 +0000569 public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED =
570 "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED";
Sander Alewijnse8c411562014-11-12 18:03:11 +0000571
572 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100573 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
574 * will be set to.
575 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000576 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
577 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100578 */
579 public static final String EXTRA_PROVISIONING_TIME_ZONE
Esteban Talavera37f01842014-09-05 10:50:57 +0100580 = "android.app.extra.PROVISIONING_TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100581
582 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100583 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
584 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100585 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000586 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
587 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100588 */
589 public static final String EXTRA_PROVISIONING_LOCAL_TIME
Esteban Talavera37f01842014-09-05 10:50:57 +0100590 = "android.app.extra.PROVISIONING_LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100591
592 /**
593 * A String extra holding the {@link java.util.Locale} that the device will be set to.
594 * Format: xx_yy, where xx is the language code, and yy the country code.
595 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000596 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
597 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100598 */
599 public static final String EXTRA_PROVISIONING_LOCALE
Esteban Talavera37f01842014-09-05 10:50:57 +0100600 = "android.app.extra.PROVISIONING_LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100601
602 /**
603 * A String extra holding the ssid of the wifi network that should be used during nfc device
604 * owner provisioning for downloading the mobile device management application.
605 *
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_SSID
Esteban Talavera37f01842014-09-05 10:50:57 +0100610 = "android.app.extra.PROVISIONING_WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100611
612 /**
613 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
614 * is hidden or not.
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_HIDDEN
Esteban Talavera37f01842014-09-05 10:50:57 +0100620 = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100621
622 /**
623 * A String extra indicating the security type of the wifi network in
Mahaver Chopra76b08a92015-10-08 17:58:45 +0100624 * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or
625 * {@code WEP}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100626 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000627 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
628 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100629 */
630 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
Esteban Talavera37f01842014-09-05 10:50:57 +0100631 = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100632
633 /**
634 * A String extra holding the password of the wifi network in
635 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
636 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000637 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
638 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100639 */
640 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talavera37f01842014-09-05 10:50:57 +0100641 = "android.app.extra.PROVISIONING_WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100642
643 /**
644 * A String extra holding the proxy host for the wifi network in
645 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
646 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000647 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
648 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100649 */
650 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
Esteban Talavera37f01842014-09-05 10:50:57 +0100651 = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100652
653 /**
654 * An int extra holding the proxy port for the wifi network in
655 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
656 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000657 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
658 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100659 */
660 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
Esteban Talavera37f01842014-09-05 10:50:57 +0100661 = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100662
663 /**
664 * A String extra holding the proxy bypass for the wifi network in
665 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
666 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000667 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
668 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100669 */
670 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
Esteban Talavera37f01842014-09-05 10:50:57 +0100671 = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100672
673 /**
674 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
675 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
676 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000677 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
678 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100679 */
680 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
Esteban Talavera37f01842014-09-05 10:50:57 +0100681 = "android.app.extra.PROVISIONING_WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100682
683 /**
684 * A String extra holding a url that specifies the download location of the device admin
685 * package. When not provided it is assumed that the device admin package is already installed.
686 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000687 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
688 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100689 */
690 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talavera37f01842014-09-05 10:50:57 +0100691 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100692
693 /**
Victor Chang38cfd9c2017-01-04 17:41:11 +0000694 * A String extra holding the localized name of the organization under management.
695 *
696 * The name is displayed only during provisioning.
697 *
698 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE}
699 *
700 * @hide
701 */
702 @SystemApi
703 public static final String EXTRA_PROVISIONING_ORGANIZATION_NAME =
704 "android.app.extra.PROVISIONING_ORGANIZATION_NAME";
705
706 /**
707 * A String extra holding a url to the website of the device's provider. The website can be
708 * opened in a browser during provisioning.
709 *
710 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE}
711 *
712 * @hide
713 */
714 @SystemApi
715 public static final String EXTRA_PROVISIONING_SUPPORT_URL =
716 "android.app.extra.PROVISIONING_SUPPORT_URL";
717
718 /**
719 * A String extra holding the localized name of the device admin package. It should be the same
720 * as the app label of the package.
721 *
722 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE}
723 *
724 * @hide
725 */
726 @SystemApi
727 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL =
728 "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL";
729
730 /**
731 * A {@link Uri} extra pointing to the app icon of device admin package. This image will be
732 * shown during the provisioning.
733 * <h5>The following URI schemes are accepted:</h5>
734 * <ul>
735 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
736 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
737 * </ul>
738 *
739 * <p> It is the responsibility of the caller to provide an image with a reasonable
740 * pixel density for the device.
741 *
742 * <p> If a content: URI is passed, the intent should have the flag
743 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
744 * {@link android.content.ClipData} of the intent too.
745 *
746 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE}
747 *
748 * @hide
749 */
750 @SystemApi
751 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI =
752 "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI";
753
754 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400755 * An int extra holding a minimum required version code for the device admin package. If the
756 * device admin is already installed on the device, it will only be re-downloaded from
757 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the
758 * installed package is less than this version code.
759 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400760 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400761 * provisioning via an NFC bump.
762 */
763 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE
764 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE";
765
766 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100767 * A String extra holding a http cookie header which should be used in the http request to the
768 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
769 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000770 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
771 * provisioning via an NFC bump.
Sander Alewijnse681bce92014-07-24 16:46:26 +0100772 */
773 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talavera37f01842014-09-05 10:50:57 +0100774 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100775
776 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100777 * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of
778 * the file at download location specified in
779 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100780 *
Benjamin Franzea956242016-03-21 15:45:56 +0000781 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} must be
782 * present. The provided checksum must match the checksum of the file at the download
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100783 * location. If the checksum doesn't match an error will be shown to the user and the user will
784 * be asked to factory reset the device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100785 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000786 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
787 * provisioning via an NFC bump.
Rubin Xud92e7572015-05-18 17:01:13 +0100788 *
789 * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP}
790 * and {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1} only SHA-1 hash is supported.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700791 * Starting from {@link android.os.Build.VERSION_CODES#M}, this parameter accepts SHA-256 in
Rubin Xud92e7572015-05-18 17:01:13 +0100792 * addition to SHA-1. Support for SHA-1 is likely to be removed in future OS releases.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100793 */
794 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100795 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100796
797 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100798 * A String extra holding the URL-safe base64 encoded SHA-256 checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100799 * android package archive at the download location specified in {@link
800 * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
801 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100802 * <p>The signatures of an android package archive can be obtained using
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100803 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
804 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
805 *
Benjamin Franzea956242016-03-21 15:45:56 +0000806 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} must be
807 * present. The provided checksum must match the checksum of any signature of the file at
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100808 * the download location. If the checksum does not match an error will be shown to the user and
809 * the user will be asked to factory reset the device.
810 *
811 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
812 * provisioning via an NFC bump.
813 */
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100814 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM
815 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM";
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100816
817 /**
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000818 * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile
819 * has completed successfully.
820 *
821 * <p>The broadcast is limited to the primary profile, to the app specified in the provisioning
Nicolas Prevotebe2d992015-05-12 18:14:53 -0700822 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000823 *
Mahaver7074caf2016-11-29 20:52:18 +0000824 * <p>This intent will contain the following extras
825 * <ul>
826 * <li>{@link Intent#EXTRA_USER}, corresponds to the {@link UserHandle} of the managed
827 * profile.</li>
828 * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, corresponds to the account requested to
829 * be migrated at provisioning time, if any.</li>
830 * </ul>
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000831 */
832 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
833 public static final String ACTION_MANAGED_PROFILE_PROVISIONED
834 = "android.app.action.MANAGED_PROFILE_PROVISIONED";
835
836 /**
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000837 * Activity action: This activity action is sent to indicate that provisioning of a managed
838 * profile or managed device has completed successfully. It'll be sent at the same time as
839 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast but this will be
840 * delivered faster as it's an activity intent.
841 *
842 * <p>The intent is only sent to the application on the profile that requested provisioning. In
843 * the device owner case the profile is the primary user.
844 *
845 * @see #ACTION_PROVISION_MANAGED_PROFILE
846 * @see #ACTION_PROVISION_MANAGED_DEVICE
847 */
848 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
849 public static final String ACTION_PROVISIONING_SUCCESSFUL =
850 "android.app.action.PROVISIONING_SUCCESSFUL";
851
852 /**
Benjamin Franzea956242016-03-21 15:45:56 +0000853 * A boolean extra indicating whether device encryption can be skipped as part of device owner
854 * or managed profile provisioning.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500855 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400856 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100857 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Benjamin Franzea956242016-03-21 15:45:56 +0000858 *
859 * <p>From {@link android.os.Build.VERSION_CODES#N} onwards, this is also supported for an
860 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500861 */
862 public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION =
863 "android.app.extra.PROVISIONING_SKIP_ENCRYPTION";
864
865 /**
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000866 * A {@link Uri} extra pointing to a logo image. This image will be shown during the
867 * provisioning. If this extra is not passed, a default image will be shown.
868 * <h5>The following URI schemes are accepted:</h5>
869 * <ul>
870 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
871 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
872 * </ul>
873 *
Victor Changc10f6692016-12-09 15:24:00 +0000874 * <p> It is the responsibility of the caller to provide an image with a reasonable
Victor Chang38cfd9c2017-01-04 17:41:11 +0000875 * pixel density for the device.
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000876 *
877 * <p> If a content: URI is passed, the intent should have the flag
878 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
879 * {@link android.content.ClipData} of the intent too.
880 *
881 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or
882 * {@link #ACTION_PROVISION_MANAGED_DEVICE}
883 */
884 public static final String EXTRA_PROVISIONING_LOGO_URI =
885 "android.app.extra.PROVISIONING_LOGO_URI";
886
887 /**
Victor Changc10f6692016-12-09 15:24:00 +0000888 * A {@link Bundle}[] extra consisting of list of disclaimer headers and disclaimer contents.
889 * Each {@link Bundle} must have both {@link #EXTRA_PROVISIONING_DISCLAIMER_HEADER}
890 * as disclaimer header, and {@link #EXTRA_PROVISIONING_DISCLAIMER_CONTENT} as disclaimer
891 * content.
892 *
893 * <p> The extra typically contains one disclaimer from the company of mobile device
894 * management application (MDM), and one disclaimer from the organization.
895 *
896 * <p> Call {@link Bundle#putParcelableArray(String, Parcelable[])} to put the {@link Bundle}[]
897 *
898 * <p> Maximum 3 key-value pairs can be specified. The rest will be ignored.
899 *
900 * <p> Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or
901 * {@link #ACTION_PROVISION_MANAGED_DEVICE}
902 */
903 public static final String EXTRA_PROVISIONING_DISCLAIMERS =
904 "android.app.extra.PROVISIONING_DISCLAIMERS";
905
906 /**
907 * A String extra of localized disclaimer header.
908 *
909 * <p> The extra is typically the company name of mobile device management application (MDM)
910 * or the organization name.
911 *
912 * <p> Use in Bundle {@link #EXTRA_PROVISIONING_DISCLAIMERS}
Victor Chang98607132017-01-27 11:51:56 +0000913 *
914 * <p> System app, i.e. application with {@link ApplicationInfo#FLAG_SYSTEM}, can also insert a
915 * disclaimer by declaring an application-level meta-data in {@code AndroidManifest.xml}.
916 * Must use it with {@link #EXTRA_PROVISIONING_DISCLAIMER_CONTENT}. Here is the example:
917 *
918 * <pre>
919 * &lt;meta-data
920 * android:name="android.app.extra.PROVISIONING_DISCLAIMER_HEADER"
921 * android:resource="@string/disclaimer_header"
922 * /&gt;</pre>
Victor Changc10f6692016-12-09 15:24:00 +0000923 */
924 public static final String EXTRA_PROVISIONING_DISCLAIMER_HEADER =
925 "android.app.extra.PROVISIONING_DISCLAIMER_HEADER";
926
927 /**
928 * A {@link Uri} extra pointing to disclaimer content.
929 *
930 * <h5>The following URI schemes are accepted:</h5>
931 * <ul>
932 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
933 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
934 * </ul>
935 *
936 * <p> Styled text is supported in the disclaimer content. The content is parsed by
937 * {@link android.text.Html#fromHtml(String)} and displayed in a
938 * {@link android.widget.TextView}.
939 *
940 * <p> If a <code>content:</code> URI is passed, URI is passed, the intent should have the flag
941 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
942 * {@link android.content.ClipData} of the intent too.
943 *
944 * <p> Use in Bundle {@link #EXTRA_PROVISIONING_DISCLAIMERS}
Victor Chang98607132017-01-27 11:51:56 +0000945 *
946 * <p> System app, i.e. application with {@link ApplicationInfo#FLAG_SYSTEM}, can also insert a
947 * disclaimer by declaring an application-level meta-data in {@code AndroidManifest.xml}.
948 * Must use it with {@link #EXTRA_PROVISIONING_DISCLAIMER_HEADER}. Here is the example:
949 *
950 * <pre>
951 * &lt;meta-data
952 * android:name="android.app.extra.PROVISIONING_DISCLAIMER_CONTENT"
953 * android:resource="@string/disclaimer_content"
954 * /&gt;</pre>
Victor Changc10f6692016-12-09 15:24:00 +0000955 */
956 public static final String EXTRA_PROVISIONING_DISCLAIMER_CONTENT =
957 "android.app.extra.PROVISIONING_DISCLAIMER_CONTENT";
958
959 /**
Alan Treadway94de8c82016-01-11 10:25:23 +0000960 * A boolean extra indicating if user setup should be skipped, for when provisioning is started
961 * during setup-wizard.
962 *
963 * <p>If unspecified, defaults to {@code true} to match the behavior in
964 * {@link android.os.Build.VERSION_CODES#M} and earlier.
965 *
Alan Treadway1a538d02016-01-18 16:42:30 +0000966 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or
967 * {@link #ACTION_PROVISION_MANAGED_USER}.
Alan Treadway94de8c82016-01-11 10:25:23 +0000968 *
969 * @hide
970 */
971 public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP =
972 "android.app.extra.PROVISIONING_SKIP_USER_SETUP";
973
974 /**
Victor Chang51d84f92016-11-16 12:22:56 +0000975 * A boolean extra indicating if the user consent steps from the provisioning flow should be
976 * skipped. If unspecified, defaults to {@code false}.
977 *
978 * It can only be used by an existing device owner trying to create a managed profile via
979 * {@link #ACTION_PROVISION_MANAGED_PROFILE}. Otherwise it is ignored.
980 */
981 public static final String EXTRA_PROVISIONING_SKIP_USER_CONSENT =
982 "android.app.extra.PROVISIONING_SKIP_USER_CONSENT";
983
984 /**
Benjamin Franzea956242016-03-21 15:45:56 +0000985 * This MIME type is used for starting the device owner provisioning.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100986 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400987 * <p>During device owner provisioning a device admin app is set as the owner of the device.
988 * A device owner has full control over the device. The device owner can not be modified by the
989 * user and the only way of resetting the device is if the device owner app calls a factory
990 * reset.
991 *
992 * <p> A typical use case would be a device that is owned by a company, but used by either an
993 * employee or client.
994 *
Benjamin Franzea956242016-03-21 15:45:56 +0000995 * <p> The NFC message must be sent to an unprovisioned device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100996 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000997 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100998 * contains the following properties:
999 * <ul>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -04001000 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
1001 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +01001002 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -04001003 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +01001004 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
1005 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
1006 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
1007 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
1008 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
1009 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
1010 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
1011 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
1012 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
1013 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Rubin Xu41f2ccb92015-08-05 16:29:13 +01001014 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
1015 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from
1016 * {@link android.os.Build.VERSION_CODES#M} </li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +01001017 *
Nicolas Prevot18440252015-03-09 14:07:17 +00001018 * <p>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07001019 * As of {@link android.os.Build.VERSION_CODES#M}, the properties should contain
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -04001020 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of
1021 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only
1022 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -04001023 */
1024 public static final String MIME_TYPE_PROVISIONING_NFC
1025 = "application/com.android.managedprovisioning";
1026
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +01001027 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001028 * Activity action: ask the user to add a new device administrator to the system.
1029 * The desired policy is the ComponentName of the policy in the
1030 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
1031 * bring the user through adding the device administrator to the system (or
1032 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001033 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001034 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
1035 * field to provide the user with additional explanation (in addition
1036 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001037 *
1038 * <p>If your administrator is already active, this will ordinarily return immediately (without
1039 * user intervention). However, if your administrator has been updated and is requesting
1040 * additional uses-policy flags, the user will be presented with the new list. New policies
1041 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001042 */
1043 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1044 public static final String ACTION_ADD_DEVICE_ADMIN
1045 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001046
Dianne Hackbornd6847842010-01-12 18:14:19 -08001047 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001048 * @hide
1049 * Activity action: ask the user to add a new device administrator as the profile owner
Amith Yamasani814e9872015-03-23 14:04:53 -07001050 * for this user. Only system apps can launch this intent.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001051 *
Amith Yamasani814e9872015-03-23 14:04:53 -07001052 * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN}
1053 * extra field. This will invoke a UI to bring the user through adding the profile owner admin
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001054 * to remotely control restrictions on the user.
1055 *
Makoto Onukic8a5a552015-11-19 14:29:12 -08001056 * <p>The intent must be invoked via {@link Activity#startActivityForResult} to receive the
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001057 * result of whether or not the user approved the action. If approved, the result will
1058 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
1059 * as a profile owner.
1060 *
1061 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
1062 * field to provide the user with additional explanation (in addition
1063 * to your component's description) about what is being added.
1064 *
Amith Yamasani814e9872015-03-23 14:04:53 -07001065 * <p>If there is already a profile owner active or the caller is not a system app, the
1066 * operation will return a failure result.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001067 */
1068 @SystemApi
1069 public static final String ACTION_SET_PROFILE_OWNER
1070 = "android.app.action.SET_PROFILE_OWNER";
1071
1072 /**
1073 * @hide
1074 * Name of the profile owner admin that controls the user.
1075 */
1076 @SystemApi
1077 public static final String EXTRA_PROFILE_OWNER_NAME
1078 = "android.app.extra.PROFILE_OWNER_NAME";
1079
1080 /**
Nicolas Prevot00799002015-07-27 18:15:20 +01001081 * Broadcast action: send when any policy admin changes a policy.
Jim Miller284b62e2010-06-08 14:27:42 -07001082 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -07001083 *
Jim Miller284b62e2010-06-08 14:27:42 -07001084 * @hide
1085 */
1086 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
1087 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
1088
1089 /**
Tony Mak1970f972016-08-30 17:41:48 +01001090 * Broadcast action: sent when the device owner is set, changed or cleared.
Nicolas Prevot00799002015-07-27 18:15:20 +01001091 *
1092 * This broadcast is sent only to the primary user.
1093 * @see #ACTION_PROVISION_MANAGED_DEVICE
1094 */
1095 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1096 public static final String ACTION_DEVICE_OWNER_CHANGED
1097 = "android.app.action.DEVICE_OWNER_CHANGED";
1098
1099 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001100 * The ComponentName of the administrator component.
1101 *
1102 * @see #ACTION_ADD_DEVICE_ADMIN
1103 */
1104 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001105
Dianne Hackbornd6847842010-01-12 18:14:19 -08001106 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001107 * An optional CharSequence providing additional explanation for why the
1108 * admin is being added.
1109 *
1110 * @see #ACTION_ADD_DEVICE_ADMIN
1111 */
1112 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001113
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001114 /**
phweiss73145f42017-01-17 19:06:38 +01001115 * Constant to indicate the feature of disabling the camera. Used as argument to
1116 * {@link #createAdminSupportIntent(String)}.
1117 * @see #setCameraDisabled(ComponentName, boolean)
1118 */
1119 public static final String POLICY_DISABLE_CAMERA = "policy_disable_camera";
1120
1121 /**
1122 * Constant to indicate the feature of disabling screen captures. Used as argument to
1123 * {@link #createAdminSupportIntent(String)}.
1124 * @see #setScreenCaptureDisabled(ComponentName, boolean)
1125 */
1126 public static final String POLICY_DISABLE_SCREEN_CAPTURE = "policy_disable_screen_capture";
1127
1128 /**
1129 * A String indicating a specific restricted feature. Can be a user restriction from the
1130 * {@link UserManager}, e.g. {@link UserManager#DISALLOW_ADJUST_VOLUME}, or one of the values
1131 * {@link #POLICY_DISABLE_CAMERA} or {@link #POLICY_DISABLE_SCREEN_CAPTURE}.
1132 * @see #createAdminSupportIntent(String)
1133 * @hide
1134 */
1135 @TestApi
1136 public static final String EXTRA_RESTRICTION = "android.app.extra.RESTRICTION";
1137
1138 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001139 * Activity action: have the user enter a new password. This activity should
1140 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
1141 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
1142 * enter a new password that meets the current requirements. You can use
1143 * {@link #isActivePasswordSufficient()} to determine whether you need to
1144 * have the user select a new password in order to meet the current
1145 * constraints. Upon being resumed from this activity, you can check the new
1146 * password characteristics to see if they are sufficient.
Benjamin Franzc9921092016-01-08 17:17:44 +00001147 *
1148 * If the intent is launched from within a managed profile with a profile
1149 * owner built against {@link android.os.Build.VERSION_CODES#M} or before,
1150 * this will trigger entering a new password for the parent of the profile.
1151 * For all other cases it will trigger entering a new password for the user
1152 * or profile it is launched from.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001153 *
1154 * @see #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
Dianne Hackbornd6847842010-01-12 18:14:19 -08001155 */
1156 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1157 public static final String ACTION_SET_NEW_PASSWORD
1158 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001159
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001160 /**
Benjamin Franzc9921092016-01-08 17:17:44 +00001161 * Activity action: have the user enter a new password for the parent profile.
1162 * If the intent is launched from within a managed profile, this will trigger
1163 * entering a new password for the parent of the profile. In all other cases
1164 * the behaviour is identical to {@link #ACTION_SET_NEW_PASSWORD}.
1165 */
1166 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1167 public static final String ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
1168 = "android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD";
1169
1170 /**
phweissa0cb2512016-12-14 21:37:48 +01001171 * Broadcast action: Tell the status bar to open the device monitoring dialog, e.g. when
1172 * Network logging was enabled and the user tapped the notification.
1173 * <p class="note">This is a protected intent that can only be sent by the system.</p>
1174 * @hide
1175 */
1176 public static final String ACTION_SHOW_DEVICE_MONITORING_DIALOG
1177 = "android.app.action.SHOW_DEVICE_MONITORING_DIALOG";
1178
1179 /**
Edman Anjos9e62c312017-01-26 22:22:58 +01001180 * Broadcast Action: Sent after application delegation scopes are changed. The new delegation
1181 * scopes will be sent in an {@code ArrayList<String>} extra identified by the
1182 * {@link #EXTRA_DELEGATION_SCOPES} key.
Edman Anjosf9946772016-11-28 16:35:15 +01001183 *
1184 * <p class=”note”> Note: This is a protected intent that can only be sent by the system.</p>
1185 */
1186 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1187 public static final String ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED =
1188 "android.app.action.APPLICATION_DELEGATION_SCOPES_CHANGED";
1189
1190 /**
Edman Anjos9e62c312017-01-26 22:22:58 +01001191 * An {@code ArrayList<String>} corresponding to the delegation scopes given to an app in the
Edman Anjosf9946772016-11-28 16:35:15 +01001192 * {@link #ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED} broadcast.
1193 */
1194 public static final String EXTRA_DELEGATION_SCOPES = "android.app.extra.DELEGATION_SCOPES";
1195
1196 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +00001197 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
1198 * the parent profile to access intents sent from the managed profile.
1199 * That is, when an app in the managed profile calls
1200 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
1201 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001202 */
Nicolas Prevot86a96732014-09-08 12:13:05 +01001203 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001204
1205 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +00001206 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
1207 * the managed profile to access intents sent from the parent profile.
1208 * That is, when an app in the parent profile calls
1209 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
1210 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001211 */
Nicolas Prevot86a96732014-09-08 12:13:05 +01001212 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001213
Dianne Hackbornd6847842010-01-12 18:14:19 -08001214 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01001215 * Broadcast action: notify that a new local system update policy has been set by the device
1216 * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00001217 */
1218 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Rubin Xu5faad8e2015-04-20 17:43:48 +01001219 public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED
1220 = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED";
Rubin Xu8027a4f2015-03-10 17:52:37 +00001221
Amith Yamasanid49489b2015-04-28 14:00:26 -07001222 /**
1223 * Permission policy to prompt user for new permission requests for runtime permissions.
1224 * Already granted or denied permissions are not affected by this.
1225 */
1226 public static final int PERMISSION_POLICY_PROMPT = 0;
1227
1228 /**
1229 * Permission policy to always grant new permission requests for runtime permissions.
1230 * Already granted or denied permissions are not affected by this.
1231 */
1232 public static final int PERMISSION_POLICY_AUTO_GRANT = 1;
1233
1234 /**
1235 * Permission policy to always deny new permission requests for runtime permissions.
1236 * Already granted or denied permissions are not affected by this.
1237 */
1238 public static final int PERMISSION_POLICY_AUTO_DENY = 2;
1239
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07001240 /**
1241 * Runtime permission state: The user can manage the permission
1242 * through the UI.
1243 */
1244 public static final int PERMISSION_GRANT_STATE_DEFAULT = 0;
1245
1246 /**
1247 * Runtime permission state: The permission is granted to the app
1248 * and the user cannot manage the permission through the UI.
1249 */
1250 public static final int PERMISSION_GRANT_STATE_GRANTED = 1;
1251
1252 /**
1253 * Runtime permission state: The permission is denied to the app
1254 * and the user cannot manage the permission through the UI.
1255 */
1256 public static final int PERMISSION_GRANT_STATE_DENIED = 2;
Rubin Xu8027a4f2015-03-10 17:52:37 +00001257
1258 /**
Edman Anjosf9946772016-11-28 16:35:15 +01001259 * Delegation of certificate installation and management. This scope grants access to the
1260 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
1261 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair} APIs.
1262 */
1263 public static final String DELEGATION_CERT_INSTALL = "delegation-cert-install";
1264
1265 /**
1266 * Delegation of application restrictions management. This scope grants access to the
1267 * {@link #setApplicationRestrictions} and {@link #getApplicationRestrictions} APIs.
1268 */
1269 public static final String DELEGATION_APP_RESTRICTIONS = "delegation-app-restrictions";
1270
1271 /**
Edman Anjosa5f2fb12016-12-19 11:25:54 -08001272 * Delegation of application uninstall block. This scope grants access to the
1273 * {@link #setUninstallBlocked} API.
1274 */
1275 public static final String DELEGATION_BLOCK_UNINSTALL = "delegation-block-uninstall";
1276
1277 /**
Edman Anjos52088e42017-01-13 22:26:17 +01001278 * Delegation of permission policy and permission grant state. This scope grants access to the
1279 * {@link #setPermissionPolicy}, {@link #getPermissionGrantState},
1280 * and {@link #setPermissionGrantState} APIs.
1281 */
1282 public static final String DELEGATION_PERMISSION_GRANT = "delegation-permission-grant";
1283
1284 /**
1285 * Delegation of package access state. This scope grants access to the
1286 * {@link #isApplicationHidden}, {@link #setApplicationHidden}, {@link #isPackageSuspended}, and
1287 * {@link #setPackagesSuspended} APIs.
1288 */
1289 public static final String DELEGATION_PACKAGE_ACCESS = "delegation-package-access";
1290
1291 /**
1292 * Delegation for enabling system apps. This scope grants access to the {@link #enableSystemApp}
1293 * API.
1294 */
1295 public static final String DELEGATION_ENABLE_SYSTEM_APP = "delegation-enable-system-app";
1296
1297 /**
1298 * Delegation of management of uninstalled packages. This scope grants access to the
1299 * {@code #setKeepUninstalledPackages} and {@code #getKeepUninstalledPackages} APIs.
1300 * @hide
1301 */
1302 public static final String DELEGATION_KEEP_UNINSTALLED_PACKAGES =
1303 "delegation-keep-uninstalled-packages";
1304
1305 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00001306 * No management for current user in-effect. This is the default.
1307 * @hide
1308 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001309 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001310 public static final int STATE_USER_UNMANAGED = 0;
1311
1312 /**
1313 * Management partially setup, user setup needs to be completed.
1314 * @hide
1315 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001316 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001317 public static final int STATE_USER_SETUP_INCOMPLETE = 1;
1318
1319 /**
1320 * Management partially setup, user setup completed.
1321 * @hide
1322 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001323 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001324 public static final int STATE_USER_SETUP_COMPLETE = 2;
1325
1326 /**
1327 * Management setup and active on current user.
1328 * @hide
1329 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001330 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001331 public static final int STATE_USER_SETUP_FINALIZED = 3;
1332
1333 /**
1334 * Management partially setup on a managed profile.
1335 * @hide
1336 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001337 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001338 public static final int STATE_USER_PROFILE_COMPLETE = 4;
1339
1340 /**
1341 * @hide
1342 */
1343 @IntDef({STATE_USER_UNMANAGED, STATE_USER_SETUP_INCOMPLETE, STATE_USER_SETUP_COMPLETE,
1344 STATE_USER_SETUP_FINALIZED, STATE_USER_PROFILE_COMPLETE})
1345 @Retention(RetentionPolicy.SOURCE)
1346 public @interface UserProvisioningState {}
1347
1348 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001349 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001350 *
1351 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1352 * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and
1353 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when provisioning is allowed.
1354 *
1355 * @hide
1356 */
1357 public static final int CODE_OK = 0;
1358
1359 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001360 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001361 *
1362 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and
1363 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the device already has a device
1364 * owner.
1365 *
1366 * @hide
1367 */
1368 public static final int CODE_HAS_DEVICE_OWNER = 1;
1369
1370 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001371 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001372 *
1373 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1374 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user has a profile owner and for
1375 * {@link #ACTION_PROVISION_MANAGED_PROFILE} when the profile owner is already set.
1376 *
1377 * @hide
1378 */
1379 public static final int CODE_USER_HAS_PROFILE_OWNER = 2;
1380
1381 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001382 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001383 *
1384 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and
1385 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user isn't running.
1386 *
1387 * @hide
1388 */
1389 public static final int CODE_USER_NOT_RUNNING = 3;
1390
1391 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001392 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001393 *
1394 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1395 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the device has already been setup and
1396 * for {@link #ACTION_PROVISION_MANAGED_USER} if the user has already been setup.
1397 *
1398 * @hide
1399 */
1400 public static final int CODE_USER_SETUP_COMPLETED = 4;
1401
1402 /**
1403 * Code used to indicate that the device also has a user other than the system user.
1404 *
1405 * @hide
1406 */
1407 public static final int CODE_NONSYSTEM_USER_EXISTS = 5;
1408
1409 /**
1410 * Code used to indicate that device has an account that prevents provisioning.
1411 *
1412 * @hide
1413 */
1414 public static final int CODE_ACCOUNTS_NOT_EMPTY = 6;
1415
1416 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001417 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001418 *
1419 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and
1420 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the user is not a system user.
1421 *
1422 * @hide
1423 */
1424 public static final int CODE_NOT_SYSTEM_USER = 7;
1425
1426 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001427 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001428 *
1429 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1430 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} and {@link #ACTION_PROVISION_MANAGED_USER}
1431 * when the device is a watch and is already paired.
1432 *
1433 * @hide
1434 */
1435 public static final int CODE_HAS_PAIRED = 8;
1436
1437 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001438 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001439 *
1440 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} and
1441 * {@link #ACTION_PROVISION_MANAGED_USER} on devices which do not support managed users.
1442 *
1443 * @see {@link PackageManager#FEATURE_MANAGED_USERS}
1444 * @hide
1445 */
1446 public static final int CODE_MANAGED_USERS_NOT_SUPPORTED = 9;
1447
1448 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001449 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001450 *
1451 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} if the user is a system user.
1452 *
1453 * @hide
1454 */
1455 public static final int CODE_SYSTEM_USER = 10;
1456
1457 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001458 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001459 *
1460 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when the user cannot have more
1461 * managed profiles.
1462 *
1463 * @hide
1464 */
1465 public static final int CODE_CANNOT_ADD_MANAGED_PROFILE = 11;
1466
1467 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001468 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001469 *
1470 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} and
1471 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices not running with split system
1472 * user.
1473 *
1474 * @hide
1475 */
1476 public static final int CODE_NOT_SYSTEM_USER_SPLIT = 12;
1477
1478 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001479 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001480 *
1481 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1482 * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and
1483 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices which do no support device
1484 * admins.
1485 *
1486 * @hide
1487 */
1488 public static final int CODE_DEVICE_ADMIN_NOT_SUPPORTED = 13;
1489
1490 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001491 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001492 *
Esteban Talavera6c9116a2016-11-24 16:12:44 +00001493 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when the device the user is a
1494 * system user on a split system user device.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001495 *
1496 * @hide
1497 */
1498 public static final int CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER = 14;
1499
1500 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001501 * Result code for {@link #checkProvisioningPreCondition}.
1502 *
1503 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when adding a managed profile is
1504 * disallowed by {@link UserManager#DISALLOW_ADD_MANAGED_PROFILE}.
1505 *
1506 * @hide
1507 */
1508 public static final int CODE_ADD_MANAGED_PROFILE_DISALLOWED = 15;
1509
1510 /**
1511 * Result codes for {@link #checkProvisioningPreCondition} indicating all the provisioning pre
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001512 * conditions.
1513 *
1514 * @hide
1515 */
1516 @Retention(RetentionPolicy.SOURCE)
1517 @IntDef({CODE_OK, CODE_HAS_DEVICE_OWNER, CODE_USER_HAS_PROFILE_OWNER, CODE_USER_NOT_RUNNING,
1518 CODE_USER_SETUP_COMPLETED, CODE_NOT_SYSTEM_USER, CODE_HAS_PAIRED,
1519 CODE_MANAGED_USERS_NOT_SUPPORTED, CODE_SYSTEM_USER, CODE_CANNOT_ADD_MANAGED_PROFILE,
1520 CODE_NOT_SYSTEM_USER_SPLIT, CODE_DEVICE_ADMIN_NOT_SUPPORTED,
Esteban Talavera01576862016-12-15 11:16:44 +00001521 CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER, CODE_ADD_MANAGED_PROFILE_DISALLOWED})
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001522 public @interface ProvisioningPreCondition {}
1523
1524 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001525 * Return true if the given administrator component is currently active (enabled) in the system.
1526 *
1527 * @param admin The administrator component to check for.
1528 * @return {@code true} if {@code admin} is currently enabled in the system, {@code false}
1529 * otherwise
Dianne Hackbornd6847842010-01-12 18:14:19 -08001530 */
Robin Lee25e26452015-06-02 09:56:29 -07001531 public boolean isAdminActive(@NonNull ComponentName admin) {
Charles He8c760562016-10-25 16:36:53 +01001532 throwIfParentInstance("isAdminActive");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001533 return isAdminActiveAsUser(admin, myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001534 }
1535
1536 /**
1537 * @see #isAdminActive(ComponentName)
1538 * @hide
1539 */
Robin Lee25e26452015-06-02 09:56:29 -07001540 public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001541 if (mService != null) {
1542 try {
Robin Lee25e26452015-06-02 09:56:29 -07001543 return mService.isAdminActive(admin, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001544 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001545 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001546 }
1547 }
1548 return false;
1549 }
Charles Hedea0c3b2017-01-13 10:04:12 +00001550
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001551 /**
1552 * Return true if the given administrator component is currently being removed
1553 * for the user.
1554 * @hide
1555 */
Robin Lee25e26452015-06-02 09:56:29 -07001556 public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) {
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001557 if (mService != null) {
1558 try {
Robin Lee25e26452015-06-02 09:56:29 -07001559 return mService.isRemovingAdmin(admin, userId);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001560 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001561 throw e.rethrowFromSystemServer();
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001562 }
1563 }
1564 return false;
1565 }
1566
Dianne Hackbornd6847842010-01-12 18:14:19 -08001567 /**
Robin Lee25e26452015-06-02 09:56:29 -07001568 * Return a list of all currently active device administrators' component
1569 * names. If there are no administrators {@code null} may be
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001570 * returned.
1571 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07001572 public @Nullable List<ComponentName> getActiveAdmins() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001573 throwIfParentInstance("getActiveAdmins");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001574 return getActiveAdminsAsUser(myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001575 }
1576
1577 /**
1578 * @see #getActiveAdmins()
1579 * @hide
1580 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07001581 public @Nullable List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001582 if (mService != null) {
1583 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001584 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001585 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001586 throw e.rethrowFromSystemServer();
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001587 }
1588 }
1589 return null;
1590 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001591
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001592 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001593 * Used by package administration code to determine if a package can be stopped
1594 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001595 * @hide
1596 */
David Ouyang3a83a332017-01-11 16:36:40 -08001597 @SystemApi
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001598 public boolean packageHasActiveAdmins(String packageName) {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001599 return packageHasActiveAdmins(packageName, myUserId());
1600 }
1601
1602 /**
1603 * Used by package administration code to determine if a package can be stopped
1604 * or uninstalled.
1605 * @hide
1606 */
1607 public boolean packageHasActiveAdmins(String packageName, int userId) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001608 if (mService != null) {
1609 try {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001610 return mService.packageHasActiveAdmins(packageName, userId);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001611 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001612 throw e.rethrowFromSystemServer();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001613 }
1614 }
1615 return false;
1616 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001617
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001618 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001619 * Remove a current administration component. This can only be called
1620 * by the application that owns the administration component; if you
1621 * try to remove someone else's component, a security exception will be
1622 * thrown.
Esteban Talavera552a5612016-02-19 17:02:24 +00001623 *
1624 * <p>Note that the operation is not synchronous and the admin might still be active (as
1625 * indicated by {@link #getActiveAdmins()}) by the time this method returns.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001626 *
1627 * @param admin The administration compononent to remove.
1628 * @throws SecurityException if the caller is not in the owner application of {@code admin}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001629 */
Robin Lee25e26452015-06-02 09:56:29 -07001630 public void removeActiveAdmin(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001631 throwIfParentInstance("removeActiveAdmin");
Dianne Hackbornd6847842010-01-12 18:14:19 -08001632 if (mService != null) {
1633 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001634 mService.removeActiveAdmin(admin, myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001635 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001636 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001637 }
1638 }
1639 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001640
Dianne Hackbornd6847842010-01-12 18:14:19 -08001641 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001642 * Returns true if an administrator has been granted a particular device policy. This can be
1643 * used to check whether the administrator was activated under an earlier set of policies, but
1644 * requires additional policies after an upgrade.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001645 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001646 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be an
1647 * active administrator, or an exception will be thrown.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001648 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001649 * @throws SecurityException if {@code admin} is not an active administrator.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001650 */
Robin Lee25e26452015-06-02 09:56:29 -07001651 public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001652 throwIfParentInstance("hasGrantedPolicy");
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001653 if (mService != null) {
1654 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001655 return mService.hasGrantedPolicy(admin, usesPolicy, myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001656 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001657 throw e.rethrowFromSystemServer();
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001658 }
1659 }
1660 return false;
1661 }
1662
1663 /**
Clara Bayarria1771112015-12-18 16:29:18 +00001664 * Returns true if the Profile Challenge is available to use for the given profile user.
1665 *
1666 * @hide
1667 */
1668 public boolean isSeparateProfileChallengeAllowed(int userHandle) {
1669 if (mService != null) {
1670 try {
1671 return mService.isSeparateProfileChallengeAllowed(userHandle);
1672 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001673 throw e.rethrowFromSystemServer();
Clara Bayarria1771112015-12-18 16:29:18 +00001674 }
1675 }
1676 return false;
1677 }
1678
1679 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001680 * Constant for {@link #setPasswordQuality}: the policy has no requirements
1681 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001682 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001683 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001684 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001685
Dianne Hackbornd6847842010-01-12 18:14:19 -08001686 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -07001687 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
1688 * recognition technology. This implies technologies that can recognize the identity of
1689 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
1690 * Note that quality constants are ordered so that higher values are more restrictive.
1691 */
1692 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
1693
1694 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001695 * Constant for {@link #setPasswordQuality}: the policy requires some kind
Benjamin Franzc6a96532015-06-16 11:23:38 +01001696 * of password or pattern, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001697 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001698 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001699 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001700
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001701 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001702 * Constant for {@link #setPasswordQuality}: the user must have entered a
1703 * password containing at least numeric characters. Note that quality
1704 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001705 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001706 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001707
Dianne Hackbornd6847842010-01-12 18:14:19 -08001708 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001709 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -08001710 * password containing at least numeric characters with no repeating (4444)
1711 * or ordered (1234, 4321, 2468) sequences. Note that quality
1712 * constants are ordered so that higher values are more restrictive.
1713 */
1714 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
1715
1716 /**
1717 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001718 * password containing at least alphabetic (or other symbol) characters.
1719 * Note that quality constants are ordered so that higher values are more
1720 * restrictive.
1721 */
1722 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001723
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001724 /**
1725 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001726 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001727 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001728 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001729 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001730 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001731
Dianne Hackbornd6847842010-01-12 18:14:19 -08001732 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001733 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001734 * password containing at least a letter, a numerical digit and a special
1735 * symbol, by default. With this password quality, passwords can be
1736 * restricted to contain various sets of characters, like at least an
1737 * uppercase letter, etc. These are specified using various methods,
1738 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
1739 * that quality constants are ordered so that higher values are more
1740 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001741 */
1742 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
1743
1744 /**
Oleksandr Peletskyi0fdcd3d2016-01-13 16:49:56 +01001745 * Constant for {@link #setPasswordQuality}: the user is not allowed to
1746 * modify password. In case this password quality is set, the password is
1747 * managed by a profile owner. The profile owner can set any password,
1748 * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note
1749 * that quality constants are ordered so that higher values are more
1750 * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is
1751 * the highest.
1752 * @hide
1753 */
1754 public static final int PASSWORD_QUALITY_MANAGED = 0x80000;
1755
1756 /**
Makoto Onuki5e7e06702016-09-01 18:02:01 -07001757 * @hide
1758 *
1759 * adb shell dpm set-{device,profile}-owner will normally not allow installing an owner to
1760 * a user with accounts. {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED}
1761 * and {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} are the account features
1762 * used by authenticator to exempt their accounts from this:
1763 *
1764 * <ul>
1765 * <li>Non-test-only DO/PO still can't be installed when there are accounts.
1766 * <p>In order to make an apk test-only, add android:testOnly="true" to the
1767 * &lt;application&gt; tag in the manifest.
1768 *
1769 * <li>Test-only DO/PO can be installed even when there are accounts, as long as all the
1770 * accounts have the {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} feature.
1771 * Some authenticators claim to have any features, so to detect it, we also check
1772 * {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} and disallow installing
1773 * if any of the accounts have it.
1774 * </ul>
1775 */
1776 public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED =
1777 "android.account.DEVICE_OR_PROFILE_OWNER_ALLOWED";
1778
1779 /** @hide See {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} */
1780 public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED =
1781 "android.account.DEVICE_OR_PROFILE_OWNER_DISALLOWED";
1782
1783 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001784 * Called by an application that is administering the device to set the password restrictions it
1785 * is imposing. After setting this, the user will not be able to enter a new password that is
1786 * not at least as restrictive as what has been set. Note that the current password will remain
1787 * until the user has set a new one, so the change does not take place immediately. To prompt
1788 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
Esteban Talaverac1c83592016-02-17 17:56:15 +00001789 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after calling this method.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001790 * <p>
1791 * Quality constants are ordered so that higher values are more restrictive; thus the highest
1792 * requested quality constant (between the policy set here, the user's preference, and any other
1793 * considerations) is the one that is in effect.
1794 * <p>
1795 * The calling device admin must have requested
1796 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1797 * not, a security exception will be thrown.
1798 * <p>
1799 * This method can be called on the {@link DevicePolicyManager} instance returned by
1800 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1801 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001802 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001803 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001804 * @param quality The new desired quality. One of {@link #PASSWORD_QUALITY_UNSPECIFIED},
1805 * {@link #PASSWORD_QUALITY_SOMETHING}, {@link #PASSWORD_QUALITY_NUMERIC},
1806 * {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC},
1807 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} or {@link #PASSWORD_QUALITY_COMPLEX}.
1808 * @throws SecurityException if {@code admin} is not an active administrator or if {@code admin}
1809 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Dianne Hackbornd6847842010-01-12 18:14:19 -08001810 */
Robin Lee25e26452015-06-02 09:56:29 -07001811 public void setPasswordQuality(@NonNull ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001812 if (mService != null) {
1813 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001814 mService.setPasswordQuality(admin, quality, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001815 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001816 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001817 }
1818 }
1819 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001820
Dianne Hackbornd6847842010-01-12 18:14:19 -08001821 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001822 * Retrieve the current minimum password quality for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01001823 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00001824 * a separate challenge are not taken into account.
1825 *
1826 * <p>This method can be called on the {@link DevicePolicyManager} instance
1827 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1828 * restrictions on the parent profile.
1829 *
Robin Lee25e26452015-06-02 09:56:29 -07001830 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001831 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001832 */
Robin Lee25e26452015-06-02 09:56:29 -07001833 public int getPasswordQuality(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001834 return getPasswordQuality(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001835 }
1836
1837 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001838 public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001839 if (mService != null) {
1840 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001841 return mService.getPasswordQuality(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001842 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001843 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001844 }
1845 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001846 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001847 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001848
Dianne Hackbornd6847842010-01-12 18:14:19 -08001849 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001850 * Called by an application that is administering the device to set the minimum allowed password
1851 * length. After setting this, the user will not be able to enter a new password that is not at
1852 * least as restrictive as what has been set. Note that the current password will remain until
1853 * the user has set a new one, so the change does not take place immediately. To prompt the user
1854 * for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
1855 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
1856 * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC}
1857 * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC},
1858 * {@link #PASSWORD_QUALITY_ALPHANUMERIC}, or {@link #PASSWORD_QUALITY_COMPLEX} with
1859 * {@link #setPasswordQuality}.
1860 * <p>
1861 * The calling device admin must have requested
1862 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1863 * not, a security exception will be thrown.
1864 * <p>
1865 * This method can be called on the {@link DevicePolicyManager} instance returned by
1866 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1867 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001868 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001869 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001870 * @param length The new desired minimum password length. A value of 0 means there is no
1871 * restriction.
1872 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1873 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Dianne Hackbornd6847842010-01-12 18:14:19 -08001874 */
Robin Lee25e26452015-06-02 09:56:29 -07001875 public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001876 if (mService != null) {
1877 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001878 mService.setPasswordMinimumLength(admin, length, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001879 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001880 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001881 }
1882 }
1883 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001884
Dianne Hackbornd6847842010-01-12 18:14:19 -08001885 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001886 * Retrieve the current minimum password length for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01001887 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00001888 * a separate challenge are not taken into account.
1889 *
1890 * <p>This method can be called on the {@link DevicePolicyManager} instance
1891 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1892 * restrictions on the parent profile.
1893 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001894 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001895 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001896 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001897 */
Robin Lee25e26452015-06-02 09:56:29 -07001898 public int getPasswordMinimumLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001899 return getPasswordMinimumLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001900 }
1901
1902 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001903 public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001904 if (mService != null) {
1905 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001906 return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001907 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001908 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001909 }
1910 }
1911 return 0;
1912 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001913
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001914 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001915 * Called by an application that is administering the device to set the minimum number of upper
1916 * case letters required in the password. After setting this, the user will not be able to enter
1917 * a new password that is not at least as restrictive as what has been set. Note that the
1918 * current password will remain until the user has set a new one, so the change does not take
1919 * place immediately. To prompt the user for a new password, use
1920 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
1921 * setting this value. This constraint is only imposed if the administrator has also requested
1922 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001923 * <p>
1924 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001925 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1926 * not, a security exception will be thrown.
1927 * <p>
1928 * This method can be called on the {@link DevicePolicyManager} instance returned by
1929 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1930 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001931 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001932 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1933 * @param length The new desired minimum number of upper case letters required in the password.
1934 * A value of 0 means there is no restriction.
1935 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1936 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001937 */
Robin Lee25e26452015-06-02 09:56:29 -07001938 public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001939 if (mService != null) {
1940 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001941 mService.setPasswordMinimumUpperCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001942 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001943 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001944 }
1945 }
1946 }
1947
1948 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001949 * Retrieve the current number of upper case letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01001950 * for a particular admin or all admins that set restrictions on this user and
Esteban Talaverac1c83592016-02-17 17:56:15 +00001951 * its participating profiles. Restrictions on profiles that have a separate challenge
1952 * are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001953 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001954 * {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001955 * and only applies when the password quality is
1956 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001957 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001958 * <p>This method can be called on the {@link DevicePolicyManager} instance
1959 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1960 * restrictions on the parent profile.
1961 *
Robin Lee25e26452015-06-02 09:56:29 -07001962 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001963 * aggregate all admins.
1964 * @return The minimum number of upper case letters required in the
1965 * password.
1966 */
Robin Lee25e26452015-06-02 09:56:29 -07001967 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001968 return getPasswordMinimumUpperCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001969 }
1970
1971 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001972 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001973 if (mService != null) {
1974 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001975 return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001976 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001977 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001978 }
1979 }
1980 return 0;
1981 }
1982
1983 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001984 * Called by an application that is administering the device to set the minimum number of lower
1985 * case letters required in the password. After setting this, the user will not be able to enter
1986 * a new password that is not at least as restrictive as what has been set. Note that the
1987 * current password will remain until the user has set a new one, so the change does not take
1988 * place immediately. To prompt the user for a new password, use
1989 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
1990 * setting this value. This constraint is only imposed if the administrator has also requested
1991 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001992 * <p>
1993 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001994 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1995 * not, a security exception will be thrown.
1996 * <p>
1997 * This method can be called on the {@link DevicePolicyManager} instance returned by
1998 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1999 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002000 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002001 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2002 * @param length The new desired minimum number of lower case letters required in the password.
2003 * A value of 0 means there is no restriction.
2004 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2005 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002006 */
Robin Lee25e26452015-06-02 09:56:29 -07002007 public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002008 if (mService != null) {
2009 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002010 mService.setPasswordMinimumLowerCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002011 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002012 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002013 }
2014 }
2015 }
2016
2017 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002018 * Retrieve the current number of lower case letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002019 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002020 * and its participating profiles. Restrictions on profiles that have
2021 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01002022 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00002023 * {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002024 * and only applies when the password quality is
2025 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002026 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002027 * <p>This method can be called on the {@link DevicePolicyManager} instance
2028 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2029 * restrictions on the parent profile.
2030 *
Robin Lee25e26452015-06-02 09:56:29 -07002031 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002032 * aggregate all admins.
2033 * @return The minimum number of lower case letters required in the
2034 * password.
2035 */
Robin Lee25e26452015-06-02 09:56:29 -07002036 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002037 return getPasswordMinimumLowerCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002038 }
2039
2040 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002041 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002042 if (mService != null) {
2043 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002044 return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002045 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002046 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002047 }
2048 }
2049 return 0;
2050 }
2051
2052 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002053 * Called by an application that is administering the device to set the minimum number of
2054 * letters required in the password. After setting this, the user will not be able to enter a
2055 * new password that is not at least as restrictive as what has been set. Note that the current
2056 * password will remain until the user has set a new one, so the change does not take place
2057 * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
2058 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
2059 * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
2060 * {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002061 * <p>
2062 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002063 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2064 * not, a security exception will be thrown.
2065 * <p>
2066 * This method can be called on the {@link DevicePolicyManager} instance returned by
2067 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2068 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002069 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002070 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2071 * @param length The new desired minimum number of letters required in the password. A value of
2072 * 0 means there is no restriction.
2073 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2074 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002075 */
Robin Lee25e26452015-06-02 09:56:29 -07002076 public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002077 if (mService != null) {
2078 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002079 mService.setPasswordMinimumLetters(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002080 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002081 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002082 }
2083 }
2084 }
2085
2086 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002087 * Retrieve the current number of letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002088 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002089 * and its participating profiles. Restrictions on profiles that have
2090 * a separate challenge are not taken into account.
2091 * This is the same value as set by
2092 * {@link #setPasswordMinimumLetters(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002093 * and only applies when the password quality is
2094 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002095 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002096 * <p>This method can be called on the {@link DevicePolicyManager} instance
2097 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2098 * restrictions on the parent profile.
2099 *
Robin Lee25e26452015-06-02 09:56:29 -07002100 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002101 * aggregate all admins.
2102 * @return The minimum number of letters required in the password.
2103 */
Robin Lee25e26452015-06-02 09:56:29 -07002104 public int getPasswordMinimumLetters(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002105 return getPasswordMinimumLetters(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002106 }
2107
2108 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002109 public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002110 if (mService != null) {
2111 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002112 return mService.getPasswordMinimumLetters(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002113 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002114 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002115 }
2116 }
2117 return 0;
2118 }
2119
2120 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002121 * Called by an application that is administering the device to set the minimum number of
2122 * numerical digits required in the password. After setting this, the user will not be able to
2123 * enter a new password that is not at least as restrictive as what has been set. Note that the
2124 * current password will remain until the user has set a new one, so the change does not take
2125 * place immediately. To prompt the user for a new password, use
2126 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
2127 * setting this value. This constraint is only imposed if the administrator has also requested
2128 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002129 * <p>
2130 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002131 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2132 * not, a security exception will be thrown.
2133 * <p>
2134 * This method can be called on the {@link DevicePolicyManager} instance returned by
2135 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2136 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002137 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002138 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2139 * @param length The new desired minimum number of numerical digits required in the password. A
2140 * value of 0 means there is no restriction.
2141 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2142 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002143 */
Robin Lee25e26452015-06-02 09:56:29 -07002144 public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002145 if (mService != null) {
2146 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002147 mService.setPasswordMinimumNumeric(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002148 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002149 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002150 }
2151 }
2152 }
2153
2154 /**
2155 * Retrieve the current number of numerical digits required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002156 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002157 * and its participating profiles. Restrictions on profiles that have
2158 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01002159 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00002160 * {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002161 * and only applies when the password quality is
2162 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002163 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002164 * <p>This method can be called on the {@link DevicePolicyManager} instance
2165 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2166 * restrictions on the parent profile.
2167 *
Robin Lee25e26452015-06-02 09:56:29 -07002168 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002169 * aggregate all admins.
2170 * @return The minimum number of numerical digits required in the password.
2171 */
Robin Lee25e26452015-06-02 09:56:29 -07002172 public int getPasswordMinimumNumeric(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002173 return getPasswordMinimumNumeric(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002174 }
2175
2176 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002177 public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002178 if (mService != null) {
2179 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002180 return mService.getPasswordMinimumNumeric(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002181 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002182 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002183 }
2184 }
2185 return 0;
2186 }
2187
2188 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002189 * Called by an application that is administering the device to set the minimum number of
2190 * symbols required in the password. After setting this, the user will not be able to enter a
2191 * new password that is not at least as restrictive as what has been set. Note that the current
2192 * password will remain until the user has set a new one, so the change does not take place
2193 * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
2194 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
2195 * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
2196 * {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002197 * <p>
2198 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002199 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2200 * not, a security exception will be thrown.
2201 * <p>
2202 * This method can be called on the {@link DevicePolicyManager} instance returned by
2203 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2204 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002205 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002206 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2207 * @param length The new desired minimum number of symbols required in the password. A value of
2208 * 0 means there is no restriction.
2209 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2210 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002211 */
Robin Lee25e26452015-06-02 09:56:29 -07002212 public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002213 if (mService != null) {
2214 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002215 mService.setPasswordMinimumSymbols(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002216 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002217 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002218 }
2219 }
2220 }
2221
2222 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002223 * Retrieve the current number of symbols required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002224 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002225 * and its participating profiles. Restrictions on profiles that have
2226 * a separate challenge are not taken into account. This is the same value as
2227 * set by {@link #setPasswordMinimumSymbols(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002228 * and only applies when the password quality is
2229 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002230 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002231 * <p>This method can be called on the {@link DevicePolicyManager} instance
2232 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2233 * restrictions on the parent profile.
2234 *
Robin Lee25e26452015-06-02 09:56:29 -07002235 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002236 * aggregate all admins.
2237 * @return The minimum number of symbols required in the password.
2238 */
Robin Lee25e26452015-06-02 09:56:29 -07002239 public int getPasswordMinimumSymbols(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002240 return getPasswordMinimumSymbols(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002241 }
2242
2243 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002244 public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002245 if (mService != null) {
2246 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002247 return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002248 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002249 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002250 }
2251 }
2252 return 0;
2253 }
2254
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002255 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002256 * Called by an application that is administering the device to set the minimum number of
2257 * non-letter characters (numerical digits or symbols) required in the password. After setting
2258 * this, the user will not be able to enter a new password that is not at least as restrictive
2259 * as what has been set. Note that the current password will remain until the user has set a new
2260 * one, so the change does not take place immediately. To prompt the user for a new password,
2261 * use {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
2262 * setting this value. This constraint is only imposed if the administrator has also requested
2263 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002264 * <p>
2265 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002266 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2267 * not, a security exception will be thrown.
2268 * <p>
2269 * This method can be called on the {@link DevicePolicyManager} instance returned by
2270 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2271 * profile.
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002272 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002273 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2274 * @param length The new desired minimum number of letters required in the password. A value of
2275 * 0 means there is no restriction.
2276 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2277 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002278 */
Robin Lee25e26452015-06-02 09:56:29 -07002279 public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002280 if (mService != null) {
2281 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002282 mService.setPasswordMinimumNonLetter(admin, length, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002283 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002284 throw e.rethrowFromSystemServer();
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002285 }
2286 }
2287 }
2288
2289 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002290 * Retrieve the current number of non-letter characters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002291 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002292 * and its participating profiles. Restrictions on profiles that have
2293 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01002294 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00002295 * {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002296 * and only applies when the password quality is
2297 * {@link #PASSWORD_QUALITY_COMPLEX}.
2298 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002299 * <p>This method can be called on the {@link DevicePolicyManager} instance
2300 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2301 * restrictions on the parent profile.
2302 *
Robin Lee25e26452015-06-02 09:56:29 -07002303 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002304 * aggregate all admins.
2305 * @return The minimum number of letters required in the password.
2306 */
Robin Lee25e26452015-06-02 09:56:29 -07002307 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002308 return getPasswordMinimumNonLetter(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002309 }
2310
2311 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002312 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002313 if (mService != null) {
2314 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002315 return mService.getPasswordMinimumNonLetter(admin, userHandle, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002316 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002317 throw e.rethrowFromSystemServer();
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002318 }
2319 }
2320 return 0;
2321 }
2322
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002323 /**
2324 * Called by an application that is administering the device to set the length of the password
2325 * history. After setting this, the user will not be able to enter a new password that is the
2326 * same as any password in the history. Note that the current password will remain until the
2327 * user has set a new one, so the change does not take place immediately. To prompt the user for
2328 * a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
2329 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
2330 * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC}
2331 * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX} {@link #PASSWORD_QUALITY_ALPHABETIC}, or
2332 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} with {@link #setPasswordQuality}.
2333 * <p>
2334 * The calling device admin must have requested
2335 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2336 * not, a security exception will be thrown.
2337 * <p>
2338 * This method can be called on the {@link DevicePolicyManager} instance returned by
2339 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2340 * profile.
2341 *
2342 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2343 * @param length The new desired length of password history. A value of 0 means there is no
2344 * restriction.
2345 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2346 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
2347 */
Robin Lee25e26452015-06-02 09:56:29 -07002348 public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002349 if (mService != null) {
2350 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002351 mService.setPasswordHistoryLength(admin, length, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002352 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002353 throw e.rethrowFromSystemServer();
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002354 }
2355 }
2356 }
2357
2358 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002359 * Called by a device admin to set the password expiration timeout. Calling this method will
2360 * restart the countdown for password expiration for the given admin, as will changing the
2361 * device password (for all admins).
2362 * <p>
2363 * The provided timeout is the time delta in ms and will be added to the current time. For
2364 * example, to have the password expire 5 days from now, timeout would be 5 * 86400 * 1000 =
2365 * 432000000 ms for timeout.
2366 * <p>
2367 * To disable password expiration, a value of 0 may be used for timeout.
2368 * <p>
2369 * The calling device admin must have requested
2370 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this method; if it has
2371 * not, a security exception will be thrown.
2372 * <p>
2373 * Note that setting the password will automatically reset the expiration time for all active
2374 * admins. Active admins do not need to explicitly call this method in that case.
2375 * <p>
2376 * This method can be called on the {@link DevicePolicyManager} instance returned by
2377 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2378 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002379 *
Jim Millera4e28d12010-11-08 16:15:47 -08002380 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002381 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0 means
2382 * there is no restriction (unlimited).
2383 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2384 * does not use {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD}
Jim Millera4e28d12010-11-08 16:15:47 -08002385 */
Robin Lee25e26452015-06-02 09:56:29 -07002386 public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) {
Jim Millera4e28d12010-11-08 16:15:47 -08002387 if (mService != null) {
2388 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002389 mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08002390 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002391 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08002392 }
2393 }
2394 }
2395
2396 /**
Jim Miller6b857682011-02-16 16:27:41 -08002397 * Get the password expiration timeout for the given admin. The expiration timeout is the
2398 * recurring expiration timeout provided in the call to
2399 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
Esteban Talaverac1c83592016-02-17 17:56:15 +00002400 * aggregate of all participating policy administrators if {@code admin} is null. Admins that
2401 * have set restrictions on profiles that have a separate challenge are not taken into account.
2402 *
2403 * <p>This method can be called on the {@link DevicePolicyManager} instance
2404 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2405 * restrictions on the parent profile.
Jim Millera4e28d12010-11-08 16:15:47 -08002406 *
Robin Lee25e26452015-06-02 09:56:29 -07002407 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08002408 * @return The timeout for the given admin or the minimum of all timeouts
2409 */
Robin Lee25e26452015-06-02 09:56:29 -07002410 public long getPasswordExpirationTimeout(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08002411 if (mService != null) {
2412 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002413 return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08002414 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002415 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08002416 }
2417 }
2418 return 0;
2419 }
2420
2421 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002422 * Get the current password expiration time for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01002423 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00002424 * a separate challenge are not taken into account. If admin is {@code null}, then a composite
2425 * of all expiration times is returned - which will be the minimum of all of them.
2426 *
2427 * <p>This method can be called on the {@link DevicePolicyManager} instance
2428 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2429 * the password expiration for the parent profile.
Jim Millera4e28d12010-11-08 16:15:47 -08002430 *
Robin Lee25e26452015-06-02 09:56:29 -07002431 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002432 * @return The password expiration time, in milliseconds since epoch.
Jim Millera4e28d12010-11-08 16:15:47 -08002433 */
Robin Lee25e26452015-06-02 09:56:29 -07002434 public long getPasswordExpiration(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08002435 if (mService != null) {
2436 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002437 return mService.getPasswordExpiration(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08002438 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002439 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08002440 }
2441 }
2442 return 0;
2443 }
2444
2445 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002446 * Retrieve the current password history length for a particular admin or all admins that
Rubin Xud3609d42016-07-13 18:32:57 +01002447 * set restrictions on this user and its participating profiles. Restrictions on profiles that
Esteban Talaverac1c83592016-02-17 17:56:15 +00002448 * have a separate challenge are not taken into account.
2449 *
2450 * <p>This method can be called on the {@link DevicePolicyManager} instance
2451 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2452 * restrictions on the parent profile.
2453 *
Robin Lee25e26452015-06-02 09:56:29 -07002454 * @param admin The name of the admin component to check, or {@code null} to aggregate
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002455 * all admins.
2456 * @return The length of the password history
2457 */
Robin Lee25e26452015-06-02 09:56:29 -07002458 public int getPasswordHistoryLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002459 return getPasswordHistoryLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002460 }
2461
2462 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002463 public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002464 if (mService != null) {
2465 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002466 return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002467 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002468 throw e.rethrowFromSystemServer();
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002469 }
2470 }
2471 return 0;
2472 }
2473
Dianne Hackbornd6847842010-01-12 18:14:19 -08002474 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08002475 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08002476 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08002477 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08002478 * @return Returns the maximum length that the user can enter.
2479 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08002480 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08002481 // Kind-of arbitrary.
2482 return 16;
2483 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002484
Dianne Hackborn254cb442010-01-27 19:23:59 -08002485 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002486 * Determine whether the current password the user has set is sufficient to meet the policy
2487 * requirements (e.g. quality, minimum length) that have been requested by the admins of this
2488 * user and its participating profiles. Restrictions on profiles that have a separate challenge
Andrew Scull5daf2732016-11-14 15:02:45 +00002489 * are not taken into account. The user must be unlocked in order to perform the check.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002490 * <p>
2491 * The calling device admin must have requested
2492 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2493 * not, a security exception will be thrown.
2494 * <p>
2495 * This method can be called on the {@link DevicePolicyManager} instance returned by
2496 * {@link #getParentProfileInstance(ComponentName)} in order to determine if the password set on
2497 * the parent profile is sufficient.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002498 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01002499 * @return Returns true if the password meets the current requirements, else false.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002500 * @throws SecurityException if the calling application does not own an active administrator
2501 * that uses {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Andrew Scull5daf2732016-11-14 15:02:45 +00002502 * @throws InvalidStateException if the user is not unlocked.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002503 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002504 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002505 if (mService != null) {
2506 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00002507 return mService.isActivePasswordSufficient(myUserId(), mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002508 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002509 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002510 }
2511 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002512 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08002513 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002514
Dianne Hackbornd6847842010-01-12 18:14:19 -08002515 /**
Clara Bayarrid7693912016-01-22 17:26:31 +00002516 * Determine whether the current profile password the user has set is sufficient
Esteban Talaverac1c83592016-02-17 17:56:15 +00002517 * to meet the policy requirements (e.g. quality, minimum length) that have been
Clara Bayarrid7693912016-01-22 17:26:31 +00002518 * requested by the admins of the parent user and its profiles.
2519 *
2520 * @param userHandle the userId of the profile to check the password for.
2521 * @return Returns true if the password would meet the current requirements, else false.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002522 * @throws SecurityException if {@code userHandle} is not a managed profile.
Clara Bayarrid7693912016-01-22 17:26:31 +00002523 * @hide
2524 */
2525 public boolean isProfileActivePasswordSufficientForParent(int userHandle) {
2526 if (mService != null) {
2527 try {
2528 return mService.isProfileActivePasswordSufficientForParent(userHandle);
2529 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002530 throw e.rethrowFromSystemServer();
Clara Bayarrid7693912016-01-22 17:26:31 +00002531 }
2532 }
2533 return false;
2534 }
2535
2536 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002537 * Retrieve the number of times the user has failed at entering a password since that last
2538 * successful password entry.
2539 * <p>
2540 * This method can be called on the {@link DevicePolicyManager} instance returned by
2541 * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the number of failed
2542 * password attemts for the parent user.
2543 * <p>
2544 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN}
2545 * to be able to call this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002546 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002547 * @return The number of times user has entered an incorrect password since the last correct
2548 * password entry.
2549 * @throws SecurityException if the calling application does not own an active administrator
2550 * that uses {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002551 */
2552 public int getCurrentFailedPasswordAttempts() {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00002553 return getCurrentFailedPasswordAttempts(myUserId());
2554 }
2555
2556 /**
2557 * Retrieve the number of times the given user has failed at entering a
2558 * password since that last successful password entry.
2559 *
2560 * <p>The calling device admin must have requested
2561 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call this method; if it has
2562 * not and it is not the system uid, a security exception will be thrown.
2563 *
2564 * @hide
2565 */
2566 public int getCurrentFailedPasswordAttempts(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002567 if (mService != null) {
2568 try {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00002569 return mService.getCurrentFailedPasswordAttempts(userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002570 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002571 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002572 }
2573 }
2574 return -1;
2575 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002576
2577 /**
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002578 * Queries whether {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002579 *
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002580 * @return true if RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002581 * @hide
2582 */
2583 public boolean getDoNotAskCredentialsOnBoot() {
2584 if (mService != null) {
2585 try {
2586 return mService.getDoNotAskCredentialsOnBoot();
2587 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002588 throw e.rethrowFromSystemServer();
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002589 }
2590 }
2591 return false;
2592 }
2593
2594 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002595 * Setting this to a value greater than zero enables a built-in policy that will perform a
2596 * device or profile wipe after too many incorrect device-unlock passwords have been entered.
2597 * This built-in policy combines watching for failed passwords and wiping the device, and
2598 * requires that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002599 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002600 * <p>
2601 * To implement any other policy (e.g. wiping data for a particular application only, erasing or
2602 * revoking credentials, or reporting the failure to a server), you should implement
2603 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} instead. Do not
2604 * use this API, because if the maximum count is reached, the device or profile will be wiped
2605 * immediately, and your callback will not be invoked.
2606 * <p>
2607 * This method can be called on the {@link DevicePolicyManager} instance returned by
2608 * {@link #getParentProfileInstance(ComponentName)} in order to set a value on the parent
2609 * profile.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002610 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002611 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002612 * @param num The number of failed password attempts at which point the device or profile will
2613 * be wiped.
2614 * @throws SecurityException if {@code admin} is not an active administrator or does not use
2615 * both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
2616 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002617 */
Robin Lee25e26452015-06-02 09:56:29 -07002618 public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002619 if (mService != null) {
2620 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002621 mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002622 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002623 throw e.rethrowFromSystemServer();
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002624 }
2625 }
2626 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002627
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002628 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002629 * Retrieve the current maximum number of login attempts that are allowed before the device
Rubin Xud3609d42016-07-13 18:32:57 +01002630 * or profile is wiped, for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002631 * and its participating profiles. Restrictions on profiles that have a separate challenge are
2632 * not taken into account.
2633 *
2634 * <p>This method can be called on the {@link DevicePolicyManager} instance
2635 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2636 * the value for the parent profile.
2637 *
Robin Lee25e26452015-06-02 09:56:29 -07002638 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002639 * all admins.
2640 */
Robin Lee25e26452015-06-02 09:56:29 -07002641 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002642 return getMaximumFailedPasswordsForWipe(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002643 }
2644
2645 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002646 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08002647 if (mService != null) {
2648 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002649 return mService.getMaximumFailedPasswordsForWipe(
2650 admin, userHandle, mParentInstance);
Dianne Hackborn254cb442010-01-27 19:23:59 -08002651 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002652 throw e.rethrowFromSystemServer();
Dianne Hackborn254cb442010-01-27 19:23:59 -08002653 }
2654 }
2655 return 0;
2656 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002657
Dianne Hackborn254cb442010-01-27 19:23:59 -08002658 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002659 * Returns the profile with the smallest maximum failed passwords for wipe,
2660 * for the given user. So for primary user, it might return the primary or
2661 * a managed profile. For a secondary user, it would be the same as the
2662 * user passed in.
2663 * @hide Used only by Keyguard
2664 */
2665 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
2666 if (mService != null) {
2667 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002668 return mService.getProfileWithMinimumFailedPasswordsForWipe(
2669 userHandle, mParentInstance);
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002670 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002671 throw e.rethrowFromSystemServer();
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002672 }
2673 }
2674 return UserHandle.USER_NULL;
2675 }
2676
2677 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002678 * Flag for {@link #resetPassword}: don't allow other admins to change
2679 * the password again until the user has entered it.
2680 */
2681 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002682
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002683 /**
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002684 * Flag for {@link #resetPassword}: don't ask for user credentials on device boot.
2685 * If the flag is set, the device can be booted without asking for user password.
2686 * The absence of this flag does not change the current boot requirements. This flag
2687 * can be set by the device owner only. If the app is not the device owner, the flag
2688 * is ignored. Once the flag is set, it cannot be reverted back without resetting the
2689 * device to factory defaults.
2690 */
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002691 public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002;
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002692
2693 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002694 * Force a new device unlock password (the password needed to access the entire device, not for
2695 * individual accounts) on the user. This takes effect immediately.
2696 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002697 * <em>Note: This API has been limited as of {@link android.os.Build.VERSION_CODES#N} for
Makoto Onuki70f929e2015-11-11 12:40:15 -08002698 * device admins that are not device owner and not profile owner.
2699 * The password can now only be changed if there is currently no password set. Device owner
Ricky Wai977ade22016-05-24 15:02:41 +01002700 * and profile owner can still do this when user is unlocked and does not have a managed
2701 * profile.</em>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002702 * <p>
2703 * The given password must be sufficient for the current password quality and length constraints
2704 * as returned by {@link #getPasswordQuality(ComponentName)} and
2705 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then
2706 * it will be rejected and false returned. Note that the password may be a stronger quality
2707 * (containing alphanumeric characters when the requested quality is only numeric), in which
2708 * case the currently active quality will be increased to match.
2709 * <p>
2710 * Calling with a null or empty password will clear any existing PIN, pattern or password if the
Robin Leece5c4002016-03-23 17:05:03 +00002711 * current password constraints allow it. <em>Note: This will not work in
2712 * {@link android.os.Build.VERSION_CODES#N} and later for managed profiles, or for device admins
2713 * that are not device owner or profile owner. Once set, the password cannot be changed to null
2714 * or empty except by these admins.</em>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002715 * <p>
2716 * The calling device admin must have requested
2717 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call this method; if it has
2718 * not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002719 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01002720 * @param password The new password for the user. Null or empty clears the password.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002721 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002722 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
2723 * @return Returns true if the password was applied, or false if it is not acceptable for the
2724 * current constraints or if the user has not been decrypted yet.
2725 * @throws SecurityException if the calling application does not own an active administrator
2726 * that uses {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD}
Ricky Wai977ade22016-05-24 15:02:41 +01002727 * @throws IllegalStateException if the calling user is locked or has a managed profile.
Andrew Scull3f81f4e2016-07-29 16:29:58 +01002728 * @throws IllegalArgumentException if the password does not meet system requirements.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002729 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002730 public boolean resetPassword(String password, int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002731 throwIfParentInstance("resetPassword");
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002732 if (mService != null) {
2733 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002734 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002735 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002736 throw e.rethrowFromSystemServer();
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002737 }
2738 }
2739 return false;
2740 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002741
Dianne Hackbornd6847842010-01-12 18:14:19 -08002742 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002743 * Called by an application that is administering the device to set the maximum time for user
2744 * activity until the device will lock. This limits the length that the user can set. It takes
2745 * effect immediately.
2746 * <p>
2747 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
2748 * to be able to call this method; if it has not, a security exception will be thrown.
2749 * <p>
2750 * This method can be called on the {@link DevicePolicyManager} instance returned by
2751 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2752 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002753 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002754 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002755 * @param timeMs The new desired maximum time to lock in milliseconds. A value of 0 means there
2756 * is no restriction.
2757 * @throws SecurityException if {@code admin} is not an active administrator or it does not use
2758 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002759 */
Robin Lee25e26452015-06-02 09:56:29 -07002760 public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002761 if (mService != null) {
2762 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002763 mService.setMaximumTimeToLock(admin, timeMs, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002764 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002765 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002766 }
2767 }
2768 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002769
Dianne Hackbornd6847842010-01-12 18:14:19 -08002770 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002771 * Retrieve the current maximum time to unlock for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01002772 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00002773 * a separate challenge are not taken into account.
2774 *
2775 * <p>This method can be called on the {@link DevicePolicyManager} instance
2776 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2777 * restrictions on the parent profile.
2778 *
Robin Lee25e26452015-06-02 09:56:29 -07002779 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002780 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07002781 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07002782 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002783 */
Robin Lee25e26452015-06-02 09:56:29 -07002784 public long getMaximumTimeToLock(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002785 return getMaximumTimeToLock(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002786 }
2787
2788 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002789 public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002790 if (mService != null) {
2791 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002792 return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002793 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002794 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002795 }
2796 }
2797 return 0;
2798 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002799
Dianne Hackbornd6847842010-01-12 18:14:19 -08002800 /**
Ricky Wai035e9242016-03-18 16:43:31 +00002801 * Returns maximum time to lock that applied by all profiles in this user. We do this because we
2802 * do not have a separate timeout to lock for work challenge only.
2803 *
2804 * @hide
2805 */
2806 public long getMaximumTimeToLockForUserAndProfiles(int userHandle) {
2807 if (mService != null) {
2808 try {
2809 return mService.getMaximumTimeToLockForUserAndProfiles(userHandle);
2810 } catch (RemoteException e) {
2811 throw e.rethrowFromSystemServer();
2812 }
2813 }
2814 return 0;
2815 }
2816
2817 /**
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002818 * Called by a device/profile owner to set the timeout after which unlocking with secondary, non
2819 * strong auth (e.g. fingerprint, trust agents) times out, i.e. the user has to use a strong
2820 * authentication method like password, pin or pattern.
2821 *
2822 * <p>This timeout is used internally to reset the timer to require strong auth again after
2823 * specified timeout each time it has been successfully used.
2824 *
2825 * <p>Fingerprint can also be disabled altogether using {@link #KEYGUARD_DISABLE_FINGERPRINT}.
2826 *
2827 * <p>Trust agents can also be disabled altogether using {@link #KEYGUARD_DISABLE_TRUST_AGENTS}.
2828 *
2829 * <p>The calling device admin must be a device or profile owner. If it is not,
2830 * a {@link SecurityException} will be thrown.
2831 *
Michal Karpinski943aabd2016-10-06 11:09:25 +01002832 * <p>The calling device admin can verify the value it has set by calling
2833 * {@link #getRequiredStrongAuthTimeout(ComponentName)} and passing in its instance.
2834 *
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002835 * <p>This method can be called on the {@link DevicePolicyManager} instance returned by
2836 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2837 * profile.
2838 *
2839 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2840 * @param timeoutMs The new timeout, after which the user will have to unlock with strong
Michal Karpinski943aabd2016-10-06 11:09:25 +01002841 * authentication method. A value of 0 means the admin is not participating in
2842 * controlling the timeout.
2843 * The minimum and maximum timeouts are platform-defined and are typically 1 hour and
2844 * 72 hours, respectively. Though discouraged, the admin may choose to require strong
2845 * auth at all times using {@link #KEYGUARD_DISABLE_FINGERPRINT} and/or
2846 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002847 *
2848 * @throws SecurityException if {@code admin} is not a device or profile owner.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002849 */
2850 public void setRequiredStrongAuthTimeout(@NonNull ComponentName admin,
2851 long timeoutMs) {
2852 if (mService != null) {
2853 try {
2854 mService.setRequiredStrongAuthTimeout(admin, timeoutMs, mParentInstance);
2855 } catch (RemoteException e) {
2856 throw e.rethrowFromSystemServer();
2857 }
2858 }
2859 }
2860
2861 /**
2862 * Determine for how long the user will be able to use secondary, non strong auth for
2863 * authentication, since last strong method authentication (password, pin or pattern) was used.
2864 * After the returned timeout the user is required to use strong authentication method.
2865 *
2866 * <p>This method can be called on the {@link DevicePolicyManager} instance
2867 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2868 * restrictions on the parent profile.
2869 *
2870 * @param admin The name of the admin component to check, or {@code null} to aggregate
2871 * accross all participating admins.
Michal Karpinski943aabd2016-10-06 11:09:25 +01002872 * @return The timeout or 0 if not configured for the provided admin.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002873 */
2874 public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin) {
2875 return getRequiredStrongAuthTimeout(admin, myUserId());
2876 }
2877
2878 /** @hide per-user version */
2879 public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin, @UserIdInt int userId) {
2880 if (mService != null) {
2881 try {
2882 return mService.getRequiredStrongAuthTimeout(admin, userId, mParentInstance);
2883 } catch (RemoteException e) {
2884 throw e.rethrowFromSystemServer();
2885 }
2886 }
2887 return DEFAULT_STRONG_AUTH_TIMEOUT_MS;
2888 }
2889
2890 /**
Andrew Scull85a63bc2016-10-24 13:47:47 +01002891 * Flag for {@link #lockNow(int)}: also evict the user's credential encryption key from the
2892 * keyring. The user's credential will need to be entered again in order to derive the
2893 * credential encryption key that will be stored back in the keyring for future use.
2894 * <p>
2895 * This flag can only be used by a profile owner when locking a managed profile on an FBE
2896 * device.
2897 * <p>
2898 * In order to secure user data, the user will be stopped and restarted so apps should wait
2899 * until they are next run to perform further actions.
2900 */
2901 public static final int FLAG_EVICT_CE_KEY = 1;
2902
2903 /** @hide */
2904 @Retention(RetentionPolicy.SOURCE)
2905 @IntDef(flag=true, value={FLAG_EVICT_CE_KEY})
2906 public @interface LockNowFlag {}
2907
2908 /**
2909 * Make the device lock immediately, as if the lock screen timeout has expired at the point of
2910 * this call.
2911 * <p>
2912 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
2913 * to be able to call this method; if it has not, a security exception will be thrown.
2914 * <p>
2915 * This method can be called on the {@link DevicePolicyManager} instance returned by
2916 * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile.
2917 * <p>
2918 * Equivalent to calling {@link #lockNow(int)} with no flags.
2919 *
2920 * @throws SecurityException if the calling application does not own an active administrator
2921 * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
2922 */
2923 public void lockNow() {
2924 lockNow(0);
2925 }
2926
2927 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002928 * Make the device lock immediately, as if the lock screen timeout has expired at the point of
2929 * this call.
2930 * <p>
2931 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
2932 * to be able to call this method; if it has not, a security exception will be thrown.
2933 * <p>
2934 * This method can be called on the {@link DevicePolicyManager} instance returned by
2935 * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002936 *
Andrew Scull85a63bc2016-10-24 13:47:47 +01002937 * @param flags May be 0 or {@link #FLAG_EVICT_CE_KEY}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002938 * @throws SecurityException if the calling application does not own an active administrator
Andrew Scull85a63bc2016-10-24 13:47:47 +01002939 * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} or the
2940 * {@link #FLAG_EVICT_CE_KEY} flag is passed by an application that is not a profile
2941 * owner of a managed profile.
2942 * @throws IllegalArgumentException if the {@link #FLAG_EVICT_CE_KEY} flag is passed when
2943 * locking the parent profile.
2944 * @throws UnsupportedOperationException if the {@link #FLAG_EVICT_CE_KEY} flag is passed on a
2945 * non-FBE device.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002946 */
Andrew Scull85a63bc2016-10-24 13:47:47 +01002947 public void lockNow(@LockNowFlag int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002948 if (mService != null) {
2949 try {
Andrew Scull85a63bc2016-10-24 13:47:47 +01002950 mService.lockNow(flags, mParentInstance);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002951 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002952 throw e.rethrowFromSystemServer();
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002953 }
2954 }
2955 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002956
Dianne Hackbornd6847842010-01-12 18:14:19 -08002957 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07002958 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002959 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07002960 */
2961 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
2962
2963 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002964 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
2965 * data.
2966 *
Paul Crowley2934b262014-12-02 11:21:13 +00002967 * <p>This flag may only be set by device owner admins; if it is set by
2968 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002969 */
2970 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
2971
2972 /**
Suprabh Shukla556b05a2016-08-10 15:49:24 -07002973 * Ask that all user data be wiped. If called as a secondary user, the user will be removed and
2974 * other users will remain unaffected. Calling from the primary user will cause the device to
2975 * reboot, erasing all device data - including all the secondary users and their data - while
2976 * booting up.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002977 * <p>
2978 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to
2979 * be able to call this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002980 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002981 * @param flags Bit mask of additional options: currently supported flags are
2982 * {@link #WIPE_EXTERNAL_STORAGE} and {@link #WIPE_RESET_PROTECTION_DATA}.
2983 * @throws SecurityException if the calling application does not own an active administrator
2984 * that uses {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002985 */
2986 public void wipeData(int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002987 throwIfParentInstance("wipeData");
Dianne Hackbornd6847842010-01-12 18:14:19 -08002988 if (mService != null) {
2989 try {
Makoto Onuki70f929e2015-11-11 12:40:15 -08002990 mService.wipeData(flags);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002991 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002992 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002993 }
2994 }
2995 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002996
Dianne Hackbornd6847842010-01-12 18:14:19 -08002997 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07002998 * Called by an application that is administering the device to set the
2999 * global proxy and exclusion list.
3000 * <p>
3001 * The calling device admin must have requested
3002 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
3003 * this method; if it has not, a security exception will be thrown.
3004 * Only the first device admin can set the proxy. If a second admin attempts
3005 * to set the proxy, the {@link ComponentName} of the admin originally setting the
Robin Lee25e26452015-06-02 09:56:29 -07003006 * proxy will be returned. If successful in setting the proxy, {@code null} will
Oscar Montemayor69238c62010-08-03 10:51:06 -07003007 * be returned.
3008 * The method can be called repeatedly by the device admin alrady setting the
3009 * proxy to update the proxy and exclusion list.
3010 *
Robin Lee25e26452015-06-02 09:56:29 -07003011 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Oscar Montemayor69238c62010-08-03 10:51:06 -07003012 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
3013 * Pass Proxy.NO_PROXY to reset the proxy.
3014 * @param exclusionList a list of domains to be excluded from the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07003015 * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName}
3016 * of the device admin that sets the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08003017 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07003018 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003019 public @Nullable ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec,
Oscar Montemayor69238c62010-08-03 10:51:06 -07003020 List<String> exclusionList ) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003021 throwIfParentInstance("setGlobalProxy");
Oscar Montemayor69238c62010-08-03 10:51:06 -07003022 if (proxySpec == null) {
3023 throw new NullPointerException();
3024 }
3025 if (mService != null) {
3026 try {
3027 String hostSpec;
3028 String exclSpec;
3029 if (proxySpec.equals(Proxy.NO_PROXY)) {
3030 hostSpec = null;
3031 exclSpec = null;
3032 } else {
3033 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
3034 throw new IllegalArgumentException();
3035 }
3036 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
3037 String hostName = sa.getHostName();
3038 int port = sa.getPort();
3039 StringBuilder hostBuilder = new StringBuilder();
3040 hostSpec = hostBuilder.append(hostName)
3041 .append(":").append(Integer.toString(port)).toString();
3042 if (exclusionList == null) {
3043 exclSpec = "";
3044 } else {
3045 StringBuilder listBuilder = new StringBuilder();
3046 boolean firstDomain = true;
3047 for (String exclDomain : exclusionList) {
3048 if (!firstDomain) {
3049 listBuilder = listBuilder.append(",");
3050 } else {
3051 firstDomain = false;
3052 }
3053 listBuilder = listBuilder.append(exclDomain.trim());
3054 }
3055 exclSpec = listBuilder.toString();
3056 }
Yuhao Zheng90704842014-02-28 17:22:45 -08003057 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
3058 != android.net.Proxy.PROXY_VALID)
3059 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07003060 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003061 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07003062 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003063 throw e.rethrowFromSystemServer();
Oscar Montemayor69238c62010-08-03 10:51:06 -07003064 }
3065 }
3066 return null;
3067 }
3068
3069 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003070 * Set a network-independent global HTTP proxy. This is not normally what you want for typical
3071 * HTTP proxies - they are generally network dependent. However if you're doing something
3072 * unusual like general internal filtering this may be useful. On a private network where the
3073 * proxy is not accessible, you may break HTTP using this.
3074 * <p>
3075 * This method requires the caller to be the device owner.
3076 * <p>
3077 * This proxy is only a recommendation and it is possible that some apps will ignore it.
Jason Monk03bc9912014-05-13 09:44:57 -04003078 *
Jason Monk03bc9912014-05-13 09:44:57 -04003079 * @see ProxyInfo
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003080 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3081 * @param proxyInfo The a {@link ProxyInfo} object defining the new global HTTP proxy. A
3082 * {@code null} value will clear the global HTTP proxy.
3083 * @throws SecurityException if {@code admin} is not the device owner.
Jason Monk03bc9912014-05-13 09:44:57 -04003084 */
Robin Lee25e26452015-06-02 09:56:29 -07003085 public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo
3086 proxyInfo) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003087 throwIfParentInstance("setRecommendedGlobalProxy");
Jason Monk03bc9912014-05-13 09:44:57 -04003088 if (mService != null) {
3089 try {
3090 mService.setRecommendedGlobalProxy(admin, proxyInfo);
3091 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003092 throw e.rethrowFromSystemServer();
Jason Monk03bc9912014-05-13 09:44:57 -04003093 }
3094 }
3095 }
3096
3097 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07003098 * Returns the component name setting the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07003099 * @return ComponentName object of the device admin that set the global proxy, or {@code null}
3100 * if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08003101 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07003102 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003103 public @Nullable ComponentName getGlobalProxyAdmin() {
Oscar Montemayor69238c62010-08-03 10:51:06 -07003104 if (mService != null) {
3105 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003106 return mService.getGlobalProxyAdmin(myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07003107 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003108 throw e.rethrowFromSystemServer();
Oscar Montemayor69238c62010-08-03 10:51:06 -07003109 }
3110 }
3111 return null;
3112 }
3113
3114 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08003115 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003116 * indicating that encryption is not supported.
3117 */
3118 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
3119
3120 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08003121 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003122 * indicating that encryption is supported, but is not currently active.
3123 */
3124 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
3125
3126 /**
Robin Lee3795fb02015-02-16 14:17:23 +00003127 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003128 * indicating that encryption is not currently active, but is currently
3129 * being activated. This is only reported by devices that support
3130 * encryption of data and only when the storage is currently
3131 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
3132 * to become encrypted will never return this value.
3133 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08003134 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003135
3136 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08003137 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003138 * indicating that encryption is active.
Amith Yamasani75db1252016-07-11 14:41:01 -07003139 * <p>
3140 * Also see {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003141 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08003142 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003143
3144 /**
Robin Lee3795fb02015-02-16 14:17:23 +00003145 * Result code for {@link #getStorageEncryptionStatus}:
3146 * indicating that encryption is active, but an encryption key has not
3147 * been set by the user.
3148 */
3149 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
3150
3151 /**
Makoto Onukid4c9e542016-02-25 18:17:30 -08003152 * Result code for {@link #getStorageEncryptionStatus}:
Amith Yamasani75db1252016-07-11 14:41:01 -07003153 * indicating that encryption is active and the encryption key is tied to the user or profile.
3154 * <p>
3155 * This value is only returned to apps targeting API level 24 and above. For apps targeting
3156 * earlier API levels, {@link #ENCRYPTION_STATUS_ACTIVE} is returned, even if the
3157 * encryption key is specific to the user or profile.
Makoto Onukid4c9e542016-02-25 18:17:30 -08003158 */
3159 public static final int ENCRYPTION_STATUS_ACTIVE_PER_USER = 5;
3160
3161 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003162 * Activity action: begin the process of encrypting data on the device. This activity should
3163 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
3164 * After resuming from this activity, use {@link #getStorageEncryption}
3165 * to check encryption status. However, on some devices this activity may never return, as
3166 * it may trigger a reboot and in some cases a complete data wipe of the device.
3167 */
3168 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
3169 public static final String ACTION_START_ENCRYPTION
3170 = "android.app.action.START_ENCRYPTION";
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003171 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07003172 * Widgets are enabled in keyguard
3173 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07003174 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07003175
3176 /**
Jim Miller50e62182014-04-23 17:25:00 -07003177 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07003178 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07003179 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
3180
3181 /**
3182 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
3183 */
3184 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
3185
3186 /**
Jim Miller50e62182014-04-23 17:25:00 -07003187 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
3188 */
3189 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
3190
3191 /**
3192 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
3193 */
3194 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
3195
3196 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02003197 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07003198 * (e.g. PIN/Pattern/Password).
3199 */
3200 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
3201
3202 /**
Jim Miller06e34502014-07-17 14:46:05 -07003203 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
3204 */
3205 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
3206
3207 /**
Adrian Roos7f06eed2016-02-05 15:21:02 -08003208 * Disable text entry into notifications on secure keyguard screens (e.g. PIN/Pattern/Password).
3209 */
3210 public static final int KEYGUARD_DISABLE_REMOTE_INPUT = 1 << 6;
3211
3212 /**
Jim Miller35207742012-11-02 15:33:20 -07003213 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07003214 */
3215 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07003216
3217 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003218 * Called by an application that is administering the device to request that the storage system
3219 * be encrypted.
3220 * <p>
3221 * When multiple device administrators attempt to control device encryption, the most secure,
3222 * supported setting will always be used. If any device administrator requests device
3223 * encryption, it will be enabled; Conversely, if a device administrator attempts to disable
3224 * device encryption while another device administrator has enabled it, the call to disable will
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003225 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003226 * <p>
3227 * This policy controls encryption of the secure (application data) storage area. Data written
3228 * to other storage areas may or may not be encrypted, and this policy does not require or
3229 * control the encryption of any other storage areas. There is one exception: If
3230 * {@link android.os.Environment#isExternalStorageEmulated()} is {@code true}, then the
3231 * directory returned by {@link android.os.Environment#getExternalStorageDirectory()} must be
3232 * written to disk within the encrypted storage area.
3233 * <p>
3234 * Important Note: On some devices, it is possible to encrypt storage without requiring the user
3235 * to create a device PIN or Password. In this case, the storage is encrypted, but the
3236 * encryption key may not be fully secured. For maximum security, the administrator should also
3237 * require (and check for) a pattern, PIN, or password.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003238 *
3239 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3240 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08003241 * @return the new request status (for all active admins) - will be one of
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003242 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
3243 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
3244 * {@link #getStorageEncryptionStatus()} to query the actual device state.
3245 * @throws SecurityException if {@code admin} is not an active administrator or does not use
3246 * {@link DeviceAdminInfo#USES_ENCRYPTED_STORAGE}
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003247 */
Robin Lee25e26452015-06-02 09:56:29 -07003248 public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003249 throwIfParentInstance("setStorageEncryption");
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003250 if (mService != null) {
3251 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003252 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003253 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003254 throw e.rethrowFromSystemServer();
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003255 }
3256 }
3257 return ENCRYPTION_STATUS_UNSUPPORTED;
3258 }
3259
3260 /**
3261 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08003262 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003263 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08003264 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
3265 * this will return the requested encryption setting as an aggregate of all active
3266 * administrators.
3267 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003268 */
Robin Lee25e26452015-06-02 09:56:29 -07003269 public boolean getStorageEncryption(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003270 throwIfParentInstance("getStorageEncryption");
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003271 if (mService != null) {
3272 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003273 return mService.getStorageEncryption(admin, myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003274 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003275 throw e.rethrowFromSystemServer();
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003276 }
3277 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08003278 return false;
3279 }
3280
3281 /**
3282 * Called by an application that is administering the device to
3283 * determine the current encryption status of the device.
Amith Yamasani75db1252016-07-11 14:41:01 -07003284 * <p>
Andy Stadler22dbfda2011-01-17 12:47:31 -08003285 * Depending on the returned status code, the caller may proceed in different
3286 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
3287 * storage system does not support encryption. If the
3288 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
3289 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00003290 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
3291 * storage system has enabled encryption but no password is set so further action
Amith Yamasani75db1252016-07-11 14:41:01 -07003292 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING},
3293 * {@link #ENCRYPTION_STATUS_ACTIVE} or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER},
3294 * no further action is required.
Andy Stadler22dbfda2011-01-17 12:47:31 -08003295 *
Robin Lee7e678712014-07-24 16:41:31 +01003296 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08003297 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00003298 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
Amith Yamasani75db1252016-07-11 14:41:01 -07003299 * {@link #ENCRYPTION_STATUS_ACTIVE}, or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08003300 */
3301 public int getStorageEncryptionStatus() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003302 throwIfParentInstance("getStorageEncryptionStatus");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003303 return getStorageEncryptionStatus(myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003304 }
3305
3306 /** @hide per-user version */
3307 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08003308 if (mService != null) {
3309 try {
Makoto Onukid4c9e542016-02-25 18:17:30 -08003310 return mService.getStorageEncryptionStatus(mContext.getPackageName(), userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08003311 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003312 throw e.rethrowFromSystemServer();
Andy Stadler22dbfda2011-01-17 12:47:31 -08003313 }
3314 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003315 return ENCRYPTION_STATUS_UNSUPPORTED;
3316 }
3317
3318 /**
Robin Lee2f7e1e42016-03-21 10:50:01 +00003319 * Mark a CA certificate as approved by the device user. This means that they have been notified
3320 * of the installation, were made aware of the risks, viewed the certificate and still wanted to
3321 * keep the certificate on the device.
3322 *
3323 * Calling with {@param approval} as {@code true} will cancel any ongoing warnings related to
3324 * this certificate.
3325 *
3326 * @hide
3327 */
3328 public boolean approveCaCert(String alias, int userHandle, boolean approval) {
3329 if (mService != null) {
3330 try {
3331 return mService.approveCaCert(alias, userHandle, approval);
3332 } catch (RemoteException e) {
3333 throw e.rethrowFromSystemServer();
3334 }
3335 }
3336 return false;
3337 }
3338
3339 /**
3340 * Check whether a CA certificate has been approved by the device user.
3341 *
3342 * @hide
3343 */
3344 public boolean isCaCertApproved(String alias, int userHandle) {
3345 if (mService != null) {
3346 try {
3347 return mService.isCaCertApproved(alias, userHandle);
3348 } catch (RemoteException e) {
3349 throw e.rethrowFromSystemServer();
3350 }
3351 }
3352 return false;
3353 }
3354
3355 /**
Robin Lee7e678712014-07-24 16:41:31 +01003356 * Installs the given certificate as a user CA.
3357 *
Edman Anjosf9946772016-11-28 16:35:15 +01003358 * The caller must be a profile or device owner on that user, or a delegate package given the
3359 * {@link #DELEGATION_CERT_INSTALL} scope via {@link #setDelegatedScopes}; otherwise a
3360 * security exception will be thrown.
3361 *
Robin Lee25e26452015-06-02 09:56:29 -07003362 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3363 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003364 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04003365 *
3366 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01003367 * interrupted, true otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003368 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3369 * owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003370 * @see #setDelegatedScopes
3371 * @see #DELEGATION_CERT_INSTALL
Maggie Benthallda51e682013-08-08 22:35:44 -04003372 */
Robin Lee25e26452015-06-02 09:56:29 -07003373 public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003374 throwIfParentInstance("installCaCert");
Maggie Benthallda51e682013-08-08 22:35:44 -04003375 if (mService != null) {
3376 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003377 return mService.installCaCert(admin, mContext.getPackageName(), certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04003378 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003379 throw e.rethrowFromSystemServer();
Maggie Benthallda51e682013-08-08 22:35:44 -04003380 }
3381 }
3382 return false;
3383 }
3384
3385 /**
Robin Lee7e678712014-07-24 16:41:31 +01003386 * Uninstalls the given certificate from trusted user CAs, if present.
3387 *
Edman Anjosf9946772016-11-28 16:35:15 +01003388 * The caller must be a profile or device owner on that user, or a delegate package given the
3389 * {@link #DELEGATION_CERT_INSTALL} scope via {@link #setDelegatedScopes}; otherwise a
3390 * security exception will be thrown.
3391 *
Robin Lee25e26452015-06-02 09:56:29 -07003392 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3393 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003394 * @param certBuffer encoded form of the certificate to remove.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003395 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3396 * owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003397 * @see #setDelegatedScopes
3398 * @see #DELEGATION_CERT_INSTALL
Maggie Benthallda51e682013-08-08 22:35:44 -04003399 */
Robin Lee25e26452015-06-02 09:56:29 -07003400 public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003401 throwIfParentInstance("uninstallCaCert");
Maggie Benthallda51e682013-08-08 22:35:44 -04003402 if (mService != null) {
3403 try {
Robin Lee306fe082014-06-19 14:04:24 +00003404 final String alias = getCaCertAlias(certBuffer);
Edman Anjosf9946772016-11-28 16:35:15 +01003405 mService.uninstallCaCerts(admin, mContext.getPackageName(), new String[] {alias});
Robin Lee306fe082014-06-19 14:04:24 +00003406 } catch (CertificateException e) {
3407 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04003408 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003409 throw e.rethrowFromSystemServer();
Maggie Benthallda51e682013-08-08 22:35:44 -04003410 }
3411 }
3412 }
3413
3414 /**
Robin Lee7e678712014-07-24 16:41:31 +01003415 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
3416 * If a user has installed any certificates by other means than device policy these will be
3417 * included too.
3418 *
Robin Lee25e26452015-06-02 09:56:29 -07003419 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3420 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003421 * @return a List of byte[] arrays, each encoding one user CA certificate.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003422 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3423 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04003424 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003425 public @NonNull List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) {
3426 final List<byte[]> certs = new ArrayList<byte[]>();
Benjamin Franzbc33c822016-04-15 08:57:52 +01003427 throwIfParentInstance("getInstalledCaCerts");
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003428 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01003429 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003430 mService.enforceCanManageCaCerts(admin, mContext.getPackageName());
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003431 final TrustedCertificateStore certStore = new TrustedCertificateStore();
3432 for (String alias : certStore.userAliases()) {
3433 try {
3434 certs.add(certStore.getCertificate(alias).getEncoded());
3435 } catch (CertificateException ce) {
3436 Log.w(TAG, "Could not encode certificate: " + alias, ce);
3437 }
3438 }
3439 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003440 throw re.rethrowFromSystemServer();
Robin Lee7e678712014-07-24 16:41:31 +01003441 }
3442 }
3443 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04003444 }
3445
3446 /**
Robin Lee7e678712014-07-24 16:41:31 +01003447 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
3448 * means other than device policy will also be removed, except for system CA certificates.
3449 *
Robin Lee25e26452015-06-02 09:56:29 -07003450 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3451 * {@code null} if calling from a delegated certificate installer.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003452 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3453 * owner.
Robin Lee7e678712014-07-24 16:41:31 +01003454 */
Robin Lee25e26452015-06-02 09:56:29 -07003455 public void uninstallAllUserCaCerts(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003456 throwIfParentInstance("uninstallAllUserCaCerts");
Robin Lee7e678712014-07-24 16:41:31 +01003457 if (mService != null) {
Robin Lee83881bd2015-06-09 16:04:38 -07003458 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003459 mService.uninstallCaCerts(admin, mContext.getPackageName(),
3460 new TrustedCertificateStore().userAliases() .toArray(new String[0]));
Robin Lee83881bd2015-06-09 16:04:38 -07003461 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003462 throw re.rethrowFromSystemServer();
Robin Lee7e678712014-07-24 16:41:31 +01003463 }
3464 }
3465 }
3466
3467 /**
3468 * Returns whether this certificate is installed as a trusted CA.
3469 *
Robin Lee25e26452015-06-02 09:56:29 -07003470 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3471 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003472 * @param certBuffer encoded form of the certificate to look up.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003473 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3474 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04003475 */
Robin Lee25e26452015-06-02 09:56:29 -07003476 public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003477 throwIfParentInstance("hasCaCertInstalled");
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003478 if (mService != null) {
3479 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003480 mService.enforceCanManageCaCerts(admin, mContext.getPackageName());
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003481 return getCaCertAlias(certBuffer) != null;
3482 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003483 throw re.rethrowFromSystemServer();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003484 } catch (CertificateException ce) {
3485 Log.w(TAG, "Could not parse certificate", ce);
3486 }
Maggie Benthallda51e682013-08-08 22:35:44 -04003487 }
3488 return false;
3489 }
3490
3491 /**
Robin Leece3399f2016-02-24 12:08:32 +00003492 * Called by a device or profile owner, or delegated certificate installer, to install a
3493 * certificate and corresponding private key. All apps within the profile will be able to access
3494 * the certificate and use the private key, given direct user approval.
3495 *
3496 * <p>Access to the installed credentials will not be granted to the caller of this API without
3497 * direct user approval. This is for security - should a certificate installer become
3498 * compromised, certificates it had already installed will be protected.
3499 *
3500 * <p>If the installer must have access to the credentials, call
Rubin Xub4365912016-03-23 12:13:22 +00003501 * {@link #installKeyPair(ComponentName, PrivateKey, Certificate[], String, boolean)} instead.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003502 *
Robin Lee25e26452015-06-02 09:56:29 -07003503 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3504 * {@code null} if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003505 * @param privKey The private key to install.
3506 * @param cert The certificate to install.
3507 * @param alias The private key alias under which to install the certificate. If a certificate
3508 * with that alias already exists, it will be overwritten.
3509 * @return {@code true} if the keys were installed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003510 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3511 * owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003512 * @see #setDelegatedScopes
3513 * @see #DELEGATION_CERT_INSTALL
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003514 */
Robin Leefbc65642015-08-03 16:21:22 +01003515 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
3516 @NonNull Certificate cert, @NonNull String alias) {
Rubin Xub4365912016-03-23 12:13:22 +00003517 return installKeyPair(admin, privKey, new Certificate[] {cert}, alias, false);
Robin Leece3399f2016-02-24 12:08:32 +00003518 }
3519
3520 /**
3521 * Called by a device or profile owner, or delegated certificate installer, to install a
Rubin Xub4365912016-03-23 12:13:22 +00003522 * certificate chain and corresponding private key for the leaf certificate. All apps within the
3523 * profile will be able to access the certificate chain and use the private key, given direct
3524 * user approval.
Robin Leece3399f2016-02-24 12:08:32 +00003525 *
Robin Leea1b290e2016-03-09 14:38:36 +00003526 * <p>The caller of this API may grant itself access to the certificate and private key
3527 * immediately, without user approval. It is a best practice not to request this unless strictly
3528 * necessary since it opens up additional security vulnerabilities.
Robin Leece3399f2016-02-24 12:08:32 +00003529 *
3530 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Robin Leea1b290e2016-03-09 14:38:36 +00003531 * {@code null} if calling from a delegated certificate installer.
Robin Leece3399f2016-02-24 12:08:32 +00003532 * @param privKey The private key to install.
Rubin Xub4365912016-03-23 12:13:22 +00003533 * @param certs The certificate chain to install. The chain should start with the leaf
3534 * certificate and include the chain of trust in order. This will be returned by
3535 * {@link android.security.KeyChain#getCertificateChain}.
Robin Leece3399f2016-02-24 12:08:32 +00003536 * @param alias The private key alias under which to install the certificate. If a certificate
Robin Leea1b290e2016-03-09 14:38:36 +00003537 * with that alias already exists, it will be overwritten.
Robin Leece3399f2016-02-24 12:08:32 +00003538 * @param requestAccess {@code true} to request that the calling app be granted access to the
Robin Leea1b290e2016-03-09 14:38:36 +00003539 * credentials immediately. Otherwise, access to the credentials will be gated by user
3540 * approval.
Robin Leece3399f2016-02-24 12:08:32 +00003541 * @return {@code true} if the keys were installed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003542 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3543 * owner.
Rubin Xub4365912016-03-23 12:13:22 +00003544 * @see android.security.KeyChain#getCertificateChain
Edman Anjosf9946772016-11-28 16:35:15 +01003545 * @see #setDelegatedScopes
3546 * @see #DELEGATION_CERT_INSTALL
Robin Leece3399f2016-02-24 12:08:32 +00003547 */
3548 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
Rubin Xub4365912016-03-23 12:13:22 +00003549 @NonNull Certificate[] certs, @NonNull String alias, boolean requestAccess) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003550 throwIfParentInstance("installKeyPair");
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003551 try {
Rubin Xub4365912016-03-23 12:13:22 +00003552 final byte[] pemCert = Credentials.convertToPem(certs[0]);
3553 byte[] pemChain = null;
3554 if (certs.length > 1) {
3555 pemChain = Credentials.convertToPem(Arrays.copyOfRange(certs, 1, certs.length));
3556 }
Robin Lee0d5ccb72014-09-12 17:41:44 +01003557 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
3558 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
Edman Anjosf9946772016-11-28 16:35:15 +01003559 return mService.installKeyPair(admin, mContext.getPackageName(), pkcs8Key, pemCert,
3560 pemChain, alias, requestAccess);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003561 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003562 throw e.rethrowFromSystemServer();
Robin Lee0d5ccb72014-09-12 17:41:44 +01003563 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
3564 Log.w(TAG, "Failed to obtain private key material", e);
3565 } catch (CertificateException | IOException e) {
3566 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003567 }
3568 return false;
3569 }
3570
3571 /**
Robin Leea1b290e2016-03-09 14:38:36 +00003572 * Called by a device or profile owner, or delegated certificate installer, to remove a
3573 * certificate and private key pair installed under a given alias.
Robin Leefbc65642015-08-03 16:21:22 +01003574 *
3575 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Robin Leea1b290e2016-03-09 14:38:36 +00003576 * {@code null} if calling from a delegated certificate installer.
Robin Leefbc65642015-08-03 16:21:22 +01003577 * @param alias The private key alias under which the certificate is installed.
Robin Leea1b290e2016-03-09 14:38:36 +00003578 * @return {@code true} if the private key alias no longer exists, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003579 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3580 * owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003581 * @see #setDelegatedScopes
3582 * @see #DELEGATION_CERT_INSTALL
Robin Leefbc65642015-08-03 16:21:22 +01003583 */
3584 public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003585 throwIfParentInstance("removeKeyPair");
Robin Leefbc65642015-08-03 16:21:22 +01003586 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003587 return mService.removeKeyPair(admin, mContext.getPackageName(), alias);
Robin Leefbc65642015-08-03 16:21:22 +01003588 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003589 throw e.rethrowFromSystemServer();
Robin Leefbc65642015-08-03 16:21:22 +01003590 }
Robin Leefbc65642015-08-03 16:21:22 +01003591 }
3592
3593 /**
Robin Lee25e26452015-06-02 09:56:29 -07003594 * @return the alias of a given CA certificate in the certificate store, or {@code null} if it
Robin Lee306fe082014-06-19 14:04:24 +00003595 * doesn't exist.
3596 */
3597 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
3598 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
3599 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
3600 new ByteArrayInputStream(certBuffer));
3601 return new TrustedCertificateStore().getCertificateAlias(cert);
3602 }
3603
3604 /**
Rubin Xuec32b562015-03-03 17:34:05 +00003605 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01003606 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00003607 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01003608 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00003609 * <p>
3610 * Delegated certificate installer is a per-user state. The delegated access is persistent until
3611 * it is later cleared by calling this method with a null value or uninstallling the certificate
3612 * installer.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003613 * <p>
Rubin Xuf03d0a62016-02-10 14:54:15 +00003614 * <b>Note:</b>Starting from {@link android.os.Build.VERSION_CODES#N}, if the caller
3615 * application's target SDK version is {@link android.os.Build.VERSION_CODES#N} or newer, the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003616 * supplied certificate installer package must be installed when calling this API, otherwise an
3617 * {@link IllegalArgumentException} will be thrown.
Rubin Xuec32b562015-03-03 17:34:05 +00003618 *
Robin Lee25e26452015-06-02 09:56:29 -07003619 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xuec32b562015-03-03 17:34:05 +00003620 * @param installerPackage The package name of the certificate installer which will be given
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003621 * access. If {@code null} is given the current package will be cleared.
3622 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003623 *
3624 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #setDelegatedScopes}
3625 * with the {@link #DELEGATION_CERT_INSTALL} scope instead.
Rubin Xuec32b562015-03-03 17:34:05 +00003626 */
Edman Anjosf9946772016-11-28 16:35:15 +01003627 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07003628 public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String
3629 installerPackage) throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003630 throwIfParentInstance("setCertInstallerPackage");
Rubin Xuec32b562015-03-03 17:34:05 +00003631 if (mService != null) {
3632 try {
Robin Lee25e26452015-06-02 09:56:29 -07003633 mService.setCertInstallerPackage(admin, installerPackage);
Rubin Xuec32b562015-03-03 17:34:05 +00003634 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003635 throw e.rethrowFromSystemServer();
Rubin Xuec32b562015-03-03 17:34:05 +00003636 }
3637 }
3638 }
3639
3640 /**
Edman Anjosf9946772016-11-28 16:35:15 +01003641 * Called by a profile owner or device owner to retrieve the certificate installer for the user,
3642 * or {@code null} if none is set. If there are multiple delegates this function will return one
3643 * of them.
Rubin Xuec32b562015-03-03 17:34:05 +00003644 *
Robin Lee25e26452015-06-02 09:56:29 -07003645 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003646 * @return The package name of the current delegated certificate installer, or {@code null} if
3647 * none is set.
3648 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003649 *
3650 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatePackages}
3651 * with the {@link #DELEGATION_CERT_INSTALL} scope instead.
Rubin Xuec32b562015-03-03 17:34:05 +00003652 */
Edman Anjosf9946772016-11-28 16:35:15 +01003653 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07003654 public @Nullable String getCertInstallerPackage(@NonNull ComponentName admin)
3655 throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003656 throwIfParentInstance("getCertInstallerPackage");
Rubin Xuec32b562015-03-03 17:34:05 +00003657 if (mService != null) {
3658 try {
Robin Lee25e26452015-06-02 09:56:29 -07003659 return mService.getCertInstallerPackage(admin);
Rubin Xuec32b562015-03-03 17:34:05 +00003660 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003661 throw e.rethrowFromSystemServer();
Rubin Xuec32b562015-03-03 17:34:05 +00003662 }
3663 }
3664 return null;
3665 }
3666
3667 /**
Edman Anjosf9946772016-11-28 16:35:15 +01003668 * Called by a profile owner or device owner to grant access to privileged APIs to another app.
3669 * Granted APIs are determined by {@code scopes}, which is a list of the {@code DELEGATION_*}
3670 * constants.
3671 * <p>
Edman Anjos9e62c312017-01-26 22:22:58 +01003672 * A broadcast with the {@link #ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED} action will be
3673 * sent to the {@code delegatePackage} with its new scopes in an {@code ArrayList<String>} extra
3674 * under the {@link #EXTRA_DELEGATION_SCOPES} key. The broadcast is sent with the
3675 * {@link Intent#FLAG_RECEIVER_REGISTERED_ONLY} flag.
3676 * <p>
Edman Anjosf9946772016-11-28 16:35:15 +01003677 * Delegated scopes are a per-user state. The delegated access is persistent until it is later
3678 * cleared by calling this method with an empty {@code scopes} list or uninstalling the
3679 * {@code delegatePackage}.
3680 *
3681 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3682 * @param delegatePackage The package name of the app which will be given access.
3683 * @param scopes The groups of privileged APIs whose access should be granted to
3684 * {@code delegatedPackage}.
3685 * @throws SecurityException if {@code admin} is not a device or a profile owner.
3686 */
3687 public void setDelegatedScopes(@NonNull ComponentName admin, @NonNull String delegatePackage,
3688 @NonNull List<String> scopes) {
3689 throwIfParentInstance("setDelegatedScopes");
3690 if (mService != null) {
3691 try {
3692 mService.setDelegatedScopes(admin, delegatePackage, scopes);
3693 } catch (RemoteException e) {
3694 throw e.rethrowFromSystemServer();
3695 }
3696 }
3697 }
3698
3699 /**
3700 * Called by a profile owner or device owner to retrieve a list of the scopes given to a
3701 * delegate package. Other apps can use this method to retrieve their own delegated scopes by
3702 * passing {@code null} for {@code admin} and their own package name as
3703 * {@code delegatedPackage}.
3704 *
3705 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3706 * {@code null} if the caller is {@code delegatedPackage}.
3707 * @param delegatedPackage The package name of the app whose scopes should be retrieved.
3708 * @return A list containing the scopes given to {@code delegatedPackage}.
3709 * @throws SecurityException if {@code admin} is not a device or a profile owner.
3710 */
3711 @NonNull
Edman Anjos9e62c312017-01-26 22:22:58 +01003712 public List<String> getDelegatedScopes(@Nullable ComponentName admin,
Edman Anjosf9946772016-11-28 16:35:15 +01003713 @NonNull String delegatedPackage) {
3714 throwIfParentInstance("getDelegatedScopes");
3715 if (mService != null) {
3716 try {
3717 return mService.getDelegatedScopes(admin, delegatedPackage);
3718 } catch (RemoteException e) {
3719 throw e.rethrowFromSystemServer();
3720 }
3721 }
3722 return null;
3723 }
3724
3725 /**
3726 * Called by a profile owner or device owner to retrieve a list of delegate packages that were
3727 * granted a delegation scope.
3728 *
3729 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3730 * @param delegationScope The scope whose delegates should be retrieved.
3731 * @return A list of package names of the current delegated packages for
3732 {@code delegationScope}.
3733 * @throws SecurityException if {@code admin} is not a device or a profile owner.
3734 */
3735 @Nullable
3736 public List<String> getDelegatePackages(@NonNull ComponentName admin,
3737 @NonNull String delegationScope) {
3738 throwIfParentInstance("getDelegatePackages");
3739 if (mService != null) {
3740 try {
3741 return mService.getDelegatePackages(admin, delegationScope);
3742 } catch (RemoteException e) {
3743 throw e.rethrowFromSystemServer();
3744 }
3745 }
3746 return null;
3747 }
3748
3749 /**
Robin Lee244ce8e2016-01-05 18:03:46 +00003750 * Called by a device or profile owner to configure an always-on VPN connection through a
Robin Leedc679712016-05-03 13:23:03 +01003751 * specific application for the current user.
3752 *
3753 * @deprecated this version only exists for compability with previous developer preview builds.
3754 * TODO: delete once there are no longer any live references.
3755 * @hide
3756 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07003757 @Deprecated
Robin Leedc679712016-05-03 13:23:03 +01003758 public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage)
3759 throws NameNotFoundException, UnsupportedOperationException {
3760 setAlwaysOnVpnPackage(admin, vpnPackage, /* lockdownEnabled */ true);
3761 }
3762
3763 /**
3764 * Called by a device or profile owner to configure an always-on VPN connection through a
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003765 * specific application for the current user. This connection is automatically granted and
3766 * persisted after a reboot.
3767 * <p>
3768 * The designated package should declare a {@link android.net.VpnService} in its manifest
3769 * guarded by {@link android.Manifest.permission#BIND_VPN_SERVICE}, otherwise the call will
3770 * fail.
Robin Lee244ce8e2016-01-05 18:03:46 +00003771 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003772 * @param vpnPackage The package name for an installed VPN app on the device, or {@code null} to
Robin Leedc679712016-05-03 13:23:03 +01003773 * remove an existing always-on VPN configuration.
3774 * @param lockdownEnabled {@code true} to disallow networking when the VPN is not connected or
3775 * {@code false} otherwise. This carries the risk that any failure of the VPN provider
3776 * could break networking for all apps. This has no effect when clearing.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003777 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Robin Leeee5eb932016-04-05 16:27:15 +01003778 * @throws NameNotFoundException if {@code vpnPackage} is not installed.
3779 * @throws UnsupportedOperationException if {@code vpnPackage} exists but does not support being
3780 * set as always-on, or if always-on VPN is not available.
Robin Lee244ce8e2016-01-05 18:03:46 +00003781 */
Robin Leedc679712016-05-03 13:23:03 +01003782 public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage,
3783 boolean lockdownEnabled)
Robin Leeee5eb932016-04-05 16:27:15 +01003784 throws NameNotFoundException, UnsupportedOperationException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003785 throwIfParentInstance("setAlwaysOnVpnPackage");
Robin Lee244ce8e2016-01-05 18:03:46 +00003786 if (mService != null) {
3787 try {
Robin Leedc679712016-05-03 13:23:03 +01003788 if (!mService.setAlwaysOnVpnPackage(admin, vpnPackage, lockdownEnabled)) {
Robin Leeee5eb932016-04-05 16:27:15 +01003789 throw new NameNotFoundException(vpnPackage);
3790 }
Robin Lee244ce8e2016-01-05 18:03:46 +00003791 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003792 throw e.rethrowFromSystemServer();
Robin Lee244ce8e2016-01-05 18:03:46 +00003793 }
3794 }
Robin Lee244ce8e2016-01-05 18:03:46 +00003795 }
3796
3797 /**
3798 * Called by a device or profile owner to read the name of the package administering an
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003799 * always-on VPN connection for the current user. If there is no such package, or the always-on
3800 * VPN is provided by the system instead of by an application, {@code null} will be returned.
Robin Lee244ce8e2016-01-05 18:03:46 +00003801 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003802 * @return Package name of VPN controller responsible for always-on VPN, or {@code null} if none
3803 * is set.
3804 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Robin Lee244ce8e2016-01-05 18:03:46 +00003805 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003806 public @Nullable String getAlwaysOnVpnPackage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003807 throwIfParentInstance("getAlwaysOnVpnPackage");
Robin Lee244ce8e2016-01-05 18:03:46 +00003808 if (mService != null) {
3809 try {
3810 return mService.getAlwaysOnVpnPackage(admin);
3811 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003812 throw e.rethrowFromSystemServer();
Robin Lee244ce8e2016-01-05 18:03:46 +00003813 }
3814 }
3815 return null;
3816 }
3817
3818 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003819 * Called by an application that is administering the device to disable all cameras on the
3820 * device, for this user. After setting this, no applications running as this user will be able
3821 * to access any cameras on the device.
3822 * <p>
3823 * If the caller is device owner, then the restriction will be applied to all users.
3824 * <p>
3825 * The calling device admin must have requested
3826 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call this method; if it has
3827 * not, a security exception will be thrown.
Ben Komalo2447edd2011-05-09 16:05:33 -07003828 *
3829 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3830 * @param disabled Whether or not the camera should be disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003831 * @throws SecurityException if {@code admin} is not an active administrator or does not use
3832 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA}.
Ben Komalo2447edd2011-05-09 16:05:33 -07003833 */
Robin Lee25e26452015-06-02 09:56:29 -07003834 public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003835 throwIfParentInstance("setCameraDisabled");
Ben Komalo2447edd2011-05-09 16:05:33 -07003836 if (mService != null) {
3837 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003838 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07003839 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003840 throw e.rethrowFromSystemServer();
Ben Komalo2447edd2011-05-09 16:05:33 -07003841 }
3842 }
3843 }
3844
3845 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07003846 * Determine whether or not the device's cameras have been disabled for this user,
Makoto Onuki32b30572015-12-11 14:29:51 -08003847 * either by the calling admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07003848 * @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 -07003849 * have disabled the camera
3850 */
Robin Lee25e26452015-06-02 09:56:29 -07003851 public boolean getCameraDisabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003852 throwIfParentInstance("getCameraDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003853 return getCameraDisabled(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003854 }
3855
3856 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003857 public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07003858 if (mService != null) {
3859 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003860 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07003861 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003862 throw e.rethrowFromSystemServer();
Ben Komalo2447edd2011-05-09 16:05:33 -07003863 }
3864 }
3865 return false;
3866 }
3867
3868 /**
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003869 * Called by a device owner to request a bugreport.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003870 * <p>
Esteban Talaverad36dd152016-12-15 08:51:45 +00003871 * If the device contains secondary users or profiles, they must be affiliated with the device
3872 * owner user. Otherwise a {@link SecurityException} will be thrown. See
3873 * {@link #setAffiliationIds}.
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003874 *
3875 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003876 * @return {@code true} if the bugreport collection started successfully, or {@code false} if it
3877 * wasn't triggered because a previous bugreport operation is still active (either the
3878 * bugreport is still running or waiting for the user to share or decline)
Esteban Talaverad36dd152016-12-15 08:51:45 +00003879 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
3880 * profile or secondary user that is not affiliated with the device owner user.
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003881 */
3882 public boolean requestBugreport(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003883 throwIfParentInstance("requestBugreport");
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003884 if (mService != null) {
3885 try {
3886 return mService.requestBugreport(admin);
3887 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003888 throw e.rethrowFromSystemServer();
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003889 }
3890 }
3891 return false;
3892 }
3893
3894 /**
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07003895 * Determine whether or not creating a guest user has been disabled for the device
3896 *
3897 * @hide
3898 */
3899 public boolean getGuestUserDisabled(@Nullable ComponentName admin) {
3900 // Currently guest users can always be created if multi-user is enabled
3901 // TODO introduce a policy for guest user creation
3902 return false;
3903 }
3904
3905 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01003906 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
3907 * screen capture also prevents the content from being shown on display devices that do not have
3908 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
3909 * secure surfaces and secure displays.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003910 * <p>
3911 * The calling device admin must be a device or profile owner. If it is not, a security
3912 * exception will be thrown.
3913 * <p>
3914 * From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also blocks
3915 * assist requests for all activities of the relevant user.
Benjamin Franzc200f442015-06-25 18:20:04 +01003916 *
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003917 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003918 * @param disabled Whether screen capture is disabled or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003919 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003920 */
Robin Lee25e26452015-06-02 09:56:29 -07003921 public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003922 throwIfParentInstance("setScreenCaptureDisabled");
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003923 if (mService != null) {
3924 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003925 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003926 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003927 throw e.rethrowFromSystemServer();
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003928 }
3929 }
3930 }
3931
3932 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08003933 * Determine whether or not screen capture has been disabled by the calling
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003934 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07003935 * @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 +01003936 * have disabled screen capture.
3937 */
Robin Lee25e26452015-06-02 09:56:29 -07003938 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003939 throwIfParentInstance("getScreenCaptureDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003940 return getScreenCaptureDisabled(admin, myUserId());
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003941 }
3942
3943 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003944 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003945 if (mService != null) {
3946 try {
3947 return mService.getScreenCaptureDisabled(admin, userHandle);
3948 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003949 throw e.rethrowFromSystemServer();
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003950 }
3951 }
3952 return false;
3953 }
3954
3955 /**
Jason Parks841cb0a2017-01-17 15:25:17 -06003956 * Called by a device or profile owner to set whether auto time is required. If auto time is
3957 * required, no user will be able set the date and time and network date and time will be used.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003958 * <p>
3959 * Note: if auto time is required the user can still manually set the time zone.
3960 * <p>
Jason Parks841cb0a2017-01-17 15:25:17 -06003961 * The calling device admin must be a device or profile owner. If it is not, a security
3962 * exception will be thrown.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003963 *
3964 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3965 * @param required Whether auto time is set required or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003966 * @throws SecurityException if {@code admin} is not a device owner.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003967 */
Robin Lee25e26452015-06-02 09:56:29 -07003968 public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003969 throwIfParentInstance("setAutoTimeRequired");
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003970 if (mService != null) {
3971 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003972 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003973 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003974 throw e.rethrowFromSystemServer();
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003975 }
3976 }
3977 }
3978
3979 /**
3980 * @return true if auto time is required.
3981 */
3982 public boolean getAutoTimeRequired() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003983 throwIfParentInstance("getAutoTimeRequired");
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003984 if (mService != null) {
3985 try {
3986 return mService.getAutoTimeRequired();
3987 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003988 throw e.rethrowFromSystemServer();
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003989 }
3990 }
3991 return false;
3992 }
3993
3994 /**
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003995 * Called by a device owner to set whether all users created on the device should be ephemeral.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003996 * <p>
3997 * The system user is exempt from this policy - it is never ephemeral.
3998 * <p>
3999 * The calling device admin must be the device owner. If it is not, a security exception will be
4000 * thrown.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004001 *
4002 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4003 * @param forceEphemeralUsers If true, all the existing users will be deleted and all
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004004 * subsequently created users will be ephemeral.
4005 * @throws SecurityException if {@code admin} is not a device owner.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004006 * @hide
4007 */
4008 public void setForceEphemeralUsers(
4009 @NonNull ComponentName admin, boolean forceEphemeralUsers) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004010 throwIfParentInstance("setForceEphemeralUsers");
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004011 if (mService != null) {
4012 try {
4013 mService.setForceEphemeralUsers(admin, forceEphemeralUsers);
4014 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004015 throw e.rethrowFromSystemServer();
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004016 }
4017 }
4018 }
4019
4020 /**
4021 * @return true if all users are created ephemeral.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004022 * @throws SecurityException if {@code admin} is not a device owner.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004023 * @hide
4024 */
4025 public boolean getForceEphemeralUsers(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004026 throwIfParentInstance("getForceEphemeralUsers");
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004027 if (mService != null) {
4028 try {
4029 return mService.getForceEphemeralUsers(admin);
4030 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004031 throw e.rethrowFromSystemServer();
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004032 }
4033 }
4034 return false;
4035 }
4036
4037 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07004038 * Called by an application that is administering the device to disable keyguard customizations,
4039 * such as widgets. After setting this, keyguard features will be disabled according to the
4040 * provided feature list.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004041 * <p>
4042 * The calling device admin must have requested
4043 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method;
4044 * if it has not, a security exception will be thrown.
4045 * <p>
4046 * Calling this from a managed profile before version {@link android.os.Build.VERSION_CODES#M}
4047 * will throw a security exception. From version {@link android.os.Build.VERSION_CODES#M} the
4048 * profile owner of a managed profile can set:
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00004049 * <ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00004050 * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which affects the parent user, but only if there
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004051 * is no separate challenge set on the managed profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00004052 * <li>{@link #KEYGUARD_DISABLE_FINGERPRINT} which affects the managed profile challenge if
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004053 * there is one, or the parent user otherwise.
4054 * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} which affects notifications generated
4055 * by applications in the managed profile.
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00004056 * </ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00004057 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} and {@link #KEYGUARD_DISABLE_FINGERPRINT} can also be
4058 * set on the {@link DevicePolicyManager} instance returned by
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004059 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
4060 * profile.
4061 * <p>
4062 * Requests to disable other features on a managed profile will be ignored.
4063 * <p>
4064 * The admin can check which features have been disabled by calling
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00004065 * {@link #getKeyguardDisabledFeatures(ComponentName)}
Amith Yamasani242f4b12014-10-14 16:06:13 -07004066 *
Jim Millerb8ec4702012-08-31 17:19:10 -07004067 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07004068 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004069 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
4070 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS},
4071 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
4072 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS},
4073 * {@link #KEYGUARD_DISABLE_FINGERPRINT}, {@link #KEYGUARD_DISABLE_FEATURES_ALL}
4074 * @throws SecurityException if {@code admin} is not an active administrator or does not user
4075 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES}
Jim Millerb8ec4702012-08-31 17:19:10 -07004076 */
Robin Lee25e26452015-06-02 09:56:29 -07004077 public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07004078 if (mService != null) {
4079 try {
Esteban Talavera62399912016-01-11 15:37:55 +00004080 mService.setKeyguardDisabledFeatures(admin, which, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07004081 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004082 throw e.rethrowFromSystemServer();
Jim Millerb8ec4702012-08-31 17:19:10 -07004083 }
4084 }
4085 }
4086
4087 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004088 * Determine whether or not features have been disabled in keyguard either by the calling
Rubin Xud3609d42016-07-13 18:32:57 +01004089 * admin, if specified, or all admins that set restrictions on this user and its participating
Esteban Talaverac1c83592016-02-17 17:56:15 +00004090 * profiles. Restrictions on profiles that have a separate challenge are not taken into account.
4091 *
4092 * <p>This method can be called on the {@link DevicePolicyManager} instance
4093 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
4094 * restrictions on the parent profile.
4095 *
Esteban Talavera62399912016-01-11 15:37:55 +00004096 * @param admin The name of the admin component to check, or {@code null} to check whether any
4097 * admins have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07004098 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
4099 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07004100 */
Robin Lee25e26452015-06-02 09:56:29 -07004101 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004102 return getKeyguardDisabledFeatures(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004103 }
4104
4105 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07004106 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07004107 if (mService != null) {
4108 try {
Esteban Talavera62399912016-01-11 15:37:55 +00004109 return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07004110 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004111 throw e.rethrowFromSystemServer();
Jim Millerb8ec4702012-08-31 17:19:10 -07004112 }
4113 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07004114 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07004115 }
4116
4117 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08004118 * @hide
4119 */
Robin Lee25e26452015-06-02 09:56:29 -07004120 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
4121 int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08004122 if (mService != null) {
4123 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01004124 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08004125 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004126 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08004127 }
4128 }
4129 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07004130
Dianne Hackbornd6847842010-01-12 18:14:19 -08004131 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01004132 * @hide
4133 */
Robin Lee25e26452015-06-02 09:56:29 -07004134 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004135 setActiveAdmin(policyReceiver, refreshing, myUserId());
Jessica Hummel6d36b602014-04-04 12:42:17 +01004136 }
4137
4138 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08004139 * @hide
4140 */
Robin Lee25e26452015-06-02 09:56:29 -07004141 public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08004142 if (mService != null) {
4143 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004144 mService.getRemoveWarning(admin, result, myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08004145 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004146 throw e.rethrowFromSystemServer();
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08004147 }
4148 }
4149 }
4150
4151 /**
4152 * @hide
4153 */
Andrew Scull5f9e6f32016-08-02 14:22:17 +01004154 public void setActivePasswordState(PasswordMetrics metrics, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08004155 if (mService != null) {
4156 try {
Andrew Scull5f9e6f32016-08-02 14:22:17 +01004157 mService.setActivePasswordState(metrics, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08004158 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004159 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08004160 }
4161 }
4162 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07004163
Dianne Hackbornd6847842010-01-12 18:14:19 -08004164 /**
4165 * @hide
4166 */
Andrew Scull5daf2732016-11-14 15:02:45 +00004167 public void reportPasswordChanged(@UserIdInt int userId) {
4168 if (mService != null) {
4169 try {
4170 mService.reportPasswordChanged(userId);
4171 } catch (RemoteException e) {
4172 throw e.rethrowFromSystemServer();
4173 }
4174 }
4175 }
4176
4177 /**
4178 * @hide
4179 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004180 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08004181 if (mService != null) {
4182 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004183 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08004184 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004185 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08004186 }
4187 }
4188 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07004189
Dianne Hackbornd6847842010-01-12 18:14:19 -08004190 /**
4191 * @hide
4192 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004193 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08004194 if (mService != null) {
4195 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004196 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08004197 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004198 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08004199 }
4200 }
4201 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07004202
4203 /**
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004204 * @hide
4205 */
4206 public void reportFailedFingerprintAttempt(int userHandle) {
4207 if (mService != null) {
4208 try {
4209 mService.reportFailedFingerprintAttempt(userHandle);
4210 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004211 throw e.rethrowFromSystemServer();
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004212 }
4213 }
4214 }
4215
4216 /**
4217 * @hide
4218 */
4219 public void reportSuccessfulFingerprintAttempt(int userHandle) {
4220 if (mService != null) {
4221 try {
4222 mService.reportSuccessfulFingerprintAttempt(userHandle);
4223 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004224 throw e.rethrowFromSystemServer();
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004225 }
4226 }
4227 }
4228
4229 /**
Michal Karpinski31502d32016-01-25 16:43:07 +00004230 * Should be called when keyguard has been dismissed.
4231 * @hide
4232 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004233 public void reportKeyguardDismissed(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00004234 if (mService != null) {
4235 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004236 mService.reportKeyguardDismissed(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00004237 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004238 throw e.rethrowFromSystemServer();
Michal Karpinski31502d32016-01-25 16:43:07 +00004239 }
4240 }
4241 }
4242
4243 /**
4244 * Should be called when keyguard view has been shown to the user.
4245 * @hide
4246 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004247 public void reportKeyguardSecured(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00004248 if (mService != null) {
4249 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004250 mService.reportKeyguardSecured(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00004251 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004252 throw e.rethrowFromSystemServer();
Michal Karpinski31502d32016-01-25 16:43:07 +00004253 }
4254 }
4255 }
4256
4257 /**
Amith Yamasani71e6c692013-03-24 17:39:28 -07004258 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00004259 * Sets the given package as the device owner.
Makoto Onukia52562c2015-10-01 16:12:31 -07004260 * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name.
4261 * @param who the component name to be registered as device owner.
Amith Yamasani71e6c692013-03-24 17:39:28 -07004262 * @return whether the package was successfully registered as the device owner.
4263 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00004264 * @throws IllegalStateException If the preconditions mentioned are not met.
Amith Yamasani71e6c692013-03-24 17:39:28 -07004265 */
Makoto Onukia52562c2015-10-01 16:12:31 -07004266 public boolean setDeviceOwner(ComponentName who) {
4267 return setDeviceOwner(who, null);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004268 }
4269
4270 /**
4271 * @hide
Makoto Onuki58b684f2015-09-04 10:48:16 -07004272 */
Makoto Onukia52562c2015-10-01 16:12:31 -07004273 public boolean setDeviceOwner(ComponentName who, int userId) {
4274 return setDeviceOwner(who, null, userId);
Makoto Onuki58b684f2015-09-04 10:48:16 -07004275 }
4276
4277 /**
4278 * @hide
4279 */
Makoto Onukia52562c2015-10-01 16:12:31 -07004280 public boolean setDeviceOwner(ComponentName who, String ownerName) {
4281 return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM);
Makoto Onuki58b684f2015-09-04 10:48:16 -07004282 }
4283
4284 /**
4285 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00004286 * Sets the given package as the device owner. The package must already be installed. There
4287 * must not already be a device owner.
4288 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
4289 * this method.
4290 * Calling this after the setup phase of the primary user has completed is allowed only if
4291 * the caller is the shell uid, and there are no additional users and no accounts.
Makoto Onukia52562c2015-10-01 16:12:31 -07004292 * @param who the component name to be registered as device owner.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004293 * @param ownerName the human readable name of the institution that owns this device.
Makoto Onuki58b684f2015-09-04 10:48:16 -07004294 * @param userId ID of the user on which the device owner runs.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004295 * @return whether the package was successfully registered as the device owner.
4296 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00004297 * @throws IllegalStateException If the preconditions mentioned are not met.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004298 */
Makoto Onukia52562c2015-10-01 16:12:31 -07004299 public boolean setDeviceOwner(ComponentName who, String ownerName, int userId)
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004300 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07004301 if (mService != null) {
4302 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07004303 return mService.setDeviceOwner(who, ownerName, userId);
Amith Yamasani71e6c692013-03-24 17:39:28 -07004304 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004305 throw re.rethrowFromSystemServer();
Amith Yamasani71e6c692013-03-24 17:39:28 -07004306 }
4307 }
4308 return false;
4309 }
4310
4311 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004312 * Used to determine if a particular package has been registered as a Device Owner app.
4313 * A device owner app is a special device admin that cannot be deactivated by the user, once
Robin Lee25e26452015-06-02 09:56:29 -07004314 * activated as a device admin. It also cannot be uninstalled. To check whether a particular
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004315 * package is currently registered as the device owner app, pass in the package name from
4316 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
Robin Lee25e26452015-06-02 09:56:29 -07004317 * admin apps that want to check whether they are also registered as the device owner app. The
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004318 * exact mechanism by which a device admin app is registered as a device owner app is defined by
4319 * the setup process.
4320 * @param packageName the package name of the app, to compare with the registered device owner
4321 * app, if any.
Makoto Onukic8a5a552015-11-19 14:29:12 -08004322 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07004323 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004324 public boolean isDeviceOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004325 throwIfParentInstance("isDeviceOwnerApp");
Makoto Onukic8a5a552015-11-19 14:29:12 -08004326 return isDeviceOwnerAppOnCallingUser(packageName);
4327 }
4328
4329 /**
4330 * @return true if a package is registered as device owner, only when it's running on the
4331 * calling user.
4332 *
4333 * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity.
4334 * @hide
4335 */
4336 public boolean isDeviceOwnerAppOnCallingUser(String packageName) {
4337 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true);
4338 }
4339
4340 /**
4341 * @return true if a package is registered as device owner, even if it's running on a different
4342 * user.
4343 *
4344 * <p>Requires the MANAGE_USERS permission.
4345 *
4346 * @hide
4347 */
4348 public boolean isDeviceOwnerAppOnAnyUser(String packageName) {
4349 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false);
4350 }
4351
4352 /**
4353 * @return device owner component name, only when it's running on the calling user.
4354 *
4355 * @hide
4356 */
4357 public ComponentName getDeviceOwnerComponentOnCallingUser() {
4358 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true);
4359 }
4360
4361 /**
4362 * @return device owner component name, even if it's running on a different user.
4363 *
4364 * <p>Requires the MANAGE_USERS permission.
4365 *
4366 * @hide
4367 */
Polina Bondarenko23561db2016-12-16 11:47:28 +01004368 @SystemApi
Makoto Onukic8a5a552015-11-19 14:29:12 -08004369 public ComponentName getDeviceOwnerComponentOnAnyUser() {
4370 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false);
4371 }
4372
4373 private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) {
Makoto Onuki70f929e2015-11-11 12:40:15 -08004374 if (packageName == null) {
4375 return false;
Amith Yamasani71e6c692013-03-24 17:39:28 -07004376 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08004377 final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly);
Makoto Onuki70f929e2015-11-11 12:40:15 -08004378 if (deviceOwner == null) {
4379 return false;
4380 }
4381 return packageName.equals(deviceOwner.getPackageName());
Amith Yamasani71e6c692013-03-24 17:39:28 -07004382 }
4383
Makoto Onukic8a5a552015-11-19 14:29:12 -08004384 private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) {
4385 if (mService != null) {
4386 try {
4387 return mService.getDeviceOwnerComponent(callingUserOnly);
4388 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004389 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08004390 }
4391 }
4392 return null;
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004393 }
4394
Jason Monkb0dced82014-06-06 14:36:20 -04004395 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08004396 * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's
4397 * no device owner.
4398 *
4399 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07004400 *
4401 * @hide
4402 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08004403 public int getDeviceOwnerUserId() {
4404 if (mService != null) {
4405 try {
4406 return mService.getDeviceOwnerUserId();
4407 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004408 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08004409 }
4410 }
4411 return UserHandle.USER_NULL;
Makoto Onukia52562c2015-10-01 16:12:31 -07004412 }
4413
4414 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004415 * Clears the current device owner. The caller must be the device owner. This function should be
4416 * used cautiously as once it is called it cannot be undone. The device owner can only be set as
4417 * a part of device setup before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04004418 *
4419 * @param packageName The package name of the device owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004420 * @throws SecurityException if the caller is not in {@code packageName} or {@code packageName}
4421 * does not own the current device owner component.
Jason Monkb0dced82014-06-06 14:36:20 -04004422 */
Jason Monk94d2cf92014-06-18 09:53:34 -04004423 public void clearDeviceOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004424 throwIfParentInstance("clearDeviceOwnerApp");
Jason Monkb0dced82014-06-06 14:36:20 -04004425 if (mService != null) {
4426 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04004427 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04004428 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004429 throw re.rethrowFromSystemServer();
Jason Monkb0dced82014-06-06 14:36:20 -04004430 }
4431 }
4432 }
4433
Makoto Onukia52562c2015-10-01 16:12:31 -07004434 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08004435 * Returns the device owner package name, only if it's running on the calling user.
4436 *
4437 * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity.
Makoto Onukia52562c2015-10-01 16:12:31 -07004438 *
4439 * @hide
4440 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01004441 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004442 public @Nullable String getDeviceOwner() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004443 throwIfParentInstance("getDeviceOwner");
Makoto Onukic8a5a552015-11-19 14:29:12 -08004444 final ComponentName name = getDeviceOwnerComponentOnCallingUser();
4445 return name != null ? name.getPackageName() : null;
Makoto Onukia52562c2015-10-01 16:12:31 -07004446 }
4447
4448 /**
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004449 * Called by the system to find out whether the device is managed by a Device Owner.
Makoto Onukic8a5a552015-11-19 14:29:12 -08004450 *
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004451 * @return whether the device is managed by a Device Owner.
4452 * @throws SecurityException if the caller is not the device owner, does not hold the
4453 * MANAGE_USERS permission and is not the system.
Makoto Onukia52562c2015-10-01 16:12:31 -07004454 *
4455 * @hide
4456 */
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004457 @SystemApi
4458 @TestApi
Makoto Onukic8a5a552015-11-19 14:29:12 -08004459 public boolean isDeviceManaged() {
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004460 try {
4461 return mService.hasDeviceOwner();
4462 } catch (RemoteException re) {
4463 throw re.rethrowFromSystemServer();
4464 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08004465 }
4466
4467 /**
4468 * Returns the device owner name. Note this method *will* return the device owner
4469 * name when it's running on a different user.
4470 *
4471 * <p>Requires the MANAGE_USERS permission.
4472 *
4473 * @hide
4474 */
Makoto Onukia2b274b2016-01-19 13:26:02 -08004475 @SystemApi
Makoto Onukic8a5a552015-11-19 14:29:12 -08004476 public String getDeviceOwnerNameOnAnyUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004477 throwIfParentInstance("getDeviceOwnerNameOnAnyUser");
Amith Yamasani71e6c692013-03-24 17:39:28 -07004478 if (mService != null) {
4479 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07004480 return mService.getDeviceOwnerName();
Amith Yamasani71e6c692013-03-24 17:39:28 -07004481 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004482 throw re.rethrowFromSystemServer();
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004483 }
4484 }
4485 return null;
4486 }
Adam Connors776c5552014-01-09 10:42:56 +00004487
4488 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04004489 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004490 * @deprecated Do not use
4491 * @removed
Julia Reynolds20118f12015-02-11 12:34:08 -05004492 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004493 @Deprecated
Julia Reynolds20118f12015-02-11 12:34:08 -05004494 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004495 public @Nullable String getDeviceInitializerApp() {
Julia Reynolds20118f12015-02-11 12:34:08 -05004496 return null;
4497 }
4498
4499 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004500 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004501 * @deprecated Do not use
4502 * @removed
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004503 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004504 @Deprecated
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004505 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004506 public @Nullable ComponentName getDeviceInitializerComponent() {
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004507 return null;
4508 }
4509
Julia Reynolds20118f12015-02-11 12:34:08 -05004510 /**
Adam Connors776c5552014-01-09 10:42:56 +00004511 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004512 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304513 * Sets the given component as an active admin and registers the package as the profile
4514 * owner for this user. The package must already be installed and there shouldn't be
4515 * an existing profile owner registered for this user. Also, this method must be called
4516 * before the user setup has been completed.
4517 * <p>
4518 * This method can only be called by system apps that hold MANAGE_USERS permission and
4519 * MANAGE_DEVICE_ADMINS permission.
4520 * @param admin The component to register as an active admin and profile owner.
4521 * @param ownerName The user-visible name of the entity that is managing this user.
4522 * @return whether the admin was successfully registered as the profile owner.
4523 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
4524 * the user has already been set up.
4525 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07004526 @Deprecated
Justin Morey80440cc2014-07-24 09:16:35 -05004527 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07004528 public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304529 throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004530 throwIfParentInstance("setActiveProfileOwner");
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304531 if (mService != null) {
4532 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004533 final int myUserId = myUserId();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304534 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004535 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304536 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004537 throw re.rethrowFromSystemServer();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304538 }
4539 }
4540 return false;
4541 }
4542
4543 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004544 * Clears the active profile owner and removes all user restrictions. The caller must be from
4545 * the same package as the active profile owner for this user, otherwise a SecurityException
4546 * will be thrown.
4547 * <p>
4548 * This doesn't work for managed profile owners.
Makoto Onuki5bf68022016-01-27 13:49:19 -08004549 *
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004550 * @param admin The component to remove as the profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004551 * @throws SecurityException if {@code admin} is not an active profile owner.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004552 */
Robin Lee25e26452015-06-02 09:56:29 -07004553 public void clearProfileOwner(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004554 throwIfParentInstance("clearProfileOwner");
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004555 if (mService != null) {
4556 try {
4557 mService.clearProfileOwner(admin);
4558 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004559 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004560 }
4561 }
4562 }
4563
4564 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05004565 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07004566 * Checks whether the user was already setup.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004567 */
4568 public boolean hasUserSetupCompleted() {
4569 if (mService != null) {
4570 try {
4571 return mService.hasUserSetupCompleted();
4572 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004573 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004574 }
4575 }
4576 return true;
4577 }
4578
4579 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004580 * @hide
4581 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00004582 * already be installed. There must not already be a profile owner for this user.
4583 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
4584 * this method.
4585 * Calling this after the setup phase of the specified user has completed is allowed only if:
4586 * - the caller is SYSTEM_UID.
4587 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004588 * @param admin the component name to be registered as profile owner.
4589 * @param ownerName the human readable name of the organisation associated with this DPM.
4590 * @param userHandle the userId to set the profile owner for.
4591 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00004592 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
4593 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004594 */
Robin Lee25e26452015-06-02 09:56:29 -07004595 public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName,
Robin Leeddd553f2015-04-30 14:18:22 +01004596 int userHandle) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00004597 if (mService != null) {
4598 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004599 if (ownerName == null) {
4600 ownerName = "";
4601 }
4602 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00004603 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004604 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004605 }
4606 }
4607 return false;
4608 }
4609
4610 /**
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004611 * Sets the device owner information to be shown on the lock screen.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004612 * <p>
4613 * If the device owner information is {@code null} or empty then the device owner info is
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004614 * cleared and the user owner info is shown on the lock screen if it is set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004615 * <p>
4616 * If the device owner information contains only whitespaces then the message on the lock screen
4617 * will be blank and the user will not be allowed to change it.
4618 * <p>
4619 * If the device owner information needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00004620 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
4621 * and set a new version of this string accordingly.
4622 *
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004623 * @param admin The name of the admin component to check.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004624 * @param info Device owner information which will be displayed instead of the user owner info.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004625 * @throws SecurityException if {@code admin} is not a device owner.
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004626 */
Andrei Stingaceanu16187902016-03-21 15:44:45 +00004627 public void setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, CharSequence info) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004628 throwIfParentInstance("setDeviceOwnerLockScreenInfo");
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004629 if (mService != null) {
4630 try {
Andrei Stingaceanu16187902016-03-21 15:44:45 +00004631 mService.setDeviceOwnerLockScreenInfo(admin, info);
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004632 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004633 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004634 }
4635 }
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004636 }
4637
4638 /**
4639 * @return The device owner information. If it is not set returns {@code null}.
4640 */
Andrei Stingaceanu16187902016-03-21 15:44:45 +00004641 public CharSequence getDeviceOwnerLockScreenInfo() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004642 throwIfParentInstance("getDeviceOwnerLockScreenInfo");
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004643 if (mService != null) {
4644 try {
4645 return mService.getDeviceOwnerLockScreenInfo();
4646 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004647 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004648 }
4649 }
4650 return null;
4651 }
4652
4653 /**
Edman Anjos52088e42017-01-13 22:26:17 +01004654 * Called by device or profile owners to suspend packages for this user. This function can be
4655 * called by a device owner, profile owner, or by a delegate given the
4656 * {@link #DELEGATION_PACKAGE_ACCESS} scope via {@link #setDelegatedScopes}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004657 * <p>
4658 * A suspended package will not be able to start activities. Its notifications will be hidden,
4659 * it will not show up in recents, will not be able to show toasts or dialogs or ring the
4660 * device.
4661 * <p>
4662 * The package must already be installed. If the package is uninstalled while suspended the
4663 * package will no longer be suspended. The admin can block this by using
Kenny Guy871f3eb2016-03-09 20:06:16 +00004664 * {@link #setUninstallBlocked}.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004665 *
Edman Anjos52088e42017-01-13 22:26:17 +01004666 * @param admin The name of the admin component to check, or {@code null} if the caller is a
4667 * package access delegate.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004668 * @param packageNames The package names to suspend or unsuspend.
4669 * @param suspended If set to {@code true} than the packages will be suspended, if set to
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004670 * {@code false} the packages will be unsuspended.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004671 * @return an array of package names for which the suspended status is not set as requested in
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004672 * this method.
4673 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01004674 * @see #setDelegatedScopes
4675 * @see #DELEGATION_PACKAGE_ACCESS
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004676 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004677 public @NonNull String[] setPackagesSuspended(@NonNull ComponentName admin,
4678 @NonNull String[] packageNames, boolean suspended) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004679 throwIfParentInstance("setPackagesSuspended");
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004680 if (mService != null) {
4681 try {
Edman Anjos52088e42017-01-13 22:26:17 +01004682 return mService.setPackagesSuspended(admin, mContext.getPackageName(), packageNames,
4683 suspended);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004684 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004685 throw re.rethrowFromSystemServer();
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004686 }
4687 }
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004688 return packageNames;
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004689 }
4690
4691 /**
Edman Anjos52088e42017-01-13 22:26:17 +01004692 * Determine if a package is suspended. This function can be called by a device owner, profile
4693 * owner, or by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via
4694 * {@link #setDelegatedScopes}.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004695 *
Edman Anjos52088e42017-01-13 22:26:17 +01004696 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
4697 * {@code null} if the caller is a package access delegate.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004698 * @param packageName The name of the package to retrieve the suspended status of.
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00004699 * @return {@code true} if the package is suspended or {@code false} if the package is not
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004700 * suspended, could not be found or an error occurred.
4701 * @throws SecurityException if {@code admin} is not a device or profile owner.
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004702 * @throws NameNotFoundException if the package could not be found.
Edman Anjos52088e42017-01-13 22:26:17 +01004703 * @see #setDelegatedScopes
4704 * @see #DELEGATION_PACKAGE_ACCESS
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004705 */
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004706 public boolean isPackageSuspended(@NonNull ComponentName admin, String packageName)
4707 throws NameNotFoundException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004708 throwIfParentInstance("isPackageSuspended");
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004709 if (mService != null) {
4710 try {
Edman Anjos52088e42017-01-13 22:26:17 +01004711 return mService.isPackageSuspended(admin, mContext.getPackageName(), packageName);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004712 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004713 throw e.rethrowFromSystemServer();
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004714 } catch (IllegalArgumentException ex) {
4715 throw new NameNotFoundException(packageName);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004716 }
4717 }
4718 return false;
4719 }
4720
4721 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004722 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
4723 * be used. Only the profile owner can call this.
4724 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01004725 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004726 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004727 * @throws SecurityException if {@code admin} is not a profile owner.
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004728 */
Robin Lee25e26452015-06-02 09:56:29 -07004729 public void setProfileEnabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004730 throwIfParentInstance("setProfileEnabled");
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004731 if (mService != null) {
4732 try {
4733 mService.setProfileEnabled(admin);
4734 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004735 throw e.rethrowFromSystemServer();
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004736 }
4737 }
4738 }
4739
4740 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004741 * Sets the name of the profile. In the device owner case it sets the name of the user which it
4742 * is called from. Only a profile owner or device owner can call this. If this is never called
4743 * by the profile or device owner, the name will be set to default values.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004744 *
4745 * @see #isProfileOwnerApp
4746 * @see #isDeviceOwnerApp
Robin Lee25e26452015-06-02 09:56:29 -07004747 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004748 * @param profileName The name of the profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004749 * @throws SecurityException if {@code admin} is not a device or profile owner.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004750 */
Robin Lee25e26452015-06-02 09:56:29 -07004751 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004752 throwIfParentInstance("setProfileName");
Jessica Hummel1333ea12014-06-23 11:20:10 +01004753 if (mService != null) {
4754 try {
Robin Lee25e26452015-06-02 09:56:29 -07004755 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07004756 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004757 throw e.rethrowFromSystemServer();
Fyodor Kupolov78f13142015-05-27 16:52:45 -07004758 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01004759 }
4760 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01004761
4762 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004763 * Used to determine if a particular package is registered as the profile owner for the
Makoto Onuki32b30572015-12-11 14:29:51 -08004764 * user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004765 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00004766 *
4767 * @param packageName The package name of the app to compare with the registered profile owner.
4768 * @return Whether or not the package is registered as the profile owner.
4769 */
4770 public boolean isProfileOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004771 throwIfParentInstance("isProfileOwnerApp");
Adam Connors776c5552014-01-09 10:42:56 +00004772 if (mService != null) {
4773 try {
Makoto Onuki90b89652016-01-28 14:44:18 -08004774 ComponentName profileOwner = mService.getProfileOwner(myUserId());
Nicolas Prevot90af6d72014-07-30 14:19:12 +01004775 return profileOwner != null
4776 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00004777 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004778 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004779 }
4780 }
4781 return false;
4782 }
4783
4784 /**
4785 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07004786 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00004787 * owner has been set for that user.
4788 * @throws IllegalArgumentException if the userId is invalid.
4789 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01004790 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004791 public @Nullable ComponentName getProfileOwner() throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004792 throwIfParentInstance("getProfileOwner");
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01004793 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
4794 }
4795
4796 /**
4797 * @see #getProfileOwner()
4798 * @hide
4799 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004800 public @Nullable ComponentName getProfileOwnerAsUser(final int userId)
4801 throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00004802 if (mService != null) {
4803 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01004804 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00004805 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004806 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004807 }
4808 }
4809 return null;
4810 }
4811
4812 /**
4813 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07004814 * @return the human readable name of the organisation associated with this DPM or {@code null}
4815 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00004816 * @throws IllegalArgumentException if the userId is invalid.
4817 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004818 public @Nullable String getProfileOwnerName() throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00004819 if (mService != null) {
4820 try {
4821 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
4822 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004823 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004824 }
4825 }
4826 return null;
4827 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004828
4829 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07004830 * @hide
Makoto Onukic8a5a552015-11-19 14:29:12 -08004831 * @param userId The user for whom to fetch the profile owner name, if any.
Amith Yamasani38f836b2014-08-20 14:51:15 -07004832 * @return the human readable name of the organisation associated with this profile owner or
4833 * null if one is not set.
4834 * @throws IllegalArgumentException if the userId is invalid.
4835 */
4836 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004837 public @Nullable String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004838 throwIfParentInstance("getProfileOwnerNameAsUser");
Amith Yamasani38f836b2014-08-20 14:51:15 -07004839 if (mService != null) {
4840 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02004841 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07004842 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004843 throw re.rethrowFromSystemServer();
Amith Yamasani38f836b2014-08-20 14:51:15 -07004844 }
4845 }
4846 return null;
4847 }
4848
4849 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004850 * Called by a profile owner or device owner to add a default intent handler activity for
4851 * intents that match a certain intent filter. This activity will remain the default intent
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004852 * handler even if the set of potential event handlers for the intent filter changes and if the
4853 * intent preferences are reset.
4854 * <p>
4855 * The default disambiguation mechanism takes over if the activity is not installed (anymore).
4856 * When the activity is (re)installed, it is automatically reset as default intent handler for
4857 * the filter.
4858 * <p>
4859 * The calling device admin must be a profile owner or device owner. If it is not, a security
4860 * exception will be thrown.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004861 *
4862 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4863 * @param filter The IntentFilter for which a default handler is added.
4864 * @param activity The Activity that is added as default intent handler.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004865 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004866 */
Robin Lee25e26452015-06-02 09:56:29 -07004867 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
4868 @NonNull ComponentName activity) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004869 throwIfParentInstance("addPersistentPreferredActivity");
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004870 if (mService != null) {
4871 try {
4872 mService.addPersistentPreferredActivity(admin, filter, activity);
4873 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004874 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004875 }
4876 }
4877 }
4878
4879 /**
4880 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00004881 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004882 * <p>
4883 * The calling device admin must be a profile owner. If it is not, a security exception will be
4884 * thrown.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004885 *
4886 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4887 * @param packageName The name of the package for which preferences are removed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004888 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004889 */
Robin Lee25e26452015-06-02 09:56:29 -07004890 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004891 String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004892 throwIfParentInstance("clearPackagePersistentPreferredActivities");
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004893 if (mService != null) {
4894 try {
4895 mService.clearPackagePersistentPreferredActivities(admin, packageName);
4896 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004897 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004898 }
4899 }
4900 }
Robin Lee66e5d962014-04-09 16:44:21 +01004901
4902 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00004903 * Called by a profile owner or device owner to grant permission to a package to manage
4904 * application restrictions for the calling user via {@link #setApplicationRestrictions} and
4905 * {@link #getApplicationRestrictions}.
4906 * <p>
4907 * This permission is persistent until it is later cleared by calling this method with a
4908 * {@code null} value or uninstalling the managing package.
Rubin Xuf03d0a62016-02-10 14:54:15 +00004909 * <p>
4910 * The supplied application restriction managing package must be installed when calling this
Victor Changcd14c0a2016-03-16 19:10:15 +00004911 * API, otherwise an {@link NameNotFoundException} will be thrown.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004912 *
4913 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4914 * @param packageName The package name which will be given access to application restrictions
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004915 * APIs. If {@code null} is given the current package will be cleared.
4916 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Changcd14c0a2016-03-16 19:10:15 +00004917 * @throws NameNotFoundException if {@code packageName} is not found
Edman Anjosf9946772016-11-28 16:35:15 +01004918 *
4919 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #setDelegatedScopes}
4920 * with the {@link #DELEGATION_APP_RESTRICTIONS} scope instead.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004921 */
Edman Anjosf9946772016-11-28 16:35:15 +01004922 @Deprecated
Esteban Talaverabf60f722015-12-10 16:26:44 +00004923 public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin,
Victor Changcd14c0a2016-03-16 19:10:15 +00004924 @Nullable String packageName) throws NameNotFoundException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004925 throwIfParentInstance("setApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00004926 if (mService != null) {
4927 try {
Victor Changcd14c0a2016-03-16 19:10:15 +00004928 if (!mService.setApplicationRestrictionsManagingPackage(admin, packageName)) {
4929 throw new NameNotFoundException(packageName);
4930 }
Esteban Talaverabf60f722015-12-10 16:26:44 +00004931 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004932 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00004933 }
4934 }
4935 }
4936
4937 /**
4938 * Called by a profile owner or device owner to retrieve the application restrictions managing
Edman Anjosf9946772016-11-28 16:35:15 +01004939 * package for the current user, or {@code null} if none is set. If there are multiple
4940 * delegates this function will return one of them.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004941 *
4942 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4943 * @return The package name allowed to manage application restrictions on the current user, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004944 * {@code null} if none is set.
4945 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01004946 *
4947 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatePackages}
4948 * with the {@link #DELEGATION_APP_RESTRICTIONS} scope instead.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004949 */
Edman Anjosf9946772016-11-28 16:35:15 +01004950 @Deprecated
4951 @Nullable
4952 public String getApplicationRestrictionsManagingPackage(
Makoto Onuki408e8e42016-10-25 12:10:27 -07004953 @NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004954 throwIfParentInstance("getApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00004955 if (mService != null) {
4956 try {
4957 return mService.getApplicationRestrictionsManagingPackage(admin);
4958 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004959 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00004960 }
4961 }
4962 return null;
4963 }
4964
4965 /**
Esteban Talavera96895ca2016-03-16 12:00:40 +00004966 * Called by any application to find out whether it has been granted permission via
4967 * {@link #setApplicationRestrictionsManagingPackage} to manage application restrictions
4968 * for the calling user.
4969 *
4970 * <p>This is done by comparing the calling Linux uid with the uid of the package specified by
4971 * that method.
Edman Anjosf9946772016-11-28 16:35:15 +01004972 *
4973 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatedScopes}
4974 * instead.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004975 */
Edman Anjosf9946772016-11-28 16:35:15 +01004976 @Deprecated
Esteban Talaverabf60f722015-12-10 16:26:44 +00004977 public boolean isCallerApplicationRestrictionsManagingPackage() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004978 throwIfParentInstance("isCallerApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00004979 if (mService != null) {
4980 try {
Edman Anjosf9946772016-11-28 16:35:15 +01004981 return mService.isCallerApplicationRestrictionsManagingPackage(
4982 mContext.getPackageName());
Esteban Talaverabf60f722015-12-10 16:26:44 +00004983 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004984 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00004985 }
4986 }
4987 return false;
4988 }
4989
4990 /**
4991 * Sets the application restrictions for a given target application running in the calling user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004992 * <p>
4993 * The caller must be a profile or device owner on that user, or the package allowed to manage
Edman Anjosf9946772016-11-28 16:35:15 +01004994 * application restrictions via {@link #setDelegatedScopes} with the
4995 * {@link #DELEGATION_APP_RESTRICTIONS} scope; otherwise a security exception will be thrown.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004996 * <p>
4997 * The provided {@link Bundle} consists of key-value pairs, where the types of values may be:
Esteban Talavera6b8e0642015-08-10 17:26:04 +01004998 * <ul>
4999 * <li>{@code boolean}
5000 * <li>{@code int}
5001 * <li>{@code String} or {@code String[]}
5002 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
5003 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005004 * <p>
5005 * If the restrictions are not available yet, but may be applied in the near future, the caller
5006 * can notify the target application of that by adding
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00005007 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005008 * <p>
5009 * The application restrictions are only made visible to the target application via
5010 * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or device
5011 * owner, and the application restrictions managing package via
Esteban Talaverabf60f722015-12-10 16:26:44 +00005012 * {@link #getApplicationRestrictions}.
Robin Lee66e5d962014-04-09 16:44:21 +01005013 *
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005014 * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
5015 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00005016 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005017 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01005018 * @param packageName The name of the package to update restricted settings for.
5019 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005020 * set of active restrictions.
5021 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01005022 * @see #setDelegatedScopes
5023 * @see #DELEGATION_APP_RESTRICTIONS
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00005024 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01005025 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005026 @WorkerThread
Esteban Talaverabf60f722015-12-10 16:26:44 +00005027 public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01005028 Bundle settings) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005029 throwIfParentInstance("setApplicationRestrictions");
Robin Lee66e5d962014-04-09 16:44:21 +01005030 if (mService != null) {
5031 try {
Edman Anjosf9946772016-11-28 16:35:15 +01005032 mService.setApplicationRestrictions(admin, mContext.getPackageName(), packageName,
5033 settings);
Robin Lee66e5d962014-04-09 16:44:21 +01005034 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005035 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01005036 }
5037 }
5038 }
5039
5040 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005041 * Sets a list of configuration features to enable for a TrustAgent component. This is meant to
5042 * be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all trust
5043 * agents but those enabled by this function call. If flag
Jim Millere303bf42014-08-26 17:12:29 -07005044 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005045 * <p>
5046 * The calling device admin must have requested
5047 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method;
5048 * if not, a security exception will be thrown.
Tony Mak089d8402016-04-05 17:42:55 +01005049 * <p>
5050 * This method can be called on the {@link DevicePolicyManager} instance returned by
5051 * {@link #getParentProfileInstance(ComponentName)} in order to set the configuration for
5052 * the parent profile.
Jim Miller604e7552014-07-18 19:00:02 -07005053 *
5054 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07005055 * @param target Component name of the agent to be enabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005056 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent will be
5057 * strictly disabled according to the state of the
5058 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
5059 * <p>
5060 * If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all
5061 * admins, then it's up to the TrustAgent itself to aggregate the values from all
5062 * device admins.
5063 * <p>
5064 * Consult documentation for the specific TrustAgent to determine legal options
5065 * parameters.
5066 * @throws SecurityException if {@code admin} is not an active administrator or does not use
5067 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES}
Jim Miller604e7552014-07-18 19:00:02 -07005068 */
Robin Lee25e26452015-06-02 09:56:29 -07005069 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
5070 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07005071 if (mService != null) {
5072 try {
Tony Mak089d8402016-04-05 17:42:55 +01005073 mService.setTrustAgentConfiguration(admin, target, configuration, mParentInstance);
Jim Miller604e7552014-07-18 19:00:02 -07005074 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005075 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07005076 }
5077 }
5078 }
5079
5080 /**
Jim Millere303bf42014-08-26 17:12:29 -07005081 * Gets configuration for the given trust agent based on aggregating all calls to
5082 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
5083 * all device admins.
Tony Mak089d8402016-04-05 17:42:55 +01005084 * <p>
5085 * This method can be called on the {@link DevicePolicyManager} instance returned by
5086 * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the configuration set
5087 * on the parent profile.
Jim Miller604e7552014-07-18 19:00:02 -07005088 *
Jim Millerb5db57a2015-01-14 18:17:19 -08005089 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
5090 * this function returns a list of configurations for all admins that declare
5091 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
5092 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
5093 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
5094 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07005095 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07005096 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07005097 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005098 public @Nullable List<PersistableBundle> getTrustAgentConfiguration(
5099 @Nullable ComponentName admin, @NonNull ComponentName agent) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07005100 return getTrustAgentConfiguration(admin, agent, myUserId());
Jim Millere303bf42014-08-26 17:12:29 -07005101 }
5102
5103 /** @hide per-user version */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005104 public @Nullable List<PersistableBundle> getTrustAgentConfiguration(
5105 @Nullable ComponentName admin, @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07005106 if (mService != null) {
5107 try {
Tony Mak089d8402016-04-05 17:42:55 +01005108 return mService.getTrustAgentConfiguration(admin, agent, userHandle,
5109 mParentInstance);
Jim Miller604e7552014-07-18 19:00:02 -07005110 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005111 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07005112 }
5113 }
Jim Millere303bf42014-08-26 17:12:29 -07005114 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07005115 }
5116
5117 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005118 * Called by a profile owner of a managed profile to set whether caller-Id information from the
5119 * managed profile will be shown in the parent profile, for incoming calls.
5120 * <p>
5121 * The calling device admin must be a profile owner. If it is not, a security exception will be
5122 * thrown.
Adam Connors210fe212014-07-17 15:41:43 +01005123 *
Robin Lee25e26452015-06-02 09:56:29 -07005124 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01005125 * @param disabled If true caller-Id information in the managed profile is not displayed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005126 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors210fe212014-07-17 15:41:43 +01005127 */
Robin Lee25e26452015-06-02 09:56:29 -07005128 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005129 throwIfParentInstance("setCrossProfileCallerIdDisabled");
Adam Connors210fe212014-07-17 15:41:43 +01005130 if (mService != null) {
5131 try {
Robin Lee25e26452015-06-02 09:56:29 -07005132 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01005133 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005134 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01005135 }
5136 }
5137 }
5138
5139 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005140 * Called by a profile owner of a managed profile to determine whether or not caller-Id
5141 * information has been disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005142 * <p>
5143 * The calling device admin must be a profile owner. If it is not, a security exception will be
5144 * thrown.
Adam Connors210fe212014-07-17 15:41:43 +01005145 *
Robin Lee25e26452015-06-02 09:56:29 -07005146 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005147 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors210fe212014-07-17 15:41:43 +01005148 */
Robin Lee25e26452015-06-02 09:56:29 -07005149 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005150 throwIfParentInstance("getCrossProfileCallerIdDisabled");
Adam Connors210fe212014-07-17 15:41:43 +01005151 if (mService != null) {
5152 try {
Robin Lee25e26452015-06-02 09:56:29 -07005153 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01005154 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005155 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01005156 }
5157 }
5158 return false;
5159 }
5160
5161 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07005162 * Determine whether or not caller-Id information has been disabled.
5163 *
5164 * @param userHandle The user for whom to check the caller-id permission
5165 * @hide
5166 */
5167 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
5168 if (mService != null) {
5169 try {
5170 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
5171 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005172 throw e.rethrowFromSystemServer();
Amith Yamasani570002f2014-07-18 15:48:54 -07005173 }
5174 }
5175 return false;
5176 }
5177
5178 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005179 * Called by a profile owner of a managed profile to set whether contacts search from the
5180 * managed profile will be shown in the parent profile, for incoming calls.
5181 * <p>
5182 * The calling device admin must be a profile owner. If it is not, a security exception will be
5183 * thrown.
Victor Chang1060c6182016-01-04 20:16:23 +00005184 *
5185 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5186 * @param disabled If true contacts search in the managed profile is not displayed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005187 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Chang1060c6182016-01-04 20:16:23 +00005188 */
5189 public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin,
5190 boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005191 throwIfParentInstance("setCrossProfileContactsSearchDisabled");
Victor Chang1060c6182016-01-04 20:16:23 +00005192 if (mService != null) {
5193 try {
5194 mService.setCrossProfileContactsSearchDisabled(admin, disabled);
5195 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005196 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00005197 }
5198 }
5199 }
5200
5201 /**
5202 * Called by a profile owner of a managed profile to determine whether or not contacts search
5203 * has been disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005204 * <p>
5205 * The calling device admin must be a profile owner. If it is not, a security exception will be
5206 * thrown.
Victor Chang1060c6182016-01-04 20:16:23 +00005207 *
5208 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005209 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Chang1060c6182016-01-04 20:16:23 +00005210 */
5211 public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005212 throwIfParentInstance("getCrossProfileContactsSearchDisabled");
Victor Chang1060c6182016-01-04 20:16:23 +00005213 if (mService != null) {
5214 try {
5215 return mService.getCrossProfileContactsSearchDisabled(admin);
5216 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005217 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00005218 }
5219 }
5220 return false;
5221 }
5222
5223
5224 /**
5225 * Determine whether or not contacts search has been disabled.
5226 *
5227 * @param userHandle The user for whom to check the contacts search permission
5228 * @hide
5229 */
5230 public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) {
5231 if (mService != null) {
5232 try {
5233 return mService
5234 .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier());
5235 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005236 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00005237 }
5238 }
5239 return false;
5240 }
5241
5242 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005243 * Start Quick Contact on the managed profile for the user, if the policy allows.
Victor Chang97bdacc2016-01-21 22:24:11 +00005244 *
Makoto Onuki1040da12015-03-19 11:24:00 -07005245 * @hide
5246 */
5247 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
Victor Chang97bdacc2016-01-21 22:24:11 +00005248 boolean isContactIdIgnored, long directoryId, Intent originalIntent) {
Makoto Onuki1040da12015-03-19 11:24:00 -07005249 if (mService != null) {
5250 try {
Victor Chang97bdacc2016-01-21 22:24:11 +00005251 mService.startManagedQuickContact(actualLookupKey, actualContactId,
5252 isContactIdIgnored, directoryId, originalIntent);
Makoto Onuki1040da12015-03-19 11:24:00 -07005253 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005254 throw e.rethrowFromSystemServer();
Makoto Onuki1040da12015-03-19 11:24:00 -07005255 }
5256 }
5257 }
5258
5259 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005260 * Start Quick Contact on the managed profile for the user, if the policy allows.
Ricky Wai494b95d2015-11-20 16:07:15 +00005261 * @hide
5262 */
5263 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
5264 Intent originalIntent) {
Victor Chang97bdacc2016-01-21 22:24:11 +00005265 startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT,
Ricky Wai494b95d2015-11-20 16:07:15 +00005266 originalIntent);
5267 }
5268
5269 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005270 * Called by a profile owner of a managed profile to set whether bluetooth devices can access
5271 * enterprise contacts.
Ricky Wai778ba132015-03-31 14:21:22 +01005272 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005273 * The calling device admin must be a profile owner. If it is not, a security exception will be
5274 * thrown.
Ricky Wai778ba132015-03-31 14:21:22 +01005275 * <p>
5276 * This API works on managed profile only.
5277 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005278 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5279 * @param disabled If true, bluetooth devices cannot access enterprise contacts.
5280 * @throws SecurityException if {@code admin} is not a device or profile owner.
Ricky Wai778ba132015-03-31 14:21:22 +01005281 */
Robin Lee25e26452015-06-02 09:56:29 -07005282 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005283 throwIfParentInstance("setBluetoothContactSharingDisabled");
Ricky Wai778ba132015-03-31 14:21:22 +01005284 if (mService != null) {
5285 try {
Robin Lee25e26452015-06-02 09:56:29 -07005286 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01005287 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005288 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01005289 }
5290 }
5291 }
5292
5293 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005294 * Called by a profile owner of a managed profile to determine whether or not Bluetooth devices
5295 * cannot access enterprise contacts.
Ricky Wai778ba132015-03-31 14:21:22 +01005296 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005297 * The calling device admin must be a profile owner. If it is not, a security exception will be
5298 * thrown.
Ricky Wai778ba132015-03-31 14:21:22 +01005299 * <p>
5300 * This API works on managed profile only.
5301 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005302 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5303 * @throws SecurityException if {@code admin} is not a device or profile owner.
Ricky Wai778ba132015-03-31 14:21:22 +01005304 */
Robin Lee25e26452015-06-02 09:56:29 -07005305 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005306 throwIfParentInstance("getBluetoothContactSharingDisabled");
Ricky Wai778ba132015-03-31 14:21:22 +01005307 if (mService != null) {
5308 try {
Robin Lee25e26452015-06-02 09:56:29 -07005309 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01005310 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005311 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01005312 }
5313 }
5314 return true;
5315 }
5316
5317 /**
5318 * Determine whether or not Bluetooth devices cannot access contacts.
5319 * <p>
5320 * This API works on managed profile UserHandle only.
5321 *
5322 * @param userHandle The user for whom to check the caller-id permission
5323 * @hide
5324 */
5325 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
5326 if (mService != null) {
5327 try {
5328 return mService.getBluetoothContactSharingDisabledForUser(userHandle
5329 .getIdentifier());
5330 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005331 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01005332 }
5333 }
5334 return true;
5335 }
5336
5337 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005338 * Called by the profile owner of a managed profile so that some intents sent in the managed
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005339 * profile can also be resolved in the parent, or vice versa. Only activity intents are
5340 * supported.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00005341 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005342 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01005343 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005344 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01005345 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005346 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
5347 * @throws SecurityException if {@code admin} is not a device or profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005348 */
Robin Lee25e26452015-06-02 09:56:29 -07005349 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005350 throwIfParentInstance("addCrossProfileIntentFilter");
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005351 if (mService != null) {
5352 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01005353 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005354 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005355 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005356 }
5357 }
5358 }
5359
5360 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005361 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
5362 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01005363 * Only removes those that have been set by the profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005364 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005365 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005366 * @throws SecurityException if {@code admin} is not a device or profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005367 */
Robin Lee25e26452015-06-02 09:56:29 -07005368 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005369 throwIfParentInstance("clearCrossProfileIntentFilters");
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005370 if (mService != null) {
5371 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01005372 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005373 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005374 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005375 }
5376 }
5377 }
5378
5379 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005380 * Called by a profile or device owner to set the permitted accessibility services. When set by
5381 * a device owner or profile owner the restriction applies to all profiles of the user the
5382 * device owner or profile owner is an admin for. By default the user can use any accessiblity
5383 * service. When zero or more packages have been added, accessiblity services that are not in
5384 * the list and not part of the system can not be enabled by the user.
5385 * <p>
5386 * Calling with a null value for the list disables the restriction so that all services can be
5387 * used, calling with an empty list only allows the builtin system's services.
5388 * <p>
5389 * System accesibility services are always available to the user the list can't modify this.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005390 *
5391 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5392 * @param packageNames List of accessibility service package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005393 * @return true if setting the restriction succeeded. It fail if there is one or more non-system
5394 * accessibility services enabled, that are not in the list.
5395 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005396 */
Robin Lee25e26452015-06-02 09:56:29 -07005397 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005398 List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005399 throwIfParentInstance("setPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005400 if (mService != null) {
5401 try {
5402 return mService.setPermittedAccessibilityServices(admin, packageNames);
5403 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005404 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005405 }
5406 }
5407 return false;
5408 }
5409
5410 /**
5411 * Returns the list of permitted accessibility services set by this device or profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005412 * <p>
5413 * An empty list means no accessibility services except system services are allowed. Null means
5414 * all accessibility services are allowed.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005415 *
5416 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5417 * @return List of accessiblity service package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005418 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005419 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005420 public @Nullable List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005421 throwIfParentInstance("getPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005422 if (mService != null) {
5423 try {
5424 return mService.getPermittedAccessibilityServices(admin);
5425 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005426 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005427 }
5428 }
5429 return null;
5430 }
5431
5432 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00005433 * Called by the system to check if a specific accessibility service is disabled by admin.
5434 *
5435 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5436 * @param packageName Accessibility service package name that needs to be checked.
5437 * @param userHandle user id the admin is running as.
5438 * @return true if the accessibility service is permitted, otherwise false.
5439 *
5440 * @hide
5441 */
5442 public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin,
5443 @NonNull String packageName, int userHandle) {
5444 if (mService != null) {
5445 try {
5446 return mService.isAccessibilityServicePermittedByAdmin(admin, packageName,
5447 userHandle);
5448 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005449 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00005450 }
5451 }
5452 return false;
5453 }
5454
5455 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005456 * Returns the list of accessibility services permitted by the device or profiles
5457 * owners of this user.
5458 *
5459 * <p>Null means all accessibility services are allowed, if a non-null list is returned
5460 * it will contain the intersection of the permitted lists for any device or profile
5461 * owners that apply to this user. It will also include any system accessibility services.
5462 *
5463 * @param userId which user to check for.
5464 * @return List of accessiblity service package names.
5465 * @hide
5466 */
5467 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07005468 public @Nullable List<String> getPermittedAccessibilityServices(int userId) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005469 throwIfParentInstance("getPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005470 if (mService != null) {
5471 try {
5472 return mService.getPermittedAccessibilityServicesForUser(userId);
5473 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005474 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005475 }
5476 }
5477 return null;
5478 }
5479
5480 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005481 * Called by a profile or device owner to set the permitted input methods services. When set by
5482 * a device owner or profile owner the restriction applies to all profiles of the user the
5483 * device owner or profile owner is an admin for. By default the user can use any input method.
5484 * When zero or more packages have been added, input method that are not in the list and not
5485 * part of the system can not be enabled by the user. This method will fail if it is called for
5486 * a admin that is not for the foreground user or a profile of the foreground user.
5487 * <p>
5488 * Calling with a null value for the list disables the restriction so that all input methods can
5489 * be used, calling with an empty list disables all but the system's own input methods.
5490 * <p>
5491 * System input methods are always available to the user this method can't modify this.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005492 *
5493 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5494 * @param packageNames List of input method package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005495 * @return true if setting the restriction succeeded. It will fail if there are one or more
5496 * non-system input methods currently enabled that are not in the packageNames list.
5497 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005498 */
Robin Lee25e26452015-06-02 09:56:29 -07005499 public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005500 throwIfParentInstance("setPermittedInputMethods");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005501 if (mService != null) {
5502 try {
5503 return mService.setPermittedInputMethods(admin, packageNames);
5504 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005505 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005506 }
5507 }
5508 return false;
5509 }
5510
5511
5512 /**
5513 * Returns the list of permitted input methods set by this device or profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005514 * <p>
5515 * An empty list means no input methods except system input methods are allowed. Null means all
5516 * input methods are allowed.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005517 *
5518 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5519 * @return List of input method package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005520 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005521 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005522 public @Nullable List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005523 throwIfParentInstance("getPermittedInputMethods");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005524 if (mService != null) {
5525 try {
5526 return mService.getPermittedInputMethods(admin);
5527 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005528 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005529 }
5530 }
5531 return null;
5532 }
5533
5534 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00005535 * Called by the system to check if a specific input method is disabled by admin.
5536 *
5537 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5538 * @param packageName Input method package name that needs to be checked.
5539 * @param userHandle user id the admin is running as.
5540 * @return true if the input method is permitted, otherwise false.
5541 *
5542 * @hide
5543 */
5544 public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin,
5545 @NonNull String packageName, int userHandle) {
5546 if (mService != null) {
5547 try {
5548 return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle);
5549 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005550 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00005551 }
5552 }
5553 return false;
5554 }
5555
5556 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005557 * Returns the list of input methods permitted by the device or profiles
Makoto Onuki32b30572015-12-11 14:29:51 -08005558 * owners of the current user. (*Not* calling user, due to a limitation in InputMethodManager.)
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005559 *
5560 * <p>Null means all input methods are allowed, if a non-null list is returned
5561 * it will contain the intersection of the permitted lists for any device or profile
5562 * owners that apply to this user. It will also include any system input methods.
5563 *
5564 * @return List of input method package names.
5565 * @hide
5566 */
5567 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07005568 public @Nullable List<String> getPermittedInputMethodsForCurrentUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005569 throwIfParentInstance("getPermittedInputMethodsForCurrentUser");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005570 if (mService != null) {
5571 try {
5572 return mService.getPermittedInputMethodsForCurrentUser();
5573 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005574 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005575 }
5576 }
5577 return null;
5578 }
5579
5580 /**
Edman Anjos52088e42017-01-13 22:26:17 +01005581 * Get the list of apps to keep around as APKs even if no user has currently installed it. This
5582 * function can be called by a device owner or by a delegate given the
5583 * {@link #DELEGATION_KEEP_UNINSTALLED_PACKAGES} scope via {@link #setDelegatedScopes}.
5584 * <p>
5585 * Please note that packages returned in this method are not automatically pre-cached.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005586 *
Edman Anjos52088e42017-01-13 22:26:17 +01005587 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
5588 * {@code null} if the caller is a keep uninstalled packages delegate.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005589 * @return List of package names to keep cached.
Edman Anjos52088e42017-01-13 22:26:17 +01005590 * @see #setDelegatedScopes
5591 * @see #DELEGATION_KEEP_UNINSTALLED_PACKAGES
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005592 * @hide
5593 */
Edman Anjos52088e42017-01-13 22:26:17 +01005594 public @Nullable List<String> getKeepUninstalledPackages(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005595 throwIfParentInstance("getKeepUninstalledPackages");
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005596 if (mService != null) {
5597 try {
Edman Anjos52088e42017-01-13 22:26:17 +01005598 return mService.getKeepUninstalledPackages(admin, mContext.getPackageName());
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005599 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005600 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005601 }
5602 }
5603 return null;
5604 }
5605
5606 /**
Edman Anjos52088e42017-01-13 22:26:17 +01005607 * Set a list of apps to keep around as APKs even if no user has currently installed it. This
5608 * function can be called by a device owner or by a delegate given the
5609 * {@link #DELEGATION_KEEP_UNINSTALLED_PACKAGES} scope via {@link #setDelegatedScopes}.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005610 *
5611 * <p>Please note that setting this policy does not imply that specified apps will be
5612 * automatically pre-cached.</p>
5613 *
Edman Anjos52088e42017-01-13 22:26:17 +01005614 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
5615 * {@code null} if the caller is a keep uninstalled packages delegate.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005616 * @param packageNames List of package names to keep cached.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005617 * @throws SecurityException if {@code admin} is not a device owner.
Edman Anjos52088e42017-01-13 22:26:17 +01005618 * @see #setDelegatedScopes
5619 * @see #DELEGATION_KEEP_UNINSTALLED_PACKAGES
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005620 * @hide
5621 */
Edman Anjos52088e42017-01-13 22:26:17 +01005622 public void setKeepUninstalledPackages(@Nullable ComponentName admin,
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005623 @NonNull List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005624 throwIfParentInstance("setKeepUninstalledPackages");
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005625 if (mService != null) {
5626 try {
Edman Anjos52088e42017-01-13 22:26:17 +01005627 mService.setKeepUninstalledPackages(admin, mContext.getPackageName(), packageNames);
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005628 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005629 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005630 }
5631 }
5632 }
5633
5634 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04005635 * Called by a device owner to create a user with the specified name. The UserHandle returned
5636 * by this method should not be persisted as user handles are recycled as users are removed and
5637 * created. If you need to persist an identifier for this user, use
5638 * {@link UserManager#getSerialNumberForUser}.
5639 *
5640 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5641 * @param name the user's name
5642 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07005643 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
5644 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01005645 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005646 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01005647 * @removed From {@link android.os.Build.VERSION_CODES#N}
Julia Reynolds1e958392014-05-16 14:25:21 -04005648 */
Kenny Guy14f48e52015-06-29 15:12:36 +01005649 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07005650 public @Nullable UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04005651 return null;
5652 }
5653
5654 /**
Jason Monk03978a42014-06-10 15:05:30 -04005655 * Called by a device owner to create a user with the specified name. The UserHandle returned
5656 * by this method should not be persisted as user handles are recycled as users are removed and
5657 * created. If you need to persist an identifier for this user, use
5658 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
5659 * immediately.
5660 *
5661 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
5662 * as registered as an active admin on the new user. The profile owner package will be
5663 * installed on the new user if it already is installed on the device.
5664 *
5665 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
5666 * profileOwnerComponent when onEnable is called.
5667 *
5668 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5669 * @param name the user's name
5670 * @param ownerName the human readable name of the organisation associated with this DPM.
5671 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
5672 * the user.
5673 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
5674 * on the new user.
5675 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07005676 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
5677 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01005678 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005679 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01005680 * @removed From {@link android.os.Build.VERSION_CODES#N}
Jason Monk03978a42014-06-10 15:05:30 -04005681 */
Kenny Guy14f48e52015-06-29 15:12:36 +01005682 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07005683 public @Nullable UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
Robin Lee25e26452015-06-02 09:56:29 -07005684 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04005685 return null;
5686 }
5687
5688 /**
phweissa92e1212016-01-25 17:14:10 +01005689 * Flag used by {@link #createAndManageUser} to skip setup wizard after creating a new user.
phweiss343fb332016-01-25 14:48:59 +01005690 */
5691 public static final int SKIP_SETUP_WIZARD = 0x0001;
5692
5693 /**
Lenka Trochtovac8202c82016-01-26 15:11:09 +01005694 * Flag used by {@link #createAndManageUser} to specify that the user should be created
5695 * ephemeral.
5696 * @hide
5697 */
5698 public static final int MAKE_USER_EPHEMERAL = 0x0002;
5699
5700 /**
phweissa92e1212016-01-25 17:14:10 +01005701 * Called by a device owner to create a user with the specified name and a given component of
5702 * the calling package as profile owner. The UserHandle returned by this method should not be
5703 * persisted as user handles are recycled as users are removed and created. If you need to
5704 * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new
5705 * user will not be started in the background.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005706 * <p>
5707 * admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also a
5708 * DeviceAdminReceiver in the same package as admin, and will become the profile owner and will
5709 * be registered as an active admin on the new user. The profile owner package will be installed
5710 * on the new user.
5711 * <p>
5712 * If the adminExtras are not null, they will be stored on the device until the user is started
5713 * for the first time. Then the extras will be passed to the admin when onEnable is called.
phweiss343fb332016-01-25 14:48:59 +01005714 *
5715 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5716 * @param name The user's name.
phweissa92e1212016-01-25 17:14:10 +01005717 * @param profileOwner Which {@link DeviceAdminReceiver} will be profile owner. Has to be in the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005718 * same package as admin, otherwise no user is created and an
5719 * IllegalArgumentException is thrown.
phweiss343fb332016-01-25 14:48:59 +01005720 * @param adminExtras Extras that will be passed to onEnable of the admin receiver on the new
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005721 * user.
phweissa92e1212016-01-25 17:14:10 +01005722 * @param flags {@link #SKIP_SETUP_WIZARD} is supported.
phweiss343fb332016-01-25 14:48:59 +01005723 * @see UserHandle
5724 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
5725 * user could not be created.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005726 * @throws SecurityException if {@code admin} is not a device owner.
phweiss343fb332016-01-25 14:48:59 +01005727 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005728 public @Nullable UserHandle createAndManageUser(@NonNull ComponentName admin,
5729 @NonNull String name,
phweissa92e1212016-01-25 17:14:10 +01005730 @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras,
5731 int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005732 throwIfParentInstance("createAndManageUser");
phweiss343fb332016-01-25 14:48:59 +01005733 try {
phweissa92e1212016-01-25 17:14:10 +01005734 return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags);
phweiss343fb332016-01-25 14:48:59 +01005735 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005736 throw re.rethrowFromSystemServer();
phweiss343fb332016-01-25 14:48:59 +01005737 }
phweiss343fb332016-01-25 14:48:59 +01005738 }
5739
5740 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005741 * Called by a device owner to remove a user and all associated data. The primary user can not
5742 * be removed.
Julia Reynolds1e958392014-05-16 14:25:21 -04005743 *
5744 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5745 * @param userHandle the user to remove.
5746 * @return {@code true} if the user was removed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005747 * @throws SecurityException if {@code admin} is not a device owner.
Julia Reynolds1e958392014-05-16 14:25:21 -04005748 */
Robin Lee25e26452015-06-02 09:56:29 -07005749 public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005750 throwIfParentInstance("removeUser");
Julia Reynolds1e958392014-05-16 14:25:21 -04005751 try {
5752 return mService.removeUser(admin, userHandle);
5753 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005754 throw re.rethrowFromSystemServer();
Julia Reynolds1e958392014-05-16 14:25:21 -04005755 }
5756 }
5757
5758 /**
Jason Monk582d9112014-07-09 19:57:08 -04005759 * Called by a device owner to switch the specified user to the foreground.
5760 *
5761 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5762 * @param userHandle the user to switch to; null will switch to primary.
5763 * @return {@code true} if the switch was successful, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005764 * @throws SecurityException if {@code admin} is not a device owner.
Jason Monk582d9112014-07-09 19:57:08 -04005765 * @see Intent#ACTION_USER_FOREGROUND
5766 */
Robin Lee25e26452015-06-02 09:56:29 -07005767 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005768 throwIfParentInstance("switchUser");
Jason Monk582d9112014-07-09 19:57:08 -04005769 try {
5770 return mService.switchUser(admin, userHandle);
5771 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005772 throw re.rethrowFromSystemServer();
Jason Monk582d9112014-07-09 19:57:08 -04005773 }
5774 }
5775
5776 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00005777 * Retrieves the application restrictions for a given target application running in the calling
5778 * user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005779 * <p>
5780 * The caller must be a profile or device owner on that user, or the package allowed to manage
Edman Anjosf9946772016-11-28 16:35:15 +01005781 * application restrictions via {@link #setDelegatedScopes} with the
5782 * {@link #DELEGATION_APP_RESTRICTIONS} scope; otherwise a security exception will be thrown.
Robin Lee66e5d962014-04-09 16:44:21 +01005783 *
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005784 * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
5785 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00005786 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005787 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01005788 * @param packageName The name of the package to fetch restricted settings of.
5789 * @return {@link Bundle} of settings corresponding to what was set last time
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005790 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty
5791 * {@link Bundle} if no restrictions have been set.
5792 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01005793 * @see #setDelegatedScopes
5794 * @see #DELEGATION_APP_RESTRICTIONS
Robin Lee66e5d962014-04-09 16:44:21 +01005795 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005796 @WorkerThread
Makoto Onuki408e8e42016-10-25 12:10:27 -07005797 public @NonNull Bundle getApplicationRestrictions(
5798 @Nullable ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005799 throwIfParentInstance("getApplicationRestrictions");
Robin Lee66e5d962014-04-09 16:44:21 +01005800 if (mService != null) {
5801 try {
Edman Anjosf9946772016-11-28 16:35:15 +01005802 return mService.getApplicationRestrictions(admin, mContext.getPackageName(),
5803 packageName);
Robin Lee66e5d962014-04-09 16:44:21 +01005804 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005805 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01005806 }
5807 }
5808 return null;
5809 }
Amith Yamasanibe465322014-04-24 13:45:17 -07005810
5811 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05005812 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07005813 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005814 * The calling device admin must be a profile or device owner; if it is not, a security
5815 * exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07005816 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005817 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5818 * @param key The key of the restriction. See the constants in {@link android.os.UserManager}
5819 * for the list of keys.
5820 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanibe465322014-04-24 13:45:17 -07005821 */
Robin Lee25e26452015-06-02 09:56:29 -07005822 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005823 throwIfParentInstance("addUserRestriction");
Amith Yamasanibe465322014-04-24 13:45:17 -07005824 if (mService != null) {
5825 try {
5826 mService.setUserRestriction(admin, key, true);
5827 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005828 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07005829 }
5830 }
5831 }
5832
5833 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05005834 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07005835 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005836 * The calling device admin must be a profile or device owner; if it is not, a security
5837 * exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07005838 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005839 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5840 * @param key The key of the restriction. See the constants in {@link android.os.UserManager}
5841 * for the list of keys.
5842 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanibe465322014-04-24 13:45:17 -07005843 */
Robin Lee25e26452015-06-02 09:56:29 -07005844 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005845 throwIfParentInstance("clearUserRestriction");
Amith Yamasanibe465322014-04-24 13:45:17 -07005846 if (mService != null) {
5847 try {
5848 mService.setUserRestriction(admin, key, false);
5849 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005850 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07005851 }
5852 }
5853 }
Adam Connors010cfd42014-04-16 12:48:13 +01005854
5855 /**
Makoto Onuki3a3092f2015-10-30 11:07:51 -07005856 * Called by a profile or device owner to get user restrictions set with
5857 * {@link #addUserRestriction(ComponentName, String)}.
5858 * <p>
5859 * The target user may have more restrictions set by the system or other device owner / profile
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005860 * owner. To get all the user restrictions currently set, use
Makoto Onuki3a3092f2015-10-30 11:07:51 -07005861 * {@link UserManager#getUserRestrictions()}.
5862 *
5863 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005864 * @throws SecurityException if {@code admin} is not a device or profile owner.
Makoto Onuki3a3092f2015-10-30 11:07:51 -07005865 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005866 public @NonNull Bundle getUserRestrictions(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005867 throwIfParentInstance("getUserRestrictions");
Makoto Onuki3a3092f2015-10-30 11:07:51 -07005868 Bundle ret = null;
5869 if (mService != null) {
5870 try {
Sudheer Shanka549b9692016-03-30 17:12:07 -07005871 ret = mService.getUserRestrictions(admin);
5872 } catch (RemoteException e) {
5873 throw e.rethrowFromSystemServer();
5874 }
5875 }
5876 return ret == null ? new Bundle() : ret;
5877 }
5878
5879 /**
phweiss73145f42017-01-17 19:06:38 +01005880 * Called by any app to display a support dialog when a feature was disabled by an admin.
5881 * This returns an intent that can be used with {@link Context#startActivity(Intent)} to
5882 * display the dialog. It will tell the user that the feature indicated by {@code restriction}
5883 * was disabled by an admin, and include a link for more information. The default content of
5884 * the dialog can be changed by the restricting admin via
5885 * {@link #setShortSupportMessage(ComponentName, CharSequence)}. If the restriction is not
5886 * set (i.e. the feature is available), then the return value will be {@code null}.
5887 * @param restriction Indicates for which feature the dialog should be displayed. Can be a
5888 * user restriction from {@link UserManager}, e.g.
5889 * {@link UserManager#DISALLOW_ADJUST_VOLUME}, or one of the constants
5890 * {@link #POLICY_DISABLE_CAMERA} or {@link #POLICY_DISABLE_SCREEN_CAPTURE}.
5891 * @return Intent An intent to be used to start the dialog-activity if the restriction is
5892 * set by an admin, or null if the restriction does not exist or no admin set it.
5893 */
5894 public Intent createAdminSupportIntent(@NonNull String restriction) {
5895 throwIfParentInstance("createAdminSupportIntent");
5896 if (mService != null) {
5897 try {
5898 return mService.createAdminSupportIntent(restriction);
5899 } catch (RemoteException e) {
5900 throw e.rethrowFromSystemServer();
5901 }
5902 }
5903 return null;
5904 }
5905
5906 /**
Edman Anjos52088e42017-01-13 22:26:17 +01005907 * Hide or unhide packages. When a package is hidden it is unavailable for use, but the data and
5908 * actual package file remain. This function can be called by a device owner, profile owner, or
5909 * by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via
5910 * {@link #setDelegatedScopes}.
Julia Reynolds966881e2014-05-14 12:23:08 -04005911 *
Edman Anjos52088e42017-01-13 22:26:17 +01005912 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
5913 * {@code null} if the caller is a package access delegate.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005914 * @param packageName The name of the package to hide or unhide.
5915 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005916 * unhidden.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005917 * @return boolean Whether the hidden setting of the package was successfully updated.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005918 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01005919 * @see #setDelegatedScopes
5920 * @see #DELEGATION_PACKAGE_ACCESS
Julia Reynolds966881e2014-05-14 12:23:08 -04005921 */
Robin Lee25e26452015-06-02 09:56:29 -07005922 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005923 boolean hidden) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005924 throwIfParentInstance("setApplicationHidden");
Julia Reynolds966881e2014-05-14 12:23:08 -04005925 if (mService != null) {
5926 try {
Edman Anjos52088e42017-01-13 22:26:17 +01005927 return mService.setApplicationHidden(admin, mContext.getPackageName(), packageName,
5928 hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04005929 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005930 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04005931 }
5932 }
5933 return false;
5934 }
5935
5936 /**
Edman Anjos52088e42017-01-13 22:26:17 +01005937 * Determine if a package is hidden. This function can be called by a device owner, profile
5938 * owner, or by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via
5939 * {@link #setDelegatedScopes}.
Julia Reynolds966881e2014-05-14 12:23:08 -04005940 *
Edman Anjos52088e42017-01-13 22:26:17 +01005941 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
5942 * {@code null} if the caller is a package access delegate.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005943 * @param packageName The name of the package to retrieve the hidden status of.
5944 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005945 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01005946 * @see #setDelegatedScopes
5947 * @see #DELEGATION_PACKAGE_ACCESS
Julia Reynolds966881e2014-05-14 12:23:08 -04005948 */
Robin Lee25e26452015-06-02 09:56:29 -07005949 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005950 throwIfParentInstance("isApplicationHidden");
Julia Reynolds966881e2014-05-14 12:23:08 -04005951 if (mService != null) {
5952 try {
Edman Anjos52088e42017-01-13 22:26:17 +01005953 return mService.isApplicationHidden(admin, mContext.getPackageName(), packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04005954 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005955 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04005956 }
5957 }
5958 return false;
5959 }
5960
5961 /**
Edman Anjos52088e42017-01-13 22:26:17 +01005962 * Re-enable a system app that was disabled by default when the user was initialized. This
5963 * function can be called by a device owner, profile owner, or by a delegate given the
5964 * {@link #DELEGATION_ENABLE_SYSTEM_APP} scope via {@link #setDelegatedScopes}.
Adam Connors655be2a2014-07-14 09:01:25 +00005965 *
Edman Anjos52088e42017-01-13 22:26:17 +01005966 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
5967 * {@code null} if the caller is an enable system app delegate.
Makoto Onuki32b30572015-12-11 14:29:51 -08005968 * @param packageName The package to be re-enabled in the calling profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005969 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01005970 * @see #setDelegatedScopes
5971 * @see #DELEGATION_PACKAGE_ACCESS
Adam Connors655be2a2014-07-14 09:01:25 +00005972 */
Robin Lee25e26452015-06-02 09:56:29 -07005973 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005974 throwIfParentInstance("enableSystemApp");
Adam Connors655be2a2014-07-14 09:01:25 +00005975 if (mService != null) {
5976 try {
Edman Anjos52088e42017-01-13 22:26:17 +01005977 mService.enableSystemApp(admin, mContext.getPackageName(), packageName);
Adam Connors655be2a2014-07-14 09:01:25 +00005978 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005979 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00005980 }
5981 }
5982 }
5983
5984 /**
Edman Anjos52088e42017-01-13 22:26:17 +01005985 * Re-enable system apps by intent that were disabled by default when the user was initialized.
5986 * This function can be called by a device owner, profile owner, or by a delegate given the
5987 * {@link #DELEGATION_ENABLE_SYSTEM_APP} scope via {@link #setDelegatedScopes}.
Adam Connors655be2a2014-07-14 09:01:25 +00005988 *
Edman Anjos52088e42017-01-13 22:26:17 +01005989 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
5990 * {@code null} if the caller is an enable system app delegate.
Adam Connors655be2a2014-07-14 09:01:25 +00005991 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005992 * intent will be re-enabled in the calling profile.
Adam Connors655be2a2014-07-14 09:01:25 +00005993 * @return int The number of activities that matched the intent and were installed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005994 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01005995 * @see #setDelegatedScopes
5996 * @see #DELEGATION_PACKAGE_ACCESS
Adam Connors655be2a2014-07-14 09:01:25 +00005997 */
Robin Lee25e26452015-06-02 09:56:29 -07005998 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005999 throwIfParentInstance("enableSystemApp");
Adam Connors655be2a2014-07-14 09:01:25 +00006000 if (mService != null) {
6001 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006002 return mService.enableSystemAppWithIntent(admin, mContext.getPackageName(), intent);
Adam Connors655be2a2014-07-14 09:01:25 +00006003 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006004 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00006005 }
6006 }
6007 return 0;
6008 }
6009
6010 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00006011 * Called by a device owner or profile owner to disable account management for a specific type
6012 * of account.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006013 * <p>
6014 * The calling device admin must be a device owner or profile owner. If it is not, a security
6015 * exception will be thrown.
6016 * <p>
6017 * When account management is disabled for an account type, adding or removing an account of
6018 * that type will not be possible.
6019 * <p>
6020 * From {@link android.os.Build.VERSION_CODES#N} the profile or device owner can still use
Benjamin Franzb6c0ce42015-11-05 10:06:51 +00006021 * {@link android.accounts.AccountManager} APIs to add or remove accounts when account
6022 * management for a specific type is disabled.
6023 *
Sander Alewijnse650c3342014-05-08 18:00:50 +01006024 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6025 * @param accountType For which account management is disabled or enabled.
6026 * @param disabled The boolean indicating that account management will be disabled (true) or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006027 * enabled (false).
6028 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnse650c3342014-05-08 18:00:50 +01006029 */
Robin Lee25e26452015-06-02 09:56:29 -07006030 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01006031 boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006032 throwIfParentInstance("setAccountManagementDisabled");
Sander Alewijnse650c3342014-05-08 18:00:50 +01006033 if (mService != null) {
6034 try {
6035 mService.setAccountManagementDisabled(admin, accountType, disabled);
6036 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006037 throw e.rethrowFromSystemServer();
Sander Alewijnse650c3342014-05-08 18:00:50 +01006038 }
6039 }
6040 }
6041
6042 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01006043 * Gets the array of accounts for which account management is disabled by the profile owner.
6044 *
6045 * <p> Account management can be disabled/enabled by calling
6046 * {@link #setAccountManagementDisabled}.
6047 *
6048 * @return a list of account types for which account management has been disabled.
6049 *
6050 * @see #setAccountManagementDisabled
6051 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006052 public @Nullable String[] getAccountTypesWithManagementDisabled() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006053 throwIfParentInstance("getAccountTypesWithManagementDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07006054 return getAccountTypesWithManagementDisabledAsUser(myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01006055 }
6056
6057 /**
6058 * @see #getAccountTypesWithManagementDisabled()
6059 * @hide
6060 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006061 public @Nullable String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01006062 if (mService != null) {
6063 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01006064 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01006065 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006066 throw e.rethrowFromSystemServer();
Sander Alewijnse5c02db62014-05-07 10:46:57 +01006067 }
6068 }
6069
6070 return null;
6071 }
justinzhang511e0d82014-03-24 16:09:24 -04006072
6073 /**
Jason Monkd7b86212014-06-16 13:15:38 -04006074 * Sets which packages may enter lock task mode.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006075 * <p>
Esteban Talaverabdcada92017-02-01 14:20:06 +00006076 * Any packages that share uid with an allowed package will also be allowed to activate lock
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006077 * task. From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task
Esteban Talaverabdcada92017-02-01 14:20:06 +00006078 * package list results in locked tasks belonging to those packages to be finished.
6079 * <p>
6080 * This function can only be called by the device owner or by a profile owner of a user/profile
6081 * that is affiliated with the device owner user. See {@link #setAffiliationIds}. Any packages
6082 * set via this method will be cleared if the user becomes unaffiliated.
Jason Monkd7b86212014-06-16 13:15:38 -04006083 *
Jason Monkd7b86212014-06-16 13:15:38 -04006084 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04006085 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Esteban Talaverabdcada92017-02-01 14:20:06 +00006086 * @throws SecurityException if {@code admin} is not the device owner, or the profile owner of
6087 * an affiliated user or profile.
Jason Monkd7b86212014-06-16 13:15:38 -04006088 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00006089 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
6090 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04006091 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04006092 */
Esteban Talaverabdcada92017-02-01 14:20:06 +00006093 public void setLockTaskPackages(@NonNull ComponentName admin, @NonNull String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04006094 throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006095 throwIfParentInstance("setLockTaskPackages");
justinzhang511e0d82014-03-24 16:09:24 -04006096 if (mService != null) {
6097 try {
Jason Monk48aacba2014-08-13 16:29:08 -04006098 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04006099 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006100 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04006101 }
6102 }
6103 }
6104
6105 /**
Esteban Talaverabdcada92017-02-01 14:20:06 +00006106 * Returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04006107 *
Esteban Talaverabdcada92017-02-01 14:20:06 +00006108 * @throws SecurityException if {@code admin} is not the device owner, or the profile owner of
6109 * an affiliated user or profile.
6110 * @see #setLockTaskPackages
6111 *
justinzhang511e0d82014-03-24 16:09:24 -04006112 * @hide
6113 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006114 public @NonNull String[] getLockTaskPackages(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006115 throwIfParentInstance("getLockTaskPackages");
justinzhang511e0d82014-03-24 16:09:24 -04006116 if (mService != null) {
6117 try {
Jason Monk48aacba2014-08-13 16:29:08 -04006118 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04006119 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006120 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04006121 }
6122 }
Esteban Talaverabdcada92017-02-01 14:20:06 +00006123 return new String[0];
justinzhang511e0d82014-03-24 16:09:24 -04006124 }
6125
6126 /**
6127 * This function lets the caller know whether the given component is allowed to start the
6128 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04006129 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04006130 */
Jason Monkd7b86212014-06-16 13:15:38 -04006131 public boolean isLockTaskPermitted(String pkg) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006132 throwIfParentInstance("isLockTaskPermitted");
justinzhang511e0d82014-03-24 16:09:24 -04006133 if (mService != null) {
6134 try {
Jason Monkd7b86212014-06-16 13:15:38 -04006135 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04006136 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006137 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04006138 }
6139 }
6140 return false;
6141 }
Julia Reynoldsda551652014-05-14 17:15:16 -04006142
6143 /**
6144 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
6145 * 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 -07006146 * <p>
6147 * The settings that can be updated with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04006148 * <ul>
6149 * <li>{@link Settings.Global#ADB_ENABLED}</li>
6150 * <li>{@link Settings.Global#AUTO_TIME}</li>
6151 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04006152 * <li>{@link Settings.Global#DATA_ROAMING}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04006153 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04006154 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006155 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN} This setting is only available from
6156 * {@link android.os.Build.VERSION_CODES#M} onwards and can only be set if
6157 * {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
6158 * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li> This setting is only
6159 * available from {@link android.os.Build.VERSION_CODES#M} onwards.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04006160 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006161 * <p>
6162 * Changing the following settings has no effect as of {@link android.os.Build.VERSION_CODES#M}:
Esteban Talavera656fa7f2015-06-29 17:41:39 +01006163 * <ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006164 * <li>{@link Settings.Global#BLUETOOTH_ON}. Use
6165 * {@link android.bluetooth.BluetoothAdapter#enable()} and
6166 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01006167 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006168 * <li>{@link Settings.Global#MODE_RINGER}. Use
6169 * {@link android.media.AudioManager#setRingerMode(int)} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01006170 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006171 * <li>{@link Settings.Global#WIFI_ON}. Use
6172 * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01006173 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04006174 *
6175 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6176 * @param setting The name of the setting to update.
6177 * @param value The value to update the setting to.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006178 * @throws SecurityException if {@code admin} is not a device owner.
Julia Reynoldsda551652014-05-14 17:15:16 -04006179 */
Robin Lee25e26452015-06-02 09:56:29 -07006180 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006181 throwIfParentInstance("setGlobalSetting");
Julia Reynoldsda551652014-05-14 17:15:16 -04006182 if (mService != null) {
6183 try {
6184 mService.setGlobalSetting(admin, setting, value);
6185 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006186 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04006187 }
6188 }
6189 }
6190
6191 /**
6192 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
6193 * that the value of the setting is in the correct form for the setting type should be performed
6194 * by the caller.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006195 * <p>
6196 * The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04006197 * <ul>
6198 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07006199 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04006200 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
6201 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006202 * <p>
6203 * A device owner can additionally update the following settings:
Julia Reynolds82735bc2014-09-04 16:43:30 -04006204 * <ul>
6205 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
6206 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006207 *
Julia Reynoldsda551652014-05-14 17:15:16 -04006208 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6209 * @param setting The name of the setting to update.
6210 * @param value The value to update the setting to.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006211 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynoldsda551652014-05-14 17:15:16 -04006212 */
Robin Lee25e26452015-06-02 09:56:29 -07006213 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006214 throwIfParentInstance("setSecureSetting");
Julia Reynoldsda551652014-05-14 17:15:16 -04006215 if (mService != null) {
6216 try {
6217 mService.setSecureSetting(admin, setting, value);
6218 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006219 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04006220 }
6221 }
6222 }
6223
Amith Yamasanif20d6402014-05-24 15:34:37 -07006224 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006225 * Designates a specific service component as the provider for making permission requests of a
6226 * local or remote administrator of the user.
Amith Yamasanif20d6402014-05-24 15:34:37 -07006227 * <p/>
6228 * Only a profile owner can designate the restrictions provider.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006229 *
Amith Yamasanif20d6402014-05-24 15:34:37 -07006230 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07006231 * @param provider The component name of the service that implements
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006232 * {@link RestrictionsReceiver}. If this param is null, it removes the restrictions
6233 * provider previously assigned.
6234 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanif20d6402014-05-24 15:34:37 -07006235 */
Robin Lee25e26452015-06-02 09:56:29 -07006236 public void setRestrictionsProvider(@NonNull ComponentName admin,
6237 @Nullable ComponentName provider) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006238 throwIfParentInstance("setRestrictionsProvider");
Amith Yamasanif20d6402014-05-24 15:34:37 -07006239 if (mService != null) {
6240 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07006241 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07006242 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006243 throw re.rethrowFromSystemServer();
Amith Yamasanif20d6402014-05-24 15:34:37 -07006244 }
6245 }
6246 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04006247
6248 /**
6249 * Called by profile or device owners to set the master volume mute on or off.
Nicolas Prevotaef3ce22016-09-22 12:00:25 +01006250 * This has no effect when set on a managed profile.
Julia Reynolds4a21b252014-06-04 11:11:43 -04006251 *
6252 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6253 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006254 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds4a21b252014-06-04 11:11:43 -04006255 */
Robin Lee25e26452015-06-02 09:56:29 -07006256 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006257 throwIfParentInstance("setMasterVolumeMuted");
Julia Reynolds4a21b252014-06-04 11:11:43 -04006258 if (mService != null) {
6259 try {
6260 mService.setMasterVolumeMuted(admin, on);
6261 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006262 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04006263 }
6264 }
6265 }
6266
6267 /**
6268 * Called by profile or device owners to check whether the master volume mute is on or off.
6269 *
6270 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6271 * @return {@code true} if master volume is muted, {@code false} if it's not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006272 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds4a21b252014-06-04 11:11:43 -04006273 */
Robin Lee25e26452015-06-02 09:56:29 -07006274 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006275 throwIfParentInstance("isMasterVolumeMuted");
Julia Reynolds4a21b252014-06-04 11:11:43 -04006276 if (mService != null) {
6277 try {
6278 return mService.isMasterVolumeMuted(admin);
6279 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006280 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04006281 }
6282 }
6283 return false;
6284 }
Kenny Guyc13053b2014-05-29 14:17:17 +01006285
6286 /**
Edman Anjosa5f2fb12016-12-19 11:25:54 -08006287 * Change whether a user can uninstall a package. This function can be called by a device owner,
6288 * profile owner, or by a delegate given the {@link #DELEGATION_BLOCK_UNINSTALL} scope via
6289 * {@link #setDelegatedScopes}.
Kenny Guyc13053b2014-05-29 14:17:17 +01006290 *
Edman Anjosa5f2fb12016-12-19 11:25:54 -08006291 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
6292 * {@code null} if the caller is a block uninstall delegate.
Kenny Guyc13053b2014-05-29 14:17:17 +01006293 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01006294 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006295 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjosa5f2fb12016-12-19 11:25:54 -08006296 * @see #setDelegatedScopes
6297 * @see #DELEGATION_BLOCK_UNINSTALL
Kenny Guyc13053b2014-05-29 14:17:17 +01006298 */
Edman Anjosa5f2fb12016-12-19 11:25:54 -08006299 public void setUninstallBlocked(@Nullable ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01006300 boolean uninstallBlocked) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006301 throwIfParentInstance("setUninstallBlocked");
Kenny Guyc13053b2014-05-29 14:17:17 +01006302 if (mService != null) {
6303 try {
Edman Anjosa5f2fb12016-12-19 11:25:54 -08006304 mService.setUninstallBlocked(admin, mContext.getPackageName(), packageName,
6305 uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01006306 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006307 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01006308 }
6309 }
6310 }
6311
6312 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08006313 * Check whether the user has been blocked by device policy from uninstalling a package.
Rubin Xua97855b2014-11-07 05:41:00 +00006314 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00006315 * <p>
6316 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006317 * behavior of this API is changed such that passing {@code null} as the {@code admin} parameter
6318 * will return if any admin has blocked the uninstallation. Before L MR1, passing {@code null}
6319 * will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01006320 *
Robin Lee25e26452015-06-02 09:56:29 -07006321 * @param admin The name of the admin component whose blocking policy will be checked, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006322 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01006323 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00006324 * @return true if uninstallation is blocked.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006325 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyc13053b2014-05-29 14:17:17 +01006326 */
Robin Lee25e26452015-06-02 09:56:29 -07006327 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006328 throwIfParentInstance("isUninstallBlocked");
Kenny Guyc13053b2014-05-29 14:17:17 +01006329 if (mService != null) {
6330 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01006331 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01006332 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006333 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01006334 }
6335 }
6336 return false;
6337 }
Svetoslav976e8bd2014-07-16 15:12:03 -07006338
6339 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006340 * Called by the profile owner of a managed profile to enable widget providers from a given
6341 * package to be available in the parent profile. As a result the user will be able to add
6342 * widgets from the white-listed package running under the profile to a widget host which runs
6343 * under the parent profile, for example the home screen. Note that a package may have zero or
6344 * more provider components, where each component provides a different widget type.
Svetoslav976e8bd2014-07-16 15:12:03 -07006345 * <p>
6346 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07006347 *
6348 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6349 * @param packageName The package from which widget providers are white-listed.
6350 * @return Whether the package was added.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006351 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07006352 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
6353 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
6354 */
Robin Lee25e26452015-06-02 09:56:29 -07006355 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006356 throwIfParentInstance("addCrossProfileWidgetProvider");
Svetoslav976e8bd2014-07-16 15:12:03 -07006357 if (mService != null) {
6358 try {
6359 return mService.addCrossProfileWidgetProvider(admin, packageName);
6360 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006361 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07006362 }
6363 }
6364 return false;
6365 }
6366
6367 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07006368 * Called by the profile owner of a managed profile to disable widget providers from a given
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006369 * package to be available in the parent profile. For this method to take effect the package
6370 * should have been added via
6371 * {@link #addCrossProfileWidgetProvider( android.content.ComponentName, String)}.
Svetoslav976e8bd2014-07-16 15:12:03 -07006372 * <p>
6373 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07006374 *
6375 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006376 * @param packageName The package from which widget providers are no longer white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07006377 * @return Whether the package was removed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006378 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07006379 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
6380 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
6381 */
Esteban Talavera62399912016-01-11 15:37:55 +00006382 public boolean removeCrossProfileWidgetProvider(
6383 @NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006384 throwIfParentInstance("removeCrossProfileWidgetProvider");
Svetoslav976e8bd2014-07-16 15:12:03 -07006385 if (mService != null) {
6386 try {
6387 return mService.removeCrossProfileWidgetProvider(admin, packageName);
6388 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006389 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07006390 }
6391 }
6392 return false;
6393 }
6394
6395 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07006396 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07006397 * available in the parent profile.
6398 *
6399 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6400 * @return The white-listed package list.
Svetoslav976e8bd2014-07-16 15:12:03 -07006401 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
6402 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006403 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07006404 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006405 public @NonNull List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006406 throwIfParentInstance("getCrossProfileWidgetProviders");
Svetoslav976e8bd2014-07-16 15:12:03 -07006407 if (mService != null) {
6408 try {
6409 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
6410 if (providers != null) {
6411 return providers;
6412 }
6413 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006414 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07006415 }
6416 }
6417 return Collections.emptyList();
6418 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006419
6420 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08006421 * Called by profile or device owners to set the user's photo.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006422 *
6423 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6424 * @param icon the bitmap to set as the photo.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006425 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006426 */
Robin Lee25e26452015-06-02 09:56:29 -07006427 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006428 throwIfParentInstance("setUserIcon");
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006429 try {
6430 mService.setUserIcon(admin, icon);
6431 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006432 throw re.rethrowFromSystemServer();
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006433 }
6434 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04006435
6436 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01006437 * Called by device owners to set a local system update policy. When a new policy is set,
6438 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00006439 *
Robin Lee25e26452015-06-02 09:56:29 -07006440 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006441 * components in the device owner package can set system update policies and the most
6442 * recent policy takes effect.
Robin Lee25e26452015-06-02 09:56:29 -07006443 * @param policy the new policy, or {@code null} to clear the current policy.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006444 * @throws SecurityException if {@code admin} is not a device owner.
Rubin Xu5faad8e2015-04-20 17:43:48 +01006445 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00006446 */
Robin Lee25e26452015-06-02 09:56:29 -07006447 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006448 throwIfParentInstance("setSystemUpdatePolicy");
Rubin Xu8027a4f2015-03-10 17:52:37 +00006449 if (mService != null) {
6450 try {
Robin Lee25e26452015-06-02 09:56:29 -07006451 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00006452 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006453 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00006454 }
6455 }
6456 }
6457
6458 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01006459 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00006460 *
Robin Lee25e26452015-06-02 09:56:29 -07006461 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00006462 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006463 public @Nullable SystemUpdatePolicy getSystemUpdatePolicy() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006464 throwIfParentInstance("getSystemUpdatePolicy");
Rubin Xu8027a4f2015-03-10 17:52:37 +00006465 if (mService != null) {
6466 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01006467 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00006468 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006469 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00006470 }
6471 }
6472 return null;
6473 }
Benjamin Franze36087e2015-04-07 16:40:34 +01006474
6475 /**
6476 * Called by a device owner to disable the keyguard altogether.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006477 * <p>
6478 * Setting the keyguard to disabled has the same effect as choosing "None" as the screen lock
6479 * type. However, this call has no effect if a password, pin or pattern is currently set. If a
6480 * password, pin or pattern is set after the keyguard was disabled, the keyguard stops being
6481 * disabled.
Benjamin Franze36087e2015-04-07 16:40:34 +01006482 *
6483 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01006484 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01006485 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006486 * place. {@code true} otherwise.
6487 * @throws SecurityException if {@code admin} is not a device owner.
Benjamin Franze36087e2015-04-07 16:40:34 +01006488 */
Robin Lee25e26452015-06-02 09:56:29 -07006489 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006490 throwIfParentInstance("setKeyguardDisabled");
Benjamin Franze36087e2015-04-07 16:40:34 +01006491 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01006492 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01006493 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006494 throw re.rethrowFromSystemServer();
Benjamin Franze36087e2015-04-07 16:40:34 +01006495 }
6496 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00006497
6498 /**
Benjamin Franzbece8062015-05-06 12:14:31 +01006499 * Called by device owner to disable the status bar. Disabling the status bar blocks
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006500 * notifications, quick settings and other screen overlays that allow escaping from a single use
6501 * device.
Benjamin Franzea2ec972015-03-16 17:18:09 +00006502 *
6503 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01006504 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006505 * @return {@code false} if attempting to disable the status bar failed. {@code true} otherwise.
6506 * @throws SecurityException if {@code admin} is not a device owner.
Benjamin Franzea2ec972015-03-16 17:18:09 +00006507 */
Robin Lee25e26452015-06-02 09:56:29 -07006508 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006509 throwIfParentInstance("setStatusBarDisabled");
Benjamin Franzea2ec972015-03-16 17:18:09 +00006510 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01006511 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00006512 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006513 throw re.rethrowFromSystemServer();
Benjamin Franzea2ec972015-03-16 17:18:09 +00006514 }
6515 }
Rubin Xudc105cc2015-04-14 23:38:01 +01006516
6517 /**
Charles Hedea0c3b2017-01-13 10:04:12 +00006518 * Called by the system update service to notify device and profile owners of pending system
6519 * updates.
Rubin Xudc105cc2015-04-14 23:38:01 +01006520 *
Charles Hedea0c3b2017-01-13 10:04:12 +00006521 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
6522 * permission. This method should only be used when it is unknown whether the pending system
6523 * update is a security patch. Otherwise, use
6524 * {@link #notifyPendingSystemUpdate(long, boolean)}.
6525 *
6526 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()}
6527 * indicating when the current pending update was first available. {@code -1} if no
6528 * update is available.
6529 * @see #notifyPendingSystemUpdate(long, boolean)
Rubin Xudc105cc2015-04-14 23:38:01 +01006530 * @hide
6531 */
6532 @SystemApi
6533 public void notifyPendingSystemUpdate(long updateReceivedTime) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006534 throwIfParentInstance("notifyPendingSystemUpdate");
Rubin Xudc105cc2015-04-14 23:38:01 +01006535 if (mService != null) {
6536 try {
Charles Hedea0c3b2017-01-13 10:04:12 +00006537 mService.notifyPendingSystemUpdate(SystemUpdateInfo.of(updateReceivedTime));
6538 } catch (RemoteException re) {
6539 throw re.rethrowFromSystemServer();
6540 }
6541 }
6542 }
6543
6544 /**
6545 * Called by the system update service to notify device and profile owners of pending system
6546 * updates.
6547 *
6548 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
6549 * permission. This method should be used instead of {@link #notifyPendingSystemUpdate(long)}
6550 * when it is known whether the pending system update is a security patch.
6551 *
6552 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()}
6553 * indicating when the current pending update was first available. {@code -1} if no
6554 * update is available.
6555 * @param isSecurityPatch {@code true} if this system update is purely a security patch;
6556 * {@code false} if not.
6557 * @see #notifyPendingSystemUpdate(long)
6558 * @hide
6559 */
6560 @SystemApi
6561 public void notifyPendingSystemUpdate(long updateReceivedTime, boolean isSecurityPatch) {
6562 throwIfParentInstance("notifyPendingSystemUpdate");
6563 if (mService != null) {
6564 try {
6565 mService.notifyPendingSystemUpdate(SystemUpdateInfo.of(updateReceivedTime,
6566 isSecurityPatch));
Rubin Xudc105cc2015-04-14 23:38:01 +01006567 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006568 throw re.rethrowFromSystemServer();
Rubin Xudc105cc2015-04-14 23:38:01 +01006569 }
6570 }
6571 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04006572
6573 /**
Pavel Grafovd65799e2016-12-02 11:21:45 +00006574 * Called by device or profile owners to get information about a pending system update.
6575 *
6576 * @param admin Which profile or device owner this request is associated with.
6577 * @return Information about a pending system update or {@code null} if no update pending.
6578 * @throws SecurityException if {@code admin} is not a device or profile owner.
6579 * @see DeviceAdminReceiver#onSystemUpdatePending(Context, Intent, long)
6580 */
6581 public @Nullable SystemUpdateInfo getPendingSystemUpdate(@NonNull ComponentName admin) {
6582 throwIfParentInstance("getPendingSystemUpdate");
6583 try {
6584 return mService.getPendingSystemUpdate(admin);
6585 } catch (RemoteException re) {
6586 throw re.rethrowFromSystemServer();
6587 }
6588 }
6589
6590 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006591 * Set the default response for future runtime permission requests by applications. This
6592 * function can be called by a device owner, profile owner, or by a delegate given the
6593 * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}.
6594 * The policy can allow for normal operation which prompts the user to grant a permission, or
6595 * can allow automatic granting or denying of runtime permission requests by an application.
6596 * This also applies to new permissions declared by app updates. When a permission is denied or
6597 * granted this way, the effect is equivalent to setting the permission * grant state via
6598 * {@link #setPermissionGrantState}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006599 * <p/>
6600 * As this policy only acts on runtime permission requests, it only applies to applications
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07006601 * built with a {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Benjamin Franz45dd6662015-07-08 14:24:14 +01006602 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07006603 * @param admin Which profile or device owner this request is associated with.
6604 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006605 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
6606 * @throws SecurityException if {@code admin} is not a device or profile owner.
Benjamin Franz45dd6662015-07-08 14:24:14 +01006607 * @see #setPermissionGrantState
Edman Anjos52088e42017-01-13 22:26:17 +01006608 * @see #setDelegatedScopes
6609 * @see #DELEGATION_PERMISSION_GRANT
Amith Yamasanid49489b2015-04-28 14:00:26 -07006610 */
Robin Lee25e26452015-06-02 09:56:29 -07006611 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006612 throwIfParentInstance("setPermissionPolicy");
Amith Yamasanid49489b2015-04-28 14:00:26 -07006613 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006614 mService.setPermissionPolicy(admin, mContext.getPackageName(), policy);
Amith Yamasanid49489b2015-04-28 14:00:26 -07006615 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006616 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07006617 }
6618 }
6619
6620 /**
6621 * Returns the current runtime permission policy set by the device or profile owner. The
6622 * default is {@link #PERMISSION_POLICY_PROMPT}.
Edman Anjos52088e42017-01-13 22:26:17 +01006623 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07006624 * @param admin Which profile or device owner this request is associated with.
6625 * @return the current policy for future permission requests.
6626 */
Esteban Talavera28b95702015-06-24 15:23:42 +01006627 public int getPermissionPolicy(ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006628 throwIfParentInstance("getPermissionPolicy");
Amith Yamasanid49489b2015-04-28 14:00:26 -07006629 try {
6630 return mService.getPermissionPolicy(admin);
6631 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006632 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07006633 }
6634 }
6635
6636 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006637 * Sets the grant state of a runtime permission for a specific application. The state can be
6638 * {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it through the UI,
6639 * {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission is denied and the user
6640 * cannot manage it through the UI, and {@link #PERMISSION_GRANT_STATE_GRANTED granted} in which
6641 * the permission is granted and the user cannot manage it through the UI. This might affect all
6642 * permissions in a group that the runtime permission belongs to. This method can only be called
Edman Anjos52088e42017-01-13 22:26:17 +01006643 * by a profile owner, device owner, or a delegate given the
6644 * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006645 * <p/>
6646 * Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not revoke
6647 * the permission. It retains the previous grant, if any.
6648 * <p/>
6649 * Permissions can be granted or revoked only for applications built with a
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07006650 * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07006651 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07006652 * @param admin Which profile or device owner this request is associated with.
6653 * @param packageName The application to grant or revoke a permission to.
6654 * @param permission The permission to grant or revoke.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006655 * @param grantState The permission grant state which is one of
6656 * {@link #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
6657 * {@link #PERMISSION_GRANT_STATE_GRANTED},
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006658 * @return whether the permission was successfully granted or revoked.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006659 * @throws SecurityException if {@code admin} is not a device or profile owner.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006660 * @see #PERMISSION_GRANT_STATE_DENIED
6661 * @see #PERMISSION_GRANT_STATE_DEFAULT
6662 * @see #PERMISSION_GRANT_STATE_GRANTED
Edman Anjos52088e42017-01-13 22:26:17 +01006663 * @see #setDelegatedScopes
6664 * @see #DELEGATION_PERMISSION_GRANT
Amith Yamasanid49489b2015-04-28 14:00:26 -07006665 */
Robin Lee25e26452015-06-02 09:56:29 -07006666 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006667 String permission, int grantState) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006668 throwIfParentInstance("setPermissionGrantState");
Amith Yamasanid49489b2015-04-28 14:00:26 -07006669 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006670 return mService.setPermissionGrantState(admin, mContext.getPackageName(), packageName,
6671 permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07006672 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006673 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07006674 }
6675 }
Amith Yamasani184b3752015-05-22 13:00:51 -07006676
6677 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006678 * Returns the current grant state of a runtime permission for a specific application. This
6679 * function can be called by a device owner, profile owner, or by a delegate given the
6680 * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}.
Amith Yamasani184b3752015-05-22 13:00:51 -07006681 *
Edman Anjos52088e42017-01-13 22:26:17 +01006682 * @param admin Which profile or device owner this request is associated with, or {@code null}
6683 * if the caller is a permission grant delegate.
Amith Yamasani184b3752015-05-22 13:00:51 -07006684 * @param packageName The application to check the grant state for.
6685 * @param permission The permission to check for.
6686 * @return the current grant state specified by device policy. If the profile or device owner
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006687 * has not set a grant state, the return value is
6688 * {@link #PERMISSION_GRANT_STATE_DEFAULT}. This does not indicate whether or not the
6689 * permission is currently granted for the package.
6690 * <p/>
6691 * If a grant state was set by the profile or device owner, then the return value will
6692 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or
6693 * {@link #PERMISSION_GRANT_STATE_GRANTED}, which indicates if the permission is
6694 * currently denied or granted.
6695 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasani184b3752015-05-22 13:00:51 -07006696 * @see #setPermissionGrantState(ComponentName, String, String, int)
6697 * @see PackageManager#checkPermission(String, String)
Edman Anjos52088e42017-01-13 22:26:17 +01006698 * @see #setDelegatedScopes
6699 * @see #DELEGATION_PERMISSION_GRANT
Amith Yamasani184b3752015-05-22 13:00:51 -07006700 */
Bartosz Fabianowski4b0624f2017-01-16 11:47:28 +01006701 public int getPermissionGrantState(@Nullable ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07006702 String permission) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006703 throwIfParentInstance("getPermissionGrantState");
Amith Yamasani184b3752015-05-22 13:00:51 -07006704 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006705 return mService.getPermissionGrantState(admin, mContext.getPackageName(), packageName,
6706 permission);
Amith Yamasani184b3752015-05-22 13:00:51 -07006707 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006708 throw re.rethrowFromSystemServer();
Amith Yamasani184b3752015-05-22 13:00:51 -07006709 }
6710 }
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006711
6712 /**
Esteban Talavera01576862016-12-15 11:16:44 +00006713 * Returns whether it is possible for the caller to initiate provisioning of a managed profile
6714 * or device, setting itself as the device or profile owner.
6715 *
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006716 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
6717 * {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Esteban Talavera01576862016-12-15 11:16:44 +00006718 * @return whether provisioning a managed profile or device is possible.
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006719 * @throws IllegalArgumentException if the supplied action is not valid.
6720 */
Esteban Talavera01576862016-12-15 11:16:44 +00006721 public boolean isProvisioningAllowed(@NonNull String action) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006722 throwIfParentInstance("isProvisioningAllowed");
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006723 try {
Esteban Talavera01576862016-12-15 11:16:44 +00006724 return mService.isProvisioningAllowed(action, mContext.getPackageName());
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006725 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006726 throw re.rethrowFromSystemServer();
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006727 }
6728 }
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006729
6730 /**
Esteban Talavera01576862016-12-15 11:16:44 +00006731 * Checks whether it is possible to initiate provisioning a managed device,
6732 * profile or user, setting the given package as owner.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00006733 *
6734 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
6735 * {@link #ACTION_PROVISION_MANAGED_PROFILE},
6736 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE},
6737 * {@link #ACTION_PROVISION_MANAGED_USER}
Esteban Talavera01576862016-12-15 11:16:44 +00006738 * @param packageName The package of the component that would be set as device, user, or profile
6739 * owner.
6740 * @return A {@link ProvisioningPreCondition} value indicating whether provisioning is allowed.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00006741 * @hide
6742 */
Esteban Talavera01576862016-12-15 11:16:44 +00006743 public @ProvisioningPreCondition int checkProvisioningPreCondition(
6744 String action, @NonNull String packageName) {
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00006745 try {
Esteban Talavera01576862016-12-15 11:16:44 +00006746 return mService.checkProvisioningPreCondition(action, packageName);
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00006747 } catch (RemoteException re) {
6748 throw re.rethrowFromSystemServer();
6749 }
6750 }
6751
6752 /**
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006753 * Return if this user is a managed profile of another user. An admin can become the profile
6754 * owner of a managed profile with {@link #ACTION_PROVISION_MANAGED_PROFILE} and of a managed
Kenny Guyffa38402016-03-31 16:40:57 +01006755 * user with {@link #createAndManageUser}
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006756 * @param admin Which profile owner this request is associated with.
6757 * @return if this user is a managed profile of another user.
6758 */
6759 public boolean isManagedProfile(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006760 throwIfParentInstance("isManagedProfile");
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006761 try {
6762 return mService.isManagedProfile(admin);
6763 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006764 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006765 }
6766 }
6767
6768 /**
6769 * @hide
6770 * Return if this user is a system-only user. An admin can manage a device from a system only
6771 * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}.
6772 * @param admin Which device owner this request is associated with.
6773 * @return if this user is a system-only user.
6774 */
6775 public boolean isSystemOnlyUser(@NonNull ComponentName admin) {
6776 try {
6777 return mService.isSystemOnlyUser(admin);
6778 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006779 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006780 }
6781 }
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006782
6783 /**
6784 * Called by device owner to get the MAC address of the Wi-Fi device.
6785 *
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08006786 * @param admin Which device owner this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006787 * @return the MAC address of the Wi-Fi device, or null when the information is not available.
6788 * (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.)
6789 * <p>
6790 * The address will be in the {@code XX:XX:XX:XX:XX:XX} format.
6791 * @throws SecurityException if {@code admin} is not a device owner.
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006792 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006793 public @Nullable String getWifiMacAddress(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006794 throwIfParentInstance("getWifiMacAddress");
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006795 try {
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08006796 return mService.getWifiMacAddress(admin);
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006797 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006798 throw re.rethrowFromSystemServer();
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006799 }
6800 }
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00006801
6802 /**
Mahaver Chopra1216ae52016-03-11 15:39:48 +00006803 * Called by device owner to reboot the device. If there is an ongoing call on the device,
6804 * throws an {@link IllegalStateException}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006805 * @param admin Which device owner the request is associated with.
Mahaver Chopra1216ae52016-03-11 15:39:48 +00006806 * @throws IllegalStateException if device has an ongoing call.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006807 * @throws SecurityException if {@code admin} is not a device owner.
Mahaver Chopra1216ae52016-03-11 15:39:48 +00006808 * @see TelephonyManager#CALL_STATE_IDLE
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00006809 */
6810 public void reboot(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006811 throwIfParentInstance("reboot");
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00006812 try {
6813 mService.reboot(admin);
6814 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006815 throw re.rethrowFromSystemServer();
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00006816 }
6817 }
Kenny Guy06de4e72015-12-22 12:07:39 +00006818
6819 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006820 * Called by a device admin to set the short support message. This will be displayed to the user
6821 * in settings screens where funtionality has been disabled by the admin. The message should be
6822 * limited to a short statement such as "This setting is disabled by your administrator. Contact
6823 * someone@example.com for support." If the message is longer than 200 characters it may be
6824 * truncated.
6825 * <p>
6826 * If the short support message needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006827 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
6828 * and set a new version of this string accordingly.
6829 *
Kenny Guy06de4e72015-12-22 12:07:39 +00006830 * @see #setLongSupportMessage
Kenny Guy06de4e72015-12-22 12:07:39 +00006831 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006832 * @param message Short message to be displayed to the user in settings or null to clear the
6833 * existing message.
6834 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00006835 */
6836 public void setShortSupportMessage(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006837 @Nullable CharSequence message) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006838 throwIfParentInstance("setShortSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00006839 if (mService != null) {
6840 try {
6841 mService.setShortSupportMessage(admin, message);
6842 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006843 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006844 }
6845 }
6846 }
6847
6848 /**
6849 * Called by a device admin to get the short support message.
6850 *
6851 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006852 * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)} or
6853 * null if no message has been set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006854 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00006855 */
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006856 public CharSequence getShortSupportMessage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006857 throwIfParentInstance("getShortSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00006858 if (mService != null) {
6859 try {
6860 return mService.getShortSupportMessage(admin);
6861 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006862 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006863 }
6864 }
6865 return null;
6866 }
6867
6868 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006869 * Called by a device admin to set the long support message. This will be displayed to the user
6870 * in the device administators settings screen.
6871 * <p>
6872 * If the long support message needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006873 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
6874 * and set a new version of this string accordingly.
6875 *
Kenny Guy06de4e72015-12-22 12:07:39 +00006876 * @see #setShortSupportMessage
Kenny Guy06de4e72015-12-22 12:07:39 +00006877 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006878 * @param message Long message to be displayed to the user in settings or null to clear the
6879 * existing message.
6880 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00006881 */
6882 public void setLongSupportMessage(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006883 @Nullable CharSequence message) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006884 throwIfParentInstance("setLongSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00006885 if (mService != null) {
6886 try {
6887 mService.setLongSupportMessage(admin, message);
6888 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006889 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006890 }
6891 }
6892 }
6893
6894 /**
6895 * Called by a device admin to get the long support message.
6896 *
6897 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006898 * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)} or
6899 * null if no message has been set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006900 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00006901 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006902 public @Nullable CharSequence getLongSupportMessage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006903 throwIfParentInstance("getLongSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00006904 if (mService != null) {
6905 try {
6906 return mService.getLongSupportMessage(admin);
6907 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006908 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006909 }
6910 }
6911 return null;
6912 }
6913
6914 /**
6915 * Called by the system to get the short support message.
6916 *
6917 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6918 * @param userHandle user id the admin is running as.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006919 * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)}
Kenny Guy06de4e72015-12-22 12:07:39 +00006920 *
6921 * @hide
6922 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006923 public @Nullable CharSequence getShortSupportMessageForUser(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006924 int userHandle) {
Kenny Guy06de4e72015-12-22 12:07:39 +00006925 if (mService != null) {
6926 try {
6927 return mService.getShortSupportMessageForUser(admin, userHandle);
6928 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006929 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006930 }
6931 }
6932 return null;
6933 }
6934
6935
6936 /**
6937 * Called by the system to get the long support message.
6938 *
6939 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6940 * @param userHandle user id the admin is running as.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006941 * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)}
Kenny Guy06de4e72015-12-22 12:07:39 +00006942 *
6943 * @hide
6944 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006945 public @Nullable CharSequence getLongSupportMessageForUser(
6946 @NonNull ComponentName admin, int userHandle) {
Kenny Guy06de4e72015-12-22 12:07:39 +00006947 if (mService != null) {
6948 try {
6949 return mService.getLongSupportMessageForUser(admin, userHandle);
6950 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006951 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006952 }
6953 }
6954 return null;
6955 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006956
6957 /**
Esteban Talavera62399912016-01-11 15:37:55 +00006958 * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager}
6959 * whose calls act on the parent profile.
Benjamin Franz66b45f02016-04-05 19:12:39 +01006960 *
6961 * <p>The following methods are supported for the parent instance, all other methods will
6962 * throw a SecurityException when called on the parent instance:
6963 * <ul>
6964 * <li>{@link #getPasswordQuality}</li>
6965 * <li>{@link #setPasswordQuality}</li>
6966 * <li>{@link #getPasswordMinimumLength}</li>
6967 * <li>{@link #setPasswordMinimumLength}</li>
6968 * <li>{@link #getPasswordMinimumUpperCase}</li>
6969 * <li>{@link #setPasswordMinimumUpperCase}</li>
6970 * <li>{@link #getPasswordMinimumLowerCase}</li>
6971 * <li>{@link #setPasswordMinimumLowerCase}</li>
6972 * <li>{@link #getPasswordMinimumLetters}</li>
6973 * <li>{@link #setPasswordMinimumLetters}</li>
6974 * <li>{@link #getPasswordMinimumNumeric}</li>
6975 * <li>{@link #setPasswordMinimumNumeric}</li>
6976 * <li>{@link #getPasswordMinimumSymbols}</li>
6977 * <li>{@link #setPasswordMinimumSymbols}</li>
6978 * <li>{@link #getPasswordMinimumNonLetter}</li>
6979 * <li>{@link #setPasswordMinimumNonLetter}</li>
6980 * <li>{@link #getPasswordHistoryLength}</li>
6981 * <li>{@link #setPasswordHistoryLength}</li>
6982 * <li>{@link #getPasswordExpirationTimeout}</li>
6983 * <li>{@link #setPasswordExpirationTimeout}</li>
6984 * <li>{@link #getPasswordExpiration}</li>
Charles He8c760562016-10-25 16:36:53 +01006985 * <li>{@link #getPasswordMaximumLength}</li>
Benjamin Franz66b45f02016-04-05 19:12:39 +01006986 * <li>{@link #isActivePasswordSufficient}</li>
6987 * <li>{@link #getCurrentFailedPasswordAttempts}</li>
6988 * <li>{@link #getMaximumFailedPasswordsForWipe}</li>
6989 * <li>{@link #setMaximumFailedPasswordsForWipe}</li>
6990 * <li>{@link #getMaximumTimeToLock}</li>
6991 * <li>{@link #setMaximumTimeToLock}</li>
6992 * <li>{@link #lockNow}</li>
6993 * <li>{@link #getKeyguardDisabledFeatures}</li>
6994 * <li>{@link #setKeyguardDisabledFeatures}</li>
6995 * <li>{@link #getTrustAgentConfiguration}</li>
6996 * <li>{@link #setTrustAgentConfiguration}</li>
Michal Karpinskia20d8bb2016-11-23 12:09:08 +00006997 * <li>{@link #getRequiredStrongAuthTimeout}</li>
6998 * <li>{@link #setRequiredStrongAuthTimeout}</li>
Benjamin Franz66b45f02016-04-05 19:12:39 +01006999 * </ul>
Clara Bayarri3e826ef2015-12-14 17:51:22 +00007000 *
7001 * @return a new instance of {@link DevicePolicyManager} that acts on the parent profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007002 * @throws SecurityException if {@code admin} is not a profile owner.
Clara Bayarri3e826ef2015-12-14 17:51:22 +00007003 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007004 public @NonNull DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007005 throwIfParentInstance("getParentProfileInstance");
Clara Bayarri3e826ef2015-12-14 17:51:22 +00007006 try {
7007 if (!mService.isManagedProfile(admin)) {
7008 throw new SecurityException("The current user does not have a parent profile.");
7009 }
Jeff Sharkey49ca5292016-05-10 12:54:45 -06007010 return new DevicePolicyManager(mContext, mService, true);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007011 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007012 throw e.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007013 }
7014 }
7015
7016 /**
Esteban Talaverad36dd152016-12-15 08:51:45 +00007017 * Called by device owner to control the security logging feature.
Michal Karpinski6235a942016-03-15 12:07:23 +00007018 *
7019 * <p> Security logs contain various information intended for security auditing purposes.
7020 * See {@link SecurityEvent} for details.
7021 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00007022 * <p><strong>Note:</strong> The device owner won't be able to retrieve security logs if there
7023 * are unaffiliated secondary users or profiles on the device, regardless of whether the
7024 * feature is enabled. Logs will be discarded if the internal buffer fills up while waiting for
7025 * all users to become affiliated. Therefore it's recommended that affiliation ids are set for
7026 * new users as soon as possible after provisioning via {@link #setAffiliationIds}.
Michal Karpinskib58e4962016-03-01 14:55:10 +00007027 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007028 * @param admin Which device owner this request is associated with.
Michal Karpinski6235a942016-03-15 12:07:23 +00007029 * @param enabled whether security logging should be enabled or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007030 * @throws SecurityException if {@code admin} is not a device owner.
Michal Karpinski6235a942016-03-15 12:07:23 +00007031 * @see #retrieveSecurityLogs
7032 */
7033 public void setSecurityLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007034 throwIfParentInstance("setSecurityLoggingEnabled");
Michal Karpinski6235a942016-03-15 12:07:23 +00007035 try {
7036 mService.setSecurityLoggingEnabled(admin, enabled);
7037 } catch (RemoteException re) {
7038 throw re.rethrowFromSystemServer();
7039 }
7040 }
7041
7042 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00007043 * Return whether security logging is enabled or not by the device owner.
7044 *
7045 * <p>Can only be called by the device owner, otherwise a {@link SecurityException} will be
7046 * thrown.
7047 *
7048 * @param admin Which device owner this request is associated with.
7049 * @return {@code true} if security logging is enabled by device owner, {@code false} otherwise.
7050 * @throws SecurityException if {@code admin} is not a device owner.
7051 */
7052 public boolean isSecurityLoggingEnabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007053 throwIfParentInstance("isSecurityLoggingEnabled");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007054 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00007055 return mService.isSecurityLoggingEnabled(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007056 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007057 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007058 }
7059 }
7060
7061 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00007062 * Called by device owner to retrieve all new security logging entries since the last call to
7063 * this API after device boots.
7064 *
7065 * <p> Access to the logs is rate limited and it will only return new logs after the device
7066 * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}.
7067 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00007068 * <p>If there is any other user or profile on the device, it must be affiliated with the
7069 * device owner. Otherwise a {@link SecurityException} will be thrown. See
7070 * {@link #setAffiliationIds}
Michal Karpinskib58e4962016-03-01 14:55:10 +00007071 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007072 * @param admin Which device owner this request is associated with.
Michal Karpinski6235a942016-03-15 12:07:23 +00007073 * @return the new batch of security logs which is a list of {@link SecurityEvent},
7074 * or {@code null} if rate limitation is exceeded or if logging is currently disabled.
Esteban Talaverad36dd152016-12-15 08:51:45 +00007075 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
7076 * profile or secondary user that is not affiliated with the device owner user.
7077 * @see DeviceAdminReceiver#onSecurityLogsAvailable
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007078 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007079 public @Nullable List<SecurityEvent> retrieveSecurityLogs(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007080 throwIfParentInstance("retrieveSecurityLogs");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007081 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00007082 ParceledListSlice<SecurityEvent> list = mService.retrieveSecurityLogs(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007083 if (list != null) {
7084 return list.getList();
7085 } else {
7086 // Rate limit exceeded.
7087 return null;
7088 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00007089 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007090 throw re.rethrowFromSystemServer();
Clara Bayarri3e826ef2015-12-14 17:51:22 +00007091 }
7092 }
Benjamin Franz59720bb2016-01-18 15:26:11 +00007093
7094 /**
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00007095 * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent
7096 * profile.
7097 *
7098 * @hide
7099 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007100 public @NonNull DevicePolicyManager getParentProfileInstance(UserInfo uInfo) {
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00007101 mContext.checkSelfPermission(
7102 android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS);
7103 if (!uInfo.isManagedProfile()) {
7104 throw new SecurityException("The user " + uInfo.id
7105 + " does not have a parent profile.");
7106 }
Jeff Sharkey49ca5292016-05-10 12:54:45 -06007107 return new DevicePolicyManager(mContext, mService, true);
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00007108 }
7109
7110 /**
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007111 * Called by device owners to retrieve device logs from before the device's last reboot.
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007112 * <p>
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01007113 * <strong> This API is not supported on all devices. Calling this API on unsupported devices
7114 * will result in {@code null} being returned. The device logs are retrieved from a RAM region
7115 * which is not guaranteed to be corruption-free during power cycles, as a result be cautious
7116 * about data corruption when parsing. </strong>
Esteban Talaverad36dd152016-12-15 08:51:45 +00007117 *
7118 * <p>If there is any other user or profile on the device, it must be affiliated with the
7119 * device owner. Otherwise a {@link SecurityException} will be thrown. See
7120 * {@link #setAffiliationIds}
Michal Karpinskib58e4962016-03-01 14:55:10 +00007121 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007122 * @param admin Which device owner this request is associated with.
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01007123 * @return Device logs from before the latest reboot of the system, or {@code null} if this API
7124 * is not supported on the device.
Esteban Talaverad36dd152016-12-15 08:51:45 +00007125 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
7126 * profile or secondary user that is not affiliated with the device owner user.
7127 * @see #retrieveSecurityLogs
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007128 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007129 public @Nullable List<SecurityEvent> retrievePreRebootSecurityLogs(
7130 @NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007131 throwIfParentInstance("retrievePreRebootSecurityLogs");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007132 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00007133 ParceledListSlice<SecurityEvent> list = mService.retrievePreRebootSecurityLogs(admin);
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01007134 if (list != null) {
7135 return list.getList();
7136 } else {
7137 return null;
7138 }
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007139 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007140 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007141 }
7142 }
7143
7144 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007145 * Called by a profile owner of a managed profile to set the color used for customization. This
7146 * color is used as background color of the confirm credentials screen for that user. The
Clara Bayarri8d0bd7fa2016-03-30 14:59:58 +01007147 * default color is teal (#00796B).
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007148 * <p>
7149 * The confirm credentials screen can be created using
Benjamin Franz59720bb2016-01-18 15:26:11 +00007150 * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}.
7151 *
7152 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinski74cd7302016-04-12 15:17:36 +01007153 * @param color The 24bit (0xRRGGBB) representation of the color to be used.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007154 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz59720bb2016-01-18 15:26:11 +00007155 */
7156 public void setOrganizationColor(@NonNull ComponentName admin, int color) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007157 throwIfParentInstance("setOrganizationColor");
Benjamin Franz59720bb2016-01-18 15:26:11 +00007158 try {
Michal Karpinski74cd7302016-04-12 15:17:36 +01007159 // always enforce alpha channel to have 100% opacity
7160 color |= 0xFF000000;
Benjamin Franz59720bb2016-01-18 15:26:11 +00007161 mService.setOrganizationColor(admin, color);
7162 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007163 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00007164 }
7165 }
7166
7167 /**
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00007168 * @hide
7169 *
7170 * Sets the color used for customization.
7171 *
Michal Karpinski74cd7302016-04-12 15:17:36 +01007172 * @param color The 24bit (0xRRGGBB) representation of the color to be used.
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00007173 * @param userId which user to set the color to.
7174 * @RequiresPermission(allOf = {
7175 * Manifest.permission.MANAGE_USERS,
7176 * Manifest.permission.INTERACT_ACROSS_USERS_FULL})
7177 */
7178 public void setOrganizationColorForUser(@ColorInt int color, @UserIdInt int userId) {
7179 try {
Michal Karpinski74cd7302016-04-12 15:17:36 +01007180 // always enforce alpha channel to have 100% opacity
7181 color |= 0xFF000000;
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00007182 mService.setOrganizationColorForUser(color, userId);
7183 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007184 throw re.rethrowFromSystemServer();
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00007185 }
7186 }
7187
7188 /**
Benjamin Franz59720bb2016-01-18 15:26:11 +00007189 * Called by a profile owner of a managed profile to retrieve the color used for customization.
7190 * This color is used as background color of the confirm credentials screen for that user.
7191 *
7192 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinski74cd7302016-04-12 15:17:36 +01007193 * @return The 24bit (0xRRGGBB) representation of the color to be used.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007194 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz59720bb2016-01-18 15:26:11 +00007195 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01007196 public @ColorInt int getOrganizationColor(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007197 throwIfParentInstance("getOrganizationColor");
Benjamin Franz59720bb2016-01-18 15:26:11 +00007198 try {
7199 return mService.getOrganizationColor(admin);
7200 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007201 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00007202 }
7203 }
7204
7205 /**
7206 * @hide
7207 * Retrieve the customization color for a given user.
7208 *
7209 * @param userHandle The user id of the user we're interested in.
Michal Karpinski74cd7302016-04-12 15:17:36 +01007210 * @return The 24bit (0xRRGGBB) representation of the color to be used.
Benjamin Franz59720bb2016-01-18 15:26:11 +00007211 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01007212 public @ColorInt int getOrganizationColorForUser(int userHandle) {
Benjamin Franz59720bb2016-01-18 15:26:11 +00007213 try {
7214 return mService.getOrganizationColorForUser(userHandle);
7215 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007216 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00007217 }
7218 }
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007219
7220 /**
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01007221 * Called by the device owner or profile owner to set the name of the organization under
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007222 * management.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007223 * <p>
7224 * If the organization name needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007225 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
7226 * and set a new version of this string accordingly.
7227 *
7228 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7229 * @param title The organization name or {@code null} to clear a previously set name.
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01007230 * @throws SecurityException if {@code admin} is not a device or profile owner.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007231 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01007232 public void setOrganizationName(@NonNull ComponentName admin, @Nullable CharSequence title) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007233 throwIfParentInstance("setOrganizationName");
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007234 try {
7235 mService.setOrganizationName(admin, title);
7236 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007237 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007238 }
7239 }
7240
7241 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007242 * Called by a profile owner of a managed profile to retrieve the name of the organization under
7243 * management.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007244 *
7245 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7246 * @return The organization name or {@code null} if none is set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007247 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007248 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007249 public @Nullable CharSequence getOrganizationName(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007250 throwIfParentInstance("getOrganizationName");
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007251 try {
7252 return mService.getOrganizationName(admin);
7253 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007254 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007255 }
7256 }
7257
7258 /**
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01007259 * Called by the system to retrieve the name of the organization managing the device.
7260 *
7261 * @return The organization name or {@code null} if none is set.
7262 * @throws SecurityException if the caller is not the device owner, does not hold the
7263 * MANAGE_USERS permission and is not the system.
7264 *
7265 * @hide
7266 */
7267 @SystemApi
7268 @TestApi
7269 public @Nullable CharSequence getDeviceOwnerOrganizationName() {
7270 try {
7271 return mService.getDeviceOwnerOrganizationName();
7272 } catch (RemoteException re) {
7273 throw re.rethrowFromSystemServer();
7274 }
7275 }
7276
7277 /**
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007278 * Retrieve the default title message used in the confirm credentials screen for a given user.
7279 *
7280 * @param userHandle The user id of the user we're interested in.
7281 * @return The organization name or {@code null} if none is set.
7282 *
7283 * @hide
7284 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007285 public @Nullable CharSequence getOrganizationNameForUser(int userHandle) {
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007286 try {
7287 return mService.getOrganizationNameForUser(userHandle);
7288 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007289 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007290 }
7291 }
7292
7293 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00007294 * @return the {@link UserProvisioningState} for the current user - for unmanaged users will
7295 * return {@link #STATE_USER_UNMANAGED}
7296 * @hide
7297 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00007298 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00007299 @UserProvisioningState
7300 public int getUserProvisioningState() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007301 throwIfParentInstance("getUserProvisioningState");
Alan Treadwayafad8782016-01-19 15:15:08 +00007302 if (mService != null) {
7303 try {
7304 return mService.getUserProvisioningState();
7305 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007306 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00007307 }
7308 }
7309 return STATE_USER_UNMANAGED;
7310 }
7311
7312 /**
7313 * Set the {@link UserProvisioningState} for the supplied user, if they are managed.
7314 *
7315 * @param state to store
7316 * @param userHandle for user
7317 * @hide
7318 */
7319 public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) {
7320 if (mService != null) {
7321 try {
7322 mService.setUserProvisioningState(state, userHandle);
7323 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007324 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00007325 }
7326 }
7327 }
7328
7329 /**
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007330 * Indicates the entity that controls the device or profile owner. Two users/profiles are
7331 * affiliated if the set of ids set by their device or profile owners intersect.
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007332 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00007333 * <p><strong>Note:</strong> Features that depend on user affiliation (such as security logging
7334 * or {@link #bindDeviceAdminServiceAsUser}) won't be available when a secondary user or profile
7335 * is created, until it becomes affiliated. Therefore it is recommended that the appropriate
7336 * affiliation ids are set by its profile owner as soon as possible after the user/profile is
7337 * created.
7338 *
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007339 * @param admin Which profile or device owner this request is associated with.
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007340 * @param ids A list of opaque non-empty affiliation ids. Duplicate elements will be ignored.
7341 *
7342 * @throws NullPointerException if {@code ids} is null or contains null elements.
7343 * @throws IllegalArgumentException if {@code ids} contains an empty string.
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007344 */
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007345 public void setAffiliationIds(@NonNull ComponentName admin, @NonNull List<String> ids) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007346 throwIfParentInstance("setAffiliationIds");
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007347 try {
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007348 mService.setAffiliationIds(admin, ids);
7349 } catch (RemoteException e) {
7350 throw e.rethrowFromSystemServer();
7351 }
7352 }
7353
7354 /**
7355 * Returns the list of affiliation ids previously set via {@link #setAffiliationIds}, or an
7356 * empty list if none have been set.
7357 */
7358 public @NonNull List<String> getAffiliationIds(@NonNull ComponentName admin) {
7359 throwIfParentInstance("getAffiliationIds");
7360 try {
7361 return mService.getAffiliationIds(admin);
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007362 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007363 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007364 }
7365 }
7366
7367 /**
7368 * @hide
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007369 * Returns whether this user/profile is affiliated with the device.
7370 * <p>
7371 * By definition, the user that the device owner runs on is always affiliated with the device.
7372 * Any other user/profile is considered affiliated with the device if the set specified by its
7373 * profile owner via {@link #setAffiliationIds} intersects with the device owner's.
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007374 *
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007375 */
7376 public boolean isAffiliatedUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007377 throwIfParentInstance("isAffiliatedUser");
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007378 try {
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007379 return mService.isAffiliatedUser();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007380 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007381 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007382 }
7383 }
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08007384
7385 /**
7386 * @hide
7387 * Returns whether the uninstall for {@code packageName} for the current user is in queue
7388 * to be started
7389 * @param packageName the package to check for
7390 * @return whether the uninstall intent for {@code packageName} is pending
7391 */
7392 public boolean isUninstallInQueue(String packageName) {
7393 try {
7394 return mService.isUninstallInQueue(packageName);
7395 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007396 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08007397 }
7398 }
7399
7400 /**
7401 * @hide
7402 * @param packageName the package containing active DAs to be uninstalled
7403 */
7404 public void uninstallPackageWithActiveAdmins(String packageName) {
7405 try {
7406 mService.uninstallPackageWithActiveAdmins(packageName);
7407 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007408 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08007409 }
7410 }
Benjamin Franzbc33c822016-04-15 08:57:52 +01007411
Kenny Guy38dcca52016-04-19 13:09:18 +01007412 /**
7413 * @hide
7414 * Remove a test admin synchronously without sending it a broadcast about being removed.
7415 * If the admin is a profile owner or device owner it will still be removed.
7416 *
7417 * @param userHandle user id to remove the admin for.
7418 * @param admin The administration compononent to remove.
7419 * @throws SecurityException if the caller is not shell / root or the admin package
7420 * isn't a test application see {@link ApplicationInfo#FLAG_TEST_APP}.
7421 */
7422 public void forceRemoveActiveAdmin(ComponentName adminReceiver, int userHandle) {
7423 try {
7424 mService.forceRemoveActiveAdmin(adminReceiver, userHandle);
7425 } catch (RemoteException re) {
7426 throw re.rethrowFromSystemServer();
7427 }
7428 }
7429
Mahaver Chopra790d1982016-07-07 16:06:49 +01007430 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007431 * Returns whether the device has been provisioned.
7432 *
7433 * <p>Not for use by third-party applications.
7434 *
Mahaver Chopra790d1982016-07-07 16:06:49 +01007435 * @hide
Mahaver Chopra790d1982016-07-07 16:06:49 +01007436 */
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007437 @SystemApi
Mahaver Chopra790d1982016-07-07 16:06:49 +01007438 public boolean isDeviceProvisioned() {
7439 try {
7440 return mService.isDeviceProvisioned();
7441 } catch (RemoteException re) {
7442 throw re.rethrowFromSystemServer();
7443 }
7444 }
7445
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007446 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007447 * Writes that the provisioning configuration has been applied.
7448 *
7449 * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS}
7450 * permission.
7451 *
7452 * <p>Not for use by third-party applications.
7453 *
7454 * @hide
7455 */
7456 @SystemApi
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007457 public void setDeviceProvisioningConfigApplied() {
7458 try {
7459 mService.setDeviceProvisioningConfigApplied();
7460 } catch (RemoteException re) {
7461 throw re.rethrowFromSystemServer();
7462 }
7463 }
7464
7465 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007466 * Returns whether the provisioning configuration has been applied.
7467 *
7468 * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS} permission.
7469 *
7470 * <p>Not for use by third-party applications.
7471 *
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007472 * @return whether the provisioning configuration has been applied.
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007473 *
7474 * @hide
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007475 */
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007476 @SystemApi
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007477 public boolean isDeviceProvisioningConfigApplied() {
7478 try {
7479 return mService.isDeviceProvisioningConfigApplied();
7480 } catch (RemoteException re) {
7481 throw re.rethrowFromSystemServer();
7482 }
7483 }
7484
Victor Chang9bfc65f2016-08-15 12:27:09 +01007485 /**
7486 * @hide
Victor Chang3577ed22016-08-25 18:49:26 +01007487 * Force update user setup completed status. This API has no effect on user build.
7488 * @throws {@link SecurityException} if the caller has no
Esteban Talavera01576862016-12-15 11:16:44 +00007489 * {@code android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS} or the caller is
7490 * not {@link UserHandle#SYSTEM_USER}
Victor Chang9bfc65f2016-08-15 12:27:09 +01007491 */
7492 public void forceUpdateUserSetupComplete() {
7493 try {
7494 mService.forceUpdateUserSetupComplete();
7495 } catch (RemoteException re) {
7496 throw re.rethrowFromSystemServer();
7497 }
7498 }
7499
Benjamin Franzbc33c822016-04-15 08:57:52 +01007500 private void throwIfParentInstance(String functionName) {
7501 if (mParentInstance) {
7502 throw new SecurityException(functionName + " cannot be called on the parent instance");
7503 }
7504 }
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007505
7506 /**
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007507 * Allows the device owner to enable or disable the backup service.
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007508 *
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007509 * <p> Backup service manages all backup and restore mechanisms on the device. Setting this to
7510 * false will prevent data from being backed up or restored.
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007511 *
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007512 * <p> Backup service is off by default when device owner is present.
7513 *
7514 * @throws SecurityException if {@code admin} is not a device owner.
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007515 */
7516 public void setBackupServiceEnabled(@NonNull ComponentName admin, boolean enabled) {
7517 try {
7518 mService.setBackupServiceEnabled(admin, enabled);
7519 } catch (RemoteException re) {
7520 throw re.rethrowFromSystemServer();
7521 }
7522 }
7523
7524 /**
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007525 * Return whether the backup service is enabled by the device owner.
7526 *
7527 * <p> Backup service manages all backup and restore mechanisms on the device.
7528 *
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007529 * @return {@code true} if backup service is enabled, {@code false} otherwise.
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007530 * @see #setBackupServiceEnabled
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007531 */
7532 public boolean isBackupServiceEnabled(@NonNull ComponentName admin) {
7533 try {
7534 return mService.isBackupServiceEnabled(admin);
7535 } catch (RemoteException re) {
7536 throw re.rethrowFromSystemServer();
7537 }
7538 }
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007539
7540 /**
Esteban Talaverad36dd152016-12-15 08:51:45 +00007541 * Called by a device owner to control the network logging feature.
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007542 *
7543 * <p> Network logs contain DNS lookup and connect() library call events.
7544 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00007545 * <p><strong>Note:</strong> The device owner won't be able to retrieve network logs if there
7546 * are unaffiliated secondary users or profiles on the device, regardless of whether the
7547 * feature is enabled. Logs will be discarded if the internal buffer fills up while waiting for
7548 * all users to become affiliated. Therefore it's recommended that affiliation ids are set for
7549 * new users as soon as possible after provisioning via {@link #setAffiliationIds}.
7550 *
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007551 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7552 * @param enabled whether network logging should be enabled or not.
Esteban Talaverad36dd152016-12-15 08:51:45 +00007553 * @throws SecurityException if {@code admin} is not a device owner.
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007554 * @see #retrieveNetworkLogs
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007555 */
7556 public void setNetworkLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
7557 throwIfParentInstance("setNetworkLoggingEnabled");
7558 try {
7559 mService.setNetworkLoggingEnabled(admin, enabled);
7560 } catch (RemoteException re) {
7561 throw re.rethrowFromSystemServer();
7562 }
7563 }
7564
7565 /**
7566 * Return whether network logging is enabled by a device owner.
7567 *
phweissa4e169e2016-11-24 16:20:57 +01007568 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Can only
7569 * be {@code null} if the caller has MANAGE_USERS permission.
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007570 * @return {@code true} if network logging is enabled by device owner, {@code false} otherwise.
Esteban Talaverad36dd152016-12-15 08:51:45 +00007571 * @throws SecurityException if {@code admin} is not a device owner and caller has
phweissa4e169e2016-11-24 16:20:57 +01007572 * no MANAGE_USERS permission
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007573 */
phweissa4e169e2016-11-24 16:20:57 +01007574 public boolean isNetworkLoggingEnabled(@Nullable ComponentName admin) {
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007575 throwIfParentInstance("isNetworkLoggingEnabled");
7576 try {
7577 return mService.isNetworkLoggingEnabled(admin);
7578 } catch (RemoteException re) {
7579 throw re.rethrowFromSystemServer();
7580 }
7581 }
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007582
7583 /**
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007584 * Called by device owner to retrieve the most recent batch of network logging events.
7585 * A device owner has to provide a batchToken provided as part of
7586 * {@link DeviceAdminReceiver#onNetworkLogsAvailable} callback. If the token doesn't match the
7587 * token of the most recent available batch of logs, {@code null} will be returned.
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007588 *
7589 * <p> {@link NetworkEvent} can be one of {@link DnsEvent} or {@link ConnectEvent}.
7590 *
7591 * <p> The list of network events is sorted chronologically, and contains at most 1200 events.
7592 *
7593 * <p> Access to the logs is rate limited and this method will only return a new batch of logs
7594 * after the device device owner has been notified via
7595 * {@link DeviceAdminReceiver#onNetworkLogsAvailable}.
7596 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00007597 * <p>If a secondary user or profile is created, calling this method will throw a
7598 * {@link SecurityException} until all users become affiliated again. It will also no longer be
7599 * possible to retrieve the network logs batch with the most recent batchToken provided
7600 * by {@link DeviceAdminReceiver#onNetworkLogsAvailable}. See
7601 * {@link DevicePolicyManager#setAffiliationIds}.
7602 *
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007603 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007604 * @param batchToken A token of the batch to retrieve
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007605 * @return A new batch of network logs which is a list of {@link NetworkEvent}. Returns
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007606 * {@code null} if the batch represented by batchToken is no longer available or if
7607 * logging is disabled.
Esteban Talaverad36dd152016-12-15 08:51:45 +00007608 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
7609 * profile or secondary user that is not affiliated with the device owner user.
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007610 * @see DeviceAdminReceiver#onNetworkLogsAvailable
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007611 */
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007612 public @Nullable List<NetworkEvent> retrieveNetworkLogs(@NonNull ComponentName admin,
7613 long batchToken) {
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007614 throwIfParentInstance("retrieveNetworkLogs");
7615 try {
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007616 return mService.retrieveNetworkLogs(admin, batchToken);
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007617 } catch (RemoteException re) {
7618 throw re.rethrowFromSystemServer();
7619 }
7620 }
Tony Mak46aabe52016-11-14 12:53:06 +00007621
7622 /**
Esteban Talavera2f897912017-01-26 10:30:48 +00007623 * Called by a device owner to bind to a service from a profile owner or vice versa.
7624 * See {@link #getBindDeviceAdminTargetUsers} for a definition of which
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007625 * device/profile owners are allowed to bind to services of another profile/device owner.
7626 * <p>
Tony Mak46aabe52016-11-14 12:53:06 +00007627 * The service must be unexported. Note that the {@link Context} used to obtain this
7628 * {@link DevicePolicyManager} instance via {@link Context#getSystemService(Class)} will be used
7629 * to bind to the {@link android.app.Service}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007630 *
Tony Mak46aabe52016-11-14 12:53:06 +00007631 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7632 * @param serviceIntent Identifies the service to connect to. The Intent must specify either an
7633 * explicit component name or a package name to match an
7634 * {@link IntentFilter} published by a service.
Tony Makbf9928d2016-12-22 11:02:45 +00007635 * @param conn Receives information as the service is started and stopped in main thread. This
7636 * must be a valid {@link ServiceConnection} object; it must not be {@code null}.
Tony Mak46aabe52016-11-14 12:53:06 +00007637 * @param flags Operation options for the binding operation. See
7638 * {@link Context#bindService(Intent, ServiceConnection, int)}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007639 * @param targetUser Which user to bind to. Must be one of the users returned by
7640 * {@link #getBindDeviceAdminTargetUsers}, otherwise a {@link SecurityException} will
7641 * be thrown.
Tony Mak46aabe52016-11-14 12:53:06 +00007642 * @return If you have successfully bound to the service, {@code true} is returned;
7643 * {@code false} is returned if the connection is not made and you will not
7644 * receive the service object.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007645 *
Tony Mak46aabe52016-11-14 12:53:06 +00007646 * @see Context#bindService(Intent, ServiceConnection, int)
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007647 * @see #getBindDeviceAdminTargetUsers(ComponentName)
Tony Mak46aabe52016-11-14 12:53:06 +00007648 */
7649 public boolean bindDeviceAdminServiceAsUser(
7650 @NonNull ComponentName admin, Intent serviceIntent, @NonNull ServiceConnection conn,
7651 @Context.BindServiceFlags int flags, @NonNull UserHandle targetUser) {
7652 throwIfParentInstance("bindDeviceAdminServiceAsUser");
7653 // Keep this in sync with ContextImpl.bindServiceCommon.
7654 try {
Tony Makbf9928d2016-12-22 11:02:45 +00007655 final IServiceConnection sd = mContext.getServiceDispatcher(
7656 conn, mContext.getMainThreadHandler(), flags);
Tony Mak46aabe52016-11-14 12:53:06 +00007657 serviceIntent.prepareToLeaveProcess(mContext);
7658 return mService.bindDeviceAdminServiceAsUser(admin,
7659 mContext.getIApplicationThread(), mContext.getActivityToken(), serviceIntent,
7660 sd, flags, targetUser.getIdentifier());
7661 } catch (RemoteException re) {
7662 throw re.rethrowFromSystemServer();
7663 }
7664 }
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007665
7666 /**
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007667 * Returns the list of target users that the calling device or profile owner can use when
7668 * calling {@link #bindDeviceAdminServiceAsUser}.
7669 * <p>
Esteban Talavera2f897912017-01-26 10:30:48 +00007670 * A device owner can bind to a service from a profile owner and vice versa, provided that:
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007671 * <ul>
7672 * <li>Both belong to the same package name.
Esteban Talavera2f897912017-01-26 10:30:48 +00007673 * <li>Both users are affiliated. See {@link #setAffiliationIds}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007674 * </ul>
7675 */
7676 public @NonNull List<UserHandle> getBindDeviceAdminTargetUsers(@NonNull ComponentName admin) {
7677 throwIfParentInstance("getBindDeviceAdminTargetUsers");
7678 try {
7679 return mService.getBindDeviceAdminTargetUsers(admin);
7680 } catch (RemoteException re) {
7681 throw re.rethrowFromSystemServer();
7682 }
7683 }
7684
7685 /**
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007686 * Called by the system to get the time at which the device owner last retrieved security
7687 * logging entries.
7688 *
7689 * @return the time at which the device owner most recently retrieved security logging entries,
7690 * in milliseconds since epoch; -1 if security logging entries were never retrieved.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007691 * @throws SecurityException if the caller is not the device owner, does not hold the
7692 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007693 *
7694 * @hide
7695 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007696 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007697 public long getLastSecurityLogRetrievalTime() {
7698 try {
7699 return mService.getLastSecurityLogRetrievalTime();
7700 } catch (RemoteException re) {
7701 throw re.rethrowFromSystemServer();
7702 }
7703 }
7704
7705 /**
7706 * Called by the system to get the time at which the device owner last requested a bug report.
7707 *
7708 * @return the time at which the device owner most recently requested a bug report, in
7709 * milliseconds since epoch; -1 if a bug report was never requested.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007710 * @throws SecurityException if the caller is not the device owner, does not hold the
7711 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007712 *
7713 * @hide
7714 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007715 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007716 public long getLastBugReportRequestTime() {
7717 try {
7718 return mService.getLastBugReportRequestTime();
7719 } catch (RemoteException re) {
7720 throw re.rethrowFromSystemServer();
7721 }
7722 }
7723
7724 /**
7725 * Called by the system to get the time at which the device owner last retrieved network logging
7726 * events.
7727 *
7728 * @return the time at which the device owner most recently retrieved network logging events, in
7729 * milliseconds since epoch; -1 if network logging events were never retrieved.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007730 * @throws SecurityException if the caller is not the device owner, does not hold the
7731 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007732 *
7733 * @hide
7734 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007735 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007736 public long getLastNetworkLogRetrievalTime() {
7737 try {
7738 return mService.getLastNetworkLogRetrievalTime();
7739 } catch (RemoteException re) {
7740 throw re.rethrowFromSystemServer();
7741 }
7742 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08007743}