blob: b0c9850108301ee33963bc81f1e045855192b847 [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;
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060023import android.annotation.RequiresPermission;
Dianne Hackbornd6847842010-01-12 18:14:19 -080024import android.annotation.SdkConstant;
25import android.annotation.SdkConstant.SdkConstantType;
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060026import android.annotation.SuppressLint;
Justin Moreyb5deda72014-07-24 10:53:40 -050027import android.annotation.SystemApi;
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060028import android.annotation.SystemService;
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +010029import android.annotation.TestApi;
Nicolas Prevot8f7698a2016-02-11 16:05:33 +000030import android.annotation.UserIdInt;
Fyodor Kupolov4e9af062016-07-18 16:59:11 -070031import android.annotation.WorkerThread;
Jason Monkd7b86212014-06-16 13:15:38 -040032import android.app.Activity;
Tony Mak46aabe52016-11-14 12:53:06 +000033import android.app.IServiceConnection;
Rubin Xuaab7a412016-12-30 21:13:29 +000034import android.app.KeyguardManager;
Michal Karpinski6235a942016-03-15 12:07:23 +000035import android.app.admin.SecurityLog.SecurityEvent;
Dianne Hackbornd6847842010-01-12 18:14:19 -080036import android.content.ComponentName;
37import android.content.Context;
Adam Connors010cfd42014-04-16 12:48:13 +010038import android.content.Intent;
Sander Alewijnsef475ca32014-02-17 15:13:58 +000039import android.content.IntentFilter;
Tony Mak46aabe52016-11-14 12:53:06 +000040import android.content.ServiceConnection;
Victor Chang98607132017-01-27 11:51:56 +000041import android.content.pm.ApplicationInfo;
Dianne Hackbornd6847842010-01-12 18:14:19 -080042import android.content.pm.PackageManager;
Victor Changcd14c0a2016-03-16 19:10:15 +000043import android.content.pm.PackageManager.NameNotFoundException;
Rubin Xuc3cd05f2016-01-11 12:11:35 +000044import android.content.pm.ParceledListSlice;
Sudheer Shanka978fc0d2016-01-28 13:51:10 +000045import android.content.pm.UserInfo;
Julia Reynoldsfca04ca2015-02-17 13:39:12 -050046import android.graphics.Bitmap;
Jason Monk03bc9912014-05-13 09:44:57 -040047import android.net.ProxyInfo;
Nicolas Prevot8b7991c2015-11-12 17:40:12 +000048import android.net.Uri;
Robin Lee66e5d962014-04-09 16:44:21 +010049import android.os.Bundle;
Victor Changc10f6692016-12-09 15:24:00 +000050import android.os.Parcelable;
Jim Millere303bf42014-08-26 17:12:29 -070051import android.os.PersistableBundle;
Adam Connors776c5552014-01-09 10:42:56 +000052import android.os.Process;
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080053import android.os.RemoteCallback;
Dianne Hackbornd6847842010-01-12 18:14:19 -080054import android.os.RemoteException;
Amith Yamasani599dd7c2012-09-14 23:20:08 -070055import android.os.UserHandle;
Julia Reynolds1e958392014-05-16 14:25:21 -040056import android.os.UserManager;
Ricky Wai494b95d2015-11-20 16:07:15 +000057import android.provider.ContactsContract.Directory;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010058import android.security.Credentials;
Amith Yamasanid1d7c022014-08-19 17:03:41 -070059import android.service.restrictions.RestrictionsReceiver;
Mahaver Chopra1216ae52016-03-11 15:39:48 +000060import android.telephony.TelephonyManager;
Tony Mak31657432017-04-25 09:29:55 +010061import android.util.ArraySet;
Dianne Hackbornd6847842010-01-12 18:14:19 -080062import android.util.Log;
63
Makoto Onukicc4bbeb2015-09-17 10:28:24 -070064import com.android.internal.annotations.VisibleForTesting;
Maggie Benthallda51e682013-08-08 22:35:44 -040065import com.android.org.conscrypt.TrustedCertificateStore;
66
67import java.io.ByteArrayInputStream;
Dianne Hackbornd6847842010-01-12 18:14:19 -080068import java.io.IOException;
Alan Treadwayafad8782016-01-19 15:15:08 +000069import java.lang.annotation.Retention;
70import java.lang.annotation.RetentionPolicy;
Oscar Montemayor69238c62010-08-03 10:51:06 -070071import java.net.InetSocketAddress;
72import java.net.Proxy;
Robin Lee0d5ccb72014-09-12 17:41:44 +010073import java.security.KeyFactory;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000074import java.security.NoSuchAlgorithmException;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010075import java.security.PrivateKey;
76import java.security.cert.Certificate;
Maggie Benthallda51e682013-08-08 22:35:44 -040077import java.security.cert.CertificateException;
78import java.security.cert.CertificateFactory;
79import java.security.cert.X509Certificate;
Robin Lee0d5ccb72014-09-12 17:41:44 +010080import java.security.spec.InvalidKeySpecException;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000081import java.security.spec.PKCS8EncodedKeySpec;
Jim Miller604e7552014-07-18 19:00:02 -070082import java.util.ArrayList;
Rubin Xub4365912016-03-23 12:13:22 +000083import java.util.Arrays;
Svetoslav976e8bd2014-07-16 15:12:03 -070084import java.util.Collections;
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -080085import java.util.List;
Tony Mak31657432017-04-25 09:29:55 +010086import java.util.Set;
Dianne Hackbornd6847842010-01-12 18:14:19 -080087
88/**
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000089 * Public interface for managing policies enforced on a device. Most clients of this class must be
Suprabh Shukla34d92ef2016-03-14 13:49:37 -070090 * registered with the system as a <a href="{@docRoot}guide/topics/admin/device-admin.html">device
91 * administrator</a>. Additionally, a device administrator may be registered as either a profile or
92 * device owner. A given method is accessible to all device administrators unless the documentation
93 * for that method specifies that it is restricted to either device or profile owners. Any
94 * application calling an api may only pass as an argument a device administrator component it
95 * owns. Otherwise, a {@link SecurityException} will be thrown.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080096 * <div class="special reference">
97 * <h3>Developer Guides</h3>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -070098 * <p>
99 * For more information about managing policies for device administration, read the <a href=
100 * "{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a> developer
101 * guide. </div>
Dianne Hackbornd6847842010-01-12 18:14:19 -0800102 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -0600103@SystemService(Context.DEVICE_POLICY_SERVICE)
Dianne Hackbornd6847842010-01-12 18:14:19 -0800104public class DevicePolicyManager {
105 private static String TAG = "DevicePolicyManager";
Dianne Hackbornd6847842010-01-12 18:14:19 -0800106
107 private final Context mContext;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800108 private final IDevicePolicyManager mService;
Esteban Talavera62399912016-01-11 15:37:55 +0000109 private final boolean mParentInstance;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700110
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600111 /** @hide */
112 public DevicePolicyManager(Context context, IDevicePolicyManager service) {
113 this(context, service, false);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800114 }
115
Dianne Hackborn87bba1e2010-02-26 17:25:54 -0800116 /** @hide */
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700117 @VisibleForTesting
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600118 protected DevicePolicyManager(Context context, IDevicePolicyManager service,
119 boolean parentInstance) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700120 mContext = context;
121 mService = service;
Esteban Talavera62399912016-01-11 15:37:55 +0000122 mParentInstance = parentInstance;
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700123 }
124
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700125 /** @hide test will override it. */
126 @VisibleForTesting
127 protected int myUserId() {
128 return UserHandle.myUserId();
129 }
130
Dianne Hackbornd6847842010-01-12 18:14:19 -0800131 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +0000132 * Activity action: Starts the provisioning flow which sets up a managed profile.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000133 *
Jessica Hummel9da60392014-05-21 12:32:57 +0100134 * <p>A managed profile allows data separation for example for the usage of a
135 * device as a personal and corporate device. The user which provisioning is started from and
136 * the managed profile share a launcher.
137 *
Andrew Solovay27f53372015-03-02 16:37:59 -0800138 * <p>This intent will typically be sent by a mobile device management application (MDM).
139 * Provisioning adds a managed profile and sets the MDM as the profile owner who has full
140 * control over the profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100141 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000142 * <p>It is possible to check if provisioning is allowed or not by querying the method
143 * {@link #isProvisioningAllowed(String)}.
144 *
145 * <p>In version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this intent must contain the
Nicolas Prevot18440252015-03-09 14:07:17 +0000146 * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700147 * As of {@link android.os.Build.VERSION_CODES#M}, it should contain the extra
Nicolas Prevot18440252015-03-09 14:07:17 +0000148 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only
149 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000150 *
Benjamin Franzea956242016-03-21 15:45:56 +0000151 * <p>The intent may also contain the following extras:
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000152 * <ul>
Benjamin Franzea956242016-03-21 15:45:56 +0000153 * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, optional </li>
154 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional, supported from
155 * {@link android.os.Build.VERSION_CODES#N}</li>
156 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
157 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
158 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Victor Chang51d84f92016-11-16 12:22:56 +0000159 * <li>{@link #EXTRA_PROVISIONING_SKIP_USER_CONSENT}, optional</li>
Victor Chang89ee2792016-11-23 12:10:55 +0000160 * <li>{@link #EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION}, optional</li>
Victor Changc10f6692016-12-09 15:24:00 +0000161 * <li>{@link #EXTRA_PROVISIONING_DISCLAIMERS}, optional</li>
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000162 * </ul>
Jessica Hummelf72078b2014-03-06 16:13:12 +0000163 *
Benjamin Franzea956242016-03-21 15:45:56 +0000164 * <p>When managed provisioning has completed, broadcasts are sent to the application specified
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000165 * in the provisioning intent. The
166 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the
167 * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in
168 * the primary profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100169 *
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000170 * <p>From version {@link android.os.Build.VERSION_CODES#O}, when managed provisioning has
171 * completed, along with the above broadcast, activity intent
Esteban Talavera4047bae2017-06-28 11:03:09 +0100172 * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the profile owner.
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000173 *
Benjamin Franzea956242016-03-21 15:45:56 +0000174 * <p>If provisioning fails, the managedProfile is removed so the device returns to its
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100175 * previous state.
Alan Treadway4582f812015-07-28 11:49:35 +0100176 *
177 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
178 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
179 * the provisioning flow was successful, although this doesn't guarantee the full flow will
180 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
181 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000182 */
183 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
184 public static final String ACTION_PROVISION_MANAGED_PROFILE
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100185 = "android.app.action.PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000186
187 /**
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000188 * Activity action: Starts the provisioning flow which sets up a managed user.
189 *
190 * <p>This intent will typically be sent by a mobile device management application (MDM).
Makoto Onuki32b30572015-12-11 14:29:51 -0800191 * Provisioning configures the user as managed user and sets the MDM as the profile
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000192 * owner who has full control over the user. Provisioning can only happen before user setup has
193 * been completed. Use {@link #isProvisioningAllowed(String)} to check if provisioning is
194 * allowed.
195 *
Benjamin Franzea956242016-03-21 15:45:56 +0000196 * <p>The intent contains the following extras:
197 * <ul>
198 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
199 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
200 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
201 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
202 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
203 * </ul>
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000204 *
Benjamin Franzea956242016-03-21 15:45:56 +0000205 * <p>If provisioning fails, the device returns to its previous state.
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000206 *
207 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
208 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
209 * the provisioning flow was successful, although this doesn't guarantee the full flow will
210 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
211 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Benjamin Franzea956242016-03-21 15:45:56 +0000212 *
213 * @hide
Mahaver Chopra5e732562015-11-05 11:55:12 +0000214 */
215 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
216 public static final String ACTION_PROVISION_MANAGED_USER
217 = "android.app.action.PROVISION_MANAGED_USER";
218
219 /**
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100220 * Activity action: Starts the provisioning flow which sets up a managed device.
221 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
222 *
223 * <p> During device owner provisioning a device admin app is set as the owner of the device.
224 * A device owner has full control over the device. The device owner can not be modified by the
225 * user.
226 *
227 * <p> A typical use case would be a device that is owned by a company, but used by either an
228 * employee or client.
229 *
230 * <p> An intent with this action can be sent only on an unprovisioned device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000231 * It is possible to check if provisioning is allowed or not by querying the method
232 * {@link #isProvisioningAllowed(String)}.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100233 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000234 * <p>The intent contains the following extras:
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100235 * <ul>
236 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
237 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
238 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
Rubin Xua4f9dc12015-06-12 13:27:59 +0100239 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000240 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000241 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Victor Changc10f6692016-12-09 15:24:00 +0000242 * <li>{@link #EXTRA_PROVISIONING_DISCLAIMERS}, optional</li>
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100243 * </ul>
244 *
Benjamin Franzea956242016-03-21 15:45:56 +0000245 * <p>When device owner provisioning has completed, an intent of the type
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100246 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
247 * device owner.
248 *
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000249 * <p>From version {@link android.os.Build.VERSION_CODES#O}, when device owner provisioning has
250 * completed, along with the above broadcast, activity intent
251 * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the device owner.
252 *
Benjamin Franzea956242016-03-21 15:45:56 +0000253 * <p>If provisioning fails, the device is factory reset.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100254 *
Alan Treadway4582f812015-07-28 11:49:35 +0100255 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
256 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
257 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
258 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100259 */
260 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
261 public static final String ACTION_PROVISION_MANAGED_DEVICE
262 = "android.app.action.PROVISION_MANAGED_DEVICE";
263
264 /**
Victor Chang18800092017-04-11 19:41:43 +0100265 * Activity action: launch when user provisioning completed, i.e.
266 * {@link #getUserProvisioningState()} returns one of the complete state.
267 *
268 * <p> Please note that the API behavior is not necessarily consistent across various releases,
269 * and devices, as it's contract between SetupWizard and ManagedProvisioning. The default
270 * implementation is that ManagedProvisioning launches SetupWizard in NFC provisioning only.
271 *
272 * <p> The activity must be protected by permission
273 * {@link android.Manifest.permission#BIND_DEVICE_ADMIN}, and the process must hold
274 * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE} to be launched.
275 * Only one {@link ComponentName} in the entire system should be enabled, and the rest of the
276 * components are not started by this intent.
277 * @hide
278 */
279 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
Jeff Sharkey90396362017-06-12 16:26:53 -0600280 @SystemApi
Victor Chang18800092017-04-11 19:41:43 +0100281 public static final String ACTION_STATE_USER_SETUP_COMPLETE =
282 "android.app.action.STATE_USER_SETUP_COMPLETE";
283
284 /**
Alan Treadway46dd4492015-11-09 13:57:19 +0000285 * Activity action: Starts the provisioning flow which sets up a managed device.
Steven Ng980a1b62016-02-02 17:43:18 +0000286 *
287 * <p>During device owner provisioning, a device admin app is downloaded and set as the owner of
288 * the device. A device owner has full control over the device. The device owner can not be
289 * modified by the user and the only way of resetting the device is via factory reset.
290 *
291 * <p>A typical use case would be a device that is owned by a company, but used by either an
292 * employee or client.
293 *
294 * <p>The provisioning message should be sent to an unprovisioned device.
295 *
296 * <p>Unlike {@link #ACTION_PROVISION_MANAGED_DEVICE}, the provisioning message can only be sent
297 * by a privileged app with the permission
298 * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE}.
299 *
300 * <p>The provisioning intent contains the following properties:
301 * <ul>
302 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
303 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
304 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
305 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Victor Chang38cfd9c2017-01-04 17:41:11 +0000306 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL}, optional</li>
307 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI}, optional</li>
Steven Ng980a1b62016-02-02 17:43:18 +0000308 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
309 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
310 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
311 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
312 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
313 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
314 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
315 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
316 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
317 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
318 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
Victor Chang38cfd9c2017-01-04 17:41:11 +0000319 * <li>{@link #EXTRA_PROVISIONING_SUPPORT_URL}, optional</li>
320 * <li>{@link #EXTRA_PROVISIONING_ORGANIZATION_NAME}, optional</li>
Steven Ng980a1b62016-02-02 17:43:18 +0000321 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li></ul>
322 *
323 * @hide
324 */
325 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
326 @SystemApi
327 public static final String ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE =
328 "android.app.action.PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE";
329
330 /**
331 * Activity action: Starts the provisioning flow which sets up a managed device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000332 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
333 *
334 * <p>NOTE: This is only supported on split system user devices, and puts the device into a
335 * management state that is distinct from that reached by
336 * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system
337 * user, and only has control over device-wide policies, not individual users and their data.
338 * The primary benefit is that multiple non-system users are supported when provisioning using
339 * this form of device management.
340 *
Benjamin Franzea956242016-03-21 15:45:56 +0000341 * <p>During device owner provisioning a device admin app is set as the owner of the device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000342 * A device owner has full control over the device. The device owner can not be modified by the
343 * user.
344 *
Benjamin Franzea956242016-03-21 15:45:56 +0000345 * <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 +0000346 * employee or client.
347 *
Benjamin Franzea956242016-03-21 15:45:56 +0000348 * <p>An intent with this action can be sent only on an unprovisioned device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000349 * It is possible to check if provisioning is allowed or not by querying the method
350 * {@link #isProvisioningAllowed(String)}.
351 *
352 * <p>The intent contains the following extras:
353 * <ul>
354 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
355 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
356 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
357 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Benjamin Franzea956242016-03-21 15:45:56 +0000358 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
359 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Alan Treadway46dd4492015-11-09 13:57:19 +0000360 * </ul>
361 *
Benjamin Franzea956242016-03-21 15:45:56 +0000362 * <p>When device owner provisioning has completed, an intent of the type
Alan Treadway46dd4492015-11-09 13:57:19 +0000363 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
364 * device owner.
365 *
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000366 * <p>From version {@link android.os.Build.VERSION_CODES#O}, when device owner provisioning has
367 * completed, along with the above broadcast, activity intent
368 * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the device owner.
369 *
Benjamin Franzea956242016-03-21 15:45:56 +0000370 * <p>If provisioning fails, the device is factory reset.
Alan Treadway46dd4492015-11-09 13:57:19 +0000371 *
372 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
373 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
374 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
375 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
376 *
377 * @hide
378 */
379 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
380 public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE
381 = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE";
382
383 /**
Alan Treadwayafad8782016-01-19 15:15:08 +0000384 * Activity action: Finalizes management provisioning, should be used after user-setup
385 * has been completed and {@link #getUserProvisioningState()} returns one of:
386 * <ul>
387 * <li>{@link #STATE_USER_SETUP_INCOMPLETE}</li>
388 * <li>{@link #STATE_USER_SETUP_COMPLETE}</li>
389 * <li>{@link #STATE_USER_PROFILE_COMPLETE}</li>
390 * </ul>
391 *
392 * @hide
393 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +0000394 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +0000395 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
396 public static final String ACTION_PROVISION_FINALIZATION
397 = "android.app.action.PROVISION_FINALIZATION";
398
399 /**
Michal Karpinskiba244092016-02-25 17:28:24 +0000400 * Action: Bugreport sharing with device owner has been accepted by the user.
401 *
402 * @hide
403 */
404 public static final String ACTION_BUGREPORT_SHARING_ACCEPTED =
Rubin Xu7226c7d2017-02-06 17:18:50 +0000405 "com.android.server.action.REMOTE_BUGREPORT_SHARING_ACCEPTED";
Michal Karpinskiba244092016-02-25 17:28:24 +0000406
407 /**
408 * Action: Bugreport sharing with device owner has been declined by the user.
409 *
410 * @hide
411 */
412 public static final String ACTION_BUGREPORT_SHARING_DECLINED =
Rubin Xu7226c7d2017-02-06 17:18:50 +0000413 "com.android.server.action.REMOTE_BUGREPORT_SHARING_DECLINED";
Michal Karpinskiba244092016-02-25 17:28:24 +0000414
415 /**
Esteban Talavera01576862016-12-15 11:16:44 +0000416 * Action: Bugreport has been collected and is dispatched to {@code DevicePolicyManagerService}.
Michal Karpinskiba244092016-02-25 17:28:24 +0000417 *
418 * @hide
419 */
420 public static final String ACTION_REMOTE_BUGREPORT_DISPATCH =
421 "android.intent.action.REMOTE_BUGREPORT_DISPATCH";
422
423 /**
424 * Extra for shared bugreport's SHA-256 hash.
425 *
426 * @hide
427 */
428 public static final String EXTRA_REMOTE_BUGREPORT_HASH =
429 "android.intent.extra.REMOTE_BUGREPORT_HASH";
430
431 /**
432 * Extra for remote bugreport notification shown type.
433 *
434 * @hide
435 */
436 public static final String EXTRA_BUGREPORT_NOTIFICATION_TYPE =
437 "android.app.extra.bugreport_notification_type";
438
439 /**
440 * Notification type for a started remote bugreport flow.
441 *
442 * @hide
443 */
444 public static final int NOTIFICATION_BUGREPORT_STARTED = 1;
445
446 /**
447 * Notification type for a bugreport that has already been accepted to be shared, but is still
448 * being taken.
449 *
450 * @hide
451 */
452 public static final int NOTIFICATION_BUGREPORT_ACCEPTED_NOT_FINISHED = 2;
453
454 /**
455 * Notification type for a bugreport that has been taken and can be shared or declined.
456 *
457 * @hide
458 */
459 public static final int NOTIFICATION_BUGREPORT_FINISHED_NOT_ACCEPTED = 3;
460
461 /**
Michal Karpinski8f010dd2016-06-21 15:05:53 +0100462 * Default and maximum timeout in milliseconds after which unlocking with weak auth times out,
463 * i.e. the user has to use a strong authentication method like password, PIN or pattern.
464 *
465 * @hide
466 */
467 public static final long DEFAULT_STRONG_AUTH_TIMEOUT_MS = 72 * 60 * 60 * 1000; // 72h
468
469 /**
Rubin Xua4f9dc12015-06-12 13:27:59 +0100470 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100471 * allows a mobile device management application or NFC programmer application which starts
472 * managed provisioning to pass data to the management application instance after provisioning.
Rubin Xua4f9dc12015-06-12 13:27:59 +0100473 * <p>
474 * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that
475 * sends the intent to pass data to itself on the newly created profile.
476 * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same
477 * instance of the app on the primary user.
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100478 * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with
479 * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC
480 * message should contain a stringified {@link java.util.Properties} instance, whose string
481 * properties will be converted into a {@link android.os.PersistableBundle} and passed to the
482 * management application after provisioning.
483 *
Rubin Xua4f9dc12015-06-12 13:27:59 +0100484 * <p>
485 * In both cases the application receives the data in
Brian Carlstromf1fe51b2014-09-03 08:55:05 -0700486 * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action
487 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed
Rubin Xua4f9dc12015-06-12 13:27:59 +0100488 * during the managed provisioning.
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100489 */
490 public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE =
Esteban Talavera37f01842014-09-05 10:50:57 +0100491 "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE";
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100492
493 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100494 * A String extra holding the package name of the mobile device management application that
495 * will be set as the profile owner or device owner.
496 *
497 * <p>If an application starts provisioning directly via an intent with action
498 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
499 * application that started provisioning. The package will be set as profile owner in that case.
500 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000501 * <p>This package is set as device owner when device owner provisioning is started by an NFC
502 * message containing an NFC record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000503 *
504 * <p> When this extra is set, the application must have exactly one device admin receiver.
Robin Lee25e26452015-06-02 09:56:29 -0700505 * This receiver will be set as the profile or device owner and active admin.
Benjamin Franzea956242016-03-21 15:45:56 +0000506 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000507 * @see DeviceAdminReceiver
508 * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still
Nicolas Prevot8f78d6a2015-08-21 11:06:31 +0100509 * supported, but only if there is only one device admin receiver in the package that requires
510 * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000511 */
Nicolas Prevot18440252015-03-09 14:07:17 +0000512 @Deprecated
Jessica Hummelf72078b2014-03-06 16:13:12 +0000513 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100514 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000515
516 /**
Nicolas Prevot18440252015-03-09 14:07:17 +0000517 * A ComponentName extra indicating the device admin receiver of the mobile device management
518 * application that will be set as the profile owner or device owner and active admin.
519 *
520 * <p>If an application starts provisioning directly via an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100521 * {@link #ACTION_PROVISION_MANAGED_PROFILE} or
522 * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this
523 * component has to match the package name of the application that started provisioning.
Nicolas Prevot18440252015-03-09 14:07:17 +0000524 *
525 * <p>This component is set as device owner and active admin when device owner provisioning is
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100526 * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC
527 * message containing an NFC record with MIME type
Benjamin Franzea956242016-03-21 15:45:56 +0000528 * {@link #MIME_TYPE_PROVISIONING_NFC}. For the NFC record, the component name must be
Rubin Xu44ef750b2015-03-23 16:51:33 +0000529 * flattened to a string, via {@link ComponentName#flattenToShortString()}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000530 *
531 * @see DeviceAdminReceiver
532 */
533 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME
534 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME";
535
536 /**
Alexandra Gherghinaaaf2f3e2014-11-13 12:46:15 +0000537 * An {@link android.accounts.Account} extra holding the account to migrate during managed
538 * profile provisioning. If the account supplied is present in the primary user, it will be
539 * copied, along with its credentials to the managed profile and removed from the primary user.
540 *
541 * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}.
542 */
543
544 public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE
545 = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE";
546
547 /**
Victor Changaa9cbc02016-12-05 20:50:57 +0000548 * Boolean extra to indicate that the migrated account should be kept. This is used in
549 * conjunction with {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}. If it's set to {@code true},
550 * the account will not be removed from the primary user after it is migrated to the newly
551 * created user or profile.
Victor Chang89ee2792016-11-23 12:10:55 +0000552 *
553 * <p> Defaults to {@code false}
554 *
Victor Changaa9cbc02016-12-05 20:50:57 +0000555 * <p> Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
556 * {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}
Victor Chang89ee2792016-11-23 12:10:55 +0000557 */
558 public static final String EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION
559 = "android.app.extra.PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION";
560
561 /**
Mahaver761ce772017-03-13 16:40:45 +0000562 * @deprecated From {@link android.os.Build.VERSION_CODES#O}, never used while provisioning the
563 * device.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100564 */
Mahaver761ce772017-03-13 16:40:45 +0000565 @Deprecated
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100566 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
567 = "android.app.extra.PROVISIONING_EMAIL_ADDRESS";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100568
569 /**
Nicolas Prevotcd2d8592015-11-23 13:27:21 +0000570 * A integer extra indicating the predominant color to show during the provisioning.
571 * Refer to {@link android.graphics.Color} for how the color is represented.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000572 *
573 * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or
574 * {@link #ACTION_PROVISION_MANAGED_DEVICE}.
575 */
576 public static final String EXTRA_PROVISIONING_MAIN_COLOR =
577 "android.app.extra.PROVISIONING_MAIN_COLOR";
578
579 /**
Sander Alewijnse8c411562014-11-12 18:03:11 +0000580 * A Boolean extra that can be used by the mobile device management application to skip the
Robin Lee25e26452015-06-02 09:56:29 -0700581 * disabling of system apps during provisioning when set to {@code true}.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000582 *
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100583 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
584 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000585 */
Sander Alewijnse5a144252014-11-18 13:25:04 +0000586 public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED =
587 "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED";
Sander Alewijnse8c411562014-11-12 18:03:11 +0000588
589 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100590 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
591 * will be set to.
592 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000593 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
594 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100595 */
596 public static final String EXTRA_PROVISIONING_TIME_ZONE
Esteban Talavera37f01842014-09-05 10:50:57 +0100597 = "android.app.extra.PROVISIONING_TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100598
599 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100600 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
601 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100602 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000603 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
604 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100605 */
606 public static final String EXTRA_PROVISIONING_LOCAL_TIME
Esteban Talavera37f01842014-09-05 10:50:57 +0100607 = "android.app.extra.PROVISIONING_LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100608
609 /**
610 * A String extra holding the {@link java.util.Locale} that the device will be set to.
611 * Format: xx_yy, where xx is the language code, and yy the country code.
612 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000613 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
614 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100615 */
616 public static final String EXTRA_PROVISIONING_LOCALE
Esteban Talavera37f01842014-09-05 10:50:57 +0100617 = "android.app.extra.PROVISIONING_LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100618
619 /**
620 * A String extra holding the ssid of the wifi network that should be used during nfc device
621 * owner provisioning for downloading the mobile device management application.
622 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000623 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
624 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100625 */
626 public static final String EXTRA_PROVISIONING_WIFI_SSID
Esteban Talavera37f01842014-09-05 10:50:57 +0100627 = "android.app.extra.PROVISIONING_WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100628
629 /**
630 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
631 * is hidden or not.
632 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000633 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
634 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100635 */
636 public static final String EXTRA_PROVISIONING_WIFI_HIDDEN
Esteban Talavera37f01842014-09-05 10:50:57 +0100637 = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100638
639 /**
640 * A String extra indicating the security type of the wifi network in
Mahaver Chopra76b08a92015-10-08 17:58:45 +0100641 * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or
642 * {@code WEP}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100643 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000644 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
645 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100646 */
647 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
Esteban Talavera37f01842014-09-05 10:50:57 +0100648 = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100649
650 /**
651 * A String extra holding the password of the wifi network in
652 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
653 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000654 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
655 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100656 */
657 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talavera37f01842014-09-05 10:50:57 +0100658 = "android.app.extra.PROVISIONING_WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100659
660 /**
661 * A String extra holding the proxy host for the wifi network in
662 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
663 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000664 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
665 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100666 */
667 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
Esteban Talavera37f01842014-09-05 10:50:57 +0100668 = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100669
670 /**
671 * An int extra holding the proxy port for the wifi network in
672 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
673 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000674 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
675 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100676 */
677 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
Esteban Talavera37f01842014-09-05 10:50:57 +0100678 = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100679
680 /**
681 * A String extra holding the proxy bypass for the wifi network in
682 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
683 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000684 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
685 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100686 */
687 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
Esteban Talavera37f01842014-09-05 10:50:57 +0100688 = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100689
690 /**
691 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
692 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
693 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000694 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
695 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100696 */
697 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
Esteban Talavera37f01842014-09-05 10:50:57 +0100698 = "android.app.extra.PROVISIONING_WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100699
700 /**
701 * A String extra holding a url that specifies the download location of the device admin
702 * package. When not provided it is assumed that the device admin package is already installed.
703 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000704 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
705 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100706 */
707 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talavera37f01842014-09-05 10:50:57 +0100708 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100709
710 /**
Victor Chang38cfd9c2017-01-04 17:41:11 +0000711 * A String extra holding the localized name of the organization under management.
712 *
713 * The name is displayed only during provisioning.
714 *
715 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE}
716 *
717 * @hide
718 */
719 @SystemApi
720 public static final String EXTRA_PROVISIONING_ORGANIZATION_NAME =
721 "android.app.extra.PROVISIONING_ORGANIZATION_NAME";
722
723 /**
Alejandro Fernándezbfd61932017-04-04 19:33:01 +0100724 * A String extra holding a url to the website of the device provider so the user can open it
725 * during provisioning. If the url is not HTTPS, an error will be shown.
Victor Chang38cfd9c2017-01-04 17:41:11 +0000726 *
727 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE}
728 *
729 * @hide
730 */
731 @SystemApi
732 public static final String EXTRA_PROVISIONING_SUPPORT_URL =
733 "android.app.extra.PROVISIONING_SUPPORT_URL";
734
735 /**
736 * A String extra holding the localized name of the device admin package. It should be the same
737 * as the app label of the package.
738 *
739 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE}
740 *
741 * @hide
742 */
743 @SystemApi
744 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL =
745 "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL";
746
747 /**
748 * A {@link Uri} extra pointing to the app icon of device admin package. This image will be
749 * shown during the provisioning.
750 * <h5>The following URI schemes are accepted:</h5>
751 * <ul>
752 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
753 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
754 * </ul>
755 *
756 * <p> It is the responsibility of the caller to provide an image with a reasonable
757 * pixel density for the device.
758 *
759 * <p> If a content: URI is passed, the intent should have the flag
760 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
761 * {@link android.content.ClipData} of the intent too.
762 *
763 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE}
764 *
765 * @hide
766 */
767 @SystemApi
768 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI =
769 "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI";
770
771 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400772 * An int extra holding a minimum required version code for the device admin package. If the
773 * device admin is already installed on the device, it will only be re-downloaded from
774 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the
775 * installed package is less than this version code.
776 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400777 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400778 * provisioning via an NFC bump.
779 */
780 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE
781 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE";
782
783 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100784 * A String extra holding a http cookie header which should be used in the http request to the
785 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
786 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000787 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
788 * provisioning via an NFC bump.
Sander Alewijnse681bce92014-07-24 16:46:26 +0100789 */
790 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talavera37f01842014-09-05 10:50:57 +0100791 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100792
793 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100794 * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of
795 * the file at download location specified in
796 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100797 *
Benjamin Franzea956242016-03-21 15:45:56 +0000798 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} must be
799 * present. The provided checksum must match the checksum of the file at the download
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100800 * location. If the checksum doesn't match an error will be shown to the user and the user will
801 * be asked to factory reset the device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100802 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000803 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
804 * provisioning via an NFC bump.
Rubin Xud92e7572015-05-18 17:01:13 +0100805 *
806 * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP}
807 * and {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1} only SHA-1 hash is supported.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700808 * Starting from {@link android.os.Build.VERSION_CODES#M}, this parameter accepts SHA-256 in
Rubin Xud92e7572015-05-18 17:01:13 +0100809 * addition to SHA-1. Support for SHA-1 is likely to be removed in future OS releases.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100810 */
811 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100812 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100813
814 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100815 * A String extra holding the URL-safe base64 encoded SHA-256 checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100816 * android package archive at the download location specified in {@link
817 * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
818 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100819 * <p>The signatures of an android package archive can be obtained using
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100820 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
821 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
822 *
Benjamin Franzea956242016-03-21 15:45:56 +0000823 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} must be
824 * present. The provided checksum must match the checksum of any signature of the file at
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100825 * the download location. If the checksum does not match an error will be shown to the user and
826 * the user will be asked to factory reset the device.
827 *
828 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
829 * provisioning via an NFC bump.
830 */
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100831 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM
832 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM";
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100833
834 /**
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000835 * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile
836 * has completed successfully.
837 *
838 * <p>The broadcast is limited to the primary profile, to the app specified in the provisioning
Nicolas Prevotebe2d992015-05-12 18:14:53 -0700839 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000840 *
Mahaver7074caf2016-11-29 20:52:18 +0000841 * <p>This intent will contain the following extras
842 * <ul>
843 * <li>{@link Intent#EXTRA_USER}, corresponds to the {@link UserHandle} of the managed
844 * profile.</li>
845 * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, corresponds to the account requested to
846 * be migrated at provisioning time, if any.</li>
847 * </ul>
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000848 */
849 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
850 public static final String ACTION_MANAGED_PROFILE_PROVISIONED
851 = "android.app.action.MANAGED_PROFILE_PROVISIONED";
852
853 /**
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000854 * Activity action: This activity action is sent to indicate that provisioning of a managed
855 * profile or managed device has completed successfully. It'll be sent at the same time as
856 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast but this will be
857 * delivered faster as it's an activity intent.
858 *
Esteban Talavera4047bae2017-06-28 11:03:09 +0100859 * <p>The intent is only sent to the new device or profile owner.
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000860 *
861 * @see #ACTION_PROVISION_MANAGED_PROFILE
862 * @see #ACTION_PROVISION_MANAGED_DEVICE
863 */
864 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
865 public static final String ACTION_PROVISIONING_SUCCESSFUL =
866 "android.app.action.PROVISIONING_SUCCESSFUL";
867
868 /**
Benjamin Franzea956242016-03-21 15:45:56 +0000869 * A boolean extra indicating whether device encryption can be skipped as part of device owner
870 * or managed profile provisioning.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500871 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400872 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100873 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Benjamin Franzea956242016-03-21 15:45:56 +0000874 *
875 * <p>From {@link android.os.Build.VERSION_CODES#N} onwards, this is also supported for an
876 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500877 */
878 public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION =
879 "android.app.extra.PROVISIONING_SKIP_ENCRYPTION";
880
881 /**
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000882 * A {@link Uri} extra pointing to a logo image. This image will be shown during the
883 * provisioning. If this extra is not passed, a default image will be shown.
884 * <h5>The following URI schemes are accepted:</h5>
885 * <ul>
886 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
887 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
888 * </ul>
889 *
Victor Changc10f6692016-12-09 15:24:00 +0000890 * <p> It is the responsibility of the caller to provide an image with a reasonable
Victor Chang38cfd9c2017-01-04 17:41:11 +0000891 * pixel density for the device.
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000892 *
893 * <p> If a content: URI is passed, the intent should have the flag
894 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
895 * {@link android.content.ClipData} of the intent too.
896 *
897 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or
898 * {@link #ACTION_PROVISION_MANAGED_DEVICE}
899 */
900 public static final String EXTRA_PROVISIONING_LOGO_URI =
901 "android.app.extra.PROVISIONING_LOGO_URI";
902
903 /**
Victor Changc10f6692016-12-09 15:24:00 +0000904 * A {@link Bundle}[] extra consisting of list of disclaimer headers and disclaimer contents.
905 * Each {@link Bundle} must have both {@link #EXTRA_PROVISIONING_DISCLAIMER_HEADER}
906 * as disclaimer header, and {@link #EXTRA_PROVISIONING_DISCLAIMER_CONTENT} as disclaimer
907 * content.
908 *
909 * <p> The extra typically contains one disclaimer from the company of mobile device
910 * management application (MDM), and one disclaimer from the organization.
911 *
912 * <p> Call {@link Bundle#putParcelableArray(String, Parcelable[])} to put the {@link Bundle}[]
913 *
914 * <p> Maximum 3 key-value pairs can be specified. The rest will be ignored.
915 *
916 * <p> Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or
917 * {@link #ACTION_PROVISION_MANAGED_DEVICE}
918 */
919 public static final String EXTRA_PROVISIONING_DISCLAIMERS =
920 "android.app.extra.PROVISIONING_DISCLAIMERS";
921
922 /**
923 * A String extra of localized disclaimer header.
924 *
925 * <p> The extra is typically the company name of mobile device management application (MDM)
926 * or the organization name.
927 *
928 * <p> Use in Bundle {@link #EXTRA_PROVISIONING_DISCLAIMERS}
Victor Chang98607132017-01-27 11:51:56 +0000929 *
930 * <p> System app, i.e. application with {@link ApplicationInfo#FLAG_SYSTEM}, can also insert a
931 * disclaimer by declaring an application-level meta-data in {@code AndroidManifest.xml}.
932 * Must use it with {@link #EXTRA_PROVISIONING_DISCLAIMER_CONTENT}. Here is the example:
933 *
934 * <pre>
935 * &lt;meta-data
936 * android:name="android.app.extra.PROVISIONING_DISCLAIMER_HEADER"
937 * android:resource="@string/disclaimer_header"
938 * /&gt;</pre>
Victor Changc10f6692016-12-09 15:24:00 +0000939 */
940 public static final String EXTRA_PROVISIONING_DISCLAIMER_HEADER =
941 "android.app.extra.PROVISIONING_DISCLAIMER_HEADER";
942
943 /**
944 * A {@link Uri} extra pointing to disclaimer content.
945 *
946 * <h5>The following URI schemes are accepted:</h5>
947 * <ul>
948 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
949 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
950 * </ul>
951 *
952 * <p> Styled text is supported in the disclaimer content. The content is parsed by
953 * {@link android.text.Html#fromHtml(String)} and displayed in a
954 * {@link android.widget.TextView}.
955 *
956 * <p> If a <code>content:</code> URI is passed, URI is passed, the intent should have the flag
957 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
958 * {@link android.content.ClipData} of the intent too.
959 *
960 * <p> Use in Bundle {@link #EXTRA_PROVISIONING_DISCLAIMERS}
Victor Chang98607132017-01-27 11:51:56 +0000961 *
962 * <p> System app, i.e. application with {@link ApplicationInfo#FLAG_SYSTEM}, can also insert a
963 * disclaimer by declaring an application-level meta-data in {@code AndroidManifest.xml}.
964 * Must use it with {@link #EXTRA_PROVISIONING_DISCLAIMER_HEADER}. Here is the example:
965 *
966 * <pre>
967 * &lt;meta-data
968 * android:name="android.app.extra.PROVISIONING_DISCLAIMER_CONTENT"
969 * android:resource="@string/disclaimer_content"
970 * /&gt;</pre>
Victor Changc10f6692016-12-09 15:24:00 +0000971 */
972 public static final String EXTRA_PROVISIONING_DISCLAIMER_CONTENT =
973 "android.app.extra.PROVISIONING_DISCLAIMER_CONTENT";
974
975 /**
Alan Treadway94de8c82016-01-11 10:25:23 +0000976 * A boolean extra indicating if user setup should be skipped, for when provisioning is started
977 * during setup-wizard.
978 *
979 * <p>If unspecified, defaults to {@code true} to match the behavior in
980 * {@link android.os.Build.VERSION_CODES#M} and earlier.
981 *
Alan Treadway1a538d02016-01-18 16:42:30 +0000982 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or
983 * {@link #ACTION_PROVISION_MANAGED_USER}.
Alan Treadway94de8c82016-01-11 10:25:23 +0000984 *
985 * @hide
986 */
987 public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP =
988 "android.app.extra.PROVISIONING_SKIP_USER_SETUP";
989
990 /**
Victor Chang51d84f92016-11-16 12:22:56 +0000991 * A boolean extra indicating if the user consent steps from the provisioning flow should be
992 * skipped. If unspecified, defaults to {@code false}.
993 *
994 * It can only be used by an existing device owner trying to create a managed profile via
995 * {@link #ACTION_PROVISION_MANAGED_PROFILE}. Otherwise it is ignored.
996 */
997 public static final String EXTRA_PROVISIONING_SKIP_USER_CONSENT =
998 "android.app.extra.PROVISIONING_SKIP_USER_CONSENT";
999
1000 /**
Benjamin Franzea956242016-03-21 15:45:56 +00001001 * This MIME type is used for starting the device owner provisioning.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +01001002 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -04001003 * <p>During device owner provisioning a device admin app is set as the owner of the device.
1004 * A device owner has full control over the device. The device owner can not be modified by the
1005 * user and the only way of resetting the device is if the device owner app calls a factory
1006 * reset.
1007 *
1008 * <p> A typical use case would be a device that is owned by a company, but used by either an
1009 * employee or client.
1010 *
Benjamin Franzea956242016-03-21 15:45:56 +00001011 * <p> The NFC message must be sent to an unprovisioned device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +01001012 *
Sander Alewijnse8c411562014-11-12 18:03:11 +00001013 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +01001014 * contains the following properties:
1015 * <ul>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -04001016 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
1017 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +01001018 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -04001019 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +01001020 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
1021 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
1022 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
1023 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
1024 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
1025 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
1026 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
1027 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
1028 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
1029 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Rubin Xu41f2ccb92015-08-05 16:29:13 +01001030 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
1031 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from
1032 * {@link android.os.Build.VERSION_CODES#M} </li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +01001033 *
Nicolas Prevot18440252015-03-09 14:07:17 +00001034 * <p>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07001035 * As of {@link android.os.Build.VERSION_CODES#M}, the properties should contain
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -04001036 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of
1037 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only
1038 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -04001039 */
1040 public static final String MIME_TYPE_PROVISIONING_NFC
1041 = "application/com.android.managedprovisioning";
1042
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +01001043 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001044 * Activity action: ask the user to add a new device administrator to the system.
1045 * The desired policy is the ComponentName of the policy in the
1046 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
1047 * bring the user through adding the device administrator to the system (or
1048 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001049 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001050 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
1051 * field to provide the user with additional explanation (in addition
1052 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001053 *
1054 * <p>If your administrator is already active, this will ordinarily return immediately (without
1055 * user intervention). However, if your administrator has been updated and is requesting
1056 * additional uses-policy flags, the user will be presented with the new list. New policies
1057 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001058 */
1059 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1060 public static final String ACTION_ADD_DEVICE_ADMIN
1061 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001062
Dianne Hackbornd6847842010-01-12 18:14:19 -08001063 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001064 * @hide
1065 * Activity action: ask the user to add a new device administrator as the profile owner
Amith Yamasani814e9872015-03-23 14:04:53 -07001066 * for this user. Only system apps can launch this intent.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001067 *
Amith Yamasani814e9872015-03-23 14:04:53 -07001068 * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN}
1069 * extra field. This will invoke a UI to bring the user through adding the profile owner admin
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001070 * to remotely control restrictions on the user.
1071 *
Makoto Onukic8a5a552015-11-19 14:29:12 -08001072 * <p>The intent must be invoked via {@link Activity#startActivityForResult} to receive the
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001073 * result of whether or not the user approved the action. If approved, the result will
1074 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
1075 * as a profile owner.
1076 *
1077 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
1078 * field to provide the user with additional explanation (in addition
1079 * to your component's description) about what is being added.
1080 *
Amith Yamasani814e9872015-03-23 14:04:53 -07001081 * <p>If there is already a profile owner active or the caller is not a system app, the
1082 * operation will return a failure result.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001083 */
1084 @SystemApi
1085 public static final String ACTION_SET_PROFILE_OWNER
1086 = "android.app.action.SET_PROFILE_OWNER";
1087
1088 /**
1089 * @hide
1090 * Name of the profile owner admin that controls the user.
1091 */
1092 @SystemApi
1093 public static final String EXTRA_PROFILE_OWNER_NAME
1094 = "android.app.extra.PROFILE_OWNER_NAME";
1095
1096 /**
Nicolas Prevot00799002015-07-27 18:15:20 +01001097 * Broadcast action: send when any policy admin changes a policy.
Jim Miller284b62e2010-06-08 14:27:42 -07001098 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -07001099 *
Jim Miller284b62e2010-06-08 14:27:42 -07001100 * @hide
1101 */
1102 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
1103 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
1104
1105 /**
Tony Mak1970f972016-08-30 17:41:48 +01001106 * Broadcast action: sent when the device owner is set, changed or cleared.
Nicolas Prevot00799002015-07-27 18:15:20 +01001107 *
1108 * This broadcast is sent only to the primary user.
1109 * @see #ACTION_PROVISION_MANAGED_DEVICE
1110 */
1111 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1112 public static final String ACTION_DEVICE_OWNER_CHANGED
1113 = "android.app.action.DEVICE_OWNER_CHANGED";
1114
1115 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001116 * The ComponentName of the administrator component.
1117 *
1118 * @see #ACTION_ADD_DEVICE_ADMIN
1119 */
1120 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001121
Dianne Hackbornd6847842010-01-12 18:14:19 -08001122 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001123 * An optional CharSequence providing additional explanation for why the
1124 * admin is being added.
1125 *
1126 * @see #ACTION_ADD_DEVICE_ADMIN
1127 */
1128 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001129
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001130 /**
phweiss73145f42017-01-17 19:06:38 +01001131 * Constant to indicate the feature of disabling the camera. Used as argument to
1132 * {@link #createAdminSupportIntent(String)}.
1133 * @see #setCameraDisabled(ComponentName, boolean)
1134 */
1135 public static final String POLICY_DISABLE_CAMERA = "policy_disable_camera";
1136
1137 /**
1138 * Constant to indicate the feature of disabling screen captures. Used as argument to
1139 * {@link #createAdminSupportIntent(String)}.
1140 * @see #setScreenCaptureDisabled(ComponentName, boolean)
1141 */
1142 public static final String POLICY_DISABLE_SCREEN_CAPTURE = "policy_disable_screen_capture";
1143
1144 /**
1145 * A String indicating a specific restricted feature. Can be a user restriction from the
1146 * {@link UserManager}, e.g. {@link UserManager#DISALLOW_ADJUST_VOLUME}, or one of the values
1147 * {@link #POLICY_DISABLE_CAMERA} or {@link #POLICY_DISABLE_SCREEN_CAPTURE}.
1148 * @see #createAdminSupportIntent(String)
1149 * @hide
1150 */
1151 @TestApi
1152 public static final String EXTRA_RESTRICTION = "android.app.extra.RESTRICTION";
1153
1154 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001155 * Activity action: have the user enter a new password. This activity should
1156 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
1157 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
1158 * enter a new password that meets the current requirements. You can use
1159 * {@link #isActivePasswordSufficient()} to determine whether you need to
1160 * have the user select a new password in order to meet the current
1161 * constraints. Upon being resumed from this activity, you can check the new
1162 * password characteristics to see if they are sufficient.
Benjamin Franzc9921092016-01-08 17:17:44 +00001163 *
1164 * If the intent is launched from within a managed profile with a profile
1165 * owner built against {@link android.os.Build.VERSION_CODES#M} or before,
1166 * this will trigger entering a new password for the parent of the profile.
1167 * For all other cases it will trigger entering a new password for the user
1168 * or profile it is launched from.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001169 *
1170 * @see #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
Dianne Hackbornd6847842010-01-12 18:14:19 -08001171 */
1172 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1173 public static final String ACTION_SET_NEW_PASSWORD
1174 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001175
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001176 /**
Benjamin Franzc9921092016-01-08 17:17:44 +00001177 * Activity action: have the user enter a new password for the parent profile.
1178 * If the intent is launched from within a managed profile, this will trigger
1179 * entering a new password for the parent of the profile. In all other cases
1180 * the behaviour is identical to {@link #ACTION_SET_NEW_PASSWORD}.
1181 */
1182 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1183 public static final String ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
1184 = "android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD";
1185
1186 /**
phweissa0cb2512016-12-14 21:37:48 +01001187 * Broadcast action: Tell the status bar to open the device monitoring dialog, e.g. when
1188 * Network logging was enabled and the user tapped the notification.
1189 * <p class="note">This is a protected intent that can only be sent by the system.</p>
1190 * @hide
1191 */
1192 public static final String ACTION_SHOW_DEVICE_MONITORING_DIALOG
1193 = "android.app.action.SHOW_DEVICE_MONITORING_DIALOG";
1194
1195 /**
Edman Anjos9e62c312017-01-26 22:22:58 +01001196 * Broadcast Action: Sent after application delegation scopes are changed. The new delegation
1197 * scopes will be sent in an {@code ArrayList<String>} extra identified by the
1198 * {@link #EXTRA_DELEGATION_SCOPES} key.
Edman Anjosf9946772016-11-28 16:35:15 +01001199 *
1200 * <p class=”note”> Note: This is a protected intent that can only be sent by the system.</p>
1201 */
1202 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1203 public static final String ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED =
1204 "android.app.action.APPLICATION_DELEGATION_SCOPES_CHANGED";
1205
1206 /**
Edman Anjos9e62c312017-01-26 22:22:58 +01001207 * An {@code ArrayList<String>} corresponding to the delegation scopes given to an app in the
Edman Anjosf9946772016-11-28 16:35:15 +01001208 * {@link #ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED} broadcast.
1209 */
1210 public static final String EXTRA_DELEGATION_SCOPES = "android.app.extra.DELEGATION_SCOPES";
1211
1212 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +00001213 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
1214 * the parent profile to access intents sent from the managed profile.
1215 * That is, when an app in the managed profile calls
1216 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
1217 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001218 */
Nicolas Prevot86a96732014-09-08 12:13:05 +01001219 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001220
1221 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +00001222 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
1223 * the managed profile to access intents sent from the parent profile.
1224 * That is, when an app in the parent profile calls
1225 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
1226 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001227 */
Nicolas Prevot86a96732014-09-08 12:13:05 +01001228 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001229
Dianne Hackbornd6847842010-01-12 18:14:19 -08001230 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01001231 * Broadcast action: notify that a new local system update policy has been set by the device
1232 * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00001233 */
1234 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Rubin Xu5faad8e2015-04-20 17:43:48 +01001235 public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED
1236 = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED";
Rubin Xu8027a4f2015-03-10 17:52:37 +00001237
Amith Yamasanid49489b2015-04-28 14:00:26 -07001238 /**
1239 * Permission policy to prompt user for new permission requests for runtime permissions.
1240 * Already granted or denied permissions are not affected by this.
1241 */
1242 public static final int PERMISSION_POLICY_PROMPT = 0;
1243
1244 /**
1245 * Permission policy to always grant new permission requests for runtime permissions.
1246 * Already granted or denied permissions are not affected by this.
1247 */
1248 public static final int PERMISSION_POLICY_AUTO_GRANT = 1;
1249
1250 /**
1251 * Permission policy to always deny new permission requests for runtime permissions.
1252 * Already granted or denied permissions are not affected by this.
1253 */
1254 public static final int PERMISSION_POLICY_AUTO_DENY = 2;
1255
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07001256 /**
1257 * Runtime permission state: The user can manage the permission
1258 * through the UI.
1259 */
1260 public static final int PERMISSION_GRANT_STATE_DEFAULT = 0;
1261
1262 /**
1263 * Runtime permission state: The permission is granted to the app
1264 * and the user cannot manage the permission through the UI.
1265 */
1266 public static final int PERMISSION_GRANT_STATE_GRANTED = 1;
1267
1268 /**
1269 * Runtime permission state: The permission is denied to the app
1270 * and the user cannot manage the permission through the UI.
1271 */
1272 public static final int PERMISSION_GRANT_STATE_DENIED = 2;
Rubin Xu8027a4f2015-03-10 17:52:37 +00001273
1274 /**
Edman Anjosf9946772016-11-28 16:35:15 +01001275 * Delegation of certificate installation and management. This scope grants access to the
1276 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
1277 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair} APIs.
1278 */
1279 public static final String DELEGATION_CERT_INSTALL = "delegation-cert-install";
1280
1281 /**
1282 * Delegation of application restrictions management. This scope grants access to the
1283 * {@link #setApplicationRestrictions} and {@link #getApplicationRestrictions} APIs.
1284 */
1285 public static final String DELEGATION_APP_RESTRICTIONS = "delegation-app-restrictions";
1286
1287 /**
Edman Anjosa5f2fb12016-12-19 11:25:54 -08001288 * Delegation of application uninstall block. This scope grants access to the
1289 * {@link #setUninstallBlocked} API.
1290 */
1291 public static final String DELEGATION_BLOCK_UNINSTALL = "delegation-block-uninstall";
1292
1293 /**
Edman Anjos52088e42017-01-13 22:26:17 +01001294 * Delegation of permission policy and permission grant state. This scope grants access to the
1295 * {@link #setPermissionPolicy}, {@link #getPermissionGrantState},
1296 * and {@link #setPermissionGrantState} APIs.
1297 */
1298 public static final String DELEGATION_PERMISSION_GRANT = "delegation-permission-grant";
1299
1300 /**
1301 * Delegation of package access state. This scope grants access to the
1302 * {@link #isApplicationHidden}, {@link #setApplicationHidden}, {@link #isPackageSuspended}, and
1303 * {@link #setPackagesSuspended} APIs.
1304 */
1305 public static final String DELEGATION_PACKAGE_ACCESS = "delegation-package-access";
1306
1307 /**
1308 * Delegation for enabling system apps. This scope grants access to the {@link #enableSystemApp}
1309 * API.
1310 */
1311 public static final String DELEGATION_ENABLE_SYSTEM_APP = "delegation-enable-system-app";
1312
1313 /**
1314 * Delegation of management of uninstalled packages. This scope grants access to the
1315 * {@code #setKeepUninstalledPackages} and {@code #getKeepUninstalledPackages} APIs.
1316 * @hide
1317 */
1318 public static final String DELEGATION_KEEP_UNINSTALLED_PACKAGES =
1319 "delegation-keep-uninstalled-packages";
1320
1321 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00001322 * No management for current user in-effect. This is the default.
1323 * @hide
1324 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001325 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001326 public static final int STATE_USER_UNMANAGED = 0;
1327
1328 /**
1329 * Management partially setup, user setup needs to be completed.
1330 * @hide
1331 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001332 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001333 public static final int STATE_USER_SETUP_INCOMPLETE = 1;
1334
1335 /**
1336 * Management partially setup, user setup completed.
1337 * @hide
1338 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001339 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001340 public static final int STATE_USER_SETUP_COMPLETE = 2;
1341
1342 /**
1343 * Management setup and active on current user.
1344 * @hide
1345 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001346 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001347 public static final int STATE_USER_SETUP_FINALIZED = 3;
1348
1349 /**
1350 * Management partially setup on a managed profile.
1351 * @hide
1352 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001353 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001354 public static final int STATE_USER_PROFILE_COMPLETE = 4;
1355
1356 /**
1357 * @hide
1358 */
1359 @IntDef({STATE_USER_UNMANAGED, STATE_USER_SETUP_INCOMPLETE, STATE_USER_SETUP_COMPLETE,
1360 STATE_USER_SETUP_FINALIZED, STATE_USER_PROFILE_COMPLETE})
1361 @Retention(RetentionPolicy.SOURCE)
1362 public @interface UserProvisioningState {}
1363
1364 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001365 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001366 *
1367 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1368 * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and
1369 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when provisioning is allowed.
1370 *
1371 * @hide
1372 */
1373 public static final int CODE_OK = 0;
1374
1375 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001376 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001377 *
1378 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and
1379 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the device already has a device
1380 * owner.
1381 *
1382 * @hide
1383 */
1384 public static final int CODE_HAS_DEVICE_OWNER = 1;
1385
1386 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001387 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001388 *
1389 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1390 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user has a profile owner and for
1391 * {@link #ACTION_PROVISION_MANAGED_PROFILE} when the profile owner is already set.
1392 *
1393 * @hide
1394 */
1395 public static final int CODE_USER_HAS_PROFILE_OWNER = 2;
1396
1397 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001398 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001399 *
1400 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and
1401 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user isn't running.
1402 *
1403 * @hide
1404 */
1405 public static final int CODE_USER_NOT_RUNNING = 3;
1406
1407 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001408 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001409 *
1410 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1411 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the device has already been setup and
1412 * for {@link #ACTION_PROVISION_MANAGED_USER} if the user has already been setup.
1413 *
1414 * @hide
1415 */
1416 public static final int CODE_USER_SETUP_COMPLETED = 4;
1417
1418 /**
1419 * Code used to indicate that the device also has a user other than the system user.
1420 *
1421 * @hide
1422 */
1423 public static final int CODE_NONSYSTEM_USER_EXISTS = 5;
1424
1425 /**
1426 * Code used to indicate that device has an account that prevents provisioning.
1427 *
1428 * @hide
1429 */
1430 public static final int CODE_ACCOUNTS_NOT_EMPTY = 6;
1431
1432 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001433 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001434 *
1435 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and
1436 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the user is not a system user.
1437 *
1438 * @hide
1439 */
1440 public static final int CODE_NOT_SYSTEM_USER = 7;
1441
1442 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001443 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001444 *
1445 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1446 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} and {@link #ACTION_PROVISION_MANAGED_USER}
1447 * when the device is a watch and is already paired.
1448 *
1449 * @hide
1450 */
1451 public static final int CODE_HAS_PAIRED = 8;
1452
1453 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001454 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001455 *
1456 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} and
1457 * {@link #ACTION_PROVISION_MANAGED_USER} on devices which do not support managed users.
1458 *
1459 * @see {@link PackageManager#FEATURE_MANAGED_USERS}
1460 * @hide
1461 */
1462 public static final int CODE_MANAGED_USERS_NOT_SUPPORTED = 9;
1463
1464 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001465 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001466 *
1467 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} if the user is a system user.
1468 *
1469 * @hide
1470 */
1471 public static final int CODE_SYSTEM_USER = 10;
1472
1473 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001474 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001475 *
1476 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when the user cannot have more
1477 * managed profiles.
1478 *
1479 * @hide
1480 */
1481 public static final int CODE_CANNOT_ADD_MANAGED_PROFILE = 11;
1482
1483 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001484 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001485 *
1486 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} and
1487 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices not running with split system
1488 * user.
1489 *
1490 * @hide
1491 */
1492 public static final int CODE_NOT_SYSTEM_USER_SPLIT = 12;
1493
1494 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001495 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001496 *
1497 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1498 * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and
1499 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices which do no support device
1500 * admins.
1501 *
1502 * @hide
1503 */
1504 public static final int CODE_DEVICE_ADMIN_NOT_SUPPORTED = 13;
1505
1506 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001507 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001508 *
Esteban Talavera6c9116a2016-11-24 16:12:44 +00001509 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when the device the user is a
1510 * system user on a split system user device.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001511 *
1512 * @hide
1513 */
1514 public static final int CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER = 14;
1515
1516 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001517 * Result code for {@link #checkProvisioningPreCondition}.
1518 *
1519 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when adding a managed profile is
1520 * disallowed by {@link UserManager#DISALLOW_ADD_MANAGED_PROFILE}.
1521 *
1522 * @hide
1523 */
1524 public static final int CODE_ADD_MANAGED_PROFILE_DISALLOWED = 15;
1525
1526 /**
1527 * Result codes for {@link #checkProvisioningPreCondition} indicating all the provisioning pre
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001528 * conditions.
1529 *
1530 * @hide
1531 */
1532 @Retention(RetentionPolicy.SOURCE)
1533 @IntDef({CODE_OK, CODE_HAS_DEVICE_OWNER, CODE_USER_HAS_PROFILE_OWNER, CODE_USER_NOT_RUNNING,
1534 CODE_USER_SETUP_COMPLETED, CODE_NOT_SYSTEM_USER, CODE_HAS_PAIRED,
1535 CODE_MANAGED_USERS_NOT_SUPPORTED, CODE_SYSTEM_USER, CODE_CANNOT_ADD_MANAGED_PROFILE,
1536 CODE_NOT_SYSTEM_USER_SPLIT, CODE_DEVICE_ADMIN_NOT_SUPPORTED,
Esteban Talavera01576862016-12-15 11:16:44 +00001537 CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER, CODE_ADD_MANAGED_PROFILE_DISALLOWED})
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001538 public @interface ProvisioningPreCondition {}
1539
1540 /**
Makoto Onukifc73d792017-03-22 14:22:35 -07001541 * Service action: Action for a service that device owner and profile owner can optionally
1542 * own. If a device owner or a profile owner has such a service, the system tries to keep
1543 * a bound connection to it, in order to keep their process always running.
Makoto Onukife739702017-04-25 13:26:21 -07001544 * The service must be protected with the {@link android.Manifest.permission#BIND_DEVICE_ADMIN}
1545 * permission.
Makoto Onukifc73d792017-03-22 14:22:35 -07001546 */
1547 @SdkConstant(SdkConstantType.SERVICE_ACTION)
1548 public static final String ACTION_DEVICE_ADMIN_SERVICE
1549 = "android.app.action.DEVICE_ADMIN_SERVICE";
1550
1551 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001552 * Return true if the given administrator component is currently active (enabled) in the system.
1553 *
1554 * @param admin The administrator component to check for.
1555 * @return {@code true} if {@code admin} is currently enabled in the system, {@code false}
1556 * otherwise
Dianne Hackbornd6847842010-01-12 18:14:19 -08001557 */
Robin Lee25e26452015-06-02 09:56:29 -07001558 public boolean isAdminActive(@NonNull ComponentName admin) {
Charles He8c760562016-10-25 16:36:53 +01001559 throwIfParentInstance("isAdminActive");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001560 return isAdminActiveAsUser(admin, myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001561 }
1562
1563 /**
1564 * @see #isAdminActive(ComponentName)
1565 * @hide
1566 */
Robin Lee25e26452015-06-02 09:56:29 -07001567 public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001568 if (mService != null) {
1569 try {
Robin Lee25e26452015-06-02 09:56:29 -07001570 return mService.isAdminActive(admin, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001571 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001572 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001573 }
1574 }
1575 return false;
1576 }
Charles Hedea0c3b2017-01-13 10:04:12 +00001577
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001578 /**
1579 * Return true if the given administrator component is currently being removed
1580 * for the user.
1581 * @hide
1582 */
Robin Lee25e26452015-06-02 09:56:29 -07001583 public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) {
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001584 if (mService != null) {
1585 try {
Robin Lee25e26452015-06-02 09:56:29 -07001586 return mService.isRemovingAdmin(admin, userId);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001587 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001588 throw e.rethrowFromSystemServer();
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001589 }
1590 }
1591 return false;
1592 }
1593
Dianne Hackbornd6847842010-01-12 18:14:19 -08001594 /**
Robin Lee25e26452015-06-02 09:56:29 -07001595 * Return a list of all currently active device administrators' component
1596 * names. If there are no administrators {@code null} may be
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001597 * returned.
1598 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07001599 public @Nullable List<ComponentName> getActiveAdmins() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001600 throwIfParentInstance("getActiveAdmins");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001601 return getActiveAdminsAsUser(myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001602 }
1603
1604 /**
1605 * @see #getActiveAdmins()
1606 * @hide
1607 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07001608 public @Nullable List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001609 if (mService != null) {
1610 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001611 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001612 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001613 throw e.rethrowFromSystemServer();
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001614 }
1615 }
1616 return null;
1617 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001618
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001619 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001620 * Used by package administration code to determine if a package can be stopped
1621 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001622 * @hide
1623 */
David Ouyang3a83a332017-01-11 16:36:40 -08001624 @SystemApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06001625 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001626 public boolean packageHasActiveAdmins(String packageName) {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001627 return packageHasActiveAdmins(packageName, myUserId());
1628 }
1629
1630 /**
1631 * Used by package administration code to determine if a package can be stopped
1632 * or uninstalled.
1633 * @hide
1634 */
1635 public boolean packageHasActiveAdmins(String packageName, int userId) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001636 if (mService != null) {
1637 try {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001638 return mService.packageHasActiveAdmins(packageName, userId);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001639 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001640 throw e.rethrowFromSystemServer();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001641 }
1642 }
1643 return false;
1644 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001645
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001646 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001647 * Remove a current administration component. This can only be called
1648 * by the application that owns the administration component; if you
1649 * try to remove someone else's component, a security exception will be
1650 * thrown.
Esteban Talavera552a5612016-02-19 17:02:24 +00001651 *
1652 * <p>Note that the operation is not synchronous and the admin might still be active (as
1653 * indicated by {@link #getActiveAdmins()}) by the time this method returns.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001654 *
1655 * @param admin The administration compononent to remove.
1656 * @throws SecurityException if the caller is not in the owner application of {@code admin}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001657 */
Robin Lee25e26452015-06-02 09:56:29 -07001658 public void removeActiveAdmin(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001659 throwIfParentInstance("removeActiveAdmin");
Dianne Hackbornd6847842010-01-12 18:14:19 -08001660 if (mService != null) {
1661 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001662 mService.removeActiveAdmin(admin, myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001663 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001664 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001665 }
1666 }
1667 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001668
Dianne Hackbornd6847842010-01-12 18:14:19 -08001669 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001670 * Returns true if an administrator has been granted a particular device policy. This can be
1671 * used to check whether the administrator was activated under an earlier set of policies, but
1672 * requires additional policies after an upgrade.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001673 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001674 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be an
1675 * active administrator, or an exception will be thrown.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001676 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001677 * @throws SecurityException if {@code admin} is not an active administrator.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001678 */
Robin Lee25e26452015-06-02 09:56:29 -07001679 public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001680 throwIfParentInstance("hasGrantedPolicy");
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001681 if (mService != null) {
1682 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001683 return mService.hasGrantedPolicy(admin, usesPolicy, myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001684 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001685 throw e.rethrowFromSystemServer();
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001686 }
1687 }
1688 return false;
1689 }
1690
1691 /**
Clara Bayarria1771112015-12-18 16:29:18 +00001692 * Returns true if the Profile Challenge is available to use for the given profile user.
1693 *
1694 * @hide
1695 */
1696 public boolean isSeparateProfileChallengeAllowed(int userHandle) {
1697 if (mService != null) {
1698 try {
1699 return mService.isSeparateProfileChallengeAllowed(userHandle);
1700 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001701 throw e.rethrowFromSystemServer();
Clara Bayarria1771112015-12-18 16:29:18 +00001702 }
1703 }
1704 return false;
1705 }
1706
1707 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001708 * Constant for {@link #setPasswordQuality}: the policy has no requirements
1709 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001710 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001711 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001712 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001713
Dianne Hackbornd6847842010-01-12 18:14:19 -08001714 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -07001715 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
1716 * recognition technology. This implies technologies that can recognize the identity of
1717 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
1718 * Note that quality constants are ordered so that higher values are more restrictive.
1719 */
1720 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
1721
1722 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001723 * Constant for {@link #setPasswordQuality}: the policy requires some kind
Benjamin Franzc6a96532015-06-16 11:23:38 +01001724 * of password or pattern, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001725 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001726 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001727 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001728
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001729 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001730 * Constant for {@link #setPasswordQuality}: the user must have entered a
1731 * password containing at least numeric characters. Note that quality
1732 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001733 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001734 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001735
Dianne Hackbornd6847842010-01-12 18:14:19 -08001736 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001737 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -08001738 * password containing at least numeric characters with no repeating (4444)
1739 * or ordered (1234, 4321, 2468) sequences. Note that quality
1740 * constants are ordered so that higher values are more restrictive.
1741 */
1742 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
1743
1744 /**
1745 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001746 * password containing at least alphabetic (or other symbol) characters.
1747 * Note that quality constants are ordered so that higher values are more
1748 * restrictive.
1749 */
1750 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001751
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001752 /**
1753 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001754 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001755 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001756 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001757 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001758 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001759
Dianne Hackbornd6847842010-01-12 18:14:19 -08001760 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001761 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001762 * password containing at least a letter, a numerical digit and a special
1763 * symbol, by default. With this password quality, passwords can be
1764 * restricted to contain various sets of characters, like at least an
1765 * uppercase letter, etc. These are specified using various methods,
1766 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
1767 * that quality constants are ordered so that higher values are more
1768 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001769 */
1770 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
1771
1772 /**
Oleksandr Peletskyi0fdcd3d2016-01-13 16:49:56 +01001773 * Constant for {@link #setPasswordQuality}: the user is not allowed to
1774 * modify password. In case this password quality is set, the password is
1775 * managed by a profile owner. The profile owner can set any password,
1776 * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note
1777 * that quality constants are ordered so that higher values are more
1778 * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is
1779 * the highest.
1780 * @hide
1781 */
1782 public static final int PASSWORD_QUALITY_MANAGED = 0x80000;
1783
1784 /**
Makoto Onuki5e7e06702016-09-01 18:02:01 -07001785 * @hide
1786 *
1787 * adb shell dpm set-{device,profile}-owner will normally not allow installing an owner to
1788 * a user with accounts. {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED}
1789 * and {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} are the account features
1790 * used by authenticator to exempt their accounts from this:
1791 *
1792 * <ul>
1793 * <li>Non-test-only DO/PO still can't be installed when there are accounts.
1794 * <p>In order to make an apk test-only, add android:testOnly="true" to the
1795 * &lt;application&gt; tag in the manifest.
1796 *
1797 * <li>Test-only DO/PO can be installed even when there are accounts, as long as all the
1798 * accounts have the {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} feature.
1799 * Some authenticators claim to have any features, so to detect it, we also check
1800 * {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} and disallow installing
1801 * if any of the accounts have it.
1802 * </ul>
1803 */
Makoto Onuki47c203d2017-02-13 16:21:19 -08001804 @SystemApi
1805 @TestApi
Makoto Onuki5e7e06702016-09-01 18:02:01 -07001806 public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED =
1807 "android.account.DEVICE_OR_PROFILE_OWNER_ALLOWED";
1808
1809 /** @hide See {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} */
Makoto Onuki47c203d2017-02-13 16:21:19 -08001810 @SystemApi
1811 @TestApi
Makoto Onuki5e7e06702016-09-01 18:02:01 -07001812 public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED =
1813 "android.account.DEVICE_OR_PROFILE_OWNER_DISALLOWED";
1814
1815 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001816 * Called by an application that is administering the device to set the password restrictions it
1817 * is imposing. After setting this, the user will not be able to enter a new password that is
1818 * not at least as restrictive as what has been set. Note that the current password will remain
1819 * until the user has set a new one, so the change does not take place immediately. To prompt
1820 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
Esteban Talaverac1c83592016-02-17 17:56:15 +00001821 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after calling this method.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001822 * <p>
1823 * Quality constants are ordered so that higher values are more restrictive; thus the highest
1824 * requested quality constant (between the policy set here, the user's preference, and any other
1825 * considerations) is the one that is in effect.
1826 * <p>
1827 * The calling device admin must have requested
1828 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1829 * not, a security exception will be thrown.
1830 * <p>
1831 * This method can be called on the {@link DevicePolicyManager} instance returned by
1832 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1833 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001834 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001835 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001836 * @param quality The new desired quality. One of {@link #PASSWORD_QUALITY_UNSPECIFIED},
1837 * {@link #PASSWORD_QUALITY_SOMETHING}, {@link #PASSWORD_QUALITY_NUMERIC},
1838 * {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC},
1839 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} or {@link #PASSWORD_QUALITY_COMPLEX}.
1840 * @throws SecurityException if {@code admin} is not an active administrator or if {@code admin}
1841 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Dianne Hackbornd6847842010-01-12 18:14:19 -08001842 */
Robin Lee25e26452015-06-02 09:56:29 -07001843 public void setPasswordQuality(@NonNull ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001844 if (mService != null) {
1845 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001846 mService.setPasswordQuality(admin, quality, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001847 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001848 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001849 }
1850 }
1851 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001852
Dianne Hackbornd6847842010-01-12 18:14:19 -08001853 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001854 * Retrieve the current minimum password quality for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01001855 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00001856 * a separate challenge are not taken into account.
1857 *
1858 * <p>This method can be called on the {@link DevicePolicyManager} instance
1859 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1860 * restrictions on the parent profile.
1861 *
Robin Lee25e26452015-06-02 09:56:29 -07001862 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001863 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001864 */
Robin Lee25e26452015-06-02 09:56:29 -07001865 public int getPasswordQuality(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001866 return getPasswordQuality(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001867 }
1868
1869 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001870 public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001871 if (mService != null) {
1872 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001873 return mService.getPasswordQuality(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001874 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001875 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001876 }
1877 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001878 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001879 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001880
Dianne Hackbornd6847842010-01-12 18:14:19 -08001881 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001882 * Called by an application that is administering the device to set the minimum allowed password
1883 * length. After setting this, the user will not be able to enter a new password that is not at
1884 * least as restrictive as what has been set. Note that the current password will remain until
1885 * the user has set a new one, so the change does not take place immediately. To prompt the user
1886 * for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
1887 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
1888 * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC}
1889 * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC},
1890 * {@link #PASSWORD_QUALITY_ALPHANUMERIC}, or {@link #PASSWORD_QUALITY_COMPLEX} with
1891 * {@link #setPasswordQuality}.
1892 * <p>
1893 * The calling device admin must have requested
1894 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1895 * not, a security exception will be thrown.
1896 * <p>
1897 * This method can be called on the {@link DevicePolicyManager} instance returned by
1898 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1899 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001900 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001901 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001902 * @param length The new desired minimum password length. A value of 0 means there is no
1903 * restriction.
1904 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1905 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Dianne Hackbornd6847842010-01-12 18:14:19 -08001906 */
Robin Lee25e26452015-06-02 09:56:29 -07001907 public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001908 if (mService != null) {
1909 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001910 mService.setPasswordMinimumLength(admin, length, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001911 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001912 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001913 }
1914 }
1915 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001916
Dianne Hackbornd6847842010-01-12 18:14:19 -08001917 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001918 * Retrieve the current minimum password length for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01001919 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00001920 * a separate challenge are not taken into account.
1921 *
1922 * <p>This method can be called on the {@link DevicePolicyManager} instance
1923 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1924 * restrictions on the parent profile.
1925 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001926 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001927 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001928 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001929 */
Robin Lee25e26452015-06-02 09:56:29 -07001930 public int getPasswordMinimumLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001931 return getPasswordMinimumLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001932 }
1933
1934 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001935 public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001936 if (mService != null) {
1937 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001938 return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001939 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001940 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001941 }
1942 }
1943 return 0;
1944 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001945
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001946 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001947 * Called by an application that is administering the device to set the minimum number of upper
1948 * case letters required in the password. After setting this, the user will not be able to enter
1949 * a new password that is not at least as restrictive as what has been set. Note that the
1950 * current password will remain until the user has set a new one, so the change does not take
1951 * place immediately. To prompt the user for a new password, use
1952 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
1953 * setting this value. This constraint is only imposed if the administrator has also requested
1954 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001955 * <p>
1956 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001957 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1958 * not, a security exception will be thrown.
1959 * <p>
1960 * This method can be called on the {@link DevicePolicyManager} instance returned by
1961 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1962 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001963 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001964 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1965 * @param length The new desired minimum number of upper case letters required in the password.
1966 * A value of 0 means there is no restriction.
1967 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1968 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001969 */
Robin Lee25e26452015-06-02 09:56:29 -07001970 public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001971 if (mService != null) {
1972 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001973 mService.setPasswordMinimumUpperCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001974 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001975 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001976 }
1977 }
1978 }
1979
1980 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001981 * Retrieve the current number of upper case letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01001982 * for a particular admin or all admins that set restrictions on this user and
Esteban Talaverac1c83592016-02-17 17:56:15 +00001983 * its participating profiles. Restrictions on profiles that have a separate challenge
1984 * are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001985 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001986 * {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001987 * and only applies when the password quality is
1988 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001989 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001990 * <p>This method can be called on the {@link DevicePolicyManager} instance
1991 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1992 * restrictions on the parent profile.
1993 *
Robin Lee25e26452015-06-02 09:56:29 -07001994 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001995 * aggregate all admins.
1996 * @return The minimum number of upper case letters required in the
1997 * password.
1998 */
Robin Lee25e26452015-06-02 09:56:29 -07001999 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002000 return getPasswordMinimumUpperCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002001 }
2002
2003 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002004 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002005 if (mService != null) {
2006 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002007 return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002008 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002009 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002010 }
2011 }
2012 return 0;
2013 }
2014
2015 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002016 * Called by an application that is administering the device to set the minimum number of lower
2017 * case letters required in the password. After setting this, the user will not be able to enter
2018 * a new password that is not at least as restrictive as what has been set. Note that the
2019 * current password will remain until the user has set a new one, so the change does not take
2020 * place immediately. To prompt the user for a new password, use
2021 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
2022 * setting this value. This constraint is only imposed if the administrator has also requested
2023 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002024 * <p>
2025 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002026 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2027 * not, a security exception will be thrown.
2028 * <p>
2029 * This method can be called on the {@link DevicePolicyManager} instance returned by
2030 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2031 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002032 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002033 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2034 * @param length The new desired minimum number of lower case letters required in the password.
2035 * A value of 0 means there is no restriction.
2036 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2037 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002038 */
Robin Lee25e26452015-06-02 09:56:29 -07002039 public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002040 if (mService != null) {
2041 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002042 mService.setPasswordMinimumLowerCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002043 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002044 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002045 }
2046 }
2047 }
2048
2049 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002050 * Retrieve the current number of lower case letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002051 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002052 * and its participating profiles. Restrictions on profiles that have
2053 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01002054 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00002055 * {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002056 * and only applies when the password quality is
2057 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002058 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002059 * <p>This method can be called on the {@link DevicePolicyManager} instance
2060 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2061 * restrictions on the parent profile.
2062 *
Robin Lee25e26452015-06-02 09:56:29 -07002063 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002064 * aggregate all admins.
2065 * @return The minimum number of lower case letters required in the
2066 * password.
2067 */
Robin Lee25e26452015-06-02 09:56:29 -07002068 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002069 return getPasswordMinimumLowerCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002070 }
2071
2072 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002073 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002074 if (mService != null) {
2075 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002076 return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002077 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002078 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002079 }
2080 }
2081 return 0;
2082 }
2083
2084 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002085 * Called by an application that is administering the device to set the minimum number of
2086 * letters required in the password. After setting this, the user will not be able to enter a
2087 * new password that is not at least as restrictive as what has been set. Note that the current
2088 * password will remain until the user has set a new one, so the change does not take place
2089 * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
2090 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
2091 * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
2092 * {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002093 * <p>
2094 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002095 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2096 * not, a security exception will be thrown.
2097 * <p>
2098 * This method can be called on the {@link DevicePolicyManager} instance returned by
2099 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2100 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002101 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002102 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2103 * @param length The new desired minimum number of letters required in the password. A value of
2104 * 0 means there is no restriction.
2105 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2106 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002107 */
Robin Lee25e26452015-06-02 09:56:29 -07002108 public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002109 if (mService != null) {
2110 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002111 mService.setPasswordMinimumLetters(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002112 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002113 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002114 }
2115 }
2116 }
2117
2118 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002119 * Retrieve the current number of letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002120 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002121 * and its participating profiles. Restrictions on profiles that have
2122 * a separate challenge are not taken into account.
2123 * This is the same value as set by
2124 * {@link #setPasswordMinimumLetters(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002125 * and only applies when the password quality is
2126 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002127 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002128 * <p>This method can be called on the {@link DevicePolicyManager} instance
2129 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2130 * restrictions on the parent profile.
2131 *
Robin Lee25e26452015-06-02 09:56:29 -07002132 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002133 * aggregate all admins.
2134 * @return The minimum number of letters required in the password.
2135 */
Robin Lee25e26452015-06-02 09:56:29 -07002136 public int getPasswordMinimumLetters(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002137 return getPasswordMinimumLetters(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002138 }
2139
2140 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002141 public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002142 if (mService != null) {
2143 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002144 return mService.getPasswordMinimumLetters(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002145 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002146 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002147 }
2148 }
2149 return 0;
2150 }
2151
2152 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002153 * Called by an application that is administering the device to set the minimum number of
2154 * numerical digits required in the password. After setting this, the user will not be able to
2155 * enter a new password that is not at least as restrictive as what has been set. Note that the
2156 * current password will remain until the user has set a new one, so the change does not take
2157 * place immediately. To prompt the user for a new password, use
2158 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
2159 * setting this value. This constraint is only imposed if the administrator has also requested
2160 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002161 * <p>
2162 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002163 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2164 * not, a security exception will be thrown.
2165 * <p>
2166 * This method can be called on the {@link DevicePolicyManager} instance returned by
2167 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2168 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002169 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002170 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2171 * @param length The new desired minimum number of numerical digits required in the password. A
2172 * value of 0 means there is no restriction.
2173 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2174 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002175 */
Robin Lee25e26452015-06-02 09:56:29 -07002176 public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002177 if (mService != null) {
2178 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002179 mService.setPasswordMinimumNumeric(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002180 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002181 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002182 }
2183 }
2184 }
2185
2186 /**
2187 * Retrieve the current number of numerical digits required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002188 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002189 * and its participating profiles. Restrictions on profiles that have
2190 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01002191 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00002192 * {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002193 * and only applies when the password quality is
2194 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002195 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002196 * <p>This method can be called on the {@link DevicePolicyManager} instance
2197 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2198 * restrictions on the parent profile.
2199 *
Robin Lee25e26452015-06-02 09:56:29 -07002200 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002201 * aggregate all admins.
2202 * @return The minimum number of numerical digits required in the password.
2203 */
Robin Lee25e26452015-06-02 09:56:29 -07002204 public int getPasswordMinimumNumeric(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002205 return getPasswordMinimumNumeric(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002206 }
2207
2208 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002209 public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002210 if (mService != null) {
2211 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002212 return mService.getPasswordMinimumNumeric(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002213 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002214 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002215 }
2216 }
2217 return 0;
2218 }
2219
2220 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002221 * Called by an application that is administering the device to set the minimum number of
2222 * symbols required in the password. After setting this, the user will not be able to enter a
2223 * new password that is not at least as restrictive as what has been set. Note that the current
2224 * password will remain until the user has set a new one, so the change does not take place
2225 * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
2226 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
2227 * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
2228 * {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002229 * <p>
2230 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002231 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2232 * not, a security exception will be thrown.
2233 * <p>
2234 * This method can be called on the {@link DevicePolicyManager} instance returned by
2235 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2236 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002237 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002238 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2239 * @param length The new desired minimum number of symbols required in the password. A value of
2240 * 0 means there is no restriction.
2241 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2242 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002243 */
Robin Lee25e26452015-06-02 09:56:29 -07002244 public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002245 if (mService != null) {
2246 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002247 mService.setPasswordMinimumSymbols(admin, length, 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 }
2253
2254 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002255 * Retrieve the current number of symbols required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002256 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002257 * and its participating profiles. Restrictions on profiles that have
2258 * a separate challenge are not taken into account. This is the same value as
2259 * set by {@link #setPasswordMinimumSymbols(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002260 * and only applies when the password quality is
2261 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002262 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002263 * <p>This method can be called on the {@link DevicePolicyManager} instance
2264 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2265 * restrictions on the parent profile.
2266 *
Robin Lee25e26452015-06-02 09:56:29 -07002267 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002268 * aggregate all admins.
2269 * @return The minimum number of symbols required in the password.
2270 */
Robin Lee25e26452015-06-02 09:56:29 -07002271 public int getPasswordMinimumSymbols(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002272 return getPasswordMinimumSymbols(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002273 }
2274
2275 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002276 public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002277 if (mService != null) {
2278 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002279 return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002280 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002281 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002282 }
2283 }
2284 return 0;
2285 }
2286
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002287 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002288 * Called by an application that is administering the device to set the minimum number of
2289 * non-letter characters (numerical digits or symbols) required in the password. After setting
2290 * this, the user will not be able to enter a new password that is not at least as restrictive
2291 * as what has been set. Note that the current password will remain until the user has set a new
2292 * one, so the change does not take place immediately. To prompt the user for a new password,
2293 * use {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
2294 * setting this value. This constraint is only imposed if the administrator has also requested
2295 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002296 * <p>
2297 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002298 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2299 * not, a security exception will be thrown.
2300 * <p>
2301 * This method can be called on the {@link DevicePolicyManager} instance returned by
2302 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2303 * profile.
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002304 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002305 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2306 * @param length The new desired minimum number of letters required in the password. A value of
2307 * 0 means there is no restriction.
2308 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2309 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002310 */
Robin Lee25e26452015-06-02 09:56:29 -07002311 public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002312 if (mService != null) {
2313 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002314 mService.setPasswordMinimumNonLetter(admin, length, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002315 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002316 throw e.rethrowFromSystemServer();
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002317 }
2318 }
2319 }
2320
2321 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002322 * Retrieve the current number of non-letter characters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002323 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002324 * and its participating profiles. Restrictions on profiles that have
2325 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01002326 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00002327 * {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002328 * and only applies when the password quality is
2329 * {@link #PASSWORD_QUALITY_COMPLEX}.
2330 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002331 * <p>This method can be called on the {@link DevicePolicyManager} instance
2332 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2333 * restrictions on the parent profile.
2334 *
Robin Lee25e26452015-06-02 09:56:29 -07002335 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002336 * aggregate all admins.
2337 * @return The minimum number of letters required in the password.
2338 */
Robin Lee25e26452015-06-02 09:56:29 -07002339 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002340 return getPasswordMinimumNonLetter(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002341 }
2342
2343 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002344 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002345 if (mService != null) {
2346 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002347 return mService.getPasswordMinimumNonLetter(admin, userHandle, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002348 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002349 throw e.rethrowFromSystemServer();
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002350 }
2351 }
2352 return 0;
2353 }
2354
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002355 /**
2356 * Called by an application that is administering the device to set the length of the password
2357 * history. After setting this, the user will not be able to enter a new password that is the
2358 * same as any password in the history. Note that the current password will remain until the
2359 * user has set a new one, so the change does not take place immediately. To prompt the user for
2360 * a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
2361 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
2362 * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC}
2363 * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX} {@link #PASSWORD_QUALITY_ALPHABETIC}, or
2364 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} with {@link #setPasswordQuality}.
2365 * <p>
2366 * The calling device admin must have requested
2367 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2368 * not, a security exception will be thrown.
2369 * <p>
2370 * This method can be called on the {@link DevicePolicyManager} instance returned by
2371 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2372 * profile.
2373 *
2374 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2375 * @param length The new desired length of password history. A value of 0 means there is no
2376 * restriction.
2377 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2378 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
2379 */
Robin Lee25e26452015-06-02 09:56:29 -07002380 public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002381 if (mService != null) {
2382 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002383 mService.setPasswordHistoryLength(admin, length, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002384 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002385 throw e.rethrowFromSystemServer();
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002386 }
2387 }
2388 }
2389
2390 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002391 * Called by a device admin to set the password expiration timeout. Calling this method will
2392 * restart the countdown for password expiration for the given admin, as will changing the
2393 * device password (for all admins).
2394 * <p>
2395 * The provided timeout is the time delta in ms and will be added to the current time. For
2396 * example, to have the password expire 5 days from now, timeout would be 5 * 86400 * 1000 =
2397 * 432000000 ms for timeout.
2398 * <p>
2399 * To disable password expiration, a value of 0 may be used for timeout.
2400 * <p>
2401 * The calling device admin must have requested
2402 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this method; if it has
2403 * not, a security exception will be thrown.
2404 * <p>
2405 * Note that setting the password will automatically reset the expiration time for all active
2406 * admins. Active admins do not need to explicitly call this method in that case.
2407 * <p>
2408 * This method can be called on the {@link DevicePolicyManager} instance returned by
2409 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2410 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002411 *
Jim Millera4e28d12010-11-08 16:15:47 -08002412 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002413 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0 means
2414 * there is no restriction (unlimited).
2415 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2416 * does not use {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD}
Jim Millera4e28d12010-11-08 16:15:47 -08002417 */
Robin Lee25e26452015-06-02 09:56:29 -07002418 public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) {
Jim Millera4e28d12010-11-08 16:15:47 -08002419 if (mService != null) {
2420 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002421 mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08002422 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002423 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08002424 }
2425 }
2426 }
2427
2428 /**
Jim Miller6b857682011-02-16 16:27:41 -08002429 * Get the password expiration timeout for the given admin. The expiration timeout is the
2430 * recurring expiration timeout provided in the call to
2431 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
Esteban Talaverac1c83592016-02-17 17:56:15 +00002432 * aggregate of all participating policy administrators if {@code admin} is null. Admins that
2433 * have set restrictions on profiles that have a separate challenge are not taken into account.
2434 *
2435 * <p>This method can be called on the {@link DevicePolicyManager} instance
2436 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2437 * restrictions on the parent profile.
Jim Millera4e28d12010-11-08 16:15:47 -08002438 *
Robin Lee25e26452015-06-02 09:56:29 -07002439 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08002440 * @return The timeout for the given admin or the minimum of all timeouts
2441 */
Robin Lee25e26452015-06-02 09:56:29 -07002442 public long getPasswordExpirationTimeout(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08002443 if (mService != null) {
2444 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002445 return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08002446 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002447 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08002448 }
2449 }
2450 return 0;
2451 }
2452
2453 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002454 * Get the current password expiration time for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01002455 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00002456 * a separate challenge are not taken into account. If admin is {@code null}, then a composite
2457 * of all expiration times is returned - which will be the minimum of all of them.
2458 *
2459 * <p>This method can be called on the {@link DevicePolicyManager} instance
2460 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2461 * the password expiration for the parent profile.
Jim Millera4e28d12010-11-08 16:15:47 -08002462 *
Robin Lee25e26452015-06-02 09:56:29 -07002463 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002464 * @return The password expiration time, in milliseconds since epoch.
Jim Millera4e28d12010-11-08 16:15:47 -08002465 */
Robin Lee25e26452015-06-02 09:56:29 -07002466 public long getPasswordExpiration(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08002467 if (mService != null) {
2468 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002469 return mService.getPasswordExpiration(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08002470 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002471 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08002472 }
2473 }
2474 return 0;
2475 }
2476
2477 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002478 * Retrieve the current password history length for a particular admin or all admins that
Rubin Xud3609d42016-07-13 18:32:57 +01002479 * set restrictions on this user and its participating profiles. Restrictions on profiles that
Esteban Talaverac1c83592016-02-17 17:56:15 +00002480 * have a separate challenge are not taken into account.
2481 *
2482 * <p>This method can be called on the {@link DevicePolicyManager} instance
2483 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2484 * restrictions on the parent profile.
2485 *
Robin Lee25e26452015-06-02 09:56:29 -07002486 * @param admin The name of the admin component to check, or {@code null} to aggregate
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002487 * all admins.
2488 * @return The length of the password history
2489 */
Robin Lee25e26452015-06-02 09:56:29 -07002490 public int getPasswordHistoryLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002491 return getPasswordHistoryLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002492 }
2493
2494 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002495 public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002496 if (mService != null) {
2497 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002498 return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002499 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002500 throw e.rethrowFromSystemServer();
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002501 }
2502 }
2503 return 0;
2504 }
2505
Dianne Hackbornd6847842010-01-12 18:14:19 -08002506 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08002507 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08002508 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08002509 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08002510 * @return Returns the maximum length that the user can enter.
2511 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08002512 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08002513 // Kind-of arbitrary.
2514 return 16;
2515 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002516
Dianne Hackborn254cb442010-01-27 19:23:59 -08002517 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002518 * Determine whether the current password the user has set is sufficient to meet the policy
2519 * requirements (e.g. quality, minimum length) that have been requested by the admins of this
2520 * user and its participating profiles. Restrictions on profiles that have a separate challenge
Andrew Scull5daf2732016-11-14 15:02:45 +00002521 * are not taken into account. The user must be unlocked in order to perform the check.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002522 * <p>
2523 * The calling device admin must have requested
2524 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2525 * not, a security exception will be thrown.
2526 * <p>
2527 * This method can be called on the {@link DevicePolicyManager} instance returned by
2528 * {@link #getParentProfileInstance(ComponentName)} in order to determine if the password set on
2529 * the parent profile is sufficient.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002530 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01002531 * @return Returns true if the password meets the current requirements, else false.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002532 * @throws SecurityException if the calling application does not own an active administrator
2533 * that uses {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Andrew Scull5daf2732016-11-14 15:02:45 +00002534 * @throws InvalidStateException if the user is not unlocked.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002535 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002536 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002537 if (mService != null) {
2538 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00002539 return mService.isActivePasswordSufficient(myUserId(), mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002540 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002541 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002542 }
2543 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002544 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08002545 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002546
Dianne Hackbornd6847842010-01-12 18:14:19 -08002547 /**
Clara Bayarrid7693912016-01-22 17:26:31 +00002548 * Determine whether the current profile password the user has set is sufficient
Esteban Talaverac1c83592016-02-17 17:56:15 +00002549 * to meet the policy requirements (e.g. quality, minimum length) that have been
Clara Bayarrid7693912016-01-22 17:26:31 +00002550 * requested by the admins of the parent user and its profiles.
2551 *
2552 * @param userHandle the userId of the profile to check the password for.
2553 * @return Returns true if the password would meet the current requirements, else false.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002554 * @throws SecurityException if {@code userHandle} is not a managed profile.
Clara Bayarrid7693912016-01-22 17:26:31 +00002555 * @hide
2556 */
2557 public boolean isProfileActivePasswordSufficientForParent(int userHandle) {
2558 if (mService != null) {
2559 try {
2560 return mService.isProfileActivePasswordSufficientForParent(userHandle);
2561 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002562 throw e.rethrowFromSystemServer();
Clara Bayarrid7693912016-01-22 17:26:31 +00002563 }
2564 }
2565 return false;
2566 }
2567
2568 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002569 * Retrieve the number of times the user has failed at entering a password since that last
2570 * successful password entry.
2571 * <p>
2572 * This method can be called on the {@link DevicePolicyManager} instance returned by
2573 * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the number of failed
2574 * password attemts for the parent user.
2575 * <p>
2576 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN}
2577 * to be able to call this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002578 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002579 * @return The number of times user has entered an incorrect password since the last correct
2580 * password entry.
2581 * @throws SecurityException if the calling application does not own an active administrator
2582 * that uses {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002583 */
2584 public int getCurrentFailedPasswordAttempts() {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00002585 return getCurrentFailedPasswordAttempts(myUserId());
2586 }
2587
2588 /**
2589 * Retrieve the number of times the given user has failed at entering a
2590 * password since that last successful password entry.
2591 *
2592 * <p>The calling device admin must have requested
2593 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call this method; if it has
2594 * not and it is not the system uid, a security exception will be thrown.
2595 *
2596 * @hide
2597 */
2598 public int getCurrentFailedPasswordAttempts(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002599 if (mService != null) {
2600 try {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00002601 return mService.getCurrentFailedPasswordAttempts(userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002602 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002603 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002604 }
2605 }
2606 return -1;
2607 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002608
2609 /**
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002610 * Queries whether {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002611 *
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002612 * @return true if RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002613 * @hide
2614 */
2615 public boolean getDoNotAskCredentialsOnBoot() {
2616 if (mService != null) {
2617 try {
2618 return mService.getDoNotAskCredentialsOnBoot();
2619 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002620 throw e.rethrowFromSystemServer();
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002621 }
2622 }
2623 return false;
2624 }
2625
2626 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002627 * Setting this to a value greater than zero enables a built-in policy that will perform a
2628 * device or profile wipe after too many incorrect device-unlock passwords have been entered.
2629 * This built-in policy combines watching for failed passwords and wiping the device, and
2630 * requires that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002631 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002632 * <p>
2633 * To implement any other policy (e.g. wiping data for a particular application only, erasing or
2634 * revoking credentials, or reporting the failure to a server), you should implement
2635 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} instead. Do not
2636 * use this API, because if the maximum count is reached, the device or profile will be wiped
2637 * immediately, and your callback will not be invoked.
2638 * <p>
2639 * This method can be called on the {@link DevicePolicyManager} instance returned by
2640 * {@link #getParentProfileInstance(ComponentName)} in order to set a value on the parent
2641 * profile.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002642 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002643 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002644 * @param num The number of failed password attempts at which point the device or profile will
2645 * be wiped.
2646 * @throws SecurityException if {@code admin} is not an active administrator or does not use
2647 * both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
2648 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002649 */
Robin Lee25e26452015-06-02 09:56:29 -07002650 public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002651 if (mService != null) {
2652 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002653 mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002654 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002655 throw e.rethrowFromSystemServer();
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002656 }
2657 }
2658 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002659
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002660 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002661 * Retrieve the current maximum number of login attempts that are allowed before the device
Rubin Xud3609d42016-07-13 18:32:57 +01002662 * or profile is wiped, for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002663 * and its participating profiles. Restrictions on profiles that have a separate challenge are
2664 * not taken into account.
2665 *
2666 * <p>This method can be called on the {@link DevicePolicyManager} instance
2667 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2668 * the value for the parent profile.
2669 *
Robin Lee25e26452015-06-02 09:56:29 -07002670 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002671 * all admins.
2672 */
Robin Lee25e26452015-06-02 09:56:29 -07002673 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002674 return getMaximumFailedPasswordsForWipe(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002675 }
2676
2677 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002678 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08002679 if (mService != null) {
2680 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002681 return mService.getMaximumFailedPasswordsForWipe(
2682 admin, userHandle, mParentInstance);
Dianne Hackborn254cb442010-01-27 19:23:59 -08002683 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002684 throw e.rethrowFromSystemServer();
Dianne Hackborn254cb442010-01-27 19:23:59 -08002685 }
2686 }
2687 return 0;
2688 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002689
Dianne Hackborn254cb442010-01-27 19:23:59 -08002690 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002691 * Returns the profile with the smallest maximum failed passwords for wipe,
2692 * for the given user. So for primary user, it might return the primary or
2693 * a managed profile. For a secondary user, it would be the same as the
2694 * user passed in.
2695 * @hide Used only by Keyguard
2696 */
2697 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
2698 if (mService != null) {
2699 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002700 return mService.getProfileWithMinimumFailedPasswordsForWipe(
2701 userHandle, mParentInstance);
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002702 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002703 throw e.rethrowFromSystemServer();
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002704 }
2705 }
2706 return UserHandle.USER_NULL;
2707 }
2708
2709 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002710 * Flag for {@link #resetPassword}: don't allow other admins to change
2711 * the password again until the user has entered it.
2712 */
2713 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002714
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002715 /**
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002716 * Flag for {@link #resetPassword}: don't ask for user credentials on device boot.
2717 * If the flag is set, the device can be booted without asking for user password.
2718 * The absence of this flag does not change the current boot requirements. This flag
2719 * can be set by the device owner only. If the app is not the device owner, the flag
2720 * is ignored. Once the flag is set, it cannot be reverted back without resetting the
2721 * device to factory defaults.
2722 */
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002723 public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002;
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002724
2725 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002726 * Force a new device unlock password (the password needed to access the entire device, not for
2727 * individual accounts) on the user. This takes effect immediately.
2728 * <p>
Rubin Xuaab7a412016-12-30 21:13:29 +00002729 * <em>For device owner and profile owners targeting SDK level
2730 * {@link android.os.Build.VERSION_CODES#O} or above, this API is no longer available and will
2731 * throw {@link SecurityException}. Please use the new API {@link #resetPasswordWithToken}
2732 * instead. </em>
2733 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002734 * <em>Note: This API has been limited as of {@link android.os.Build.VERSION_CODES#N} for
Makoto Onuki70f929e2015-11-11 12:40:15 -08002735 * device admins that are not device owner and not profile owner.
2736 * The password can now only be changed if there is currently no password set. Device owner
Ricky Wai977ade22016-05-24 15:02:41 +01002737 * and profile owner can still do this when user is unlocked and does not have a managed
2738 * profile.</em>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002739 * <p>
2740 * The given password must be sufficient for the current password quality and length constraints
2741 * as returned by {@link #getPasswordQuality(ComponentName)} and
2742 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then
2743 * it will be rejected and false returned. Note that the password may be a stronger quality
2744 * (containing alphanumeric characters when the requested quality is only numeric), in which
2745 * case the currently active quality will be increased to match.
2746 * <p>
2747 * Calling with a null or empty password will clear any existing PIN, pattern or password if the
Robin Leece5c4002016-03-23 17:05:03 +00002748 * current password constraints allow it. <em>Note: This will not work in
2749 * {@link android.os.Build.VERSION_CODES#N} and later for managed profiles, or for device admins
2750 * that are not device owner or profile owner. Once set, the password cannot be changed to null
2751 * or empty except by these admins.</em>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002752 * <p>
2753 * The calling device admin must have requested
2754 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call this method; if it has
2755 * not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002756 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01002757 * @param password The new password for the user. Null or empty clears the password.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002758 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002759 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
2760 * @return Returns true if the password was applied, or false if it is not acceptable for the
2761 * current constraints or if the user has not been decrypted yet.
2762 * @throws SecurityException if the calling application does not own an active administrator
2763 * that uses {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD}
Ricky Wai977ade22016-05-24 15:02:41 +01002764 * @throws IllegalStateException if the calling user is locked or has a managed profile.
Andrew Scull3f81f4e2016-07-29 16:29:58 +01002765 * @throws IllegalArgumentException if the password does not meet system requirements.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002766 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002767 public boolean resetPassword(String password, int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002768 throwIfParentInstance("resetPassword");
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002769 if (mService != null) {
2770 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002771 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002772 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002773 throw e.rethrowFromSystemServer();
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002774 }
2775 }
2776 return false;
2777 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002778
Dianne Hackbornd6847842010-01-12 18:14:19 -08002779 /**
Rubin Xuaab7a412016-12-30 21:13:29 +00002780 * Called by a profile or device owner to provision a token which can later be used to reset the
Esteban Talavera7e4cbad2017-03-30 17:59:50 +01002781 * device lockscreen password (if called by device owner), or managed profile challenge (if
2782 * called by profile owner), via {@link #resetPasswordWithToken}.
Rubin Xuaab7a412016-12-30 21:13:29 +00002783 * <p>
2784 * If the user currently has a lockscreen password, the provisioned token will not be
2785 * immediately usable; it only becomes active after the user performs a confirm credential
2786 * operation, which can be triggered by {@link KeyguardManager#createConfirmDeviceCredentialIntent}.
2787 * If the user has no lockscreen password, the token is activated immediately. In all cases,
2788 * the active state of the current token can be checked by {@link #isResetPasswordTokenActive}.
2789 * For security reasons, un-activated tokens are only stored in memory and will be lost once
2790 * the device reboots. In this case a new token needs to be provisioned again.
2791 * <p>
2792 * Once provisioned and activated, the token will remain effective even if the user changes
2793 * or clears the lockscreen password.
2794 * <p>
2795 * <em>This token is highly sensitive and should be treated at the same level as user
Rubin Xuf7b036d2017-04-05 18:37:07 +01002796 * credentials. In particular, NEVER store this token on device in plaintext. Do not store
2797 * the plaintext token in device-encrypted storage if it will be needed to reset password on
2798 * file-based encryption devices before user unlocks. Consider carefully how any password token
2799 * will be stored on your server and who will need access to them. Tokens may be the subject of
2800 * legal access requests.
Rubin Xuaab7a412016-12-30 21:13:29 +00002801 * </em>
2802 *
2803 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2804 * @param token a secure token a least 32-byte long, which must be generated by a
2805 * cryptographically strong random number generator.
2806 * @return true if the operation is successful, false otherwise.
2807 * @throws IllegalArgumentException if the supplied token is invalid.
2808 * @throws SecurityException
2809 */
2810 public boolean setResetPasswordToken(ComponentName admin, byte[] token) {
2811 throwIfParentInstance("setResetPasswordToken");
2812 if (mService != null) {
2813 try {
2814 return mService.setResetPasswordToken(admin, token);
2815 } catch (RemoteException e) {
2816 throw e.rethrowFromSystemServer();
2817 }
2818 }
2819 return false;
2820 }
2821
2822 /**
2823 * Called by a profile or device owner to revoke the current password reset token.
2824 *
2825 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2826 * @return true if the operation is successful, false otherwise.
2827 */
2828 public boolean clearResetPasswordToken(ComponentName admin) {
2829 throwIfParentInstance("clearResetPasswordToken");
2830 if (mService != null) {
2831 try {
2832 return mService.clearResetPasswordToken(admin);
2833 } catch (RemoteException e) {
2834 throw e.rethrowFromSystemServer();
2835 }
2836 }
2837 return false;
2838 }
2839
2840 /**
2841 * Called by a profile or device owner to check if the current reset password token is active.
2842 *
2843 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2844 * @return true if the token is active, false otherwise.
2845 * @throws IllegalStateException if no token has been set.
2846 */
2847 public boolean isResetPasswordTokenActive(ComponentName admin) {
2848 throwIfParentInstance("isResetPasswordTokenActive");
2849 if (mService != null) {
2850 try {
2851 return mService.isResetPasswordTokenActive(admin);
2852 } catch (RemoteException e) {
2853 throw e.rethrowFromSystemServer();
2854 }
2855 }
2856 return false;
2857 }
2858
2859 /**
Esteban Talavera7e4cbad2017-03-30 17:59:50 +01002860 * Called by device or profile owner to force set a new device unlock password or a managed
2861 * profile challenge on current user. This takes effect immediately.
Rubin Xuaab7a412016-12-30 21:13:29 +00002862 * <p>
2863 * Unlike {@link #resetPassword}, this API can change the password even before the user or
2864 * device is unlocked or decrypted. The supplied token must have been previously provisioned via
2865 * {@link #setResetPasswordToken}, and in active state {@link #isResetPasswordTokenActive}.
2866 * <p>
2867 * The given password must be sufficient for the current password quality and length constraints
2868 * as returned by {@link #getPasswordQuality(ComponentName)} and
2869 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then
2870 * it will be rejected and false returned. Note that the password may be a stronger quality
2871 * (containing alphanumeric characters when the requested quality is only numeric), in which
2872 * case the currently active quality will be increased to match.
2873 * <p>
2874 * Calling with a null or empty password will clear any existing PIN, pattern or password if the
2875 * current password constraints allow it.
2876 *
2877 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2878 * @param password The new password for the user. Null or empty clears the password.
2879 * @param token the password reset token previously provisioned by #setResetPasswordToken.
2880 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
2881 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
2882 * @return Returns true if the password was applied, or false if it is not acceptable for the
2883 * current constraints.
2884 * @throws SecurityException if the calling application does not own an active administrator
2885 * that uses {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD}
2886 * @throws IllegalStateException if the provided token is not valid.
2887 * @throws IllegalArgumentException if the password does not meet system requirements.
2888 */
2889 public boolean resetPasswordWithToken(@NonNull ComponentName admin, String password,
2890 byte[] token, int flags) {
2891 throwIfParentInstance("resetPassword");
2892 if (mService != null) {
2893 try {
2894 return mService.resetPasswordWithToken(admin, password, token, flags);
2895 } catch (RemoteException e) {
2896 throw e.rethrowFromSystemServer();
2897 }
2898 }
2899 return false;
2900 }
2901
2902 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002903 * Called by an application that is administering the device to set the maximum time for user
2904 * activity until the device will lock. This limits the length that the user can set. It takes
2905 * effect immediately.
2906 * <p>
2907 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
2908 * to be able to call this method; if it has not, a security exception will be thrown.
2909 * <p>
2910 * This method can be called on the {@link DevicePolicyManager} instance returned by
2911 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2912 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002913 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002914 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002915 * @param timeMs The new desired maximum time to lock in milliseconds. A value of 0 means there
2916 * is no restriction.
2917 * @throws SecurityException if {@code admin} is not an active administrator or it does not use
2918 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002919 */
Robin Lee25e26452015-06-02 09:56:29 -07002920 public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002921 if (mService != null) {
2922 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002923 mService.setMaximumTimeToLock(admin, timeMs, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002924 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002925 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002926 }
2927 }
2928 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002929
Dianne Hackbornd6847842010-01-12 18:14:19 -08002930 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002931 * Retrieve the current maximum time to unlock for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01002932 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00002933 * a separate challenge are not taken into account.
2934 *
2935 * <p>This method can be called on the {@link DevicePolicyManager} instance
2936 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2937 * restrictions on the parent profile.
2938 *
Robin Lee25e26452015-06-02 09:56:29 -07002939 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002940 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07002941 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07002942 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002943 */
Robin Lee25e26452015-06-02 09:56:29 -07002944 public long getMaximumTimeToLock(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002945 return getMaximumTimeToLock(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002946 }
2947
2948 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002949 public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002950 if (mService != null) {
2951 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002952 return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002953 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002954 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002955 }
2956 }
2957 return 0;
2958 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002959
Dianne Hackbornd6847842010-01-12 18:14:19 -08002960 /**
Ricky Wai035e9242016-03-18 16:43:31 +00002961 * Returns maximum time to lock that applied by all profiles in this user. We do this because we
2962 * do not have a separate timeout to lock for work challenge only.
2963 *
2964 * @hide
2965 */
2966 public long getMaximumTimeToLockForUserAndProfiles(int userHandle) {
2967 if (mService != null) {
2968 try {
2969 return mService.getMaximumTimeToLockForUserAndProfiles(userHandle);
2970 } catch (RemoteException e) {
2971 throw e.rethrowFromSystemServer();
2972 }
2973 }
2974 return 0;
2975 }
2976
2977 /**
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002978 * Called by a device/profile owner to set the timeout after which unlocking with secondary, non
2979 * strong auth (e.g. fingerprint, trust agents) times out, i.e. the user has to use a strong
2980 * authentication method like password, pin or pattern.
2981 *
2982 * <p>This timeout is used internally to reset the timer to require strong auth again after
2983 * specified timeout each time it has been successfully used.
2984 *
2985 * <p>Fingerprint can also be disabled altogether using {@link #KEYGUARD_DISABLE_FINGERPRINT}.
2986 *
2987 * <p>Trust agents can also be disabled altogether using {@link #KEYGUARD_DISABLE_TRUST_AGENTS}.
2988 *
2989 * <p>The calling device admin must be a device or profile owner. If it is not,
2990 * a {@link SecurityException} will be thrown.
2991 *
Michal Karpinski943aabd2016-10-06 11:09:25 +01002992 * <p>The calling device admin can verify the value it has set by calling
2993 * {@link #getRequiredStrongAuthTimeout(ComponentName)} and passing in its instance.
2994 *
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002995 * <p>This method can be called on the {@link DevicePolicyManager} instance returned by
2996 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2997 * profile.
2998 *
2999 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xu5d39ea72017-04-24 20:26:30 +01003000 * @param timeoutMs The new timeout in milliseconds, after which the user will have to unlock
3001 * with strong authentication method. A value of 0 means the admin is not participating
3002 * in controlling the timeout.
Michal Karpinski943aabd2016-10-06 11:09:25 +01003003 * The minimum and maximum timeouts are platform-defined and are typically 1 hour and
3004 * 72 hours, respectively. Though discouraged, the admin may choose to require strong
3005 * auth at all times using {@link #KEYGUARD_DISABLE_FINGERPRINT} and/or
3006 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01003007 *
3008 * @throws SecurityException if {@code admin} is not a device or profile owner.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01003009 */
3010 public void setRequiredStrongAuthTimeout(@NonNull ComponentName admin,
3011 long timeoutMs) {
3012 if (mService != null) {
3013 try {
3014 mService.setRequiredStrongAuthTimeout(admin, timeoutMs, mParentInstance);
3015 } catch (RemoteException e) {
3016 throw e.rethrowFromSystemServer();
3017 }
3018 }
3019 }
3020
3021 /**
3022 * Determine for how long the user will be able to use secondary, non strong auth for
3023 * authentication, since last strong method authentication (password, pin or pattern) was used.
3024 * After the returned timeout the user is required to use strong authentication method.
3025 *
3026 * <p>This method can be called on the {@link DevicePolicyManager} instance
3027 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
3028 * restrictions on the parent profile.
3029 *
3030 * @param admin The name of the admin component to check, or {@code null} to aggregate
3031 * accross all participating admins.
Rubin Xu5d39ea72017-04-24 20:26:30 +01003032 * @return The timeout in milliseconds or 0 if not configured for the provided admin.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01003033 */
3034 public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin) {
3035 return getRequiredStrongAuthTimeout(admin, myUserId());
3036 }
3037
3038 /** @hide per-user version */
3039 public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin, @UserIdInt int userId) {
3040 if (mService != null) {
3041 try {
3042 return mService.getRequiredStrongAuthTimeout(admin, userId, mParentInstance);
3043 } catch (RemoteException e) {
3044 throw e.rethrowFromSystemServer();
3045 }
3046 }
3047 return DEFAULT_STRONG_AUTH_TIMEOUT_MS;
3048 }
3049
3050 /**
Andrew Scull85a63bc2016-10-24 13:47:47 +01003051 * Flag for {@link #lockNow(int)}: also evict the user's credential encryption key from the
3052 * keyring. The user's credential will need to be entered again in order to derive the
3053 * credential encryption key that will be stored back in the keyring for future use.
3054 * <p>
Andrew Scull17e1b5d2017-04-25 14:44:24 +01003055 * This flag can only be used by a profile owner when locking a managed profile when
3056 * {@link #getStorageEncryptionStatus} returns {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}.
Andrew Scull85a63bc2016-10-24 13:47:47 +01003057 * <p>
3058 * In order to secure user data, the user will be stopped and restarted so apps should wait
3059 * until they are next run to perform further actions.
3060 */
Andrew Scull17e1b5d2017-04-25 14:44:24 +01003061 public static final int FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY = 1;
3062
Andrew Scull85a63bc2016-10-24 13:47:47 +01003063 /** @hide */
3064 @Retention(RetentionPolicy.SOURCE)
Andrew Scull17e1b5d2017-04-25 14:44:24 +01003065 @IntDef(flag=true, value={FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY})
Andrew Scull85a63bc2016-10-24 13:47:47 +01003066 public @interface LockNowFlag {}
3067
3068 /**
3069 * Make the device lock immediately, as if the lock screen timeout has expired at the point of
3070 * this call.
3071 * <p>
3072 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
3073 * to be able to call this method; if it has not, a security exception will be thrown.
3074 * <p>
3075 * This method can be called on the {@link DevicePolicyManager} instance returned by
3076 * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile.
3077 * <p>
3078 * Equivalent to calling {@link #lockNow(int)} with no flags.
3079 *
3080 * @throws SecurityException if the calling application does not own an active administrator
3081 * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
3082 */
3083 public void lockNow() {
3084 lockNow(0);
3085 }
3086
3087 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003088 * Make the device lock immediately, as if the lock screen timeout has expired at the point of
3089 * this call.
3090 * <p>
3091 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
3092 * to be able to call this method; if it has not, a security exception will be thrown.
3093 * <p>
3094 * This method can be called on the {@link DevicePolicyManager} instance returned by
3095 * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003096 *
Andrew Scull17e1b5d2017-04-25 14:44:24 +01003097 * @param flags May be 0 or {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003098 * @throws SecurityException if the calling application does not own an active administrator
Andrew Scull85a63bc2016-10-24 13:47:47 +01003099 * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} or the
Andrew Scull17e1b5d2017-04-25 14:44:24 +01003100 * {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY} flag is passed by an application
3101 * that is not a profile
Andrew Scull85a63bc2016-10-24 13:47:47 +01003102 * owner of a managed profile.
Andrew Scull17e1b5d2017-04-25 14:44:24 +01003103 * @throws IllegalArgumentException if the {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY} flag is
3104 * passed when locking the parent profile.
3105 * @throws UnsupportedOperationException if the {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY}
3106 * flag is passed when {@link #getStorageEncryptionStatus} does not return
3107 * {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08003108 */
Andrew Scull85a63bc2016-10-24 13:47:47 +01003109 public void lockNow(@LockNowFlag int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -08003110 if (mService != null) {
3111 try {
Andrew Scull85a63bc2016-10-24 13:47:47 +01003112 mService.lockNow(flags, mParentInstance);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08003113 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003114 throw e.rethrowFromSystemServer();
Dianne Hackborndf83afa2010-01-20 13:37:26 -08003115 }
3116 }
3117 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003118
Dianne Hackbornd6847842010-01-12 18:14:19 -08003119 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07003120 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00003121 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07003122 */
3123 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
3124
3125 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00003126 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
3127 * data.
3128 *
Paul Crowley2934b262014-12-02 11:21:13 +00003129 * <p>This flag may only be set by device owner admins; if it is set by
3130 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00003131 */
3132 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
3133
3134 /**
yinxuf4f9cec2017-06-19 10:28:19 -07003135 * Flag for {@link #wipeData(int)}: also erase the device's eUICC data.
3136 *
3137 * TODO(b/35851809): make this public.
3138 * @hide
3139 */
3140 public static final int WIPE_EUICC = 0x0004;
3141
3142 /**
Suprabh Shukla556b05a2016-08-10 15:49:24 -07003143 * Ask that all user data be wiped. If called as a secondary user, the user will be removed and
3144 * other users will remain unaffected. Calling from the primary user will cause the device to
3145 * reboot, erasing all device data - including all the secondary users and their data - while
3146 * booting up.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003147 * <p>
3148 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to
3149 * be able to call this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003150 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003151 * @param flags Bit mask of additional options: currently supported flags are
3152 * {@link #WIPE_EXTERNAL_STORAGE} and {@link #WIPE_RESET_PROTECTION_DATA}.
3153 * @throws SecurityException if the calling application does not own an active administrator
3154 * that uses {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}
Dianne Hackbornd6847842010-01-12 18:14:19 -08003155 */
3156 public void wipeData(int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003157 throwIfParentInstance("wipeData");
Dianne Hackbornd6847842010-01-12 18:14:19 -08003158 if (mService != null) {
3159 try {
Makoto Onuki70f929e2015-11-11 12:40:15 -08003160 mService.wipeData(flags);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003161 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003162 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003163 }
3164 }
3165 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003166
Dianne Hackbornd6847842010-01-12 18:14:19 -08003167 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07003168 * Called by an application that is administering the device to set the
3169 * global proxy and exclusion list.
3170 * <p>
3171 * The calling device admin must have requested
3172 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
3173 * this method; if it has not, a security exception will be thrown.
3174 * Only the first device admin can set the proxy. If a second admin attempts
3175 * to set the proxy, the {@link ComponentName} of the admin originally setting the
Robin Lee25e26452015-06-02 09:56:29 -07003176 * proxy will be returned. If successful in setting the proxy, {@code null} will
Oscar Montemayor69238c62010-08-03 10:51:06 -07003177 * be returned.
3178 * The method can be called repeatedly by the device admin alrady setting the
3179 * proxy to update the proxy and exclusion list.
3180 *
Robin Lee25e26452015-06-02 09:56:29 -07003181 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Oscar Montemayor69238c62010-08-03 10:51:06 -07003182 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
3183 * Pass Proxy.NO_PROXY to reset the proxy.
3184 * @param exclusionList a list of domains to be excluded from the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07003185 * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName}
3186 * of the device admin that sets the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08003187 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07003188 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003189 public @Nullable ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec,
Oscar Montemayor69238c62010-08-03 10:51:06 -07003190 List<String> exclusionList ) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003191 throwIfParentInstance("setGlobalProxy");
Oscar Montemayor69238c62010-08-03 10:51:06 -07003192 if (proxySpec == null) {
3193 throw new NullPointerException();
3194 }
3195 if (mService != null) {
3196 try {
3197 String hostSpec;
3198 String exclSpec;
3199 if (proxySpec.equals(Proxy.NO_PROXY)) {
3200 hostSpec = null;
3201 exclSpec = null;
3202 } else {
3203 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
3204 throw new IllegalArgumentException();
3205 }
3206 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
3207 String hostName = sa.getHostName();
3208 int port = sa.getPort();
3209 StringBuilder hostBuilder = new StringBuilder();
3210 hostSpec = hostBuilder.append(hostName)
3211 .append(":").append(Integer.toString(port)).toString();
3212 if (exclusionList == null) {
3213 exclSpec = "";
3214 } else {
3215 StringBuilder listBuilder = new StringBuilder();
3216 boolean firstDomain = true;
3217 for (String exclDomain : exclusionList) {
3218 if (!firstDomain) {
3219 listBuilder = listBuilder.append(",");
3220 } else {
3221 firstDomain = false;
3222 }
3223 listBuilder = listBuilder.append(exclDomain.trim());
3224 }
3225 exclSpec = listBuilder.toString();
3226 }
Yuhao Zheng90704842014-02-28 17:22:45 -08003227 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
3228 != android.net.Proxy.PROXY_VALID)
3229 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07003230 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003231 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07003232 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003233 throw e.rethrowFromSystemServer();
Oscar Montemayor69238c62010-08-03 10:51:06 -07003234 }
3235 }
3236 return null;
3237 }
3238
3239 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003240 * Set a network-independent global HTTP proxy. This is not normally what you want for typical
3241 * HTTP proxies - they are generally network dependent. However if you're doing something
3242 * unusual like general internal filtering this may be useful. On a private network where the
3243 * proxy is not accessible, you may break HTTP using this.
3244 * <p>
3245 * This method requires the caller to be the device owner.
3246 * <p>
3247 * This proxy is only a recommendation and it is possible that some apps will ignore it.
Jason Monk03bc9912014-05-13 09:44:57 -04003248 *
Jason Monk03bc9912014-05-13 09:44:57 -04003249 * @see ProxyInfo
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003250 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3251 * @param proxyInfo The a {@link ProxyInfo} object defining the new global HTTP proxy. A
3252 * {@code null} value will clear the global HTTP proxy.
3253 * @throws SecurityException if {@code admin} is not the device owner.
Jason Monk03bc9912014-05-13 09:44:57 -04003254 */
Robin Lee25e26452015-06-02 09:56:29 -07003255 public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo
3256 proxyInfo) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003257 throwIfParentInstance("setRecommendedGlobalProxy");
Jason Monk03bc9912014-05-13 09:44:57 -04003258 if (mService != null) {
3259 try {
3260 mService.setRecommendedGlobalProxy(admin, proxyInfo);
3261 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003262 throw e.rethrowFromSystemServer();
Jason Monk03bc9912014-05-13 09:44:57 -04003263 }
3264 }
3265 }
3266
3267 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07003268 * Returns the component name setting the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07003269 * @return ComponentName object of the device admin that set the global proxy, or {@code null}
3270 * if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08003271 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07003272 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003273 public @Nullable ComponentName getGlobalProxyAdmin() {
Oscar Montemayor69238c62010-08-03 10:51:06 -07003274 if (mService != null) {
3275 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003276 return mService.getGlobalProxyAdmin(myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07003277 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003278 throw e.rethrowFromSystemServer();
Oscar Montemayor69238c62010-08-03 10:51:06 -07003279 }
3280 }
3281 return null;
3282 }
3283
3284 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08003285 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003286 * indicating that encryption is not supported.
3287 */
3288 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
3289
3290 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08003291 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003292 * indicating that encryption is supported, but is not currently active.
3293 */
3294 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
3295
3296 /**
Robin Lee3795fb02015-02-16 14:17:23 +00003297 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003298 * indicating that encryption is not currently active, but is currently
3299 * being activated. This is only reported by devices that support
3300 * encryption of data and only when the storage is currently
3301 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
3302 * to become encrypted will never return this value.
3303 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08003304 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003305
3306 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08003307 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003308 * indicating that encryption is active.
Amith Yamasani75db1252016-07-11 14:41:01 -07003309 * <p>
3310 * Also see {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003311 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08003312 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003313
3314 /**
Robin Lee3795fb02015-02-16 14:17:23 +00003315 * Result code for {@link #getStorageEncryptionStatus}:
3316 * indicating that encryption is active, but an encryption key has not
3317 * been set by the user.
3318 */
3319 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
3320
3321 /**
Makoto Onukid4c9e542016-02-25 18:17:30 -08003322 * Result code for {@link #getStorageEncryptionStatus}:
Amith Yamasani75db1252016-07-11 14:41:01 -07003323 * indicating that encryption is active and the encryption key is tied to the user or profile.
3324 * <p>
3325 * This value is only returned to apps targeting API level 24 and above. For apps targeting
3326 * earlier API levels, {@link #ENCRYPTION_STATUS_ACTIVE} is returned, even if the
3327 * encryption key is specific to the user or profile.
Makoto Onukid4c9e542016-02-25 18:17:30 -08003328 */
3329 public static final int ENCRYPTION_STATUS_ACTIVE_PER_USER = 5;
3330
3331 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003332 * Activity action: begin the process of encrypting data on the device. This activity should
3333 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
3334 * After resuming from this activity, use {@link #getStorageEncryption}
3335 * to check encryption status. However, on some devices this activity may never return, as
3336 * it may trigger a reboot and in some cases a complete data wipe of the device.
3337 */
3338 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
3339 public static final String ACTION_START_ENCRYPTION
3340 = "android.app.action.START_ENCRYPTION";
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003341 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07003342 * Widgets are enabled in keyguard
3343 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07003344 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07003345
3346 /**
Jim Miller50e62182014-04-23 17:25:00 -07003347 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07003348 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07003349 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
3350
3351 /**
3352 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
3353 */
3354 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
3355
3356 /**
Jim Miller50e62182014-04-23 17:25:00 -07003357 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
3358 */
3359 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
3360
3361 /**
3362 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
3363 */
3364 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
3365
3366 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02003367 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07003368 * (e.g. PIN/Pattern/Password).
3369 */
3370 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
3371
3372 /**
Jim Miller06e34502014-07-17 14:46:05 -07003373 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
3374 */
3375 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
3376
3377 /**
Adrian Roos7f06eed2016-02-05 15:21:02 -08003378 * Disable text entry into notifications on secure keyguard screens (e.g. PIN/Pattern/Password).
3379 */
3380 public static final int KEYGUARD_DISABLE_REMOTE_INPUT = 1 << 6;
3381
3382 /**
Jim Miller35207742012-11-02 15:33:20 -07003383 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07003384 */
3385 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07003386
3387 /**
Robin Leeacdeac62017-02-21 22:13:38 +00003388 * Keyguard features that when set on a managed profile that doesn't have its own challenge will
3389 * affect the profile's parent user. These can also be set on the managed profile's parent
3390 * {@link DevicePolicyManager} instance.
3391 *
3392 * @hide
3393 */
3394 public static final int PROFILE_KEYGUARD_FEATURES_AFFECT_OWNER =
3395 DevicePolicyManager.KEYGUARD_DISABLE_TRUST_AGENTS
3396 | DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT;
3397
3398 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003399 * Called by an application that is administering the device to request that the storage system
3400 * be encrypted.
3401 * <p>
3402 * When multiple device administrators attempt to control device encryption, the most secure,
3403 * supported setting will always be used. If any device administrator requests device
3404 * encryption, it will be enabled; Conversely, if a device administrator attempts to disable
3405 * device encryption while another device administrator has enabled it, the call to disable will
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003406 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003407 * <p>
3408 * This policy controls encryption of the secure (application data) storage area. Data written
3409 * to other storage areas may or may not be encrypted, and this policy does not require or
3410 * control the encryption of any other storage areas. There is one exception: If
3411 * {@link android.os.Environment#isExternalStorageEmulated()} is {@code true}, then the
3412 * directory returned by {@link android.os.Environment#getExternalStorageDirectory()} must be
3413 * written to disk within the encrypted storage area.
3414 * <p>
3415 * Important Note: On some devices, it is possible to encrypt storage without requiring the user
3416 * to create a device PIN or Password. In this case, the storage is encrypted, but the
3417 * encryption key may not be fully secured. For maximum security, the administrator should also
3418 * require (and check for) a pattern, PIN, or password.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003419 *
3420 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3421 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08003422 * @return the new request status (for all active admins) - will be one of
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003423 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
3424 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
3425 * {@link #getStorageEncryptionStatus()} to query the actual device state.
3426 * @throws SecurityException if {@code admin} is not an active administrator or does not use
3427 * {@link DeviceAdminInfo#USES_ENCRYPTED_STORAGE}
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003428 */
Robin Lee25e26452015-06-02 09:56:29 -07003429 public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003430 throwIfParentInstance("setStorageEncryption");
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003431 if (mService != null) {
3432 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003433 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003434 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003435 throw e.rethrowFromSystemServer();
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003436 }
3437 }
3438 return ENCRYPTION_STATUS_UNSUPPORTED;
3439 }
3440
3441 /**
3442 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08003443 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003444 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08003445 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
3446 * this will return the requested encryption setting as an aggregate of all active
3447 * administrators.
3448 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003449 */
Robin Lee25e26452015-06-02 09:56:29 -07003450 public boolean getStorageEncryption(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003451 throwIfParentInstance("getStorageEncryption");
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003452 if (mService != null) {
3453 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003454 return mService.getStorageEncryption(admin, myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003455 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003456 throw e.rethrowFromSystemServer();
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003457 }
3458 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08003459 return false;
3460 }
3461
3462 /**
3463 * Called by an application that is administering the device to
3464 * determine the current encryption status of the device.
Amith Yamasani75db1252016-07-11 14:41:01 -07003465 * <p>
Andy Stadler22dbfda2011-01-17 12:47:31 -08003466 * Depending on the returned status code, the caller may proceed in different
3467 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
3468 * storage system does not support encryption. If the
3469 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
3470 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00003471 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
3472 * storage system has enabled encryption but no password is set so further action
Amith Yamasani75db1252016-07-11 14:41:01 -07003473 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING},
3474 * {@link #ENCRYPTION_STATUS_ACTIVE} or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER},
3475 * no further action is required.
Andy Stadler22dbfda2011-01-17 12:47:31 -08003476 *
Robin Lee7e678712014-07-24 16:41:31 +01003477 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08003478 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00003479 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
Amith Yamasani75db1252016-07-11 14:41:01 -07003480 * {@link #ENCRYPTION_STATUS_ACTIVE}, or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08003481 */
3482 public int getStorageEncryptionStatus() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003483 throwIfParentInstance("getStorageEncryptionStatus");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003484 return getStorageEncryptionStatus(myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003485 }
3486
3487 /** @hide per-user version */
3488 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08003489 if (mService != null) {
3490 try {
Makoto Onukid4c9e542016-02-25 18:17:30 -08003491 return mService.getStorageEncryptionStatus(mContext.getPackageName(), userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08003492 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003493 throw e.rethrowFromSystemServer();
Andy Stadler22dbfda2011-01-17 12:47:31 -08003494 }
3495 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003496 return ENCRYPTION_STATUS_UNSUPPORTED;
3497 }
3498
3499 /**
Robin Lee2f7e1e42016-03-21 10:50:01 +00003500 * Mark a CA certificate as approved by the device user. This means that they have been notified
3501 * of the installation, were made aware of the risks, viewed the certificate and still wanted to
3502 * keep the certificate on the device.
3503 *
3504 * Calling with {@param approval} as {@code true} will cancel any ongoing warnings related to
3505 * this certificate.
3506 *
3507 * @hide
3508 */
3509 public boolean approveCaCert(String alias, int userHandle, boolean approval) {
3510 if (mService != null) {
3511 try {
3512 return mService.approveCaCert(alias, userHandle, approval);
3513 } catch (RemoteException e) {
3514 throw e.rethrowFromSystemServer();
3515 }
3516 }
3517 return false;
3518 }
3519
3520 /**
3521 * Check whether a CA certificate has been approved by the device user.
3522 *
3523 * @hide
3524 */
3525 public boolean isCaCertApproved(String alias, int userHandle) {
3526 if (mService != null) {
3527 try {
3528 return mService.isCaCertApproved(alias, userHandle);
3529 } catch (RemoteException e) {
3530 throw e.rethrowFromSystemServer();
3531 }
3532 }
3533 return false;
3534 }
3535
3536 /**
Robin Lee7e678712014-07-24 16:41:31 +01003537 * Installs the given certificate as a user CA.
3538 *
Edman Anjosf9946772016-11-28 16:35:15 +01003539 * The caller must be a profile or device owner on that user, or a delegate package given the
3540 * {@link #DELEGATION_CERT_INSTALL} scope via {@link #setDelegatedScopes}; otherwise a
3541 * security exception will be thrown.
3542 *
Robin Lee25e26452015-06-02 09:56:29 -07003543 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3544 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003545 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04003546 *
3547 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01003548 * interrupted, true otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003549 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3550 * owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003551 * @see #setDelegatedScopes
3552 * @see #DELEGATION_CERT_INSTALL
Maggie Benthallda51e682013-08-08 22:35:44 -04003553 */
Robin Lee25e26452015-06-02 09:56:29 -07003554 public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003555 throwIfParentInstance("installCaCert");
Maggie Benthallda51e682013-08-08 22:35:44 -04003556 if (mService != null) {
3557 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003558 return mService.installCaCert(admin, mContext.getPackageName(), certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04003559 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003560 throw e.rethrowFromSystemServer();
Maggie Benthallda51e682013-08-08 22:35:44 -04003561 }
3562 }
3563 return false;
3564 }
3565
3566 /**
Robin Lee7e678712014-07-24 16:41:31 +01003567 * Uninstalls the given certificate from trusted user CAs, if present.
3568 *
Edman Anjosf9946772016-11-28 16:35:15 +01003569 * The caller must be a profile or device owner on that user, or a delegate package given the
3570 * {@link #DELEGATION_CERT_INSTALL} scope via {@link #setDelegatedScopes}; otherwise a
3571 * security exception will be thrown.
3572 *
Robin Lee25e26452015-06-02 09:56:29 -07003573 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3574 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003575 * @param certBuffer encoded form of the certificate to remove.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003576 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3577 * owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003578 * @see #setDelegatedScopes
3579 * @see #DELEGATION_CERT_INSTALL
Maggie Benthallda51e682013-08-08 22:35:44 -04003580 */
Robin Lee25e26452015-06-02 09:56:29 -07003581 public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003582 throwIfParentInstance("uninstallCaCert");
Maggie Benthallda51e682013-08-08 22:35:44 -04003583 if (mService != null) {
3584 try {
Robin Lee306fe082014-06-19 14:04:24 +00003585 final String alias = getCaCertAlias(certBuffer);
Edman Anjosf9946772016-11-28 16:35:15 +01003586 mService.uninstallCaCerts(admin, mContext.getPackageName(), new String[] {alias});
Robin Lee306fe082014-06-19 14:04:24 +00003587 } catch (CertificateException e) {
3588 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04003589 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003590 throw e.rethrowFromSystemServer();
Maggie Benthallda51e682013-08-08 22:35:44 -04003591 }
3592 }
3593 }
3594
3595 /**
Robin Lee7e678712014-07-24 16:41:31 +01003596 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
3597 * If a user has installed any certificates by other means than device policy these will be
3598 * included too.
3599 *
Robin Lee25e26452015-06-02 09:56:29 -07003600 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3601 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003602 * @return a List of byte[] arrays, each encoding one user CA certificate.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003603 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3604 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04003605 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003606 public @NonNull List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) {
3607 final List<byte[]> certs = new ArrayList<byte[]>();
Benjamin Franzbc33c822016-04-15 08:57:52 +01003608 throwIfParentInstance("getInstalledCaCerts");
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003609 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01003610 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003611 mService.enforceCanManageCaCerts(admin, mContext.getPackageName());
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003612 final TrustedCertificateStore certStore = new TrustedCertificateStore();
3613 for (String alias : certStore.userAliases()) {
3614 try {
3615 certs.add(certStore.getCertificate(alias).getEncoded());
3616 } catch (CertificateException ce) {
3617 Log.w(TAG, "Could not encode certificate: " + alias, ce);
3618 }
3619 }
3620 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003621 throw re.rethrowFromSystemServer();
Robin Lee7e678712014-07-24 16:41:31 +01003622 }
3623 }
3624 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04003625 }
3626
3627 /**
Robin Lee7e678712014-07-24 16:41:31 +01003628 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
3629 * means other than device policy will also be removed, except for system CA certificates.
3630 *
Robin Lee25e26452015-06-02 09:56:29 -07003631 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3632 * {@code null} if calling from a delegated certificate installer.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003633 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3634 * owner.
Robin Lee7e678712014-07-24 16:41:31 +01003635 */
Robin Lee25e26452015-06-02 09:56:29 -07003636 public void uninstallAllUserCaCerts(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003637 throwIfParentInstance("uninstallAllUserCaCerts");
Robin Lee7e678712014-07-24 16:41:31 +01003638 if (mService != null) {
Robin Lee83881bd2015-06-09 16:04:38 -07003639 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003640 mService.uninstallCaCerts(admin, mContext.getPackageName(),
3641 new TrustedCertificateStore().userAliases() .toArray(new String[0]));
Robin Lee83881bd2015-06-09 16:04:38 -07003642 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003643 throw re.rethrowFromSystemServer();
Robin Lee7e678712014-07-24 16:41:31 +01003644 }
3645 }
3646 }
3647
3648 /**
3649 * Returns whether this certificate is installed as a trusted CA.
3650 *
Robin Lee25e26452015-06-02 09:56:29 -07003651 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3652 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003653 * @param certBuffer encoded form of the certificate to look up.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003654 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3655 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04003656 */
Robin Lee25e26452015-06-02 09:56:29 -07003657 public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003658 throwIfParentInstance("hasCaCertInstalled");
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003659 if (mService != null) {
3660 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003661 mService.enforceCanManageCaCerts(admin, mContext.getPackageName());
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003662 return getCaCertAlias(certBuffer) != null;
3663 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003664 throw re.rethrowFromSystemServer();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003665 } catch (CertificateException ce) {
3666 Log.w(TAG, "Could not parse certificate", ce);
3667 }
Maggie Benthallda51e682013-08-08 22:35:44 -04003668 }
3669 return false;
3670 }
3671
3672 /**
Robin Leece3399f2016-02-24 12:08:32 +00003673 * Called by a device or profile owner, or delegated certificate installer, to install a
3674 * certificate and corresponding private key. All apps within the profile will be able to access
3675 * the certificate and use the private key, given direct user approval.
3676 *
3677 * <p>Access to the installed credentials will not be granted to the caller of this API without
3678 * direct user approval. This is for security - should a certificate installer become
3679 * compromised, certificates it had already installed will be protected.
3680 *
3681 * <p>If the installer must have access to the credentials, call
Rubin Xub4365912016-03-23 12:13:22 +00003682 * {@link #installKeyPair(ComponentName, PrivateKey, Certificate[], String, boolean)} instead.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003683 *
Robin Lee25e26452015-06-02 09:56:29 -07003684 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3685 * {@code null} if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003686 * @param privKey The private key to install.
3687 * @param cert The certificate to install.
3688 * @param alias The private key alias under which to install the certificate. If a certificate
3689 * with that alias already exists, it will be overwritten.
3690 * @return {@code true} if the keys were installed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003691 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3692 * owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003693 * @see #setDelegatedScopes
3694 * @see #DELEGATION_CERT_INSTALL
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003695 */
Robin Leefbc65642015-08-03 16:21:22 +01003696 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
3697 @NonNull Certificate cert, @NonNull String alias) {
Rubin Xub4365912016-03-23 12:13:22 +00003698 return installKeyPair(admin, privKey, new Certificate[] {cert}, alias, false);
Robin Leece3399f2016-02-24 12:08:32 +00003699 }
3700
3701 /**
3702 * Called by a device or profile owner, or delegated certificate installer, to install a
Rubin Xub4365912016-03-23 12:13:22 +00003703 * certificate chain and corresponding private key for the leaf certificate. All apps within the
3704 * profile will be able to access the certificate chain and use the private key, given direct
3705 * user approval.
Robin Leece3399f2016-02-24 12:08:32 +00003706 *
Robin Leea1b290e2016-03-09 14:38:36 +00003707 * <p>The caller of this API may grant itself access to the certificate and private key
3708 * immediately, without user approval. It is a best practice not to request this unless strictly
3709 * necessary since it opens up additional security vulnerabilities.
Robin Leece3399f2016-02-24 12:08:32 +00003710 *
3711 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Robin Leea1b290e2016-03-09 14:38:36 +00003712 * {@code null} if calling from a delegated certificate installer.
Robin Leece3399f2016-02-24 12:08:32 +00003713 * @param privKey The private key to install.
Rubin Xub4365912016-03-23 12:13:22 +00003714 * @param certs The certificate chain to install. The chain should start with the leaf
3715 * certificate and include the chain of trust in order. This will be returned by
3716 * {@link android.security.KeyChain#getCertificateChain}.
Robin Leece3399f2016-02-24 12:08:32 +00003717 * @param alias The private key alias under which to install the certificate. If a certificate
Robin Leea1b290e2016-03-09 14:38:36 +00003718 * with that alias already exists, it will be overwritten.
Robin Leece3399f2016-02-24 12:08:32 +00003719 * @param requestAccess {@code true} to request that the calling app be granted access to the
Robin Leea1b290e2016-03-09 14:38:36 +00003720 * credentials immediately. Otherwise, access to the credentials will be gated by user
3721 * approval.
Robin Leece3399f2016-02-24 12:08:32 +00003722 * @return {@code true} if the keys were installed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003723 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3724 * owner.
Rubin Xub4365912016-03-23 12:13:22 +00003725 * @see android.security.KeyChain#getCertificateChain
Edman Anjosf9946772016-11-28 16:35:15 +01003726 * @see #setDelegatedScopes
3727 * @see #DELEGATION_CERT_INSTALL
Robin Leece3399f2016-02-24 12:08:32 +00003728 */
3729 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
Rubin Xub4365912016-03-23 12:13:22 +00003730 @NonNull Certificate[] certs, @NonNull String alias, boolean requestAccess) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003731 throwIfParentInstance("installKeyPair");
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003732 try {
Rubin Xub4365912016-03-23 12:13:22 +00003733 final byte[] pemCert = Credentials.convertToPem(certs[0]);
3734 byte[] pemChain = null;
3735 if (certs.length > 1) {
3736 pemChain = Credentials.convertToPem(Arrays.copyOfRange(certs, 1, certs.length));
3737 }
Robin Lee0d5ccb72014-09-12 17:41:44 +01003738 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
3739 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
Edman Anjosf9946772016-11-28 16:35:15 +01003740 return mService.installKeyPair(admin, mContext.getPackageName(), pkcs8Key, pemCert,
3741 pemChain, alias, requestAccess);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003742 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003743 throw e.rethrowFromSystemServer();
Robin Lee0d5ccb72014-09-12 17:41:44 +01003744 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
3745 Log.w(TAG, "Failed to obtain private key material", e);
3746 } catch (CertificateException | IOException e) {
3747 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003748 }
3749 return false;
3750 }
3751
3752 /**
Robin Leea1b290e2016-03-09 14:38:36 +00003753 * Called by a device or profile owner, or delegated certificate installer, to remove a
3754 * certificate and private key pair installed under a given alias.
Robin Leefbc65642015-08-03 16:21:22 +01003755 *
3756 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Robin Leea1b290e2016-03-09 14:38:36 +00003757 * {@code null} if calling from a delegated certificate installer.
Robin Leefbc65642015-08-03 16:21:22 +01003758 * @param alias The private key alias under which the certificate is installed.
Robin Leea1b290e2016-03-09 14:38:36 +00003759 * @return {@code true} if the private key alias no longer exists, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003760 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3761 * owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003762 * @see #setDelegatedScopes
3763 * @see #DELEGATION_CERT_INSTALL
Robin Leefbc65642015-08-03 16:21:22 +01003764 */
3765 public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003766 throwIfParentInstance("removeKeyPair");
Robin Leefbc65642015-08-03 16:21:22 +01003767 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003768 return mService.removeKeyPair(admin, mContext.getPackageName(), alias);
Robin Leefbc65642015-08-03 16:21:22 +01003769 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003770 throw e.rethrowFromSystemServer();
Robin Leefbc65642015-08-03 16:21:22 +01003771 }
Robin Leefbc65642015-08-03 16:21:22 +01003772 }
3773
3774 /**
Robin Lee25e26452015-06-02 09:56:29 -07003775 * @return the alias of a given CA certificate in the certificate store, or {@code null} if it
Robin Lee306fe082014-06-19 14:04:24 +00003776 * doesn't exist.
3777 */
3778 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
3779 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
3780 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
3781 new ByteArrayInputStream(certBuffer));
3782 return new TrustedCertificateStore().getCertificateAlias(cert);
3783 }
3784
3785 /**
Rubin Xuec32b562015-03-03 17:34:05 +00003786 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01003787 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00003788 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01003789 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00003790 * <p>
3791 * Delegated certificate installer is a per-user state. The delegated access is persistent until
3792 * it is later cleared by calling this method with a null value or uninstallling the certificate
3793 * installer.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003794 * <p>
Rubin Xuf03d0a62016-02-10 14:54:15 +00003795 * <b>Note:</b>Starting from {@link android.os.Build.VERSION_CODES#N}, if the caller
3796 * application's target SDK version is {@link android.os.Build.VERSION_CODES#N} or newer, the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003797 * supplied certificate installer package must be installed when calling this API, otherwise an
3798 * {@link IllegalArgumentException} will be thrown.
Rubin Xuec32b562015-03-03 17:34:05 +00003799 *
Robin Lee25e26452015-06-02 09:56:29 -07003800 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xuec32b562015-03-03 17:34:05 +00003801 * @param installerPackage The package name of the certificate installer which will be given
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003802 * access. If {@code null} is given the current package will be cleared.
3803 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003804 *
3805 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #setDelegatedScopes}
3806 * with the {@link #DELEGATION_CERT_INSTALL} scope instead.
Rubin Xuec32b562015-03-03 17:34:05 +00003807 */
Edman Anjosf9946772016-11-28 16:35:15 +01003808 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07003809 public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String
3810 installerPackage) throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003811 throwIfParentInstance("setCertInstallerPackage");
Rubin Xuec32b562015-03-03 17:34:05 +00003812 if (mService != null) {
3813 try {
Robin Lee25e26452015-06-02 09:56:29 -07003814 mService.setCertInstallerPackage(admin, installerPackage);
Rubin Xuec32b562015-03-03 17:34:05 +00003815 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003816 throw e.rethrowFromSystemServer();
Rubin Xuec32b562015-03-03 17:34:05 +00003817 }
3818 }
3819 }
3820
3821 /**
Edman Anjosf9946772016-11-28 16:35:15 +01003822 * Called by a profile owner or device owner to retrieve the certificate installer for the user,
3823 * or {@code null} if none is set. If there are multiple delegates this function will return one
3824 * of them.
Rubin Xuec32b562015-03-03 17:34:05 +00003825 *
Robin Lee25e26452015-06-02 09:56:29 -07003826 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003827 * @return The package name of the current delegated certificate installer, or {@code null} if
3828 * none is set.
3829 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003830 *
3831 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatePackages}
3832 * with the {@link #DELEGATION_CERT_INSTALL} scope instead.
Rubin Xuec32b562015-03-03 17:34:05 +00003833 */
Edman Anjosf9946772016-11-28 16:35:15 +01003834 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07003835 public @Nullable String getCertInstallerPackage(@NonNull ComponentName admin)
3836 throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003837 throwIfParentInstance("getCertInstallerPackage");
Rubin Xuec32b562015-03-03 17:34:05 +00003838 if (mService != null) {
3839 try {
Robin Lee25e26452015-06-02 09:56:29 -07003840 return mService.getCertInstallerPackage(admin);
Rubin Xuec32b562015-03-03 17:34:05 +00003841 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003842 throw e.rethrowFromSystemServer();
Rubin Xuec32b562015-03-03 17:34:05 +00003843 }
3844 }
3845 return null;
3846 }
3847
3848 /**
Edman Anjosf9946772016-11-28 16:35:15 +01003849 * Called by a profile owner or device owner to grant access to privileged APIs to another app.
3850 * Granted APIs are determined by {@code scopes}, which is a list of the {@code DELEGATION_*}
3851 * constants.
3852 * <p>
Edman Anjos9e62c312017-01-26 22:22:58 +01003853 * A broadcast with the {@link #ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED} action will be
3854 * sent to the {@code delegatePackage} with its new scopes in an {@code ArrayList<String>} extra
3855 * under the {@link #EXTRA_DELEGATION_SCOPES} key. The broadcast is sent with the
3856 * {@link Intent#FLAG_RECEIVER_REGISTERED_ONLY} flag.
3857 * <p>
Edman Anjosf9946772016-11-28 16:35:15 +01003858 * Delegated scopes are a per-user state. The delegated access is persistent until it is later
3859 * cleared by calling this method with an empty {@code scopes} list or uninstalling the
3860 * {@code delegatePackage}.
3861 *
3862 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3863 * @param delegatePackage The package name of the app which will be given access.
3864 * @param scopes The groups of privileged APIs whose access should be granted to
3865 * {@code delegatedPackage}.
3866 * @throws SecurityException if {@code admin} is not a device or a profile owner.
3867 */
3868 public void setDelegatedScopes(@NonNull ComponentName admin, @NonNull String delegatePackage,
3869 @NonNull List<String> scopes) {
3870 throwIfParentInstance("setDelegatedScopes");
3871 if (mService != null) {
3872 try {
3873 mService.setDelegatedScopes(admin, delegatePackage, scopes);
3874 } catch (RemoteException e) {
3875 throw e.rethrowFromSystemServer();
3876 }
3877 }
3878 }
3879
3880 /**
3881 * Called by a profile owner or device owner to retrieve a list of the scopes given to a
3882 * delegate package. Other apps can use this method to retrieve their own delegated scopes by
3883 * passing {@code null} for {@code admin} and their own package name as
3884 * {@code delegatedPackage}.
3885 *
3886 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3887 * {@code null} if the caller is {@code delegatedPackage}.
3888 * @param delegatedPackage The package name of the app whose scopes should be retrieved.
3889 * @return A list containing the scopes given to {@code delegatedPackage}.
3890 * @throws SecurityException if {@code admin} is not a device or a profile owner.
3891 */
3892 @NonNull
Edman Anjos9e62c312017-01-26 22:22:58 +01003893 public List<String> getDelegatedScopes(@Nullable ComponentName admin,
Edman Anjosf9946772016-11-28 16:35:15 +01003894 @NonNull String delegatedPackage) {
3895 throwIfParentInstance("getDelegatedScopes");
3896 if (mService != null) {
3897 try {
3898 return mService.getDelegatedScopes(admin, delegatedPackage);
3899 } catch (RemoteException e) {
3900 throw e.rethrowFromSystemServer();
3901 }
3902 }
3903 return null;
3904 }
3905
3906 /**
3907 * Called by a profile owner or device owner to retrieve a list of delegate packages that were
3908 * granted a delegation scope.
3909 *
3910 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3911 * @param delegationScope The scope whose delegates should be retrieved.
3912 * @return A list of package names of the current delegated packages for
3913 {@code delegationScope}.
3914 * @throws SecurityException if {@code admin} is not a device or a profile owner.
3915 */
3916 @Nullable
3917 public List<String> getDelegatePackages(@NonNull ComponentName admin,
3918 @NonNull String delegationScope) {
3919 throwIfParentInstance("getDelegatePackages");
3920 if (mService != null) {
3921 try {
3922 return mService.getDelegatePackages(admin, delegationScope);
3923 } catch (RemoteException e) {
3924 throw e.rethrowFromSystemServer();
3925 }
3926 }
3927 return null;
3928 }
3929
3930 /**
Robin Lee244ce8e2016-01-05 18:03:46 +00003931 * Called by a device or profile owner to configure an always-on VPN connection through a
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003932 * specific application for the current user. This connection is automatically granted and
3933 * persisted after a reboot.
3934 * <p>
Charles He36738632017-05-15 17:07:18 +01003935 * To support the always-on feature, an app must
3936 * <ul>
3937 * <li>declare a {@link android.net.VpnService} in its manifest, guarded by
3938 * {@link android.Manifest.permission#BIND_VPN_SERVICE};</li>
3939 * <li>target {@link android.os.Build.VERSION_CODES#N API 24} or above; and</li>
3940 * <li><i>not</i> explicitly opt out of the feature through
3941 * {@link android.net.VpnService#METADATA_SUPPORTS_ALWAYS_ON}.</li>
3942 * </ul>
3943 * The call will fail if called with the package name of an unsupported VPN app.
Robin Lee244ce8e2016-01-05 18:03:46 +00003944 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003945 * @param vpnPackage The package name for an installed VPN app on the device, or {@code null} to
Robin Leedc679712016-05-03 13:23:03 +01003946 * remove an existing always-on VPN configuration.
3947 * @param lockdownEnabled {@code true} to disallow networking when the VPN is not connected or
3948 * {@code false} otherwise. This carries the risk that any failure of the VPN provider
3949 * could break networking for all apps. This has no effect when clearing.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003950 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Robin Leeee5eb932016-04-05 16:27:15 +01003951 * @throws NameNotFoundException if {@code vpnPackage} is not installed.
3952 * @throws UnsupportedOperationException if {@code vpnPackage} exists but does not support being
3953 * set as always-on, or if always-on VPN is not available.
Robin Lee244ce8e2016-01-05 18:03:46 +00003954 */
Robin Leedc679712016-05-03 13:23:03 +01003955 public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage,
3956 boolean lockdownEnabled)
Robin Leeee5eb932016-04-05 16:27:15 +01003957 throws NameNotFoundException, UnsupportedOperationException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003958 throwIfParentInstance("setAlwaysOnVpnPackage");
Robin Lee244ce8e2016-01-05 18:03:46 +00003959 if (mService != null) {
3960 try {
Robin Leedc679712016-05-03 13:23:03 +01003961 if (!mService.setAlwaysOnVpnPackage(admin, vpnPackage, lockdownEnabled)) {
Robin Leeee5eb932016-04-05 16:27:15 +01003962 throw new NameNotFoundException(vpnPackage);
3963 }
Robin Lee244ce8e2016-01-05 18:03:46 +00003964 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003965 throw e.rethrowFromSystemServer();
Robin Lee244ce8e2016-01-05 18:03:46 +00003966 }
3967 }
Robin Lee244ce8e2016-01-05 18:03:46 +00003968 }
3969
3970 /**
3971 * Called by a device or profile owner to read the name of the package administering an
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003972 * always-on VPN connection for the current user. If there is no such package, or the always-on
3973 * VPN is provided by the system instead of by an application, {@code null} will be returned.
Robin Lee244ce8e2016-01-05 18:03:46 +00003974 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003975 * @return Package name of VPN controller responsible for always-on VPN, or {@code null} if none
3976 * is set.
3977 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Robin Lee244ce8e2016-01-05 18:03:46 +00003978 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003979 public @Nullable String getAlwaysOnVpnPackage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003980 throwIfParentInstance("getAlwaysOnVpnPackage");
Robin Lee244ce8e2016-01-05 18:03:46 +00003981 if (mService != null) {
3982 try {
3983 return mService.getAlwaysOnVpnPackage(admin);
3984 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003985 throw e.rethrowFromSystemServer();
Robin Lee244ce8e2016-01-05 18:03:46 +00003986 }
3987 }
3988 return null;
3989 }
3990
3991 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003992 * Called by an application that is administering the device to disable all cameras on the
3993 * device, for this user. After setting this, no applications running as this user will be able
3994 * to access any cameras on the device.
3995 * <p>
3996 * If the caller is device owner, then the restriction will be applied to all users.
3997 * <p>
3998 * The calling device admin must have requested
3999 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call this method; if it has
4000 * not, a security exception will be thrown.
Ben Komalo2447edd2011-05-09 16:05:33 -07004001 *
4002 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4003 * @param disabled Whether or not the camera should be disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004004 * @throws SecurityException if {@code admin} is not an active administrator or does not use
4005 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA}.
Ben Komalo2447edd2011-05-09 16:05:33 -07004006 */
Robin Lee25e26452015-06-02 09:56:29 -07004007 public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004008 throwIfParentInstance("setCameraDisabled");
Ben Komalo2447edd2011-05-09 16:05:33 -07004009 if (mService != null) {
4010 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08004011 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07004012 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004013 throw e.rethrowFromSystemServer();
Ben Komalo2447edd2011-05-09 16:05:33 -07004014 }
4015 }
4016 }
4017
4018 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07004019 * Determine whether or not the device's cameras have been disabled for this user,
Makoto Onuki32b30572015-12-11 14:29:51 -08004020 * either by the calling admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07004021 * @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 -07004022 * have disabled the camera
4023 */
Robin Lee25e26452015-06-02 09:56:29 -07004024 public boolean getCameraDisabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004025 throwIfParentInstance("getCameraDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004026 return getCameraDisabled(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004027 }
4028
4029 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07004030 public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07004031 if (mService != null) {
4032 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004033 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07004034 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004035 throw e.rethrowFromSystemServer();
Ben Komalo2447edd2011-05-09 16:05:33 -07004036 }
4037 }
4038 return false;
4039 }
4040
4041 /**
Michal Karpinski3fc437e2015-12-15 10:09:00 +00004042 * Called by a device owner to request a bugreport.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004043 * <p>
Esteban Talaverad36dd152016-12-15 08:51:45 +00004044 * If the device contains secondary users or profiles, they must be affiliated with the device
4045 * owner user. Otherwise a {@link SecurityException} will be thrown. See
4046 * {@link #setAffiliationIds}.
Michal Karpinski3fc437e2015-12-15 10:09:00 +00004047 *
4048 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004049 * @return {@code true} if the bugreport collection started successfully, or {@code false} if it
4050 * wasn't triggered because a previous bugreport operation is still active (either the
4051 * bugreport is still running or waiting for the user to share or decline)
Esteban Talaverad36dd152016-12-15 08:51:45 +00004052 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
4053 * profile or secondary user that is not affiliated with the device owner user.
Michal Karpinski3fc437e2015-12-15 10:09:00 +00004054 */
4055 public boolean requestBugreport(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004056 throwIfParentInstance("requestBugreport");
Michal Karpinski3fc437e2015-12-15 10:09:00 +00004057 if (mService != null) {
4058 try {
4059 return mService.requestBugreport(admin);
4060 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004061 throw e.rethrowFromSystemServer();
Michal Karpinski3fc437e2015-12-15 10:09:00 +00004062 }
4063 }
4064 return false;
4065 }
4066
4067 /**
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07004068 * Determine whether or not creating a guest user has been disabled for the device
4069 *
4070 * @hide
4071 */
4072 public boolean getGuestUserDisabled(@Nullable ComponentName admin) {
4073 // Currently guest users can always be created if multi-user is enabled
4074 // TODO introduce a policy for guest user creation
4075 return false;
4076 }
4077
4078 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01004079 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
4080 * screen capture also prevents the content from being shown on display devices that do not have
4081 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
4082 * secure surfaces and secure displays.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004083 * <p>
4084 * The calling device admin must be a device or profile owner. If it is not, a security
4085 * exception will be thrown.
4086 * <p>
4087 * From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also blocks
4088 * assist requests for all activities of the relevant user.
Benjamin Franzc200f442015-06-25 18:20:04 +01004089 *
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004090 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004091 * @param disabled Whether screen capture is disabled or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004092 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004093 */
Robin Lee25e26452015-06-02 09:56:29 -07004094 public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004095 throwIfParentInstance("setScreenCaptureDisabled");
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004096 if (mService != null) {
4097 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08004098 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004099 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004100 throw e.rethrowFromSystemServer();
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004101 }
4102 }
4103 }
4104
4105 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004106 * Determine whether or not screen capture has been disabled by the calling
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004107 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07004108 * @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 +01004109 * have disabled screen capture.
4110 */
Robin Lee25e26452015-06-02 09:56:29 -07004111 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004112 throwIfParentInstance("getScreenCaptureDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004113 return getScreenCaptureDisabled(admin, myUserId());
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004114 }
4115
4116 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07004117 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004118 if (mService != null) {
4119 try {
4120 return mService.getScreenCaptureDisabled(admin, userHandle);
4121 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004122 throw e.rethrowFromSystemServer();
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004123 }
4124 }
4125 return false;
4126 }
4127
4128 /**
Jason Parks841cb0a2017-01-17 15:25:17 -06004129 * Called by a device or profile owner to set whether auto time is required. If auto time is
4130 * 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 -07004131 * <p>
4132 * Note: if auto time is required the user can still manually set the time zone.
4133 * <p>
Jason Parks841cb0a2017-01-17 15:25:17 -06004134 * The calling device admin must be a device or profile owner. If it is not, a security
4135 * exception will be thrown.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004136 *
4137 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4138 * @param required Whether auto time is set required or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004139 * @throws SecurityException if {@code admin} is not a device owner.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004140 */
Robin Lee25e26452015-06-02 09:56:29 -07004141 public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004142 throwIfParentInstance("setAutoTimeRequired");
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004143 if (mService != null) {
4144 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08004145 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004146 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004147 throw e.rethrowFromSystemServer();
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004148 }
4149 }
4150 }
4151
4152 /**
4153 * @return true if auto time is required.
4154 */
4155 public boolean getAutoTimeRequired() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004156 throwIfParentInstance("getAutoTimeRequired");
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004157 if (mService != null) {
4158 try {
4159 return mService.getAutoTimeRequired();
4160 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004161 throw e.rethrowFromSystemServer();
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004162 }
4163 }
4164 return false;
4165 }
4166
4167 /**
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004168 * Called by a device owner to set whether all users created on the device should be ephemeral.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004169 * <p>
4170 * The system user is exempt from this policy - it is never ephemeral.
4171 * <p>
4172 * The calling device admin must be the device owner. If it is not, a security exception will be
4173 * thrown.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004174 *
4175 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4176 * @param forceEphemeralUsers If true, all the existing users will be deleted and all
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004177 * subsequently created users will be ephemeral.
4178 * @throws SecurityException if {@code admin} is not a device owner.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004179 * @hide
4180 */
4181 public void setForceEphemeralUsers(
4182 @NonNull ComponentName admin, boolean forceEphemeralUsers) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004183 throwIfParentInstance("setForceEphemeralUsers");
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004184 if (mService != null) {
4185 try {
4186 mService.setForceEphemeralUsers(admin, forceEphemeralUsers);
4187 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004188 throw e.rethrowFromSystemServer();
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004189 }
4190 }
4191 }
4192
4193 /**
4194 * @return true if all users are created ephemeral.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004195 * @throws SecurityException if {@code admin} is not a device owner.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004196 * @hide
4197 */
4198 public boolean getForceEphemeralUsers(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004199 throwIfParentInstance("getForceEphemeralUsers");
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004200 if (mService != null) {
4201 try {
4202 return mService.getForceEphemeralUsers(admin);
4203 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004204 throw e.rethrowFromSystemServer();
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004205 }
4206 }
4207 return false;
4208 }
4209
4210 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07004211 * Called by an application that is administering the device to disable keyguard customizations,
4212 * such as widgets. After setting this, keyguard features will be disabled according to the
4213 * provided feature list.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004214 * <p>
4215 * The calling device admin must have requested
4216 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method;
4217 * if it has not, a security exception will be thrown.
4218 * <p>
4219 * Calling this from a managed profile before version {@link android.os.Build.VERSION_CODES#M}
4220 * will throw a security exception. From version {@link android.os.Build.VERSION_CODES#M} the
4221 * profile owner of a managed profile can set:
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00004222 * <ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00004223 * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which affects the parent user, but only if there
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004224 * is no separate challenge set on the managed profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00004225 * <li>{@link #KEYGUARD_DISABLE_FINGERPRINT} which affects the managed profile challenge if
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004226 * there is one, or the parent user otherwise.
4227 * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} which affects notifications generated
4228 * by applications in the managed profile.
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00004229 * </ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00004230 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} and {@link #KEYGUARD_DISABLE_FINGERPRINT} can also be
4231 * set on the {@link DevicePolicyManager} instance returned by
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004232 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
4233 * profile.
4234 * <p>
4235 * Requests to disable other features on a managed profile will be ignored.
4236 * <p>
4237 * The admin can check which features have been disabled by calling
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00004238 * {@link #getKeyguardDisabledFeatures(ComponentName)}
Amith Yamasani242f4b12014-10-14 16:06:13 -07004239 *
Jim Millerb8ec4702012-08-31 17:19:10 -07004240 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07004241 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004242 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
4243 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS},
4244 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
4245 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS},
4246 * {@link #KEYGUARD_DISABLE_FINGERPRINT}, {@link #KEYGUARD_DISABLE_FEATURES_ALL}
4247 * @throws SecurityException if {@code admin} is not an active administrator or does not user
4248 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES}
Jim Millerb8ec4702012-08-31 17:19:10 -07004249 */
Robin Lee25e26452015-06-02 09:56:29 -07004250 public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07004251 if (mService != null) {
4252 try {
Esteban Talavera62399912016-01-11 15:37:55 +00004253 mService.setKeyguardDisabledFeatures(admin, which, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07004254 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004255 throw e.rethrowFromSystemServer();
Jim Millerb8ec4702012-08-31 17:19:10 -07004256 }
4257 }
4258 }
4259
4260 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004261 * Determine whether or not features have been disabled in keyguard either by the calling
Rubin Xud3609d42016-07-13 18:32:57 +01004262 * admin, if specified, or all admins that set restrictions on this user and its participating
Esteban Talaverac1c83592016-02-17 17:56:15 +00004263 * profiles. Restrictions on profiles that have a separate challenge are not taken into account.
4264 *
4265 * <p>This method can be called on the {@link DevicePolicyManager} instance
4266 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
4267 * restrictions on the parent profile.
4268 *
Esteban Talavera62399912016-01-11 15:37:55 +00004269 * @param admin The name of the admin component to check, or {@code null} to check whether any
4270 * admins have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07004271 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
4272 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07004273 */
Robin Lee25e26452015-06-02 09:56:29 -07004274 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004275 return getKeyguardDisabledFeatures(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004276 }
4277
4278 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07004279 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07004280 if (mService != null) {
4281 try {
Esteban Talavera62399912016-01-11 15:37:55 +00004282 return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07004283 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004284 throw e.rethrowFromSystemServer();
Jim Millerb8ec4702012-08-31 17:19:10 -07004285 }
4286 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07004287 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07004288 }
4289
4290 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08004291 * @hide
4292 */
Robin Lee25e26452015-06-02 09:56:29 -07004293 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
4294 int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08004295 if (mService != null) {
4296 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01004297 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08004298 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004299 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08004300 }
4301 }
4302 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07004303
Dianne Hackbornd6847842010-01-12 18:14:19 -08004304 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01004305 * @hide
4306 */
Robin Lee25e26452015-06-02 09:56:29 -07004307 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004308 setActiveAdmin(policyReceiver, refreshing, myUserId());
Jessica Hummel6d36b602014-04-04 12:42:17 +01004309 }
4310
4311 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08004312 * @hide
4313 */
Robin Lee25e26452015-06-02 09:56:29 -07004314 public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08004315 if (mService != null) {
4316 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004317 mService.getRemoveWarning(admin, result, myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08004318 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004319 throw e.rethrowFromSystemServer();
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08004320 }
4321 }
4322 }
4323
4324 /**
4325 * @hide
4326 */
Andrew Scull5f9e6f32016-08-02 14:22:17 +01004327 public void setActivePasswordState(PasswordMetrics metrics, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08004328 if (mService != null) {
4329 try {
Andrew Scull5f9e6f32016-08-02 14:22:17 +01004330 mService.setActivePasswordState(metrics, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08004331 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004332 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08004333 }
4334 }
4335 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07004336
Dianne Hackbornd6847842010-01-12 18:14:19 -08004337 /**
4338 * @hide
4339 */
Andrew Scull5daf2732016-11-14 15:02:45 +00004340 public void reportPasswordChanged(@UserIdInt int userId) {
4341 if (mService != null) {
4342 try {
4343 mService.reportPasswordChanged(userId);
4344 } catch (RemoteException e) {
4345 throw e.rethrowFromSystemServer();
4346 }
4347 }
4348 }
4349
4350 /**
4351 * @hide
4352 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004353 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08004354 if (mService != null) {
4355 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004356 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08004357 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004358 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08004359 }
4360 }
4361 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07004362
Dianne Hackbornd6847842010-01-12 18:14:19 -08004363 /**
4364 * @hide
4365 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004366 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08004367 if (mService != null) {
4368 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004369 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08004370 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004371 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08004372 }
4373 }
4374 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07004375
4376 /**
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004377 * @hide
4378 */
4379 public void reportFailedFingerprintAttempt(int userHandle) {
4380 if (mService != null) {
4381 try {
4382 mService.reportFailedFingerprintAttempt(userHandle);
4383 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004384 throw e.rethrowFromSystemServer();
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004385 }
4386 }
4387 }
4388
4389 /**
4390 * @hide
4391 */
4392 public void reportSuccessfulFingerprintAttempt(int userHandle) {
4393 if (mService != null) {
4394 try {
4395 mService.reportSuccessfulFingerprintAttempt(userHandle);
4396 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004397 throw e.rethrowFromSystemServer();
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004398 }
4399 }
4400 }
4401
4402 /**
Michal Karpinski31502d32016-01-25 16:43:07 +00004403 * Should be called when keyguard has been dismissed.
4404 * @hide
4405 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004406 public void reportKeyguardDismissed(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00004407 if (mService != null) {
4408 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004409 mService.reportKeyguardDismissed(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00004410 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004411 throw e.rethrowFromSystemServer();
Michal Karpinski31502d32016-01-25 16:43:07 +00004412 }
4413 }
4414 }
4415
4416 /**
4417 * Should be called when keyguard view has been shown to the user.
4418 * @hide
4419 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004420 public void reportKeyguardSecured(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00004421 if (mService != null) {
4422 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004423 mService.reportKeyguardSecured(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00004424 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004425 throw e.rethrowFromSystemServer();
Michal Karpinski31502d32016-01-25 16:43:07 +00004426 }
4427 }
4428 }
4429
4430 /**
Amith Yamasani71e6c692013-03-24 17:39:28 -07004431 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00004432 * Sets the given package as the device owner.
Makoto Onukia52562c2015-10-01 16:12:31 -07004433 * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name.
4434 * @param who the component name to be registered as device owner.
Amith Yamasani71e6c692013-03-24 17:39:28 -07004435 * @return whether the package was successfully registered as the device owner.
4436 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00004437 * @throws IllegalStateException If the preconditions mentioned are not met.
Amith Yamasani71e6c692013-03-24 17:39:28 -07004438 */
Makoto Onukia52562c2015-10-01 16:12:31 -07004439 public boolean setDeviceOwner(ComponentName who) {
4440 return setDeviceOwner(who, null);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004441 }
4442
4443 /**
4444 * @hide
Makoto Onuki58b684f2015-09-04 10:48:16 -07004445 */
Makoto Onukia52562c2015-10-01 16:12:31 -07004446 public boolean setDeviceOwner(ComponentName who, int userId) {
4447 return setDeviceOwner(who, null, userId);
Makoto Onuki58b684f2015-09-04 10:48:16 -07004448 }
4449
4450 /**
4451 * @hide
4452 */
Makoto Onukia52562c2015-10-01 16:12:31 -07004453 public boolean setDeviceOwner(ComponentName who, String ownerName) {
4454 return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM);
Makoto Onuki58b684f2015-09-04 10:48:16 -07004455 }
4456
4457 /**
4458 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00004459 * Sets the given package as the device owner. The package must already be installed. There
4460 * must not already be a device owner.
4461 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
4462 * this method.
4463 * Calling this after the setup phase of the primary user has completed is allowed only if
4464 * the caller is the shell uid, and there are no additional users and no accounts.
Makoto Onukia52562c2015-10-01 16:12:31 -07004465 * @param who the component name to be registered as device owner.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004466 * @param ownerName the human readable name of the institution that owns this device.
Makoto Onuki58b684f2015-09-04 10:48:16 -07004467 * @param userId ID of the user on which the device owner runs.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004468 * @return whether the package was successfully registered as the device owner.
4469 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00004470 * @throws IllegalStateException If the preconditions mentioned are not met.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004471 */
Makoto Onukia52562c2015-10-01 16:12:31 -07004472 public boolean setDeviceOwner(ComponentName who, String ownerName, int userId)
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004473 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07004474 if (mService != null) {
4475 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07004476 return mService.setDeviceOwner(who, ownerName, userId);
Amith Yamasani71e6c692013-03-24 17:39:28 -07004477 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004478 throw re.rethrowFromSystemServer();
Amith Yamasani71e6c692013-03-24 17:39:28 -07004479 }
4480 }
4481 return false;
4482 }
4483
4484 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004485 * Used to determine if a particular package has been registered as a Device Owner app.
4486 * A device owner app is a special device admin that cannot be deactivated by the user, once
Robin Lee25e26452015-06-02 09:56:29 -07004487 * activated as a device admin. It also cannot be uninstalled. To check whether a particular
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004488 * package is currently registered as the device owner app, pass in the package name from
4489 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
Robin Lee25e26452015-06-02 09:56:29 -07004490 * admin apps that want to check whether they are also registered as the device owner app. The
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004491 * exact mechanism by which a device admin app is registered as a device owner app is defined by
4492 * the setup process.
4493 * @param packageName the package name of the app, to compare with the registered device owner
4494 * app, if any.
Makoto Onukic8a5a552015-11-19 14:29:12 -08004495 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07004496 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004497 public boolean isDeviceOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004498 throwIfParentInstance("isDeviceOwnerApp");
Makoto Onukic8a5a552015-11-19 14:29:12 -08004499 return isDeviceOwnerAppOnCallingUser(packageName);
4500 }
4501
4502 /**
4503 * @return true if a package is registered as device owner, only when it's running on the
4504 * calling user.
4505 *
4506 * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity.
4507 * @hide
4508 */
4509 public boolean isDeviceOwnerAppOnCallingUser(String packageName) {
4510 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true);
4511 }
4512
4513 /**
4514 * @return true if a package is registered as device owner, even if it's running on a different
4515 * user.
4516 *
4517 * <p>Requires the MANAGE_USERS permission.
4518 *
4519 * @hide
4520 */
4521 public boolean isDeviceOwnerAppOnAnyUser(String packageName) {
4522 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false);
4523 }
4524
4525 /**
4526 * @return device owner component name, only when it's running on the calling user.
4527 *
4528 * @hide
4529 */
4530 public ComponentName getDeviceOwnerComponentOnCallingUser() {
4531 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true);
4532 }
4533
4534 /**
4535 * @return device owner component name, even if it's running on a different user.
4536 *
Makoto Onukic8a5a552015-11-19 14:29:12 -08004537 * @hide
4538 */
Polina Bondarenko23561db2016-12-16 11:47:28 +01004539 @SystemApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06004540 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Makoto Onukic8a5a552015-11-19 14:29:12 -08004541 public ComponentName getDeviceOwnerComponentOnAnyUser() {
4542 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false);
4543 }
4544
4545 private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) {
Makoto Onuki70f929e2015-11-11 12:40:15 -08004546 if (packageName == null) {
4547 return false;
Amith Yamasani71e6c692013-03-24 17:39:28 -07004548 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08004549 final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly);
Makoto Onuki70f929e2015-11-11 12:40:15 -08004550 if (deviceOwner == null) {
4551 return false;
4552 }
4553 return packageName.equals(deviceOwner.getPackageName());
Amith Yamasani71e6c692013-03-24 17:39:28 -07004554 }
4555
Makoto Onukic8a5a552015-11-19 14:29:12 -08004556 private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) {
4557 if (mService != null) {
4558 try {
4559 return mService.getDeviceOwnerComponent(callingUserOnly);
4560 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004561 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08004562 }
4563 }
4564 return null;
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004565 }
4566
Jason Monkb0dced82014-06-06 14:36:20 -04004567 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08004568 * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's
4569 * no device owner.
4570 *
4571 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07004572 *
4573 * @hide
4574 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08004575 public int getDeviceOwnerUserId() {
4576 if (mService != null) {
4577 try {
4578 return mService.getDeviceOwnerUserId();
4579 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004580 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08004581 }
4582 }
4583 return UserHandle.USER_NULL;
Makoto Onukia52562c2015-10-01 16:12:31 -07004584 }
4585
4586 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004587 * Clears the current device owner. The caller must be the device owner. This function should be
4588 * used cautiously as once it is called it cannot be undone. The device owner can only be set as
Esteban Talaveraa5b09632017-02-10 16:15:24 +00004589 * a part of device setup, before it completes.
4590 * <p>
4591 * While some policies previously set by the device owner will be cleared by this method, it is
4592 * a best-effort process and some other policies will still remain in place after the device
4593 * owner is cleared.
Jason Monk94d2cf92014-06-18 09:53:34 -04004594 *
4595 * @param packageName The package name of the device owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004596 * @throws SecurityException if the caller is not in {@code packageName} or {@code packageName}
4597 * does not own the current device owner component.
Esteban Talaveraa5b09632017-02-10 16:15:24 +00004598 *
4599 * @deprecated This method is expected to be used for testing purposes only. The device owner
4600 * will lose control of the device and its data after calling it. In order to protect any
4601 * sensitive data that remains on the device, it is advised that the device owner factory resets
4602 * the device instead of calling this method. See {@link #wipeData(int)}.
Jason Monkb0dced82014-06-06 14:36:20 -04004603 */
Esteban Talaveraa5b09632017-02-10 16:15:24 +00004604 @Deprecated
Jason Monk94d2cf92014-06-18 09:53:34 -04004605 public void clearDeviceOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004606 throwIfParentInstance("clearDeviceOwnerApp");
Jason Monkb0dced82014-06-06 14:36:20 -04004607 if (mService != null) {
4608 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04004609 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04004610 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004611 throw re.rethrowFromSystemServer();
Jason Monkb0dced82014-06-06 14:36:20 -04004612 }
4613 }
4614 }
4615
Makoto Onukia52562c2015-10-01 16:12:31 -07004616 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08004617 * Returns the device owner package name, only if it's running on the calling user.
4618 *
4619 * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity.
Makoto Onukia52562c2015-10-01 16:12:31 -07004620 *
4621 * @hide
4622 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01004623 @SystemApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06004624 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Makoto Onuki408e8e42016-10-25 12:10:27 -07004625 public @Nullable String getDeviceOwner() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004626 throwIfParentInstance("getDeviceOwner");
Makoto Onukic8a5a552015-11-19 14:29:12 -08004627 final ComponentName name = getDeviceOwnerComponentOnCallingUser();
4628 return name != null ? name.getPackageName() : null;
Makoto Onukia52562c2015-10-01 16:12:31 -07004629 }
4630
4631 /**
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004632 * Called by the system to find out whether the device is managed by a Device Owner.
Makoto Onukic8a5a552015-11-19 14:29:12 -08004633 *
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004634 * @return whether the device is managed by a Device Owner.
4635 * @throws SecurityException if the caller is not the device owner, does not hold the
4636 * MANAGE_USERS permission and is not the system.
Makoto Onukia52562c2015-10-01 16:12:31 -07004637 *
4638 * @hide
4639 */
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004640 @SystemApi
4641 @TestApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06004642 @SuppressLint("Doclava125")
Makoto Onukic8a5a552015-11-19 14:29:12 -08004643 public boolean isDeviceManaged() {
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004644 try {
4645 return mService.hasDeviceOwner();
4646 } catch (RemoteException re) {
4647 throw re.rethrowFromSystemServer();
4648 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08004649 }
4650
4651 /**
4652 * Returns the device owner name. Note this method *will* return the device owner
4653 * name when it's running on a different user.
4654 *
Makoto Onukic8a5a552015-11-19 14:29:12 -08004655 * @hide
4656 */
Makoto Onukia2b274b2016-01-19 13:26:02 -08004657 @SystemApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06004658 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Makoto Onukic8a5a552015-11-19 14:29:12 -08004659 public String getDeviceOwnerNameOnAnyUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004660 throwIfParentInstance("getDeviceOwnerNameOnAnyUser");
Amith Yamasani71e6c692013-03-24 17:39:28 -07004661 if (mService != null) {
4662 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07004663 return mService.getDeviceOwnerName();
Amith Yamasani71e6c692013-03-24 17:39:28 -07004664 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004665 throw re.rethrowFromSystemServer();
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004666 }
4667 }
4668 return null;
4669 }
Adam Connors776c5552014-01-09 10:42:56 +00004670
4671 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04004672 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004673 * @deprecated Do not use
4674 * @removed
Julia Reynolds20118f12015-02-11 12:34:08 -05004675 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004676 @Deprecated
Julia Reynolds20118f12015-02-11 12:34:08 -05004677 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06004678 @SuppressLint("Doclava125")
Makoto Onuki408e8e42016-10-25 12:10:27 -07004679 public @Nullable String getDeviceInitializerApp() {
Julia Reynolds20118f12015-02-11 12:34:08 -05004680 return null;
4681 }
4682
4683 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004684 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004685 * @deprecated Do not use
4686 * @removed
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004687 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004688 @Deprecated
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004689 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06004690 @SuppressLint("Doclava125")
Makoto Onuki408e8e42016-10-25 12:10:27 -07004691 public @Nullable ComponentName getDeviceInitializerComponent() {
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004692 return null;
4693 }
4694
Julia Reynolds20118f12015-02-11 12:34:08 -05004695 /**
Adam Connors776c5552014-01-09 10:42:56 +00004696 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004697 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304698 * Sets the given component as an active admin and registers the package as the profile
4699 * owner for this user. The package must already be installed and there shouldn't be
4700 * an existing profile owner registered for this user. Also, this method must be called
4701 * before the user setup has been completed.
4702 * <p>
4703 * This method can only be called by system apps that hold MANAGE_USERS permission and
4704 * MANAGE_DEVICE_ADMINS permission.
4705 * @param admin The component to register as an active admin and profile owner.
4706 * @param ownerName The user-visible name of the entity that is managing this user.
4707 * @return whether the admin was successfully registered as the profile owner.
4708 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
4709 * the user has already been set up.
4710 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07004711 @Deprecated
Justin Morey80440cc2014-07-24 09:16:35 -05004712 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06004713 @RequiresPermission(android.Manifest.permission.MANAGE_DEVICE_ADMINS)
Robin Lee25e26452015-06-02 09:56:29 -07004714 public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304715 throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004716 throwIfParentInstance("setActiveProfileOwner");
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304717 if (mService != null) {
4718 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004719 final int myUserId = myUserId();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304720 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004721 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304722 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004723 throw re.rethrowFromSystemServer();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304724 }
4725 }
4726 return false;
4727 }
4728
4729 /**
Esteban Talaveraa5b09632017-02-10 16:15:24 +00004730 * Clears the active profile owner. The caller must be the profile owner of this user, otherwise
4731 * a SecurityException will be thrown. This method is not available to managed profile owners.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004732 * <p>
Esteban Talaveraa5b09632017-02-10 16:15:24 +00004733 * While some policies previously set by the profile owner will be cleared by this method, it is
4734 * a best-effort process and some other policies will still remain in place after the profile
4735 * owner is cleared.
Makoto Onuki5bf68022016-01-27 13:49:19 -08004736 *
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004737 * @param admin The component to remove as the profile owner.
Esteban Talaveraa5b09632017-02-10 16:15:24 +00004738 * @throws SecurityException if {@code admin} is not an active profile owner, or the method is
4739 * being called from a managed profile.
4740 *
4741 * @deprecated This method is expected to be used for testing purposes only. The profile owner
4742 * will lose control of the user and its data after calling it. In order to protect any
4743 * sensitive data that remains on this user, it is advised that the profile owner deletes it
4744 * instead of calling this method. See {@link #wipeData(int)}.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004745 */
Esteban Talaveraa5b09632017-02-10 16:15:24 +00004746 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07004747 public void clearProfileOwner(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004748 throwIfParentInstance("clearProfileOwner");
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004749 if (mService != null) {
4750 try {
4751 mService.clearProfileOwner(admin);
4752 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004753 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004754 }
4755 }
4756 }
4757
4758 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05004759 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07004760 * Checks whether the user was already setup.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004761 */
4762 public boolean hasUserSetupCompleted() {
4763 if (mService != null) {
4764 try {
4765 return mService.hasUserSetupCompleted();
4766 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004767 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004768 }
4769 }
4770 return true;
4771 }
4772
4773 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004774 * @hide
4775 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00004776 * already be installed. There must not already be a profile owner for this user.
4777 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
4778 * this method.
4779 * Calling this after the setup phase of the specified user has completed is allowed only if:
4780 * - the caller is SYSTEM_UID.
4781 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004782 * @param admin the component name to be registered as profile owner.
4783 * @param ownerName the human readable name of the organisation associated with this DPM.
4784 * @param userHandle the userId to set the profile owner for.
4785 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00004786 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
4787 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004788 */
Robin Lee25e26452015-06-02 09:56:29 -07004789 public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName,
Robin Leeddd553f2015-04-30 14:18:22 +01004790 int userHandle) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00004791 if (mService != null) {
4792 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004793 if (ownerName == null) {
4794 ownerName = "";
4795 }
4796 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00004797 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004798 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004799 }
4800 }
4801 return false;
4802 }
4803
4804 /**
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004805 * Sets the device owner information to be shown on the lock screen.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004806 * <p>
4807 * If the device owner information is {@code null} or empty then the device owner info is
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004808 * cleared and the user owner info is shown on the lock screen if it is set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004809 * <p>
4810 * If the device owner information contains only whitespaces then the message on the lock screen
4811 * will be blank and the user will not be allowed to change it.
4812 * <p>
4813 * If the device owner information needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00004814 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
4815 * and set a new version of this string accordingly.
4816 *
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004817 * @param admin The name of the admin component to check.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004818 * @param info Device owner information which will be displayed instead of the user owner info.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004819 * @throws SecurityException if {@code admin} is not a device owner.
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004820 */
Andrei Stingaceanu16187902016-03-21 15:44:45 +00004821 public void setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, CharSequence info) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004822 throwIfParentInstance("setDeviceOwnerLockScreenInfo");
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004823 if (mService != null) {
4824 try {
Andrei Stingaceanu16187902016-03-21 15:44:45 +00004825 mService.setDeviceOwnerLockScreenInfo(admin, info);
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004826 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004827 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004828 }
4829 }
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004830 }
4831
4832 /**
4833 * @return The device owner information. If it is not set returns {@code null}.
4834 */
Andrei Stingaceanu16187902016-03-21 15:44:45 +00004835 public CharSequence getDeviceOwnerLockScreenInfo() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004836 throwIfParentInstance("getDeviceOwnerLockScreenInfo");
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004837 if (mService != null) {
4838 try {
4839 return mService.getDeviceOwnerLockScreenInfo();
4840 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004841 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004842 }
4843 }
4844 return null;
4845 }
4846
4847 /**
Edman Anjos52088e42017-01-13 22:26:17 +01004848 * Called by device or profile owners to suspend packages for this user. This function can be
4849 * called by a device owner, profile owner, or by a delegate given the
4850 * {@link #DELEGATION_PACKAGE_ACCESS} scope via {@link #setDelegatedScopes}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004851 * <p>
4852 * A suspended package will not be able to start activities. Its notifications will be hidden,
4853 * it will not show up in recents, will not be able to show toasts or dialogs or ring the
4854 * device.
4855 * <p>
4856 * The package must already be installed. If the package is uninstalled while suspended the
4857 * package will no longer be suspended. The admin can block this by using
Kenny Guy871f3eb2016-03-09 20:06:16 +00004858 * {@link #setUninstallBlocked}.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004859 *
Edman Anjos52088e42017-01-13 22:26:17 +01004860 * @param admin The name of the admin component to check, or {@code null} if the caller is a
4861 * package access delegate.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004862 * @param packageNames The package names to suspend or unsuspend.
4863 * @param suspended If set to {@code true} than the packages will be suspended, if set to
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004864 * {@code false} the packages will be unsuspended.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004865 * @return an array of package names for which the suspended status is not set as requested in
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004866 * this method.
4867 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01004868 * @see #setDelegatedScopes
4869 * @see #DELEGATION_PACKAGE_ACCESS
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004870 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004871 public @NonNull String[] setPackagesSuspended(@NonNull ComponentName admin,
4872 @NonNull String[] packageNames, boolean suspended) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004873 throwIfParentInstance("setPackagesSuspended");
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004874 if (mService != null) {
4875 try {
Edman Anjos52088e42017-01-13 22:26:17 +01004876 return mService.setPackagesSuspended(admin, mContext.getPackageName(), packageNames,
4877 suspended);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004878 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004879 throw re.rethrowFromSystemServer();
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004880 }
4881 }
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004882 return packageNames;
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004883 }
4884
4885 /**
Edman Anjos52088e42017-01-13 22:26:17 +01004886 * Determine if a package is suspended. This function can be called by a device owner, profile
4887 * owner, or by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via
4888 * {@link #setDelegatedScopes}.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004889 *
Edman Anjos52088e42017-01-13 22:26:17 +01004890 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
4891 * {@code null} if the caller is a package access delegate.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004892 * @param packageName The name of the package to retrieve the suspended status of.
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00004893 * @return {@code true} if the package is suspended or {@code false} if the package is not
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004894 * suspended, could not be found or an error occurred.
4895 * @throws SecurityException if {@code admin} is not a device or profile owner.
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004896 * @throws NameNotFoundException if the package could not be found.
Edman Anjos52088e42017-01-13 22:26:17 +01004897 * @see #setDelegatedScopes
4898 * @see #DELEGATION_PACKAGE_ACCESS
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004899 */
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004900 public boolean isPackageSuspended(@NonNull ComponentName admin, String packageName)
4901 throws NameNotFoundException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004902 throwIfParentInstance("isPackageSuspended");
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004903 if (mService != null) {
4904 try {
Edman Anjos52088e42017-01-13 22:26:17 +01004905 return mService.isPackageSuspended(admin, mContext.getPackageName(), packageName);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004906 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004907 throw e.rethrowFromSystemServer();
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004908 } catch (IllegalArgumentException ex) {
4909 throw new NameNotFoundException(packageName);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004910 }
4911 }
4912 return false;
4913 }
4914
4915 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004916 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
4917 * be used. Only the profile owner can call this.
4918 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01004919 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004920 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004921 * @throws SecurityException if {@code admin} is not a profile owner.
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004922 */
Robin Lee25e26452015-06-02 09:56:29 -07004923 public void setProfileEnabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004924 throwIfParentInstance("setProfileEnabled");
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004925 if (mService != null) {
4926 try {
4927 mService.setProfileEnabled(admin);
4928 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004929 throw e.rethrowFromSystemServer();
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004930 }
4931 }
4932 }
4933
4934 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004935 * Sets the name of the profile. In the device owner case it sets the name of the user which it
4936 * is called from. Only a profile owner or device owner can call this. If this is never called
4937 * by the profile or device owner, the name will be set to default values.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004938 *
4939 * @see #isProfileOwnerApp
4940 * @see #isDeviceOwnerApp
Robin Lee25e26452015-06-02 09:56:29 -07004941 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004942 * @param profileName The name of the profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004943 * @throws SecurityException if {@code admin} is not a device or profile owner.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004944 */
Robin Lee25e26452015-06-02 09:56:29 -07004945 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004946 throwIfParentInstance("setProfileName");
Jessica Hummel1333ea12014-06-23 11:20:10 +01004947 if (mService != null) {
4948 try {
Robin Lee25e26452015-06-02 09:56:29 -07004949 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07004950 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004951 throw e.rethrowFromSystemServer();
Fyodor Kupolov78f13142015-05-27 16:52:45 -07004952 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01004953 }
4954 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01004955
4956 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004957 * Used to determine if a particular package is registered as the profile owner for the
Makoto Onuki32b30572015-12-11 14:29:51 -08004958 * user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004959 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00004960 *
4961 * @param packageName The package name of the app to compare with the registered profile owner.
4962 * @return Whether or not the package is registered as the profile owner.
4963 */
4964 public boolean isProfileOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004965 throwIfParentInstance("isProfileOwnerApp");
Adam Connors776c5552014-01-09 10:42:56 +00004966 if (mService != null) {
4967 try {
Makoto Onuki90b89652016-01-28 14:44:18 -08004968 ComponentName profileOwner = mService.getProfileOwner(myUserId());
Nicolas Prevot90af6d72014-07-30 14:19:12 +01004969 return profileOwner != null
4970 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00004971 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004972 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004973 }
4974 }
4975 return false;
4976 }
4977
4978 /**
4979 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07004980 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00004981 * owner has been set for that user.
4982 * @throws IllegalArgumentException if the userId is invalid.
4983 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01004984 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004985 public @Nullable ComponentName getProfileOwner() throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004986 throwIfParentInstance("getProfileOwner");
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01004987 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
4988 }
4989
4990 /**
4991 * @see #getProfileOwner()
4992 * @hide
4993 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004994 public @Nullable ComponentName getProfileOwnerAsUser(final int userId)
4995 throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00004996 if (mService != null) {
4997 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01004998 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00004999 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005000 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00005001 }
5002 }
5003 return null;
5004 }
5005
5006 /**
5007 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07005008 * @return the human readable name of the organisation associated with this DPM or {@code null}
5009 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00005010 * @throws IllegalArgumentException if the userId is invalid.
5011 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005012 public @Nullable String getProfileOwnerName() throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00005013 if (mService != null) {
5014 try {
5015 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
5016 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005017 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00005018 }
5019 }
5020 return null;
5021 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005022
5023 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07005024 * @hide
Makoto Onukic8a5a552015-11-19 14:29:12 -08005025 * @param userId The user for whom to fetch the profile owner name, if any.
Amith Yamasani38f836b2014-08-20 14:51:15 -07005026 * @return the human readable name of the organisation associated with this profile owner or
5027 * null if one is not set.
5028 * @throws IllegalArgumentException if the userId is invalid.
5029 */
5030 @SystemApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06005031 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Makoto Onuki408e8e42016-10-25 12:10:27 -07005032 public @Nullable String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005033 throwIfParentInstance("getProfileOwnerNameAsUser");
Amith Yamasani38f836b2014-08-20 14:51:15 -07005034 if (mService != null) {
5035 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02005036 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07005037 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005038 throw re.rethrowFromSystemServer();
Amith Yamasani38f836b2014-08-20 14:51:15 -07005039 }
5040 }
5041 return null;
5042 }
5043
5044 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005045 * Called by a profile owner or device owner to add a default intent handler activity for
5046 * intents that match a certain intent filter. This activity will remain the default intent
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005047 * handler even if the set of potential event handlers for the intent filter changes and if the
5048 * intent preferences are reset.
5049 * <p>
5050 * The default disambiguation mechanism takes over if the activity is not installed (anymore).
5051 * When the activity is (re)installed, it is automatically reset as default intent handler for
5052 * the filter.
5053 * <p>
5054 * The calling device admin must be a profile owner or device owner. If it is not, a security
5055 * exception will be thrown.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005056 *
5057 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5058 * @param filter The IntentFilter for which a default handler is added.
5059 * @param activity The Activity that is added as default intent handler.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005060 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005061 */
Robin Lee25e26452015-06-02 09:56:29 -07005062 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
5063 @NonNull ComponentName activity) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005064 throwIfParentInstance("addPersistentPreferredActivity");
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005065 if (mService != null) {
5066 try {
5067 mService.addPersistentPreferredActivity(admin, filter, activity);
5068 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005069 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005070 }
5071 }
5072 }
5073
5074 /**
5075 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00005076 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005077 * <p>
5078 * The calling device admin must be a profile owner. If it is not, a security exception will be
5079 * thrown.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005080 *
5081 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5082 * @param packageName The name of the package for which preferences are removed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005083 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005084 */
Robin Lee25e26452015-06-02 09:56:29 -07005085 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005086 String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005087 throwIfParentInstance("clearPackagePersistentPreferredActivities");
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005088 if (mService != null) {
5089 try {
5090 mService.clearPackagePersistentPreferredActivities(admin, packageName);
5091 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005092 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005093 }
5094 }
5095 }
Robin Lee66e5d962014-04-09 16:44:21 +01005096
5097 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00005098 * Called by a profile owner or device owner to grant permission to a package to manage
5099 * application restrictions for the calling user via {@link #setApplicationRestrictions} and
5100 * {@link #getApplicationRestrictions}.
5101 * <p>
5102 * This permission is persistent until it is later cleared by calling this method with a
5103 * {@code null} value or uninstalling the managing package.
Rubin Xuf03d0a62016-02-10 14:54:15 +00005104 * <p>
5105 * The supplied application restriction managing package must be installed when calling this
Victor Changcd14c0a2016-03-16 19:10:15 +00005106 * API, otherwise an {@link NameNotFoundException} will be thrown.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005107 *
5108 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5109 * @param packageName The package name which will be given access to application restrictions
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005110 * APIs. If {@code null} is given the current package will be cleared.
5111 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Changcd14c0a2016-03-16 19:10:15 +00005112 * @throws NameNotFoundException if {@code packageName} is not found
Edman Anjosf9946772016-11-28 16:35:15 +01005113 *
5114 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #setDelegatedScopes}
5115 * with the {@link #DELEGATION_APP_RESTRICTIONS} scope instead.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005116 */
Edman Anjosf9946772016-11-28 16:35:15 +01005117 @Deprecated
Esteban Talaverabf60f722015-12-10 16:26:44 +00005118 public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin,
Victor Changcd14c0a2016-03-16 19:10:15 +00005119 @Nullable String packageName) throws NameNotFoundException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005120 throwIfParentInstance("setApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00005121 if (mService != null) {
5122 try {
Victor Changcd14c0a2016-03-16 19:10:15 +00005123 if (!mService.setApplicationRestrictionsManagingPackage(admin, packageName)) {
5124 throw new NameNotFoundException(packageName);
5125 }
Esteban Talaverabf60f722015-12-10 16:26:44 +00005126 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005127 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00005128 }
5129 }
5130 }
5131
5132 /**
5133 * Called by a profile owner or device owner to retrieve the application restrictions managing
Edman Anjosf9946772016-11-28 16:35:15 +01005134 * package for the current user, or {@code null} if none is set. If there are multiple
5135 * delegates this function will return one of them.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005136 *
5137 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5138 * @return The package name allowed to manage application restrictions on the current user, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005139 * {@code null} if none is set.
5140 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01005141 *
5142 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatePackages}
5143 * with the {@link #DELEGATION_APP_RESTRICTIONS} scope instead.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005144 */
Edman Anjosf9946772016-11-28 16:35:15 +01005145 @Deprecated
5146 @Nullable
5147 public String getApplicationRestrictionsManagingPackage(
Makoto Onuki408e8e42016-10-25 12:10:27 -07005148 @NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005149 throwIfParentInstance("getApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00005150 if (mService != null) {
5151 try {
5152 return mService.getApplicationRestrictionsManagingPackage(admin);
5153 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005154 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00005155 }
5156 }
5157 return null;
5158 }
5159
5160 /**
Esteban Talavera96895ca2016-03-16 12:00:40 +00005161 * Called by any application to find out whether it has been granted permission via
5162 * {@link #setApplicationRestrictionsManagingPackage} to manage application restrictions
5163 * for the calling user.
5164 *
5165 * <p>This is done by comparing the calling Linux uid with the uid of the package specified by
5166 * that method.
Edman Anjosf9946772016-11-28 16:35:15 +01005167 *
5168 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatedScopes}
5169 * instead.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005170 */
Edman Anjosf9946772016-11-28 16:35:15 +01005171 @Deprecated
Esteban Talaverabf60f722015-12-10 16:26:44 +00005172 public boolean isCallerApplicationRestrictionsManagingPackage() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005173 throwIfParentInstance("isCallerApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00005174 if (mService != null) {
5175 try {
Edman Anjosf9946772016-11-28 16:35:15 +01005176 return mService.isCallerApplicationRestrictionsManagingPackage(
5177 mContext.getPackageName());
Esteban Talaverabf60f722015-12-10 16:26:44 +00005178 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005179 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00005180 }
5181 }
5182 return false;
5183 }
5184
5185 /**
5186 * Sets the application restrictions for a given target application running in the calling user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005187 * <p>
5188 * 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 +01005189 * application restrictions via {@link #setDelegatedScopes} with the
5190 * {@link #DELEGATION_APP_RESTRICTIONS} scope; otherwise a security exception will be thrown.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005191 * <p>
5192 * The provided {@link Bundle} consists of key-value pairs, where the types of values may be:
Esteban Talavera6b8e0642015-08-10 17:26:04 +01005193 * <ul>
5194 * <li>{@code boolean}
5195 * <li>{@code int}
5196 * <li>{@code String} or {@code String[]}
5197 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
5198 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005199 * <p>
5200 * If the restrictions are not available yet, but may be applied in the near future, the caller
5201 * can notify the target application of that by adding
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00005202 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005203 * <p>
5204 * The application restrictions are only made visible to the target application via
5205 * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or device
5206 * owner, and the application restrictions managing package via
Esteban Talaverabf60f722015-12-10 16:26:44 +00005207 * {@link #getApplicationRestrictions}.
Robin Lee66e5d962014-04-09 16:44:21 +01005208 *
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005209 * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
5210 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00005211 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005212 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01005213 * @param packageName The name of the package to update restricted settings for.
5214 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005215 * set of active restrictions.
5216 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01005217 * @see #setDelegatedScopes
5218 * @see #DELEGATION_APP_RESTRICTIONS
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00005219 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01005220 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005221 @WorkerThread
Esteban Talaverabf60f722015-12-10 16:26:44 +00005222 public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01005223 Bundle settings) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005224 throwIfParentInstance("setApplicationRestrictions");
Robin Lee66e5d962014-04-09 16:44:21 +01005225 if (mService != null) {
5226 try {
Edman Anjosf9946772016-11-28 16:35:15 +01005227 mService.setApplicationRestrictions(admin, mContext.getPackageName(), packageName,
5228 settings);
Robin Lee66e5d962014-04-09 16:44:21 +01005229 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005230 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01005231 }
5232 }
5233 }
5234
5235 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005236 * Sets a list of configuration features to enable for a TrustAgent component. This is meant to
5237 * be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all trust
5238 * agents but those enabled by this function call. If flag
Jim Millere303bf42014-08-26 17:12:29 -07005239 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005240 * <p>
5241 * The calling device admin must have requested
5242 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method;
5243 * if not, a security exception will be thrown.
Tony Mak089d8402016-04-05 17:42:55 +01005244 * <p>
5245 * This method can be called on the {@link DevicePolicyManager} instance returned by
5246 * {@link #getParentProfileInstance(ComponentName)} in order to set the configuration for
5247 * the parent profile.
Jim Miller604e7552014-07-18 19:00:02 -07005248 *
5249 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07005250 * @param target Component name of the agent to be enabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005251 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent will be
5252 * strictly disabled according to the state of the
5253 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
5254 * <p>
5255 * If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all
5256 * admins, then it's up to the TrustAgent itself to aggregate the values from all
5257 * device admins.
5258 * <p>
5259 * Consult documentation for the specific TrustAgent to determine legal options
5260 * parameters.
5261 * @throws SecurityException if {@code admin} is not an active administrator or does not use
5262 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES}
Jim Miller604e7552014-07-18 19:00:02 -07005263 */
Robin Lee25e26452015-06-02 09:56:29 -07005264 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
5265 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07005266 if (mService != null) {
5267 try {
Tony Mak089d8402016-04-05 17:42:55 +01005268 mService.setTrustAgentConfiguration(admin, target, configuration, mParentInstance);
Jim Miller604e7552014-07-18 19:00:02 -07005269 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005270 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07005271 }
5272 }
5273 }
5274
5275 /**
Jim Millere303bf42014-08-26 17:12:29 -07005276 * Gets configuration for the given trust agent based on aggregating all calls to
5277 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
5278 * all device admins.
Tony Mak089d8402016-04-05 17:42:55 +01005279 * <p>
5280 * This method can be called on the {@link DevicePolicyManager} instance returned by
5281 * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the configuration set
5282 * on the parent profile.
Jim Miller604e7552014-07-18 19:00:02 -07005283 *
Jim Millerb5db57a2015-01-14 18:17:19 -08005284 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
5285 * this function returns a list of configurations for all admins that declare
5286 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
5287 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
5288 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
5289 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07005290 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07005291 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07005292 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005293 public @Nullable List<PersistableBundle> getTrustAgentConfiguration(
5294 @Nullable ComponentName admin, @NonNull ComponentName agent) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07005295 return getTrustAgentConfiguration(admin, agent, myUserId());
Jim Millere303bf42014-08-26 17:12:29 -07005296 }
5297
5298 /** @hide per-user version */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005299 public @Nullable List<PersistableBundle> getTrustAgentConfiguration(
5300 @Nullable ComponentName admin, @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07005301 if (mService != null) {
5302 try {
Tony Mak089d8402016-04-05 17:42:55 +01005303 return mService.getTrustAgentConfiguration(admin, agent, userHandle,
5304 mParentInstance);
Jim Miller604e7552014-07-18 19:00:02 -07005305 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005306 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07005307 }
5308 }
Jim Millere303bf42014-08-26 17:12:29 -07005309 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07005310 }
5311
5312 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005313 * Called by a profile owner of a managed profile to set whether caller-Id information from the
5314 * managed profile will be shown in the parent profile, for incoming calls.
5315 * <p>
5316 * The calling device admin must be a profile owner. If it is not, a security exception will be
5317 * thrown.
Adam Connors210fe212014-07-17 15:41:43 +01005318 *
Robin Lee25e26452015-06-02 09:56:29 -07005319 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01005320 * @param disabled If true caller-Id information in the managed profile is not displayed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005321 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors210fe212014-07-17 15:41:43 +01005322 */
Robin Lee25e26452015-06-02 09:56:29 -07005323 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005324 throwIfParentInstance("setCrossProfileCallerIdDisabled");
Adam Connors210fe212014-07-17 15:41:43 +01005325 if (mService != null) {
5326 try {
Robin Lee25e26452015-06-02 09:56:29 -07005327 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01005328 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005329 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01005330 }
5331 }
5332 }
5333
5334 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005335 * Called by a profile owner of a managed profile to determine whether or not caller-Id
5336 * information has been disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005337 * <p>
5338 * The calling device admin must be a profile owner. If it is not, a security exception will be
5339 * thrown.
Adam Connors210fe212014-07-17 15:41:43 +01005340 *
Robin Lee25e26452015-06-02 09:56:29 -07005341 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005342 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors210fe212014-07-17 15:41:43 +01005343 */
Robin Lee25e26452015-06-02 09:56:29 -07005344 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005345 throwIfParentInstance("getCrossProfileCallerIdDisabled");
Adam Connors210fe212014-07-17 15:41:43 +01005346 if (mService != null) {
5347 try {
Robin Lee25e26452015-06-02 09:56:29 -07005348 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01005349 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005350 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01005351 }
5352 }
5353 return false;
5354 }
5355
5356 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07005357 * Determine whether or not caller-Id information has been disabled.
5358 *
5359 * @param userHandle The user for whom to check the caller-id permission
5360 * @hide
5361 */
5362 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
5363 if (mService != null) {
5364 try {
5365 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
5366 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005367 throw e.rethrowFromSystemServer();
Amith Yamasani570002f2014-07-18 15:48:54 -07005368 }
5369 }
5370 return false;
5371 }
5372
5373 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005374 * Called by a profile owner of a managed profile to set whether contacts search from the
5375 * managed profile will be shown in the parent profile, for incoming calls.
5376 * <p>
5377 * The calling device admin must be a profile owner. If it is not, a security exception will be
5378 * thrown.
Victor Chang1060c6182016-01-04 20:16:23 +00005379 *
5380 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5381 * @param disabled If true contacts search in the managed profile is not displayed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005382 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Chang1060c6182016-01-04 20:16:23 +00005383 */
5384 public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin,
5385 boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005386 throwIfParentInstance("setCrossProfileContactsSearchDisabled");
Victor Chang1060c6182016-01-04 20:16:23 +00005387 if (mService != null) {
5388 try {
5389 mService.setCrossProfileContactsSearchDisabled(admin, disabled);
5390 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005391 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00005392 }
5393 }
5394 }
5395
5396 /**
5397 * Called by a profile owner of a managed profile to determine whether or not contacts search
5398 * has been disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005399 * <p>
5400 * The calling device admin must be a profile owner. If it is not, a security exception will be
5401 * thrown.
Victor Chang1060c6182016-01-04 20:16:23 +00005402 *
5403 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005404 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Chang1060c6182016-01-04 20:16:23 +00005405 */
5406 public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005407 throwIfParentInstance("getCrossProfileContactsSearchDisabled");
Victor Chang1060c6182016-01-04 20:16:23 +00005408 if (mService != null) {
5409 try {
5410 return mService.getCrossProfileContactsSearchDisabled(admin);
5411 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005412 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00005413 }
5414 }
5415 return false;
5416 }
5417
5418
5419 /**
5420 * Determine whether or not contacts search has been disabled.
5421 *
5422 * @param userHandle The user for whom to check the contacts search permission
5423 * @hide
5424 */
5425 public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) {
5426 if (mService != null) {
5427 try {
5428 return mService
5429 .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier());
5430 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005431 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00005432 }
5433 }
5434 return false;
5435 }
5436
5437 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005438 * Start Quick Contact on the managed profile for the user, if the policy allows.
Victor Chang97bdacc2016-01-21 22:24:11 +00005439 *
Makoto Onuki1040da12015-03-19 11:24:00 -07005440 * @hide
5441 */
5442 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
Victor Chang97bdacc2016-01-21 22:24:11 +00005443 boolean isContactIdIgnored, long directoryId, Intent originalIntent) {
Makoto Onuki1040da12015-03-19 11:24:00 -07005444 if (mService != null) {
5445 try {
Victor Chang97bdacc2016-01-21 22:24:11 +00005446 mService.startManagedQuickContact(actualLookupKey, actualContactId,
5447 isContactIdIgnored, directoryId, originalIntent);
Makoto Onuki1040da12015-03-19 11:24:00 -07005448 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005449 throw e.rethrowFromSystemServer();
Makoto Onuki1040da12015-03-19 11:24:00 -07005450 }
5451 }
5452 }
5453
5454 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005455 * Start Quick Contact on the managed profile for the user, if the policy allows.
Ricky Wai494b95d2015-11-20 16:07:15 +00005456 * @hide
5457 */
5458 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
5459 Intent originalIntent) {
Victor Chang97bdacc2016-01-21 22:24:11 +00005460 startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT,
Ricky Wai494b95d2015-11-20 16:07:15 +00005461 originalIntent);
5462 }
5463
5464 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005465 * Called by a profile owner of a managed profile to set whether bluetooth devices can access
5466 * enterprise contacts.
Ricky Wai778ba132015-03-31 14:21:22 +01005467 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005468 * The calling device admin must be a profile owner. If it is not, a security exception will be
5469 * thrown.
Ricky Wai778ba132015-03-31 14:21:22 +01005470 * <p>
5471 * This API works on managed profile only.
5472 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005473 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5474 * @param disabled If true, bluetooth devices cannot access enterprise contacts.
5475 * @throws SecurityException if {@code admin} is not a device or profile owner.
Ricky Wai778ba132015-03-31 14:21:22 +01005476 */
Robin Lee25e26452015-06-02 09:56:29 -07005477 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005478 throwIfParentInstance("setBluetoothContactSharingDisabled");
Ricky Wai778ba132015-03-31 14:21:22 +01005479 if (mService != null) {
5480 try {
Robin Lee25e26452015-06-02 09:56:29 -07005481 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01005482 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005483 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01005484 }
5485 }
5486 }
5487
5488 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005489 * Called by a profile owner of a managed profile to determine whether or not Bluetooth devices
5490 * cannot access enterprise contacts.
Ricky Wai778ba132015-03-31 14:21:22 +01005491 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005492 * The calling device admin must be a profile owner. If it is not, a security exception will be
5493 * thrown.
Ricky Wai778ba132015-03-31 14:21:22 +01005494 * <p>
5495 * This API works on managed profile only.
5496 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005497 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5498 * @throws SecurityException if {@code admin} is not a device or profile owner.
Ricky Wai778ba132015-03-31 14:21:22 +01005499 */
Robin Lee25e26452015-06-02 09:56:29 -07005500 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005501 throwIfParentInstance("getBluetoothContactSharingDisabled");
Ricky Wai778ba132015-03-31 14:21:22 +01005502 if (mService != null) {
5503 try {
Robin Lee25e26452015-06-02 09:56:29 -07005504 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01005505 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005506 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01005507 }
5508 }
5509 return true;
5510 }
5511
5512 /**
5513 * Determine whether or not Bluetooth devices cannot access contacts.
5514 * <p>
5515 * This API works on managed profile UserHandle only.
5516 *
5517 * @param userHandle The user for whom to check the caller-id permission
5518 * @hide
5519 */
5520 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
5521 if (mService != null) {
5522 try {
5523 return mService.getBluetoothContactSharingDisabledForUser(userHandle
5524 .getIdentifier());
5525 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005526 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01005527 }
5528 }
5529 return true;
5530 }
5531
5532 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005533 * Called by the profile owner of a managed profile so that some intents sent in the managed
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005534 * profile can also be resolved in the parent, or vice versa. Only activity intents are
5535 * supported.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00005536 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005537 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01005538 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005539 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01005540 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005541 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
5542 * @throws SecurityException if {@code admin} is not a device or profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005543 */
Robin Lee25e26452015-06-02 09:56:29 -07005544 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005545 throwIfParentInstance("addCrossProfileIntentFilter");
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005546 if (mService != null) {
5547 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01005548 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005549 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005550 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005551 }
5552 }
5553 }
5554
5555 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005556 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
5557 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01005558 * Only removes those that have been set by the profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005559 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005560 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005561 * @throws SecurityException if {@code admin} is not a device or profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005562 */
Robin Lee25e26452015-06-02 09:56:29 -07005563 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005564 throwIfParentInstance("clearCrossProfileIntentFilters");
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005565 if (mService != null) {
5566 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01005567 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005568 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005569 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005570 }
5571 }
5572 }
5573
5574 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005575 * Called by a profile or device owner to set the permitted accessibility services. When set by
5576 * a device owner or profile owner the restriction applies to all profiles of the user the
5577 * device owner or profile owner is an admin for. By default the user can use any accessiblity
5578 * service. When zero or more packages have been added, accessiblity services that are not in
5579 * the list and not part of the system can not be enabled by the user.
5580 * <p>
5581 * Calling with a null value for the list disables the restriction so that all services can be
5582 * used, calling with an empty list only allows the builtin system's services.
5583 * <p>
Esteban Talavera7e4cbad2017-03-30 17:59:50 +01005584 * System accessibility services are always available to the user the list can't modify this.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005585 *
5586 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5587 * @param packageNames List of accessibility service package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005588 * @return true if setting the restriction succeeded. It fail if there is one or more non-system
5589 * accessibility services enabled, that are not in the list.
5590 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005591 */
Robin Lee25e26452015-06-02 09:56:29 -07005592 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005593 List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005594 throwIfParentInstance("setPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005595 if (mService != null) {
5596 try {
5597 return mService.setPermittedAccessibilityServices(admin, packageNames);
5598 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005599 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005600 }
5601 }
5602 return false;
5603 }
5604
5605 /**
5606 * Returns the list of permitted accessibility services set by this device or profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005607 * <p>
5608 * An empty list means no accessibility services except system services are allowed. Null means
5609 * all accessibility services are allowed.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005610 *
5611 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5612 * @return List of accessiblity service package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005613 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005614 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005615 public @Nullable List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005616 throwIfParentInstance("getPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005617 if (mService != null) {
5618 try {
5619 return mService.getPermittedAccessibilityServices(admin);
5620 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005621 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005622 }
5623 }
5624 return null;
5625 }
5626
5627 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00005628 * Called by the system to check if a specific accessibility service is disabled by admin.
5629 *
5630 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5631 * @param packageName Accessibility service package name that needs to be checked.
5632 * @param userHandle user id the admin is running as.
5633 * @return true if the accessibility service is permitted, otherwise false.
5634 *
5635 * @hide
5636 */
5637 public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin,
5638 @NonNull String packageName, int userHandle) {
5639 if (mService != null) {
5640 try {
5641 return mService.isAccessibilityServicePermittedByAdmin(admin, packageName,
5642 userHandle);
5643 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005644 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00005645 }
5646 }
5647 return false;
5648 }
5649
5650 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005651 * Returns the list of accessibility services permitted by the device or profiles
5652 * owners of this user.
5653 *
5654 * <p>Null means all accessibility services are allowed, if a non-null list is returned
5655 * it will contain the intersection of the permitted lists for any device or profile
5656 * owners that apply to this user. It will also include any system accessibility services.
5657 *
5658 * @param userId which user to check for.
5659 * @return List of accessiblity service package names.
5660 * @hide
5661 */
5662 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07005663 public @Nullable List<String> getPermittedAccessibilityServices(int userId) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005664 throwIfParentInstance("getPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005665 if (mService != null) {
5666 try {
5667 return mService.getPermittedAccessibilityServicesForUser(userId);
5668 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005669 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005670 }
5671 }
5672 return null;
5673 }
5674
5675 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005676 * Called by a profile or device owner to set the permitted input methods services. When set by
5677 * a device owner or profile owner the restriction applies to all profiles of the user the
5678 * device owner or profile owner is an admin for. By default the user can use any input method.
5679 * When zero or more packages have been added, input method that are not in the list and not
5680 * part of the system can not be enabled by the user. This method will fail if it is called for
5681 * a admin that is not for the foreground user or a profile of the foreground user.
5682 * <p>
5683 * Calling with a null value for the list disables the restriction so that all input methods can
5684 * be used, calling with an empty list disables all but the system's own input methods.
5685 * <p>
5686 * System input methods are always available to the user this method can't modify this.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005687 *
5688 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5689 * @param packageNames List of input method package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005690 * @return true if setting the restriction succeeded. It will fail if there are one or more
5691 * non-system input methods currently enabled that are not in the packageNames list.
5692 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005693 */
Esteban Talavera7e4cbad2017-03-30 17:59:50 +01005694 public boolean setPermittedInputMethods(
5695 @NonNull ComponentName admin, List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005696 throwIfParentInstance("setPermittedInputMethods");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005697 if (mService != null) {
5698 try {
5699 return mService.setPermittedInputMethods(admin, packageNames);
5700 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005701 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005702 }
5703 }
5704 return false;
5705 }
5706
5707
5708 /**
5709 * Returns the list of permitted input methods set by this device or profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005710 * <p>
5711 * An empty list means no input methods except system input methods are allowed. Null means all
5712 * input methods are allowed.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005713 *
5714 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5715 * @return List of input method package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005716 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005717 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005718 public @Nullable List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005719 throwIfParentInstance("getPermittedInputMethods");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005720 if (mService != null) {
5721 try {
5722 return mService.getPermittedInputMethods(admin);
5723 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005724 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005725 }
5726 }
5727 return null;
5728 }
5729
5730 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00005731 * Called by the system to check if a specific input method is disabled by admin.
5732 *
5733 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5734 * @param packageName Input method package name that needs to be checked.
5735 * @param userHandle user id the admin is running as.
5736 * @return true if the input method is permitted, otherwise false.
5737 *
5738 * @hide
5739 */
5740 public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin,
5741 @NonNull String packageName, int userHandle) {
5742 if (mService != null) {
5743 try {
5744 return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle);
5745 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005746 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00005747 }
5748 }
5749 return false;
5750 }
5751
5752 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005753 * Returns the list of input methods permitted by the device or profiles
Makoto Onuki32b30572015-12-11 14:29:51 -08005754 * owners of the current user. (*Not* calling user, due to a limitation in InputMethodManager.)
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005755 *
5756 * <p>Null means all input methods are allowed, if a non-null list is returned
5757 * it will contain the intersection of the permitted lists for any device or profile
5758 * owners that apply to this user. It will also include any system input methods.
5759 *
5760 * @return List of input method package names.
5761 * @hide
5762 */
5763 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07005764 public @Nullable List<String> getPermittedInputMethodsForCurrentUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005765 throwIfParentInstance("getPermittedInputMethodsForCurrentUser");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005766 if (mService != null) {
5767 try {
5768 return mService.getPermittedInputMethodsForCurrentUser();
5769 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005770 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005771 }
5772 }
5773 return null;
5774 }
5775
5776 /**
Esteban Talavera7e4cbad2017-03-30 17:59:50 +01005777 * Called by a profile owner of a managed profile to set the packages that are allowed to use
5778 * a {@link android.service.notification.NotificationListenerService} in the primary user to
5779 * see notifications from the managed profile. By default all packages are permitted by this
5780 * policy. When zero or more packages have been added, notification listeners installed on the
5781 * primary user that are not in the list and are not part of the system won't receive events
5782 * for managed profile notifications.
5783 * <p>
5784 * Calling with a {@code null} value for the list disables the restriction so that all
5785 * notification listener services be used. Calling with an empty list disables all but the
5786 * system's own notification listeners. System notification listener services are always
5787 * available to the user.
5788 * <p>
5789 * If a device or profile owner want to stop notification listeners in their user from seeing
5790 * that user's notifications they should prevent that service from running instead (e.g. via
5791 * {@link #setApplicationHidden(ComponentName, String, boolean)})
5792 *
5793 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5794 * @param packageList List of package names to whitelist
5795 * @return true if setting the restriction succeeded. It will fail if called outside a managed
5796 * profile
5797 * @throws SecurityException if {@code admin} is not a profile owner.
5798 *
5799 * @see android.service.notification.NotificationListenerService
5800 */
5801 public boolean setPermittedCrossProfileNotificationListeners(
5802 @NonNull ComponentName admin, @Nullable List<String> packageList) {
5803 throwIfParentInstance("setPermittedCrossProfileNotificationListeners");
5804 if (mService != null) {
5805 try {
5806 return mService.setPermittedCrossProfileNotificationListeners(admin, packageList);
5807 } catch (RemoteException e) {
5808 throw e.rethrowFromSystemServer();
5809 }
5810 }
5811 return false;
5812 }
5813
5814 /**
5815 * Returns the list of packages installed on the primary user that allowed to use a
5816 * {@link android.service.notification.NotificationListenerService} to receive
5817 * notifications from this managed profile, as set by the profile owner.
5818 * <p>
5819 * An empty list means no notification listener services except system ones are allowed.
5820 * A {@code null} return value indicates that all notification listeners are allowed.
5821 */
5822 public @Nullable List<String> getPermittedCrossProfileNotificationListeners(
5823 @NonNull ComponentName admin) {
5824 throwIfParentInstance("getPermittedCrossProfileNotificationListeners");
5825 if (mService != null) {
5826 try {
5827 return mService.getPermittedCrossProfileNotificationListeners(admin);
5828 } catch (RemoteException e) {
5829 throw e.rethrowFromSystemServer();
5830 }
5831 }
5832 return null;
5833 }
5834
5835 /**
5836 * Returns true if {@code NotificationListenerServices} from the given package are allowed to
5837 * receive events for notifications from the given user id. Can only be called by the system uid
5838 *
5839 * @see #setPermittedCrossProfileNotificationListeners(ComponentName, List)
5840 *
5841 * @hide
5842 */
5843 public boolean isNotificationListenerServicePermitted(
5844 @NonNull String packageName, @UserIdInt int userId) {
5845 if (mService != null) {
5846 try {
5847 return mService.isNotificationListenerServicePermitted(packageName, userId);
5848 } catch (RemoteException e) {
5849 throw e.rethrowFromSystemServer();
5850 }
5851 }
5852 return true;
5853 }
5854
5855 /**
Edman Anjos52088e42017-01-13 22:26:17 +01005856 * Get the list of apps to keep around as APKs even if no user has currently installed it. This
5857 * function can be called by a device owner or by a delegate given the
5858 * {@link #DELEGATION_KEEP_UNINSTALLED_PACKAGES} scope via {@link #setDelegatedScopes}.
5859 * <p>
5860 * Please note that packages returned in this method are not automatically pre-cached.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005861 *
Edman Anjos52088e42017-01-13 22:26:17 +01005862 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
5863 * {@code null} if the caller is a keep uninstalled packages delegate.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005864 * @return List of package names to keep cached.
Edman Anjos52088e42017-01-13 22:26:17 +01005865 * @see #setDelegatedScopes
5866 * @see #DELEGATION_KEEP_UNINSTALLED_PACKAGES
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005867 * @hide
5868 */
Edman Anjos52088e42017-01-13 22:26:17 +01005869 public @Nullable List<String> getKeepUninstalledPackages(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005870 throwIfParentInstance("getKeepUninstalledPackages");
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005871 if (mService != null) {
5872 try {
Edman Anjos52088e42017-01-13 22:26:17 +01005873 return mService.getKeepUninstalledPackages(admin, mContext.getPackageName());
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005874 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005875 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005876 }
5877 }
5878 return null;
5879 }
5880
5881 /**
Edman Anjos52088e42017-01-13 22:26:17 +01005882 * Set a list of apps to keep around as APKs even if no user has currently installed it. This
5883 * function can be called by a device owner or by a delegate given the
5884 * {@link #DELEGATION_KEEP_UNINSTALLED_PACKAGES} scope via {@link #setDelegatedScopes}.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005885 *
5886 * <p>Please note that setting this policy does not imply that specified apps will be
5887 * automatically pre-cached.</p>
5888 *
Edman Anjos52088e42017-01-13 22:26:17 +01005889 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
5890 * {@code null} if the caller is a keep uninstalled packages delegate.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005891 * @param packageNames List of package names to keep cached.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005892 * @throws SecurityException if {@code admin} is not a device owner.
Edman Anjos52088e42017-01-13 22:26:17 +01005893 * @see #setDelegatedScopes
5894 * @see #DELEGATION_KEEP_UNINSTALLED_PACKAGES
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005895 * @hide
5896 */
Edman Anjos52088e42017-01-13 22:26:17 +01005897 public void setKeepUninstalledPackages(@Nullable ComponentName admin,
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005898 @NonNull List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005899 throwIfParentInstance("setKeepUninstalledPackages");
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005900 if (mService != null) {
5901 try {
Edman Anjos52088e42017-01-13 22:26:17 +01005902 mService.setKeepUninstalledPackages(admin, mContext.getPackageName(), packageNames);
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005903 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005904 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005905 }
5906 }
5907 }
5908
5909 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04005910 * Called by a device owner to create a user with the specified name. The UserHandle returned
5911 * by this method should not be persisted as user handles are recycled as users are removed and
5912 * created. If you need to persist an identifier for this user, use
5913 * {@link UserManager#getSerialNumberForUser}.
5914 *
5915 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5916 * @param name the user's name
5917 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07005918 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
5919 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01005920 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005921 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01005922 * @removed From {@link android.os.Build.VERSION_CODES#N}
Julia Reynolds1e958392014-05-16 14:25:21 -04005923 */
Kenny Guy14f48e52015-06-29 15:12:36 +01005924 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07005925 public @Nullable UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04005926 return null;
5927 }
5928
5929 /**
Jason Monk03978a42014-06-10 15:05:30 -04005930 * Called by a device owner to create a user with the specified name. The UserHandle returned
5931 * by this method should not be persisted as user handles are recycled as users are removed and
5932 * created. If you need to persist an identifier for this user, use
5933 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
5934 * immediately.
5935 *
5936 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
5937 * as registered as an active admin on the new user. The profile owner package will be
5938 * installed on the new user if it already is installed on the device.
5939 *
5940 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
5941 * profileOwnerComponent when onEnable is called.
5942 *
5943 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5944 * @param name the user's name
5945 * @param ownerName the human readable name of the organisation associated with this DPM.
5946 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
5947 * the user.
5948 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
5949 * on the new user.
5950 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07005951 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
5952 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01005953 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005954 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01005955 * @removed From {@link android.os.Build.VERSION_CODES#N}
Jason Monk03978a42014-06-10 15:05:30 -04005956 */
Kenny Guy14f48e52015-06-29 15:12:36 +01005957 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07005958 public @Nullable UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
Robin Lee25e26452015-06-02 09:56:29 -07005959 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04005960 return null;
5961 }
5962
5963 /**
phweissa92e1212016-01-25 17:14:10 +01005964 * Flag used by {@link #createAndManageUser} to skip setup wizard after creating a new user.
phweiss343fb332016-01-25 14:48:59 +01005965 */
5966 public static final int SKIP_SETUP_WIZARD = 0x0001;
5967
5968 /**
Lenka Trochtovac8202c82016-01-26 15:11:09 +01005969 * Flag used by {@link #createAndManageUser} to specify that the user should be created
5970 * ephemeral.
5971 * @hide
5972 */
5973 public static final int MAKE_USER_EPHEMERAL = 0x0002;
5974
5975 /**
Christine Franks361b8252017-06-23 18:12:46 -07005976 * Flag used by {@link #createAndManageUser} to specify that the user should be created as a
5977 * demo user.
5978 * @hide
5979 */
5980 public static final int MAKE_USER_DEMO = 0x0004;
5981
5982 /**
Benjamin Franz77c94a92017-08-09 14:16:03 +01005983 * Flag used by {@link #createAndManageUser} to specificy that the newly created user should be
5984 * started in the background as part of the user creation.
5985 */
5986 // TODO: Investigate solutions for the case where reboot happens before setup is completed.
5987 public static final int START_USER_IN_BACKGROUND = 0x0008;
5988
5989 /**
5990 * @hide
5991 */
5992 @IntDef(
5993 flag = true,
5994 prefix = {"SKIP_", "MAKE_USER_", "START_"},
5995 value = {SKIP_SETUP_WIZARD, MAKE_USER_EPHEMERAL, MAKE_USER_DEMO,
5996 START_USER_IN_BACKGROUND}
5997 )
5998 @Retention(RetentionPolicy.SOURCE)
5999 public @interface CreateAndManageUserFlags {}
6000
6001
6002 /**
phweissa92e1212016-01-25 17:14:10 +01006003 * Called by a device owner to create a user with the specified name and a given component of
6004 * the calling package as profile owner. The UserHandle returned by this method should not be
6005 * persisted as user handles are recycled as users are removed and created. If you need to
6006 * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new
6007 * user will not be started in the background.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006008 * <p>
6009 * admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also a
6010 * DeviceAdminReceiver in the same package as admin, and will become the profile owner and will
6011 * be registered as an active admin on the new user. The profile owner package will be installed
6012 * on the new user.
6013 * <p>
6014 * If the adminExtras are not null, they will be stored on the device until the user is started
6015 * for the first time. Then the extras will be passed to the admin when onEnable is called.
phweiss343fb332016-01-25 14:48:59 +01006016 *
6017 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6018 * @param name The user's name.
phweissa92e1212016-01-25 17:14:10 +01006019 * @param profileOwner Which {@link DeviceAdminReceiver} will be profile owner. Has to be in the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006020 * same package as admin, otherwise no user is created and an
6021 * IllegalArgumentException is thrown.
phweiss343fb332016-01-25 14:48:59 +01006022 * @param adminExtras Extras that will be passed to onEnable of the admin receiver on the new
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006023 * user.
phweissa92e1212016-01-25 17:14:10 +01006024 * @param flags {@link #SKIP_SETUP_WIZARD} is supported.
phweiss343fb332016-01-25 14:48:59 +01006025 * @see UserHandle
6026 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
6027 * user could not be created.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006028 * @throws SecurityException if {@code admin} is not a device owner.
phweiss343fb332016-01-25 14:48:59 +01006029 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006030 public @Nullable UserHandle createAndManageUser(@NonNull ComponentName admin,
6031 @NonNull String name,
phweissa92e1212016-01-25 17:14:10 +01006032 @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras,
Benjamin Franz77c94a92017-08-09 14:16:03 +01006033 @CreateAndManageUserFlags int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006034 throwIfParentInstance("createAndManageUser");
phweiss343fb332016-01-25 14:48:59 +01006035 try {
phweissa92e1212016-01-25 17:14:10 +01006036 return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags);
phweiss343fb332016-01-25 14:48:59 +01006037 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006038 throw re.rethrowFromSystemServer();
phweiss343fb332016-01-25 14:48:59 +01006039 }
phweiss343fb332016-01-25 14:48:59 +01006040 }
6041
6042 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006043 * Called by a device owner to remove a user and all associated data. The primary user can not
6044 * be removed.
Julia Reynolds1e958392014-05-16 14:25:21 -04006045 *
6046 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6047 * @param userHandle the user to remove.
6048 * @return {@code true} if the user was removed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006049 * @throws SecurityException if {@code admin} is not a device owner.
Julia Reynolds1e958392014-05-16 14:25:21 -04006050 */
Robin Lee25e26452015-06-02 09:56:29 -07006051 public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006052 throwIfParentInstance("removeUser");
Julia Reynolds1e958392014-05-16 14:25:21 -04006053 try {
6054 return mService.removeUser(admin, userHandle);
6055 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006056 throw re.rethrowFromSystemServer();
Julia Reynolds1e958392014-05-16 14:25:21 -04006057 }
6058 }
6059
6060 /**
Jason Monk582d9112014-07-09 19:57:08 -04006061 * Called by a device owner to switch the specified user to the foreground.
6062 *
6063 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6064 * @param userHandle the user to switch to; null will switch to primary.
6065 * @return {@code true} if the switch was successful, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006066 * @throws SecurityException if {@code admin} is not a device owner.
Jason Monk582d9112014-07-09 19:57:08 -04006067 * @see Intent#ACTION_USER_FOREGROUND
6068 */
Robin Lee25e26452015-06-02 09:56:29 -07006069 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006070 throwIfParentInstance("switchUser");
Jason Monk582d9112014-07-09 19:57:08 -04006071 try {
6072 return mService.switchUser(admin, userHandle);
6073 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006074 throw re.rethrowFromSystemServer();
Jason Monk582d9112014-07-09 19:57:08 -04006075 }
6076 }
6077
6078 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00006079 * Retrieves the application restrictions for a given target application running in the calling
6080 * user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006081 * <p>
6082 * 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 +01006083 * application restrictions via {@link #setDelegatedScopes} with the
6084 * {@link #DELEGATION_APP_RESTRICTIONS} scope; otherwise a security exception will be thrown.
Robin Lee66e5d962014-04-09 16:44:21 +01006085 *
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07006086 * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
6087 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00006088 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006089 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01006090 * @param packageName The name of the package to fetch restricted settings of.
6091 * @return {@link Bundle} of settings corresponding to what was set last time
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006092 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty
6093 * {@link Bundle} if no restrictions have been set.
6094 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01006095 * @see #setDelegatedScopes
6096 * @see #DELEGATION_APP_RESTRICTIONS
Robin Lee66e5d962014-04-09 16:44:21 +01006097 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07006098 @WorkerThread
Makoto Onuki408e8e42016-10-25 12:10:27 -07006099 public @NonNull Bundle getApplicationRestrictions(
6100 @Nullable ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006101 throwIfParentInstance("getApplicationRestrictions");
Robin Lee66e5d962014-04-09 16:44:21 +01006102 if (mService != null) {
6103 try {
Edman Anjosf9946772016-11-28 16:35:15 +01006104 return mService.getApplicationRestrictions(admin, mContext.getPackageName(),
6105 packageName);
Robin Lee66e5d962014-04-09 16:44:21 +01006106 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006107 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01006108 }
6109 }
6110 return null;
6111 }
Amith Yamasanibe465322014-04-24 13:45:17 -07006112
6113 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05006114 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07006115 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006116 * The calling device admin must be a profile or device owner; if it is not, a security
6117 * exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07006118 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006119 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6120 * @param key The key of the restriction. See the constants in {@link android.os.UserManager}
6121 * for the list of keys.
6122 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanibe465322014-04-24 13:45:17 -07006123 */
Robin Lee25e26452015-06-02 09:56:29 -07006124 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006125 throwIfParentInstance("addUserRestriction");
Amith Yamasanibe465322014-04-24 13:45:17 -07006126 if (mService != null) {
6127 try {
6128 mService.setUserRestriction(admin, key, true);
6129 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006130 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07006131 }
6132 }
6133 }
6134
6135 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05006136 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07006137 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006138 * The calling device admin must be a profile or device owner; if it is not, a security
6139 * exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07006140 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006141 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6142 * @param key The key of the restriction. See the constants in {@link android.os.UserManager}
6143 * for the list of keys.
6144 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanibe465322014-04-24 13:45:17 -07006145 */
Robin Lee25e26452015-06-02 09:56:29 -07006146 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006147 throwIfParentInstance("clearUserRestriction");
Amith Yamasanibe465322014-04-24 13:45:17 -07006148 if (mService != null) {
6149 try {
6150 mService.setUserRestriction(admin, key, false);
6151 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006152 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07006153 }
6154 }
6155 }
Adam Connors010cfd42014-04-16 12:48:13 +01006156
6157 /**
Makoto Onuki3a3092f2015-10-30 11:07:51 -07006158 * Called by a profile or device owner to get user restrictions set with
6159 * {@link #addUserRestriction(ComponentName, String)}.
6160 * <p>
6161 * The target user may have more restrictions set by the system or other device owner / profile
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006162 * owner. To get all the user restrictions currently set, use
Makoto Onuki3a3092f2015-10-30 11:07:51 -07006163 * {@link UserManager#getUserRestrictions()}.
6164 *
6165 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006166 * @throws SecurityException if {@code admin} is not a device or profile owner.
Makoto Onuki3a3092f2015-10-30 11:07:51 -07006167 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006168 public @NonNull Bundle getUserRestrictions(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006169 throwIfParentInstance("getUserRestrictions");
Makoto Onuki3a3092f2015-10-30 11:07:51 -07006170 Bundle ret = null;
6171 if (mService != null) {
6172 try {
Sudheer Shanka549b9692016-03-30 17:12:07 -07006173 ret = mService.getUserRestrictions(admin);
6174 } catch (RemoteException e) {
6175 throw e.rethrowFromSystemServer();
6176 }
6177 }
6178 return ret == null ? new Bundle() : ret;
6179 }
6180
6181 /**
phweiss73145f42017-01-17 19:06:38 +01006182 * Called by any app to display a support dialog when a feature was disabled by an admin.
6183 * This returns an intent that can be used with {@link Context#startActivity(Intent)} to
6184 * display the dialog. It will tell the user that the feature indicated by {@code restriction}
6185 * was disabled by an admin, and include a link for more information. The default content of
6186 * the dialog can be changed by the restricting admin via
6187 * {@link #setShortSupportMessage(ComponentName, CharSequence)}. If the restriction is not
6188 * set (i.e. the feature is available), then the return value will be {@code null}.
6189 * @param restriction Indicates for which feature the dialog should be displayed. Can be a
6190 * user restriction from {@link UserManager}, e.g.
6191 * {@link UserManager#DISALLOW_ADJUST_VOLUME}, or one of the constants
6192 * {@link #POLICY_DISABLE_CAMERA} or {@link #POLICY_DISABLE_SCREEN_CAPTURE}.
6193 * @return Intent An intent to be used to start the dialog-activity if the restriction is
6194 * set by an admin, or null if the restriction does not exist or no admin set it.
6195 */
6196 public Intent createAdminSupportIntent(@NonNull String restriction) {
6197 throwIfParentInstance("createAdminSupportIntent");
6198 if (mService != null) {
6199 try {
6200 return mService.createAdminSupportIntent(restriction);
6201 } catch (RemoteException e) {
6202 throw e.rethrowFromSystemServer();
6203 }
6204 }
6205 return null;
6206 }
6207
6208 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006209 * Hide or unhide packages. When a package is hidden it is unavailable for use, but the data and
6210 * actual package file remain. This function can be called by a device owner, profile owner, or
6211 * by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via
6212 * {@link #setDelegatedScopes}.
Julia Reynolds966881e2014-05-14 12:23:08 -04006213 *
Edman Anjos52088e42017-01-13 22:26:17 +01006214 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
6215 * {@code null} if the caller is a package access delegate.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07006216 * @param packageName The name of the package to hide or unhide.
6217 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006218 * unhidden.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07006219 * @return boolean Whether the hidden setting of the package was successfully updated.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006220 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01006221 * @see #setDelegatedScopes
6222 * @see #DELEGATION_PACKAGE_ACCESS
Julia Reynolds966881e2014-05-14 12:23:08 -04006223 */
Robin Lee25e26452015-06-02 09:56:29 -07006224 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07006225 boolean hidden) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006226 throwIfParentInstance("setApplicationHidden");
Julia Reynolds966881e2014-05-14 12:23:08 -04006227 if (mService != null) {
6228 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006229 return mService.setApplicationHidden(admin, mContext.getPackageName(), packageName,
6230 hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04006231 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006232 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04006233 }
6234 }
6235 return false;
6236 }
6237
6238 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006239 * Determine if a package is hidden. This function can be called by a device owner, profile
6240 * owner, or by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via
6241 * {@link #setDelegatedScopes}.
Julia Reynolds966881e2014-05-14 12:23:08 -04006242 *
Edman Anjos52088e42017-01-13 22:26:17 +01006243 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
6244 * {@code null} if the caller is a package access delegate.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07006245 * @param packageName The name of the package to retrieve the hidden status of.
6246 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006247 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01006248 * @see #setDelegatedScopes
6249 * @see #DELEGATION_PACKAGE_ACCESS
Julia Reynolds966881e2014-05-14 12:23:08 -04006250 */
Robin Lee25e26452015-06-02 09:56:29 -07006251 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006252 throwIfParentInstance("isApplicationHidden");
Julia Reynolds966881e2014-05-14 12:23:08 -04006253 if (mService != null) {
6254 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006255 return mService.isApplicationHidden(admin, mContext.getPackageName(), packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04006256 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006257 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04006258 }
6259 }
6260 return false;
6261 }
6262
6263 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006264 * Re-enable a system app that was disabled by default when the user was initialized. This
6265 * function can be called by a device owner, profile owner, or by a delegate given the
6266 * {@link #DELEGATION_ENABLE_SYSTEM_APP} scope via {@link #setDelegatedScopes}.
Adam Connors655be2a2014-07-14 09:01:25 +00006267 *
Edman Anjos52088e42017-01-13 22:26:17 +01006268 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
6269 * {@code null} if the caller is an enable system app delegate.
Makoto Onuki32b30572015-12-11 14:29:51 -08006270 * @param packageName The package to be re-enabled in the calling profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006271 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01006272 * @see #setDelegatedScopes
6273 * @see #DELEGATION_PACKAGE_ACCESS
Adam Connors655be2a2014-07-14 09:01:25 +00006274 */
Robin Lee25e26452015-06-02 09:56:29 -07006275 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006276 throwIfParentInstance("enableSystemApp");
Adam Connors655be2a2014-07-14 09:01:25 +00006277 if (mService != null) {
6278 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006279 mService.enableSystemApp(admin, mContext.getPackageName(), packageName);
Adam Connors655be2a2014-07-14 09:01:25 +00006280 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006281 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00006282 }
6283 }
6284 }
6285
6286 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006287 * Re-enable system apps by intent that were disabled by default when the user was initialized.
6288 * This function can be called by a device owner, profile owner, or by a delegate given the
6289 * {@link #DELEGATION_ENABLE_SYSTEM_APP} scope via {@link #setDelegatedScopes}.
Adam Connors655be2a2014-07-14 09:01:25 +00006290 *
Edman Anjos52088e42017-01-13 22:26:17 +01006291 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
6292 * {@code null} if the caller is an enable system app delegate.
Adam Connors655be2a2014-07-14 09:01:25 +00006293 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006294 * intent will be re-enabled in the calling profile.
Adam Connors655be2a2014-07-14 09:01:25 +00006295 * @return int The number of activities that matched the intent and were installed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006296 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01006297 * @see #setDelegatedScopes
6298 * @see #DELEGATION_PACKAGE_ACCESS
Adam Connors655be2a2014-07-14 09:01:25 +00006299 */
Robin Lee25e26452015-06-02 09:56:29 -07006300 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006301 throwIfParentInstance("enableSystemApp");
Adam Connors655be2a2014-07-14 09:01:25 +00006302 if (mService != null) {
6303 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006304 return mService.enableSystemAppWithIntent(admin, mContext.getPackageName(), intent);
Adam Connors655be2a2014-07-14 09:01:25 +00006305 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006306 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00006307 }
6308 }
6309 return 0;
6310 }
6311
6312 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00006313 * Called by a device owner or profile owner to disable account management for a specific type
6314 * of account.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006315 * <p>
6316 * The calling device admin must be a device owner or profile owner. If it is not, a security
6317 * exception will be thrown.
6318 * <p>
6319 * When account management is disabled for an account type, adding or removing an account of
6320 * that type will not be possible.
6321 * <p>
6322 * From {@link android.os.Build.VERSION_CODES#N} the profile or device owner can still use
Benjamin Franzb6c0ce42015-11-05 10:06:51 +00006323 * {@link android.accounts.AccountManager} APIs to add or remove accounts when account
6324 * management for a specific type is disabled.
6325 *
Sander Alewijnse650c3342014-05-08 18:00:50 +01006326 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6327 * @param accountType For which account management is disabled or enabled.
6328 * @param disabled The boolean indicating that account management will be disabled (true) or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006329 * enabled (false).
6330 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnse650c3342014-05-08 18:00:50 +01006331 */
Robin Lee25e26452015-06-02 09:56:29 -07006332 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01006333 boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006334 throwIfParentInstance("setAccountManagementDisabled");
Sander Alewijnse650c3342014-05-08 18:00:50 +01006335 if (mService != null) {
6336 try {
6337 mService.setAccountManagementDisabled(admin, accountType, disabled);
6338 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006339 throw e.rethrowFromSystemServer();
Sander Alewijnse650c3342014-05-08 18:00:50 +01006340 }
6341 }
6342 }
6343
6344 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01006345 * Gets the array of accounts for which account management is disabled by the profile owner.
6346 *
6347 * <p> Account management can be disabled/enabled by calling
6348 * {@link #setAccountManagementDisabled}.
6349 *
6350 * @return a list of account types for which account management has been disabled.
6351 *
6352 * @see #setAccountManagementDisabled
6353 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006354 public @Nullable String[] getAccountTypesWithManagementDisabled() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006355 throwIfParentInstance("getAccountTypesWithManagementDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07006356 return getAccountTypesWithManagementDisabledAsUser(myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01006357 }
6358
6359 /**
6360 * @see #getAccountTypesWithManagementDisabled()
6361 * @hide
6362 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006363 public @Nullable String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01006364 if (mService != null) {
6365 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01006366 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01006367 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006368 throw e.rethrowFromSystemServer();
Sander Alewijnse5c02db62014-05-07 10:46:57 +01006369 }
6370 }
6371
6372 return null;
6373 }
justinzhang511e0d82014-03-24 16:09:24 -04006374
6375 /**
Jason Monkd7b86212014-06-16 13:15:38 -04006376 * Sets which packages may enter lock task mode.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006377 * <p>
Esteban Talaverabdcada92017-02-01 14:20:06 +00006378 * Any packages that share uid with an allowed package will also be allowed to activate lock
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006379 * task. From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task
Esteban Talaverabdcada92017-02-01 14:20:06 +00006380 * package list results in locked tasks belonging to those packages to be finished.
6381 * <p>
6382 * This function can only be called by the device owner or by a profile owner of a user/profile
6383 * that is affiliated with the device owner user. See {@link #setAffiliationIds}. Any packages
6384 * set via this method will be cleared if the user becomes unaffiliated.
Jason Monkd7b86212014-06-16 13:15:38 -04006385 *
Jason Monkd7b86212014-06-16 13:15:38 -04006386 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04006387 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Esteban Talaverabdcada92017-02-01 14:20:06 +00006388 * @throws SecurityException if {@code admin} is not the device owner, or the profile owner of
6389 * an affiliated user or profile.
Jason Monkd7b86212014-06-16 13:15:38 -04006390 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00006391 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
6392 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04006393 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04006394 */
Esteban Talaverabdcada92017-02-01 14:20:06 +00006395 public void setLockTaskPackages(@NonNull ComponentName admin, @NonNull String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04006396 throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006397 throwIfParentInstance("setLockTaskPackages");
justinzhang511e0d82014-03-24 16:09:24 -04006398 if (mService != null) {
6399 try {
Jason Monk48aacba2014-08-13 16:29:08 -04006400 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04006401 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006402 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04006403 }
6404 }
6405 }
6406
6407 /**
Esteban Talaverabdcada92017-02-01 14:20:06 +00006408 * Returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04006409 *
Esteban Talaverabdcada92017-02-01 14:20:06 +00006410 * @throws SecurityException if {@code admin} is not the device owner, or the profile owner of
6411 * an affiliated user or profile.
6412 * @see #setLockTaskPackages
justinzhang511e0d82014-03-24 16:09:24 -04006413 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006414 public @NonNull String[] getLockTaskPackages(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006415 throwIfParentInstance("getLockTaskPackages");
justinzhang511e0d82014-03-24 16:09:24 -04006416 if (mService != null) {
6417 try {
Jason Monk48aacba2014-08-13 16:29:08 -04006418 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04006419 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006420 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04006421 }
6422 }
Esteban Talaverabdcada92017-02-01 14:20:06 +00006423 return new String[0];
justinzhang511e0d82014-03-24 16:09:24 -04006424 }
6425
6426 /**
6427 * This function lets the caller know whether the given component is allowed to start the
6428 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04006429 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04006430 */
Jason Monkd7b86212014-06-16 13:15:38 -04006431 public boolean isLockTaskPermitted(String pkg) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006432 throwIfParentInstance("isLockTaskPermitted");
justinzhang511e0d82014-03-24 16:09:24 -04006433 if (mService != null) {
6434 try {
Jason Monkd7b86212014-06-16 13:15:38 -04006435 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04006436 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006437 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04006438 }
6439 }
6440 return false;
6441 }
Julia Reynoldsda551652014-05-14 17:15:16 -04006442
6443 /**
Benjamin Franz482bb232017-06-23 13:48:20 +01006444 * Called by device owners to update {@link android.provider.Settings.Global} settings.
6445 * Validation that the value of the setting is in the correct form for the setting type should
6446 * be performed by the caller.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006447 * <p>
6448 * The settings that can be updated with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04006449 * <ul>
Benjamin Franz482bb232017-06-23 13:48:20 +01006450 * <li>{@link android.provider.Settings.Global#ADB_ENABLED}</li>
6451 * <li>{@link android.provider.Settings.Global#AUTO_TIME}</li>
6452 * <li>{@link android.provider.Settings.Global#AUTO_TIME_ZONE}</li>
6453 * <li>{@link android.provider.Settings.Global#DATA_ROAMING}</li>
6454 * <li>{@link android.provider.Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
6455 * <li>{@link android.provider.Settings.Global#WIFI_SLEEP_POLICY}</li>
6456 * <li>{@link android.provider.Settings.Global#STAY_ON_WHILE_PLUGGED_IN} This setting is only
6457 * available from {@link android.os.Build.VERSION_CODES#M} onwards and can only be set if
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006458 * {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
Benjamin Franz482bb232017-06-23 13:48:20 +01006459 * <li>{@link android.provider.Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li> This
6460 * setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04006461 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006462 * <p>
6463 * Changing the following settings has no effect as of {@link android.os.Build.VERSION_CODES#M}:
Esteban Talavera656fa7f2015-06-29 17:41:39 +01006464 * <ul>
Benjamin Franz482bb232017-06-23 13:48:20 +01006465 * <li>{@link android.provider.Settings.Global#BLUETOOTH_ON}. Use
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006466 * {@link android.bluetooth.BluetoothAdapter#enable()} and
6467 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
Benjamin Franz482bb232017-06-23 13:48:20 +01006468 * <li>{@link android.provider.Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
6469 * <li>{@link android.provider.Settings.Global#MODE_RINGER}. Use
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006470 * {@link android.media.AudioManager#setRingerMode(int)} instead.</li>
Benjamin Franz482bb232017-06-23 13:48:20 +01006471 * <li>{@link android.provider.Settings.Global#NETWORK_PREFERENCE}</li>
6472 * <li>{@link android.provider.Settings.Global#WIFI_ON}. Use
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006473 * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01006474 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04006475 *
6476 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6477 * @param setting The name of the setting to update.
6478 * @param value The value to update the setting to.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006479 * @throws SecurityException if {@code admin} is not a device owner.
Julia Reynoldsda551652014-05-14 17:15:16 -04006480 */
Robin Lee25e26452015-06-02 09:56:29 -07006481 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006482 throwIfParentInstance("setGlobalSetting");
Julia Reynoldsda551652014-05-14 17:15:16 -04006483 if (mService != null) {
6484 try {
6485 mService.setGlobalSetting(admin, setting, value);
6486 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006487 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04006488 }
6489 }
6490 }
6491
6492 /**
Benjamin Franz482bb232017-06-23 13:48:20 +01006493 * Called by profile or device owners to update {@link android.provider.Settings.Secure}
6494 * settings. Validation that the value of the setting is in the correct form for the setting
6495 * type should be performed by the caller.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006496 * <p>
6497 * The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04006498 * <ul>
Benjamin Franz482bb232017-06-23 13:48:20 +01006499 * <li>{@link android.provider.Settings.Secure#DEFAULT_INPUT_METHOD}</li>
6500 * <li>{@link android.provider.Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04006501 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006502 * <p>
6503 * A device owner can additionally update the following settings:
Julia Reynolds82735bc2014-09-04 16:43:30 -04006504 * <ul>
Benjamin Franz482bb232017-06-23 13:48:20 +01006505 * <li>{@link android.provider.Settings.Secure#LOCATION_MODE}</li>
Julia Reynolds82735bc2014-09-04 16:43:30 -04006506 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006507 *
Suprabh Shukla0b1356f2017-02-21 14:33:50 -08006508 * <strong>Note: Starting from Android O, apps should no longer call this method with the
6509 * setting {@link android.provider.Settings.Secure#INSTALL_NON_MARKET_APPS}, which is
6510 * deprecated. Instead, device owners or profile owners should use the restriction
6511 * {@link UserManager#DISALLOW_INSTALL_UNKNOWN_SOURCES}.
6512 * If any app targeting {@link android.os.Build.VERSION_CODES#O} or higher calls this method
6513 * with {@link android.provider.Settings.Secure#INSTALL_NON_MARKET_APPS},
6514 * an {@link UnsupportedOperationException} is thrown.
6515 * </strong>
6516 *
Julia Reynoldsda551652014-05-14 17:15:16 -04006517 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6518 * @param setting The name of the setting to update.
6519 * @param value The value to update the setting to.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006520 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynoldsda551652014-05-14 17:15:16 -04006521 */
Robin Lee25e26452015-06-02 09:56:29 -07006522 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006523 throwIfParentInstance("setSecureSetting");
Julia Reynoldsda551652014-05-14 17:15:16 -04006524 if (mService != null) {
6525 try {
6526 mService.setSecureSetting(admin, setting, value);
6527 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006528 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04006529 }
6530 }
6531 }
6532
Amith Yamasanif20d6402014-05-24 15:34:37 -07006533 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006534 * Designates a specific service component as the provider for making permission requests of a
6535 * local or remote administrator of the user.
Amith Yamasanif20d6402014-05-24 15:34:37 -07006536 * <p/>
6537 * Only a profile owner can designate the restrictions provider.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006538 *
Amith Yamasanif20d6402014-05-24 15:34:37 -07006539 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07006540 * @param provider The component name of the service that implements
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006541 * {@link RestrictionsReceiver}. If this param is null, it removes the restrictions
6542 * provider previously assigned.
6543 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanif20d6402014-05-24 15:34:37 -07006544 */
Robin Lee25e26452015-06-02 09:56:29 -07006545 public void setRestrictionsProvider(@NonNull ComponentName admin,
6546 @Nullable ComponentName provider) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006547 throwIfParentInstance("setRestrictionsProvider");
Amith Yamasanif20d6402014-05-24 15:34:37 -07006548 if (mService != null) {
6549 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07006550 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07006551 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006552 throw re.rethrowFromSystemServer();
Amith Yamasanif20d6402014-05-24 15:34:37 -07006553 }
6554 }
6555 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04006556
6557 /**
6558 * Called by profile or device owners to set the master volume mute on or off.
Nicolas Prevotaef3ce22016-09-22 12:00:25 +01006559 * This has no effect when set on a managed profile.
Julia Reynolds4a21b252014-06-04 11:11:43 -04006560 *
6561 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6562 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006563 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds4a21b252014-06-04 11:11:43 -04006564 */
Robin Lee25e26452015-06-02 09:56:29 -07006565 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006566 throwIfParentInstance("setMasterVolumeMuted");
Julia Reynolds4a21b252014-06-04 11:11:43 -04006567 if (mService != null) {
6568 try {
6569 mService.setMasterVolumeMuted(admin, on);
6570 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006571 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04006572 }
6573 }
6574 }
6575
6576 /**
6577 * Called by profile or device owners to check whether the master volume mute is on or off.
6578 *
6579 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6580 * @return {@code true} if master volume is muted, {@code false} if it's not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006581 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds4a21b252014-06-04 11:11:43 -04006582 */
Robin Lee25e26452015-06-02 09:56:29 -07006583 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006584 throwIfParentInstance("isMasterVolumeMuted");
Julia Reynolds4a21b252014-06-04 11:11:43 -04006585 if (mService != null) {
6586 try {
6587 return mService.isMasterVolumeMuted(admin);
6588 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006589 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04006590 }
6591 }
6592 return false;
6593 }
Kenny Guyc13053b2014-05-29 14:17:17 +01006594
6595 /**
Edman Anjosa5f2fb12016-12-19 11:25:54 -08006596 * Change whether a user can uninstall a package. This function can be called by a device owner,
6597 * profile owner, or by a delegate given the {@link #DELEGATION_BLOCK_UNINSTALL} scope via
6598 * {@link #setDelegatedScopes}.
Kenny Guyc13053b2014-05-29 14:17:17 +01006599 *
Edman Anjosa5f2fb12016-12-19 11:25:54 -08006600 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
6601 * {@code null} if the caller is a block uninstall delegate.
Kenny Guyc13053b2014-05-29 14:17:17 +01006602 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01006603 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006604 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjosa5f2fb12016-12-19 11:25:54 -08006605 * @see #setDelegatedScopes
6606 * @see #DELEGATION_BLOCK_UNINSTALL
Kenny Guyc13053b2014-05-29 14:17:17 +01006607 */
Edman Anjosa5f2fb12016-12-19 11:25:54 -08006608 public void setUninstallBlocked(@Nullable ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01006609 boolean uninstallBlocked) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006610 throwIfParentInstance("setUninstallBlocked");
Kenny Guyc13053b2014-05-29 14:17:17 +01006611 if (mService != null) {
6612 try {
Edman Anjosa5f2fb12016-12-19 11:25:54 -08006613 mService.setUninstallBlocked(admin, mContext.getPackageName(), packageName,
6614 uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01006615 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006616 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01006617 }
6618 }
6619 }
6620
6621 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08006622 * Check whether the user has been blocked by device policy from uninstalling a package.
Rubin Xua97855b2014-11-07 05:41:00 +00006623 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00006624 * <p>
6625 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006626 * behavior of this API is changed such that passing {@code null} as the {@code admin} parameter
6627 * will return if any admin has blocked the uninstallation. Before L MR1, passing {@code null}
6628 * will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01006629 *
Robin Lee25e26452015-06-02 09:56:29 -07006630 * @param admin The name of the admin component whose blocking policy will be checked, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006631 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01006632 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00006633 * @return true if uninstallation is blocked.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006634 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyc13053b2014-05-29 14:17:17 +01006635 */
Robin Lee25e26452015-06-02 09:56:29 -07006636 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006637 throwIfParentInstance("isUninstallBlocked");
Kenny Guyc13053b2014-05-29 14:17:17 +01006638 if (mService != null) {
6639 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01006640 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01006641 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006642 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01006643 }
6644 }
6645 return false;
6646 }
Svetoslav976e8bd2014-07-16 15:12:03 -07006647
6648 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006649 * Called by the profile owner of a managed profile to enable widget providers from a given
6650 * package to be available in the parent profile. As a result the user will be able to add
6651 * widgets from the white-listed package running under the profile to a widget host which runs
6652 * under the parent profile, for example the home screen. Note that a package may have zero or
6653 * more provider components, where each component provides a different widget type.
Svetoslav976e8bd2014-07-16 15:12:03 -07006654 * <p>
6655 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07006656 *
6657 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6658 * @param packageName The package from which widget providers are white-listed.
6659 * @return Whether the package was added.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006660 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07006661 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
6662 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
6663 */
Robin Lee25e26452015-06-02 09:56:29 -07006664 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006665 throwIfParentInstance("addCrossProfileWidgetProvider");
Svetoslav976e8bd2014-07-16 15:12:03 -07006666 if (mService != null) {
6667 try {
6668 return mService.addCrossProfileWidgetProvider(admin, packageName);
6669 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006670 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07006671 }
6672 }
6673 return false;
6674 }
6675
6676 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07006677 * Called by the profile owner of a managed profile to disable widget providers from a given
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006678 * package to be available in the parent profile. For this method to take effect the package
6679 * should have been added via
6680 * {@link #addCrossProfileWidgetProvider( android.content.ComponentName, String)}.
Svetoslav976e8bd2014-07-16 15:12:03 -07006681 * <p>
6682 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07006683 *
6684 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006685 * @param packageName The package from which widget providers are no longer white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07006686 * @return Whether the package was removed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006687 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07006688 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
6689 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
6690 */
Esteban Talavera62399912016-01-11 15:37:55 +00006691 public boolean removeCrossProfileWidgetProvider(
6692 @NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006693 throwIfParentInstance("removeCrossProfileWidgetProvider");
Svetoslav976e8bd2014-07-16 15:12:03 -07006694 if (mService != null) {
6695 try {
6696 return mService.removeCrossProfileWidgetProvider(admin, packageName);
6697 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006698 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07006699 }
6700 }
6701 return false;
6702 }
6703
6704 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07006705 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07006706 * available in the parent profile.
6707 *
6708 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6709 * @return The white-listed package list.
Svetoslav976e8bd2014-07-16 15:12:03 -07006710 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
6711 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006712 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07006713 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006714 public @NonNull List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006715 throwIfParentInstance("getCrossProfileWidgetProviders");
Svetoslav976e8bd2014-07-16 15:12:03 -07006716 if (mService != null) {
6717 try {
6718 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
6719 if (providers != null) {
6720 return providers;
6721 }
6722 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006723 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07006724 }
6725 }
6726 return Collections.emptyList();
6727 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006728
6729 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08006730 * Called by profile or device owners to set the user's photo.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006731 *
6732 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6733 * @param icon the bitmap to set as the photo.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006734 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006735 */
Robin Lee25e26452015-06-02 09:56:29 -07006736 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006737 throwIfParentInstance("setUserIcon");
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006738 try {
6739 mService.setUserIcon(admin, icon);
6740 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006741 throw re.rethrowFromSystemServer();
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006742 }
6743 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04006744
6745 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01006746 * Called by device owners to set a local system update policy. When a new policy is set,
6747 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00006748 *
Robin Lee25e26452015-06-02 09:56:29 -07006749 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006750 * components in the device owner package can set system update policies and the most
6751 * recent policy takes effect.
Robin Lee25e26452015-06-02 09:56:29 -07006752 * @param policy the new policy, or {@code null} to clear the current policy.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006753 * @throws SecurityException if {@code admin} is not a device owner.
Rubin Xu5faad8e2015-04-20 17:43:48 +01006754 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00006755 */
Robin Lee25e26452015-06-02 09:56:29 -07006756 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006757 throwIfParentInstance("setSystemUpdatePolicy");
Rubin Xu8027a4f2015-03-10 17:52:37 +00006758 if (mService != null) {
6759 try {
Robin Lee25e26452015-06-02 09:56:29 -07006760 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00006761 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006762 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00006763 }
6764 }
6765 }
6766
6767 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01006768 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00006769 *
Robin Lee25e26452015-06-02 09:56:29 -07006770 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00006771 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006772 public @Nullable SystemUpdatePolicy getSystemUpdatePolicy() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006773 throwIfParentInstance("getSystemUpdatePolicy");
Rubin Xu8027a4f2015-03-10 17:52:37 +00006774 if (mService != null) {
6775 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01006776 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00006777 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006778 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00006779 }
6780 }
6781 return null;
6782 }
Benjamin Franze36087e2015-04-07 16:40:34 +01006783
6784 /**
6785 * Called by a device owner to disable the keyguard altogether.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006786 * <p>
6787 * Setting the keyguard to disabled has the same effect as choosing "None" as the screen lock
6788 * type. However, this call has no effect if a password, pin or pattern is currently set. If a
6789 * password, pin or pattern is set after the keyguard was disabled, the keyguard stops being
6790 * disabled.
Benjamin Franze36087e2015-04-07 16:40:34 +01006791 *
6792 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01006793 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01006794 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006795 * place. {@code true} otherwise.
6796 * @throws SecurityException if {@code admin} is not a device owner.
Benjamin Franze36087e2015-04-07 16:40:34 +01006797 */
Robin Lee25e26452015-06-02 09:56:29 -07006798 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006799 throwIfParentInstance("setKeyguardDisabled");
Benjamin Franze36087e2015-04-07 16:40:34 +01006800 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01006801 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01006802 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006803 throw re.rethrowFromSystemServer();
Benjamin Franze36087e2015-04-07 16:40:34 +01006804 }
6805 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00006806
6807 /**
Benjamin Franzbece8062015-05-06 12:14:31 +01006808 * Called by device owner to disable the status bar. Disabling the status bar blocks
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006809 * notifications, quick settings and other screen overlays that allow escaping from a single use
6810 * device.
Benjamin Franzea2ec972015-03-16 17:18:09 +00006811 *
6812 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01006813 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006814 * @return {@code false} if attempting to disable the status bar failed. {@code true} otherwise.
6815 * @throws SecurityException if {@code admin} is not a device owner.
Benjamin Franzea2ec972015-03-16 17:18:09 +00006816 */
Robin Lee25e26452015-06-02 09:56:29 -07006817 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006818 throwIfParentInstance("setStatusBarDisabled");
Benjamin Franzea2ec972015-03-16 17:18:09 +00006819 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01006820 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00006821 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006822 throw re.rethrowFromSystemServer();
Benjamin Franzea2ec972015-03-16 17:18:09 +00006823 }
6824 }
Rubin Xudc105cc2015-04-14 23:38:01 +01006825
6826 /**
Charles Hedea0c3b2017-01-13 10:04:12 +00006827 * Called by the system update service to notify device and profile owners of pending system
6828 * updates.
Rubin Xudc105cc2015-04-14 23:38:01 +01006829 *
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06006830 * This method should only be used when it is unknown whether the pending system
Charles Hedea0c3b2017-01-13 10:04:12 +00006831 * update is a security patch. Otherwise, use
6832 * {@link #notifyPendingSystemUpdate(long, boolean)}.
6833 *
6834 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()}
6835 * indicating when the current pending update was first available. {@code -1} if no
6836 * update is available.
6837 * @see #notifyPendingSystemUpdate(long, boolean)
Rubin Xudc105cc2015-04-14 23:38:01 +01006838 * @hide
6839 */
6840 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06006841 @RequiresPermission(android.Manifest.permission.NOTIFY_PENDING_SYSTEM_UPDATE)
Rubin Xudc105cc2015-04-14 23:38:01 +01006842 public void notifyPendingSystemUpdate(long updateReceivedTime) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006843 throwIfParentInstance("notifyPendingSystemUpdate");
Rubin Xudc105cc2015-04-14 23:38:01 +01006844 if (mService != null) {
6845 try {
Charles Hedea0c3b2017-01-13 10:04:12 +00006846 mService.notifyPendingSystemUpdate(SystemUpdateInfo.of(updateReceivedTime));
6847 } catch (RemoteException re) {
6848 throw re.rethrowFromSystemServer();
6849 }
6850 }
6851 }
6852
6853 /**
6854 * Called by the system update service to notify device and profile owners of pending system
6855 * updates.
6856 *
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06006857 * This method should be used instead of {@link #notifyPendingSystemUpdate(long)}
Charles Hedea0c3b2017-01-13 10:04:12 +00006858 * when it is known whether the pending system update is a security patch.
6859 *
6860 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()}
6861 * indicating when the current pending update was first available. {@code -1} if no
6862 * update is available.
6863 * @param isSecurityPatch {@code true} if this system update is purely a security patch;
6864 * {@code false} if not.
6865 * @see #notifyPendingSystemUpdate(long)
6866 * @hide
6867 */
6868 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06006869 @RequiresPermission(android.Manifest.permission.NOTIFY_PENDING_SYSTEM_UPDATE)
Charles Hedea0c3b2017-01-13 10:04:12 +00006870 public void notifyPendingSystemUpdate(long updateReceivedTime, boolean isSecurityPatch) {
6871 throwIfParentInstance("notifyPendingSystemUpdate");
6872 if (mService != null) {
6873 try {
6874 mService.notifyPendingSystemUpdate(SystemUpdateInfo.of(updateReceivedTime,
6875 isSecurityPatch));
Rubin Xudc105cc2015-04-14 23:38:01 +01006876 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006877 throw re.rethrowFromSystemServer();
Rubin Xudc105cc2015-04-14 23:38:01 +01006878 }
6879 }
6880 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04006881
6882 /**
Pavel Grafovd65799e2016-12-02 11:21:45 +00006883 * Called by device or profile owners to get information about a pending system update.
6884 *
6885 * @param admin Which profile or device owner this request is associated with.
6886 * @return Information about a pending system update or {@code null} if no update pending.
6887 * @throws SecurityException if {@code admin} is not a device or profile owner.
6888 * @see DeviceAdminReceiver#onSystemUpdatePending(Context, Intent, long)
6889 */
6890 public @Nullable SystemUpdateInfo getPendingSystemUpdate(@NonNull ComponentName admin) {
6891 throwIfParentInstance("getPendingSystemUpdate");
6892 try {
6893 return mService.getPendingSystemUpdate(admin);
6894 } catch (RemoteException re) {
6895 throw re.rethrowFromSystemServer();
6896 }
6897 }
6898
6899 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006900 * Set the default response for future runtime permission requests by applications. This
6901 * function can be called by a device owner, profile owner, or by a delegate given the
6902 * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}.
6903 * The policy can allow for normal operation which prompts the user to grant a permission, or
6904 * can allow automatic granting or denying of runtime permission requests by an application.
6905 * This also applies to new permissions declared by app updates. When a permission is denied or
6906 * granted this way, the effect is equivalent to setting the permission * grant state via
6907 * {@link #setPermissionGrantState}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006908 * <p/>
6909 * As this policy only acts on runtime permission requests, it only applies to applications
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07006910 * built with a {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Benjamin Franz45dd6662015-07-08 14:24:14 +01006911 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07006912 * @param admin Which profile or device owner this request is associated with.
6913 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006914 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
6915 * @throws SecurityException if {@code admin} is not a device or profile owner.
Benjamin Franz45dd6662015-07-08 14:24:14 +01006916 * @see #setPermissionGrantState
Edman Anjos52088e42017-01-13 22:26:17 +01006917 * @see #setDelegatedScopes
6918 * @see #DELEGATION_PERMISSION_GRANT
Amith Yamasanid49489b2015-04-28 14:00:26 -07006919 */
Robin Lee25e26452015-06-02 09:56:29 -07006920 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006921 throwIfParentInstance("setPermissionPolicy");
Amith Yamasanid49489b2015-04-28 14:00:26 -07006922 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006923 mService.setPermissionPolicy(admin, mContext.getPackageName(), policy);
Amith Yamasanid49489b2015-04-28 14:00:26 -07006924 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006925 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07006926 }
6927 }
6928
6929 /**
6930 * Returns the current runtime permission policy set by the device or profile owner. The
6931 * default is {@link #PERMISSION_POLICY_PROMPT}.
Edman Anjos52088e42017-01-13 22:26:17 +01006932 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07006933 * @param admin Which profile or device owner this request is associated with.
6934 * @return the current policy for future permission requests.
6935 */
Esteban Talavera28b95702015-06-24 15:23:42 +01006936 public int getPermissionPolicy(ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006937 throwIfParentInstance("getPermissionPolicy");
Amith Yamasanid49489b2015-04-28 14:00:26 -07006938 try {
6939 return mService.getPermissionPolicy(admin);
6940 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006941 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07006942 }
6943 }
6944
6945 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006946 * Sets the grant state of a runtime permission for a specific application. The state can be
6947 * {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it through the UI,
6948 * {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission is denied and the user
6949 * cannot manage it through the UI, and {@link #PERMISSION_GRANT_STATE_GRANTED granted} in which
6950 * the permission is granted and the user cannot manage it through the UI. This might affect all
6951 * permissions in a group that the runtime permission belongs to. This method can only be called
Edman Anjos52088e42017-01-13 22:26:17 +01006952 * by a profile owner, device owner, or a delegate given the
6953 * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006954 * <p/>
6955 * Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not revoke
6956 * the permission. It retains the previous grant, if any.
6957 * <p/>
6958 * Permissions can be granted or revoked only for applications built with a
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07006959 * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07006960 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07006961 * @param admin Which profile or device owner this request is associated with.
6962 * @param packageName The application to grant or revoke a permission to.
6963 * @param permission The permission to grant or revoke.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006964 * @param grantState The permission grant state which is one of
6965 * {@link #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
6966 * {@link #PERMISSION_GRANT_STATE_GRANTED},
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006967 * @return whether the permission was successfully granted or revoked.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006968 * @throws SecurityException if {@code admin} is not a device or profile owner.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006969 * @see #PERMISSION_GRANT_STATE_DENIED
6970 * @see #PERMISSION_GRANT_STATE_DEFAULT
6971 * @see #PERMISSION_GRANT_STATE_GRANTED
Edman Anjos52088e42017-01-13 22:26:17 +01006972 * @see #setDelegatedScopes
6973 * @see #DELEGATION_PERMISSION_GRANT
Amith Yamasanid49489b2015-04-28 14:00:26 -07006974 */
Robin Lee25e26452015-06-02 09:56:29 -07006975 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006976 String permission, int grantState) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006977 throwIfParentInstance("setPermissionGrantState");
Amith Yamasanid49489b2015-04-28 14:00:26 -07006978 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006979 return mService.setPermissionGrantState(admin, mContext.getPackageName(), packageName,
6980 permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07006981 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006982 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07006983 }
6984 }
Amith Yamasani184b3752015-05-22 13:00:51 -07006985
6986 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006987 * Returns the current grant state of a runtime permission for a specific application. This
6988 * function can be called by a device owner, profile owner, or by a delegate given the
6989 * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}.
Amith Yamasani184b3752015-05-22 13:00:51 -07006990 *
Edman Anjos52088e42017-01-13 22:26:17 +01006991 * @param admin Which profile or device owner this request is associated with, or {@code null}
6992 * if the caller is a permission grant delegate.
Amith Yamasani184b3752015-05-22 13:00:51 -07006993 * @param packageName The application to check the grant state for.
6994 * @param permission The permission to check for.
6995 * @return the current grant state specified by device policy. If the profile or device owner
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006996 * has not set a grant state, the return value is
6997 * {@link #PERMISSION_GRANT_STATE_DEFAULT}. This does not indicate whether or not the
6998 * permission is currently granted for the package.
6999 * <p/>
7000 * If a grant state was set by the profile or device owner, then the return value will
7001 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or
7002 * {@link #PERMISSION_GRANT_STATE_GRANTED}, which indicates if the permission is
7003 * currently denied or granted.
7004 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasani184b3752015-05-22 13:00:51 -07007005 * @see #setPermissionGrantState(ComponentName, String, String, int)
7006 * @see PackageManager#checkPermission(String, String)
Edman Anjos52088e42017-01-13 22:26:17 +01007007 * @see #setDelegatedScopes
7008 * @see #DELEGATION_PERMISSION_GRANT
Amith Yamasani184b3752015-05-22 13:00:51 -07007009 */
Bartosz Fabianowski4b0624f2017-01-16 11:47:28 +01007010 public int getPermissionGrantState(@Nullable ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07007011 String permission) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007012 throwIfParentInstance("getPermissionGrantState");
Amith Yamasani184b3752015-05-22 13:00:51 -07007013 try {
Edman Anjos52088e42017-01-13 22:26:17 +01007014 return mService.getPermissionGrantState(admin, mContext.getPackageName(), packageName,
7015 permission);
Amith Yamasani184b3752015-05-22 13:00:51 -07007016 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007017 throw re.rethrowFromSystemServer();
Amith Yamasani184b3752015-05-22 13:00:51 -07007018 }
7019 }
Nicolas Prevot07387fe2015-10-30 17:53:30 +00007020
7021 /**
Esteban Talavera01576862016-12-15 11:16:44 +00007022 * Returns whether it is possible for the caller to initiate provisioning of a managed profile
7023 * or device, setting itself as the device or profile owner.
7024 *
Nicolas Prevot07387fe2015-10-30 17:53:30 +00007025 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
7026 * {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Esteban Talavera01576862016-12-15 11:16:44 +00007027 * @return whether provisioning a managed profile or device is possible.
Nicolas Prevot07387fe2015-10-30 17:53:30 +00007028 * @throws IllegalArgumentException if the supplied action is not valid.
7029 */
Esteban Talavera01576862016-12-15 11:16:44 +00007030 public boolean isProvisioningAllowed(@NonNull String action) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007031 throwIfParentInstance("isProvisioningAllowed");
Nicolas Prevot07387fe2015-10-30 17:53:30 +00007032 try {
Esteban Talavera01576862016-12-15 11:16:44 +00007033 return mService.isProvisioningAllowed(action, mContext.getPackageName());
Nicolas Prevot07387fe2015-10-30 17:53:30 +00007034 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007035 throw re.rethrowFromSystemServer();
Nicolas Prevot07387fe2015-10-30 17:53:30 +00007036 }
7037 }
Mahaver Chopra15a46b02015-11-11 14:54:35 +00007038
7039 /**
Esteban Talavera01576862016-12-15 11:16:44 +00007040 * Checks whether it is possible to initiate provisioning a managed device,
7041 * profile or user, setting the given package as owner.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00007042 *
7043 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
7044 * {@link #ACTION_PROVISION_MANAGED_PROFILE},
7045 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE},
7046 * {@link #ACTION_PROVISION_MANAGED_USER}
Esteban Talavera01576862016-12-15 11:16:44 +00007047 * @param packageName The package of the component that would be set as device, user, or profile
7048 * owner.
7049 * @return A {@link ProvisioningPreCondition} value indicating whether provisioning is allowed.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00007050 * @hide
7051 */
Esteban Talavera01576862016-12-15 11:16:44 +00007052 public @ProvisioningPreCondition int checkProvisioningPreCondition(
7053 String action, @NonNull String packageName) {
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00007054 try {
Esteban Talavera01576862016-12-15 11:16:44 +00007055 return mService.checkProvisioningPreCondition(action, packageName);
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00007056 } catch (RemoteException re) {
7057 throw re.rethrowFromSystemServer();
7058 }
7059 }
7060
7061 /**
Mahaver Chopra15a46b02015-11-11 14:54:35 +00007062 * Return if this user is a managed profile of another user. An admin can become the profile
7063 * owner of a managed profile with {@link #ACTION_PROVISION_MANAGED_PROFILE} and of a managed
Kenny Guyffa38402016-03-31 16:40:57 +01007064 * user with {@link #createAndManageUser}
Mahaver Chopra15a46b02015-11-11 14:54:35 +00007065 * @param admin Which profile owner this request is associated with.
7066 * @return if this user is a managed profile of another user.
7067 */
7068 public boolean isManagedProfile(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007069 throwIfParentInstance("isManagedProfile");
Mahaver Chopra15a46b02015-11-11 14:54:35 +00007070 try {
7071 return mService.isManagedProfile(admin);
7072 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007073 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00007074 }
7075 }
7076
7077 /**
7078 * @hide
7079 * Return if this user is a system-only user. An admin can manage a device from a system only
7080 * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}.
7081 * @param admin Which device owner this request is associated with.
7082 * @return if this user is a system-only user.
7083 */
7084 public boolean isSystemOnlyUser(@NonNull ComponentName admin) {
7085 try {
7086 return mService.isSystemOnlyUser(admin);
7087 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007088 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00007089 }
7090 }
Makoto Onukia31ebbc2015-11-23 17:15:21 -08007091
7092 /**
7093 * Called by device owner to get the MAC address of the Wi-Fi device.
7094 *
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08007095 * @param admin Which device owner this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007096 * @return the MAC address of the Wi-Fi device, or null when the information is not available.
7097 * (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.)
7098 * <p>
7099 * The address will be in the {@code XX:XX:XX:XX:XX:XX} format.
7100 * @throws SecurityException if {@code admin} is not a device owner.
Makoto Onukia31ebbc2015-11-23 17:15:21 -08007101 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007102 public @Nullable String getWifiMacAddress(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007103 throwIfParentInstance("getWifiMacAddress");
Makoto Onukia31ebbc2015-11-23 17:15:21 -08007104 try {
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08007105 return mService.getWifiMacAddress(admin);
Makoto Onukia31ebbc2015-11-23 17:15:21 -08007106 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007107 throw re.rethrowFromSystemServer();
Makoto Onukia31ebbc2015-11-23 17:15:21 -08007108 }
7109 }
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00007110
7111 /**
Mahaver Chopra1216ae52016-03-11 15:39:48 +00007112 * Called by device owner to reboot the device. If there is an ongoing call on the device,
7113 * throws an {@link IllegalStateException}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007114 * @param admin Which device owner the request is associated with.
Mahaver Chopra1216ae52016-03-11 15:39:48 +00007115 * @throws IllegalStateException if device has an ongoing call.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007116 * @throws SecurityException if {@code admin} is not a device owner.
Mahaver Chopra1216ae52016-03-11 15:39:48 +00007117 * @see TelephonyManager#CALL_STATE_IDLE
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00007118 */
7119 public void reboot(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007120 throwIfParentInstance("reboot");
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00007121 try {
7122 mService.reboot(admin);
7123 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007124 throw re.rethrowFromSystemServer();
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00007125 }
7126 }
Kenny Guy06de4e72015-12-22 12:07:39 +00007127
7128 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007129 * Called by a device admin to set the short support message. This will be displayed to the user
7130 * in settings screens where funtionality has been disabled by the admin. The message should be
7131 * limited to a short statement such as "This setting is disabled by your administrator. Contact
7132 * someone@example.com for support." If the message is longer than 200 characters it may be
7133 * truncated.
7134 * <p>
7135 * If the short support message needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007136 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
7137 * and set a new version of this string accordingly.
7138 *
Kenny Guy06de4e72015-12-22 12:07:39 +00007139 * @see #setLongSupportMessage
Kenny Guy06de4e72015-12-22 12:07:39 +00007140 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007141 * @param message Short message to be displayed to the user in settings or null to clear the
7142 * existing message.
7143 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00007144 */
7145 public void setShortSupportMessage(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007146 @Nullable CharSequence message) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007147 throwIfParentInstance("setShortSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00007148 if (mService != null) {
7149 try {
7150 mService.setShortSupportMessage(admin, message);
7151 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007152 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00007153 }
7154 }
7155 }
7156
7157 /**
7158 * Called by a device admin to get the short support message.
7159 *
7160 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007161 * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)} or
7162 * null if no message has been set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007163 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00007164 */
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007165 public CharSequence getShortSupportMessage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007166 throwIfParentInstance("getShortSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00007167 if (mService != null) {
7168 try {
7169 return mService.getShortSupportMessage(admin);
7170 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007171 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00007172 }
7173 }
7174 return null;
7175 }
7176
7177 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007178 * Called by a device admin to set the long support message. This will be displayed to the user
7179 * in the device administators settings screen.
7180 * <p>
7181 * If the long support message needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007182 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
7183 * and set a new version of this string accordingly.
7184 *
Kenny Guy06de4e72015-12-22 12:07:39 +00007185 * @see #setShortSupportMessage
Kenny Guy06de4e72015-12-22 12:07:39 +00007186 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007187 * @param message Long message to be displayed to the user in settings or null to clear the
7188 * existing message.
7189 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00007190 */
7191 public void setLongSupportMessage(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007192 @Nullable CharSequence message) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007193 throwIfParentInstance("setLongSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00007194 if (mService != null) {
7195 try {
7196 mService.setLongSupportMessage(admin, message);
7197 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007198 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00007199 }
7200 }
7201 }
7202
7203 /**
7204 * Called by a device admin to get the long support message.
7205 *
7206 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007207 * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)} or
7208 * null if no message has been set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007209 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00007210 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007211 public @Nullable CharSequence getLongSupportMessage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007212 throwIfParentInstance("getLongSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00007213 if (mService != null) {
7214 try {
7215 return mService.getLongSupportMessage(admin);
7216 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007217 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00007218 }
7219 }
7220 return null;
7221 }
7222
7223 /**
7224 * Called by the system to get the short support message.
7225 *
7226 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7227 * @param userHandle user id the admin is running as.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007228 * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)}
Kenny Guy06de4e72015-12-22 12:07:39 +00007229 *
7230 * @hide
7231 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007232 public @Nullable CharSequence getShortSupportMessageForUser(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007233 int userHandle) {
Kenny Guy06de4e72015-12-22 12:07:39 +00007234 if (mService != null) {
7235 try {
7236 return mService.getShortSupportMessageForUser(admin, userHandle);
7237 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007238 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00007239 }
7240 }
7241 return null;
7242 }
7243
7244
7245 /**
7246 * Called by the system to get the long support message.
7247 *
7248 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7249 * @param userHandle user id the admin is running as.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007250 * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)}
Kenny Guy06de4e72015-12-22 12:07:39 +00007251 *
7252 * @hide
7253 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007254 public @Nullable CharSequence getLongSupportMessageForUser(
7255 @NonNull ComponentName admin, int userHandle) {
Kenny Guy06de4e72015-12-22 12:07:39 +00007256 if (mService != null) {
7257 try {
7258 return mService.getLongSupportMessageForUser(admin, userHandle);
7259 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007260 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00007261 }
7262 }
7263 return null;
7264 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00007265
7266 /**
Esteban Talavera62399912016-01-11 15:37:55 +00007267 * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager}
7268 * whose calls act on the parent profile.
Benjamin Franz66b45f02016-04-05 19:12:39 +01007269 *
7270 * <p>The following methods are supported for the parent instance, all other methods will
7271 * throw a SecurityException when called on the parent instance:
7272 * <ul>
7273 * <li>{@link #getPasswordQuality}</li>
7274 * <li>{@link #setPasswordQuality}</li>
7275 * <li>{@link #getPasswordMinimumLength}</li>
7276 * <li>{@link #setPasswordMinimumLength}</li>
7277 * <li>{@link #getPasswordMinimumUpperCase}</li>
7278 * <li>{@link #setPasswordMinimumUpperCase}</li>
7279 * <li>{@link #getPasswordMinimumLowerCase}</li>
7280 * <li>{@link #setPasswordMinimumLowerCase}</li>
7281 * <li>{@link #getPasswordMinimumLetters}</li>
7282 * <li>{@link #setPasswordMinimumLetters}</li>
7283 * <li>{@link #getPasswordMinimumNumeric}</li>
7284 * <li>{@link #setPasswordMinimumNumeric}</li>
7285 * <li>{@link #getPasswordMinimumSymbols}</li>
7286 * <li>{@link #setPasswordMinimumSymbols}</li>
7287 * <li>{@link #getPasswordMinimumNonLetter}</li>
7288 * <li>{@link #setPasswordMinimumNonLetter}</li>
7289 * <li>{@link #getPasswordHistoryLength}</li>
7290 * <li>{@link #setPasswordHistoryLength}</li>
7291 * <li>{@link #getPasswordExpirationTimeout}</li>
7292 * <li>{@link #setPasswordExpirationTimeout}</li>
7293 * <li>{@link #getPasswordExpiration}</li>
Charles He8c760562016-10-25 16:36:53 +01007294 * <li>{@link #getPasswordMaximumLength}</li>
Benjamin Franz66b45f02016-04-05 19:12:39 +01007295 * <li>{@link #isActivePasswordSufficient}</li>
7296 * <li>{@link #getCurrentFailedPasswordAttempts}</li>
7297 * <li>{@link #getMaximumFailedPasswordsForWipe}</li>
7298 * <li>{@link #setMaximumFailedPasswordsForWipe}</li>
7299 * <li>{@link #getMaximumTimeToLock}</li>
7300 * <li>{@link #setMaximumTimeToLock}</li>
7301 * <li>{@link #lockNow}</li>
7302 * <li>{@link #getKeyguardDisabledFeatures}</li>
7303 * <li>{@link #setKeyguardDisabledFeatures}</li>
7304 * <li>{@link #getTrustAgentConfiguration}</li>
7305 * <li>{@link #setTrustAgentConfiguration}</li>
Michal Karpinskia20d8bb2016-11-23 12:09:08 +00007306 * <li>{@link #getRequiredStrongAuthTimeout}</li>
7307 * <li>{@link #setRequiredStrongAuthTimeout}</li>
Benjamin Franz66b45f02016-04-05 19:12:39 +01007308 * </ul>
Clara Bayarri3e826ef2015-12-14 17:51:22 +00007309 *
7310 * @return a new instance of {@link DevicePolicyManager} that acts on the parent profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007311 * @throws SecurityException if {@code admin} is not a profile owner.
Clara Bayarri3e826ef2015-12-14 17:51:22 +00007312 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007313 public @NonNull DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007314 throwIfParentInstance("getParentProfileInstance");
Clara Bayarri3e826ef2015-12-14 17:51:22 +00007315 try {
7316 if (!mService.isManagedProfile(admin)) {
7317 throw new SecurityException("The current user does not have a parent profile.");
7318 }
Jeff Sharkey49ca5292016-05-10 12:54:45 -06007319 return new DevicePolicyManager(mContext, mService, true);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007320 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007321 throw e.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007322 }
7323 }
7324
7325 /**
Esteban Talaverad36dd152016-12-15 08:51:45 +00007326 * Called by device owner to control the security logging feature.
Michal Karpinski6235a942016-03-15 12:07:23 +00007327 *
7328 * <p> Security logs contain various information intended for security auditing purposes.
7329 * See {@link SecurityEvent} for details.
7330 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00007331 * <p><strong>Note:</strong> The device owner won't be able to retrieve security logs if there
7332 * are unaffiliated secondary users or profiles on the device, regardless of whether the
7333 * feature is enabled. Logs will be discarded if the internal buffer fills up while waiting for
7334 * all users to become affiliated. Therefore it's recommended that affiliation ids are set for
7335 * new users as soon as possible after provisioning via {@link #setAffiliationIds}.
Michal Karpinskib58e4962016-03-01 14:55:10 +00007336 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007337 * @param admin Which device owner this request is associated with.
Michal Karpinski6235a942016-03-15 12:07:23 +00007338 * @param enabled whether security logging should be enabled or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007339 * @throws SecurityException if {@code admin} is not a device owner.
Michal Karpinski6235a942016-03-15 12:07:23 +00007340 * @see #retrieveSecurityLogs
7341 */
7342 public void setSecurityLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007343 throwIfParentInstance("setSecurityLoggingEnabled");
Michal Karpinski6235a942016-03-15 12:07:23 +00007344 try {
7345 mService.setSecurityLoggingEnabled(admin, enabled);
7346 } catch (RemoteException re) {
7347 throw re.rethrowFromSystemServer();
7348 }
7349 }
7350
7351 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00007352 * Return whether security logging is enabled or not by the device owner.
7353 *
7354 * <p>Can only be called by the device owner, otherwise a {@link SecurityException} will be
7355 * thrown.
7356 *
7357 * @param admin Which device owner this request is associated with.
7358 * @return {@code true} if security logging is enabled by device owner, {@code false} otherwise.
7359 * @throws SecurityException if {@code admin} is not a device owner.
7360 */
Bartosz Fabianowski0ec00002017-03-24 14:22:24 +01007361 public boolean isSecurityLoggingEnabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007362 throwIfParentInstance("isSecurityLoggingEnabled");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007363 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00007364 return mService.isSecurityLoggingEnabled(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007365 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007366 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007367 }
7368 }
7369
7370 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00007371 * Called by device owner to retrieve all new security logging entries since the last call to
7372 * this API after device boots.
7373 *
7374 * <p> Access to the logs is rate limited and it will only return new logs after the device
7375 * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}.
7376 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00007377 * <p>If there is any other user or profile on the device, it must be affiliated with the
7378 * device owner. Otherwise a {@link SecurityException} will be thrown. See
7379 * {@link #setAffiliationIds}
Michal Karpinskib58e4962016-03-01 14:55:10 +00007380 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007381 * @param admin Which device owner this request is associated with.
Michal Karpinski6235a942016-03-15 12:07:23 +00007382 * @return the new batch of security logs which is a list of {@link SecurityEvent},
7383 * or {@code null} if rate limitation is exceeded or if logging is currently disabled.
Esteban Talaverad36dd152016-12-15 08:51:45 +00007384 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
7385 * profile or secondary user that is not affiliated with the device owner user.
7386 * @see DeviceAdminReceiver#onSecurityLogsAvailable
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007387 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007388 public @Nullable List<SecurityEvent> retrieveSecurityLogs(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007389 throwIfParentInstance("retrieveSecurityLogs");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007390 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00007391 ParceledListSlice<SecurityEvent> list = mService.retrieveSecurityLogs(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007392 if (list != null) {
7393 return list.getList();
7394 } else {
7395 // Rate limit exceeded.
7396 return null;
7397 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00007398 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007399 throw re.rethrowFromSystemServer();
Clara Bayarri3e826ef2015-12-14 17:51:22 +00007400 }
7401 }
Benjamin Franz59720bb2016-01-18 15:26:11 +00007402
7403 /**
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00007404 * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent
7405 * profile.
7406 *
7407 * @hide
7408 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007409 public @NonNull DevicePolicyManager getParentProfileInstance(UserInfo uInfo) {
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00007410 mContext.checkSelfPermission(
7411 android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS);
7412 if (!uInfo.isManagedProfile()) {
7413 throw new SecurityException("The user " + uInfo.id
7414 + " does not have a parent profile.");
7415 }
Jeff Sharkey49ca5292016-05-10 12:54:45 -06007416 return new DevicePolicyManager(mContext, mService, true);
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00007417 }
7418
7419 /**
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007420 * Called by device owners to retrieve device logs from before the device's last reboot.
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007421 * <p>
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01007422 * <strong> This API is not supported on all devices. Calling this API on unsupported devices
7423 * will result in {@code null} being returned. The device logs are retrieved from a RAM region
7424 * which is not guaranteed to be corruption-free during power cycles, as a result be cautious
7425 * about data corruption when parsing. </strong>
Esteban Talaverad36dd152016-12-15 08:51:45 +00007426 *
7427 * <p>If there is any other user or profile on the device, it must be affiliated with the
7428 * device owner. Otherwise a {@link SecurityException} will be thrown. See
7429 * {@link #setAffiliationIds}
Michal Karpinskib58e4962016-03-01 14:55:10 +00007430 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007431 * @param admin Which device owner this request is associated with.
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01007432 * @return Device logs from before the latest reboot of the system, or {@code null} if this API
7433 * is not supported on the device.
Esteban Talaverad36dd152016-12-15 08:51:45 +00007434 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
7435 * profile or secondary user that is not affiliated with the device owner user.
7436 * @see #retrieveSecurityLogs
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007437 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007438 public @Nullable List<SecurityEvent> retrievePreRebootSecurityLogs(
7439 @NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007440 throwIfParentInstance("retrievePreRebootSecurityLogs");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007441 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00007442 ParceledListSlice<SecurityEvent> list = mService.retrievePreRebootSecurityLogs(admin);
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01007443 if (list != null) {
7444 return list.getList();
7445 } else {
7446 return null;
7447 }
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007448 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007449 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007450 }
7451 }
7452
7453 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007454 * Called by a profile owner of a managed profile to set the color used for customization. This
7455 * color is used as background color of the confirm credentials screen for that user. The
Clara Bayarri8d0bd7fa2016-03-30 14:59:58 +01007456 * default color is teal (#00796B).
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007457 * <p>
7458 * The confirm credentials screen can be created using
Benjamin Franz59720bb2016-01-18 15:26:11 +00007459 * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}.
7460 *
7461 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinski74cd7302016-04-12 15:17:36 +01007462 * @param color The 24bit (0xRRGGBB) representation of the color to be used.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007463 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz59720bb2016-01-18 15:26:11 +00007464 */
7465 public void setOrganizationColor(@NonNull ComponentName admin, int color) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007466 throwIfParentInstance("setOrganizationColor");
Benjamin Franz59720bb2016-01-18 15:26:11 +00007467 try {
Michal Karpinski74cd7302016-04-12 15:17:36 +01007468 // always enforce alpha channel to have 100% opacity
7469 color |= 0xFF000000;
Benjamin Franz59720bb2016-01-18 15:26:11 +00007470 mService.setOrganizationColor(admin, color);
7471 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007472 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00007473 }
7474 }
7475
7476 /**
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00007477 * @hide
7478 *
7479 * Sets the color used for customization.
7480 *
Michal Karpinski74cd7302016-04-12 15:17:36 +01007481 * @param color The 24bit (0xRRGGBB) representation of the color to be used.
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00007482 * @param userId which user to set the color to.
7483 * @RequiresPermission(allOf = {
7484 * Manifest.permission.MANAGE_USERS,
7485 * Manifest.permission.INTERACT_ACROSS_USERS_FULL})
7486 */
7487 public void setOrganizationColorForUser(@ColorInt int color, @UserIdInt int userId) {
7488 try {
Michal Karpinski74cd7302016-04-12 15:17:36 +01007489 // always enforce alpha channel to have 100% opacity
7490 color |= 0xFF000000;
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00007491 mService.setOrganizationColorForUser(color, userId);
7492 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007493 throw re.rethrowFromSystemServer();
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00007494 }
7495 }
7496
7497 /**
Benjamin Franz59720bb2016-01-18 15:26:11 +00007498 * Called by a profile owner of a managed profile to retrieve the color used for customization.
7499 * This color is used as background color of the confirm credentials screen for that user.
7500 *
7501 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinski74cd7302016-04-12 15:17:36 +01007502 * @return The 24bit (0xRRGGBB) representation of the color to be used.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007503 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz59720bb2016-01-18 15:26:11 +00007504 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01007505 public @ColorInt int getOrganizationColor(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007506 throwIfParentInstance("getOrganizationColor");
Benjamin Franz59720bb2016-01-18 15:26:11 +00007507 try {
7508 return mService.getOrganizationColor(admin);
7509 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007510 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00007511 }
7512 }
7513
7514 /**
7515 * @hide
7516 * Retrieve the customization color for a given user.
7517 *
7518 * @param userHandle The user id of the user we're interested in.
Michal Karpinski74cd7302016-04-12 15:17:36 +01007519 * @return The 24bit (0xRRGGBB) representation of the color to be used.
Benjamin Franz59720bb2016-01-18 15:26:11 +00007520 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01007521 public @ColorInt int getOrganizationColorForUser(int userHandle) {
Benjamin Franz59720bb2016-01-18 15:26:11 +00007522 try {
7523 return mService.getOrganizationColorForUser(userHandle);
7524 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007525 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00007526 }
7527 }
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007528
7529 /**
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01007530 * Called by the device owner or profile owner to set the name of the organization under
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007531 * management.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007532 * <p>
7533 * If the organization name needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007534 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
7535 * and set a new version of this string accordingly.
7536 *
7537 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7538 * @param title The organization name or {@code null} to clear a previously set name.
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01007539 * @throws SecurityException if {@code admin} is not a device or profile owner.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007540 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01007541 public void setOrganizationName(@NonNull ComponentName admin, @Nullable CharSequence title) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007542 throwIfParentInstance("setOrganizationName");
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007543 try {
7544 mService.setOrganizationName(admin, title);
7545 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007546 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007547 }
7548 }
7549
7550 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007551 * Called by a profile owner of a managed profile to retrieve the name of the organization under
7552 * management.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007553 *
7554 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7555 * @return The organization name or {@code null} if none is set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007556 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007557 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007558 public @Nullable CharSequence getOrganizationName(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007559 throwIfParentInstance("getOrganizationName");
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007560 try {
7561 return mService.getOrganizationName(admin);
7562 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007563 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007564 }
7565 }
7566
7567 /**
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01007568 * Called by the system to retrieve the name of the organization managing the device.
7569 *
7570 * @return The organization name or {@code null} if none is set.
7571 * @throws SecurityException if the caller is not the device owner, does not hold the
7572 * MANAGE_USERS permission and is not the system.
7573 *
7574 * @hide
7575 */
7576 @SystemApi
7577 @TestApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06007578 @SuppressLint("Doclava125")
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01007579 public @Nullable CharSequence getDeviceOwnerOrganizationName() {
7580 try {
7581 return mService.getDeviceOwnerOrganizationName();
7582 } catch (RemoteException re) {
7583 throw re.rethrowFromSystemServer();
7584 }
7585 }
7586
7587 /**
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007588 * Retrieve the default title message used in the confirm credentials screen for a given user.
7589 *
7590 * @param userHandle The user id of the user we're interested in.
7591 * @return The organization name or {@code null} if none is set.
7592 *
7593 * @hide
7594 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007595 public @Nullable CharSequence getOrganizationNameForUser(int userHandle) {
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007596 try {
7597 return mService.getOrganizationNameForUser(userHandle);
7598 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007599 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007600 }
7601 }
7602
7603 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00007604 * @return the {@link UserProvisioningState} for the current user - for unmanaged users will
7605 * return {@link #STATE_USER_UNMANAGED}
7606 * @hide
7607 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00007608 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00007609 @UserProvisioningState
7610 public int getUserProvisioningState() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007611 throwIfParentInstance("getUserProvisioningState");
Alan Treadwayafad8782016-01-19 15:15:08 +00007612 if (mService != null) {
7613 try {
7614 return mService.getUserProvisioningState();
7615 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007616 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00007617 }
7618 }
7619 return STATE_USER_UNMANAGED;
7620 }
7621
7622 /**
7623 * Set the {@link UserProvisioningState} for the supplied user, if they are managed.
7624 *
7625 * @param state to store
7626 * @param userHandle for user
7627 * @hide
7628 */
7629 public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) {
7630 if (mService != null) {
7631 try {
7632 mService.setUserProvisioningState(state, userHandle);
7633 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007634 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00007635 }
7636 }
7637 }
7638
7639 /**
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007640 * Indicates the entity that controls the device or profile owner. Two users/profiles are
7641 * affiliated if the set of ids set by their device or profile owners intersect.
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007642 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00007643 * <p><strong>Note:</strong> Features that depend on user affiliation (such as security logging
7644 * or {@link #bindDeviceAdminServiceAsUser}) won't be available when a secondary user or profile
7645 * is created, until it becomes affiliated. Therefore it is recommended that the appropriate
7646 * affiliation ids are set by its profile owner as soon as possible after the user/profile is
7647 * created.
7648 *
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007649 * @param admin Which profile or device owner this request is associated with.
Tony Mak31657432017-04-25 09:29:55 +01007650 * @param ids A set of opaque non-empty affiliation ids.
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007651 *
Tony Mak31657432017-04-25 09:29:55 +01007652 * @throws IllegalArgumentException if {@code ids} is null or contains an empty string.
7653 */
7654 public void setAffiliationIds(@NonNull ComponentName admin, @NonNull Set<String> ids) {
7655 throwIfParentInstance("setAffiliationIds");
7656 if (ids == null) {
7657 throw new IllegalArgumentException("ids must not be null");
7658 }
7659 try {
7660 mService.setAffiliationIds(admin, new ArrayList<>(ids));
7661 } catch (RemoteException e) {
7662 throw e.rethrowFromSystemServer();
7663 }
7664 }
7665
7666 /**
Tony Mak31657432017-04-25 09:29:55 +01007667 * Returns the set of affiliation ids previously set via {@link #setAffiliationIds}, or an
7668 * empty set if none have been set.
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007669 */
Tony Mak31657432017-04-25 09:29:55 +01007670 public @NonNull Set<String> getAffiliationIds(@NonNull ComponentName admin) {
Tony Mak62cf5862017-05-02 13:50:18 +01007671 throwIfParentInstance("getAffiliationIds");
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007672 try {
Tony Mak31657432017-04-25 09:29:55 +01007673 return new ArraySet<>(mService.getAffiliationIds(admin));
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007674 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007675 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007676 }
7677 }
7678
7679 /**
7680 * @hide
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007681 * Returns whether this user/profile is affiliated with the device.
7682 * <p>
7683 * By definition, the user that the device owner runs on is always affiliated with the device.
7684 * Any other user/profile is considered affiliated with the device if the set specified by its
7685 * profile owner via {@link #setAffiliationIds} intersects with the device owner's.
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007686 *
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007687 */
7688 public boolean isAffiliatedUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007689 throwIfParentInstance("isAffiliatedUser");
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007690 try {
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007691 return mService.isAffiliatedUser();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007692 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007693 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007694 }
7695 }
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08007696
7697 /**
7698 * @hide
7699 * Returns whether the uninstall for {@code packageName} for the current user is in queue
7700 * to be started
7701 * @param packageName the package to check for
7702 * @return whether the uninstall intent for {@code packageName} is pending
7703 */
7704 public boolean isUninstallInQueue(String packageName) {
7705 try {
7706 return mService.isUninstallInQueue(packageName);
7707 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007708 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08007709 }
7710 }
7711
7712 /**
7713 * @hide
7714 * @param packageName the package containing active DAs to be uninstalled
7715 */
7716 public void uninstallPackageWithActiveAdmins(String packageName) {
7717 try {
7718 mService.uninstallPackageWithActiveAdmins(packageName);
7719 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007720 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08007721 }
7722 }
Benjamin Franzbc33c822016-04-15 08:57:52 +01007723
Kenny Guy38dcca52016-04-19 13:09:18 +01007724 /**
7725 * @hide
7726 * Remove a test admin synchronously without sending it a broadcast about being removed.
7727 * If the admin is a profile owner or device owner it will still be removed.
7728 *
7729 * @param userHandle user id to remove the admin for.
7730 * @param admin The administration compononent to remove.
7731 * @throws SecurityException if the caller is not shell / root or the admin package
7732 * isn't a test application see {@link ApplicationInfo#FLAG_TEST_APP}.
7733 */
7734 public void forceRemoveActiveAdmin(ComponentName adminReceiver, int userHandle) {
7735 try {
7736 mService.forceRemoveActiveAdmin(adminReceiver, userHandle);
7737 } catch (RemoteException re) {
7738 throw re.rethrowFromSystemServer();
7739 }
7740 }
7741
Mahaver Chopra790d1982016-07-07 16:06:49 +01007742 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007743 * Returns whether the device has been provisioned.
7744 *
7745 * <p>Not for use by third-party applications.
7746 *
Mahaver Chopra790d1982016-07-07 16:06:49 +01007747 * @hide
Mahaver Chopra790d1982016-07-07 16:06:49 +01007748 */
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007749 @SystemApi
Mahaver Chopra790d1982016-07-07 16:06:49 +01007750 public boolean isDeviceProvisioned() {
7751 try {
7752 return mService.isDeviceProvisioned();
7753 } catch (RemoteException re) {
7754 throw re.rethrowFromSystemServer();
7755 }
7756 }
7757
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007758 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007759 * Writes that the provisioning configuration has been applied.
7760 *
7761 * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS}
7762 * permission.
7763 *
7764 * <p>Not for use by third-party applications.
7765 *
7766 * @hide
7767 */
7768 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06007769 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007770 public void setDeviceProvisioningConfigApplied() {
7771 try {
7772 mService.setDeviceProvisioningConfigApplied();
7773 } catch (RemoteException re) {
7774 throw re.rethrowFromSystemServer();
7775 }
7776 }
7777
7778 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007779 * Returns whether the provisioning configuration has been applied.
7780 *
7781 * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS} permission.
7782 *
7783 * <p>Not for use by third-party applications.
7784 *
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007785 * @return whether the provisioning configuration has been applied.
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007786 *
7787 * @hide
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007788 */
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007789 @SystemApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06007790 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007791 public boolean isDeviceProvisioningConfigApplied() {
7792 try {
7793 return mService.isDeviceProvisioningConfigApplied();
7794 } catch (RemoteException re) {
7795 throw re.rethrowFromSystemServer();
7796 }
7797 }
7798
Victor Chang9bfc65f2016-08-15 12:27:09 +01007799 /**
7800 * @hide
Victor Chang3577ed22016-08-25 18:49:26 +01007801 * Force update user setup completed status. This API has no effect on user build.
7802 * @throws {@link SecurityException} if the caller has no
Esteban Talavera01576862016-12-15 11:16:44 +00007803 * {@code android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS} or the caller is
7804 * not {@link UserHandle#SYSTEM_USER}
Victor Chang9bfc65f2016-08-15 12:27:09 +01007805 */
7806 public void forceUpdateUserSetupComplete() {
7807 try {
7808 mService.forceUpdateUserSetupComplete();
7809 } catch (RemoteException re) {
7810 throw re.rethrowFromSystemServer();
7811 }
7812 }
7813
Benjamin Franzbc33c822016-04-15 08:57:52 +01007814 private void throwIfParentInstance(String functionName) {
7815 if (mParentInstance) {
7816 throw new SecurityException(functionName + " cannot be called on the parent instance");
7817 }
7818 }
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007819
7820 /**
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007821 * Allows the device owner to enable or disable the backup service.
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007822 *
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007823 * <p> Backup service manages all backup and restore mechanisms on the device. Setting this to
7824 * false will prevent data from being backed up or restored.
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007825 *
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007826 * <p> Backup service is off by default when device owner is present.
7827 *
Rubin Xu0367f072017-04-24 20:17:16 +01007828 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7829 * @param enabled {@code true} to enable the backup service, {@code false} to disable it.
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007830 * @throws SecurityException if {@code admin} is not a device owner.
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007831 */
7832 public void setBackupServiceEnabled(@NonNull ComponentName admin, boolean enabled) {
Esteban Talavera5b7f2d02017-02-17 09:45:24 +00007833 throwIfParentInstance("setBackupServiceEnabled");
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007834 try {
7835 mService.setBackupServiceEnabled(admin, enabled);
7836 } catch (RemoteException re) {
7837 throw re.rethrowFromSystemServer();
7838 }
7839 }
7840
7841 /**
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007842 * Return whether the backup service is enabled by the device owner.
7843 *
7844 * <p> Backup service manages all backup and restore mechanisms on the device.
7845 *
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007846 * @return {@code true} if backup service is enabled, {@code false} otherwise.
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007847 * @see #setBackupServiceEnabled
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007848 */
7849 public boolean isBackupServiceEnabled(@NonNull ComponentName admin) {
Esteban Talavera5b7f2d02017-02-17 09:45:24 +00007850 throwIfParentInstance("isBackupServiceEnabled");
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007851 try {
7852 return mService.isBackupServiceEnabled(admin);
7853 } catch (RemoteException re) {
7854 throw re.rethrowFromSystemServer();
7855 }
7856 }
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007857
7858 /**
Esteban Talaverad36dd152016-12-15 08:51:45 +00007859 * Called by a device owner to control the network logging feature.
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007860 *
Robin Leea40a2fb2017-02-08 17:07:06 +00007861 * <p> Network logs contain DNS lookup and connect() library call events. The following library
7862 * functions are recorded while network logging is active:
7863 * <ul>
7864 * <li>{@code getaddrinfo()}</li>
7865 * <li>{@code gethostbyname()}</li>
7866 * <li>{@code connect()}</li>
7867 * </ul>
7868 *
7869 * <p> Network logging is a low-overhead tool for forensics but it is not guaranteed to use
7870 * full system call logging; event reporting is enabled by default for all processes but not
7871 * strongly enforced.
7872 * Events from applications using alternative implementations of libc, making direct kernel
7873 * calls, or deliberately obfuscating traffic may not be recorded.
7874 *
7875 * <p> Some common network events may not be reported. For example:
7876 * <ul>
7877 * <li>Applications may hardcode IP addresses to reduce the number of DNS lookups, or use
7878 * an alternative system for name resolution, and so avoid calling
7879 * {@code getaddrinfo()} or {@code gethostbyname}.</li>
7880 * <li>Applications may use datagram sockets for performance reasons, for example
7881 * for a game client. Calling {@code connect()} is unnecessary for this kind of
7882 * socket, so it will not trigger a network event.</li>
7883 * </ul>
7884 *
7885 * <p> It is possible to directly intercept layer 3 traffic leaving the device using an
7886 * always-on VPN service.
7887 * See {@link #setAlwaysOnVpnPackage(ComponentName, String, boolean)}
7888 * and {@link android.net.VpnService} for details.
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007889 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00007890 * <p><strong>Note:</strong> The device owner won't be able to retrieve network logs if there
7891 * are unaffiliated secondary users or profiles on the device, regardless of whether the
7892 * feature is enabled. Logs will be discarded if the internal buffer fills up while waiting for
7893 * all users to become affiliated. Therefore it's recommended that affiliation ids are set for
7894 * new users as soon as possible after provisioning via {@link #setAffiliationIds}.
7895 *
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007896 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7897 * @param enabled whether network logging should be enabled or not.
Esteban Talaverad36dd152016-12-15 08:51:45 +00007898 * @throws SecurityException if {@code admin} is not a device owner.
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007899 * @see #retrieveNetworkLogs
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007900 */
7901 public void setNetworkLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
7902 throwIfParentInstance("setNetworkLoggingEnabled");
7903 try {
7904 mService.setNetworkLoggingEnabled(admin, enabled);
7905 } catch (RemoteException re) {
7906 throw re.rethrowFromSystemServer();
7907 }
7908 }
7909
7910 /**
7911 * Return whether network logging is enabled by a device owner.
7912 *
phweissa4e169e2016-11-24 16:20:57 +01007913 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Can only
7914 * be {@code null} if the caller has MANAGE_USERS permission.
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007915 * @return {@code true} if network logging is enabled by device owner, {@code false} otherwise.
Esteban Talaverad36dd152016-12-15 08:51:45 +00007916 * @throws SecurityException if {@code admin} is not a device owner and caller has
phweissa4e169e2016-11-24 16:20:57 +01007917 * no MANAGE_USERS permission
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007918 */
phweissa4e169e2016-11-24 16:20:57 +01007919 public boolean isNetworkLoggingEnabled(@Nullable ComponentName admin) {
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007920 throwIfParentInstance("isNetworkLoggingEnabled");
7921 try {
7922 return mService.isNetworkLoggingEnabled(admin);
7923 } catch (RemoteException re) {
7924 throw re.rethrowFromSystemServer();
7925 }
7926 }
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007927
7928 /**
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007929 * Called by device owner to retrieve the most recent batch of network logging events.
7930 * A device owner has to provide a batchToken provided as part of
7931 * {@link DeviceAdminReceiver#onNetworkLogsAvailable} callback. If the token doesn't match the
7932 * token of the most recent available batch of logs, {@code null} will be returned.
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007933 *
7934 * <p> {@link NetworkEvent} can be one of {@link DnsEvent} or {@link ConnectEvent}.
7935 *
7936 * <p> The list of network events is sorted chronologically, and contains at most 1200 events.
7937 *
7938 * <p> Access to the logs is rate limited and this method will only return a new batch of logs
7939 * after the device device owner has been notified via
7940 * {@link DeviceAdminReceiver#onNetworkLogsAvailable}.
7941 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00007942 * <p>If a secondary user or profile is created, calling this method will throw a
7943 * {@link SecurityException} until all users become affiliated again. It will also no longer be
7944 * possible to retrieve the network logs batch with the most recent batchToken provided
7945 * by {@link DeviceAdminReceiver#onNetworkLogsAvailable}. See
7946 * {@link DevicePolicyManager#setAffiliationIds}.
7947 *
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007948 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007949 * @param batchToken A token of the batch to retrieve
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007950 * @return A new batch of network logs which is a list of {@link NetworkEvent}. Returns
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007951 * {@code null} if the batch represented by batchToken is no longer available or if
7952 * logging is disabled.
Esteban Talaverad36dd152016-12-15 08:51:45 +00007953 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
7954 * profile or secondary user that is not affiliated with the device owner user.
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007955 * @see DeviceAdminReceiver#onNetworkLogsAvailable
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007956 */
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007957 public @Nullable List<NetworkEvent> retrieveNetworkLogs(@NonNull ComponentName admin,
7958 long batchToken) {
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007959 throwIfParentInstance("retrieveNetworkLogs");
7960 try {
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007961 return mService.retrieveNetworkLogs(admin, batchToken);
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007962 } catch (RemoteException re) {
7963 throw re.rethrowFromSystemServer();
7964 }
7965 }
Tony Mak46aabe52016-11-14 12:53:06 +00007966
7967 /**
Esteban Talavera2f897912017-01-26 10:30:48 +00007968 * Called by a device owner to bind to a service from a profile owner or vice versa.
7969 * See {@link #getBindDeviceAdminTargetUsers} for a definition of which
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007970 * device/profile owners are allowed to bind to services of another profile/device owner.
7971 * <p>
Tony Makeda0a9a2017-04-25 12:07:14 +01007972 * The service must be protected by {@link android.Manifest.permission#BIND_DEVICE_ADMIN}.
7973 * Note that the {@link Context} used to obtain this
Tony Mak46aabe52016-11-14 12:53:06 +00007974 * {@link DevicePolicyManager} instance via {@link Context#getSystemService(Class)} will be used
7975 * to bind to the {@link android.app.Service}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007976 *
Tony Mak46aabe52016-11-14 12:53:06 +00007977 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7978 * @param serviceIntent Identifies the service to connect to. The Intent must specify either an
7979 * explicit component name or a package name to match an
7980 * {@link IntentFilter} published by a service.
Tony Makbf9928d2016-12-22 11:02:45 +00007981 * @param conn Receives information as the service is started and stopped in main thread. This
7982 * must be a valid {@link ServiceConnection} object; it must not be {@code null}.
Tony Mak46aabe52016-11-14 12:53:06 +00007983 * @param flags Operation options for the binding operation. See
7984 * {@link Context#bindService(Intent, ServiceConnection, int)}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007985 * @param targetUser Which user to bind to. Must be one of the users returned by
7986 * {@link #getBindDeviceAdminTargetUsers}, otherwise a {@link SecurityException} will
7987 * be thrown.
Tony Mak46aabe52016-11-14 12:53:06 +00007988 * @return If you have successfully bound to the service, {@code true} is returned;
7989 * {@code false} is returned if the connection is not made and you will not
7990 * receive the service object.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007991 *
Tony Mak46aabe52016-11-14 12:53:06 +00007992 * @see Context#bindService(Intent, ServiceConnection, int)
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007993 * @see #getBindDeviceAdminTargetUsers(ComponentName)
Tony Mak46aabe52016-11-14 12:53:06 +00007994 */
7995 public boolean bindDeviceAdminServiceAsUser(
7996 @NonNull ComponentName admin, Intent serviceIntent, @NonNull ServiceConnection conn,
7997 @Context.BindServiceFlags int flags, @NonNull UserHandle targetUser) {
7998 throwIfParentInstance("bindDeviceAdminServiceAsUser");
7999 // Keep this in sync with ContextImpl.bindServiceCommon.
8000 try {
Tony Makbf9928d2016-12-22 11:02:45 +00008001 final IServiceConnection sd = mContext.getServiceDispatcher(
8002 conn, mContext.getMainThreadHandler(), flags);
Tony Mak46aabe52016-11-14 12:53:06 +00008003 serviceIntent.prepareToLeaveProcess(mContext);
8004 return mService.bindDeviceAdminServiceAsUser(admin,
8005 mContext.getIApplicationThread(), mContext.getActivityToken(), serviceIntent,
8006 sd, flags, targetUser.getIdentifier());
8007 } catch (RemoteException re) {
8008 throw re.rethrowFromSystemServer();
8009 }
8010 }
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01008011
8012 /**
Esteban Talaverafc291bc2016-11-21 13:52:03 +00008013 * Returns the list of target users that the calling device or profile owner can use when
8014 * calling {@link #bindDeviceAdminServiceAsUser}.
8015 * <p>
Esteban Talavera2f897912017-01-26 10:30:48 +00008016 * A device owner can bind to a service from a profile owner and vice versa, provided that:
Esteban Talaverafc291bc2016-11-21 13:52:03 +00008017 * <ul>
8018 * <li>Both belong to the same package name.
Esteban Talavera2f897912017-01-26 10:30:48 +00008019 * <li>Both users are affiliated. See {@link #setAffiliationIds}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00008020 * </ul>
8021 */
8022 public @NonNull List<UserHandle> getBindDeviceAdminTargetUsers(@NonNull ComponentName admin) {
8023 throwIfParentInstance("getBindDeviceAdminTargetUsers");
8024 try {
8025 return mService.getBindDeviceAdminTargetUsers(admin);
8026 } catch (RemoteException re) {
8027 throw re.rethrowFromSystemServer();
8028 }
8029 }
8030
8031 /**
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01008032 * Called by the system to get the time at which the device owner last retrieved security
8033 * logging entries.
8034 *
8035 * @return the time at which the device owner most recently retrieved security logging entries,
8036 * in milliseconds since epoch; -1 if security logging entries were never retrieved.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01008037 * @throws SecurityException if the caller is not the device owner, does not hold the
8038 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01008039 *
8040 * @hide
8041 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01008042 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01008043 public long getLastSecurityLogRetrievalTime() {
8044 try {
8045 return mService.getLastSecurityLogRetrievalTime();
8046 } catch (RemoteException re) {
8047 throw re.rethrowFromSystemServer();
8048 }
8049 }
8050
8051 /**
8052 * Called by the system to get the time at which the device owner last requested a bug report.
8053 *
8054 * @return the time at which the device owner most recently requested a bug report, in
8055 * milliseconds since epoch; -1 if a bug report was never requested.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01008056 * @throws SecurityException if the caller is not the device owner, does not hold the
8057 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01008058 *
8059 * @hide
8060 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01008061 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01008062 public long getLastBugReportRequestTime() {
8063 try {
8064 return mService.getLastBugReportRequestTime();
8065 } catch (RemoteException re) {
8066 throw re.rethrowFromSystemServer();
8067 }
8068 }
8069
8070 /**
8071 * Called by the system to get the time at which the device owner last retrieved network logging
8072 * events.
8073 *
8074 * @return the time at which the device owner most recently retrieved network logging events, in
8075 * milliseconds since epoch; -1 if network logging events were never retrieved.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01008076 * @throws SecurityException if the caller is not the device owner, does not hold the
8077 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01008078 *
8079 * @hide
8080 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01008081 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01008082 public long getLastNetworkLogRetrievalTime() {
8083 try {
8084 return mService.getLastNetworkLogRetrievalTime();
8085 } catch (RemoteException re) {
8086 throw re.rethrowFromSystemServer();
8087 }
8088 }
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01008089
8090 /**
Bartosz Fabianowski172f7802017-03-06 12:07:57 +01008091 * Called by the system to find out whether the current user's IME was set by the device/profile
8092 * owner or the user.
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01008093 *
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01008094 * @return {@code true} if the user's IME was set by the device or profile owner, {@code false}
8095 * otherwise.
Bartosz Fabianowski172f7802017-03-06 12:07:57 +01008096 * @throws SecurityException if the caller is not the device owner/profile owner.
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01008097 *
8098 * @hide
8099 */
8100 @TestApi
Bartosz Fabianowski172f7802017-03-06 12:07:57 +01008101 public boolean isCurrentInputMethodSetByOwner() {
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01008102 try {
Bartosz Fabianowski172f7802017-03-06 12:07:57 +01008103 return mService.isCurrentInputMethodSetByOwner();
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01008104 } catch (RemoteException re) {
8105 throw re.rethrowFromSystemServer();
8106 }
8107 }
Bartosz Fabianowski05dc9f72017-02-22 23:41:14 +01008108
Bartosz Fabianowski05dc9f72017-02-22 23:41:14 +01008109 /**
8110 * Called by the system to get a list of CA certificates that were installed by the device or
8111 * profile owner.
8112 *
Bartosz Fabianowski172f7802017-03-06 12:07:57 +01008113 * <p> The caller must be the target user's device owner/profile Owner or hold the
Bartosz Fabianowski05dc9f72017-02-22 23:41:14 +01008114 * {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} permission.
8115 *
8116 * @param user The user for whom to retrieve information.
8117 * @return list of aliases identifying CA certificates installed by the device or profile owner
8118 * @throws SecurityException if the caller does not have permission to retrieve information
8119 * about the given user's CA certificates.
8120 *
8121 * @hide
8122 */
8123 @TestApi
8124 public List<String> getOwnerInstalledCaCerts(@NonNull UserHandle user) {
8125 try {
8126 return mService.getOwnerInstalledCaCerts(user).getList();
8127 } catch (RemoteException re) {
8128 throw re.rethrowFromSystemServer();
8129 }
8130 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08008131}