blob: ab8edee724f2a5d6699eec2e051f4560577715dc [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
yuemingwf7f67dc2017-09-08 14:23:53 +010066import com.android.internal.R;
Makoto Onukicc4bbeb2015-09-17 10:28:24 -070067import com.android.internal.annotations.VisibleForTesting;
yuemingwf7f67dc2017-09-08 14:23:53 +010068import com.android.internal.util.Preconditions;
Maggie Benthallda51e682013-08-08 22:35:44 -040069import com.android.org.conscrypt.TrustedCertificateStore;
70
71import java.io.ByteArrayInputStream;
Dianne Hackbornd6847842010-01-12 18:14:19 -080072import java.io.IOException;
Alan Treadwayafad8782016-01-19 15:15:08 +000073import java.lang.annotation.Retention;
74import java.lang.annotation.RetentionPolicy;
Oscar Montemayor69238c62010-08-03 10:51:06 -070075import java.net.InetSocketAddress;
76import java.net.Proxy;
Robin Lee0d5ccb72014-09-12 17:41:44 +010077import java.security.KeyFactory;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000078import java.security.NoSuchAlgorithmException;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010079import java.security.PrivateKey;
80import java.security.cert.Certificate;
Maggie Benthallda51e682013-08-08 22:35:44 -040081import java.security.cert.CertificateException;
82import java.security.cert.CertificateFactory;
83import java.security.cert.X509Certificate;
Robin Lee0d5ccb72014-09-12 17:41:44 +010084import java.security.spec.InvalidKeySpecException;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000085import java.security.spec.PKCS8EncodedKeySpec;
Jim Miller604e7552014-07-18 19:00:02 -070086import java.util.ArrayList;
Rubin Xub4365912016-03-23 12:13:22 +000087import java.util.Arrays;
Svetoslav976e8bd2014-07-16 15:12:03 -070088import java.util.Collections;
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -080089import java.util.List;
Tony Mak31657432017-04-25 09:29:55 +010090import java.util.Set;
Dianne Hackbornd6847842010-01-12 18:14:19 -080091
92/**
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000093 * Public interface for managing policies enforced on a device. Most clients of this class must be
Suprabh Shukla34d92ef2016-03-14 13:49:37 -070094 * registered with the system as a <a href="{@docRoot}guide/topics/admin/device-admin.html">device
95 * administrator</a>. Additionally, a device administrator may be registered as either a profile or
96 * device owner. A given method is accessible to all device administrators unless the documentation
97 * for that method specifies that it is restricted to either device or profile owners. Any
98 * application calling an api may only pass as an argument a device administrator component it
99 * owns. Otherwise, a {@link SecurityException} will be thrown.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -0800100 * <div class="special reference">
101 * <h3>Developer Guides</h3>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -0700102 * <p>
103 * For more information about managing policies for device administration, read the <a href=
104 * "{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a> developer
105 * guide. </div>
Dianne Hackbornd6847842010-01-12 18:14:19 -0800106 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -0600107@SystemService(Context.DEVICE_POLICY_SERVICE)
Dianne Hackbornd6847842010-01-12 18:14:19 -0800108public class DevicePolicyManager {
109 private static String TAG = "DevicePolicyManager";
Dianne Hackbornd6847842010-01-12 18:14:19 -0800110
111 private final Context mContext;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800112 private final IDevicePolicyManager mService;
Esteban Talavera62399912016-01-11 15:37:55 +0000113 private final boolean mParentInstance;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700114
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600115 /** @hide */
116 public DevicePolicyManager(Context context, IDevicePolicyManager service) {
117 this(context, service, false);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800118 }
119
Dianne Hackborn87bba1e2010-02-26 17:25:54 -0800120 /** @hide */
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700121 @VisibleForTesting
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600122 protected DevicePolicyManager(Context context, IDevicePolicyManager service,
123 boolean parentInstance) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700124 mContext = context;
125 mService = service;
Esteban Talavera62399912016-01-11 15:37:55 +0000126 mParentInstance = parentInstance;
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700127 }
128
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700129 /** @hide test will override it. */
130 @VisibleForTesting
131 protected int myUserId() {
132 return UserHandle.myUserId();
133 }
134
Dianne Hackbornd6847842010-01-12 18:14:19 -0800135 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +0000136 * Activity action: Starts the provisioning flow which sets up a managed profile.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000137 *
Jessica Hummel9da60392014-05-21 12:32:57 +0100138 * <p>A managed profile allows data separation for example for the usage of a
139 * device as a personal and corporate device. The user which provisioning is started from and
140 * the managed profile share a launcher.
141 *
Andrew Solovay27f53372015-03-02 16:37:59 -0800142 * <p>This intent will typically be sent by a mobile device management application (MDM).
143 * Provisioning adds a managed profile and sets the MDM as the profile owner who has full
144 * control over the profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100145 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000146 * <p>It is possible to check if provisioning is allowed or not by querying the method
147 * {@link #isProvisioningAllowed(String)}.
148 *
149 * <p>In version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this intent must contain the
Nicolas Prevot18440252015-03-09 14:07:17 +0000150 * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700151 * As of {@link android.os.Build.VERSION_CODES#M}, it should contain the extra
Nicolas Prevot18440252015-03-09 14:07:17 +0000152 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only
153 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000154 *
Benjamin Franzea956242016-03-21 15:45:56 +0000155 * <p>The intent may also contain the following extras:
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000156 * <ul>
Benjamin Franzea956242016-03-21 15:45:56 +0000157 * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, optional </li>
158 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional, supported from
159 * {@link android.os.Build.VERSION_CODES#N}</li>
160 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
161 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
162 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Victor Chang51d84f92016-11-16 12:22:56 +0000163 * <li>{@link #EXTRA_PROVISIONING_SKIP_USER_CONSENT}, optional</li>
Victor Chang89ee2792016-11-23 12:10:55 +0000164 * <li>{@link #EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION}, optional</li>
Victor Changc10f6692016-12-09 15:24:00 +0000165 * <li>{@link #EXTRA_PROVISIONING_DISCLAIMERS}, optional</li>
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000166 * </ul>
Jessica Hummelf72078b2014-03-06 16:13:12 +0000167 *
Benjamin Franzea956242016-03-21 15:45:56 +0000168 * <p>When managed provisioning has completed, broadcasts are sent to the application specified
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000169 * in the provisioning intent. The
170 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the
171 * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in
172 * the primary profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100173 *
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000174 * <p>From version {@link android.os.Build.VERSION_CODES#O}, when managed provisioning has
175 * completed, along with the above broadcast, activity intent
Esteban Talavera4047bae2017-06-28 11:03:09 +0100176 * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the profile owner.
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000177 *
Benjamin Franzea956242016-03-21 15:45:56 +0000178 * <p>If provisioning fails, the managedProfile is removed so the device returns to its
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100179 * previous state.
Alan Treadway4582f812015-07-28 11:49:35 +0100180 *
181 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
182 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
183 * the provisioning flow was successful, although this doesn't guarantee the full flow will
184 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
185 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000186 */
187 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
188 public static final String ACTION_PROVISION_MANAGED_PROFILE
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100189 = "android.app.action.PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000190
191 /**
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000192 * Activity action: Starts the provisioning flow which sets up a managed user.
193 *
194 * <p>This intent will typically be sent by a mobile device management application (MDM).
Makoto Onuki32b30572015-12-11 14:29:51 -0800195 * Provisioning configures the user as managed user and sets the MDM as the profile
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000196 * owner who has full control over the user. Provisioning can only happen before user setup has
197 * been completed. Use {@link #isProvisioningAllowed(String)} to check if provisioning is
198 * allowed.
199 *
Benjamin Franzea956242016-03-21 15:45:56 +0000200 * <p>The intent contains the following extras:
201 * <ul>
202 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
203 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
204 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
205 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
206 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
207 * </ul>
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000208 *
Benjamin Franzea956242016-03-21 15:45:56 +0000209 * <p>If provisioning fails, the device returns to its previous state.
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000210 *
211 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
212 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
213 * the provisioning flow was successful, although this doesn't guarantee the full flow will
214 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
215 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Benjamin Franzea956242016-03-21 15:45:56 +0000216 *
217 * @hide
Mahaver Chopra5e732562015-11-05 11:55:12 +0000218 */
219 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
220 public static final String ACTION_PROVISION_MANAGED_USER
221 = "android.app.action.PROVISION_MANAGED_USER";
222
223 /**
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100224 * Activity action: Starts the provisioning flow which sets up a managed device.
225 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
226 *
227 * <p> During device owner provisioning a device admin app is set as the owner of the device.
228 * A device owner has full control over the device. The device owner can not be modified by the
229 * user.
230 *
231 * <p> A typical use case would be a device that is owned by a company, but used by either an
232 * employee or client.
233 *
234 * <p> An intent with this action can be sent only on an unprovisioned device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000235 * It is possible to check if provisioning is allowed or not by querying the method
236 * {@link #isProvisioningAllowed(String)}.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100237 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000238 * <p>The intent contains the following extras:
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100239 * <ul>
240 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
241 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
242 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
Rubin Xua4f9dc12015-06-12 13:27:59 +0100243 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000244 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000245 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Victor Changc10f6692016-12-09 15:24:00 +0000246 * <li>{@link #EXTRA_PROVISIONING_DISCLAIMERS}, optional</li>
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100247 * </ul>
248 *
Benjamin Franzea956242016-03-21 15:45:56 +0000249 * <p>When device owner provisioning has completed, an intent of the type
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100250 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
251 * device owner.
252 *
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000253 * <p>From version {@link android.os.Build.VERSION_CODES#O}, when device owner provisioning has
254 * completed, along with the above broadcast, activity intent
255 * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the device owner.
256 *
Benjamin Franzea956242016-03-21 15:45:56 +0000257 * <p>If provisioning fails, the device is factory reset.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100258 *
Alan Treadway4582f812015-07-28 11:49:35 +0100259 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
260 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
261 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
262 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100263 */
264 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
265 public static final String ACTION_PROVISION_MANAGED_DEVICE
266 = "android.app.action.PROVISION_MANAGED_DEVICE";
267
268 /**
Victor Chang18800092017-04-11 19:41:43 +0100269 * Activity action: launch when user provisioning completed, i.e.
270 * {@link #getUserProvisioningState()} returns one of the complete state.
271 *
272 * <p> Please note that the API behavior is not necessarily consistent across various releases,
273 * and devices, as it's contract between SetupWizard and ManagedProvisioning. The default
274 * implementation is that ManagedProvisioning launches SetupWizard in NFC provisioning only.
275 *
276 * <p> The activity must be protected by permission
277 * {@link android.Manifest.permission#BIND_DEVICE_ADMIN}, and the process must hold
278 * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE} to be launched.
279 * Only one {@link ComponentName} in the entire system should be enabled, and the rest of the
280 * components are not started by this intent.
281 * @hide
282 */
283 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
Jeff Sharkey90396362017-06-12 16:26:53 -0600284 @SystemApi
Victor Chang18800092017-04-11 19:41:43 +0100285 public static final String ACTION_STATE_USER_SETUP_COMPLETE =
286 "android.app.action.STATE_USER_SETUP_COMPLETE";
287
288 /**
Alan Treadway46dd4492015-11-09 13:57:19 +0000289 * Activity action: Starts the provisioning flow which sets up a managed device.
Steven Ng980a1b62016-02-02 17:43:18 +0000290 *
291 * <p>During device owner provisioning, a device admin app is downloaded and set as the owner of
292 * the device. A device owner has full control over the device. The device owner can not be
293 * modified by the user and the only way of resetting the device is via factory reset.
294 *
295 * <p>A typical use case would be a device that is owned by a company, but used by either an
296 * employee or client.
297 *
298 * <p>The provisioning message should be sent to an unprovisioned device.
299 *
300 * <p>Unlike {@link #ACTION_PROVISION_MANAGED_DEVICE}, the provisioning message can only be sent
301 * by a privileged app with the permission
302 * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE}.
303 *
304 * <p>The provisioning intent contains the following properties:
305 * <ul>
306 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
307 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
308 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
309 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Victor Chang38cfd9c2017-01-04 17:41:11 +0000310 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL}, optional</li>
311 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI}, optional</li>
Steven Ng980a1b62016-02-02 17:43:18 +0000312 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
313 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
314 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
315 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
316 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
317 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
318 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
319 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
320 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
321 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
322 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
Victor Chang38cfd9c2017-01-04 17:41:11 +0000323 * <li>{@link #EXTRA_PROVISIONING_SUPPORT_URL}, optional</li>
324 * <li>{@link #EXTRA_PROVISIONING_ORGANIZATION_NAME}, optional</li>
Steven Ng980a1b62016-02-02 17:43:18 +0000325 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li></ul>
326 *
327 * @hide
328 */
329 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
330 @SystemApi
331 public static final String ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE =
332 "android.app.action.PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE";
333
334 /**
335 * Activity action: Starts the provisioning flow which sets up a managed device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000336 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
337 *
338 * <p>NOTE: This is only supported on split system user devices, and puts the device into a
339 * management state that is distinct from that reached by
340 * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system
341 * user, and only has control over device-wide policies, not individual users and their data.
342 * The primary benefit is that multiple non-system users are supported when provisioning using
343 * this form of device management.
344 *
Benjamin Franzea956242016-03-21 15:45:56 +0000345 * <p>During device owner provisioning a device admin app is set as the owner of the device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000346 * A device owner has full control over the device. The device owner can not be modified by the
347 * user.
348 *
Benjamin Franzea956242016-03-21 15:45:56 +0000349 * <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 +0000350 * employee or client.
351 *
Benjamin Franzea956242016-03-21 15:45:56 +0000352 * <p>An intent with this action can be sent only on an unprovisioned device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000353 * It is possible to check if provisioning is allowed or not by querying the method
354 * {@link #isProvisioningAllowed(String)}.
355 *
356 * <p>The intent contains the following extras:
357 * <ul>
358 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
359 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
360 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
361 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Benjamin Franzea956242016-03-21 15:45:56 +0000362 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
363 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Alan Treadway46dd4492015-11-09 13:57:19 +0000364 * </ul>
365 *
Benjamin Franzea956242016-03-21 15:45:56 +0000366 * <p>When device owner provisioning has completed, an intent of the type
Alan Treadway46dd4492015-11-09 13:57:19 +0000367 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
368 * device owner.
369 *
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000370 * <p>From version {@link android.os.Build.VERSION_CODES#O}, when device owner provisioning has
371 * completed, along with the above broadcast, activity intent
372 * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the device owner.
373 *
Benjamin Franzea956242016-03-21 15:45:56 +0000374 * <p>If provisioning fails, the device is factory reset.
Alan Treadway46dd4492015-11-09 13:57:19 +0000375 *
376 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
377 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
378 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
379 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
380 *
381 * @hide
382 */
383 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
384 public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE
385 = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE";
386
387 /**
Alan Treadwayafad8782016-01-19 15:15:08 +0000388 * Activity action: Finalizes management provisioning, should be used after user-setup
389 * has been completed and {@link #getUserProvisioningState()} returns one of:
390 * <ul>
391 * <li>{@link #STATE_USER_SETUP_INCOMPLETE}</li>
392 * <li>{@link #STATE_USER_SETUP_COMPLETE}</li>
393 * <li>{@link #STATE_USER_PROFILE_COMPLETE}</li>
394 * </ul>
395 *
396 * @hide
397 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +0000398 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +0000399 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
400 public static final String ACTION_PROVISION_FINALIZATION
401 = "android.app.action.PROVISION_FINALIZATION";
402
403 /**
Michal Karpinskiba244092016-02-25 17:28:24 +0000404 * Action: Bugreport sharing with device owner has been accepted by the user.
405 *
406 * @hide
407 */
408 public static final String ACTION_BUGREPORT_SHARING_ACCEPTED =
Rubin Xu7226c7d2017-02-06 17:18:50 +0000409 "com.android.server.action.REMOTE_BUGREPORT_SHARING_ACCEPTED";
Michal Karpinskiba244092016-02-25 17:28:24 +0000410
411 /**
412 * Action: Bugreport sharing with device owner has been declined by the user.
413 *
414 * @hide
415 */
416 public static final String ACTION_BUGREPORT_SHARING_DECLINED =
Rubin Xu7226c7d2017-02-06 17:18:50 +0000417 "com.android.server.action.REMOTE_BUGREPORT_SHARING_DECLINED";
Michal Karpinskiba244092016-02-25 17:28:24 +0000418
419 /**
Esteban Talavera01576862016-12-15 11:16:44 +0000420 * Action: Bugreport has been collected and is dispatched to {@code DevicePolicyManagerService}.
Michal Karpinskiba244092016-02-25 17:28:24 +0000421 *
422 * @hide
423 */
424 public static final String ACTION_REMOTE_BUGREPORT_DISPATCH =
425 "android.intent.action.REMOTE_BUGREPORT_DISPATCH";
426
427 /**
428 * Extra for shared bugreport's SHA-256 hash.
429 *
430 * @hide
431 */
432 public static final String EXTRA_REMOTE_BUGREPORT_HASH =
433 "android.intent.extra.REMOTE_BUGREPORT_HASH";
434
435 /**
436 * Extra for remote bugreport notification shown type.
437 *
438 * @hide
439 */
440 public static final String EXTRA_BUGREPORT_NOTIFICATION_TYPE =
441 "android.app.extra.bugreport_notification_type";
442
443 /**
444 * Notification type for a started remote bugreport flow.
445 *
446 * @hide
447 */
448 public static final int NOTIFICATION_BUGREPORT_STARTED = 1;
449
450 /**
451 * Notification type for a bugreport that has already been accepted to be shared, but is still
452 * being taken.
453 *
454 * @hide
455 */
456 public static final int NOTIFICATION_BUGREPORT_ACCEPTED_NOT_FINISHED = 2;
457
458 /**
459 * Notification type for a bugreport that has been taken and can be shared or declined.
460 *
461 * @hide
462 */
463 public static final int NOTIFICATION_BUGREPORT_FINISHED_NOT_ACCEPTED = 3;
464
465 /**
Michal Karpinski8f010dd2016-06-21 15:05:53 +0100466 * Default and maximum timeout in milliseconds after which unlocking with weak auth times out,
467 * i.e. the user has to use a strong authentication method like password, PIN or pattern.
468 *
469 * @hide
470 */
471 public static final long DEFAULT_STRONG_AUTH_TIMEOUT_MS = 72 * 60 * 60 * 1000; // 72h
472
473 /**
Rubin Xua4f9dc12015-06-12 13:27:59 +0100474 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100475 * allows a mobile device management application or NFC programmer application which starts
476 * managed provisioning to pass data to the management application instance after provisioning.
Rubin Xua4f9dc12015-06-12 13:27:59 +0100477 * <p>
478 * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that
479 * sends the intent to pass data to itself on the newly created profile.
480 * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same
481 * instance of the app on the primary user.
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100482 * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with
483 * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC
484 * message should contain a stringified {@link java.util.Properties} instance, whose string
485 * properties will be converted into a {@link android.os.PersistableBundle} and passed to the
486 * management application after provisioning.
487 *
Rubin Xua4f9dc12015-06-12 13:27:59 +0100488 * <p>
489 * In both cases the application receives the data in
Brian Carlstromf1fe51b2014-09-03 08:55:05 -0700490 * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action
491 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed
Rubin Xua4f9dc12015-06-12 13:27:59 +0100492 * during the managed provisioning.
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100493 */
494 public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE =
Esteban Talavera37f01842014-09-05 10:50:57 +0100495 "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE";
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100496
497 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100498 * A String extra holding the package name of the mobile device management application that
499 * will be set as the profile owner or device owner.
500 *
501 * <p>If an application starts provisioning directly via an intent with action
502 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
503 * application that started provisioning. The package will be set as profile owner in that case.
504 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000505 * <p>This package is set as device owner when device owner provisioning is started by an NFC
506 * message containing an NFC record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000507 *
508 * <p> When this extra is set, the application must have exactly one device admin receiver.
Robin Lee25e26452015-06-02 09:56:29 -0700509 * This receiver will be set as the profile or device owner and active admin.
Benjamin Franzea956242016-03-21 15:45:56 +0000510 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000511 * @see DeviceAdminReceiver
512 * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still
Nicolas Prevot8f78d6a2015-08-21 11:06:31 +0100513 * supported, but only if there is only one device admin receiver in the package that requires
514 * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000515 */
Nicolas Prevot18440252015-03-09 14:07:17 +0000516 @Deprecated
Jessica Hummelf72078b2014-03-06 16:13:12 +0000517 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100518 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000519
520 /**
Nicolas Prevot18440252015-03-09 14:07:17 +0000521 * A ComponentName extra indicating the device admin receiver of the mobile device management
522 * application that will be set as the profile owner or device owner and active admin.
523 *
524 * <p>If an application starts provisioning directly via an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100525 * {@link #ACTION_PROVISION_MANAGED_PROFILE} or
526 * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this
527 * component has to match the package name of the application that started provisioning.
Nicolas Prevot18440252015-03-09 14:07:17 +0000528 *
529 * <p>This component is set as device owner and active admin when device owner provisioning is
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100530 * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC
531 * message containing an NFC record with MIME type
Benjamin Franzea956242016-03-21 15:45:56 +0000532 * {@link #MIME_TYPE_PROVISIONING_NFC}. For the NFC record, the component name must be
Rubin Xu44ef750b2015-03-23 16:51:33 +0000533 * flattened to a string, via {@link ComponentName#flattenToShortString()}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000534 *
535 * @see DeviceAdminReceiver
536 */
537 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME
538 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME";
539
540 /**
Alexandra Gherghinaaaf2f3e2014-11-13 12:46:15 +0000541 * An {@link android.accounts.Account} extra holding the account to migrate during managed
542 * profile provisioning. If the account supplied is present in the primary user, it will be
543 * copied, along with its credentials to the managed profile and removed from the primary user.
544 *
545 * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}.
546 */
547
548 public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE
549 = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE";
550
551 /**
Victor Changaa9cbc02016-12-05 20:50:57 +0000552 * Boolean extra to indicate that the migrated account should be kept. This is used in
553 * conjunction with {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}. If it's set to {@code true},
554 * the account will not be removed from the primary user after it is migrated to the newly
555 * created user or profile.
Victor Chang89ee2792016-11-23 12:10:55 +0000556 *
557 * <p> Defaults to {@code false}
558 *
Victor Changaa9cbc02016-12-05 20:50:57 +0000559 * <p> Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
560 * {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}
Victor Chang89ee2792016-11-23 12:10:55 +0000561 */
562 public static final String EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION
563 = "android.app.extra.PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION";
564
565 /**
Mahaver761ce772017-03-13 16:40:45 +0000566 * @deprecated From {@link android.os.Build.VERSION_CODES#O}, never used while provisioning the
567 * device.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100568 */
Mahaver761ce772017-03-13 16:40:45 +0000569 @Deprecated
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100570 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
571 = "android.app.extra.PROVISIONING_EMAIL_ADDRESS";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100572
573 /**
Nicolas Prevotcd2d8592015-11-23 13:27:21 +0000574 * A integer extra indicating the predominant color to show during the provisioning.
575 * Refer to {@link android.graphics.Color} for how the color is represented.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000576 *
577 * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or
578 * {@link #ACTION_PROVISION_MANAGED_DEVICE}.
579 */
580 public static final String EXTRA_PROVISIONING_MAIN_COLOR =
581 "android.app.extra.PROVISIONING_MAIN_COLOR";
582
583 /**
Sander Alewijnse8c411562014-11-12 18:03:11 +0000584 * A Boolean extra that can be used by the mobile device management application to skip the
Robin Lee25e26452015-06-02 09:56:29 -0700585 * disabling of system apps during provisioning when set to {@code true}.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000586 *
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100587 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
588 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000589 */
Sander Alewijnse5a144252014-11-18 13:25:04 +0000590 public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED =
591 "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED";
Sander Alewijnse8c411562014-11-12 18:03:11 +0000592
593 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100594 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
595 * will be set to.
596 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000597 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
598 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100599 */
600 public static final String EXTRA_PROVISIONING_TIME_ZONE
Esteban Talavera37f01842014-09-05 10:50:57 +0100601 = "android.app.extra.PROVISIONING_TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100602
603 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100604 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
605 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100606 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000607 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
608 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100609 */
610 public static final String EXTRA_PROVISIONING_LOCAL_TIME
Esteban Talavera37f01842014-09-05 10:50:57 +0100611 = "android.app.extra.PROVISIONING_LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100612
613 /**
614 * A String extra holding the {@link java.util.Locale} that the device will be set to.
615 * Format: xx_yy, where xx is the language code, and yy the country code.
616 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000617 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
618 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100619 */
620 public static final String EXTRA_PROVISIONING_LOCALE
Esteban Talavera37f01842014-09-05 10:50:57 +0100621 = "android.app.extra.PROVISIONING_LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100622
623 /**
624 * A String extra holding the ssid of the wifi network that should be used during nfc device
625 * owner provisioning for downloading the mobile device management application.
626 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000627 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
628 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100629 */
630 public static final String EXTRA_PROVISIONING_WIFI_SSID
Esteban Talavera37f01842014-09-05 10:50:57 +0100631 = "android.app.extra.PROVISIONING_WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100632
633 /**
634 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
635 * is hidden or not.
636 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000637 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
638 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100639 */
640 public static final String EXTRA_PROVISIONING_WIFI_HIDDEN
Esteban Talavera37f01842014-09-05 10:50:57 +0100641 = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100642
643 /**
644 * A String extra indicating the security type of the wifi network in
Mahaver Chopra76b08a92015-10-08 17:58:45 +0100645 * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or
646 * {@code WEP}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100647 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000648 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
649 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100650 */
651 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
Esteban Talavera37f01842014-09-05 10:50:57 +0100652 = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100653
654 /**
655 * A String extra holding the password of the wifi network in
656 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
657 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000658 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
659 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100660 */
661 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talavera37f01842014-09-05 10:50:57 +0100662 = "android.app.extra.PROVISIONING_WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100663
664 /**
665 * A String extra holding the proxy host for the wifi network in
666 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
667 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000668 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
669 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100670 */
671 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
Esteban Talavera37f01842014-09-05 10:50:57 +0100672 = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100673
674 /**
675 * An int extra holding the proxy port for the wifi network in
676 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
677 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000678 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
679 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100680 */
681 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
Esteban Talavera37f01842014-09-05 10:50:57 +0100682 = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100683
684 /**
685 * A String extra holding the proxy bypass for the wifi network in
686 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
687 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000688 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
689 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100690 */
691 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
Esteban Talavera37f01842014-09-05 10:50:57 +0100692 = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100693
694 /**
695 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
696 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
697 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000698 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
699 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100700 */
701 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
Esteban Talavera37f01842014-09-05 10:50:57 +0100702 = "android.app.extra.PROVISIONING_WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100703
704 /**
705 * A String extra holding a url that specifies the download location of the device admin
706 * package. When not provided it is assumed that the device admin package is already installed.
707 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000708 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
709 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100710 */
711 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talavera37f01842014-09-05 10:50:57 +0100712 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100713
714 /**
Victor Chang38cfd9c2017-01-04 17:41:11 +0000715 * A String extra holding the localized name of the organization under management.
716 *
717 * The name is displayed only during provisioning.
718 *
719 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE}
720 *
721 * @hide
722 */
723 @SystemApi
724 public static final String EXTRA_PROVISIONING_ORGANIZATION_NAME =
725 "android.app.extra.PROVISIONING_ORGANIZATION_NAME";
726
727 /**
Alejandro Fernándezbfd61932017-04-04 19:33:01 +0100728 * A String extra holding a url to the website of the device provider so the user can open it
729 * during provisioning. If the url is not HTTPS, an error will be shown.
Victor Chang38cfd9c2017-01-04 17:41:11 +0000730 *
731 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE}
732 *
733 * @hide
734 */
735 @SystemApi
736 public static final String EXTRA_PROVISIONING_SUPPORT_URL =
737 "android.app.extra.PROVISIONING_SUPPORT_URL";
738
739 /**
740 * A String extra holding the localized name of the device admin package. It should be the same
741 * as the app label of the package.
742 *
743 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE}
744 *
745 * @hide
746 */
747 @SystemApi
748 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL =
749 "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL";
750
751 /**
752 * A {@link Uri} extra pointing to the app icon of device admin package. This image will be
753 * shown during the provisioning.
754 * <h5>The following URI schemes are accepted:</h5>
755 * <ul>
756 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
757 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
758 * </ul>
759 *
760 * <p> It is the responsibility of the caller to provide an image with a reasonable
761 * pixel density for the device.
762 *
763 * <p> If a content: URI is passed, the intent should have the flag
764 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
765 * {@link android.content.ClipData} of the intent too.
766 *
767 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE}
768 *
769 * @hide
770 */
771 @SystemApi
772 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI =
773 "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI";
774
775 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400776 * An int extra holding a minimum required version code for the device admin package. If the
777 * device admin is already installed on the device, it will only be re-downloaded from
778 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the
779 * installed package is less than this version code.
780 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400781 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400782 * provisioning via an NFC bump.
783 */
784 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE
785 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE";
786
787 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100788 * A String extra holding a http cookie header which should be used in the http request to the
789 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
790 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000791 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
792 * provisioning via an NFC bump.
Sander Alewijnse681bce92014-07-24 16:46:26 +0100793 */
794 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talavera37f01842014-09-05 10:50:57 +0100795 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100796
797 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100798 * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of
799 * the file at download location specified in
800 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100801 *
Benjamin Franzea956242016-03-21 15:45:56 +0000802 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} must be
803 * present. The provided checksum must match the checksum of the file at the download
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100804 * location. If the checksum doesn't match an error will be shown to the user and the user will
805 * be asked to factory reset the device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100806 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000807 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
808 * provisioning via an NFC bump.
Rubin Xud92e7572015-05-18 17:01:13 +0100809 *
810 * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP}
811 * and {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1} only SHA-1 hash is supported.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700812 * Starting from {@link android.os.Build.VERSION_CODES#M}, this parameter accepts SHA-256 in
Rubin Xud92e7572015-05-18 17:01:13 +0100813 * addition to SHA-1. Support for SHA-1 is likely to be removed in future OS releases.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100814 */
815 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100816 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100817
818 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100819 * A String extra holding the URL-safe base64 encoded SHA-256 checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100820 * android package archive at the download location specified in {@link
821 * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
822 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100823 * <p>The signatures of an android package archive can be obtained using
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100824 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
825 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
826 *
Benjamin Franzea956242016-03-21 15:45:56 +0000827 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} must be
828 * present. The provided checksum must match the checksum of any signature of the file at
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100829 * the download location. If the checksum does not match an error will be shown to the user and
830 * the user will be asked to factory reset the device.
831 *
832 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
833 * provisioning via an NFC bump.
834 */
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100835 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM
836 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM";
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100837
838 /**
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000839 * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile
840 * has completed successfully.
841 *
842 * <p>The broadcast is limited to the primary profile, to the app specified in the provisioning
Nicolas Prevotebe2d992015-05-12 18:14:53 -0700843 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000844 *
Mahaver7074caf2016-11-29 20:52:18 +0000845 * <p>This intent will contain the following extras
846 * <ul>
847 * <li>{@link Intent#EXTRA_USER}, corresponds to the {@link UserHandle} of the managed
848 * profile.</li>
849 * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, corresponds to the account requested to
850 * be migrated at provisioning time, if any.</li>
851 * </ul>
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000852 */
853 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
854 public static final String ACTION_MANAGED_PROFILE_PROVISIONED
855 = "android.app.action.MANAGED_PROFILE_PROVISIONED";
856
857 /**
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000858 * Activity action: This activity action is sent to indicate that provisioning of a managed
859 * profile or managed device has completed successfully. It'll be sent at the same time as
860 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast but this will be
861 * delivered faster as it's an activity intent.
862 *
Esteban Talavera4047bae2017-06-28 11:03:09 +0100863 * <p>The intent is only sent to the new device or profile owner.
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000864 *
865 * @see #ACTION_PROVISION_MANAGED_PROFILE
866 * @see #ACTION_PROVISION_MANAGED_DEVICE
867 */
868 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
869 public static final String ACTION_PROVISIONING_SUCCESSFUL =
870 "android.app.action.PROVISIONING_SUCCESSFUL";
871
872 /**
Benjamin Franzea956242016-03-21 15:45:56 +0000873 * A boolean extra indicating whether device encryption can be skipped as part of device owner
874 * or managed profile provisioning.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500875 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400876 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100877 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Benjamin Franzea956242016-03-21 15:45:56 +0000878 *
879 * <p>From {@link android.os.Build.VERSION_CODES#N} onwards, this is also supported for an
880 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500881 */
882 public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION =
883 "android.app.extra.PROVISIONING_SKIP_ENCRYPTION";
884
885 /**
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000886 * A {@link Uri} extra pointing to a logo image. This image will be shown during the
887 * provisioning. If this extra is not passed, a default image will be shown.
888 * <h5>The following URI schemes are accepted:</h5>
889 * <ul>
890 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
891 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
892 * </ul>
893 *
Victor Changc10f6692016-12-09 15:24:00 +0000894 * <p> It is the responsibility of the caller to provide an image with a reasonable
Victor Chang38cfd9c2017-01-04 17:41:11 +0000895 * pixel density for the device.
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000896 *
897 * <p> If a content: URI is passed, the intent should have the flag
898 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
899 * {@link android.content.ClipData} of the intent too.
900 *
901 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or
902 * {@link #ACTION_PROVISION_MANAGED_DEVICE}
903 */
904 public static final String EXTRA_PROVISIONING_LOGO_URI =
905 "android.app.extra.PROVISIONING_LOGO_URI";
906
907 /**
Victor Changc10f6692016-12-09 15:24:00 +0000908 * A {@link Bundle}[] extra consisting of list of disclaimer headers and disclaimer contents.
909 * Each {@link Bundle} must have both {@link #EXTRA_PROVISIONING_DISCLAIMER_HEADER}
910 * as disclaimer header, and {@link #EXTRA_PROVISIONING_DISCLAIMER_CONTENT} as disclaimer
911 * content.
912 *
913 * <p> The extra typically contains one disclaimer from the company of mobile device
914 * management application (MDM), and one disclaimer from the organization.
915 *
916 * <p> Call {@link Bundle#putParcelableArray(String, Parcelable[])} to put the {@link Bundle}[]
917 *
918 * <p> Maximum 3 key-value pairs can be specified. The rest will be ignored.
919 *
920 * <p> Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or
921 * {@link #ACTION_PROVISION_MANAGED_DEVICE}
922 */
923 public static final String EXTRA_PROVISIONING_DISCLAIMERS =
924 "android.app.extra.PROVISIONING_DISCLAIMERS";
925
926 /**
927 * A String extra of localized disclaimer header.
928 *
929 * <p> The extra is typically the company name of mobile device management application (MDM)
930 * or the organization name.
931 *
932 * <p> Use in Bundle {@link #EXTRA_PROVISIONING_DISCLAIMERS}
Victor Chang98607132017-01-27 11:51:56 +0000933 *
934 * <p> System app, i.e. application with {@link ApplicationInfo#FLAG_SYSTEM}, can also insert a
935 * disclaimer by declaring an application-level meta-data in {@code AndroidManifest.xml}.
936 * Must use it with {@link #EXTRA_PROVISIONING_DISCLAIMER_CONTENT}. Here is the example:
937 *
938 * <pre>
939 * &lt;meta-data
940 * android:name="android.app.extra.PROVISIONING_DISCLAIMER_HEADER"
941 * android:resource="@string/disclaimer_header"
942 * /&gt;</pre>
Victor Changc10f6692016-12-09 15:24:00 +0000943 */
944 public static final String EXTRA_PROVISIONING_DISCLAIMER_HEADER =
945 "android.app.extra.PROVISIONING_DISCLAIMER_HEADER";
946
947 /**
948 * A {@link Uri} extra pointing to disclaimer content.
949 *
950 * <h5>The following URI schemes are accepted:</h5>
951 * <ul>
952 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
953 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
954 * </ul>
955 *
956 * <p> Styled text is supported in the disclaimer content. The content is parsed by
957 * {@link android.text.Html#fromHtml(String)} and displayed in a
958 * {@link android.widget.TextView}.
959 *
960 * <p> If a <code>content:</code> URI is passed, URI is passed, the intent should have the flag
961 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
962 * {@link android.content.ClipData} of the intent too.
963 *
964 * <p> Use in Bundle {@link #EXTRA_PROVISIONING_DISCLAIMERS}
Victor Chang98607132017-01-27 11:51:56 +0000965 *
966 * <p> System app, i.e. application with {@link ApplicationInfo#FLAG_SYSTEM}, can also insert a
967 * disclaimer by declaring an application-level meta-data in {@code AndroidManifest.xml}.
968 * Must use it with {@link #EXTRA_PROVISIONING_DISCLAIMER_HEADER}. Here is the example:
969 *
970 * <pre>
971 * &lt;meta-data
972 * android:name="android.app.extra.PROVISIONING_DISCLAIMER_CONTENT"
973 * android:resource="@string/disclaimer_content"
974 * /&gt;</pre>
Victor Changc10f6692016-12-09 15:24:00 +0000975 */
976 public static final String EXTRA_PROVISIONING_DISCLAIMER_CONTENT =
977 "android.app.extra.PROVISIONING_DISCLAIMER_CONTENT";
978
979 /**
Alan Treadway94de8c82016-01-11 10:25:23 +0000980 * A boolean extra indicating if user setup should be skipped, for when provisioning is started
981 * during setup-wizard.
982 *
983 * <p>If unspecified, defaults to {@code true} to match the behavior in
984 * {@link android.os.Build.VERSION_CODES#M} and earlier.
985 *
Alan Treadway1a538d02016-01-18 16:42:30 +0000986 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or
987 * {@link #ACTION_PROVISION_MANAGED_USER}.
Alan Treadway94de8c82016-01-11 10:25:23 +0000988 *
989 * @hide
990 */
991 public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP =
992 "android.app.extra.PROVISIONING_SKIP_USER_SETUP";
993
994 /**
Victor Chang51d84f92016-11-16 12:22:56 +0000995 * A boolean extra indicating if the user consent steps from the provisioning flow should be
996 * skipped. If unspecified, defaults to {@code false}.
997 *
998 * It can only be used by an existing device owner trying to create a managed profile via
999 * {@link #ACTION_PROVISION_MANAGED_PROFILE}. Otherwise it is ignored.
1000 */
1001 public static final String EXTRA_PROVISIONING_SKIP_USER_CONSENT =
1002 "android.app.extra.PROVISIONING_SKIP_USER_CONSENT";
1003
1004 /**
Benjamin Franzea956242016-03-21 15:45:56 +00001005 * This MIME type is used for starting the device owner provisioning.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +01001006 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -04001007 * <p>During device owner provisioning a device admin app is set as the owner of the device.
1008 * A device owner has full control over the device. The device owner can not be modified by the
1009 * user and the only way of resetting the device is if the device owner app calls a factory
1010 * reset.
1011 *
1012 * <p> A typical use case would be a device that is owned by a company, but used by either an
1013 * employee or client.
1014 *
Benjamin Franzea956242016-03-21 15:45:56 +00001015 * <p> The NFC message must be sent to an unprovisioned device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +01001016 *
Sander Alewijnse8c411562014-11-12 18:03:11 +00001017 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +01001018 * contains the following properties:
1019 * <ul>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -04001020 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
1021 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +01001022 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -04001023 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +01001024 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
1025 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
1026 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
1027 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
1028 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
1029 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
1030 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
1031 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
1032 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
1033 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Rubin Xu41f2ccb92015-08-05 16:29:13 +01001034 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
1035 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from
1036 * {@link android.os.Build.VERSION_CODES#M} </li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +01001037 *
Nicolas Prevot18440252015-03-09 14:07:17 +00001038 * <p>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07001039 * As of {@link android.os.Build.VERSION_CODES#M}, the properties should contain
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -04001040 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of
1041 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only
1042 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -04001043 */
1044 public static final String MIME_TYPE_PROVISIONING_NFC
1045 = "application/com.android.managedprovisioning";
1046
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +01001047 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001048 * Activity action: ask the user to add a new device administrator to the system.
1049 * The desired policy is the ComponentName of the policy in the
1050 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
1051 * bring the user through adding the device administrator to the system (or
1052 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001053 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001054 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
1055 * field to provide the user with additional explanation (in addition
1056 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001057 *
1058 * <p>If your administrator is already active, this will ordinarily return immediately (without
1059 * user intervention). However, if your administrator has been updated and is requesting
1060 * additional uses-policy flags, the user will be presented with the new list. New policies
1061 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001062 */
1063 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1064 public static final String ACTION_ADD_DEVICE_ADMIN
1065 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001066
Dianne Hackbornd6847842010-01-12 18:14:19 -08001067 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001068 * @hide
1069 * Activity action: ask the user to add a new device administrator as the profile owner
Amith Yamasani814e9872015-03-23 14:04:53 -07001070 * for this user. Only system apps can launch this intent.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001071 *
Amith Yamasani814e9872015-03-23 14:04:53 -07001072 * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN}
1073 * extra field. This will invoke a UI to bring the user through adding the profile owner admin
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001074 * to remotely control restrictions on the user.
1075 *
Makoto Onukic8a5a552015-11-19 14:29:12 -08001076 * <p>The intent must be invoked via {@link Activity#startActivityForResult} to receive the
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001077 * result of whether or not the user approved the action. If approved, the result will
1078 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
1079 * as a profile owner.
1080 *
1081 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
1082 * field to provide the user with additional explanation (in addition
1083 * to your component's description) about what is being added.
1084 *
Amith Yamasani814e9872015-03-23 14:04:53 -07001085 * <p>If there is already a profile owner active or the caller is not a system app, the
1086 * operation will return a failure result.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001087 */
1088 @SystemApi
1089 public static final String ACTION_SET_PROFILE_OWNER
1090 = "android.app.action.SET_PROFILE_OWNER";
1091
1092 /**
1093 * @hide
1094 * Name of the profile owner admin that controls the user.
1095 */
1096 @SystemApi
1097 public static final String EXTRA_PROFILE_OWNER_NAME
1098 = "android.app.extra.PROFILE_OWNER_NAME";
1099
1100 /**
Nicolas Prevot00799002015-07-27 18:15:20 +01001101 * Broadcast action: send when any policy admin changes a policy.
Jim Miller284b62e2010-06-08 14:27:42 -07001102 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -07001103 *
Jim Miller284b62e2010-06-08 14:27:42 -07001104 * @hide
1105 */
1106 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
1107 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
1108
1109 /**
Tony Mak1970f972016-08-30 17:41:48 +01001110 * Broadcast action: sent when the device owner is set, changed or cleared.
Nicolas Prevot00799002015-07-27 18:15:20 +01001111 *
1112 * This broadcast is sent only to the primary user.
1113 * @see #ACTION_PROVISION_MANAGED_DEVICE
1114 */
1115 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1116 public static final String ACTION_DEVICE_OWNER_CHANGED
1117 = "android.app.action.DEVICE_OWNER_CHANGED";
1118
1119 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001120 * The ComponentName of the administrator component.
1121 *
1122 * @see #ACTION_ADD_DEVICE_ADMIN
1123 */
1124 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001125
Dianne Hackbornd6847842010-01-12 18:14:19 -08001126 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001127 * An optional CharSequence providing additional explanation for why the
1128 * admin is being added.
1129 *
1130 * @see #ACTION_ADD_DEVICE_ADMIN
1131 */
1132 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001133
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001134 /**
phweiss73145f42017-01-17 19:06:38 +01001135 * Constant to indicate the feature of disabling the camera. Used as argument to
1136 * {@link #createAdminSupportIntent(String)}.
1137 * @see #setCameraDisabled(ComponentName, boolean)
1138 */
1139 public static final String POLICY_DISABLE_CAMERA = "policy_disable_camera";
1140
1141 /**
1142 * Constant to indicate the feature of disabling screen captures. Used as argument to
1143 * {@link #createAdminSupportIntent(String)}.
1144 * @see #setScreenCaptureDisabled(ComponentName, boolean)
1145 */
1146 public static final String POLICY_DISABLE_SCREEN_CAPTURE = "policy_disable_screen_capture";
1147
1148 /**
1149 * A String indicating a specific restricted feature. Can be a user restriction from the
1150 * {@link UserManager}, e.g. {@link UserManager#DISALLOW_ADJUST_VOLUME}, or one of the values
1151 * {@link #POLICY_DISABLE_CAMERA} or {@link #POLICY_DISABLE_SCREEN_CAPTURE}.
1152 * @see #createAdminSupportIntent(String)
1153 * @hide
1154 */
1155 @TestApi
1156 public static final String EXTRA_RESTRICTION = "android.app.extra.RESTRICTION";
1157
1158 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001159 * Activity action: have the user enter a new password. This activity should
1160 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
1161 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
1162 * enter a new password that meets the current requirements. You can use
1163 * {@link #isActivePasswordSufficient()} to determine whether you need to
1164 * have the user select a new password in order to meet the current
1165 * constraints. Upon being resumed from this activity, you can check the new
1166 * password characteristics to see if they are sufficient.
Benjamin Franzc9921092016-01-08 17:17:44 +00001167 *
1168 * If the intent is launched from within a managed profile with a profile
1169 * owner built against {@link android.os.Build.VERSION_CODES#M} or before,
1170 * this will trigger entering a new password for the parent of the profile.
1171 * For all other cases it will trigger entering a new password for the user
1172 * or profile it is launched from.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001173 *
1174 * @see #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
Dianne Hackbornd6847842010-01-12 18:14:19 -08001175 */
1176 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1177 public static final String ACTION_SET_NEW_PASSWORD
1178 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001179
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001180 /**
Benjamin Franzc9921092016-01-08 17:17:44 +00001181 * Activity action: have the user enter a new password for the parent profile.
1182 * If the intent is launched from within a managed profile, this will trigger
1183 * entering a new password for the parent of the profile. In all other cases
1184 * the behaviour is identical to {@link #ACTION_SET_NEW_PASSWORD}.
1185 */
1186 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1187 public static final String ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
1188 = "android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD";
1189
1190 /**
phweissa0cb2512016-12-14 21:37:48 +01001191 * Broadcast action: Tell the status bar to open the device monitoring dialog, e.g. when
1192 * Network logging was enabled and the user tapped the notification.
1193 * <p class="note">This is a protected intent that can only be sent by the system.</p>
1194 * @hide
1195 */
1196 public static final String ACTION_SHOW_DEVICE_MONITORING_DIALOG
1197 = "android.app.action.SHOW_DEVICE_MONITORING_DIALOG";
1198
1199 /**
Edman Anjos9e62c312017-01-26 22:22:58 +01001200 * Broadcast Action: Sent after application delegation scopes are changed. The new delegation
1201 * scopes will be sent in an {@code ArrayList<String>} extra identified by the
1202 * {@link #EXTRA_DELEGATION_SCOPES} key.
Edman Anjosf9946772016-11-28 16:35:15 +01001203 *
1204 * <p class=”note”> Note: This is a protected intent that can only be sent by the system.</p>
1205 */
1206 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1207 public static final String ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED =
1208 "android.app.action.APPLICATION_DELEGATION_SCOPES_CHANGED";
1209
1210 /**
Edman Anjos9e62c312017-01-26 22:22:58 +01001211 * An {@code ArrayList<String>} corresponding to the delegation scopes given to an app in the
Edman Anjosf9946772016-11-28 16:35:15 +01001212 * {@link #ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED} broadcast.
1213 */
1214 public static final String EXTRA_DELEGATION_SCOPES = "android.app.extra.DELEGATION_SCOPES";
1215
1216 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +00001217 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
1218 * the parent profile to access intents sent from the managed profile.
1219 * That is, when an app in the managed profile calls
1220 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
1221 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001222 */
Nicolas Prevot86a96732014-09-08 12:13:05 +01001223 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001224
1225 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +00001226 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
1227 * the managed profile to access intents sent from the parent profile.
1228 * That is, when an app in the parent profile calls
1229 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
1230 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001231 */
Nicolas Prevot86a96732014-09-08 12:13:05 +01001232 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001233
Dianne Hackbornd6847842010-01-12 18:14:19 -08001234 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01001235 * Broadcast action: notify that a new local system update policy has been set by the device
1236 * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00001237 */
1238 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Rubin Xu5faad8e2015-04-20 17:43:48 +01001239 public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED
1240 = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED";
Rubin Xu8027a4f2015-03-10 17:52:37 +00001241
Amith Yamasanid49489b2015-04-28 14:00:26 -07001242 /**
1243 * Permission policy to prompt user for new permission requests for runtime permissions.
1244 * Already granted or denied permissions are not affected by this.
1245 */
1246 public static final int PERMISSION_POLICY_PROMPT = 0;
1247
1248 /**
1249 * Permission policy to always grant new permission requests for runtime permissions.
1250 * Already granted or denied permissions are not affected by this.
1251 */
1252 public static final int PERMISSION_POLICY_AUTO_GRANT = 1;
1253
1254 /**
1255 * Permission policy to always deny new permission requests for runtime permissions.
1256 * Already granted or denied permissions are not affected by this.
1257 */
1258 public static final int PERMISSION_POLICY_AUTO_DENY = 2;
1259
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07001260 /**
1261 * Runtime permission state: The user can manage the permission
1262 * through the UI.
1263 */
1264 public static final int PERMISSION_GRANT_STATE_DEFAULT = 0;
1265
1266 /**
1267 * Runtime permission state: The permission is granted to the app
1268 * and the user cannot manage the permission through the UI.
1269 */
1270 public static final int PERMISSION_GRANT_STATE_GRANTED = 1;
1271
1272 /**
1273 * Runtime permission state: The permission is denied to the app
1274 * and the user cannot manage the permission through the UI.
1275 */
1276 public static final int PERMISSION_GRANT_STATE_DENIED = 2;
Rubin Xu8027a4f2015-03-10 17:52:37 +00001277
1278 /**
Edman Anjosf9946772016-11-28 16:35:15 +01001279 * Delegation of certificate installation and management. This scope grants access to the
1280 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
1281 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair} APIs.
1282 */
1283 public static final String DELEGATION_CERT_INSTALL = "delegation-cert-install";
1284
1285 /**
1286 * Delegation of application restrictions management. This scope grants access to the
1287 * {@link #setApplicationRestrictions} and {@link #getApplicationRestrictions} APIs.
1288 */
1289 public static final String DELEGATION_APP_RESTRICTIONS = "delegation-app-restrictions";
1290
1291 /**
Edman Anjosa5f2fb12016-12-19 11:25:54 -08001292 * Delegation of application uninstall block. This scope grants access to the
1293 * {@link #setUninstallBlocked} API.
1294 */
1295 public static final String DELEGATION_BLOCK_UNINSTALL = "delegation-block-uninstall";
1296
1297 /**
Edman Anjos52088e42017-01-13 22:26:17 +01001298 * Delegation of permission policy and permission grant state. This scope grants access to the
1299 * {@link #setPermissionPolicy}, {@link #getPermissionGrantState},
1300 * and {@link #setPermissionGrantState} APIs.
1301 */
1302 public static final String DELEGATION_PERMISSION_GRANT = "delegation-permission-grant";
1303
1304 /**
1305 * Delegation of package access state. This scope grants access to the
1306 * {@link #isApplicationHidden}, {@link #setApplicationHidden}, {@link #isPackageSuspended}, and
1307 * {@link #setPackagesSuspended} APIs.
1308 */
1309 public static final String DELEGATION_PACKAGE_ACCESS = "delegation-package-access";
1310
1311 /**
1312 * Delegation for enabling system apps. This scope grants access to the {@link #enableSystemApp}
1313 * API.
1314 */
1315 public static final String DELEGATION_ENABLE_SYSTEM_APP = "delegation-enable-system-app";
1316
1317 /**
1318 * Delegation of management of uninstalled packages. This scope grants access to the
1319 * {@code #setKeepUninstalledPackages} and {@code #getKeepUninstalledPackages} APIs.
1320 * @hide
1321 */
1322 public static final String DELEGATION_KEEP_UNINSTALLED_PACKAGES =
1323 "delegation-keep-uninstalled-packages";
1324
1325 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00001326 * No management for current user in-effect. This is the default.
1327 * @hide
1328 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001329 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001330 public static final int STATE_USER_UNMANAGED = 0;
1331
1332 /**
1333 * Management partially setup, user setup needs to be completed.
1334 * @hide
1335 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001336 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001337 public static final int STATE_USER_SETUP_INCOMPLETE = 1;
1338
1339 /**
1340 * Management partially setup, user setup completed.
1341 * @hide
1342 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001343 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001344 public static final int STATE_USER_SETUP_COMPLETE = 2;
1345
1346 /**
1347 * Management setup and active on current user.
1348 * @hide
1349 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001350 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001351 public static final int STATE_USER_SETUP_FINALIZED = 3;
1352
1353 /**
1354 * Management partially setup on a managed profile.
1355 * @hide
1356 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001357 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001358 public static final int STATE_USER_PROFILE_COMPLETE = 4;
1359
1360 /**
1361 * @hide
1362 */
1363 @IntDef({STATE_USER_UNMANAGED, STATE_USER_SETUP_INCOMPLETE, STATE_USER_SETUP_COMPLETE,
1364 STATE_USER_SETUP_FINALIZED, STATE_USER_PROFILE_COMPLETE})
1365 @Retention(RetentionPolicy.SOURCE)
1366 public @interface UserProvisioningState {}
1367
1368 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001369 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001370 *
1371 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1372 * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and
1373 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when provisioning is allowed.
1374 *
1375 * @hide
1376 */
1377 public static final int CODE_OK = 0;
1378
1379 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001380 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001381 *
1382 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and
1383 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the device already has a device
1384 * owner.
1385 *
1386 * @hide
1387 */
1388 public static final int CODE_HAS_DEVICE_OWNER = 1;
1389
1390 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001391 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001392 *
1393 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1394 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user has a profile owner and for
1395 * {@link #ACTION_PROVISION_MANAGED_PROFILE} when the profile owner is already set.
1396 *
1397 * @hide
1398 */
1399 public static final int CODE_USER_HAS_PROFILE_OWNER = 2;
1400
1401 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001402 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001403 *
1404 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and
1405 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user isn't running.
1406 *
1407 * @hide
1408 */
1409 public static final int CODE_USER_NOT_RUNNING = 3;
1410
1411 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001412 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001413 *
1414 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1415 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the device has already been setup and
1416 * for {@link #ACTION_PROVISION_MANAGED_USER} if the user has already been setup.
1417 *
1418 * @hide
1419 */
1420 public static final int CODE_USER_SETUP_COMPLETED = 4;
1421
1422 /**
1423 * Code used to indicate that the device also has a user other than the system user.
1424 *
1425 * @hide
1426 */
1427 public static final int CODE_NONSYSTEM_USER_EXISTS = 5;
1428
1429 /**
1430 * Code used to indicate that device has an account that prevents provisioning.
1431 *
1432 * @hide
1433 */
1434 public static final int CODE_ACCOUNTS_NOT_EMPTY = 6;
1435
1436 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001437 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001438 *
1439 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and
1440 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the user is not a system user.
1441 *
1442 * @hide
1443 */
1444 public static final int CODE_NOT_SYSTEM_USER = 7;
1445
1446 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001447 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001448 *
1449 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1450 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} and {@link #ACTION_PROVISION_MANAGED_USER}
1451 * when the device is a watch and is already paired.
1452 *
1453 * @hide
1454 */
1455 public static final int CODE_HAS_PAIRED = 8;
1456
1457 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001458 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001459 *
1460 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} and
1461 * {@link #ACTION_PROVISION_MANAGED_USER} on devices which do not support managed users.
1462 *
1463 * @see {@link PackageManager#FEATURE_MANAGED_USERS}
1464 * @hide
1465 */
1466 public static final int CODE_MANAGED_USERS_NOT_SUPPORTED = 9;
1467
1468 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001469 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001470 *
1471 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} if the user is a system user.
1472 *
1473 * @hide
1474 */
1475 public static final int CODE_SYSTEM_USER = 10;
1476
1477 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001478 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001479 *
1480 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when the user cannot have more
1481 * managed profiles.
1482 *
1483 * @hide
1484 */
1485 public static final int CODE_CANNOT_ADD_MANAGED_PROFILE = 11;
1486
1487 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001488 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001489 *
1490 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} and
1491 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices not running with split system
1492 * user.
1493 *
1494 * @hide
1495 */
1496 public static final int CODE_NOT_SYSTEM_USER_SPLIT = 12;
1497
1498 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001499 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001500 *
1501 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1502 * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and
1503 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices which do no support device
1504 * admins.
1505 *
1506 * @hide
1507 */
1508 public static final int CODE_DEVICE_ADMIN_NOT_SUPPORTED = 13;
1509
1510 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001511 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001512 *
Esteban Talavera6c9116a2016-11-24 16:12:44 +00001513 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when the device the user is a
1514 * system user on a split system user device.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001515 *
1516 * @hide
1517 */
1518 public static final int CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER = 14;
1519
1520 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001521 * Result code for {@link #checkProvisioningPreCondition}.
1522 *
1523 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when adding a managed profile is
1524 * disallowed by {@link UserManager#DISALLOW_ADD_MANAGED_PROFILE}.
1525 *
1526 * @hide
1527 */
1528 public static final int CODE_ADD_MANAGED_PROFILE_DISALLOWED = 15;
1529
1530 /**
1531 * Result codes for {@link #checkProvisioningPreCondition} indicating all the provisioning pre
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001532 * conditions.
1533 *
1534 * @hide
1535 */
1536 @Retention(RetentionPolicy.SOURCE)
1537 @IntDef({CODE_OK, CODE_HAS_DEVICE_OWNER, CODE_USER_HAS_PROFILE_OWNER, CODE_USER_NOT_RUNNING,
1538 CODE_USER_SETUP_COMPLETED, CODE_NOT_SYSTEM_USER, CODE_HAS_PAIRED,
1539 CODE_MANAGED_USERS_NOT_SUPPORTED, CODE_SYSTEM_USER, CODE_CANNOT_ADD_MANAGED_PROFILE,
1540 CODE_NOT_SYSTEM_USER_SPLIT, CODE_DEVICE_ADMIN_NOT_SUPPORTED,
Esteban Talavera01576862016-12-15 11:16:44 +00001541 CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER, CODE_ADD_MANAGED_PROFILE_DISALLOWED})
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001542 public @interface ProvisioningPreCondition {}
1543
1544 /**
Makoto Onukifc73d792017-03-22 14:22:35 -07001545 * Service action: Action for a service that device owner and profile owner can optionally
1546 * own. If a device owner or a profile owner has such a service, the system tries to keep
1547 * a bound connection to it, in order to keep their process always running.
Makoto Onukife739702017-04-25 13:26:21 -07001548 * The service must be protected with the {@link android.Manifest.permission#BIND_DEVICE_ADMIN}
1549 * permission.
Makoto Onukifc73d792017-03-22 14:22:35 -07001550 */
1551 @SdkConstant(SdkConstantType.SERVICE_ACTION)
1552 public static final String ACTION_DEVICE_ADMIN_SERVICE
1553 = "android.app.action.DEVICE_ADMIN_SERVICE";
1554
1555 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001556 * Return true if the given administrator component is currently active (enabled) in the system.
1557 *
1558 * @param admin The administrator component to check for.
1559 * @return {@code true} if {@code admin} is currently enabled in the system, {@code false}
1560 * otherwise
Dianne Hackbornd6847842010-01-12 18:14:19 -08001561 */
Robin Lee25e26452015-06-02 09:56:29 -07001562 public boolean isAdminActive(@NonNull ComponentName admin) {
Charles He8c760562016-10-25 16:36:53 +01001563 throwIfParentInstance("isAdminActive");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001564 return isAdminActiveAsUser(admin, myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001565 }
1566
1567 /**
1568 * @see #isAdminActive(ComponentName)
1569 * @hide
1570 */
Robin Lee25e26452015-06-02 09:56:29 -07001571 public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001572 if (mService != null) {
1573 try {
Robin Lee25e26452015-06-02 09:56:29 -07001574 return mService.isAdminActive(admin, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001575 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001576 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001577 }
1578 }
1579 return false;
1580 }
Charles Hedea0c3b2017-01-13 10:04:12 +00001581
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001582 /**
1583 * Return true if the given administrator component is currently being removed
1584 * for the user.
1585 * @hide
1586 */
Robin Lee25e26452015-06-02 09:56:29 -07001587 public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) {
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001588 if (mService != null) {
1589 try {
Robin Lee25e26452015-06-02 09:56:29 -07001590 return mService.isRemovingAdmin(admin, userId);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001591 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001592 throw e.rethrowFromSystemServer();
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001593 }
1594 }
1595 return false;
1596 }
1597
Dianne Hackbornd6847842010-01-12 18:14:19 -08001598 /**
Robin Lee25e26452015-06-02 09:56:29 -07001599 * Return a list of all currently active device administrators' component
1600 * names. If there are no administrators {@code null} may be
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001601 * returned.
1602 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07001603 public @Nullable List<ComponentName> getActiveAdmins() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001604 throwIfParentInstance("getActiveAdmins");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001605 return getActiveAdminsAsUser(myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001606 }
1607
1608 /**
1609 * @see #getActiveAdmins()
1610 * @hide
1611 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07001612 public @Nullable List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001613 if (mService != null) {
1614 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001615 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001616 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001617 throw e.rethrowFromSystemServer();
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001618 }
1619 }
1620 return null;
1621 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001622
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001623 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001624 * Used by package administration code to determine if a package can be stopped
1625 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001626 * @hide
1627 */
David Ouyang3a83a332017-01-11 16:36:40 -08001628 @SystemApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06001629 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001630 public boolean packageHasActiveAdmins(String packageName) {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001631 return packageHasActiveAdmins(packageName, myUserId());
1632 }
1633
1634 /**
1635 * Used by package administration code to determine if a package can be stopped
1636 * or uninstalled.
1637 * @hide
1638 */
1639 public boolean packageHasActiveAdmins(String packageName, int userId) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001640 if (mService != null) {
1641 try {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001642 return mService.packageHasActiveAdmins(packageName, userId);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001643 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001644 throw e.rethrowFromSystemServer();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001645 }
1646 }
1647 return false;
1648 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001649
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001650 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001651 * Remove a current administration component. This can only be called
1652 * by the application that owns the administration component; if you
1653 * try to remove someone else's component, a security exception will be
1654 * thrown.
Esteban Talavera552a5612016-02-19 17:02:24 +00001655 *
1656 * <p>Note that the operation is not synchronous and the admin might still be active (as
1657 * indicated by {@link #getActiveAdmins()}) by the time this method returns.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001658 *
1659 * @param admin The administration compononent to remove.
1660 * @throws SecurityException if the caller is not in the owner application of {@code admin}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001661 */
Robin Lee25e26452015-06-02 09:56:29 -07001662 public void removeActiveAdmin(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001663 throwIfParentInstance("removeActiveAdmin");
Dianne Hackbornd6847842010-01-12 18:14:19 -08001664 if (mService != null) {
1665 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001666 mService.removeActiveAdmin(admin, myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001667 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001668 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001669 }
1670 }
1671 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001672
Dianne Hackbornd6847842010-01-12 18:14:19 -08001673 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001674 * Returns true if an administrator has been granted a particular device policy. This can be
1675 * used to check whether the administrator was activated under an earlier set of policies, but
1676 * requires additional policies after an upgrade.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001677 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001678 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be an
1679 * active administrator, or an exception will be thrown.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001680 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001681 * @throws SecurityException if {@code admin} is not an active administrator.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001682 */
Robin Lee25e26452015-06-02 09:56:29 -07001683 public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001684 throwIfParentInstance("hasGrantedPolicy");
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001685 if (mService != null) {
1686 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001687 return mService.hasGrantedPolicy(admin, usesPolicy, myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001688 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001689 throw e.rethrowFromSystemServer();
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001690 }
1691 }
1692 return false;
1693 }
1694
1695 /**
Clara Bayarria1771112015-12-18 16:29:18 +00001696 * Returns true if the Profile Challenge is available to use for the given profile user.
1697 *
1698 * @hide
1699 */
1700 public boolean isSeparateProfileChallengeAllowed(int userHandle) {
1701 if (mService != null) {
1702 try {
1703 return mService.isSeparateProfileChallengeAllowed(userHandle);
1704 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001705 throw e.rethrowFromSystemServer();
Clara Bayarria1771112015-12-18 16:29:18 +00001706 }
1707 }
1708 return false;
1709 }
1710
1711 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001712 * Constant for {@link #setPasswordQuality}: the policy has no requirements
1713 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001714 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001715 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001716 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001717
Dianne Hackbornd6847842010-01-12 18:14:19 -08001718 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -07001719 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
1720 * recognition technology. This implies technologies that can recognize the identity of
1721 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
1722 * Note that quality constants are ordered so that higher values are more restrictive.
1723 */
1724 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
1725
1726 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001727 * Constant for {@link #setPasswordQuality}: the policy requires some kind
Benjamin Franzc6a96532015-06-16 11:23:38 +01001728 * of password or pattern, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001729 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001730 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001731 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001732
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001733 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001734 * Constant for {@link #setPasswordQuality}: the user must have entered a
1735 * password containing at least numeric characters. Note that quality
1736 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001737 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001738 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001739
Dianne Hackbornd6847842010-01-12 18:14:19 -08001740 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001741 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -08001742 * password containing at least numeric characters with no repeating (4444)
1743 * or ordered (1234, 4321, 2468) sequences. Note that quality
1744 * constants are ordered so that higher values are more restrictive.
1745 */
1746 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
1747
1748 /**
1749 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001750 * password containing at least alphabetic (or other symbol) characters.
1751 * Note that quality constants are ordered so that higher values are more
1752 * restrictive.
1753 */
1754 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001755
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001756 /**
1757 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001758 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001759 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001760 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001761 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001762 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001763
Dianne Hackbornd6847842010-01-12 18:14:19 -08001764 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001765 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001766 * password containing at least a letter, a numerical digit and a special
1767 * symbol, by default. With this password quality, passwords can be
1768 * restricted to contain various sets of characters, like at least an
1769 * uppercase letter, etc. These are specified using various methods,
1770 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
1771 * that quality constants are ordered so that higher values are more
1772 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001773 */
1774 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
1775
1776 /**
Oleksandr Peletskyi0fdcd3d2016-01-13 16:49:56 +01001777 * Constant for {@link #setPasswordQuality}: the user is not allowed to
1778 * modify password. In case this password quality is set, the password is
1779 * managed by a profile owner. The profile owner can set any password,
1780 * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note
1781 * that quality constants are ordered so that higher values are more
1782 * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is
1783 * the highest.
1784 * @hide
1785 */
1786 public static final int PASSWORD_QUALITY_MANAGED = 0x80000;
1787
1788 /**
Makoto Onuki5e7e06702016-09-01 18:02:01 -07001789 * @hide
1790 *
1791 * adb shell dpm set-{device,profile}-owner will normally not allow installing an owner to
1792 * a user with accounts. {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED}
1793 * and {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} are the account features
1794 * used by authenticator to exempt their accounts from this:
1795 *
1796 * <ul>
1797 * <li>Non-test-only DO/PO still can't be installed when there are accounts.
1798 * <p>In order to make an apk test-only, add android:testOnly="true" to the
1799 * &lt;application&gt; tag in the manifest.
1800 *
1801 * <li>Test-only DO/PO can be installed even when there are accounts, as long as all the
1802 * accounts have the {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} feature.
1803 * Some authenticators claim to have any features, so to detect it, we also check
1804 * {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} and disallow installing
1805 * if any of the accounts have it.
1806 * </ul>
1807 */
Makoto Onuki47c203d2017-02-13 16:21:19 -08001808 @SystemApi
1809 @TestApi
Makoto Onuki5e7e06702016-09-01 18:02:01 -07001810 public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED =
1811 "android.account.DEVICE_OR_PROFILE_OWNER_ALLOWED";
1812
1813 /** @hide See {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} */
Makoto Onuki47c203d2017-02-13 16:21:19 -08001814 @SystemApi
1815 @TestApi
Makoto Onuki5e7e06702016-09-01 18:02:01 -07001816 public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED =
1817 "android.account.DEVICE_OR_PROFILE_OWNER_DISALLOWED";
1818
1819 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001820 * Called by an application that is administering the device to set the password restrictions it
1821 * is imposing. After setting this, the user will not be able to enter a new password that is
1822 * not at least as restrictive as what has been set. Note that the current password will remain
1823 * until the user has set a new one, so the change does not take place immediately. To prompt
1824 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
Esteban Talaverac1c83592016-02-17 17:56:15 +00001825 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after calling this method.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001826 * <p>
1827 * Quality constants are ordered so that higher values are more restrictive; thus the highest
1828 * requested quality constant (between the policy set here, the user's preference, and any other
1829 * considerations) is the one that is in effect.
1830 * <p>
1831 * The calling device admin must have requested
1832 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1833 * not, a security exception will be thrown.
1834 * <p>
1835 * This method can be called on the {@link DevicePolicyManager} instance returned by
1836 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1837 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001838 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001839 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001840 * @param quality The new desired quality. One of {@link #PASSWORD_QUALITY_UNSPECIFIED},
1841 * {@link #PASSWORD_QUALITY_SOMETHING}, {@link #PASSWORD_QUALITY_NUMERIC},
1842 * {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC},
1843 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} or {@link #PASSWORD_QUALITY_COMPLEX}.
1844 * @throws SecurityException if {@code admin} is not an active administrator or if {@code admin}
1845 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Dianne Hackbornd6847842010-01-12 18:14:19 -08001846 */
Robin Lee25e26452015-06-02 09:56:29 -07001847 public void setPasswordQuality(@NonNull ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001848 if (mService != null) {
1849 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001850 mService.setPasswordQuality(admin, quality, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001851 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001852 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001853 }
1854 }
1855 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001856
Dianne Hackbornd6847842010-01-12 18:14:19 -08001857 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001858 * Retrieve the current minimum password quality for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01001859 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00001860 * a separate challenge are not taken into account.
1861 *
1862 * <p>This method can be called on the {@link DevicePolicyManager} instance
1863 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1864 * restrictions on the parent profile.
1865 *
Robin Lee25e26452015-06-02 09:56:29 -07001866 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001867 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001868 */
Robin Lee25e26452015-06-02 09:56:29 -07001869 public int getPasswordQuality(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001870 return getPasswordQuality(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001871 }
1872
1873 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001874 public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001875 if (mService != null) {
1876 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001877 return mService.getPasswordQuality(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001878 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001879 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001880 }
1881 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001882 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001883 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001884
Dianne Hackbornd6847842010-01-12 18:14:19 -08001885 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001886 * Called by an application that is administering the device to set the minimum allowed password
1887 * length. After setting this, the user will not be able to enter a new password that is not at
1888 * least as restrictive as what has been set. Note that the current password will remain until
1889 * the user has set a new one, so the change does not take place immediately. To prompt the user
1890 * for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
1891 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
1892 * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC}
1893 * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC},
1894 * {@link #PASSWORD_QUALITY_ALPHANUMERIC}, or {@link #PASSWORD_QUALITY_COMPLEX} with
1895 * {@link #setPasswordQuality}.
1896 * <p>
1897 * The calling device admin must have requested
1898 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1899 * not, a security exception will be thrown.
1900 * <p>
1901 * This method can be called on the {@link DevicePolicyManager} instance returned by
1902 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1903 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001904 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001905 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001906 * @param length The new desired minimum password length. A value of 0 means there is no
1907 * restriction.
1908 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1909 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Dianne Hackbornd6847842010-01-12 18:14:19 -08001910 */
Robin Lee25e26452015-06-02 09:56:29 -07001911 public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001912 if (mService != null) {
1913 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001914 mService.setPasswordMinimumLength(admin, length, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001915 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001916 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001917 }
1918 }
1919 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001920
Dianne Hackbornd6847842010-01-12 18:14:19 -08001921 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001922 * Retrieve the current minimum password length for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01001923 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00001924 * a separate challenge are not taken into account.
1925 *
1926 * <p>This method can be called on the {@link DevicePolicyManager} instance
1927 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1928 * restrictions on the parent profile.
1929 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001930 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001931 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001932 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001933 */
Robin Lee25e26452015-06-02 09:56:29 -07001934 public int getPasswordMinimumLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001935 return getPasswordMinimumLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001936 }
1937
1938 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001939 public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001940 if (mService != null) {
1941 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001942 return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001943 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001944 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001945 }
1946 }
1947 return 0;
1948 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001949
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001950 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001951 * Called by an application that is administering the device to set the minimum number of upper
1952 * case letters required in the password. After setting this, the user will not be able to enter
1953 * a new password that is not at least as restrictive as what has been set. Note that the
1954 * current password will remain until the user has set a new one, so the change does not take
1955 * place immediately. To prompt the user for a new password, use
1956 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
1957 * setting this value. This constraint is only imposed if the administrator has also requested
1958 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001959 * <p>
1960 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001961 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1962 * not, a security exception will be thrown.
1963 * <p>
1964 * This method can be called on the {@link DevicePolicyManager} instance returned by
1965 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1966 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001967 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001968 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1969 * @param length The new desired minimum number of upper case letters required in the password.
1970 * A value of 0 means there is no restriction.
1971 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1972 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001973 */
Robin Lee25e26452015-06-02 09:56:29 -07001974 public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001975 if (mService != null) {
1976 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001977 mService.setPasswordMinimumUpperCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001978 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001979 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001980 }
1981 }
1982 }
1983
1984 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001985 * Retrieve the current number of upper case letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01001986 * for a particular admin or all admins that set restrictions on this user and
Esteban Talaverac1c83592016-02-17 17:56:15 +00001987 * its participating profiles. Restrictions on profiles that have a separate challenge
1988 * are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001989 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001990 * {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001991 * and only applies when the password quality is
1992 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001993 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001994 * <p>This method can be called on the {@link DevicePolicyManager} instance
1995 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1996 * restrictions on the parent profile.
1997 *
Robin Lee25e26452015-06-02 09:56:29 -07001998 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001999 * aggregate all admins.
2000 * @return The minimum number of upper case letters required in the
2001 * password.
2002 */
Robin Lee25e26452015-06-02 09:56:29 -07002003 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002004 return getPasswordMinimumUpperCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002005 }
2006
2007 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002008 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002009 if (mService != null) {
2010 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002011 return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002012 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002013 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002014 }
2015 }
2016 return 0;
2017 }
2018
2019 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002020 * Called by an application that is administering the device to set the minimum number of lower
2021 * case letters required in the password. After setting this, the user will not be able to enter
2022 * a new password that is not at least as restrictive as what has been set. Note that the
2023 * current password will remain until the user has set a new one, so the change does not take
2024 * place immediately. To prompt the user for a new password, use
2025 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
2026 * setting this value. This constraint is only imposed if the administrator has also requested
2027 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002028 * <p>
2029 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002030 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2031 * not, a security exception will be thrown.
2032 * <p>
2033 * This method can be called on the {@link DevicePolicyManager} instance returned by
2034 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2035 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002036 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002037 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2038 * @param length The new desired minimum number of lower case letters required in the password.
2039 * A value of 0 means there is no restriction.
2040 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2041 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002042 */
Robin Lee25e26452015-06-02 09:56:29 -07002043 public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002044 if (mService != null) {
2045 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002046 mService.setPasswordMinimumLowerCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002047 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002048 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002049 }
2050 }
2051 }
2052
2053 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002054 * Retrieve the current number of lower case letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002055 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002056 * and its participating profiles. Restrictions on profiles that have
2057 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01002058 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00002059 * {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002060 * and only applies when the password quality is
2061 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002062 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002063 * <p>This method can be called on the {@link DevicePolicyManager} instance
2064 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2065 * restrictions on the parent profile.
2066 *
Robin Lee25e26452015-06-02 09:56:29 -07002067 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002068 * aggregate all admins.
2069 * @return The minimum number of lower case letters required in the
2070 * password.
2071 */
Robin Lee25e26452015-06-02 09:56:29 -07002072 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002073 return getPasswordMinimumLowerCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002074 }
2075
2076 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002077 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002078 if (mService != null) {
2079 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002080 return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002081 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002082 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002083 }
2084 }
2085 return 0;
2086 }
2087
2088 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002089 * Called by an application that is administering the device to set the minimum number of
2090 * letters required in the password. After setting this, the user will not be able to enter a
2091 * new password that is not at least as restrictive as what has been set. Note that the current
2092 * password will remain until the user has set a new one, so the change does not take place
2093 * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
2094 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
2095 * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
2096 * {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002097 * <p>
2098 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002099 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2100 * not, a security exception will be thrown.
2101 * <p>
2102 * This method can be called on the {@link DevicePolicyManager} instance returned by
2103 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2104 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002105 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002106 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2107 * @param length The new desired minimum number of letters required in the password. A value of
2108 * 0 means there is no restriction.
2109 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2110 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002111 */
Robin Lee25e26452015-06-02 09:56:29 -07002112 public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002113 if (mService != null) {
2114 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002115 mService.setPasswordMinimumLetters(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002116 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002117 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002118 }
2119 }
2120 }
2121
2122 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002123 * Retrieve the current number of letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002124 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002125 * and its participating profiles. Restrictions on profiles that have
2126 * a separate challenge are not taken into account.
2127 * This is the same value as set by
2128 * {@link #setPasswordMinimumLetters(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002129 * and only applies when the password quality is
2130 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002131 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002132 * <p>This method can be called on the {@link DevicePolicyManager} instance
2133 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2134 * restrictions on the parent profile.
2135 *
Robin Lee25e26452015-06-02 09:56:29 -07002136 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002137 * aggregate all admins.
2138 * @return The minimum number of letters required in the password.
2139 */
Robin Lee25e26452015-06-02 09:56:29 -07002140 public int getPasswordMinimumLetters(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002141 return getPasswordMinimumLetters(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002142 }
2143
2144 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002145 public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002146 if (mService != null) {
2147 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002148 return mService.getPasswordMinimumLetters(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002149 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002150 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002151 }
2152 }
2153 return 0;
2154 }
2155
2156 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002157 * Called by an application that is administering the device to set the minimum number of
2158 * numerical digits required in the password. After setting this, the user will not be able to
2159 * enter a new password that is not at least as restrictive as what has been set. Note that the
2160 * current password will remain until the user has set a new one, so the change does not take
2161 * place immediately. To prompt the user for a new password, use
2162 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
2163 * setting this value. This constraint is only imposed if the administrator has also requested
2164 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002165 * <p>
2166 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002167 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2168 * not, a security exception will be thrown.
2169 * <p>
2170 * This method can be called on the {@link DevicePolicyManager} instance returned by
2171 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2172 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002173 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002174 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2175 * @param length The new desired minimum number of numerical digits required in the password. A
2176 * value of 0 means there is no restriction.
2177 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2178 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002179 */
Robin Lee25e26452015-06-02 09:56:29 -07002180 public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002181 if (mService != null) {
2182 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002183 mService.setPasswordMinimumNumeric(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002184 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002185 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002186 }
2187 }
2188 }
2189
2190 /**
2191 * Retrieve the current number of numerical digits required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002192 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002193 * and its participating profiles. Restrictions on profiles that have
2194 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01002195 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00002196 * {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002197 * and only applies when the password quality is
2198 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002199 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002200 * <p>This method can be called on the {@link DevicePolicyManager} instance
2201 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2202 * restrictions on the parent profile.
2203 *
Robin Lee25e26452015-06-02 09:56:29 -07002204 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002205 * aggregate all admins.
2206 * @return The minimum number of numerical digits required in the password.
2207 */
Robin Lee25e26452015-06-02 09:56:29 -07002208 public int getPasswordMinimumNumeric(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002209 return getPasswordMinimumNumeric(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002210 }
2211
2212 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002213 public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002214 if (mService != null) {
2215 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002216 return mService.getPasswordMinimumNumeric(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002217 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002218 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002219 }
2220 }
2221 return 0;
2222 }
2223
2224 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002225 * Called by an application that is administering the device to set the minimum number of
2226 * symbols required in the password. After setting this, the user will not be able to enter a
2227 * new password that is not at least as restrictive as what has been set. Note that the current
2228 * password will remain until the user has set a new one, so the change does not take place
2229 * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
2230 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
2231 * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
2232 * {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002233 * <p>
2234 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002235 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2236 * not, a security exception will be thrown.
2237 * <p>
2238 * This method can be called on the {@link DevicePolicyManager} instance returned by
2239 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2240 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002241 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002242 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2243 * @param length The new desired minimum number of symbols required in the password. A value of
2244 * 0 means there is no restriction.
2245 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2246 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002247 */
Robin Lee25e26452015-06-02 09:56:29 -07002248 public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002249 if (mService != null) {
2250 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002251 mService.setPasswordMinimumSymbols(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002252 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002253 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002254 }
2255 }
2256 }
2257
2258 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002259 * Retrieve the current number of symbols required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002260 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002261 * and its participating profiles. Restrictions on profiles that have
2262 * a separate challenge are not taken into account. This is the same value as
2263 * set by {@link #setPasswordMinimumSymbols(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002264 * and only applies when the password quality is
2265 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002266 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002267 * <p>This method can be called on the {@link DevicePolicyManager} instance
2268 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2269 * restrictions on the parent profile.
2270 *
Robin Lee25e26452015-06-02 09:56:29 -07002271 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002272 * aggregate all admins.
2273 * @return The minimum number of symbols required in the password.
2274 */
Robin Lee25e26452015-06-02 09:56:29 -07002275 public int getPasswordMinimumSymbols(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002276 return getPasswordMinimumSymbols(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002277 }
2278
2279 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002280 public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002281 if (mService != null) {
2282 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002283 return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002284 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002285 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002286 }
2287 }
2288 return 0;
2289 }
2290
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002291 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002292 * Called by an application that is administering the device to set the minimum number of
2293 * non-letter characters (numerical digits or symbols) required in the password. After setting
2294 * this, the user will not be able to enter a new password that is not at least as restrictive
2295 * as what has been set. Note that the current password will remain until the user has set a new
2296 * one, so the change does not take place immediately. To prompt the user for a new password,
2297 * use {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
2298 * setting this value. This constraint is only imposed if the administrator has also requested
2299 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002300 * <p>
2301 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002302 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2303 * not, a security exception will be thrown.
2304 * <p>
2305 * This method can be called on the {@link DevicePolicyManager} instance returned by
2306 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2307 * profile.
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002308 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002309 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2310 * @param length The new desired minimum number of letters required in the password. A value of
2311 * 0 means there is no restriction.
2312 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2313 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002314 */
Robin Lee25e26452015-06-02 09:56:29 -07002315 public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002316 if (mService != null) {
2317 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002318 mService.setPasswordMinimumNonLetter(admin, length, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002319 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002320 throw e.rethrowFromSystemServer();
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002321 }
2322 }
2323 }
2324
2325 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002326 * Retrieve the current number of non-letter characters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002327 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002328 * and its participating profiles. Restrictions on profiles that have
2329 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01002330 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00002331 * {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002332 * and only applies when the password quality is
2333 * {@link #PASSWORD_QUALITY_COMPLEX}.
2334 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002335 * <p>This method can be called on the {@link DevicePolicyManager} instance
2336 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2337 * restrictions on the parent profile.
2338 *
Robin Lee25e26452015-06-02 09:56:29 -07002339 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002340 * aggregate all admins.
2341 * @return The minimum number of letters required in the password.
2342 */
Robin Lee25e26452015-06-02 09:56:29 -07002343 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002344 return getPasswordMinimumNonLetter(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002345 }
2346
2347 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002348 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002349 if (mService != null) {
2350 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002351 return mService.getPasswordMinimumNonLetter(admin, userHandle, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002352 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002353 throw e.rethrowFromSystemServer();
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002354 }
2355 }
2356 return 0;
2357 }
2358
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002359 /**
2360 * Called by an application that is administering the device to set the length of the password
2361 * history. After setting this, the user will not be able to enter a new password that is the
2362 * same as any password in the history. Note that the current password will remain until the
2363 * user has set a new one, so the change does not take place immediately. To prompt the user for
2364 * a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
2365 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
2366 * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC}
2367 * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX} {@link #PASSWORD_QUALITY_ALPHABETIC}, or
2368 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} with {@link #setPasswordQuality}.
2369 * <p>
2370 * The calling device admin must have requested
2371 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2372 * not, a security exception will be thrown.
2373 * <p>
2374 * This method can be called on the {@link DevicePolicyManager} instance returned by
2375 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2376 * profile.
2377 *
2378 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2379 * @param length The new desired length of password history. A value of 0 means there is no
2380 * restriction.
2381 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2382 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
2383 */
Robin Lee25e26452015-06-02 09:56:29 -07002384 public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002385 if (mService != null) {
2386 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002387 mService.setPasswordHistoryLength(admin, length, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002388 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002389 throw e.rethrowFromSystemServer();
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002390 }
2391 }
2392 }
2393
2394 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002395 * Called by a device admin to set the password expiration timeout. Calling this method will
2396 * restart the countdown for password expiration for the given admin, as will changing the
2397 * device password (for all admins).
2398 * <p>
2399 * The provided timeout is the time delta in ms and will be added to the current time. For
2400 * example, to have the password expire 5 days from now, timeout would be 5 * 86400 * 1000 =
2401 * 432000000 ms for timeout.
2402 * <p>
2403 * To disable password expiration, a value of 0 may be used for timeout.
2404 * <p>
2405 * The calling device admin must have requested
2406 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this method; if it has
2407 * not, a security exception will be thrown.
2408 * <p>
2409 * Note that setting the password will automatically reset the expiration time for all active
2410 * admins. Active admins do not need to explicitly call this method in that case.
2411 * <p>
2412 * This method can be called on the {@link DevicePolicyManager} instance returned by
2413 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2414 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002415 *
Jim Millera4e28d12010-11-08 16:15:47 -08002416 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002417 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0 means
2418 * there is no restriction (unlimited).
2419 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2420 * does not use {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD}
Jim Millera4e28d12010-11-08 16:15:47 -08002421 */
Robin Lee25e26452015-06-02 09:56:29 -07002422 public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) {
Jim Millera4e28d12010-11-08 16:15:47 -08002423 if (mService != null) {
2424 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002425 mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08002426 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002427 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08002428 }
2429 }
2430 }
2431
2432 /**
Jim Miller6b857682011-02-16 16:27:41 -08002433 * Get the password expiration timeout for the given admin. The expiration timeout is the
2434 * recurring expiration timeout provided in the call to
2435 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
Esteban Talaverac1c83592016-02-17 17:56:15 +00002436 * aggregate of all participating policy administrators if {@code admin} is null. Admins that
2437 * have set restrictions on profiles that have a separate challenge are not taken into account.
2438 *
2439 * <p>This method can be called on the {@link DevicePolicyManager} instance
2440 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2441 * restrictions on the parent profile.
Jim Millera4e28d12010-11-08 16:15:47 -08002442 *
Robin Lee25e26452015-06-02 09:56:29 -07002443 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08002444 * @return The timeout for the given admin or the minimum of all timeouts
2445 */
Robin Lee25e26452015-06-02 09:56:29 -07002446 public long getPasswordExpirationTimeout(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08002447 if (mService != null) {
2448 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002449 return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08002450 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002451 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08002452 }
2453 }
2454 return 0;
2455 }
2456
2457 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002458 * Get the current password expiration time for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01002459 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00002460 * a separate challenge are not taken into account. If admin is {@code null}, then a composite
2461 * of all expiration times is returned - which will be the minimum of all of them.
2462 *
2463 * <p>This method can be called on the {@link DevicePolicyManager} instance
2464 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2465 * the password expiration for the parent profile.
Jim Millera4e28d12010-11-08 16:15:47 -08002466 *
Robin Lee25e26452015-06-02 09:56:29 -07002467 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002468 * @return The password expiration time, in milliseconds since epoch.
Jim Millera4e28d12010-11-08 16:15:47 -08002469 */
Robin Lee25e26452015-06-02 09:56:29 -07002470 public long getPasswordExpiration(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08002471 if (mService != null) {
2472 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002473 return mService.getPasswordExpiration(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08002474 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002475 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08002476 }
2477 }
2478 return 0;
2479 }
2480
2481 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002482 * Retrieve the current password history length for a particular admin or all admins that
Rubin Xud3609d42016-07-13 18:32:57 +01002483 * set restrictions on this user and its participating profiles. Restrictions on profiles that
Esteban Talaverac1c83592016-02-17 17:56:15 +00002484 * have a separate challenge are not taken into account.
2485 *
2486 * <p>This method can be called on the {@link DevicePolicyManager} instance
2487 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2488 * restrictions on the parent profile.
2489 *
Robin Lee25e26452015-06-02 09:56:29 -07002490 * @param admin The name of the admin component to check, or {@code null} to aggregate
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002491 * all admins.
2492 * @return The length of the password history
2493 */
Robin Lee25e26452015-06-02 09:56:29 -07002494 public int getPasswordHistoryLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002495 return getPasswordHistoryLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002496 }
2497
2498 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002499 public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002500 if (mService != null) {
2501 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002502 return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002503 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002504 throw e.rethrowFromSystemServer();
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002505 }
2506 }
2507 return 0;
2508 }
2509
Dianne Hackbornd6847842010-01-12 18:14:19 -08002510 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08002511 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08002512 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08002513 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08002514 * @return Returns the maximum length that the user can enter.
2515 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08002516 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08002517 // Kind-of arbitrary.
2518 return 16;
2519 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002520
Dianne Hackborn254cb442010-01-27 19:23:59 -08002521 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002522 * Determine whether the current password the user has set is sufficient to meet the policy
2523 * requirements (e.g. quality, minimum length) that have been requested by the admins of this
2524 * user and its participating profiles. Restrictions on profiles that have a separate challenge
Andrew Scull5daf2732016-11-14 15:02:45 +00002525 * are not taken into account. The user must be unlocked in order to perform the check.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002526 * <p>
2527 * The calling device admin must have requested
2528 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2529 * not, a security exception will be thrown.
2530 * <p>
2531 * This method can be called on the {@link DevicePolicyManager} instance returned by
2532 * {@link #getParentProfileInstance(ComponentName)} in order to determine if the password set on
2533 * the parent profile is sufficient.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002534 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01002535 * @return Returns true if the password meets the current requirements, else false.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002536 * @throws SecurityException if the calling application does not own an active administrator
2537 * that uses {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Rubin Xu7cf45092017-08-28 11:47:35 +01002538 * @throws IllegalStateException if the user is not unlocked.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002539 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002540 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002541 if (mService != null) {
2542 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00002543 return mService.isActivePasswordSufficient(myUserId(), mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002544 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002545 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002546 }
2547 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002548 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08002549 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002550
Dianne Hackbornd6847842010-01-12 18:14:19 -08002551 /**
Clara Bayarrid7693912016-01-22 17:26:31 +00002552 * Determine whether the current profile password the user has set is sufficient
Esteban Talaverac1c83592016-02-17 17:56:15 +00002553 * to meet the policy requirements (e.g. quality, minimum length) that have been
Clara Bayarrid7693912016-01-22 17:26:31 +00002554 * requested by the admins of the parent user and its profiles.
2555 *
2556 * @param userHandle the userId of the profile to check the password for.
2557 * @return Returns true if the password would meet the current requirements, else false.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002558 * @throws SecurityException if {@code userHandle} is not a managed profile.
Clara Bayarrid7693912016-01-22 17:26:31 +00002559 * @hide
2560 */
2561 public boolean isProfileActivePasswordSufficientForParent(int userHandle) {
2562 if (mService != null) {
2563 try {
2564 return mService.isProfileActivePasswordSufficientForParent(userHandle);
2565 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002566 throw e.rethrowFromSystemServer();
Clara Bayarrid7693912016-01-22 17:26:31 +00002567 }
2568 }
2569 return false;
2570 }
2571
2572 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002573 * Retrieve the number of times the user has failed at entering a password since that last
2574 * successful password entry.
2575 * <p>
2576 * This method can be called on the {@link DevicePolicyManager} instance returned by
2577 * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the number of failed
2578 * password attemts for the parent user.
2579 * <p>
2580 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN}
2581 * to be able to call this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002582 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002583 * @return The number of times user has entered an incorrect password since the last correct
2584 * password entry.
2585 * @throws SecurityException if the calling application does not own an active administrator
2586 * that uses {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002587 */
2588 public int getCurrentFailedPasswordAttempts() {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00002589 return getCurrentFailedPasswordAttempts(myUserId());
2590 }
2591
2592 /**
2593 * Retrieve the number of times the given user has failed at entering a
2594 * password since that last successful password entry.
2595 *
2596 * <p>The calling device admin must have requested
2597 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call this method; if it has
2598 * not and it is not the system uid, a security exception will be thrown.
2599 *
2600 * @hide
2601 */
2602 public int getCurrentFailedPasswordAttempts(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002603 if (mService != null) {
2604 try {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00002605 return mService.getCurrentFailedPasswordAttempts(userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002606 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002607 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002608 }
2609 }
2610 return -1;
2611 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002612
2613 /**
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002614 * Queries whether {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002615 *
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002616 * @return true if RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002617 * @hide
2618 */
2619 public boolean getDoNotAskCredentialsOnBoot() {
2620 if (mService != null) {
2621 try {
2622 return mService.getDoNotAskCredentialsOnBoot();
2623 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002624 throw e.rethrowFromSystemServer();
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002625 }
2626 }
2627 return false;
2628 }
2629
2630 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002631 * Setting this to a value greater than zero enables a built-in policy that will perform a
2632 * device or profile wipe after too many incorrect device-unlock passwords have been entered.
2633 * This built-in policy combines watching for failed passwords and wiping the device, and
2634 * requires that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002635 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002636 * <p>
2637 * To implement any other policy (e.g. wiping data for a particular application only, erasing or
2638 * revoking credentials, or reporting the failure to a server), you should implement
2639 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} instead. Do not
2640 * use this API, because if the maximum count is reached, the device or profile will be wiped
2641 * immediately, and your callback will not be invoked.
2642 * <p>
2643 * This method can be called on the {@link DevicePolicyManager} instance returned by
2644 * {@link #getParentProfileInstance(ComponentName)} in order to set a value on the parent
2645 * profile.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002646 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002647 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002648 * @param num The number of failed password attempts at which point the device or profile will
2649 * be wiped.
2650 * @throws SecurityException if {@code admin} is not an active administrator or does not use
2651 * both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
2652 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002653 */
Robin Lee25e26452015-06-02 09:56:29 -07002654 public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002655 if (mService != null) {
2656 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002657 mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002658 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002659 throw e.rethrowFromSystemServer();
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002660 }
2661 }
2662 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002663
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002664 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002665 * Retrieve the current maximum number of login attempts that are allowed before the device
Rubin Xud3609d42016-07-13 18:32:57 +01002666 * or profile is wiped, for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002667 * and its participating profiles. Restrictions on profiles that have a separate challenge are
2668 * not taken into account.
2669 *
2670 * <p>This method can be called on the {@link DevicePolicyManager} instance
2671 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2672 * the value for the parent profile.
2673 *
Robin Lee25e26452015-06-02 09:56:29 -07002674 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002675 * all admins.
2676 */
Robin Lee25e26452015-06-02 09:56:29 -07002677 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002678 return getMaximumFailedPasswordsForWipe(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002679 }
2680
2681 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002682 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08002683 if (mService != null) {
2684 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002685 return mService.getMaximumFailedPasswordsForWipe(
2686 admin, userHandle, mParentInstance);
Dianne Hackborn254cb442010-01-27 19:23:59 -08002687 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002688 throw e.rethrowFromSystemServer();
Dianne Hackborn254cb442010-01-27 19:23:59 -08002689 }
2690 }
2691 return 0;
2692 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002693
Dianne Hackborn254cb442010-01-27 19:23:59 -08002694 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002695 * Returns the profile with the smallest maximum failed passwords for wipe,
2696 * for the given user. So for primary user, it might return the primary or
2697 * a managed profile. For a secondary user, it would be the same as the
2698 * user passed in.
2699 * @hide Used only by Keyguard
2700 */
2701 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
2702 if (mService != null) {
2703 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002704 return mService.getProfileWithMinimumFailedPasswordsForWipe(
2705 userHandle, mParentInstance);
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002706 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002707 throw e.rethrowFromSystemServer();
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002708 }
2709 }
2710 return UserHandle.USER_NULL;
2711 }
2712
2713 /**
Benjamin Miller1aed7882017-08-15 18:04:20 +02002714 * Flag for {@link #resetPasswordWithToken} and {@link #resetPassword}: don't allow other admins
2715 * to change the password again until the user has entered it.
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002716 */
2717 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002718
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002719 /**
Benjamin Miller1aed7882017-08-15 18:04:20 +02002720 * Flag for {@link #resetPasswordWithToken} and {@link #resetPassword}: don't ask for user
2721 * credentials on device boot.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002722 * If the flag is set, the device can be booted without asking for user password.
2723 * The absence of this flag does not change the current boot requirements. This flag
2724 * can be set by the device owner only. If the app is not the device owner, the flag
2725 * is ignored. Once the flag is set, it cannot be reverted back without resetting the
2726 * device to factory defaults.
2727 */
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002728 public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002;
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002729
2730 /**
Benjamin Miller1aed7882017-08-15 18:04:20 +02002731 * Force a new password for device unlock (the password needed to access the entire device) or
2732 * the work profile challenge on the current user. This takes effect immediately.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002733 * <p>
Rubin Xuaab7a412016-12-30 21:13:29 +00002734 * <em>For device owner and profile owners targeting SDK level
2735 * {@link android.os.Build.VERSION_CODES#O} or above, this API is no longer available and will
2736 * throw {@link SecurityException}. Please use the new API {@link #resetPasswordWithToken}
2737 * instead. </em>
2738 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002739 * <em>Note: This API has been limited as of {@link android.os.Build.VERSION_CODES#N} for
Makoto Onuki70f929e2015-11-11 12:40:15 -08002740 * device admins that are not device owner and not profile owner.
2741 * The password can now only be changed if there is currently no password set. Device owner
Ricky Wai977ade22016-05-24 15:02:41 +01002742 * and profile owner can still do this when user is unlocked and does not have a managed
2743 * profile.</em>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002744 * <p>
2745 * The given password must be sufficient for the current password quality and length constraints
2746 * as returned by {@link #getPasswordQuality(ComponentName)} and
2747 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then
2748 * it will be rejected and false returned. Note that the password may be a stronger quality
2749 * (containing alphanumeric characters when the requested quality is only numeric), in which
2750 * case the currently active quality will be increased to match.
2751 * <p>
2752 * Calling with a null or empty password will clear any existing PIN, pattern or password if the
Robin Leece5c4002016-03-23 17:05:03 +00002753 * current password constraints allow it. <em>Note: This will not work in
2754 * {@link android.os.Build.VERSION_CODES#N} and later for managed profiles, or for device admins
2755 * that are not device owner or profile owner. Once set, the password cannot be changed to null
2756 * or empty except by these admins.</em>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002757 * <p>
2758 * The calling device admin must have requested
2759 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call this method; if it has
2760 * not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002761 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01002762 * @param password The new password for the user. Null or empty clears the password.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002763 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002764 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
2765 * @return Returns true if the password was applied, or false if it is not acceptable for the
2766 * current constraints or if the user has not been decrypted yet.
2767 * @throws SecurityException if the calling application does not own an active administrator
2768 * that uses {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD}
Ricky Wai977ade22016-05-24 15:02:41 +01002769 * @throws IllegalStateException if the calling user is locked or has a managed profile.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002770 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002771 public boolean resetPassword(String password, int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002772 throwIfParentInstance("resetPassword");
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002773 if (mService != null) {
2774 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002775 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002776 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002777 throw e.rethrowFromSystemServer();
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002778 }
2779 }
2780 return false;
2781 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002782
Dianne Hackbornd6847842010-01-12 18:14:19 -08002783 /**
Rubin Xuaab7a412016-12-30 21:13:29 +00002784 * 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 +01002785 * device lockscreen password (if called by device owner), or managed profile challenge (if
2786 * called by profile owner), via {@link #resetPasswordWithToken}.
Rubin Xuaab7a412016-12-30 21:13:29 +00002787 * <p>
2788 * If the user currently has a lockscreen password, the provisioned token will not be
2789 * immediately usable; it only becomes active after the user performs a confirm credential
2790 * operation, which can be triggered by {@link KeyguardManager#createConfirmDeviceCredentialIntent}.
2791 * If the user has no lockscreen password, the token is activated immediately. In all cases,
2792 * the active state of the current token can be checked by {@link #isResetPasswordTokenActive}.
2793 * For security reasons, un-activated tokens are only stored in memory and will be lost once
2794 * the device reboots. In this case a new token needs to be provisioned again.
2795 * <p>
2796 * Once provisioned and activated, the token will remain effective even if the user changes
2797 * or clears the lockscreen password.
2798 * <p>
2799 * <em>This token is highly sensitive and should be treated at the same level as user
Rubin Xuf7b036d2017-04-05 18:37:07 +01002800 * credentials. In particular, NEVER store this token on device in plaintext. Do not store
2801 * the plaintext token in device-encrypted storage if it will be needed to reset password on
2802 * file-based encryption devices before user unlocks. Consider carefully how any password token
2803 * will be stored on your server and who will need access to them. Tokens may be the subject of
2804 * legal access requests.
Rubin Xuaab7a412016-12-30 21:13:29 +00002805 * </em>
2806 *
2807 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2808 * @param token a secure token a least 32-byte long, which must be generated by a
2809 * cryptographically strong random number generator.
2810 * @return true if the operation is successful, false otherwise.
Benjamin Miller1aed7882017-08-15 18:04:20 +02002811 * @throws SecurityException if admin is not a device or profile owner.
Rubin Xuaab7a412016-12-30 21:13:29 +00002812 * @throws IllegalArgumentException if the supplied token is invalid.
Rubin Xuaab7a412016-12-30 21:13:29 +00002813 */
2814 public boolean setResetPasswordToken(ComponentName admin, byte[] token) {
2815 throwIfParentInstance("setResetPasswordToken");
2816 if (mService != null) {
2817 try {
2818 return mService.setResetPasswordToken(admin, token);
2819 } catch (RemoteException e) {
2820 throw e.rethrowFromSystemServer();
2821 }
2822 }
2823 return false;
2824 }
2825
2826 /**
2827 * Called by a profile or device owner to revoke the current password reset token.
2828 *
2829 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2830 * @return true if the operation is successful, false otherwise.
Benjamin Miller1aed7882017-08-15 18:04:20 +02002831 * @throws SecurityException if admin is not a device or profile owner.
Rubin Xuaab7a412016-12-30 21:13:29 +00002832 */
2833 public boolean clearResetPasswordToken(ComponentName admin) {
2834 throwIfParentInstance("clearResetPasswordToken");
2835 if (mService != null) {
2836 try {
2837 return mService.clearResetPasswordToken(admin);
2838 } catch (RemoteException e) {
2839 throw e.rethrowFromSystemServer();
2840 }
2841 }
2842 return false;
2843 }
2844
2845 /**
2846 * Called by a profile or device owner to check if the current reset password token is active.
2847 *
2848 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2849 * @return true if the token is active, false otherwise.
Benjamin Miller1aed7882017-08-15 18:04:20 +02002850 * @throws SecurityException if admin is not a device or profile owner.
Rubin Xuaab7a412016-12-30 21:13:29 +00002851 * @throws IllegalStateException if no token has been set.
2852 */
2853 public boolean isResetPasswordTokenActive(ComponentName admin) {
2854 throwIfParentInstance("isResetPasswordTokenActive");
2855 if (mService != null) {
2856 try {
2857 return mService.isResetPasswordTokenActive(admin);
2858 } catch (RemoteException e) {
2859 throw e.rethrowFromSystemServer();
2860 }
2861 }
2862 return false;
2863 }
2864
2865 /**
Esteban Talavera7e4cbad2017-03-30 17:59:50 +01002866 * Called by device or profile owner to force set a new device unlock password or a managed
2867 * profile challenge on current user. This takes effect immediately.
Rubin Xuaab7a412016-12-30 21:13:29 +00002868 * <p>
2869 * Unlike {@link #resetPassword}, this API can change the password even before the user or
2870 * device is unlocked or decrypted. The supplied token must have been previously provisioned via
2871 * {@link #setResetPasswordToken}, and in active state {@link #isResetPasswordTokenActive}.
2872 * <p>
2873 * The given password must be sufficient for the current password quality and length constraints
2874 * as returned by {@link #getPasswordQuality(ComponentName)} and
2875 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then
Benjamin Miller1aed7882017-08-15 18:04:20 +02002876 * it will be rejected and false returned. Note that the password may be a stronger quality, for
2877 * example, a password containing alphanumeric characters when the requested quality is only
2878 * numeric.
Rubin Xuaab7a412016-12-30 21:13:29 +00002879 * <p>
Benjamin Miller1aed7882017-08-15 18:04:20 +02002880 * Calling with a {@code null} or empty password will clear any existing PIN, pattern or
2881 * password if the current password constraints allow it.
Rubin Xuaab7a412016-12-30 21:13:29 +00002882 *
2883 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Miller1aed7882017-08-15 18:04:20 +02002884 * @param password The new password for the user. {@code null} or empty clears the password.
2885 * @param token the password reset token previously provisioned by
2886 * {@link #setResetPasswordToken}.
Rubin Xuaab7a412016-12-30 21:13:29 +00002887 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Benjamin Miller1aed7882017-08-15 18:04:20 +02002888 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
Rubin Xuaab7a412016-12-30 21:13:29 +00002889 * @return Returns true if the password was applied, or false if it is not acceptable for the
2890 * current constraints.
Benjamin Miller1aed7882017-08-15 18:04:20 +02002891 * @throws SecurityException if admin is not a device or profile owner.
Rubin Xuaab7a412016-12-30 21:13:29 +00002892 * @throws IllegalStateException if the provided token is not valid.
Rubin Xuaab7a412016-12-30 21:13:29 +00002893 */
2894 public boolean resetPasswordWithToken(@NonNull ComponentName admin, String password,
2895 byte[] token, int flags) {
2896 throwIfParentInstance("resetPassword");
2897 if (mService != null) {
2898 try {
2899 return mService.resetPasswordWithToken(admin, password, token, flags);
2900 } catch (RemoteException e) {
2901 throw e.rethrowFromSystemServer();
2902 }
2903 }
2904 return false;
2905 }
2906
2907 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002908 * Called by an application that is administering the device to set the maximum time for user
2909 * activity until the device will lock. This limits the length that the user can set. It takes
2910 * effect immediately.
2911 * <p>
2912 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
2913 * to be able to call this method; if it has not, a security exception will be thrown.
2914 * <p>
2915 * This method can be called on the {@link DevicePolicyManager} instance returned by
2916 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2917 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002918 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002919 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002920 * @param timeMs The new desired maximum time to lock in milliseconds. A value of 0 means there
2921 * is no restriction.
2922 * @throws SecurityException if {@code admin} is not an active administrator or it does not use
2923 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002924 */
Robin Lee25e26452015-06-02 09:56:29 -07002925 public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002926 if (mService != null) {
2927 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002928 mService.setMaximumTimeToLock(admin, timeMs, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002929 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002930 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002931 }
2932 }
2933 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002934
Dianne Hackbornd6847842010-01-12 18:14:19 -08002935 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002936 * Retrieve the current maximum time to unlock for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01002937 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00002938 * a separate challenge are not taken into account.
2939 *
2940 * <p>This method can be called on the {@link DevicePolicyManager} instance
2941 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2942 * restrictions on the parent profile.
2943 *
Robin Lee25e26452015-06-02 09:56:29 -07002944 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002945 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07002946 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07002947 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002948 */
Robin Lee25e26452015-06-02 09:56:29 -07002949 public long getMaximumTimeToLock(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002950 return getMaximumTimeToLock(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002951 }
2952
2953 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002954 public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002955 if (mService != null) {
2956 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002957 return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002958 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002959 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002960 }
2961 }
2962 return 0;
2963 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002964
Dianne Hackbornd6847842010-01-12 18:14:19 -08002965 /**
Ricky Wai035e9242016-03-18 16:43:31 +00002966 * Returns maximum time to lock that applied by all profiles in this user. We do this because we
2967 * do not have a separate timeout to lock for work challenge only.
2968 *
2969 * @hide
2970 */
2971 public long getMaximumTimeToLockForUserAndProfiles(int userHandle) {
2972 if (mService != null) {
2973 try {
2974 return mService.getMaximumTimeToLockForUserAndProfiles(userHandle);
2975 } catch (RemoteException e) {
2976 throw e.rethrowFromSystemServer();
2977 }
2978 }
2979 return 0;
2980 }
2981
2982 /**
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002983 * Called by a device/profile owner to set the timeout after which unlocking with secondary, non
2984 * strong auth (e.g. fingerprint, trust agents) times out, i.e. the user has to use a strong
2985 * authentication method like password, pin or pattern.
2986 *
2987 * <p>This timeout is used internally to reset the timer to require strong auth again after
2988 * specified timeout each time it has been successfully used.
2989 *
2990 * <p>Fingerprint can also be disabled altogether using {@link #KEYGUARD_DISABLE_FINGERPRINT}.
2991 *
2992 * <p>Trust agents can also be disabled altogether using {@link #KEYGUARD_DISABLE_TRUST_AGENTS}.
2993 *
2994 * <p>The calling device admin must be a device or profile owner. If it is not,
2995 * a {@link SecurityException} will be thrown.
2996 *
Michal Karpinski943aabd2016-10-06 11:09:25 +01002997 * <p>The calling device admin can verify the value it has set by calling
2998 * {@link #getRequiredStrongAuthTimeout(ComponentName)} and passing in its instance.
2999 *
Michal Karpinski8f010dd2016-06-21 15:05:53 +01003000 * <p>This method can be called on the {@link DevicePolicyManager} instance returned by
3001 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
3002 * profile.
3003 *
3004 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xu5d39ea72017-04-24 20:26:30 +01003005 * @param timeoutMs The new timeout in milliseconds, after which the user will have to unlock
3006 * with strong authentication method. A value of 0 means the admin is not participating
3007 * in controlling the timeout.
Michal Karpinski943aabd2016-10-06 11:09:25 +01003008 * The minimum and maximum timeouts are platform-defined and are typically 1 hour and
3009 * 72 hours, respectively. Though discouraged, the admin may choose to require strong
3010 * auth at all times using {@link #KEYGUARD_DISABLE_FINGERPRINT} and/or
3011 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01003012 *
3013 * @throws SecurityException if {@code admin} is not a device or profile owner.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01003014 */
3015 public void setRequiredStrongAuthTimeout(@NonNull ComponentName admin,
3016 long timeoutMs) {
3017 if (mService != null) {
3018 try {
3019 mService.setRequiredStrongAuthTimeout(admin, timeoutMs, mParentInstance);
3020 } catch (RemoteException e) {
3021 throw e.rethrowFromSystemServer();
3022 }
3023 }
3024 }
3025
3026 /**
3027 * Determine for how long the user will be able to use secondary, non strong auth for
3028 * authentication, since last strong method authentication (password, pin or pattern) was used.
3029 * After the returned timeout the user is required to use strong authentication method.
3030 *
3031 * <p>This method can be called on the {@link DevicePolicyManager} instance
3032 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
3033 * restrictions on the parent profile.
3034 *
3035 * @param admin The name of the admin component to check, or {@code null} to aggregate
3036 * accross all participating admins.
Rubin Xu5d39ea72017-04-24 20:26:30 +01003037 * @return The timeout in milliseconds or 0 if not configured for the provided admin.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01003038 */
3039 public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin) {
3040 return getRequiredStrongAuthTimeout(admin, myUserId());
3041 }
3042
3043 /** @hide per-user version */
3044 public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin, @UserIdInt int userId) {
3045 if (mService != null) {
3046 try {
3047 return mService.getRequiredStrongAuthTimeout(admin, userId, mParentInstance);
3048 } catch (RemoteException e) {
3049 throw e.rethrowFromSystemServer();
3050 }
3051 }
3052 return DEFAULT_STRONG_AUTH_TIMEOUT_MS;
3053 }
3054
3055 /**
Andrew Scull85a63bc2016-10-24 13:47:47 +01003056 * Flag for {@link #lockNow(int)}: also evict the user's credential encryption key from the
3057 * keyring. The user's credential will need to be entered again in order to derive the
3058 * credential encryption key that will be stored back in the keyring for future use.
3059 * <p>
Andrew Scull17e1b5d2017-04-25 14:44:24 +01003060 * This flag can only be used by a profile owner when locking a managed profile when
3061 * {@link #getStorageEncryptionStatus} returns {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}.
Andrew Scull85a63bc2016-10-24 13:47:47 +01003062 * <p>
3063 * In order to secure user data, the user will be stopped and restarted so apps should wait
3064 * until they are next run to perform further actions.
3065 */
Andrew Scull17e1b5d2017-04-25 14:44:24 +01003066 public static final int FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY = 1;
3067
Andrew Scull85a63bc2016-10-24 13:47:47 +01003068 /** @hide */
3069 @Retention(RetentionPolicy.SOURCE)
Andrew Scull17e1b5d2017-04-25 14:44:24 +01003070 @IntDef(flag=true, value={FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY})
Andrew Scull85a63bc2016-10-24 13:47:47 +01003071 public @interface LockNowFlag {}
3072
3073 /**
3074 * Make the device lock immediately, as if the lock screen timeout has expired at the point of
3075 * this call.
3076 * <p>
3077 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
3078 * to be able to call this method; if it has not, a security exception will be thrown.
3079 * <p>
3080 * This method can be called on the {@link DevicePolicyManager} instance returned by
3081 * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile.
3082 * <p>
3083 * Equivalent to calling {@link #lockNow(int)} with no flags.
3084 *
3085 * @throws SecurityException if the calling application does not own an active administrator
3086 * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
3087 */
3088 public void lockNow() {
3089 lockNow(0);
3090 }
3091
3092 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003093 * Make the device lock immediately, as if the lock screen timeout has expired at the point of
3094 * this call.
3095 * <p>
3096 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
3097 * to be able to call this method; if it has not, a security exception will be thrown.
3098 * <p>
3099 * This method can be called on the {@link DevicePolicyManager} instance returned by
3100 * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003101 *
Andrew Scull17e1b5d2017-04-25 14:44:24 +01003102 * @param flags May be 0 or {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003103 * @throws SecurityException if the calling application does not own an active administrator
Andrew Scull85a63bc2016-10-24 13:47:47 +01003104 * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} or the
Andrew Scull17e1b5d2017-04-25 14:44:24 +01003105 * {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY} flag is passed by an application
3106 * that is not a profile
Andrew Scull85a63bc2016-10-24 13:47:47 +01003107 * owner of a managed profile.
Andrew Scull17e1b5d2017-04-25 14:44:24 +01003108 * @throws IllegalArgumentException if the {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY} flag is
3109 * passed when locking the parent profile.
3110 * @throws UnsupportedOperationException if the {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY}
3111 * flag is passed when {@link #getStorageEncryptionStatus} does not return
3112 * {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08003113 */
Andrew Scull85a63bc2016-10-24 13:47:47 +01003114 public void lockNow(@LockNowFlag int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -08003115 if (mService != null) {
3116 try {
Andrew Scull85a63bc2016-10-24 13:47:47 +01003117 mService.lockNow(flags, mParentInstance);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08003118 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003119 throw e.rethrowFromSystemServer();
Dianne Hackborndf83afa2010-01-20 13:37:26 -08003120 }
3121 }
3122 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003123
Dianne Hackbornd6847842010-01-12 18:14:19 -08003124 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07003125 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00003126 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07003127 */
3128 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
3129
3130 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00003131 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
3132 * data.
3133 *
Paul Crowley2934b262014-12-02 11:21:13 +00003134 * <p>This flag may only be set by device owner admins; if it is set by
3135 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00003136 */
3137 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
3138
3139 /**
yinxuf4f9cec2017-06-19 10:28:19 -07003140 * Flag for {@link #wipeData(int)}: also erase the device's eUICC data.
3141 *
3142 * TODO(b/35851809): make this public.
3143 * @hide
3144 */
3145 public static final int WIPE_EUICC = 0x0004;
3146
yuemingwf7f67dc2017-09-08 14:23:53 +01003147
yinxuf4f9cec2017-06-19 10:28:19 -07003148 /**
Suprabh Shukla556b05a2016-08-10 15:49:24 -07003149 * Ask that all user data be wiped. If called as a secondary user, the user will be removed and
3150 * other users will remain unaffected. Calling from the primary user will cause the device to
3151 * reboot, erasing all device data - including all the secondary users and their data - while
3152 * booting up.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003153 * <p>
3154 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to
3155 * be able to call this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003156 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003157 * @param flags Bit mask of additional options: currently supported flags are
3158 * {@link #WIPE_EXTERNAL_STORAGE} and {@link #WIPE_RESET_PROTECTION_DATA}.
3159 * @throws SecurityException if the calling application does not own an active administrator
3160 * that uses {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}
Dianne Hackbornd6847842010-01-12 18:14:19 -08003161 */
3162 public void wipeData(int flags) {
yuemingwf7f67dc2017-09-08 14:23:53 +01003163 final String wipeReasonForUser = mContext.getString(
3164 R.string.work_profile_deleted_description_dpm_wipe);
3165 wipeDataInternal(flags, wipeReasonForUser);
3166 }
3167
3168 /**
3169 * Ask that all user data be wiped. If called as a secondary user, the user will be removed and
3170 * other users will remain unaffected, the provided reason for wiping data can be shown to
3171 * user. Calling from the primary user will cause the device to reboot, erasing all device data
3172 * - including all the secondary users and their data - while booting up. In this case, we don't
3173 * show the reason to the user since the device would be factory reset.
3174 * <p>
3175 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to
3176 * be able to call this method; if it has not, a security exception will be thrown.
3177 *
3178 * @param flags Bit mask of additional options: currently supported flags are
3179 * {@link #WIPE_EXTERNAL_STORAGE} and {@link #WIPE_RESET_PROTECTION_DATA}.
3180 * @param reason a string that contains the reason for wiping data, which can be
3181 * presented to the user.
3182 * @throws SecurityException if the calling application does not own an active administrator
3183 * that uses {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}
3184 * @throws IllegalArgumentException if the input reason string is null or empty.
3185 */
3186 public void wipeDataWithReason(int flags, @NonNull CharSequence reason) {
3187 Preconditions.checkNotNull(reason, "CharSequence is null");
3188 wipeDataInternal(flags, reason.toString());
3189 }
3190
3191 /**
3192 * Internal function for both {@link #wipeData(int)} and
3193 * {@link #wipeDataWithReason(int, CharSequence)} to call.
3194 *
3195 * @see #wipeData(int)
3196 * @see #wipeDataWithReason(int, CharSequence)
3197 * @hide
3198 */
3199 private void wipeDataInternal(int flags, @NonNull String wipeReasonForUser) {
3200 throwIfParentInstance("wipeDataWithReason");
Dianne Hackbornd6847842010-01-12 18:14:19 -08003201 if (mService != null) {
3202 try {
yuemingwf7f67dc2017-09-08 14:23:53 +01003203 mService.wipeDataWithReason(flags, wipeReasonForUser);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003204 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003205 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003206 }
3207 }
3208 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003209
Dianne Hackbornd6847842010-01-12 18:14:19 -08003210 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07003211 * Called by an application that is administering the device to set the
3212 * global proxy and exclusion list.
3213 * <p>
3214 * The calling device admin must have requested
3215 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
3216 * this method; if it has not, a security exception will be thrown.
3217 * Only the first device admin can set the proxy. If a second admin attempts
3218 * to set the proxy, the {@link ComponentName} of the admin originally setting the
Robin Lee25e26452015-06-02 09:56:29 -07003219 * proxy will be returned. If successful in setting the proxy, {@code null} will
Oscar Montemayor69238c62010-08-03 10:51:06 -07003220 * be returned.
3221 * The method can be called repeatedly by the device admin alrady setting the
3222 * proxy to update the proxy and exclusion list.
3223 *
Robin Lee25e26452015-06-02 09:56:29 -07003224 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Oscar Montemayor69238c62010-08-03 10:51:06 -07003225 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
3226 * Pass Proxy.NO_PROXY to reset the proxy.
3227 * @param exclusionList a list of domains to be excluded from the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07003228 * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName}
3229 * of the device admin that sets the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08003230 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07003231 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003232 public @Nullable ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec,
Oscar Montemayor69238c62010-08-03 10:51:06 -07003233 List<String> exclusionList ) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003234 throwIfParentInstance("setGlobalProxy");
Oscar Montemayor69238c62010-08-03 10:51:06 -07003235 if (proxySpec == null) {
3236 throw new NullPointerException();
3237 }
3238 if (mService != null) {
3239 try {
3240 String hostSpec;
3241 String exclSpec;
3242 if (proxySpec.equals(Proxy.NO_PROXY)) {
3243 hostSpec = null;
3244 exclSpec = null;
3245 } else {
3246 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
3247 throw new IllegalArgumentException();
3248 }
3249 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
3250 String hostName = sa.getHostName();
3251 int port = sa.getPort();
3252 StringBuilder hostBuilder = new StringBuilder();
3253 hostSpec = hostBuilder.append(hostName)
3254 .append(":").append(Integer.toString(port)).toString();
3255 if (exclusionList == null) {
3256 exclSpec = "";
3257 } else {
3258 StringBuilder listBuilder = new StringBuilder();
3259 boolean firstDomain = true;
3260 for (String exclDomain : exclusionList) {
3261 if (!firstDomain) {
3262 listBuilder = listBuilder.append(",");
3263 } else {
3264 firstDomain = false;
3265 }
3266 listBuilder = listBuilder.append(exclDomain.trim());
3267 }
3268 exclSpec = listBuilder.toString();
3269 }
Yuhao Zheng90704842014-02-28 17:22:45 -08003270 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
3271 != android.net.Proxy.PROXY_VALID)
3272 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07003273 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003274 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07003275 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003276 throw e.rethrowFromSystemServer();
Oscar Montemayor69238c62010-08-03 10:51:06 -07003277 }
3278 }
3279 return null;
3280 }
3281
3282 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003283 * Set a network-independent global HTTP proxy. This is not normally what you want for typical
3284 * HTTP proxies - they are generally network dependent. However if you're doing something
3285 * unusual like general internal filtering this may be useful. On a private network where the
3286 * proxy is not accessible, you may break HTTP using this.
3287 * <p>
3288 * This method requires the caller to be the device owner.
3289 * <p>
3290 * This proxy is only a recommendation and it is possible that some apps will ignore it.
Jason Monk03bc9912014-05-13 09:44:57 -04003291 *
Jason Monk03bc9912014-05-13 09:44:57 -04003292 * @see ProxyInfo
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003293 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3294 * @param proxyInfo The a {@link ProxyInfo} object defining the new global HTTP proxy. A
3295 * {@code null} value will clear the global HTTP proxy.
3296 * @throws SecurityException if {@code admin} is not the device owner.
Jason Monk03bc9912014-05-13 09:44:57 -04003297 */
Robin Lee25e26452015-06-02 09:56:29 -07003298 public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo
3299 proxyInfo) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003300 throwIfParentInstance("setRecommendedGlobalProxy");
Jason Monk03bc9912014-05-13 09:44:57 -04003301 if (mService != null) {
3302 try {
3303 mService.setRecommendedGlobalProxy(admin, proxyInfo);
3304 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003305 throw e.rethrowFromSystemServer();
Jason Monk03bc9912014-05-13 09:44:57 -04003306 }
3307 }
3308 }
3309
3310 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07003311 * Returns the component name setting the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07003312 * @return ComponentName object of the device admin that set the global proxy, or {@code null}
3313 * if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08003314 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07003315 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003316 public @Nullable ComponentName getGlobalProxyAdmin() {
Oscar Montemayor69238c62010-08-03 10:51:06 -07003317 if (mService != null) {
3318 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003319 return mService.getGlobalProxyAdmin(myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07003320 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003321 throw e.rethrowFromSystemServer();
Oscar Montemayor69238c62010-08-03 10:51:06 -07003322 }
3323 }
3324 return null;
3325 }
3326
3327 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08003328 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003329 * indicating that encryption is not supported.
3330 */
3331 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
3332
3333 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08003334 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003335 * indicating that encryption is supported, but is not currently active.
3336 */
3337 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
3338
3339 /**
Robin Lee3795fb02015-02-16 14:17:23 +00003340 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003341 * indicating that encryption is not currently active, but is currently
3342 * being activated. This is only reported by devices that support
3343 * encryption of data and only when the storage is currently
3344 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
3345 * to become encrypted will never return this value.
3346 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08003347 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003348
3349 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08003350 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003351 * indicating that encryption is active.
Amith Yamasani75db1252016-07-11 14:41:01 -07003352 * <p>
3353 * Also see {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003354 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08003355 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003356
3357 /**
Robin Lee3795fb02015-02-16 14:17:23 +00003358 * Result code for {@link #getStorageEncryptionStatus}:
3359 * indicating that encryption is active, but an encryption key has not
3360 * been set by the user.
3361 */
3362 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
3363
3364 /**
Makoto Onukid4c9e542016-02-25 18:17:30 -08003365 * Result code for {@link #getStorageEncryptionStatus}:
Amith Yamasani75db1252016-07-11 14:41:01 -07003366 * indicating that encryption is active and the encryption key is tied to the user or profile.
3367 * <p>
3368 * This value is only returned to apps targeting API level 24 and above. For apps targeting
3369 * earlier API levels, {@link #ENCRYPTION_STATUS_ACTIVE} is returned, even if the
3370 * encryption key is specific to the user or profile.
Makoto Onukid4c9e542016-02-25 18:17:30 -08003371 */
3372 public static final int ENCRYPTION_STATUS_ACTIVE_PER_USER = 5;
3373
3374 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003375 * Activity action: begin the process of encrypting data on the device. This activity should
3376 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
3377 * After resuming from this activity, use {@link #getStorageEncryption}
3378 * to check encryption status. However, on some devices this activity may never return, as
3379 * it may trigger a reboot and in some cases a complete data wipe of the device.
3380 */
3381 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
3382 public static final String ACTION_START_ENCRYPTION
3383 = "android.app.action.START_ENCRYPTION";
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003384 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07003385 * Widgets are enabled in keyguard
3386 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07003387 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07003388
3389 /**
Jim Miller50e62182014-04-23 17:25:00 -07003390 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07003391 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07003392 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
3393
3394 /**
3395 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
3396 */
3397 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
3398
3399 /**
Jim Miller50e62182014-04-23 17:25:00 -07003400 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
3401 */
3402 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
3403
3404 /**
3405 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
3406 */
3407 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
3408
3409 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02003410 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07003411 * (e.g. PIN/Pattern/Password).
3412 */
3413 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
3414
3415 /**
Jim Miller06e34502014-07-17 14:46:05 -07003416 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
3417 */
3418 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
3419
3420 /**
Adrian Roos7f06eed2016-02-05 15:21:02 -08003421 * Disable text entry into notifications on secure keyguard screens (e.g. PIN/Pattern/Password).
3422 */
3423 public static final int KEYGUARD_DISABLE_REMOTE_INPUT = 1 << 6;
3424
3425 /**
Jim Miller35207742012-11-02 15:33:20 -07003426 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07003427 */
3428 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07003429
3430 /**
Robin Leeacdeac62017-02-21 22:13:38 +00003431 * Keyguard features that when set on a managed profile that doesn't have its own challenge will
3432 * affect the profile's parent user. These can also be set on the managed profile's parent
3433 * {@link DevicePolicyManager} instance.
3434 *
3435 * @hide
3436 */
3437 public static final int PROFILE_KEYGUARD_FEATURES_AFFECT_OWNER =
3438 DevicePolicyManager.KEYGUARD_DISABLE_TRUST_AGENTS
3439 | DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT;
3440
3441 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003442 * Called by an application that is administering the device to request that the storage system
3443 * be encrypted.
3444 * <p>
3445 * When multiple device administrators attempt to control device encryption, the most secure,
3446 * supported setting will always be used. If any device administrator requests device
3447 * encryption, it will be enabled; Conversely, if a device administrator attempts to disable
3448 * device encryption while another device administrator has enabled it, the call to disable will
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003449 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003450 * <p>
3451 * This policy controls encryption of the secure (application data) storage area. Data written
3452 * to other storage areas may or may not be encrypted, and this policy does not require or
3453 * control the encryption of any other storage areas. There is one exception: If
3454 * {@link android.os.Environment#isExternalStorageEmulated()} is {@code true}, then the
3455 * directory returned by {@link android.os.Environment#getExternalStorageDirectory()} must be
3456 * written to disk within the encrypted storage area.
3457 * <p>
3458 * Important Note: On some devices, it is possible to encrypt storage without requiring the user
3459 * to create a device PIN or Password. In this case, the storage is encrypted, but the
3460 * encryption key may not be fully secured. For maximum security, the administrator should also
3461 * require (and check for) a pattern, PIN, or password.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003462 *
3463 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3464 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08003465 * @return the new request status (for all active admins) - will be one of
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003466 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
3467 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
3468 * {@link #getStorageEncryptionStatus()} to query the actual device state.
3469 * @throws SecurityException if {@code admin} is not an active administrator or does not use
3470 * {@link DeviceAdminInfo#USES_ENCRYPTED_STORAGE}
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003471 */
Robin Lee25e26452015-06-02 09:56:29 -07003472 public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003473 throwIfParentInstance("setStorageEncryption");
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003474 if (mService != null) {
3475 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003476 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003477 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003478 throw e.rethrowFromSystemServer();
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003479 }
3480 }
3481 return ENCRYPTION_STATUS_UNSUPPORTED;
3482 }
3483
3484 /**
3485 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08003486 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003487 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08003488 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
3489 * this will return the requested encryption setting as an aggregate of all active
3490 * administrators.
3491 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003492 */
Robin Lee25e26452015-06-02 09:56:29 -07003493 public boolean getStorageEncryption(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003494 throwIfParentInstance("getStorageEncryption");
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003495 if (mService != null) {
3496 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003497 return mService.getStorageEncryption(admin, myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003498 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003499 throw e.rethrowFromSystemServer();
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003500 }
3501 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08003502 return false;
3503 }
3504
3505 /**
3506 * Called by an application that is administering the device to
3507 * determine the current encryption status of the device.
Amith Yamasani75db1252016-07-11 14:41:01 -07003508 * <p>
Andy Stadler22dbfda2011-01-17 12:47:31 -08003509 * Depending on the returned status code, the caller may proceed in different
3510 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
3511 * storage system does not support encryption. If the
3512 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
3513 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00003514 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
3515 * storage system has enabled encryption but no password is set so further action
Amith Yamasani75db1252016-07-11 14:41:01 -07003516 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING},
3517 * {@link #ENCRYPTION_STATUS_ACTIVE} or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER},
3518 * no further action is required.
Andy Stadler22dbfda2011-01-17 12:47:31 -08003519 *
Robin Lee7e678712014-07-24 16:41:31 +01003520 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08003521 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00003522 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
Amith Yamasani75db1252016-07-11 14:41:01 -07003523 * {@link #ENCRYPTION_STATUS_ACTIVE}, or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08003524 */
3525 public int getStorageEncryptionStatus() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003526 throwIfParentInstance("getStorageEncryptionStatus");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003527 return getStorageEncryptionStatus(myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003528 }
3529
3530 /** @hide per-user version */
3531 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08003532 if (mService != null) {
3533 try {
Makoto Onukid4c9e542016-02-25 18:17:30 -08003534 return mService.getStorageEncryptionStatus(mContext.getPackageName(), userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08003535 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003536 throw e.rethrowFromSystemServer();
Andy Stadler22dbfda2011-01-17 12:47:31 -08003537 }
3538 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003539 return ENCRYPTION_STATUS_UNSUPPORTED;
3540 }
3541
3542 /**
Robin Lee2f7e1e42016-03-21 10:50:01 +00003543 * Mark a CA certificate as approved by the device user. This means that they have been notified
3544 * of the installation, were made aware of the risks, viewed the certificate and still wanted to
3545 * keep the certificate on the device.
3546 *
3547 * Calling with {@param approval} as {@code true} will cancel any ongoing warnings related to
3548 * this certificate.
3549 *
3550 * @hide
3551 */
3552 public boolean approveCaCert(String alias, int userHandle, boolean approval) {
3553 if (mService != null) {
3554 try {
3555 return mService.approveCaCert(alias, userHandle, approval);
3556 } catch (RemoteException e) {
3557 throw e.rethrowFromSystemServer();
3558 }
3559 }
3560 return false;
3561 }
3562
3563 /**
3564 * Check whether a CA certificate has been approved by the device user.
3565 *
3566 * @hide
3567 */
3568 public boolean isCaCertApproved(String alias, int userHandle) {
3569 if (mService != null) {
3570 try {
3571 return mService.isCaCertApproved(alias, userHandle);
3572 } catch (RemoteException e) {
3573 throw e.rethrowFromSystemServer();
3574 }
3575 }
3576 return false;
3577 }
3578
3579 /**
Robin Lee7e678712014-07-24 16:41:31 +01003580 * Installs the given certificate as a user CA.
3581 *
Edman Anjosf9946772016-11-28 16:35:15 +01003582 * The caller must be a profile or device owner on that user, or a delegate package given the
3583 * {@link #DELEGATION_CERT_INSTALL} scope via {@link #setDelegatedScopes}; otherwise a
3584 * security exception will be thrown.
3585 *
Robin Lee25e26452015-06-02 09:56:29 -07003586 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3587 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003588 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04003589 *
3590 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01003591 * interrupted, true otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003592 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3593 * owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003594 * @see #setDelegatedScopes
3595 * @see #DELEGATION_CERT_INSTALL
Maggie Benthallda51e682013-08-08 22:35:44 -04003596 */
Robin Lee25e26452015-06-02 09:56:29 -07003597 public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003598 throwIfParentInstance("installCaCert");
Maggie Benthallda51e682013-08-08 22:35:44 -04003599 if (mService != null) {
3600 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003601 return mService.installCaCert(admin, mContext.getPackageName(), certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04003602 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003603 throw e.rethrowFromSystemServer();
Maggie Benthallda51e682013-08-08 22:35:44 -04003604 }
3605 }
3606 return false;
3607 }
3608
3609 /**
Robin Lee7e678712014-07-24 16:41:31 +01003610 * Uninstalls the given certificate from trusted user CAs, if present.
3611 *
Edman Anjosf9946772016-11-28 16:35:15 +01003612 * The caller must be a profile or device owner on that user, or a delegate package given the
3613 * {@link #DELEGATION_CERT_INSTALL} scope via {@link #setDelegatedScopes}; otherwise a
3614 * security exception will be thrown.
3615 *
Robin Lee25e26452015-06-02 09:56:29 -07003616 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3617 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003618 * @param certBuffer encoded form of the certificate to remove.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003619 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3620 * owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003621 * @see #setDelegatedScopes
3622 * @see #DELEGATION_CERT_INSTALL
Maggie Benthallda51e682013-08-08 22:35:44 -04003623 */
Robin Lee25e26452015-06-02 09:56:29 -07003624 public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003625 throwIfParentInstance("uninstallCaCert");
Maggie Benthallda51e682013-08-08 22:35:44 -04003626 if (mService != null) {
3627 try {
Robin Lee306fe082014-06-19 14:04:24 +00003628 final String alias = getCaCertAlias(certBuffer);
Edman Anjosf9946772016-11-28 16:35:15 +01003629 mService.uninstallCaCerts(admin, mContext.getPackageName(), new String[] {alias});
Robin Lee306fe082014-06-19 14:04:24 +00003630 } catch (CertificateException e) {
3631 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04003632 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003633 throw e.rethrowFromSystemServer();
Maggie Benthallda51e682013-08-08 22:35:44 -04003634 }
3635 }
3636 }
3637
3638 /**
Robin Lee7e678712014-07-24 16:41:31 +01003639 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
3640 * If a user has installed any certificates by other means than device policy these will be
3641 * included too.
3642 *
Robin Lee25e26452015-06-02 09:56:29 -07003643 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3644 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003645 * @return a List of byte[] arrays, each encoding one user CA certificate.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003646 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3647 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04003648 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003649 public @NonNull List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) {
3650 final List<byte[]> certs = new ArrayList<byte[]>();
Benjamin Franzbc33c822016-04-15 08:57:52 +01003651 throwIfParentInstance("getInstalledCaCerts");
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003652 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01003653 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003654 mService.enforceCanManageCaCerts(admin, mContext.getPackageName());
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003655 final TrustedCertificateStore certStore = new TrustedCertificateStore();
3656 for (String alias : certStore.userAliases()) {
3657 try {
3658 certs.add(certStore.getCertificate(alias).getEncoded());
3659 } catch (CertificateException ce) {
3660 Log.w(TAG, "Could not encode certificate: " + alias, ce);
3661 }
3662 }
3663 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003664 throw re.rethrowFromSystemServer();
Robin Lee7e678712014-07-24 16:41:31 +01003665 }
3666 }
3667 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04003668 }
3669
3670 /**
Robin Lee7e678712014-07-24 16:41:31 +01003671 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
3672 * means other than device policy will also be removed, except for system CA certificates.
3673 *
Robin Lee25e26452015-06-02 09:56:29 -07003674 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3675 * {@code null} if calling from a delegated certificate installer.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003676 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3677 * owner.
Robin Lee7e678712014-07-24 16:41:31 +01003678 */
Robin Lee25e26452015-06-02 09:56:29 -07003679 public void uninstallAllUserCaCerts(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003680 throwIfParentInstance("uninstallAllUserCaCerts");
Robin Lee7e678712014-07-24 16:41:31 +01003681 if (mService != null) {
Robin Lee83881bd2015-06-09 16:04:38 -07003682 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003683 mService.uninstallCaCerts(admin, mContext.getPackageName(),
3684 new TrustedCertificateStore().userAliases() .toArray(new String[0]));
Robin Lee83881bd2015-06-09 16:04:38 -07003685 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003686 throw re.rethrowFromSystemServer();
Robin Lee7e678712014-07-24 16:41:31 +01003687 }
3688 }
3689 }
3690
3691 /**
3692 * Returns whether this certificate is installed as a trusted CA.
3693 *
Robin Lee25e26452015-06-02 09:56:29 -07003694 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3695 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003696 * @param certBuffer encoded form of the certificate to look up.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003697 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3698 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04003699 */
Robin Lee25e26452015-06-02 09:56:29 -07003700 public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003701 throwIfParentInstance("hasCaCertInstalled");
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003702 if (mService != null) {
3703 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003704 mService.enforceCanManageCaCerts(admin, mContext.getPackageName());
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003705 return getCaCertAlias(certBuffer) != null;
3706 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003707 throw re.rethrowFromSystemServer();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003708 } catch (CertificateException ce) {
3709 Log.w(TAG, "Could not parse certificate", ce);
3710 }
Maggie Benthallda51e682013-08-08 22:35:44 -04003711 }
3712 return false;
3713 }
3714
3715 /**
Robin Leece3399f2016-02-24 12:08:32 +00003716 * Called by a device or profile owner, or delegated certificate installer, to install a
3717 * certificate and corresponding private key. All apps within the profile will be able to access
3718 * the certificate and use the private key, given direct user approval.
3719 *
3720 * <p>Access to the installed credentials will not be granted to the caller of this API without
3721 * direct user approval. This is for security - should a certificate installer become
3722 * compromised, certificates it had already installed will be protected.
3723 *
3724 * <p>If the installer must have access to the credentials, call
Rubin Xub4365912016-03-23 12:13:22 +00003725 * {@link #installKeyPair(ComponentName, PrivateKey, Certificate[], String, boolean)} instead.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003726 *
Robin Lee25e26452015-06-02 09:56:29 -07003727 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3728 * {@code null} if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003729 * @param privKey The private key to install.
3730 * @param cert The certificate to install.
3731 * @param alias The private key alias under which to install the certificate. If a certificate
3732 * with that alias already exists, it will be overwritten.
3733 * @return {@code true} if the keys were installed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003734 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3735 * owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003736 * @see #setDelegatedScopes
3737 * @see #DELEGATION_CERT_INSTALL
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003738 */
Robin Leefbc65642015-08-03 16:21:22 +01003739 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
3740 @NonNull Certificate cert, @NonNull String alias) {
Rubin Xub4365912016-03-23 12:13:22 +00003741 return installKeyPair(admin, privKey, new Certificate[] {cert}, alias, false);
Robin Leece3399f2016-02-24 12:08:32 +00003742 }
3743
3744 /**
3745 * Called by a device or profile owner, or delegated certificate installer, to install a
Rubin Xub4365912016-03-23 12:13:22 +00003746 * certificate chain and corresponding private key for the leaf certificate. All apps within the
3747 * profile will be able to access the certificate chain and use the private key, given direct
3748 * user approval.
Robin Leece3399f2016-02-24 12:08:32 +00003749 *
Robin Leea1b290e2016-03-09 14:38:36 +00003750 * <p>The caller of this API may grant itself access to the certificate and private key
3751 * immediately, without user approval. It is a best practice not to request this unless strictly
3752 * necessary since it opens up additional security vulnerabilities.
Robin Leece3399f2016-02-24 12:08:32 +00003753 *
3754 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Robin Leea1b290e2016-03-09 14:38:36 +00003755 * {@code null} if calling from a delegated certificate installer.
Robin Leece3399f2016-02-24 12:08:32 +00003756 * @param privKey The private key to install.
Rubin Xub4365912016-03-23 12:13:22 +00003757 * @param certs The certificate chain to install. The chain should start with the leaf
3758 * certificate and include the chain of trust in order. This will be returned by
3759 * {@link android.security.KeyChain#getCertificateChain}.
Robin Leece3399f2016-02-24 12:08:32 +00003760 * @param alias The private key alias under which to install the certificate. If a certificate
Robin Leea1b290e2016-03-09 14:38:36 +00003761 * with that alias already exists, it will be overwritten.
Robin Leece3399f2016-02-24 12:08:32 +00003762 * @param requestAccess {@code true} to request that the calling app be granted access to the
Robin Leea1b290e2016-03-09 14:38:36 +00003763 * credentials immediately. Otherwise, access to the credentials will be gated by user
3764 * approval.
Robin Leece3399f2016-02-24 12:08:32 +00003765 * @return {@code true} if the keys were installed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003766 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3767 * owner.
Rubin Xub4365912016-03-23 12:13:22 +00003768 * @see android.security.KeyChain#getCertificateChain
Edman Anjosf9946772016-11-28 16:35:15 +01003769 * @see #setDelegatedScopes
3770 * @see #DELEGATION_CERT_INSTALL
Robin Leece3399f2016-02-24 12:08:32 +00003771 */
3772 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
Rubin Xub4365912016-03-23 12:13:22 +00003773 @NonNull Certificate[] certs, @NonNull String alias, boolean requestAccess) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003774 throwIfParentInstance("installKeyPair");
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003775 try {
Rubin Xub4365912016-03-23 12:13:22 +00003776 final byte[] pemCert = Credentials.convertToPem(certs[0]);
3777 byte[] pemChain = null;
3778 if (certs.length > 1) {
3779 pemChain = Credentials.convertToPem(Arrays.copyOfRange(certs, 1, certs.length));
3780 }
Robin Lee0d5ccb72014-09-12 17:41:44 +01003781 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
3782 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
Edman Anjosf9946772016-11-28 16:35:15 +01003783 return mService.installKeyPair(admin, mContext.getPackageName(), pkcs8Key, pemCert,
3784 pemChain, alias, requestAccess);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003785 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003786 throw e.rethrowFromSystemServer();
Robin Lee0d5ccb72014-09-12 17:41:44 +01003787 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
3788 Log.w(TAG, "Failed to obtain private key material", e);
3789 } catch (CertificateException | IOException e) {
3790 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003791 }
3792 return false;
3793 }
3794
3795 /**
Robin Leea1b290e2016-03-09 14:38:36 +00003796 * Called by a device or profile owner, or delegated certificate installer, to remove a
3797 * certificate and private key pair installed under a given alias.
Robin Leefbc65642015-08-03 16:21:22 +01003798 *
3799 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Robin Leea1b290e2016-03-09 14:38:36 +00003800 * {@code null} if calling from a delegated certificate installer.
Robin Leefbc65642015-08-03 16:21:22 +01003801 * @param alias The private key alias under which the certificate is installed.
Robin Leea1b290e2016-03-09 14:38:36 +00003802 * @return {@code true} if the private key alias no longer exists, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003803 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3804 * owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003805 * @see #setDelegatedScopes
3806 * @see #DELEGATION_CERT_INSTALL
Robin Leefbc65642015-08-03 16:21:22 +01003807 */
3808 public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003809 throwIfParentInstance("removeKeyPair");
Robin Leefbc65642015-08-03 16:21:22 +01003810 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003811 return mService.removeKeyPair(admin, mContext.getPackageName(), alias);
Robin Leefbc65642015-08-03 16:21:22 +01003812 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003813 throw e.rethrowFromSystemServer();
Robin Leefbc65642015-08-03 16:21:22 +01003814 }
Robin Leefbc65642015-08-03 16:21:22 +01003815 }
3816
3817 /**
Robin Lee25e26452015-06-02 09:56:29 -07003818 * @return the alias of a given CA certificate in the certificate store, or {@code null} if it
Robin Lee306fe082014-06-19 14:04:24 +00003819 * doesn't exist.
3820 */
3821 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
3822 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
3823 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
3824 new ByteArrayInputStream(certBuffer));
3825 return new TrustedCertificateStore().getCertificateAlias(cert);
3826 }
3827
3828 /**
Rubin Xuec32b562015-03-03 17:34:05 +00003829 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01003830 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00003831 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01003832 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00003833 * <p>
3834 * Delegated certificate installer is a per-user state. The delegated access is persistent until
3835 * it is later cleared by calling this method with a null value or uninstallling the certificate
3836 * installer.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003837 * <p>
Rubin Xuf03d0a62016-02-10 14:54:15 +00003838 * <b>Note:</b>Starting from {@link android.os.Build.VERSION_CODES#N}, if the caller
3839 * application's target SDK version is {@link android.os.Build.VERSION_CODES#N} or newer, the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003840 * supplied certificate installer package must be installed when calling this API, otherwise an
3841 * {@link IllegalArgumentException} will be thrown.
Rubin Xuec32b562015-03-03 17:34:05 +00003842 *
Robin Lee25e26452015-06-02 09:56:29 -07003843 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xuec32b562015-03-03 17:34:05 +00003844 * @param installerPackage The package name of the certificate installer which will be given
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003845 * access. If {@code null} is given the current package will be cleared.
3846 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003847 *
3848 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #setDelegatedScopes}
3849 * with the {@link #DELEGATION_CERT_INSTALL} scope instead.
Rubin Xuec32b562015-03-03 17:34:05 +00003850 */
Edman Anjosf9946772016-11-28 16:35:15 +01003851 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07003852 public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String
3853 installerPackage) throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003854 throwIfParentInstance("setCertInstallerPackage");
Rubin Xuec32b562015-03-03 17:34:05 +00003855 if (mService != null) {
3856 try {
Robin Lee25e26452015-06-02 09:56:29 -07003857 mService.setCertInstallerPackage(admin, installerPackage);
Rubin Xuec32b562015-03-03 17:34:05 +00003858 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003859 throw e.rethrowFromSystemServer();
Rubin Xuec32b562015-03-03 17:34:05 +00003860 }
3861 }
3862 }
3863
3864 /**
Edman Anjosf9946772016-11-28 16:35:15 +01003865 * Called by a profile owner or device owner to retrieve the certificate installer for the user,
3866 * or {@code null} if none is set. If there are multiple delegates this function will return one
3867 * of them.
Rubin Xuec32b562015-03-03 17:34:05 +00003868 *
Robin Lee25e26452015-06-02 09:56:29 -07003869 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003870 * @return The package name of the current delegated certificate installer, or {@code null} if
3871 * none is set.
3872 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003873 *
3874 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatePackages}
3875 * with the {@link #DELEGATION_CERT_INSTALL} scope instead.
Rubin Xuec32b562015-03-03 17:34:05 +00003876 */
Edman Anjosf9946772016-11-28 16:35:15 +01003877 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07003878 public @Nullable String getCertInstallerPackage(@NonNull ComponentName admin)
3879 throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003880 throwIfParentInstance("getCertInstallerPackage");
Rubin Xuec32b562015-03-03 17:34:05 +00003881 if (mService != null) {
3882 try {
Robin Lee25e26452015-06-02 09:56:29 -07003883 return mService.getCertInstallerPackage(admin);
Rubin Xuec32b562015-03-03 17:34:05 +00003884 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003885 throw e.rethrowFromSystemServer();
Rubin Xuec32b562015-03-03 17:34:05 +00003886 }
3887 }
3888 return null;
3889 }
3890
3891 /**
Edman Anjosf9946772016-11-28 16:35:15 +01003892 * Called by a profile owner or device owner to grant access to privileged APIs to another app.
3893 * Granted APIs are determined by {@code scopes}, which is a list of the {@code DELEGATION_*}
3894 * constants.
3895 * <p>
Edman Anjos9e62c312017-01-26 22:22:58 +01003896 * A broadcast with the {@link #ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED} action will be
3897 * sent to the {@code delegatePackage} with its new scopes in an {@code ArrayList<String>} extra
3898 * under the {@link #EXTRA_DELEGATION_SCOPES} key. The broadcast is sent with the
3899 * {@link Intent#FLAG_RECEIVER_REGISTERED_ONLY} flag.
3900 * <p>
Edman Anjosf9946772016-11-28 16:35:15 +01003901 * Delegated scopes are a per-user state. The delegated access is persistent until it is later
3902 * cleared by calling this method with an empty {@code scopes} list or uninstalling the
3903 * {@code delegatePackage}.
3904 *
3905 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3906 * @param delegatePackage The package name of the app which will be given access.
3907 * @param scopes The groups of privileged APIs whose access should be granted to
3908 * {@code delegatedPackage}.
3909 * @throws SecurityException if {@code admin} is not a device or a profile owner.
3910 */
3911 public void setDelegatedScopes(@NonNull ComponentName admin, @NonNull String delegatePackage,
3912 @NonNull List<String> scopes) {
3913 throwIfParentInstance("setDelegatedScopes");
3914 if (mService != null) {
3915 try {
3916 mService.setDelegatedScopes(admin, delegatePackage, scopes);
3917 } catch (RemoteException e) {
3918 throw e.rethrowFromSystemServer();
3919 }
3920 }
3921 }
3922
3923 /**
3924 * Called by a profile owner or device owner to retrieve a list of the scopes given to a
3925 * delegate package. Other apps can use this method to retrieve their own delegated scopes by
3926 * passing {@code null} for {@code admin} and their own package name as
3927 * {@code delegatedPackage}.
3928 *
3929 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3930 * {@code null} if the caller is {@code delegatedPackage}.
3931 * @param delegatedPackage The package name of the app whose scopes should be retrieved.
3932 * @return A list containing the scopes given to {@code delegatedPackage}.
3933 * @throws SecurityException if {@code admin} is not a device or a profile owner.
3934 */
3935 @NonNull
Edman Anjos9e62c312017-01-26 22:22:58 +01003936 public List<String> getDelegatedScopes(@Nullable ComponentName admin,
Edman Anjosf9946772016-11-28 16:35:15 +01003937 @NonNull String delegatedPackage) {
3938 throwIfParentInstance("getDelegatedScopes");
3939 if (mService != null) {
3940 try {
3941 return mService.getDelegatedScopes(admin, delegatedPackage);
3942 } catch (RemoteException e) {
3943 throw e.rethrowFromSystemServer();
3944 }
3945 }
3946 return null;
3947 }
3948
3949 /**
3950 * Called by a profile owner or device owner to retrieve a list of delegate packages that were
3951 * granted a delegation scope.
3952 *
3953 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3954 * @param delegationScope The scope whose delegates should be retrieved.
3955 * @return A list of package names of the current delegated packages for
3956 {@code delegationScope}.
3957 * @throws SecurityException if {@code admin} is not a device or a profile owner.
3958 */
3959 @Nullable
3960 public List<String> getDelegatePackages(@NonNull ComponentName admin,
3961 @NonNull String delegationScope) {
3962 throwIfParentInstance("getDelegatePackages");
3963 if (mService != null) {
3964 try {
3965 return mService.getDelegatePackages(admin, delegationScope);
3966 } catch (RemoteException e) {
3967 throw e.rethrowFromSystemServer();
3968 }
3969 }
3970 return null;
3971 }
3972
3973 /**
Robin Lee244ce8e2016-01-05 18:03:46 +00003974 * Called by a device or profile owner to configure an always-on VPN connection through a
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003975 * specific application for the current user. This connection is automatically granted and
3976 * persisted after a reboot.
3977 * <p>
Charles He36738632017-05-15 17:07:18 +01003978 * To support the always-on feature, an app must
3979 * <ul>
3980 * <li>declare a {@link android.net.VpnService} in its manifest, guarded by
3981 * {@link android.Manifest.permission#BIND_VPN_SERVICE};</li>
3982 * <li>target {@link android.os.Build.VERSION_CODES#N API 24} or above; and</li>
3983 * <li><i>not</i> explicitly opt out of the feature through
Charles Hec57a01c2017-08-15 15:30:22 +01003984 * {@link android.net.VpnService#SERVICE_META_DATA_SUPPORTS_ALWAYS_ON}.</li>
Charles He36738632017-05-15 17:07:18 +01003985 * </ul>
3986 * The call will fail if called with the package name of an unsupported VPN app.
Robin Lee244ce8e2016-01-05 18:03:46 +00003987 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003988 * @param vpnPackage The package name for an installed VPN app on the device, or {@code null} to
Robin Leedc679712016-05-03 13:23:03 +01003989 * remove an existing always-on VPN configuration.
3990 * @param lockdownEnabled {@code true} to disallow networking when the VPN is not connected or
3991 * {@code false} otherwise. This carries the risk that any failure of the VPN provider
3992 * could break networking for all apps. This has no effect when clearing.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003993 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Robin Leeee5eb932016-04-05 16:27:15 +01003994 * @throws NameNotFoundException if {@code vpnPackage} is not installed.
3995 * @throws UnsupportedOperationException if {@code vpnPackage} exists but does not support being
3996 * set as always-on, or if always-on VPN is not available.
Robin Lee244ce8e2016-01-05 18:03:46 +00003997 */
Robin Leedc679712016-05-03 13:23:03 +01003998 public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage,
3999 boolean lockdownEnabled)
Robin Leeee5eb932016-04-05 16:27:15 +01004000 throws NameNotFoundException, UnsupportedOperationException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004001 throwIfParentInstance("setAlwaysOnVpnPackage");
Robin Lee244ce8e2016-01-05 18:03:46 +00004002 if (mService != null) {
4003 try {
Robin Leedc679712016-05-03 13:23:03 +01004004 if (!mService.setAlwaysOnVpnPackage(admin, vpnPackage, lockdownEnabled)) {
Robin Leeee5eb932016-04-05 16:27:15 +01004005 throw new NameNotFoundException(vpnPackage);
4006 }
Robin Lee244ce8e2016-01-05 18:03:46 +00004007 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004008 throw e.rethrowFromSystemServer();
Robin Lee244ce8e2016-01-05 18:03:46 +00004009 }
4010 }
Robin Lee244ce8e2016-01-05 18:03:46 +00004011 }
4012
4013 /**
4014 * Called by a device or profile owner to read the name of the package administering an
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004015 * always-on VPN connection for the current user. If there is no such package, or the always-on
4016 * VPN is provided by the system instead of by an application, {@code null} will be returned.
Robin Lee244ce8e2016-01-05 18:03:46 +00004017 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004018 * @return Package name of VPN controller responsible for always-on VPN, or {@code null} if none
4019 * is set.
4020 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Robin Lee244ce8e2016-01-05 18:03:46 +00004021 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004022 public @Nullable String getAlwaysOnVpnPackage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004023 throwIfParentInstance("getAlwaysOnVpnPackage");
Robin Lee244ce8e2016-01-05 18:03:46 +00004024 if (mService != null) {
4025 try {
4026 return mService.getAlwaysOnVpnPackage(admin);
4027 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004028 throw e.rethrowFromSystemServer();
Robin Lee244ce8e2016-01-05 18:03:46 +00004029 }
4030 }
4031 return null;
4032 }
4033
4034 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004035 * Called by an application that is administering the device to disable all cameras on the
4036 * device, for this user. After setting this, no applications running as this user will be able
4037 * to access any cameras on the device.
4038 * <p>
4039 * If the caller is device owner, then the restriction will be applied to all users.
4040 * <p>
4041 * The calling device admin must have requested
4042 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call this method; if it has
4043 * not, a security exception will be thrown.
Ben Komalo2447edd2011-05-09 16:05:33 -07004044 *
4045 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4046 * @param disabled Whether or not the camera should be disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004047 * @throws SecurityException if {@code admin} is not an active administrator or does not use
4048 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA}.
Ben Komalo2447edd2011-05-09 16:05:33 -07004049 */
Robin Lee25e26452015-06-02 09:56:29 -07004050 public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004051 throwIfParentInstance("setCameraDisabled");
Ben Komalo2447edd2011-05-09 16:05:33 -07004052 if (mService != null) {
4053 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08004054 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07004055 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004056 throw e.rethrowFromSystemServer();
Ben Komalo2447edd2011-05-09 16:05:33 -07004057 }
4058 }
4059 }
4060
4061 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07004062 * Determine whether or not the device's cameras have been disabled for this user,
Makoto Onuki32b30572015-12-11 14:29:51 -08004063 * either by the calling admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07004064 * @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 -07004065 * have disabled the camera
4066 */
Robin Lee25e26452015-06-02 09:56:29 -07004067 public boolean getCameraDisabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004068 throwIfParentInstance("getCameraDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004069 return getCameraDisabled(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004070 }
4071
4072 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07004073 public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07004074 if (mService != null) {
4075 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004076 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07004077 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004078 throw e.rethrowFromSystemServer();
Ben Komalo2447edd2011-05-09 16:05:33 -07004079 }
4080 }
4081 return false;
4082 }
4083
4084 /**
Michal Karpinski3fc437e2015-12-15 10:09:00 +00004085 * Called by a device owner to request a bugreport.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004086 * <p>
Esteban Talaverad36dd152016-12-15 08:51:45 +00004087 * If the device contains secondary users or profiles, they must be affiliated with the device
4088 * owner user. Otherwise a {@link SecurityException} will be thrown. See
4089 * {@link #setAffiliationIds}.
Michal Karpinski3fc437e2015-12-15 10:09:00 +00004090 *
4091 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004092 * @return {@code true} if the bugreport collection started successfully, or {@code false} if it
4093 * wasn't triggered because a previous bugreport operation is still active (either the
4094 * bugreport is still running or waiting for the user to share or decline)
Esteban Talaverad36dd152016-12-15 08:51:45 +00004095 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
4096 * profile or secondary user that is not affiliated with the device owner user.
Michal Karpinski3fc437e2015-12-15 10:09:00 +00004097 */
4098 public boolean requestBugreport(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004099 throwIfParentInstance("requestBugreport");
Michal Karpinski3fc437e2015-12-15 10:09:00 +00004100 if (mService != null) {
4101 try {
4102 return mService.requestBugreport(admin);
4103 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004104 throw e.rethrowFromSystemServer();
Michal Karpinski3fc437e2015-12-15 10:09:00 +00004105 }
4106 }
4107 return false;
4108 }
4109
4110 /**
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07004111 * Determine whether or not creating a guest user has been disabled for the device
4112 *
4113 * @hide
4114 */
4115 public boolean getGuestUserDisabled(@Nullable ComponentName admin) {
4116 // Currently guest users can always be created if multi-user is enabled
4117 // TODO introduce a policy for guest user creation
4118 return false;
4119 }
4120
4121 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01004122 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
4123 * screen capture also prevents the content from being shown on display devices that do not have
4124 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
4125 * secure surfaces and secure displays.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004126 * <p>
4127 * The calling device admin must be a device or profile owner. If it is not, a security
4128 * exception will be thrown.
4129 * <p>
4130 * From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also blocks
4131 * assist requests for all activities of the relevant user.
Benjamin Franzc200f442015-06-25 18:20:04 +01004132 *
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004133 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004134 * @param disabled Whether screen capture is disabled or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004135 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004136 */
Robin Lee25e26452015-06-02 09:56:29 -07004137 public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004138 throwIfParentInstance("setScreenCaptureDisabled");
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004139 if (mService != null) {
4140 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08004141 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004142 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004143 throw e.rethrowFromSystemServer();
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004144 }
4145 }
4146 }
4147
4148 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004149 * Determine whether or not screen capture has been disabled by the calling
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004150 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07004151 * @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 +01004152 * have disabled screen capture.
4153 */
Robin Lee25e26452015-06-02 09:56:29 -07004154 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004155 throwIfParentInstance("getScreenCaptureDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004156 return getScreenCaptureDisabled(admin, myUserId());
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004157 }
4158
4159 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07004160 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004161 if (mService != null) {
4162 try {
4163 return mService.getScreenCaptureDisabled(admin, userHandle);
4164 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004165 throw e.rethrowFromSystemServer();
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004166 }
4167 }
4168 return false;
4169 }
4170
4171 /**
Jason Parks841cb0a2017-01-17 15:25:17 -06004172 * Called by a device or profile owner to set whether auto time is required. If auto time is
4173 * 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 -07004174 * <p>
4175 * Note: if auto time is required the user can still manually set the time zone.
4176 * <p>
Jason Parks841cb0a2017-01-17 15:25:17 -06004177 * The calling device admin must be a device or profile owner. If it is not, a security
4178 * exception will be thrown.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004179 *
4180 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4181 * @param required Whether auto time is set required or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004182 * @throws SecurityException if {@code admin} is not a device owner.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004183 */
Robin Lee25e26452015-06-02 09:56:29 -07004184 public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004185 throwIfParentInstance("setAutoTimeRequired");
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004186 if (mService != null) {
4187 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08004188 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004189 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004190 throw e.rethrowFromSystemServer();
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004191 }
4192 }
4193 }
4194
4195 /**
4196 * @return true if auto time is required.
4197 */
4198 public boolean getAutoTimeRequired() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004199 throwIfParentInstance("getAutoTimeRequired");
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004200 if (mService != null) {
4201 try {
4202 return mService.getAutoTimeRequired();
4203 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004204 throw e.rethrowFromSystemServer();
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004205 }
4206 }
4207 return false;
4208 }
4209
4210 /**
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004211 * Called by a device owner to set whether all users created on the device should be ephemeral.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004212 * <p>
4213 * The system user is exempt from this policy - it is never ephemeral.
4214 * <p>
4215 * The calling device admin must be the device owner. If it is not, a security exception will be
4216 * thrown.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004217 *
4218 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4219 * @param forceEphemeralUsers If true, all the existing users will be deleted and all
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004220 * subsequently created users will be ephemeral.
4221 * @throws SecurityException if {@code admin} is not a device owner.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004222 * @hide
4223 */
4224 public void setForceEphemeralUsers(
4225 @NonNull ComponentName admin, boolean forceEphemeralUsers) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004226 throwIfParentInstance("setForceEphemeralUsers");
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004227 if (mService != null) {
4228 try {
4229 mService.setForceEphemeralUsers(admin, forceEphemeralUsers);
4230 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004231 throw e.rethrowFromSystemServer();
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004232 }
4233 }
4234 }
4235
4236 /**
4237 * @return true if all users are created ephemeral.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004238 * @throws SecurityException if {@code admin} is not a device owner.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004239 * @hide
4240 */
4241 public boolean getForceEphemeralUsers(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004242 throwIfParentInstance("getForceEphemeralUsers");
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004243 if (mService != null) {
4244 try {
4245 return mService.getForceEphemeralUsers(admin);
4246 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004247 throw e.rethrowFromSystemServer();
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004248 }
4249 }
4250 return false;
4251 }
4252
4253 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07004254 * Called by an application that is administering the device to disable keyguard customizations,
4255 * such as widgets. After setting this, keyguard features will be disabled according to the
4256 * provided feature list.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004257 * <p>
4258 * The calling device admin must have requested
4259 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method;
4260 * if it has not, a security exception will be thrown.
4261 * <p>
4262 * Calling this from a managed profile before version {@link android.os.Build.VERSION_CODES#M}
4263 * will throw a security exception. From version {@link android.os.Build.VERSION_CODES#M} the
4264 * profile owner of a managed profile can set:
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00004265 * <ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00004266 * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which affects the parent user, but only if there
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004267 * is no separate challenge set on the managed profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00004268 * <li>{@link #KEYGUARD_DISABLE_FINGERPRINT} which affects the managed profile challenge if
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004269 * there is one, or the parent user otherwise.
4270 * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} which affects notifications generated
4271 * by applications in the managed profile.
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00004272 * </ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00004273 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} and {@link #KEYGUARD_DISABLE_FINGERPRINT} can also be
4274 * set on the {@link DevicePolicyManager} instance returned by
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004275 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
4276 * profile.
4277 * <p>
4278 * Requests to disable other features on a managed profile will be ignored.
4279 * <p>
4280 * The admin can check which features have been disabled by calling
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00004281 * {@link #getKeyguardDisabledFeatures(ComponentName)}
Amith Yamasani242f4b12014-10-14 16:06:13 -07004282 *
Jim Millerb8ec4702012-08-31 17:19:10 -07004283 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07004284 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004285 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
4286 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS},
4287 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
4288 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS},
4289 * {@link #KEYGUARD_DISABLE_FINGERPRINT}, {@link #KEYGUARD_DISABLE_FEATURES_ALL}
4290 * @throws SecurityException if {@code admin} is not an active administrator or does not user
4291 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES}
Jim Millerb8ec4702012-08-31 17:19:10 -07004292 */
Robin Lee25e26452015-06-02 09:56:29 -07004293 public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07004294 if (mService != null) {
4295 try {
Esteban Talavera62399912016-01-11 15:37:55 +00004296 mService.setKeyguardDisabledFeatures(admin, which, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07004297 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004298 throw e.rethrowFromSystemServer();
Jim Millerb8ec4702012-08-31 17:19:10 -07004299 }
4300 }
4301 }
4302
4303 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004304 * Determine whether or not features have been disabled in keyguard either by the calling
Rubin Xud3609d42016-07-13 18:32:57 +01004305 * admin, if specified, or all admins that set restrictions on this user and its participating
Esteban Talaverac1c83592016-02-17 17:56:15 +00004306 * profiles. Restrictions on profiles that have a separate challenge are not taken into account.
4307 *
4308 * <p>This method can be called on the {@link DevicePolicyManager} instance
4309 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
4310 * restrictions on the parent profile.
4311 *
Esteban Talavera62399912016-01-11 15:37:55 +00004312 * @param admin The name of the admin component to check, or {@code null} to check whether any
4313 * admins have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07004314 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
4315 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07004316 */
Robin Lee25e26452015-06-02 09:56:29 -07004317 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004318 return getKeyguardDisabledFeatures(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004319 }
4320
4321 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07004322 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07004323 if (mService != null) {
4324 try {
Esteban Talavera62399912016-01-11 15:37:55 +00004325 return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07004326 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004327 throw e.rethrowFromSystemServer();
Jim Millerb8ec4702012-08-31 17:19:10 -07004328 }
4329 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07004330 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07004331 }
4332
4333 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08004334 * @hide
4335 */
Robin Lee25e26452015-06-02 09:56:29 -07004336 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
4337 int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08004338 if (mService != null) {
4339 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01004340 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08004341 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004342 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08004343 }
4344 }
4345 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07004346
Dianne Hackbornd6847842010-01-12 18:14:19 -08004347 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01004348 * @hide
4349 */
Robin Lee25e26452015-06-02 09:56:29 -07004350 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004351 setActiveAdmin(policyReceiver, refreshing, myUserId());
Jessica Hummel6d36b602014-04-04 12:42:17 +01004352 }
4353
4354 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08004355 * @hide
4356 */
Robin Lee25e26452015-06-02 09:56:29 -07004357 public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08004358 if (mService != null) {
4359 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004360 mService.getRemoveWarning(admin, result, myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08004361 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004362 throw e.rethrowFromSystemServer();
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08004363 }
4364 }
4365 }
4366
4367 /**
4368 * @hide
4369 */
Andrew Scull5f9e6f32016-08-02 14:22:17 +01004370 public void setActivePasswordState(PasswordMetrics metrics, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08004371 if (mService != null) {
4372 try {
Andrew Scull5f9e6f32016-08-02 14:22:17 +01004373 mService.setActivePasswordState(metrics, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08004374 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004375 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08004376 }
4377 }
4378 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07004379
Dianne Hackbornd6847842010-01-12 18:14:19 -08004380 /**
4381 * @hide
4382 */
Andrew Scull5daf2732016-11-14 15:02:45 +00004383 public void reportPasswordChanged(@UserIdInt int userId) {
4384 if (mService != null) {
4385 try {
4386 mService.reportPasswordChanged(userId);
4387 } catch (RemoteException e) {
4388 throw e.rethrowFromSystemServer();
4389 }
4390 }
4391 }
4392
4393 /**
4394 * @hide
4395 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004396 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08004397 if (mService != null) {
4398 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004399 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08004400 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004401 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08004402 }
4403 }
4404 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07004405
Dianne Hackbornd6847842010-01-12 18:14:19 -08004406 /**
4407 * @hide
4408 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004409 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08004410 if (mService != null) {
4411 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004412 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08004413 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004414 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08004415 }
4416 }
4417 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07004418
4419 /**
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004420 * @hide
4421 */
4422 public void reportFailedFingerprintAttempt(int userHandle) {
4423 if (mService != null) {
4424 try {
4425 mService.reportFailedFingerprintAttempt(userHandle);
4426 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004427 throw e.rethrowFromSystemServer();
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004428 }
4429 }
4430 }
4431
4432 /**
4433 * @hide
4434 */
4435 public void reportSuccessfulFingerprintAttempt(int userHandle) {
4436 if (mService != null) {
4437 try {
4438 mService.reportSuccessfulFingerprintAttempt(userHandle);
4439 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004440 throw e.rethrowFromSystemServer();
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004441 }
4442 }
4443 }
4444
4445 /**
Michal Karpinski31502d32016-01-25 16:43:07 +00004446 * Should be called when keyguard has been dismissed.
4447 * @hide
4448 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004449 public void reportKeyguardDismissed(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00004450 if (mService != null) {
4451 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004452 mService.reportKeyguardDismissed(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00004453 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004454 throw e.rethrowFromSystemServer();
Michal Karpinski31502d32016-01-25 16:43:07 +00004455 }
4456 }
4457 }
4458
4459 /**
4460 * Should be called when keyguard view has been shown to the user.
4461 * @hide
4462 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004463 public void reportKeyguardSecured(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00004464 if (mService != null) {
4465 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004466 mService.reportKeyguardSecured(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00004467 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004468 throw e.rethrowFromSystemServer();
Michal Karpinski31502d32016-01-25 16:43:07 +00004469 }
4470 }
4471 }
4472
4473 /**
Amith Yamasani71e6c692013-03-24 17:39:28 -07004474 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00004475 * Sets the given package as the device owner.
Makoto Onukia52562c2015-10-01 16:12:31 -07004476 * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name.
4477 * @param who the component name to be registered as device owner.
Amith Yamasani71e6c692013-03-24 17:39:28 -07004478 * @return whether the package was successfully registered as the device owner.
4479 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00004480 * @throws IllegalStateException If the preconditions mentioned are not met.
Amith Yamasani71e6c692013-03-24 17:39:28 -07004481 */
Makoto Onukia52562c2015-10-01 16:12:31 -07004482 public boolean setDeviceOwner(ComponentName who) {
4483 return setDeviceOwner(who, null);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004484 }
4485
4486 /**
4487 * @hide
Makoto Onuki58b684f2015-09-04 10:48:16 -07004488 */
Makoto Onukia52562c2015-10-01 16:12:31 -07004489 public boolean setDeviceOwner(ComponentName who, int userId) {
4490 return setDeviceOwner(who, null, userId);
Makoto Onuki58b684f2015-09-04 10:48:16 -07004491 }
4492
4493 /**
4494 * @hide
4495 */
Makoto Onukia52562c2015-10-01 16:12:31 -07004496 public boolean setDeviceOwner(ComponentName who, String ownerName) {
4497 return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM);
Makoto Onuki58b684f2015-09-04 10:48:16 -07004498 }
4499
4500 /**
4501 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00004502 * Sets the given package as the device owner. The package must already be installed. There
4503 * must not already be a device owner.
4504 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
4505 * this method.
4506 * Calling this after the setup phase of the primary user has completed is allowed only if
4507 * the caller is the shell uid, and there are no additional users and no accounts.
Makoto Onukia52562c2015-10-01 16:12:31 -07004508 * @param who the component name to be registered as device owner.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004509 * @param ownerName the human readable name of the institution that owns this device.
Makoto Onuki58b684f2015-09-04 10:48:16 -07004510 * @param userId ID of the user on which the device owner runs.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004511 * @return whether the package was successfully registered as the device owner.
4512 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00004513 * @throws IllegalStateException If the preconditions mentioned are not met.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004514 */
Makoto Onukia52562c2015-10-01 16:12:31 -07004515 public boolean setDeviceOwner(ComponentName who, String ownerName, int userId)
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004516 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07004517 if (mService != null) {
4518 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07004519 return mService.setDeviceOwner(who, ownerName, userId);
Amith Yamasani71e6c692013-03-24 17:39:28 -07004520 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004521 throw re.rethrowFromSystemServer();
Amith Yamasani71e6c692013-03-24 17:39:28 -07004522 }
4523 }
4524 return false;
4525 }
4526
4527 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004528 * Used to determine if a particular package has been registered as a Device Owner app.
4529 * A device owner app is a special device admin that cannot be deactivated by the user, once
Robin Lee25e26452015-06-02 09:56:29 -07004530 * activated as a device admin. It also cannot be uninstalled. To check whether a particular
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004531 * package is currently registered as the device owner app, pass in the package name from
4532 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
Robin Lee25e26452015-06-02 09:56:29 -07004533 * admin apps that want to check whether they are also registered as the device owner app. The
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004534 * exact mechanism by which a device admin app is registered as a device owner app is defined by
4535 * the setup process.
4536 * @param packageName the package name of the app, to compare with the registered device owner
4537 * app, if any.
Makoto Onukic8a5a552015-11-19 14:29:12 -08004538 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07004539 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004540 public boolean isDeviceOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004541 throwIfParentInstance("isDeviceOwnerApp");
Makoto Onukic8a5a552015-11-19 14:29:12 -08004542 return isDeviceOwnerAppOnCallingUser(packageName);
4543 }
4544
4545 /**
4546 * @return true if a package is registered as device owner, only when it's running on the
4547 * calling user.
4548 *
4549 * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity.
4550 * @hide
4551 */
4552 public boolean isDeviceOwnerAppOnCallingUser(String packageName) {
4553 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true);
4554 }
4555
4556 /**
4557 * @return true if a package is registered as device owner, even if it's running on a different
4558 * user.
4559 *
4560 * <p>Requires the MANAGE_USERS permission.
4561 *
4562 * @hide
4563 */
4564 public boolean isDeviceOwnerAppOnAnyUser(String packageName) {
4565 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false);
4566 }
4567
4568 /**
4569 * @return device owner component name, only when it's running on the calling user.
4570 *
4571 * @hide
4572 */
4573 public ComponentName getDeviceOwnerComponentOnCallingUser() {
4574 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true);
4575 }
4576
4577 /**
4578 * @return device owner component name, even if it's running on a different user.
4579 *
Makoto Onukic8a5a552015-11-19 14:29:12 -08004580 * @hide
4581 */
Polina Bondarenko23561db2016-12-16 11:47:28 +01004582 @SystemApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06004583 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Makoto Onukic8a5a552015-11-19 14:29:12 -08004584 public ComponentName getDeviceOwnerComponentOnAnyUser() {
4585 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false);
4586 }
4587
4588 private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) {
Makoto Onuki70f929e2015-11-11 12:40:15 -08004589 if (packageName == null) {
4590 return false;
Amith Yamasani71e6c692013-03-24 17:39:28 -07004591 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08004592 final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly);
Makoto Onuki70f929e2015-11-11 12:40:15 -08004593 if (deviceOwner == null) {
4594 return false;
4595 }
4596 return packageName.equals(deviceOwner.getPackageName());
Amith Yamasani71e6c692013-03-24 17:39:28 -07004597 }
4598
Makoto Onukic8a5a552015-11-19 14:29:12 -08004599 private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) {
4600 if (mService != null) {
4601 try {
4602 return mService.getDeviceOwnerComponent(callingUserOnly);
4603 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004604 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08004605 }
4606 }
4607 return null;
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004608 }
4609
Jason Monkb0dced82014-06-06 14:36:20 -04004610 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08004611 * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's
4612 * no device owner.
4613 *
4614 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07004615 *
4616 * @hide
4617 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08004618 public int getDeviceOwnerUserId() {
4619 if (mService != null) {
4620 try {
4621 return mService.getDeviceOwnerUserId();
4622 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004623 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08004624 }
4625 }
4626 return UserHandle.USER_NULL;
Makoto Onukia52562c2015-10-01 16:12:31 -07004627 }
4628
4629 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004630 * Clears the current device owner. The caller must be the device owner. This function should be
4631 * 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 +00004632 * a part of device setup, before it completes.
4633 * <p>
4634 * While some policies previously set by the device owner will be cleared by this method, it is
4635 * a best-effort process and some other policies will still remain in place after the device
4636 * owner is cleared.
Jason Monk94d2cf92014-06-18 09:53:34 -04004637 *
4638 * @param packageName The package name of the device owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004639 * @throws SecurityException if the caller is not in {@code packageName} or {@code packageName}
4640 * does not own the current device owner component.
Esteban Talaveraa5b09632017-02-10 16:15:24 +00004641 *
4642 * @deprecated This method is expected to be used for testing purposes only. The device owner
4643 * will lose control of the device and its data after calling it. In order to protect any
4644 * sensitive data that remains on the device, it is advised that the device owner factory resets
4645 * the device instead of calling this method. See {@link #wipeData(int)}.
Jason Monkb0dced82014-06-06 14:36:20 -04004646 */
Esteban Talaveraa5b09632017-02-10 16:15:24 +00004647 @Deprecated
Jason Monk94d2cf92014-06-18 09:53:34 -04004648 public void clearDeviceOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004649 throwIfParentInstance("clearDeviceOwnerApp");
Jason Monkb0dced82014-06-06 14:36:20 -04004650 if (mService != null) {
4651 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04004652 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04004653 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004654 throw re.rethrowFromSystemServer();
Jason Monkb0dced82014-06-06 14:36:20 -04004655 }
4656 }
4657 }
4658
Makoto Onukia52562c2015-10-01 16:12:31 -07004659 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08004660 * Returns the device owner package name, only if it's running on the calling user.
4661 *
4662 * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity.
Makoto Onukia52562c2015-10-01 16:12:31 -07004663 *
4664 * @hide
4665 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01004666 @SystemApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06004667 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Makoto Onuki408e8e42016-10-25 12:10:27 -07004668 public @Nullable String getDeviceOwner() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004669 throwIfParentInstance("getDeviceOwner");
Makoto Onukic8a5a552015-11-19 14:29:12 -08004670 final ComponentName name = getDeviceOwnerComponentOnCallingUser();
4671 return name != null ? name.getPackageName() : null;
Makoto Onukia52562c2015-10-01 16:12:31 -07004672 }
4673
4674 /**
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004675 * Called by the system to find out whether the device is managed by a Device Owner.
Makoto Onukic8a5a552015-11-19 14:29:12 -08004676 *
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004677 * @return whether the device is managed by a Device Owner.
4678 * @throws SecurityException if the caller is not the device owner, does not hold the
4679 * MANAGE_USERS permission and is not the system.
Makoto Onukia52562c2015-10-01 16:12:31 -07004680 *
4681 * @hide
4682 */
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004683 @SystemApi
4684 @TestApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06004685 @SuppressLint("Doclava125")
Makoto Onukic8a5a552015-11-19 14:29:12 -08004686 public boolean isDeviceManaged() {
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004687 try {
4688 return mService.hasDeviceOwner();
4689 } catch (RemoteException re) {
4690 throw re.rethrowFromSystemServer();
4691 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08004692 }
4693
4694 /**
4695 * Returns the device owner name. Note this method *will* return the device owner
4696 * name when it's running on a different user.
4697 *
Makoto Onukic8a5a552015-11-19 14:29:12 -08004698 * @hide
4699 */
Makoto Onukia2b274b2016-01-19 13:26:02 -08004700 @SystemApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06004701 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Makoto Onukic8a5a552015-11-19 14:29:12 -08004702 public String getDeviceOwnerNameOnAnyUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004703 throwIfParentInstance("getDeviceOwnerNameOnAnyUser");
Amith Yamasani71e6c692013-03-24 17:39:28 -07004704 if (mService != null) {
4705 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07004706 return mService.getDeviceOwnerName();
Amith Yamasani71e6c692013-03-24 17:39:28 -07004707 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004708 throw re.rethrowFromSystemServer();
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004709 }
4710 }
4711 return null;
4712 }
Adam Connors776c5552014-01-09 10:42:56 +00004713
4714 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04004715 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004716 * @deprecated Do not use
4717 * @removed
Julia Reynolds20118f12015-02-11 12:34:08 -05004718 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004719 @Deprecated
Julia Reynolds20118f12015-02-11 12:34:08 -05004720 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06004721 @SuppressLint("Doclava125")
Makoto Onuki408e8e42016-10-25 12:10:27 -07004722 public @Nullable String getDeviceInitializerApp() {
Julia Reynolds20118f12015-02-11 12:34:08 -05004723 return null;
4724 }
4725
4726 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004727 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004728 * @deprecated Do not use
4729 * @removed
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004730 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004731 @Deprecated
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004732 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06004733 @SuppressLint("Doclava125")
Makoto Onuki408e8e42016-10-25 12:10:27 -07004734 public @Nullable ComponentName getDeviceInitializerComponent() {
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004735 return null;
4736 }
4737
Julia Reynolds20118f12015-02-11 12:34:08 -05004738 /**
Adam Connors776c5552014-01-09 10:42:56 +00004739 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004740 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304741 * Sets the given component as an active admin and registers the package as the profile
4742 * owner for this user. The package must already be installed and there shouldn't be
4743 * an existing profile owner registered for this user. Also, this method must be called
4744 * before the user setup has been completed.
4745 * <p>
4746 * This method can only be called by system apps that hold MANAGE_USERS permission and
4747 * MANAGE_DEVICE_ADMINS permission.
4748 * @param admin The component to register as an active admin and profile owner.
4749 * @param ownerName The user-visible name of the entity that is managing this user.
4750 * @return whether the admin was successfully registered as the profile owner.
4751 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
4752 * the user has already been set up.
4753 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07004754 @Deprecated
Justin Morey80440cc2014-07-24 09:16:35 -05004755 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06004756 @RequiresPermission(android.Manifest.permission.MANAGE_DEVICE_ADMINS)
Robin Lee25e26452015-06-02 09:56:29 -07004757 public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304758 throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004759 throwIfParentInstance("setActiveProfileOwner");
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304760 if (mService != null) {
4761 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004762 final int myUserId = myUserId();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304763 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004764 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304765 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004766 throw re.rethrowFromSystemServer();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304767 }
4768 }
4769 return false;
4770 }
4771
4772 /**
Esteban Talaveraa5b09632017-02-10 16:15:24 +00004773 * Clears the active profile owner. The caller must be the profile owner of this user, otherwise
4774 * a SecurityException will be thrown. This method is not available to managed profile owners.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004775 * <p>
Esteban Talaveraa5b09632017-02-10 16:15:24 +00004776 * While some policies previously set by the profile owner will be cleared by this method, it is
4777 * a best-effort process and some other policies will still remain in place after the profile
4778 * owner is cleared.
Makoto Onuki5bf68022016-01-27 13:49:19 -08004779 *
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004780 * @param admin The component to remove as the profile owner.
Esteban Talaveraa5b09632017-02-10 16:15:24 +00004781 * @throws SecurityException if {@code admin} is not an active profile owner, or the method is
4782 * being called from a managed profile.
4783 *
4784 * @deprecated This method is expected to be used for testing purposes only. The profile owner
4785 * will lose control of the user and its data after calling it. In order to protect any
4786 * sensitive data that remains on this user, it is advised that the profile owner deletes it
4787 * instead of calling this method. See {@link #wipeData(int)}.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004788 */
Esteban Talaveraa5b09632017-02-10 16:15:24 +00004789 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07004790 public void clearProfileOwner(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004791 throwIfParentInstance("clearProfileOwner");
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004792 if (mService != null) {
4793 try {
4794 mService.clearProfileOwner(admin);
4795 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004796 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004797 }
4798 }
4799 }
4800
4801 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05004802 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07004803 * Checks whether the user was already setup.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004804 */
4805 public boolean hasUserSetupCompleted() {
4806 if (mService != null) {
4807 try {
4808 return mService.hasUserSetupCompleted();
4809 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004810 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004811 }
4812 }
4813 return true;
4814 }
4815
4816 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004817 * @hide
4818 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00004819 * already be installed. There must not already be a profile owner for this user.
4820 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
4821 * this method.
4822 * Calling this after the setup phase of the specified user has completed is allowed only if:
4823 * - the caller is SYSTEM_UID.
4824 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004825 * @param admin the component name to be registered as profile owner.
4826 * @param ownerName the human readable name of the organisation associated with this DPM.
4827 * @param userHandle the userId to set the profile owner for.
4828 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00004829 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
4830 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004831 */
Robin Lee25e26452015-06-02 09:56:29 -07004832 public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName,
Robin Leeddd553f2015-04-30 14:18:22 +01004833 int userHandle) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00004834 if (mService != null) {
4835 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004836 if (ownerName == null) {
4837 ownerName = "";
4838 }
4839 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00004840 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004841 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004842 }
4843 }
4844 return false;
4845 }
4846
4847 /**
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004848 * Sets the device owner information to be shown on the lock screen.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004849 * <p>
4850 * If the device owner information is {@code null} or empty then the device owner info is
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004851 * cleared and the user owner info is shown on the lock screen if it is set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004852 * <p>
4853 * If the device owner information contains only whitespaces then the message on the lock screen
4854 * will be blank and the user will not be allowed to change it.
4855 * <p>
4856 * If the device owner information needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00004857 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
4858 * and set a new version of this string accordingly.
4859 *
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004860 * @param admin The name of the admin component to check.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004861 * @param info Device owner information which will be displayed instead of the user owner info.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004862 * @throws SecurityException if {@code admin} is not a device owner.
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004863 */
Andrei Stingaceanu16187902016-03-21 15:44:45 +00004864 public void setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, CharSequence info) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004865 throwIfParentInstance("setDeviceOwnerLockScreenInfo");
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004866 if (mService != null) {
4867 try {
Andrei Stingaceanu16187902016-03-21 15:44:45 +00004868 mService.setDeviceOwnerLockScreenInfo(admin, info);
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004869 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004870 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004871 }
4872 }
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004873 }
4874
4875 /**
4876 * @return The device owner information. If it is not set returns {@code null}.
4877 */
Andrei Stingaceanu16187902016-03-21 15:44:45 +00004878 public CharSequence getDeviceOwnerLockScreenInfo() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004879 throwIfParentInstance("getDeviceOwnerLockScreenInfo");
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004880 if (mService != null) {
4881 try {
4882 return mService.getDeviceOwnerLockScreenInfo();
4883 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004884 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004885 }
4886 }
4887 return null;
4888 }
4889
4890 /**
Edman Anjos52088e42017-01-13 22:26:17 +01004891 * Called by device or profile owners to suspend packages for this user. This function can be
4892 * called by a device owner, profile owner, or by a delegate given the
4893 * {@link #DELEGATION_PACKAGE_ACCESS} scope via {@link #setDelegatedScopes}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004894 * <p>
4895 * A suspended package will not be able to start activities. Its notifications will be hidden,
4896 * it will not show up in recents, will not be able to show toasts or dialogs or ring the
4897 * device.
4898 * <p>
4899 * The package must already be installed. If the package is uninstalled while suspended the
4900 * package will no longer be suspended. The admin can block this by using
Kenny Guy871f3eb2016-03-09 20:06:16 +00004901 * {@link #setUninstallBlocked}.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004902 *
Edman Anjos52088e42017-01-13 22:26:17 +01004903 * @param admin The name of the admin component to check, or {@code null} if the caller is a
4904 * package access delegate.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004905 * @param packageNames The package names to suspend or unsuspend.
4906 * @param suspended If set to {@code true} than the packages will be suspended, if set to
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004907 * {@code false} the packages will be unsuspended.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004908 * @return an array of package names for which the suspended status is not set as requested in
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004909 * this method.
4910 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01004911 * @see #setDelegatedScopes
4912 * @see #DELEGATION_PACKAGE_ACCESS
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004913 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004914 public @NonNull String[] setPackagesSuspended(@NonNull ComponentName admin,
4915 @NonNull String[] packageNames, boolean suspended) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004916 throwIfParentInstance("setPackagesSuspended");
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004917 if (mService != null) {
4918 try {
Edman Anjos52088e42017-01-13 22:26:17 +01004919 return mService.setPackagesSuspended(admin, mContext.getPackageName(), packageNames,
4920 suspended);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004921 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004922 throw re.rethrowFromSystemServer();
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004923 }
4924 }
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004925 return packageNames;
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004926 }
4927
4928 /**
Edman Anjos52088e42017-01-13 22:26:17 +01004929 * Determine if a package is suspended. This function can be called by a device owner, profile
4930 * owner, or by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via
4931 * {@link #setDelegatedScopes}.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004932 *
Edman Anjos52088e42017-01-13 22:26:17 +01004933 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
4934 * {@code null} if the caller is a package access delegate.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004935 * @param packageName The name of the package to retrieve the suspended status of.
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00004936 * @return {@code true} if the package is suspended or {@code false} if the package is not
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004937 * suspended, could not be found or an error occurred.
4938 * @throws SecurityException if {@code admin} is not a device or profile owner.
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004939 * @throws NameNotFoundException if the package could not be found.
Edman Anjos52088e42017-01-13 22:26:17 +01004940 * @see #setDelegatedScopes
4941 * @see #DELEGATION_PACKAGE_ACCESS
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004942 */
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004943 public boolean isPackageSuspended(@NonNull ComponentName admin, String packageName)
4944 throws NameNotFoundException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004945 throwIfParentInstance("isPackageSuspended");
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004946 if (mService != null) {
4947 try {
Edman Anjos52088e42017-01-13 22:26:17 +01004948 return mService.isPackageSuspended(admin, mContext.getPackageName(), packageName);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004949 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004950 throw e.rethrowFromSystemServer();
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004951 } catch (IllegalArgumentException ex) {
4952 throw new NameNotFoundException(packageName);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004953 }
4954 }
4955 return false;
4956 }
4957
4958 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004959 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
4960 * be used. Only the profile owner can call this.
4961 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01004962 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004963 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004964 * @throws SecurityException if {@code admin} is not a profile owner.
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004965 */
Robin Lee25e26452015-06-02 09:56:29 -07004966 public void setProfileEnabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004967 throwIfParentInstance("setProfileEnabled");
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004968 if (mService != null) {
4969 try {
4970 mService.setProfileEnabled(admin);
4971 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004972 throw e.rethrowFromSystemServer();
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004973 }
4974 }
4975 }
4976
4977 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004978 * Sets the name of the profile. In the device owner case it sets the name of the user which it
4979 * is called from. Only a profile owner or device owner can call this. If this is never called
4980 * by the profile or device owner, the name will be set to default values.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004981 *
4982 * @see #isProfileOwnerApp
4983 * @see #isDeviceOwnerApp
Robin Lee25e26452015-06-02 09:56:29 -07004984 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004985 * @param profileName The name of the profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004986 * @throws SecurityException if {@code admin} is not a device or profile owner.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004987 */
Robin Lee25e26452015-06-02 09:56:29 -07004988 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004989 throwIfParentInstance("setProfileName");
Jessica Hummel1333ea12014-06-23 11:20:10 +01004990 if (mService != null) {
4991 try {
Robin Lee25e26452015-06-02 09:56:29 -07004992 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07004993 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004994 throw e.rethrowFromSystemServer();
Fyodor Kupolov78f13142015-05-27 16:52:45 -07004995 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01004996 }
4997 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01004998
4999 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005000 * Used to determine if a particular package is registered as the profile owner for the
Makoto Onuki32b30572015-12-11 14:29:51 -08005001 * user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005002 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00005003 *
5004 * @param packageName The package name of the app to compare with the registered profile owner.
5005 * @return Whether or not the package is registered as the profile owner.
5006 */
5007 public boolean isProfileOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005008 throwIfParentInstance("isProfileOwnerApp");
Adam Connors776c5552014-01-09 10:42:56 +00005009 if (mService != null) {
5010 try {
Makoto Onuki90b89652016-01-28 14:44:18 -08005011 ComponentName profileOwner = mService.getProfileOwner(myUserId());
Nicolas Prevot90af6d72014-07-30 14:19:12 +01005012 return profileOwner != null
5013 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00005014 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005015 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00005016 }
5017 }
5018 return false;
5019 }
5020
5021 /**
5022 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07005023 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00005024 * owner has been set for that user.
5025 * @throws IllegalArgumentException if the userId is invalid.
5026 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01005027 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07005028 public @Nullable ComponentName getProfileOwner() throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005029 throwIfParentInstance("getProfileOwner");
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01005030 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
5031 }
5032
5033 /**
5034 * @see #getProfileOwner()
5035 * @hide
5036 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005037 public @Nullable ComponentName getProfileOwnerAsUser(final int userId)
5038 throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00005039 if (mService != null) {
5040 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01005041 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00005042 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005043 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00005044 }
5045 }
5046 return null;
5047 }
5048
5049 /**
5050 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07005051 * @return the human readable name of the organisation associated with this DPM or {@code null}
5052 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00005053 * @throws IllegalArgumentException if the userId is invalid.
5054 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005055 public @Nullable String getProfileOwnerName() throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00005056 if (mService != null) {
5057 try {
5058 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
5059 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005060 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00005061 }
5062 }
5063 return null;
5064 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005065
5066 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07005067 * @hide
Makoto Onukic8a5a552015-11-19 14:29:12 -08005068 * @param userId The user for whom to fetch the profile owner name, if any.
Amith Yamasani38f836b2014-08-20 14:51:15 -07005069 * @return the human readable name of the organisation associated with this profile owner or
5070 * null if one is not set.
5071 * @throws IllegalArgumentException if the userId is invalid.
5072 */
5073 @SystemApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06005074 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Makoto Onuki408e8e42016-10-25 12:10:27 -07005075 public @Nullable String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005076 throwIfParentInstance("getProfileOwnerNameAsUser");
Amith Yamasani38f836b2014-08-20 14:51:15 -07005077 if (mService != null) {
5078 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02005079 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07005080 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005081 throw re.rethrowFromSystemServer();
Amith Yamasani38f836b2014-08-20 14:51:15 -07005082 }
5083 }
5084 return null;
5085 }
5086
5087 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005088 * Called by a profile owner or device owner to add a default intent handler activity for
5089 * intents that match a certain intent filter. This activity will remain the default intent
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005090 * handler even if the set of potential event handlers for the intent filter changes and if the
5091 * intent preferences are reset.
5092 * <p>
5093 * The default disambiguation mechanism takes over if the activity is not installed (anymore).
5094 * When the activity is (re)installed, it is automatically reset as default intent handler for
5095 * the filter.
5096 * <p>
5097 * The calling device admin must be a profile owner or device owner. If it is not, a security
5098 * exception will be thrown.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005099 *
5100 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5101 * @param filter The IntentFilter for which a default handler is added.
5102 * @param activity The Activity that is added as default intent handler.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005103 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005104 */
Robin Lee25e26452015-06-02 09:56:29 -07005105 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
5106 @NonNull ComponentName activity) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005107 throwIfParentInstance("addPersistentPreferredActivity");
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005108 if (mService != null) {
5109 try {
5110 mService.addPersistentPreferredActivity(admin, filter, activity);
5111 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005112 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005113 }
5114 }
5115 }
5116
5117 /**
5118 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00005119 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005120 * <p>
5121 * The calling device admin must be a profile owner. If it is not, a security exception will be
5122 * thrown.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005123 *
5124 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5125 * @param packageName The name of the package for which preferences are removed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005126 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005127 */
Robin Lee25e26452015-06-02 09:56:29 -07005128 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005129 String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005130 throwIfParentInstance("clearPackagePersistentPreferredActivities");
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005131 if (mService != null) {
5132 try {
5133 mService.clearPackagePersistentPreferredActivities(admin, packageName);
5134 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005135 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005136 }
5137 }
5138 }
Robin Lee66e5d962014-04-09 16:44:21 +01005139
5140 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00005141 * Called by a profile owner or device owner to grant permission to a package to manage
5142 * application restrictions for the calling user via {@link #setApplicationRestrictions} and
5143 * {@link #getApplicationRestrictions}.
5144 * <p>
5145 * This permission is persistent until it is later cleared by calling this method with a
5146 * {@code null} value or uninstalling the managing package.
Rubin Xuf03d0a62016-02-10 14:54:15 +00005147 * <p>
5148 * The supplied application restriction managing package must be installed when calling this
Victor Changcd14c0a2016-03-16 19:10:15 +00005149 * API, otherwise an {@link NameNotFoundException} will be thrown.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005150 *
5151 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5152 * @param packageName The package name which will be given access to application restrictions
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005153 * APIs. If {@code null} is given the current package will be cleared.
5154 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Changcd14c0a2016-03-16 19:10:15 +00005155 * @throws NameNotFoundException if {@code packageName} is not found
Edman Anjosf9946772016-11-28 16:35:15 +01005156 *
5157 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #setDelegatedScopes}
5158 * with the {@link #DELEGATION_APP_RESTRICTIONS} scope instead.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005159 */
Edman Anjosf9946772016-11-28 16:35:15 +01005160 @Deprecated
Esteban Talaverabf60f722015-12-10 16:26:44 +00005161 public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin,
Victor Changcd14c0a2016-03-16 19:10:15 +00005162 @Nullable String packageName) throws NameNotFoundException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005163 throwIfParentInstance("setApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00005164 if (mService != null) {
5165 try {
Victor Changcd14c0a2016-03-16 19:10:15 +00005166 if (!mService.setApplicationRestrictionsManagingPackage(admin, packageName)) {
5167 throw new NameNotFoundException(packageName);
5168 }
Esteban Talaverabf60f722015-12-10 16:26:44 +00005169 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005170 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00005171 }
5172 }
5173 }
5174
5175 /**
5176 * Called by a profile owner or device owner to retrieve the application restrictions managing
Edman Anjosf9946772016-11-28 16:35:15 +01005177 * package for the current user, or {@code null} if none is set. If there are multiple
5178 * delegates this function will return one of them.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005179 *
5180 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5181 * @return The package name allowed to manage application restrictions on the current user, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005182 * {@code null} if none is set.
5183 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01005184 *
5185 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatePackages}
5186 * with the {@link #DELEGATION_APP_RESTRICTIONS} scope instead.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005187 */
Edman Anjosf9946772016-11-28 16:35:15 +01005188 @Deprecated
5189 @Nullable
5190 public String getApplicationRestrictionsManagingPackage(
Makoto Onuki408e8e42016-10-25 12:10:27 -07005191 @NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005192 throwIfParentInstance("getApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00005193 if (mService != null) {
5194 try {
5195 return mService.getApplicationRestrictionsManagingPackage(admin);
5196 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005197 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00005198 }
5199 }
5200 return null;
5201 }
5202
5203 /**
Esteban Talavera96895ca2016-03-16 12:00:40 +00005204 * Called by any application to find out whether it has been granted permission via
5205 * {@link #setApplicationRestrictionsManagingPackage} to manage application restrictions
5206 * for the calling user.
5207 *
5208 * <p>This is done by comparing the calling Linux uid with the uid of the package specified by
5209 * that method.
Edman Anjosf9946772016-11-28 16:35:15 +01005210 *
5211 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatedScopes}
5212 * instead.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005213 */
Edman Anjosf9946772016-11-28 16:35:15 +01005214 @Deprecated
Esteban Talaverabf60f722015-12-10 16:26:44 +00005215 public boolean isCallerApplicationRestrictionsManagingPackage() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005216 throwIfParentInstance("isCallerApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00005217 if (mService != null) {
5218 try {
Edman Anjosf9946772016-11-28 16:35:15 +01005219 return mService.isCallerApplicationRestrictionsManagingPackage(
5220 mContext.getPackageName());
Esteban Talaverabf60f722015-12-10 16:26:44 +00005221 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005222 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00005223 }
5224 }
5225 return false;
5226 }
5227
5228 /**
5229 * Sets the application restrictions for a given target application running in the calling user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005230 * <p>
5231 * 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 +01005232 * application restrictions via {@link #setDelegatedScopes} with the
5233 * {@link #DELEGATION_APP_RESTRICTIONS} scope; otherwise a security exception will be thrown.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005234 * <p>
5235 * The provided {@link Bundle} consists of key-value pairs, where the types of values may be:
Esteban Talavera6b8e0642015-08-10 17:26:04 +01005236 * <ul>
5237 * <li>{@code boolean}
5238 * <li>{@code int}
5239 * <li>{@code String} or {@code String[]}
5240 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
5241 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005242 * <p>
5243 * If the restrictions are not available yet, but may be applied in the near future, the caller
5244 * can notify the target application of that by adding
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00005245 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005246 * <p>
5247 * The application restrictions are only made visible to the target application via
5248 * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or device
5249 * owner, and the application restrictions managing package via
Esteban Talaverabf60f722015-12-10 16:26:44 +00005250 * {@link #getApplicationRestrictions}.
Robin Lee66e5d962014-04-09 16:44:21 +01005251 *
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005252 * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
5253 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00005254 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005255 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01005256 * @param packageName The name of the package to update restricted settings for.
5257 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005258 * set of active restrictions.
5259 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01005260 * @see #setDelegatedScopes
5261 * @see #DELEGATION_APP_RESTRICTIONS
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00005262 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01005263 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005264 @WorkerThread
Esteban Talaverabf60f722015-12-10 16:26:44 +00005265 public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01005266 Bundle settings) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005267 throwIfParentInstance("setApplicationRestrictions");
Robin Lee66e5d962014-04-09 16:44:21 +01005268 if (mService != null) {
5269 try {
Edman Anjosf9946772016-11-28 16:35:15 +01005270 mService.setApplicationRestrictions(admin, mContext.getPackageName(), packageName,
5271 settings);
Robin Lee66e5d962014-04-09 16:44:21 +01005272 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005273 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01005274 }
5275 }
5276 }
5277
5278 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005279 * Sets a list of configuration features to enable for a TrustAgent component. This is meant to
5280 * be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all trust
5281 * agents but those enabled by this function call. If flag
Jim Millere303bf42014-08-26 17:12:29 -07005282 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005283 * <p>
5284 * The calling device admin must have requested
5285 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method;
5286 * if not, a security exception will be thrown.
Tony Mak089d8402016-04-05 17:42:55 +01005287 * <p>
5288 * This method can be called on the {@link DevicePolicyManager} instance returned by
5289 * {@link #getParentProfileInstance(ComponentName)} in order to set the configuration for
5290 * the parent profile.
Jim Miller604e7552014-07-18 19:00:02 -07005291 *
5292 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07005293 * @param target Component name of the agent to be enabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005294 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent will be
5295 * strictly disabled according to the state of the
5296 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
5297 * <p>
5298 * If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all
5299 * admins, then it's up to the TrustAgent itself to aggregate the values from all
5300 * device admins.
5301 * <p>
5302 * Consult documentation for the specific TrustAgent to determine legal options
5303 * parameters.
5304 * @throws SecurityException if {@code admin} is not an active administrator or does not use
5305 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES}
Jim Miller604e7552014-07-18 19:00:02 -07005306 */
Robin Lee25e26452015-06-02 09:56:29 -07005307 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
5308 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07005309 if (mService != null) {
5310 try {
Tony Mak089d8402016-04-05 17:42:55 +01005311 mService.setTrustAgentConfiguration(admin, target, configuration, mParentInstance);
Jim Miller604e7552014-07-18 19:00:02 -07005312 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005313 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07005314 }
5315 }
5316 }
5317
5318 /**
Jim Millere303bf42014-08-26 17:12:29 -07005319 * Gets configuration for the given trust agent based on aggregating all calls to
5320 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
5321 * all device admins.
Tony Mak089d8402016-04-05 17:42:55 +01005322 * <p>
5323 * This method can be called on the {@link DevicePolicyManager} instance returned by
5324 * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the configuration set
5325 * on the parent profile.
Jim Miller604e7552014-07-18 19:00:02 -07005326 *
Jim Millerb5db57a2015-01-14 18:17:19 -08005327 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
5328 * this function returns a list of configurations for all admins that declare
5329 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
5330 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
5331 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
5332 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07005333 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07005334 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07005335 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005336 public @Nullable List<PersistableBundle> getTrustAgentConfiguration(
5337 @Nullable ComponentName admin, @NonNull ComponentName agent) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07005338 return getTrustAgentConfiguration(admin, agent, myUserId());
Jim Millere303bf42014-08-26 17:12:29 -07005339 }
5340
5341 /** @hide per-user version */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005342 public @Nullable List<PersistableBundle> getTrustAgentConfiguration(
5343 @Nullable ComponentName admin, @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07005344 if (mService != null) {
5345 try {
Tony Mak089d8402016-04-05 17:42:55 +01005346 return mService.getTrustAgentConfiguration(admin, agent, userHandle,
5347 mParentInstance);
Jim Miller604e7552014-07-18 19:00:02 -07005348 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005349 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07005350 }
5351 }
Jim Millere303bf42014-08-26 17:12:29 -07005352 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07005353 }
5354
5355 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005356 * Called by a profile owner of a managed profile to set whether caller-Id information from the
5357 * managed profile will be shown in the parent profile, for incoming calls.
5358 * <p>
5359 * The calling device admin must be a profile owner. If it is not, a security exception will be
5360 * thrown.
Adam Connors210fe212014-07-17 15:41:43 +01005361 *
Robin Lee25e26452015-06-02 09:56:29 -07005362 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01005363 * @param disabled If true caller-Id information in the managed profile is not displayed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005364 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors210fe212014-07-17 15:41:43 +01005365 */
Robin Lee25e26452015-06-02 09:56:29 -07005366 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005367 throwIfParentInstance("setCrossProfileCallerIdDisabled");
Adam Connors210fe212014-07-17 15:41:43 +01005368 if (mService != null) {
5369 try {
Robin Lee25e26452015-06-02 09:56:29 -07005370 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01005371 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005372 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01005373 }
5374 }
5375 }
5376
5377 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005378 * Called by a profile owner of a managed profile to determine whether or not caller-Id
5379 * information has been disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005380 * <p>
5381 * The calling device admin must be a profile owner. If it is not, a security exception will be
5382 * thrown.
Adam Connors210fe212014-07-17 15:41:43 +01005383 *
Robin Lee25e26452015-06-02 09:56:29 -07005384 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005385 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors210fe212014-07-17 15:41:43 +01005386 */
Robin Lee25e26452015-06-02 09:56:29 -07005387 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005388 throwIfParentInstance("getCrossProfileCallerIdDisabled");
Adam Connors210fe212014-07-17 15:41:43 +01005389 if (mService != null) {
5390 try {
Robin Lee25e26452015-06-02 09:56:29 -07005391 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01005392 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005393 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01005394 }
5395 }
5396 return false;
5397 }
5398
5399 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07005400 * Determine whether or not caller-Id information has been disabled.
5401 *
5402 * @param userHandle The user for whom to check the caller-id permission
5403 * @hide
5404 */
5405 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
5406 if (mService != null) {
5407 try {
5408 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
5409 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005410 throw e.rethrowFromSystemServer();
Amith Yamasani570002f2014-07-18 15:48:54 -07005411 }
5412 }
5413 return false;
5414 }
5415
5416 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005417 * Called by a profile owner of a managed profile to set whether contacts search from the
5418 * managed profile will be shown in the parent profile, for incoming calls.
5419 * <p>
5420 * The calling device admin must be a profile owner. If it is not, a security exception will be
5421 * thrown.
Victor Chang1060c6182016-01-04 20:16:23 +00005422 *
5423 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5424 * @param disabled If true contacts search in the managed profile is not displayed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005425 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Chang1060c6182016-01-04 20:16:23 +00005426 */
5427 public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin,
5428 boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005429 throwIfParentInstance("setCrossProfileContactsSearchDisabled");
Victor Chang1060c6182016-01-04 20:16:23 +00005430 if (mService != null) {
5431 try {
5432 mService.setCrossProfileContactsSearchDisabled(admin, disabled);
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 }
5438
5439 /**
5440 * Called by a profile owner of a managed profile to determine whether or not contacts search
5441 * has been disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005442 * <p>
5443 * The calling device admin must be a profile owner. If it is not, a security exception will be
5444 * thrown.
Victor Chang1060c6182016-01-04 20:16:23 +00005445 *
5446 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005447 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Chang1060c6182016-01-04 20:16:23 +00005448 */
5449 public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005450 throwIfParentInstance("getCrossProfileContactsSearchDisabled");
Victor Chang1060c6182016-01-04 20:16:23 +00005451 if (mService != null) {
5452 try {
5453 return mService.getCrossProfileContactsSearchDisabled(admin);
5454 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005455 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00005456 }
5457 }
5458 return false;
5459 }
5460
5461
5462 /**
5463 * Determine whether or not contacts search has been disabled.
5464 *
5465 * @param userHandle The user for whom to check the contacts search permission
5466 * @hide
5467 */
5468 public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) {
5469 if (mService != null) {
5470 try {
5471 return mService
5472 .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier());
5473 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005474 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00005475 }
5476 }
5477 return false;
5478 }
5479
5480 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005481 * Start Quick Contact on the managed profile for the user, if the policy allows.
Victor Chang97bdacc2016-01-21 22:24:11 +00005482 *
Makoto Onuki1040da12015-03-19 11:24:00 -07005483 * @hide
5484 */
5485 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
Victor Chang97bdacc2016-01-21 22:24:11 +00005486 boolean isContactIdIgnored, long directoryId, Intent originalIntent) {
Makoto Onuki1040da12015-03-19 11:24:00 -07005487 if (mService != null) {
5488 try {
Victor Chang97bdacc2016-01-21 22:24:11 +00005489 mService.startManagedQuickContact(actualLookupKey, actualContactId,
5490 isContactIdIgnored, directoryId, originalIntent);
Makoto Onuki1040da12015-03-19 11:24:00 -07005491 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005492 throw e.rethrowFromSystemServer();
Makoto Onuki1040da12015-03-19 11:24:00 -07005493 }
5494 }
5495 }
5496
5497 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005498 * Start Quick Contact on the managed profile for the user, if the policy allows.
Ricky Wai494b95d2015-11-20 16:07:15 +00005499 * @hide
5500 */
5501 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
5502 Intent originalIntent) {
Victor Chang97bdacc2016-01-21 22:24:11 +00005503 startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT,
Ricky Wai494b95d2015-11-20 16:07:15 +00005504 originalIntent);
5505 }
5506
5507 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005508 * Called by a profile owner of a managed profile to set whether bluetooth devices can access
5509 * enterprise contacts.
Ricky Wai778ba132015-03-31 14:21:22 +01005510 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005511 * The calling device admin must be a profile owner. If it is not, a security exception will be
5512 * thrown.
Ricky Wai778ba132015-03-31 14:21:22 +01005513 * <p>
5514 * This API works on managed profile only.
5515 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005516 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5517 * @param disabled If true, bluetooth devices cannot access enterprise contacts.
5518 * @throws SecurityException if {@code admin} is not a device or profile owner.
Ricky Wai778ba132015-03-31 14:21:22 +01005519 */
Robin Lee25e26452015-06-02 09:56:29 -07005520 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005521 throwIfParentInstance("setBluetoothContactSharingDisabled");
Ricky Wai778ba132015-03-31 14:21:22 +01005522 if (mService != null) {
5523 try {
Robin Lee25e26452015-06-02 09:56:29 -07005524 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01005525 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005526 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01005527 }
5528 }
5529 }
5530
5531 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005532 * Called by a profile owner of a managed profile to determine whether or not Bluetooth devices
5533 * cannot access enterprise contacts.
Ricky Wai778ba132015-03-31 14:21:22 +01005534 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005535 * The calling device admin must be a profile owner. If it is not, a security exception will be
5536 * thrown.
Ricky Wai778ba132015-03-31 14:21:22 +01005537 * <p>
5538 * This API works on managed profile only.
5539 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005540 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5541 * @throws SecurityException if {@code admin} is not a device or profile owner.
Ricky Wai778ba132015-03-31 14:21:22 +01005542 */
Robin Lee25e26452015-06-02 09:56:29 -07005543 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005544 throwIfParentInstance("getBluetoothContactSharingDisabled");
Ricky Wai778ba132015-03-31 14:21:22 +01005545 if (mService != null) {
5546 try {
Robin Lee25e26452015-06-02 09:56:29 -07005547 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01005548 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005549 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01005550 }
5551 }
5552 return true;
5553 }
5554
5555 /**
5556 * Determine whether or not Bluetooth devices cannot access contacts.
5557 * <p>
5558 * This API works on managed profile UserHandle only.
5559 *
5560 * @param userHandle The user for whom to check the caller-id permission
5561 * @hide
5562 */
5563 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
5564 if (mService != null) {
5565 try {
5566 return mService.getBluetoothContactSharingDisabledForUser(userHandle
5567 .getIdentifier());
5568 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005569 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01005570 }
5571 }
5572 return true;
5573 }
5574
5575 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005576 * Called by the profile owner of a managed profile so that some intents sent in the managed
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005577 * profile can also be resolved in the parent, or vice versa. Only activity intents are
5578 * supported.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00005579 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005580 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01005581 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005582 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01005583 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005584 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
5585 * @throws SecurityException if {@code admin} is not a device or profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005586 */
Robin Lee25e26452015-06-02 09:56:29 -07005587 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005588 throwIfParentInstance("addCrossProfileIntentFilter");
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005589 if (mService != null) {
5590 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01005591 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005592 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005593 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005594 }
5595 }
5596 }
5597
5598 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005599 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
5600 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01005601 * Only removes those that have been set by the profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005602 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005603 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005604 * @throws SecurityException if {@code admin} is not a device or profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005605 */
Robin Lee25e26452015-06-02 09:56:29 -07005606 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005607 throwIfParentInstance("clearCrossProfileIntentFilters");
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005608 if (mService != null) {
5609 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01005610 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005611 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005612 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005613 }
5614 }
5615 }
5616
5617 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005618 * Called by a profile or device owner to set the permitted accessibility services. When set by
5619 * a device owner or profile owner the restriction applies to all profiles of the user the
5620 * device owner or profile owner is an admin for. By default the user can use any accessiblity
5621 * service. When zero or more packages have been added, accessiblity services that are not in
5622 * the list and not part of the system can not be enabled by the user.
5623 * <p>
5624 * Calling with a null value for the list disables the restriction so that all services can be
5625 * used, calling with an empty list only allows the builtin system's services.
5626 * <p>
Esteban Talavera7e4cbad2017-03-30 17:59:50 +01005627 * System accessibility services are always available to the user the list can't modify this.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005628 *
5629 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5630 * @param packageNames List of accessibility service package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005631 * @return true if setting the restriction succeeded. It fail if there is one or more non-system
5632 * accessibility services enabled, that are not in the list.
5633 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005634 */
Robin Lee25e26452015-06-02 09:56:29 -07005635 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005636 List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005637 throwIfParentInstance("setPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005638 if (mService != null) {
5639 try {
5640 return mService.setPermittedAccessibilityServices(admin, packageNames);
5641 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005642 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005643 }
5644 }
5645 return false;
5646 }
5647
5648 /**
5649 * Returns the list of permitted accessibility services set by this device or profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005650 * <p>
5651 * An empty list means no accessibility services except system services are allowed. Null means
5652 * all accessibility services are allowed.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005653 *
5654 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5655 * @return List of accessiblity service package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005656 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005657 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005658 public @Nullable List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005659 throwIfParentInstance("getPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005660 if (mService != null) {
5661 try {
5662 return mService.getPermittedAccessibilityServices(admin);
5663 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005664 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005665 }
5666 }
5667 return null;
5668 }
5669
5670 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00005671 * Called by the system to check if a specific accessibility service is disabled by admin.
5672 *
5673 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5674 * @param packageName Accessibility service package name that needs to be checked.
5675 * @param userHandle user id the admin is running as.
5676 * @return true if the accessibility service is permitted, otherwise false.
5677 *
5678 * @hide
5679 */
5680 public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin,
5681 @NonNull String packageName, int userHandle) {
5682 if (mService != null) {
5683 try {
5684 return mService.isAccessibilityServicePermittedByAdmin(admin, packageName,
5685 userHandle);
5686 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005687 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00005688 }
5689 }
5690 return false;
5691 }
5692
5693 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005694 * Returns the list of accessibility services permitted by the device or profiles
5695 * owners of this user.
5696 *
5697 * <p>Null means all accessibility services are allowed, if a non-null list is returned
5698 * it will contain the intersection of the permitted lists for any device or profile
5699 * owners that apply to this user. It will also include any system accessibility services.
5700 *
5701 * @param userId which user to check for.
5702 * @return List of accessiblity service package names.
5703 * @hide
5704 */
5705 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07005706 public @Nullable List<String> getPermittedAccessibilityServices(int userId) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005707 throwIfParentInstance("getPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005708 if (mService != null) {
5709 try {
5710 return mService.getPermittedAccessibilityServicesForUser(userId);
5711 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005712 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005713 }
5714 }
5715 return null;
5716 }
5717
5718 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005719 * Called by a profile or device owner to set the permitted input methods services. When set by
5720 * a device owner or profile owner the restriction applies to all profiles of the user the
5721 * device owner or profile owner is an admin for. By default the user can use any input method.
5722 * When zero or more packages have been added, input method that are not in the list and not
5723 * part of the system can not be enabled by the user. This method will fail if it is called for
5724 * a admin that is not for the foreground user or a profile of the foreground user.
5725 * <p>
5726 * Calling with a null value for the list disables the restriction so that all input methods can
5727 * be used, calling with an empty list disables all but the system's own input methods.
5728 * <p>
5729 * System input methods are always available to the user this method can't modify this.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005730 *
5731 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5732 * @param packageNames List of input method package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005733 * @return true if setting the restriction succeeded. It will fail if there are one or more
5734 * non-system input methods currently enabled that are not in the packageNames list.
5735 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005736 */
Esteban Talavera7e4cbad2017-03-30 17:59:50 +01005737 public boolean setPermittedInputMethods(
5738 @NonNull ComponentName admin, List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005739 throwIfParentInstance("setPermittedInputMethods");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005740 if (mService != null) {
5741 try {
5742 return mService.setPermittedInputMethods(admin, packageNames);
5743 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005744 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005745 }
5746 }
5747 return false;
5748 }
5749
5750
5751 /**
5752 * Returns the list of permitted input methods set by this device or profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005753 * <p>
5754 * An empty list means no input methods except system input methods are allowed. Null means all
5755 * input methods are allowed.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005756 *
5757 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5758 * @return List of input method package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005759 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005760 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005761 public @Nullable List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005762 throwIfParentInstance("getPermittedInputMethods");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005763 if (mService != null) {
5764 try {
5765 return mService.getPermittedInputMethods(admin);
5766 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005767 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005768 }
5769 }
5770 return null;
5771 }
5772
5773 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00005774 * Called by the system to check if a specific input method is disabled by admin.
5775 *
5776 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5777 * @param packageName Input method package name that needs to be checked.
5778 * @param userHandle user id the admin is running as.
5779 * @return true if the input method is permitted, otherwise false.
5780 *
5781 * @hide
5782 */
5783 public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin,
5784 @NonNull String packageName, int userHandle) {
5785 if (mService != null) {
5786 try {
5787 return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle);
5788 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005789 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00005790 }
5791 }
5792 return false;
5793 }
5794
5795 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005796 * Returns the list of input methods permitted by the device or profiles
Makoto Onuki32b30572015-12-11 14:29:51 -08005797 * owners of the current user. (*Not* calling user, due to a limitation in InputMethodManager.)
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005798 *
5799 * <p>Null means all input methods are allowed, if a non-null list is returned
5800 * it will contain the intersection of the permitted lists for any device or profile
5801 * owners that apply to this user. It will also include any system input methods.
5802 *
5803 * @return List of input method package names.
5804 * @hide
5805 */
5806 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07005807 public @Nullable List<String> getPermittedInputMethodsForCurrentUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005808 throwIfParentInstance("getPermittedInputMethodsForCurrentUser");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005809 if (mService != null) {
5810 try {
5811 return mService.getPermittedInputMethodsForCurrentUser();
5812 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005813 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005814 }
5815 }
5816 return null;
5817 }
5818
5819 /**
Esteban Talavera7e4cbad2017-03-30 17:59:50 +01005820 * Called by a profile owner of a managed profile to set the packages that are allowed to use
5821 * a {@link android.service.notification.NotificationListenerService} in the primary user to
5822 * see notifications from the managed profile. By default all packages are permitted by this
5823 * policy. When zero or more packages have been added, notification listeners installed on the
5824 * primary user that are not in the list and are not part of the system won't receive events
5825 * for managed profile notifications.
5826 * <p>
5827 * Calling with a {@code null} value for the list disables the restriction so that all
5828 * notification listener services be used. Calling with an empty list disables all but the
5829 * system's own notification listeners. System notification listener services are always
5830 * available to the user.
5831 * <p>
5832 * If a device or profile owner want to stop notification listeners in their user from seeing
5833 * that user's notifications they should prevent that service from running instead (e.g. via
5834 * {@link #setApplicationHidden(ComponentName, String, boolean)})
5835 *
5836 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5837 * @param packageList List of package names to whitelist
5838 * @return true if setting the restriction succeeded. It will fail if called outside a managed
5839 * profile
5840 * @throws SecurityException if {@code admin} is not a profile owner.
5841 *
5842 * @see android.service.notification.NotificationListenerService
5843 */
5844 public boolean setPermittedCrossProfileNotificationListeners(
5845 @NonNull ComponentName admin, @Nullable List<String> packageList) {
5846 throwIfParentInstance("setPermittedCrossProfileNotificationListeners");
5847 if (mService != null) {
5848 try {
5849 return mService.setPermittedCrossProfileNotificationListeners(admin, packageList);
5850 } catch (RemoteException e) {
5851 throw e.rethrowFromSystemServer();
5852 }
5853 }
5854 return false;
5855 }
5856
5857 /**
5858 * Returns the list of packages installed on the primary user that allowed to use a
5859 * {@link android.service.notification.NotificationListenerService} to receive
5860 * notifications from this managed profile, as set by the profile owner.
5861 * <p>
5862 * An empty list means no notification listener services except system ones are allowed.
5863 * A {@code null} return value indicates that all notification listeners are allowed.
5864 */
5865 public @Nullable List<String> getPermittedCrossProfileNotificationListeners(
5866 @NonNull ComponentName admin) {
5867 throwIfParentInstance("getPermittedCrossProfileNotificationListeners");
5868 if (mService != null) {
5869 try {
5870 return mService.getPermittedCrossProfileNotificationListeners(admin);
5871 } catch (RemoteException e) {
5872 throw e.rethrowFromSystemServer();
5873 }
5874 }
5875 return null;
5876 }
5877
5878 /**
5879 * Returns true if {@code NotificationListenerServices} from the given package are allowed to
5880 * receive events for notifications from the given user id. Can only be called by the system uid
5881 *
5882 * @see #setPermittedCrossProfileNotificationListeners(ComponentName, List)
5883 *
5884 * @hide
5885 */
5886 public boolean isNotificationListenerServicePermitted(
5887 @NonNull String packageName, @UserIdInt int userId) {
5888 if (mService != null) {
5889 try {
5890 return mService.isNotificationListenerServicePermitted(packageName, userId);
5891 } catch (RemoteException e) {
5892 throw e.rethrowFromSystemServer();
5893 }
5894 }
5895 return true;
5896 }
5897
5898 /**
Edman Anjos52088e42017-01-13 22:26:17 +01005899 * Get the list of apps to keep around as APKs even if no user has currently installed it. This
5900 * function can be called by a device owner or by a delegate given the
5901 * {@link #DELEGATION_KEEP_UNINSTALLED_PACKAGES} scope via {@link #setDelegatedScopes}.
5902 * <p>
5903 * Please note that packages returned in this method are not automatically pre-cached.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005904 *
Edman Anjos52088e42017-01-13 22:26:17 +01005905 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
5906 * {@code null} if the caller is a keep uninstalled packages delegate.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005907 * @return List of package names to keep cached.
Edman Anjos52088e42017-01-13 22:26:17 +01005908 * @see #setDelegatedScopes
5909 * @see #DELEGATION_KEEP_UNINSTALLED_PACKAGES
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005910 * @hide
5911 */
Edman Anjos52088e42017-01-13 22:26:17 +01005912 public @Nullable List<String> getKeepUninstalledPackages(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005913 throwIfParentInstance("getKeepUninstalledPackages");
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005914 if (mService != null) {
5915 try {
Edman Anjos52088e42017-01-13 22:26:17 +01005916 return mService.getKeepUninstalledPackages(admin, mContext.getPackageName());
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005917 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005918 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005919 }
5920 }
5921 return null;
5922 }
5923
5924 /**
Edman Anjos52088e42017-01-13 22:26:17 +01005925 * Set a list of apps to keep around as APKs even if no user has currently installed it. This
5926 * function can be called by a device owner or by a delegate given the
5927 * {@link #DELEGATION_KEEP_UNINSTALLED_PACKAGES} scope via {@link #setDelegatedScopes}.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005928 *
5929 * <p>Please note that setting this policy does not imply that specified apps will be
5930 * automatically pre-cached.</p>
5931 *
Edman Anjos52088e42017-01-13 22:26:17 +01005932 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
5933 * {@code null} if the caller is a keep uninstalled packages delegate.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005934 * @param packageNames List of package names to keep cached.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005935 * @throws SecurityException if {@code admin} is not a device owner.
Edman Anjos52088e42017-01-13 22:26:17 +01005936 * @see #setDelegatedScopes
5937 * @see #DELEGATION_KEEP_UNINSTALLED_PACKAGES
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005938 * @hide
5939 */
Edman Anjos52088e42017-01-13 22:26:17 +01005940 public void setKeepUninstalledPackages(@Nullable ComponentName admin,
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005941 @NonNull List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005942 throwIfParentInstance("setKeepUninstalledPackages");
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005943 if (mService != null) {
5944 try {
Edman Anjos52088e42017-01-13 22:26:17 +01005945 mService.setKeepUninstalledPackages(admin, mContext.getPackageName(), packageNames);
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005946 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005947 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005948 }
5949 }
5950 }
5951
5952 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04005953 * Called by a device owner to create a user with the specified name. The UserHandle returned
5954 * by this method should not be persisted as user handles are recycled as users are removed and
5955 * created. If you need to persist an identifier for this user, use
5956 * {@link UserManager#getSerialNumberForUser}.
5957 *
5958 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5959 * @param name the user's name
5960 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07005961 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
5962 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01005963 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005964 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01005965 * @removed From {@link android.os.Build.VERSION_CODES#N}
Julia Reynolds1e958392014-05-16 14:25:21 -04005966 */
Kenny Guy14f48e52015-06-29 15:12:36 +01005967 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07005968 public @Nullable UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04005969 return null;
5970 }
5971
5972 /**
Jason Monk03978a42014-06-10 15:05:30 -04005973 * Called by a device owner to create a user with the specified name. The UserHandle returned
5974 * by this method should not be persisted as user handles are recycled as users are removed and
5975 * created. If you need to persist an identifier for this user, use
5976 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
5977 * immediately.
5978 *
5979 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
5980 * as registered as an active admin on the new user. The profile owner package will be
5981 * installed on the new user if it already is installed on the device.
5982 *
5983 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
5984 * profileOwnerComponent when onEnable is called.
5985 *
5986 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5987 * @param name the user's name
5988 * @param ownerName the human readable name of the organisation associated with this DPM.
5989 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
5990 * the user.
5991 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
5992 * on the new user.
5993 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07005994 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
5995 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01005996 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005997 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01005998 * @removed From {@link android.os.Build.VERSION_CODES#N}
Jason Monk03978a42014-06-10 15:05:30 -04005999 */
Kenny Guy14f48e52015-06-29 15:12:36 +01006000 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07006001 public @Nullable UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
Robin Lee25e26452015-06-02 09:56:29 -07006002 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04006003 return null;
6004 }
6005
6006 /**
phweissa92e1212016-01-25 17:14:10 +01006007 * Flag used by {@link #createAndManageUser} to skip setup wizard after creating a new user.
phweiss343fb332016-01-25 14:48:59 +01006008 */
6009 public static final int SKIP_SETUP_WIZARD = 0x0001;
6010
6011 /**
Lenka Trochtovac8202c82016-01-26 15:11:09 +01006012 * Flag used by {@link #createAndManageUser} to specify that the user should be created
6013 * ephemeral.
6014 * @hide
6015 */
6016 public static final int MAKE_USER_EPHEMERAL = 0x0002;
6017
6018 /**
Christine Franks361b8252017-06-23 18:12:46 -07006019 * Flag used by {@link #createAndManageUser} to specify that the user should be created as a
6020 * demo user.
6021 * @hide
6022 */
6023 public static final int MAKE_USER_DEMO = 0x0004;
6024
6025 /**
Benjamin Franz77c94a92017-08-09 14:16:03 +01006026 * Flag used by {@link #createAndManageUser} to specificy that the newly created user should be
6027 * started in the background as part of the user creation.
6028 */
6029 // TODO: Investigate solutions for the case where reboot happens before setup is completed.
6030 public static final int START_USER_IN_BACKGROUND = 0x0008;
6031
6032 /**
6033 * @hide
6034 */
6035 @IntDef(
6036 flag = true,
6037 prefix = {"SKIP_", "MAKE_USER_", "START_"},
6038 value = {SKIP_SETUP_WIZARD, MAKE_USER_EPHEMERAL, MAKE_USER_DEMO,
6039 START_USER_IN_BACKGROUND}
6040 )
6041 @Retention(RetentionPolicy.SOURCE)
6042 public @interface CreateAndManageUserFlags {}
6043
6044
6045 /**
phweissa92e1212016-01-25 17:14:10 +01006046 * Called by a device owner to create a user with the specified name and a given component of
6047 * the calling package as profile owner. The UserHandle returned by this method should not be
6048 * persisted as user handles are recycled as users are removed and created. If you need to
6049 * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new
6050 * user will not be started in the background.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006051 * <p>
6052 * admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also a
6053 * DeviceAdminReceiver in the same package as admin, and will become the profile owner and will
6054 * be registered as an active admin on the new user. The profile owner package will be installed
6055 * on the new user.
6056 * <p>
6057 * If the adminExtras are not null, they will be stored on the device until the user is started
6058 * for the first time. Then the extras will be passed to the admin when onEnable is called.
phweiss343fb332016-01-25 14:48:59 +01006059 *
6060 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6061 * @param name The user's name.
phweissa92e1212016-01-25 17:14:10 +01006062 * @param profileOwner Which {@link DeviceAdminReceiver} will be profile owner. Has to be in the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006063 * same package as admin, otherwise no user is created and an
6064 * IllegalArgumentException is thrown.
phweiss343fb332016-01-25 14:48:59 +01006065 * @param adminExtras Extras that will be passed to onEnable of the admin receiver on the new
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006066 * user.
phweissa92e1212016-01-25 17:14:10 +01006067 * @param flags {@link #SKIP_SETUP_WIZARD} is supported.
phweiss343fb332016-01-25 14:48:59 +01006068 * @see UserHandle
6069 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
6070 * user could not be created.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006071 * @throws SecurityException if {@code admin} is not a device owner.
phweiss343fb332016-01-25 14:48:59 +01006072 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006073 public @Nullable UserHandle createAndManageUser(@NonNull ComponentName admin,
6074 @NonNull String name,
phweissa92e1212016-01-25 17:14:10 +01006075 @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras,
Benjamin Franz77c94a92017-08-09 14:16:03 +01006076 @CreateAndManageUserFlags int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006077 throwIfParentInstance("createAndManageUser");
phweiss343fb332016-01-25 14:48:59 +01006078 try {
phweissa92e1212016-01-25 17:14:10 +01006079 return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags);
phweiss343fb332016-01-25 14:48:59 +01006080 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006081 throw re.rethrowFromSystemServer();
phweiss343fb332016-01-25 14:48:59 +01006082 }
phweiss343fb332016-01-25 14:48:59 +01006083 }
6084
6085 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006086 * Called by a device owner to remove a user and all associated data. The primary user can not
6087 * be removed.
Julia Reynolds1e958392014-05-16 14:25:21 -04006088 *
6089 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6090 * @param userHandle the user to remove.
6091 * @return {@code true} if the user was removed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006092 * @throws SecurityException if {@code admin} is not a device owner.
Julia Reynolds1e958392014-05-16 14:25:21 -04006093 */
Robin Lee25e26452015-06-02 09:56:29 -07006094 public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006095 throwIfParentInstance("removeUser");
Julia Reynolds1e958392014-05-16 14:25:21 -04006096 try {
6097 return mService.removeUser(admin, userHandle);
6098 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006099 throw re.rethrowFromSystemServer();
Julia Reynolds1e958392014-05-16 14:25:21 -04006100 }
6101 }
6102
6103 /**
Jason Monk582d9112014-07-09 19:57:08 -04006104 * Called by a device owner to switch the specified user to the foreground.
6105 *
6106 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6107 * @param userHandle the user to switch to; null will switch to primary.
6108 * @return {@code true} if the switch was successful, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006109 * @throws SecurityException if {@code admin} is not a device owner.
Jason Monk582d9112014-07-09 19:57:08 -04006110 * @see Intent#ACTION_USER_FOREGROUND
6111 */
Robin Lee25e26452015-06-02 09:56:29 -07006112 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006113 throwIfParentInstance("switchUser");
Jason Monk582d9112014-07-09 19:57:08 -04006114 try {
6115 return mService.switchUser(admin, userHandle);
6116 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006117 throw re.rethrowFromSystemServer();
Jason Monk582d9112014-07-09 19:57:08 -04006118 }
6119 }
6120
6121 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00006122 * Retrieves the application restrictions for a given target application running in the calling
6123 * user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006124 * <p>
6125 * 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 +01006126 * application restrictions via {@link #setDelegatedScopes} with the
6127 * {@link #DELEGATION_APP_RESTRICTIONS} scope; otherwise a security exception will be thrown.
Robin Lee66e5d962014-04-09 16:44:21 +01006128 *
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07006129 * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
6130 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00006131 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006132 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01006133 * @param packageName The name of the package to fetch restricted settings of.
6134 * @return {@link Bundle} of settings corresponding to what was set last time
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006135 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty
6136 * {@link Bundle} if no restrictions have been set.
6137 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01006138 * @see #setDelegatedScopes
6139 * @see #DELEGATION_APP_RESTRICTIONS
Robin Lee66e5d962014-04-09 16:44:21 +01006140 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07006141 @WorkerThread
Makoto Onuki408e8e42016-10-25 12:10:27 -07006142 public @NonNull Bundle getApplicationRestrictions(
6143 @Nullable ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006144 throwIfParentInstance("getApplicationRestrictions");
Robin Lee66e5d962014-04-09 16:44:21 +01006145 if (mService != null) {
6146 try {
Edman Anjosf9946772016-11-28 16:35:15 +01006147 return mService.getApplicationRestrictions(admin, mContext.getPackageName(),
6148 packageName);
Robin Lee66e5d962014-04-09 16:44:21 +01006149 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006150 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01006151 }
6152 }
6153 return null;
6154 }
Amith Yamasanibe465322014-04-24 13:45:17 -07006155
6156 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05006157 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07006158 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006159 * The calling device admin must be a profile or device owner; if it is not, a security
6160 * exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07006161 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006162 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6163 * @param key The key of the restriction. See the constants in {@link android.os.UserManager}
6164 * for the list of keys.
6165 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanibe465322014-04-24 13:45:17 -07006166 */
Robin Lee25e26452015-06-02 09:56:29 -07006167 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006168 throwIfParentInstance("addUserRestriction");
Amith Yamasanibe465322014-04-24 13:45:17 -07006169 if (mService != null) {
6170 try {
6171 mService.setUserRestriction(admin, key, true);
6172 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006173 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07006174 }
6175 }
6176 }
6177
6178 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05006179 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07006180 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006181 * The calling device admin must be a profile or device owner; if it is not, a security
6182 * exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07006183 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006184 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6185 * @param key The key of the restriction. See the constants in {@link android.os.UserManager}
6186 * for the list of keys.
6187 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanibe465322014-04-24 13:45:17 -07006188 */
Robin Lee25e26452015-06-02 09:56:29 -07006189 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006190 throwIfParentInstance("clearUserRestriction");
Amith Yamasanibe465322014-04-24 13:45:17 -07006191 if (mService != null) {
6192 try {
6193 mService.setUserRestriction(admin, key, false);
6194 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006195 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07006196 }
6197 }
6198 }
Adam Connors010cfd42014-04-16 12:48:13 +01006199
6200 /**
Makoto Onuki3a3092f2015-10-30 11:07:51 -07006201 * Called by a profile or device owner to get user restrictions set with
6202 * {@link #addUserRestriction(ComponentName, String)}.
6203 * <p>
6204 * The target user may have more restrictions set by the system or other device owner / profile
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006205 * owner. To get all the user restrictions currently set, use
Makoto Onuki3a3092f2015-10-30 11:07:51 -07006206 * {@link UserManager#getUserRestrictions()}.
6207 *
6208 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006209 * @throws SecurityException if {@code admin} is not a device or profile owner.
Makoto Onuki3a3092f2015-10-30 11:07:51 -07006210 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006211 public @NonNull Bundle getUserRestrictions(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006212 throwIfParentInstance("getUserRestrictions");
Makoto Onuki3a3092f2015-10-30 11:07:51 -07006213 Bundle ret = null;
6214 if (mService != null) {
6215 try {
Sudheer Shanka549b9692016-03-30 17:12:07 -07006216 ret = mService.getUserRestrictions(admin);
6217 } catch (RemoteException e) {
6218 throw e.rethrowFromSystemServer();
6219 }
6220 }
6221 return ret == null ? new Bundle() : ret;
6222 }
6223
6224 /**
phweiss73145f42017-01-17 19:06:38 +01006225 * Called by any app to display a support dialog when a feature was disabled by an admin.
6226 * This returns an intent that can be used with {@link Context#startActivity(Intent)} to
6227 * display the dialog. It will tell the user that the feature indicated by {@code restriction}
6228 * was disabled by an admin, and include a link for more information. The default content of
6229 * the dialog can be changed by the restricting admin via
6230 * {@link #setShortSupportMessage(ComponentName, CharSequence)}. If the restriction is not
6231 * set (i.e. the feature is available), then the return value will be {@code null}.
6232 * @param restriction Indicates for which feature the dialog should be displayed. Can be a
6233 * user restriction from {@link UserManager}, e.g.
6234 * {@link UserManager#DISALLOW_ADJUST_VOLUME}, or one of the constants
6235 * {@link #POLICY_DISABLE_CAMERA} or {@link #POLICY_DISABLE_SCREEN_CAPTURE}.
6236 * @return Intent An intent to be used to start the dialog-activity if the restriction is
6237 * set by an admin, or null if the restriction does not exist or no admin set it.
6238 */
6239 public Intent createAdminSupportIntent(@NonNull String restriction) {
6240 throwIfParentInstance("createAdminSupportIntent");
6241 if (mService != null) {
6242 try {
6243 return mService.createAdminSupportIntent(restriction);
6244 } catch (RemoteException e) {
6245 throw e.rethrowFromSystemServer();
6246 }
6247 }
6248 return null;
6249 }
6250
6251 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006252 * Hide or unhide packages. When a package is hidden it is unavailable for use, but the data and
6253 * actual package file remain. This function can be called by a device owner, profile owner, or
6254 * by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via
6255 * {@link #setDelegatedScopes}.
Julia Reynolds966881e2014-05-14 12:23:08 -04006256 *
Edman Anjos52088e42017-01-13 22:26:17 +01006257 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
6258 * {@code null} if the caller is a package access delegate.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07006259 * @param packageName The name of the package to hide or unhide.
6260 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006261 * unhidden.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07006262 * @return boolean Whether the hidden setting of the package was successfully updated.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006263 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01006264 * @see #setDelegatedScopes
6265 * @see #DELEGATION_PACKAGE_ACCESS
Julia Reynolds966881e2014-05-14 12:23:08 -04006266 */
Robin Lee25e26452015-06-02 09:56:29 -07006267 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07006268 boolean hidden) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006269 throwIfParentInstance("setApplicationHidden");
Julia Reynolds966881e2014-05-14 12:23:08 -04006270 if (mService != null) {
6271 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006272 return mService.setApplicationHidden(admin, mContext.getPackageName(), packageName,
6273 hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04006274 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006275 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04006276 }
6277 }
6278 return false;
6279 }
6280
6281 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006282 * Determine if a package is hidden. This function can be called by a device owner, profile
6283 * owner, or by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via
6284 * {@link #setDelegatedScopes}.
Julia Reynolds966881e2014-05-14 12:23:08 -04006285 *
Edman Anjos52088e42017-01-13 22:26:17 +01006286 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
6287 * {@code null} if the caller is a package access delegate.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07006288 * @param packageName The name of the package to retrieve the hidden status of.
6289 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006290 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01006291 * @see #setDelegatedScopes
6292 * @see #DELEGATION_PACKAGE_ACCESS
Julia Reynolds966881e2014-05-14 12:23:08 -04006293 */
Robin Lee25e26452015-06-02 09:56:29 -07006294 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006295 throwIfParentInstance("isApplicationHidden");
Julia Reynolds966881e2014-05-14 12:23:08 -04006296 if (mService != null) {
6297 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006298 return mService.isApplicationHidden(admin, mContext.getPackageName(), packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04006299 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006300 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04006301 }
6302 }
6303 return false;
6304 }
6305
6306 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006307 * Re-enable a system app that was disabled by default when the user was initialized. This
6308 * function can be called by a device owner, profile owner, or by a delegate given the
6309 * {@link #DELEGATION_ENABLE_SYSTEM_APP} scope via {@link #setDelegatedScopes}.
Adam Connors655be2a2014-07-14 09:01:25 +00006310 *
Edman Anjos52088e42017-01-13 22:26:17 +01006311 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
6312 * {@code null} if the caller is an enable system app delegate.
Makoto Onuki32b30572015-12-11 14:29:51 -08006313 * @param packageName The package to be re-enabled in the calling profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006314 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01006315 * @see #setDelegatedScopes
6316 * @see #DELEGATION_PACKAGE_ACCESS
Adam Connors655be2a2014-07-14 09:01:25 +00006317 */
Robin Lee25e26452015-06-02 09:56:29 -07006318 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006319 throwIfParentInstance("enableSystemApp");
Adam Connors655be2a2014-07-14 09:01:25 +00006320 if (mService != null) {
6321 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006322 mService.enableSystemApp(admin, mContext.getPackageName(), packageName);
Adam Connors655be2a2014-07-14 09:01:25 +00006323 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006324 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00006325 }
6326 }
6327 }
6328
6329 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006330 * Re-enable system apps by intent that were disabled by default when the user was initialized.
6331 * This function can be called by a device owner, profile owner, or by a delegate given the
6332 * {@link #DELEGATION_ENABLE_SYSTEM_APP} scope via {@link #setDelegatedScopes}.
Adam Connors655be2a2014-07-14 09:01:25 +00006333 *
Edman Anjos52088e42017-01-13 22:26:17 +01006334 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
6335 * {@code null} if the caller is an enable system app delegate.
Adam Connors655be2a2014-07-14 09:01:25 +00006336 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006337 * intent will be re-enabled in the calling profile.
Adam Connors655be2a2014-07-14 09:01:25 +00006338 * @return int The number of activities that matched the intent and were installed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006339 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01006340 * @see #setDelegatedScopes
6341 * @see #DELEGATION_PACKAGE_ACCESS
Adam Connors655be2a2014-07-14 09:01:25 +00006342 */
Robin Lee25e26452015-06-02 09:56:29 -07006343 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006344 throwIfParentInstance("enableSystemApp");
Adam Connors655be2a2014-07-14 09:01:25 +00006345 if (mService != null) {
6346 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006347 return mService.enableSystemAppWithIntent(admin, mContext.getPackageName(), intent);
Adam Connors655be2a2014-07-14 09:01:25 +00006348 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006349 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00006350 }
6351 }
6352 return 0;
6353 }
6354
6355 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00006356 * Called by a device owner or profile owner to disable account management for a specific type
6357 * of account.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006358 * <p>
6359 * The calling device admin must be a device owner or profile owner. If it is not, a security
6360 * exception will be thrown.
6361 * <p>
6362 * When account management is disabled for an account type, adding or removing an account of
6363 * that type will not be possible.
6364 * <p>
6365 * From {@link android.os.Build.VERSION_CODES#N} the profile or device owner can still use
Benjamin Franzb6c0ce42015-11-05 10:06:51 +00006366 * {@link android.accounts.AccountManager} APIs to add or remove accounts when account
6367 * management for a specific type is disabled.
6368 *
Sander Alewijnse650c3342014-05-08 18:00:50 +01006369 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6370 * @param accountType For which account management is disabled or enabled.
6371 * @param disabled The boolean indicating that account management will be disabled (true) or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006372 * enabled (false).
6373 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnse650c3342014-05-08 18:00:50 +01006374 */
Robin Lee25e26452015-06-02 09:56:29 -07006375 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01006376 boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006377 throwIfParentInstance("setAccountManagementDisabled");
Sander Alewijnse650c3342014-05-08 18:00:50 +01006378 if (mService != null) {
6379 try {
6380 mService.setAccountManagementDisabled(admin, accountType, disabled);
6381 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006382 throw e.rethrowFromSystemServer();
Sander Alewijnse650c3342014-05-08 18:00:50 +01006383 }
6384 }
6385 }
6386
6387 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01006388 * Gets the array of accounts for which account management is disabled by the profile owner.
6389 *
6390 * <p> Account management can be disabled/enabled by calling
6391 * {@link #setAccountManagementDisabled}.
6392 *
6393 * @return a list of account types for which account management has been disabled.
6394 *
6395 * @see #setAccountManagementDisabled
6396 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006397 public @Nullable String[] getAccountTypesWithManagementDisabled() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006398 throwIfParentInstance("getAccountTypesWithManagementDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07006399 return getAccountTypesWithManagementDisabledAsUser(myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01006400 }
6401
6402 /**
6403 * @see #getAccountTypesWithManagementDisabled()
6404 * @hide
6405 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006406 public @Nullable String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01006407 if (mService != null) {
6408 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01006409 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01006410 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006411 throw e.rethrowFromSystemServer();
Sander Alewijnse5c02db62014-05-07 10:46:57 +01006412 }
6413 }
6414
6415 return null;
6416 }
justinzhang511e0d82014-03-24 16:09:24 -04006417
6418 /**
Jason Monkd7b86212014-06-16 13:15:38 -04006419 * Sets which packages may enter lock task mode.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006420 * <p>
Esteban Talaverabdcada92017-02-01 14:20:06 +00006421 * Any packages that share uid with an allowed package will also be allowed to activate lock
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006422 * task. From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task
Esteban Talaverabdcada92017-02-01 14:20:06 +00006423 * package list results in locked tasks belonging to those packages to be finished.
6424 * <p>
6425 * This function can only be called by the device owner or by a profile owner of a user/profile
6426 * that is affiliated with the device owner user. See {@link #setAffiliationIds}. Any packages
6427 * set via this method will be cleared if the user becomes unaffiliated.
Jason Monkd7b86212014-06-16 13:15:38 -04006428 *
Jason Monkd7b86212014-06-16 13:15:38 -04006429 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04006430 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Esteban Talaverabdcada92017-02-01 14:20:06 +00006431 * @throws SecurityException if {@code admin} is not the device owner, or the profile owner of
6432 * an affiliated user or profile.
Jason Monkd7b86212014-06-16 13:15:38 -04006433 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00006434 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
6435 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04006436 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04006437 */
Esteban Talaverabdcada92017-02-01 14:20:06 +00006438 public void setLockTaskPackages(@NonNull ComponentName admin, @NonNull String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04006439 throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006440 throwIfParentInstance("setLockTaskPackages");
justinzhang511e0d82014-03-24 16:09:24 -04006441 if (mService != null) {
6442 try {
Jason Monk48aacba2014-08-13 16:29:08 -04006443 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04006444 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006445 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04006446 }
6447 }
6448 }
6449
6450 /**
Esteban Talaverabdcada92017-02-01 14:20:06 +00006451 * Returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04006452 *
Esteban Talaverabdcada92017-02-01 14:20:06 +00006453 * @throws SecurityException if {@code admin} is not the device owner, or the profile owner of
6454 * an affiliated user or profile.
6455 * @see #setLockTaskPackages
justinzhang511e0d82014-03-24 16:09:24 -04006456 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006457 public @NonNull String[] getLockTaskPackages(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006458 throwIfParentInstance("getLockTaskPackages");
justinzhang511e0d82014-03-24 16:09:24 -04006459 if (mService != null) {
6460 try {
Jason Monk48aacba2014-08-13 16:29:08 -04006461 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04006462 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006463 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04006464 }
6465 }
Esteban Talaverabdcada92017-02-01 14:20:06 +00006466 return new String[0];
justinzhang511e0d82014-03-24 16:09:24 -04006467 }
6468
6469 /**
6470 * This function lets the caller know whether the given component is allowed to start the
6471 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04006472 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04006473 */
Jason Monkd7b86212014-06-16 13:15:38 -04006474 public boolean isLockTaskPermitted(String pkg) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006475 throwIfParentInstance("isLockTaskPermitted");
justinzhang511e0d82014-03-24 16:09:24 -04006476 if (mService != null) {
6477 try {
Jason Monkd7b86212014-06-16 13:15:38 -04006478 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04006479 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006480 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04006481 }
6482 }
6483 return false;
6484 }
Julia Reynoldsda551652014-05-14 17:15:16 -04006485
6486 /**
Benjamin Franz482bb232017-06-23 13:48:20 +01006487 * Called by device owners to update {@link android.provider.Settings.Global} settings.
6488 * Validation that the value of the setting is in the correct form for the setting type should
6489 * be performed by the caller.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006490 * <p>
6491 * The settings that can be updated with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04006492 * <ul>
Benjamin Franz482bb232017-06-23 13:48:20 +01006493 * <li>{@link android.provider.Settings.Global#ADB_ENABLED}</li>
6494 * <li>{@link android.provider.Settings.Global#AUTO_TIME}</li>
6495 * <li>{@link android.provider.Settings.Global#AUTO_TIME_ZONE}</li>
6496 * <li>{@link android.provider.Settings.Global#DATA_ROAMING}</li>
6497 * <li>{@link android.provider.Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
6498 * <li>{@link android.provider.Settings.Global#WIFI_SLEEP_POLICY}</li>
6499 * <li>{@link android.provider.Settings.Global#STAY_ON_WHILE_PLUGGED_IN} This setting is only
6500 * available from {@link android.os.Build.VERSION_CODES#M} onwards and can only be set if
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006501 * {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
Benjamin Franz482bb232017-06-23 13:48:20 +01006502 * <li>{@link android.provider.Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li> This
6503 * setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04006504 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006505 * <p>
6506 * Changing the following settings has no effect as of {@link android.os.Build.VERSION_CODES#M}:
Esteban Talavera656fa7f2015-06-29 17:41:39 +01006507 * <ul>
Benjamin Franz482bb232017-06-23 13:48:20 +01006508 * <li>{@link android.provider.Settings.Global#BLUETOOTH_ON}. Use
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006509 * {@link android.bluetooth.BluetoothAdapter#enable()} and
6510 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
Benjamin Franz482bb232017-06-23 13:48:20 +01006511 * <li>{@link android.provider.Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
6512 * <li>{@link android.provider.Settings.Global#MODE_RINGER}. Use
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006513 * {@link android.media.AudioManager#setRingerMode(int)} instead.</li>
Benjamin Franz482bb232017-06-23 13:48:20 +01006514 * <li>{@link android.provider.Settings.Global#NETWORK_PREFERENCE}</li>
6515 * <li>{@link android.provider.Settings.Global#WIFI_ON}. Use
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006516 * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01006517 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04006518 *
6519 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6520 * @param setting The name of the setting to update.
6521 * @param value The value to update the setting to.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006522 * @throws SecurityException if {@code admin} is not a device owner.
Julia Reynoldsda551652014-05-14 17:15:16 -04006523 */
Robin Lee25e26452015-06-02 09:56:29 -07006524 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006525 throwIfParentInstance("setGlobalSetting");
Julia Reynoldsda551652014-05-14 17:15:16 -04006526 if (mService != null) {
6527 try {
6528 mService.setGlobalSetting(admin, setting, value);
6529 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006530 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04006531 }
6532 }
6533 }
6534
6535 /**
yuemingwe43cdf72017-10-12 16:52:11 +01006536 * Called by device owner to set the system wall clock time. This only takes effect if called
6537 * when {@link android.provider.Settings.Global#AUTO_TIME} is 0, otherwise {@code false} will be
6538 * returned.
6539 *
6540 * @param admin Which {@link DeviceAdminReceiver} this request is associated with
6541 * @param millis time in milliseconds since the Epoch
6542 * @return {@code true} if set time succeeded, {@code false} otherwise.
6543 * @throws SecurityException if {@code admin} is not a device owner.
6544 */
6545 public boolean setTime(@NonNull ComponentName admin, long millis) {
6546 throwIfParentInstance("setTime");
6547 if (mService != null) {
6548 try {
6549 return mService.setTime(admin, millis);
6550 } catch (RemoteException e) {
6551 throw e.rethrowFromSystemServer();
6552 }
6553 }
6554 return false;
6555 }
6556
6557 /**
6558 * Called by device owner to set the system's persistent default time zone. This only takes
6559 * effect if called when {@link android.provider.Settings.Global#AUTO_TIME_ZONE} is 0, otherwise
6560 * {@code false} will be returned.
6561 *
6562 * @see android.app.AlarmManager#setTimeZone(String)
6563 * @param admin Which {@link DeviceAdminReceiver} this request is associated with
6564 * @param timeZone one of the Olson ids from the list returned by
6565 * {@link java.util.TimeZone#getAvailableIDs}
6566 * @return {@code true} if set timezone succeeded, {@code false} otherwise.
6567 * @throws SecurityException if {@code admin} is not a device owner.
6568 */
6569 public boolean setTimeZone(@NonNull ComponentName admin, String timeZone) {
6570 throwIfParentInstance("setTimeZone");
6571 if (mService != null) {
6572 try {
6573 return mService.setTimeZone(admin, timeZone);
6574 } catch (RemoteException e) {
6575 throw e.rethrowFromSystemServer();
6576 }
6577 }
6578 return false;
6579 }
6580
6581 /**
Benjamin Franz482bb232017-06-23 13:48:20 +01006582 * Called by profile or device owners to update {@link android.provider.Settings.Secure}
6583 * settings. Validation that the value of the setting is in the correct form for the setting
6584 * type should be performed by the caller.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006585 * <p>
6586 * The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04006587 * <ul>
Benjamin Franz482bb232017-06-23 13:48:20 +01006588 * <li>{@link android.provider.Settings.Secure#DEFAULT_INPUT_METHOD}</li>
6589 * <li>{@link android.provider.Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04006590 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006591 * <p>
6592 * A device owner can additionally update the following settings:
Julia Reynolds82735bc2014-09-04 16:43:30 -04006593 * <ul>
Benjamin Franz482bb232017-06-23 13:48:20 +01006594 * <li>{@link android.provider.Settings.Secure#LOCATION_MODE}</li>
Julia Reynolds82735bc2014-09-04 16:43:30 -04006595 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006596 *
Suprabh Shukla0b1356f2017-02-21 14:33:50 -08006597 * <strong>Note: Starting from Android O, apps should no longer call this method with the
6598 * setting {@link android.provider.Settings.Secure#INSTALL_NON_MARKET_APPS}, which is
6599 * deprecated. Instead, device owners or profile owners should use the restriction
6600 * {@link UserManager#DISALLOW_INSTALL_UNKNOWN_SOURCES}.
6601 * If any app targeting {@link android.os.Build.VERSION_CODES#O} or higher calls this method
6602 * with {@link android.provider.Settings.Secure#INSTALL_NON_MARKET_APPS},
6603 * an {@link UnsupportedOperationException} is thrown.
6604 * </strong>
6605 *
Julia Reynoldsda551652014-05-14 17:15:16 -04006606 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6607 * @param setting The name of the setting to update.
6608 * @param value The value to update the setting to.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006609 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynoldsda551652014-05-14 17:15:16 -04006610 */
Robin Lee25e26452015-06-02 09:56:29 -07006611 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006612 throwIfParentInstance("setSecureSetting");
Julia Reynoldsda551652014-05-14 17:15:16 -04006613 if (mService != null) {
6614 try {
6615 mService.setSecureSetting(admin, setting, value);
6616 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006617 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04006618 }
6619 }
6620 }
6621
Amith Yamasanif20d6402014-05-24 15:34:37 -07006622 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006623 * Designates a specific service component as the provider for making permission requests of a
6624 * local or remote administrator of the user.
Amith Yamasanif20d6402014-05-24 15:34:37 -07006625 * <p/>
6626 * Only a profile owner can designate the restrictions provider.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006627 *
Amith Yamasanif20d6402014-05-24 15:34:37 -07006628 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07006629 * @param provider The component name of the service that implements
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006630 * {@link RestrictionsReceiver}. If this param is null, it removes the restrictions
6631 * provider previously assigned.
6632 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanif20d6402014-05-24 15:34:37 -07006633 */
Robin Lee25e26452015-06-02 09:56:29 -07006634 public void setRestrictionsProvider(@NonNull ComponentName admin,
6635 @Nullable ComponentName provider) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006636 throwIfParentInstance("setRestrictionsProvider");
Amith Yamasanif20d6402014-05-24 15:34:37 -07006637 if (mService != null) {
6638 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07006639 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07006640 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006641 throw re.rethrowFromSystemServer();
Amith Yamasanif20d6402014-05-24 15:34:37 -07006642 }
6643 }
6644 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04006645
6646 /**
6647 * Called by profile or device owners to set the master volume mute on or off.
Nicolas Prevotaef3ce22016-09-22 12:00:25 +01006648 * This has no effect when set on a managed profile.
Julia Reynolds4a21b252014-06-04 11:11:43 -04006649 *
6650 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6651 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006652 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds4a21b252014-06-04 11:11:43 -04006653 */
Robin Lee25e26452015-06-02 09:56:29 -07006654 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006655 throwIfParentInstance("setMasterVolumeMuted");
Julia Reynolds4a21b252014-06-04 11:11:43 -04006656 if (mService != null) {
6657 try {
6658 mService.setMasterVolumeMuted(admin, on);
6659 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006660 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04006661 }
6662 }
6663 }
6664
6665 /**
6666 * Called by profile or device owners to check whether the master volume mute is on or off.
6667 *
6668 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6669 * @return {@code true} if master volume is muted, {@code false} if it's not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006670 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds4a21b252014-06-04 11:11:43 -04006671 */
Robin Lee25e26452015-06-02 09:56:29 -07006672 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006673 throwIfParentInstance("isMasterVolumeMuted");
Julia Reynolds4a21b252014-06-04 11:11:43 -04006674 if (mService != null) {
6675 try {
6676 return mService.isMasterVolumeMuted(admin);
6677 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006678 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04006679 }
6680 }
6681 return false;
6682 }
Kenny Guyc13053b2014-05-29 14:17:17 +01006683
6684 /**
Edman Anjosa5f2fb12016-12-19 11:25:54 -08006685 * Change whether a user can uninstall a package. This function can be called by a device owner,
6686 * profile owner, or by a delegate given the {@link #DELEGATION_BLOCK_UNINSTALL} scope via
6687 * {@link #setDelegatedScopes}.
Kenny Guyc13053b2014-05-29 14:17:17 +01006688 *
Edman Anjosa5f2fb12016-12-19 11:25:54 -08006689 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
6690 * {@code null} if the caller is a block uninstall delegate.
Kenny Guyc13053b2014-05-29 14:17:17 +01006691 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01006692 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006693 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjosa5f2fb12016-12-19 11:25:54 -08006694 * @see #setDelegatedScopes
6695 * @see #DELEGATION_BLOCK_UNINSTALL
Kenny Guyc13053b2014-05-29 14:17:17 +01006696 */
Edman Anjosa5f2fb12016-12-19 11:25:54 -08006697 public void setUninstallBlocked(@Nullable ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01006698 boolean uninstallBlocked) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006699 throwIfParentInstance("setUninstallBlocked");
Kenny Guyc13053b2014-05-29 14:17:17 +01006700 if (mService != null) {
6701 try {
Edman Anjosa5f2fb12016-12-19 11:25:54 -08006702 mService.setUninstallBlocked(admin, mContext.getPackageName(), packageName,
6703 uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01006704 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006705 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01006706 }
6707 }
6708 }
6709
6710 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08006711 * Check whether the user has been blocked by device policy from uninstalling a package.
Rubin Xua97855b2014-11-07 05:41:00 +00006712 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00006713 * <p>
6714 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006715 * behavior of this API is changed such that passing {@code null} as the {@code admin} parameter
6716 * will return if any admin has blocked the uninstallation. Before L MR1, passing {@code null}
6717 * will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01006718 *
Robin Lee25e26452015-06-02 09:56:29 -07006719 * @param admin The name of the admin component whose blocking policy will be checked, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006720 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01006721 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00006722 * @return true if uninstallation is blocked.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006723 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyc13053b2014-05-29 14:17:17 +01006724 */
Robin Lee25e26452015-06-02 09:56:29 -07006725 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006726 throwIfParentInstance("isUninstallBlocked");
Kenny Guyc13053b2014-05-29 14:17:17 +01006727 if (mService != null) {
6728 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01006729 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01006730 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006731 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01006732 }
6733 }
6734 return false;
6735 }
Svetoslav976e8bd2014-07-16 15:12:03 -07006736
6737 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006738 * Called by the profile owner of a managed profile to enable widget providers from a given
6739 * package to be available in the parent profile. As a result the user will be able to add
6740 * widgets from the white-listed package running under the profile to a widget host which runs
6741 * under the parent profile, for example the home screen. Note that a package may have zero or
6742 * more provider components, where each component provides a different widget type.
Svetoslav976e8bd2014-07-16 15:12:03 -07006743 * <p>
6744 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07006745 *
6746 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6747 * @param packageName The package from which widget providers are white-listed.
6748 * @return Whether the package was added.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006749 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07006750 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
6751 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
6752 */
Robin Lee25e26452015-06-02 09:56:29 -07006753 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006754 throwIfParentInstance("addCrossProfileWidgetProvider");
Svetoslav976e8bd2014-07-16 15:12:03 -07006755 if (mService != null) {
6756 try {
6757 return mService.addCrossProfileWidgetProvider(admin, packageName);
6758 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006759 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07006760 }
6761 }
6762 return false;
6763 }
6764
6765 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07006766 * Called by the profile owner of a managed profile to disable widget providers from a given
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006767 * package to be available in the parent profile. For this method to take effect the package
6768 * should have been added via
6769 * {@link #addCrossProfileWidgetProvider( android.content.ComponentName, String)}.
Svetoslav976e8bd2014-07-16 15:12:03 -07006770 * <p>
6771 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07006772 *
6773 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006774 * @param packageName The package from which widget providers are no longer white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07006775 * @return Whether the package was removed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006776 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07006777 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
6778 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
6779 */
Esteban Talavera62399912016-01-11 15:37:55 +00006780 public boolean removeCrossProfileWidgetProvider(
6781 @NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006782 throwIfParentInstance("removeCrossProfileWidgetProvider");
Svetoslav976e8bd2014-07-16 15:12:03 -07006783 if (mService != null) {
6784 try {
6785 return mService.removeCrossProfileWidgetProvider(admin, packageName);
6786 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006787 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07006788 }
6789 }
6790 return false;
6791 }
6792
6793 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07006794 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07006795 * available in the parent profile.
6796 *
6797 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6798 * @return The white-listed package list.
Svetoslav976e8bd2014-07-16 15:12:03 -07006799 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
6800 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006801 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07006802 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006803 public @NonNull List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006804 throwIfParentInstance("getCrossProfileWidgetProviders");
Svetoslav976e8bd2014-07-16 15:12:03 -07006805 if (mService != null) {
6806 try {
6807 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
6808 if (providers != null) {
6809 return providers;
6810 }
6811 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006812 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07006813 }
6814 }
6815 return Collections.emptyList();
6816 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006817
6818 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08006819 * Called by profile or device owners to set the user's photo.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006820 *
6821 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6822 * @param icon the bitmap to set as the photo.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006823 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006824 */
Robin Lee25e26452015-06-02 09:56:29 -07006825 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006826 throwIfParentInstance("setUserIcon");
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006827 try {
6828 mService.setUserIcon(admin, icon);
6829 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006830 throw re.rethrowFromSystemServer();
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006831 }
6832 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04006833
6834 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01006835 * Called by device owners to set a local system update policy. When a new policy is set,
6836 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00006837 *
Robin Lee25e26452015-06-02 09:56:29 -07006838 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006839 * components in the device owner package can set system update policies and the most
6840 * recent policy takes effect.
Robin Lee25e26452015-06-02 09:56:29 -07006841 * @param policy the new policy, or {@code null} to clear the current policy.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006842 * @throws SecurityException if {@code admin} is not a device owner.
Rubin Xu5faad8e2015-04-20 17:43:48 +01006843 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00006844 */
Robin Lee25e26452015-06-02 09:56:29 -07006845 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006846 throwIfParentInstance("setSystemUpdatePolicy");
Rubin Xu8027a4f2015-03-10 17:52:37 +00006847 if (mService != null) {
6848 try {
Robin Lee25e26452015-06-02 09:56:29 -07006849 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00006850 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006851 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00006852 }
6853 }
6854 }
6855
6856 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01006857 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00006858 *
Robin Lee25e26452015-06-02 09:56:29 -07006859 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00006860 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006861 public @Nullable SystemUpdatePolicy getSystemUpdatePolicy() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006862 throwIfParentInstance("getSystemUpdatePolicy");
Rubin Xu8027a4f2015-03-10 17:52:37 +00006863 if (mService != null) {
6864 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01006865 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00006866 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006867 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00006868 }
6869 }
6870 return null;
6871 }
Benjamin Franze36087e2015-04-07 16:40:34 +01006872
6873 /**
6874 * Called by a device owner to disable the keyguard altogether.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006875 * <p>
6876 * Setting the keyguard to disabled has the same effect as choosing "None" as the screen lock
6877 * type. However, this call has no effect if a password, pin or pattern is currently set. If a
6878 * password, pin or pattern is set after the keyguard was disabled, the keyguard stops being
6879 * disabled.
Benjamin Franze36087e2015-04-07 16:40:34 +01006880 *
Benjamin Franz32a3bf32017-08-04 15:01:52 +01006881 * <p>
Benjamin Franz64affcb2017-09-01 13:47:22 +01006882 * As of {@link android.os.Build.VERSION_CODES#P}, this call also dismisses the
Benjamin Franz32a3bf32017-08-04 15:01:52 +01006883 * keyguard if it is currently shown.
6884 *
Benjamin Franze36087e2015-04-07 16:40:34 +01006885 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01006886 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01006887 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006888 * place. {@code true} otherwise.
6889 * @throws SecurityException if {@code admin} is not a device owner.
Benjamin Franze36087e2015-04-07 16:40:34 +01006890 */
Robin Lee25e26452015-06-02 09:56:29 -07006891 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006892 throwIfParentInstance("setKeyguardDisabled");
Benjamin Franze36087e2015-04-07 16:40:34 +01006893 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01006894 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01006895 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006896 throw re.rethrowFromSystemServer();
Benjamin Franze36087e2015-04-07 16:40:34 +01006897 }
6898 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00006899
6900 /**
Benjamin Franzbece8062015-05-06 12:14:31 +01006901 * Called by device owner to disable the status bar. Disabling the status bar blocks
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006902 * notifications, quick settings and other screen overlays that allow escaping from a single use
6903 * device.
Benjamin Franzea2ec972015-03-16 17:18:09 +00006904 *
6905 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01006906 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006907 * @return {@code false} if attempting to disable the status bar failed. {@code true} otherwise.
6908 * @throws SecurityException if {@code admin} is not a device owner.
Benjamin Franzea2ec972015-03-16 17:18:09 +00006909 */
Robin Lee25e26452015-06-02 09:56:29 -07006910 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006911 throwIfParentInstance("setStatusBarDisabled");
Benjamin Franzea2ec972015-03-16 17:18:09 +00006912 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01006913 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00006914 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006915 throw re.rethrowFromSystemServer();
Benjamin Franzea2ec972015-03-16 17:18:09 +00006916 }
6917 }
Rubin Xudc105cc2015-04-14 23:38:01 +01006918
6919 /**
Charles Hedea0c3b2017-01-13 10:04:12 +00006920 * Called by the system update service to notify device and profile owners of pending system
6921 * updates.
Rubin Xudc105cc2015-04-14 23:38:01 +01006922 *
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06006923 * This method should only be used when it is unknown whether the pending system
Charles Hedea0c3b2017-01-13 10:04:12 +00006924 * update is a security patch. Otherwise, use
6925 * {@link #notifyPendingSystemUpdate(long, boolean)}.
6926 *
6927 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()}
6928 * indicating when the current pending update was first available. {@code -1} if no
6929 * update is available.
6930 * @see #notifyPendingSystemUpdate(long, boolean)
Rubin Xudc105cc2015-04-14 23:38:01 +01006931 * @hide
6932 */
6933 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06006934 @RequiresPermission(android.Manifest.permission.NOTIFY_PENDING_SYSTEM_UPDATE)
Rubin Xudc105cc2015-04-14 23:38:01 +01006935 public void notifyPendingSystemUpdate(long updateReceivedTime) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006936 throwIfParentInstance("notifyPendingSystemUpdate");
Rubin Xudc105cc2015-04-14 23:38:01 +01006937 if (mService != null) {
6938 try {
Charles Hedea0c3b2017-01-13 10:04:12 +00006939 mService.notifyPendingSystemUpdate(SystemUpdateInfo.of(updateReceivedTime));
6940 } catch (RemoteException re) {
6941 throw re.rethrowFromSystemServer();
6942 }
6943 }
6944 }
6945
6946 /**
6947 * Called by the system update service to notify device and profile owners of pending system
6948 * updates.
6949 *
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06006950 * This method should be used instead of {@link #notifyPendingSystemUpdate(long)}
Charles Hedea0c3b2017-01-13 10:04:12 +00006951 * when it is known whether the pending system update is a security patch.
6952 *
6953 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()}
6954 * indicating when the current pending update was first available. {@code -1} if no
6955 * update is available.
6956 * @param isSecurityPatch {@code true} if this system update is purely a security patch;
6957 * {@code false} if not.
6958 * @see #notifyPendingSystemUpdate(long)
6959 * @hide
6960 */
6961 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06006962 @RequiresPermission(android.Manifest.permission.NOTIFY_PENDING_SYSTEM_UPDATE)
Charles Hedea0c3b2017-01-13 10:04:12 +00006963 public void notifyPendingSystemUpdate(long updateReceivedTime, boolean isSecurityPatch) {
6964 throwIfParentInstance("notifyPendingSystemUpdate");
6965 if (mService != null) {
6966 try {
6967 mService.notifyPendingSystemUpdate(SystemUpdateInfo.of(updateReceivedTime,
6968 isSecurityPatch));
Rubin Xudc105cc2015-04-14 23:38:01 +01006969 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006970 throw re.rethrowFromSystemServer();
Rubin Xudc105cc2015-04-14 23:38:01 +01006971 }
6972 }
6973 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04006974
6975 /**
Pavel Grafovd65799e2016-12-02 11:21:45 +00006976 * Called by device or profile owners to get information about a pending system update.
6977 *
6978 * @param admin Which profile or device owner this request is associated with.
6979 * @return Information about a pending system update or {@code null} if no update pending.
6980 * @throws SecurityException if {@code admin} is not a device or profile owner.
6981 * @see DeviceAdminReceiver#onSystemUpdatePending(Context, Intent, long)
6982 */
6983 public @Nullable SystemUpdateInfo getPendingSystemUpdate(@NonNull ComponentName admin) {
6984 throwIfParentInstance("getPendingSystemUpdate");
6985 try {
6986 return mService.getPendingSystemUpdate(admin);
6987 } catch (RemoteException re) {
6988 throw re.rethrowFromSystemServer();
6989 }
6990 }
6991
6992 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006993 * Set the default response for future runtime permission requests by applications. This
6994 * function can be called by a device owner, profile owner, or by a delegate given the
6995 * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}.
6996 * The policy can allow for normal operation which prompts the user to grant a permission, or
6997 * can allow automatic granting or denying of runtime permission requests by an application.
6998 * This also applies to new permissions declared by app updates. When a permission is denied or
6999 * granted this way, the effect is equivalent to setting the permission * grant state via
7000 * {@link #setPermissionGrantState}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007001 * <p/>
7002 * As this policy only acts on runtime permission requests, it only applies to applications
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07007003 * built with a {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Benjamin Franz45dd6662015-07-08 14:24:14 +01007004 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07007005 * @param admin Which profile or device owner this request is associated with.
7006 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007007 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
7008 * @throws SecurityException if {@code admin} is not a device or profile owner.
Benjamin Franz45dd6662015-07-08 14:24:14 +01007009 * @see #setPermissionGrantState
Edman Anjos52088e42017-01-13 22:26:17 +01007010 * @see #setDelegatedScopes
7011 * @see #DELEGATION_PERMISSION_GRANT
Amith Yamasanid49489b2015-04-28 14:00:26 -07007012 */
Robin Lee25e26452015-06-02 09:56:29 -07007013 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007014 throwIfParentInstance("setPermissionPolicy");
Amith Yamasanid49489b2015-04-28 14:00:26 -07007015 try {
Edman Anjos52088e42017-01-13 22:26:17 +01007016 mService.setPermissionPolicy(admin, mContext.getPackageName(), policy);
Amith Yamasanid49489b2015-04-28 14:00:26 -07007017 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007018 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07007019 }
7020 }
7021
7022 /**
7023 * Returns the current runtime permission policy set by the device or profile owner. The
7024 * default is {@link #PERMISSION_POLICY_PROMPT}.
Edman Anjos52088e42017-01-13 22:26:17 +01007025 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07007026 * @param admin Which profile or device owner this request is associated with.
7027 * @return the current policy for future permission requests.
7028 */
Esteban Talavera28b95702015-06-24 15:23:42 +01007029 public int getPermissionPolicy(ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007030 throwIfParentInstance("getPermissionPolicy");
Amith Yamasanid49489b2015-04-28 14:00:26 -07007031 try {
7032 return mService.getPermissionPolicy(admin);
7033 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007034 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07007035 }
7036 }
7037
7038 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007039 * Sets the grant state of a runtime permission for a specific application. The state can be
7040 * {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it through the UI,
7041 * {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission is denied and the user
7042 * cannot manage it through the UI, and {@link #PERMISSION_GRANT_STATE_GRANTED granted} in which
7043 * the permission is granted and the user cannot manage it through the UI. This might affect all
7044 * permissions in a group that the runtime permission belongs to. This method can only be called
Edman Anjos52088e42017-01-13 22:26:17 +01007045 * by a profile owner, device owner, or a delegate given the
7046 * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007047 * <p/>
7048 * Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not revoke
7049 * the permission. It retains the previous grant, if any.
7050 * <p/>
7051 * Permissions can be granted or revoked only for applications built with a
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07007052 * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07007053 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07007054 * @param admin Which profile or device owner this request is associated with.
7055 * @param packageName The application to grant or revoke a permission to.
7056 * @param permission The permission to grant or revoke.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007057 * @param grantState The permission grant state which is one of
7058 * {@link #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
7059 * {@link #PERMISSION_GRANT_STATE_GRANTED},
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07007060 * @return whether the permission was successfully granted or revoked.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007061 * @throws SecurityException if {@code admin} is not a device or profile owner.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07007062 * @see #PERMISSION_GRANT_STATE_DENIED
7063 * @see #PERMISSION_GRANT_STATE_DEFAULT
7064 * @see #PERMISSION_GRANT_STATE_GRANTED
Edman Anjos52088e42017-01-13 22:26:17 +01007065 * @see #setDelegatedScopes
7066 * @see #DELEGATION_PERMISSION_GRANT
Amith Yamasanid49489b2015-04-28 14:00:26 -07007067 */
Robin Lee25e26452015-06-02 09:56:29 -07007068 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07007069 String permission, int grantState) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007070 throwIfParentInstance("setPermissionGrantState");
Amith Yamasanid49489b2015-04-28 14:00:26 -07007071 try {
Edman Anjos52088e42017-01-13 22:26:17 +01007072 return mService.setPermissionGrantState(admin, mContext.getPackageName(), packageName,
7073 permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07007074 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007075 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07007076 }
7077 }
Amith Yamasani184b3752015-05-22 13:00:51 -07007078
7079 /**
Edman Anjos52088e42017-01-13 22:26:17 +01007080 * Returns the current grant state of a runtime permission for a specific application. This
7081 * function can be called by a device owner, profile owner, or by a delegate given the
7082 * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}.
Amith Yamasani184b3752015-05-22 13:00:51 -07007083 *
Edman Anjos52088e42017-01-13 22:26:17 +01007084 * @param admin Which profile or device owner this request is associated with, or {@code null}
7085 * if the caller is a permission grant delegate.
Amith Yamasani184b3752015-05-22 13:00:51 -07007086 * @param packageName The application to check the grant state for.
7087 * @param permission The permission to check for.
7088 * @return the current grant state specified by device policy. If the profile or device owner
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007089 * has not set a grant state, the return value is
7090 * {@link #PERMISSION_GRANT_STATE_DEFAULT}. This does not indicate whether or not the
7091 * permission is currently granted for the package.
7092 * <p/>
7093 * If a grant state was set by the profile or device owner, then the return value will
7094 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or
7095 * {@link #PERMISSION_GRANT_STATE_GRANTED}, which indicates if the permission is
7096 * currently denied or granted.
7097 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasani184b3752015-05-22 13:00:51 -07007098 * @see #setPermissionGrantState(ComponentName, String, String, int)
7099 * @see PackageManager#checkPermission(String, String)
Edman Anjos52088e42017-01-13 22:26:17 +01007100 * @see #setDelegatedScopes
7101 * @see #DELEGATION_PERMISSION_GRANT
Amith Yamasani184b3752015-05-22 13:00:51 -07007102 */
Bartosz Fabianowski4b0624f2017-01-16 11:47:28 +01007103 public int getPermissionGrantState(@Nullable ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07007104 String permission) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007105 throwIfParentInstance("getPermissionGrantState");
Amith Yamasani184b3752015-05-22 13:00:51 -07007106 try {
Edman Anjos52088e42017-01-13 22:26:17 +01007107 return mService.getPermissionGrantState(admin, mContext.getPackageName(), packageName,
7108 permission);
Amith Yamasani184b3752015-05-22 13:00:51 -07007109 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007110 throw re.rethrowFromSystemServer();
Amith Yamasani184b3752015-05-22 13:00:51 -07007111 }
7112 }
Nicolas Prevot07387fe2015-10-30 17:53:30 +00007113
7114 /**
Esteban Talavera01576862016-12-15 11:16:44 +00007115 * Returns whether it is possible for the caller to initiate provisioning of a managed profile
7116 * or device, setting itself as the device or profile owner.
7117 *
Nicolas Prevot07387fe2015-10-30 17:53:30 +00007118 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
7119 * {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Esteban Talavera01576862016-12-15 11:16:44 +00007120 * @return whether provisioning a managed profile or device is possible.
Nicolas Prevot07387fe2015-10-30 17:53:30 +00007121 * @throws IllegalArgumentException if the supplied action is not valid.
7122 */
Esteban Talavera01576862016-12-15 11:16:44 +00007123 public boolean isProvisioningAllowed(@NonNull String action) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007124 throwIfParentInstance("isProvisioningAllowed");
Nicolas Prevot07387fe2015-10-30 17:53:30 +00007125 try {
Esteban Talavera01576862016-12-15 11:16:44 +00007126 return mService.isProvisioningAllowed(action, mContext.getPackageName());
Nicolas Prevot07387fe2015-10-30 17:53:30 +00007127 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007128 throw re.rethrowFromSystemServer();
Nicolas Prevot07387fe2015-10-30 17:53:30 +00007129 }
7130 }
Mahaver Chopra15a46b02015-11-11 14:54:35 +00007131
7132 /**
Esteban Talavera01576862016-12-15 11:16:44 +00007133 * Checks whether it is possible to initiate provisioning a managed device,
7134 * profile or user, setting the given package as owner.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00007135 *
7136 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
7137 * {@link #ACTION_PROVISION_MANAGED_PROFILE},
7138 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE},
7139 * {@link #ACTION_PROVISION_MANAGED_USER}
Esteban Talavera01576862016-12-15 11:16:44 +00007140 * @param packageName The package of the component that would be set as device, user, or profile
7141 * owner.
7142 * @return A {@link ProvisioningPreCondition} value indicating whether provisioning is allowed.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00007143 * @hide
7144 */
Esteban Talavera01576862016-12-15 11:16:44 +00007145 public @ProvisioningPreCondition int checkProvisioningPreCondition(
7146 String action, @NonNull String packageName) {
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00007147 try {
Esteban Talavera01576862016-12-15 11:16:44 +00007148 return mService.checkProvisioningPreCondition(action, packageName);
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00007149 } catch (RemoteException re) {
7150 throw re.rethrowFromSystemServer();
7151 }
7152 }
7153
7154 /**
Mahaver Chopra15a46b02015-11-11 14:54:35 +00007155 * Return if this user is a managed profile of another user. An admin can become the profile
7156 * owner of a managed profile with {@link #ACTION_PROVISION_MANAGED_PROFILE} and of a managed
Kenny Guyffa38402016-03-31 16:40:57 +01007157 * user with {@link #createAndManageUser}
Mahaver Chopra15a46b02015-11-11 14:54:35 +00007158 * @param admin Which profile owner this request is associated with.
7159 * @return if this user is a managed profile of another user.
7160 */
7161 public boolean isManagedProfile(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007162 throwIfParentInstance("isManagedProfile");
Mahaver Chopra15a46b02015-11-11 14:54:35 +00007163 try {
7164 return mService.isManagedProfile(admin);
7165 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007166 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00007167 }
7168 }
7169
7170 /**
7171 * @hide
7172 * Return if this user is a system-only user. An admin can manage a device from a system only
7173 * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}.
7174 * @param admin Which device owner this request is associated with.
7175 * @return if this user is a system-only user.
7176 */
7177 public boolean isSystemOnlyUser(@NonNull ComponentName admin) {
7178 try {
7179 return mService.isSystemOnlyUser(admin);
7180 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007181 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00007182 }
7183 }
Makoto Onukia31ebbc2015-11-23 17:15:21 -08007184
7185 /**
7186 * Called by device owner to get the MAC address of the Wi-Fi device.
7187 *
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08007188 * @param admin Which device owner this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007189 * @return the MAC address of the Wi-Fi device, or null when the information is not available.
7190 * (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.)
7191 * <p>
7192 * The address will be in the {@code XX:XX:XX:XX:XX:XX} format.
7193 * @throws SecurityException if {@code admin} is not a device owner.
Makoto Onukia31ebbc2015-11-23 17:15:21 -08007194 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007195 public @Nullable String getWifiMacAddress(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007196 throwIfParentInstance("getWifiMacAddress");
Makoto Onukia31ebbc2015-11-23 17:15:21 -08007197 try {
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08007198 return mService.getWifiMacAddress(admin);
Makoto Onukia31ebbc2015-11-23 17:15:21 -08007199 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007200 throw re.rethrowFromSystemServer();
Makoto Onukia31ebbc2015-11-23 17:15:21 -08007201 }
7202 }
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00007203
7204 /**
Mahaver Chopra1216ae52016-03-11 15:39:48 +00007205 * Called by device owner to reboot the device. If there is an ongoing call on the device,
7206 * throws an {@link IllegalStateException}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007207 * @param admin Which device owner the request is associated with.
Mahaver Chopra1216ae52016-03-11 15:39:48 +00007208 * @throws IllegalStateException if device has an ongoing call.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007209 * @throws SecurityException if {@code admin} is not a device owner.
Mahaver Chopra1216ae52016-03-11 15:39:48 +00007210 * @see TelephonyManager#CALL_STATE_IDLE
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00007211 */
7212 public void reboot(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007213 throwIfParentInstance("reboot");
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00007214 try {
7215 mService.reboot(admin);
7216 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007217 throw re.rethrowFromSystemServer();
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00007218 }
7219 }
Kenny Guy06de4e72015-12-22 12:07:39 +00007220
7221 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007222 * Called by a device admin to set the short support message. This will be displayed to the user
7223 * in settings screens where funtionality has been disabled by the admin. The message should be
7224 * limited to a short statement such as "This setting is disabled by your administrator. Contact
7225 * someone@example.com for support." If the message is longer than 200 characters it may be
7226 * truncated.
7227 * <p>
7228 * If the short support message needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007229 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
7230 * and set a new version of this string accordingly.
7231 *
Kenny Guy06de4e72015-12-22 12:07:39 +00007232 * @see #setLongSupportMessage
Kenny Guy06de4e72015-12-22 12:07:39 +00007233 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007234 * @param message Short message to be displayed to the user in settings or null to clear the
7235 * existing message.
7236 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00007237 */
7238 public void setShortSupportMessage(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007239 @Nullable CharSequence message) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007240 throwIfParentInstance("setShortSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00007241 if (mService != null) {
7242 try {
7243 mService.setShortSupportMessage(admin, message);
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 }
7249
7250 /**
7251 * Called by a device admin to get the short support message.
7252 *
7253 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007254 * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)} or
7255 * null if no message has been set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007256 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00007257 */
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007258 public CharSequence getShortSupportMessage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007259 throwIfParentInstance("getShortSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00007260 if (mService != null) {
7261 try {
7262 return mService.getShortSupportMessage(admin);
7263 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007264 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00007265 }
7266 }
7267 return null;
7268 }
7269
7270 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007271 * Called by a device admin to set the long support message. This will be displayed to the user
7272 * in the device administators settings screen.
7273 * <p>
7274 * If the long support message needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007275 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
7276 * and set a new version of this string accordingly.
7277 *
Kenny Guy06de4e72015-12-22 12:07:39 +00007278 * @see #setShortSupportMessage
Kenny Guy06de4e72015-12-22 12:07:39 +00007279 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007280 * @param message Long message to be displayed to the user in settings or null to clear the
7281 * existing message.
7282 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00007283 */
7284 public void setLongSupportMessage(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007285 @Nullable CharSequence message) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007286 throwIfParentInstance("setLongSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00007287 if (mService != null) {
7288 try {
7289 mService.setLongSupportMessage(admin, message);
7290 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007291 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00007292 }
7293 }
7294 }
7295
7296 /**
7297 * Called by a device admin to get the long support message.
7298 *
7299 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007300 * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)} or
7301 * null if no message has been set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007302 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00007303 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007304 public @Nullable CharSequence getLongSupportMessage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007305 throwIfParentInstance("getLongSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00007306 if (mService != null) {
7307 try {
7308 return mService.getLongSupportMessage(admin);
7309 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007310 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00007311 }
7312 }
7313 return null;
7314 }
7315
7316 /**
7317 * Called by the system to get the short support message.
7318 *
7319 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7320 * @param userHandle user id the admin is running as.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007321 * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)}
Kenny Guy06de4e72015-12-22 12:07:39 +00007322 *
7323 * @hide
7324 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007325 public @Nullable CharSequence getShortSupportMessageForUser(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007326 int userHandle) {
Kenny Guy06de4e72015-12-22 12:07:39 +00007327 if (mService != null) {
7328 try {
7329 return mService.getShortSupportMessageForUser(admin, userHandle);
7330 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007331 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00007332 }
7333 }
7334 return null;
7335 }
7336
7337
7338 /**
7339 * Called by the system to get the long support message.
7340 *
7341 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7342 * @param userHandle user id the admin is running as.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007343 * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)}
Kenny Guy06de4e72015-12-22 12:07:39 +00007344 *
7345 * @hide
7346 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007347 public @Nullable CharSequence getLongSupportMessageForUser(
7348 @NonNull ComponentName admin, int userHandle) {
Kenny Guy06de4e72015-12-22 12:07:39 +00007349 if (mService != null) {
7350 try {
7351 return mService.getLongSupportMessageForUser(admin, userHandle);
7352 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007353 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00007354 }
7355 }
7356 return null;
7357 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00007358
7359 /**
Esteban Talavera62399912016-01-11 15:37:55 +00007360 * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager}
7361 * whose calls act on the parent profile.
Benjamin Franz66b45f02016-04-05 19:12:39 +01007362 *
7363 * <p>The following methods are supported for the parent instance, all other methods will
7364 * throw a SecurityException when called on the parent instance:
7365 * <ul>
7366 * <li>{@link #getPasswordQuality}</li>
7367 * <li>{@link #setPasswordQuality}</li>
7368 * <li>{@link #getPasswordMinimumLength}</li>
7369 * <li>{@link #setPasswordMinimumLength}</li>
7370 * <li>{@link #getPasswordMinimumUpperCase}</li>
7371 * <li>{@link #setPasswordMinimumUpperCase}</li>
7372 * <li>{@link #getPasswordMinimumLowerCase}</li>
7373 * <li>{@link #setPasswordMinimumLowerCase}</li>
7374 * <li>{@link #getPasswordMinimumLetters}</li>
7375 * <li>{@link #setPasswordMinimumLetters}</li>
7376 * <li>{@link #getPasswordMinimumNumeric}</li>
7377 * <li>{@link #setPasswordMinimumNumeric}</li>
7378 * <li>{@link #getPasswordMinimumSymbols}</li>
7379 * <li>{@link #setPasswordMinimumSymbols}</li>
7380 * <li>{@link #getPasswordMinimumNonLetter}</li>
7381 * <li>{@link #setPasswordMinimumNonLetter}</li>
7382 * <li>{@link #getPasswordHistoryLength}</li>
7383 * <li>{@link #setPasswordHistoryLength}</li>
7384 * <li>{@link #getPasswordExpirationTimeout}</li>
7385 * <li>{@link #setPasswordExpirationTimeout}</li>
7386 * <li>{@link #getPasswordExpiration}</li>
Charles He8c760562016-10-25 16:36:53 +01007387 * <li>{@link #getPasswordMaximumLength}</li>
Benjamin Franz66b45f02016-04-05 19:12:39 +01007388 * <li>{@link #isActivePasswordSufficient}</li>
7389 * <li>{@link #getCurrentFailedPasswordAttempts}</li>
7390 * <li>{@link #getMaximumFailedPasswordsForWipe}</li>
7391 * <li>{@link #setMaximumFailedPasswordsForWipe}</li>
7392 * <li>{@link #getMaximumTimeToLock}</li>
7393 * <li>{@link #setMaximumTimeToLock}</li>
7394 * <li>{@link #lockNow}</li>
7395 * <li>{@link #getKeyguardDisabledFeatures}</li>
7396 * <li>{@link #setKeyguardDisabledFeatures}</li>
7397 * <li>{@link #getTrustAgentConfiguration}</li>
7398 * <li>{@link #setTrustAgentConfiguration}</li>
Michal Karpinskia20d8bb2016-11-23 12:09:08 +00007399 * <li>{@link #getRequiredStrongAuthTimeout}</li>
7400 * <li>{@link #setRequiredStrongAuthTimeout}</li>
Benjamin Franz66b45f02016-04-05 19:12:39 +01007401 * </ul>
Clara Bayarri3e826ef2015-12-14 17:51:22 +00007402 *
7403 * @return a new instance of {@link DevicePolicyManager} that acts on the parent profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007404 * @throws SecurityException if {@code admin} is not a profile owner.
Clara Bayarri3e826ef2015-12-14 17:51:22 +00007405 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007406 public @NonNull DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007407 throwIfParentInstance("getParentProfileInstance");
Clara Bayarri3e826ef2015-12-14 17:51:22 +00007408 try {
7409 if (!mService.isManagedProfile(admin)) {
7410 throw new SecurityException("The current user does not have a parent profile.");
7411 }
Jeff Sharkey49ca5292016-05-10 12:54:45 -06007412 return new DevicePolicyManager(mContext, mService, true);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007413 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007414 throw e.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007415 }
7416 }
7417
7418 /**
Esteban Talaverad36dd152016-12-15 08:51:45 +00007419 * Called by device owner to control the security logging feature.
Michal Karpinski6235a942016-03-15 12:07:23 +00007420 *
7421 * <p> Security logs contain various information intended for security auditing purposes.
7422 * See {@link SecurityEvent} for details.
7423 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00007424 * <p><strong>Note:</strong> The device owner won't be able to retrieve security logs if there
7425 * are unaffiliated secondary users or profiles on the device, regardless of whether the
7426 * feature is enabled. Logs will be discarded if the internal buffer fills up while waiting for
7427 * all users to become affiliated. Therefore it's recommended that affiliation ids are set for
7428 * new users as soon as possible after provisioning via {@link #setAffiliationIds}.
Michal Karpinskib58e4962016-03-01 14:55:10 +00007429 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007430 * @param admin Which device owner this request is associated with.
Michal Karpinski6235a942016-03-15 12:07:23 +00007431 * @param enabled whether security logging should be enabled or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007432 * @throws SecurityException if {@code admin} is not a device owner.
Michal Karpinski6235a942016-03-15 12:07:23 +00007433 * @see #retrieveSecurityLogs
7434 */
7435 public void setSecurityLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007436 throwIfParentInstance("setSecurityLoggingEnabled");
Michal Karpinski6235a942016-03-15 12:07:23 +00007437 try {
7438 mService.setSecurityLoggingEnabled(admin, enabled);
7439 } catch (RemoteException re) {
7440 throw re.rethrowFromSystemServer();
7441 }
7442 }
7443
7444 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00007445 * Return whether security logging is enabled or not by the device owner.
7446 *
7447 * <p>Can only be called by the device owner, otherwise a {@link SecurityException} will be
7448 * thrown.
7449 *
7450 * @param admin Which device owner this request is associated with.
7451 * @return {@code true} if security logging is enabled by device owner, {@code false} otherwise.
7452 * @throws SecurityException if {@code admin} is not a device owner.
7453 */
Bartosz Fabianowski0ec00002017-03-24 14:22:24 +01007454 public boolean isSecurityLoggingEnabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007455 throwIfParentInstance("isSecurityLoggingEnabled");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007456 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00007457 return mService.isSecurityLoggingEnabled(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007458 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007459 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007460 }
7461 }
7462
7463 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00007464 * Called by device owner to retrieve all new security logging entries since the last call to
7465 * this API after device boots.
7466 *
7467 * <p> Access to the logs is rate limited and it will only return new logs after the device
7468 * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}.
7469 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00007470 * <p>If there is any other user or profile on the device, it must be affiliated with the
7471 * device owner. Otherwise a {@link SecurityException} will be thrown. See
7472 * {@link #setAffiliationIds}
Michal Karpinskib58e4962016-03-01 14:55:10 +00007473 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007474 * @param admin Which device owner this request is associated with.
Michal Karpinski6235a942016-03-15 12:07:23 +00007475 * @return the new batch of security logs which is a list of {@link SecurityEvent},
7476 * or {@code null} if rate limitation is exceeded or if logging is currently disabled.
Esteban Talaverad36dd152016-12-15 08:51:45 +00007477 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
7478 * profile or secondary user that is not affiliated with the device owner user.
7479 * @see DeviceAdminReceiver#onSecurityLogsAvailable
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007480 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007481 public @Nullable List<SecurityEvent> retrieveSecurityLogs(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007482 throwIfParentInstance("retrieveSecurityLogs");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007483 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00007484 ParceledListSlice<SecurityEvent> list = mService.retrieveSecurityLogs(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007485 if (list != null) {
7486 return list.getList();
7487 } else {
7488 // Rate limit exceeded.
7489 return null;
7490 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00007491 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007492 throw re.rethrowFromSystemServer();
Clara Bayarri3e826ef2015-12-14 17:51:22 +00007493 }
7494 }
Benjamin Franz59720bb2016-01-18 15:26:11 +00007495
7496 /**
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00007497 * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent
7498 * profile.
7499 *
7500 * @hide
7501 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007502 public @NonNull DevicePolicyManager getParentProfileInstance(UserInfo uInfo) {
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00007503 mContext.checkSelfPermission(
7504 android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS);
7505 if (!uInfo.isManagedProfile()) {
7506 throw new SecurityException("The user " + uInfo.id
7507 + " does not have a parent profile.");
7508 }
Jeff Sharkey49ca5292016-05-10 12:54:45 -06007509 return new DevicePolicyManager(mContext, mService, true);
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00007510 }
7511
7512 /**
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007513 * Called by device owners to retrieve device logs from before the device's last reboot.
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007514 * <p>
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01007515 * <strong> This API is not supported on all devices. Calling this API on unsupported devices
7516 * will result in {@code null} being returned. The device logs are retrieved from a RAM region
7517 * which is not guaranteed to be corruption-free during power cycles, as a result be cautious
7518 * about data corruption when parsing. </strong>
Esteban Talaverad36dd152016-12-15 08:51:45 +00007519 *
7520 * <p>If there is any other user or profile on the device, it must be affiliated with the
7521 * device owner. Otherwise a {@link SecurityException} will be thrown. See
7522 * {@link #setAffiliationIds}
Michal Karpinskib58e4962016-03-01 14:55:10 +00007523 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007524 * @param admin Which device owner this request is associated with.
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01007525 * @return Device logs from before the latest reboot of the system, or {@code null} if this API
7526 * is not supported on the device.
Esteban Talaverad36dd152016-12-15 08:51:45 +00007527 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
7528 * profile or secondary user that is not affiliated with the device owner user.
7529 * @see #retrieveSecurityLogs
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007530 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007531 public @Nullable List<SecurityEvent> retrievePreRebootSecurityLogs(
7532 @NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007533 throwIfParentInstance("retrievePreRebootSecurityLogs");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007534 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00007535 ParceledListSlice<SecurityEvent> list = mService.retrievePreRebootSecurityLogs(admin);
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01007536 if (list != null) {
7537 return list.getList();
7538 } else {
7539 return null;
7540 }
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007541 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007542 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007543 }
7544 }
7545
7546 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007547 * Called by a profile owner of a managed profile to set the color used for customization. This
7548 * color is used as background color of the confirm credentials screen for that user. The
Clara Bayarri8d0bd7fa2016-03-30 14:59:58 +01007549 * default color is teal (#00796B).
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007550 * <p>
7551 * The confirm credentials screen can be created using
Benjamin Franz59720bb2016-01-18 15:26:11 +00007552 * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}.
7553 *
7554 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinski74cd7302016-04-12 15:17:36 +01007555 * @param color The 24bit (0xRRGGBB) representation of the color to be used.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007556 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz59720bb2016-01-18 15:26:11 +00007557 */
7558 public void setOrganizationColor(@NonNull ComponentName admin, int color) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007559 throwIfParentInstance("setOrganizationColor");
Benjamin Franz59720bb2016-01-18 15:26:11 +00007560 try {
Michal Karpinski74cd7302016-04-12 15:17:36 +01007561 // always enforce alpha channel to have 100% opacity
7562 color |= 0xFF000000;
Benjamin Franz59720bb2016-01-18 15:26:11 +00007563 mService.setOrganizationColor(admin, color);
7564 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007565 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00007566 }
7567 }
7568
7569 /**
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00007570 * @hide
7571 *
7572 * Sets the color used for customization.
7573 *
Michal Karpinski74cd7302016-04-12 15:17:36 +01007574 * @param color The 24bit (0xRRGGBB) representation of the color to be used.
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00007575 * @param userId which user to set the color to.
7576 * @RequiresPermission(allOf = {
7577 * Manifest.permission.MANAGE_USERS,
7578 * Manifest.permission.INTERACT_ACROSS_USERS_FULL})
7579 */
7580 public void setOrganizationColorForUser(@ColorInt int color, @UserIdInt int userId) {
7581 try {
Michal Karpinski74cd7302016-04-12 15:17:36 +01007582 // always enforce alpha channel to have 100% opacity
7583 color |= 0xFF000000;
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00007584 mService.setOrganizationColorForUser(color, userId);
7585 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007586 throw re.rethrowFromSystemServer();
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00007587 }
7588 }
7589
7590 /**
Benjamin Franz59720bb2016-01-18 15:26:11 +00007591 * Called by a profile owner of a managed profile to retrieve the color used for customization.
7592 * This color is used as background color of the confirm credentials screen for that user.
7593 *
7594 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinski74cd7302016-04-12 15:17:36 +01007595 * @return The 24bit (0xRRGGBB) representation of the color to be used.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007596 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz59720bb2016-01-18 15:26:11 +00007597 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01007598 public @ColorInt int getOrganizationColor(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007599 throwIfParentInstance("getOrganizationColor");
Benjamin Franz59720bb2016-01-18 15:26:11 +00007600 try {
7601 return mService.getOrganizationColor(admin);
7602 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007603 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00007604 }
7605 }
7606
7607 /**
7608 * @hide
7609 * Retrieve the customization color for a given user.
7610 *
7611 * @param userHandle The user id of the user we're interested in.
Michal Karpinski74cd7302016-04-12 15:17:36 +01007612 * @return The 24bit (0xRRGGBB) representation of the color to be used.
Benjamin Franz59720bb2016-01-18 15:26:11 +00007613 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01007614 public @ColorInt int getOrganizationColorForUser(int userHandle) {
Benjamin Franz59720bb2016-01-18 15:26:11 +00007615 try {
7616 return mService.getOrganizationColorForUser(userHandle);
7617 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007618 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00007619 }
7620 }
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007621
7622 /**
Wen ZHANG2be4cfc2017-09-21 18:29:43 +01007623 * Called by the device owner (since API 26) or profile owner (since API 24) to set the name of
7624 * the organization under management.
7625 *
7626 * <p>If the organization name needs to be localized, it is the responsibility of the {@link
7627 * DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast and set
7628 * a new version of this string accordingly.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007629 *
7630 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7631 * @param title The organization name or {@code null} to clear a previously set name.
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01007632 * @throws SecurityException if {@code admin} is not a device or profile owner.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007633 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01007634 public void setOrganizationName(@NonNull ComponentName admin, @Nullable CharSequence title) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007635 throwIfParentInstance("setOrganizationName");
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007636 try {
7637 mService.setOrganizationName(admin, title);
7638 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007639 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007640 }
7641 }
7642
7643 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007644 * Called by a profile owner of a managed profile to retrieve the name of the organization under
7645 * management.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007646 *
7647 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7648 * @return The organization name or {@code null} if none is set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007649 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007650 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007651 public @Nullable CharSequence getOrganizationName(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007652 throwIfParentInstance("getOrganizationName");
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007653 try {
7654 return mService.getOrganizationName(admin);
7655 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007656 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007657 }
7658 }
7659
7660 /**
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01007661 * Called by the system to retrieve the name of the organization managing the device.
7662 *
7663 * @return The organization name or {@code null} if none is set.
7664 * @throws SecurityException if the caller is not the device owner, does not hold the
7665 * MANAGE_USERS permission and is not the system.
7666 *
7667 * @hide
7668 */
7669 @SystemApi
7670 @TestApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06007671 @SuppressLint("Doclava125")
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01007672 public @Nullable CharSequence getDeviceOwnerOrganizationName() {
7673 try {
7674 return mService.getDeviceOwnerOrganizationName();
7675 } catch (RemoteException re) {
7676 throw re.rethrowFromSystemServer();
7677 }
7678 }
7679
7680 /**
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007681 * Retrieve the default title message used in the confirm credentials screen for a given user.
7682 *
7683 * @param userHandle The user id of the user we're interested in.
7684 * @return The organization name or {@code null} if none is set.
7685 *
7686 * @hide
7687 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007688 public @Nullable CharSequence getOrganizationNameForUser(int userHandle) {
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007689 try {
7690 return mService.getOrganizationNameForUser(userHandle);
7691 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007692 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007693 }
7694 }
7695
7696 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00007697 * @return the {@link UserProvisioningState} for the current user - for unmanaged users will
7698 * return {@link #STATE_USER_UNMANAGED}
7699 * @hide
7700 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00007701 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00007702 @UserProvisioningState
7703 public int getUserProvisioningState() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007704 throwIfParentInstance("getUserProvisioningState");
Alan Treadwayafad8782016-01-19 15:15:08 +00007705 if (mService != null) {
7706 try {
7707 return mService.getUserProvisioningState();
7708 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007709 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00007710 }
7711 }
7712 return STATE_USER_UNMANAGED;
7713 }
7714
7715 /**
7716 * Set the {@link UserProvisioningState} for the supplied user, if they are managed.
7717 *
7718 * @param state to store
7719 * @param userHandle for user
7720 * @hide
7721 */
7722 public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) {
7723 if (mService != null) {
7724 try {
7725 mService.setUserProvisioningState(state, userHandle);
7726 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007727 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00007728 }
7729 }
7730 }
7731
7732 /**
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007733 * Indicates the entity that controls the device or profile owner. Two users/profiles are
7734 * affiliated if the set of ids set by their device or profile owners intersect.
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007735 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00007736 * <p><strong>Note:</strong> Features that depend on user affiliation (such as security logging
7737 * or {@link #bindDeviceAdminServiceAsUser}) won't be available when a secondary user or profile
7738 * is created, until it becomes affiliated. Therefore it is recommended that the appropriate
7739 * affiliation ids are set by its profile owner as soon as possible after the user/profile is
7740 * created.
7741 *
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007742 * @param admin Which profile or device owner this request is associated with.
Tony Mak31657432017-04-25 09:29:55 +01007743 * @param ids A set of opaque non-empty affiliation ids.
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007744 *
Tony Mak31657432017-04-25 09:29:55 +01007745 * @throws IllegalArgumentException if {@code ids} is null or contains an empty string.
7746 */
7747 public void setAffiliationIds(@NonNull ComponentName admin, @NonNull Set<String> ids) {
7748 throwIfParentInstance("setAffiliationIds");
7749 if (ids == null) {
7750 throw new IllegalArgumentException("ids must not be null");
7751 }
7752 try {
7753 mService.setAffiliationIds(admin, new ArrayList<>(ids));
7754 } catch (RemoteException e) {
7755 throw e.rethrowFromSystemServer();
7756 }
7757 }
7758
7759 /**
Tony Mak31657432017-04-25 09:29:55 +01007760 * Returns the set of affiliation ids previously set via {@link #setAffiliationIds}, or an
7761 * empty set if none have been set.
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007762 */
Tony Mak31657432017-04-25 09:29:55 +01007763 public @NonNull Set<String> getAffiliationIds(@NonNull ComponentName admin) {
Tony Mak62cf5862017-05-02 13:50:18 +01007764 throwIfParentInstance("getAffiliationIds");
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007765 try {
Tony Mak31657432017-04-25 09:29:55 +01007766 return new ArraySet<>(mService.getAffiliationIds(admin));
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007767 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007768 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007769 }
7770 }
7771
7772 /**
7773 * @hide
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007774 * Returns whether this user/profile is affiliated with the device.
7775 * <p>
7776 * By definition, the user that the device owner runs on is always affiliated with the device.
7777 * Any other user/profile is considered affiliated with the device if the set specified by its
7778 * profile owner via {@link #setAffiliationIds} intersects with the device owner's.
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007779 *
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007780 */
7781 public boolean isAffiliatedUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007782 throwIfParentInstance("isAffiliatedUser");
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007783 try {
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007784 return mService.isAffiliatedUser();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007785 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007786 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007787 }
7788 }
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08007789
7790 /**
7791 * @hide
7792 * Returns whether the uninstall for {@code packageName} for the current user is in queue
7793 * to be started
7794 * @param packageName the package to check for
7795 * @return whether the uninstall intent for {@code packageName} is pending
7796 */
7797 public boolean isUninstallInQueue(String packageName) {
7798 try {
7799 return mService.isUninstallInQueue(packageName);
7800 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007801 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08007802 }
7803 }
7804
7805 /**
7806 * @hide
7807 * @param packageName the package containing active DAs to be uninstalled
7808 */
7809 public void uninstallPackageWithActiveAdmins(String packageName) {
7810 try {
7811 mService.uninstallPackageWithActiveAdmins(packageName);
7812 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007813 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08007814 }
7815 }
Benjamin Franzbc33c822016-04-15 08:57:52 +01007816
Kenny Guy38dcca52016-04-19 13:09:18 +01007817 /**
7818 * @hide
7819 * Remove a test admin synchronously without sending it a broadcast about being removed.
7820 * If the admin is a profile owner or device owner it will still be removed.
7821 *
7822 * @param userHandle user id to remove the admin for.
7823 * @param admin The administration compononent to remove.
7824 * @throws SecurityException if the caller is not shell / root or the admin package
7825 * isn't a test application see {@link ApplicationInfo#FLAG_TEST_APP}.
7826 */
7827 public void forceRemoveActiveAdmin(ComponentName adminReceiver, int userHandle) {
7828 try {
7829 mService.forceRemoveActiveAdmin(adminReceiver, userHandle);
7830 } catch (RemoteException re) {
7831 throw re.rethrowFromSystemServer();
7832 }
7833 }
7834
Mahaver Chopra790d1982016-07-07 16:06:49 +01007835 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007836 * Returns whether the device has been provisioned.
7837 *
7838 * <p>Not for use by third-party applications.
7839 *
Mahaver Chopra790d1982016-07-07 16:06:49 +01007840 * @hide
Mahaver Chopra790d1982016-07-07 16:06:49 +01007841 */
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007842 @SystemApi
Mahaver Chopra790d1982016-07-07 16:06:49 +01007843 public boolean isDeviceProvisioned() {
7844 try {
7845 return mService.isDeviceProvisioned();
7846 } catch (RemoteException re) {
7847 throw re.rethrowFromSystemServer();
7848 }
7849 }
7850
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007851 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007852 * Writes that the provisioning configuration has been applied.
7853 *
7854 * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS}
7855 * permission.
7856 *
7857 * <p>Not for use by third-party applications.
7858 *
7859 * @hide
7860 */
7861 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06007862 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007863 public void setDeviceProvisioningConfigApplied() {
7864 try {
7865 mService.setDeviceProvisioningConfigApplied();
7866 } catch (RemoteException re) {
7867 throw re.rethrowFromSystemServer();
7868 }
7869 }
7870
7871 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007872 * Returns whether the provisioning configuration has been applied.
7873 *
7874 * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS} permission.
7875 *
7876 * <p>Not for use by third-party applications.
7877 *
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007878 * @return whether the provisioning configuration has been applied.
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007879 *
7880 * @hide
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007881 */
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007882 @SystemApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06007883 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007884 public boolean isDeviceProvisioningConfigApplied() {
7885 try {
7886 return mService.isDeviceProvisioningConfigApplied();
7887 } catch (RemoteException re) {
7888 throw re.rethrowFromSystemServer();
7889 }
7890 }
7891
Victor Chang9bfc65f2016-08-15 12:27:09 +01007892 /**
7893 * @hide
Victor Chang3577ed22016-08-25 18:49:26 +01007894 * Force update user setup completed status. This API has no effect on user build.
7895 * @throws {@link SecurityException} if the caller has no
Esteban Talavera01576862016-12-15 11:16:44 +00007896 * {@code android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS} or the caller is
7897 * not {@link UserHandle#SYSTEM_USER}
Victor Chang9bfc65f2016-08-15 12:27:09 +01007898 */
7899 public void forceUpdateUserSetupComplete() {
7900 try {
7901 mService.forceUpdateUserSetupComplete();
7902 } catch (RemoteException re) {
7903 throw re.rethrowFromSystemServer();
7904 }
7905 }
7906
Benjamin Franzbc33c822016-04-15 08:57:52 +01007907 private void throwIfParentInstance(String functionName) {
7908 if (mParentInstance) {
7909 throw new SecurityException(functionName + " cannot be called on the parent instance");
7910 }
7911 }
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007912
7913 /**
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007914 * Allows the device owner to enable or disable the backup service.
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007915 *
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007916 * <p> Backup service manages all backup and restore mechanisms on the device. Setting this to
7917 * false will prevent data from being backed up or restored.
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007918 *
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007919 * <p> Backup service is off by default when device owner is present.
7920 *
Rubin Xu0367f072017-04-24 20:17:16 +01007921 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7922 * @param enabled {@code true} to enable the backup service, {@code false} to disable it.
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007923 * @throws SecurityException if {@code admin} is not a device owner.
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007924 */
7925 public void setBackupServiceEnabled(@NonNull ComponentName admin, boolean enabled) {
Esteban Talavera5b7f2d02017-02-17 09:45:24 +00007926 throwIfParentInstance("setBackupServiceEnabled");
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007927 try {
7928 mService.setBackupServiceEnabled(admin, enabled);
7929 } catch (RemoteException re) {
7930 throw re.rethrowFromSystemServer();
7931 }
7932 }
7933
7934 /**
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007935 * Return whether the backup service is enabled by the device owner.
7936 *
7937 * <p> Backup service manages all backup and restore mechanisms on the device.
7938 *
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007939 * @return {@code true} if backup service is enabled, {@code false} otherwise.
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007940 * @see #setBackupServiceEnabled
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007941 */
7942 public boolean isBackupServiceEnabled(@NonNull ComponentName admin) {
Esteban Talavera5b7f2d02017-02-17 09:45:24 +00007943 throwIfParentInstance("isBackupServiceEnabled");
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007944 try {
7945 return mService.isBackupServiceEnabled(admin);
7946 } catch (RemoteException re) {
7947 throw re.rethrowFromSystemServer();
7948 }
7949 }
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007950
7951 /**
Esteban Talaverad36dd152016-12-15 08:51:45 +00007952 * Called by a device owner to control the network logging feature.
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007953 *
Robin Leea40a2fb2017-02-08 17:07:06 +00007954 * <p> Network logs contain DNS lookup and connect() library call events. The following library
7955 * functions are recorded while network logging is active:
7956 * <ul>
7957 * <li>{@code getaddrinfo()}</li>
7958 * <li>{@code gethostbyname()}</li>
7959 * <li>{@code connect()}</li>
7960 * </ul>
7961 *
7962 * <p> Network logging is a low-overhead tool for forensics but it is not guaranteed to use
7963 * full system call logging; event reporting is enabled by default for all processes but not
7964 * strongly enforced.
7965 * Events from applications using alternative implementations of libc, making direct kernel
7966 * calls, or deliberately obfuscating traffic may not be recorded.
7967 *
7968 * <p> Some common network events may not be reported. For example:
7969 * <ul>
7970 * <li>Applications may hardcode IP addresses to reduce the number of DNS lookups, or use
7971 * an alternative system for name resolution, and so avoid calling
7972 * {@code getaddrinfo()} or {@code gethostbyname}.</li>
7973 * <li>Applications may use datagram sockets for performance reasons, for example
7974 * for a game client. Calling {@code connect()} is unnecessary for this kind of
7975 * socket, so it will not trigger a network event.</li>
7976 * </ul>
7977 *
7978 * <p> It is possible to directly intercept layer 3 traffic leaving the device using an
7979 * always-on VPN service.
7980 * See {@link #setAlwaysOnVpnPackage(ComponentName, String, boolean)}
7981 * and {@link android.net.VpnService} for details.
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007982 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00007983 * <p><strong>Note:</strong> The device owner won't be able to retrieve network logs if there
7984 * are unaffiliated secondary users or profiles on the device, regardless of whether the
7985 * feature is enabled. Logs will be discarded if the internal buffer fills up while waiting for
7986 * all users to become affiliated. Therefore it's recommended that affiliation ids are set for
7987 * new users as soon as possible after provisioning via {@link #setAffiliationIds}.
7988 *
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007989 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7990 * @param enabled whether network logging should be enabled or not.
Esteban Talaverad36dd152016-12-15 08:51:45 +00007991 * @throws SecurityException if {@code admin} is not a device owner.
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007992 * @see #retrieveNetworkLogs
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007993 */
7994 public void setNetworkLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
7995 throwIfParentInstance("setNetworkLoggingEnabled");
7996 try {
7997 mService.setNetworkLoggingEnabled(admin, enabled);
7998 } catch (RemoteException re) {
7999 throw re.rethrowFromSystemServer();
8000 }
8001 }
8002
8003 /**
8004 * Return whether network logging is enabled by a device owner.
8005 *
phweissa4e169e2016-11-24 16:20:57 +01008006 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Can only
8007 * be {@code null} if the caller has MANAGE_USERS permission.
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01008008 * @return {@code true} if network logging is enabled by device owner, {@code false} otherwise.
Esteban Talaverad36dd152016-12-15 08:51:45 +00008009 * @throws SecurityException if {@code admin} is not a device owner and caller has
phweissa4e169e2016-11-24 16:20:57 +01008010 * no MANAGE_USERS permission
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01008011 */
phweissa4e169e2016-11-24 16:20:57 +01008012 public boolean isNetworkLoggingEnabled(@Nullable ComponentName admin) {
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01008013 throwIfParentInstance("isNetworkLoggingEnabled");
8014 try {
8015 return mService.isNetworkLoggingEnabled(admin);
8016 } catch (RemoteException re) {
8017 throw re.rethrowFromSystemServer();
8018 }
8019 }
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01008020
8021 /**
Michal Karpinskia9ff2062016-11-03 15:46:17 +00008022 * Called by device owner to retrieve the most recent batch of network logging events.
8023 * A device owner has to provide a batchToken provided as part of
8024 * {@link DeviceAdminReceiver#onNetworkLogsAvailable} callback. If the token doesn't match the
8025 * token of the most recent available batch of logs, {@code null} will be returned.
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01008026 *
8027 * <p> {@link NetworkEvent} can be one of {@link DnsEvent} or {@link ConnectEvent}.
8028 *
8029 * <p> The list of network events is sorted chronologically, and contains at most 1200 events.
8030 *
8031 * <p> Access to the logs is rate limited and this method will only return a new batch of logs
8032 * after the device device owner has been notified via
8033 * {@link DeviceAdminReceiver#onNetworkLogsAvailable}.
8034 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00008035 * <p>If a secondary user or profile is created, calling this method will throw a
8036 * {@link SecurityException} until all users become affiliated again. It will also no longer be
8037 * possible to retrieve the network logs batch with the most recent batchToken provided
8038 * by {@link DeviceAdminReceiver#onNetworkLogsAvailable}. See
8039 * {@link DevicePolicyManager#setAffiliationIds}.
8040 *
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01008041 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinskia9ff2062016-11-03 15:46:17 +00008042 * @param batchToken A token of the batch to retrieve
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01008043 * @return A new batch of network logs which is a list of {@link NetworkEvent}. Returns
Michal Karpinskia9ff2062016-11-03 15:46:17 +00008044 * {@code null} if the batch represented by batchToken is no longer available or if
8045 * logging is disabled.
Esteban Talaverad36dd152016-12-15 08:51:45 +00008046 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
8047 * profile or secondary user that is not affiliated with the device owner user.
Michal Karpinskia9ff2062016-11-03 15:46:17 +00008048 * @see DeviceAdminReceiver#onNetworkLogsAvailable
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01008049 */
Michal Karpinskia9ff2062016-11-03 15:46:17 +00008050 public @Nullable List<NetworkEvent> retrieveNetworkLogs(@NonNull ComponentName admin,
8051 long batchToken) {
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01008052 throwIfParentInstance("retrieveNetworkLogs");
8053 try {
Michal Karpinskia9ff2062016-11-03 15:46:17 +00008054 return mService.retrieveNetworkLogs(admin, batchToken);
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01008055 } catch (RemoteException re) {
8056 throw re.rethrowFromSystemServer();
8057 }
8058 }
Tony Mak46aabe52016-11-14 12:53:06 +00008059
8060 /**
Esteban Talavera2f897912017-01-26 10:30:48 +00008061 * Called by a device owner to bind to a service from a profile owner or vice versa.
8062 * See {@link #getBindDeviceAdminTargetUsers} for a definition of which
Esteban Talaverafc291bc2016-11-21 13:52:03 +00008063 * device/profile owners are allowed to bind to services of another profile/device owner.
8064 * <p>
Tony Makeda0a9a2017-04-25 12:07:14 +01008065 * The service must be protected by {@link android.Manifest.permission#BIND_DEVICE_ADMIN}.
8066 * Note that the {@link Context} used to obtain this
Tony Mak46aabe52016-11-14 12:53:06 +00008067 * {@link DevicePolicyManager} instance via {@link Context#getSystemService(Class)} will be used
8068 * to bind to the {@link android.app.Service}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00008069 *
Tony Mak46aabe52016-11-14 12:53:06 +00008070 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
8071 * @param serviceIntent Identifies the service to connect to. The Intent must specify either an
8072 * explicit component name or a package name to match an
8073 * {@link IntentFilter} published by a service.
Tony Makbf9928d2016-12-22 11:02:45 +00008074 * @param conn Receives information as the service is started and stopped in main thread. This
8075 * must be a valid {@link ServiceConnection} object; it must not be {@code null}.
Tony Mak46aabe52016-11-14 12:53:06 +00008076 * @param flags Operation options for the binding operation. See
8077 * {@link Context#bindService(Intent, ServiceConnection, int)}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00008078 * @param targetUser Which user to bind to. Must be one of the users returned by
8079 * {@link #getBindDeviceAdminTargetUsers}, otherwise a {@link SecurityException} will
8080 * be thrown.
Tony Mak46aabe52016-11-14 12:53:06 +00008081 * @return If you have successfully bound to the service, {@code true} is returned;
8082 * {@code false} is returned if the connection is not made and you will not
8083 * receive the service object.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00008084 *
Tony Mak46aabe52016-11-14 12:53:06 +00008085 * @see Context#bindService(Intent, ServiceConnection, int)
Esteban Talaverafc291bc2016-11-21 13:52:03 +00008086 * @see #getBindDeviceAdminTargetUsers(ComponentName)
Tony Mak46aabe52016-11-14 12:53:06 +00008087 */
8088 public boolean bindDeviceAdminServiceAsUser(
8089 @NonNull ComponentName admin, Intent serviceIntent, @NonNull ServiceConnection conn,
8090 @Context.BindServiceFlags int flags, @NonNull UserHandle targetUser) {
8091 throwIfParentInstance("bindDeviceAdminServiceAsUser");
8092 // Keep this in sync with ContextImpl.bindServiceCommon.
8093 try {
Tony Makbf9928d2016-12-22 11:02:45 +00008094 final IServiceConnection sd = mContext.getServiceDispatcher(
8095 conn, mContext.getMainThreadHandler(), flags);
Tony Mak46aabe52016-11-14 12:53:06 +00008096 serviceIntent.prepareToLeaveProcess(mContext);
8097 return mService.bindDeviceAdminServiceAsUser(admin,
8098 mContext.getIApplicationThread(), mContext.getActivityToken(), serviceIntent,
8099 sd, flags, targetUser.getIdentifier());
8100 } catch (RemoteException re) {
8101 throw re.rethrowFromSystemServer();
8102 }
8103 }
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01008104
8105 /**
Esteban Talaverafc291bc2016-11-21 13:52:03 +00008106 * Returns the list of target users that the calling device or profile owner can use when
8107 * calling {@link #bindDeviceAdminServiceAsUser}.
8108 * <p>
Esteban Talavera2f897912017-01-26 10:30:48 +00008109 * A device owner can bind to a service from a profile owner and vice versa, provided that:
Esteban Talaverafc291bc2016-11-21 13:52:03 +00008110 * <ul>
8111 * <li>Both belong to the same package name.
Esteban Talavera2f897912017-01-26 10:30:48 +00008112 * <li>Both users are affiliated. See {@link #setAffiliationIds}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00008113 * </ul>
8114 */
8115 public @NonNull List<UserHandle> getBindDeviceAdminTargetUsers(@NonNull ComponentName admin) {
8116 throwIfParentInstance("getBindDeviceAdminTargetUsers");
8117 try {
8118 return mService.getBindDeviceAdminTargetUsers(admin);
8119 } catch (RemoteException re) {
8120 throw re.rethrowFromSystemServer();
8121 }
8122 }
8123
8124 /**
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01008125 * Called by the system to get the time at which the device owner last retrieved security
8126 * logging entries.
8127 *
8128 * @return the time at which the device owner most recently retrieved security logging entries,
8129 * in milliseconds since epoch; -1 if security logging entries were never retrieved.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01008130 * @throws SecurityException if the caller is not the device owner, does not hold the
8131 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01008132 *
8133 * @hide
8134 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01008135 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01008136 public long getLastSecurityLogRetrievalTime() {
8137 try {
8138 return mService.getLastSecurityLogRetrievalTime();
8139 } catch (RemoteException re) {
8140 throw re.rethrowFromSystemServer();
8141 }
8142 }
8143
8144 /**
8145 * Called by the system to get the time at which the device owner last requested a bug report.
8146 *
8147 * @return the time at which the device owner most recently requested a bug report, in
8148 * milliseconds since epoch; -1 if a bug report was never requested.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01008149 * @throws SecurityException if the caller is not the device owner, does not hold the
8150 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01008151 *
8152 * @hide
8153 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01008154 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01008155 public long getLastBugReportRequestTime() {
8156 try {
8157 return mService.getLastBugReportRequestTime();
8158 } catch (RemoteException re) {
8159 throw re.rethrowFromSystemServer();
8160 }
8161 }
8162
8163 /**
8164 * Called by the system to get the time at which the device owner last retrieved network logging
8165 * events.
8166 *
8167 * @return the time at which the device owner most recently retrieved network logging events, in
8168 * milliseconds since epoch; -1 if network logging events were never retrieved.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01008169 * @throws SecurityException if the caller is not the device owner, does not hold the
8170 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01008171 *
8172 * @hide
8173 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01008174 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01008175 public long getLastNetworkLogRetrievalTime() {
8176 try {
8177 return mService.getLastNetworkLogRetrievalTime();
8178 } catch (RemoteException re) {
8179 throw re.rethrowFromSystemServer();
8180 }
8181 }
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01008182
8183 /**
Bartosz Fabianowski172f7802017-03-06 12:07:57 +01008184 * Called by the system to find out whether the current user's IME was set by the device/profile
8185 * owner or the user.
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01008186 *
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01008187 * @return {@code true} if the user's IME was set by the device or profile owner, {@code false}
8188 * otherwise.
Bartosz Fabianowski172f7802017-03-06 12:07:57 +01008189 * @throws SecurityException if the caller is not the device owner/profile owner.
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01008190 *
8191 * @hide
8192 */
8193 @TestApi
Bartosz Fabianowski172f7802017-03-06 12:07:57 +01008194 public boolean isCurrentInputMethodSetByOwner() {
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01008195 try {
Bartosz Fabianowski172f7802017-03-06 12:07:57 +01008196 return mService.isCurrentInputMethodSetByOwner();
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01008197 } catch (RemoteException re) {
8198 throw re.rethrowFromSystemServer();
8199 }
8200 }
Bartosz Fabianowski05dc9f72017-02-22 23:41:14 +01008201
Bartosz Fabianowski05dc9f72017-02-22 23:41:14 +01008202 /**
8203 * Called by the system to get a list of CA certificates that were installed by the device or
8204 * profile owner.
8205 *
Bartosz Fabianowski172f7802017-03-06 12:07:57 +01008206 * <p> The caller must be the target user's device owner/profile Owner or hold the
Bartosz Fabianowski05dc9f72017-02-22 23:41:14 +01008207 * {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} permission.
8208 *
8209 * @param user The user for whom to retrieve information.
8210 * @return list of aliases identifying CA certificates installed by the device or profile owner
8211 * @throws SecurityException if the caller does not have permission to retrieve information
8212 * about the given user's CA certificates.
8213 *
8214 * @hide
8215 */
8216 @TestApi
8217 public List<String> getOwnerInstalledCaCerts(@NonNull UserHandle user) {
8218 try {
8219 return mService.getOwnerInstalledCaCerts(user).getList();
8220 } catch (RemoteException re) {
8221 throw re.rethrowFromSystemServer();
8222 }
8223 }
Benjamin Franza77e3572017-06-23 12:01:44 +01008224
8225 /**
8226 * Called by the device owner or profile owner to clear application user data of a given
8227 * package. The behaviour of this is equivalent to the target application calling
8228 * {@link android.app.ActivityManager#clearApplicationUserData()}.
8229 *
8230 * <p><strong>Note:</strong> an application can store data outside of its application data, e.g.
8231 * external storage or user dictionary. This data will not be wiped by calling this API.
8232 *
8233 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
8234 * @param packageName The name of the package which will have its user data wiped.
8235 * @param listener A callback object that will inform the caller when the clearing is done.
8236 * @param handler The handler indicating the thread on which the listener should be invoked.
8237 * @throws SecurityException if the caller is not the device owner/profile owner.
8238 * @return whether the clearing succeeded.
8239 */
8240 public boolean clearApplicationUserData(@NonNull ComponentName admin,
8241 @NonNull String packageName, @NonNull OnClearApplicationUserDataListener listener,
8242 @NonNull Handler handler) {
8243 throwIfParentInstance("clearAppData");
8244 try {
8245 return mService.clearApplicationUserData(admin, packageName,
8246 new IPackageDataObserver.Stub() {
8247 public void onRemoveCompleted(String pkg, boolean succeeded) {
8248 handler.post(() ->
8249 listener.onApplicationUserDataCleared(pkg, succeeded));
8250 }
8251 });
8252 } catch (RemoteException re) {
8253 throw re.rethrowFromSystemServer();
8254 }
8255 }
8256
8257 /**
8258 * Callback used in {@link #clearApplicationUserData}
8259 * to indicate that the clearing of an application's user data is done.
8260 */
8261 public interface OnClearApplicationUserDataListener {
8262 /**
8263 * Method invoked when clearing the application user data has completed.
8264 *
8265 * @param packageName The name of the package which had its user data cleared.
8266 * @param succeeded Whether the clearing succeeded. Clearing fails for device administrator
8267 * apps and protected system packages.
8268 */
8269 void onApplicationUserDataCleared(String packageName, boolean succeeded);
8270 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08008271}