blob: 833af1b538d09adb691a08283bceb9703fc9512d [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;
Benjamin Franza77e3572017-06-23 12:01:44 +010042import android.content.pm.IPackageDataObserver;
Dianne Hackbornd6847842010-01-12 18:14:19 -080043import android.content.pm.PackageManager;
Victor Changcd14c0a2016-03-16 19:10:15 +000044import android.content.pm.PackageManager.NameNotFoundException;
Rubin Xuc3cd05f2016-01-11 12:11:35 +000045import android.content.pm.ParceledListSlice;
Sudheer Shanka978fc0d2016-01-28 13:51:10 +000046import android.content.pm.UserInfo;
Julia Reynoldsfca04ca2015-02-17 13:39:12 -050047import android.graphics.Bitmap;
Jason Monk03bc9912014-05-13 09:44:57 -040048import android.net.ProxyInfo;
Nicolas Prevot8b7991c2015-11-12 17:40:12 +000049import android.net.Uri;
Robin Lee66e5d962014-04-09 16:44:21 +010050import android.os.Bundle;
Benjamin Franza77e3572017-06-23 12:01:44 +010051import android.os.Handler;
Victor Changc10f6692016-12-09 15:24:00 +000052import android.os.Parcelable;
Jim Millere303bf42014-08-26 17:12:29 -070053import android.os.PersistableBundle;
Adam Connors776c5552014-01-09 10:42:56 +000054import android.os.Process;
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080055import android.os.RemoteCallback;
Dianne Hackbornd6847842010-01-12 18:14:19 -080056import android.os.RemoteException;
Amith Yamasani599dd7c2012-09-14 23:20:08 -070057import android.os.UserHandle;
Julia Reynolds1e958392014-05-16 14:25:21 -040058import android.os.UserManager;
Ricky Wai494b95d2015-11-20 16:07:15 +000059import android.provider.ContactsContract.Directory;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010060import android.security.Credentials;
Amith Yamasanid1d7c022014-08-19 17:03:41 -070061import android.service.restrictions.RestrictionsReceiver;
Mahaver Chopra1216ae52016-03-11 15:39:48 +000062import android.telephony.TelephonyManager;
Tony Mak31657432017-04-25 09:29:55 +010063import android.util.ArraySet;
Dianne Hackbornd6847842010-01-12 18:14:19 -080064import android.util.Log;
65
Makoto Onukicc4bbeb2015-09-17 10:28:24 -070066import com.android.internal.annotations.VisibleForTesting;
Maggie Benthallda51e682013-08-08 22:35:44 -040067import com.android.org.conscrypt.TrustedCertificateStore;
68
69import java.io.ByteArrayInputStream;
Dianne Hackbornd6847842010-01-12 18:14:19 -080070import java.io.IOException;
Alan Treadwayafad8782016-01-19 15:15:08 +000071import java.lang.annotation.Retention;
72import java.lang.annotation.RetentionPolicy;
Oscar Montemayor69238c62010-08-03 10:51:06 -070073import java.net.InetSocketAddress;
74import java.net.Proxy;
Robin Lee0d5ccb72014-09-12 17:41:44 +010075import java.security.KeyFactory;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000076import java.security.NoSuchAlgorithmException;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010077import java.security.PrivateKey;
78import java.security.cert.Certificate;
Maggie Benthallda51e682013-08-08 22:35:44 -040079import java.security.cert.CertificateException;
80import java.security.cert.CertificateFactory;
81import java.security.cert.X509Certificate;
Robin Lee0d5ccb72014-09-12 17:41:44 +010082import java.security.spec.InvalidKeySpecException;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000083import java.security.spec.PKCS8EncodedKeySpec;
Jim Miller604e7552014-07-18 19:00:02 -070084import java.util.ArrayList;
Rubin Xub4365912016-03-23 12:13:22 +000085import java.util.Arrays;
Svetoslav976e8bd2014-07-16 15:12:03 -070086import java.util.Collections;
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -080087import java.util.List;
Tony Mak31657432017-04-25 09:29:55 +010088import java.util.Set;
Dianne Hackbornd6847842010-01-12 18:14:19 -080089
90/**
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000091 * Public interface for managing policies enforced on a device. Most clients of this class must be
Suprabh Shukla34d92ef2016-03-14 13:49:37 -070092 * registered with the system as a <a href="{@docRoot}guide/topics/admin/device-admin.html">device
93 * administrator</a>. Additionally, a device administrator may be registered as either a profile or
94 * device owner. A given method is accessible to all device administrators unless the documentation
95 * for that method specifies that it is restricted to either device or profile owners. Any
96 * application calling an api may only pass as an argument a device administrator component it
97 * owns. Otherwise, a {@link SecurityException} will be thrown.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080098 * <div class="special reference">
99 * <h3>Developer Guides</h3>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -0700100 * <p>
101 * For more information about managing policies for device administration, read the <a href=
102 * "{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a> developer
103 * guide. </div>
Dianne Hackbornd6847842010-01-12 18:14:19 -0800104 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -0600105@SystemService(Context.DEVICE_POLICY_SERVICE)
Dianne Hackbornd6847842010-01-12 18:14:19 -0800106public class DevicePolicyManager {
107 private static String TAG = "DevicePolicyManager";
Dianne Hackbornd6847842010-01-12 18:14:19 -0800108
109 private final Context mContext;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800110 private final IDevicePolicyManager mService;
Esteban Talavera62399912016-01-11 15:37:55 +0000111 private final boolean mParentInstance;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700112
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600113 /** @hide */
114 public DevicePolicyManager(Context context, IDevicePolicyManager service) {
115 this(context, service, false);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800116 }
117
Dianne Hackborn87bba1e2010-02-26 17:25:54 -0800118 /** @hide */
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700119 @VisibleForTesting
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600120 protected DevicePolicyManager(Context context, IDevicePolicyManager service,
121 boolean parentInstance) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700122 mContext = context;
123 mService = service;
Esteban Talavera62399912016-01-11 15:37:55 +0000124 mParentInstance = parentInstance;
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700125 }
126
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700127 /** @hide test will override it. */
128 @VisibleForTesting
129 protected int myUserId() {
130 return UserHandle.myUserId();
131 }
132
Dianne Hackbornd6847842010-01-12 18:14:19 -0800133 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +0000134 * Activity action: Starts the provisioning flow which sets up a managed profile.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000135 *
Jessica Hummel9da60392014-05-21 12:32:57 +0100136 * <p>A managed profile allows data separation for example for the usage of a
137 * device as a personal and corporate device. The user which provisioning is started from and
138 * the managed profile share a launcher.
139 *
Andrew Solovay27f53372015-03-02 16:37:59 -0800140 * <p>This intent will typically be sent by a mobile device management application (MDM).
141 * Provisioning adds a managed profile and sets the MDM as the profile owner who has full
142 * control over the profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100143 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000144 * <p>It is possible to check if provisioning is allowed or not by querying the method
145 * {@link #isProvisioningAllowed(String)}.
146 *
147 * <p>In version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this intent must contain the
Nicolas Prevot18440252015-03-09 14:07:17 +0000148 * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700149 * As of {@link android.os.Build.VERSION_CODES#M}, it should contain the extra
Nicolas Prevot18440252015-03-09 14:07:17 +0000150 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only
151 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000152 *
Benjamin Franzea956242016-03-21 15:45:56 +0000153 * <p>The intent may also contain the following extras:
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000154 * <ul>
Benjamin Franzea956242016-03-21 15:45:56 +0000155 * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, optional </li>
156 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional, supported from
157 * {@link android.os.Build.VERSION_CODES#N}</li>
158 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
159 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
160 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Victor Chang51d84f92016-11-16 12:22:56 +0000161 * <li>{@link #EXTRA_PROVISIONING_SKIP_USER_CONSENT}, optional</li>
Victor Chang89ee2792016-11-23 12:10:55 +0000162 * <li>{@link #EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION}, optional</li>
Victor Changc10f6692016-12-09 15:24:00 +0000163 * <li>{@link #EXTRA_PROVISIONING_DISCLAIMERS}, optional</li>
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000164 * </ul>
Jessica Hummelf72078b2014-03-06 16:13:12 +0000165 *
Benjamin Franzea956242016-03-21 15:45:56 +0000166 * <p>When managed provisioning has completed, broadcasts are sent to the application specified
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000167 * in the provisioning intent. The
168 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the
169 * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in
170 * the primary profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100171 *
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000172 * <p>From version {@link android.os.Build.VERSION_CODES#O}, when managed provisioning has
173 * completed, along with the above broadcast, activity intent
Esteban Talavera4047bae2017-06-28 11:03:09 +0100174 * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the profile owner.
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000175 *
Benjamin Franzea956242016-03-21 15:45:56 +0000176 * <p>If provisioning fails, the managedProfile is removed so the device returns to its
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100177 * previous state.
Alan Treadway4582f812015-07-28 11:49:35 +0100178 *
179 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
180 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
181 * the provisioning flow was successful, although this doesn't guarantee the full flow will
182 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
183 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000184 */
185 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
186 public static final String ACTION_PROVISION_MANAGED_PROFILE
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100187 = "android.app.action.PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000188
189 /**
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000190 * Activity action: Starts the provisioning flow which sets up a managed user.
191 *
192 * <p>This intent will typically be sent by a mobile device management application (MDM).
Makoto Onuki32b30572015-12-11 14:29:51 -0800193 * Provisioning configures the user as managed user and sets the MDM as the profile
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000194 * owner who has full control over the user. Provisioning can only happen before user setup has
195 * been completed. Use {@link #isProvisioningAllowed(String)} to check if provisioning is
196 * allowed.
197 *
Benjamin Franzea956242016-03-21 15:45:56 +0000198 * <p>The intent contains the following extras:
199 * <ul>
200 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
201 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
202 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
203 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
204 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
205 * </ul>
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000206 *
Benjamin Franzea956242016-03-21 15:45:56 +0000207 * <p>If provisioning fails, the device returns to its previous state.
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000208 *
209 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
210 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
211 * the provisioning flow was successful, although this doesn't guarantee the full flow will
212 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
213 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Benjamin Franzea956242016-03-21 15:45:56 +0000214 *
215 * @hide
Mahaver Chopra5e732562015-11-05 11:55:12 +0000216 */
217 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
218 public static final String ACTION_PROVISION_MANAGED_USER
219 = "android.app.action.PROVISION_MANAGED_USER";
220
221 /**
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100222 * Activity action: Starts the provisioning flow which sets up a managed device.
223 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
224 *
225 * <p> During device owner provisioning a device admin app is set as the owner of the device.
226 * A device owner has full control over the device. The device owner can not be modified by the
227 * user.
228 *
229 * <p> A typical use case would be a device that is owned by a company, but used by either an
230 * employee or client.
231 *
232 * <p> An intent with this action can be sent only on an unprovisioned device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000233 * It is possible to check if provisioning is allowed or not by querying the method
234 * {@link #isProvisioningAllowed(String)}.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100235 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000236 * <p>The intent contains the following extras:
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100237 * <ul>
238 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
239 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
240 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
Rubin Xua4f9dc12015-06-12 13:27:59 +0100241 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000242 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000243 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Victor Changc10f6692016-12-09 15:24:00 +0000244 * <li>{@link #EXTRA_PROVISIONING_DISCLAIMERS}, optional</li>
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100245 * </ul>
246 *
Benjamin Franzea956242016-03-21 15:45:56 +0000247 * <p>When device owner provisioning has completed, an intent of the type
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100248 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
249 * device owner.
250 *
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000251 * <p>From version {@link android.os.Build.VERSION_CODES#O}, when device owner provisioning has
252 * completed, along with the above broadcast, activity intent
253 * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the device owner.
254 *
Benjamin Franzea956242016-03-21 15:45:56 +0000255 * <p>If provisioning fails, the device is factory reset.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100256 *
Alan Treadway4582f812015-07-28 11:49:35 +0100257 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
258 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
259 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
260 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100261 */
262 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
263 public static final String ACTION_PROVISION_MANAGED_DEVICE
264 = "android.app.action.PROVISION_MANAGED_DEVICE";
265
266 /**
Victor Chang18800092017-04-11 19:41:43 +0100267 * Activity action: launch when user provisioning completed, i.e.
268 * {@link #getUserProvisioningState()} returns one of the complete state.
269 *
270 * <p> Please note that the API behavior is not necessarily consistent across various releases,
271 * and devices, as it's contract between SetupWizard and ManagedProvisioning. The default
272 * implementation is that ManagedProvisioning launches SetupWizard in NFC provisioning only.
273 *
274 * <p> The activity must be protected by permission
275 * {@link android.Manifest.permission#BIND_DEVICE_ADMIN}, and the process must hold
276 * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE} to be launched.
277 * Only one {@link ComponentName} in the entire system should be enabled, and the rest of the
278 * components are not started by this intent.
279 * @hide
280 */
281 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
Jeff Sharkey90396362017-06-12 16:26:53 -0600282 @SystemApi
Victor Chang18800092017-04-11 19:41:43 +0100283 public static final String ACTION_STATE_USER_SETUP_COMPLETE =
284 "android.app.action.STATE_USER_SETUP_COMPLETE";
285
286 /**
Alan Treadway46dd4492015-11-09 13:57:19 +0000287 * Activity action: Starts the provisioning flow which sets up a managed device.
Steven Ng980a1b62016-02-02 17:43:18 +0000288 *
289 * <p>During device owner provisioning, a device admin app is downloaded and set as the owner of
290 * the device. A device owner has full control over the device. The device owner can not be
291 * modified by the user and the only way of resetting the device is via factory reset.
292 *
293 * <p>A typical use case would be a device that is owned by a company, but used by either an
294 * employee or client.
295 *
296 * <p>The provisioning message should be sent to an unprovisioned device.
297 *
298 * <p>Unlike {@link #ACTION_PROVISION_MANAGED_DEVICE}, the provisioning message can only be sent
299 * by a privileged app with the permission
300 * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE}.
301 *
302 * <p>The provisioning intent contains the following properties:
303 * <ul>
304 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
305 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
306 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
307 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Victor Chang38cfd9c2017-01-04 17:41:11 +0000308 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL}, optional</li>
309 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI}, optional</li>
Steven Ng980a1b62016-02-02 17:43:18 +0000310 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
311 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
312 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
313 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
314 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
315 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
316 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
317 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
318 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
319 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
320 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
Victor Chang38cfd9c2017-01-04 17:41:11 +0000321 * <li>{@link #EXTRA_PROVISIONING_SUPPORT_URL}, optional</li>
322 * <li>{@link #EXTRA_PROVISIONING_ORGANIZATION_NAME}, optional</li>
Steven Ng980a1b62016-02-02 17:43:18 +0000323 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li></ul>
324 *
325 * @hide
326 */
327 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
328 @SystemApi
329 public static final String ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE =
330 "android.app.action.PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE";
331
332 /**
333 * Activity action: Starts the provisioning flow which sets up a managed device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000334 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
335 *
336 * <p>NOTE: This is only supported on split system user devices, and puts the device into a
337 * management state that is distinct from that reached by
338 * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system
339 * user, and only has control over device-wide policies, not individual users and their data.
340 * The primary benefit is that multiple non-system users are supported when provisioning using
341 * this form of device management.
342 *
Benjamin Franzea956242016-03-21 15:45:56 +0000343 * <p>During device owner provisioning a device admin app is set as the owner of the device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000344 * A device owner has full control over the device. The device owner can not be modified by the
345 * user.
346 *
Benjamin Franzea956242016-03-21 15:45:56 +0000347 * <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 +0000348 * employee or client.
349 *
Benjamin Franzea956242016-03-21 15:45:56 +0000350 * <p>An intent with this action can be sent only on an unprovisioned device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000351 * It is possible to check if provisioning is allowed or not by querying the method
352 * {@link #isProvisioningAllowed(String)}.
353 *
354 * <p>The intent contains the following extras:
355 * <ul>
356 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
357 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
358 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
359 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Benjamin Franzea956242016-03-21 15:45:56 +0000360 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
361 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Alan Treadway46dd4492015-11-09 13:57:19 +0000362 * </ul>
363 *
Benjamin Franzea956242016-03-21 15:45:56 +0000364 * <p>When device owner provisioning has completed, an intent of the type
Alan Treadway46dd4492015-11-09 13:57:19 +0000365 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
366 * device owner.
367 *
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000368 * <p>From version {@link android.os.Build.VERSION_CODES#O}, when device owner provisioning has
369 * completed, along with the above broadcast, activity intent
370 * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the device owner.
371 *
Benjamin Franzea956242016-03-21 15:45:56 +0000372 * <p>If provisioning fails, the device is factory reset.
Alan Treadway46dd4492015-11-09 13:57:19 +0000373 *
374 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
375 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
376 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
377 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
378 *
379 * @hide
380 */
381 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
382 public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE
383 = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE";
384
385 /**
Alan Treadwayafad8782016-01-19 15:15:08 +0000386 * Activity action: Finalizes management provisioning, should be used after user-setup
387 * has been completed and {@link #getUserProvisioningState()} returns one of:
388 * <ul>
389 * <li>{@link #STATE_USER_SETUP_INCOMPLETE}</li>
390 * <li>{@link #STATE_USER_SETUP_COMPLETE}</li>
391 * <li>{@link #STATE_USER_PROFILE_COMPLETE}</li>
392 * </ul>
393 *
394 * @hide
395 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +0000396 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +0000397 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
398 public static final String ACTION_PROVISION_FINALIZATION
399 = "android.app.action.PROVISION_FINALIZATION";
400
401 /**
Michal Karpinskiba244092016-02-25 17:28:24 +0000402 * Action: Bugreport sharing with device owner has been accepted by the user.
403 *
404 * @hide
405 */
406 public static final String ACTION_BUGREPORT_SHARING_ACCEPTED =
Rubin Xu7226c7d2017-02-06 17:18:50 +0000407 "com.android.server.action.REMOTE_BUGREPORT_SHARING_ACCEPTED";
Michal Karpinskiba244092016-02-25 17:28:24 +0000408
409 /**
410 * Action: Bugreport sharing with device owner has been declined by the user.
411 *
412 * @hide
413 */
414 public static final String ACTION_BUGREPORT_SHARING_DECLINED =
Rubin Xu7226c7d2017-02-06 17:18:50 +0000415 "com.android.server.action.REMOTE_BUGREPORT_SHARING_DECLINED";
Michal Karpinskiba244092016-02-25 17:28:24 +0000416
417 /**
Esteban Talavera01576862016-12-15 11:16:44 +0000418 * Action: Bugreport has been collected and is dispatched to {@code DevicePolicyManagerService}.
Michal Karpinskiba244092016-02-25 17:28:24 +0000419 *
420 * @hide
421 */
422 public static final String ACTION_REMOTE_BUGREPORT_DISPATCH =
423 "android.intent.action.REMOTE_BUGREPORT_DISPATCH";
424
425 /**
426 * Extra for shared bugreport's SHA-256 hash.
427 *
428 * @hide
429 */
430 public static final String EXTRA_REMOTE_BUGREPORT_HASH =
431 "android.intent.extra.REMOTE_BUGREPORT_HASH";
432
433 /**
434 * Extra for remote bugreport notification shown type.
435 *
436 * @hide
437 */
438 public static final String EXTRA_BUGREPORT_NOTIFICATION_TYPE =
439 "android.app.extra.bugreport_notification_type";
440
441 /**
442 * Notification type for a started remote bugreport flow.
443 *
444 * @hide
445 */
446 public static final int NOTIFICATION_BUGREPORT_STARTED = 1;
447
448 /**
449 * Notification type for a bugreport that has already been accepted to be shared, but is still
450 * being taken.
451 *
452 * @hide
453 */
454 public static final int NOTIFICATION_BUGREPORT_ACCEPTED_NOT_FINISHED = 2;
455
456 /**
457 * Notification type for a bugreport that has been taken and can be shared or declined.
458 *
459 * @hide
460 */
461 public static final int NOTIFICATION_BUGREPORT_FINISHED_NOT_ACCEPTED = 3;
462
463 /**
Michal Karpinski8f010dd2016-06-21 15:05:53 +0100464 * Default and maximum timeout in milliseconds after which unlocking with weak auth times out,
465 * i.e. the user has to use a strong authentication method like password, PIN or pattern.
466 *
467 * @hide
468 */
469 public static final long DEFAULT_STRONG_AUTH_TIMEOUT_MS = 72 * 60 * 60 * 1000; // 72h
470
471 /**
Rubin Xua4f9dc12015-06-12 13:27:59 +0100472 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100473 * allows a mobile device management application or NFC programmer application which starts
474 * managed provisioning to pass data to the management application instance after provisioning.
Rubin Xua4f9dc12015-06-12 13:27:59 +0100475 * <p>
476 * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that
477 * sends the intent to pass data to itself on the newly created profile.
478 * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same
479 * instance of the app on the primary user.
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100480 * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with
481 * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC
482 * message should contain a stringified {@link java.util.Properties} instance, whose string
483 * properties will be converted into a {@link android.os.PersistableBundle} and passed to the
484 * management application after provisioning.
485 *
Rubin Xua4f9dc12015-06-12 13:27:59 +0100486 * <p>
487 * In both cases the application receives the data in
Brian Carlstromf1fe51b2014-09-03 08:55:05 -0700488 * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action
489 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed
Rubin Xua4f9dc12015-06-12 13:27:59 +0100490 * during the managed provisioning.
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100491 */
492 public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE =
Esteban Talavera37f01842014-09-05 10:50:57 +0100493 "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE";
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100494
495 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100496 * A String extra holding the package name of the mobile device management application that
497 * will be set as the profile owner or device owner.
498 *
499 * <p>If an application starts provisioning directly via an intent with action
500 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
501 * application that started provisioning. The package will be set as profile owner in that case.
502 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000503 * <p>This package is set as device owner when device owner provisioning is started by an NFC
504 * message containing an NFC record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000505 *
506 * <p> When this extra is set, the application must have exactly one device admin receiver.
Robin Lee25e26452015-06-02 09:56:29 -0700507 * This receiver will be set as the profile or device owner and active admin.
Benjamin Franzea956242016-03-21 15:45:56 +0000508 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000509 * @see DeviceAdminReceiver
510 * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still
Nicolas Prevot8f78d6a2015-08-21 11:06:31 +0100511 * supported, but only if there is only one device admin receiver in the package that requires
512 * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000513 */
Nicolas Prevot18440252015-03-09 14:07:17 +0000514 @Deprecated
Jessica Hummelf72078b2014-03-06 16:13:12 +0000515 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100516 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000517
518 /**
Nicolas Prevot18440252015-03-09 14:07:17 +0000519 * A ComponentName extra indicating the device admin receiver of the mobile device management
520 * application that will be set as the profile owner or device owner and active admin.
521 *
522 * <p>If an application starts provisioning directly via an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100523 * {@link #ACTION_PROVISION_MANAGED_PROFILE} or
524 * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this
525 * component has to match the package name of the application that started provisioning.
Nicolas Prevot18440252015-03-09 14:07:17 +0000526 *
527 * <p>This component is set as device owner and active admin when device owner provisioning is
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100528 * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC
529 * message containing an NFC record with MIME type
Benjamin Franzea956242016-03-21 15:45:56 +0000530 * {@link #MIME_TYPE_PROVISIONING_NFC}. For the NFC record, the component name must be
Rubin Xu44ef750b2015-03-23 16:51:33 +0000531 * flattened to a string, via {@link ComponentName#flattenToShortString()}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000532 *
533 * @see DeviceAdminReceiver
534 */
535 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME
536 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME";
537
538 /**
Alexandra Gherghinaaaf2f3e2014-11-13 12:46:15 +0000539 * An {@link android.accounts.Account} extra holding the account to migrate during managed
540 * profile provisioning. If the account supplied is present in the primary user, it will be
541 * copied, along with its credentials to the managed profile and removed from the primary user.
542 *
543 * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}.
544 */
545
546 public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE
547 = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE";
548
549 /**
Victor Changaa9cbc02016-12-05 20:50:57 +0000550 * Boolean extra to indicate that the migrated account should be kept. This is used in
551 * conjunction with {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}. If it's set to {@code true},
552 * the account will not be removed from the primary user after it is migrated to the newly
553 * created user or profile.
Victor Chang89ee2792016-11-23 12:10:55 +0000554 *
555 * <p> Defaults to {@code false}
556 *
Victor Changaa9cbc02016-12-05 20:50:57 +0000557 * <p> Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
558 * {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}
Victor Chang89ee2792016-11-23 12:10:55 +0000559 */
560 public static final String EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION
561 = "android.app.extra.PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION";
562
563 /**
Mahaver761ce772017-03-13 16:40:45 +0000564 * @deprecated From {@link android.os.Build.VERSION_CODES#O}, never used while provisioning the
565 * device.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100566 */
Mahaver761ce772017-03-13 16:40:45 +0000567 @Deprecated
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100568 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
569 = "android.app.extra.PROVISIONING_EMAIL_ADDRESS";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100570
571 /**
Nicolas Prevotcd2d8592015-11-23 13:27:21 +0000572 * A integer extra indicating the predominant color to show during the provisioning.
573 * Refer to {@link android.graphics.Color} for how the color is represented.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000574 *
575 * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or
576 * {@link #ACTION_PROVISION_MANAGED_DEVICE}.
577 */
578 public static final String EXTRA_PROVISIONING_MAIN_COLOR =
579 "android.app.extra.PROVISIONING_MAIN_COLOR";
580
581 /**
Sander Alewijnse8c411562014-11-12 18:03:11 +0000582 * A Boolean extra that can be used by the mobile device management application to skip the
Robin Lee25e26452015-06-02 09:56:29 -0700583 * disabling of system apps during provisioning when set to {@code true}.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000584 *
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100585 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
586 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000587 */
Sander Alewijnse5a144252014-11-18 13:25:04 +0000588 public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED =
589 "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED";
Sander Alewijnse8c411562014-11-12 18:03:11 +0000590
591 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100592 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
593 * will be set to.
594 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000595 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
596 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100597 */
598 public static final String EXTRA_PROVISIONING_TIME_ZONE
Esteban Talavera37f01842014-09-05 10:50:57 +0100599 = "android.app.extra.PROVISIONING_TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100600
601 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100602 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
603 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100604 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000605 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
606 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100607 */
608 public static final String EXTRA_PROVISIONING_LOCAL_TIME
Esteban Talavera37f01842014-09-05 10:50:57 +0100609 = "android.app.extra.PROVISIONING_LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100610
611 /**
612 * A String extra holding the {@link java.util.Locale} that the device will be set to.
613 * Format: xx_yy, where xx is the language code, and yy the country code.
614 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000615 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
616 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100617 */
618 public static final String EXTRA_PROVISIONING_LOCALE
Esteban Talavera37f01842014-09-05 10:50:57 +0100619 = "android.app.extra.PROVISIONING_LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100620
621 /**
622 * A String extra holding the ssid of the wifi network that should be used during nfc device
623 * owner provisioning for downloading the mobile device management application.
624 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000625 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
626 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100627 */
628 public static final String EXTRA_PROVISIONING_WIFI_SSID
Esteban Talavera37f01842014-09-05 10:50:57 +0100629 = "android.app.extra.PROVISIONING_WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100630
631 /**
632 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
633 * is hidden or not.
634 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000635 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
636 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100637 */
638 public static final String EXTRA_PROVISIONING_WIFI_HIDDEN
Esteban Talavera37f01842014-09-05 10:50:57 +0100639 = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100640
641 /**
642 * A String extra indicating the security type of the wifi network in
Mahaver Chopra76b08a92015-10-08 17:58:45 +0100643 * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or
644 * {@code WEP}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100645 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000646 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
647 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100648 */
649 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
Esteban Talavera37f01842014-09-05 10:50:57 +0100650 = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100651
652 /**
653 * A String extra holding the password of the wifi network in
654 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
655 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000656 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
657 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100658 */
659 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talavera37f01842014-09-05 10:50:57 +0100660 = "android.app.extra.PROVISIONING_WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100661
662 /**
663 * A String extra holding the proxy host for the wifi network in
664 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
665 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000666 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
667 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100668 */
669 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
Esteban Talavera37f01842014-09-05 10:50:57 +0100670 = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100671
672 /**
673 * An int extra holding the proxy port for the wifi network in
674 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
675 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000676 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
677 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100678 */
679 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
Esteban Talavera37f01842014-09-05 10:50:57 +0100680 = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100681
682 /**
683 * A String extra holding the proxy bypass for the wifi network in
684 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
685 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000686 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
687 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100688 */
689 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
Esteban Talavera37f01842014-09-05 10:50:57 +0100690 = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100691
692 /**
693 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
694 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
695 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000696 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
697 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100698 */
699 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
Esteban Talavera37f01842014-09-05 10:50:57 +0100700 = "android.app.extra.PROVISIONING_WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100701
702 /**
703 * A String extra holding a url that specifies the download location of the device admin
704 * package. When not provided it is assumed that the device admin package is already installed.
705 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000706 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
707 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100708 */
709 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talavera37f01842014-09-05 10:50:57 +0100710 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100711
712 /**
Victor Chang38cfd9c2017-01-04 17:41:11 +0000713 * A String extra holding the localized name of the organization under management.
714 *
715 * The name is displayed only during provisioning.
716 *
717 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE}
718 *
719 * @hide
720 */
721 @SystemApi
722 public static final String EXTRA_PROVISIONING_ORGANIZATION_NAME =
723 "android.app.extra.PROVISIONING_ORGANIZATION_NAME";
724
725 /**
Alejandro Fernándezbfd61932017-04-04 19:33:01 +0100726 * A String extra holding a url to the website of the device provider so the user can open it
727 * during provisioning. If the url is not HTTPS, an error will be shown.
Victor Chang38cfd9c2017-01-04 17:41:11 +0000728 *
729 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE}
730 *
731 * @hide
732 */
733 @SystemApi
734 public static final String EXTRA_PROVISIONING_SUPPORT_URL =
735 "android.app.extra.PROVISIONING_SUPPORT_URL";
736
737 /**
738 * A String extra holding the localized name of the device admin package. It should be the same
739 * as the app label of the package.
740 *
741 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE}
742 *
743 * @hide
744 */
745 @SystemApi
746 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL =
747 "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL";
748
749 /**
750 * A {@link Uri} extra pointing to the app icon of device admin package. This image will be
751 * shown during the provisioning.
752 * <h5>The following URI schemes are accepted:</h5>
753 * <ul>
754 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
755 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
756 * </ul>
757 *
758 * <p> It is the responsibility of the caller to provide an image with a reasonable
759 * pixel density for the device.
760 *
761 * <p> If a content: URI is passed, the intent should have the flag
762 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
763 * {@link android.content.ClipData} of the intent too.
764 *
765 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE}
766 *
767 * @hide
768 */
769 @SystemApi
770 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI =
771 "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI";
772
773 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400774 * An int extra holding a minimum required version code for the device admin package. If the
775 * device admin is already installed on the device, it will only be re-downloaded from
776 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the
777 * installed package is less than this version code.
778 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400779 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400780 * provisioning via an NFC bump.
781 */
782 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE
783 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE";
784
785 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100786 * A String extra holding a http cookie header which should be used in the http request to the
787 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
788 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000789 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
790 * provisioning via an NFC bump.
Sander Alewijnse681bce92014-07-24 16:46:26 +0100791 */
792 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talavera37f01842014-09-05 10:50:57 +0100793 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100794
795 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100796 * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of
797 * the file at download location specified in
798 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100799 *
Benjamin Franzea956242016-03-21 15:45:56 +0000800 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} must be
801 * present. The provided checksum must match the checksum of the file at the download
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100802 * location. If the checksum doesn't match an error will be shown to the user and the user will
803 * be asked to factory reset the device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100804 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000805 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
806 * provisioning via an NFC bump.
Rubin Xud92e7572015-05-18 17:01:13 +0100807 *
808 * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP}
809 * and {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1} only SHA-1 hash is supported.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700810 * Starting from {@link android.os.Build.VERSION_CODES#M}, this parameter accepts SHA-256 in
Rubin Xud92e7572015-05-18 17:01:13 +0100811 * addition to SHA-1. Support for SHA-1 is likely to be removed in future OS releases.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100812 */
813 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100814 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100815
816 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100817 * A String extra holding the URL-safe base64 encoded SHA-256 checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100818 * android package archive at the download location specified in {@link
819 * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
820 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100821 * <p>The signatures of an android package archive can be obtained using
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100822 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
823 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
824 *
Benjamin Franzea956242016-03-21 15:45:56 +0000825 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} must be
826 * present. The provided checksum must match the checksum of any signature of the file at
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100827 * the download location. If the checksum does not match an error will be shown to the user and
828 * the user will be asked to factory reset the device.
829 *
830 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
831 * provisioning via an NFC bump.
832 */
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100833 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM
834 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM";
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100835
836 /**
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000837 * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile
838 * has completed successfully.
839 *
840 * <p>The broadcast is limited to the primary profile, to the app specified in the provisioning
Nicolas Prevotebe2d992015-05-12 18:14:53 -0700841 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000842 *
Mahaver7074caf2016-11-29 20:52:18 +0000843 * <p>This intent will contain the following extras
844 * <ul>
845 * <li>{@link Intent#EXTRA_USER}, corresponds to the {@link UserHandle} of the managed
846 * profile.</li>
847 * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, corresponds to the account requested to
848 * be migrated at provisioning time, if any.</li>
849 * </ul>
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000850 */
851 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
852 public static final String ACTION_MANAGED_PROFILE_PROVISIONED
853 = "android.app.action.MANAGED_PROFILE_PROVISIONED";
854
855 /**
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000856 * Activity action: This activity action is sent to indicate that provisioning of a managed
857 * profile or managed device has completed successfully. It'll be sent at the same time as
858 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast but this will be
859 * delivered faster as it's an activity intent.
860 *
Esteban Talavera4047bae2017-06-28 11:03:09 +0100861 * <p>The intent is only sent to the new device or profile owner.
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000862 *
863 * @see #ACTION_PROVISION_MANAGED_PROFILE
864 * @see #ACTION_PROVISION_MANAGED_DEVICE
865 */
866 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
867 public static final String ACTION_PROVISIONING_SUCCESSFUL =
868 "android.app.action.PROVISIONING_SUCCESSFUL";
869
870 /**
Benjamin Franzea956242016-03-21 15:45:56 +0000871 * A boolean extra indicating whether device encryption can be skipped as part of device owner
872 * or managed profile provisioning.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500873 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400874 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100875 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Benjamin Franzea956242016-03-21 15:45:56 +0000876 *
877 * <p>From {@link android.os.Build.VERSION_CODES#N} onwards, this is also supported for an
878 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500879 */
880 public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION =
881 "android.app.extra.PROVISIONING_SKIP_ENCRYPTION";
882
883 /**
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000884 * A {@link Uri} extra pointing to a logo image. This image will be shown during the
885 * provisioning. If this extra is not passed, a default image will be shown.
886 * <h5>The following URI schemes are accepted:</h5>
887 * <ul>
888 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
889 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
890 * </ul>
891 *
Victor Changc10f6692016-12-09 15:24:00 +0000892 * <p> It is the responsibility of the caller to provide an image with a reasonable
Victor Chang38cfd9c2017-01-04 17:41:11 +0000893 * pixel density for the device.
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000894 *
895 * <p> If a content: URI is passed, the intent should have the flag
896 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
897 * {@link android.content.ClipData} of the intent too.
898 *
899 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or
900 * {@link #ACTION_PROVISION_MANAGED_DEVICE}
901 */
902 public static final String EXTRA_PROVISIONING_LOGO_URI =
903 "android.app.extra.PROVISIONING_LOGO_URI";
904
905 /**
Victor Changc10f6692016-12-09 15:24:00 +0000906 * A {@link Bundle}[] extra consisting of list of disclaimer headers and disclaimer contents.
907 * Each {@link Bundle} must have both {@link #EXTRA_PROVISIONING_DISCLAIMER_HEADER}
908 * as disclaimer header, and {@link #EXTRA_PROVISIONING_DISCLAIMER_CONTENT} as disclaimer
909 * content.
910 *
911 * <p> The extra typically contains one disclaimer from the company of mobile device
912 * management application (MDM), and one disclaimer from the organization.
913 *
914 * <p> Call {@link Bundle#putParcelableArray(String, Parcelable[])} to put the {@link Bundle}[]
915 *
916 * <p> Maximum 3 key-value pairs can be specified. The rest will be ignored.
917 *
918 * <p> Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or
919 * {@link #ACTION_PROVISION_MANAGED_DEVICE}
920 */
921 public static final String EXTRA_PROVISIONING_DISCLAIMERS =
922 "android.app.extra.PROVISIONING_DISCLAIMERS";
923
924 /**
925 * A String extra of localized disclaimer header.
926 *
927 * <p> The extra is typically the company name of mobile device management application (MDM)
928 * or the organization name.
929 *
930 * <p> Use in Bundle {@link #EXTRA_PROVISIONING_DISCLAIMERS}
Victor Chang98607132017-01-27 11:51:56 +0000931 *
932 * <p> System app, i.e. application with {@link ApplicationInfo#FLAG_SYSTEM}, can also insert a
933 * disclaimer by declaring an application-level meta-data in {@code AndroidManifest.xml}.
934 * Must use it with {@link #EXTRA_PROVISIONING_DISCLAIMER_CONTENT}. Here is the example:
935 *
936 * <pre>
937 * &lt;meta-data
938 * android:name="android.app.extra.PROVISIONING_DISCLAIMER_HEADER"
939 * android:resource="@string/disclaimer_header"
940 * /&gt;</pre>
Victor Changc10f6692016-12-09 15:24:00 +0000941 */
942 public static final String EXTRA_PROVISIONING_DISCLAIMER_HEADER =
943 "android.app.extra.PROVISIONING_DISCLAIMER_HEADER";
944
945 /**
946 * A {@link Uri} extra pointing to disclaimer content.
947 *
948 * <h5>The following URI schemes are accepted:</h5>
949 * <ul>
950 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
951 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
952 * </ul>
953 *
954 * <p> Styled text is supported in the disclaimer content. The content is parsed by
955 * {@link android.text.Html#fromHtml(String)} and displayed in a
956 * {@link android.widget.TextView}.
957 *
958 * <p> If a <code>content:</code> URI is passed, URI is passed, the intent should have the flag
959 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
960 * {@link android.content.ClipData} of the intent too.
961 *
962 * <p> Use in Bundle {@link #EXTRA_PROVISIONING_DISCLAIMERS}
Victor Chang98607132017-01-27 11:51:56 +0000963 *
964 * <p> System app, i.e. application with {@link ApplicationInfo#FLAG_SYSTEM}, can also insert a
965 * disclaimer by declaring an application-level meta-data in {@code AndroidManifest.xml}.
966 * Must use it with {@link #EXTRA_PROVISIONING_DISCLAIMER_HEADER}. Here is the example:
967 *
968 * <pre>
969 * &lt;meta-data
970 * android:name="android.app.extra.PROVISIONING_DISCLAIMER_CONTENT"
971 * android:resource="@string/disclaimer_content"
972 * /&gt;</pre>
Victor Changc10f6692016-12-09 15:24:00 +0000973 */
974 public static final String EXTRA_PROVISIONING_DISCLAIMER_CONTENT =
975 "android.app.extra.PROVISIONING_DISCLAIMER_CONTENT";
976
977 /**
Alan Treadway94de8c82016-01-11 10:25:23 +0000978 * A boolean extra indicating if user setup should be skipped, for when provisioning is started
979 * during setup-wizard.
980 *
981 * <p>If unspecified, defaults to {@code true} to match the behavior in
982 * {@link android.os.Build.VERSION_CODES#M} and earlier.
983 *
Alan Treadway1a538d02016-01-18 16:42:30 +0000984 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or
985 * {@link #ACTION_PROVISION_MANAGED_USER}.
Alan Treadway94de8c82016-01-11 10:25:23 +0000986 *
987 * @hide
988 */
989 public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP =
990 "android.app.extra.PROVISIONING_SKIP_USER_SETUP";
991
992 /**
Victor Chang51d84f92016-11-16 12:22:56 +0000993 * A boolean extra indicating if the user consent steps from the provisioning flow should be
994 * skipped. If unspecified, defaults to {@code false}.
995 *
996 * It can only be used by an existing device owner trying to create a managed profile via
997 * {@link #ACTION_PROVISION_MANAGED_PROFILE}. Otherwise it is ignored.
998 */
999 public static final String EXTRA_PROVISIONING_SKIP_USER_CONSENT =
1000 "android.app.extra.PROVISIONING_SKIP_USER_CONSENT";
1001
1002 /**
Benjamin Franzea956242016-03-21 15:45:56 +00001003 * This MIME type is used for starting the device owner provisioning.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +01001004 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -04001005 * <p>During device owner provisioning a device admin app is set as the owner of the device.
1006 * A device owner has full control over the device. The device owner can not be modified by the
1007 * user and the only way of resetting the device is if the device owner app calls a factory
1008 * reset.
1009 *
1010 * <p> A typical use case would be a device that is owned by a company, but used by either an
1011 * employee or client.
1012 *
Benjamin Franzea956242016-03-21 15:45:56 +00001013 * <p> The NFC message must be sent to an unprovisioned device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +01001014 *
Sander Alewijnse8c411562014-11-12 18:03:11 +00001015 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +01001016 * contains the following properties:
1017 * <ul>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -04001018 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
1019 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +01001020 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -04001021 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +01001022 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
1023 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
1024 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
1025 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
1026 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
1027 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
1028 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
1029 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
1030 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
1031 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Rubin Xu41f2ccb92015-08-05 16:29:13 +01001032 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
1033 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from
1034 * {@link android.os.Build.VERSION_CODES#M} </li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +01001035 *
Nicolas Prevot18440252015-03-09 14:07:17 +00001036 * <p>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07001037 * As of {@link android.os.Build.VERSION_CODES#M}, the properties should contain
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -04001038 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of
1039 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only
1040 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -04001041 */
1042 public static final String MIME_TYPE_PROVISIONING_NFC
1043 = "application/com.android.managedprovisioning";
1044
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +01001045 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001046 * Activity action: ask the user to add a new device administrator to the system.
1047 * The desired policy is the ComponentName of the policy in the
1048 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
1049 * bring the user through adding the device administrator to the system (or
1050 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001051 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001052 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
1053 * field to provide the user with additional explanation (in addition
1054 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001055 *
1056 * <p>If your administrator is already active, this will ordinarily return immediately (without
1057 * user intervention). However, if your administrator has been updated and is requesting
1058 * additional uses-policy flags, the user will be presented with the new list. New policies
1059 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001060 */
1061 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1062 public static final String ACTION_ADD_DEVICE_ADMIN
1063 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001064
Dianne Hackbornd6847842010-01-12 18:14:19 -08001065 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001066 * @hide
1067 * Activity action: ask the user to add a new device administrator as the profile owner
Amith Yamasani814e9872015-03-23 14:04:53 -07001068 * for this user. Only system apps can launch this intent.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001069 *
Amith Yamasani814e9872015-03-23 14:04:53 -07001070 * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN}
1071 * extra field. This will invoke a UI to bring the user through adding the profile owner admin
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001072 * to remotely control restrictions on the user.
1073 *
Makoto Onukic8a5a552015-11-19 14:29:12 -08001074 * <p>The intent must be invoked via {@link Activity#startActivityForResult} to receive the
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001075 * result of whether or not the user approved the action. If approved, the result will
1076 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
1077 * as a profile owner.
1078 *
1079 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
1080 * field to provide the user with additional explanation (in addition
1081 * to your component's description) about what is being added.
1082 *
Amith Yamasani814e9872015-03-23 14:04:53 -07001083 * <p>If there is already a profile owner active or the caller is not a system app, the
1084 * operation will return a failure result.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001085 */
1086 @SystemApi
1087 public static final String ACTION_SET_PROFILE_OWNER
1088 = "android.app.action.SET_PROFILE_OWNER";
1089
1090 /**
1091 * @hide
1092 * Name of the profile owner admin that controls the user.
1093 */
1094 @SystemApi
1095 public static final String EXTRA_PROFILE_OWNER_NAME
1096 = "android.app.extra.PROFILE_OWNER_NAME";
1097
1098 /**
Nicolas Prevot00799002015-07-27 18:15:20 +01001099 * Broadcast action: send when any policy admin changes a policy.
Jim Miller284b62e2010-06-08 14:27:42 -07001100 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -07001101 *
Jim Miller284b62e2010-06-08 14:27:42 -07001102 * @hide
1103 */
1104 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
1105 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
1106
1107 /**
Tony Mak1970f972016-08-30 17:41:48 +01001108 * Broadcast action: sent when the device owner is set, changed or cleared.
Nicolas Prevot00799002015-07-27 18:15:20 +01001109 *
1110 * This broadcast is sent only to the primary user.
1111 * @see #ACTION_PROVISION_MANAGED_DEVICE
1112 */
1113 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1114 public static final String ACTION_DEVICE_OWNER_CHANGED
1115 = "android.app.action.DEVICE_OWNER_CHANGED";
1116
1117 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001118 * The ComponentName of the administrator component.
1119 *
1120 * @see #ACTION_ADD_DEVICE_ADMIN
1121 */
1122 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001123
Dianne Hackbornd6847842010-01-12 18:14:19 -08001124 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001125 * An optional CharSequence providing additional explanation for why the
1126 * admin is being added.
1127 *
1128 * @see #ACTION_ADD_DEVICE_ADMIN
1129 */
1130 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001131
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001132 /**
phweiss73145f42017-01-17 19:06:38 +01001133 * Constant to indicate the feature of disabling the camera. Used as argument to
1134 * {@link #createAdminSupportIntent(String)}.
1135 * @see #setCameraDisabled(ComponentName, boolean)
1136 */
1137 public static final String POLICY_DISABLE_CAMERA = "policy_disable_camera";
1138
1139 /**
1140 * Constant to indicate the feature of disabling screen captures. Used as argument to
1141 * {@link #createAdminSupportIntent(String)}.
1142 * @see #setScreenCaptureDisabled(ComponentName, boolean)
1143 */
1144 public static final String POLICY_DISABLE_SCREEN_CAPTURE = "policy_disable_screen_capture";
1145
1146 /**
1147 * A String indicating a specific restricted feature. Can be a user restriction from the
1148 * {@link UserManager}, e.g. {@link UserManager#DISALLOW_ADJUST_VOLUME}, or one of the values
1149 * {@link #POLICY_DISABLE_CAMERA} or {@link #POLICY_DISABLE_SCREEN_CAPTURE}.
1150 * @see #createAdminSupportIntent(String)
1151 * @hide
1152 */
1153 @TestApi
1154 public static final String EXTRA_RESTRICTION = "android.app.extra.RESTRICTION";
1155
1156 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001157 * Activity action: have the user enter a new password. This activity should
1158 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
1159 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
1160 * enter a new password that meets the current requirements. You can use
1161 * {@link #isActivePasswordSufficient()} to determine whether you need to
1162 * have the user select a new password in order to meet the current
1163 * constraints. Upon being resumed from this activity, you can check the new
1164 * password characteristics to see if they are sufficient.
Benjamin Franzc9921092016-01-08 17:17:44 +00001165 *
1166 * If the intent is launched from within a managed profile with a profile
1167 * owner built against {@link android.os.Build.VERSION_CODES#M} or before,
1168 * this will trigger entering a new password for the parent of the profile.
1169 * For all other cases it will trigger entering a new password for the user
1170 * or profile it is launched from.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001171 *
1172 * @see #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
Dianne Hackbornd6847842010-01-12 18:14:19 -08001173 */
1174 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1175 public static final String ACTION_SET_NEW_PASSWORD
1176 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001177
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001178 /**
Benjamin Franzc9921092016-01-08 17:17:44 +00001179 * Activity action: have the user enter a new password for the parent profile.
1180 * If the intent is launched from within a managed profile, this will trigger
1181 * entering a new password for the parent of the profile. In all other cases
1182 * the behaviour is identical to {@link #ACTION_SET_NEW_PASSWORD}.
1183 */
1184 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1185 public static final String ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
1186 = "android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD";
1187
1188 /**
phweissa0cb2512016-12-14 21:37:48 +01001189 * Broadcast action: Tell the status bar to open the device monitoring dialog, e.g. when
1190 * Network logging was enabled and the user tapped the notification.
1191 * <p class="note">This is a protected intent that can only be sent by the system.</p>
1192 * @hide
1193 */
1194 public static final String ACTION_SHOW_DEVICE_MONITORING_DIALOG
1195 = "android.app.action.SHOW_DEVICE_MONITORING_DIALOG";
1196
1197 /**
Edman Anjos9e62c312017-01-26 22:22:58 +01001198 * Broadcast Action: Sent after application delegation scopes are changed. The new delegation
1199 * scopes will be sent in an {@code ArrayList<String>} extra identified by the
1200 * {@link #EXTRA_DELEGATION_SCOPES} key.
Edman Anjosf9946772016-11-28 16:35:15 +01001201 *
1202 * <p class=”note”> Note: This is a protected intent that can only be sent by the system.</p>
1203 */
1204 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1205 public static final String ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED =
1206 "android.app.action.APPLICATION_DELEGATION_SCOPES_CHANGED";
1207
1208 /**
Edman Anjos9e62c312017-01-26 22:22:58 +01001209 * An {@code ArrayList<String>} corresponding to the delegation scopes given to an app in the
Edman Anjosf9946772016-11-28 16:35:15 +01001210 * {@link #ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED} broadcast.
1211 */
1212 public static final String EXTRA_DELEGATION_SCOPES = "android.app.extra.DELEGATION_SCOPES";
1213
1214 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +00001215 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
1216 * the parent profile to access intents sent from the managed profile.
1217 * That is, when an app in the managed profile calls
1218 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
1219 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001220 */
Nicolas Prevot86a96732014-09-08 12:13:05 +01001221 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001222
1223 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +00001224 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
1225 * the managed profile to access intents sent from the parent profile.
1226 * That is, when an app in the parent profile calls
1227 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
1228 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001229 */
Nicolas Prevot86a96732014-09-08 12:13:05 +01001230 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001231
Dianne Hackbornd6847842010-01-12 18:14:19 -08001232 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01001233 * Broadcast action: notify that a new local system update policy has been set by the device
1234 * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00001235 */
1236 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Rubin Xu5faad8e2015-04-20 17:43:48 +01001237 public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED
1238 = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED";
Rubin Xu8027a4f2015-03-10 17:52:37 +00001239
Amith Yamasanid49489b2015-04-28 14:00:26 -07001240 /**
1241 * Permission policy to prompt user for new permission requests for runtime permissions.
1242 * Already granted or denied permissions are not affected by this.
1243 */
1244 public static final int PERMISSION_POLICY_PROMPT = 0;
1245
1246 /**
1247 * Permission policy to always grant new permission requests for runtime permissions.
1248 * Already granted or denied permissions are not affected by this.
1249 */
1250 public static final int PERMISSION_POLICY_AUTO_GRANT = 1;
1251
1252 /**
1253 * Permission policy to always deny new permission requests for runtime permissions.
1254 * Already granted or denied permissions are not affected by this.
1255 */
1256 public static final int PERMISSION_POLICY_AUTO_DENY = 2;
1257
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07001258 /**
1259 * Runtime permission state: The user can manage the permission
1260 * through the UI.
1261 */
1262 public static final int PERMISSION_GRANT_STATE_DEFAULT = 0;
1263
1264 /**
1265 * Runtime permission state: The permission is granted to the app
1266 * and the user cannot manage the permission through the UI.
1267 */
1268 public static final int PERMISSION_GRANT_STATE_GRANTED = 1;
1269
1270 /**
1271 * Runtime permission state: The permission is denied to the app
1272 * and the user cannot manage the permission through the UI.
1273 */
1274 public static final int PERMISSION_GRANT_STATE_DENIED = 2;
Rubin Xu8027a4f2015-03-10 17:52:37 +00001275
1276 /**
Edman Anjosf9946772016-11-28 16:35:15 +01001277 * Delegation of certificate installation and management. This scope grants access to the
1278 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
1279 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair} APIs.
1280 */
1281 public static final String DELEGATION_CERT_INSTALL = "delegation-cert-install";
1282
1283 /**
1284 * Delegation of application restrictions management. This scope grants access to the
1285 * {@link #setApplicationRestrictions} and {@link #getApplicationRestrictions} APIs.
1286 */
1287 public static final String DELEGATION_APP_RESTRICTIONS = "delegation-app-restrictions";
1288
1289 /**
Edman Anjosa5f2fb12016-12-19 11:25:54 -08001290 * Delegation of application uninstall block. This scope grants access to the
1291 * {@link #setUninstallBlocked} API.
1292 */
1293 public static final String DELEGATION_BLOCK_UNINSTALL = "delegation-block-uninstall";
1294
1295 /**
Edman Anjos52088e42017-01-13 22:26:17 +01001296 * Delegation of permission policy and permission grant state. This scope grants access to the
1297 * {@link #setPermissionPolicy}, {@link #getPermissionGrantState},
1298 * and {@link #setPermissionGrantState} APIs.
1299 */
1300 public static final String DELEGATION_PERMISSION_GRANT = "delegation-permission-grant";
1301
1302 /**
1303 * Delegation of package access state. This scope grants access to the
1304 * {@link #isApplicationHidden}, {@link #setApplicationHidden}, {@link #isPackageSuspended}, and
1305 * {@link #setPackagesSuspended} APIs.
1306 */
1307 public static final String DELEGATION_PACKAGE_ACCESS = "delegation-package-access";
1308
1309 /**
1310 * Delegation for enabling system apps. This scope grants access to the {@link #enableSystemApp}
1311 * API.
1312 */
1313 public static final String DELEGATION_ENABLE_SYSTEM_APP = "delegation-enable-system-app";
1314
1315 /**
1316 * Delegation of management of uninstalled packages. This scope grants access to the
1317 * {@code #setKeepUninstalledPackages} and {@code #getKeepUninstalledPackages} APIs.
1318 * @hide
1319 */
1320 public static final String DELEGATION_KEEP_UNINSTALLED_PACKAGES =
1321 "delegation-keep-uninstalled-packages";
1322
1323 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00001324 * No management for current user in-effect. This is the default.
1325 * @hide
1326 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001327 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001328 public static final int STATE_USER_UNMANAGED = 0;
1329
1330 /**
1331 * Management partially setup, user setup needs to be completed.
1332 * @hide
1333 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001334 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001335 public static final int STATE_USER_SETUP_INCOMPLETE = 1;
1336
1337 /**
1338 * Management partially setup, user setup completed.
1339 * @hide
1340 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001341 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001342 public static final int STATE_USER_SETUP_COMPLETE = 2;
1343
1344 /**
1345 * Management setup and active on current user.
1346 * @hide
1347 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001348 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001349 public static final int STATE_USER_SETUP_FINALIZED = 3;
1350
1351 /**
1352 * Management partially setup on a managed profile.
1353 * @hide
1354 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001355 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001356 public static final int STATE_USER_PROFILE_COMPLETE = 4;
1357
1358 /**
1359 * @hide
1360 */
1361 @IntDef({STATE_USER_UNMANAGED, STATE_USER_SETUP_INCOMPLETE, STATE_USER_SETUP_COMPLETE,
1362 STATE_USER_SETUP_FINALIZED, STATE_USER_PROFILE_COMPLETE})
1363 @Retention(RetentionPolicy.SOURCE)
1364 public @interface UserProvisioningState {}
1365
1366 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001367 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001368 *
1369 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1370 * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and
1371 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when provisioning is allowed.
1372 *
1373 * @hide
1374 */
1375 public static final int CODE_OK = 0;
1376
1377 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001378 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001379 *
1380 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and
1381 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the device already has a device
1382 * owner.
1383 *
1384 * @hide
1385 */
1386 public static final int CODE_HAS_DEVICE_OWNER = 1;
1387
1388 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001389 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001390 *
1391 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1392 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user has a profile owner and for
1393 * {@link #ACTION_PROVISION_MANAGED_PROFILE} when the profile owner is already set.
1394 *
1395 * @hide
1396 */
1397 public static final int CODE_USER_HAS_PROFILE_OWNER = 2;
1398
1399 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001400 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001401 *
1402 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and
1403 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user isn't running.
1404 *
1405 * @hide
1406 */
1407 public static final int CODE_USER_NOT_RUNNING = 3;
1408
1409 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001410 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001411 *
1412 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1413 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the device has already been setup and
1414 * for {@link #ACTION_PROVISION_MANAGED_USER} if the user has already been setup.
1415 *
1416 * @hide
1417 */
1418 public static final int CODE_USER_SETUP_COMPLETED = 4;
1419
1420 /**
1421 * Code used to indicate that the device also has a user other than the system user.
1422 *
1423 * @hide
1424 */
1425 public static final int CODE_NONSYSTEM_USER_EXISTS = 5;
1426
1427 /**
1428 * Code used to indicate that device has an account that prevents provisioning.
1429 *
1430 * @hide
1431 */
1432 public static final int CODE_ACCOUNTS_NOT_EMPTY = 6;
1433
1434 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001435 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001436 *
1437 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and
1438 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the user is not a system user.
1439 *
1440 * @hide
1441 */
1442 public static final int CODE_NOT_SYSTEM_USER = 7;
1443
1444 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001445 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001446 *
1447 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1448 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} and {@link #ACTION_PROVISION_MANAGED_USER}
1449 * when the device is a watch and is already paired.
1450 *
1451 * @hide
1452 */
1453 public static final int CODE_HAS_PAIRED = 8;
1454
1455 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001456 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001457 *
1458 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} and
1459 * {@link #ACTION_PROVISION_MANAGED_USER} on devices which do not support managed users.
1460 *
1461 * @see {@link PackageManager#FEATURE_MANAGED_USERS}
1462 * @hide
1463 */
1464 public static final int CODE_MANAGED_USERS_NOT_SUPPORTED = 9;
1465
1466 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001467 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001468 *
1469 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} if the user is a system user.
1470 *
1471 * @hide
1472 */
1473 public static final int CODE_SYSTEM_USER = 10;
1474
1475 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001476 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001477 *
1478 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when the user cannot have more
1479 * managed profiles.
1480 *
1481 * @hide
1482 */
1483 public static final int CODE_CANNOT_ADD_MANAGED_PROFILE = 11;
1484
1485 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001486 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001487 *
1488 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} and
1489 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices not running with split system
1490 * user.
1491 *
1492 * @hide
1493 */
1494 public static final int CODE_NOT_SYSTEM_USER_SPLIT = 12;
1495
1496 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001497 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001498 *
1499 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1500 * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and
1501 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices which do no support device
1502 * admins.
1503 *
1504 * @hide
1505 */
1506 public static final int CODE_DEVICE_ADMIN_NOT_SUPPORTED = 13;
1507
1508 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001509 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001510 *
Esteban Talavera6c9116a2016-11-24 16:12:44 +00001511 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when the device the user is a
1512 * system user on a split system user device.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001513 *
1514 * @hide
1515 */
1516 public static final int CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER = 14;
1517
1518 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001519 * Result code for {@link #checkProvisioningPreCondition}.
1520 *
1521 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when adding a managed profile is
1522 * disallowed by {@link UserManager#DISALLOW_ADD_MANAGED_PROFILE}.
1523 *
1524 * @hide
1525 */
1526 public static final int CODE_ADD_MANAGED_PROFILE_DISALLOWED = 15;
1527
1528 /**
1529 * Result codes for {@link #checkProvisioningPreCondition} indicating all the provisioning pre
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001530 * conditions.
1531 *
1532 * @hide
1533 */
1534 @Retention(RetentionPolicy.SOURCE)
1535 @IntDef({CODE_OK, CODE_HAS_DEVICE_OWNER, CODE_USER_HAS_PROFILE_OWNER, CODE_USER_NOT_RUNNING,
1536 CODE_USER_SETUP_COMPLETED, CODE_NOT_SYSTEM_USER, CODE_HAS_PAIRED,
1537 CODE_MANAGED_USERS_NOT_SUPPORTED, CODE_SYSTEM_USER, CODE_CANNOT_ADD_MANAGED_PROFILE,
1538 CODE_NOT_SYSTEM_USER_SPLIT, CODE_DEVICE_ADMIN_NOT_SUPPORTED,
Esteban Talavera01576862016-12-15 11:16:44 +00001539 CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER, CODE_ADD_MANAGED_PROFILE_DISALLOWED})
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001540 public @interface ProvisioningPreCondition {}
1541
1542 /**
Makoto Onukifc73d792017-03-22 14:22:35 -07001543 * Service action: Action for a service that device owner and profile owner can optionally
1544 * own. If a device owner or a profile owner has such a service, the system tries to keep
1545 * a bound connection to it, in order to keep their process always running.
Makoto Onukife739702017-04-25 13:26:21 -07001546 * The service must be protected with the {@link android.Manifest.permission#BIND_DEVICE_ADMIN}
1547 * permission.
Makoto Onukifc73d792017-03-22 14:22:35 -07001548 */
1549 @SdkConstant(SdkConstantType.SERVICE_ACTION)
1550 public static final String ACTION_DEVICE_ADMIN_SERVICE
1551 = "android.app.action.DEVICE_ADMIN_SERVICE";
1552
1553 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001554 * Return true if the given administrator component is currently active (enabled) in the system.
1555 *
1556 * @param admin The administrator component to check for.
1557 * @return {@code true} if {@code admin} is currently enabled in the system, {@code false}
1558 * otherwise
Dianne Hackbornd6847842010-01-12 18:14:19 -08001559 */
Robin Lee25e26452015-06-02 09:56:29 -07001560 public boolean isAdminActive(@NonNull ComponentName admin) {
Charles He8c760562016-10-25 16:36:53 +01001561 throwIfParentInstance("isAdminActive");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001562 return isAdminActiveAsUser(admin, myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001563 }
1564
1565 /**
1566 * @see #isAdminActive(ComponentName)
1567 * @hide
1568 */
Robin Lee25e26452015-06-02 09:56:29 -07001569 public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001570 if (mService != null) {
1571 try {
Robin Lee25e26452015-06-02 09:56:29 -07001572 return mService.isAdminActive(admin, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001573 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001574 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001575 }
1576 }
1577 return false;
1578 }
Charles Hedea0c3b2017-01-13 10:04:12 +00001579
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001580 /**
1581 * Return true if the given administrator component is currently being removed
1582 * for the user.
1583 * @hide
1584 */
Robin Lee25e26452015-06-02 09:56:29 -07001585 public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) {
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001586 if (mService != null) {
1587 try {
Robin Lee25e26452015-06-02 09:56:29 -07001588 return mService.isRemovingAdmin(admin, userId);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001589 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001590 throw e.rethrowFromSystemServer();
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001591 }
1592 }
1593 return false;
1594 }
1595
Dianne Hackbornd6847842010-01-12 18:14:19 -08001596 /**
Robin Lee25e26452015-06-02 09:56:29 -07001597 * Return a list of all currently active device administrators' component
1598 * names. If there are no administrators {@code null} may be
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001599 * returned.
1600 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07001601 public @Nullable List<ComponentName> getActiveAdmins() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001602 throwIfParentInstance("getActiveAdmins");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001603 return getActiveAdminsAsUser(myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001604 }
1605
1606 /**
1607 * @see #getActiveAdmins()
1608 * @hide
1609 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07001610 public @Nullable List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001611 if (mService != null) {
1612 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001613 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001614 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001615 throw e.rethrowFromSystemServer();
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001616 }
1617 }
1618 return null;
1619 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001620
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001621 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001622 * Used by package administration code to determine if a package can be stopped
1623 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001624 * @hide
1625 */
David Ouyang3a83a332017-01-11 16:36:40 -08001626 @SystemApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06001627 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001628 public boolean packageHasActiveAdmins(String packageName) {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001629 return packageHasActiveAdmins(packageName, myUserId());
1630 }
1631
1632 /**
1633 * Used by package administration code to determine if a package can be stopped
1634 * or uninstalled.
1635 * @hide
1636 */
1637 public boolean packageHasActiveAdmins(String packageName, int userId) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001638 if (mService != null) {
1639 try {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001640 return mService.packageHasActiveAdmins(packageName, userId);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001641 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001642 throw e.rethrowFromSystemServer();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001643 }
1644 }
1645 return false;
1646 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001647
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001648 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001649 * Remove a current administration component. This can only be called
1650 * by the application that owns the administration component; if you
1651 * try to remove someone else's component, a security exception will be
1652 * thrown.
Esteban Talavera552a5612016-02-19 17:02:24 +00001653 *
1654 * <p>Note that the operation is not synchronous and the admin might still be active (as
1655 * indicated by {@link #getActiveAdmins()}) by the time this method returns.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001656 *
1657 * @param admin The administration compononent to remove.
1658 * @throws SecurityException if the caller is not in the owner application of {@code admin}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001659 */
Robin Lee25e26452015-06-02 09:56:29 -07001660 public void removeActiveAdmin(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001661 throwIfParentInstance("removeActiveAdmin");
Dianne Hackbornd6847842010-01-12 18:14:19 -08001662 if (mService != null) {
1663 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001664 mService.removeActiveAdmin(admin, myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001665 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001666 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001667 }
1668 }
1669 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001670
Dianne Hackbornd6847842010-01-12 18:14:19 -08001671 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001672 * Returns true if an administrator has been granted a particular device policy. This can be
1673 * used to check whether the administrator was activated under an earlier set of policies, but
1674 * requires additional policies after an upgrade.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001675 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001676 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be an
1677 * active administrator, or an exception will be thrown.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001678 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001679 * @throws SecurityException if {@code admin} is not an active administrator.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001680 */
Robin Lee25e26452015-06-02 09:56:29 -07001681 public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001682 throwIfParentInstance("hasGrantedPolicy");
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001683 if (mService != null) {
1684 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001685 return mService.hasGrantedPolicy(admin, usesPolicy, myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001686 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001687 throw e.rethrowFromSystemServer();
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001688 }
1689 }
1690 return false;
1691 }
1692
1693 /**
Clara Bayarria1771112015-12-18 16:29:18 +00001694 * Returns true if the Profile Challenge is available to use for the given profile user.
1695 *
1696 * @hide
1697 */
1698 public boolean isSeparateProfileChallengeAllowed(int userHandle) {
1699 if (mService != null) {
1700 try {
1701 return mService.isSeparateProfileChallengeAllowed(userHandle);
1702 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001703 throw e.rethrowFromSystemServer();
Clara Bayarria1771112015-12-18 16:29:18 +00001704 }
1705 }
1706 return false;
1707 }
1708
1709 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001710 * Constant for {@link #setPasswordQuality}: the policy has no requirements
1711 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001712 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001713 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001714 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001715
Dianne Hackbornd6847842010-01-12 18:14:19 -08001716 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -07001717 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
1718 * recognition technology. This implies technologies that can recognize the identity of
1719 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
1720 * Note that quality constants are ordered so that higher values are more restrictive.
1721 */
1722 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
1723
1724 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001725 * Constant for {@link #setPasswordQuality}: the policy requires some kind
Benjamin Franzc6a96532015-06-16 11:23:38 +01001726 * of password or pattern, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001727 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001728 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001729 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001730
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001731 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001732 * Constant for {@link #setPasswordQuality}: the user must have entered a
1733 * password containing at least numeric characters. Note that quality
1734 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001735 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001736 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001737
Dianne Hackbornd6847842010-01-12 18:14:19 -08001738 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001739 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -08001740 * password containing at least numeric characters with no repeating (4444)
1741 * or ordered (1234, 4321, 2468) sequences. Note that quality
1742 * constants are ordered so that higher values are more restrictive.
1743 */
1744 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
1745
1746 /**
1747 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001748 * password containing at least alphabetic (or other symbol) characters.
1749 * Note that quality constants are ordered so that higher values are more
1750 * restrictive.
1751 */
1752 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001753
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001754 /**
1755 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001756 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001757 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001758 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001759 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001760 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001761
Dianne Hackbornd6847842010-01-12 18:14:19 -08001762 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001763 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001764 * password containing at least a letter, a numerical digit and a special
1765 * symbol, by default. With this password quality, passwords can be
1766 * restricted to contain various sets of characters, like at least an
1767 * uppercase letter, etc. These are specified using various methods,
1768 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
1769 * that quality constants are ordered so that higher values are more
1770 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001771 */
1772 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
1773
1774 /**
Oleksandr Peletskyi0fdcd3d2016-01-13 16:49:56 +01001775 * Constant for {@link #setPasswordQuality}: the user is not allowed to
1776 * modify password. In case this password quality is set, the password is
1777 * managed by a profile owner. The profile owner can set any password,
1778 * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note
1779 * that quality constants are ordered so that higher values are more
1780 * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is
1781 * the highest.
1782 * @hide
1783 */
1784 public static final int PASSWORD_QUALITY_MANAGED = 0x80000;
1785
1786 /**
Makoto Onuki5e7e06702016-09-01 18:02:01 -07001787 * @hide
1788 *
1789 * adb shell dpm set-{device,profile}-owner will normally not allow installing an owner to
1790 * a user with accounts. {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED}
1791 * and {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} are the account features
1792 * used by authenticator to exempt their accounts from this:
1793 *
1794 * <ul>
1795 * <li>Non-test-only DO/PO still can't be installed when there are accounts.
1796 * <p>In order to make an apk test-only, add android:testOnly="true" to the
1797 * &lt;application&gt; tag in the manifest.
1798 *
1799 * <li>Test-only DO/PO can be installed even when there are accounts, as long as all the
1800 * accounts have the {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} feature.
1801 * Some authenticators claim to have any features, so to detect it, we also check
1802 * {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} and disallow installing
1803 * if any of the accounts have it.
1804 * </ul>
1805 */
Makoto Onuki47c203d2017-02-13 16:21:19 -08001806 @SystemApi
1807 @TestApi
Makoto Onuki5e7e06702016-09-01 18:02:01 -07001808 public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED =
1809 "android.account.DEVICE_OR_PROFILE_OWNER_ALLOWED";
1810
1811 /** @hide See {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} */
Makoto Onuki47c203d2017-02-13 16:21:19 -08001812 @SystemApi
1813 @TestApi
Makoto Onuki5e7e06702016-09-01 18:02:01 -07001814 public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED =
1815 "android.account.DEVICE_OR_PROFILE_OWNER_DISALLOWED";
1816
1817 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001818 * Called by an application that is administering the device to set the password restrictions it
1819 * is imposing. After setting this, the user will not be able to enter a new password that is
1820 * not at least as restrictive as what has been set. Note that the current password will remain
1821 * until the user has set a new one, so the change does not take place immediately. To prompt
1822 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
Esteban Talaverac1c83592016-02-17 17:56:15 +00001823 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after calling this method.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001824 * <p>
1825 * Quality constants are ordered so that higher values are more restrictive; thus the highest
1826 * requested quality constant (between the policy set here, the user's preference, and any other
1827 * considerations) is the one that is in effect.
1828 * <p>
1829 * The calling device admin must have requested
1830 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1831 * not, a security exception will be thrown.
1832 * <p>
1833 * This method can be called on the {@link DevicePolicyManager} instance returned by
1834 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1835 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001836 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001837 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001838 * @param quality The new desired quality. One of {@link #PASSWORD_QUALITY_UNSPECIFIED},
1839 * {@link #PASSWORD_QUALITY_SOMETHING}, {@link #PASSWORD_QUALITY_NUMERIC},
1840 * {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC},
1841 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} or {@link #PASSWORD_QUALITY_COMPLEX}.
1842 * @throws SecurityException if {@code admin} is not an active administrator or if {@code admin}
1843 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Dianne Hackbornd6847842010-01-12 18:14:19 -08001844 */
Robin Lee25e26452015-06-02 09:56:29 -07001845 public void setPasswordQuality(@NonNull ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001846 if (mService != null) {
1847 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001848 mService.setPasswordQuality(admin, quality, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001849 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001850 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001851 }
1852 }
1853 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001854
Dianne Hackbornd6847842010-01-12 18:14:19 -08001855 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001856 * Retrieve the current minimum password quality for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01001857 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00001858 * a separate challenge are not taken into account.
1859 *
1860 * <p>This method can be called on the {@link DevicePolicyManager} instance
1861 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1862 * restrictions on the parent profile.
1863 *
Robin Lee25e26452015-06-02 09:56:29 -07001864 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001865 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001866 */
Robin Lee25e26452015-06-02 09:56:29 -07001867 public int getPasswordQuality(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001868 return getPasswordQuality(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001869 }
1870
1871 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001872 public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001873 if (mService != null) {
1874 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001875 return mService.getPasswordQuality(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001876 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001877 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001878 }
1879 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001880 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001881 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001882
Dianne Hackbornd6847842010-01-12 18:14:19 -08001883 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001884 * Called by an application that is administering the device to set the minimum allowed password
1885 * length. After setting this, the user will not be able to enter a new password that is not at
1886 * least as restrictive as what has been set. Note that the current password will remain until
1887 * the user has set a new one, so the change does not take place immediately. To prompt the user
1888 * for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
1889 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
1890 * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC}
1891 * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC},
1892 * {@link #PASSWORD_QUALITY_ALPHANUMERIC}, or {@link #PASSWORD_QUALITY_COMPLEX} with
1893 * {@link #setPasswordQuality}.
1894 * <p>
1895 * The calling device admin must have requested
1896 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1897 * not, a security exception will be thrown.
1898 * <p>
1899 * This method can be called on the {@link DevicePolicyManager} instance returned by
1900 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1901 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001902 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001903 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001904 * @param length The new desired minimum password length. A value of 0 means there is no
1905 * restriction.
1906 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1907 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Dianne Hackbornd6847842010-01-12 18:14:19 -08001908 */
Robin Lee25e26452015-06-02 09:56:29 -07001909 public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001910 if (mService != null) {
1911 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001912 mService.setPasswordMinimumLength(admin, length, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001913 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001914 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001915 }
1916 }
1917 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001918
Dianne Hackbornd6847842010-01-12 18:14:19 -08001919 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001920 * Retrieve the current minimum password length for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01001921 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00001922 * a separate challenge are not taken into account.
1923 *
1924 * <p>This method can be called on the {@link DevicePolicyManager} instance
1925 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1926 * restrictions on the parent profile.
1927 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001928 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001929 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001930 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001931 */
Robin Lee25e26452015-06-02 09:56:29 -07001932 public int getPasswordMinimumLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001933 return getPasswordMinimumLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001934 }
1935
1936 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001937 public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001938 if (mService != null) {
1939 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001940 return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001941 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001942 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001943 }
1944 }
1945 return 0;
1946 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001947
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001948 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001949 * Called by an application that is administering the device to set the minimum number of upper
1950 * case letters required in the password. After setting this, the user will not be able to enter
1951 * a new password that is not at least as restrictive as what has been set. Note that the
1952 * current password will remain until the user has set a new one, so the change does not take
1953 * place immediately. To prompt the user for a new password, use
1954 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
1955 * setting this value. This constraint is only imposed if the administrator has also requested
1956 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001957 * <p>
1958 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001959 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1960 * not, a security exception will be thrown.
1961 * <p>
1962 * This method can be called on the {@link DevicePolicyManager} instance returned by
1963 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1964 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001965 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001966 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1967 * @param length The new desired minimum number of upper case letters required in the password.
1968 * A value of 0 means there is no restriction.
1969 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1970 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001971 */
Robin Lee25e26452015-06-02 09:56:29 -07001972 public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001973 if (mService != null) {
1974 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001975 mService.setPasswordMinimumUpperCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001976 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001977 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001978 }
1979 }
1980 }
1981
1982 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001983 * Retrieve the current number of upper case letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01001984 * for a particular admin or all admins that set restrictions on this user and
Esteban Talaverac1c83592016-02-17 17:56:15 +00001985 * its participating profiles. Restrictions on profiles that have a separate challenge
1986 * are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001987 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001988 * {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001989 * and only applies when the password quality is
1990 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001991 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001992 * <p>This method can be called on the {@link DevicePolicyManager} instance
1993 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1994 * restrictions on the parent profile.
1995 *
Robin Lee25e26452015-06-02 09:56:29 -07001996 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001997 * aggregate all admins.
1998 * @return The minimum number of upper case letters required in the
1999 * password.
2000 */
Robin Lee25e26452015-06-02 09:56:29 -07002001 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002002 return getPasswordMinimumUpperCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002003 }
2004
2005 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002006 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002007 if (mService != null) {
2008 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002009 return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002010 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002011 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002012 }
2013 }
2014 return 0;
2015 }
2016
2017 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002018 * Called by an application that is administering the device to set the minimum number of lower
2019 * case letters required in the password. After setting this, the user will not be able to enter
2020 * a new password that is not at least as restrictive as what has been set. Note that the
2021 * current password will remain until the user has set a new one, so the change does not take
2022 * place immediately. To prompt the user for a new password, use
2023 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
2024 * setting this value. This constraint is only imposed if the administrator has also requested
2025 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002026 * <p>
2027 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002028 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2029 * not, a security exception will be thrown.
2030 * <p>
2031 * This method can be called on the {@link DevicePolicyManager} instance returned by
2032 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2033 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002034 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002035 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2036 * @param length The new desired minimum number of lower case letters required in the password.
2037 * A value of 0 means there is no restriction.
2038 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2039 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002040 */
Robin Lee25e26452015-06-02 09:56:29 -07002041 public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002042 if (mService != null) {
2043 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002044 mService.setPasswordMinimumLowerCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002045 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002046 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002047 }
2048 }
2049 }
2050
2051 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002052 * Retrieve the current number of lower case letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002053 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002054 * and its participating profiles. Restrictions on profiles that have
2055 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01002056 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00002057 * {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002058 * and only applies when the password quality is
2059 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002060 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002061 * <p>This method can be called on the {@link DevicePolicyManager} instance
2062 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2063 * restrictions on the parent profile.
2064 *
Robin Lee25e26452015-06-02 09:56:29 -07002065 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002066 * aggregate all admins.
2067 * @return The minimum number of lower case letters required in the
2068 * password.
2069 */
Robin Lee25e26452015-06-02 09:56:29 -07002070 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002071 return getPasswordMinimumLowerCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002072 }
2073
2074 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002075 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002076 if (mService != null) {
2077 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002078 return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002079 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002080 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002081 }
2082 }
2083 return 0;
2084 }
2085
2086 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002087 * Called by an application that is administering the device to set the minimum number of
2088 * letters required in the password. After setting this, the user will not be able to enter a
2089 * new password that is not at least as restrictive as what has been set. Note that the current
2090 * password will remain until the user has set a new one, so the change does not take place
2091 * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
2092 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
2093 * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
2094 * {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002095 * <p>
2096 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002097 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2098 * not, a security exception will be thrown.
2099 * <p>
2100 * This method can be called on the {@link DevicePolicyManager} instance returned by
2101 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2102 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002103 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002104 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2105 * @param length The new desired minimum number of letters required in the password. A value of
2106 * 0 means there is no restriction.
2107 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2108 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002109 */
Robin Lee25e26452015-06-02 09:56:29 -07002110 public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002111 if (mService != null) {
2112 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002113 mService.setPasswordMinimumLetters(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002114 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002115 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002116 }
2117 }
2118 }
2119
2120 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002121 * Retrieve the current number of letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002122 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002123 * and its participating profiles. Restrictions on profiles that have
2124 * a separate challenge are not taken into account.
2125 * This is the same value as set by
2126 * {@link #setPasswordMinimumLetters(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002127 * and only applies when the password quality is
2128 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002129 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002130 * <p>This method can be called on the {@link DevicePolicyManager} instance
2131 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2132 * restrictions on the parent profile.
2133 *
Robin Lee25e26452015-06-02 09:56:29 -07002134 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002135 * aggregate all admins.
2136 * @return The minimum number of letters required in the password.
2137 */
Robin Lee25e26452015-06-02 09:56:29 -07002138 public int getPasswordMinimumLetters(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002139 return getPasswordMinimumLetters(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002140 }
2141
2142 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002143 public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002144 if (mService != null) {
2145 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002146 return mService.getPasswordMinimumLetters(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002147 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002148 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002149 }
2150 }
2151 return 0;
2152 }
2153
2154 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002155 * Called by an application that is administering the device to set the minimum number of
2156 * numerical digits required in the password. After setting this, the user will not be able to
2157 * enter a new password that is not at least as restrictive as what has been set. Note that the
2158 * current password will remain until the user has set a new one, so the change does not take
2159 * place immediately. To prompt the user for a new password, use
2160 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
2161 * setting this value. This constraint is only imposed if the administrator has also requested
2162 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002163 * <p>
2164 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002165 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2166 * not, a security exception will be thrown.
2167 * <p>
2168 * This method can be called on the {@link DevicePolicyManager} instance returned by
2169 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2170 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002171 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002172 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2173 * @param length The new desired minimum number of numerical digits required in the password. A
2174 * value of 0 means there is no restriction.
2175 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2176 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002177 */
Robin Lee25e26452015-06-02 09:56:29 -07002178 public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002179 if (mService != null) {
2180 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002181 mService.setPasswordMinimumNumeric(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002182 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002183 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002184 }
2185 }
2186 }
2187
2188 /**
2189 * Retrieve the current number of numerical digits required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002190 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002191 * and its participating profiles. Restrictions on profiles that have
2192 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01002193 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00002194 * {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002195 * and only applies when the password quality is
2196 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002197 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002198 * <p>This method can be called on the {@link DevicePolicyManager} instance
2199 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2200 * restrictions on the parent profile.
2201 *
Robin Lee25e26452015-06-02 09:56:29 -07002202 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002203 * aggregate all admins.
2204 * @return The minimum number of numerical digits required in the password.
2205 */
Robin Lee25e26452015-06-02 09:56:29 -07002206 public int getPasswordMinimumNumeric(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002207 return getPasswordMinimumNumeric(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002208 }
2209
2210 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002211 public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002212 if (mService != null) {
2213 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002214 return mService.getPasswordMinimumNumeric(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002215 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002216 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002217 }
2218 }
2219 return 0;
2220 }
2221
2222 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002223 * Called by an application that is administering the device to set the minimum number of
2224 * symbols required in the password. After setting this, the user will not be able to enter a
2225 * new password that is not at least as restrictive as what has been set. Note that the current
2226 * password will remain until the user has set a new one, so the change does not take place
2227 * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
2228 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
2229 * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
2230 * {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002231 * <p>
2232 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002233 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2234 * not, a security exception will be thrown.
2235 * <p>
2236 * This method can be called on the {@link DevicePolicyManager} instance returned by
2237 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2238 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002239 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002240 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2241 * @param length The new desired minimum number of symbols required in the password. A value of
2242 * 0 means there is no restriction.
2243 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2244 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002245 */
Robin Lee25e26452015-06-02 09:56:29 -07002246 public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002247 if (mService != null) {
2248 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002249 mService.setPasswordMinimumSymbols(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002250 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002251 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002252 }
2253 }
2254 }
2255
2256 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002257 * Retrieve the current number of symbols required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002258 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002259 * and its participating profiles. Restrictions on profiles that have
2260 * a separate challenge are not taken into account. This is the same value as
2261 * set by {@link #setPasswordMinimumSymbols(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002262 * and only applies when the password quality is
2263 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002264 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002265 * <p>This method can be called on the {@link DevicePolicyManager} instance
2266 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2267 * restrictions on the parent profile.
2268 *
Robin Lee25e26452015-06-02 09:56:29 -07002269 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002270 * aggregate all admins.
2271 * @return The minimum number of symbols required in the password.
2272 */
Robin Lee25e26452015-06-02 09:56:29 -07002273 public int getPasswordMinimumSymbols(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002274 return getPasswordMinimumSymbols(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002275 }
2276
2277 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002278 public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002279 if (mService != null) {
2280 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002281 return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002282 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002283 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002284 }
2285 }
2286 return 0;
2287 }
2288
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002289 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002290 * Called by an application that is administering the device to set the minimum number of
2291 * non-letter characters (numerical digits or symbols) required in the password. After setting
2292 * this, the user will not be able to enter a new password that is not at least as restrictive
2293 * as what has been set. Note that the current password will remain until the user has set a new
2294 * one, so the change does not take place immediately. To prompt the user for a new password,
2295 * use {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
2296 * setting this value. This constraint is only imposed if the administrator has also requested
2297 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002298 * <p>
2299 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002300 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2301 * not, a security exception will be thrown.
2302 * <p>
2303 * This method can be called on the {@link DevicePolicyManager} instance returned by
2304 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2305 * profile.
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002306 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002307 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2308 * @param length The new desired minimum number of letters required in the password. A value of
2309 * 0 means there is no restriction.
2310 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2311 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002312 */
Robin Lee25e26452015-06-02 09:56:29 -07002313 public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002314 if (mService != null) {
2315 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002316 mService.setPasswordMinimumNonLetter(admin, length, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002317 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002318 throw e.rethrowFromSystemServer();
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002319 }
2320 }
2321 }
2322
2323 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002324 * Retrieve the current number of non-letter characters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002325 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002326 * and its participating profiles. Restrictions on profiles that have
2327 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01002328 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00002329 * {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002330 * and only applies when the password quality is
2331 * {@link #PASSWORD_QUALITY_COMPLEX}.
2332 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002333 * <p>This method can be called on the {@link DevicePolicyManager} instance
2334 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2335 * restrictions on the parent profile.
2336 *
Robin Lee25e26452015-06-02 09:56:29 -07002337 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002338 * aggregate all admins.
2339 * @return The minimum number of letters required in the password.
2340 */
Robin Lee25e26452015-06-02 09:56:29 -07002341 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002342 return getPasswordMinimumNonLetter(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002343 }
2344
2345 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002346 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002347 if (mService != null) {
2348 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002349 return mService.getPasswordMinimumNonLetter(admin, userHandle, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002350 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002351 throw e.rethrowFromSystemServer();
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002352 }
2353 }
2354 return 0;
2355 }
2356
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002357 /**
2358 * Called by an application that is administering the device to set the length of the password
2359 * history. After setting this, the user will not be able to enter a new password that is the
2360 * same as any password in the history. Note that the current password will remain until the
2361 * user has set a new one, so the change does not take place immediately. To prompt the user for
2362 * a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
2363 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
2364 * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC}
2365 * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX} {@link #PASSWORD_QUALITY_ALPHABETIC}, or
2366 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} with {@link #setPasswordQuality}.
2367 * <p>
2368 * The calling device admin must have requested
2369 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2370 * not, a security exception will be thrown.
2371 * <p>
2372 * This method can be called on the {@link DevicePolicyManager} instance returned by
2373 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2374 * profile.
2375 *
2376 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2377 * @param length The new desired length of password history. A value of 0 means there is no
2378 * restriction.
2379 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2380 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
2381 */
Robin Lee25e26452015-06-02 09:56:29 -07002382 public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002383 if (mService != null) {
2384 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002385 mService.setPasswordHistoryLength(admin, length, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002386 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002387 throw e.rethrowFromSystemServer();
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002388 }
2389 }
2390 }
2391
2392 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002393 * Called by a device admin to set the password expiration timeout. Calling this method will
2394 * restart the countdown for password expiration for the given admin, as will changing the
2395 * device password (for all admins).
2396 * <p>
2397 * The provided timeout is the time delta in ms and will be added to the current time. For
2398 * example, to have the password expire 5 days from now, timeout would be 5 * 86400 * 1000 =
2399 * 432000000 ms for timeout.
2400 * <p>
2401 * To disable password expiration, a value of 0 may be used for timeout.
2402 * <p>
2403 * The calling device admin must have requested
2404 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this method; if it has
2405 * not, a security exception will be thrown.
2406 * <p>
2407 * Note that setting the password will automatically reset the expiration time for all active
2408 * admins. Active admins do not need to explicitly call this method in that case.
2409 * <p>
2410 * This method can be called on the {@link DevicePolicyManager} instance returned by
2411 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2412 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002413 *
Jim Millera4e28d12010-11-08 16:15:47 -08002414 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002415 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0 means
2416 * there is no restriction (unlimited).
2417 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2418 * does not use {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD}
Jim Millera4e28d12010-11-08 16:15:47 -08002419 */
Robin Lee25e26452015-06-02 09:56:29 -07002420 public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) {
Jim Millera4e28d12010-11-08 16:15:47 -08002421 if (mService != null) {
2422 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002423 mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08002424 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002425 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08002426 }
2427 }
2428 }
2429
2430 /**
Jim Miller6b857682011-02-16 16:27:41 -08002431 * Get the password expiration timeout for the given admin. The expiration timeout is the
2432 * recurring expiration timeout provided in the call to
2433 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
Esteban Talaverac1c83592016-02-17 17:56:15 +00002434 * aggregate of all participating policy administrators if {@code admin} is null. Admins that
2435 * have set restrictions on profiles that have a separate challenge are not taken into account.
2436 *
2437 * <p>This method can be called on the {@link DevicePolicyManager} instance
2438 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2439 * restrictions on the parent profile.
Jim Millera4e28d12010-11-08 16:15:47 -08002440 *
Robin Lee25e26452015-06-02 09:56:29 -07002441 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08002442 * @return The timeout for the given admin or the minimum of all timeouts
2443 */
Robin Lee25e26452015-06-02 09:56:29 -07002444 public long getPasswordExpirationTimeout(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08002445 if (mService != null) {
2446 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002447 return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08002448 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002449 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08002450 }
2451 }
2452 return 0;
2453 }
2454
2455 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002456 * Get the current password expiration time for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01002457 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00002458 * a separate challenge are not taken into account. If admin is {@code null}, then a composite
2459 * of all expiration times is returned - which will be the minimum of all of them.
2460 *
2461 * <p>This method can be called on the {@link DevicePolicyManager} instance
2462 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2463 * the password expiration for the parent profile.
Jim Millera4e28d12010-11-08 16:15:47 -08002464 *
Robin Lee25e26452015-06-02 09:56:29 -07002465 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002466 * @return The password expiration time, in milliseconds since epoch.
Jim Millera4e28d12010-11-08 16:15:47 -08002467 */
Robin Lee25e26452015-06-02 09:56:29 -07002468 public long getPasswordExpiration(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08002469 if (mService != null) {
2470 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002471 return mService.getPasswordExpiration(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08002472 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002473 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08002474 }
2475 }
2476 return 0;
2477 }
2478
2479 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002480 * Retrieve the current password history length for a particular admin or all admins that
Rubin Xud3609d42016-07-13 18:32:57 +01002481 * set restrictions on this user and its participating profiles. Restrictions on profiles that
Esteban Talaverac1c83592016-02-17 17:56:15 +00002482 * have a separate challenge are not taken into account.
2483 *
2484 * <p>This method can be called on the {@link DevicePolicyManager} instance
2485 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2486 * restrictions on the parent profile.
2487 *
Robin Lee25e26452015-06-02 09:56:29 -07002488 * @param admin The name of the admin component to check, or {@code null} to aggregate
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002489 * all admins.
2490 * @return The length of the password history
2491 */
Robin Lee25e26452015-06-02 09:56:29 -07002492 public int getPasswordHistoryLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002493 return getPasswordHistoryLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002494 }
2495
2496 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002497 public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002498 if (mService != null) {
2499 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002500 return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002501 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002502 throw e.rethrowFromSystemServer();
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002503 }
2504 }
2505 return 0;
2506 }
2507
Dianne Hackbornd6847842010-01-12 18:14:19 -08002508 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08002509 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08002510 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08002511 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08002512 * @return Returns the maximum length that the user can enter.
2513 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08002514 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08002515 // Kind-of arbitrary.
2516 return 16;
2517 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002518
Dianne Hackborn254cb442010-01-27 19:23:59 -08002519 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002520 * Determine whether the current password the user has set is sufficient to meet the policy
2521 * requirements (e.g. quality, minimum length) that have been requested by the admins of this
2522 * user and its participating profiles. Restrictions on profiles that have a separate challenge
Andrew Scull5daf2732016-11-14 15:02:45 +00002523 * are not taken into account. The user must be unlocked in order to perform the check.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002524 * <p>
2525 * The calling device admin must have requested
2526 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2527 * not, a security exception will be thrown.
2528 * <p>
2529 * This method can be called on the {@link DevicePolicyManager} instance returned by
2530 * {@link #getParentProfileInstance(ComponentName)} in order to determine if the password set on
2531 * the parent profile is sufficient.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002532 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01002533 * @return Returns true if the password meets the current requirements, else false.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002534 * @throws SecurityException if the calling application does not own an active administrator
2535 * that uses {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Andrew Scull5daf2732016-11-14 15:02:45 +00002536 * @throws InvalidStateException if the user is not unlocked.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002537 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002538 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002539 if (mService != null) {
2540 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00002541 return mService.isActivePasswordSufficient(myUserId(), mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002542 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002543 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002544 }
2545 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002546 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08002547 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002548
Dianne Hackbornd6847842010-01-12 18:14:19 -08002549 /**
Clara Bayarrid7693912016-01-22 17:26:31 +00002550 * Determine whether the current profile password the user has set is sufficient
Esteban Talaverac1c83592016-02-17 17:56:15 +00002551 * to meet the policy requirements (e.g. quality, minimum length) that have been
Clara Bayarrid7693912016-01-22 17:26:31 +00002552 * requested by the admins of the parent user and its profiles.
2553 *
2554 * @param userHandle the userId of the profile to check the password for.
2555 * @return Returns true if the password would meet the current requirements, else false.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002556 * @throws SecurityException if {@code userHandle} is not a managed profile.
Clara Bayarrid7693912016-01-22 17:26:31 +00002557 * @hide
2558 */
2559 public boolean isProfileActivePasswordSufficientForParent(int userHandle) {
2560 if (mService != null) {
2561 try {
2562 return mService.isProfileActivePasswordSufficientForParent(userHandle);
2563 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002564 throw e.rethrowFromSystemServer();
Clara Bayarrid7693912016-01-22 17:26:31 +00002565 }
2566 }
2567 return false;
2568 }
2569
2570 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002571 * Retrieve the number of times the user has failed at entering a password since that last
2572 * successful password entry.
2573 * <p>
2574 * This method can be called on the {@link DevicePolicyManager} instance returned by
2575 * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the number of failed
2576 * password attemts for the parent user.
2577 * <p>
2578 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN}
2579 * to be able to call this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002580 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002581 * @return The number of times user has entered an incorrect password since the last correct
2582 * password entry.
2583 * @throws SecurityException if the calling application does not own an active administrator
2584 * that uses {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002585 */
2586 public int getCurrentFailedPasswordAttempts() {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00002587 return getCurrentFailedPasswordAttempts(myUserId());
2588 }
2589
2590 /**
2591 * Retrieve the number of times the given user has failed at entering a
2592 * password since that last successful password entry.
2593 *
2594 * <p>The calling device admin must have requested
2595 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call this method; if it has
2596 * not and it is not the system uid, a security exception will be thrown.
2597 *
2598 * @hide
2599 */
2600 public int getCurrentFailedPasswordAttempts(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002601 if (mService != null) {
2602 try {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00002603 return mService.getCurrentFailedPasswordAttempts(userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002604 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002605 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002606 }
2607 }
2608 return -1;
2609 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002610
2611 /**
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002612 * Queries whether {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002613 *
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002614 * @return true if RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002615 * @hide
2616 */
2617 public boolean getDoNotAskCredentialsOnBoot() {
2618 if (mService != null) {
2619 try {
2620 return mService.getDoNotAskCredentialsOnBoot();
2621 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002622 throw e.rethrowFromSystemServer();
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002623 }
2624 }
2625 return false;
2626 }
2627
2628 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002629 * Setting this to a value greater than zero enables a built-in policy that will perform a
2630 * device or profile wipe after too many incorrect device-unlock passwords have been entered.
2631 * This built-in policy combines watching for failed passwords and wiping the device, and
2632 * requires that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002633 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002634 * <p>
2635 * To implement any other policy (e.g. wiping data for a particular application only, erasing or
2636 * revoking credentials, or reporting the failure to a server), you should implement
2637 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} instead. Do not
2638 * use this API, because if the maximum count is reached, the device or profile will be wiped
2639 * immediately, and your callback will not be invoked.
2640 * <p>
2641 * This method can be called on the {@link DevicePolicyManager} instance returned by
2642 * {@link #getParentProfileInstance(ComponentName)} in order to set a value on the parent
2643 * profile.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002644 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002645 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002646 * @param num The number of failed password attempts at which point the device or profile will
2647 * be wiped.
2648 * @throws SecurityException if {@code admin} is not an active administrator or does not use
2649 * both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
2650 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002651 */
Robin Lee25e26452015-06-02 09:56:29 -07002652 public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002653 if (mService != null) {
2654 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002655 mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002656 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002657 throw e.rethrowFromSystemServer();
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002658 }
2659 }
2660 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002661
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002662 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002663 * Retrieve the current maximum number of login attempts that are allowed before the device
Rubin Xud3609d42016-07-13 18:32:57 +01002664 * or profile is wiped, for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002665 * and its participating profiles. Restrictions on profiles that have a separate challenge are
2666 * not taken into account.
2667 *
2668 * <p>This method can be called on the {@link DevicePolicyManager} instance
2669 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2670 * the value for the parent profile.
2671 *
Robin Lee25e26452015-06-02 09:56:29 -07002672 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002673 * all admins.
2674 */
Robin Lee25e26452015-06-02 09:56:29 -07002675 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002676 return getMaximumFailedPasswordsForWipe(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002677 }
2678
2679 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002680 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08002681 if (mService != null) {
2682 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002683 return mService.getMaximumFailedPasswordsForWipe(
2684 admin, userHandle, mParentInstance);
Dianne Hackborn254cb442010-01-27 19:23:59 -08002685 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002686 throw e.rethrowFromSystemServer();
Dianne Hackborn254cb442010-01-27 19:23:59 -08002687 }
2688 }
2689 return 0;
2690 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002691
Dianne Hackborn254cb442010-01-27 19:23:59 -08002692 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002693 * Returns the profile with the smallest maximum failed passwords for wipe,
2694 * for the given user. So for primary user, it might return the primary or
2695 * a managed profile. For a secondary user, it would be the same as the
2696 * user passed in.
2697 * @hide Used only by Keyguard
2698 */
2699 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
2700 if (mService != null) {
2701 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002702 return mService.getProfileWithMinimumFailedPasswordsForWipe(
2703 userHandle, mParentInstance);
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002704 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002705 throw e.rethrowFromSystemServer();
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002706 }
2707 }
2708 return UserHandle.USER_NULL;
2709 }
2710
2711 /**
Benjamin Miller1aed7882017-08-15 18:04:20 +02002712 * Flag for {@link #resetPasswordWithToken} and {@link #resetPassword}: don't allow other admins
2713 * to change the password again until the user has entered it.
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002714 */
2715 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002716
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002717 /**
Benjamin Miller1aed7882017-08-15 18:04:20 +02002718 * Flag for {@link #resetPasswordWithToken} and {@link #resetPassword}: don't ask for user
2719 * credentials on device boot.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002720 * If the flag is set, the device can be booted without asking for user password.
2721 * The absence of this flag does not change the current boot requirements. This flag
2722 * can be set by the device owner only. If the app is not the device owner, the flag
2723 * is ignored. Once the flag is set, it cannot be reverted back without resetting the
2724 * device to factory defaults.
2725 */
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002726 public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002;
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002727
2728 /**
Benjamin Miller1aed7882017-08-15 18:04:20 +02002729 * Force a new password for device unlock (the password needed to access the entire device) or
2730 * the work profile challenge on the current user. This takes effect immediately.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002731 * <p>
Rubin Xuaab7a412016-12-30 21:13:29 +00002732 * <em>For device owner and profile owners targeting SDK level
2733 * {@link android.os.Build.VERSION_CODES#O} or above, this API is no longer available and will
2734 * throw {@link SecurityException}. Please use the new API {@link #resetPasswordWithToken}
2735 * instead. </em>
2736 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002737 * <em>Note: This API has been limited as of {@link android.os.Build.VERSION_CODES#N} for
Makoto Onuki70f929e2015-11-11 12:40:15 -08002738 * device admins that are not device owner and not profile owner.
2739 * The password can now only be changed if there is currently no password set. Device owner
Ricky Wai977ade22016-05-24 15:02:41 +01002740 * and profile owner can still do this when user is unlocked and does not have a managed
2741 * profile.</em>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002742 * <p>
2743 * The given password must be sufficient for the current password quality and length constraints
2744 * as returned by {@link #getPasswordQuality(ComponentName)} and
2745 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then
2746 * it will be rejected and false returned. Note that the password may be a stronger quality
2747 * (containing alphanumeric characters when the requested quality is only numeric), in which
2748 * case the currently active quality will be increased to match.
2749 * <p>
2750 * Calling with a null or empty password will clear any existing PIN, pattern or password if the
Robin Leece5c4002016-03-23 17:05:03 +00002751 * current password constraints allow it. <em>Note: This will not work in
2752 * {@link android.os.Build.VERSION_CODES#N} and later for managed profiles, or for device admins
2753 * that are not device owner or profile owner. Once set, the password cannot be changed to null
2754 * or empty except by these admins.</em>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002755 * <p>
2756 * The calling device admin must have requested
2757 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call this method; if it has
2758 * not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002759 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01002760 * @param password The new password for the user. Null or empty clears the password.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002761 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002762 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
2763 * @return Returns true if the password was applied, or false if it is not acceptable for the
2764 * current constraints or if the user has not been decrypted yet.
2765 * @throws SecurityException if the calling application does not own an active administrator
2766 * that uses {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD}
Ricky Wai977ade22016-05-24 15:02:41 +01002767 * @throws IllegalStateException if the calling user is locked or has a managed profile.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002768 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002769 public boolean resetPassword(String password, int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002770 throwIfParentInstance("resetPassword");
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002771 if (mService != null) {
2772 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002773 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002774 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002775 throw e.rethrowFromSystemServer();
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002776 }
2777 }
2778 return false;
2779 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002780
Dianne Hackbornd6847842010-01-12 18:14:19 -08002781 /**
Rubin Xuaab7a412016-12-30 21:13:29 +00002782 * 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 +01002783 * device lockscreen password (if called by device owner), or managed profile challenge (if
2784 * called by profile owner), via {@link #resetPasswordWithToken}.
Rubin Xuaab7a412016-12-30 21:13:29 +00002785 * <p>
2786 * If the user currently has a lockscreen password, the provisioned token will not be
2787 * immediately usable; it only becomes active after the user performs a confirm credential
2788 * operation, which can be triggered by {@link KeyguardManager#createConfirmDeviceCredentialIntent}.
2789 * If the user has no lockscreen password, the token is activated immediately. In all cases,
2790 * the active state of the current token can be checked by {@link #isResetPasswordTokenActive}.
2791 * For security reasons, un-activated tokens are only stored in memory and will be lost once
2792 * the device reboots. In this case a new token needs to be provisioned again.
2793 * <p>
2794 * Once provisioned and activated, the token will remain effective even if the user changes
2795 * or clears the lockscreen password.
2796 * <p>
2797 * <em>This token is highly sensitive and should be treated at the same level as user
Rubin Xuf7b036d2017-04-05 18:37:07 +01002798 * credentials. In particular, NEVER store this token on device in plaintext. Do not store
2799 * the plaintext token in device-encrypted storage if it will be needed to reset password on
2800 * file-based encryption devices before user unlocks. Consider carefully how any password token
2801 * will be stored on your server and who will need access to them. Tokens may be the subject of
2802 * legal access requests.
Rubin Xuaab7a412016-12-30 21:13:29 +00002803 * </em>
2804 *
2805 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2806 * @param token a secure token a least 32-byte long, which must be generated by a
2807 * cryptographically strong random number generator.
2808 * @return true if the operation is successful, false otherwise.
Benjamin Miller1aed7882017-08-15 18:04:20 +02002809 * @throws SecurityException if admin is not a device or profile owner.
Rubin Xuaab7a412016-12-30 21:13:29 +00002810 * @throws IllegalArgumentException if the supplied token is invalid.
Rubin Xuaab7a412016-12-30 21:13:29 +00002811 */
2812 public boolean setResetPasswordToken(ComponentName admin, byte[] token) {
2813 throwIfParentInstance("setResetPasswordToken");
2814 if (mService != null) {
2815 try {
2816 return mService.setResetPasswordToken(admin, token);
2817 } catch (RemoteException e) {
2818 throw e.rethrowFromSystemServer();
2819 }
2820 }
2821 return false;
2822 }
2823
2824 /**
2825 * Called by a profile or device owner to revoke the current password reset token.
2826 *
2827 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2828 * @return true if the operation is successful, false otherwise.
Benjamin Miller1aed7882017-08-15 18:04:20 +02002829 * @throws SecurityException if admin is not a device or profile owner.
Rubin Xuaab7a412016-12-30 21:13:29 +00002830 */
2831 public boolean clearResetPasswordToken(ComponentName admin) {
2832 throwIfParentInstance("clearResetPasswordToken");
2833 if (mService != null) {
2834 try {
2835 return mService.clearResetPasswordToken(admin);
2836 } catch (RemoteException e) {
2837 throw e.rethrowFromSystemServer();
2838 }
2839 }
2840 return false;
2841 }
2842
2843 /**
2844 * Called by a profile or device owner to check if the current reset password token is active.
2845 *
2846 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2847 * @return true if the token is active, false otherwise.
Benjamin Miller1aed7882017-08-15 18:04:20 +02002848 * @throws SecurityException if admin is not a device or profile owner.
Rubin Xuaab7a412016-12-30 21:13:29 +00002849 * @throws IllegalStateException if no token has been set.
2850 */
2851 public boolean isResetPasswordTokenActive(ComponentName admin) {
2852 throwIfParentInstance("isResetPasswordTokenActive");
2853 if (mService != null) {
2854 try {
2855 return mService.isResetPasswordTokenActive(admin);
2856 } catch (RemoteException e) {
2857 throw e.rethrowFromSystemServer();
2858 }
2859 }
2860 return false;
2861 }
2862
2863 /**
Esteban Talavera7e4cbad2017-03-30 17:59:50 +01002864 * Called by device or profile owner to force set a new device unlock password or a managed
2865 * profile challenge on current user. This takes effect immediately.
Rubin Xuaab7a412016-12-30 21:13:29 +00002866 * <p>
2867 * Unlike {@link #resetPassword}, this API can change the password even before the user or
2868 * device is unlocked or decrypted. The supplied token must have been previously provisioned via
2869 * {@link #setResetPasswordToken}, and in active state {@link #isResetPasswordTokenActive}.
2870 * <p>
2871 * The given password must be sufficient for the current password quality and length constraints
2872 * as returned by {@link #getPasswordQuality(ComponentName)} and
2873 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then
Benjamin Miller1aed7882017-08-15 18:04:20 +02002874 * it will be rejected and false returned. Note that the password may be a stronger quality, for
2875 * example, a password containing alphanumeric characters when the requested quality is only
2876 * numeric.
Rubin Xuaab7a412016-12-30 21:13:29 +00002877 * <p>
Benjamin Miller1aed7882017-08-15 18:04:20 +02002878 * Calling with a {@code null} or empty password will clear any existing PIN, pattern or
2879 * password if the current password constraints allow it.
Rubin Xuaab7a412016-12-30 21:13:29 +00002880 *
2881 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Miller1aed7882017-08-15 18:04:20 +02002882 * @param password The new password for the user. {@code null} or empty clears the password.
2883 * @param token the password reset token previously provisioned by
2884 * {@link #setResetPasswordToken}.
Rubin Xuaab7a412016-12-30 21:13:29 +00002885 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Benjamin Miller1aed7882017-08-15 18:04:20 +02002886 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
Rubin Xuaab7a412016-12-30 21:13:29 +00002887 * @return Returns true if the password was applied, or false if it is not acceptable for the
2888 * current constraints.
Benjamin Miller1aed7882017-08-15 18:04:20 +02002889 * @throws SecurityException if admin is not a device or profile owner.
Rubin Xuaab7a412016-12-30 21:13:29 +00002890 * @throws IllegalStateException if the provided token is not valid.
Rubin Xuaab7a412016-12-30 21:13:29 +00002891 */
2892 public boolean resetPasswordWithToken(@NonNull ComponentName admin, String password,
2893 byte[] token, int flags) {
2894 throwIfParentInstance("resetPassword");
2895 if (mService != null) {
2896 try {
2897 return mService.resetPasswordWithToken(admin, password, token, flags);
2898 } catch (RemoteException e) {
2899 throw e.rethrowFromSystemServer();
2900 }
2901 }
2902 return false;
2903 }
2904
2905 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002906 * Called by an application that is administering the device to set the maximum time for user
2907 * activity until the device will lock. This limits the length that the user can set. It takes
2908 * effect immediately.
2909 * <p>
2910 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
2911 * to be able to call this method; if it has not, a security exception will be thrown.
2912 * <p>
2913 * This method can be called on the {@link DevicePolicyManager} instance returned by
2914 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2915 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002916 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002917 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002918 * @param timeMs The new desired maximum time to lock in milliseconds. A value of 0 means there
2919 * is no restriction.
2920 * @throws SecurityException if {@code admin} is not an active administrator or it does not use
2921 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002922 */
Robin Lee25e26452015-06-02 09:56:29 -07002923 public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002924 if (mService != null) {
2925 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002926 mService.setMaximumTimeToLock(admin, timeMs, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002927 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002928 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002929 }
2930 }
2931 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002932
Dianne Hackbornd6847842010-01-12 18:14:19 -08002933 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002934 * Retrieve the current maximum time to unlock for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01002935 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00002936 * a separate challenge are not taken into account.
2937 *
2938 * <p>This method can be called on the {@link DevicePolicyManager} instance
2939 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2940 * restrictions on the parent profile.
2941 *
Robin Lee25e26452015-06-02 09:56:29 -07002942 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002943 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07002944 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07002945 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002946 */
Robin Lee25e26452015-06-02 09:56:29 -07002947 public long getMaximumTimeToLock(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002948 return getMaximumTimeToLock(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002949 }
2950
2951 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002952 public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002953 if (mService != null) {
2954 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002955 return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002956 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002957 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002958 }
2959 }
2960 return 0;
2961 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002962
Dianne Hackbornd6847842010-01-12 18:14:19 -08002963 /**
Ricky Wai035e9242016-03-18 16:43:31 +00002964 * Returns maximum time to lock that applied by all profiles in this user. We do this because we
2965 * do not have a separate timeout to lock for work challenge only.
2966 *
2967 * @hide
2968 */
2969 public long getMaximumTimeToLockForUserAndProfiles(int userHandle) {
2970 if (mService != null) {
2971 try {
2972 return mService.getMaximumTimeToLockForUserAndProfiles(userHandle);
2973 } catch (RemoteException e) {
2974 throw e.rethrowFromSystemServer();
2975 }
2976 }
2977 return 0;
2978 }
2979
2980 /**
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002981 * Called by a device/profile owner to set the timeout after which unlocking with secondary, non
2982 * strong auth (e.g. fingerprint, trust agents) times out, i.e. the user has to use a strong
2983 * authentication method like password, pin or pattern.
2984 *
2985 * <p>This timeout is used internally to reset the timer to require strong auth again after
2986 * specified timeout each time it has been successfully used.
2987 *
2988 * <p>Fingerprint can also be disabled altogether using {@link #KEYGUARD_DISABLE_FINGERPRINT}.
2989 *
2990 * <p>Trust agents can also be disabled altogether using {@link #KEYGUARD_DISABLE_TRUST_AGENTS}.
2991 *
2992 * <p>The calling device admin must be a device or profile owner. If it is not,
2993 * a {@link SecurityException} will be thrown.
2994 *
Michal Karpinski943aabd2016-10-06 11:09:25 +01002995 * <p>The calling device admin can verify the value it has set by calling
2996 * {@link #getRequiredStrongAuthTimeout(ComponentName)} and passing in its instance.
2997 *
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002998 * <p>This method can be called on the {@link DevicePolicyManager} instance returned by
2999 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
3000 * profile.
3001 *
3002 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xu5d39ea72017-04-24 20:26:30 +01003003 * @param timeoutMs The new timeout in milliseconds, after which the user will have to unlock
3004 * with strong authentication method. A value of 0 means the admin is not participating
3005 * in controlling the timeout.
Michal Karpinski943aabd2016-10-06 11:09:25 +01003006 * The minimum and maximum timeouts are platform-defined and are typically 1 hour and
3007 * 72 hours, respectively. Though discouraged, the admin may choose to require strong
3008 * auth at all times using {@link #KEYGUARD_DISABLE_FINGERPRINT} and/or
3009 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01003010 *
3011 * @throws SecurityException if {@code admin} is not a device or profile owner.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01003012 */
3013 public void setRequiredStrongAuthTimeout(@NonNull ComponentName admin,
3014 long timeoutMs) {
3015 if (mService != null) {
3016 try {
3017 mService.setRequiredStrongAuthTimeout(admin, timeoutMs, mParentInstance);
3018 } catch (RemoteException e) {
3019 throw e.rethrowFromSystemServer();
3020 }
3021 }
3022 }
3023
3024 /**
3025 * Determine for how long the user will be able to use secondary, non strong auth for
3026 * authentication, since last strong method authentication (password, pin or pattern) was used.
3027 * After the returned timeout the user is required to use strong authentication method.
3028 *
3029 * <p>This method can be called on the {@link DevicePolicyManager} instance
3030 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
3031 * restrictions on the parent profile.
3032 *
3033 * @param admin The name of the admin component to check, or {@code null} to aggregate
3034 * accross all participating admins.
Rubin Xu5d39ea72017-04-24 20:26:30 +01003035 * @return The timeout in milliseconds or 0 if not configured for the provided admin.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01003036 */
3037 public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin) {
3038 return getRequiredStrongAuthTimeout(admin, myUserId());
3039 }
3040
3041 /** @hide per-user version */
3042 public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin, @UserIdInt int userId) {
3043 if (mService != null) {
3044 try {
3045 return mService.getRequiredStrongAuthTimeout(admin, userId, mParentInstance);
3046 } catch (RemoteException e) {
3047 throw e.rethrowFromSystemServer();
3048 }
3049 }
3050 return DEFAULT_STRONG_AUTH_TIMEOUT_MS;
3051 }
3052
3053 /**
Andrew Scull85a63bc2016-10-24 13:47:47 +01003054 * Flag for {@link #lockNow(int)}: also evict the user's credential encryption key from the
3055 * keyring. The user's credential will need to be entered again in order to derive the
3056 * credential encryption key that will be stored back in the keyring for future use.
3057 * <p>
Andrew Scull17e1b5d2017-04-25 14:44:24 +01003058 * This flag can only be used by a profile owner when locking a managed profile when
3059 * {@link #getStorageEncryptionStatus} returns {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}.
Andrew Scull85a63bc2016-10-24 13:47:47 +01003060 * <p>
3061 * In order to secure user data, the user will be stopped and restarted so apps should wait
3062 * until they are next run to perform further actions.
3063 */
Andrew Scull17e1b5d2017-04-25 14:44:24 +01003064 public static final int FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY = 1;
3065
Andrew Scull85a63bc2016-10-24 13:47:47 +01003066 /** @hide */
3067 @Retention(RetentionPolicy.SOURCE)
Andrew Scull17e1b5d2017-04-25 14:44:24 +01003068 @IntDef(flag=true, value={FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY})
Andrew Scull85a63bc2016-10-24 13:47:47 +01003069 public @interface LockNowFlag {}
3070
3071 /**
3072 * Make the device lock immediately, as if the lock screen timeout has expired at the point of
3073 * this call.
3074 * <p>
3075 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
3076 * to be able to call this method; if it has not, a security exception will be thrown.
3077 * <p>
3078 * This method can be called on the {@link DevicePolicyManager} instance returned by
3079 * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile.
3080 * <p>
3081 * Equivalent to calling {@link #lockNow(int)} with no flags.
3082 *
3083 * @throws SecurityException if the calling application does not own an active administrator
3084 * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
3085 */
3086 public void lockNow() {
3087 lockNow(0);
3088 }
3089
3090 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003091 * Make the device lock immediately, as if the lock screen timeout has expired at the point of
3092 * this call.
3093 * <p>
3094 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
3095 * to be able to call this method; if it has not, a security exception will be thrown.
3096 * <p>
3097 * This method can be called on the {@link DevicePolicyManager} instance returned by
3098 * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003099 *
Andrew Scull17e1b5d2017-04-25 14:44:24 +01003100 * @param flags May be 0 or {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003101 * @throws SecurityException if the calling application does not own an active administrator
Andrew Scull85a63bc2016-10-24 13:47:47 +01003102 * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} or the
Andrew Scull17e1b5d2017-04-25 14:44:24 +01003103 * {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY} flag is passed by an application
3104 * that is not a profile
Andrew Scull85a63bc2016-10-24 13:47:47 +01003105 * owner of a managed profile.
Andrew Scull17e1b5d2017-04-25 14:44:24 +01003106 * @throws IllegalArgumentException if the {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY} flag is
3107 * passed when locking the parent profile.
3108 * @throws UnsupportedOperationException if the {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY}
3109 * flag is passed when {@link #getStorageEncryptionStatus} does not return
3110 * {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08003111 */
Andrew Scull85a63bc2016-10-24 13:47:47 +01003112 public void lockNow(@LockNowFlag int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -08003113 if (mService != null) {
3114 try {
Andrew Scull85a63bc2016-10-24 13:47:47 +01003115 mService.lockNow(flags, mParentInstance);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08003116 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003117 throw e.rethrowFromSystemServer();
Dianne Hackborndf83afa2010-01-20 13:37:26 -08003118 }
3119 }
3120 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003121
Dianne Hackbornd6847842010-01-12 18:14:19 -08003122 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07003123 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00003124 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07003125 */
3126 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
3127
3128 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00003129 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
3130 * data.
3131 *
Paul Crowley2934b262014-12-02 11:21:13 +00003132 * <p>This flag may only be set by device owner admins; if it is set by
3133 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00003134 */
3135 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
3136
3137 /**
yinxuf4f9cec2017-06-19 10:28:19 -07003138 * Flag for {@link #wipeData(int)}: also erase the device's eUICC data.
3139 *
3140 * TODO(b/35851809): make this public.
3141 * @hide
3142 */
3143 public static final int WIPE_EUICC = 0x0004;
3144
3145 /**
Suprabh Shukla556b05a2016-08-10 15:49:24 -07003146 * Ask that all user data be wiped. If called as a secondary user, the user will be removed and
3147 * other users will remain unaffected. Calling from the primary user will cause the device to
3148 * reboot, erasing all device data - including all the secondary users and their data - while
3149 * booting up.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003150 * <p>
3151 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to
3152 * be able to call this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003153 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003154 * @param flags Bit mask of additional options: currently supported flags are
3155 * {@link #WIPE_EXTERNAL_STORAGE} and {@link #WIPE_RESET_PROTECTION_DATA}.
3156 * @throws SecurityException if the calling application does not own an active administrator
3157 * that uses {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}
Dianne Hackbornd6847842010-01-12 18:14:19 -08003158 */
3159 public void wipeData(int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003160 throwIfParentInstance("wipeData");
Dianne Hackbornd6847842010-01-12 18:14:19 -08003161 if (mService != null) {
3162 try {
Makoto Onuki70f929e2015-11-11 12:40:15 -08003163 mService.wipeData(flags);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003164 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003165 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003166 }
3167 }
3168 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003169
Dianne Hackbornd6847842010-01-12 18:14:19 -08003170 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07003171 * Called by an application that is administering the device to set the
3172 * global proxy and exclusion list.
3173 * <p>
3174 * The calling device admin must have requested
3175 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
3176 * this method; if it has not, a security exception will be thrown.
3177 * Only the first device admin can set the proxy. If a second admin attempts
3178 * to set the proxy, the {@link ComponentName} of the admin originally setting the
Robin Lee25e26452015-06-02 09:56:29 -07003179 * proxy will be returned. If successful in setting the proxy, {@code null} will
Oscar Montemayor69238c62010-08-03 10:51:06 -07003180 * be returned.
3181 * The method can be called repeatedly by the device admin alrady setting the
3182 * proxy to update the proxy and exclusion list.
3183 *
Robin Lee25e26452015-06-02 09:56:29 -07003184 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Oscar Montemayor69238c62010-08-03 10:51:06 -07003185 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
3186 * Pass Proxy.NO_PROXY to reset the proxy.
3187 * @param exclusionList a list of domains to be excluded from the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07003188 * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName}
3189 * of the device admin that sets the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08003190 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07003191 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003192 public @Nullable ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec,
Oscar Montemayor69238c62010-08-03 10:51:06 -07003193 List<String> exclusionList ) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003194 throwIfParentInstance("setGlobalProxy");
Oscar Montemayor69238c62010-08-03 10:51:06 -07003195 if (proxySpec == null) {
3196 throw new NullPointerException();
3197 }
3198 if (mService != null) {
3199 try {
3200 String hostSpec;
3201 String exclSpec;
3202 if (proxySpec.equals(Proxy.NO_PROXY)) {
3203 hostSpec = null;
3204 exclSpec = null;
3205 } else {
3206 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
3207 throw new IllegalArgumentException();
3208 }
3209 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
3210 String hostName = sa.getHostName();
3211 int port = sa.getPort();
3212 StringBuilder hostBuilder = new StringBuilder();
3213 hostSpec = hostBuilder.append(hostName)
3214 .append(":").append(Integer.toString(port)).toString();
3215 if (exclusionList == null) {
3216 exclSpec = "";
3217 } else {
3218 StringBuilder listBuilder = new StringBuilder();
3219 boolean firstDomain = true;
3220 for (String exclDomain : exclusionList) {
3221 if (!firstDomain) {
3222 listBuilder = listBuilder.append(",");
3223 } else {
3224 firstDomain = false;
3225 }
3226 listBuilder = listBuilder.append(exclDomain.trim());
3227 }
3228 exclSpec = listBuilder.toString();
3229 }
Yuhao Zheng90704842014-02-28 17:22:45 -08003230 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
3231 != android.net.Proxy.PROXY_VALID)
3232 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07003233 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003234 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07003235 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003236 throw e.rethrowFromSystemServer();
Oscar Montemayor69238c62010-08-03 10:51:06 -07003237 }
3238 }
3239 return null;
3240 }
3241
3242 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003243 * Set a network-independent global HTTP proxy. This is not normally what you want for typical
3244 * HTTP proxies - they are generally network dependent. However if you're doing something
3245 * unusual like general internal filtering this may be useful. On a private network where the
3246 * proxy is not accessible, you may break HTTP using this.
3247 * <p>
3248 * This method requires the caller to be the device owner.
3249 * <p>
3250 * This proxy is only a recommendation and it is possible that some apps will ignore it.
Jason Monk03bc9912014-05-13 09:44:57 -04003251 *
Jason Monk03bc9912014-05-13 09:44:57 -04003252 * @see ProxyInfo
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003253 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3254 * @param proxyInfo The a {@link ProxyInfo} object defining the new global HTTP proxy. A
3255 * {@code null} value will clear the global HTTP proxy.
3256 * @throws SecurityException if {@code admin} is not the device owner.
Jason Monk03bc9912014-05-13 09:44:57 -04003257 */
Robin Lee25e26452015-06-02 09:56:29 -07003258 public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo
3259 proxyInfo) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003260 throwIfParentInstance("setRecommendedGlobalProxy");
Jason Monk03bc9912014-05-13 09:44:57 -04003261 if (mService != null) {
3262 try {
3263 mService.setRecommendedGlobalProxy(admin, proxyInfo);
3264 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003265 throw e.rethrowFromSystemServer();
Jason Monk03bc9912014-05-13 09:44:57 -04003266 }
3267 }
3268 }
3269
3270 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07003271 * Returns the component name setting the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07003272 * @return ComponentName object of the device admin that set the global proxy, or {@code null}
3273 * if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08003274 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07003275 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003276 public @Nullable ComponentName getGlobalProxyAdmin() {
Oscar Montemayor69238c62010-08-03 10:51:06 -07003277 if (mService != null) {
3278 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003279 return mService.getGlobalProxyAdmin(myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07003280 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003281 throw e.rethrowFromSystemServer();
Oscar Montemayor69238c62010-08-03 10:51:06 -07003282 }
3283 }
3284 return null;
3285 }
3286
3287 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08003288 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003289 * indicating that encryption is not supported.
3290 */
3291 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
3292
3293 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08003294 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003295 * indicating that encryption is supported, but is not currently active.
3296 */
3297 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
3298
3299 /**
Robin Lee3795fb02015-02-16 14:17:23 +00003300 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003301 * indicating that encryption is not currently active, but is currently
3302 * being activated. This is only reported by devices that support
3303 * encryption of data and only when the storage is currently
3304 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
3305 * to become encrypted will never return this value.
3306 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08003307 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003308
3309 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08003310 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003311 * indicating that encryption is active.
Amith Yamasani75db1252016-07-11 14:41:01 -07003312 * <p>
3313 * Also see {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003314 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08003315 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003316
3317 /**
Robin Lee3795fb02015-02-16 14:17:23 +00003318 * Result code for {@link #getStorageEncryptionStatus}:
3319 * indicating that encryption is active, but an encryption key has not
3320 * been set by the user.
3321 */
3322 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
3323
3324 /**
Makoto Onukid4c9e542016-02-25 18:17:30 -08003325 * Result code for {@link #getStorageEncryptionStatus}:
Amith Yamasani75db1252016-07-11 14:41:01 -07003326 * indicating that encryption is active and the encryption key is tied to the user or profile.
3327 * <p>
3328 * This value is only returned to apps targeting API level 24 and above. For apps targeting
3329 * earlier API levels, {@link #ENCRYPTION_STATUS_ACTIVE} is returned, even if the
3330 * encryption key is specific to the user or profile.
Makoto Onukid4c9e542016-02-25 18:17:30 -08003331 */
3332 public static final int ENCRYPTION_STATUS_ACTIVE_PER_USER = 5;
3333
3334 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003335 * Activity action: begin the process of encrypting data on the device. This activity should
3336 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
3337 * After resuming from this activity, use {@link #getStorageEncryption}
3338 * to check encryption status. However, on some devices this activity may never return, as
3339 * it may trigger a reboot and in some cases a complete data wipe of the device.
3340 */
3341 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
3342 public static final String ACTION_START_ENCRYPTION
3343 = "android.app.action.START_ENCRYPTION";
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003344 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07003345 * Widgets are enabled in keyguard
3346 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07003347 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07003348
3349 /**
Jim Miller50e62182014-04-23 17:25:00 -07003350 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07003351 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07003352 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
3353
3354 /**
3355 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
3356 */
3357 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
3358
3359 /**
Jim Miller50e62182014-04-23 17:25:00 -07003360 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
3361 */
3362 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
3363
3364 /**
3365 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
3366 */
3367 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
3368
3369 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02003370 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07003371 * (e.g. PIN/Pattern/Password).
3372 */
3373 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
3374
3375 /**
Jim Miller06e34502014-07-17 14:46:05 -07003376 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
3377 */
3378 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
3379
3380 /**
Adrian Roos7f06eed2016-02-05 15:21:02 -08003381 * Disable text entry into notifications on secure keyguard screens (e.g. PIN/Pattern/Password).
3382 */
3383 public static final int KEYGUARD_DISABLE_REMOTE_INPUT = 1 << 6;
3384
3385 /**
Jim Miller35207742012-11-02 15:33:20 -07003386 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07003387 */
3388 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07003389
3390 /**
Robin Leeacdeac62017-02-21 22:13:38 +00003391 * Keyguard features that when set on a managed profile that doesn't have its own challenge will
3392 * affect the profile's parent user. These can also be set on the managed profile's parent
3393 * {@link DevicePolicyManager} instance.
3394 *
3395 * @hide
3396 */
3397 public static final int PROFILE_KEYGUARD_FEATURES_AFFECT_OWNER =
3398 DevicePolicyManager.KEYGUARD_DISABLE_TRUST_AGENTS
3399 | DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT;
3400
3401 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003402 * Called by an application that is administering the device to request that the storage system
3403 * be encrypted.
3404 * <p>
3405 * When multiple device administrators attempt to control device encryption, the most secure,
3406 * supported setting will always be used. If any device administrator requests device
3407 * encryption, it will be enabled; Conversely, if a device administrator attempts to disable
3408 * device encryption while another device administrator has enabled it, the call to disable will
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003409 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003410 * <p>
3411 * This policy controls encryption of the secure (application data) storage area. Data written
3412 * to other storage areas may or may not be encrypted, and this policy does not require or
3413 * control the encryption of any other storage areas. There is one exception: If
3414 * {@link android.os.Environment#isExternalStorageEmulated()} is {@code true}, then the
3415 * directory returned by {@link android.os.Environment#getExternalStorageDirectory()} must be
3416 * written to disk within the encrypted storage area.
3417 * <p>
3418 * Important Note: On some devices, it is possible to encrypt storage without requiring the user
3419 * to create a device PIN or Password. In this case, the storage is encrypted, but the
3420 * encryption key may not be fully secured. For maximum security, the administrator should also
3421 * require (and check for) a pattern, PIN, or password.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003422 *
3423 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3424 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08003425 * @return the new request status (for all active admins) - will be one of
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003426 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
3427 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
3428 * {@link #getStorageEncryptionStatus()} to query the actual device state.
3429 * @throws SecurityException if {@code admin} is not an active administrator or does not use
3430 * {@link DeviceAdminInfo#USES_ENCRYPTED_STORAGE}
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003431 */
Robin Lee25e26452015-06-02 09:56:29 -07003432 public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003433 throwIfParentInstance("setStorageEncryption");
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003434 if (mService != null) {
3435 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003436 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003437 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003438 throw e.rethrowFromSystemServer();
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003439 }
3440 }
3441 return ENCRYPTION_STATUS_UNSUPPORTED;
3442 }
3443
3444 /**
3445 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08003446 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003447 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08003448 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
3449 * this will return the requested encryption setting as an aggregate of all active
3450 * administrators.
3451 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003452 */
Robin Lee25e26452015-06-02 09:56:29 -07003453 public boolean getStorageEncryption(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003454 throwIfParentInstance("getStorageEncryption");
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003455 if (mService != null) {
3456 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003457 return mService.getStorageEncryption(admin, myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003458 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003459 throw e.rethrowFromSystemServer();
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003460 }
3461 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08003462 return false;
3463 }
3464
3465 /**
3466 * Called by an application that is administering the device to
3467 * determine the current encryption status of the device.
Amith Yamasani75db1252016-07-11 14:41:01 -07003468 * <p>
Andy Stadler22dbfda2011-01-17 12:47:31 -08003469 * Depending on the returned status code, the caller may proceed in different
3470 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
3471 * storage system does not support encryption. If the
3472 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
3473 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00003474 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
3475 * storage system has enabled encryption but no password is set so further action
Amith Yamasani75db1252016-07-11 14:41:01 -07003476 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING},
3477 * {@link #ENCRYPTION_STATUS_ACTIVE} or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER},
3478 * no further action is required.
Andy Stadler22dbfda2011-01-17 12:47:31 -08003479 *
Robin Lee7e678712014-07-24 16:41:31 +01003480 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08003481 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00003482 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
Amith Yamasani75db1252016-07-11 14:41:01 -07003483 * {@link #ENCRYPTION_STATUS_ACTIVE}, or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08003484 */
3485 public int getStorageEncryptionStatus() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003486 throwIfParentInstance("getStorageEncryptionStatus");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003487 return getStorageEncryptionStatus(myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003488 }
3489
3490 /** @hide per-user version */
3491 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08003492 if (mService != null) {
3493 try {
Makoto Onukid4c9e542016-02-25 18:17:30 -08003494 return mService.getStorageEncryptionStatus(mContext.getPackageName(), userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08003495 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003496 throw e.rethrowFromSystemServer();
Andy Stadler22dbfda2011-01-17 12:47:31 -08003497 }
3498 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003499 return ENCRYPTION_STATUS_UNSUPPORTED;
3500 }
3501
3502 /**
Robin Lee2f7e1e42016-03-21 10:50:01 +00003503 * Mark a CA certificate as approved by the device user. This means that they have been notified
3504 * of the installation, were made aware of the risks, viewed the certificate and still wanted to
3505 * keep the certificate on the device.
3506 *
3507 * Calling with {@param approval} as {@code true} will cancel any ongoing warnings related to
3508 * this certificate.
3509 *
3510 * @hide
3511 */
3512 public boolean approveCaCert(String alias, int userHandle, boolean approval) {
3513 if (mService != null) {
3514 try {
3515 return mService.approveCaCert(alias, userHandle, approval);
3516 } catch (RemoteException e) {
3517 throw e.rethrowFromSystemServer();
3518 }
3519 }
3520 return false;
3521 }
3522
3523 /**
3524 * Check whether a CA certificate has been approved by the device user.
3525 *
3526 * @hide
3527 */
3528 public boolean isCaCertApproved(String alias, int userHandle) {
3529 if (mService != null) {
3530 try {
3531 return mService.isCaCertApproved(alias, userHandle);
3532 } catch (RemoteException e) {
3533 throw e.rethrowFromSystemServer();
3534 }
3535 }
3536 return false;
3537 }
3538
3539 /**
Robin Lee7e678712014-07-24 16:41:31 +01003540 * Installs the given certificate as a user CA.
3541 *
Edman Anjosf9946772016-11-28 16:35:15 +01003542 * The caller must be a profile or device owner on that user, or a delegate package given the
3543 * {@link #DELEGATION_CERT_INSTALL} scope via {@link #setDelegatedScopes}; otherwise a
3544 * security exception will be thrown.
3545 *
Robin Lee25e26452015-06-02 09:56:29 -07003546 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3547 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003548 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04003549 *
3550 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01003551 * interrupted, true otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003552 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3553 * owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003554 * @see #setDelegatedScopes
3555 * @see #DELEGATION_CERT_INSTALL
Maggie Benthallda51e682013-08-08 22:35:44 -04003556 */
Robin Lee25e26452015-06-02 09:56:29 -07003557 public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003558 throwIfParentInstance("installCaCert");
Maggie Benthallda51e682013-08-08 22:35:44 -04003559 if (mService != null) {
3560 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003561 return mService.installCaCert(admin, mContext.getPackageName(), certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04003562 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003563 throw e.rethrowFromSystemServer();
Maggie Benthallda51e682013-08-08 22:35:44 -04003564 }
3565 }
3566 return false;
3567 }
3568
3569 /**
Robin Lee7e678712014-07-24 16:41:31 +01003570 * Uninstalls the given certificate from trusted user CAs, if present.
3571 *
Edman Anjosf9946772016-11-28 16:35:15 +01003572 * The caller must be a profile or device owner on that user, or a delegate package given the
3573 * {@link #DELEGATION_CERT_INSTALL} scope via {@link #setDelegatedScopes}; otherwise a
3574 * security exception will be thrown.
3575 *
Robin Lee25e26452015-06-02 09:56:29 -07003576 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3577 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003578 * @param certBuffer encoded form of the certificate to remove.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003579 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3580 * owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003581 * @see #setDelegatedScopes
3582 * @see #DELEGATION_CERT_INSTALL
Maggie Benthallda51e682013-08-08 22:35:44 -04003583 */
Robin Lee25e26452015-06-02 09:56:29 -07003584 public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003585 throwIfParentInstance("uninstallCaCert");
Maggie Benthallda51e682013-08-08 22:35:44 -04003586 if (mService != null) {
3587 try {
Robin Lee306fe082014-06-19 14:04:24 +00003588 final String alias = getCaCertAlias(certBuffer);
Edman Anjosf9946772016-11-28 16:35:15 +01003589 mService.uninstallCaCerts(admin, mContext.getPackageName(), new String[] {alias});
Robin Lee306fe082014-06-19 14:04:24 +00003590 } catch (CertificateException e) {
3591 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04003592 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003593 throw e.rethrowFromSystemServer();
Maggie Benthallda51e682013-08-08 22:35:44 -04003594 }
3595 }
3596 }
3597
3598 /**
Robin Lee7e678712014-07-24 16:41:31 +01003599 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
3600 * If a user has installed any certificates by other means than device policy these will be
3601 * included too.
3602 *
Robin Lee25e26452015-06-02 09:56:29 -07003603 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3604 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003605 * @return a List of byte[] arrays, each encoding one user CA certificate.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003606 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3607 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04003608 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003609 public @NonNull List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) {
3610 final List<byte[]> certs = new ArrayList<byte[]>();
Benjamin Franzbc33c822016-04-15 08:57:52 +01003611 throwIfParentInstance("getInstalledCaCerts");
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003612 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01003613 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003614 mService.enforceCanManageCaCerts(admin, mContext.getPackageName());
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003615 final TrustedCertificateStore certStore = new TrustedCertificateStore();
3616 for (String alias : certStore.userAliases()) {
3617 try {
3618 certs.add(certStore.getCertificate(alias).getEncoded());
3619 } catch (CertificateException ce) {
3620 Log.w(TAG, "Could not encode certificate: " + alias, ce);
3621 }
3622 }
3623 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003624 throw re.rethrowFromSystemServer();
Robin Lee7e678712014-07-24 16:41:31 +01003625 }
3626 }
3627 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04003628 }
3629
3630 /**
Robin Lee7e678712014-07-24 16:41:31 +01003631 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
3632 * means other than device policy will also be removed, except for system CA certificates.
3633 *
Robin Lee25e26452015-06-02 09:56:29 -07003634 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3635 * {@code null} if calling from a delegated certificate installer.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003636 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3637 * owner.
Robin Lee7e678712014-07-24 16:41:31 +01003638 */
Robin Lee25e26452015-06-02 09:56:29 -07003639 public void uninstallAllUserCaCerts(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003640 throwIfParentInstance("uninstallAllUserCaCerts");
Robin Lee7e678712014-07-24 16:41:31 +01003641 if (mService != null) {
Robin Lee83881bd2015-06-09 16:04:38 -07003642 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003643 mService.uninstallCaCerts(admin, mContext.getPackageName(),
3644 new TrustedCertificateStore().userAliases() .toArray(new String[0]));
Robin Lee83881bd2015-06-09 16:04:38 -07003645 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003646 throw re.rethrowFromSystemServer();
Robin Lee7e678712014-07-24 16:41:31 +01003647 }
3648 }
3649 }
3650
3651 /**
3652 * Returns whether this certificate is installed as a trusted CA.
3653 *
Robin Lee25e26452015-06-02 09:56:29 -07003654 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3655 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003656 * @param certBuffer encoded form of the certificate to look up.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003657 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3658 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04003659 */
Robin Lee25e26452015-06-02 09:56:29 -07003660 public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003661 throwIfParentInstance("hasCaCertInstalled");
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003662 if (mService != null) {
3663 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003664 mService.enforceCanManageCaCerts(admin, mContext.getPackageName());
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003665 return getCaCertAlias(certBuffer) != null;
3666 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003667 throw re.rethrowFromSystemServer();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003668 } catch (CertificateException ce) {
3669 Log.w(TAG, "Could not parse certificate", ce);
3670 }
Maggie Benthallda51e682013-08-08 22:35:44 -04003671 }
3672 return false;
3673 }
3674
3675 /**
Robin Leece3399f2016-02-24 12:08:32 +00003676 * Called by a device or profile owner, or delegated certificate installer, to install a
3677 * certificate and corresponding private key. All apps within the profile will be able to access
3678 * the certificate and use the private key, given direct user approval.
3679 *
3680 * <p>Access to the installed credentials will not be granted to the caller of this API without
3681 * direct user approval. This is for security - should a certificate installer become
3682 * compromised, certificates it had already installed will be protected.
3683 *
3684 * <p>If the installer must have access to the credentials, call
Rubin Xub4365912016-03-23 12:13:22 +00003685 * {@link #installKeyPair(ComponentName, PrivateKey, Certificate[], String, boolean)} instead.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003686 *
Robin Lee25e26452015-06-02 09:56:29 -07003687 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3688 * {@code null} if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003689 * @param privKey The private key to install.
3690 * @param cert The certificate to install.
3691 * @param alias The private key alias under which to install the certificate. If a certificate
3692 * with that alias already exists, it will be overwritten.
3693 * @return {@code true} if the keys were installed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003694 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3695 * owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003696 * @see #setDelegatedScopes
3697 * @see #DELEGATION_CERT_INSTALL
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003698 */
Robin Leefbc65642015-08-03 16:21:22 +01003699 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
3700 @NonNull Certificate cert, @NonNull String alias) {
Rubin Xub4365912016-03-23 12:13:22 +00003701 return installKeyPair(admin, privKey, new Certificate[] {cert}, alias, false);
Robin Leece3399f2016-02-24 12:08:32 +00003702 }
3703
3704 /**
3705 * Called by a device or profile owner, or delegated certificate installer, to install a
Rubin Xub4365912016-03-23 12:13:22 +00003706 * certificate chain and corresponding private key for the leaf certificate. All apps within the
3707 * profile will be able to access the certificate chain and use the private key, given direct
3708 * user approval.
Robin Leece3399f2016-02-24 12:08:32 +00003709 *
Robin Leea1b290e2016-03-09 14:38:36 +00003710 * <p>The caller of this API may grant itself access to the certificate and private key
3711 * immediately, without user approval. It is a best practice not to request this unless strictly
3712 * necessary since it opens up additional security vulnerabilities.
Robin Leece3399f2016-02-24 12:08:32 +00003713 *
3714 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Robin Leea1b290e2016-03-09 14:38:36 +00003715 * {@code null} if calling from a delegated certificate installer.
Robin Leece3399f2016-02-24 12:08:32 +00003716 * @param privKey The private key to install.
Rubin Xub4365912016-03-23 12:13:22 +00003717 * @param certs The certificate chain to install. The chain should start with the leaf
3718 * certificate and include the chain of trust in order. This will be returned by
3719 * {@link android.security.KeyChain#getCertificateChain}.
Robin Leece3399f2016-02-24 12:08:32 +00003720 * @param alias The private key alias under which to install the certificate. If a certificate
Robin Leea1b290e2016-03-09 14:38:36 +00003721 * with that alias already exists, it will be overwritten.
Robin Leece3399f2016-02-24 12:08:32 +00003722 * @param requestAccess {@code true} to request that the calling app be granted access to the
Robin Leea1b290e2016-03-09 14:38:36 +00003723 * credentials immediately. Otherwise, access to the credentials will be gated by user
3724 * approval.
Robin Leece3399f2016-02-24 12:08:32 +00003725 * @return {@code true} if the keys were installed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003726 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3727 * owner.
Rubin Xub4365912016-03-23 12:13:22 +00003728 * @see android.security.KeyChain#getCertificateChain
Edman Anjosf9946772016-11-28 16:35:15 +01003729 * @see #setDelegatedScopes
3730 * @see #DELEGATION_CERT_INSTALL
Robin Leece3399f2016-02-24 12:08:32 +00003731 */
3732 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
Rubin Xub4365912016-03-23 12:13:22 +00003733 @NonNull Certificate[] certs, @NonNull String alias, boolean requestAccess) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003734 throwIfParentInstance("installKeyPair");
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003735 try {
Rubin Xub4365912016-03-23 12:13:22 +00003736 final byte[] pemCert = Credentials.convertToPem(certs[0]);
3737 byte[] pemChain = null;
3738 if (certs.length > 1) {
3739 pemChain = Credentials.convertToPem(Arrays.copyOfRange(certs, 1, certs.length));
3740 }
Robin Lee0d5ccb72014-09-12 17:41:44 +01003741 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
3742 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
Edman Anjosf9946772016-11-28 16:35:15 +01003743 return mService.installKeyPair(admin, mContext.getPackageName(), pkcs8Key, pemCert,
3744 pemChain, alias, requestAccess);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003745 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003746 throw e.rethrowFromSystemServer();
Robin Lee0d5ccb72014-09-12 17:41:44 +01003747 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
3748 Log.w(TAG, "Failed to obtain private key material", e);
3749 } catch (CertificateException | IOException e) {
3750 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003751 }
3752 return false;
3753 }
3754
3755 /**
Robin Leea1b290e2016-03-09 14:38:36 +00003756 * Called by a device or profile owner, or delegated certificate installer, to remove a
3757 * certificate and private key pair installed under a given alias.
Robin Leefbc65642015-08-03 16:21:22 +01003758 *
3759 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Robin Leea1b290e2016-03-09 14:38:36 +00003760 * {@code null} if calling from a delegated certificate installer.
Robin Leefbc65642015-08-03 16:21:22 +01003761 * @param alias The private key alias under which the certificate is installed.
Robin Leea1b290e2016-03-09 14:38:36 +00003762 * @return {@code true} if the private key alias no longer exists, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003763 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3764 * owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003765 * @see #setDelegatedScopes
3766 * @see #DELEGATION_CERT_INSTALL
Robin Leefbc65642015-08-03 16:21:22 +01003767 */
3768 public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003769 throwIfParentInstance("removeKeyPair");
Robin Leefbc65642015-08-03 16:21:22 +01003770 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003771 return mService.removeKeyPair(admin, mContext.getPackageName(), alias);
Robin Leefbc65642015-08-03 16:21:22 +01003772 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003773 throw e.rethrowFromSystemServer();
Robin Leefbc65642015-08-03 16:21:22 +01003774 }
Robin Leefbc65642015-08-03 16:21:22 +01003775 }
3776
3777 /**
Robin Lee25e26452015-06-02 09:56:29 -07003778 * @return the alias of a given CA certificate in the certificate store, or {@code null} if it
Robin Lee306fe082014-06-19 14:04:24 +00003779 * doesn't exist.
3780 */
3781 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
3782 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
3783 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
3784 new ByteArrayInputStream(certBuffer));
3785 return new TrustedCertificateStore().getCertificateAlias(cert);
3786 }
3787
3788 /**
Rubin Xuec32b562015-03-03 17:34:05 +00003789 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01003790 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00003791 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01003792 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00003793 * <p>
3794 * Delegated certificate installer is a per-user state. The delegated access is persistent until
3795 * it is later cleared by calling this method with a null value or uninstallling the certificate
3796 * installer.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003797 * <p>
Rubin Xuf03d0a62016-02-10 14:54:15 +00003798 * <b>Note:</b>Starting from {@link android.os.Build.VERSION_CODES#N}, if the caller
3799 * application's target SDK version is {@link android.os.Build.VERSION_CODES#N} or newer, the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003800 * supplied certificate installer package must be installed when calling this API, otherwise an
3801 * {@link IllegalArgumentException} will be thrown.
Rubin Xuec32b562015-03-03 17:34:05 +00003802 *
Robin Lee25e26452015-06-02 09:56:29 -07003803 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xuec32b562015-03-03 17:34:05 +00003804 * @param installerPackage The package name of the certificate installer which will be given
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003805 * access. If {@code null} is given the current package will be cleared.
3806 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003807 *
3808 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #setDelegatedScopes}
3809 * with the {@link #DELEGATION_CERT_INSTALL} scope instead.
Rubin Xuec32b562015-03-03 17:34:05 +00003810 */
Edman Anjosf9946772016-11-28 16:35:15 +01003811 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07003812 public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String
3813 installerPackage) throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003814 throwIfParentInstance("setCertInstallerPackage");
Rubin Xuec32b562015-03-03 17:34:05 +00003815 if (mService != null) {
3816 try {
Robin Lee25e26452015-06-02 09:56:29 -07003817 mService.setCertInstallerPackage(admin, installerPackage);
Rubin Xuec32b562015-03-03 17:34:05 +00003818 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003819 throw e.rethrowFromSystemServer();
Rubin Xuec32b562015-03-03 17:34:05 +00003820 }
3821 }
3822 }
3823
3824 /**
Edman Anjosf9946772016-11-28 16:35:15 +01003825 * Called by a profile owner or device owner to retrieve the certificate installer for the user,
3826 * or {@code null} if none is set. If there are multiple delegates this function will return one
3827 * of them.
Rubin Xuec32b562015-03-03 17:34:05 +00003828 *
Robin Lee25e26452015-06-02 09:56:29 -07003829 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003830 * @return The package name of the current delegated certificate installer, or {@code null} if
3831 * none is set.
3832 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003833 *
3834 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatePackages}
3835 * with the {@link #DELEGATION_CERT_INSTALL} scope instead.
Rubin Xuec32b562015-03-03 17:34:05 +00003836 */
Edman Anjosf9946772016-11-28 16:35:15 +01003837 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07003838 public @Nullable String getCertInstallerPackage(@NonNull ComponentName admin)
3839 throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003840 throwIfParentInstance("getCertInstallerPackage");
Rubin Xuec32b562015-03-03 17:34:05 +00003841 if (mService != null) {
3842 try {
Robin Lee25e26452015-06-02 09:56:29 -07003843 return mService.getCertInstallerPackage(admin);
Rubin Xuec32b562015-03-03 17:34:05 +00003844 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003845 throw e.rethrowFromSystemServer();
Rubin Xuec32b562015-03-03 17:34:05 +00003846 }
3847 }
3848 return null;
3849 }
3850
3851 /**
Edman Anjosf9946772016-11-28 16:35:15 +01003852 * Called by a profile owner or device owner to grant access to privileged APIs to another app.
3853 * Granted APIs are determined by {@code scopes}, which is a list of the {@code DELEGATION_*}
3854 * constants.
3855 * <p>
Edman Anjos9e62c312017-01-26 22:22:58 +01003856 * A broadcast with the {@link #ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED} action will be
3857 * sent to the {@code delegatePackage} with its new scopes in an {@code ArrayList<String>} extra
3858 * under the {@link #EXTRA_DELEGATION_SCOPES} key. The broadcast is sent with the
3859 * {@link Intent#FLAG_RECEIVER_REGISTERED_ONLY} flag.
3860 * <p>
Edman Anjosf9946772016-11-28 16:35:15 +01003861 * Delegated scopes are a per-user state. The delegated access is persistent until it is later
3862 * cleared by calling this method with an empty {@code scopes} list or uninstalling the
3863 * {@code delegatePackage}.
3864 *
3865 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3866 * @param delegatePackage The package name of the app which will be given access.
3867 * @param scopes The groups of privileged APIs whose access should be granted to
3868 * {@code delegatedPackage}.
3869 * @throws SecurityException if {@code admin} is not a device or a profile owner.
3870 */
3871 public void setDelegatedScopes(@NonNull ComponentName admin, @NonNull String delegatePackage,
3872 @NonNull List<String> scopes) {
3873 throwIfParentInstance("setDelegatedScopes");
3874 if (mService != null) {
3875 try {
3876 mService.setDelegatedScopes(admin, delegatePackage, scopes);
3877 } catch (RemoteException e) {
3878 throw e.rethrowFromSystemServer();
3879 }
3880 }
3881 }
3882
3883 /**
3884 * Called by a profile owner or device owner to retrieve a list of the scopes given to a
3885 * delegate package. Other apps can use this method to retrieve their own delegated scopes by
3886 * passing {@code null} for {@code admin} and their own package name as
3887 * {@code delegatedPackage}.
3888 *
3889 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3890 * {@code null} if the caller is {@code delegatedPackage}.
3891 * @param delegatedPackage The package name of the app whose scopes should be retrieved.
3892 * @return A list containing the scopes given to {@code delegatedPackage}.
3893 * @throws SecurityException if {@code admin} is not a device or a profile owner.
3894 */
3895 @NonNull
Edman Anjos9e62c312017-01-26 22:22:58 +01003896 public List<String> getDelegatedScopes(@Nullable ComponentName admin,
Edman Anjosf9946772016-11-28 16:35:15 +01003897 @NonNull String delegatedPackage) {
3898 throwIfParentInstance("getDelegatedScopes");
3899 if (mService != null) {
3900 try {
3901 return mService.getDelegatedScopes(admin, delegatedPackage);
3902 } catch (RemoteException e) {
3903 throw e.rethrowFromSystemServer();
3904 }
3905 }
3906 return null;
3907 }
3908
3909 /**
3910 * Called by a profile owner or device owner to retrieve a list of delegate packages that were
3911 * granted a delegation scope.
3912 *
3913 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3914 * @param delegationScope The scope whose delegates should be retrieved.
3915 * @return A list of package names of the current delegated packages for
3916 {@code delegationScope}.
3917 * @throws SecurityException if {@code admin} is not a device or a profile owner.
3918 */
3919 @Nullable
3920 public List<String> getDelegatePackages(@NonNull ComponentName admin,
3921 @NonNull String delegationScope) {
3922 throwIfParentInstance("getDelegatePackages");
3923 if (mService != null) {
3924 try {
3925 return mService.getDelegatePackages(admin, delegationScope);
3926 } catch (RemoteException e) {
3927 throw e.rethrowFromSystemServer();
3928 }
3929 }
3930 return null;
3931 }
3932
3933 /**
Robin Lee244ce8e2016-01-05 18:03:46 +00003934 * Called by a device or profile owner to configure an always-on VPN connection through a
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003935 * specific application for the current user. This connection is automatically granted and
3936 * persisted after a reboot.
3937 * <p>
Charles He36738632017-05-15 17:07:18 +01003938 * To support the always-on feature, an app must
3939 * <ul>
3940 * <li>declare a {@link android.net.VpnService} in its manifest, guarded by
3941 * {@link android.Manifest.permission#BIND_VPN_SERVICE};</li>
3942 * <li>target {@link android.os.Build.VERSION_CODES#N API 24} or above; and</li>
3943 * <li><i>not</i> explicitly opt out of the feature through
Charles Hec57a01c2017-08-15 15:30:22 +01003944 * {@link android.net.VpnService#SERVICE_META_DATA_SUPPORTS_ALWAYS_ON}.</li>
Charles He36738632017-05-15 17:07:18 +01003945 * </ul>
3946 * The call will fail if called with the package name of an unsupported VPN app.
Robin Lee244ce8e2016-01-05 18:03:46 +00003947 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003948 * @param vpnPackage The package name for an installed VPN app on the device, or {@code null} to
Robin Leedc679712016-05-03 13:23:03 +01003949 * remove an existing always-on VPN configuration.
3950 * @param lockdownEnabled {@code true} to disallow networking when the VPN is not connected or
3951 * {@code false} otherwise. This carries the risk that any failure of the VPN provider
3952 * could break networking for all apps. This has no effect when clearing.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003953 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Robin Leeee5eb932016-04-05 16:27:15 +01003954 * @throws NameNotFoundException if {@code vpnPackage} is not installed.
3955 * @throws UnsupportedOperationException if {@code vpnPackage} exists but does not support being
3956 * set as always-on, or if always-on VPN is not available.
Robin Lee244ce8e2016-01-05 18:03:46 +00003957 */
Robin Leedc679712016-05-03 13:23:03 +01003958 public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage,
3959 boolean lockdownEnabled)
Robin Leeee5eb932016-04-05 16:27:15 +01003960 throws NameNotFoundException, UnsupportedOperationException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003961 throwIfParentInstance("setAlwaysOnVpnPackage");
Robin Lee244ce8e2016-01-05 18:03:46 +00003962 if (mService != null) {
3963 try {
Robin Leedc679712016-05-03 13:23:03 +01003964 if (!mService.setAlwaysOnVpnPackage(admin, vpnPackage, lockdownEnabled)) {
Robin Leeee5eb932016-04-05 16:27:15 +01003965 throw new NameNotFoundException(vpnPackage);
3966 }
Robin Lee244ce8e2016-01-05 18:03:46 +00003967 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003968 throw e.rethrowFromSystemServer();
Robin Lee244ce8e2016-01-05 18:03:46 +00003969 }
3970 }
Robin Lee244ce8e2016-01-05 18:03:46 +00003971 }
3972
3973 /**
3974 * Called by a device or profile owner to read the name of the package administering an
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003975 * always-on VPN connection for the current user. If there is no such package, or the always-on
3976 * VPN is provided by the system instead of by an application, {@code null} will be returned.
Robin Lee244ce8e2016-01-05 18:03:46 +00003977 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003978 * @return Package name of VPN controller responsible for always-on VPN, or {@code null} if none
3979 * is set.
3980 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Robin Lee244ce8e2016-01-05 18:03:46 +00003981 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003982 public @Nullable String getAlwaysOnVpnPackage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003983 throwIfParentInstance("getAlwaysOnVpnPackage");
Robin Lee244ce8e2016-01-05 18:03:46 +00003984 if (mService != null) {
3985 try {
3986 return mService.getAlwaysOnVpnPackage(admin);
3987 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003988 throw e.rethrowFromSystemServer();
Robin Lee244ce8e2016-01-05 18:03:46 +00003989 }
3990 }
3991 return null;
3992 }
3993
3994 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003995 * Called by an application that is administering the device to disable all cameras on the
3996 * device, for this user. After setting this, no applications running as this user will be able
3997 * to access any cameras on the device.
3998 * <p>
3999 * If the caller is device owner, then the restriction will be applied to all users.
4000 * <p>
4001 * The calling device admin must have requested
4002 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call this method; if it has
4003 * not, a security exception will be thrown.
Ben Komalo2447edd2011-05-09 16:05:33 -07004004 *
4005 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4006 * @param disabled Whether or not the camera should be disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004007 * @throws SecurityException if {@code admin} is not an active administrator or does not use
4008 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA}.
Ben Komalo2447edd2011-05-09 16:05:33 -07004009 */
Robin Lee25e26452015-06-02 09:56:29 -07004010 public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004011 throwIfParentInstance("setCameraDisabled");
Ben Komalo2447edd2011-05-09 16:05:33 -07004012 if (mService != null) {
4013 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08004014 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07004015 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004016 throw e.rethrowFromSystemServer();
Ben Komalo2447edd2011-05-09 16:05:33 -07004017 }
4018 }
4019 }
4020
4021 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07004022 * Determine whether or not the device's cameras have been disabled for this user,
Makoto Onuki32b30572015-12-11 14:29:51 -08004023 * either by the calling admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07004024 * @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 -07004025 * have disabled the camera
4026 */
Robin Lee25e26452015-06-02 09:56:29 -07004027 public boolean getCameraDisabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004028 throwIfParentInstance("getCameraDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004029 return getCameraDisabled(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004030 }
4031
4032 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07004033 public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07004034 if (mService != null) {
4035 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004036 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07004037 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004038 throw e.rethrowFromSystemServer();
Ben Komalo2447edd2011-05-09 16:05:33 -07004039 }
4040 }
4041 return false;
4042 }
4043
4044 /**
Michal Karpinski3fc437e2015-12-15 10:09:00 +00004045 * Called by a device owner to request a bugreport.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004046 * <p>
Esteban Talaverad36dd152016-12-15 08:51:45 +00004047 * If the device contains secondary users or profiles, they must be affiliated with the device
4048 * owner user. Otherwise a {@link SecurityException} will be thrown. See
4049 * {@link #setAffiliationIds}.
Michal Karpinski3fc437e2015-12-15 10:09:00 +00004050 *
4051 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004052 * @return {@code true} if the bugreport collection started successfully, or {@code false} if it
4053 * wasn't triggered because a previous bugreport operation is still active (either the
4054 * bugreport is still running or waiting for the user to share or decline)
Esteban Talaverad36dd152016-12-15 08:51:45 +00004055 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
4056 * profile or secondary user that is not affiliated with the device owner user.
Michal Karpinski3fc437e2015-12-15 10:09:00 +00004057 */
4058 public boolean requestBugreport(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004059 throwIfParentInstance("requestBugreport");
Michal Karpinski3fc437e2015-12-15 10:09:00 +00004060 if (mService != null) {
4061 try {
4062 return mService.requestBugreport(admin);
4063 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004064 throw e.rethrowFromSystemServer();
Michal Karpinski3fc437e2015-12-15 10:09:00 +00004065 }
4066 }
4067 return false;
4068 }
4069
4070 /**
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07004071 * Determine whether or not creating a guest user has been disabled for the device
4072 *
4073 * @hide
4074 */
4075 public boolean getGuestUserDisabled(@Nullable ComponentName admin) {
4076 // Currently guest users can always be created if multi-user is enabled
4077 // TODO introduce a policy for guest user creation
4078 return false;
4079 }
4080
4081 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01004082 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
4083 * screen capture also prevents the content from being shown on display devices that do not have
4084 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
4085 * secure surfaces and secure displays.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004086 * <p>
4087 * The calling device admin must be a device or profile owner. If it is not, a security
4088 * exception will be thrown.
4089 * <p>
4090 * From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also blocks
4091 * assist requests for all activities of the relevant user.
Benjamin Franzc200f442015-06-25 18:20:04 +01004092 *
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004093 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004094 * @param disabled Whether screen capture is disabled or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004095 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004096 */
Robin Lee25e26452015-06-02 09:56:29 -07004097 public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004098 throwIfParentInstance("setScreenCaptureDisabled");
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004099 if (mService != null) {
4100 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08004101 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004102 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004103 throw e.rethrowFromSystemServer();
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004104 }
4105 }
4106 }
4107
4108 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004109 * Determine whether or not screen capture has been disabled by the calling
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004110 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07004111 * @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 +01004112 * have disabled screen capture.
4113 */
Robin Lee25e26452015-06-02 09:56:29 -07004114 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004115 throwIfParentInstance("getScreenCaptureDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004116 return getScreenCaptureDisabled(admin, myUserId());
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004117 }
4118
4119 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07004120 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004121 if (mService != null) {
4122 try {
4123 return mService.getScreenCaptureDisabled(admin, userHandle);
4124 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004125 throw e.rethrowFromSystemServer();
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004126 }
4127 }
4128 return false;
4129 }
4130
4131 /**
Jason Parks841cb0a2017-01-17 15:25:17 -06004132 * Called by a device or profile owner to set whether auto time is required. If auto time is
4133 * 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 -07004134 * <p>
4135 * Note: if auto time is required the user can still manually set the time zone.
4136 * <p>
Jason Parks841cb0a2017-01-17 15:25:17 -06004137 * The calling device admin must be a device or profile owner. If it is not, a security
4138 * exception will be thrown.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004139 *
4140 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4141 * @param required Whether auto time is set required or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004142 * @throws SecurityException if {@code admin} is not a device owner.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004143 */
Robin Lee25e26452015-06-02 09:56:29 -07004144 public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004145 throwIfParentInstance("setAutoTimeRequired");
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004146 if (mService != null) {
4147 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08004148 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004149 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004150 throw e.rethrowFromSystemServer();
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004151 }
4152 }
4153 }
4154
4155 /**
4156 * @return true if auto time is required.
4157 */
4158 public boolean getAutoTimeRequired() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004159 throwIfParentInstance("getAutoTimeRequired");
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004160 if (mService != null) {
4161 try {
4162 return mService.getAutoTimeRequired();
4163 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004164 throw e.rethrowFromSystemServer();
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004165 }
4166 }
4167 return false;
4168 }
4169
4170 /**
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004171 * Called by a device owner to set whether all users created on the device should be ephemeral.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004172 * <p>
4173 * The system user is exempt from this policy - it is never ephemeral.
4174 * <p>
4175 * The calling device admin must be the device owner. If it is not, a security exception will be
4176 * thrown.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004177 *
4178 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4179 * @param forceEphemeralUsers If true, all the existing users will be deleted and all
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004180 * subsequently created users will be ephemeral.
4181 * @throws SecurityException if {@code admin} is not a device owner.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004182 * @hide
4183 */
4184 public void setForceEphemeralUsers(
4185 @NonNull ComponentName admin, boolean forceEphemeralUsers) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004186 throwIfParentInstance("setForceEphemeralUsers");
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004187 if (mService != null) {
4188 try {
4189 mService.setForceEphemeralUsers(admin, forceEphemeralUsers);
4190 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004191 throw e.rethrowFromSystemServer();
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004192 }
4193 }
4194 }
4195
4196 /**
4197 * @return true if all users are created ephemeral.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004198 * @throws SecurityException if {@code admin} is not a device owner.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004199 * @hide
4200 */
4201 public boolean getForceEphemeralUsers(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004202 throwIfParentInstance("getForceEphemeralUsers");
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004203 if (mService != null) {
4204 try {
4205 return mService.getForceEphemeralUsers(admin);
4206 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004207 throw e.rethrowFromSystemServer();
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004208 }
4209 }
4210 return false;
4211 }
4212
4213 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07004214 * Called by an application that is administering the device to disable keyguard customizations,
4215 * such as widgets. After setting this, keyguard features will be disabled according to the
4216 * provided feature list.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004217 * <p>
4218 * The calling device admin must have requested
4219 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method;
4220 * if it has not, a security exception will be thrown.
4221 * <p>
4222 * Calling this from a managed profile before version {@link android.os.Build.VERSION_CODES#M}
4223 * will throw a security exception. From version {@link android.os.Build.VERSION_CODES#M} the
4224 * profile owner of a managed profile can set:
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00004225 * <ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00004226 * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which affects the parent user, but only if there
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004227 * is no separate challenge set on the managed profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00004228 * <li>{@link #KEYGUARD_DISABLE_FINGERPRINT} which affects the managed profile challenge if
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004229 * there is one, or the parent user otherwise.
4230 * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} which affects notifications generated
4231 * by applications in the managed profile.
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00004232 * </ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00004233 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} and {@link #KEYGUARD_DISABLE_FINGERPRINT} can also be
4234 * set on the {@link DevicePolicyManager} instance returned by
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004235 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
4236 * profile.
4237 * <p>
4238 * Requests to disable other features on a managed profile will be ignored.
4239 * <p>
4240 * The admin can check which features have been disabled by calling
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00004241 * {@link #getKeyguardDisabledFeatures(ComponentName)}
Amith Yamasani242f4b12014-10-14 16:06:13 -07004242 *
Jim Millerb8ec4702012-08-31 17:19:10 -07004243 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07004244 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004245 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
4246 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS},
4247 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
4248 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS},
4249 * {@link #KEYGUARD_DISABLE_FINGERPRINT}, {@link #KEYGUARD_DISABLE_FEATURES_ALL}
4250 * @throws SecurityException if {@code admin} is not an active administrator or does not user
4251 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES}
Jim Millerb8ec4702012-08-31 17:19:10 -07004252 */
Robin Lee25e26452015-06-02 09:56:29 -07004253 public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07004254 if (mService != null) {
4255 try {
Esteban Talavera62399912016-01-11 15:37:55 +00004256 mService.setKeyguardDisabledFeatures(admin, which, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07004257 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004258 throw e.rethrowFromSystemServer();
Jim Millerb8ec4702012-08-31 17:19:10 -07004259 }
4260 }
4261 }
4262
4263 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004264 * Determine whether or not features have been disabled in keyguard either by the calling
Rubin Xud3609d42016-07-13 18:32:57 +01004265 * admin, if specified, or all admins that set restrictions on this user and its participating
Esteban Talaverac1c83592016-02-17 17:56:15 +00004266 * profiles. Restrictions on profiles that have a separate challenge are not taken into account.
4267 *
4268 * <p>This method can be called on the {@link DevicePolicyManager} instance
4269 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
4270 * restrictions on the parent profile.
4271 *
Esteban Talavera62399912016-01-11 15:37:55 +00004272 * @param admin The name of the admin component to check, or {@code null} to check whether any
4273 * admins have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07004274 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
4275 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07004276 */
Robin Lee25e26452015-06-02 09:56:29 -07004277 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004278 return getKeyguardDisabledFeatures(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004279 }
4280
4281 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07004282 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07004283 if (mService != null) {
4284 try {
Esteban Talavera62399912016-01-11 15:37:55 +00004285 return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07004286 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004287 throw e.rethrowFromSystemServer();
Jim Millerb8ec4702012-08-31 17:19:10 -07004288 }
4289 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07004290 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07004291 }
4292
4293 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08004294 * @hide
4295 */
Robin Lee25e26452015-06-02 09:56:29 -07004296 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
4297 int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08004298 if (mService != null) {
4299 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01004300 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08004301 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004302 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08004303 }
4304 }
4305 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07004306
Dianne Hackbornd6847842010-01-12 18:14:19 -08004307 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01004308 * @hide
4309 */
Robin Lee25e26452015-06-02 09:56:29 -07004310 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004311 setActiveAdmin(policyReceiver, refreshing, myUserId());
Jessica Hummel6d36b602014-04-04 12:42:17 +01004312 }
4313
4314 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08004315 * @hide
4316 */
Robin Lee25e26452015-06-02 09:56:29 -07004317 public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08004318 if (mService != null) {
4319 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004320 mService.getRemoveWarning(admin, result, myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08004321 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004322 throw e.rethrowFromSystemServer();
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08004323 }
4324 }
4325 }
4326
4327 /**
4328 * @hide
4329 */
Andrew Scull5f9e6f32016-08-02 14:22:17 +01004330 public void setActivePasswordState(PasswordMetrics metrics, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08004331 if (mService != null) {
4332 try {
Andrew Scull5f9e6f32016-08-02 14:22:17 +01004333 mService.setActivePasswordState(metrics, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08004334 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004335 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08004336 }
4337 }
4338 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07004339
Dianne Hackbornd6847842010-01-12 18:14:19 -08004340 /**
4341 * @hide
4342 */
Andrew Scull5daf2732016-11-14 15:02:45 +00004343 public void reportPasswordChanged(@UserIdInt int userId) {
4344 if (mService != null) {
4345 try {
4346 mService.reportPasswordChanged(userId);
4347 } catch (RemoteException e) {
4348 throw e.rethrowFromSystemServer();
4349 }
4350 }
4351 }
4352
4353 /**
4354 * @hide
4355 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004356 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08004357 if (mService != null) {
4358 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004359 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08004360 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004361 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08004362 }
4363 }
4364 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07004365
Dianne Hackbornd6847842010-01-12 18:14:19 -08004366 /**
4367 * @hide
4368 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004369 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08004370 if (mService != null) {
4371 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004372 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08004373 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004374 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08004375 }
4376 }
4377 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07004378
4379 /**
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004380 * @hide
4381 */
4382 public void reportFailedFingerprintAttempt(int userHandle) {
4383 if (mService != null) {
4384 try {
4385 mService.reportFailedFingerprintAttempt(userHandle);
4386 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004387 throw e.rethrowFromSystemServer();
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004388 }
4389 }
4390 }
4391
4392 /**
4393 * @hide
4394 */
4395 public void reportSuccessfulFingerprintAttempt(int userHandle) {
4396 if (mService != null) {
4397 try {
4398 mService.reportSuccessfulFingerprintAttempt(userHandle);
4399 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004400 throw e.rethrowFromSystemServer();
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004401 }
4402 }
4403 }
4404
4405 /**
Michal Karpinski31502d32016-01-25 16:43:07 +00004406 * Should be called when keyguard has been dismissed.
4407 * @hide
4408 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004409 public void reportKeyguardDismissed(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00004410 if (mService != null) {
4411 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004412 mService.reportKeyguardDismissed(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00004413 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004414 throw e.rethrowFromSystemServer();
Michal Karpinski31502d32016-01-25 16:43:07 +00004415 }
4416 }
4417 }
4418
4419 /**
4420 * Should be called when keyguard view has been shown to the user.
4421 * @hide
4422 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004423 public void reportKeyguardSecured(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00004424 if (mService != null) {
4425 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004426 mService.reportKeyguardSecured(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00004427 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004428 throw e.rethrowFromSystemServer();
Michal Karpinski31502d32016-01-25 16:43:07 +00004429 }
4430 }
4431 }
4432
4433 /**
Amith Yamasani71e6c692013-03-24 17:39:28 -07004434 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00004435 * Sets the given package as the device owner.
Makoto Onukia52562c2015-10-01 16:12:31 -07004436 * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name.
4437 * @param who the component name to be registered as device owner.
Amith Yamasani71e6c692013-03-24 17:39:28 -07004438 * @return whether the package was successfully registered as the device owner.
4439 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00004440 * @throws IllegalStateException If the preconditions mentioned are not met.
Amith Yamasani71e6c692013-03-24 17:39:28 -07004441 */
Makoto Onukia52562c2015-10-01 16:12:31 -07004442 public boolean setDeviceOwner(ComponentName who) {
4443 return setDeviceOwner(who, null);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004444 }
4445
4446 /**
4447 * @hide
Makoto Onuki58b684f2015-09-04 10:48:16 -07004448 */
Makoto Onukia52562c2015-10-01 16:12:31 -07004449 public boolean setDeviceOwner(ComponentName who, int userId) {
4450 return setDeviceOwner(who, null, userId);
Makoto Onuki58b684f2015-09-04 10:48:16 -07004451 }
4452
4453 /**
4454 * @hide
4455 */
Makoto Onukia52562c2015-10-01 16:12:31 -07004456 public boolean setDeviceOwner(ComponentName who, String ownerName) {
4457 return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM);
Makoto Onuki58b684f2015-09-04 10:48:16 -07004458 }
4459
4460 /**
4461 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00004462 * Sets the given package as the device owner. The package must already be installed. There
4463 * must not already be a device owner.
4464 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
4465 * this method.
4466 * Calling this after the setup phase of the primary user has completed is allowed only if
4467 * the caller is the shell uid, and there are no additional users and no accounts.
Makoto Onukia52562c2015-10-01 16:12:31 -07004468 * @param who the component name to be registered as device owner.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004469 * @param ownerName the human readable name of the institution that owns this device.
Makoto Onuki58b684f2015-09-04 10:48:16 -07004470 * @param userId ID of the user on which the device owner runs.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004471 * @return whether the package was successfully registered as the device owner.
4472 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00004473 * @throws IllegalStateException If the preconditions mentioned are not met.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004474 */
Makoto Onukia52562c2015-10-01 16:12:31 -07004475 public boolean setDeviceOwner(ComponentName who, String ownerName, int userId)
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004476 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07004477 if (mService != null) {
4478 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07004479 return mService.setDeviceOwner(who, ownerName, userId);
Amith Yamasani71e6c692013-03-24 17:39:28 -07004480 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004481 throw re.rethrowFromSystemServer();
Amith Yamasani71e6c692013-03-24 17:39:28 -07004482 }
4483 }
4484 return false;
4485 }
4486
4487 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004488 * Used to determine if a particular package has been registered as a Device Owner app.
4489 * A device owner app is a special device admin that cannot be deactivated by the user, once
Robin Lee25e26452015-06-02 09:56:29 -07004490 * activated as a device admin. It also cannot be uninstalled. To check whether a particular
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004491 * package is currently registered as the device owner app, pass in the package name from
4492 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
Robin Lee25e26452015-06-02 09:56:29 -07004493 * admin apps that want to check whether they are also registered as the device owner app. The
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004494 * exact mechanism by which a device admin app is registered as a device owner app is defined by
4495 * the setup process.
4496 * @param packageName the package name of the app, to compare with the registered device owner
4497 * app, if any.
Makoto Onukic8a5a552015-11-19 14:29:12 -08004498 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07004499 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004500 public boolean isDeviceOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004501 throwIfParentInstance("isDeviceOwnerApp");
Makoto Onukic8a5a552015-11-19 14:29:12 -08004502 return isDeviceOwnerAppOnCallingUser(packageName);
4503 }
4504
4505 /**
4506 * @return true if a package is registered as device owner, only when it's running on the
4507 * calling user.
4508 *
4509 * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity.
4510 * @hide
4511 */
4512 public boolean isDeviceOwnerAppOnCallingUser(String packageName) {
4513 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true);
4514 }
4515
4516 /**
4517 * @return true if a package is registered as device owner, even if it's running on a different
4518 * user.
4519 *
4520 * <p>Requires the MANAGE_USERS permission.
4521 *
4522 * @hide
4523 */
4524 public boolean isDeviceOwnerAppOnAnyUser(String packageName) {
4525 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false);
4526 }
4527
4528 /**
4529 * @return device owner component name, only when it's running on the calling user.
4530 *
4531 * @hide
4532 */
4533 public ComponentName getDeviceOwnerComponentOnCallingUser() {
4534 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true);
4535 }
4536
4537 /**
4538 * @return device owner component name, even if it's running on a different user.
4539 *
Makoto Onukic8a5a552015-11-19 14:29:12 -08004540 * @hide
4541 */
Polina Bondarenko23561db2016-12-16 11:47:28 +01004542 @SystemApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06004543 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Makoto Onukic8a5a552015-11-19 14:29:12 -08004544 public ComponentName getDeviceOwnerComponentOnAnyUser() {
4545 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false);
4546 }
4547
4548 private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) {
Makoto Onuki70f929e2015-11-11 12:40:15 -08004549 if (packageName == null) {
4550 return false;
Amith Yamasani71e6c692013-03-24 17:39:28 -07004551 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08004552 final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly);
Makoto Onuki70f929e2015-11-11 12:40:15 -08004553 if (deviceOwner == null) {
4554 return false;
4555 }
4556 return packageName.equals(deviceOwner.getPackageName());
Amith Yamasani71e6c692013-03-24 17:39:28 -07004557 }
4558
Makoto Onukic8a5a552015-11-19 14:29:12 -08004559 private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) {
4560 if (mService != null) {
4561 try {
4562 return mService.getDeviceOwnerComponent(callingUserOnly);
4563 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004564 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08004565 }
4566 }
4567 return null;
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004568 }
4569
Jason Monkb0dced82014-06-06 14:36:20 -04004570 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08004571 * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's
4572 * no device owner.
4573 *
4574 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07004575 *
4576 * @hide
4577 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08004578 public int getDeviceOwnerUserId() {
4579 if (mService != null) {
4580 try {
4581 return mService.getDeviceOwnerUserId();
4582 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004583 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08004584 }
4585 }
4586 return UserHandle.USER_NULL;
Makoto Onukia52562c2015-10-01 16:12:31 -07004587 }
4588
4589 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004590 * Clears the current device owner. The caller must be the device owner. This function should be
4591 * 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 +00004592 * a part of device setup, before it completes.
4593 * <p>
4594 * While some policies previously set by the device owner will be cleared by this method, it is
4595 * a best-effort process and some other policies will still remain in place after the device
4596 * owner is cleared.
Jason Monk94d2cf92014-06-18 09:53:34 -04004597 *
4598 * @param packageName The package name of the device owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004599 * @throws SecurityException if the caller is not in {@code packageName} or {@code packageName}
4600 * does not own the current device owner component.
Esteban Talaveraa5b09632017-02-10 16:15:24 +00004601 *
4602 * @deprecated This method is expected to be used for testing purposes only. The device owner
4603 * will lose control of the device and its data after calling it. In order to protect any
4604 * sensitive data that remains on the device, it is advised that the device owner factory resets
4605 * the device instead of calling this method. See {@link #wipeData(int)}.
Jason Monkb0dced82014-06-06 14:36:20 -04004606 */
Esteban Talaveraa5b09632017-02-10 16:15:24 +00004607 @Deprecated
Jason Monk94d2cf92014-06-18 09:53:34 -04004608 public void clearDeviceOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004609 throwIfParentInstance("clearDeviceOwnerApp");
Jason Monkb0dced82014-06-06 14:36:20 -04004610 if (mService != null) {
4611 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04004612 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04004613 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004614 throw re.rethrowFromSystemServer();
Jason Monkb0dced82014-06-06 14:36:20 -04004615 }
4616 }
4617 }
4618
Makoto Onukia52562c2015-10-01 16:12:31 -07004619 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08004620 * Returns the device owner package name, only if it's running on the calling user.
4621 *
4622 * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity.
Makoto Onukia52562c2015-10-01 16:12:31 -07004623 *
4624 * @hide
4625 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01004626 @SystemApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06004627 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Makoto Onuki408e8e42016-10-25 12:10:27 -07004628 public @Nullable String getDeviceOwner() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004629 throwIfParentInstance("getDeviceOwner");
Makoto Onukic8a5a552015-11-19 14:29:12 -08004630 final ComponentName name = getDeviceOwnerComponentOnCallingUser();
4631 return name != null ? name.getPackageName() : null;
Makoto Onukia52562c2015-10-01 16:12:31 -07004632 }
4633
4634 /**
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004635 * Called by the system to find out whether the device is managed by a Device Owner.
Makoto Onukic8a5a552015-11-19 14:29:12 -08004636 *
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004637 * @return whether the device is managed by a Device Owner.
4638 * @throws SecurityException if the caller is not the device owner, does not hold the
4639 * MANAGE_USERS permission and is not the system.
Makoto Onukia52562c2015-10-01 16:12:31 -07004640 *
4641 * @hide
4642 */
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004643 @SystemApi
4644 @TestApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06004645 @SuppressLint("Doclava125")
Makoto Onukic8a5a552015-11-19 14:29:12 -08004646 public boolean isDeviceManaged() {
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004647 try {
4648 return mService.hasDeviceOwner();
4649 } catch (RemoteException re) {
4650 throw re.rethrowFromSystemServer();
4651 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08004652 }
4653
4654 /**
4655 * Returns the device owner name. Note this method *will* return the device owner
4656 * name when it's running on a different user.
4657 *
Makoto Onukic8a5a552015-11-19 14:29:12 -08004658 * @hide
4659 */
Makoto Onukia2b274b2016-01-19 13:26:02 -08004660 @SystemApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06004661 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Makoto Onukic8a5a552015-11-19 14:29:12 -08004662 public String getDeviceOwnerNameOnAnyUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004663 throwIfParentInstance("getDeviceOwnerNameOnAnyUser");
Amith Yamasani71e6c692013-03-24 17:39:28 -07004664 if (mService != null) {
4665 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07004666 return mService.getDeviceOwnerName();
Amith Yamasani71e6c692013-03-24 17:39:28 -07004667 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004668 throw re.rethrowFromSystemServer();
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004669 }
4670 }
4671 return null;
4672 }
Adam Connors776c5552014-01-09 10:42:56 +00004673
4674 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04004675 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004676 * @deprecated Do not use
4677 * @removed
Julia Reynolds20118f12015-02-11 12:34:08 -05004678 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004679 @Deprecated
Julia Reynolds20118f12015-02-11 12:34:08 -05004680 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06004681 @SuppressLint("Doclava125")
Makoto Onuki408e8e42016-10-25 12:10:27 -07004682 public @Nullable String getDeviceInitializerApp() {
Julia Reynolds20118f12015-02-11 12:34:08 -05004683 return null;
4684 }
4685
4686 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004687 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004688 * @deprecated Do not use
4689 * @removed
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004690 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004691 @Deprecated
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004692 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06004693 @SuppressLint("Doclava125")
Makoto Onuki408e8e42016-10-25 12:10:27 -07004694 public @Nullable ComponentName getDeviceInitializerComponent() {
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004695 return null;
4696 }
4697
Julia Reynolds20118f12015-02-11 12:34:08 -05004698 /**
Adam Connors776c5552014-01-09 10:42:56 +00004699 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004700 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304701 * Sets the given component as an active admin and registers the package as the profile
4702 * owner for this user. The package must already be installed and there shouldn't be
4703 * an existing profile owner registered for this user. Also, this method must be called
4704 * before the user setup has been completed.
4705 * <p>
4706 * This method can only be called by system apps that hold MANAGE_USERS permission and
4707 * MANAGE_DEVICE_ADMINS permission.
4708 * @param admin The component to register as an active admin and profile owner.
4709 * @param ownerName The user-visible name of the entity that is managing this user.
4710 * @return whether the admin was successfully registered as the profile owner.
4711 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
4712 * the user has already been set up.
4713 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07004714 @Deprecated
Justin Morey80440cc2014-07-24 09:16:35 -05004715 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06004716 @RequiresPermission(android.Manifest.permission.MANAGE_DEVICE_ADMINS)
Robin Lee25e26452015-06-02 09:56:29 -07004717 public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304718 throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004719 throwIfParentInstance("setActiveProfileOwner");
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304720 if (mService != null) {
4721 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004722 final int myUserId = myUserId();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304723 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004724 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304725 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004726 throw re.rethrowFromSystemServer();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304727 }
4728 }
4729 return false;
4730 }
4731
4732 /**
Esteban Talaveraa5b09632017-02-10 16:15:24 +00004733 * Clears the active profile owner. The caller must be the profile owner of this user, otherwise
4734 * a SecurityException will be thrown. This method is not available to managed profile owners.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004735 * <p>
Esteban Talaveraa5b09632017-02-10 16:15:24 +00004736 * While some policies previously set by the profile owner will be cleared by this method, it is
4737 * a best-effort process and some other policies will still remain in place after the profile
4738 * owner is cleared.
Makoto Onuki5bf68022016-01-27 13:49:19 -08004739 *
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004740 * @param admin The component to remove as the profile owner.
Esteban Talaveraa5b09632017-02-10 16:15:24 +00004741 * @throws SecurityException if {@code admin} is not an active profile owner, or the method is
4742 * being called from a managed profile.
4743 *
4744 * @deprecated This method is expected to be used for testing purposes only. The profile owner
4745 * will lose control of the user and its data after calling it. In order to protect any
4746 * sensitive data that remains on this user, it is advised that the profile owner deletes it
4747 * instead of calling this method. See {@link #wipeData(int)}.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004748 */
Esteban Talaveraa5b09632017-02-10 16:15:24 +00004749 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07004750 public void clearProfileOwner(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004751 throwIfParentInstance("clearProfileOwner");
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004752 if (mService != null) {
4753 try {
4754 mService.clearProfileOwner(admin);
4755 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004756 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004757 }
4758 }
4759 }
4760
4761 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05004762 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07004763 * Checks whether the user was already setup.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004764 */
4765 public boolean hasUserSetupCompleted() {
4766 if (mService != null) {
4767 try {
4768 return mService.hasUserSetupCompleted();
4769 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004770 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004771 }
4772 }
4773 return true;
4774 }
4775
4776 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004777 * @hide
4778 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00004779 * already be installed. There must not already be a profile owner for this user.
4780 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
4781 * this method.
4782 * Calling this after the setup phase of the specified user has completed is allowed only if:
4783 * - the caller is SYSTEM_UID.
4784 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004785 * @param admin the component name to be registered as profile owner.
4786 * @param ownerName the human readable name of the organisation associated with this DPM.
4787 * @param userHandle the userId to set the profile owner for.
4788 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00004789 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
4790 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004791 */
Robin Lee25e26452015-06-02 09:56:29 -07004792 public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName,
Robin Leeddd553f2015-04-30 14:18:22 +01004793 int userHandle) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00004794 if (mService != null) {
4795 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004796 if (ownerName == null) {
4797 ownerName = "";
4798 }
4799 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00004800 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004801 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004802 }
4803 }
4804 return false;
4805 }
4806
4807 /**
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004808 * Sets the device owner information to be shown on the lock screen.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004809 * <p>
4810 * If the device owner information is {@code null} or empty then the device owner info is
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004811 * cleared and the user owner info is shown on the lock screen if it is set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004812 * <p>
4813 * If the device owner information contains only whitespaces then the message on the lock screen
4814 * will be blank and the user will not be allowed to change it.
4815 * <p>
4816 * If the device owner information needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00004817 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
4818 * and set a new version of this string accordingly.
4819 *
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004820 * @param admin The name of the admin component to check.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004821 * @param info Device owner information which will be displayed instead of the user owner info.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004822 * @throws SecurityException if {@code admin} is not a device owner.
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004823 */
Andrei Stingaceanu16187902016-03-21 15:44:45 +00004824 public void setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, CharSequence info) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004825 throwIfParentInstance("setDeviceOwnerLockScreenInfo");
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004826 if (mService != null) {
4827 try {
Andrei Stingaceanu16187902016-03-21 15:44:45 +00004828 mService.setDeviceOwnerLockScreenInfo(admin, info);
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004829 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004830 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004831 }
4832 }
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004833 }
4834
4835 /**
4836 * @return The device owner information. If it is not set returns {@code null}.
4837 */
Andrei Stingaceanu16187902016-03-21 15:44:45 +00004838 public CharSequence getDeviceOwnerLockScreenInfo() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004839 throwIfParentInstance("getDeviceOwnerLockScreenInfo");
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004840 if (mService != null) {
4841 try {
4842 return mService.getDeviceOwnerLockScreenInfo();
4843 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004844 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004845 }
4846 }
4847 return null;
4848 }
4849
4850 /**
Edman Anjos52088e42017-01-13 22:26:17 +01004851 * Called by device or profile owners to suspend packages for this user. This function can be
4852 * called by a device owner, profile owner, or by a delegate given the
4853 * {@link #DELEGATION_PACKAGE_ACCESS} scope via {@link #setDelegatedScopes}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004854 * <p>
4855 * A suspended package will not be able to start activities. Its notifications will be hidden,
4856 * it will not show up in recents, will not be able to show toasts or dialogs or ring the
4857 * device.
4858 * <p>
4859 * The package must already be installed. If the package is uninstalled while suspended the
4860 * package will no longer be suspended. The admin can block this by using
Kenny Guy871f3eb2016-03-09 20:06:16 +00004861 * {@link #setUninstallBlocked}.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004862 *
Edman Anjos52088e42017-01-13 22:26:17 +01004863 * @param admin The name of the admin component to check, or {@code null} if the caller is a
4864 * package access delegate.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004865 * @param packageNames The package names to suspend or unsuspend.
4866 * @param suspended If set to {@code true} than the packages will be suspended, if set to
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004867 * {@code false} the packages will be unsuspended.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004868 * @return an array of package names for which the suspended status is not set as requested in
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004869 * this method.
4870 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01004871 * @see #setDelegatedScopes
4872 * @see #DELEGATION_PACKAGE_ACCESS
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004873 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004874 public @NonNull String[] setPackagesSuspended(@NonNull ComponentName admin,
4875 @NonNull String[] packageNames, boolean suspended) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004876 throwIfParentInstance("setPackagesSuspended");
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004877 if (mService != null) {
4878 try {
Edman Anjos52088e42017-01-13 22:26:17 +01004879 return mService.setPackagesSuspended(admin, mContext.getPackageName(), packageNames,
4880 suspended);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004881 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004882 throw re.rethrowFromSystemServer();
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004883 }
4884 }
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004885 return packageNames;
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004886 }
4887
4888 /**
Edman Anjos52088e42017-01-13 22:26:17 +01004889 * Determine if a package is suspended. This function can be called by a device owner, profile
4890 * owner, or by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via
4891 * {@link #setDelegatedScopes}.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004892 *
Edman Anjos52088e42017-01-13 22:26:17 +01004893 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
4894 * {@code null} if the caller is a package access delegate.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004895 * @param packageName The name of the package to retrieve the suspended status of.
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00004896 * @return {@code true} if the package is suspended or {@code false} if the package is not
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004897 * suspended, could not be found or an error occurred.
4898 * @throws SecurityException if {@code admin} is not a device or profile owner.
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004899 * @throws NameNotFoundException if the package could not be found.
Edman Anjos52088e42017-01-13 22:26:17 +01004900 * @see #setDelegatedScopes
4901 * @see #DELEGATION_PACKAGE_ACCESS
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004902 */
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004903 public boolean isPackageSuspended(@NonNull ComponentName admin, String packageName)
4904 throws NameNotFoundException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004905 throwIfParentInstance("isPackageSuspended");
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004906 if (mService != null) {
4907 try {
Edman Anjos52088e42017-01-13 22:26:17 +01004908 return mService.isPackageSuspended(admin, mContext.getPackageName(), packageName);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004909 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004910 throw e.rethrowFromSystemServer();
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004911 } catch (IllegalArgumentException ex) {
4912 throw new NameNotFoundException(packageName);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004913 }
4914 }
4915 return false;
4916 }
4917
4918 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004919 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
4920 * be used. Only the profile owner can call this.
4921 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01004922 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004923 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004924 * @throws SecurityException if {@code admin} is not a profile owner.
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004925 */
Robin Lee25e26452015-06-02 09:56:29 -07004926 public void setProfileEnabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004927 throwIfParentInstance("setProfileEnabled");
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004928 if (mService != null) {
4929 try {
4930 mService.setProfileEnabled(admin);
4931 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004932 throw e.rethrowFromSystemServer();
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004933 }
4934 }
4935 }
4936
4937 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004938 * Sets the name of the profile. In the device owner case it sets the name of the user which it
4939 * is called from. Only a profile owner or device owner can call this. If this is never called
4940 * by the profile or device owner, the name will be set to default values.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004941 *
4942 * @see #isProfileOwnerApp
4943 * @see #isDeviceOwnerApp
Robin Lee25e26452015-06-02 09:56:29 -07004944 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004945 * @param profileName The name of the profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004946 * @throws SecurityException if {@code admin} is not a device or profile owner.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004947 */
Robin Lee25e26452015-06-02 09:56:29 -07004948 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004949 throwIfParentInstance("setProfileName");
Jessica Hummel1333ea12014-06-23 11:20:10 +01004950 if (mService != null) {
4951 try {
Robin Lee25e26452015-06-02 09:56:29 -07004952 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07004953 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004954 throw e.rethrowFromSystemServer();
Fyodor Kupolov78f13142015-05-27 16:52:45 -07004955 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01004956 }
4957 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01004958
4959 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004960 * Used to determine if a particular package is registered as the profile owner for the
Makoto Onuki32b30572015-12-11 14:29:51 -08004961 * user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004962 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00004963 *
4964 * @param packageName The package name of the app to compare with the registered profile owner.
4965 * @return Whether or not the package is registered as the profile owner.
4966 */
4967 public boolean isProfileOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004968 throwIfParentInstance("isProfileOwnerApp");
Adam Connors776c5552014-01-09 10:42:56 +00004969 if (mService != null) {
4970 try {
Makoto Onuki90b89652016-01-28 14:44:18 -08004971 ComponentName profileOwner = mService.getProfileOwner(myUserId());
Nicolas Prevot90af6d72014-07-30 14:19:12 +01004972 return profileOwner != null
4973 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00004974 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004975 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004976 }
4977 }
4978 return false;
4979 }
4980
4981 /**
4982 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07004983 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00004984 * owner has been set for that user.
4985 * @throws IllegalArgumentException if the userId is invalid.
4986 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01004987 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004988 public @Nullable ComponentName getProfileOwner() throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004989 throwIfParentInstance("getProfileOwner");
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01004990 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
4991 }
4992
4993 /**
4994 * @see #getProfileOwner()
4995 * @hide
4996 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004997 public @Nullable ComponentName getProfileOwnerAsUser(final int userId)
4998 throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00004999 if (mService != null) {
5000 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01005001 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00005002 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005003 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00005004 }
5005 }
5006 return null;
5007 }
5008
5009 /**
5010 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07005011 * @return the human readable name of the organisation associated with this DPM or {@code null}
5012 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00005013 * @throws IllegalArgumentException if the userId is invalid.
5014 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005015 public @Nullable String getProfileOwnerName() throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00005016 if (mService != null) {
5017 try {
5018 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
5019 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005020 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00005021 }
5022 }
5023 return null;
5024 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005025
5026 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07005027 * @hide
Makoto Onukic8a5a552015-11-19 14:29:12 -08005028 * @param userId The user for whom to fetch the profile owner name, if any.
Amith Yamasani38f836b2014-08-20 14:51:15 -07005029 * @return the human readable name of the organisation associated with this profile owner or
5030 * null if one is not set.
5031 * @throws IllegalArgumentException if the userId is invalid.
5032 */
5033 @SystemApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06005034 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Makoto Onuki408e8e42016-10-25 12:10:27 -07005035 public @Nullable String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005036 throwIfParentInstance("getProfileOwnerNameAsUser");
Amith Yamasani38f836b2014-08-20 14:51:15 -07005037 if (mService != null) {
5038 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02005039 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07005040 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005041 throw re.rethrowFromSystemServer();
Amith Yamasani38f836b2014-08-20 14:51:15 -07005042 }
5043 }
5044 return null;
5045 }
5046
5047 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005048 * Called by a profile owner or device owner to add a default intent handler activity for
5049 * intents that match a certain intent filter. This activity will remain the default intent
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005050 * handler even if the set of potential event handlers for the intent filter changes and if the
5051 * intent preferences are reset.
5052 * <p>
5053 * The default disambiguation mechanism takes over if the activity is not installed (anymore).
5054 * When the activity is (re)installed, it is automatically reset as default intent handler for
5055 * the filter.
5056 * <p>
5057 * The calling device admin must be a profile owner or device owner. If it is not, a security
5058 * exception will be thrown.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005059 *
5060 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5061 * @param filter The IntentFilter for which a default handler is added.
5062 * @param activity The Activity that is added as default intent handler.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005063 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005064 */
Robin Lee25e26452015-06-02 09:56:29 -07005065 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
5066 @NonNull ComponentName activity) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005067 throwIfParentInstance("addPersistentPreferredActivity");
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005068 if (mService != null) {
5069 try {
5070 mService.addPersistentPreferredActivity(admin, filter, activity);
5071 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005072 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005073 }
5074 }
5075 }
5076
5077 /**
5078 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00005079 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005080 * <p>
5081 * The calling device admin must be a profile owner. If it is not, a security exception will be
5082 * thrown.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005083 *
5084 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5085 * @param packageName The name of the package for which preferences are removed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005086 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005087 */
Robin Lee25e26452015-06-02 09:56:29 -07005088 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005089 String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005090 throwIfParentInstance("clearPackagePersistentPreferredActivities");
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005091 if (mService != null) {
5092 try {
5093 mService.clearPackagePersistentPreferredActivities(admin, packageName);
5094 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005095 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005096 }
5097 }
5098 }
Robin Lee66e5d962014-04-09 16:44:21 +01005099
5100 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00005101 * Called by a profile owner or device owner to grant permission to a package to manage
5102 * application restrictions for the calling user via {@link #setApplicationRestrictions} and
5103 * {@link #getApplicationRestrictions}.
5104 * <p>
5105 * This permission is persistent until it is later cleared by calling this method with a
5106 * {@code null} value or uninstalling the managing package.
Rubin Xuf03d0a62016-02-10 14:54:15 +00005107 * <p>
5108 * The supplied application restriction managing package must be installed when calling this
Victor Changcd14c0a2016-03-16 19:10:15 +00005109 * API, otherwise an {@link NameNotFoundException} will be thrown.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005110 *
5111 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5112 * @param packageName The package name which will be given access to application restrictions
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005113 * APIs. If {@code null} is given the current package will be cleared.
5114 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Changcd14c0a2016-03-16 19:10:15 +00005115 * @throws NameNotFoundException if {@code packageName} is not found
Edman Anjosf9946772016-11-28 16:35:15 +01005116 *
5117 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #setDelegatedScopes}
5118 * with the {@link #DELEGATION_APP_RESTRICTIONS} scope instead.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005119 */
Edman Anjosf9946772016-11-28 16:35:15 +01005120 @Deprecated
Esteban Talaverabf60f722015-12-10 16:26:44 +00005121 public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin,
Victor Changcd14c0a2016-03-16 19:10:15 +00005122 @Nullable String packageName) throws NameNotFoundException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005123 throwIfParentInstance("setApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00005124 if (mService != null) {
5125 try {
Victor Changcd14c0a2016-03-16 19:10:15 +00005126 if (!mService.setApplicationRestrictionsManagingPackage(admin, packageName)) {
5127 throw new NameNotFoundException(packageName);
5128 }
Esteban Talaverabf60f722015-12-10 16:26:44 +00005129 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005130 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00005131 }
5132 }
5133 }
5134
5135 /**
5136 * Called by a profile owner or device owner to retrieve the application restrictions managing
Edman Anjosf9946772016-11-28 16:35:15 +01005137 * package for the current user, or {@code null} if none is set. If there are multiple
5138 * delegates this function will return one of them.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005139 *
5140 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5141 * @return The package name allowed to manage application restrictions on the current user, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005142 * {@code null} if none is set.
5143 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01005144 *
5145 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatePackages}
5146 * with the {@link #DELEGATION_APP_RESTRICTIONS} scope instead.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005147 */
Edman Anjosf9946772016-11-28 16:35:15 +01005148 @Deprecated
5149 @Nullable
5150 public String getApplicationRestrictionsManagingPackage(
Makoto Onuki408e8e42016-10-25 12:10:27 -07005151 @NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005152 throwIfParentInstance("getApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00005153 if (mService != null) {
5154 try {
5155 return mService.getApplicationRestrictionsManagingPackage(admin);
5156 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005157 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00005158 }
5159 }
5160 return null;
5161 }
5162
5163 /**
Esteban Talavera96895ca2016-03-16 12:00:40 +00005164 * Called by any application to find out whether it has been granted permission via
5165 * {@link #setApplicationRestrictionsManagingPackage} to manage application restrictions
5166 * for the calling user.
5167 *
5168 * <p>This is done by comparing the calling Linux uid with the uid of the package specified by
5169 * that method.
Edman Anjosf9946772016-11-28 16:35:15 +01005170 *
5171 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatedScopes}
5172 * instead.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005173 */
Edman Anjosf9946772016-11-28 16:35:15 +01005174 @Deprecated
Esteban Talaverabf60f722015-12-10 16:26:44 +00005175 public boolean isCallerApplicationRestrictionsManagingPackage() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005176 throwIfParentInstance("isCallerApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00005177 if (mService != null) {
5178 try {
Edman Anjosf9946772016-11-28 16:35:15 +01005179 return mService.isCallerApplicationRestrictionsManagingPackage(
5180 mContext.getPackageName());
Esteban Talaverabf60f722015-12-10 16:26:44 +00005181 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005182 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00005183 }
5184 }
5185 return false;
5186 }
5187
5188 /**
5189 * Sets the application restrictions for a given target application running in the calling user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005190 * <p>
5191 * 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 +01005192 * application restrictions via {@link #setDelegatedScopes} with the
5193 * {@link #DELEGATION_APP_RESTRICTIONS} scope; otherwise a security exception will be thrown.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005194 * <p>
5195 * The provided {@link Bundle} consists of key-value pairs, where the types of values may be:
Esteban Talavera6b8e0642015-08-10 17:26:04 +01005196 * <ul>
5197 * <li>{@code boolean}
5198 * <li>{@code int}
5199 * <li>{@code String} or {@code String[]}
5200 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
5201 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005202 * <p>
5203 * If the restrictions are not available yet, but may be applied in the near future, the caller
5204 * can notify the target application of that by adding
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00005205 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005206 * <p>
5207 * The application restrictions are only made visible to the target application via
5208 * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or device
5209 * owner, and the application restrictions managing package via
Esteban Talaverabf60f722015-12-10 16:26:44 +00005210 * {@link #getApplicationRestrictions}.
Robin Lee66e5d962014-04-09 16:44:21 +01005211 *
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005212 * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
5213 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00005214 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005215 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01005216 * @param packageName The name of the package to update restricted settings for.
5217 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005218 * set of active restrictions.
5219 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01005220 * @see #setDelegatedScopes
5221 * @see #DELEGATION_APP_RESTRICTIONS
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00005222 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01005223 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005224 @WorkerThread
Esteban Talaverabf60f722015-12-10 16:26:44 +00005225 public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01005226 Bundle settings) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005227 throwIfParentInstance("setApplicationRestrictions");
Robin Lee66e5d962014-04-09 16:44:21 +01005228 if (mService != null) {
5229 try {
Edman Anjosf9946772016-11-28 16:35:15 +01005230 mService.setApplicationRestrictions(admin, mContext.getPackageName(), packageName,
5231 settings);
Robin Lee66e5d962014-04-09 16:44:21 +01005232 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005233 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01005234 }
5235 }
5236 }
5237
5238 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005239 * Sets a list of configuration features to enable for a TrustAgent component. This is meant to
5240 * be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all trust
5241 * agents but those enabled by this function call. If flag
Jim Millere303bf42014-08-26 17:12:29 -07005242 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005243 * <p>
5244 * The calling device admin must have requested
5245 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method;
5246 * if not, a security exception will be thrown.
Tony Mak089d8402016-04-05 17:42:55 +01005247 * <p>
5248 * This method can be called on the {@link DevicePolicyManager} instance returned by
5249 * {@link #getParentProfileInstance(ComponentName)} in order to set the configuration for
5250 * the parent profile.
Jim Miller604e7552014-07-18 19:00:02 -07005251 *
5252 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07005253 * @param target Component name of the agent to be enabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005254 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent will be
5255 * strictly disabled according to the state of the
5256 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
5257 * <p>
5258 * If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all
5259 * admins, then it's up to the TrustAgent itself to aggregate the values from all
5260 * device admins.
5261 * <p>
5262 * Consult documentation for the specific TrustAgent to determine legal options
5263 * parameters.
5264 * @throws SecurityException if {@code admin} is not an active administrator or does not use
5265 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES}
Jim Miller604e7552014-07-18 19:00:02 -07005266 */
Robin Lee25e26452015-06-02 09:56:29 -07005267 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
5268 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07005269 if (mService != null) {
5270 try {
Tony Mak089d8402016-04-05 17:42:55 +01005271 mService.setTrustAgentConfiguration(admin, target, configuration, mParentInstance);
Jim Miller604e7552014-07-18 19:00:02 -07005272 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005273 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07005274 }
5275 }
5276 }
5277
5278 /**
Jim Millere303bf42014-08-26 17:12:29 -07005279 * Gets configuration for the given trust agent based on aggregating all calls to
5280 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
5281 * all device admins.
Tony Mak089d8402016-04-05 17:42:55 +01005282 * <p>
5283 * This method can be called on the {@link DevicePolicyManager} instance returned by
5284 * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the configuration set
5285 * on the parent profile.
Jim Miller604e7552014-07-18 19:00:02 -07005286 *
Jim Millerb5db57a2015-01-14 18:17:19 -08005287 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
5288 * this function returns a list of configurations for all admins that declare
5289 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
5290 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
5291 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
5292 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07005293 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07005294 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07005295 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005296 public @Nullable List<PersistableBundle> getTrustAgentConfiguration(
5297 @Nullable ComponentName admin, @NonNull ComponentName agent) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07005298 return getTrustAgentConfiguration(admin, agent, myUserId());
Jim Millere303bf42014-08-26 17:12:29 -07005299 }
5300
5301 /** @hide per-user version */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005302 public @Nullable List<PersistableBundle> getTrustAgentConfiguration(
5303 @Nullable ComponentName admin, @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07005304 if (mService != null) {
5305 try {
Tony Mak089d8402016-04-05 17:42:55 +01005306 return mService.getTrustAgentConfiguration(admin, agent, userHandle,
5307 mParentInstance);
Jim Miller604e7552014-07-18 19:00:02 -07005308 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005309 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07005310 }
5311 }
Jim Millere303bf42014-08-26 17:12:29 -07005312 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07005313 }
5314
5315 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005316 * Called by a profile owner of a managed profile to set whether caller-Id information from the
5317 * managed profile will be shown in the parent profile, for incoming calls.
5318 * <p>
5319 * The calling device admin must be a profile owner. If it is not, a security exception will be
5320 * thrown.
Adam Connors210fe212014-07-17 15:41:43 +01005321 *
Robin Lee25e26452015-06-02 09:56:29 -07005322 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01005323 * @param disabled If true caller-Id information in the managed profile is not displayed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005324 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors210fe212014-07-17 15:41:43 +01005325 */
Robin Lee25e26452015-06-02 09:56:29 -07005326 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005327 throwIfParentInstance("setCrossProfileCallerIdDisabled");
Adam Connors210fe212014-07-17 15:41:43 +01005328 if (mService != null) {
5329 try {
Robin Lee25e26452015-06-02 09:56:29 -07005330 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01005331 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005332 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01005333 }
5334 }
5335 }
5336
5337 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005338 * Called by a profile owner of a managed profile to determine whether or not caller-Id
5339 * information has been disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005340 * <p>
5341 * The calling device admin must be a profile owner. If it is not, a security exception will be
5342 * thrown.
Adam Connors210fe212014-07-17 15:41:43 +01005343 *
Robin Lee25e26452015-06-02 09:56:29 -07005344 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005345 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors210fe212014-07-17 15:41:43 +01005346 */
Robin Lee25e26452015-06-02 09:56:29 -07005347 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005348 throwIfParentInstance("getCrossProfileCallerIdDisabled");
Adam Connors210fe212014-07-17 15:41:43 +01005349 if (mService != null) {
5350 try {
Robin Lee25e26452015-06-02 09:56:29 -07005351 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01005352 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005353 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01005354 }
5355 }
5356 return false;
5357 }
5358
5359 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07005360 * Determine whether or not caller-Id information has been disabled.
5361 *
5362 * @param userHandle The user for whom to check the caller-id permission
5363 * @hide
5364 */
5365 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
5366 if (mService != null) {
5367 try {
5368 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
5369 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005370 throw e.rethrowFromSystemServer();
Amith Yamasani570002f2014-07-18 15:48:54 -07005371 }
5372 }
5373 return false;
5374 }
5375
5376 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005377 * Called by a profile owner of a managed profile to set whether contacts search from the
5378 * managed profile will be shown in the parent profile, for incoming calls.
5379 * <p>
5380 * The calling device admin must be a profile owner. If it is not, a security exception will be
5381 * thrown.
Victor Chang1060c6182016-01-04 20:16:23 +00005382 *
5383 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5384 * @param disabled If true contacts search in the managed profile is not displayed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005385 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Chang1060c6182016-01-04 20:16:23 +00005386 */
5387 public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin,
5388 boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005389 throwIfParentInstance("setCrossProfileContactsSearchDisabled");
Victor Chang1060c6182016-01-04 20:16:23 +00005390 if (mService != null) {
5391 try {
5392 mService.setCrossProfileContactsSearchDisabled(admin, disabled);
5393 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005394 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00005395 }
5396 }
5397 }
5398
5399 /**
5400 * Called by a profile owner of a managed profile to determine whether or not contacts search
5401 * has been disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005402 * <p>
5403 * The calling device admin must be a profile owner. If it is not, a security exception will be
5404 * thrown.
Victor Chang1060c6182016-01-04 20:16:23 +00005405 *
5406 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005407 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Chang1060c6182016-01-04 20:16:23 +00005408 */
5409 public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005410 throwIfParentInstance("getCrossProfileContactsSearchDisabled");
Victor Chang1060c6182016-01-04 20:16:23 +00005411 if (mService != null) {
5412 try {
5413 return mService.getCrossProfileContactsSearchDisabled(admin);
5414 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005415 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00005416 }
5417 }
5418 return false;
5419 }
5420
5421
5422 /**
5423 * Determine whether or not contacts search has been disabled.
5424 *
5425 * @param userHandle The user for whom to check the contacts search permission
5426 * @hide
5427 */
5428 public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) {
5429 if (mService != null) {
5430 try {
5431 return mService
5432 .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier());
5433 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005434 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00005435 }
5436 }
5437 return false;
5438 }
5439
5440 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005441 * Start Quick Contact on the managed profile for the user, if the policy allows.
Victor Chang97bdacc2016-01-21 22:24:11 +00005442 *
Makoto Onuki1040da12015-03-19 11:24:00 -07005443 * @hide
5444 */
5445 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
Victor Chang97bdacc2016-01-21 22:24:11 +00005446 boolean isContactIdIgnored, long directoryId, Intent originalIntent) {
Makoto Onuki1040da12015-03-19 11:24:00 -07005447 if (mService != null) {
5448 try {
Victor Chang97bdacc2016-01-21 22:24:11 +00005449 mService.startManagedQuickContact(actualLookupKey, actualContactId,
5450 isContactIdIgnored, directoryId, originalIntent);
Makoto Onuki1040da12015-03-19 11:24:00 -07005451 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005452 throw e.rethrowFromSystemServer();
Makoto Onuki1040da12015-03-19 11:24:00 -07005453 }
5454 }
5455 }
5456
5457 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005458 * Start Quick Contact on the managed profile for the user, if the policy allows.
Ricky Wai494b95d2015-11-20 16:07:15 +00005459 * @hide
5460 */
5461 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
5462 Intent originalIntent) {
Victor Chang97bdacc2016-01-21 22:24:11 +00005463 startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT,
Ricky Wai494b95d2015-11-20 16:07:15 +00005464 originalIntent);
5465 }
5466
5467 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005468 * Called by a profile owner of a managed profile to set whether bluetooth devices can access
5469 * enterprise contacts.
Ricky Wai778ba132015-03-31 14:21:22 +01005470 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005471 * The calling device admin must be a profile owner. If it is not, a security exception will be
5472 * thrown.
Ricky Wai778ba132015-03-31 14:21:22 +01005473 * <p>
5474 * This API works on managed profile only.
5475 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005476 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5477 * @param disabled If true, bluetooth devices cannot access enterprise contacts.
5478 * @throws SecurityException if {@code admin} is not a device or profile owner.
Ricky Wai778ba132015-03-31 14:21:22 +01005479 */
Robin Lee25e26452015-06-02 09:56:29 -07005480 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005481 throwIfParentInstance("setBluetoothContactSharingDisabled");
Ricky Wai778ba132015-03-31 14:21:22 +01005482 if (mService != null) {
5483 try {
Robin Lee25e26452015-06-02 09:56:29 -07005484 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01005485 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005486 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01005487 }
5488 }
5489 }
5490
5491 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005492 * Called by a profile owner of a managed profile to determine whether or not Bluetooth devices
5493 * cannot access enterprise contacts.
Ricky Wai778ba132015-03-31 14:21:22 +01005494 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005495 * The calling device admin must be a profile owner. If it is not, a security exception will be
5496 * thrown.
Ricky Wai778ba132015-03-31 14:21:22 +01005497 * <p>
5498 * This API works on managed profile only.
5499 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005500 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5501 * @throws SecurityException if {@code admin} is not a device or profile owner.
Ricky Wai778ba132015-03-31 14:21:22 +01005502 */
Robin Lee25e26452015-06-02 09:56:29 -07005503 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005504 throwIfParentInstance("getBluetoothContactSharingDisabled");
Ricky Wai778ba132015-03-31 14:21:22 +01005505 if (mService != null) {
5506 try {
Robin Lee25e26452015-06-02 09:56:29 -07005507 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01005508 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005509 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01005510 }
5511 }
5512 return true;
5513 }
5514
5515 /**
5516 * Determine whether or not Bluetooth devices cannot access contacts.
5517 * <p>
5518 * This API works on managed profile UserHandle only.
5519 *
5520 * @param userHandle The user for whom to check the caller-id permission
5521 * @hide
5522 */
5523 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
5524 if (mService != null) {
5525 try {
5526 return mService.getBluetoothContactSharingDisabledForUser(userHandle
5527 .getIdentifier());
5528 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005529 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01005530 }
5531 }
5532 return true;
5533 }
5534
5535 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005536 * Called by the profile owner of a managed profile so that some intents sent in the managed
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005537 * profile can also be resolved in the parent, or vice versa. Only activity intents are
5538 * supported.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00005539 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005540 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01005541 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005542 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01005543 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005544 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
5545 * @throws SecurityException if {@code admin} is not a device or profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005546 */
Robin Lee25e26452015-06-02 09:56:29 -07005547 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005548 throwIfParentInstance("addCrossProfileIntentFilter");
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005549 if (mService != null) {
5550 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01005551 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005552 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005553 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005554 }
5555 }
5556 }
5557
5558 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005559 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
5560 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01005561 * Only removes those that have been set by the profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005562 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005563 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005564 * @throws SecurityException if {@code admin} is not a device or profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005565 */
Robin Lee25e26452015-06-02 09:56:29 -07005566 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005567 throwIfParentInstance("clearCrossProfileIntentFilters");
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005568 if (mService != null) {
5569 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01005570 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005571 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005572 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005573 }
5574 }
5575 }
5576
5577 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005578 * Called by a profile or device owner to set the permitted accessibility services. When set by
5579 * a device owner or profile owner the restriction applies to all profiles of the user the
5580 * device owner or profile owner is an admin for. By default the user can use any accessiblity
5581 * service. When zero or more packages have been added, accessiblity services that are not in
5582 * the list and not part of the system can not be enabled by the user.
5583 * <p>
5584 * Calling with a null value for the list disables the restriction so that all services can be
5585 * used, calling with an empty list only allows the builtin system's services.
5586 * <p>
Esteban Talavera7e4cbad2017-03-30 17:59:50 +01005587 * System accessibility services are always available to the user the list can't modify this.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005588 *
5589 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5590 * @param packageNames List of accessibility service package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005591 * @return true if setting the restriction succeeded. It fail if there is one or more non-system
5592 * accessibility services enabled, that are not in the list.
5593 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005594 */
Robin Lee25e26452015-06-02 09:56:29 -07005595 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005596 List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005597 throwIfParentInstance("setPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005598 if (mService != null) {
5599 try {
5600 return mService.setPermittedAccessibilityServices(admin, packageNames);
5601 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005602 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005603 }
5604 }
5605 return false;
5606 }
5607
5608 /**
5609 * Returns the list of permitted accessibility services set by this device or profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005610 * <p>
5611 * An empty list means no accessibility services except system services are allowed. Null means
5612 * all accessibility services are allowed.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005613 *
5614 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5615 * @return List of accessiblity service package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005616 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005617 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005618 public @Nullable List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005619 throwIfParentInstance("getPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005620 if (mService != null) {
5621 try {
5622 return mService.getPermittedAccessibilityServices(admin);
5623 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005624 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005625 }
5626 }
5627 return null;
5628 }
5629
5630 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00005631 * Called by the system to check if a specific accessibility service is disabled by admin.
5632 *
5633 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5634 * @param packageName Accessibility service package name that needs to be checked.
5635 * @param userHandle user id the admin is running as.
5636 * @return true if the accessibility service is permitted, otherwise false.
5637 *
5638 * @hide
5639 */
5640 public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin,
5641 @NonNull String packageName, int userHandle) {
5642 if (mService != null) {
5643 try {
5644 return mService.isAccessibilityServicePermittedByAdmin(admin, packageName,
5645 userHandle);
5646 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005647 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00005648 }
5649 }
5650 return false;
5651 }
5652
5653 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005654 * Returns the list of accessibility services permitted by the device or profiles
5655 * owners of this user.
5656 *
5657 * <p>Null means all accessibility services are allowed, if a non-null list is returned
5658 * it will contain the intersection of the permitted lists for any device or profile
5659 * owners that apply to this user. It will also include any system accessibility services.
5660 *
5661 * @param userId which user to check for.
5662 * @return List of accessiblity service package names.
5663 * @hide
5664 */
5665 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07005666 public @Nullable List<String> getPermittedAccessibilityServices(int userId) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005667 throwIfParentInstance("getPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005668 if (mService != null) {
5669 try {
5670 return mService.getPermittedAccessibilityServicesForUser(userId);
5671 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005672 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005673 }
5674 }
5675 return null;
5676 }
5677
5678 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005679 * Called by a profile or device owner to set the permitted input methods services. When set by
5680 * a device owner or profile owner the restriction applies to all profiles of the user the
5681 * device owner or profile owner is an admin for. By default the user can use any input method.
5682 * When zero or more packages have been added, input method that are not in the list and not
5683 * part of the system can not be enabled by the user. This method will fail if it is called for
5684 * a admin that is not for the foreground user or a profile of the foreground user.
5685 * <p>
5686 * Calling with a null value for the list disables the restriction so that all input methods can
5687 * be used, calling with an empty list disables all but the system's own input methods.
5688 * <p>
5689 * System input methods are always available to the user this method can't modify this.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005690 *
5691 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5692 * @param packageNames List of input method package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005693 * @return true if setting the restriction succeeded. It will fail if there are one or more
5694 * non-system input methods currently enabled that are not in the packageNames list.
5695 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005696 */
Esteban Talavera7e4cbad2017-03-30 17:59:50 +01005697 public boolean setPermittedInputMethods(
5698 @NonNull ComponentName admin, List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005699 throwIfParentInstance("setPermittedInputMethods");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005700 if (mService != null) {
5701 try {
5702 return mService.setPermittedInputMethods(admin, packageNames);
5703 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005704 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005705 }
5706 }
5707 return false;
5708 }
5709
5710
5711 /**
5712 * Returns the list of permitted input methods set by this device or profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005713 * <p>
5714 * An empty list means no input methods except system input methods are allowed. Null means all
5715 * input methods are allowed.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005716 *
5717 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5718 * @return List of input method package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005719 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005720 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005721 public @Nullable List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005722 throwIfParentInstance("getPermittedInputMethods");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005723 if (mService != null) {
5724 try {
5725 return mService.getPermittedInputMethods(admin);
5726 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005727 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005728 }
5729 }
5730 return null;
5731 }
5732
5733 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00005734 * Called by the system to check if a specific input method is disabled by admin.
5735 *
5736 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5737 * @param packageName Input method package name that needs to be checked.
5738 * @param userHandle user id the admin is running as.
5739 * @return true if the input method is permitted, otherwise false.
5740 *
5741 * @hide
5742 */
5743 public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin,
5744 @NonNull String packageName, int userHandle) {
5745 if (mService != null) {
5746 try {
5747 return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle);
5748 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005749 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00005750 }
5751 }
5752 return false;
5753 }
5754
5755 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005756 * Returns the list of input methods permitted by the device or profiles
Makoto Onuki32b30572015-12-11 14:29:51 -08005757 * owners of the current user. (*Not* calling user, due to a limitation in InputMethodManager.)
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005758 *
5759 * <p>Null means all input methods are allowed, if a non-null list is returned
5760 * it will contain the intersection of the permitted lists for any device or profile
5761 * owners that apply to this user. It will also include any system input methods.
5762 *
5763 * @return List of input method package names.
5764 * @hide
5765 */
5766 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07005767 public @Nullable List<String> getPermittedInputMethodsForCurrentUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005768 throwIfParentInstance("getPermittedInputMethodsForCurrentUser");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005769 if (mService != null) {
5770 try {
5771 return mService.getPermittedInputMethodsForCurrentUser();
5772 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005773 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005774 }
5775 }
5776 return null;
5777 }
5778
5779 /**
Esteban Talavera7e4cbad2017-03-30 17:59:50 +01005780 * Called by a profile owner of a managed profile to set the packages that are allowed to use
5781 * a {@link android.service.notification.NotificationListenerService} in the primary user to
5782 * see notifications from the managed profile. By default all packages are permitted by this
5783 * policy. When zero or more packages have been added, notification listeners installed on the
5784 * primary user that are not in the list and are not part of the system won't receive events
5785 * for managed profile notifications.
5786 * <p>
5787 * Calling with a {@code null} value for the list disables the restriction so that all
5788 * notification listener services be used. Calling with an empty list disables all but the
5789 * system's own notification listeners. System notification listener services are always
5790 * available to the user.
5791 * <p>
5792 * If a device or profile owner want to stop notification listeners in their user from seeing
5793 * that user's notifications they should prevent that service from running instead (e.g. via
5794 * {@link #setApplicationHidden(ComponentName, String, boolean)})
5795 *
5796 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5797 * @param packageList List of package names to whitelist
5798 * @return true if setting the restriction succeeded. It will fail if called outside a managed
5799 * profile
5800 * @throws SecurityException if {@code admin} is not a profile owner.
5801 *
5802 * @see android.service.notification.NotificationListenerService
5803 */
5804 public boolean setPermittedCrossProfileNotificationListeners(
5805 @NonNull ComponentName admin, @Nullable List<String> packageList) {
5806 throwIfParentInstance("setPermittedCrossProfileNotificationListeners");
5807 if (mService != null) {
5808 try {
5809 return mService.setPermittedCrossProfileNotificationListeners(admin, packageList);
5810 } catch (RemoteException e) {
5811 throw e.rethrowFromSystemServer();
5812 }
5813 }
5814 return false;
5815 }
5816
5817 /**
5818 * Returns the list of packages installed on the primary user that allowed to use a
5819 * {@link android.service.notification.NotificationListenerService} to receive
5820 * notifications from this managed profile, as set by the profile owner.
5821 * <p>
5822 * An empty list means no notification listener services except system ones are allowed.
5823 * A {@code null} return value indicates that all notification listeners are allowed.
5824 */
5825 public @Nullable List<String> getPermittedCrossProfileNotificationListeners(
5826 @NonNull ComponentName admin) {
5827 throwIfParentInstance("getPermittedCrossProfileNotificationListeners");
5828 if (mService != null) {
5829 try {
5830 return mService.getPermittedCrossProfileNotificationListeners(admin);
5831 } catch (RemoteException e) {
5832 throw e.rethrowFromSystemServer();
5833 }
5834 }
5835 return null;
5836 }
5837
5838 /**
5839 * Returns true if {@code NotificationListenerServices} from the given package are allowed to
5840 * receive events for notifications from the given user id. Can only be called by the system uid
5841 *
5842 * @see #setPermittedCrossProfileNotificationListeners(ComponentName, List)
5843 *
5844 * @hide
5845 */
5846 public boolean isNotificationListenerServicePermitted(
5847 @NonNull String packageName, @UserIdInt int userId) {
5848 if (mService != null) {
5849 try {
5850 return mService.isNotificationListenerServicePermitted(packageName, userId);
5851 } catch (RemoteException e) {
5852 throw e.rethrowFromSystemServer();
5853 }
5854 }
5855 return true;
5856 }
5857
5858 /**
Edman Anjos52088e42017-01-13 22:26:17 +01005859 * Get the list of apps to keep around as APKs even if no user has currently installed it. This
5860 * function can be called by a device owner or by a delegate given the
5861 * {@link #DELEGATION_KEEP_UNINSTALLED_PACKAGES} scope via {@link #setDelegatedScopes}.
5862 * <p>
5863 * Please note that packages returned in this method are not automatically pre-cached.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005864 *
Edman Anjos52088e42017-01-13 22:26:17 +01005865 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
5866 * {@code null} if the caller is a keep uninstalled packages delegate.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005867 * @return List of package names to keep cached.
Edman Anjos52088e42017-01-13 22:26:17 +01005868 * @see #setDelegatedScopes
5869 * @see #DELEGATION_KEEP_UNINSTALLED_PACKAGES
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005870 * @hide
5871 */
Edman Anjos52088e42017-01-13 22:26:17 +01005872 public @Nullable List<String> getKeepUninstalledPackages(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005873 throwIfParentInstance("getKeepUninstalledPackages");
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005874 if (mService != null) {
5875 try {
Edman Anjos52088e42017-01-13 22:26:17 +01005876 return mService.getKeepUninstalledPackages(admin, mContext.getPackageName());
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005877 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005878 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005879 }
5880 }
5881 return null;
5882 }
5883
5884 /**
Edman Anjos52088e42017-01-13 22:26:17 +01005885 * Set a list of apps to keep around as APKs even if no user has currently installed it. This
5886 * function can be called by a device owner or by a delegate given the
5887 * {@link #DELEGATION_KEEP_UNINSTALLED_PACKAGES} scope via {@link #setDelegatedScopes}.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005888 *
5889 * <p>Please note that setting this policy does not imply that specified apps will be
5890 * automatically pre-cached.</p>
5891 *
Edman Anjos52088e42017-01-13 22:26:17 +01005892 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
5893 * {@code null} if the caller is a keep uninstalled packages delegate.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005894 * @param packageNames List of package names to keep cached.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005895 * @throws SecurityException if {@code admin} is not a device owner.
Edman Anjos52088e42017-01-13 22:26:17 +01005896 * @see #setDelegatedScopes
5897 * @see #DELEGATION_KEEP_UNINSTALLED_PACKAGES
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005898 * @hide
5899 */
Edman Anjos52088e42017-01-13 22:26:17 +01005900 public void setKeepUninstalledPackages(@Nullable ComponentName admin,
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005901 @NonNull List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005902 throwIfParentInstance("setKeepUninstalledPackages");
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005903 if (mService != null) {
5904 try {
Edman Anjos52088e42017-01-13 22:26:17 +01005905 mService.setKeepUninstalledPackages(admin, mContext.getPackageName(), packageNames);
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005906 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005907 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005908 }
5909 }
5910 }
5911
5912 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04005913 * Called by a device owner to create a user with the specified name. The UserHandle returned
5914 * by this method should not be persisted as user handles are recycled as users are removed and
5915 * created. If you need to persist an identifier for this user, use
5916 * {@link UserManager#getSerialNumberForUser}.
5917 *
5918 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5919 * @param name the user's name
5920 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07005921 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
5922 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01005923 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005924 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01005925 * @removed From {@link android.os.Build.VERSION_CODES#N}
Julia Reynolds1e958392014-05-16 14:25:21 -04005926 */
Kenny Guy14f48e52015-06-29 15:12:36 +01005927 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07005928 public @Nullable UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04005929 return null;
5930 }
5931
5932 /**
Jason Monk03978a42014-06-10 15:05:30 -04005933 * Called by a device owner to create a user with the specified name. The UserHandle returned
5934 * by this method should not be persisted as user handles are recycled as users are removed and
5935 * created. If you need to persist an identifier for this user, use
5936 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
5937 * immediately.
5938 *
5939 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
5940 * as registered as an active admin on the new user. The profile owner package will be
5941 * installed on the new user if it already is installed on the device.
5942 *
5943 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
5944 * profileOwnerComponent when onEnable is called.
5945 *
5946 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5947 * @param name the user's name
5948 * @param ownerName the human readable name of the organisation associated with this DPM.
5949 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
5950 * the user.
5951 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
5952 * on the new user.
5953 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07005954 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
5955 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01005956 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005957 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01005958 * @removed From {@link android.os.Build.VERSION_CODES#N}
Jason Monk03978a42014-06-10 15:05:30 -04005959 */
Kenny Guy14f48e52015-06-29 15:12:36 +01005960 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07005961 public @Nullable UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
Robin Lee25e26452015-06-02 09:56:29 -07005962 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04005963 return null;
5964 }
5965
5966 /**
phweissa92e1212016-01-25 17:14:10 +01005967 * Flag used by {@link #createAndManageUser} to skip setup wizard after creating a new user.
phweiss343fb332016-01-25 14:48:59 +01005968 */
5969 public static final int SKIP_SETUP_WIZARD = 0x0001;
5970
5971 /**
Lenka Trochtovac8202c82016-01-26 15:11:09 +01005972 * Flag used by {@link #createAndManageUser} to specify that the user should be created
5973 * ephemeral.
5974 * @hide
5975 */
5976 public static final int MAKE_USER_EPHEMERAL = 0x0002;
5977
5978 /**
Christine Franks361b8252017-06-23 18:12:46 -07005979 * Flag used by {@link #createAndManageUser} to specify that the user should be created as a
5980 * demo user.
5981 * @hide
5982 */
5983 public static final int MAKE_USER_DEMO = 0x0004;
5984
5985 /**
Benjamin Franz77c94a92017-08-09 14:16:03 +01005986 * Flag used by {@link #createAndManageUser} to specificy that the newly created user should be
5987 * started in the background as part of the user creation.
5988 */
5989 // TODO: Investigate solutions for the case where reboot happens before setup is completed.
5990 public static final int START_USER_IN_BACKGROUND = 0x0008;
5991
5992 /**
5993 * @hide
5994 */
5995 @IntDef(
5996 flag = true,
5997 prefix = {"SKIP_", "MAKE_USER_", "START_"},
5998 value = {SKIP_SETUP_WIZARD, MAKE_USER_EPHEMERAL, MAKE_USER_DEMO,
5999 START_USER_IN_BACKGROUND}
6000 )
6001 @Retention(RetentionPolicy.SOURCE)
6002 public @interface CreateAndManageUserFlags {}
6003
6004
6005 /**
phweissa92e1212016-01-25 17:14:10 +01006006 * Called by a device owner to create a user with the specified name and a given component of
6007 * the calling package as profile owner. The UserHandle returned by this method should not be
6008 * persisted as user handles are recycled as users are removed and created. If you need to
6009 * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new
6010 * user will not be started in the background.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006011 * <p>
6012 * admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also a
6013 * DeviceAdminReceiver in the same package as admin, and will become the profile owner and will
6014 * be registered as an active admin on the new user. The profile owner package will be installed
6015 * on the new user.
6016 * <p>
6017 * If the adminExtras are not null, they will be stored on the device until the user is started
6018 * for the first time. Then the extras will be passed to the admin when onEnable is called.
phweiss343fb332016-01-25 14:48:59 +01006019 *
6020 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6021 * @param name The user's name.
phweissa92e1212016-01-25 17:14:10 +01006022 * @param profileOwner Which {@link DeviceAdminReceiver} will be profile owner. Has to be in the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006023 * same package as admin, otherwise no user is created and an
6024 * IllegalArgumentException is thrown.
phweiss343fb332016-01-25 14:48:59 +01006025 * @param adminExtras Extras that will be passed to onEnable of the admin receiver on the new
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006026 * user.
phweissa92e1212016-01-25 17:14:10 +01006027 * @param flags {@link #SKIP_SETUP_WIZARD} is supported.
phweiss343fb332016-01-25 14:48:59 +01006028 * @see UserHandle
6029 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
6030 * user could not be created.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006031 * @throws SecurityException if {@code admin} is not a device owner.
phweiss343fb332016-01-25 14:48:59 +01006032 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006033 public @Nullable UserHandle createAndManageUser(@NonNull ComponentName admin,
6034 @NonNull String name,
phweissa92e1212016-01-25 17:14:10 +01006035 @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras,
Benjamin Franz77c94a92017-08-09 14:16:03 +01006036 @CreateAndManageUserFlags int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006037 throwIfParentInstance("createAndManageUser");
phweiss343fb332016-01-25 14:48:59 +01006038 try {
phweissa92e1212016-01-25 17:14:10 +01006039 return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags);
phweiss343fb332016-01-25 14:48:59 +01006040 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006041 throw re.rethrowFromSystemServer();
phweiss343fb332016-01-25 14:48:59 +01006042 }
phweiss343fb332016-01-25 14:48:59 +01006043 }
6044
6045 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006046 * Called by a device owner to remove a user and all associated data. The primary user can not
6047 * be removed.
Julia Reynolds1e958392014-05-16 14:25:21 -04006048 *
6049 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6050 * @param userHandle the user to remove.
6051 * @return {@code true} if the user was removed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006052 * @throws SecurityException if {@code admin} is not a device owner.
Julia Reynolds1e958392014-05-16 14:25:21 -04006053 */
Robin Lee25e26452015-06-02 09:56:29 -07006054 public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006055 throwIfParentInstance("removeUser");
Julia Reynolds1e958392014-05-16 14:25:21 -04006056 try {
6057 return mService.removeUser(admin, userHandle);
6058 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006059 throw re.rethrowFromSystemServer();
Julia Reynolds1e958392014-05-16 14:25:21 -04006060 }
6061 }
6062
6063 /**
Jason Monk582d9112014-07-09 19:57:08 -04006064 * Called by a device owner to switch the specified user to the foreground.
6065 *
6066 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6067 * @param userHandle the user to switch to; null will switch to primary.
6068 * @return {@code true} if the switch was successful, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006069 * @throws SecurityException if {@code admin} is not a device owner.
Jason Monk582d9112014-07-09 19:57:08 -04006070 * @see Intent#ACTION_USER_FOREGROUND
6071 */
Robin Lee25e26452015-06-02 09:56:29 -07006072 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006073 throwIfParentInstance("switchUser");
Jason Monk582d9112014-07-09 19:57:08 -04006074 try {
6075 return mService.switchUser(admin, userHandle);
6076 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006077 throw re.rethrowFromSystemServer();
Jason Monk582d9112014-07-09 19:57:08 -04006078 }
6079 }
6080
6081 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00006082 * Retrieves the application restrictions for a given target application running in the calling
6083 * user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006084 * <p>
6085 * 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 +01006086 * application restrictions via {@link #setDelegatedScopes} with the
6087 * {@link #DELEGATION_APP_RESTRICTIONS} scope; otherwise a security exception will be thrown.
Robin Lee66e5d962014-04-09 16:44:21 +01006088 *
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07006089 * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
6090 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00006091 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006092 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01006093 * @param packageName The name of the package to fetch restricted settings of.
6094 * @return {@link Bundle} of settings corresponding to what was set last time
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006095 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty
6096 * {@link Bundle} if no restrictions have been set.
6097 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01006098 * @see #setDelegatedScopes
6099 * @see #DELEGATION_APP_RESTRICTIONS
Robin Lee66e5d962014-04-09 16:44:21 +01006100 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07006101 @WorkerThread
Makoto Onuki408e8e42016-10-25 12:10:27 -07006102 public @NonNull Bundle getApplicationRestrictions(
6103 @Nullable ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006104 throwIfParentInstance("getApplicationRestrictions");
Robin Lee66e5d962014-04-09 16:44:21 +01006105 if (mService != null) {
6106 try {
Edman Anjosf9946772016-11-28 16:35:15 +01006107 return mService.getApplicationRestrictions(admin, mContext.getPackageName(),
6108 packageName);
Robin Lee66e5d962014-04-09 16:44:21 +01006109 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006110 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01006111 }
6112 }
6113 return null;
6114 }
Amith Yamasanibe465322014-04-24 13:45:17 -07006115
6116 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05006117 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07006118 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006119 * The calling device admin must be a profile or device owner; if it is not, a security
6120 * exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07006121 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006122 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6123 * @param key The key of the restriction. See the constants in {@link android.os.UserManager}
6124 * for the list of keys.
6125 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanibe465322014-04-24 13:45:17 -07006126 */
Robin Lee25e26452015-06-02 09:56:29 -07006127 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006128 throwIfParentInstance("addUserRestriction");
Amith Yamasanibe465322014-04-24 13:45:17 -07006129 if (mService != null) {
6130 try {
6131 mService.setUserRestriction(admin, key, true);
6132 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006133 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07006134 }
6135 }
6136 }
6137
6138 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05006139 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07006140 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006141 * The calling device admin must be a profile or device owner; if it is not, a security
6142 * exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07006143 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006144 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6145 * @param key The key of the restriction. See the constants in {@link android.os.UserManager}
6146 * for the list of keys.
6147 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanibe465322014-04-24 13:45:17 -07006148 */
Robin Lee25e26452015-06-02 09:56:29 -07006149 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006150 throwIfParentInstance("clearUserRestriction");
Amith Yamasanibe465322014-04-24 13:45:17 -07006151 if (mService != null) {
6152 try {
6153 mService.setUserRestriction(admin, key, false);
6154 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006155 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07006156 }
6157 }
6158 }
Adam Connors010cfd42014-04-16 12:48:13 +01006159
6160 /**
Makoto Onuki3a3092f2015-10-30 11:07:51 -07006161 * Called by a profile or device owner to get user restrictions set with
6162 * {@link #addUserRestriction(ComponentName, String)}.
6163 * <p>
6164 * The target user may have more restrictions set by the system or other device owner / profile
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006165 * owner. To get all the user restrictions currently set, use
Makoto Onuki3a3092f2015-10-30 11:07:51 -07006166 * {@link UserManager#getUserRestrictions()}.
6167 *
6168 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006169 * @throws SecurityException if {@code admin} is not a device or profile owner.
Makoto Onuki3a3092f2015-10-30 11:07:51 -07006170 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006171 public @NonNull Bundle getUserRestrictions(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006172 throwIfParentInstance("getUserRestrictions");
Makoto Onuki3a3092f2015-10-30 11:07:51 -07006173 Bundle ret = null;
6174 if (mService != null) {
6175 try {
Sudheer Shanka549b9692016-03-30 17:12:07 -07006176 ret = mService.getUserRestrictions(admin);
6177 } catch (RemoteException e) {
6178 throw e.rethrowFromSystemServer();
6179 }
6180 }
6181 return ret == null ? new Bundle() : ret;
6182 }
6183
6184 /**
phweiss73145f42017-01-17 19:06:38 +01006185 * Called by any app to display a support dialog when a feature was disabled by an admin.
6186 * This returns an intent that can be used with {@link Context#startActivity(Intent)} to
6187 * display the dialog. It will tell the user that the feature indicated by {@code restriction}
6188 * was disabled by an admin, and include a link for more information. The default content of
6189 * the dialog can be changed by the restricting admin via
6190 * {@link #setShortSupportMessage(ComponentName, CharSequence)}. If the restriction is not
6191 * set (i.e. the feature is available), then the return value will be {@code null}.
6192 * @param restriction Indicates for which feature the dialog should be displayed. Can be a
6193 * user restriction from {@link UserManager}, e.g.
6194 * {@link UserManager#DISALLOW_ADJUST_VOLUME}, or one of the constants
6195 * {@link #POLICY_DISABLE_CAMERA} or {@link #POLICY_DISABLE_SCREEN_CAPTURE}.
6196 * @return Intent An intent to be used to start the dialog-activity if the restriction is
6197 * set by an admin, or null if the restriction does not exist or no admin set it.
6198 */
6199 public Intent createAdminSupportIntent(@NonNull String restriction) {
6200 throwIfParentInstance("createAdminSupportIntent");
6201 if (mService != null) {
6202 try {
6203 return mService.createAdminSupportIntent(restriction);
6204 } catch (RemoteException e) {
6205 throw e.rethrowFromSystemServer();
6206 }
6207 }
6208 return null;
6209 }
6210
6211 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006212 * Hide or unhide packages. When a package is hidden it is unavailable for use, but the data and
6213 * actual package file remain. This function can be called by a device owner, profile owner, or
6214 * by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via
6215 * {@link #setDelegatedScopes}.
Julia Reynolds966881e2014-05-14 12:23:08 -04006216 *
Edman Anjos52088e42017-01-13 22:26:17 +01006217 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
6218 * {@code null} if the caller is a package access delegate.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07006219 * @param packageName The name of the package to hide or unhide.
6220 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006221 * unhidden.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07006222 * @return boolean Whether the hidden setting of the package was successfully updated.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006223 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01006224 * @see #setDelegatedScopes
6225 * @see #DELEGATION_PACKAGE_ACCESS
Julia Reynolds966881e2014-05-14 12:23:08 -04006226 */
Robin Lee25e26452015-06-02 09:56:29 -07006227 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07006228 boolean hidden) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006229 throwIfParentInstance("setApplicationHidden");
Julia Reynolds966881e2014-05-14 12:23:08 -04006230 if (mService != null) {
6231 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006232 return mService.setApplicationHidden(admin, mContext.getPackageName(), packageName,
6233 hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04006234 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006235 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04006236 }
6237 }
6238 return false;
6239 }
6240
6241 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006242 * Determine if a package is hidden. This function can be called by a device owner, profile
6243 * owner, or by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via
6244 * {@link #setDelegatedScopes}.
Julia Reynolds966881e2014-05-14 12:23:08 -04006245 *
Edman Anjos52088e42017-01-13 22:26:17 +01006246 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
6247 * {@code null} if the caller is a package access delegate.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07006248 * @param packageName The name of the package to retrieve the hidden status of.
6249 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006250 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01006251 * @see #setDelegatedScopes
6252 * @see #DELEGATION_PACKAGE_ACCESS
Julia Reynolds966881e2014-05-14 12:23:08 -04006253 */
Robin Lee25e26452015-06-02 09:56:29 -07006254 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006255 throwIfParentInstance("isApplicationHidden");
Julia Reynolds966881e2014-05-14 12:23:08 -04006256 if (mService != null) {
6257 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006258 return mService.isApplicationHidden(admin, mContext.getPackageName(), packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04006259 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006260 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04006261 }
6262 }
6263 return false;
6264 }
6265
6266 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006267 * Re-enable a system app that was disabled by default when the user was initialized. This
6268 * function can be called by a device owner, profile owner, or by a delegate given the
6269 * {@link #DELEGATION_ENABLE_SYSTEM_APP} scope via {@link #setDelegatedScopes}.
Adam Connors655be2a2014-07-14 09:01:25 +00006270 *
Edman Anjos52088e42017-01-13 22:26:17 +01006271 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
6272 * {@code null} if the caller is an enable system app delegate.
Makoto Onuki32b30572015-12-11 14:29:51 -08006273 * @param packageName The package to be re-enabled in the calling profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006274 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01006275 * @see #setDelegatedScopes
6276 * @see #DELEGATION_PACKAGE_ACCESS
Adam Connors655be2a2014-07-14 09:01:25 +00006277 */
Robin Lee25e26452015-06-02 09:56:29 -07006278 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006279 throwIfParentInstance("enableSystemApp");
Adam Connors655be2a2014-07-14 09:01:25 +00006280 if (mService != null) {
6281 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006282 mService.enableSystemApp(admin, mContext.getPackageName(), packageName);
Adam Connors655be2a2014-07-14 09:01:25 +00006283 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006284 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00006285 }
6286 }
6287 }
6288
6289 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006290 * Re-enable system apps by intent that were disabled by default when the user was initialized.
6291 * This function can be called by a device owner, profile owner, or by a delegate given the
6292 * {@link #DELEGATION_ENABLE_SYSTEM_APP} scope via {@link #setDelegatedScopes}.
Adam Connors655be2a2014-07-14 09:01:25 +00006293 *
Edman Anjos52088e42017-01-13 22:26:17 +01006294 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
6295 * {@code null} if the caller is an enable system app delegate.
Adam Connors655be2a2014-07-14 09:01:25 +00006296 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006297 * intent will be re-enabled in the calling profile.
Adam Connors655be2a2014-07-14 09:01:25 +00006298 * @return int The number of activities that matched the intent and were installed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006299 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01006300 * @see #setDelegatedScopes
6301 * @see #DELEGATION_PACKAGE_ACCESS
Adam Connors655be2a2014-07-14 09:01:25 +00006302 */
Robin Lee25e26452015-06-02 09:56:29 -07006303 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006304 throwIfParentInstance("enableSystemApp");
Adam Connors655be2a2014-07-14 09:01:25 +00006305 if (mService != null) {
6306 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006307 return mService.enableSystemAppWithIntent(admin, mContext.getPackageName(), intent);
Adam Connors655be2a2014-07-14 09:01:25 +00006308 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006309 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00006310 }
6311 }
6312 return 0;
6313 }
6314
6315 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00006316 * Called by a device owner or profile owner to disable account management for a specific type
6317 * of account.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006318 * <p>
6319 * The calling device admin must be a device owner or profile owner. If it is not, a security
6320 * exception will be thrown.
6321 * <p>
6322 * When account management is disabled for an account type, adding or removing an account of
6323 * that type will not be possible.
6324 * <p>
6325 * From {@link android.os.Build.VERSION_CODES#N} the profile or device owner can still use
Benjamin Franzb6c0ce42015-11-05 10:06:51 +00006326 * {@link android.accounts.AccountManager} APIs to add or remove accounts when account
6327 * management for a specific type is disabled.
6328 *
Sander Alewijnse650c3342014-05-08 18:00:50 +01006329 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6330 * @param accountType For which account management is disabled or enabled.
6331 * @param disabled The boolean indicating that account management will be disabled (true) or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006332 * enabled (false).
6333 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnse650c3342014-05-08 18:00:50 +01006334 */
Robin Lee25e26452015-06-02 09:56:29 -07006335 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01006336 boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006337 throwIfParentInstance("setAccountManagementDisabled");
Sander Alewijnse650c3342014-05-08 18:00:50 +01006338 if (mService != null) {
6339 try {
6340 mService.setAccountManagementDisabled(admin, accountType, disabled);
6341 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006342 throw e.rethrowFromSystemServer();
Sander Alewijnse650c3342014-05-08 18:00:50 +01006343 }
6344 }
6345 }
6346
6347 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01006348 * Gets the array of accounts for which account management is disabled by the profile owner.
6349 *
6350 * <p> Account management can be disabled/enabled by calling
6351 * {@link #setAccountManagementDisabled}.
6352 *
6353 * @return a list of account types for which account management has been disabled.
6354 *
6355 * @see #setAccountManagementDisabled
6356 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006357 public @Nullable String[] getAccountTypesWithManagementDisabled() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006358 throwIfParentInstance("getAccountTypesWithManagementDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07006359 return getAccountTypesWithManagementDisabledAsUser(myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01006360 }
6361
6362 /**
6363 * @see #getAccountTypesWithManagementDisabled()
6364 * @hide
6365 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006366 public @Nullable String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01006367 if (mService != null) {
6368 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01006369 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01006370 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006371 throw e.rethrowFromSystemServer();
Sander Alewijnse5c02db62014-05-07 10:46:57 +01006372 }
6373 }
6374
6375 return null;
6376 }
justinzhang511e0d82014-03-24 16:09:24 -04006377
6378 /**
Jason Monkd7b86212014-06-16 13:15:38 -04006379 * Sets which packages may enter lock task mode.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006380 * <p>
Esteban Talaverabdcada92017-02-01 14:20:06 +00006381 * Any packages that share uid with an allowed package will also be allowed to activate lock
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006382 * task. From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task
Esteban Talaverabdcada92017-02-01 14:20:06 +00006383 * package list results in locked tasks belonging to those packages to be finished.
6384 * <p>
6385 * This function can only be called by the device owner or by a profile owner of a user/profile
6386 * that is affiliated with the device owner user. See {@link #setAffiliationIds}. Any packages
6387 * set via this method will be cleared if the user becomes unaffiliated.
Jason Monkd7b86212014-06-16 13:15:38 -04006388 *
Jason Monkd7b86212014-06-16 13:15:38 -04006389 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04006390 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Esteban Talaverabdcada92017-02-01 14:20:06 +00006391 * @throws SecurityException if {@code admin} is not the device owner, or the profile owner of
6392 * an affiliated user or profile.
Jason Monkd7b86212014-06-16 13:15:38 -04006393 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00006394 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
6395 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04006396 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04006397 */
Esteban Talaverabdcada92017-02-01 14:20:06 +00006398 public void setLockTaskPackages(@NonNull ComponentName admin, @NonNull String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04006399 throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006400 throwIfParentInstance("setLockTaskPackages");
justinzhang511e0d82014-03-24 16:09:24 -04006401 if (mService != null) {
6402 try {
Jason Monk48aacba2014-08-13 16:29:08 -04006403 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04006404 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006405 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04006406 }
6407 }
6408 }
6409
6410 /**
Esteban Talaverabdcada92017-02-01 14:20:06 +00006411 * Returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04006412 *
Esteban Talaverabdcada92017-02-01 14:20:06 +00006413 * @throws SecurityException if {@code admin} is not the device owner, or the profile owner of
6414 * an affiliated user or profile.
6415 * @see #setLockTaskPackages
justinzhang511e0d82014-03-24 16:09:24 -04006416 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006417 public @NonNull String[] getLockTaskPackages(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006418 throwIfParentInstance("getLockTaskPackages");
justinzhang511e0d82014-03-24 16:09:24 -04006419 if (mService != null) {
6420 try {
Jason Monk48aacba2014-08-13 16:29:08 -04006421 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04006422 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006423 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04006424 }
6425 }
Esteban Talaverabdcada92017-02-01 14:20:06 +00006426 return new String[0];
justinzhang511e0d82014-03-24 16:09:24 -04006427 }
6428
6429 /**
6430 * This function lets the caller know whether the given component is allowed to start the
6431 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04006432 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04006433 */
Jason Monkd7b86212014-06-16 13:15:38 -04006434 public boolean isLockTaskPermitted(String pkg) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006435 throwIfParentInstance("isLockTaskPermitted");
justinzhang511e0d82014-03-24 16:09:24 -04006436 if (mService != null) {
6437 try {
Jason Monkd7b86212014-06-16 13:15:38 -04006438 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04006439 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006440 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04006441 }
6442 }
6443 return false;
6444 }
Julia Reynoldsda551652014-05-14 17:15:16 -04006445
6446 /**
Benjamin Franz482bb232017-06-23 13:48:20 +01006447 * Called by device owners to update {@link android.provider.Settings.Global} settings.
6448 * Validation that the value of the setting is in the correct form for the setting type should
6449 * be performed by the caller.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006450 * <p>
6451 * The settings that can be updated with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04006452 * <ul>
Benjamin Franz482bb232017-06-23 13:48:20 +01006453 * <li>{@link android.provider.Settings.Global#ADB_ENABLED}</li>
6454 * <li>{@link android.provider.Settings.Global#AUTO_TIME}</li>
6455 * <li>{@link android.provider.Settings.Global#AUTO_TIME_ZONE}</li>
6456 * <li>{@link android.provider.Settings.Global#DATA_ROAMING}</li>
6457 * <li>{@link android.provider.Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
6458 * <li>{@link android.provider.Settings.Global#WIFI_SLEEP_POLICY}</li>
6459 * <li>{@link android.provider.Settings.Global#STAY_ON_WHILE_PLUGGED_IN} This setting is only
6460 * available from {@link android.os.Build.VERSION_CODES#M} onwards and can only be set if
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006461 * {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
Benjamin Franz482bb232017-06-23 13:48:20 +01006462 * <li>{@link android.provider.Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li> This
6463 * setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04006464 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006465 * <p>
6466 * Changing the following settings has no effect as of {@link android.os.Build.VERSION_CODES#M}:
Esteban Talavera656fa7f2015-06-29 17:41:39 +01006467 * <ul>
Benjamin Franz482bb232017-06-23 13:48:20 +01006468 * <li>{@link android.provider.Settings.Global#BLUETOOTH_ON}. Use
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006469 * {@link android.bluetooth.BluetoothAdapter#enable()} and
6470 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
Benjamin Franz482bb232017-06-23 13:48:20 +01006471 * <li>{@link android.provider.Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
6472 * <li>{@link android.provider.Settings.Global#MODE_RINGER}. Use
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006473 * {@link android.media.AudioManager#setRingerMode(int)} instead.</li>
Benjamin Franz482bb232017-06-23 13:48:20 +01006474 * <li>{@link android.provider.Settings.Global#NETWORK_PREFERENCE}</li>
6475 * <li>{@link android.provider.Settings.Global#WIFI_ON}. Use
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006476 * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01006477 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04006478 *
6479 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6480 * @param setting The name of the setting to update.
6481 * @param value The value to update the setting to.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006482 * @throws SecurityException if {@code admin} is not a device owner.
Julia Reynoldsda551652014-05-14 17:15:16 -04006483 */
Robin Lee25e26452015-06-02 09:56:29 -07006484 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006485 throwIfParentInstance("setGlobalSetting");
Julia Reynoldsda551652014-05-14 17:15:16 -04006486 if (mService != null) {
6487 try {
6488 mService.setGlobalSetting(admin, setting, value);
6489 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006490 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04006491 }
6492 }
6493 }
6494
6495 /**
Benjamin Franz482bb232017-06-23 13:48:20 +01006496 * Called by profile or device owners to update {@link android.provider.Settings.Secure}
6497 * settings. Validation that the value of the setting is in the correct form for the setting
6498 * type should be performed by the caller.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006499 * <p>
6500 * The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04006501 * <ul>
Benjamin Franz482bb232017-06-23 13:48:20 +01006502 * <li>{@link android.provider.Settings.Secure#DEFAULT_INPUT_METHOD}</li>
6503 * <li>{@link android.provider.Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04006504 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006505 * <p>
6506 * A device owner can additionally update the following settings:
Julia Reynolds82735bc2014-09-04 16:43:30 -04006507 * <ul>
Benjamin Franz482bb232017-06-23 13:48:20 +01006508 * <li>{@link android.provider.Settings.Secure#LOCATION_MODE}</li>
Julia Reynolds82735bc2014-09-04 16:43:30 -04006509 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006510 *
Suprabh Shukla0b1356f2017-02-21 14:33:50 -08006511 * <strong>Note: Starting from Android O, apps should no longer call this method with the
6512 * setting {@link android.provider.Settings.Secure#INSTALL_NON_MARKET_APPS}, which is
6513 * deprecated. Instead, device owners or profile owners should use the restriction
6514 * {@link UserManager#DISALLOW_INSTALL_UNKNOWN_SOURCES}.
6515 * If any app targeting {@link android.os.Build.VERSION_CODES#O} or higher calls this method
6516 * with {@link android.provider.Settings.Secure#INSTALL_NON_MARKET_APPS},
6517 * an {@link UnsupportedOperationException} is thrown.
6518 * </strong>
6519 *
Julia Reynoldsda551652014-05-14 17:15:16 -04006520 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6521 * @param setting The name of the setting to update.
6522 * @param value The value to update the setting to.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006523 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynoldsda551652014-05-14 17:15:16 -04006524 */
Robin Lee25e26452015-06-02 09:56:29 -07006525 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006526 throwIfParentInstance("setSecureSetting");
Julia Reynoldsda551652014-05-14 17:15:16 -04006527 if (mService != null) {
6528 try {
6529 mService.setSecureSetting(admin, setting, value);
6530 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006531 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04006532 }
6533 }
6534 }
6535
Amith Yamasanif20d6402014-05-24 15:34:37 -07006536 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006537 * Designates a specific service component as the provider for making permission requests of a
6538 * local or remote administrator of the user.
Amith Yamasanif20d6402014-05-24 15:34:37 -07006539 * <p/>
6540 * Only a profile owner can designate the restrictions provider.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006541 *
Amith Yamasanif20d6402014-05-24 15:34:37 -07006542 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07006543 * @param provider The component name of the service that implements
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006544 * {@link RestrictionsReceiver}. If this param is null, it removes the restrictions
6545 * provider previously assigned.
6546 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanif20d6402014-05-24 15:34:37 -07006547 */
Robin Lee25e26452015-06-02 09:56:29 -07006548 public void setRestrictionsProvider(@NonNull ComponentName admin,
6549 @Nullable ComponentName provider) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006550 throwIfParentInstance("setRestrictionsProvider");
Amith Yamasanif20d6402014-05-24 15:34:37 -07006551 if (mService != null) {
6552 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07006553 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07006554 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006555 throw re.rethrowFromSystemServer();
Amith Yamasanif20d6402014-05-24 15:34:37 -07006556 }
6557 }
6558 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04006559
6560 /**
6561 * Called by profile or device owners to set the master volume mute on or off.
Nicolas Prevotaef3ce22016-09-22 12:00:25 +01006562 * This has no effect when set on a managed profile.
Julia Reynolds4a21b252014-06-04 11:11:43 -04006563 *
6564 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6565 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006566 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds4a21b252014-06-04 11:11:43 -04006567 */
Robin Lee25e26452015-06-02 09:56:29 -07006568 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006569 throwIfParentInstance("setMasterVolumeMuted");
Julia Reynolds4a21b252014-06-04 11:11:43 -04006570 if (mService != null) {
6571 try {
6572 mService.setMasterVolumeMuted(admin, on);
6573 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006574 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04006575 }
6576 }
6577 }
6578
6579 /**
6580 * Called by profile or device owners to check whether the master volume mute is on or off.
6581 *
6582 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6583 * @return {@code true} if master volume is muted, {@code false} if it's not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006584 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds4a21b252014-06-04 11:11:43 -04006585 */
Robin Lee25e26452015-06-02 09:56:29 -07006586 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006587 throwIfParentInstance("isMasterVolumeMuted");
Julia Reynolds4a21b252014-06-04 11:11:43 -04006588 if (mService != null) {
6589 try {
6590 return mService.isMasterVolumeMuted(admin);
6591 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006592 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04006593 }
6594 }
6595 return false;
6596 }
Kenny Guyc13053b2014-05-29 14:17:17 +01006597
6598 /**
Edman Anjosa5f2fb12016-12-19 11:25:54 -08006599 * Change whether a user can uninstall a package. This function can be called by a device owner,
6600 * profile owner, or by a delegate given the {@link #DELEGATION_BLOCK_UNINSTALL} scope via
6601 * {@link #setDelegatedScopes}.
Kenny Guyc13053b2014-05-29 14:17:17 +01006602 *
Edman Anjosa5f2fb12016-12-19 11:25:54 -08006603 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
6604 * {@code null} if the caller is a block uninstall delegate.
Kenny Guyc13053b2014-05-29 14:17:17 +01006605 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01006606 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006607 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjosa5f2fb12016-12-19 11:25:54 -08006608 * @see #setDelegatedScopes
6609 * @see #DELEGATION_BLOCK_UNINSTALL
Kenny Guyc13053b2014-05-29 14:17:17 +01006610 */
Edman Anjosa5f2fb12016-12-19 11:25:54 -08006611 public void setUninstallBlocked(@Nullable ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01006612 boolean uninstallBlocked) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006613 throwIfParentInstance("setUninstallBlocked");
Kenny Guyc13053b2014-05-29 14:17:17 +01006614 if (mService != null) {
6615 try {
Edman Anjosa5f2fb12016-12-19 11:25:54 -08006616 mService.setUninstallBlocked(admin, mContext.getPackageName(), packageName,
6617 uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01006618 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006619 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01006620 }
6621 }
6622 }
6623
6624 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08006625 * Check whether the user has been blocked by device policy from uninstalling a package.
Rubin Xua97855b2014-11-07 05:41:00 +00006626 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00006627 * <p>
6628 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006629 * behavior of this API is changed such that passing {@code null} as the {@code admin} parameter
6630 * will return if any admin has blocked the uninstallation. Before L MR1, passing {@code null}
6631 * will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01006632 *
Robin Lee25e26452015-06-02 09:56:29 -07006633 * @param admin The name of the admin component whose blocking policy will be checked, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006634 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01006635 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00006636 * @return true if uninstallation is blocked.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006637 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyc13053b2014-05-29 14:17:17 +01006638 */
Robin Lee25e26452015-06-02 09:56:29 -07006639 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006640 throwIfParentInstance("isUninstallBlocked");
Kenny Guyc13053b2014-05-29 14:17:17 +01006641 if (mService != null) {
6642 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01006643 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01006644 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006645 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01006646 }
6647 }
6648 return false;
6649 }
Svetoslav976e8bd2014-07-16 15:12:03 -07006650
6651 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006652 * Called by the profile owner of a managed profile to enable widget providers from a given
6653 * package to be available in the parent profile. As a result the user will be able to add
6654 * widgets from the white-listed package running under the profile to a widget host which runs
6655 * under the parent profile, for example the home screen. Note that a package may have zero or
6656 * more provider components, where each component provides a different widget type.
Svetoslav976e8bd2014-07-16 15:12:03 -07006657 * <p>
6658 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07006659 *
6660 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6661 * @param packageName The package from which widget providers are white-listed.
6662 * @return Whether the package was added.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006663 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07006664 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
6665 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
6666 */
Robin Lee25e26452015-06-02 09:56:29 -07006667 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006668 throwIfParentInstance("addCrossProfileWidgetProvider");
Svetoslav976e8bd2014-07-16 15:12:03 -07006669 if (mService != null) {
6670 try {
6671 return mService.addCrossProfileWidgetProvider(admin, packageName);
6672 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006673 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07006674 }
6675 }
6676 return false;
6677 }
6678
6679 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07006680 * Called by the profile owner of a managed profile to disable widget providers from a given
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006681 * package to be available in the parent profile. For this method to take effect the package
6682 * should have been added via
6683 * {@link #addCrossProfileWidgetProvider( android.content.ComponentName, String)}.
Svetoslav976e8bd2014-07-16 15:12:03 -07006684 * <p>
6685 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07006686 *
6687 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006688 * @param packageName The package from which widget providers are no longer white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07006689 * @return Whether the package was removed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006690 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07006691 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
6692 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
6693 */
Esteban Talavera62399912016-01-11 15:37:55 +00006694 public boolean removeCrossProfileWidgetProvider(
6695 @NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006696 throwIfParentInstance("removeCrossProfileWidgetProvider");
Svetoslav976e8bd2014-07-16 15:12:03 -07006697 if (mService != null) {
6698 try {
6699 return mService.removeCrossProfileWidgetProvider(admin, packageName);
6700 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006701 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07006702 }
6703 }
6704 return false;
6705 }
6706
6707 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07006708 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07006709 * available in the parent profile.
6710 *
6711 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6712 * @return The white-listed package list.
Svetoslav976e8bd2014-07-16 15:12:03 -07006713 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
6714 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006715 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07006716 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006717 public @NonNull List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006718 throwIfParentInstance("getCrossProfileWidgetProviders");
Svetoslav976e8bd2014-07-16 15:12:03 -07006719 if (mService != null) {
6720 try {
6721 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
6722 if (providers != null) {
6723 return providers;
6724 }
6725 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006726 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07006727 }
6728 }
6729 return Collections.emptyList();
6730 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006731
6732 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08006733 * Called by profile or device owners to set the user's photo.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006734 *
6735 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6736 * @param icon the bitmap to set as the photo.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006737 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006738 */
Robin Lee25e26452015-06-02 09:56:29 -07006739 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006740 throwIfParentInstance("setUserIcon");
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006741 try {
6742 mService.setUserIcon(admin, icon);
6743 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006744 throw re.rethrowFromSystemServer();
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006745 }
6746 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04006747
6748 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01006749 * Called by device owners to set a local system update policy. When a new policy is set,
6750 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00006751 *
Robin Lee25e26452015-06-02 09:56:29 -07006752 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006753 * components in the device owner package can set system update policies and the most
6754 * recent policy takes effect.
Robin Lee25e26452015-06-02 09:56:29 -07006755 * @param policy the new policy, or {@code null} to clear the current policy.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006756 * @throws SecurityException if {@code admin} is not a device owner.
Rubin Xu5faad8e2015-04-20 17:43:48 +01006757 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00006758 */
Robin Lee25e26452015-06-02 09:56:29 -07006759 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006760 throwIfParentInstance("setSystemUpdatePolicy");
Rubin Xu8027a4f2015-03-10 17:52:37 +00006761 if (mService != null) {
6762 try {
Robin Lee25e26452015-06-02 09:56:29 -07006763 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00006764 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006765 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00006766 }
6767 }
6768 }
6769
6770 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01006771 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00006772 *
Robin Lee25e26452015-06-02 09:56:29 -07006773 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00006774 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006775 public @Nullable SystemUpdatePolicy getSystemUpdatePolicy() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006776 throwIfParentInstance("getSystemUpdatePolicy");
Rubin Xu8027a4f2015-03-10 17:52:37 +00006777 if (mService != null) {
6778 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01006779 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00006780 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006781 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00006782 }
6783 }
6784 return null;
6785 }
Benjamin Franze36087e2015-04-07 16:40:34 +01006786
6787 /**
6788 * Called by a device owner to disable the keyguard altogether.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006789 * <p>
6790 * Setting the keyguard to disabled has the same effect as choosing "None" as the screen lock
6791 * type. However, this call has no effect if a password, pin or pattern is currently set. If a
6792 * password, pin or pattern is set after the keyguard was disabled, the keyguard stops being
6793 * disabled.
Benjamin Franze36087e2015-04-07 16:40:34 +01006794 *
Benjamin Franz32a3bf32017-08-04 15:01:52 +01006795 * <p>
Benjamin Franz64affcb2017-09-01 13:47:22 +01006796 * As of {@link android.os.Build.VERSION_CODES#P}, this call also dismisses the
Benjamin Franz32a3bf32017-08-04 15:01:52 +01006797 * keyguard if it is currently shown.
6798 *
Benjamin Franze36087e2015-04-07 16:40:34 +01006799 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01006800 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01006801 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006802 * place. {@code true} otherwise.
6803 * @throws SecurityException if {@code admin} is not a device owner.
Benjamin Franze36087e2015-04-07 16:40:34 +01006804 */
Robin Lee25e26452015-06-02 09:56:29 -07006805 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006806 throwIfParentInstance("setKeyguardDisabled");
Benjamin Franze36087e2015-04-07 16:40:34 +01006807 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01006808 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01006809 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006810 throw re.rethrowFromSystemServer();
Benjamin Franze36087e2015-04-07 16:40:34 +01006811 }
6812 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00006813
6814 /**
Benjamin Franzbece8062015-05-06 12:14:31 +01006815 * Called by device owner to disable the status bar. Disabling the status bar blocks
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006816 * notifications, quick settings and other screen overlays that allow escaping from a single use
6817 * device.
Benjamin Franzea2ec972015-03-16 17:18:09 +00006818 *
6819 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01006820 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006821 * @return {@code false} if attempting to disable the status bar failed. {@code true} otherwise.
6822 * @throws SecurityException if {@code admin} is not a device owner.
Benjamin Franzea2ec972015-03-16 17:18:09 +00006823 */
Robin Lee25e26452015-06-02 09:56:29 -07006824 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006825 throwIfParentInstance("setStatusBarDisabled");
Benjamin Franzea2ec972015-03-16 17:18:09 +00006826 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01006827 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00006828 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006829 throw re.rethrowFromSystemServer();
Benjamin Franzea2ec972015-03-16 17:18:09 +00006830 }
6831 }
Rubin Xudc105cc2015-04-14 23:38:01 +01006832
6833 /**
Charles Hedea0c3b2017-01-13 10:04:12 +00006834 * Called by the system update service to notify device and profile owners of pending system
6835 * updates.
Rubin Xudc105cc2015-04-14 23:38:01 +01006836 *
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06006837 * This method should only be used when it is unknown whether the pending system
Charles Hedea0c3b2017-01-13 10:04:12 +00006838 * update is a security patch. Otherwise, use
6839 * {@link #notifyPendingSystemUpdate(long, boolean)}.
6840 *
6841 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()}
6842 * indicating when the current pending update was first available. {@code -1} if no
6843 * update is available.
6844 * @see #notifyPendingSystemUpdate(long, boolean)
Rubin Xudc105cc2015-04-14 23:38:01 +01006845 * @hide
6846 */
6847 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06006848 @RequiresPermission(android.Manifest.permission.NOTIFY_PENDING_SYSTEM_UPDATE)
Rubin Xudc105cc2015-04-14 23:38:01 +01006849 public void notifyPendingSystemUpdate(long updateReceivedTime) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006850 throwIfParentInstance("notifyPendingSystemUpdate");
Rubin Xudc105cc2015-04-14 23:38:01 +01006851 if (mService != null) {
6852 try {
Charles Hedea0c3b2017-01-13 10:04:12 +00006853 mService.notifyPendingSystemUpdate(SystemUpdateInfo.of(updateReceivedTime));
6854 } catch (RemoteException re) {
6855 throw re.rethrowFromSystemServer();
6856 }
6857 }
6858 }
6859
6860 /**
6861 * Called by the system update service to notify device and profile owners of pending system
6862 * updates.
6863 *
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06006864 * This method should be used instead of {@link #notifyPendingSystemUpdate(long)}
Charles Hedea0c3b2017-01-13 10:04:12 +00006865 * when it is known whether the pending system update is a security patch.
6866 *
6867 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()}
6868 * indicating when the current pending update was first available. {@code -1} if no
6869 * update is available.
6870 * @param isSecurityPatch {@code true} if this system update is purely a security patch;
6871 * {@code false} if not.
6872 * @see #notifyPendingSystemUpdate(long)
6873 * @hide
6874 */
6875 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06006876 @RequiresPermission(android.Manifest.permission.NOTIFY_PENDING_SYSTEM_UPDATE)
Charles Hedea0c3b2017-01-13 10:04:12 +00006877 public void notifyPendingSystemUpdate(long updateReceivedTime, boolean isSecurityPatch) {
6878 throwIfParentInstance("notifyPendingSystemUpdate");
6879 if (mService != null) {
6880 try {
6881 mService.notifyPendingSystemUpdate(SystemUpdateInfo.of(updateReceivedTime,
6882 isSecurityPatch));
Rubin Xudc105cc2015-04-14 23:38:01 +01006883 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006884 throw re.rethrowFromSystemServer();
Rubin Xudc105cc2015-04-14 23:38:01 +01006885 }
6886 }
6887 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04006888
6889 /**
Pavel Grafovd65799e2016-12-02 11:21:45 +00006890 * Called by device or profile owners to get information about a pending system update.
6891 *
6892 * @param admin Which profile or device owner this request is associated with.
6893 * @return Information about a pending system update or {@code null} if no update pending.
6894 * @throws SecurityException if {@code admin} is not a device or profile owner.
6895 * @see DeviceAdminReceiver#onSystemUpdatePending(Context, Intent, long)
6896 */
6897 public @Nullable SystemUpdateInfo getPendingSystemUpdate(@NonNull ComponentName admin) {
6898 throwIfParentInstance("getPendingSystemUpdate");
6899 try {
6900 return mService.getPendingSystemUpdate(admin);
6901 } catch (RemoteException re) {
6902 throw re.rethrowFromSystemServer();
6903 }
6904 }
6905
6906 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006907 * Set the default response for future runtime permission requests by applications. This
6908 * function can be called by a device owner, profile owner, or by a delegate given the
6909 * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}.
6910 * The policy can allow for normal operation which prompts the user to grant a permission, or
6911 * can allow automatic granting or denying of runtime permission requests by an application.
6912 * This also applies to new permissions declared by app updates. When a permission is denied or
6913 * granted this way, the effect is equivalent to setting the permission * grant state via
6914 * {@link #setPermissionGrantState}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006915 * <p/>
6916 * As this policy only acts on runtime permission requests, it only applies to applications
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07006917 * built with a {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Benjamin Franz45dd6662015-07-08 14:24:14 +01006918 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07006919 * @param admin Which profile or device owner this request is associated with.
6920 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006921 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
6922 * @throws SecurityException if {@code admin} is not a device or profile owner.
Benjamin Franz45dd6662015-07-08 14:24:14 +01006923 * @see #setPermissionGrantState
Edman Anjos52088e42017-01-13 22:26:17 +01006924 * @see #setDelegatedScopes
6925 * @see #DELEGATION_PERMISSION_GRANT
Amith Yamasanid49489b2015-04-28 14:00:26 -07006926 */
Robin Lee25e26452015-06-02 09:56:29 -07006927 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006928 throwIfParentInstance("setPermissionPolicy");
Amith Yamasanid49489b2015-04-28 14:00:26 -07006929 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006930 mService.setPermissionPolicy(admin, mContext.getPackageName(), policy);
Amith Yamasanid49489b2015-04-28 14:00:26 -07006931 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006932 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07006933 }
6934 }
6935
6936 /**
6937 * Returns the current runtime permission policy set by the device or profile owner. The
6938 * default is {@link #PERMISSION_POLICY_PROMPT}.
Edman Anjos52088e42017-01-13 22:26:17 +01006939 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07006940 * @param admin Which profile or device owner this request is associated with.
6941 * @return the current policy for future permission requests.
6942 */
Esteban Talavera28b95702015-06-24 15:23:42 +01006943 public int getPermissionPolicy(ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006944 throwIfParentInstance("getPermissionPolicy");
Amith Yamasanid49489b2015-04-28 14:00:26 -07006945 try {
6946 return mService.getPermissionPolicy(admin);
6947 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006948 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07006949 }
6950 }
6951
6952 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006953 * Sets the grant state of a runtime permission for a specific application. The state can be
6954 * {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it through the UI,
6955 * {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission is denied and the user
6956 * cannot manage it through the UI, and {@link #PERMISSION_GRANT_STATE_GRANTED granted} in which
6957 * the permission is granted and the user cannot manage it through the UI. This might affect all
6958 * permissions in a group that the runtime permission belongs to. This method can only be called
Edman Anjos52088e42017-01-13 22:26:17 +01006959 * by a profile owner, device owner, or a delegate given the
6960 * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006961 * <p/>
6962 * Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not revoke
6963 * the permission. It retains the previous grant, if any.
6964 * <p/>
6965 * Permissions can be granted or revoked only for applications built with a
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07006966 * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07006967 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07006968 * @param admin Which profile or device owner this request is associated with.
6969 * @param packageName The application to grant or revoke a permission to.
6970 * @param permission The permission to grant or revoke.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006971 * @param grantState The permission grant state which is one of
6972 * {@link #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
6973 * {@link #PERMISSION_GRANT_STATE_GRANTED},
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006974 * @return whether the permission was successfully granted or revoked.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006975 * @throws SecurityException if {@code admin} is not a device or profile owner.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006976 * @see #PERMISSION_GRANT_STATE_DENIED
6977 * @see #PERMISSION_GRANT_STATE_DEFAULT
6978 * @see #PERMISSION_GRANT_STATE_GRANTED
Edman Anjos52088e42017-01-13 22:26:17 +01006979 * @see #setDelegatedScopes
6980 * @see #DELEGATION_PERMISSION_GRANT
Amith Yamasanid49489b2015-04-28 14:00:26 -07006981 */
Robin Lee25e26452015-06-02 09:56:29 -07006982 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006983 String permission, int grantState) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006984 throwIfParentInstance("setPermissionGrantState");
Amith Yamasanid49489b2015-04-28 14:00:26 -07006985 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006986 return mService.setPermissionGrantState(admin, mContext.getPackageName(), packageName,
6987 permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07006988 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006989 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07006990 }
6991 }
Amith Yamasani184b3752015-05-22 13:00:51 -07006992
6993 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006994 * Returns the current grant state of a runtime permission for a specific application. This
6995 * function can be called by a device owner, profile owner, or by a delegate given the
6996 * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}.
Amith Yamasani184b3752015-05-22 13:00:51 -07006997 *
Edman Anjos52088e42017-01-13 22:26:17 +01006998 * @param admin Which profile or device owner this request is associated with, or {@code null}
6999 * if the caller is a permission grant delegate.
Amith Yamasani184b3752015-05-22 13:00:51 -07007000 * @param packageName The application to check the grant state for.
7001 * @param permission The permission to check for.
7002 * @return the current grant state specified by device policy. If the profile or device owner
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007003 * has not set a grant state, the return value is
7004 * {@link #PERMISSION_GRANT_STATE_DEFAULT}. This does not indicate whether or not the
7005 * permission is currently granted for the package.
7006 * <p/>
7007 * If a grant state was set by the profile or device owner, then the return value will
7008 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or
7009 * {@link #PERMISSION_GRANT_STATE_GRANTED}, which indicates if the permission is
7010 * currently denied or granted.
7011 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasani184b3752015-05-22 13:00:51 -07007012 * @see #setPermissionGrantState(ComponentName, String, String, int)
7013 * @see PackageManager#checkPermission(String, String)
Edman Anjos52088e42017-01-13 22:26:17 +01007014 * @see #setDelegatedScopes
7015 * @see #DELEGATION_PERMISSION_GRANT
Amith Yamasani184b3752015-05-22 13:00:51 -07007016 */
Bartosz Fabianowski4b0624f2017-01-16 11:47:28 +01007017 public int getPermissionGrantState(@Nullable ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07007018 String permission) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007019 throwIfParentInstance("getPermissionGrantState");
Amith Yamasani184b3752015-05-22 13:00:51 -07007020 try {
Edman Anjos52088e42017-01-13 22:26:17 +01007021 return mService.getPermissionGrantState(admin, mContext.getPackageName(), packageName,
7022 permission);
Amith Yamasani184b3752015-05-22 13:00:51 -07007023 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007024 throw re.rethrowFromSystemServer();
Amith Yamasani184b3752015-05-22 13:00:51 -07007025 }
7026 }
Nicolas Prevot07387fe2015-10-30 17:53:30 +00007027
7028 /**
Esteban Talavera01576862016-12-15 11:16:44 +00007029 * Returns whether it is possible for the caller to initiate provisioning of a managed profile
7030 * or device, setting itself as the device or profile owner.
7031 *
Nicolas Prevot07387fe2015-10-30 17:53:30 +00007032 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
7033 * {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Esteban Talavera01576862016-12-15 11:16:44 +00007034 * @return whether provisioning a managed profile or device is possible.
Nicolas Prevot07387fe2015-10-30 17:53:30 +00007035 * @throws IllegalArgumentException if the supplied action is not valid.
7036 */
Esteban Talavera01576862016-12-15 11:16:44 +00007037 public boolean isProvisioningAllowed(@NonNull String action) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007038 throwIfParentInstance("isProvisioningAllowed");
Nicolas Prevot07387fe2015-10-30 17:53:30 +00007039 try {
Esteban Talavera01576862016-12-15 11:16:44 +00007040 return mService.isProvisioningAllowed(action, mContext.getPackageName());
Nicolas Prevot07387fe2015-10-30 17:53:30 +00007041 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007042 throw re.rethrowFromSystemServer();
Nicolas Prevot07387fe2015-10-30 17:53:30 +00007043 }
7044 }
Mahaver Chopra15a46b02015-11-11 14:54:35 +00007045
7046 /**
Esteban Talavera01576862016-12-15 11:16:44 +00007047 * Checks whether it is possible to initiate provisioning a managed device,
7048 * profile or user, setting the given package as owner.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00007049 *
7050 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
7051 * {@link #ACTION_PROVISION_MANAGED_PROFILE},
7052 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE},
7053 * {@link #ACTION_PROVISION_MANAGED_USER}
Esteban Talavera01576862016-12-15 11:16:44 +00007054 * @param packageName The package of the component that would be set as device, user, or profile
7055 * owner.
7056 * @return A {@link ProvisioningPreCondition} value indicating whether provisioning is allowed.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00007057 * @hide
7058 */
Esteban Talavera01576862016-12-15 11:16:44 +00007059 public @ProvisioningPreCondition int checkProvisioningPreCondition(
7060 String action, @NonNull String packageName) {
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00007061 try {
Esteban Talavera01576862016-12-15 11:16:44 +00007062 return mService.checkProvisioningPreCondition(action, packageName);
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00007063 } catch (RemoteException re) {
7064 throw re.rethrowFromSystemServer();
7065 }
7066 }
7067
7068 /**
Mahaver Chopra15a46b02015-11-11 14:54:35 +00007069 * Return if this user is a managed profile of another user. An admin can become the profile
7070 * owner of a managed profile with {@link #ACTION_PROVISION_MANAGED_PROFILE} and of a managed
Kenny Guyffa38402016-03-31 16:40:57 +01007071 * user with {@link #createAndManageUser}
Mahaver Chopra15a46b02015-11-11 14:54:35 +00007072 * @param admin Which profile owner this request is associated with.
7073 * @return if this user is a managed profile of another user.
7074 */
7075 public boolean isManagedProfile(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007076 throwIfParentInstance("isManagedProfile");
Mahaver Chopra15a46b02015-11-11 14:54:35 +00007077 try {
7078 return mService.isManagedProfile(admin);
7079 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007080 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00007081 }
7082 }
7083
7084 /**
7085 * @hide
7086 * Return if this user is a system-only user. An admin can manage a device from a system only
7087 * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}.
7088 * @param admin Which device owner this request is associated with.
7089 * @return if this user is a system-only user.
7090 */
7091 public boolean isSystemOnlyUser(@NonNull ComponentName admin) {
7092 try {
7093 return mService.isSystemOnlyUser(admin);
7094 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007095 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00007096 }
7097 }
Makoto Onukia31ebbc2015-11-23 17:15:21 -08007098
7099 /**
7100 * Called by device owner to get the MAC address of the Wi-Fi device.
7101 *
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08007102 * @param admin Which device owner this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007103 * @return the MAC address of the Wi-Fi device, or null when the information is not available.
7104 * (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.)
7105 * <p>
7106 * The address will be in the {@code XX:XX:XX:XX:XX:XX} format.
7107 * @throws SecurityException if {@code admin} is not a device owner.
Makoto Onukia31ebbc2015-11-23 17:15:21 -08007108 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007109 public @Nullable String getWifiMacAddress(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007110 throwIfParentInstance("getWifiMacAddress");
Makoto Onukia31ebbc2015-11-23 17:15:21 -08007111 try {
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08007112 return mService.getWifiMacAddress(admin);
Makoto Onukia31ebbc2015-11-23 17:15:21 -08007113 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007114 throw re.rethrowFromSystemServer();
Makoto Onukia31ebbc2015-11-23 17:15:21 -08007115 }
7116 }
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00007117
7118 /**
Mahaver Chopra1216ae52016-03-11 15:39:48 +00007119 * Called by device owner to reboot the device. If there is an ongoing call on the device,
7120 * throws an {@link IllegalStateException}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007121 * @param admin Which device owner the request is associated with.
Mahaver Chopra1216ae52016-03-11 15:39:48 +00007122 * @throws IllegalStateException if device has an ongoing call.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007123 * @throws SecurityException if {@code admin} is not a device owner.
Mahaver Chopra1216ae52016-03-11 15:39:48 +00007124 * @see TelephonyManager#CALL_STATE_IDLE
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00007125 */
7126 public void reboot(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007127 throwIfParentInstance("reboot");
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00007128 try {
7129 mService.reboot(admin);
7130 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007131 throw re.rethrowFromSystemServer();
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00007132 }
7133 }
Kenny Guy06de4e72015-12-22 12:07:39 +00007134
7135 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007136 * Called by a device admin to set the short support message. This will be displayed to the user
7137 * in settings screens where funtionality has been disabled by the admin. The message should be
7138 * limited to a short statement such as "This setting is disabled by your administrator. Contact
7139 * someone@example.com for support." If the message is longer than 200 characters it may be
7140 * truncated.
7141 * <p>
7142 * If the short support message needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007143 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
7144 * and set a new version of this string accordingly.
7145 *
Kenny Guy06de4e72015-12-22 12:07:39 +00007146 * @see #setLongSupportMessage
Kenny Guy06de4e72015-12-22 12:07:39 +00007147 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007148 * @param message Short message to be displayed to the user in settings or null to clear the
7149 * existing message.
7150 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00007151 */
7152 public void setShortSupportMessage(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007153 @Nullable CharSequence message) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007154 throwIfParentInstance("setShortSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00007155 if (mService != null) {
7156 try {
7157 mService.setShortSupportMessage(admin, message);
7158 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007159 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00007160 }
7161 }
7162 }
7163
7164 /**
7165 * Called by a device admin to get the short support message.
7166 *
7167 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007168 * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)} or
7169 * null if no message has been set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007170 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00007171 */
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007172 public CharSequence getShortSupportMessage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007173 throwIfParentInstance("getShortSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00007174 if (mService != null) {
7175 try {
7176 return mService.getShortSupportMessage(admin);
7177 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007178 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00007179 }
7180 }
7181 return null;
7182 }
7183
7184 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007185 * Called by a device admin to set the long support message. This will be displayed to the user
7186 * in the device administators settings screen.
7187 * <p>
7188 * If the long support message needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007189 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
7190 * and set a new version of this string accordingly.
7191 *
Kenny Guy06de4e72015-12-22 12:07:39 +00007192 * @see #setShortSupportMessage
Kenny Guy06de4e72015-12-22 12:07:39 +00007193 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007194 * @param message Long message to be displayed to the user in settings or null to clear the
7195 * existing message.
7196 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00007197 */
7198 public void setLongSupportMessage(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007199 @Nullable CharSequence message) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007200 throwIfParentInstance("setLongSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00007201 if (mService != null) {
7202 try {
7203 mService.setLongSupportMessage(admin, message);
7204 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007205 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00007206 }
7207 }
7208 }
7209
7210 /**
7211 * Called by a device admin to get the long support message.
7212 *
7213 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007214 * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)} or
7215 * null if no message has been set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007216 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00007217 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007218 public @Nullable CharSequence getLongSupportMessage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007219 throwIfParentInstance("getLongSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00007220 if (mService != null) {
7221 try {
7222 return mService.getLongSupportMessage(admin);
7223 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007224 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00007225 }
7226 }
7227 return null;
7228 }
7229
7230 /**
7231 * Called by the system to get the short support message.
7232 *
7233 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7234 * @param userHandle user id the admin is running as.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007235 * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)}
Kenny Guy06de4e72015-12-22 12:07:39 +00007236 *
7237 * @hide
7238 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007239 public @Nullable CharSequence getShortSupportMessageForUser(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007240 int userHandle) {
Kenny Guy06de4e72015-12-22 12:07:39 +00007241 if (mService != null) {
7242 try {
7243 return mService.getShortSupportMessageForUser(admin, userHandle);
7244 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007245 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00007246 }
7247 }
7248 return null;
7249 }
7250
7251
7252 /**
7253 * Called by the system to get the long support message.
7254 *
7255 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7256 * @param userHandle user id the admin is running as.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007257 * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)}
Kenny Guy06de4e72015-12-22 12:07:39 +00007258 *
7259 * @hide
7260 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007261 public @Nullable CharSequence getLongSupportMessageForUser(
7262 @NonNull ComponentName admin, int userHandle) {
Kenny Guy06de4e72015-12-22 12:07:39 +00007263 if (mService != null) {
7264 try {
7265 return mService.getLongSupportMessageForUser(admin, userHandle);
7266 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007267 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00007268 }
7269 }
7270 return null;
7271 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00007272
7273 /**
Esteban Talavera62399912016-01-11 15:37:55 +00007274 * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager}
7275 * whose calls act on the parent profile.
Benjamin Franz66b45f02016-04-05 19:12:39 +01007276 *
7277 * <p>The following methods are supported for the parent instance, all other methods will
7278 * throw a SecurityException when called on the parent instance:
7279 * <ul>
7280 * <li>{@link #getPasswordQuality}</li>
7281 * <li>{@link #setPasswordQuality}</li>
7282 * <li>{@link #getPasswordMinimumLength}</li>
7283 * <li>{@link #setPasswordMinimumLength}</li>
7284 * <li>{@link #getPasswordMinimumUpperCase}</li>
7285 * <li>{@link #setPasswordMinimumUpperCase}</li>
7286 * <li>{@link #getPasswordMinimumLowerCase}</li>
7287 * <li>{@link #setPasswordMinimumLowerCase}</li>
7288 * <li>{@link #getPasswordMinimumLetters}</li>
7289 * <li>{@link #setPasswordMinimumLetters}</li>
7290 * <li>{@link #getPasswordMinimumNumeric}</li>
7291 * <li>{@link #setPasswordMinimumNumeric}</li>
7292 * <li>{@link #getPasswordMinimumSymbols}</li>
7293 * <li>{@link #setPasswordMinimumSymbols}</li>
7294 * <li>{@link #getPasswordMinimumNonLetter}</li>
7295 * <li>{@link #setPasswordMinimumNonLetter}</li>
7296 * <li>{@link #getPasswordHistoryLength}</li>
7297 * <li>{@link #setPasswordHistoryLength}</li>
7298 * <li>{@link #getPasswordExpirationTimeout}</li>
7299 * <li>{@link #setPasswordExpirationTimeout}</li>
7300 * <li>{@link #getPasswordExpiration}</li>
Charles He8c760562016-10-25 16:36:53 +01007301 * <li>{@link #getPasswordMaximumLength}</li>
Benjamin Franz66b45f02016-04-05 19:12:39 +01007302 * <li>{@link #isActivePasswordSufficient}</li>
7303 * <li>{@link #getCurrentFailedPasswordAttempts}</li>
7304 * <li>{@link #getMaximumFailedPasswordsForWipe}</li>
7305 * <li>{@link #setMaximumFailedPasswordsForWipe}</li>
7306 * <li>{@link #getMaximumTimeToLock}</li>
7307 * <li>{@link #setMaximumTimeToLock}</li>
7308 * <li>{@link #lockNow}</li>
7309 * <li>{@link #getKeyguardDisabledFeatures}</li>
7310 * <li>{@link #setKeyguardDisabledFeatures}</li>
7311 * <li>{@link #getTrustAgentConfiguration}</li>
7312 * <li>{@link #setTrustAgentConfiguration}</li>
Michal Karpinskia20d8bb2016-11-23 12:09:08 +00007313 * <li>{@link #getRequiredStrongAuthTimeout}</li>
7314 * <li>{@link #setRequiredStrongAuthTimeout}</li>
Benjamin Franz66b45f02016-04-05 19:12:39 +01007315 * </ul>
Clara Bayarri3e826ef2015-12-14 17:51:22 +00007316 *
7317 * @return a new instance of {@link DevicePolicyManager} that acts on the parent profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007318 * @throws SecurityException if {@code admin} is not a profile owner.
Clara Bayarri3e826ef2015-12-14 17:51:22 +00007319 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007320 public @NonNull DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007321 throwIfParentInstance("getParentProfileInstance");
Clara Bayarri3e826ef2015-12-14 17:51:22 +00007322 try {
7323 if (!mService.isManagedProfile(admin)) {
7324 throw new SecurityException("The current user does not have a parent profile.");
7325 }
Jeff Sharkey49ca5292016-05-10 12:54:45 -06007326 return new DevicePolicyManager(mContext, mService, true);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007327 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007328 throw e.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007329 }
7330 }
7331
7332 /**
Esteban Talaverad36dd152016-12-15 08:51:45 +00007333 * Called by device owner to control the security logging feature.
Michal Karpinski6235a942016-03-15 12:07:23 +00007334 *
7335 * <p> Security logs contain various information intended for security auditing purposes.
7336 * See {@link SecurityEvent} for details.
7337 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00007338 * <p><strong>Note:</strong> The device owner won't be able to retrieve security logs if there
7339 * are unaffiliated secondary users or profiles on the device, regardless of whether the
7340 * feature is enabled. Logs will be discarded if the internal buffer fills up while waiting for
7341 * all users to become affiliated. Therefore it's recommended that affiliation ids are set for
7342 * new users as soon as possible after provisioning via {@link #setAffiliationIds}.
Michal Karpinskib58e4962016-03-01 14:55:10 +00007343 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007344 * @param admin Which device owner this request is associated with.
Michal Karpinski6235a942016-03-15 12:07:23 +00007345 * @param enabled whether security logging should be enabled or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007346 * @throws SecurityException if {@code admin} is not a device owner.
Michal Karpinski6235a942016-03-15 12:07:23 +00007347 * @see #retrieveSecurityLogs
7348 */
7349 public void setSecurityLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007350 throwIfParentInstance("setSecurityLoggingEnabled");
Michal Karpinski6235a942016-03-15 12:07:23 +00007351 try {
7352 mService.setSecurityLoggingEnabled(admin, enabled);
7353 } catch (RemoteException re) {
7354 throw re.rethrowFromSystemServer();
7355 }
7356 }
7357
7358 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00007359 * Return whether security logging is enabled or not by the device owner.
7360 *
7361 * <p>Can only be called by the device owner, otherwise a {@link SecurityException} will be
7362 * thrown.
7363 *
7364 * @param admin Which device owner this request is associated with.
7365 * @return {@code true} if security logging is enabled by device owner, {@code false} otherwise.
7366 * @throws SecurityException if {@code admin} is not a device owner.
7367 */
Bartosz Fabianowski0ec00002017-03-24 14:22:24 +01007368 public boolean isSecurityLoggingEnabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007369 throwIfParentInstance("isSecurityLoggingEnabled");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007370 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00007371 return mService.isSecurityLoggingEnabled(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007372 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007373 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007374 }
7375 }
7376
7377 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00007378 * Called by device owner to retrieve all new security logging entries since the last call to
7379 * this API after device boots.
7380 *
7381 * <p> Access to the logs is rate limited and it will only return new logs after the device
7382 * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}.
7383 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00007384 * <p>If there is any other user or profile on the device, it must be affiliated with the
7385 * device owner. Otherwise a {@link SecurityException} will be thrown. See
7386 * {@link #setAffiliationIds}
Michal Karpinskib58e4962016-03-01 14:55:10 +00007387 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007388 * @param admin Which device owner this request is associated with.
Michal Karpinski6235a942016-03-15 12:07:23 +00007389 * @return the new batch of security logs which is a list of {@link SecurityEvent},
7390 * or {@code null} if rate limitation is exceeded or if logging is currently disabled.
Esteban Talaverad36dd152016-12-15 08:51:45 +00007391 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
7392 * profile or secondary user that is not affiliated with the device owner user.
7393 * @see DeviceAdminReceiver#onSecurityLogsAvailable
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007394 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007395 public @Nullable List<SecurityEvent> retrieveSecurityLogs(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007396 throwIfParentInstance("retrieveSecurityLogs");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007397 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00007398 ParceledListSlice<SecurityEvent> list = mService.retrieveSecurityLogs(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007399 if (list != null) {
7400 return list.getList();
7401 } else {
7402 // Rate limit exceeded.
7403 return null;
7404 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00007405 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007406 throw re.rethrowFromSystemServer();
Clara Bayarri3e826ef2015-12-14 17:51:22 +00007407 }
7408 }
Benjamin Franz59720bb2016-01-18 15:26:11 +00007409
7410 /**
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00007411 * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent
7412 * profile.
7413 *
7414 * @hide
7415 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007416 public @NonNull DevicePolicyManager getParentProfileInstance(UserInfo uInfo) {
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00007417 mContext.checkSelfPermission(
7418 android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS);
7419 if (!uInfo.isManagedProfile()) {
7420 throw new SecurityException("The user " + uInfo.id
7421 + " does not have a parent profile.");
7422 }
Jeff Sharkey49ca5292016-05-10 12:54:45 -06007423 return new DevicePolicyManager(mContext, mService, true);
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00007424 }
7425
7426 /**
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007427 * Called by device owners to retrieve device logs from before the device's last reboot.
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007428 * <p>
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01007429 * <strong> This API is not supported on all devices. Calling this API on unsupported devices
7430 * will result in {@code null} being returned. The device logs are retrieved from a RAM region
7431 * which is not guaranteed to be corruption-free during power cycles, as a result be cautious
7432 * about data corruption when parsing. </strong>
Esteban Talaverad36dd152016-12-15 08:51:45 +00007433 *
7434 * <p>If there is any other user or profile on the device, it must be affiliated with the
7435 * device owner. Otherwise a {@link SecurityException} will be thrown. See
7436 * {@link #setAffiliationIds}
Michal Karpinskib58e4962016-03-01 14:55:10 +00007437 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007438 * @param admin Which device owner this request is associated with.
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01007439 * @return Device logs from before the latest reboot of the system, or {@code null} if this API
7440 * is not supported on the device.
Esteban Talaverad36dd152016-12-15 08:51:45 +00007441 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
7442 * profile or secondary user that is not affiliated with the device owner user.
7443 * @see #retrieveSecurityLogs
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007444 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007445 public @Nullable List<SecurityEvent> retrievePreRebootSecurityLogs(
7446 @NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007447 throwIfParentInstance("retrievePreRebootSecurityLogs");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007448 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00007449 ParceledListSlice<SecurityEvent> list = mService.retrievePreRebootSecurityLogs(admin);
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01007450 if (list != null) {
7451 return list.getList();
7452 } else {
7453 return null;
7454 }
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007455 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007456 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007457 }
7458 }
7459
7460 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007461 * Called by a profile owner of a managed profile to set the color used for customization. This
7462 * color is used as background color of the confirm credentials screen for that user. The
Clara Bayarri8d0bd7fa2016-03-30 14:59:58 +01007463 * default color is teal (#00796B).
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007464 * <p>
7465 * The confirm credentials screen can be created using
Benjamin Franz59720bb2016-01-18 15:26:11 +00007466 * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}.
7467 *
7468 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinski74cd7302016-04-12 15:17:36 +01007469 * @param color The 24bit (0xRRGGBB) representation of the color to be used.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007470 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz59720bb2016-01-18 15:26:11 +00007471 */
7472 public void setOrganizationColor(@NonNull ComponentName admin, int color) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007473 throwIfParentInstance("setOrganizationColor");
Benjamin Franz59720bb2016-01-18 15:26:11 +00007474 try {
Michal Karpinski74cd7302016-04-12 15:17:36 +01007475 // always enforce alpha channel to have 100% opacity
7476 color |= 0xFF000000;
Benjamin Franz59720bb2016-01-18 15:26:11 +00007477 mService.setOrganizationColor(admin, color);
7478 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007479 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00007480 }
7481 }
7482
7483 /**
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00007484 * @hide
7485 *
7486 * Sets the color used for customization.
7487 *
Michal Karpinski74cd7302016-04-12 15:17:36 +01007488 * @param color The 24bit (0xRRGGBB) representation of the color to be used.
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00007489 * @param userId which user to set the color to.
7490 * @RequiresPermission(allOf = {
7491 * Manifest.permission.MANAGE_USERS,
7492 * Manifest.permission.INTERACT_ACROSS_USERS_FULL})
7493 */
7494 public void setOrganizationColorForUser(@ColorInt int color, @UserIdInt int userId) {
7495 try {
Michal Karpinski74cd7302016-04-12 15:17:36 +01007496 // always enforce alpha channel to have 100% opacity
7497 color |= 0xFF000000;
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00007498 mService.setOrganizationColorForUser(color, userId);
7499 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007500 throw re.rethrowFromSystemServer();
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00007501 }
7502 }
7503
7504 /**
Benjamin Franz59720bb2016-01-18 15:26:11 +00007505 * Called by a profile owner of a managed profile to retrieve the color used for customization.
7506 * This color is used as background color of the confirm credentials screen for that user.
7507 *
7508 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinski74cd7302016-04-12 15:17:36 +01007509 * @return The 24bit (0xRRGGBB) representation of the color to be used.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007510 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz59720bb2016-01-18 15:26:11 +00007511 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01007512 public @ColorInt int getOrganizationColor(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007513 throwIfParentInstance("getOrganizationColor");
Benjamin Franz59720bb2016-01-18 15:26:11 +00007514 try {
7515 return mService.getOrganizationColor(admin);
7516 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007517 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00007518 }
7519 }
7520
7521 /**
7522 * @hide
7523 * Retrieve the customization color for a given user.
7524 *
7525 * @param userHandle The user id of the user we're interested in.
Michal Karpinski74cd7302016-04-12 15:17:36 +01007526 * @return The 24bit (0xRRGGBB) representation of the color to be used.
Benjamin Franz59720bb2016-01-18 15:26:11 +00007527 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01007528 public @ColorInt int getOrganizationColorForUser(int userHandle) {
Benjamin Franz59720bb2016-01-18 15:26:11 +00007529 try {
7530 return mService.getOrganizationColorForUser(userHandle);
7531 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007532 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00007533 }
7534 }
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007535
7536 /**
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01007537 * Called by the device owner or profile owner to set the name of the organization under
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007538 * management.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007539 * <p>
7540 * If the organization name needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007541 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
7542 * and set a new version of this string accordingly.
7543 *
7544 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7545 * @param title The organization name or {@code null} to clear a previously set name.
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01007546 * @throws SecurityException if {@code admin} is not a device or profile owner.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007547 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01007548 public void setOrganizationName(@NonNull ComponentName admin, @Nullable CharSequence title) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007549 throwIfParentInstance("setOrganizationName");
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007550 try {
7551 mService.setOrganizationName(admin, title);
7552 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007553 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007554 }
7555 }
7556
7557 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007558 * Called by a profile owner of a managed profile to retrieve the name of the organization under
7559 * management.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007560 *
7561 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7562 * @return The organization name or {@code null} if none is set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007563 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007564 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007565 public @Nullable CharSequence getOrganizationName(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007566 throwIfParentInstance("getOrganizationName");
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007567 try {
7568 return mService.getOrganizationName(admin);
7569 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007570 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007571 }
7572 }
7573
7574 /**
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01007575 * Called by the system to retrieve the name of the organization managing the device.
7576 *
7577 * @return The organization name or {@code null} if none is set.
7578 * @throws SecurityException if the caller is not the device owner, does not hold the
7579 * MANAGE_USERS permission and is not the system.
7580 *
7581 * @hide
7582 */
7583 @SystemApi
7584 @TestApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06007585 @SuppressLint("Doclava125")
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01007586 public @Nullable CharSequence getDeviceOwnerOrganizationName() {
7587 try {
7588 return mService.getDeviceOwnerOrganizationName();
7589 } catch (RemoteException re) {
7590 throw re.rethrowFromSystemServer();
7591 }
7592 }
7593
7594 /**
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007595 * Retrieve the default title message used in the confirm credentials screen for a given user.
7596 *
7597 * @param userHandle The user id of the user we're interested in.
7598 * @return The organization name or {@code null} if none is set.
7599 *
7600 * @hide
7601 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007602 public @Nullable CharSequence getOrganizationNameForUser(int userHandle) {
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007603 try {
7604 return mService.getOrganizationNameForUser(userHandle);
7605 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007606 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007607 }
7608 }
7609
7610 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00007611 * @return the {@link UserProvisioningState} for the current user - for unmanaged users will
7612 * return {@link #STATE_USER_UNMANAGED}
7613 * @hide
7614 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00007615 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00007616 @UserProvisioningState
7617 public int getUserProvisioningState() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007618 throwIfParentInstance("getUserProvisioningState");
Alan Treadwayafad8782016-01-19 15:15:08 +00007619 if (mService != null) {
7620 try {
7621 return mService.getUserProvisioningState();
7622 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007623 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00007624 }
7625 }
7626 return STATE_USER_UNMANAGED;
7627 }
7628
7629 /**
7630 * Set the {@link UserProvisioningState} for the supplied user, if they are managed.
7631 *
7632 * @param state to store
7633 * @param userHandle for user
7634 * @hide
7635 */
7636 public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) {
7637 if (mService != null) {
7638 try {
7639 mService.setUserProvisioningState(state, userHandle);
7640 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007641 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00007642 }
7643 }
7644 }
7645
7646 /**
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007647 * Indicates the entity that controls the device or profile owner. Two users/profiles are
7648 * affiliated if the set of ids set by their device or profile owners intersect.
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007649 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00007650 * <p><strong>Note:</strong> Features that depend on user affiliation (such as security logging
7651 * or {@link #bindDeviceAdminServiceAsUser}) won't be available when a secondary user or profile
7652 * is created, until it becomes affiliated. Therefore it is recommended that the appropriate
7653 * affiliation ids are set by its profile owner as soon as possible after the user/profile is
7654 * created.
7655 *
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007656 * @param admin Which profile or device owner this request is associated with.
Tony Mak31657432017-04-25 09:29:55 +01007657 * @param ids A set of opaque non-empty affiliation ids.
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007658 *
Tony Mak31657432017-04-25 09:29:55 +01007659 * @throws IllegalArgumentException if {@code ids} is null or contains an empty string.
7660 */
7661 public void setAffiliationIds(@NonNull ComponentName admin, @NonNull Set<String> ids) {
7662 throwIfParentInstance("setAffiliationIds");
7663 if (ids == null) {
7664 throw new IllegalArgumentException("ids must not be null");
7665 }
7666 try {
7667 mService.setAffiliationIds(admin, new ArrayList<>(ids));
7668 } catch (RemoteException e) {
7669 throw e.rethrowFromSystemServer();
7670 }
7671 }
7672
7673 /**
Tony Mak31657432017-04-25 09:29:55 +01007674 * Returns the set of affiliation ids previously set via {@link #setAffiliationIds}, or an
7675 * empty set if none have been set.
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007676 */
Tony Mak31657432017-04-25 09:29:55 +01007677 public @NonNull Set<String> getAffiliationIds(@NonNull ComponentName admin) {
Tony Mak62cf5862017-05-02 13:50:18 +01007678 throwIfParentInstance("getAffiliationIds");
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007679 try {
Tony Mak31657432017-04-25 09:29:55 +01007680 return new ArraySet<>(mService.getAffiliationIds(admin));
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007681 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007682 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007683 }
7684 }
7685
7686 /**
7687 * @hide
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007688 * Returns whether this user/profile is affiliated with the device.
7689 * <p>
7690 * By definition, the user that the device owner runs on is always affiliated with the device.
7691 * Any other user/profile is considered affiliated with the device if the set specified by its
7692 * profile owner via {@link #setAffiliationIds} intersects with the device owner's.
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007693 *
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007694 */
7695 public boolean isAffiliatedUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007696 throwIfParentInstance("isAffiliatedUser");
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007697 try {
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007698 return mService.isAffiliatedUser();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007699 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007700 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007701 }
7702 }
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08007703
7704 /**
7705 * @hide
7706 * Returns whether the uninstall for {@code packageName} for the current user is in queue
7707 * to be started
7708 * @param packageName the package to check for
7709 * @return whether the uninstall intent for {@code packageName} is pending
7710 */
7711 public boolean isUninstallInQueue(String packageName) {
7712 try {
7713 return mService.isUninstallInQueue(packageName);
7714 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007715 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08007716 }
7717 }
7718
7719 /**
7720 * @hide
7721 * @param packageName the package containing active DAs to be uninstalled
7722 */
7723 public void uninstallPackageWithActiveAdmins(String packageName) {
7724 try {
7725 mService.uninstallPackageWithActiveAdmins(packageName);
7726 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007727 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08007728 }
7729 }
Benjamin Franzbc33c822016-04-15 08:57:52 +01007730
Kenny Guy38dcca52016-04-19 13:09:18 +01007731 /**
7732 * @hide
7733 * Remove a test admin synchronously without sending it a broadcast about being removed.
7734 * If the admin is a profile owner or device owner it will still be removed.
7735 *
7736 * @param userHandle user id to remove the admin for.
7737 * @param admin The administration compononent to remove.
7738 * @throws SecurityException if the caller is not shell / root or the admin package
7739 * isn't a test application see {@link ApplicationInfo#FLAG_TEST_APP}.
7740 */
7741 public void forceRemoveActiveAdmin(ComponentName adminReceiver, int userHandle) {
7742 try {
7743 mService.forceRemoveActiveAdmin(adminReceiver, userHandle);
7744 } catch (RemoteException re) {
7745 throw re.rethrowFromSystemServer();
7746 }
7747 }
7748
Mahaver Chopra790d1982016-07-07 16:06:49 +01007749 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007750 * Returns whether the device has been provisioned.
7751 *
7752 * <p>Not for use by third-party applications.
7753 *
Mahaver Chopra790d1982016-07-07 16:06:49 +01007754 * @hide
Mahaver Chopra790d1982016-07-07 16:06:49 +01007755 */
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007756 @SystemApi
Mahaver Chopra790d1982016-07-07 16:06:49 +01007757 public boolean isDeviceProvisioned() {
7758 try {
7759 return mService.isDeviceProvisioned();
7760 } catch (RemoteException re) {
7761 throw re.rethrowFromSystemServer();
7762 }
7763 }
7764
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007765 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007766 * Writes that the provisioning configuration has been applied.
7767 *
7768 * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS}
7769 * permission.
7770 *
7771 * <p>Not for use by third-party applications.
7772 *
7773 * @hide
7774 */
7775 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06007776 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007777 public void setDeviceProvisioningConfigApplied() {
7778 try {
7779 mService.setDeviceProvisioningConfigApplied();
7780 } catch (RemoteException re) {
7781 throw re.rethrowFromSystemServer();
7782 }
7783 }
7784
7785 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007786 * Returns whether the provisioning configuration has been applied.
7787 *
7788 * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS} permission.
7789 *
7790 * <p>Not for use by third-party applications.
7791 *
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007792 * @return whether the provisioning configuration has been applied.
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007793 *
7794 * @hide
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007795 */
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007796 @SystemApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06007797 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007798 public boolean isDeviceProvisioningConfigApplied() {
7799 try {
7800 return mService.isDeviceProvisioningConfigApplied();
7801 } catch (RemoteException re) {
7802 throw re.rethrowFromSystemServer();
7803 }
7804 }
7805
Victor Chang9bfc65f2016-08-15 12:27:09 +01007806 /**
7807 * @hide
Victor Chang3577ed22016-08-25 18:49:26 +01007808 * Force update user setup completed status. This API has no effect on user build.
7809 * @throws {@link SecurityException} if the caller has no
Esteban Talavera01576862016-12-15 11:16:44 +00007810 * {@code android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS} or the caller is
7811 * not {@link UserHandle#SYSTEM_USER}
Victor Chang9bfc65f2016-08-15 12:27:09 +01007812 */
7813 public void forceUpdateUserSetupComplete() {
7814 try {
7815 mService.forceUpdateUserSetupComplete();
7816 } catch (RemoteException re) {
7817 throw re.rethrowFromSystemServer();
7818 }
7819 }
7820
Benjamin Franzbc33c822016-04-15 08:57:52 +01007821 private void throwIfParentInstance(String functionName) {
7822 if (mParentInstance) {
7823 throw new SecurityException(functionName + " cannot be called on the parent instance");
7824 }
7825 }
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007826
7827 /**
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007828 * Allows the device owner to enable or disable the backup service.
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007829 *
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007830 * <p> Backup service manages all backup and restore mechanisms on the device. Setting this to
7831 * false will prevent data from being backed up or restored.
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007832 *
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007833 * <p> Backup service is off by default when device owner is present.
7834 *
Rubin Xu0367f072017-04-24 20:17:16 +01007835 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7836 * @param enabled {@code true} to enable the backup service, {@code false} to disable it.
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007837 * @throws SecurityException if {@code admin} is not a device owner.
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007838 */
7839 public void setBackupServiceEnabled(@NonNull ComponentName admin, boolean enabled) {
Esteban Talavera5b7f2d02017-02-17 09:45:24 +00007840 throwIfParentInstance("setBackupServiceEnabled");
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007841 try {
7842 mService.setBackupServiceEnabled(admin, enabled);
7843 } catch (RemoteException re) {
7844 throw re.rethrowFromSystemServer();
7845 }
7846 }
7847
7848 /**
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007849 * Return whether the backup service is enabled by the device owner.
7850 *
7851 * <p> Backup service manages all backup and restore mechanisms on the device.
7852 *
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007853 * @return {@code true} if backup service is enabled, {@code false} otherwise.
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007854 * @see #setBackupServiceEnabled
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007855 */
7856 public boolean isBackupServiceEnabled(@NonNull ComponentName admin) {
Esteban Talavera5b7f2d02017-02-17 09:45:24 +00007857 throwIfParentInstance("isBackupServiceEnabled");
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007858 try {
7859 return mService.isBackupServiceEnabled(admin);
7860 } catch (RemoteException re) {
7861 throw re.rethrowFromSystemServer();
7862 }
7863 }
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007864
7865 /**
Esteban Talaverad36dd152016-12-15 08:51:45 +00007866 * Called by a device owner to control the network logging feature.
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007867 *
Robin Leea40a2fb2017-02-08 17:07:06 +00007868 * <p> Network logs contain DNS lookup and connect() library call events. The following library
7869 * functions are recorded while network logging is active:
7870 * <ul>
7871 * <li>{@code getaddrinfo()}</li>
7872 * <li>{@code gethostbyname()}</li>
7873 * <li>{@code connect()}</li>
7874 * </ul>
7875 *
7876 * <p> Network logging is a low-overhead tool for forensics but it is not guaranteed to use
7877 * full system call logging; event reporting is enabled by default for all processes but not
7878 * strongly enforced.
7879 * Events from applications using alternative implementations of libc, making direct kernel
7880 * calls, or deliberately obfuscating traffic may not be recorded.
7881 *
7882 * <p> Some common network events may not be reported. For example:
7883 * <ul>
7884 * <li>Applications may hardcode IP addresses to reduce the number of DNS lookups, or use
7885 * an alternative system for name resolution, and so avoid calling
7886 * {@code getaddrinfo()} or {@code gethostbyname}.</li>
7887 * <li>Applications may use datagram sockets for performance reasons, for example
7888 * for a game client. Calling {@code connect()} is unnecessary for this kind of
7889 * socket, so it will not trigger a network event.</li>
7890 * </ul>
7891 *
7892 * <p> It is possible to directly intercept layer 3 traffic leaving the device using an
7893 * always-on VPN service.
7894 * See {@link #setAlwaysOnVpnPackage(ComponentName, String, boolean)}
7895 * and {@link android.net.VpnService} for details.
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007896 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00007897 * <p><strong>Note:</strong> The device owner won't be able to retrieve network logs if there
7898 * are unaffiliated secondary users or profiles on the device, regardless of whether the
7899 * feature is enabled. Logs will be discarded if the internal buffer fills up while waiting for
7900 * all users to become affiliated. Therefore it's recommended that affiliation ids are set for
7901 * new users as soon as possible after provisioning via {@link #setAffiliationIds}.
7902 *
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007903 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7904 * @param enabled whether network logging should be enabled or not.
Esteban Talaverad36dd152016-12-15 08:51:45 +00007905 * @throws SecurityException if {@code admin} is not a device owner.
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007906 * @see #retrieveNetworkLogs
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007907 */
7908 public void setNetworkLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
7909 throwIfParentInstance("setNetworkLoggingEnabled");
7910 try {
7911 mService.setNetworkLoggingEnabled(admin, enabled);
7912 } catch (RemoteException re) {
7913 throw re.rethrowFromSystemServer();
7914 }
7915 }
7916
7917 /**
7918 * Return whether network logging is enabled by a device owner.
7919 *
phweissa4e169e2016-11-24 16:20:57 +01007920 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Can only
7921 * be {@code null} if the caller has MANAGE_USERS permission.
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007922 * @return {@code true} if network logging is enabled by device owner, {@code false} otherwise.
Esteban Talaverad36dd152016-12-15 08:51:45 +00007923 * @throws SecurityException if {@code admin} is not a device owner and caller has
phweissa4e169e2016-11-24 16:20:57 +01007924 * no MANAGE_USERS permission
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007925 */
phweissa4e169e2016-11-24 16:20:57 +01007926 public boolean isNetworkLoggingEnabled(@Nullable ComponentName admin) {
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007927 throwIfParentInstance("isNetworkLoggingEnabled");
7928 try {
7929 return mService.isNetworkLoggingEnabled(admin);
7930 } catch (RemoteException re) {
7931 throw re.rethrowFromSystemServer();
7932 }
7933 }
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007934
7935 /**
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007936 * Called by device owner to retrieve the most recent batch of network logging events.
7937 * A device owner has to provide a batchToken provided as part of
7938 * {@link DeviceAdminReceiver#onNetworkLogsAvailable} callback. If the token doesn't match the
7939 * token of the most recent available batch of logs, {@code null} will be returned.
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007940 *
7941 * <p> {@link NetworkEvent} can be one of {@link DnsEvent} or {@link ConnectEvent}.
7942 *
7943 * <p> The list of network events is sorted chronologically, and contains at most 1200 events.
7944 *
7945 * <p> Access to the logs is rate limited and this method will only return a new batch of logs
7946 * after the device device owner has been notified via
7947 * {@link DeviceAdminReceiver#onNetworkLogsAvailable}.
7948 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00007949 * <p>If a secondary user or profile is created, calling this method will throw a
7950 * {@link SecurityException} until all users become affiliated again. It will also no longer be
7951 * possible to retrieve the network logs batch with the most recent batchToken provided
7952 * by {@link DeviceAdminReceiver#onNetworkLogsAvailable}. See
7953 * {@link DevicePolicyManager#setAffiliationIds}.
7954 *
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007955 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007956 * @param batchToken A token of the batch to retrieve
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007957 * @return A new batch of network logs which is a list of {@link NetworkEvent}. Returns
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007958 * {@code null} if the batch represented by batchToken is no longer available or if
7959 * logging is disabled.
Esteban Talaverad36dd152016-12-15 08:51:45 +00007960 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
7961 * profile or secondary user that is not affiliated with the device owner user.
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007962 * @see DeviceAdminReceiver#onNetworkLogsAvailable
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007963 */
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007964 public @Nullable List<NetworkEvent> retrieveNetworkLogs(@NonNull ComponentName admin,
7965 long batchToken) {
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007966 throwIfParentInstance("retrieveNetworkLogs");
7967 try {
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007968 return mService.retrieveNetworkLogs(admin, batchToken);
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007969 } catch (RemoteException re) {
7970 throw re.rethrowFromSystemServer();
7971 }
7972 }
Tony Mak46aabe52016-11-14 12:53:06 +00007973
7974 /**
Esteban Talavera2f897912017-01-26 10:30:48 +00007975 * Called by a device owner to bind to a service from a profile owner or vice versa.
7976 * See {@link #getBindDeviceAdminTargetUsers} for a definition of which
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007977 * device/profile owners are allowed to bind to services of another profile/device owner.
7978 * <p>
Tony Makeda0a9a2017-04-25 12:07:14 +01007979 * The service must be protected by {@link android.Manifest.permission#BIND_DEVICE_ADMIN}.
7980 * Note that the {@link Context} used to obtain this
Tony Mak46aabe52016-11-14 12:53:06 +00007981 * {@link DevicePolicyManager} instance via {@link Context#getSystemService(Class)} will be used
7982 * to bind to the {@link android.app.Service}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007983 *
Tony Mak46aabe52016-11-14 12:53:06 +00007984 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7985 * @param serviceIntent Identifies the service to connect to. The Intent must specify either an
7986 * explicit component name or a package name to match an
7987 * {@link IntentFilter} published by a service.
Tony Makbf9928d2016-12-22 11:02:45 +00007988 * @param conn Receives information as the service is started and stopped in main thread. This
7989 * must be a valid {@link ServiceConnection} object; it must not be {@code null}.
Tony Mak46aabe52016-11-14 12:53:06 +00007990 * @param flags Operation options for the binding operation. See
7991 * {@link Context#bindService(Intent, ServiceConnection, int)}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007992 * @param targetUser Which user to bind to. Must be one of the users returned by
7993 * {@link #getBindDeviceAdminTargetUsers}, otherwise a {@link SecurityException} will
7994 * be thrown.
Tony Mak46aabe52016-11-14 12:53:06 +00007995 * @return If you have successfully bound to the service, {@code true} is returned;
7996 * {@code false} is returned if the connection is not made and you will not
7997 * receive the service object.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007998 *
Tony Mak46aabe52016-11-14 12:53:06 +00007999 * @see Context#bindService(Intent, ServiceConnection, int)
Esteban Talaverafc291bc2016-11-21 13:52:03 +00008000 * @see #getBindDeviceAdminTargetUsers(ComponentName)
Tony Mak46aabe52016-11-14 12:53:06 +00008001 */
8002 public boolean bindDeviceAdminServiceAsUser(
8003 @NonNull ComponentName admin, Intent serviceIntent, @NonNull ServiceConnection conn,
8004 @Context.BindServiceFlags int flags, @NonNull UserHandle targetUser) {
8005 throwIfParentInstance("bindDeviceAdminServiceAsUser");
8006 // Keep this in sync with ContextImpl.bindServiceCommon.
8007 try {
Tony Makbf9928d2016-12-22 11:02:45 +00008008 final IServiceConnection sd = mContext.getServiceDispatcher(
8009 conn, mContext.getMainThreadHandler(), flags);
Tony Mak46aabe52016-11-14 12:53:06 +00008010 serviceIntent.prepareToLeaveProcess(mContext);
8011 return mService.bindDeviceAdminServiceAsUser(admin,
8012 mContext.getIApplicationThread(), mContext.getActivityToken(), serviceIntent,
8013 sd, flags, targetUser.getIdentifier());
8014 } catch (RemoteException re) {
8015 throw re.rethrowFromSystemServer();
8016 }
8017 }
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01008018
8019 /**
Esteban Talaverafc291bc2016-11-21 13:52:03 +00008020 * Returns the list of target users that the calling device or profile owner can use when
8021 * calling {@link #bindDeviceAdminServiceAsUser}.
8022 * <p>
Esteban Talavera2f897912017-01-26 10:30:48 +00008023 * A device owner can bind to a service from a profile owner and vice versa, provided that:
Esteban Talaverafc291bc2016-11-21 13:52:03 +00008024 * <ul>
8025 * <li>Both belong to the same package name.
Esteban Talavera2f897912017-01-26 10:30:48 +00008026 * <li>Both users are affiliated. See {@link #setAffiliationIds}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00008027 * </ul>
8028 */
8029 public @NonNull List<UserHandle> getBindDeviceAdminTargetUsers(@NonNull ComponentName admin) {
8030 throwIfParentInstance("getBindDeviceAdminTargetUsers");
8031 try {
8032 return mService.getBindDeviceAdminTargetUsers(admin);
8033 } catch (RemoteException re) {
8034 throw re.rethrowFromSystemServer();
8035 }
8036 }
8037
8038 /**
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01008039 * Called by the system to get the time at which the device owner last retrieved security
8040 * logging entries.
8041 *
8042 * @return the time at which the device owner most recently retrieved security logging entries,
8043 * in milliseconds since epoch; -1 if security logging entries were never retrieved.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01008044 * @throws SecurityException if the caller is not the device owner, does not hold the
8045 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01008046 *
8047 * @hide
8048 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01008049 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01008050 public long getLastSecurityLogRetrievalTime() {
8051 try {
8052 return mService.getLastSecurityLogRetrievalTime();
8053 } catch (RemoteException re) {
8054 throw re.rethrowFromSystemServer();
8055 }
8056 }
8057
8058 /**
8059 * Called by the system to get the time at which the device owner last requested a bug report.
8060 *
8061 * @return the time at which the device owner most recently requested a bug report, in
8062 * milliseconds since epoch; -1 if a bug report was never requested.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01008063 * @throws SecurityException if the caller is not the device owner, does not hold the
8064 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01008065 *
8066 * @hide
8067 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01008068 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01008069 public long getLastBugReportRequestTime() {
8070 try {
8071 return mService.getLastBugReportRequestTime();
8072 } catch (RemoteException re) {
8073 throw re.rethrowFromSystemServer();
8074 }
8075 }
8076
8077 /**
8078 * Called by the system to get the time at which the device owner last retrieved network logging
8079 * events.
8080 *
8081 * @return the time at which the device owner most recently retrieved network logging events, in
8082 * milliseconds since epoch; -1 if network logging events were never retrieved.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01008083 * @throws SecurityException if the caller is not the device owner, does not hold the
8084 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01008085 *
8086 * @hide
8087 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01008088 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01008089 public long getLastNetworkLogRetrievalTime() {
8090 try {
8091 return mService.getLastNetworkLogRetrievalTime();
8092 } catch (RemoteException re) {
8093 throw re.rethrowFromSystemServer();
8094 }
8095 }
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01008096
8097 /**
Bartosz Fabianowski172f7802017-03-06 12:07:57 +01008098 * Called by the system to find out whether the current user's IME was set by the device/profile
8099 * owner or the user.
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01008100 *
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01008101 * @return {@code true} if the user's IME was set by the device or profile owner, {@code false}
8102 * otherwise.
Bartosz Fabianowski172f7802017-03-06 12:07:57 +01008103 * @throws SecurityException if the caller is not the device owner/profile owner.
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01008104 *
8105 * @hide
8106 */
8107 @TestApi
Bartosz Fabianowski172f7802017-03-06 12:07:57 +01008108 public boolean isCurrentInputMethodSetByOwner() {
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01008109 try {
Bartosz Fabianowski172f7802017-03-06 12:07:57 +01008110 return mService.isCurrentInputMethodSetByOwner();
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01008111 } catch (RemoteException re) {
8112 throw re.rethrowFromSystemServer();
8113 }
8114 }
Bartosz Fabianowski05dc9f72017-02-22 23:41:14 +01008115
Bartosz Fabianowski05dc9f72017-02-22 23:41:14 +01008116 /**
8117 * Called by the system to get a list of CA certificates that were installed by the device or
8118 * profile owner.
8119 *
Bartosz Fabianowski172f7802017-03-06 12:07:57 +01008120 * <p> The caller must be the target user's device owner/profile Owner or hold the
Bartosz Fabianowski05dc9f72017-02-22 23:41:14 +01008121 * {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} permission.
8122 *
8123 * @param user The user for whom to retrieve information.
8124 * @return list of aliases identifying CA certificates installed by the device or profile owner
8125 * @throws SecurityException if the caller does not have permission to retrieve information
8126 * about the given user's CA certificates.
8127 *
8128 * @hide
8129 */
8130 @TestApi
8131 public List<String> getOwnerInstalledCaCerts(@NonNull UserHandle user) {
8132 try {
8133 return mService.getOwnerInstalledCaCerts(user).getList();
8134 } catch (RemoteException re) {
8135 throw re.rethrowFromSystemServer();
8136 }
8137 }
Benjamin Franza77e3572017-06-23 12:01:44 +01008138
8139 /**
8140 * Called by the device owner or profile owner to clear application user data of a given
8141 * package. The behaviour of this is equivalent to the target application calling
8142 * {@link android.app.ActivityManager#clearApplicationUserData()}.
8143 *
8144 * <p><strong>Note:</strong> an application can store data outside of its application data, e.g.
8145 * external storage or user dictionary. This data will not be wiped by calling this API.
8146 *
8147 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
8148 * @param packageName The name of the package which will have its user data wiped.
8149 * @param listener A callback object that will inform the caller when the clearing is done.
8150 * @param handler The handler indicating the thread on which the listener should be invoked.
8151 * @throws SecurityException if the caller is not the device owner/profile owner.
8152 * @return whether the clearing succeeded.
8153 */
8154 public boolean clearApplicationUserData(@NonNull ComponentName admin,
8155 @NonNull String packageName, @NonNull OnClearApplicationUserDataListener listener,
8156 @NonNull Handler handler) {
8157 throwIfParentInstance("clearAppData");
8158 try {
8159 return mService.clearApplicationUserData(admin, packageName,
8160 new IPackageDataObserver.Stub() {
8161 public void onRemoveCompleted(String pkg, boolean succeeded) {
8162 handler.post(() ->
8163 listener.onApplicationUserDataCleared(pkg, succeeded));
8164 }
8165 });
8166 } catch (RemoteException re) {
8167 throw re.rethrowFromSystemServer();
8168 }
8169 }
8170
8171 /**
8172 * Callback used in {@link #clearApplicationUserData}
8173 * to indicate that the clearing of an application's user data is done.
8174 */
8175 public interface OnClearApplicationUserDataListener {
8176 /**
8177 * Method invoked when clearing the application user data has completed.
8178 *
8179 * @param packageName The name of the package which had its user data cleared.
8180 * @param succeeded Whether the clearing succeeded. Clearing fails for device administrator
8181 * apps and protected system packages.
8182 */
8183 void onApplicationUserDataCleared(String packageName, boolean succeeded);
8184 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08008185}