blob: 3871d7a2418a516938026dc1ca727fb04b5c2229 [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
Jeff Sharkey8439ac02017-12-12 17:26:23 -070019import android.annotation.CallbackExecutor;
Nicolas Prevot8f7698a2016-02-11 16:05:33 +000020import android.annotation.ColorInt;
Alan Treadwayafad8782016-01-19 15:15:08 +000021import android.annotation.IntDef;
Robin Lee25e26452015-06-02 09:56:29 -070022import android.annotation.NonNull;
23import android.annotation.Nullable;
Jeff Sharkey98af2e42018-02-16 10:14:57 -070024import android.annotation.RequiresFeature;
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060025import android.annotation.RequiresPermission;
Dianne Hackbornd6847842010-01-12 18:14:19 -080026import android.annotation.SdkConstant;
27import android.annotation.SdkConstant.SdkConstantType;
yuemingw93ffce62018-02-21 16:20:14 +000028import android.annotation.StringDef;
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060029import android.annotation.SuppressLint;
Justin Moreyb5deda72014-07-24 10:53:40 -050030import android.annotation.SystemApi;
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060031import android.annotation.SystemService;
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +010032import android.annotation.TestApi;
Mathew Inwood4fb17d12018-08-14 14:25:44 +010033import android.annotation.UnsupportedAppUsage;
Nicolas Prevot8f7698a2016-02-11 16:05:33 +000034import android.annotation.UserIdInt;
Fyodor Kupolov4e9af062016-07-18 16:59:11 -070035import android.annotation.WorkerThread;
Jason Monkd7b86212014-06-16 13:15:38 -040036import android.app.Activity;
Tony Mak46aabe52016-11-14 12:53:06 +000037import android.app.IServiceConnection;
Rubin Xuaab7a412016-12-30 21:13:29 +000038import android.app.KeyguardManager;
Michal Karpinski6235a942016-03-15 12:07:23 +000039import android.app.admin.SecurityLog.SecurityEvent;
Dianne Hackbornd6847842010-01-12 18:14:19 -080040import android.content.ComponentName;
41import android.content.Context;
Adam Connors010cfd42014-04-16 12:48:13 +010042import android.content.Intent;
Sander Alewijnsef475ca32014-02-17 15:13:58 +000043import android.content.IntentFilter;
Tony Mak46aabe52016-11-14 12:53:06 +000044import android.content.ServiceConnection;
Victor Chang98607132017-01-27 11:51:56 +000045import android.content.pm.ApplicationInfo;
Benjamin Franza77e3572017-06-23 12:01:44 +010046import android.content.pm.IPackageDataObserver;
Dianne Hackbornd6847842010-01-12 18:14:19 -080047import android.content.pm.PackageManager;
Victor Changcd14c0a2016-03-16 19:10:15 +000048import android.content.pm.PackageManager.NameNotFoundException;
Rubin Xuc3cd05f2016-01-11 12:11:35 +000049import android.content.pm.ParceledListSlice;
Sudheer Shanka978fc0d2016-01-28 13:51:10 +000050import android.content.pm.UserInfo;
Julia Reynoldsfca04ca2015-02-17 13:39:12 -050051import android.graphics.Bitmap;
Jason Monk03bc9912014-05-13 09:44:57 -040052import android.net.ProxyInfo;
Nicolas Prevot8b7991c2015-11-12 17:40:12 +000053import android.net.Uri;
Mathew Inwood55418ea2018-12-20 15:30:45 +000054import android.os.Build;
Robin Lee66e5d962014-04-09 16:44:21 +010055import android.os.Bundle;
Victor Changc10f6692016-12-09 15:24:00 +000056import android.os.Parcelable;
Jim Millere303bf42014-08-26 17:12:29 -070057import android.os.PersistableBundle;
Adam Connors776c5552014-01-09 10:42:56 +000058import android.os.Process;
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080059import android.os.RemoteCallback;
Dianne Hackbornd6847842010-01-12 18:14:19 -080060import android.os.RemoteException;
Alex Chau89386ba2018-02-13 11:09:17 +080061import android.os.ServiceSpecificException;
Amith Yamasani599dd7c2012-09-14 23:20:08 -070062import android.os.UserHandle;
Julia Reynolds1e958392014-05-16 14:25:21 -040063import android.os.UserManager;
Alex Chau89386ba2018-02-13 11:09:17 +080064import android.os.UserManager.UserOperationException;
65import android.os.UserManager.UserOperationResult;
Ricky Wai494b95d2015-11-20 16:07:15 +000066import android.provider.ContactsContract.Directory;
yuemingw93ffce62018-02-21 16:20:14 +000067import android.provider.Settings;
Eran Messeri852c8f12017-11-15 05:55:52 +000068import android.security.AttestedKeyPair;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010069import android.security.Credentials;
Eran Messeri852c8f12017-11-15 05:55:52 +000070import android.security.KeyChain;
71import android.security.KeyChainException;
Eran Messeria1730642017-12-11 17:48:47 +000072import android.security.keymaster.KeymasterCertificateChain;
73import android.security.keystore.AttestationUtils;
74import android.security.keystore.KeyAttestationException;
Eran Messeri852c8f12017-11-15 05:55:52 +000075import android.security.keystore.KeyGenParameterSpec;
76import android.security.keystore.ParcelableKeyGenParameterSpec;
Amith Yamasanid1d7c022014-08-19 17:03:41 -070077import android.service.restrictions.RestrictionsReceiver;
Mahaver Chopra1216ae52016-03-11 15:39:48 +000078import android.telephony.TelephonyManager;
yuemingwe3d9c092018-01-11 12:11:44 +000079import android.telephony.data.ApnSetting;
Tony Mak31657432017-04-25 09:29:55 +010080import android.util.ArraySet;
Dianne Hackbornd6847842010-01-12 18:14:19 -080081import android.util.Log;
82
yuemingwf7f67dc2017-09-08 14:23:53 +010083import com.android.internal.R;
Makoto Onukicc4bbeb2015-09-17 10:28:24 -070084import com.android.internal.annotations.VisibleForTesting;
yuemingwf7f67dc2017-09-08 14:23:53 +010085import com.android.internal.util.Preconditions;
Maggie Benthallda51e682013-08-08 22:35:44 -040086import com.android.org.conscrypt.TrustedCertificateStore;
87
88import java.io.ByteArrayInputStream;
Dianne Hackbornd6847842010-01-12 18:14:19 -080089import java.io.IOException;
Alan Treadwayafad8782016-01-19 15:15:08 +000090import java.lang.annotation.Retention;
91import java.lang.annotation.RetentionPolicy;
Oscar Montemayor69238c62010-08-03 10:51:06 -070092import java.net.InetSocketAddress;
93import java.net.Proxy;
Robin Lee0d5ccb72014-09-12 17:41:44 +010094import java.security.KeyFactory;
Eran Messeri852c8f12017-11-15 05:55:52 +000095import java.security.KeyPair;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000096import java.security.NoSuchAlgorithmException;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010097import java.security.PrivateKey;
98import java.security.cert.Certificate;
Maggie Benthallda51e682013-08-08 22:35:44 -040099import java.security.cert.CertificateException;
100import java.security.cert.CertificateFactory;
101import java.security.cert.X509Certificate;
Robin Lee0d5ccb72014-09-12 17:41:44 +0100102import java.security.spec.InvalidKeySpecException;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +0000103import java.security.spec.PKCS8EncodedKeySpec;
Jim Miller604e7552014-07-18 19:00:02 -0700104import java.util.ArrayList;
Rubin Xub4365912016-03-23 12:13:22 +0000105import java.util.Arrays;
Svetoslav976e8bd2014-07-16 15:12:03 -0700106import java.util.Collections;
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800107import java.util.List;
Tony Mak31657432017-04-25 09:29:55 +0100108import java.util.Set;
Jeff Sharkey8439ac02017-12-12 17:26:23 -0700109import java.util.concurrent.Executor;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800110
111/**
Alexandra Gherghina541afcd2014-11-07 11:18:12 +0000112 * Public interface for managing policies enforced on a device. Most clients of this class must be
Suprabh Shukla34d92ef2016-03-14 13:49:37 -0700113 * registered with the system as a <a href="{@docRoot}guide/topics/admin/device-admin.html">device
114 * administrator</a>. Additionally, a device administrator may be registered as either a profile or
115 * device owner. A given method is accessible to all device administrators unless the documentation
116 * for that method specifies that it is restricted to either device or profile owners. Any
117 * application calling an api may only pass as an argument a device administrator component it
118 * owns. Otherwise, a {@link SecurityException} will be thrown.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -0800119 * <div class="special reference">
120 * <h3>Developer Guides</h3>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -0700121 * <p>
122 * For more information about managing policies for device administration, read the <a href=
123 * "{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a> developer
124 * guide. </div>
Dianne Hackbornd6847842010-01-12 18:14:19 -0800125 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -0600126@SystemService(Context.DEVICE_POLICY_SERVICE)
Jeff Sharkey98af2e42018-02-16 10:14:57 -0700127@RequiresFeature(PackageManager.FEATURE_DEVICE_ADMIN)
Dianne Hackbornd6847842010-01-12 18:14:19 -0800128public class DevicePolicyManager {
Eran Messerif15d4f42018-03-23 13:32:17 +0000129
Dianne Hackbornd6847842010-01-12 18:14:19 -0800130 private static String TAG = "DevicePolicyManager";
Dianne Hackbornd6847842010-01-12 18:14:19 -0800131
132 private final Context mContext;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800133 private final IDevicePolicyManager mService;
Esteban Talavera62399912016-01-11 15:37:55 +0000134 private final boolean mParentInstance;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700135
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600136 /** @hide */
137 public DevicePolicyManager(Context context, IDevicePolicyManager service) {
138 this(context, service, false);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800139 }
140
Dianne Hackborn87bba1e2010-02-26 17:25:54 -0800141 /** @hide */
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700142 @VisibleForTesting
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600143 protected DevicePolicyManager(Context context, IDevicePolicyManager service,
144 boolean parentInstance) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700145 mContext = context;
146 mService = service;
Esteban Talavera62399912016-01-11 15:37:55 +0000147 mParentInstance = parentInstance;
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700148 }
149
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700150 /** @hide test will override it. */
151 @VisibleForTesting
152 protected int myUserId() {
Jeff Sharkeyad357d12018-02-02 13:25:31 -0700153 return mContext.getUserId();
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700154 }
155
Dianne Hackbornd6847842010-01-12 18:14:19 -0800156 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +0000157 * Activity action: Starts the provisioning flow which sets up a managed profile.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000158 *
Jessica Hummel9da60392014-05-21 12:32:57 +0100159 * <p>A managed profile allows data separation for example for the usage of a
160 * device as a personal and corporate device. The user which provisioning is started from and
161 * the managed profile share a launcher.
162 *
Andrew Solovay27f53372015-03-02 16:37:59 -0800163 * <p>This intent will typically be sent by a mobile device management application (MDM).
164 * Provisioning adds a managed profile and sets the MDM as the profile owner who has full
165 * control over the profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100166 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000167 * <p>It is possible to check if provisioning is allowed or not by querying the method
168 * {@link #isProvisioningAllowed(String)}.
169 *
170 * <p>In version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this intent must contain the
Nicolas Prevot18440252015-03-09 14:07:17 +0000171 * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700172 * As of {@link android.os.Build.VERSION_CODES#M}, it should contain the extra
Nicolas Prevot18440252015-03-09 14:07:17 +0000173 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only
174 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000175 *
Benjamin Franzea956242016-03-21 15:45:56 +0000176 * <p>The intent may also contain the following extras:
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000177 * <ul>
Benjamin Franzea956242016-03-21 15:45:56 +0000178 * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, optional </li>
179 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional, supported from
180 * {@link android.os.Build.VERSION_CODES#N}</li>
181 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
182 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
183 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Victor Chang51d84f92016-11-16 12:22:56 +0000184 * <li>{@link #EXTRA_PROVISIONING_SKIP_USER_CONSENT}, optional</li>
Victor Chang89ee2792016-11-23 12:10:55 +0000185 * <li>{@link #EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION}, optional</li>
Victor Changc10f6692016-12-09 15:24:00 +0000186 * <li>{@link #EXTRA_PROVISIONING_DISCLAIMERS}, optional</li>
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000187 * </ul>
Jessica Hummelf72078b2014-03-06 16:13:12 +0000188 *
Benjamin Franzea956242016-03-21 15:45:56 +0000189 * <p>When managed provisioning has completed, broadcasts are sent to the application specified
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000190 * in the provisioning intent. The
191 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the
192 * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in
193 * the primary profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100194 *
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000195 * <p>From version {@link android.os.Build.VERSION_CODES#O}, when managed provisioning has
196 * completed, along with the above broadcast, activity intent
Esteban Talavera4047bae2017-06-28 11:03:09 +0100197 * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the profile owner.
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000198 *
Benjamin Franzea956242016-03-21 15:45:56 +0000199 * <p>If provisioning fails, the managedProfile is removed so the device returns to its
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100200 * previous state.
Alan Treadway4582f812015-07-28 11:49:35 +0100201 *
202 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
203 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
204 * the provisioning flow was successful, although this doesn't guarantee the full flow will
205 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
206 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000207 */
208 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
209 public static final String ACTION_PROVISION_MANAGED_PROFILE
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100210 = "android.app.action.PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000211
212 /**
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000213 * Activity action: Starts the provisioning flow which sets up a managed user.
214 *
215 * <p>This intent will typically be sent by a mobile device management application (MDM).
Makoto Onuki32b30572015-12-11 14:29:51 -0800216 * Provisioning configures the user as managed user and sets the MDM as the profile
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000217 * owner who has full control over the user. Provisioning can only happen before user setup has
218 * been completed. Use {@link #isProvisioningAllowed(String)} to check if provisioning is
219 * allowed.
220 *
Benjamin Franzea956242016-03-21 15:45:56 +0000221 * <p>The intent contains the following extras:
222 * <ul>
223 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
224 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
225 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
226 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
227 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
228 * </ul>
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000229 *
Benjamin Franzea956242016-03-21 15:45:56 +0000230 * <p>If provisioning fails, the device returns to its previous state.
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000231 *
232 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
233 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
234 * the provisioning flow was successful, although this doesn't guarantee the full flow will
235 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
236 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Benjamin Franzea956242016-03-21 15:45:56 +0000237 *
238 * @hide
Mahaver Chopra5e732562015-11-05 11:55:12 +0000239 */
240 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
241 public static final String ACTION_PROVISION_MANAGED_USER
242 = "android.app.action.PROVISION_MANAGED_USER";
243
244 /**
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100245 * Activity action: Starts the provisioning flow which sets up a managed device.
246 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
247 *
248 * <p> During device owner provisioning a device admin app is set as the owner of the device.
249 * A device owner has full control over the device. The device owner can not be modified by the
250 * user.
251 *
252 * <p> A typical use case would be a device that is owned by a company, but used by either an
253 * employee or client.
254 *
255 * <p> An intent with this action can be sent only on an unprovisioned device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000256 * It is possible to check if provisioning is allowed or not by querying the method
257 * {@link #isProvisioningAllowed(String)}.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100258 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000259 * <p>The intent contains the following extras:
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100260 * <ul>
261 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
262 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
263 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
Rubin Xua4f9dc12015-06-12 13:27:59 +0100264 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000265 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000266 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Victor Changc10f6692016-12-09 15:24:00 +0000267 * <li>{@link #EXTRA_PROVISIONING_DISCLAIMERS}, optional</li>
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100268 * </ul>
269 *
Benjamin Franzea956242016-03-21 15:45:56 +0000270 * <p>When device owner provisioning has completed, an intent of the type
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100271 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
272 * device owner.
273 *
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000274 * <p>From version {@link android.os.Build.VERSION_CODES#O}, when device owner provisioning has
275 * completed, along with the above broadcast, activity intent
276 * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the device owner.
277 *
Benjamin Franzea956242016-03-21 15:45:56 +0000278 * <p>If provisioning fails, the device is factory reset.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100279 *
Alan Treadway4582f812015-07-28 11:49:35 +0100280 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
281 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
282 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
283 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100284 */
285 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
286 public static final String ACTION_PROVISION_MANAGED_DEVICE
287 = "android.app.action.PROVISION_MANAGED_DEVICE";
288
289 /**
Victor Chang18800092017-04-11 19:41:43 +0100290 * Activity action: launch when user provisioning completed, i.e.
291 * {@link #getUserProvisioningState()} returns one of the complete state.
292 *
293 * <p> Please note that the API behavior is not necessarily consistent across various releases,
294 * and devices, as it's contract between SetupWizard and ManagedProvisioning. The default
295 * implementation is that ManagedProvisioning launches SetupWizard in NFC provisioning only.
296 *
297 * <p> The activity must be protected by permission
298 * {@link android.Manifest.permission#BIND_DEVICE_ADMIN}, and the process must hold
299 * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE} to be launched.
300 * Only one {@link ComponentName} in the entire system should be enabled, and the rest of the
301 * components are not started by this intent.
302 * @hide
303 */
304 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
Jeff Sharkey90396362017-06-12 16:26:53 -0600305 @SystemApi
Victor Chang18800092017-04-11 19:41:43 +0100306 public static final String ACTION_STATE_USER_SETUP_COMPLETE =
307 "android.app.action.STATE_USER_SETUP_COMPLETE";
308
309 /**
Alan Treadway46dd4492015-11-09 13:57:19 +0000310 * Activity action: Starts the provisioning flow which sets up a managed device.
Steven Ng980a1b62016-02-02 17:43:18 +0000311 *
312 * <p>During device owner provisioning, a device admin app is downloaded and set as the owner of
313 * the device. A device owner has full control over the device. The device owner can not be
314 * modified by the user and the only way of resetting the device is via factory reset.
315 *
316 * <p>A typical use case would be a device that is owned by a company, but used by either an
317 * employee or client.
318 *
319 * <p>The provisioning message should be sent to an unprovisioned device.
320 *
321 * <p>Unlike {@link #ACTION_PROVISION_MANAGED_DEVICE}, the provisioning message can only be sent
322 * by a privileged app with the permission
323 * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE}.
324 *
325 * <p>The provisioning intent contains the following properties:
326 * <ul>
327 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
328 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
329 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
330 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Victor Chang38cfd9c2017-01-04 17:41:11 +0000331 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL}, optional</li>
332 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI}, optional</li>
Steven Ng980a1b62016-02-02 17:43:18 +0000333 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
334 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
335 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
336 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
337 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
338 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
339 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
340 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
341 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
342 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
343 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
Victor Chang38cfd9c2017-01-04 17:41:11 +0000344 * <li>{@link #EXTRA_PROVISIONING_SUPPORT_URL}, optional</li>
345 * <li>{@link #EXTRA_PROVISIONING_ORGANIZATION_NAME}, optional</li>
Alex Chaueca99a02018-04-30 17:51:56 +0100346 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
347 * <li>{@link #EXTRA_PROVISIONING_USE_MOBILE_DATA, optional </li><ul>
Steven Ng980a1b62016-02-02 17:43:18 +0000348 *
349 * @hide
350 */
351 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
352 @SystemApi
353 public static final String ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE =
354 "android.app.action.PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE";
355
356 /**
357 * Activity action: Starts the provisioning flow which sets up a managed device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000358 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
359 *
360 * <p>NOTE: This is only supported on split system user devices, and puts the device into a
361 * management state that is distinct from that reached by
362 * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system
363 * user, and only has control over device-wide policies, not individual users and their data.
364 * The primary benefit is that multiple non-system users are supported when provisioning using
365 * this form of device management.
366 *
Benjamin Franzea956242016-03-21 15:45:56 +0000367 * <p>During device owner provisioning a device admin app is set as the owner of the device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000368 * A device owner has full control over the device. The device owner can not be modified by the
369 * user.
370 *
Benjamin Franzea956242016-03-21 15:45:56 +0000371 * <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 +0000372 * employee or client.
373 *
Benjamin Franzea956242016-03-21 15:45:56 +0000374 * <p>An intent with this action can be sent only on an unprovisioned device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000375 * It is possible to check if provisioning is allowed or not by querying the method
376 * {@link #isProvisioningAllowed(String)}.
377 *
378 * <p>The intent contains the following extras:
379 * <ul>
380 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
381 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
382 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
383 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Benjamin Franzea956242016-03-21 15:45:56 +0000384 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
385 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Alan Treadway46dd4492015-11-09 13:57:19 +0000386 * </ul>
387 *
Benjamin Franzea956242016-03-21 15:45:56 +0000388 * <p>When device owner provisioning has completed, an intent of the type
Alan Treadway46dd4492015-11-09 13:57:19 +0000389 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
390 * device owner.
391 *
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000392 * <p>From version {@link android.os.Build.VERSION_CODES#O}, when device owner provisioning has
393 * completed, along with the above broadcast, activity intent
394 * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the device owner.
395 *
Benjamin Franzea956242016-03-21 15:45:56 +0000396 * <p>If provisioning fails, the device is factory reset.
Alan Treadway46dd4492015-11-09 13:57:19 +0000397 *
398 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
399 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
400 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
401 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
402 *
403 * @hide
404 */
405 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
406 public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE
407 = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE";
408
409 /**
Alan Treadwayafad8782016-01-19 15:15:08 +0000410 * Activity action: Finalizes management provisioning, should be used after user-setup
411 * has been completed and {@link #getUserProvisioningState()} returns one of:
412 * <ul>
413 * <li>{@link #STATE_USER_SETUP_INCOMPLETE}</li>
414 * <li>{@link #STATE_USER_SETUP_COMPLETE}</li>
415 * <li>{@link #STATE_USER_PROFILE_COMPLETE}</li>
416 * </ul>
417 *
418 * @hide
419 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +0000420 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +0000421 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
422 public static final String ACTION_PROVISION_FINALIZATION
423 = "android.app.action.PROVISION_FINALIZATION";
424
425 /**
Michal Karpinskiba244092016-02-25 17:28:24 +0000426 * Action: Bugreport sharing with device owner has been accepted by the user.
427 *
428 * @hide
429 */
430 public static final String ACTION_BUGREPORT_SHARING_ACCEPTED =
Rubin Xu7226c7d2017-02-06 17:18:50 +0000431 "com.android.server.action.REMOTE_BUGREPORT_SHARING_ACCEPTED";
Michal Karpinskiba244092016-02-25 17:28:24 +0000432
433 /**
434 * Action: Bugreport sharing with device owner has been declined by the user.
435 *
436 * @hide
437 */
438 public static final String ACTION_BUGREPORT_SHARING_DECLINED =
Rubin Xu7226c7d2017-02-06 17:18:50 +0000439 "com.android.server.action.REMOTE_BUGREPORT_SHARING_DECLINED";
Michal Karpinskiba244092016-02-25 17:28:24 +0000440
441 /**
Esteban Talavera01576862016-12-15 11:16:44 +0000442 * Action: Bugreport has been collected and is dispatched to {@code DevicePolicyManagerService}.
Michal Karpinskiba244092016-02-25 17:28:24 +0000443 *
444 * @hide
445 */
446 public static final String ACTION_REMOTE_BUGREPORT_DISPATCH =
447 "android.intent.action.REMOTE_BUGREPORT_DISPATCH";
448
449 /**
450 * Extra for shared bugreport's SHA-256 hash.
451 *
452 * @hide
453 */
454 public static final String EXTRA_REMOTE_BUGREPORT_HASH =
455 "android.intent.extra.REMOTE_BUGREPORT_HASH";
456
457 /**
458 * Extra for remote bugreport notification shown type.
459 *
460 * @hide
461 */
462 public static final String EXTRA_BUGREPORT_NOTIFICATION_TYPE =
463 "android.app.extra.bugreport_notification_type";
464
465 /**
466 * Notification type for a started remote bugreport flow.
467 *
468 * @hide
469 */
470 public static final int NOTIFICATION_BUGREPORT_STARTED = 1;
471
472 /**
473 * Notification type for a bugreport that has already been accepted to be shared, but is still
474 * being taken.
475 *
476 * @hide
477 */
478 public static final int NOTIFICATION_BUGREPORT_ACCEPTED_NOT_FINISHED = 2;
479
480 /**
481 * Notification type for a bugreport that has been taken and can be shared or declined.
482 *
483 * @hide
484 */
485 public static final int NOTIFICATION_BUGREPORT_FINISHED_NOT_ACCEPTED = 3;
486
487 /**
Michal Karpinski8f010dd2016-06-21 15:05:53 +0100488 * Default and maximum timeout in milliseconds after which unlocking with weak auth times out,
489 * i.e. the user has to use a strong authentication method like password, PIN or pattern.
490 *
491 * @hide
492 */
493 public static final long DEFAULT_STRONG_AUTH_TIMEOUT_MS = 72 * 60 * 60 * 1000; // 72h
494
495 /**
Rubin Xua4f9dc12015-06-12 13:27:59 +0100496 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100497 * allows a mobile device management application or NFC programmer application which starts
498 * managed provisioning to pass data to the management application instance after provisioning.
Rubin Xua4f9dc12015-06-12 13:27:59 +0100499 * <p>
500 * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that
501 * sends the intent to pass data to itself on the newly created profile.
502 * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same
503 * instance of the app on the primary user.
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100504 * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with
505 * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC
506 * message should contain a stringified {@link java.util.Properties} instance, whose string
507 * properties will be converted into a {@link android.os.PersistableBundle} and passed to the
508 * management application after provisioning.
509 *
Rubin Xua4f9dc12015-06-12 13:27:59 +0100510 * <p>
511 * In both cases the application receives the data in
Brian Carlstromf1fe51b2014-09-03 08:55:05 -0700512 * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action
513 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed
Rubin Xua4f9dc12015-06-12 13:27:59 +0100514 * during the managed provisioning.
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100515 */
516 public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE =
Esteban Talavera37f01842014-09-05 10:50:57 +0100517 "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE";
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100518
519 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100520 * A String extra holding the package name of the mobile device management application that
521 * will be set as the profile owner or device owner.
522 *
523 * <p>If an application starts provisioning directly via an intent with action
524 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
525 * application that started provisioning. The package will be set as profile owner in that case.
526 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000527 * <p>This package is set as device owner when device owner provisioning is started by an NFC
528 * message containing an NFC record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000529 *
530 * <p> When this extra is set, the application must have exactly one device admin receiver.
Robin Lee25e26452015-06-02 09:56:29 -0700531 * This receiver will be set as the profile or device owner and active admin.
Benjamin Franzea956242016-03-21 15:45:56 +0000532 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000533 * @see DeviceAdminReceiver
534 * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still
Nicolas Prevot8f78d6a2015-08-21 11:06:31 +0100535 * supported, but only if there is only one device admin receiver in the package that requires
536 * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000537 */
Nicolas Prevot18440252015-03-09 14:07:17 +0000538 @Deprecated
Jessica Hummelf72078b2014-03-06 16:13:12 +0000539 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100540 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000541
542 /**
Nicolas Prevot18440252015-03-09 14:07:17 +0000543 * A ComponentName extra indicating the device admin receiver of the mobile device management
544 * application that will be set as the profile owner or device owner and active admin.
545 *
546 * <p>If an application starts provisioning directly via an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100547 * {@link #ACTION_PROVISION_MANAGED_PROFILE} or
548 * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this
549 * component has to match the package name of the application that started provisioning.
Nicolas Prevot18440252015-03-09 14:07:17 +0000550 *
551 * <p>This component is set as device owner and active admin when device owner provisioning is
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100552 * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC
553 * message containing an NFC record with MIME type
Benjamin Franzea956242016-03-21 15:45:56 +0000554 * {@link #MIME_TYPE_PROVISIONING_NFC}. For the NFC record, the component name must be
Rubin Xu44ef750b2015-03-23 16:51:33 +0000555 * flattened to a string, via {@link ComponentName#flattenToShortString()}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000556 *
557 * @see DeviceAdminReceiver
558 */
559 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME
560 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME";
561
562 /**
Alexandra Gherghinaaaf2f3e2014-11-13 12:46:15 +0000563 * An {@link android.accounts.Account} extra holding the account to migrate during managed
564 * profile provisioning. If the account supplied is present in the primary user, it will be
565 * copied, along with its credentials to the managed profile and removed from the primary user.
566 *
567 * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}.
568 */
569
570 public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE
571 = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE";
572
573 /**
Victor Changaa9cbc02016-12-05 20:50:57 +0000574 * Boolean extra to indicate that the migrated account should be kept. This is used in
575 * conjunction with {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}. If it's set to {@code true},
576 * the account will not be removed from the primary user after it is migrated to the newly
577 * created user or profile.
Victor Chang89ee2792016-11-23 12:10:55 +0000578 *
579 * <p> Defaults to {@code false}
580 *
Victor Changaa9cbc02016-12-05 20:50:57 +0000581 * <p> Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
582 * {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}
Victor Chang89ee2792016-11-23 12:10:55 +0000583 */
584 public static final String EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION
585 = "android.app.extra.PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION";
586
587 /**
Mahaver761ce772017-03-13 16:40:45 +0000588 * @deprecated From {@link android.os.Build.VERSION_CODES#O}, never used while provisioning the
589 * device.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100590 */
Mahaver761ce772017-03-13 16:40:45 +0000591 @Deprecated
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100592 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
593 = "android.app.extra.PROVISIONING_EMAIL_ADDRESS";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100594
595 /**
Nicolas Prevotcd2d8592015-11-23 13:27:21 +0000596 * A integer extra indicating the predominant color to show during the provisioning.
597 * Refer to {@link android.graphics.Color} for how the color is represented.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000598 *
599 * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or
600 * {@link #ACTION_PROVISION_MANAGED_DEVICE}.
601 */
602 public static final String EXTRA_PROVISIONING_MAIN_COLOR =
603 "android.app.extra.PROVISIONING_MAIN_COLOR";
604
605 /**
Sander Alewijnse8c411562014-11-12 18:03:11 +0000606 * A Boolean extra that can be used by the mobile device management application to skip the
Robin Lee25e26452015-06-02 09:56:29 -0700607 * disabling of system apps during provisioning when set to {@code true}.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000608 *
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100609 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
610 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000611 */
Sander Alewijnse5a144252014-11-18 13:25:04 +0000612 public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED =
613 "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED";
Sander Alewijnse8c411562014-11-12 18:03:11 +0000614
615 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100616 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
617 * will be set to.
618 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000619 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
620 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100621 */
622 public static final String EXTRA_PROVISIONING_TIME_ZONE
Esteban Talavera37f01842014-09-05 10:50:57 +0100623 = "android.app.extra.PROVISIONING_TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100624
625 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100626 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
627 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100628 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000629 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
630 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100631 */
632 public static final String EXTRA_PROVISIONING_LOCAL_TIME
Esteban Talavera37f01842014-09-05 10:50:57 +0100633 = "android.app.extra.PROVISIONING_LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100634
635 /**
636 * A String extra holding the {@link java.util.Locale} that the device will be set to.
637 * Format: xx_yy, where xx is the language code, and yy the country code.
638 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000639 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
640 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100641 */
642 public static final String EXTRA_PROVISIONING_LOCALE
Esteban Talavera37f01842014-09-05 10:50:57 +0100643 = "android.app.extra.PROVISIONING_LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100644
645 /**
646 * A String extra holding the ssid of the wifi network that should be used during nfc device
647 * owner provisioning for downloading the mobile device management application.
648 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000649 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
650 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100651 */
652 public static final String EXTRA_PROVISIONING_WIFI_SSID
Esteban Talavera37f01842014-09-05 10:50:57 +0100653 = "android.app.extra.PROVISIONING_WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100654
655 /**
656 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
657 * is hidden or not.
658 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000659 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
660 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100661 */
662 public static final String EXTRA_PROVISIONING_WIFI_HIDDEN
Esteban Talavera37f01842014-09-05 10:50:57 +0100663 = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100664
665 /**
666 * A String extra indicating the security type of the wifi network in
Mahaver Chopra76b08a92015-10-08 17:58:45 +0100667 * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or
668 * {@code WEP}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100669 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000670 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
671 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100672 */
673 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
Esteban Talavera37f01842014-09-05 10:50:57 +0100674 = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100675
676 /**
677 * A String extra holding the password of the wifi network in
678 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
679 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000680 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
681 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100682 */
683 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talavera37f01842014-09-05 10:50:57 +0100684 = "android.app.extra.PROVISIONING_WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100685
686 /**
687 * A String extra holding the proxy host for the wifi network in
688 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
689 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000690 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
691 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100692 */
693 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
Esteban Talavera37f01842014-09-05 10:50:57 +0100694 = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100695
696 /**
697 * An int extra holding the proxy port for the wifi network in
698 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
699 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000700 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
701 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100702 */
703 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
Esteban Talavera37f01842014-09-05 10:50:57 +0100704 = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100705
706 /**
707 * A String extra holding the proxy bypass for the wifi network in
708 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
709 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000710 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
711 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100712 */
713 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
Esteban Talavera37f01842014-09-05 10:50:57 +0100714 = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100715
716 /**
717 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
718 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
719 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000720 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
721 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100722 */
723 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
Esteban Talavera37f01842014-09-05 10:50:57 +0100724 = "android.app.extra.PROVISIONING_WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100725
726 /**
727 * A String extra holding a url that specifies the download location of the device admin
728 * package. When not provided it is assumed that the device admin package is already installed.
729 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000730 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
731 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100732 */
733 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talavera37f01842014-09-05 10:50:57 +0100734 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100735
736 /**
Victor Chang38cfd9c2017-01-04 17:41:11 +0000737 * A String extra holding the localized name of the organization under management.
738 *
739 * The name is displayed only during provisioning.
740 *
741 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE}
742 *
743 * @hide
744 */
745 @SystemApi
746 public static final String EXTRA_PROVISIONING_ORGANIZATION_NAME =
747 "android.app.extra.PROVISIONING_ORGANIZATION_NAME";
748
749 /**
Alejandro Fernándezbfd61932017-04-04 19:33:01 +0100750 * A String extra holding a url to the website of the device provider so the user can open it
751 * during provisioning. If the url is not HTTPS, an error will be shown.
Victor Chang38cfd9c2017-01-04 17:41:11 +0000752 *
753 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE}
754 *
755 * @hide
756 */
757 @SystemApi
758 public static final String EXTRA_PROVISIONING_SUPPORT_URL =
759 "android.app.extra.PROVISIONING_SUPPORT_URL";
760
761 /**
762 * A String extra holding the localized name of the device admin package. It should be the same
763 * as the app label of the package.
764 *
765 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE}
766 *
767 * @hide
768 */
769 @SystemApi
770 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL =
771 "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL";
772
773 /**
774 * A {@link Uri} extra pointing to the app icon of device admin package. This image will be
775 * shown during the provisioning.
776 * <h5>The following URI schemes are accepted:</h5>
777 * <ul>
778 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
779 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
780 * </ul>
781 *
782 * <p> It is the responsibility of the caller to provide an image with a reasonable
783 * pixel density for the device.
784 *
785 * <p> If a content: URI is passed, the intent should have the flag
786 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
787 * {@link android.content.ClipData} of the intent too.
788 *
789 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE}
790 *
791 * @hide
792 */
793 @SystemApi
794 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI =
795 "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI";
796
797 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400798 * An int extra holding a minimum required version code for the device admin package. If the
799 * device admin is already installed on the device, it will only be re-downloaded from
800 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the
801 * installed package is less than this version code.
802 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400803 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400804 * provisioning via an NFC bump.
805 */
806 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE
807 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE";
808
809 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100810 * A String extra holding a http cookie header which should be used in the http request to the
811 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
812 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000813 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
814 * provisioning via an NFC bump.
Sander Alewijnse681bce92014-07-24 16:46:26 +0100815 */
816 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talavera37f01842014-09-05 10:50:57 +0100817 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100818
819 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100820 * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of
821 * the file at download location specified in
822 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100823 *
Benjamin Franzea956242016-03-21 15:45:56 +0000824 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} must be
825 * present. The provided checksum must match the checksum of the file at the download
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100826 * location. If the checksum doesn't match an error will be shown to the user and the user will
827 * be asked to factory reset the device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100828 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000829 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
830 * provisioning via an NFC bump.
Rubin Xud92e7572015-05-18 17:01:13 +0100831 *
832 * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP}
833 * and {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1} only SHA-1 hash is supported.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700834 * Starting from {@link android.os.Build.VERSION_CODES#M}, this parameter accepts SHA-256 in
Rubin Xud92e7572015-05-18 17:01:13 +0100835 * addition to SHA-1. Support for SHA-1 is likely to be removed in future OS releases.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100836 */
837 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100838 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100839
840 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100841 * A String extra holding the URL-safe base64 encoded SHA-256 checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100842 * android package archive at the download location specified in {@link
843 * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
844 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100845 * <p>The signatures of an android package archive can be obtained using
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100846 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
847 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
848 *
Benjamin Franzea956242016-03-21 15:45:56 +0000849 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} must be
850 * present. The provided checksum must match the checksum of any signature of the file at
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100851 * the download location. If the checksum does not match an error will be shown to the user and
852 * the user will be asked to factory reset the device.
853 *
854 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
855 * provisioning via an NFC bump.
856 */
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100857 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM
858 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM";
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100859
860 /**
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000861 * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile
862 * has completed successfully.
863 *
864 * <p>The broadcast is limited to the primary profile, to the app specified in the provisioning
Nicolas Prevotebe2d992015-05-12 18:14:53 -0700865 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000866 *
Mahaver7074caf2016-11-29 20:52:18 +0000867 * <p>This intent will contain the following extras
868 * <ul>
869 * <li>{@link Intent#EXTRA_USER}, corresponds to the {@link UserHandle} of the managed
870 * profile.</li>
871 * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, corresponds to the account requested to
872 * be migrated at provisioning time, if any.</li>
873 * </ul>
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000874 */
875 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
876 public static final String ACTION_MANAGED_PROFILE_PROVISIONED
877 = "android.app.action.MANAGED_PROFILE_PROVISIONED";
878
879 /**
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000880 * Activity action: This activity action is sent to indicate that provisioning of a managed
881 * profile or managed device has completed successfully. It'll be sent at the same time as
882 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast but this will be
883 * delivered faster as it's an activity intent.
884 *
Esteban Talavera4047bae2017-06-28 11:03:09 +0100885 * <p>The intent is only sent to the new device or profile owner.
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000886 *
887 * @see #ACTION_PROVISION_MANAGED_PROFILE
888 * @see #ACTION_PROVISION_MANAGED_DEVICE
889 */
890 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
891 public static final String ACTION_PROVISIONING_SUCCESSFUL =
892 "android.app.action.PROVISIONING_SUCCESSFUL";
893
894 /**
Benjamin Franzea956242016-03-21 15:45:56 +0000895 * A boolean extra indicating whether device encryption can be skipped as part of device owner
896 * or managed profile provisioning.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500897 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400898 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100899 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Benjamin Franzea956242016-03-21 15:45:56 +0000900 *
901 * <p>From {@link android.os.Build.VERSION_CODES#N} onwards, this is also supported for an
902 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500903 */
904 public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION =
905 "android.app.extra.PROVISIONING_SKIP_ENCRYPTION";
906
907 /**
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000908 * A {@link Uri} extra pointing to a logo image. This image will be shown during the
909 * provisioning. If this extra is not passed, a default image will be shown.
910 * <h5>The following URI schemes are accepted:</h5>
911 * <ul>
912 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
913 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
914 * </ul>
915 *
Victor Changc10f6692016-12-09 15:24:00 +0000916 * <p> It is the responsibility of the caller to provide an image with a reasonable
Victor Chang38cfd9c2017-01-04 17:41:11 +0000917 * pixel density for the device.
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000918 *
919 * <p> If a content: URI is passed, the intent should have the flag
920 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
921 * {@link android.content.ClipData} of the intent too.
922 *
923 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or
924 * {@link #ACTION_PROVISION_MANAGED_DEVICE}
925 */
926 public static final String EXTRA_PROVISIONING_LOGO_URI =
927 "android.app.extra.PROVISIONING_LOGO_URI";
928
929 /**
Victor Changc10f6692016-12-09 15:24:00 +0000930 * A {@link Bundle}[] extra consisting of list of disclaimer headers and disclaimer contents.
931 * Each {@link Bundle} must have both {@link #EXTRA_PROVISIONING_DISCLAIMER_HEADER}
932 * as disclaimer header, and {@link #EXTRA_PROVISIONING_DISCLAIMER_CONTENT} as disclaimer
933 * content.
934 *
935 * <p> The extra typically contains one disclaimer from the company of mobile device
936 * management application (MDM), and one disclaimer from the organization.
937 *
938 * <p> Call {@link Bundle#putParcelableArray(String, Parcelable[])} to put the {@link Bundle}[]
939 *
940 * <p> Maximum 3 key-value pairs can be specified. The rest will be ignored.
941 *
942 * <p> Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or
943 * {@link #ACTION_PROVISION_MANAGED_DEVICE}
944 */
945 public static final String EXTRA_PROVISIONING_DISCLAIMERS =
946 "android.app.extra.PROVISIONING_DISCLAIMERS";
947
948 /**
949 * A String extra of localized disclaimer header.
950 *
951 * <p> The extra is typically the company name of mobile device management application (MDM)
952 * or the organization name.
953 *
954 * <p> Use in Bundle {@link #EXTRA_PROVISIONING_DISCLAIMERS}
Victor Chang98607132017-01-27 11:51:56 +0000955 *
956 * <p> System app, i.e. application with {@link ApplicationInfo#FLAG_SYSTEM}, can also insert a
957 * disclaimer by declaring an application-level meta-data in {@code AndroidManifest.xml}.
958 * Must use it with {@link #EXTRA_PROVISIONING_DISCLAIMER_CONTENT}. Here is the example:
959 *
960 * <pre>
961 * &lt;meta-data
962 * android:name="android.app.extra.PROVISIONING_DISCLAIMER_HEADER"
963 * android:resource="@string/disclaimer_header"
964 * /&gt;</pre>
Victor Changc10f6692016-12-09 15:24:00 +0000965 */
966 public static final String EXTRA_PROVISIONING_DISCLAIMER_HEADER =
967 "android.app.extra.PROVISIONING_DISCLAIMER_HEADER";
968
969 /**
970 * A {@link Uri} extra pointing to disclaimer content.
971 *
972 * <h5>The following URI schemes are accepted:</h5>
973 * <ul>
974 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
975 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
976 * </ul>
977 *
978 * <p> Styled text is supported in the disclaimer content. The content is parsed by
979 * {@link android.text.Html#fromHtml(String)} and displayed in a
980 * {@link android.widget.TextView}.
981 *
982 * <p> If a <code>content:</code> URI is passed, URI is passed, the intent should have the flag
983 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
984 * {@link android.content.ClipData} of the intent too.
985 *
986 * <p> Use in Bundle {@link #EXTRA_PROVISIONING_DISCLAIMERS}
Victor Chang98607132017-01-27 11:51:56 +0000987 *
988 * <p> System app, i.e. application with {@link ApplicationInfo#FLAG_SYSTEM}, can also insert a
989 * disclaimer by declaring an application-level meta-data in {@code AndroidManifest.xml}.
990 * Must use it with {@link #EXTRA_PROVISIONING_DISCLAIMER_HEADER}. Here is the example:
991 *
992 * <pre>
993 * &lt;meta-data
994 * android:name="android.app.extra.PROVISIONING_DISCLAIMER_CONTENT"
995 * android:resource="@string/disclaimer_content"
996 * /&gt;</pre>
Victor Changc10f6692016-12-09 15:24:00 +0000997 */
998 public static final String EXTRA_PROVISIONING_DISCLAIMER_CONTENT =
999 "android.app.extra.PROVISIONING_DISCLAIMER_CONTENT";
1000
1001 /**
Alan Treadway94de8c82016-01-11 10:25:23 +00001002 * A boolean extra indicating if user setup should be skipped, for when provisioning is started
1003 * during setup-wizard.
1004 *
1005 * <p>If unspecified, defaults to {@code true} to match the behavior in
1006 * {@link android.os.Build.VERSION_CODES#M} and earlier.
1007 *
Alan Treadway1a538d02016-01-18 16:42:30 +00001008 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or
1009 * {@link #ACTION_PROVISION_MANAGED_USER}.
Alan Treadway94de8c82016-01-11 10:25:23 +00001010 *
1011 * @hide
1012 */
1013 public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP =
1014 "android.app.extra.PROVISIONING_SKIP_USER_SETUP";
1015
1016 /**
Victor Chang51d84f92016-11-16 12:22:56 +00001017 * A boolean extra indicating if the user consent steps from the provisioning flow should be
1018 * skipped. If unspecified, defaults to {@code false}.
1019 *
1020 * It can only be used by an existing device owner trying to create a managed profile via
1021 * {@link #ACTION_PROVISION_MANAGED_PROFILE}. Otherwise it is ignored.
1022 */
1023 public static final String EXTRA_PROVISIONING_SKIP_USER_CONSENT =
1024 "android.app.extra.PROVISIONING_SKIP_USER_CONSENT";
1025
1026 /**
Alex Chaueca99a02018-04-30 17:51:56 +01001027 * A boolean extra indicating if mobile data should be used during NFC device owner provisioning
1028 * for downloading the mobile device management application. If {@link
1029 * #EXTRA_PROVISIONING_WIFI_SSID} is also specified, wifi network will be used instead.
1030 *
1031 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
1032 * provisioning via an NFC bump.
1033 *
1034 * @hide
1035 */
1036 public static final String EXTRA_PROVISIONING_USE_MOBILE_DATA =
1037 "android.app.extra.PROVISIONING_USE_MOBILE_DATA";
1038
1039 /**
Benjamin Franzea956242016-03-21 15:45:56 +00001040 * This MIME type is used for starting the device owner provisioning.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +01001041 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -04001042 * <p>During device owner provisioning a device admin app is set as the owner of the device.
1043 * A device owner has full control over the device. The device owner can not be modified by the
1044 * user and the only way of resetting the device is if the device owner app calls a factory
1045 * reset.
1046 *
1047 * <p> A typical use case would be a device that is owned by a company, but used by either an
1048 * employee or client.
1049 *
Benjamin Franzea956242016-03-21 15:45:56 +00001050 * <p> The NFC message must be sent to an unprovisioned device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +01001051 *
Sander Alewijnse8c411562014-11-12 18:03:11 +00001052 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +01001053 * contains the following properties:
1054 * <ul>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -04001055 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
1056 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +01001057 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -04001058 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +01001059 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
1060 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
1061 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
1062 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
1063 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
1064 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
1065 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
1066 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
1067 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
1068 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Rubin Xu41f2ccb92015-08-05 16:29:13 +01001069 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
1070 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from
1071 * {@link android.os.Build.VERSION_CODES#M} </li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +01001072 *
Nicolas Prevot18440252015-03-09 14:07:17 +00001073 * <p>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07001074 * As of {@link android.os.Build.VERSION_CODES#M}, the properties should contain
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -04001075 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of
1076 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only
1077 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -04001078 */
1079 public static final String MIME_TYPE_PROVISIONING_NFC
1080 = "application/com.android.managedprovisioning";
1081
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +01001082 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001083 * Activity action: ask the user to add a new device administrator to the system.
1084 * The desired policy is the ComponentName of the policy in the
1085 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
1086 * bring the user through adding the device administrator to the system (or
1087 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001088 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001089 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
1090 * field to provide the user with additional explanation (in addition
1091 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001092 *
1093 * <p>If your administrator is already active, this will ordinarily return immediately (without
1094 * user intervention). However, if your administrator has been updated and is requesting
1095 * additional uses-policy flags, the user will be presented with the new list. New policies
1096 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001097 */
1098 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1099 public static final String ACTION_ADD_DEVICE_ADMIN
1100 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001101
Dianne Hackbornd6847842010-01-12 18:14:19 -08001102 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001103 * @hide
1104 * Activity action: ask the user to add a new device administrator as the profile owner
Amith Yamasani814e9872015-03-23 14:04:53 -07001105 * for this user. Only system apps can launch this intent.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001106 *
Amith Yamasani814e9872015-03-23 14:04:53 -07001107 * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN}
1108 * extra field. This will invoke a UI to bring the user through adding the profile owner admin
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001109 * to remotely control restrictions on the user.
1110 *
Makoto Onukic8a5a552015-11-19 14:29:12 -08001111 * <p>The intent must be invoked via {@link Activity#startActivityForResult} to receive the
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001112 * result of whether or not the user approved the action. If approved, the result will
1113 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
1114 * as a profile owner.
1115 *
1116 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
1117 * field to provide the user with additional explanation (in addition
1118 * to your component's description) about what is being added.
1119 *
Amith Yamasani814e9872015-03-23 14:04:53 -07001120 * <p>If there is already a profile owner active or the caller is not a system app, the
1121 * operation will return a failure result.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001122 */
1123 @SystemApi
1124 public static final String ACTION_SET_PROFILE_OWNER
1125 = "android.app.action.SET_PROFILE_OWNER";
1126
1127 /**
1128 * @hide
1129 * Name of the profile owner admin that controls the user.
1130 */
1131 @SystemApi
1132 public static final String EXTRA_PROFILE_OWNER_NAME
1133 = "android.app.extra.PROFILE_OWNER_NAME";
1134
1135 /**
Nicolas Prevot00799002015-07-27 18:15:20 +01001136 * Broadcast action: send when any policy admin changes a policy.
Jim Miller284b62e2010-06-08 14:27:42 -07001137 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -07001138 *
Jim Miller284b62e2010-06-08 14:27:42 -07001139 * @hide
1140 */
Mathew Inwood4fb17d12018-08-14 14:25:44 +01001141 @UnsupportedAppUsage
Jim Miller284b62e2010-06-08 14:27:42 -07001142 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
1143 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
1144
1145 /**
Tony Mak1970f972016-08-30 17:41:48 +01001146 * Broadcast action: sent when the device owner is set, changed or cleared.
Nicolas Prevot00799002015-07-27 18:15:20 +01001147 *
1148 * This broadcast is sent only to the primary user.
1149 * @see #ACTION_PROVISION_MANAGED_DEVICE
arangelov8bae4ea2017-12-20 20:26:46 +00001150 * @see DevicePolicyManager#transferOwnership(ComponentName, ComponentName, PersistableBundle)
Nicolas Prevot00799002015-07-27 18:15:20 +01001151 */
1152 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1153 public static final String ACTION_DEVICE_OWNER_CHANGED
1154 = "android.app.action.DEVICE_OWNER_CHANGED";
1155
1156 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001157 * The ComponentName of the administrator component.
1158 *
1159 * @see #ACTION_ADD_DEVICE_ADMIN
1160 */
1161 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001162
Dianne Hackbornd6847842010-01-12 18:14:19 -08001163 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001164 * An optional CharSequence providing additional explanation for why the
1165 * admin is being added.
1166 *
1167 * @see #ACTION_ADD_DEVICE_ADMIN
1168 */
1169 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001170
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001171 /**
phweiss73145f42017-01-17 19:06:38 +01001172 * Constant to indicate the feature of disabling the camera. Used as argument to
1173 * {@link #createAdminSupportIntent(String)}.
1174 * @see #setCameraDisabled(ComponentName, boolean)
1175 */
1176 public static final String POLICY_DISABLE_CAMERA = "policy_disable_camera";
1177
1178 /**
1179 * Constant to indicate the feature of disabling screen captures. Used as argument to
1180 * {@link #createAdminSupportIntent(String)}.
1181 * @see #setScreenCaptureDisabled(ComponentName, boolean)
1182 */
1183 public static final String POLICY_DISABLE_SCREEN_CAPTURE = "policy_disable_screen_capture";
1184
1185 /**
Lenka Trochtova16a91c02018-01-17 11:03:30 +01001186 * Constant to indicate the feature of mandatory backups. Used as argument to
1187 * {@link #createAdminSupportIntent(String)}.
1188 * @see #setMandatoryBackupTransport(ComponentName, ComponentName)
Lenka Trochtova27fd8212018-04-10 11:01:58 +02001189 * @hide
Lenka Trochtova16a91c02018-01-17 11:03:30 +01001190 */
1191 public static final String POLICY_MANDATORY_BACKUPS = "policy_mandatory_backups";
1192
1193 /**
Tony Mak706fbe72018-04-03 18:49:05 +01001194 * Constant to indicate the feature of suspending app. Use it as the value of
1195 * {@link #EXTRA_RESTRICTION}.
1196 * @hide
1197 */
1198 public static final String POLICY_SUSPEND_PACKAGES = "policy_suspend_packages";
1199
1200 /**
phweiss73145f42017-01-17 19:06:38 +01001201 * A String indicating a specific restricted feature. Can be a user restriction from the
1202 * {@link UserManager}, e.g. {@link UserManager#DISALLOW_ADJUST_VOLUME}, or one of the values
Lenka Trochtova16a91c02018-01-17 11:03:30 +01001203 * {@link #POLICY_DISABLE_CAMERA}, {@link #POLICY_DISABLE_SCREEN_CAPTURE} or
1204 * {@link #POLICY_MANDATORY_BACKUPS}.
phweiss73145f42017-01-17 19:06:38 +01001205 * @see #createAdminSupportIntent(String)
1206 * @hide
1207 */
1208 @TestApi
1209 public static final String EXTRA_RESTRICTION = "android.app.extra.RESTRICTION";
1210
1211 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001212 * Activity action: have the user enter a new password. This activity should
1213 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
1214 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
1215 * enter a new password that meets the current requirements. You can use
1216 * {@link #isActivePasswordSufficient()} to determine whether you need to
1217 * have the user select a new password in order to meet the current
1218 * constraints. Upon being resumed from this activity, you can check the new
1219 * password characteristics to see if they are sufficient.
Benjamin Franzc9921092016-01-08 17:17:44 +00001220 *
1221 * If the intent is launched from within a managed profile with a profile
1222 * owner built against {@link android.os.Build.VERSION_CODES#M} or before,
1223 * this will trigger entering a new password for the parent of the profile.
1224 * For all other cases it will trigger entering a new password for the user
1225 * or profile it is launched from.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001226 *
1227 * @see #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
Dianne Hackbornd6847842010-01-12 18:14:19 -08001228 */
1229 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1230 public static final String ACTION_SET_NEW_PASSWORD
1231 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001232
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001233 /**
Benjamin Franzc9921092016-01-08 17:17:44 +00001234 * Activity action: have the user enter a new password for the parent profile.
1235 * If the intent is launched from within a managed profile, this will trigger
1236 * entering a new password for the parent of the profile. In all other cases
1237 * the behaviour is identical to {@link #ACTION_SET_NEW_PASSWORD}.
1238 */
1239 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1240 public static final String ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
1241 = "android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD";
1242
1243 /**
phweissa0cb2512016-12-14 21:37:48 +01001244 * Broadcast action: Tell the status bar to open the device monitoring dialog, e.g. when
1245 * Network logging was enabled and the user tapped the notification.
1246 * <p class="note">This is a protected intent that can only be sent by the system.</p>
1247 * @hide
1248 */
1249 public static final String ACTION_SHOW_DEVICE_MONITORING_DIALOG
1250 = "android.app.action.SHOW_DEVICE_MONITORING_DIALOG";
1251
1252 /**
Edman Anjos9e62c312017-01-26 22:22:58 +01001253 * Broadcast Action: Sent after application delegation scopes are changed. The new delegation
1254 * scopes will be sent in an {@code ArrayList<String>} extra identified by the
1255 * {@link #EXTRA_DELEGATION_SCOPES} key.
Edman Anjosf9946772016-11-28 16:35:15 +01001256 *
1257 * <p class=”note”> Note: This is a protected intent that can only be sent by the system.</p>
1258 */
1259 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1260 public static final String ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED =
1261 "android.app.action.APPLICATION_DELEGATION_SCOPES_CHANGED";
1262
1263 /**
Edman Anjos9e62c312017-01-26 22:22:58 +01001264 * An {@code ArrayList<String>} corresponding to the delegation scopes given to an app in the
Edman Anjosf9946772016-11-28 16:35:15 +01001265 * {@link #ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED} broadcast.
1266 */
1267 public static final String EXTRA_DELEGATION_SCOPES = "android.app.extra.DELEGATION_SCOPES";
1268
1269 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +00001270 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
1271 * the parent profile to access intents sent from the managed profile.
1272 * That is, when an app in the managed profile calls
1273 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
1274 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001275 */
Nicolas Prevot86a96732014-09-08 12:13:05 +01001276 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001277
1278 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +00001279 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
1280 * the managed profile to access intents sent from the parent profile.
1281 * That is, when an app in the parent profile calls
1282 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
1283 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001284 */
Nicolas Prevot86a96732014-09-08 12:13:05 +01001285 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001286
Dianne Hackbornd6847842010-01-12 18:14:19 -08001287 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01001288 * Broadcast action: notify that a new local system update policy has been set by the device
1289 * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00001290 */
1291 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Rubin Xu5faad8e2015-04-20 17:43:48 +01001292 public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED
1293 = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED";
Rubin Xu8027a4f2015-03-10 17:52:37 +00001294
Amith Yamasanid49489b2015-04-28 14:00:26 -07001295 /**
Rubin Xucc391c22018-01-02 20:37:35 +00001296 * Broadcast action to notify ManagedProvisioning that
1297 * {@link UserManager#DISALLOW_SHARE_INTO_MANAGED_PROFILE} restriction has changed.
1298 * @hide
1299 */
1300 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1301 public static final String ACTION_DATA_SHARING_RESTRICTION_CHANGED =
1302 "android.app.action.DATA_SHARING_RESTRICTION_CHANGED";
1303
1304 /**
1305 * Broadcast action from ManagedProvisioning to notify that the latest change to
1306 * {@link UserManager#DISALLOW_SHARE_INTO_MANAGED_PROFILE} restriction has been successfully
1307 * applied (cross profile intent filters updated). Only usesd for CTS tests.
1308 * @hide
1309 */
1310 @TestApi
1311 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1312 public static final String ACTION_DATA_SHARING_RESTRICTION_APPLIED =
1313 "android.app.action.DATA_SHARING_RESTRICTION_APPLIED";
1314
1315 /**
Amith Yamasanid49489b2015-04-28 14:00:26 -07001316 * Permission policy to prompt user for new permission requests for runtime permissions.
1317 * Already granted or denied permissions are not affected by this.
1318 */
1319 public static final int PERMISSION_POLICY_PROMPT = 0;
1320
1321 /**
1322 * Permission policy to always grant new permission requests for runtime permissions.
1323 * Already granted or denied permissions are not affected by this.
1324 */
1325 public static final int PERMISSION_POLICY_AUTO_GRANT = 1;
1326
1327 /**
1328 * Permission policy to always deny new permission requests for runtime permissions.
1329 * Already granted or denied permissions are not affected by this.
1330 */
1331 public static final int PERMISSION_POLICY_AUTO_DENY = 2;
1332
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07001333 /**
1334 * Runtime permission state: The user can manage the permission
1335 * through the UI.
1336 */
1337 public static final int PERMISSION_GRANT_STATE_DEFAULT = 0;
1338
1339 /**
1340 * Runtime permission state: The permission is granted to the app
1341 * and the user cannot manage the permission through the UI.
1342 */
1343 public static final int PERMISSION_GRANT_STATE_GRANTED = 1;
1344
1345 /**
1346 * Runtime permission state: The permission is denied to the app
1347 * and the user cannot manage the permission through the UI.
1348 */
1349 public static final int PERMISSION_GRANT_STATE_DENIED = 2;
Rubin Xu8027a4f2015-03-10 17:52:37 +00001350
1351 /**
Edman Anjosf9946772016-11-28 16:35:15 +01001352 * Delegation of certificate installation and management. This scope grants access to the
1353 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
1354 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair} APIs.
1355 */
1356 public static final String DELEGATION_CERT_INSTALL = "delegation-cert-install";
1357
1358 /**
1359 * Delegation of application restrictions management. This scope grants access to the
1360 * {@link #setApplicationRestrictions} and {@link #getApplicationRestrictions} APIs.
1361 */
1362 public static final String DELEGATION_APP_RESTRICTIONS = "delegation-app-restrictions";
1363
1364 /**
Edman Anjosa5f2fb12016-12-19 11:25:54 -08001365 * Delegation of application uninstall block. This scope grants access to the
1366 * {@link #setUninstallBlocked} API.
1367 */
1368 public static final String DELEGATION_BLOCK_UNINSTALL = "delegation-block-uninstall";
1369
1370 /**
Edman Anjos52088e42017-01-13 22:26:17 +01001371 * Delegation of permission policy and permission grant state. This scope grants access to the
1372 * {@link #setPermissionPolicy}, {@link #getPermissionGrantState},
1373 * and {@link #setPermissionGrantState} APIs.
1374 */
1375 public static final String DELEGATION_PERMISSION_GRANT = "delegation-permission-grant";
1376
1377 /**
1378 * Delegation of package access state. This scope grants access to the
1379 * {@link #isApplicationHidden}, {@link #setApplicationHidden}, {@link #isPackageSuspended}, and
1380 * {@link #setPackagesSuspended} APIs.
1381 */
1382 public static final String DELEGATION_PACKAGE_ACCESS = "delegation-package-access";
1383
1384 /**
1385 * Delegation for enabling system apps. This scope grants access to the {@link #enableSystemApp}
1386 * API.
1387 */
1388 public static final String DELEGATION_ENABLE_SYSTEM_APP = "delegation-enable-system-app";
1389
1390 /**
Alex Chau5343fcb2017-12-05 16:49:19 +00001391 * Delegation for installing existing packages. This scope grants access to the
1392 * {@link #installExistingPackage} API.
1393 */
1394 public static final String DELEGATION_INSTALL_EXISTING_PACKAGE =
1395 "delegation-install-existing-package";
1396
1397 /**
Edman Anjos52088e42017-01-13 22:26:17 +01001398 * Delegation of management of uninstalled packages. This scope grants access to the
1399 * {@code #setKeepUninstalledPackages} and {@code #getKeepUninstalledPackages} APIs.
Edman Anjos52088e42017-01-13 22:26:17 +01001400 */
1401 public static final String DELEGATION_KEEP_UNINSTALLED_PACKAGES =
1402 "delegation-keep-uninstalled-packages";
1403
1404 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00001405 * No management for current user in-effect. This is the default.
1406 * @hide
1407 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001408 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001409 public static final int STATE_USER_UNMANAGED = 0;
1410
1411 /**
1412 * Management partially setup, user setup needs to be completed.
1413 * @hide
1414 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001415 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001416 public static final int STATE_USER_SETUP_INCOMPLETE = 1;
1417
1418 /**
1419 * Management partially setup, user setup completed.
1420 * @hide
1421 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001422 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001423 public static final int STATE_USER_SETUP_COMPLETE = 2;
1424
1425 /**
1426 * Management setup and active on current user.
1427 * @hide
1428 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001429 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001430 public static final int STATE_USER_SETUP_FINALIZED = 3;
1431
1432 /**
1433 * Management partially setup on a managed profile.
1434 * @hide
1435 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001436 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001437 public static final int STATE_USER_PROFILE_COMPLETE = 4;
1438
1439 /**
1440 * @hide
1441 */
Jeff Sharkeyce8db992017-12-13 20:05:05 -07001442 @IntDef(prefix = { "STATE_USER_" }, value = {
1443 STATE_USER_UNMANAGED,
1444 STATE_USER_SETUP_INCOMPLETE,
1445 STATE_USER_SETUP_COMPLETE,
1446 STATE_USER_SETUP_FINALIZED,
1447 STATE_USER_PROFILE_COMPLETE
1448 })
Alan Treadwayafad8782016-01-19 15:15:08 +00001449 @Retention(RetentionPolicy.SOURCE)
1450 public @interface UserProvisioningState {}
1451
1452 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001453 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001454 *
1455 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1456 * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and
1457 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when provisioning is allowed.
1458 *
1459 * @hide
1460 */
1461 public static final int CODE_OK = 0;
1462
1463 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001464 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001465 *
1466 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and
1467 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the device already has a device
1468 * owner.
1469 *
1470 * @hide
1471 */
1472 public static final int CODE_HAS_DEVICE_OWNER = 1;
1473
1474 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001475 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001476 *
1477 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1478 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user has a profile owner and for
1479 * {@link #ACTION_PROVISION_MANAGED_PROFILE} when the profile owner is already set.
1480 *
1481 * @hide
1482 */
1483 public static final int CODE_USER_HAS_PROFILE_OWNER = 2;
1484
1485 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001486 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001487 *
1488 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and
1489 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user isn't running.
1490 *
1491 * @hide
1492 */
1493 public static final int CODE_USER_NOT_RUNNING = 3;
1494
1495 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001496 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001497 *
1498 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1499 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the device has already been setup and
1500 * for {@link #ACTION_PROVISION_MANAGED_USER} if the user has already been setup.
1501 *
1502 * @hide
1503 */
1504 public static final int CODE_USER_SETUP_COMPLETED = 4;
1505
1506 /**
1507 * Code used to indicate that the device also has a user other than the system user.
1508 *
1509 * @hide
1510 */
1511 public static final int CODE_NONSYSTEM_USER_EXISTS = 5;
1512
1513 /**
1514 * Code used to indicate that device has an account that prevents provisioning.
1515 *
1516 * @hide
1517 */
1518 public static final int CODE_ACCOUNTS_NOT_EMPTY = 6;
1519
1520 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001521 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001522 *
1523 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and
1524 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the user is not a system user.
1525 *
1526 * @hide
1527 */
1528 public static final int CODE_NOT_SYSTEM_USER = 7;
1529
1530 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001531 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001532 *
1533 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1534 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} and {@link #ACTION_PROVISION_MANAGED_USER}
1535 * when the device is a watch and is already paired.
1536 *
1537 * @hide
1538 */
1539 public static final int CODE_HAS_PAIRED = 8;
1540
1541 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001542 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001543 *
1544 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} and
1545 * {@link #ACTION_PROVISION_MANAGED_USER} on devices which do not support managed users.
1546 *
1547 * @see {@link PackageManager#FEATURE_MANAGED_USERS}
1548 * @hide
1549 */
1550 public static final int CODE_MANAGED_USERS_NOT_SUPPORTED = 9;
1551
1552 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001553 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001554 *
1555 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} if the user is a system user.
1556 *
1557 * @hide
1558 */
1559 public static final int CODE_SYSTEM_USER = 10;
1560
1561 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001562 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001563 *
1564 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when the user cannot have more
1565 * managed profiles.
1566 *
1567 * @hide
1568 */
1569 public static final int CODE_CANNOT_ADD_MANAGED_PROFILE = 11;
1570
1571 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001572 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001573 *
1574 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} and
1575 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices not running with split system
1576 * user.
1577 *
1578 * @hide
1579 */
1580 public static final int CODE_NOT_SYSTEM_USER_SPLIT = 12;
1581
1582 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001583 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001584 *
1585 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1586 * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and
1587 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices which do no support device
1588 * admins.
1589 *
1590 * @hide
1591 */
1592 public static final int CODE_DEVICE_ADMIN_NOT_SUPPORTED = 13;
1593
1594 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001595 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001596 *
Esteban Talavera6c9116a2016-11-24 16:12:44 +00001597 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when the device the user is a
1598 * system user on a split system user device.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001599 *
1600 * @hide
1601 */
1602 public static final int CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER = 14;
1603
1604 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001605 * Result code for {@link #checkProvisioningPreCondition}.
1606 *
1607 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when adding a managed profile is
1608 * disallowed by {@link UserManager#DISALLOW_ADD_MANAGED_PROFILE}.
1609 *
1610 * @hide
1611 */
1612 public static final int CODE_ADD_MANAGED_PROFILE_DISALLOWED = 15;
1613
1614 /**
1615 * Result codes for {@link #checkProvisioningPreCondition} indicating all the provisioning pre
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001616 * conditions.
1617 *
1618 * @hide
1619 */
1620 @Retention(RetentionPolicy.SOURCE)
Jeff Sharkeyce8db992017-12-13 20:05:05 -07001621 @IntDef(prefix = { "CODE_" }, value = {
1622 CODE_OK, CODE_HAS_DEVICE_OWNER, CODE_USER_HAS_PROFILE_OWNER, CODE_USER_NOT_RUNNING,
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001623 CODE_USER_SETUP_COMPLETED, CODE_NOT_SYSTEM_USER, CODE_HAS_PAIRED,
1624 CODE_MANAGED_USERS_NOT_SUPPORTED, CODE_SYSTEM_USER, CODE_CANNOT_ADD_MANAGED_PROFILE,
1625 CODE_NOT_SYSTEM_USER_SPLIT, CODE_DEVICE_ADMIN_NOT_SUPPORTED,
Jeff Sharkeyce8db992017-12-13 20:05:05 -07001626 CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER, CODE_ADD_MANAGED_PROFILE_DISALLOWED
1627 })
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001628 public @interface ProvisioningPreCondition {}
1629
1630 /**
Charles Hee078db72017-10-19 18:03:20 +01001631 * Disable all configurable SystemUI features during LockTask mode. This includes,
1632 * <ul>
1633 * <li>system info area in the status bar (connectivity icons, clock, etc.)
1634 * <li>notifications (including alerts, icons, and the notification shade)
1635 * <li>Home button
1636 * <li>Recents button and UI
1637 * <li>global actions menu (i.e. power button menu)
1638 * <li>keyguard
1639 * </ul>
1640 *
Charles Hee078db72017-10-19 18:03:20 +01001641 * @see #setLockTaskFeatures(ComponentName, int)
1642 */
1643 public static final int LOCK_TASK_FEATURE_NONE = 0;
1644
1645 /**
1646 * Enable the system info area in the status bar during LockTask mode. The system info area
1647 * usually occupies the right side of the status bar (although this can differ across OEMs). It
1648 * includes all system information indicators, such as date and time, connectivity, battery,
1649 * vibration mode, etc.
1650 *
1651 * @see #setLockTaskFeatures(ComponentName, int)
1652 */
1653 public static final int LOCK_TASK_FEATURE_SYSTEM_INFO = 1;
1654
1655 /**
1656 * Enable notifications during LockTask mode. This includes notification icons on the status
1657 * bar, heads-up notifications, and the expandable notification shade. Note that the Quick
Benjamin Franz78ae1062018-03-26 11:01:32 +01001658 * Settings panel remains disabled. This feature flag can only be used in combination with
1659 * {@link #LOCK_TASK_FEATURE_HOME}. {@link #setLockTaskFeatures(ComponentName, int)}
1660 * throws an {@link IllegalArgumentException} if this feature flag is defined without
1661 * {@link #LOCK_TASK_FEATURE_HOME}.
Charles Hee078db72017-10-19 18:03:20 +01001662 *
1663 * @see #setLockTaskFeatures(ComponentName, int)
1664 */
1665 public static final int LOCK_TASK_FEATURE_NOTIFICATIONS = 1 << 1;
1666
1667 /**
1668 * Enable the Home button during LockTask mode. Note that if a custom launcher is used, it has
1669 * to be registered as the default launcher with
1670 * {@link #addPersistentPreferredActivity(ComponentName, IntentFilter, ComponentName)}, and its
1671 * package needs to be whitelisted for LockTask with
1672 * {@link #setLockTaskPackages(ComponentName, String[])}.
1673 *
1674 * @see #setLockTaskFeatures(ComponentName, int)
1675 */
1676 public static final int LOCK_TASK_FEATURE_HOME = 1 << 2;
1677
1678 /**
Benjamin Franzcaffa772018-02-05 16:36:10 +00001679 * Enable the Overview button and the Overview screen during LockTask mode. This feature flag
1680 * can only be used in combination with {@link #LOCK_TASK_FEATURE_HOME}, and
1681 * {@link #setLockTaskFeatures(ComponentName, int)} will throw an
1682 * {@link IllegalArgumentException} if this feature flag is defined without
1683 * {@link #LOCK_TASK_FEATURE_HOME}.
Charles Hee078db72017-10-19 18:03:20 +01001684 *
1685 * @see #setLockTaskFeatures(ComponentName, int)
1686 */
Benjamin Franzcaffa772018-02-05 16:36:10 +00001687 public static final int LOCK_TASK_FEATURE_OVERVIEW = 1 << 3;
Charles Hee078db72017-10-19 18:03:20 +01001688
1689 /**
1690 * Enable the global actions dialog during LockTask mode. This is the dialog that shows up when
1691 * the user long-presses the power button, for example. Note that the user may not be able to
1692 * power off the device if this flag is not set.
1693 *
Benjamin Franz78ae1062018-03-26 11:01:32 +01001694 * <p>This flag is enabled by default until {@link #setLockTaskFeatures(ComponentName, int)} is
1695 * called for the first time.
1696 *
Charles Hee078db72017-10-19 18:03:20 +01001697 * @see #setLockTaskFeatures(ComponentName, int)
1698 */
1699 public static final int LOCK_TASK_FEATURE_GLOBAL_ACTIONS = 1 << 4;
1700
1701 /**
1702 * Enable the keyguard during LockTask mode. Note that if the keyguard is already disabled with
1703 * {@link #setKeyguardDisabled(ComponentName, boolean)}, setting this flag will have no effect.
1704 * If this flag is not set, the keyguard will not be shown even if the user has a lock screen
1705 * credential.
1706 *
1707 * @see #setLockTaskFeatures(ComponentName, int)
1708 */
1709 public static final int LOCK_TASK_FEATURE_KEYGUARD = 1 << 5;
1710
1711 /**
1712 * Flags supplied to {@link #setLockTaskFeatures(ComponentName, int)}.
1713 *
1714 * @hide
1715 */
1716 @Retention(RetentionPolicy.SOURCE)
Jeff Sharkeyce8db992017-12-13 20:05:05 -07001717 @IntDef(flag = true, prefix = { "LOCK_TASK_FEATURE_" }, value = {
1718 LOCK_TASK_FEATURE_NONE,
1719 LOCK_TASK_FEATURE_SYSTEM_INFO,
1720 LOCK_TASK_FEATURE_NOTIFICATIONS,
1721 LOCK_TASK_FEATURE_HOME,
Benjamin Franzcaffa772018-02-05 16:36:10 +00001722 LOCK_TASK_FEATURE_OVERVIEW,
Jeff Sharkeyce8db992017-12-13 20:05:05 -07001723 LOCK_TASK_FEATURE_GLOBAL_ACTIONS,
1724 LOCK_TASK_FEATURE_KEYGUARD
1725 })
Charles Hee078db72017-10-19 18:03:20 +01001726 public @interface LockTaskFeature {}
1727
1728 /**
Makoto Onukifc73d792017-03-22 14:22:35 -07001729 * Service action: Action for a service that device owner and profile owner can optionally
1730 * own. If a device owner or a profile owner has such a service, the system tries to keep
1731 * a bound connection to it, in order to keep their process always running.
Makoto Onukife739702017-04-25 13:26:21 -07001732 * The service must be protected with the {@link android.Manifest.permission#BIND_DEVICE_ADMIN}
1733 * permission.
Makoto Onukifc73d792017-03-22 14:22:35 -07001734 */
1735 @SdkConstant(SdkConstantType.SERVICE_ACTION)
1736 public static final String ACTION_DEVICE_ADMIN_SERVICE
1737 = "android.app.action.DEVICE_ADMIN_SERVICE";
1738
Eran Messeri94d56762017-12-21 20:50:54 +00001739 /** @hide */
1740 @Retention(RetentionPolicy.SOURCE)
1741 @IntDef(flag = true, prefix = {"ID_TYPE_"}, value = {
1742 ID_TYPE_BASE_INFO,
1743 ID_TYPE_SERIAL,
1744 ID_TYPE_IMEI,
1745 ID_TYPE_MEID
1746 })
1747 public @interface AttestationIdType {}
1748
1749 /**
1750 * Specifies that the device should attest its manufacturer details. For use with
1751 * {@link #generateKeyPair}.
1752 *
1753 * @see #generateKeyPair
1754 */
1755 public static final int ID_TYPE_BASE_INFO = 1;
1756
1757 /**
1758 * Specifies that the device should attest its serial number. For use with
1759 * {@link #generateKeyPair}.
1760 *
1761 * @see #generateKeyPair
1762 */
1763 public static final int ID_TYPE_SERIAL = 2;
1764
1765 /**
1766 * Specifies that the device should attest its IMEI. For use with {@link #generateKeyPair}.
1767 *
1768 * @see #generateKeyPair
1769 */
1770 public static final int ID_TYPE_IMEI = 4;
1771
1772 /**
1773 * Specifies that the device should attest its MEID. For use with {@link #generateKeyPair}.
1774 *
1775 * @see #generateKeyPair
1776 */
1777 public static final int ID_TYPE_MEID = 8;
1778
Makoto Onukifc73d792017-03-22 14:22:35 -07001779 /**
Eran Messerif15d4f42018-03-23 13:32:17 +00001780 * Specifies that the calling app should be granted access to the installed credentials
1781 * immediately. Otherwise, access to the credentials will be gated by user approval.
1782 * For use with {@link #installKeyPair(ComponentName, PrivateKey, Certificate[], String, int)}
1783 *
1784 * @see #installKeyPair(ComponentName, PrivateKey, Certificate[], String, int)
1785 */
1786 public static final int INSTALLKEY_REQUEST_CREDENTIALS_ACCESS = 1;
1787
1788 /**
1789 * Specifies that a user can select the key via the Certificate Selection prompt.
1790 * If this flag is not set when calling {@link #installKeyPair}, the key can only be granted
1791 * access by implementing {@link android.app.admin.DeviceAdminReceiver#onChoosePrivateKeyAlias}.
1792 * For use with {@link #installKeyPair(ComponentName, PrivateKey, Certificate[], String, int)}
1793 *
1794 * @see #installKeyPair(ComponentName, PrivateKey, Certificate[], String, int)
1795 */
1796 public static final int INSTALLKEY_SET_USER_SELECTABLE = 2;
1797
1798 /**
arangelov8bae4ea2017-12-20 20:26:46 +00001799 * Broadcast action: sent when the profile owner is set, changed or cleared.
1800 *
1801 * This broadcast is sent only to the user managed by the new profile owner.
1802 * @see DevicePolicyManager#transferOwnership(ComponentName, ComponentName, PersistableBundle)
1803 */
1804 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1805 public static final String ACTION_PROFILE_OWNER_CHANGED =
1806 "android.app.action.PROFILE_OWNER_CHANGED";
1807
1808 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001809 * Return true if the given administrator component is currently active (enabled) in the system.
1810 *
1811 * @param admin The administrator component to check for.
1812 * @return {@code true} if {@code admin} is currently enabled in the system, {@code false}
1813 * otherwise
Dianne Hackbornd6847842010-01-12 18:14:19 -08001814 */
Robin Lee25e26452015-06-02 09:56:29 -07001815 public boolean isAdminActive(@NonNull ComponentName admin) {
Charles He8c760562016-10-25 16:36:53 +01001816 throwIfParentInstance("isAdminActive");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001817 return isAdminActiveAsUser(admin, myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001818 }
1819
1820 /**
1821 * @see #isAdminActive(ComponentName)
1822 * @hide
1823 */
Robin Lee25e26452015-06-02 09:56:29 -07001824 public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001825 if (mService != null) {
1826 try {
Robin Lee25e26452015-06-02 09:56:29 -07001827 return mService.isAdminActive(admin, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001828 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001829 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001830 }
1831 }
1832 return false;
1833 }
Charles Hedea0c3b2017-01-13 10:04:12 +00001834
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001835 /**
1836 * Return true if the given administrator component is currently being removed
1837 * for the user.
1838 * @hide
1839 */
Robin Lee25e26452015-06-02 09:56:29 -07001840 public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) {
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001841 if (mService != null) {
1842 try {
Robin Lee25e26452015-06-02 09:56:29 -07001843 return mService.isRemovingAdmin(admin, userId);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001844 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001845 throw e.rethrowFromSystemServer();
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001846 }
1847 }
1848 return false;
1849 }
1850
Dianne Hackbornd6847842010-01-12 18:14:19 -08001851 /**
Robin Lee25e26452015-06-02 09:56:29 -07001852 * Return a list of all currently active device administrators' component
1853 * names. If there are no administrators {@code null} may be
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001854 * returned.
1855 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07001856 public @Nullable List<ComponentName> getActiveAdmins() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001857 throwIfParentInstance("getActiveAdmins");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001858 return getActiveAdminsAsUser(myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001859 }
1860
1861 /**
1862 * @see #getActiveAdmins()
1863 * @hide
1864 */
Mathew Inwood4fb17d12018-08-14 14:25:44 +01001865 @UnsupportedAppUsage
Makoto Onuki408e8e42016-10-25 12:10:27 -07001866 public @Nullable List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001867 if (mService != null) {
1868 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001869 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001870 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001871 throw e.rethrowFromSystemServer();
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001872 }
1873 }
1874 return null;
1875 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001876
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001877 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001878 * Used by package administration code to determine if a package can be stopped
1879 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001880 * @hide
1881 */
David Ouyang3a83a332017-01-11 16:36:40 -08001882 @SystemApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06001883 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001884 public boolean packageHasActiveAdmins(String packageName) {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001885 return packageHasActiveAdmins(packageName, myUserId());
1886 }
1887
1888 /**
1889 * Used by package administration code to determine if a package can be stopped
1890 * or uninstalled.
1891 * @hide
1892 */
Mathew Inwood4fb17d12018-08-14 14:25:44 +01001893 @UnsupportedAppUsage
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001894 public boolean packageHasActiveAdmins(String packageName, int userId) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001895 if (mService != null) {
1896 try {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001897 return mService.packageHasActiveAdmins(packageName, userId);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001898 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001899 throw e.rethrowFromSystemServer();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001900 }
1901 }
1902 return false;
1903 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001904
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001905 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001906 * Remove a current administration component. This can only be called
1907 * by the application that owns the administration component; if you
1908 * try to remove someone else's component, a security exception will be
1909 * thrown.
Esteban Talavera552a5612016-02-19 17:02:24 +00001910 *
1911 * <p>Note that the operation is not synchronous and the admin might still be active (as
1912 * indicated by {@link #getActiveAdmins()}) by the time this method returns.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001913 *
1914 * @param admin The administration compononent to remove.
1915 * @throws SecurityException if the caller is not in the owner application of {@code admin}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001916 */
Robin Lee25e26452015-06-02 09:56:29 -07001917 public void removeActiveAdmin(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001918 throwIfParentInstance("removeActiveAdmin");
Dianne Hackbornd6847842010-01-12 18:14:19 -08001919 if (mService != null) {
1920 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001921 mService.removeActiveAdmin(admin, myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001922 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001923 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001924 }
1925 }
1926 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001927
Dianne Hackbornd6847842010-01-12 18:14:19 -08001928 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001929 * Returns true if an administrator has been granted a particular device policy. This can be
1930 * used to check whether the administrator was activated under an earlier set of policies, but
1931 * requires additional policies after an upgrade.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001932 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001933 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be an
1934 * active administrator, or an exception will be thrown.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001935 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001936 * @throws SecurityException if {@code admin} is not an active administrator.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001937 */
Robin Lee25e26452015-06-02 09:56:29 -07001938 public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001939 throwIfParentInstance("hasGrantedPolicy");
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001940 if (mService != null) {
1941 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001942 return mService.hasGrantedPolicy(admin, usesPolicy, myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001943 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001944 throw e.rethrowFromSystemServer();
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001945 }
1946 }
1947 return false;
1948 }
1949
1950 /**
Clara Bayarria1771112015-12-18 16:29:18 +00001951 * Returns true if the Profile Challenge is available to use for the given profile user.
1952 *
1953 * @hide
1954 */
1955 public boolean isSeparateProfileChallengeAllowed(int userHandle) {
1956 if (mService != null) {
1957 try {
1958 return mService.isSeparateProfileChallengeAllowed(userHandle);
1959 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001960 throw e.rethrowFromSystemServer();
Clara Bayarria1771112015-12-18 16:29:18 +00001961 }
1962 }
1963 return false;
1964 }
1965
1966 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001967 * Constant for {@link #setPasswordQuality}: the policy has no requirements
1968 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001969 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001970 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001971 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001972
Dianne Hackbornd6847842010-01-12 18:14:19 -08001973 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -07001974 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
1975 * recognition technology. This implies technologies that can recognize the identity of
1976 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
1977 * Note that quality constants are ordered so that higher values are more restrictive.
1978 */
1979 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
1980
1981 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001982 * Constant for {@link #setPasswordQuality}: the policy requires some kind
Benjamin Franzc6a96532015-06-16 11:23:38 +01001983 * of password or pattern, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001984 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001985 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001986 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001987
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001988 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001989 * Constant for {@link #setPasswordQuality}: the user must have entered a
1990 * password containing at least numeric characters. Note that quality
1991 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001992 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001993 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001994
Dianne Hackbornd6847842010-01-12 18:14:19 -08001995 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001996 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -08001997 * password containing at least numeric characters with no repeating (4444)
1998 * or ordered (1234, 4321, 2468) sequences. Note that quality
1999 * constants are ordered so that higher values are more restrictive.
2000 */
2001 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
2002
2003 /**
2004 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07002005 * password containing at least alphabetic (or other symbol) characters.
2006 * Note that quality constants are ordered so that higher values are more
2007 * restrictive.
2008 */
2009 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002010
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07002011 /**
2012 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08002013 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07002014 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08002015 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002016 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07002017 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002018
Dianne Hackbornd6847842010-01-12 18:14:19 -08002019 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002020 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002021 * password containing at least a letter, a numerical digit and a special
2022 * symbol, by default. With this password quality, passwords can be
2023 * restricted to contain various sets of characters, like at least an
2024 * uppercase letter, etc. These are specified using various methods,
2025 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
2026 * that quality constants are ordered so that higher values are more
2027 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002028 */
2029 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
2030
2031 /**
Oleksandr Peletskyi0fdcd3d2016-01-13 16:49:56 +01002032 * Constant for {@link #setPasswordQuality}: the user is not allowed to
2033 * modify password. In case this password quality is set, the password is
2034 * managed by a profile owner. The profile owner can set any password,
2035 * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note
2036 * that quality constants are ordered so that higher values are more
2037 * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is
2038 * the highest.
2039 * @hide
2040 */
2041 public static final int PASSWORD_QUALITY_MANAGED = 0x80000;
2042
2043 /**
Makoto Onuki5e7e06702016-09-01 18:02:01 -07002044 * @hide
2045 *
2046 * adb shell dpm set-{device,profile}-owner will normally not allow installing an owner to
2047 * a user with accounts. {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED}
2048 * and {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} are the account features
2049 * used by authenticator to exempt their accounts from this:
2050 *
2051 * <ul>
2052 * <li>Non-test-only DO/PO still can't be installed when there are accounts.
2053 * <p>In order to make an apk test-only, add android:testOnly="true" to the
2054 * &lt;application&gt; tag in the manifest.
2055 *
2056 * <li>Test-only DO/PO can be installed even when there are accounts, as long as all the
2057 * accounts have the {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} feature.
2058 * Some authenticators claim to have any features, so to detect it, we also check
2059 * {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} and disallow installing
2060 * if any of the accounts have it.
2061 * </ul>
2062 */
Makoto Onuki47c203d2017-02-13 16:21:19 -08002063 @SystemApi
2064 @TestApi
Makoto Onuki5e7e06702016-09-01 18:02:01 -07002065 public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED =
2066 "android.account.DEVICE_OR_PROFILE_OWNER_ALLOWED";
2067
2068 /** @hide See {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} */
Makoto Onuki47c203d2017-02-13 16:21:19 -08002069 @SystemApi
2070 @TestApi
Makoto Onuki5e7e06702016-09-01 18:02:01 -07002071 public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED =
2072 "android.account.DEVICE_OR_PROFILE_OWNER_DISALLOWED";
2073
2074 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002075 * Called by an application that is administering the device to set the password restrictions it
2076 * is imposing. After setting this, the user will not be able to enter a new password that is
2077 * not at least as restrictive as what has been set. Note that the current password will remain
2078 * until the user has set a new one, so the change does not take place immediately. To prompt
2079 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
Esteban Talaverac1c83592016-02-17 17:56:15 +00002080 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after calling this method.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002081 * <p>
2082 * Quality constants are ordered so that higher values are more restrictive; thus the highest
2083 * requested quality constant (between the policy set here, the user's preference, and any other
2084 * considerations) is the one that is in effect.
2085 * <p>
2086 * The calling device admin must have requested
2087 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2088 * not, a security exception will be thrown.
2089 * <p>
2090 * This method can be called on the {@link DevicePolicyManager} instance returned by
2091 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2092 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002093 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002094 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002095 * @param quality The new desired quality. One of {@link #PASSWORD_QUALITY_UNSPECIFIED},
2096 * {@link #PASSWORD_QUALITY_SOMETHING}, {@link #PASSWORD_QUALITY_NUMERIC},
2097 * {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC},
2098 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} or {@link #PASSWORD_QUALITY_COMPLEX}.
2099 * @throws SecurityException if {@code admin} is not an active administrator or if {@code admin}
2100 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002101 */
Robin Lee25e26452015-06-02 09:56:29 -07002102 public void setPasswordQuality(@NonNull ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002103 if (mService != null) {
2104 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00002105 mService.setPasswordQuality(admin, quality, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002106 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002107 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002108 }
2109 }
2110 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002111
Dianne Hackbornd6847842010-01-12 18:14:19 -08002112 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002113 * Retrieve the current minimum password quality for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01002114 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00002115 * a separate challenge are not taken into account.
2116 *
2117 * <p>This method can be called on the {@link DevicePolicyManager} instance
2118 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2119 * restrictions on the parent profile.
2120 *
Robin Lee25e26452015-06-02 09:56:29 -07002121 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002122 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002123 */
Robin Lee25e26452015-06-02 09:56:29 -07002124 public int getPasswordQuality(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002125 return getPasswordQuality(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002126 }
2127
2128 /** @hide per-user version */
Mathew Inwood55418ea2018-12-20 15:30:45 +00002129 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Robin Lee25e26452015-06-02 09:56:29 -07002130 public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002131 if (mService != null) {
2132 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00002133 return mService.getPasswordQuality(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002134 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002135 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002136 }
2137 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08002138 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -08002139 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002140
Dianne Hackbornd6847842010-01-12 18:14:19 -08002141 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002142 * Called by an application that is administering the device to set the minimum allowed password
2143 * length. After setting this, the user will not be able to enter a new password that is not at
2144 * least as restrictive as what has been set. Note that the current password will remain until
2145 * the user has set a new one, so the change does not take place immediately. To prompt the user
2146 * for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
2147 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
2148 * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC}
2149 * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC},
2150 * {@link #PASSWORD_QUALITY_ALPHANUMERIC}, or {@link #PASSWORD_QUALITY_COMPLEX} with
2151 * {@link #setPasswordQuality}.
2152 * <p>
2153 * The calling device admin must have requested
2154 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2155 * not, a security exception will be thrown.
2156 * <p>
2157 * This method can be called on the {@link DevicePolicyManager} instance returned by
2158 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2159 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002160 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002161 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002162 * @param length The new desired minimum password length. A value of 0 means there is no
2163 * restriction.
2164 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2165 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002166 */
Robin Lee25e26452015-06-02 09:56:29 -07002167 public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002168 if (mService != null) {
2169 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002170 mService.setPasswordMinimumLength(admin, length, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002171 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002172 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002173 }
2174 }
2175 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002176
Dianne Hackbornd6847842010-01-12 18:14:19 -08002177 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002178 * Retrieve the current minimum password length for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01002179 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00002180 * a separate challenge are not taken into account.
2181 *
2182 * <p>This method can be called on the {@link DevicePolicyManager} instance
2183 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2184 * restrictions on the parent profile.
2185 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01002186 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07002187 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002188 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002189 */
Robin Lee25e26452015-06-02 09:56:29 -07002190 public int getPasswordMinimumLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002191 return getPasswordMinimumLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002192 }
2193
2194 /** @hide per-user version */
Mathew Inwood55418ea2018-12-20 15:30:45 +00002195 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Robin Lee25e26452015-06-02 09:56:29 -07002196 public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002197 if (mService != null) {
2198 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002199 return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002200 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002201 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002202 }
2203 }
2204 return 0;
2205 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002206
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002207 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002208 * Called by an application that is administering the device to set the minimum number of upper
2209 * case letters required in the password. After setting this, the user will not be able to enter
2210 * a new password that is not at least as restrictive as what has been set. Note that the
2211 * current password will remain until the user has set a new one, so the change does not take
2212 * place immediately. To prompt the user for a new password, use
2213 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
2214 * setting this value. This constraint is only imposed if the administrator has also requested
2215 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002216 * <p>
2217 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002218 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2219 * not, a security exception will be thrown.
2220 * <p>
2221 * This method can be called on the {@link DevicePolicyManager} instance returned by
2222 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2223 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002224 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002225 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2226 * @param length The new desired minimum number of upper case letters required in the password.
2227 * A value of 0 means there is no restriction.
2228 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2229 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002230 */
Robin Lee25e26452015-06-02 09:56:29 -07002231 public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002232 if (mService != null) {
2233 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002234 mService.setPasswordMinimumUpperCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002235 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002236 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002237 }
2238 }
2239 }
2240
2241 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002242 * Retrieve the current number of upper case letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002243 * for a particular admin or all admins that set restrictions on this user and
Esteban Talaverac1c83592016-02-17 17:56:15 +00002244 * its participating profiles. Restrictions on profiles that have a separate challenge
2245 * are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01002246 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00002247 * {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002248 * and only applies when the password quality is
2249 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002250 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002251 * <p>This method can be called on the {@link DevicePolicyManager} instance
2252 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2253 * restrictions on the parent profile.
2254 *
Robin Lee25e26452015-06-02 09:56:29 -07002255 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002256 * aggregate all admins.
2257 * @return The minimum number of upper case letters required in the
2258 * password.
2259 */
Robin Lee25e26452015-06-02 09:56:29 -07002260 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002261 return getPasswordMinimumUpperCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002262 }
2263
2264 /** @hide per-user version */
Mathew Inwood55418ea2018-12-20 15:30:45 +00002265 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Robin Lee25e26452015-06-02 09:56:29 -07002266 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002267 if (mService != null) {
2268 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002269 return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002270 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002271 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002272 }
2273 }
2274 return 0;
2275 }
2276
2277 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002278 * Called by an application that is administering the device to set the minimum number of lower
2279 * case letters required in the password. After setting this, the user will not be able to enter
2280 * a new password that is not at least as restrictive as what has been set. Note that the
2281 * current password will remain until the user has set a new one, so the change does not take
2282 * place immediately. To prompt the user for a new password, use
2283 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
2284 * setting this value. This constraint is only imposed if the administrator has also requested
2285 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002286 * <p>
2287 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002288 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2289 * not, a security exception will be thrown.
2290 * <p>
2291 * This method can be called on the {@link DevicePolicyManager} instance returned by
2292 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2293 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002294 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002295 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2296 * @param length The new desired minimum number of lower case letters required in the password.
2297 * A value of 0 means there is no restriction.
2298 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2299 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002300 */
Robin Lee25e26452015-06-02 09:56:29 -07002301 public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002302 if (mService != null) {
2303 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002304 mService.setPasswordMinimumLowerCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002305 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002306 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002307 }
2308 }
2309 }
2310
2311 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002312 * Retrieve the current number of lower case letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002313 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002314 * and its participating profiles. Restrictions on profiles that have
2315 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01002316 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00002317 * {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002318 * and only applies when the password quality is
2319 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002320 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002321 * <p>This method can be called on the {@link DevicePolicyManager} instance
2322 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2323 * restrictions on the parent profile.
2324 *
Robin Lee25e26452015-06-02 09:56:29 -07002325 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002326 * aggregate all admins.
2327 * @return The minimum number of lower case letters required in the
2328 * password.
2329 */
Robin Lee25e26452015-06-02 09:56:29 -07002330 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002331 return getPasswordMinimumLowerCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002332 }
2333
2334 /** @hide per-user version */
Mathew Inwood55418ea2018-12-20 15:30:45 +00002335 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Robin Lee25e26452015-06-02 09:56:29 -07002336 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002337 if (mService != null) {
2338 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002339 return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002340 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002341 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002342 }
2343 }
2344 return 0;
2345 }
2346
2347 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002348 * Called by an application that is administering the device to set the minimum number of
2349 * letters required in the password. After setting this, the user will not be able to enter a
2350 * new password that is not at least as restrictive as what has been set. Note that the current
2351 * password will remain until the user has set a new one, so the change does not take place
2352 * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
2353 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
2354 * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
2355 * {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002356 * <p>
2357 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002358 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2359 * not, a security exception will be thrown.
2360 * <p>
2361 * This method can be called on the {@link DevicePolicyManager} instance returned by
2362 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2363 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002364 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002365 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2366 * @param length The new desired minimum number of letters required in the password. A value of
2367 * 0 means there is no restriction.
2368 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2369 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002370 */
Robin Lee25e26452015-06-02 09:56:29 -07002371 public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002372 if (mService != null) {
2373 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002374 mService.setPasswordMinimumLetters(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002375 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002376 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002377 }
2378 }
2379 }
2380
2381 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002382 * Retrieve the current number of letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002383 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002384 * and its participating profiles. Restrictions on profiles that have
2385 * a separate challenge are not taken into account.
2386 * This is the same value as set by
2387 * {@link #setPasswordMinimumLetters(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002388 * and only applies when the password quality is
2389 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002390 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002391 * <p>This method can be called on the {@link DevicePolicyManager} instance
2392 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2393 * restrictions on the parent profile.
2394 *
Robin Lee25e26452015-06-02 09:56:29 -07002395 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002396 * aggregate all admins.
2397 * @return The minimum number of letters required in the password.
2398 */
Robin Lee25e26452015-06-02 09:56:29 -07002399 public int getPasswordMinimumLetters(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002400 return getPasswordMinimumLetters(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002401 }
2402
2403 /** @hide per-user version */
Mathew Inwood55418ea2018-12-20 15:30:45 +00002404 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Robin Lee25e26452015-06-02 09:56:29 -07002405 public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002406 if (mService != null) {
2407 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002408 return mService.getPasswordMinimumLetters(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002409 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002410 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002411 }
2412 }
2413 return 0;
2414 }
2415
2416 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002417 * Called by an application that is administering the device to set the minimum number of
2418 * numerical digits required in the password. After setting this, the user will not be able to
2419 * enter a new password that is not at least as restrictive as what has been set. Note that the
2420 * current password will remain until the user has set a new one, so the change does not take
2421 * place immediately. To prompt the user for a new password, use
2422 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
2423 * setting this value. This constraint is only imposed if the administrator has also requested
2424 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002425 * <p>
2426 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002427 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2428 * not, a security exception will be thrown.
2429 * <p>
2430 * This method can be called on the {@link DevicePolicyManager} instance returned by
2431 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2432 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002433 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002434 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2435 * @param length The new desired minimum number of numerical digits required in the password. A
2436 * value of 0 means there is no restriction.
2437 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2438 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002439 */
Robin Lee25e26452015-06-02 09:56:29 -07002440 public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002441 if (mService != null) {
2442 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002443 mService.setPasswordMinimumNumeric(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002444 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002445 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002446 }
2447 }
2448 }
2449
2450 /**
2451 * Retrieve the current number of numerical digits required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002452 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002453 * and its participating profiles. Restrictions on profiles that have
2454 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01002455 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00002456 * {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002457 * and only applies when the password quality is
2458 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002459 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002460 * <p>This method can be called on the {@link DevicePolicyManager} instance
2461 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2462 * restrictions on the parent profile.
2463 *
Robin Lee25e26452015-06-02 09:56:29 -07002464 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002465 * aggregate all admins.
2466 * @return The minimum number of numerical digits required in the password.
2467 */
Robin Lee25e26452015-06-02 09:56:29 -07002468 public int getPasswordMinimumNumeric(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002469 return getPasswordMinimumNumeric(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002470 }
2471
2472 /** @hide per-user version */
Mathew Inwood55418ea2018-12-20 15:30:45 +00002473 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Robin Lee25e26452015-06-02 09:56:29 -07002474 public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002475 if (mService != null) {
2476 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002477 return mService.getPasswordMinimumNumeric(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002478 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002479 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002480 }
2481 }
2482 return 0;
2483 }
2484
2485 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002486 * Called by an application that is administering the device to set the minimum number of
2487 * symbols required in the password. After setting this, the user will not be able to enter a
2488 * new password that is not at least as restrictive as what has been set. Note that the current
2489 * password will remain until the user has set a new one, so the change does not take place
2490 * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
2491 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
2492 * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
2493 * {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002494 * <p>
2495 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002496 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2497 * not, a security exception will be thrown.
2498 * <p>
2499 * This method can be called on the {@link DevicePolicyManager} instance returned by
2500 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2501 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002502 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002503 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2504 * @param length The new desired minimum number of symbols required in the password. A value of
2505 * 0 means there is no restriction.
2506 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2507 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002508 */
Robin Lee25e26452015-06-02 09:56:29 -07002509 public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002510 if (mService != null) {
2511 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002512 mService.setPasswordMinimumSymbols(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002513 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002514 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002515 }
2516 }
2517 }
2518
2519 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002520 * Retrieve the current number of symbols required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002521 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002522 * and its participating profiles. Restrictions on profiles that have
2523 * a separate challenge are not taken into account. This is the same value as
2524 * set by {@link #setPasswordMinimumSymbols(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002525 * and only applies when the password quality is
2526 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002527 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002528 * <p>This method can be called on the {@link DevicePolicyManager} instance
2529 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2530 * restrictions on the parent profile.
2531 *
Robin Lee25e26452015-06-02 09:56:29 -07002532 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002533 * aggregate all admins.
2534 * @return The minimum number of symbols required in the password.
2535 */
Robin Lee25e26452015-06-02 09:56:29 -07002536 public int getPasswordMinimumSymbols(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002537 return getPasswordMinimumSymbols(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002538 }
2539
2540 /** @hide per-user version */
Mathew Inwood55418ea2018-12-20 15:30:45 +00002541 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Robin Lee25e26452015-06-02 09:56:29 -07002542 public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002543 if (mService != null) {
2544 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002545 return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002546 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002547 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002548 }
2549 }
2550 return 0;
2551 }
2552
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002553 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002554 * Called by an application that is administering the device to set the minimum number of
2555 * non-letter characters (numerical digits or symbols) required in the password. After setting
2556 * this, the user will not be able to enter a new password that is not at least as restrictive
2557 * as what has been set. Note that the current password will remain until the user has set a new
2558 * one, so the change does not take place immediately. To prompt the user for a new password,
2559 * use {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
2560 * setting this value. This constraint is only imposed if the administrator has also requested
2561 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002562 * <p>
2563 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002564 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2565 * not, a security exception will be thrown.
2566 * <p>
2567 * This method can be called on the {@link DevicePolicyManager} instance returned by
2568 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2569 * profile.
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002570 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002571 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2572 * @param length The new desired minimum number of letters required in the password. A value of
2573 * 0 means there is no restriction.
2574 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2575 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002576 */
Robin Lee25e26452015-06-02 09:56:29 -07002577 public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002578 if (mService != null) {
2579 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002580 mService.setPasswordMinimumNonLetter(admin, length, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002581 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002582 throw e.rethrowFromSystemServer();
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002583 }
2584 }
2585 }
2586
2587 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002588 * Retrieve the current number of non-letter characters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002589 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002590 * and its participating profiles. Restrictions on profiles that have
2591 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01002592 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00002593 * {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002594 * and only applies when the password quality is
2595 * {@link #PASSWORD_QUALITY_COMPLEX}.
2596 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002597 * <p>This method can be called on the {@link DevicePolicyManager} instance
2598 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2599 * restrictions on the parent profile.
2600 *
Robin Lee25e26452015-06-02 09:56:29 -07002601 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002602 * aggregate all admins.
2603 * @return The minimum number of letters required in the password.
2604 */
Robin Lee25e26452015-06-02 09:56:29 -07002605 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002606 return getPasswordMinimumNonLetter(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002607 }
2608
2609 /** @hide per-user version */
Mathew Inwood55418ea2018-12-20 15:30:45 +00002610 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Robin Lee25e26452015-06-02 09:56:29 -07002611 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002612 if (mService != null) {
2613 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002614 return mService.getPasswordMinimumNonLetter(admin, userHandle, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002615 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002616 throw e.rethrowFromSystemServer();
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002617 }
2618 }
2619 return 0;
2620 }
2621
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002622 /**
2623 * Called by an application that is administering the device to set the length of the password
2624 * history. After setting this, the user will not be able to enter a new password that is the
2625 * same as any password in the history. Note that the current password will remain until the
2626 * user has set a new one, so the change does not take place immediately. To prompt the user for
2627 * a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
2628 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
2629 * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC}
2630 * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX} {@link #PASSWORD_QUALITY_ALPHABETIC}, or
2631 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} with {@link #setPasswordQuality}.
2632 * <p>
2633 * The calling device admin must have requested
2634 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2635 * not, a security exception will be thrown.
2636 * <p>
2637 * This method can be called on the {@link DevicePolicyManager} instance returned by
2638 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2639 * profile.
2640 *
2641 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2642 * @param length The new desired length of password history. A value of 0 means there is no
2643 * restriction.
2644 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2645 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
2646 */
Robin Lee25e26452015-06-02 09:56:29 -07002647 public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002648 if (mService != null) {
2649 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002650 mService.setPasswordHistoryLength(admin, length, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002651 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002652 throw e.rethrowFromSystemServer();
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002653 }
2654 }
2655 }
2656
2657 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002658 * Called by a device admin to set the password expiration timeout. Calling this method will
2659 * restart the countdown for password expiration for the given admin, as will changing the
2660 * device password (for all admins).
2661 * <p>
2662 * The provided timeout is the time delta in ms and will be added to the current time. For
2663 * example, to have the password expire 5 days from now, timeout would be 5 * 86400 * 1000 =
2664 * 432000000 ms for timeout.
2665 * <p>
2666 * To disable password expiration, a value of 0 may be used for timeout.
2667 * <p>
2668 * The calling device admin must have requested
2669 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this method; if it has
2670 * not, a security exception will be thrown.
2671 * <p>
2672 * Note that setting the password will automatically reset the expiration time for all active
2673 * admins. Active admins do not need to explicitly call this method in that case.
2674 * <p>
2675 * This method can be called on the {@link DevicePolicyManager} instance returned by
2676 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2677 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002678 *
Jim Millera4e28d12010-11-08 16:15:47 -08002679 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002680 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0 means
2681 * there is no restriction (unlimited).
2682 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2683 * does not use {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD}
Jim Millera4e28d12010-11-08 16:15:47 -08002684 */
Robin Lee25e26452015-06-02 09:56:29 -07002685 public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) {
Jim Millera4e28d12010-11-08 16:15:47 -08002686 if (mService != null) {
2687 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002688 mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08002689 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002690 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08002691 }
2692 }
2693 }
2694
2695 /**
Jim Miller6b857682011-02-16 16:27:41 -08002696 * Get the password expiration timeout for the given admin. The expiration timeout is the
2697 * recurring expiration timeout provided in the call to
2698 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
Esteban Talaverac1c83592016-02-17 17:56:15 +00002699 * aggregate of all participating policy administrators if {@code admin} is null. Admins that
2700 * have set restrictions on profiles that have a separate challenge are not taken into account.
2701 *
2702 * <p>This method can be called on the {@link DevicePolicyManager} instance
2703 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2704 * restrictions on the parent profile.
Jim Millera4e28d12010-11-08 16:15:47 -08002705 *
Robin Lee25e26452015-06-02 09:56:29 -07002706 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08002707 * @return The timeout for the given admin or the minimum of all timeouts
2708 */
Robin Lee25e26452015-06-02 09:56:29 -07002709 public long getPasswordExpirationTimeout(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08002710 if (mService != null) {
2711 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002712 return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08002713 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002714 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08002715 }
2716 }
2717 return 0;
2718 }
2719
2720 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002721 * Get the current password expiration time for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01002722 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00002723 * a separate challenge are not taken into account. If admin is {@code null}, then a composite
2724 * of all expiration times is returned - which will be the minimum of all of them.
2725 *
2726 * <p>This method can be called on the {@link DevicePolicyManager} instance
2727 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2728 * the password expiration for the parent profile.
Jim Millera4e28d12010-11-08 16:15:47 -08002729 *
Robin Lee25e26452015-06-02 09:56:29 -07002730 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002731 * @return The password expiration time, in milliseconds since epoch.
Jim Millera4e28d12010-11-08 16:15:47 -08002732 */
Robin Lee25e26452015-06-02 09:56:29 -07002733 public long getPasswordExpiration(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08002734 if (mService != null) {
2735 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002736 return mService.getPasswordExpiration(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08002737 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002738 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08002739 }
2740 }
2741 return 0;
2742 }
2743
2744 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002745 * Retrieve the current password history length for a particular admin or all admins that
Rubin Xud3609d42016-07-13 18:32:57 +01002746 * set restrictions on this user and its participating profiles. Restrictions on profiles that
Esteban Talaverac1c83592016-02-17 17:56:15 +00002747 * have a separate challenge are not taken into account.
2748 *
2749 * <p>This method can be called on the {@link DevicePolicyManager} instance
2750 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2751 * restrictions on the parent profile.
2752 *
Robin Lee25e26452015-06-02 09:56:29 -07002753 * @param admin The name of the admin component to check, or {@code null} to aggregate
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002754 * all admins.
2755 * @return The length of the password history
2756 */
Robin Lee25e26452015-06-02 09:56:29 -07002757 public int getPasswordHistoryLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002758 return getPasswordHistoryLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002759 }
2760
2761 /** @hide per-user version */
Mathew Inwood55418ea2018-12-20 15:30:45 +00002762 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Robin Lee25e26452015-06-02 09:56:29 -07002763 public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002764 if (mService != null) {
2765 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002766 return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002767 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002768 throw e.rethrowFromSystemServer();
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002769 }
2770 }
2771 return 0;
2772 }
2773
Dianne Hackbornd6847842010-01-12 18:14:19 -08002774 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08002775 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08002776 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08002777 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08002778 * @return Returns the maximum length that the user can enter.
2779 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08002780 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08002781 // Kind-of arbitrary.
2782 return 16;
2783 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002784
Dianne Hackborn254cb442010-01-27 19:23:59 -08002785 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002786 * Determine whether the current password the user has set is sufficient to meet the policy
2787 * requirements (e.g. quality, minimum length) that have been requested by the admins of this
2788 * user and its participating profiles. Restrictions on profiles that have a separate challenge
Benjamin Millercc12c5f2018-04-16 12:54:43 +00002789 * are not taken into account. The user must be unlocked in order to perform the check.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002790 * <p>
2791 * The calling device admin must have requested
2792 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2793 * not, a security exception will be thrown.
2794 * <p>
2795 * This method can be called on the {@link DevicePolicyManager} instance returned by
2796 * {@link #getParentProfileInstance(ComponentName)} in order to determine if the password set on
2797 * the parent profile is sufficient.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002798 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01002799 * @return Returns true if the password meets the current requirements, else false.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002800 * @throws SecurityException if the calling application does not own an active administrator
2801 * that uses {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Rubin Xu7cf45092017-08-28 11:47:35 +01002802 * @throws IllegalStateException if the user is not unlocked.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002803 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002804 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002805 if (mService != null) {
2806 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00002807 return mService.isActivePasswordSufficient(myUserId(), mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002808 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002809 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002810 }
2811 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002812 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08002813 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002814
Dianne Hackbornd6847842010-01-12 18:14:19 -08002815 /**
Pavel Grafovc4f87e92017-10-26 16:34:25 +01002816 * When called by a profile owner of a managed profile returns true if the profile uses unified
2817 * challenge with its parent user.
2818 *
Benjamin Milleredbc4c42018-02-22 08:49:21 +00002819 * <strong>Note</strong>: This method is not concerned with password quality and will return
2820 * false if the profile has empty password as a separate challenge.
Pavel Grafovc4f87e92017-10-26 16:34:25 +01002821 *
2822 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Tony Mak6a975352018-03-06 11:33:55 +00002823 * @throws SecurityException if {@code admin} is not a profile owner of a managed profile.
Pavel Grafovc4f87e92017-10-26 16:34:25 +01002824 * @see UserManager#DISALLOW_UNIFIED_PASSWORD
2825 */
2826 public boolean isUsingUnifiedPassword(@NonNull ComponentName admin) {
Pavel Grafov3b27ed02017-12-18 18:02:47 +00002827 throwIfParentInstance("isUsingUnifiedPassword");
Pavel Grafovc4f87e92017-10-26 16:34:25 +01002828 if (mService != null) {
2829 try {
2830 return mService.isUsingUnifiedPassword(admin);
2831 } catch (RemoteException e) {
2832 throw e.rethrowFromSystemServer();
2833 }
2834 }
2835 return true;
2836 }
2837
2838 /**
Clara Bayarrid7693912016-01-22 17:26:31 +00002839 * Determine whether the current profile password the user has set is sufficient
Esteban Talaverac1c83592016-02-17 17:56:15 +00002840 * to meet the policy requirements (e.g. quality, minimum length) that have been
Clara Bayarrid7693912016-01-22 17:26:31 +00002841 * requested by the admins of the parent user and its profiles.
2842 *
2843 * @param userHandle the userId of the profile to check the password for.
2844 * @return Returns true if the password would meet the current requirements, else false.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002845 * @throws SecurityException if {@code userHandle} is not a managed profile.
Clara Bayarrid7693912016-01-22 17:26:31 +00002846 * @hide
2847 */
2848 public boolean isProfileActivePasswordSufficientForParent(int userHandle) {
2849 if (mService != null) {
2850 try {
2851 return mService.isProfileActivePasswordSufficientForParent(userHandle);
2852 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002853 throw e.rethrowFromSystemServer();
Clara Bayarrid7693912016-01-22 17:26:31 +00002854 }
2855 }
2856 return false;
2857 }
2858
2859 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002860 * Retrieve the number of times the user has failed at entering a password since that last
2861 * successful password entry.
2862 * <p>
2863 * This method can be called on the {@link DevicePolicyManager} instance returned by
2864 * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the number of failed
2865 * password attemts for the parent user.
2866 * <p>
2867 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN}
2868 * to be able to call this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002869 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002870 * @return The number of times user has entered an incorrect password since the last correct
2871 * password entry.
2872 * @throws SecurityException if the calling application does not own an active administrator
2873 * that uses {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002874 */
2875 public int getCurrentFailedPasswordAttempts() {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00002876 return getCurrentFailedPasswordAttempts(myUserId());
2877 }
2878
2879 /**
2880 * Retrieve the number of times the given user has failed at entering a
2881 * password since that last successful password entry.
2882 *
2883 * <p>The calling device admin must have requested
2884 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call this method; if it has
2885 * not and it is not the system uid, a security exception will be thrown.
2886 *
2887 * @hide
2888 */
Mathew Inwood4fb17d12018-08-14 14:25:44 +01002889 @UnsupportedAppUsage
Clara Bayarri51e41ad2016-02-11 17:48:53 +00002890 public int getCurrentFailedPasswordAttempts(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002891 if (mService != null) {
2892 try {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00002893 return mService.getCurrentFailedPasswordAttempts(userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002894 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002895 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002896 }
2897 }
2898 return -1;
2899 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002900
2901 /**
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002902 * Queries whether {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002903 *
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002904 * @return true if RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002905 * @hide
2906 */
2907 public boolean getDoNotAskCredentialsOnBoot() {
2908 if (mService != null) {
2909 try {
2910 return mService.getDoNotAskCredentialsOnBoot();
2911 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002912 throw e.rethrowFromSystemServer();
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002913 }
2914 }
2915 return false;
2916 }
2917
2918 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002919 * Setting this to a value greater than zero enables a built-in policy that will perform a
2920 * device or profile wipe after too many incorrect device-unlock passwords have been entered.
2921 * This built-in policy combines watching for failed passwords and wiping the device, and
2922 * requires that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002923 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002924 * <p>
2925 * To implement any other policy (e.g. wiping data for a particular application only, erasing or
2926 * revoking credentials, or reporting the failure to a server), you should implement
2927 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} instead. Do not
2928 * use this API, because if the maximum count is reached, the device or profile will be wiped
2929 * immediately, and your callback will not be invoked.
2930 * <p>
2931 * This method can be called on the {@link DevicePolicyManager} instance returned by
2932 * {@link #getParentProfileInstance(ComponentName)} in order to set a value on the parent
2933 * profile.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002934 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002935 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002936 * @param num The number of failed password attempts at which point the device or profile will
2937 * be wiped.
2938 * @throws SecurityException if {@code admin} is not an active administrator or does not use
2939 * both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
2940 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002941 */
Robin Lee25e26452015-06-02 09:56:29 -07002942 public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002943 if (mService != null) {
2944 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002945 mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002946 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002947 throw e.rethrowFromSystemServer();
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002948 }
2949 }
2950 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002951
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002952 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002953 * Retrieve the current maximum number of login attempts that are allowed before the device
Rubin Xud3609d42016-07-13 18:32:57 +01002954 * or profile is wiped, for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002955 * and its participating profiles. Restrictions on profiles that have a separate challenge are
2956 * not taken into account.
2957 *
2958 * <p>This method can be called on the {@link DevicePolicyManager} instance
2959 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2960 * the value for the parent profile.
2961 *
Robin Lee25e26452015-06-02 09:56:29 -07002962 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002963 * all admins.
2964 */
Robin Lee25e26452015-06-02 09:56:29 -07002965 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002966 return getMaximumFailedPasswordsForWipe(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002967 }
2968
2969 /** @hide per-user version */
Mathew Inwood4fb17d12018-08-14 14:25:44 +01002970 @UnsupportedAppUsage
Robin Lee25e26452015-06-02 09:56:29 -07002971 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08002972 if (mService != null) {
2973 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002974 return mService.getMaximumFailedPasswordsForWipe(
2975 admin, userHandle, mParentInstance);
Dianne Hackborn254cb442010-01-27 19:23:59 -08002976 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002977 throw e.rethrowFromSystemServer();
Dianne Hackborn254cb442010-01-27 19:23:59 -08002978 }
2979 }
2980 return 0;
2981 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002982
Dianne Hackborn254cb442010-01-27 19:23:59 -08002983 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002984 * Returns the profile with the smallest maximum failed passwords for wipe,
2985 * for the given user. So for primary user, it might return the primary or
2986 * a managed profile. For a secondary user, it would be the same as the
2987 * user passed in.
2988 * @hide Used only by Keyguard
2989 */
2990 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
2991 if (mService != null) {
2992 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002993 return mService.getProfileWithMinimumFailedPasswordsForWipe(
2994 userHandle, mParentInstance);
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002995 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002996 throw e.rethrowFromSystemServer();
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002997 }
2998 }
2999 return UserHandle.USER_NULL;
3000 }
3001
3002 /**
Benjamin Miller1aed7882017-08-15 18:04:20 +02003003 * Flag for {@link #resetPasswordWithToken} and {@link #resetPassword}: don't allow other admins
3004 * to change the password again until the user has entered it.
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08003005 */
3006 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003007
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08003008 /**
Benjamin Miller1aed7882017-08-15 18:04:20 +02003009 * Flag for {@link #resetPasswordWithToken} and {@link #resetPassword}: don't ask for user
3010 * credentials on device boot.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04003011 * If the flag is set, the device can be booted without asking for user password.
3012 * The absence of this flag does not change the current boot requirements. This flag
3013 * can be set by the device owner only. If the app is not the device owner, the flag
3014 * is ignored. Once the flag is set, it cannot be reverted back without resetting the
3015 * device to factory defaults.
3016 */
Craig Lafayette4e401fa2015-05-07 10:24:02 -04003017 public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002;
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04003018
3019 /**
Benjamin Miller1aed7882017-08-15 18:04:20 +02003020 * Force a new password for device unlock (the password needed to access the entire device) or
3021 * the work profile challenge on the current user. This takes effect immediately.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003022 * <p>
Rubin Xuaab7a412016-12-30 21:13:29 +00003023 * <em>For device owner and profile owners targeting SDK level
3024 * {@link android.os.Build.VERSION_CODES#O} or above, this API is no longer available and will
3025 * throw {@link SecurityException}. Please use the new API {@link #resetPasswordWithToken}
3026 * instead. </em>
3027 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003028 * <em>Note: This API has been limited as of {@link android.os.Build.VERSION_CODES#N} for
Makoto Onuki70f929e2015-11-11 12:40:15 -08003029 * device admins that are not device owner and not profile owner.
3030 * The password can now only be changed if there is currently no password set. Device owner
Ricky Wai977ade22016-05-24 15:02:41 +01003031 * and profile owner can still do this when user is unlocked and does not have a managed
3032 * profile.</em>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003033 * <p>
3034 * The given password must be sufficient for the current password quality and length constraints
3035 * as returned by {@link #getPasswordQuality(ComponentName)} and
3036 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then
3037 * it will be rejected and false returned. Note that the password may be a stronger quality
3038 * (containing alphanumeric characters when the requested quality is only numeric), in which
3039 * case the currently active quality will be increased to match.
3040 * <p>
3041 * Calling with a null or empty password will clear any existing PIN, pattern or password if the
Robin Leece5c4002016-03-23 17:05:03 +00003042 * current password constraints allow it. <em>Note: This will not work in
3043 * {@link android.os.Build.VERSION_CODES#N} and later for managed profiles, or for device admins
3044 * that are not device owner or profile owner. Once set, the password cannot be changed to null
3045 * or empty except by these admins.</em>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003046 * <p>
3047 * The calling device admin must have requested
3048 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call this method; if it has
3049 * not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003050 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01003051 * @param password The new password for the user. Null or empty clears the password.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04003052 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003053 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
3054 * @return Returns true if the password was applied, or false if it is not acceptable for the
3055 * current constraints or if the user has not been decrypted yet.
3056 * @throws SecurityException if the calling application does not own an active administrator
3057 * that uses {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD}
Ricky Wai977ade22016-05-24 15:02:41 +01003058 * @throws IllegalStateException if the calling user is locked or has a managed profile.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08003059 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08003060 public boolean resetPassword(String password, int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003061 throwIfParentInstance("resetPassword");
Dianne Hackborndf83afa2010-01-20 13:37:26 -08003062 if (mService != null) {
3063 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003064 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08003065 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003066 throw e.rethrowFromSystemServer();
Dianne Hackborndf83afa2010-01-20 13:37:26 -08003067 }
3068 }
3069 return false;
3070 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003071
Dianne Hackbornd6847842010-01-12 18:14:19 -08003072 /**
Rubin Xuaab7a412016-12-30 21:13:29 +00003073 * 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 +01003074 * device lockscreen password (if called by device owner), or managed profile challenge (if
3075 * called by profile owner), via {@link #resetPasswordWithToken}.
Rubin Xuaab7a412016-12-30 21:13:29 +00003076 * <p>
3077 * If the user currently has a lockscreen password, the provisioned token will not be
3078 * immediately usable; it only becomes active after the user performs a confirm credential
3079 * operation, which can be triggered by {@link KeyguardManager#createConfirmDeviceCredentialIntent}.
3080 * If the user has no lockscreen password, the token is activated immediately. In all cases,
3081 * the active state of the current token can be checked by {@link #isResetPasswordTokenActive}.
3082 * For security reasons, un-activated tokens are only stored in memory and will be lost once
3083 * the device reboots. In this case a new token needs to be provisioned again.
3084 * <p>
3085 * Once provisioned and activated, the token will remain effective even if the user changes
3086 * or clears the lockscreen password.
3087 * <p>
3088 * <em>This token is highly sensitive and should be treated at the same level as user
Rubin Xuf7b036d2017-04-05 18:37:07 +01003089 * credentials. In particular, NEVER store this token on device in plaintext. Do not store
3090 * the plaintext token in device-encrypted storage if it will be needed to reset password on
3091 * file-based encryption devices before user unlocks. Consider carefully how any password token
3092 * will be stored on your server and who will need access to them. Tokens may be the subject of
3093 * legal access requests.
Rubin Xuaab7a412016-12-30 21:13:29 +00003094 * </em>
3095 *
3096 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3097 * @param token a secure token a least 32-byte long, which must be generated by a
3098 * cryptographically strong random number generator.
3099 * @return true if the operation is successful, false otherwise.
Benjamin Miller1aed7882017-08-15 18:04:20 +02003100 * @throws SecurityException if admin is not a device or profile owner.
Rubin Xuaab7a412016-12-30 21:13:29 +00003101 * @throws IllegalArgumentException if the supplied token is invalid.
Rubin Xuaab7a412016-12-30 21:13:29 +00003102 */
3103 public boolean setResetPasswordToken(ComponentName admin, byte[] token) {
3104 throwIfParentInstance("setResetPasswordToken");
3105 if (mService != null) {
3106 try {
3107 return mService.setResetPasswordToken(admin, token);
3108 } catch (RemoteException e) {
3109 throw e.rethrowFromSystemServer();
3110 }
3111 }
3112 return false;
3113 }
3114
3115 /**
3116 * Called by a profile or device owner to revoke the current password reset token.
3117 *
3118 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3119 * @return true if the operation is successful, false otherwise.
Benjamin Miller1aed7882017-08-15 18:04:20 +02003120 * @throws SecurityException if admin is not a device or profile owner.
Rubin Xuaab7a412016-12-30 21:13:29 +00003121 */
3122 public boolean clearResetPasswordToken(ComponentName admin) {
3123 throwIfParentInstance("clearResetPasswordToken");
3124 if (mService != null) {
3125 try {
3126 return mService.clearResetPasswordToken(admin);
3127 } catch (RemoteException e) {
3128 throw e.rethrowFromSystemServer();
3129 }
3130 }
3131 return false;
3132 }
3133
3134 /**
3135 * Called by a profile or device owner to check if the current reset password token is active.
3136 *
3137 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3138 * @return true if the token is active, false otherwise.
Benjamin Miller1aed7882017-08-15 18:04:20 +02003139 * @throws SecurityException if admin is not a device or profile owner.
Rubin Xuaab7a412016-12-30 21:13:29 +00003140 * @throws IllegalStateException if no token has been set.
3141 */
3142 public boolean isResetPasswordTokenActive(ComponentName admin) {
3143 throwIfParentInstance("isResetPasswordTokenActive");
3144 if (mService != null) {
3145 try {
3146 return mService.isResetPasswordTokenActive(admin);
3147 } catch (RemoteException e) {
3148 throw e.rethrowFromSystemServer();
3149 }
3150 }
3151 return false;
3152 }
3153
3154 /**
Esteban Talavera7e4cbad2017-03-30 17:59:50 +01003155 * Called by device or profile owner to force set a new device unlock password or a managed
3156 * profile challenge on current user. This takes effect immediately.
Rubin Xuaab7a412016-12-30 21:13:29 +00003157 * <p>
3158 * Unlike {@link #resetPassword}, this API can change the password even before the user or
3159 * device is unlocked or decrypted. The supplied token must have been previously provisioned via
3160 * {@link #setResetPasswordToken}, and in active state {@link #isResetPasswordTokenActive}.
3161 * <p>
3162 * The given password must be sufficient for the current password quality and length constraints
3163 * as returned by {@link #getPasswordQuality(ComponentName)} and
3164 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then
Benjamin Miller1aed7882017-08-15 18:04:20 +02003165 * it will be rejected and false returned. Note that the password may be a stronger quality, for
3166 * example, a password containing alphanumeric characters when the requested quality is only
3167 * numeric.
Rubin Xuaab7a412016-12-30 21:13:29 +00003168 * <p>
Benjamin Miller1aed7882017-08-15 18:04:20 +02003169 * Calling with a {@code null} or empty password will clear any existing PIN, pattern or
3170 * password if the current password constraints allow it.
Rubin Xuaab7a412016-12-30 21:13:29 +00003171 *
3172 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Miller1aed7882017-08-15 18:04:20 +02003173 * @param password The new password for the user. {@code null} or empty clears the password.
3174 * @param token the password reset token previously provisioned by
3175 * {@link #setResetPasswordToken}.
Rubin Xuaab7a412016-12-30 21:13:29 +00003176 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Benjamin Miller1aed7882017-08-15 18:04:20 +02003177 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
Rubin Xuaab7a412016-12-30 21:13:29 +00003178 * @return Returns true if the password was applied, or false if it is not acceptable for the
3179 * current constraints.
Benjamin Miller1aed7882017-08-15 18:04:20 +02003180 * @throws SecurityException if admin is not a device or profile owner.
Rubin Xuaab7a412016-12-30 21:13:29 +00003181 * @throws IllegalStateException if the provided token is not valid.
Rubin Xuaab7a412016-12-30 21:13:29 +00003182 */
3183 public boolean resetPasswordWithToken(@NonNull ComponentName admin, String password,
3184 byte[] token, int flags) {
3185 throwIfParentInstance("resetPassword");
3186 if (mService != null) {
3187 try {
3188 return mService.resetPasswordWithToken(admin, password, token, flags);
3189 } catch (RemoteException e) {
3190 throw e.rethrowFromSystemServer();
3191 }
3192 }
3193 return false;
3194 }
3195
3196 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003197 * Called by an application that is administering the device to set the maximum time for user
3198 * activity until the device will lock. This limits the length that the user can set. It takes
3199 * effect immediately.
3200 * <p>
3201 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
3202 * to be able to call this method; if it has not, a security exception will be thrown.
3203 * <p>
3204 * This method can be called on the {@link DevicePolicyManager} instance returned by
3205 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
3206 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00003207 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08003208 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003209 * @param timeMs The new desired maximum time to lock in milliseconds. A value of 0 means there
3210 * is no restriction.
3211 * @throws SecurityException if {@code admin} is not an active administrator or it does not use
3212 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
Dianne Hackbornd6847842010-01-12 18:14:19 -08003213 */
Robin Lee25e26452015-06-02 09:56:29 -07003214 public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003215 if (mService != null) {
3216 try {
Esteban Talavera62399912016-01-11 15:37:55 +00003217 mService.setMaximumTimeToLock(admin, timeMs, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003218 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003219 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003220 }
3221 }
3222 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003223
Dianne Hackbornd6847842010-01-12 18:14:19 -08003224 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00003225 * Retrieve the current maximum time to unlock for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01003226 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00003227 * a separate challenge are not taken into account.
3228 *
3229 * <p>This method can be called on the {@link DevicePolicyManager} instance
3230 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
3231 * restrictions on the parent profile.
3232 *
Robin Lee25e26452015-06-02 09:56:29 -07003233 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08003234 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07003235 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07003236 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08003237 */
Robin Lee25e26452015-06-02 09:56:29 -07003238 public long getMaximumTimeToLock(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003239 return getMaximumTimeToLock(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003240 }
3241
3242 /** @hide per-user version */
Mathew Inwood4fb17d12018-08-14 14:25:44 +01003243 @UnsupportedAppUsage
Robin Lee25e26452015-06-02 09:56:29 -07003244 public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003245 if (mService != null) {
3246 try {
Esteban Talavera62399912016-01-11 15:37:55 +00003247 return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003248 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003249 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003250 }
3251 }
3252 return 0;
3253 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003254
Dianne Hackbornd6847842010-01-12 18:14:19 -08003255 /**
Michal Karpinski8f010dd2016-06-21 15:05:53 +01003256 * Called by a device/profile owner to set the timeout after which unlocking with secondary, non
3257 * strong auth (e.g. fingerprint, trust agents) times out, i.e. the user has to use a strong
3258 * authentication method like password, pin or pattern.
3259 *
3260 * <p>This timeout is used internally to reset the timer to require strong auth again after
3261 * specified timeout each time it has been successfully used.
3262 *
3263 * <p>Fingerprint can also be disabled altogether using {@link #KEYGUARD_DISABLE_FINGERPRINT}.
3264 *
3265 * <p>Trust agents can also be disabled altogether using {@link #KEYGUARD_DISABLE_TRUST_AGENTS}.
3266 *
3267 * <p>The calling device admin must be a device or profile owner. If it is not,
3268 * a {@link SecurityException} will be thrown.
3269 *
Michal Karpinski943aabd2016-10-06 11:09:25 +01003270 * <p>The calling device admin can verify the value it has set by calling
3271 * {@link #getRequiredStrongAuthTimeout(ComponentName)} and passing in its instance.
3272 *
Michal Karpinski8f010dd2016-06-21 15:05:53 +01003273 * <p>This method can be called on the {@link DevicePolicyManager} instance returned by
3274 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
3275 * profile.
3276 *
3277 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xu5d39ea72017-04-24 20:26:30 +01003278 * @param timeoutMs The new timeout in milliseconds, after which the user will have to unlock
3279 * with strong authentication method. A value of 0 means the admin is not participating
3280 * in controlling the timeout.
Michal Karpinski943aabd2016-10-06 11:09:25 +01003281 * The minimum and maximum timeouts are platform-defined and are typically 1 hour and
3282 * 72 hours, respectively. Though discouraged, the admin may choose to require strong
3283 * auth at all times using {@link #KEYGUARD_DISABLE_FINGERPRINT} and/or
3284 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01003285 *
3286 * @throws SecurityException if {@code admin} is not a device or profile owner.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01003287 */
3288 public void setRequiredStrongAuthTimeout(@NonNull ComponentName admin,
3289 long timeoutMs) {
3290 if (mService != null) {
3291 try {
3292 mService.setRequiredStrongAuthTimeout(admin, timeoutMs, mParentInstance);
3293 } catch (RemoteException e) {
3294 throw e.rethrowFromSystemServer();
3295 }
3296 }
3297 }
3298
3299 /**
3300 * Determine for how long the user will be able to use secondary, non strong auth for
3301 * authentication, since last strong method authentication (password, pin or pattern) was used.
3302 * After the returned timeout the user is required to use strong authentication method.
3303 *
3304 * <p>This method can be called on the {@link DevicePolicyManager} instance
3305 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
3306 * restrictions on the parent profile.
3307 *
3308 * @param admin The name of the admin component to check, or {@code null} to aggregate
koprivaa1a78482018-10-09 10:09:23 -07003309 * across all participating admins.
Rubin Xu5d39ea72017-04-24 20:26:30 +01003310 * @return The timeout in milliseconds or 0 if not configured for the provided admin.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01003311 */
3312 public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin) {
3313 return getRequiredStrongAuthTimeout(admin, myUserId());
3314 }
3315
3316 /** @hide per-user version */
Mathew Inwood4fb17d12018-08-14 14:25:44 +01003317 @UnsupportedAppUsage
Michal Karpinski8f010dd2016-06-21 15:05:53 +01003318 public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin, @UserIdInt int userId) {
3319 if (mService != null) {
3320 try {
3321 return mService.getRequiredStrongAuthTimeout(admin, userId, mParentInstance);
3322 } catch (RemoteException e) {
3323 throw e.rethrowFromSystemServer();
3324 }
3325 }
3326 return DEFAULT_STRONG_AUTH_TIMEOUT_MS;
3327 }
3328
3329 /**
Andrew Scull85a63bc2016-10-24 13:47:47 +01003330 * Flag for {@link #lockNow(int)}: also evict the user's credential encryption key from the
3331 * keyring. The user's credential will need to be entered again in order to derive the
3332 * credential encryption key that will be stored back in the keyring for future use.
3333 * <p>
Andrew Scull17e1b5d2017-04-25 14:44:24 +01003334 * This flag can only be used by a profile owner when locking a managed profile when
3335 * {@link #getStorageEncryptionStatus} returns {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}.
Andrew Scull85a63bc2016-10-24 13:47:47 +01003336 * <p>
3337 * In order to secure user data, the user will be stopped and restarted so apps should wait
3338 * until they are next run to perform further actions.
3339 */
Andrew Scull17e1b5d2017-04-25 14:44:24 +01003340 public static final int FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY = 1;
3341
Andrew Scull85a63bc2016-10-24 13:47:47 +01003342 /** @hide */
3343 @Retention(RetentionPolicy.SOURCE)
Jeff Sharkeyce8db992017-12-13 20:05:05 -07003344 @IntDef(flag = true, prefix = { "FLAG_EVICT_" }, value = {
3345 FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY
3346 })
Andrew Scull85a63bc2016-10-24 13:47:47 +01003347 public @interface LockNowFlag {}
3348
3349 /**
3350 * Make the device lock immediately, as if the lock screen timeout has expired at the point of
3351 * this call.
3352 * <p>
3353 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
3354 * to be able to call this method; if it has not, a security exception will be thrown.
3355 * <p>
3356 * This method can be called on the {@link DevicePolicyManager} instance returned by
3357 * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile.
3358 * <p>
3359 * Equivalent to calling {@link #lockNow(int)} with no flags.
3360 *
3361 * @throws SecurityException if the calling application does not own an active administrator
3362 * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
3363 */
3364 public void lockNow() {
3365 lockNow(0);
3366 }
3367
3368 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003369 * Make the device lock immediately, as if the lock screen timeout has expired at the point of
3370 * this call.
3371 * <p>
3372 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
3373 * to be able to call this method; if it has not, a security exception will be thrown.
3374 * <p>
3375 * This method can be called on the {@link DevicePolicyManager} instance returned by
3376 * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003377 *
Andrew Scull17e1b5d2017-04-25 14:44:24 +01003378 * @param flags May be 0 or {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003379 * @throws SecurityException if the calling application does not own an active administrator
Andrew Scull85a63bc2016-10-24 13:47:47 +01003380 * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} or the
Andrew Scull17e1b5d2017-04-25 14:44:24 +01003381 * {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY} flag is passed by an application
3382 * that is not a profile
Andrew Scull85a63bc2016-10-24 13:47:47 +01003383 * owner of a managed profile.
Andrew Scull17e1b5d2017-04-25 14:44:24 +01003384 * @throws IllegalArgumentException if the {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY} flag is
3385 * passed when locking the parent profile.
3386 * @throws UnsupportedOperationException if the {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY}
3387 * flag is passed when {@link #getStorageEncryptionStatus} does not return
3388 * {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08003389 */
Andrew Scull85a63bc2016-10-24 13:47:47 +01003390 public void lockNow(@LockNowFlag int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -08003391 if (mService != null) {
3392 try {
Andrew Scull85a63bc2016-10-24 13:47:47 +01003393 mService.lockNow(flags, mParentInstance);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08003394 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003395 throw e.rethrowFromSystemServer();
Dianne Hackborndf83afa2010-01-20 13:37:26 -08003396 }
3397 }
3398 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003399
Dianne Hackbornd6847842010-01-12 18:14:19 -08003400 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07003401 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00003402 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07003403 */
3404 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
3405
3406 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00003407 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
3408 * data.
3409 *
Paul Crowley2934b262014-12-02 11:21:13 +00003410 * <p>This flag may only be set by device owner admins; if it is set by
3411 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00003412 */
3413 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
3414
3415 /**
yinxuf4f9cec2017-06-19 10:28:19 -07003416 * Flag for {@link #wipeData(int)}: also erase the device's eUICC data.
yinxuf4f9cec2017-06-19 10:28:19 -07003417 */
3418 public static final int WIPE_EUICC = 0x0004;
3419
yuemingwf7f67dc2017-09-08 14:23:53 +01003420
yinxuf4f9cec2017-06-19 10:28:19 -07003421 /**
Suprabh Shukla556b05a2016-08-10 15:49:24 -07003422 * Ask that all user data be wiped. If called as a secondary user, the user will be removed and
3423 * other users will remain unaffected. Calling from the primary user will cause the device to
3424 * reboot, erasing all device data - including all the secondary users and their data - while
3425 * booting up.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003426 * <p>
3427 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to
3428 * be able to call this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003429 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003430 * @param flags Bit mask of additional options: currently supported flags are
3431 * {@link #WIPE_EXTERNAL_STORAGE} and {@link #WIPE_RESET_PROTECTION_DATA}.
3432 * @throws SecurityException if the calling application does not own an active administrator
3433 * that uses {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}
Dianne Hackbornd6847842010-01-12 18:14:19 -08003434 */
3435 public void wipeData(int flags) {
yuemingw22800192017-11-07 15:19:45 +00003436 throwIfParentInstance("wipeData");
yuemingwf7f67dc2017-09-08 14:23:53 +01003437 final String wipeReasonForUser = mContext.getString(
3438 R.string.work_profile_deleted_description_dpm_wipe);
3439 wipeDataInternal(flags, wipeReasonForUser);
3440 }
3441
3442 /**
3443 * Ask that all user data be wiped. If called as a secondary user, the user will be removed and
3444 * other users will remain unaffected, the provided reason for wiping data can be shown to
3445 * user. Calling from the primary user will cause the device to reboot, erasing all device data
3446 * - including all the secondary users and their data - while booting up. In this case, we don't
3447 * show the reason to the user since the device would be factory reset.
3448 * <p>
3449 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to
3450 * be able to call this method; if it has not, a security exception will be thrown.
3451 *
3452 * @param flags Bit mask of additional options: currently supported flags are
3453 * {@link #WIPE_EXTERNAL_STORAGE} and {@link #WIPE_RESET_PROTECTION_DATA}.
3454 * @param reason a string that contains the reason for wiping data, which can be
3455 * presented to the user.
3456 * @throws SecurityException if the calling application does not own an active administrator
3457 * that uses {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}
3458 * @throws IllegalArgumentException if the input reason string is null or empty.
3459 */
yuemingw8227e5b2018-02-22 17:29:10 +00003460 public void wipeData(int flags, @NonNull CharSequence reason) {
3461 throwIfParentInstance("wipeData");
yuemingwf7f67dc2017-09-08 14:23:53 +01003462 Preconditions.checkNotNull(reason, "CharSequence is null");
3463 wipeDataInternal(flags, reason.toString());
3464 }
3465
3466 /**
3467 * Internal function for both {@link #wipeData(int)} and
yuemingw8227e5b2018-02-22 17:29:10 +00003468 * {@link #wipeData(int, CharSequence)} to call.
yuemingwf7f67dc2017-09-08 14:23:53 +01003469 *
3470 * @see #wipeData(int)
yuemingw8227e5b2018-02-22 17:29:10 +00003471 * @see #wipeData(int, CharSequence)
yuemingwf7f67dc2017-09-08 14:23:53 +01003472 * @hide
3473 */
3474 private void wipeDataInternal(int flags, @NonNull String wipeReasonForUser) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003475 if (mService != null) {
3476 try {
yuemingwf7f67dc2017-09-08 14:23:53 +01003477 mService.wipeDataWithReason(flags, wipeReasonForUser);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003478 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003479 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003480 }
3481 }
3482 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003483
Dianne Hackbornd6847842010-01-12 18:14:19 -08003484 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07003485 * Called by an application that is administering the device to set the
3486 * global proxy and exclusion list.
3487 * <p>
3488 * The calling device admin must have requested
3489 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
3490 * this method; if it has not, a security exception will be thrown.
3491 * Only the first device admin can set the proxy. If a second admin attempts
3492 * to set the proxy, the {@link ComponentName} of the admin originally setting the
Robin Lee25e26452015-06-02 09:56:29 -07003493 * proxy will be returned. If successful in setting the proxy, {@code null} will
Oscar Montemayor69238c62010-08-03 10:51:06 -07003494 * be returned.
3495 * The method can be called repeatedly by the device admin alrady setting the
3496 * proxy to update the proxy and exclusion list.
3497 *
Robin Lee25e26452015-06-02 09:56:29 -07003498 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Oscar Montemayor69238c62010-08-03 10:51:06 -07003499 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
3500 * Pass Proxy.NO_PROXY to reset the proxy.
3501 * @param exclusionList a list of domains to be excluded from the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07003502 * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName}
3503 * of the device admin that sets the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08003504 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07003505 */
Mathew Inwood4fb17d12018-08-14 14:25:44 +01003506 @UnsupportedAppUsage
Makoto Onuki408e8e42016-10-25 12:10:27 -07003507 public @Nullable ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec,
Oscar Montemayor69238c62010-08-03 10:51:06 -07003508 List<String> exclusionList ) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003509 throwIfParentInstance("setGlobalProxy");
Oscar Montemayor69238c62010-08-03 10:51:06 -07003510 if (proxySpec == null) {
3511 throw new NullPointerException();
3512 }
3513 if (mService != null) {
3514 try {
3515 String hostSpec;
3516 String exclSpec;
3517 if (proxySpec.equals(Proxy.NO_PROXY)) {
3518 hostSpec = null;
3519 exclSpec = null;
3520 } else {
3521 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
3522 throw new IllegalArgumentException();
3523 }
3524 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
3525 String hostName = sa.getHostName();
3526 int port = sa.getPort();
3527 StringBuilder hostBuilder = new StringBuilder();
3528 hostSpec = hostBuilder.append(hostName)
3529 .append(":").append(Integer.toString(port)).toString();
3530 if (exclusionList == null) {
3531 exclSpec = "";
3532 } else {
3533 StringBuilder listBuilder = new StringBuilder();
3534 boolean firstDomain = true;
3535 for (String exclDomain : exclusionList) {
3536 if (!firstDomain) {
3537 listBuilder = listBuilder.append(",");
3538 } else {
3539 firstDomain = false;
3540 }
3541 listBuilder = listBuilder.append(exclDomain.trim());
3542 }
3543 exclSpec = listBuilder.toString();
3544 }
Yuhao Zheng90704842014-02-28 17:22:45 -08003545 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
3546 != android.net.Proxy.PROXY_VALID)
3547 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07003548 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003549 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07003550 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003551 throw e.rethrowFromSystemServer();
Oscar Montemayor69238c62010-08-03 10:51:06 -07003552 }
3553 }
3554 return null;
3555 }
3556
3557 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003558 * Set a network-independent global HTTP proxy. This is not normally what you want for typical
3559 * HTTP proxies - they are generally network dependent. However if you're doing something
3560 * unusual like general internal filtering this may be useful. On a private network where the
3561 * proxy is not accessible, you may break HTTP using this.
3562 * <p>
3563 * This method requires the caller to be the device owner.
3564 * <p>
3565 * This proxy is only a recommendation and it is possible that some apps will ignore it.
Jason Monk03bc9912014-05-13 09:44:57 -04003566 *
Jason Monk03bc9912014-05-13 09:44:57 -04003567 * @see ProxyInfo
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003568 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3569 * @param proxyInfo The a {@link ProxyInfo} object defining the new global HTTP proxy. A
3570 * {@code null} value will clear the global HTTP proxy.
3571 * @throws SecurityException if {@code admin} is not the device owner.
Jason Monk03bc9912014-05-13 09:44:57 -04003572 */
Robin Lee25e26452015-06-02 09:56:29 -07003573 public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo
3574 proxyInfo) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003575 throwIfParentInstance("setRecommendedGlobalProxy");
Jason Monk03bc9912014-05-13 09:44:57 -04003576 if (mService != null) {
3577 try {
3578 mService.setRecommendedGlobalProxy(admin, proxyInfo);
3579 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003580 throw e.rethrowFromSystemServer();
Jason Monk03bc9912014-05-13 09:44:57 -04003581 }
3582 }
3583 }
3584
3585 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07003586 * Returns the component name setting the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07003587 * @return ComponentName object of the device admin that set the global proxy, or {@code null}
3588 * if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08003589 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07003590 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003591 public @Nullable ComponentName getGlobalProxyAdmin() {
Oscar Montemayor69238c62010-08-03 10:51:06 -07003592 if (mService != null) {
3593 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003594 return mService.getGlobalProxyAdmin(myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07003595 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003596 throw e.rethrowFromSystemServer();
Oscar Montemayor69238c62010-08-03 10:51:06 -07003597 }
3598 }
3599 return null;
3600 }
3601
3602 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08003603 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003604 * indicating that encryption is not supported.
3605 */
3606 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
3607
3608 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08003609 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003610 * indicating that encryption is supported, but is not currently active.
3611 */
3612 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
3613
3614 /**
Robin Lee3795fb02015-02-16 14:17:23 +00003615 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003616 * indicating that encryption is not currently active, but is currently
3617 * being activated. This is only reported by devices that support
3618 * encryption of data and only when the storage is currently
3619 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
3620 * to become encrypted will never return this value.
3621 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08003622 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003623
3624 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08003625 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003626 * indicating that encryption is active.
Amith Yamasani75db1252016-07-11 14:41:01 -07003627 * <p>
3628 * Also see {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003629 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08003630 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003631
3632 /**
Robin Lee3795fb02015-02-16 14:17:23 +00003633 * Result code for {@link #getStorageEncryptionStatus}:
3634 * indicating that encryption is active, but an encryption key has not
3635 * been set by the user.
3636 */
3637 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
3638
3639 /**
Makoto Onukid4c9e542016-02-25 18:17:30 -08003640 * Result code for {@link #getStorageEncryptionStatus}:
Amith Yamasani75db1252016-07-11 14:41:01 -07003641 * indicating that encryption is active and the encryption key is tied to the user or profile.
3642 * <p>
3643 * This value is only returned to apps targeting API level 24 and above. For apps targeting
3644 * earlier API levels, {@link #ENCRYPTION_STATUS_ACTIVE} is returned, even if the
3645 * encryption key is specific to the user or profile.
Makoto Onukid4c9e542016-02-25 18:17:30 -08003646 */
3647 public static final int ENCRYPTION_STATUS_ACTIVE_PER_USER = 5;
3648
3649 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003650 * Activity action: begin the process of encrypting data on the device. This activity should
3651 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
3652 * After resuming from this activity, use {@link #getStorageEncryption}
3653 * to check encryption status. However, on some devices this activity may never return, as
3654 * it may trigger a reboot and in some cases a complete data wipe of the device.
3655 */
3656 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
3657 public static final String ACTION_START_ENCRYPTION
3658 = "android.app.action.START_ENCRYPTION";
Alex Chaub6a9f942017-11-07 11:28:56 +08003659
3660 /**
3661 * Broadcast action: notify managed provisioning that new managed user is created.
3662 *
3663 * @hide
3664 */
3665 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
3666 public static final String ACTION_MANAGED_USER_CREATED =
3667 "android.app.action.MANAGED_USER_CREATED";
3668
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003669 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07003670 * Widgets are enabled in keyguard
3671 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07003672 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07003673
3674 /**
Rubin Xu4b2f7aa2018-03-02 15:41:53 +00003675 * Disable all keyguard widgets. Has no effect starting from
3676 * {@link android.os.Build.VERSION_CODES#LOLLIPOP} since keyguard widget is only supported
3677 * on Android versions lower than 5.0.
Jim Millerb8ec4702012-08-31 17:19:10 -07003678 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07003679 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
3680
3681 /**
3682 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
3683 */
3684 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
3685
3686 /**
Jim Miller50e62182014-04-23 17:25:00 -07003687 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
3688 */
3689 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
3690
3691 /**
3692 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
3693 */
3694 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
3695
3696 /**
Rubin Xu50ac2412018-03-02 15:25:28 +00003697 * Disable trust agents on secure keyguard screens (e.g. PIN/Pattern/Password).
3698 * By setting this flag alone, all trust agents are disabled. If the admin then wants to
3699 * whitelist specific features of some trust agent, {@link #setTrustAgentConfiguration} can be
3700 * used in conjuction to set trust-agent-specific configurations.
Jim Miller50e62182014-04-23 17:25:00 -07003701 */
3702 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
3703
3704 /**
Vishwath Mohancf87df12018-03-20 22:57:17 -07003705 * Disable fingerprint authentication on keyguard secure screens (e.g. PIN/Pattern/Password).
Jim Miller06e34502014-07-17 14:46:05 -07003706 */
3707 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
3708
3709 /**
Adrian Roos7f06eed2016-02-05 15:21:02 -08003710 * Disable text entry into notifications on secure keyguard screens (e.g. PIN/Pattern/Password).
3711 */
3712 public static final int KEYGUARD_DISABLE_REMOTE_INPUT = 1 << 6;
3713
3714 /**
Vishwath Mohancf87df12018-03-20 22:57:17 -07003715 * Disable face authentication on keyguard secure screens (e.g. PIN/Pattern/Password).
3716 */
3717 public static final int KEYGUARD_DISABLE_FACE = 1 << 7;
3718
3719 /**
3720 * Disable iris authentication on keyguard secure screens (e.g. PIN/Pattern/Password).
3721 */
3722 public static final int KEYGUARD_DISABLE_IRIS = 1 << 8;
3723
3724 /**
3725 * Disable all biometric authentication on keyguard secure screens (e.g. PIN/Pattern/Password).
3726 */
3727 public static final int KEYGUARD_DISABLE_BIOMETRICS =
3728 DevicePolicyManager.KEYGUARD_DISABLE_FACE
3729 | DevicePolicyManager.KEYGUARD_DISABLE_IRIS
3730 | DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT;
3731
3732
3733 /**
Jim Miller35207742012-11-02 15:33:20 -07003734 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07003735 */
3736 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07003737
3738 /**
Robin Leeacdeac62017-02-21 22:13:38 +00003739 * Keyguard features that when set on a managed profile that doesn't have its own challenge will
3740 * affect the profile's parent user. These can also be set on the managed profile's parent
3741 * {@link DevicePolicyManager} instance.
3742 *
3743 * @hide
3744 */
3745 public static final int PROFILE_KEYGUARD_FEATURES_AFFECT_OWNER =
3746 DevicePolicyManager.KEYGUARD_DISABLE_TRUST_AGENTS
Rubin Xuc418d5a2018-05-02 12:18:18 +01003747 | DevicePolicyManager.KEYGUARD_DISABLE_BIOMETRICS;
Robin Leeacdeac62017-02-21 22:13:38 +00003748
3749 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003750 * Called by an application that is administering the device to request that the storage system
Alex Kershaw61ec8252018-03-16 14:31:04 +00003751 * be encrypted. Does nothing if the caller is on a secondary user or a managed profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003752 * <p>
3753 * When multiple device administrators attempt to control device encryption, the most secure,
3754 * supported setting will always be used. If any device administrator requests device
3755 * encryption, it will be enabled; Conversely, if a device administrator attempts to disable
3756 * device encryption while another device administrator has enabled it, the call to disable will
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003757 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003758 * <p>
3759 * This policy controls encryption of the secure (application data) storage area. Data written
3760 * to other storage areas may or may not be encrypted, and this policy does not require or
3761 * control the encryption of any other storage areas. There is one exception: If
3762 * {@link android.os.Environment#isExternalStorageEmulated()} is {@code true}, then the
3763 * directory returned by {@link android.os.Environment#getExternalStorageDirectory()} must be
3764 * written to disk within the encrypted storage area.
3765 * <p>
3766 * Important Note: On some devices, it is possible to encrypt storage without requiring the user
3767 * to create a device PIN or Password. In this case, the storage is encrypted, but the
3768 * encryption key may not be fully secured. For maximum security, the administrator should also
3769 * require (and check for) a pattern, PIN, or password.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003770 *
3771 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3772 * @param encrypt true to request encryption, false to release any previous request
Alex Kershaw61ec8252018-03-16 14:31:04 +00003773 * @return the new total request status (for all active admins), or {@link
3774 * DevicePolicyManager#ENCRYPTION_STATUS_UNSUPPORTED} if called for a non-system user.
3775 * Will be one of {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link
3776 * #ENCRYPTION_STATUS_INACTIVE}, or {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value
3777 * of the requests; use {@link #getStorageEncryptionStatus()} to query the actual device
3778 * state.
3779 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003780 * @throws SecurityException if {@code admin} is not an active administrator or does not use
3781 * {@link DeviceAdminInfo#USES_ENCRYPTED_STORAGE}
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003782 */
Robin Lee25e26452015-06-02 09:56:29 -07003783 public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003784 throwIfParentInstance("setStorageEncryption");
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003785 if (mService != null) {
3786 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003787 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003788 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003789 throw e.rethrowFromSystemServer();
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003790 }
3791 }
3792 return ENCRYPTION_STATUS_UNSUPPORTED;
3793 }
3794
3795 /**
3796 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08003797 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003798 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08003799 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
3800 * this will return the requested encryption setting as an aggregate of all active
3801 * administrators.
3802 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003803 */
Robin Lee25e26452015-06-02 09:56:29 -07003804 public boolean getStorageEncryption(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003805 throwIfParentInstance("getStorageEncryption");
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003806 if (mService != null) {
3807 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003808 return mService.getStorageEncryption(admin, myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003809 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003810 throw e.rethrowFromSystemServer();
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003811 }
3812 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08003813 return false;
3814 }
3815
3816 /**
3817 * Called by an application that is administering the device to
3818 * determine the current encryption status of the device.
Amith Yamasani75db1252016-07-11 14:41:01 -07003819 * <p>
Andy Stadler22dbfda2011-01-17 12:47:31 -08003820 * Depending on the returned status code, the caller may proceed in different
3821 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
3822 * storage system does not support encryption. If the
3823 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
3824 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00003825 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
3826 * storage system has enabled encryption but no password is set so further action
Amith Yamasani75db1252016-07-11 14:41:01 -07003827 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING},
3828 * {@link #ENCRYPTION_STATUS_ACTIVE} or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER},
3829 * no further action is required.
Andy Stadler22dbfda2011-01-17 12:47:31 -08003830 *
Robin Lee7e678712014-07-24 16:41:31 +01003831 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08003832 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00003833 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
Amith Yamasani75db1252016-07-11 14:41:01 -07003834 * {@link #ENCRYPTION_STATUS_ACTIVE}, or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08003835 */
3836 public int getStorageEncryptionStatus() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003837 throwIfParentInstance("getStorageEncryptionStatus");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003838 return getStorageEncryptionStatus(myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003839 }
3840
3841 /** @hide per-user version */
Mathew Inwood4fb17d12018-08-14 14:25:44 +01003842 @UnsupportedAppUsage
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003843 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08003844 if (mService != null) {
3845 try {
Makoto Onukid4c9e542016-02-25 18:17:30 -08003846 return mService.getStorageEncryptionStatus(mContext.getPackageName(), userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08003847 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003848 throw e.rethrowFromSystemServer();
Andy Stadler22dbfda2011-01-17 12:47:31 -08003849 }
3850 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003851 return ENCRYPTION_STATUS_UNSUPPORTED;
3852 }
3853
3854 /**
Robin Lee2f7e1e42016-03-21 10:50:01 +00003855 * Mark a CA certificate as approved by the device user. This means that they have been notified
3856 * of the installation, were made aware of the risks, viewed the certificate and still wanted to
3857 * keep the certificate on the device.
3858 *
3859 * Calling with {@param approval} as {@code true} will cancel any ongoing warnings related to
3860 * this certificate.
3861 *
3862 * @hide
3863 */
3864 public boolean approveCaCert(String alias, int userHandle, boolean approval) {
3865 if (mService != null) {
3866 try {
3867 return mService.approveCaCert(alias, userHandle, approval);
3868 } catch (RemoteException e) {
3869 throw e.rethrowFromSystemServer();
3870 }
3871 }
3872 return false;
3873 }
3874
3875 /**
3876 * Check whether a CA certificate has been approved by the device user.
3877 *
3878 * @hide
3879 */
3880 public boolean isCaCertApproved(String alias, int userHandle) {
3881 if (mService != null) {
3882 try {
3883 return mService.isCaCertApproved(alias, userHandle);
3884 } catch (RemoteException e) {
3885 throw e.rethrowFromSystemServer();
3886 }
3887 }
3888 return false;
3889 }
3890
3891 /**
Robin Lee7e678712014-07-24 16:41:31 +01003892 * Installs the given certificate as a user CA.
Benjamin Miller8a12c122017-04-04 12:38:24 +02003893 * <p>
3894 * Inserted user CAs aren't automatically trusted by apps in Android 7.0 (API level 24) and
3895 * higher. App developers can change the default behavior for an app by adding a
3896 * <a href="{@docRoot}training/articles/security-config.html">Security Configuration
3897 * File</a> to the app manifest file.
Robin Lee7e678712014-07-24 16:41:31 +01003898 *
Edman Anjosf9946772016-11-28 16:35:15 +01003899 * The caller must be a profile or device owner on that user, or a delegate package given the
3900 * {@link #DELEGATION_CERT_INSTALL} scope via {@link #setDelegatedScopes}; otherwise a
3901 * security exception will be thrown.
3902 *
Robin Lee25e26452015-06-02 09:56:29 -07003903 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3904 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003905 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04003906 *
3907 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01003908 * interrupted, true otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003909 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3910 * owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003911 * @see #setDelegatedScopes
3912 * @see #DELEGATION_CERT_INSTALL
Maggie Benthallda51e682013-08-08 22:35:44 -04003913 */
Robin Lee25e26452015-06-02 09:56:29 -07003914 public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003915 throwIfParentInstance("installCaCert");
Maggie Benthallda51e682013-08-08 22:35:44 -04003916 if (mService != null) {
3917 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003918 return mService.installCaCert(admin, mContext.getPackageName(), certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04003919 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003920 throw e.rethrowFromSystemServer();
Maggie Benthallda51e682013-08-08 22:35:44 -04003921 }
3922 }
3923 return false;
3924 }
3925
3926 /**
Robin Lee7e678712014-07-24 16:41:31 +01003927 * Uninstalls the given certificate from trusted user CAs, if present.
3928 *
Edman Anjosf9946772016-11-28 16:35:15 +01003929 * The caller must be a profile or device owner on that user, or a delegate package given the
3930 * {@link #DELEGATION_CERT_INSTALL} scope via {@link #setDelegatedScopes}; otherwise a
3931 * security exception will be thrown.
3932 *
Robin Lee25e26452015-06-02 09:56:29 -07003933 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3934 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003935 * @param certBuffer encoded form of the certificate to remove.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003936 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3937 * owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003938 * @see #setDelegatedScopes
3939 * @see #DELEGATION_CERT_INSTALL
Maggie Benthallda51e682013-08-08 22:35:44 -04003940 */
Robin Lee25e26452015-06-02 09:56:29 -07003941 public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003942 throwIfParentInstance("uninstallCaCert");
Maggie Benthallda51e682013-08-08 22:35:44 -04003943 if (mService != null) {
3944 try {
Robin Lee306fe082014-06-19 14:04:24 +00003945 final String alias = getCaCertAlias(certBuffer);
Edman Anjosf9946772016-11-28 16:35:15 +01003946 mService.uninstallCaCerts(admin, mContext.getPackageName(), new String[] {alias});
Robin Lee306fe082014-06-19 14:04:24 +00003947 } catch (CertificateException e) {
3948 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04003949 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003950 throw e.rethrowFromSystemServer();
Maggie Benthallda51e682013-08-08 22:35:44 -04003951 }
3952 }
3953 }
3954
3955 /**
Robin Lee7e678712014-07-24 16:41:31 +01003956 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
3957 * If a user has installed any certificates by other means than device policy these will be
3958 * included too.
3959 *
Robin Lee25e26452015-06-02 09:56:29 -07003960 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3961 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003962 * @return a List of byte[] arrays, each encoding one user CA certificate.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003963 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3964 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04003965 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003966 public @NonNull List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) {
3967 final List<byte[]> certs = new ArrayList<byte[]>();
Benjamin Franzbc33c822016-04-15 08:57:52 +01003968 throwIfParentInstance("getInstalledCaCerts");
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003969 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01003970 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003971 mService.enforceCanManageCaCerts(admin, mContext.getPackageName());
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003972 final TrustedCertificateStore certStore = new TrustedCertificateStore();
3973 for (String alias : certStore.userAliases()) {
3974 try {
3975 certs.add(certStore.getCertificate(alias).getEncoded());
3976 } catch (CertificateException ce) {
3977 Log.w(TAG, "Could not encode certificate: " + alias, ce);
3978 }
3979 }
3980 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003981 throw re.rethrowFromSystemServer();
Robin Lee7e678712014-07-24 16:41:31 +01003982 }
3983 }
3984 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04003985 }
3986
3987 /**
Robin Lee7e678712014-07-24 16:41:31 +01003988 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
3989 * means other than device policy will also be removed, except for system CA certificates.
3990 *
Robin Lee25e26452015-06-02 09:56:29 -07003991 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3992 * {@code null} if calling from a delegated certificate installer.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003993 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3994 * owner.
Robin Lee7e678712014-07-24 16:41:31 +01003995 */
Robin Lee25e26452015-06-02 09:56:29 -07003996 public void uninstallAllUserCaCerts(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003997 throwIfParentInstance("uninstallAllUserCaCerts");
Robin Lee7e678712014-07-24 16:41:31 +01003998 if (mService != null) {
Robin Lee83881bd2015-06-09 16:04:38 -07003999 try {
Edman Anjosf9946772016-11-28 16:35:15 +01004000 mService.uninstallCaCerts(admin, mContext.getPackageName(),
4001 new TrustedCertificateStore().userAliases() .toArray(new String[0]));
Robin Lee83881bd2015-06-09 16:04:38 -07004002 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004003 throw re.rethrowFromSystemServer();
Robin Lee7e678712014-07-24 16:41:31 +01004004 }
4005 }
4006 }
4007
4008 /**
4009 * Returns whether this certificate is installed as a trusted CA.
4010 *
Robin Lee25e26452015-06-02 09:56:29 -07004011 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
4012 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01004013 * @param certBuffer encoded form of the certificate to look up.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004014 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
4015 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04004016 */
Robin Lee25e26452015-06-02 09:56:29 -07004017 public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004018 throwIfParentInstance("hasCaCertInstalled");
Esteban Talavera808f6ef2014-08-28 17:15:54 +01004019 if (mService != null) {
4020 try {
Edman Anjosf9946772016-11-28 16:35:15 +01004021 mService.enforceCanManageCaCerts(admin, mContext.getPackageName());
Esteban Talavera808f6ef2014-08-28 17:15:54 +01004022 return getCaCertAlias(certBuffer) != null;
4023 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004024 throw re.rethrowFromSystemServer();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01004025 } catch (CertificateException ce) {
4026 Log.w(TAG, "Could not parse certificate", ce);
4027 }
Maggie Benthallda51e682013-08-08 22:35:44 -04004028 }
4029 return false;
4030 }
4031
4032 /**
Robin Leece3399f2016-02-24 12:08:32 +00004033 * Called by a device or profile owner, or delegated certificate installer, to install a
4034 * certificate and corresponding private key. All apps within the profile will be able to access
4035 * the certificate and use the private key, given direct user approval.
4036 *
4037 * <p>Access to the installed credentials will not be granted to the caller of this API without
4038 * direct user approval. This is for security - should a certificate installer become
4039 * compromised, certificates it had already installed will be protected.
4040 *
4041 * <p>If the installer must have access to the credentials, call
Rubin Xub4365912016-03-23 12:13:22 +00004042 * {@link #installKeyPair(ComponentName, PrivateKey, Certificate[], String, boolean)} instead.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01004043 *
Robin Lee25e26452015-06-02 09:56:29 -07004044 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
4045 * {@code null} if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01004046 * @param privKey The private key to install.
4047 * @param cert The certificate to install.
4048 * @param alias The private key alias under which to install the certificate. If a certificate
4049 * with that alias already exists, it will be overwritten.
4050 * @return {@code true} if the keys were installed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004051 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
4052 * owner.
Edman Anjosf9946772016-11-28 16:35:15 +01004053 * @see #setDelegatedScopes
4054 * @see #DELEGATION_CERT_INSTALL
Bernhard Bauer26408cc2014-09-08 14:07:31 +01004055 */
Robin Leefbc65642015-08-03 16:21:22 +01004056 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
4057 @NonNull Certificate cert, @NonNull String alias) {
Rubin Xub4365912016-03-23 12:13:22 +00004058 return installKeyPair(admin, privKey, new Certificate[] {cert}, alias, false);
Robin Leece3399f2016-02-24 12:08:32 +00004059 }
4060
4061 /**
4062 * Called by a device or profile owner, or delegated certificate installer, to install a
Rubin Xub4365912016-03-23 12:13:22 +00004063 * certificate chain and corresponding private key for the leaf certificate. All apps within the
4064 * profile will be able to access the certificate chain and use the private key, given direct
4065 * user approval.
Robin Leece3399f2016-02-24 12:08:32 +00004066 *
Robin Leea1b290e2016-03-09 14:38:36 +00004067 * <p>The caller of this API may grant itself access to the certificate and private key
4068 * immediately, without user approval. It is a best practice not to request this unless strictly
4069 * necessary since it opens up additional security vulnerabilities.
Robin Leece3399f2016-02-24 12:08:32 +00004070 *
4071 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Robin Leea1b290e2016-03-09 14:38:36 +00004072 * {@code null} if calling from a delegated certificate installer.
Robin Leece3399f2016-02-24 12:08:32 +00004073 * @param privKey The private key to install.
Rubin Xub4365912016-03-23 12:13:22 +00004074 * @param certs The certificate chain to install. The chain should start with the leaf
4075 * certificate and include the chain of trust in order. This will be returned by
4076 * {@link android.security.KeyChain#getCertificateChain}.
Robin Leece3399f2016-02-24 12:08:32 +00004077 * @param alias The private key alias under which to install the certificate. If a certificate
Robin Leea1b290e2016-03-09 14:38:36 +00004078 * with that alias already exists, it will be overwritten.
Robin Leece3399f2016-02-24 12:08:32 +00004079 * @param requestAccess {@code true} to request that the calling app be granted access to the
Robin Leea1b290e2016-03-09 14:38:36 +00004080 * credentials immediately. Otherwise, access to the credentials will be gated by user
4081 * approval.
Robin Leece3399f2016-02-24 12:08:32 +00004082 * @return {@code true} if the keys were installed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004083 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
4084 * owner.
Rubin Xub4365912016-03-23 12:13:22 +00004085 * @see android.security.KeyChain#getCertificateChain
Edman Anjosf9946772016-11-28 16:35:15 +01004086 * @see #setDelegatedScopes
4087 * @see #DELEGATION_CERT_INSTALL
Robin Leece3399f2016-02-24 12:08:32 +00004088 */
4089 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
Rubin Xub4365912016-03-23 12:13:22 +00004090 @NonNull Certificate[] certs, @NonNull String alias, boolean requestAccess) {
Eran Messerif15d4f42018-03-23 13:32:17 +00004091 int flags = INSTALLKEY_SET_USER_SELECTABLE;
4092 if (requestAccess) {
4093 flags |= INSTALLKEY_REQUEST_CREDENTIALS_ACCESS;
4094 }
4095 return installKeyPair(admin, privKey, certs, alias, flags);
Eran Messeri19d19042017-11-20 12:48:52 +00004096 }
4097
4098 /**
4099 * Called by a device or profile owner, or delegated certificate installer, to install a
4100 * certificate chain and corresponding private key for the leaf certificate. All apps within the
4101 * profile will be able to access the certificate chain and use the private key, given direct
4102 * user approval (if the user is allowed to select the private key).
4103 *
4104 * <p>The caller of this API may grant itself access to the certificate and private key
4105 * immediately, without user approval. It is a best practice not to request this unless strictly
4106 * necessary since it opens up additional security vulnerabilities.
4107 *
Benjamin Miller8040fd12018-04-16 15:52:15 +00004108 * <p>Include {@link #INSTALLKEY_SET_USER_SELECTABLE} in the {@code flags} argument to allow
4109 * the user to select the key from a dialog.
Eran Messeri19d19042017-11-20 12:48:52 +00004110 *
4111 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
4112 * {@code null} if calling from a delegated certificate installer.
4113 * @param privKey The private key to install.
4114 * @param certs The certificate chain to install. The chain should start with the leaf
4115 * certificate and include the chain of trust in order. This will be returned by
4116 * {@link android.security.KeyChain#getCertificateChain}.
4117 * @param alias The private key alias under which to install the certificate. If a certificate
4118 * with that alias already exists, it will be overwritten.
Eran Messerif15d4f42018-03-23 13:32:17 +00004119 * @param flags Flags to request that the calling app be granted access to the credentials
4120 * and set the key to be user-selectable. See {@link #INSTALLKEY_SET_USER_SELECTABLE} and
4121 * {@link #INSTALLKEY_REQUEST_CREDENTIALS_ACCESS}.
Eran Messeri19d19042017-11-20 12:48:52 +00004122 * @return {@code true} if the keys were installed, {@code false} otherwise.
4123 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
4124 * owner.
4125 * @see android.security.KeyChain#getCertificateChain
4126 * @see #setDelegatedScopes
4127 * @see #DELEGATION_CERT_INSTALL
4128 */
4129 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
Eran Messerif15d4f42018-03-23 13:32:17 +00004130 @NonNull Certificate[] certs, @NonNull String alias, int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004131 throwIfParentInstance("installKeyPair");
Eran Messerif15d4f42018-03-23 13:32:17 +00004132 boolean requestAccess = (flags & INSTALLKEY_REQUEST_CREDENTIALS_ACCESS)
4133 == INSTALLKEY_REQUEST_CREDENTIALS_ACCESS;
4134 boolean isUserSelectable = (flags & INSTALLKEY_SET_USER_SELECTABLE)
4135 == INSTALLKEY_SET_USER_SELECTABLE;
Bernhard Bauer26408cc2014-09-08 14:07:31 +01004136 try {
Rubin Xub4365912016-03-23 12:13:22 +00004137 final byte[] pemCert = Credentials.convertToPem(certs[0]);
4138 byte[] pemChain = null;
4139 if (certs.length > 1) {
4140 pemChain = Credentials.convertToPem(Arrays.copyOfRange(certs, 1, certs.length));
4141 }
Robin Lee0d5ccb72014-09-12 17:41:44 +01004142 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
4143 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
Edman Anjosf9946772016-11-28 16:35:15 +01004144 return mService.installKeyPair(admin, mContext.getPackageName(), pkcs8Key, pemCert,
Eran Messeri19d19042017-11-20 12:48:52 +00004145 pemChain, alias, requestAccess, isUserSelectable);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01004146 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004147 throw e.rethrowFromSystemServer();
Robin Lee0d5ccb72014-09-12 17:41:44 +01004148 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
4149 Log.w(TAG, "Failed to obtain private key material", e);
4150 } catch (CertificateException | IOException e) {
4151 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01004152 }
4153 return false;
4154 }
4155
4156 /**
Robin Leea1b290e2016-03-09 14:38:36 +00004157 * Called by a device or profile owner, or delegated certificate installer, to remove a
4158 * certificate and private key pair installed under a given alias.
Robin Leefbc65642015-08-03 16:21:22 +01004159 *
4160 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Robin Leea1b290e2016-03-09 14:38:36 +00004161 * {@code null} if calling from a delegated certificate installer.
Robin Leefbc65642015-08-03 16:21:22 +01004162 * @param alias The private key alias under which the certificate is installed.
Robin Leea1b290e2016-03-09 14:38:36 +00004163 * @return {@code true} if the private key alias no longer exists, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004164 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
4165 * owner.
Edman Anjosf9946772016-11-28 16:35:15 +01004166 * @see #setDelegatedScopes
4167 * @see #DELEGATION_CERT_INSTALL
Robin Leefbc65642015-08-03 16:21:22 +01004168 */
4169 public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004170 throwIfParentInstance("removeKeyPair");
Robin Leefbc65642015-08-03 16:21:22 +01004171 try {
Edman Anjosf9946772016-11-28 16:35:15 +01004172 return mService.removeKeyPair(admin, mContext.getPackageName(), alias);
Robin Leefbc65642015-08-03 16:21:22 +01004173 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004174 throw e.rethrowFromSystemServer();
Robin Leefbc65642015-08-03 16:21:22 +01004175 }
Robin Leefbc65642015-08-03 16:21:22 +01004176 }
4177
4178 /**
Eran Messeri852c8f12017-11-15 05:55:52 +00004179 * Called by a device or profile owner, or delegated certificate installer, to generate a
4180 * new private/public key pair. If the device supports key generation via secure hardware,
4181 * this method is useful for creating a key in KeyChain that never left the secure hardware.
4182 *
4183 * Access to the key is controlled the same way as in {@link #installKeyPair}.
4184 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
4185 * {@code null} if calling from a delegated certificate installer.
4186 * @param algorithm The key generation algorithm, see {@link java.security.KeyPairGenerator}.
4187 * @param keySpec Specification of the key to generate, see
4188 * {@link java.security.KeyPairGenerator}.
Eran Messeri94d56762017-12-21 20:50:54 +00004189 * @param idAttestationFlags A bitmask of all the identifiers that should be included in the
4190 * attestation record ({@code ID_TYPE_BASE_INFO}, {@code ID_TYPE_SERIAL},
4191 * {@code ID_TYPE_IMEI} and {@code ID_TYPE_MEID}), or {@code 0} if no device
4192 * identification is required in the attestation record.
4193 * Device owner, profile owner and their delegated certificate installer can use
4194 * {@link #ID_TYPE_BASE_INFO} to request inclusion of the general device information
4195 * including manufacturer, model, brand, device and product in the attestation record.
4196 * Only device owner and their delegated certificate installer can use
4197 * {@link #ID_TYPE_SERIAL}, {@link #ID_TYPE_IMEI} and {@link #ID_TYPE_MEID} to request
4198 * unique device identifiers to be attested.
4199 * <p>
4200 * If any of {@link #ID_TYPE_SERIAL}, {@link #ID_TYPE_IMEI} and {@link #ID_TYPE_MEID}
4201 * is set, it is implicitly assumed that {@link #ID_TYPE_BASE_INFO} is also set.
4202 * <p>
4203 * If any flag is specified, then an attestation challenge must be included in the
4204 * {@code keySpec}.
Eran Messeri852c8f12017-11-15 05:55:52 +00004205 * @return A non-null {@code AttestedKeyPair} if the key generation succeeded, null otherwise.
4206 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
Eran Messeri94d56762017-12-21 20:50:54 +00004207 * owner. If Device ID attestation is requested (using {@link #ID_TYPE_SERIAL},
4208 * {@link #ID_TYPE_IMEI} or {@link #ID_TYPE_MEID}), the caller must be the Device Owner
4209 * or the Certificate Installer delegate.
4210 * @throws IllegalArgumentException if the alias in {@code keySpec} is empty, if the
Eran Messeri852c8f12017-11-15 05:55:52 +00004211 * algorithm specification in {@code keySpec} is not {@code RSAKeyGenParameterSpec}
Eran Messeri94d56762017-12-21 20:50:54 +00004212 * or {@code ECGenParameterSpec}, or if Device ID attestation was requested but the
4213 * {@code keySpec} does not contain an attestation challenge.
Eran Messeri61692392018-03-26 16:43:14 +01004214 * @throws UnsupportedOperationException if Device ID attestation was requested but the
4215 * underlying hardware does not support it.
Eran Messeri94d56762017-12-21 20:50:54 +00004216 * @see KeyGenParameterSpec.Builder#setAttestationChallenge(byte[])
Eran Messeri852c8f12017-11-15 05:55:52 +00004217 */
4218 public AttestedKeyPair generateKeyPair(@Nullable ComponentName admin,
Eran Messeri94d56762017-12-21 20:50:54 +00004219 @NonNull String algorithm, @NonNull KeyGenParameterSpec keySpec,
4220 @AttestationIdType int idAttestationFlags) {
Eran Messeri852c8f12017-11-15 05:55:52 +00004221 throwIfParentInstance("generateKeyPair");
4222 try {
4223 final ParcelableKeyGenParameterSpec parcelableSpec =
4224 new ParcelableKeyGenParameterSpec(keySpec);
Eran Messeria1730642017-12-11 17:48:47 +00004225 KeymasterCertificateChain attestationChain = new KeymasterCertificateChain();
Eran Messeri94d56762017-12-21 20:50:54 +00004226
4227 // Translate ID attestation flags to values used by AttestationUtils
Eran Messeri852c8f12017-11-15 05:55:52 +00004228 final boolean success = mService.generateKeyPair(
Eran Messeri94d56762017-12-21 20:50:54 +00004229 admin, mContext.getPackageName(), algorithm, parcelableSpec,
4230 idAttestationFlags, attestationChain);
Eran Messeri852c8f12017-11-15 05:55:52 +00004231 if (!success) {
4232 Log.e(TAG, "Error generating key via DevicePolicyManagerService.");
4233 return null;
4234 }
4235
Eran Messeria1730642017-12-11 17:48:47 +00004236 final String alias = keySpec.getKeystoreAlias();
4237 final KeyPair keyPair = KeyChain.getKeyPair(mContext, alias);
4238 Certificate[] outputChain = null;
4239 try {
4240 if (AttestationUtils.isChainValid(attestationChain)) {
4241 outputChain = AttestationUtils.parseCertificateChain(attestationChain);
4242 }
4243 } catch (KeyAttestationException e) {
4244 Log.e(TAG, "Error parsing attestation chain for alias " + alias, e);
4245 mService.removeKeyPair(admin, mContext.getPackageName(), alias);
4246 return null;
4247 }
4248 return new AttestedKeyPair(keyPair, outputChain);
Eran Messeri852c8f12017-11-15 05:55:52 +00004249 } catch (RemoteException e) {
4250 throw e.rethrowFromSystemServer();
4251 } catch (KeyChainException e) {
4252 Log.w(TAG, "Failed to generate key", e);
4253 } catch (InterruptedException e) {
4254 Log.w(TAG, "Interrupted while generating key", e);
4255 Thread.currentThread().interrupt();
4256 }
4257 return null;
4258 }
4259
Eran Messeriadaf68c2018-03-27 19:34:03 +01004260 /**
4261 * Returns {@code true} if the device supports attestation of device identifiers in addition
4262 * to key attestation.
4263 * @return {@code true} if Device ID attestation is supported.
4264 */
4265 public boolean isDeviceIdAttestationSupported() {
4266 PackageManager pm = mContext.getPackageManager();
4267 return pm.hasSystemFeature(PackageManager.FEATURE_DEVICE_ID_ATTESTATION);
4268 }
Eran Messeriecf0f222017-12-11 12:32:13 +00004269
4270 /**
4271 * Called by a device or profile owner, or delegated certificate installer, to associate
4272 * certificates with a key pair that was generated using {@link #generateKeyPair}, and
4273 * set whether the key is available for the user to choose in the certificate selection
4274 * prompt.
4275 *
4276 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
4277 * {@code null} if calling from a delegated certificate installer.
4278 * @param alias The private key alias under which to install the certificate. The {@code alias}
4279 * should denote an existing private key. If a certificate with that alias already
4280 * exists, it will be overwritten.
4281 * @param certs The certificate chain to install. The chain should start with the leaf
4282 * certificate and include the chain of trust in order. This will be returned by
4283 * {@link android.security.KeyChain#getCertificateChain}.
4284 * @param isUserSelectable {@code true} to indicate that a user can select this key via the
4285 * certificate selection prompt, {@code false} to indicate that this key can only be
4286 * granted access by implementing
4287 * {@link android.app.admin.DeviceAdminReceiver#onChoosePrivateKeyAlias}.
4288 * @return {@code true} if the provided {@code alias} exists and the certificates has been
4289 * successfully associated with it, {@code false} otherwise.
4290 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
4291 * owner, or {@code admin} is null but the calling application is not a delegated
4292 * certificate installer.
4293 */
4294 public boolean setKeyPairCertificate(@Nullable ComponentName admin,
4295 @NonNull String alias, @NonNull List<Certificate> certs, boolean isUserSelectable) {
4296 throwIfParentInstance("setKeyPairCertificate");
4297 try {
4298 final byte[] pemCert = Credentials.convertToPem(certs.get(0));
4299 byte[] pemChain = null;
4300 if (certs.size() > 1) {
4301 pemChain = Credentials.convertToPem(
4302 certs.subList(1, certs.size()).toArray(new Certificate[0]));
4303 }
4304 return mService.setKeyPairCertificate(admin, mContext.getPackageName(), alias, pemCert,
4305 pemChain, isUserSelectable);
4306 } catch (RemoteException e) {
4307 throw e.rethrowFromSystemServer();
4308 } catch (CertificateException | IOException e) {
4309 Log.w(TAG, "Could not pem-encode certificate", e);
4310 }
4311 return false;
4312 }
4313
4314
Eran Messeri852c8f12017-11-15 05:55:52 +00004315 /**
Robin Lee25e26452015-06-02 09:56:29 -07004316 * @return the alias of a given CA certificate in the certificate store, or {@code null} if it
Robin Lee306fe082014-06-19 14:04:24 +00004317 * doesn't exist.
4318 */
4319 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
4320 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
4321 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
4322 new ByteArrayInputStream(certBuffer));
4323 return new TrustedCertificateStore().getCertificateAlias(cert);
4324 }
4325
4326 /**
Rubin Xuec32b562015-03-03 17:34:05 +00004327 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01004328 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00004329 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01004330 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00004331 * <p>
4332 * Delegated certificate installer is a per-user state. The delegated access is persistent until
4333 * it is later cleared by calling this method with a null value or uninstallling the certificate
4334 * installer.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004335 * <p>
Rubin Xuf03d0a62016-02-10 14:54:15 +00004336 * <b>Note:</b>Starting from {@link android.os.Build.VERSION_CODES#N}, if the caller
4337 * application's target SDK version is {@link android.os.Build.VERSION_CODES#N} or newer, the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004338 * supplied certificate installer package must be installed when calling this API, otherwise an
4339 * {@link IllegalArgumentException} will be thrown.
Rubin Xuec32b562015-03-03 17:34:05 +00004340 *
Robin Lee25e26452015-06-02 09:56:29 -07004341 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xuec32b562015-03-03 17:34:05 +00004342 * @param installerPackage The package name of the certificate installer which will be given
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004343 * access. If {@code null} is given the current package will be cleared.
4344 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01004345 *
4346 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #setDelegatedScopes}
4347 * with the {@link #DELEGATION_CERT_INSTALL} scope instead.
Rubin Xuec32b562015-03-03 17:34:05 +00004348 */
Edman Anjosf9946772016-11-28 16:35:15 +01004349 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07004350 public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String
4351 installerPackage) throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004352 throwIfParentInstance("setCertInstallerPackage");
Rubin Xuec32b562015-03-03 17:34:05 +00004353 if (mService != null) {
4354 try {
Robin Lee25e26452015-06-02 09:56:29 -07004355 mService.setCertInstallerPackage(admin, installerPackage);
Rubin Xuec32b562015-03-03 17:34:05 +00004356 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004357 throw e.rethrowFromSystemServer();
Rubin Xuec32b562015-03-03 17:34:05 +00004358 }
4359 }
4360 }
4361
4362 /**
Edman Anjosf9946772016-11-28 16:35:15 +01004363 * Called by a profile owner or device owner to retrieve the certificate installer for the user,
4364 * or {@code null} if none is set. If there are multiple delegates this function will return one
4365 * of them.
Rubin Xuec32b562015-03-03 17:34:05 +00004366 *
Robin Lee25e26452015-06-02 09:56:29 -07004367 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004368 * @return The package name of the current delegated certificate installer, or {@code null} if
4369 * none is set.
4370 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01004371 *
4372 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatePackages}
4373 * with the {@link #DELEGATION_CERT_INSTALL} scope instead.
Rubin Xuec32b562015-03-03 17:34:05 +00004374 */
Edman Anjosf9946772016-11-28 16:35:15 +01004375 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07004376 public @Nullable String getCertInstallerPackage(@NonNull ComponentName admin)
4377 throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004378 throwIfParentInstance("getCertInstallerPackage");
Rubin Xuec32b562015-03-03 17:34:05 +00004379 if (mService != null) {
4380 try {
Robin Lee25e26452015-06-02 09:56:29 -07004381 return mService.getCertInstallerPackage(admin);
Rubin Xuec32b562015-03-03 17:34:05 +00004382 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004383 throw e.rethrowFromSystemServer();
Rubin Xuec32b562015-03-03 17:34:05 +00004384 }
4385 }
4386 return null;
4387 }
4388
4389 /**
Edman Anjosf9946772016-11-28 16:35:15 +01004390 * Called by a profile owner or device owner to grant access to privileged APIs to another app.
4391 * Granted APIs are determined by {@code scopes}, which is a list of the {@code DELEGATION_*}
4392 * constants.
4393 * <p>
Edman Anjos9e62c312017-01-26 22:22:58 +01004394 * A broadcast with the {@link #ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED} action will be
4395 * sent to the {@code delegatePackage} with its new scopes in an {@code ArrayList<String>} extra
4396 * under the {@link #EXTRA_DELEGATION_SCOPES} key. The broadcast is sent with the
4397 * {@link Intent#FLAG_RECEIVER_REGISTERED_ONLY} flag.
4398 * <p>
Edman Anjosf9946772016-11-28 16:35:15 +01004399 * Delegated scopes are a per-user state. The delegated access is persistent until it is later
4400 * cleared by calling this method with an empty {@code scopes} list or uninstalling the
4401 * {@code delegatePackage}.
4402 *
4403 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4404 * @param delegatePackage The package name of the app which will be given access.
4405 * @param scopes The groups of privileged APIs whose access should be granted to
4406 * {@code delegatedPackage}.
4407 * @throws SecurityException if {@code admin} is not a device or a profile owner.
4408 */
4409 public void setDelegatedScopes(@NonNull ComponentName admin, @NonNull String delegatePackage,
4410 @NonNull List<String> scopes) {
4411 throwIfParentInstance("setDelegatedScopes");
4412 if (mService != null) {
4413 try {
4414 mService.setDelegatedScopes(admin, delegatePackage, scopes);
4415 } catch (RemoteException e) {
4416 throw e.rethrowFromSystemServer();
4417 }
4418 }
4419 }
4420
4421 /**
4422 * Called by a profile owner or device owner to retrieve a list of the scopes given to a
4423 * delegate package. Other apps can use this method to retrieve their own delegated scopes by
4424 * passing {@code null} for {@code admin} and their own package name as
4425 * {@code delegatedPackage}.
4426 *
4427 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
4428 * {@code null} if the caller is {@code delegatedPackage}.
4429 * @param delegatedPackage The package name of the app whose scopes should be retrieved.
4430 * @return A list containing the scopes given to {@code delegatedPackage}.
4431 * @throws SecurityException if {@code admin} is not a device or a profile owner.
4432 */
4433 @NonNull
Edman Anjos9e62c312017-01-26 22:22:58 +01004434 public List<String> getDelegatedScopes(@Nullable ComponentName admin,
Edman Anjosf9946772016-11-28 16:35:15 +01004435 @NonNull String delegatedPackage) {
4436 throwIfParentInstance("getDelegatedScopes");
4437 if (mService != null) {
4438 try {
4439 return mService.getDelegatedScopes(admin, delegatedPackage);
4440 } catch (RemoteException e) {
4441 throw e.rethrowFromSystemServer();
4442 }
4443 }
4444 return null;
4445 }
4446
4447 /**
4448 * Called by a profile owner or device owner to retrieve a list of delegate packages that were
4449 * granted a delegation scope.
4450 *
4451 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4452 * @param delegationScope The scope whose delegates should be retrieved.
4453 * @return A list of package names of the current delegated packages for
4454 {@code delegationScope}.
4455 * @throws SecurityException if {@code admin} is not a device or a profile owner.
4456 */
4457 @Nullable
4458 public List<String> getDelegatePackages(@NonNull ComponentName admin,
4459 @NonNull String delegationScope) {
4460 throwIfParentInstance("getDelegatePackages");
4461 if (mService != null) {
4462 try {
4463 return mService.getDelegatePackages(admin, delegationScope);
4464 } catch (RemoteException e) {
4465 throw e.rethrowFromSystemServer();
4466 }
4467 }
4468 return null;
4469 }
4470
4471 /**
Pavel Grafov5cba3362019-01-25 08:50:06 +00004472 * Service-specific error code used in implementation of {@code setAlwaysOnVpnPackage} methods.
4473 * @hide
4474 */
4475 public static final int ERROR_VPN_PACKAGE_NOT_FOUND = 1;
4476
4477 /**
Robin Lee244ce8e2016-01-05 18:03:46 +00004478 * Called by a device or profile owner to configure an always-on VPN connection through a
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004479 * specific application for the current user. This connection is automatically granted and
4480 * persisted after a reboot.
Pavel Grafov5cba3362019-01-25 08:50:06 +00004481 * <p> To support the always-on feature, an app must
Charles He36738632017-05-15 17:07:18 +01004482 * <ul>
4483 * <li>declare a {@link android.net.VpnService} in its manifest, guarded by
4484 * {@link android.Manifest.permission#BIND_VPN_SERVICE};</li>
4485 * <li>target {@link android.os.Build.VERSION_CODES#N API 24} or above; and</li>
4486 * <li><i>not</i> explicitly opt out of the feature through
Charles Hec57a01c2017-08-15 15:30:22 +01004487 * {@link android.net.VpnService#SERVICE_META_DATA_SUPPORTS_ALWAYS_ON}.</li>
Charles He36738632017-05-15 17:07:18 +01004488 * </ul>
4489 * The call will fail if called with the package name of an unsupported VPN app.
Pavel Grafov5cba3362019-01-25 08:50:06 +00004490 * <p> Enabling lockdown via {@code lockdownEnabled} argument carries the risk that any failure
4491 * of the VPN provider could break networking for all apps.
Robin Lee244ce8e2016-01-05 18:03:46 +00004492 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004493 * @param vpnPackage The package name for an installed VPN app on the device, or {@code null} to
Robin Leedc679712016-05-03 13:23:03 +01004494 * remove an existing always-on VPN configuration.
4495 * @param lockdownEnabled {@code true} to disallow networking when the VPN is not connected or
Pavel Grafov5cba3362019-01-25 08:50:06 +00004496 * {@code false} otherwise. This has no effect when clearing.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004497 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Robin Leeee5eb932016-04-05 16:27:15 +01004498 * @throws NameNotFoundException if {@code vpnPackage} is not installed.
4499 * @throws UnsupportedOperationException if {@code vpnPackage} exists but does not support being
4500 * set as always-on, or if always-on VPN is not available.
Pavel Grafov5cba3362019-01-25 08:50:06 +00004501 * @see #setAlwaysOnVpnPackage(ComponentName, String, boolean, List)
Robin Lee244ce8e2016-01-05 18:03:46 +00004502 */
Robin Leedc679712016-05-03 13:23:03 +01004503 public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage,
Pavel Grafov5cba3362019-01-25 08:50:06 +00004504 boolean lockdownEnabled) throws NameNotFoundException {
4505 setAlwaysOnVpnPackage(admin, vpnPackage, lockdownEnabled, Collections.emptyList());
4506 }
4507
4508 /**
4509 * A version of {@link #setAlwaysOnVpnPackage(ComponentName, String, boolean)} that allows the
4510 * admin to specify a set of apps that should be able to access the network directly when VPN
4511 * is not connected. When VPN connects these apps switch over to VPN if allowed to use that VPN.
4512 * System apps can always bypass VPN.
4513 * <p> Note that the system doesn't update the whitelist when packages are installed or
4514 * uninstalled, the admin app must call this method to keep the list up to date.
4515 *
4516 * @param vpnPackage package name for an installed VPN app on the device, or {@code null}
4517 * to remove an existing always-on VPN configuration
4518 * @param lockdownEnabled {@code true} to disallow networking when the VPN is not connected or
4519 * {@code false} otherwise. This has no effect when clearing.
4520 * @param lockdownWhitelist Packages that will be able to access the network directly when VPN
4521 * is in lockdown mode but not connected. Has no effect when clearing.
4522 * @throws SecurityException if {@code admin} is not a device or a profile
4523 * owner.
4524 * @throws NameNotFoundException if {@code vpnPackage} or one of
4525 * {@code lockdownWhitelist} is not installed.
4526 * @throws UnsupportedOperationException if {@code vpnPackage} exists but does
4527 * not support being set as always-on, or if always-on VPN is not
4528 * available.
4529 */
4530 public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage,
4531 boolean lockdownEnabled, @Nullable List<String> lockdownWhitelist)
4532 throws NameNotFoundException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004533 throwIfParentInstance("setAlwaysOnVpnPackage");
Robin Lee244ce8e2016-01-05 18:03:46 +00004534 if (mService != null) {
4535 try {
Pavel Grafov5cba3362019-01-25 08:50:06 +00004536 mService.setAlwaysOnVpnPackage(
4537 admin, vpnPackage, lockdownEnabled, lockdownWhitelist);
4538 } catch (ServiceSpecificException e) {
4539 switch (e.errorCode) {
4540 case ERROR_VPN_PACKAGE_NOT_FOUND:
4541 throw new NameNotFoundException(e.getMessage());
4542 default:
4543 throw new RuntimeException(
4544 "Unknown error setting always-on VPN: " + e.errorCode, e);
Robin Leeee5eb932016-04-05 16:27:15 +01004545 }
Robin Lee244ce8e2016-01-05 18:03:46 +00004546 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004547 throw e.rethrowFromSystemServer();
Robin Lee244ce8e2016-01-05 18:03:46 +00004548 }
4549 }
Robin Lee244ce8e2016-01-05 18:03:46 +00004550 }
4551
4552 /**
Pavel Grafov5cba3362019-01-25 08:50:06 +00004553 * Called by device or profile owner to query whether current always-on VPN is configured in
4554 * lockdown mode. Returns {@code false} when no always-on configuration is set.
4555 *
4556 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4557 *
4558 * @throws SecurityException if {@code admin} is not a device or a profile owner.
4559 *
4560 * @see #setAlwaysOnVpnPackage(ComponentName, String, boolean)
4561 */
4562 public boolean isAlwaysOnVpnLockdownEnabled(@NonNull ComponentName admin) {
4563 throwIfParentInstance("isAlwaysOnVpnLockdownEnabled");
4564 if (mService != null) {
4565 try {
4566 return mService.isAlwaysOnVpnLockdownEnabled(admin);
4567 } catch (RemoteException e) {
4568 throw e.rethrowFromSystemServer();
4569 }
4570 }
4571 return false;
4572 }
4573
4574 /**
4575 * Called by device or profile owner to query the list of packages that are allowed to access
4576 * the network directly when always-on VPN is in lockdown mode but not connected. Returns
4577 * {@code null} when always-on VPN is not active or not in lockdown mode.
4578 *
4579 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4580 *
4581 * @throws SecurityException if {@code admin} is not a device or a profile owner.
4582 *
4583 * @see #setAlwaysOnVpnPackage(ComponentName, String, boolean, List)
4584 */
4585 public @Nullable List<String> getAlwaysOnVpnLockdownWhitelist(@NonNull ComponentName admin) {
4586 throwIfParentInstance("getAlwaysOnVpnLockdownWhitelist");
4587 if (mService != null) {
4588 try {
4589 return mService.getAlwaysOnVpnLockdownWhitelist(admin);
4590 } catch (RemoteException e) {
4591 throw e.rethrowFromSystemServer();
4592 }
4593 }
4594 return null;
4595 }
4596
4597 /**
Robin Lee244ce8e2016-01-05 18:03:46 +00004598 * Called by a device or profile owner to read the name of the package administering an
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004599 * always-on VPN connection for the current user. If there is no such package, or the always-on
4600 * VPN is provided by the system instead of by an application, {@code null} will be returned.
Robin Lee244ce8e2016-01-05 18:03:46 +00004601 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004602 * @return Package name of VPN controller responsible for always-on VPN, or {@code null} if none
4603 * is set.
4604 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Robin Lee244ce8e2016-01-05 18:03:46 +00004605 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004606 public @Nullable String getAlwaysOnVpnPackage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004607 throwIfParentInstance("getAlwaysOnVpnPackage");
Robin Lee244ce8e2016-01-05 18:03:46 +00004608 if (mService != null) {
4609 try {
4610 return mService.getAlwaysOnVpnPackage(admin);
4611 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004612 throw e.rethrowFromSystemServer();
Robin Lee244ce8e2016-01-05 18:03:46 +00004613 }
4614 }
4615 return null;
4616 }
4617
4618 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004619 * Called by an application that is administering the device to disable all cameras on the
4620 * device, for this user. After setting this, no applications running as this user will be able
4621 * to access any cameras on the device.
4622 * <p>
4623 * If the caller is device owner, then the restriction will be applied to all users.
4624 * <p>
4625 * The calling device admin must have requested
4626 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call this method; if it has
4627 * not, a security exception will be thrown.
Ben Komalo2447edd2011-05-09 16:05:33 -07004628 *
4629 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4630 * @param disabled Whether or not the camera should be disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004631 * @throws SecurityException if {@code admin} is not an active administrator or does not use
4632 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA}.
Ben Komalo2447edd2011-05-09 16:05:33 -07004633 */
Robin Lee25e26452015-06-02 09:56:29 -07004634 public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004635 throwIfParentInstance("setCameraDisabled");
Ben Komalo2447edd2011-05-09 16:05:33 -07004636 if (mService != null) {
4637 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08004638 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07004639 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004640 throw e.rethrowFromSystemServer();
Ben Komalo2447edd2011-05-09 16:05:33 -07004641 }
4642 }
4643 }
4644
4645 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07004646 * Determine whether or not the device's cameras have been disabled for this user,
Makoto Onuki32b30572015-12-11 14:29:51 -08004647 * either by the calling admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07004648 * @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 -07004649 * have disabled the camera
4650 */
Robin Lee25e26452015-06-02 09:56:29 -07004651 public boolean getCameraDisabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004652 throwIfParentInstance("getCameraDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004653 return getCameraDisabled(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004654 }
4655
4656 /** @hide per-user version */
Mathew Inwood4fb17d12018-08-14 14:25:44 +01004657 @UnsupportedAppUsage
Robin Lee25e26452015-06-02 09:56:29 -07004658 public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07004659 if (mService != null) {
4660 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004661 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07004662 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004663 throw e.rethrowFromSystemServer();
Ben Komalo2447edd2011-05-09 16:05:33 -07004664 }
4665 }
4666 return false;
4667 }
4668
4669 /**
Michal Karpinski3fc437e2015-12-15 10:09:00 +00004670 * Called by a device owner to request a bugreport.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004671 * <p>
Alex Chau443b6432017-12-13 12:44:31 +00004672 * If the device contains secondary users or profiles, they must be affiliated with the device.
4673 * Otherwise a {@link SecurityException} will be thrown. See {@link #isAffiliatedUser}.
Michal Karpinski3fc437e2015-12-15 10:09:00 +00004674 *
4675 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004676 * @return {@code true} if the bugreport collection started successfully, or {@code false} if it
4677 * wasn't triggered because a previous bugreport operation is still active (either the
4678 * bugreport is still running or waiting for the user to share or decline)
Esteban Talaverad36dd152016-12-15 08:51:45 +00004679 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
Alex Chau443b6432017-12-13 12:44:31 +00004680 * profile or secondary user that is not affiliated with the device.
4681 * @see #isAffiliatedUser
Michal Karpinski3fc437e2015-12-15 10:09:00 +00004682 */
4683 public boolean requestBugreport(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004684 throwIfParentInstance("requestBugreport");
Michal Karpinski3fc437e2015-12-15 10:09:00 +00004685 if (mService != null) {
4686 try {
4687 return mService.requestBugreport(admin);
4688 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004689 throw e.rethrowFromSystemServer();
Michal Karpinski3fc437e2015-12-15 10:09:00 +00004690 }
4691 }
4692 return false;
4693 }
4694
4695 /**
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07004696 * Determine whether or not creating a guest user has been disabled for the device
4697 *
4698 * @hide
4699 */
4700 public boolean getGuestUserDisabled(@Nullable ComponentName admin) {
4701 // Currently guest users can always be created if multi-user is enabled
4702 // TODO introduce a policy for guest user creation
4703 return false;
4704 }
4705
4706 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01004707 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
4708 * screen capture also prevents the content from being shown on display devices that do not have
4709 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
4710 * secure surfaces and secure displays.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004711 * <p>
4712 * The calling device admin must be a device or profile owner. If it is not, a security
4713 * exception will be thrown.
4714 * <p>
4715 * From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also blocks
4716 * assist requests for all activities of the relevant user.
Benjamin Franzc200f442015-06-25 18:20:04 +01004717 *
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004718 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004719 * @param disabled Whether screen capture is disabled or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004720 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004721 */
Robin Lee25e26452015-06-02 09:56:29 -07004722 public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004723 throwIfParentInstance("setScreenCaptureDisabled");
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004724 if (mService != null) {
4725 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08004726 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004727 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004728 throw e.rethrowFromSystemServer();
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004729 }
4730 }
4731 }
4732
4733 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004734 * Determine whether or not screen capture has been disabled by the calling
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004735 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07004736 * @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 +01004737 * have disabled screen capture.
4738 */
Robin Lee25e26452015-06-02 09:56:29 -07004739 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004740 throwIfParentInstance("getScreenCaptureDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004741 return getScreenCaptureDisabled(admin, myUserId());
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004742 }
4743
4744 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07004745 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004746 if (mService != null) {
4747 try {
4748 return mService.getScreenCaptureDisabled(admin, userHandle);
4749 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004750 throw e.rethrowFromSystemServer();
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004751 }
4752 }
4753 return false;
4754 }
4755
4756 /**
Jason Parks841cb0a2017-01-17 15:25:17 -06004757 * Called by a device or profile owner to set whether auto time is required. If auto time is
4758 * 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 -07004759 * <p>
4760 * Note: if auto time is required the user can still manually set the time zone.
4761 * <p>
Jason Parks841cb0a2017-01-17 15:25:17 -06004762 * The calling device admin must be a device or profile owner. If it is not, a security
4763 * exception will be thrown.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004764 *
4765 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4766 * @param required Whether auto time is set required or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004767 * @throws SecurityException if {@code admin} is not a device owner.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004768 */
Robin Lee25e26452015-06-02 09:56:29 -07004769 public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004770 throwIfParentInstance("setAutoTimeRequired");
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004771 if (mService != null) {
4772 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08004773 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004774 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004775 throw e.rethrowFromSystemServer();
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004776 }
4777 }
4778 }
4779
4780 /**
4781 * @return true if auto time is required.
4782 */
4783 public boolean getAutoTimeRequired() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004784 throwIfParentInstance("getAutoTimeRequired");
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004785 if (mService != null) {
4786 try {
4787 return mService.getAutoTimeRequired();
4788 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004789 throw e.rethrowFromSystemServer();
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004790 }
4791 }
4792 return false;
4793 }
4794
4795 /**
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004796 * Called by a device owner to set whether all users created on the device should be ephemeral.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004797 * <p>
4798 * The system user is exempt from this policy - it is never ephemeral.
4799 * <p>
4800 * The calling device admin must be the device owner. If it is not, a security exception will be
4801 * thrown.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004802 *
4803 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4804 * @param forceEphemeralUsers If true, all the existing users will be deleted and all
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004805 * subsequently created users will be ephemeral.
4806 * @throws SecurityException if {@code admin} is not a device owner.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004807 * @hide
4808 */
4809 public void setForceEphemeralUsers(
4810 @NonNull ComponentName admin, boolean forceEphemeralUsers) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004811 throwIfParentInstance("setForceEphemeralUsers");
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004812 if (mService != null) {
4813 try {
4814 mService.setForceEphemeralUsers(admin, forceEphemeralUsers);
4815 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004816 throw e.rethrowFromSystemServer();
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004817 }
4818 }
4819 }
4820
4821 /**
4822 * @return true if all users are created ephemeral.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004823 * @throws SecurityException if {@code admin} is not a device owner.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004824 * @hide
4825 */
4826 public boolean getForceEphemeralUsers(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004827 throwIfParentInstance("getForceEphemeralUsers");
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004828 if (mService != null) {
4829 try {
4830 return mService.getForceEphemeralUsers(admin);
4831 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004832 throw e.rethrowFromSystemServer();
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004833 }
4834 }
4835 return false;
4836 }
4837
4838 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07004839 * Called by an application that is administering the device to disable keyguard customizations,
4840 * such as widgets. After setting this, keyguard features will be disabled according to the
4841 * provided feature list.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004842 * <p>
4843 * The calling device admin must have requested
4844 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method;
4845 * if it has not, a security exception will be thrown.
4846 * <p>
4847 * Calling this from a managed profile before version {@link android.os.Build.VERSION_CODES#M}
4848 * will throw a security exception. From version {@link android.os.Build.VERSION_CODES#M} the
4849 * profile owner of a managed profile can set:
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00004850 * <ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00004851 * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which affects the parent user, but only if there
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004852 * is no separate challenge set on the managed profile.
Rubin Xuc418d5a2018-05-02 12:18:18 +01004853 * <li>{@link #KEYGUARD_DISABLE_FINGERPRINT}, {@link #KEYGUARD_DISABLE_FACE} or
4854 * {@link #KEYGUARD_DISABLE_IRIS} which affects the managed profile challenge if
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004855 * there is one, or the parent user otherwise.
4856 * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} which affects notifications generated
4857 * by applications in the managed profile.
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00004858 * </ul>
Rubin Xuc418d5a2018-05-02 12:18:18 +01004859 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, {@link #KEYGUARD_DISABLE_FINGERPRINT},
4860 * {@link #KEYGUARD_DISABLE_FACE} and {@link #KEYGUARD_DISABLE_IRIS} can also be
Esteban Talaverac1c83592016-02-17 17:56:15 +00004861 * set on the {@link DevicePolicyManager} instance returned by
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004862 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
4863 * profile.
4864 * <p>
4865 * Requests to disable other features on a managed profile will be ignored.
4866 * <p>
4867 * The admin can check which features have been disabled by calling
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00004868 * {@link #getKeyguardDisabledFeatures(ComponentName)}
Amith Yamasani242f4b12014-10-14 16:06:13 -07004869 *
Jim Millerb8ec4702012-08-31 17:19:10 -07004870 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xuc418d5a2018-05-02 12:18:18 +01004871 * @param which The disabled features flag which can be either
4872 * {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
4873 * {@link #KEYGUARD_DISABLE_FEATURES_ALL}, or a combination of
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004874 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
4875 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS},
4876 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
4877 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS},
Rubin Xuc418d5a2018-05-02 12:18:18 +01004878 * {@link #KEYGUARD_DISABLE_FINGERPRINT},
4879 * {@link #KEYGUARD_DISABLE_FACE},
4880 * {@link #KEYGUARD_DISABLE_IRIS}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004881 * @throws SecurityException if {@code admin} is not an active administrator or does not user
4882 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES}
Jim Millerb8ec4702012-08-31 17:19:10 -07004883 */
Robin Lee25e26452015-06-02 09:56:29 -07004884 public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07004885 if (mService != null) {
4886 try {
Esteban Talavera62399912016-01-11 15:37:55 +00004887 mService.setKeyguardDisabledFeatures(admin, which, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07004888 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004889 throw e.rethrowFromSystemServer();
Jim Millerb8ec4702012-08-31 17:19:10 -07004890 }
4891 }
4892 }
4893
4894 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004895 * Determine whether or not features have been disabled in keyguard either by the calling
Rubin Xud3609d42016-07-13 18:32:57 +01004896 * admin, if specified, or all admins that set restrictions on this user and its participating
Esteban Talaverac1c83592016-02-17 17:56:15 +00004897 * profiles. Restrictions on profiles that have a separate challenge are not taken into account.
4898 *
4899 * <p>This method can be called on the {@link DevicePolicyManager} instance
4900 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
4901 * restrictions on the parent profile.
4902 *
Esteban Talavera62399912016-01-11 15:37:55 +00004903 * @param admin The name of the admin component to check, or {@code null} to check whether any
4904 * admins have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07004905 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
4906 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07004907 */
Robin Lee25e26452015-06-02 09:56:29 -07004908 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004909 return getKeyguardDisabledFeatures(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004910 }
4911
4912 /** @hide per-user version */
Mathew Inwood4fb17d12018-08-14 14:25:44 +01004913 @UnsupportedAppUsage
Robin Lee25e26452015-06-02 09:56:29 -07004914 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07004915 if (mService != null) {
4916 try {
Esteban Talavera62399912016-01-11 15:37:55 +00004917 return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07004918 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004919 throw e.rethrowFromSystemServer();
Jim Millerb8ec4702012-08-31 17:19:10 -07004920 }
4921 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07004922 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07004923 }
4924
4925 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08004926 * @hide
4927 */
Mathew Inwood4fb17d12018-08-14 14:25:44 +01004928 @UnsupportedAppUsage
Robin Lee25e26452015-06-02 09:56:29 -07004929 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
4930 int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08004931 if (mService != null) {
4932 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01004933 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08004934 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004935 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08004936 }
4937 }
4938 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07004939
Dianne Hackbornd6847842010-01-12 18:14:19 -08004940 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01004941 * @hide
4942 */
Mathew Inwood4fb17d12018-08-14 14:25:44 +01004943 @UnsupportedAppUsage
Robin Lee25e26452015-06-02 09:56:29 -07004944 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004945 setActiveAdmin(policyReceiver, refreshing, myUserId());
Jessica Hummel6d36b602014-04-04 12:42:17 +01004946 }
4947
4948 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08004949 * @hide
4950 */
Robin Lee25e26452015-06-02 09:56:29 -07004951 public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08004952 if (mService != null) {
4953 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004954 mService.getRemoveWarning(admin, result, myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08004955 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004956 throw e.rethrowFromSystemServer();
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08004957 }
4958 }
4959 }
4960
4961 /**
4962 * @hide
4963 */
Mathew Inwood4fb17d12018-08-14 14:25:44 +01004964 @UnsupportedAppUsage
Andrew Scull5f9e6f32016-08-02 14:22:17 +01004965 public void setActivePasswordState(PasswordMetrics metrics, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08004966 if (mService != null) {
4967 try {
Andrew Scull5f9e6f32016-08-02 14:22:17 +01004968 mService.setActivePasswordState(metrics, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08004969 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004970 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08004971 }
4972 }
4973 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07004974
Dianne Hackbornd6847842010-01-12 18:14:19 -08004975 /**
4976 * @hide
4977 */
Andrew Scull5daf2732016-11-14 15:02:45 +00004978 public void reportPasswordChanged(@UserIdInt int userId) {
4979 if (mService != null) {
4980 try {
4981 mService.reportPasswordChanged(userId);
4982 } catch (RemoteException e) {
4983 throw e.rethrowFromSystemServer();
4984 }
4985 }
4986 }
4987
4988 /**
4989 * @hide
4990 */
Mathew Inwood4fb17d12018-08-14 14:25:44 +01004991 @UnsupportedAppUsage
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004992 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08004993 if (mService != null) {
4994 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004995 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08004996 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004997 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08004998 }
4999 }
5000 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07005001
Dianne Hackbornd6847842010-01-12 18:14:19 -08005002 /**
5003 * @hide
5004 */
Mathew Inwood4fb17d12018-08-14 14:25:44 +01005005 @UnsupportedAppUsage
Amith Yamasani599dd7c2012-09-14 23:20:08 -07005006 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08005007 if (mService != null) {
5008 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07005009 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08005010 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005011 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08005012 }
5013 }
5014 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07005015
5016 /**
Michal Karpinskied5c8f02016-02-09 15:43:41 +00005017 * @hide
5018 */
5019 public void reportFailedFingerprintAttempt(int userHandle) {
5020 if (mService != null) {
5021 try {
5022 mService.reportFailedFingerprintAttempt(userHandle);
5023 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005024 throw e.rethrowFromSystemServer();
Michal Karpinskied5c8f02016-02-09 15:43:41 +00005025 }
5026 }
5027 }
5028
5029 /**
5030 * @hide
5031 */
5032 public void reportSuccessfulFingerprintAttempt(int userHandle) {
5033 if (mService != null) {
5034 try {
5035 mService.reportSuccessfulFingerprintAttempt(userHandle);
5036 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005037 throw e.rethrowFromSystemServer();
Michal Karpinskied5c8f02016-02-09 15:43:41 +00005038 }
5039 }
5040 }
5041
5042 /**
Michal Karpinski31502d32016-01-25 16:43:07 +00005043 * Should be called when keyguard has been dismissed.
5044 * @hide
5045 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00005046 public void reportKeyguardDismissed(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00005047 if (mService != null) {
5048 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00005049 mService.reportKeyguardDismissed(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00005050 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005051 throw e.rethrowFromSystemServer();
Michal Karpinski31502d32016-01-25 16:43:07 +00005052 }
5053 }
5054 }
5055
5056 /**
5057 * Should be called when keyguard view has been shown to the user.
5058 * @hide
5059 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00005060 public void reportKeyguardSecured(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00005061 if (mService != null) {
5062 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00005063 mService.reportKeyguardSecured(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00005064 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005065 throw e.rethrowFromSystemServer();
Michal Karpinski31502d32016-01-25 16:43:07 +00005066 }
5067 }
5068 }
5069
5070 /**
Amith Yamasani71e6c692013-03-24 17:39:28 -07005071 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00005072 * Sets the given package as the device owner.
Makoto Onukia52562c2015-10-01 16:12:31 -07005073 * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name.
5074 * @param who the component name to be registered as device owner.
Amith Yamasani71e6c692013-03-24 17:39:28 -07005075 * @return whether the package was successfully registered as the device owner.
5076 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00005077 * @throws IllegalStateException If the preconditions mentioned are not met.
Amith Yamasani71e6c692013-03-24 17:39:28 -07005078 */
Makoto Onukia52562c2015-10-01 16:12:31 -07005079 public boolean setDeviceOwner(ComponentName who) {
5080 return setDeviceOwner(who, null);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04005081 }
5082
5083 /**
5084 * @hide
Makoto Onuki58b684f2015-09-04 10:48:16 -07005085 */
Makoto Onukia52562c2015-10-01 16:12:31 -07005086 public boolean setDeviceOwner(ComponentName who, int userId) {
5087 return setDeviceOwner(who, null, userId);
Makoto Onuki58b684f2015-09-04 10:48:16 -07005088 }
5089
5090 /**
5091 * @hide
5092 */
Makoto Onukia52562c2015-10-01 16:12:31 -07005093 public boolean setDeviceOwner(ComponentName who, String ownerName) {
5094 return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM);
Makoto Onuki58b684f2015-09-04 10:48:16 -07005095 }
5096
5097 /**
5098 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00005099 * Sets the given package as the device owner. The package must already be installed. There
5100 * must not already be a device owner.
5101 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
5102 * this method.
5103 * Calling this after the setup phase of the primary user has completed is allowed only if
5104 * the caller is the shell uid, and there are no additional users and no accounts.
Makoto Onukia52562c2015-10-01 16:12:31 -07005105 * @param who the component name to be registered as device owner.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04005106 * @param ownerName the human readable name of the institution that owns this device.
Makoto Onuki58b684f2015-09-04 10:48:16 -07005107 * @param userId ID of the user on which the device owner runs.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04005108 * @return whether the package was successfully registered as the device owner.
5109 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00005110 * @throws IllegalStateException If the preconditions mentioned are not met.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04005111 */
Makoto Onukia52562c2015-10-01 16:12:31 -07005112 public boolean setDeviceOwner(ComponentName who, String ownerName, int userId)
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04005113 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07005114 if (mService != null) {
5115 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07005116 return mService.setDeviceOwner(who, ownerName, userId);
Amith Yamasani71e6c692013-03-24 17:39:28 -07005117 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005118 throw re.rethrowFromSystemServer();
Amith Yamasani71e6c692013-03-24 17:39:28 -07005119 }
5120 }
5121 return false;
5122 }
5123
5124 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07005125 * Used to determine if a particular package has been registered as a Device Owner app.
5126 * A device owner app is a special device admin that cannot be deactivated by the user, once
Robin Lee25e26452015-06-02 09:56:29 -07005127 * activated as a device admin. It also cannot be uninstalled. To check whether a particular
Amith Yamasani3b458ad2013-04-18 18:40:07 -07005128 * package is currently registered as the device owner app, pass in the package name from
5129 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
Robin Lee25e26452015-06-02 09:56:29 -07005130 * admin apps that want to check whether they are also registered as the device owner app. The
Amith Yamasani3b458ad2013-04-18 18:40:07 -07005131 * exact mechanism by which a device admin app is registered as a device owner app is defined by
5132 * the setup process.
5133 * @param packageName the package name of the app, to compare with the registered device owner
5134 * app, if any.
Makoto Onukic8a5a552015-11-19 14:29:12 -08005135 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07005136 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07005137 public boolean isDeviceOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005138 throwIfParentInstance("isDeviceOwnerApp");
Makoto Onukic8a5a552015-11-19 14:29:12 -08005139 return isDeviceOwnerAppOnCallingUser(packageName);
5140 }
5141
5142 /**
5143 * @return true if a package is registered as device owner, only when it's running on the
5144 * calling user.
5145 *
5146 * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity.
5147 * @hide
5148 */
5149 public boolean isDeviceOwnerAppOnCallingUser(String packageName) {
5150 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true);
5151 }
5152
5153 /**
5154 * @return true if a package is registered as device owner, even if it's running on a different
5155 * user.
5156 *
5157 * <p>Requires the MANAGE_USERS permission.
5158 *
5159 * @hide
5160 */
5161 public boolean isDeviceOwnerAppOnAnyUser(String packageName) {
5162 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false);
5163 }
5164
5165 /**
5166 * @return device owner component name, only when it's running on the calling user.
5167 *
5168 * @hide
5169 */
5170 public ComponentName getDeviceOwnerComponentOnCallingUser() {
5171 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true);
5172 }
5173
5174 /**
5175 * @return device owner component name, even if it's running on a different user.
5176 *
Makoto Onukic8a5a552015-11-19 14:29:12 -08005177 * @hide
5178 */
Polina Bondarenko23561db2016-12-16 11:47:28 +01005179 @SystemApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06005180 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Makoto Onukic8a5a552015-11-19 14:29:12 -08005181 public ComponentName getDeviceOwnerComponentOnAnyUser() {
5182 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false);
5183 }
5184
5185 private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) {
Makoto Onuki70f929e2015-11-11 12:40:15 -08005186 if (packageName == null) {
5187 return false;
Amith Yamasani71e6c692013-03-24 17:39:28 -07005188 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08005189 final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly);
Makoto Onuki70f929e2015-11-11 12:40:15 -08005190 if (deviceOwner == null) {
5191 return false;
5192 }
5193 return packageName.equals(deviceOwner.getPackageName());
Amith Yamasani71e6c692013-03-24 17:39:28 -07005194 }
5195
Makoto Onukic8a5a552015-11-19 14:29:12 -08005196 private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) {
5197 if (mService != null) {
5198 try {
5199 return mService.getDeviceOwnerComponent(callingUserOnly);
5200 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005201 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08005202 }
5203 }
5204 return null;
Amith Yamasani3b458ad2013-04-18 18:40:07 -07005205 }
5206
Jason Monkb0dced82014-06-06 14:36:20 -04005207 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08005208 * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's
5209 * no device owner.
5210 *
5211 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07005212 *
5213 * @hide
5214 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08005215 public int getDeviceOwnerUserId() {
5216 if (mService != null) {
5217 try {
5218 return mService.getDeviceOwnerUserId();
5219 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005220 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08005221 }
5222 }
5223 return UserHandle.USER_NULL;
Makoto Onukia52562c2015-10-01 16:12:31 -07005224 }
5225
5226 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005227 * Clears the current device owner. The caller must be the device owner. This function should be
5228 * 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 +00005229 * a part of device setup, before it completes.
5230 * <p>
5231 * While some policies previously set by the device owner will be cleared by this method, it is
5232 * a best-effort process and some other policies will still remain in place after the device
5233 * owner is cleared.
Jason Monk94d2cf92014-06-18 09:53:34 -04005234 *
5235 * @param packageName The package name of the device owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005236 * @throws SecurityException if the caller is not in {@code packageName} or {@code packageName}
5237 * does not own the current device owner component.
Esteban Talaveraa5b09632017-02-10 16:15:24 +00005238 *
5239 * @deprecated This method is expected to be used for testing purposes only. The device owner
5240 * will lose control of the device and its data after calling it. In order to protect any
5241 * sensitive data that remains on the device, it is advised that the device owner factory resets
5242 * the device instead of calling this method. See {@link #wipeData(int)}.
Jason Monkb0dced82014-06-06 14:36:20 -04005243 */
Esteban Talaveraa5b09632017-02-10 16:15:24 +00005244 @Deprecated
Jason Monk94d2cf92014-06-18 09:53:34 -04005245 public void clearDeviceOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005246 throwIfParentInstance("clearDeviceOwnerApp");
Jason Monkb0dced82014-06-06 14:36:20 -04005247 if (mService != null) {
5248 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04005249 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04005250 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005251 throw re.rethrowFromSystemServer();
Jason Monkb0dced82014-06-06 14:36:20 -04005252 }
5253 }
5254 }
5255
Makoto Onukia52562c2015-10-01 16:12:31 -07005256 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08005257 * Returns the device owner package name, only if it's running on the calling user.
5258 *
5259 * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity.
Makoto Onukia52562c2015-10-01 16:12:31 -07005260 *
5261 * @hide
5262 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01005263 @SystemApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06005264 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Makoto Onuki408e8e42016-10-25 12:10:27 -07005265 public @Nullable String getDeviceOwner() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005266 throwIfParentInstance("getDeviceOwner");
Makoto Onukic8a5a552015-11-19 14:29:12 -08005267 final ComponentName name = getDeviceOwnerComponentOnCallingUser();
5268 return name != null ? name.getPackageName() : null;
Makoto Onukia52562c2015-10-01 16:12:31 -07005269 }
5270
5271 /**
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01005272 * Called by the system to find out whether the device is managed by a Device Owner.
Makoto Onukic8a5a552015-11-19 14:29:12 -08005273 *
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01005274 * @return whether the device is managed by a Device Owner.
5275 * @throws SecurityException if the caller is not the device owner, does not hold the
5276 * MANAGE_USERS permission and is not the system.
Makoto Onukia52562c2015-10-01 16:12:31 -07005277 *
5278 * @hide
5279 */
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01005280 @SystemApi
5281 @TestApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06005282 @SuppressLint("Doclava125")
Makoto Onukic8a5a552015-11-19 14:29:12 -08005283 public boolean isDeviceManaged() {
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01005284 try {
5285 return mService.hasDeviceOwner();
5286 } catch (RemoteException re) {
5287 throw re.rethrowFromSystemServer();
5288 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08005289 }
5290
5291 /**
5292 * Returns the device owner name. Note this method *will* return the device owner
5293 * name when it's running on a different user.
5294 *
Makoto Onukic8a5a552015-11-19 14:29:12 -08005295 * @hide
5296 */
Makoto Onukia2b274b2016-01-19 13:26:02 -08005297 @SystemApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06005298 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Makoto Onukic8a5a552015-11-19 14:29:12 -08005299 public String getDeviceOwnerNameOnAnyUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005300 throwIfParentInstance("getDeviceOwnerNameOnAnyUser");
Amith Yamasani71e6c692013-03-24 17:39:28 -07005301 if (mService != null) {
5302 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07005303 return mService.getDeviceOwnerName();
Amith Yamasani71e6c692013-03-24 17:39:28 -07005304 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005305 throw re.rethrowFromSystemServer();
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04005306 }
5307 }
5308 return null;
5309 }
Adam Connors776c5552014-01-09 10:42:56 +00005310
5311 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04005312 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04005313 * @deprecated Do not use
5314 * @removed
Julia Reynolds20118f12015-02-11 12:34:08 -05005315 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04005316 @Deprecated
Julia Reynolds20118f12015-02-11 12:34:08 -05005317 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06005318 @SuppressLint("Doclava125")
Makoto Onuki408e8e42016-10-25 12:10:27 -07005319 public @Nullable String getDeviceInitializerApp() {
Julia Reynolds20118f12015-02-11 12:34:08 -05005320 return null;
5321 }
5322
5323 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04005324 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04005325 * @deprecated Do not use
5326 * @removed
Julia Reynoldseaafdf722015-04-02 08:49:47 -04005327 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04005328 @Deprecated
Julia Reynoldseaafdf722015-04-02 08:49:47 -04005329 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06005330 @SuppressLint("Doclava125")
Makoto Onuki408e8e42016-10-25 12:10:27 -07005331 public @Nullable ComponentName getDeviceInitializerComponent() {
Julia Reynoldseaafdf722015-04-02 08:49:47 -04005332 return null;
5333 }
5334
Julia Reynolds20118f12015-02-11 12:34:08 -05005335 /**
Adam Connors776c5552014-01-09 10:42:56 +00005336 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07005337 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05305338 * Sets the given component as an active admin and registers the package as the profile
5339 * owner for this user. The package must already be installed and there shouldn't be
5340 * an existing profile owner registered for this user. Also, this method must be called
5341 * before the user setup has been completed.
5342 * <p>
5343 * This method can only be called by system apps that hold MANAGE_USERS permission and
5344 * MANAGE_DEVICE_ADMINS permission.
5345 * @param admin The component to register as an active admin and profile owner.
5346 * @param ownerName The user-visible name of the entity that is managing this user.
5347 * @return whether the admin was successfully registered as the profile owner.
5348 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
5349 * the user has already been set up.
5350 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07005351 @Deprecated
Justin Morey80440cc2014-07-24 09:16:35 -05005352 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06005353 @RequiresPermission(android.Manifest.permission.MANAGE_DEVICE_ADMINS)
Robin Lee25e26452015-06-02 09:56:29 -07005354 public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05305355 throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005356 throwIfParentInstance("setActiveProfileOwner");
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05305357 if (mService != null) {
5358 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07005359 final int myUserId = myUserId();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05305360 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07005361 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05305362 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005363 throw re.rethrowFromSystemServer();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05305364 }
5365 }
5366 return false;
5367 }
5368
5369 /**
Esteban Talaveraa5b09632017-02-10 16:15:24 +00005370 * Clears the active profile owner. The caller must be the profile owner of this user, otherwise
5371 * a SecurityException will be thrown. This method is not available to managed profile owners.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005372 * <p>
Esteban Talaveraa5b09632017-02-10 16:15:24 +00005373 * While some policies previously set by the profile owner will be cleared by this method, it is
5374 * a best-effort process and some other policies will still remain in place after the profile
5375 * owner is cleared.
Makoto Onuki5bf68022016-01-27 13:49:19 -08005376 *
Amith Yamasanibf3a9462014-07-28 14:26:42 -07005377 * @param admin The component to remove as the profile owner.
Esteban Talaveraa5b09632017-02-10 16:15:24 +00005378 * @throws SecurityException if {@code admin} is not an active profile owner, or the method is
5379 * being called from a managed profile.
5380 *
5381 * @deprecated This method is expected to be used for testing purposes only. The profile owner
5382 * will lose control of the user and its data after calling it. In order to protect any
5383 * sensitive data that remains on this user, it is advised that the profile owner deletes it
5384 * instead of calling this method. See {@link #wipeData(int)}.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07005385 */
Esteban Talaveraa5b09632017-02-10 16:15:24 +00005386 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07005387 public void clearProfileOwner(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005388 throwIfParentInstance("clearProfileOwner");
Amith Yamasanibf3a9462014-07-28 14:26:42 -07005389 if (mService != null) {
5390 try {
5391 mService.clearProfileOwner(admin);
5392 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005393 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07005394 }
5395 }
5396 }
5397
5398 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05005399 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07005400 * Checks whether the user was already setup.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07005401 */
5402 public boolean hasUserSetupCompleted() {
5403 if (mService != null) {
5404 try {
5405 return mService.hasUserSetupCompleted();
5406 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005407 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07005408 }
5409 }
5410 return true;
5411 }
5412
5413 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07005414 * @hide
5415 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00005416 * already be installed. There must not already be a profile owner for this user.
5417 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
5418 * this method.
5419 * Calling this after the setup phase of the specified user has completed is allowed only if:
5420 * - the caller is SYSTEM_UID.
5421 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07005422 * @param admin the component name to be registered as profile owner.
5423 * @param ownerName the human readable name of the organisation associated with this DPM.
5424 * @param userHandle the userId to set the profile owner for.
5425 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00005426 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
5427 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07005428 */
Robin Lee25e26452015-06-02 09:56:29 -07005429 public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName,
Robin Leeddd553f2015-04-30 14:18:22 +01005430 int userHandle) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00005431 if (mService != null) {
5432 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07005433 if (ownerName == null) {
5434 ownerName = "";
5435 }
5436 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00005437 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005438 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00005439 }
5440 }
5441 return false;
5442 }
5443
5444 /**
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00005445 * Sets the device owner information to be shown on the lock screen.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005446 * <p>
5447 * If the device owner information is {@code null} or empty then the device owner info is
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00005448 * cleared and the user owner info is shown on the lock screen if it is set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005449 * <p>
5450 * If the device owner information contains only whitespaces then the message on the lock screen
5451 * will be blank and the user will not be allowed to change it.
5452 * <p>
5453 * If the device owner information needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00005454 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
5455 * and set a new version of this string accordingly.
5456 *
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00005457 * @param admin The name of the admin component to check.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005458 * @param info Device owner information which will be displayed instead of the user owner info.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005459 * @throws SecurityException if {@code admin} is not a device owner.
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00005460 */
Andrei Stingaceanu16187902016-03-21 15:44:45 +00005461 public void setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, CharSequence info) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005462 throwIfParentInstance("setDeviceOwnerLockScreenInfo");
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00005463 if (mService != null) {
5464 try {
Andrei Stingaceanu16187902016-03-21 15:44:45 +00005465 mService.setDeviceOwnerLockScreenInfo(admin, info);
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00005466 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005467 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00005468 }
5469 }
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00005470 }
5471
5472 /**
5473 * @return The device owner information. If it is not set returns {@code null}.
5474 */
Andrei Stingaceanu16187902016-03-21 15:44:45 +00005475 public CharSequence getDeviceOwnerLockScreenInfo() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005476 throwIfParentInstance("getDeviceOwnerLockScreenInfo");
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00005477 if (mService != null) {
5478 try {
5479 return mService.getDeviceOwnerLockScreenInfo();
5480 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005481 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00005482 }
5483 }
5484 return null;
5485 }
5486
5487 /**
Edman Anjos52088e42017-01-13 22:26:17 +01005488 * Called by device or profile owners to suspend packages for this user. This function can be
5489 * called by a device owner, profile owner, or by a delegate given the
5490 * {@link #DELEGATION_PACKAGE_ACCESS} scope via {@link #setDelegatedScopes}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005491 * <p>
5492 * A suspended package will not be able to start activities. Its notifications will be hidden,
5493 * it will not show up in recents, will not be able to show toasts or dialogs or ring the
5494 * device.
5495 * <p>
5496 * The package must already be installed. If the package is uninstalled while suspended the
5497 * package will no longer be suspended. The admin can block this by using
Kenny Guy871f3eb2016-03-09 20:06:16 +00005498 * {@link #setUninstallBlocked}.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00005499 *
Edman Anjos52088e42017-01-13 22:26:17 +01005500 * @param admin The name of the admin component to check, or {@code null} if the caller is a
5501 * package access delegate.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00005502 * @param packageNames The package names to suspend or unsuspend.
5503 * @param suspended If set to {@code true} than the packages will be suspended, if set to
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005504 * {@code false} the packages will be unsuspended.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00005505 * @return an array of package names for which the suspended status is not set as requested in
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005506 * this method.
5507 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01005508 * @see #setDelegatedScopes
5509 * @see #DELEGATION_PACKAGE_ACCESS
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00005510 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005511 public @NonNull String[] setPackagesSuspended(@NonNull ComponentName admin,
5512 @NonNull String[] packageNames, boolean suspended) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005513 throwIfParentInstance("setPackagesSuspended");
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00005514 if (mService != null) {
5515 try {
Edman Anjos52088e42017-01-13 22:26:17 +01005516 return mService.setPackagesSuspended(admin, mContext.getPackageName(), packageNames,
5517 suspended);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00005518 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005519 throw re.rethrowFromSystemServer();
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00005520 }
5521 }
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00005522 return packageNames;
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00005523 }
5524
5525 /**
Edman Anjos52088e42017-01-13 22:26:17 +01005526 * Determine if a package is suspended. This function can be called by a device owner, profile
5527 * owner, or by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via
5528 * {@link #setDelegatedScopes}.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00005529 *
Edman Anjos52088e42017-01-13 22:26:17 +01005530 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
5531 * {@code null} if the caller is a package access delegate.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00005532 * @param packageName The name of the package to retrieve the suspended status of.
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00005533 * @return {@code true} if the package is suspended or {@code false} if the package is not
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005534 * suspended, could not be found or an error occurred.
5535 * @throws SecurityException if {@code admin} is not a device or profile owner.
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00005536 * @throws NameNotFoundException if the package could not be found.
Edman Anjos52088e42017-01-13 22:26:17 +01005537 * @see #setDelegatedScopes
5538 * @see #DELEGATION_PACKAGE_ACCESS
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00005539 */
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00005540 public boolean isPackageSuspended(@NonNull ComponentName admin, String packageName)
5541 throws NameNotFoundException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005542 throwIfParentInstance("isPackageSuspended");
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00005543 if (mService != null) {
5544 try {
Edman Anjos52088e42017-01-13 22:26:17 +01005545 return mService.isPackageSuspended(admin, mContext.getPackageName(), packageName);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00005546 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005547 throw e.rethrowFromSystemServer();
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00005548 } catch (IllegalArgumentException ex) {
5549 throw new NameNotFoundException(packageName);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00005550 }
5551 }
5552 return false;
5553 }
5554
5555 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01005556 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
5557 * be used. Only the profile owner can call this.
5558 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01005559 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01005560 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005561 * @throws SecurityException if {@code admin} is not a profile owner.
Alexandra Gherghina512675b2014-04-02 11:23:54 +01005562 */
Robin Lee25e26452015-06-02 09:56:29 -07005563 public void setProfileEnabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005564 throwIfParentInstance("setProfileEnabled");
Alexandra Gherghina512675b2014-04-02 11:23:54 +01005565 if (mService != null) {
5566 try {
5567 mService.setProfileEnabled(admin);
5568 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005569 throw e.rethrowFromSystemServer();
Alexandra Gherghina512675b2014-04-02 11:23:54 +01005570 }
5571 }
5572 }
5573
5574 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005575 * Sets the name of the profile. In the device owner case it sets the name of the user which it
5576 * is called from. Only a profile owner or device owner can call this. If this is never called
5577 * by the profile or device owner, the name will be set to default values.
Jessica Hummel1333ea12014-06-23 11:20:10 +01005578 *
5579 * @see #isProfileOwnerApp
5580 * @see #isDeviceOwnerApp
Robin Lee25e26452015-06-02 09:56:29 -07005581 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01005582 * @param profileName The name of the profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005583 * @throws SecurityException if {@code admin} is not a device or profile owner.
Jessica Hummel1333ea12014-06-23 11:20:10 +01005584 */
Robin Lee25e26452015-06-02 09:56:29 -07005585 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005586 throwIfParentInstance("setProfileName");
Jessica Hummel1333ea12014-06-23 11:20:10 +01005587 if (mService != null) {
5588 try {
Robin Lee25e26452015-06-02 09:56:29 -07005589 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07005590 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005591 throw e.rethrowFromSystemServer();
Fyodor Kupolov78f13142015-05-27 16:52:45 -07005592 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01005593 }
5594 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01005595
5596 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005597 * Used to determine if a particular package is registered as the profile owner for the
Makoto Onuki32b30572015-12-11 14:29:51 -08005598 * user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005599 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00005600 *
5601 * @param packageName The package name of the app to compare with the registered profile owner.
5602 * @return Whether or not the package is registered as the profile owner.
5603 */
5604 public boolean isProfileOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005605 throwIfParentInstance("isProfileOwnerApp");
Adam Connors776c5552014-01-09 10:42:56 +00005606 if (mService != null) {
5607 try {
Makoto Onuki90b89652016-01-28 14:44:18 -08005608 ComponentName profileOwner = mService.getProfileOwner(myUserId());
Nicolas Prevot90af6d72014-07-30 14:19:12 +01005609 return profileOwner != null
5610 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00005611 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005612 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00005613 }
5614 }
5615 return false;
5616 }
5617
5618 /**
5619 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07005620 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00005621 * owner has been set for that user.
5622 * @throws IllegalArgumentException if the userId is invalid.
5623 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01005624 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07005625 public @Nullable ComponentName getProfileOwner() throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005626 throwIfParentInstance("getProfileOwner");
Jeff Sharkeyad357d12018-02-02 13:25:31 -07005627 return getProfileOwnerAsUser(mContext.getUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01005628 }
5629
5630 /**
5631 * @see #getProfileOwner()
5632 * @hide
5633 */
Mathew Inwood4fb17d12018-08-14 14:25:44 +01005634 @UnsupportedAppUsage
Makoto Onuki408e8e42016-10-25 12:10:27 -07005635 public @Nullable ComponentName getProfileOwnerAsUser(final int userId)
5636 throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00005637 if (mService != null) {
5638 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01005639 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00005640 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005641 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00005642 }
5643 }
5644 return null;
5645 }
5646
5647 /**
5648 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07005649 * @return the human readable name of the organisation associated with this DPM or {@code null}
5650 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00005651 * @throws IllegalArgumentException if the userId is invalid.
5652 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005653 public @Nullable String getProfileOwnerName() throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00005654 if (mService != null) {
5655 try {
Jeff Sharkeyad357d12018-02-02 13:25:31 -07005656 return mService.getProfileOwnerName(mContext.getUserId());
Adam Connors776c5552014-01-09 10:42:56 +00005657 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005658 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00005659 }
5660 }
5661 return null;
5662 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005663
5664 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07005665 * @hide
Makoto Onukic8a5a552015-11-19 14:29:12 -08005666 * @param userId The user for whom to fetch the profile owner name, if any.
Amith Yamasani38f836b2014-08-20 14:51:15 -07005667 * @return the human readable name of the organisation associated with this profile owner or
5668 * null if one is not set.
5669 * @throws IllegalArgumentException if the userId is invalid.
5670 */
5671 @SystemApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06005672 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Makoto Onuki408e8e42016-10-25 12:10:27 -07005673 public @Nullable String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005674 throwIfParentInstance("getProfileOwnerNameAsUser");
Amith Yamasani38f836b2014-08-20 14:51:15 -07005675 if (mService != null) {
5676 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02005677 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07005678 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005679 throw re.rethrowFromSystemServer();
Amith Yamasani38f836b2014-08-20 14:51:15 -07005680 }
5681 }
5682 return null;
5683 }
5684
5685 /**
Tony Mak329047b2018-02-28 14:17:17 +00005686 * Called by a profile owner or device owner to set a default activity that the system selects
5687 * to handle intents that match the given {@link IntentFilter}. This activity will remain the
5688 * default intent handler even if the set of potential event handlers for the intent filter
5689 * changes and if the intent preferences are reset.
5690 * <p>
5691 * Note that the caller should still declare the activity in the manifest, the API just sets
5692 * the activity to be the default one to handle the given intent filter.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005693 * <p>
5694 * The default disambiguation mechanism takes over if the activity is not installed (anymore).
5695 * When the activity is (re)installed, it is automatically reset as default intent handler for
5696 * the filter.
5697 * <p>
5698 * The calling device admin must be a profile owner or device owner. If it is not, a security
5699 * exception will be thrown.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005700 *
5701 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5702 * @param filter The IntentFilter for which a default handler is added.
5703 * @param activity The Activity that is added as default intent handler.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005704 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005705 */
Robin Lee25e26452015-06-02 09:56:29 -07005706 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
5707 @NonNull ComponentName activity) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005708 throwIfParentInstance("addPersistentPreferredActivity");
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005709 if (mService != null) {
5710 try {
5711 mService.addPersistentPreferredActivity(admin, filter, activity);
5712 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005713 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005714 }
5715 }
5716 }
5717
5718 /**
5719 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00005720 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005721 * <p>
5722 * The calling device admin must be a profile owner. If it is not, a security exception will be
5723 * thrown.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005724 *
5725 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5726 * @param packageName The name of the package for which preferences are removed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005727 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005728 */
Robin Lee25e26452015-06-02 09:56:29 -07005729 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005730 String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005731 throwIfParentInstance("clearPackagePersistentPreferredActivities");
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005732 if (mService != null) {
5733 try {
5734 mService.clearPackagePersistentPreferredActivities(admin, packageName);
5735 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005736 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005737 }
5738 }
5739 }
Robin Lee66e5d962014-04-09 16:44:21 +01005740
5741 /**
Christine Franks26449ed2018-02-22 16:19:26 -08005742 * Called by a device owner to set the default SMS application.
5743 * <p>
5744 * The calling device admin must be a device owner. If it is not, a security exception will be
5745 * thrown.
5746 *
5747 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5748 * @param packageName The name of the package to set as the default SMS application.
5749 * @throws SecurityException if {@code admin} is not a device owner.
5750 *
5751 * @hide
5752 */
Mathew Inwood4fb17d12018-08-14 14:25:44 +01005753 @UnsupportedAppUsage
Christine Franks26449ed2018-02-22 16:19:26 -08005754 public void setDefaultSmsApplication(@NonNull ComponentName admin, String packageName) {
5755 throwIfParentInstance("setDefaultSmsApplication");
5756 if (mService != null) {
5757 try {
5758 mService.setDefaultSmsApplication(admin, packageName);
5759 } catch (RemoteException e) {
5760 throw e.rethrowFromSystemServer();
5761 }
5762 }
5763 }
5764
5765 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00005766 * Called by a profile owner or device owner to grant permission to a package to manage
5767 * application restrictions for the calling user via {@link #setApplicationRestrictions} and
5768 * {@link #getApplicationRestrictions}.
5769 * <p>
5770 * This permission is persistent until it is later cleared by calling this method with a
5771 * {@code null} value or uninstalling the managing package.
Rubin Xuf03d0a62016-02-10 14:54:15 +00005772 * <p>
5773 * The supplied application restriction managing package must be installed when calling this
Victor Changcd14c0a2016-03-16 19:10:15 +00005774 * API, otherwise an {@link NameNotFoundException} will be thrown.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005775 *
5776 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5777 * @param packageName The package name which will be given access to application restrictions
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005778 * APIs. If {@code null} is given the current package will be cleared.
5779 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Changcd14c0a2016-03-16 19:10:15 +00005780 * @throws NameNotFoundException if {@code packageName} is not found
Edman Anjosf9946772016-11-28 16:35:15 +01005781 *
5782 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #setDelegatedScopes}
5783 * with the {@link #DELEGATION_APP_RESTRICTIONS} scope instead.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005784 */
Edman Anjosf9946772016-11-28 16:35:15 +01005785 @Deprecated
Esteban Talaverabf60f722015-12-10 16:26:44 +00005786 public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin,
Victor Changcd14c0a2016-03-16 19:10:15 +00005787 @Nullable String packageName) throws NameNotFoundException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005788 throwIfParentInstance("setApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00005789 if (mService != null) {
5790 try {
Victor Changcd14c0a2016-03-16 19:10:15 +00005791 if (!mService.setApplicationRestrictionsManagingPackage(admin, packageName)) {
5792 throw new NameNotFoundException(packageName);
5793 }
Esteban Talaverabf60f722015-12-10 16:26:44 +00005794 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005795 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00005796 }
5797 }
5798 }
5799
5800 /**
5801 * Called by a profile owner or device owner to retrieve the application restrictions managing
Edman Anjosf9946772016-11-28 16:35:15 +01005802 * package for the current user, or {@code null} if none is set. If there are multiple
5803 * delegates this function will return one of them.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005804 *
5805 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5806 * @return The package name allowed to manage application restrictions on the current user, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005807 * {@code null} if none is set.
5808 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01005809 *
5810 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatePackages}
5811 * with the {@link #DELEGATION_APP_RESTRICTIONS} scope instead.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005812 */
Edman Anjosf9946772016-11-28 16:35:15 +01005813 @Deprecated
5814 @Nullable
5815 public String getApplicationRestrictionsManagingPackage(
Makoto Onuki408e8e42016-10-25 12:10:27 -07005816 @NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005817 throwIfParentInstance("getApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00005818 if (mService != null) {
5819 try {
5820 return mService.getApplicationRestrictionsManagingPackage(admin);
5821 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005822 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00005823 }
5824 }
5825 return null;
5826 }
5827
5828 /**
Esteban Talavera96895ca2016-03-16 12:00:40 +00005829 * Called by any application to find out whether it has been granted permission via
5830 * {@link #setApplicationRestrictionsManagingPackage} to manage application restrictions
5831 * for the calling user.
5832 *
5833 * <p>This is done by comparing the calling Linux uid with the uid of the package specified by
5834 * that method.
Edman Anjosf9946772016-11-28 16:35:15 +01005835 *
5836 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatedScopes}
5837 * instead.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005838 */
Edman Anjosf9946772016-11-28 16:35:15 +01005839 @Deprecated
Esteban Talaverabf60f722015-12-10 16:26:44 +00005840 public boolean isCallerApplicationRestrictionsManagingPackage() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005841 throwIfParentInstance("isCallerApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00005842 if (mService != null) {
5843 try {
Edman Anjosf9946772016-11-28 16:35:15 +01005844 return mService.isCallerApplicationRestrictionsManagingPackage(
5845 mContext.getPackageName());
Esteban Talaverabf60f722015-12-10 16:26:44 +00005846 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005847 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00005848 }
5849 }
5850 return false;
5851 }
5852
5853 /**
5854 * Sets the application restrictions for a given target application running in the calling user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005855 * <p>
5856 * 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 +01005857 * application restrictions via {@link #setDelegatedScopes} with the
5858 * {@link #DELEGATION_APP_RESTRICTIONS} scope; otherwise a security exception will be thrown.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005859 * <p>
5860 * The provided {@link Bundle} consists of key-value pairs, where the types of values may be:
Esteban Talavera6b8e0642015-08-10 17:26:04 +01005861 * <ul>
5862 * <li>{@code boolean}
5863 * <li>{@code int}
5864 * <li>{@code String} or {@code String[]}
5865 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
5866 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005867 * <p>
5868 * If the restrictions are not available yet, but may be applied in the near future, the caller
5869 * can notify the target application of that by adding
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00005870 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005871 * <p>
5872 * The application restrictions are only made visible to the target application via
5873 * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or device
5874 * owner, and the application restrictions managing package via
Esteban Talaverabf60f722015-12-10 16:26:44 +00005875 * {@link #getApplicationRestrictions}.
Robin Lee66e5d962014-04-09 16:44:21 +01005876 *
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005877 * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
5878 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00005879 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005880 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01005881 * @param packageName The name of the package to update restricted settings for.
5882 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005883 * set of active restrictions.
5884 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01005885 * @see #setDelegatedScopes
5886 * @see #DELEGATION_APP_RESTRICTIONS
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00005887 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01005888 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005889 @WorkerThread
Esteban Talaverabf60f722015-12-10 16:26:44 +00005890 public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01005891 Bundle settings) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005892 throwIfParentInstance("setApplicationRestrictions");
Robin Lee66e5d962014-04-09 16:44:21 +01005893 if (mService != null) {
5894 try {
Edman Anjosf9946772016-11-28 16:35:15 +01005895 mService.setApplicationRestrictions(admin, mContext.getPackageName(), packageName,
5896 settings);
Robin Lee66e5d962014-04-09 16:44:21 +01005897 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005898 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01005899 }
5900 }
5901 }
5902
5903 /**
Rubin Xu50ac2412018-03-02 15:25:28 +00005904 * Sets a list of configuration features to enable for a trust agent component. This is meant to
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005905 * be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all trust
5906 * agents but those enabled by this function call. If flag
Jim Millere303bf42014-08-26 17:12:29 -07005907 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005908 * <p>
Rubin Xu50ac2412018-03-02 15:25:28 +00005909 * For any specific trust agent, whether it is disabled or not depends on the aggregated state
5910 * of each admin's {@link #KEYGUARD_DISABLE_TRUST_AGENTS} setting and its trust agent
5911 * configuration as set by this function call. In particular: if any admin sets
5912 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} and does not additionally set any
5913 * trust agent configuration, the trust agent is disabled completely. Otherwise, the trust agent
5914 * will receive the list of configurations from all admins who set
5915 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} and aggregate the configurations to determine its
5916 * behavior. The exact meaning of aggregation is trust-agent-specific.
5917 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005918 * The calling device admin must have requested
5919 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method;
5920 * if not, a security exception will be thrown.
Tony Mak089d8402016-04-05 17:42:55 +01005921 * <p>
5922 * This method can be called on the {@link DevicePolicyManager} instance returned by
5923 * {@link #getParentProfileInstance(ComponentName)} in order to set the configuration for
5924 * the parent profile.
Jim Miller604e7552014-07-18 19:00:02 -07005925 *
5926 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xu50ac2412018-03-02 15:25:28 +00005927 * @param target Component name of the agent to be configured.
5928 * @param configuration Trust-agent-specific feature configuration bundle. Please consult
5929 * documentation of the specific trust agent to determine the interpretation of this
5930 * bundle.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005931 * @throws SecurityException if {@code admin} is not an active administrator or does not use
5932 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES}
Jim Miller604e7552014-07-18 19:00:02 -07005933 */
Robin Lee25e26452015-06-02 09:56:29 -07005934 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
5935 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07005936 if (mService != null) {
5937 try {
Tony Mak089d8402016-04-05 17:42:55 +01005938 mService.setTrustAgentConfiguration(admin, target, configuration, mParentInstance);
Jim Miller604e7552014-07-18 19:00:02 -07005939 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005940 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07005941 }
5942 }
5943 }
5944
5945 /**
Jim Millere303bf42014-08-26 17:12:29 -07005946 * Gets configuration for the given trust agent based on aggregating all calls to
5947 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
5948 * all device admins.
Tony Mak089d8402016-04-05 17:42:55 +01005949 * <p>
5950 * This method can be called on the {@link DevicePolicyManager} instance returned by
5951 * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the configuration set
5952 * on the parent profile.
Jim Miller604e7552014-07-18 19:00:02 -07005953 *
Jim Millerb5db57a2015-01-14 18:17:19 -08005954 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
5955 * this function returns a list of configurations for all admins that declare
5956 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
5957 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
5958 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
5959 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07005960 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07005961 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07005962 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005963 public @Nullable List<PersistableBundle> getTrustAgentConfiguration(
5964 @Nullable ComponentName admin, @NonNull ComponentName agent) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07005965 return getTrustAgentConfiguration(admin, agent, myUserId());
Jim Millere303bf42014-08-26 17:12:29 -07005966 }
5967
5968 /** @hide per-user version */
Mathew Inwood4fb17d12018-08-14 14:25:44 +01005969 @UnsupportedAppUsage
Makoto Onuki408e8e42016-10-25 12:10:27 -07005970 public @Nullable List<PersistableBundle> getTrustAgentConfiguration(
5971 @Nullable ComponentName admin, @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07005972 if (mService != null) {
5973 try {
Tony Mak089d8402016-04-05 17:42:55 +01005974 return mService.getTrustAgentConfiguration(admin, agent, userHandle,
5975 mParentInstance);
Jim Miller604e7552014-07-18 19:00:02 -07005976 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005977 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07005978 }
5979 }
Jim Millere303bf42014-08-26 17:12:29 -07005980 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07005981 }
5982
5983 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005984 * Called by a profile owner of a managed profile to set whether caller-Id information from the
5985 * managed profile will be shown in the parent profile, for incoming calls.
5986 * <p>
5987 * The calling device admin must be a profile owner. If it is not, a security exception will be
5988 * thrown.
Adam Connors210fe212014-07-17 15:41:43 +01005989 *
Robin Lee25e26452015-06-02 09:56:29 -07005990 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01005991 * @param disabled If true caller-Id information in the managed profile is not displayed.
Tony Mak329047b2018-02-28 14:17:17 +00005992 * @throws SecurityException if {@code admin} is not a profile owner.
Adam Connors210fe212014-07-17 15:41:43 +01005993 */
Robin Lee25e26452015-06-02 09:56:29 -07005994 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005995 throwIfParentInstance("setCrossProfileCallerIdDisabled");
Adam Connors210fe212014-07-17 15:41:43 +01005996 if (mService != null) {
5997 try {
Robin Lee25e26452015-06-02 09:56:29 -07005998 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01005999 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006000 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01006001 }
6002 }
6003 }
6004
6005 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07006006 * Called by a profile owner of a managed profile to determine whether or not caller-Id
6007 * information has been disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006008 * <p>
6009 * The calling device admin must be a profile owner. If it is not, a security exception will be
6010 * thrown.
Adam Connors210fe212014-07-17 15:41:43 +01006011 *
Robin Lee25e26452015-06-02 09:56:29 -07006012 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Tony Mak329047b2018-02-28 14:17:17 +00006013 * @throws SecurityException if {@code admin} is not a profile owner.
Adam Connors210fe212014-07-17 15:41:43 +01006014 */
Robin Lee25e26452015-06-02 09:56:29 -07006015 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006016 throwIfParentInstance("getCrossProfileCallerIdDisabled");
Adam Connors210fe212014-07-17 15:41:43 +01006017 if (mService != null) {
6018 try {
Robin Lee25e26452015-06-02 09:56:29 -07006019 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01006020 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006021 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01006022 }
6023 }
6024 return false;
6025 }
6026
6027 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07006028 * Determine whether or not caller-Id information has been disabled.
6029 *
6030 * @param userHandle The user for whom to check the caller-id permission
6031 * @hide
6032 */
6033 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
6034 if (mService != null) {
6035 try {
6036 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
6037 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006038 throw e.rethrowFromSystemServer();
Amith Yamasani570002f2014-07-18 15:48:54 -07006039 }
6040 }
6041 return false;
6042 }
6043
6044 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006045 * Called by a profile owner of a managed profile to set whether contacts search from the
6046 * managed profile will be shown in the parent profile, for incoming calls.
6047 * <p>
6048 * The calling device admin must be a profile owner. If it is not, a security exception will be
6049 * thrown.
Victor Chang1060c6182016-01-04 20:16:23 +00006050 *
6051 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6052 * @param disabled If true contacts search in the managed profile is not displayed.
Tony Mak329047b2018-02-28 14:17:17 +00006053 * @throws SecurityException if {@code admin} is not a profile owner.
Victor Chang1060c6182016-01-04 20:16:23 +00006054 */
6055 public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin,
6056 boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006057 throwIfParentInstance("setCrossProfileContactsSearchDisabled");
Victor Chang1060c6182016-01-04 20:16:23 +00006058 if (mService != null) {
6059 try {
6060 mService.setCrossProfileContactsSearchDisabled(admin, disabled);
6061 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006062 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00006063 }
6064 }
6065 }
6066
6067 /**
6068 * Called by a profile owner of a managed profile to determine whether or not contacts search
6069 * has been disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006070 * <p>
6071 * The calling device admin must be a profile owner. If it is not, a security exception will be
6072 * thrown.
Victor Chang1060c6182016-01-04 20:16:23 +00006073 *
6074 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Tony Mak329047b2018-02-28 14:17:17 +00006075 * @throws SecurityException if {@code admin} is not a profile owner.
Victor Chang1060c6182016-01-04 20:16:23 +00006076 */
6077 public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006078 throwIfParentInstance("getCrossProfileContactsSearchDisabled");
Victor Chang1060c6182016-01-04 20:16:23 +00006079 if (mService != null) {
6080 try {
6081 return mService.getCrossProfileContactsSearchDisabled(admin);
6082 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006083 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00006084 }
6085 }
6086 return false;
6087 }
6088
6089
6090 /**
6091 * Determine whether or not contacts search has been disabled.
6092 *
6093 * @param userHandle The user for whom to check the contacts search permission
6094 * @hide
6095 */
6096 public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) {
6097 if (mService != null) {
6098 try {
6099 return mService
6100 .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier());
6101 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006102 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00006103 }
6104 }
6105 return false;
6106 }
6107
6108 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08006109 * Start Quick Contact on the managed profile for the user, if the policy allows.
Victor Chang97bdacc2016-01-21 22:24:11 +00006110 *
Makoto Onuki1040da12015-03-19 11:24:00 -07006111 * @hide
6112 */
6113 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
Victor Chang97bdacc2016-01-21 22:24:11 +00006114 boolean isContactIdIgnored, long directoryId, Intent originalIntent) {
Makoto Onuki1040da12015-03-19 11:24:00 -07006115 if (mService != null) {
6116 try {
Victor Chang97bdacc2016-01-21 22:24:11 +00006117 mService.startManagedQuickContact(actualLookupKey, actualContactId,
6118 isContactIdIgnored, directoryId, originalIntent);
Makoto Onuki1040da12015-03-19 11:24:00 -07006119 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006120 throw e.rethrowFromSystemServer();
Makoto Onuki1040da12015-03-19 11:24:00 -07006121 }
6122 }
6123 }
6124
6125 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08006126 * Start Quick Contact on the managed profile for the user, if the policy allows.
Ricky Wai494b95d2015-11-20 16:07:15 +00006127 * @hide
6128 */
6129 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
6130 Intent originalIntent) {
Victor Chang97bdacc2016-01-21 22:24:11 +00006131 startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT,
Ricky Wai494b95d2015-11-20 16:07:15 +00006132 originalIntent);
6133 }
6134
6135 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006136 * Called by a profile owner of a managed profile to set whether bluetooth devices can access
6137 * enterprise contacts.
Ricky Wai778ba132015-03-31 14:21:22 +01006138 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006139 * The calling device admin must be a profile owner. If it is not, a security exception will be
6140 * thrown.
Ricky Wai778ba132015-03-31 14:21:22 +01006141 * <p>
6142 * This API works on managed profile only.
6143 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006144 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6145 * @param disabled If true, bluetooth devices cannot access enterprise contacts.
Tony Mak329047b2018-02-28 14:17:17 +00006146 * @throws SecurityException if {@code admin} is not a profile owner.
Ricky Wai778ba132015-03-31 14:21:22 +01006147 */
Robin Lee25e26452015-06-02 09:56:29 -07006148 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006149 throwIfParentInstance("setBluetoothContactSharingDisabled");
Ricky Wai778ba132015-03-31 14:21:22 +01006150 if (mService != null) {
6151 try {
Robin Lee25e26452015-06-02 09:56:29 -07006152 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01006153 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006154 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01006155 }
6156 }
6157 }
6158
6159 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006160 * Called by a profile owner of a managed profile to determine whether or not Bluetooth devices
6161 * cannot access enterprise contacts.
Ricky Wai778ba132015-03-31 14:21:22 +01006162 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006163 * The calling device admin must be a profile owner. If it is not, a security exception will be
6164 * thrown.
Ricky Wai778ba132015-03-31 14:21:22 +01006165 * <p>
6166 * This API works on managed profile only.
6167 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006168 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Tony Mak329047b2018-02-28 14:17:17 +00006169 * @throws SecurityException if {@code admin} is not a profile owner.
Ricky Wai778ba132015-03-31 14:21:22 +01006170 */
Robin Lee25e26452015-06-02 09:56:29 -07006171 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006172 throwIfParentInstance("getBluetoothContactSharingDisabled");
Ricky Wai778ba132015-03-31 14:21:22 +01006173 if (mService != null) {
6174 try {
Robin Lee25e26452015-06-02 09:56:29 -07006175 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01006176 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006177 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01006178 }
6179 }
6180 return true;
6181 }
6182
6183 /**
6184 * Determine whether or not Bluetooth devices cannot access contacts.
6185 * <p>
6186 * This API works on managed profile UserHandle only.
6187 *
6188 * @param userHandle The user for whom to check the caller-id permission
6189 * @hide
6190 */
6191 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
6192 if (mService != null) {
6193 try {
6194 return mService.getBluetoothContactSharingDisabledForUser(userHandle
6195 .getIdentifier());
6196 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006197 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01006198 }
6199 }
6200 return true;
6201 }
6202
6203 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07006204 * Called by the profile owner of a managed profile so that some intents sent in the managed
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006205 * profile can also be resolved in the parent, or vice versa. Only activity intents are
6206 * supported.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00006207 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00006208 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01006209 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006210 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01006211 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006212 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
6213 * @throws SecurityException if {@code admin} is not a device or profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00006214 */
Robin Lee25e26452015-06-02 09:56:29 -07006215 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006216 throwIfParentInstance("addCrossProfileIntentFilter");
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00006217 if (mService != null) {
6218 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01006219 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00006220 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006221 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00006222 }
6223 }
6224 }
6225
6226 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07006227 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
6228 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01006229 * Only removes those that have been set by the profile owner.
Rubin Xucc391c22018-01-02 20:37:35 +00006230 * <p>
6231 * <em>Note</em>: A list of default cross profile intent filters are set up by the system when
6232 * the profile is created, some of them ensure the proper functioning of the profile, while
6233 * others enable sharing of data from the parent to the managed profile for user convenience.
6234 * These default intent filters are not cleared when this API is called. If the default cross
6235 * profile data sharing is not desired, they can be disabled with
6236 * {@link UserManager#DISALLOW_SHARE_INTO_MANAGED_PROFILE}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006237 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00006238 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Tony Mak329047b2018-02-28 14:17:17 +00006239 * @throws SecurityException if {@code admin} is not a profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00006240 */
Robin Lee25e26452015-06-02 09:56:29 -07006241 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006242 throwIfParentInstance("clearCrossProfileIntentFilters");
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00006243 if (mService != null) {
6244 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01006245 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00006246 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006247 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00006248 }
6249 }
6250 }
6251
6252 /**
Tony Mak329047b2018-02-28 14:17:17 +00006253 * Called by a profile or device owner to set the permitted
6254 * {@link android.accessibilityservice.AccessibilityService}. When set by
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006255 * a device owner or profile owner the restriction applies to all profiles of the user the
Tony Mak329047b2018-02-28 14:17:17 +00006256 * device owner or profile owner is an admin for. By default, the user can use any accessibility
6257 * service. When zero or more packages have been added, accessibility services that are not in
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006258 * the list and not part of the system can not be enabled by the user.
6259 * <p>
6260 * Calling with a null value for the list disables the restriction so that all services can be
Tony Mak329047b2018-02-28 14:17:17 +00006261 * used, calling with an empty list only allows the built-in system services. Any non-system
6262 * accessibility service that's currently enabled must be included in the list.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006263 * <p>
Esteban Talavera7e4cbad2017-03-30 17:59:50 +01006264 * System accessibility services are always available to the user the list can't modify this.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006265 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6266 * @param packageNames List of accessibility service package names.
Tony Mak329047b2018-02-28 14:17:17 +00006267 * @return {@code true} if the operation succeeded, or {@code false} if the list didn't
6268 * contain every enabled non-system accessibility service.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006269 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006270 */
Robin Lee25e26452015-06-02 09:56:29 -07006271 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006272 List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006273 throwIfParentInstance("setPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006274 if (mService != null) {
6275 try {
6276 return mService.setPermittedAccessibilityServices(admin, packageNames);
6277 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006278 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006279 }
6280 }
6281 return false;
6282 }
6283
6284 /**
6285 * Returns the list of permitted accessibility services set by this device or profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006286 * <p>
6287 * An empty list means no accessibility services except system services are allowed. Null means
6288 * all accessibility services are allowed.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006289 *
6290 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6291 * @return List of accessiblity service package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006292 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006293 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006294 public @Nullable List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006295 throwIfParentInstance("getPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006296 if (mService != null) {
6297 try {
6298 return mService.getPermittedAccessibilityServices(admin);
6299 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006300 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006301 }
6302 }
6303 return null;
6304 }
6305
6306 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00006307 * Called by the system to check if a specific accessibility service is disabled by admin.
6308 *
6309 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6310 * @param packageName Accessibility service package name that needs to be checked.
6311 * @param userHandle user id the admin is running as.
6312 * @return true if the accessibility service is permitted, otherwise false.
6313 *
6314 * @hide
6315 */
6316 public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin,
6317 @NonNull String packageName, int userHandle) {
6318 if (mService != null) {
6319 try {
6320 return mService.isAccessibilityServicePermittedByAdmin(admin, packageName,
6321 userHandle);
6322 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006323 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00006324 }
6325 }
6326 return false;
6327 }
6328
6329 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006330 * Returns the list of accessibility services permitted by the device or profiles
6331 * owners of this user.
6332 *
6333 * <p>Null means all accessibility services are allowed, if a non-null list is returned
6334 * it will contain the intersection of the permitted lists for any device or profile
6335 * owners that apply to this user. It will also include any system accessibility services.
6336 *
6337 * @param userId which user to check for.
6338 * @return List of accessiblity service package names.
6339 * @hide
6340 */
6341 @SystemApi
Eric Sandness5ab98de2018-04-03 18:12:39 +01006342 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Makoto Onuki408e8e42016-10-25 12:10:27 -07006343 public @Nullable List<String> getPermittedAccessibilityServices(int userId) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006344 throwIfParentInstance("getPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006345 if (mService != null) {
6346 try {
6347 return mService.getPermittedAccessibilityServicesForUser(userId);
6348 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006349 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006350 }
6351 }
6352 return null;
6353 }
6354
6355 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006356 * Called by a profile or device owner to set the permitted input methods services. When set by
6357 * a device owner or profile owner the restriction applies to all profiles of the user the
Tony Mak329047b2018-02-28 14:17:17 +00006358 * device owner or profile owner is an admin for. By default, the user can use any input method.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006359 * When zero or more packages have been added, input method that are not in the list and not
6360 * part of the system can not be enabled by the user. This method will fail if it is called for
Tony Mak329047b2018-02-28 14:17:17 +00006361 * a admin that is not for the foreground user or a profile of the foreground user. Any
6362 * non-system input method service that's currently enabled must be included in the list.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006363 * <p>
6364 * Calling with a null value for the list disables the restriction so that all input methods can
6365 * be used, calling with an empty list disables all but the system's own input methods.
6366 * <p>
6367 * System input methods are always available to the user this method can't modify this.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006368 *
6369 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6370 * @param packageNames List of input method package names.
Tony Mak329047b2018-02-28 14:17:17 +00006371 * @return {@code true} if the operation succeeded, or {@code false} if the list didn't
6372 * contain every enabled non-system input method service.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006373 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006374 */
Esteban Talavera7e4cbad2017-03-30 17:59:50 +01006375 public boolean setPermittedInputMethods(
6376 @NonNull ComponentName admin, List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006377 throwIfParentInstance("setPermittedInputMethods");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006378 if (mService != null) {
6379 try {
6380 return mService.setPermittedInputMethods(admin, packageNames);
6381 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006382 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006383 }
6384 }
6385 return false;
6386 }
6387
6388
6389 /**
6390 * Returns the list of permitted input methods set by this device or profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006391 * <p>
6392 * An empty list means no input methods except system input methods are allowed. Null means all
6393 * input methods are allowed.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006394 *
6395 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6396 * @return List of input method package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006397 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006398 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006399 public @Nullable List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006400 throwIfParentInstance("getPermittedInputMethods");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006401 if (mService != null) {
6402 try {
6403 return mService.getPermittedInputMethods(admin);
6404 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006405 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006406 }
6407 }
6408 return null;
6409 }
6410
6411 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00006412 * Called by the system to check if a specific input method is disabled by admin.
6413 *
6414 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6415 * @param packageName Input method package name that needs to be checked.
6416 * @param userHandle user id the admin is running as.
6417 * @return true if the input method is permitted, otherwise false.
6418 *
6419 * @hide
6420 */
6421 public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin,
6422 @NonNull String packageName, int userHandle) {
6423 if (mService != null) {
6424 try {
6425 return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle);
6426 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006427 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00006428 }
6429 }
6430 return false;
6431 }
6432
6433 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006434 * Returns the list of input methods permitted by the device or profiles
Makoto Onuki32b30572015-12-11 14:29:51 -08006435 * owners of the current user. (*Not* calling user, due to a limitation in InputMethodManager.)
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006436 *
6437 * <p>Null means all input methods are allowed, if a non-null list is returned
6438 * it will contain the intersection of the permitted lists for any device or profile
6439 * owners that apply to this user. It will also include any system input methods.
6440 *
6441 * @return List of input method package names.
6442 * @hide
6443 */
6444 @SystemApi
Eric Sandness57378932018-03-27 13:22:52 +01006445 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Makoto Onuki408e8e42016-10-25 12:10:27 -07006446 public @Nullable List<String> getPermittedInputMethodsForCurrentUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006447 throwIfParentInstance("getPermittedInputMethodsForCurrentUser");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006448 if (mService != null) {
6449 try {
6450 return mService.getPermittedInputMethodsForCurrentUser();
6451 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006452 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006453 }
6454 }
6455 return null;
6456 }
6457
6458 /**
Esteban Talavera7e4cbad2017-03-30 17:59:50 +01006459 * Called by a profile owner of a managed profile to set the packages that are allowed to use
6460 * a {@link android.service.notification.NotificationListenerService} in the primary user to
6461 * see notifications from the managed profile. By default all packages are permitted by this
6462 * policy. When zero or more packages have been added, notification listeners installed on the
6463 * primary user that are not in the list and are not part of the system won't receive events
6464 * for managed profile notifications.
6465 * <p>
6466 * Calling with a {@code null} value for the list disables the restriction so that all
6467 * notification listener services be used. Calling with an empty list disables all but the
6468 * system's own notification listeners. System notification listener services are always
6469 * available to the user.
6470 * <p>
6471 * If a device or profile owner want to stop notification listeners in their user from seeing
6472 * that user's notifications they should prevent that service from running instead (e.g. via
6473 * {@link #setApplicationHidden(ComponentName, String, boolean)})
6474 *
6475 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6476 * @param packageList List of package names to whitelist
6477 * @return true if setting the restriction succeeded. It will fail if called outside a managed
6478 * profile
6479 * @throws SecurityException if {@code admin} is not a profile owner.
6480 *
6481 * @see android.service.notification.NotificationListenerService
6482 */
6483 public boolean setPermittedCrossProfileNotificationListeners(
6484 @NonNull ComponentName admin, @Nullable List<String> packageList) {
6485 throwIfParentInstance("setPermittedCrossProfileNotificationListeners");
6486 if (mService != null) {
6487 try {
6488 return mService.setPermittedCrossProfileNotificationListeners(admin, packageList);
6489 } catch (RemoteException e) {
6490 throw e.rethrowFromSystemServer();
6491 }
6492 }
6493 return false;
6494 }
6495
6496 /**
6497 * Returns the list of packages installed on the primary user that allowed to use a
6498 * {@link android.service.notification.NotificationListenerService} to receive
6499 * notifications from this managed profile, as set by the profile owner.
6500 * <p>
6501 * An empty list means no notification listener services except system ones are allowed.
6502 * A {@code null} return value indicates that all notification listeners are allowed.
6503 */
6504 public @Nullable List<String> getPermittedCrossProfileNotificationListeners(
6505 @NonNull ComponentName admin) {
6506 throwIfParentInstance("getPermittedCrossProfileNotificationListeners");
6507 if (mService != null) {
6508 try {
6509 return mService.getPermittedCrossProfileNotificationListeners(admin);
6510 } catch (RemoteException e) {
6511 throw e.rethrowFromSystemServer();
6512 }
6513 }
6514 return null;
6515 }
6516
6517 /**
6518 * Returns true if {@code NotificationListenerServices} from the given package are allowed to
6519 * receive events for notifications from the given user id. Can only be called by the system uid
6520 *
6521 * @see #setPermittedCrossProfileNotificationListeners(ComponentName, List)
6522 *
6523 * @hide
6524 */
6525 public boolean isNotificationListenerServicePermitted(
6526 @NonNull String packageName, @UserIdInt int userId) {
6527 if (mService != null) {
6528 try {
6529 return mService.isNotificationListenerServicePermitted(packageName, userId);
6530 } catch (RemoteException e) {
6531 throw e.rethrowFromSystemServer();
6532 }
6533 }
6534 return true;
6535 }
6536
6537 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006538 * Get the list of apps to keep around as APKs even if no user has currently installed it. This
6539 * function can be called by a device owner or by a delegate given the
6540 * {@link #DELEGATION_KEEP_UNINSTALLED_PACKAGES} scope via {@link #setDelegatedScopes}.
6541 * <p>
6542 * Please note that packages returned in this method are not automatically pre-cached.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08006543 *
Edman Anjos52088e42017-01-13 22:26:17 +01006544 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
6545 * {@code null} if the caller is a keep uninstalled packages delegate.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08006546 * @return List of package names to keep cached.
Edman Anjos52088e42017-01-13 22:26:17 +01006547 * @see #setDelegatedScopes
6548 * @see #DELEGATION_KEEP_UNINSTALLED_PACKAGES
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08006549 */
Edman Anjos52088e42017-01-13 22:26:17 +01006550 public @Nullable List<String> getKeepUninstalledPackages(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006551 throwIfParentInstance("getKeepUninstalledPackages");
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08006552 if (mService != null) {
6553 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006554 return mService.getKeepUninstalledPackages(admin, mContext.getPackageName());
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08006555 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006556 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08006557 }
6558 }
6559 return null;
6560 }
6561
6562 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006563 * Set a list of apps to keep around as APKs even if no user has currently installed it. This
6564 * function can be called by a device owner or by a delegate given the
6565 * {@link #DELEGATION_KEEP_UNINSTALLED_PACKAGES} scope via {@link #setDelegatedScopes}.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08006566 *
6567 * <p>Please note that setting this policy does not imply that specified apps will be
6568 * automatically pre-cached.</p>
6569 *
Edman Anjos52088e42017-01-13 22:26:17 +01006570 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
6571 * {@code null} if the caller is a keep uninstalled packages delegate.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08006572 * @param packageNames List of package names to keep cached.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006573 * @throws SecurityException if {@code admin} is not a device owner.
Edman Anjos52088e42017-01-13 22:26:17 +01006574 * @see #setDelegatedScopes
6575 * @see #DELEGATION_KEEP_UNINSTALLED_PACKAGES
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08006576 */
Edman Anjos52088e42017-01-13 22:26:17 +01006577 public void setKeepUninstalledPackages(@Nullable ComponentName admin,
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08006578 @NonNull List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006579 throwIfParentInstance("setKeepUninstalledPackages");
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08006580 if (mService != null) {
6581 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006582 mService.setKeepUninstalledPackages(admin, mContext.getPackageName(), packageNames);
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08006583 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006584 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08006585 }
6586 }
6587 }
6588
6589 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04006590 * Called by a device owner to create a user with the specified name. The UserHandle returned
6591 * by this method should not be persisted as user handles are recycled as users are removed and
6592 * created. If you need to persist an identifier for this user, use
6593 * {@link UserManager#getSerialNumberForUser}.
6594 *
6595 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6596 * @param name the user's name
6597 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07006598 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
6599 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01006600 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07006601 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01006602 * @removed From {@link android.os.Build.VERSION_CODES#N}
Julia Reynolds1e958392014-05-16 14:25:21 -04006603 */
Kenny Guy14f48e52015-06-29 15:12:36 +01006604 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07006605 public @Nullable UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04006606 return null;
6607 }
6608
6609 /**
Jason Monk03978a42014-06-10 15:05:30 -04006610 * Called by a device owner to create a user with the specified name. The UserHandle returned
6611 * by this method should not be persisted as user handles are recycled as users are removed and
6612 * created. If you need to persist an identifier for this user, use
6613 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
6614 * immediately.
6615 *
6616 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
6617 * as registered as an active admin on the new user. The profile owner package will be
6618 * installed on the new user if it already is installed on the device.
6619 *
6620 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
6621 * profileOwnerComponent when onEnable is called.
6622 *
6623 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6624 * @param name the user's name
6625 * @param ownerName the human readable name of the organisation associated with this DPM.
6626 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
6627 * the user.
6628 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
6629 * on the new user.
6630 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07006631 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
6632 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01006633 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07006634 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01006635 * @removed From {@link android.os.Build.VERSION_CODES#N}
Jason Monk03978a42014-06-10 15:05:30 -04006636 */
Kenny Guy14f48e52015-06-29 15:12:36 +01006637 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07006638 public @Nullable UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
Robin Lee25e26452015-06-02 09:56:29 -07006639 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04006640 return null;
6641 }
6642
6643 /**
phweissa92e1212016-01-25 17:14:10 +01006644 * Flag used by {@link #createAndManageUser} to skip setup wizard after creating a new user.
phweiss343fb332016-01-25 14:48:59 +01006645 */
6646 public static final int SKIP_SETUP_WIZARD = 0x0001;
6647
6648 /**
Lenka Trochtovac8202c82016-01-26 15:11:09 +01006649 * Flag used by {@link #createAndManageUser} to specify that the user should be created
Alex Chau6badae62017-10-27 17:46:16 +01006650 * ephemeral. Ephemeral users will be removed after switching to another user or rebooting the
6651 * device.
Lenka Trochtovac8202c82016-01-26 15:11:09 +01006652 */
6653 public static final int MAKE_USER_EPHEMERAL = 0x0002;
6654
6655 /**
Christine Franks361b8252017-06-23 18:12:46 -07006656 * Flag used by {@link #createAndManageUser} to specify that the user should be created as a
6657 * demo user.
6658 * @hide
6659 */
6660 public static final int MAKE_USER_DEMO = 0x0004;
6661
6662 /**
Alex Chaub6a9f942017-11-07 11:28:56 +08006663 * Flag used by {@link #createAndManageUser} to specify that the newly created user should skip
6664 * the disabling of system apps during provisioning.
6665 */
6666 public static final int LEAVE_ALL_SYSTEM_APPS_ENABLED = 0x0010;
6667
6668 /**
Benjamin Franz77c94a92017-08-09 14:16:03 +01006669 * @hide
6670 */
Jeff Sharkeyce8db992017-12-13 20:05:05 -07006671 @IntDef(flag = true, prefix = { "SKIP_", "MAKE_USER_", "START_", "LEAVE_" }, value = {
6672 SKIP_SETUP_WIZARD,
6673 MAKE_USER_EPHEMERAL,
6674 MAKE_USER_DEMO,
Jeff Sharkeyce8db992017-12-13 20:05:05 -07006675 LEAVE_ALL_SYSTEM_APPS_ENABLED
6676 })
Benjamin Franz77c94a92017-08-09 14:16:03 +01006677 @Retention(RetentionPolicy.SOURCE)
6678 public @interface CreateAndManageUserFlags {}
6679
6680
6681 /**
phweissa92e1212016-01-25 17:14:10 +01006682 * Called by a device owner to create a user with the specified name and a given component of
6683 * the calling package as profile owner. The UserHandle returned by this method should not be
6684 * persisted as user handles are recycled as users are removed and created. If you need to
6685 * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new
6686 * user will not be started in the background.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006687 * <p>
6688 * admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also a
6689 * DeviceAdminReceiver in the same package as admin, and will become the profile owner and will
6690 * be registered as an active admin on the new user. The profile owner package will be installed
6691 * on the new user.
6692 * <p>
6693 * If the adminExtras are not null, they will be stored on the device until the user is started
6694 * for the first time. Then the extras will be passed to the admin when onEnable is called.
Alex Chau89386ba2018-02-13 11:09:17 +08006695 * <p>From {@link android.os.Build.VERSION_CODES#P} onwards, if targeting
6696 * {@link android.os.Build.VERSION_CODES#P}, throws {@link UserOperationException} instead of
6697 * returning {@code null} on failure.
phweiss343fb332016-01-25 14:48:59 +01006698 *
6699 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6700 * @param name The user's name.
phweissa92e1212016-01-25 17:14:10 +01006701 * @param profileOwner Which {@link DeviceAdminReceiver} will be profile owner. Has to be in the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006702 * same package as admin, otherwise no user is created and an
6703 * IllegalArgumentException is thrown.
phweiss343fb332016-01-25 14:48:59 +01006704 * @param adminExtras Extras that will be passed to onEnable of the admin receiver on the new
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006705 * user.
Alex Chaub6ef8692018-01-09 14:16:36 +00006706 * @param flags {@link #SKIP_SETUP_WIZARD}, {@link #MAKE_USER_EPHEMERAL} and
6707 * {@link #LEAVE_ALL_SYSTEM_APPS_ENABLED} are supported.
phweiss343fb332016-01-25 14:48:59 +01006708 * @see UserHandle
6709 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
6710 * user could not be created.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006711 * @throws SecurityException if {@code admin} is not a device owner.
Alex Chau89386ba2018-02-13 11:09:17 +08006712 * @throws UserOperationException if the user could not be created and the calling app is
6713 * targeting {@link android.os.Build.VERSION_CODES#P} and running on
6714 * {@link android.os.Build.VERSION_CODES#P}.
phweiss343fb332016-01-25 14:48:59 +01006715 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006716 public @Nullable UserHandle createAndManageUser(@NonNull ComponentName admin,
6717 @NonNull String name,
phweissa92e1212016-01-25 17:14:10 +01006718 @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras,
Benjamin Franz77c94a92017-08-09 14:16:03 +01006719 @CreateAndManageUserFlags int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006720 throwIfParentInstance("createAndManageUser");
phweiss343fb332016-01-25 14:48:59 +01006721 try {
phweissa92e1212016-01-25 17:14:10 +01006722 return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags);
Alex Chau89386ba2018-02-13 11:09:17 +08006723 } catch (ServiceSpecificException e) {
6724 throw new UserOperationException(e.getMessage(), e.errorCode);
phweiss343fb332016-01-25 14:48:59 +01006725 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006726 throw re.rethrowFromSystemServer();
phweiss343fb332016-01-25 14:48:59 +01006727 }
phweiss343fb332016-01-25 14:48:59 +01006728 }
6729
6730 /**
Alex Chaub6ef8692018-01-09 14:16:36 +00006731 * Called by a device owner to remove a user/profile and all associated data. The primary user
6732 * can not be removed.
Julia Reynolds1e958392014-05-16 14:25:21 -04006733 *
6734 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6735 * @param userHandle the user to remove.
6736 * @return {@code true} if the user was removed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006737 * @throws SecurityException if {@code admin} is not a device owner.
Julia Reynolds1e958392014-05-16 14:25:21 -04006738 */
Alex Chauaf9bb8d2017-12-06 14:38:25 +00006739 public boolean removeUser(@NonNull ComponentName admin, @NonNull UserHandle userHandle) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006740 throwIfParentInstance("removeUser");
Julia Reynolds1e958392014-05-16 14:25:21 -04006741 try {
6742 return mService.removeUser(admin, userHandle);
6743 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006744 throw re.rethrowFromSystemServer();
Julia Reynolds1e958392014-05-16 14:25:21 -04006745 }
6746 }
6747
6748 /**
Alex Chaub6ef8692018-01-09 14:16:36 +00006749 * Called by a device owner to switch the specified secondary user to the foreground.
Jason Monk582d9112014-07-09 19:57:08 -04006750 *
6751 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6752 * @param userHandle the user to switch to; null will switch to primary.
6753 * @return {@code true} if the switch was successful, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006754 * @throws SecurityException if {@code admin} is not a device owner.
Jason Monk582d9112014-07-09 19:57:08 -04006755 * @see Intent#ACTION_USER_FOREGROUND
Alex Chaub6ef8692018-01-09 14:16:36 +00006756 * @see #getSecondaryUsers(ComponentName)
Jason Monk582d9112014-07-09 19:57:08 -04006757 */
Robin Lee25e26452015-06-02 09:56:29 -07006758 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006759 throwIfParentInstance("switchUser");
Jason Monk582d9112014-07-09 19:57:08 -04006760 try {
6761 return mService.switchUser(admin, userHandle);
6762 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006763 throw re.rethrowFromSystemServer();
Jason Monk582d9112014-07-09 19:57:08 -04006764 }
6765 }
6766
6767 /**
Alex Chaub6ef8692018-01-09 14:16:36 +00006768 * Called by a device owner to start the specified secondary user in background.
6769 *
6770 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Alex Chau596c2882018-01-29 14:39:37 +00006771 * @param userHandle the user to be started in background.
6772 * @return one of the following result codes:
Alex Chau89386ba2018-02-13 11:09:17 +08006773 * {@link UserManager#USER_OPERATION_ERROR_UNKNOWN},
6774 * {@link UserManager#USER_OPERATION_SUCCESS},
6775 * {@link UserManager#USER_OPERATION_ERROR_MANAGED_PROFILE},
6776 * {@link UserManager#USER_OPERATION_ERROR_MAX_RUNNING_USERS},
Alex Chaub6ef8692018-01-09 14:16:36 +00006777 * @throws SecurityException if {@code admin} is not a device owner.
6778 * @see #getSecondaryUsers(ComponentName)
6779 */
Alex Chau596c2882018-01-29 14:39:37 +00006780 public @UserOperationResult int startUserInBackground(
Alex Chaub6ef8692018-01-09 14:16:36 +00006781 @NonNull ComponentName admin, @NonNull UserHandle userHandle) {
6782 throwIfParentInstance("startUserInBackground");
6783 try {
6784 return mService.startUserInBackground(admin, userHandle);
6785 } catch (RemoteException re) {
6786 throw re.rethrowFromSystemServer();
6787 }
6788 }
6789
6790 /**
Alex Chauaf9bb8d2017-12-06 14:38:25 +00006791 * Called by a device owner to stop the specified secondary user.
Alex Chauaf9bb8d2017-12-06 14:38:25 +00006792 *
6793 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6794 * @param userHandle the user to be stopped.
Alex Chau596c2882018-01-29 14:39:37 +00006795 * @return one of the following result codes:
Alex Chau89386ba2018-02-13 11:09:17 +08006796 * {@link UserManager#USER_OPERATION_ERROR_UNKNOWN},
6797 * {@link UserManager#USER_OPERATION_SUCCESS},
6798 * {@link UserManager#USER_OPERATION_ERROR_MANAGED_PROFILE},
6799 * {@link UserManager#USER_OPERATION_ERROR_CURRENT_USER}
Alex Chauaf9bb8d2017-12-06 14:38:25 +00006800 * @throws SecurityException if {@code admin} is not a device owner.
Alex Chaub6ef8692018-01-09 14:16:36 +00006801 * @see #getSecondaryUsers(ComponentName)
Alex Chauaf9bb8d2017-12-06 14:38:25 +00006802 */
Alex Chau596c2882018-01-29 14:39:37 +00006803 public @UserOperationResult int stopUser(
6804 @NonNull ComponentName admin, @NonNull UserHandle userHandle) {
Alex Chauaf9bb8d2017-12-06 14:38:25 +00006805 throwIfParentInstance("stopUser");
6806 try {
6807 return mService.stopUser(admin, userHandle);
6808 } catch (RemoteException re) {
6809 throw re.rethrowFromSystemServer();
6810 }
6811 }
6812
6813 /**
Alex Chaub6ef8692018-01-09 14:16:36 +00006814 * Called by a profile owner of secondary user that is affiliated with the device to stop the
6815 * calling user and switch back to primary.
Alex Chauaf9bb8d2017-12-06 14:38:25 +00006816 *
6817 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Alex Chau596c2882018-01-29 14:39:37 +00006818 * @return one of the following result codes:
Alex Chau89386ba2018-02-13 11:09:17 +08006819 * {@link UserManager#USER_OPERATION_ERROR_UNKNOWN},
6820 * {@link UserManager#USER_OPERATION_SUCCESS},
6821 * {@link UserManager#USER_OPERATION_ERROR_MANAGED_PROFILE},
6822 * {@link UserManager#USER_OPERATION_ERROR_CURRENT_USER}
Alex Chau443b6432017-12-13 12:44:31 +00006823 * @throws SecurityException if {@code admin} is not a profile owner affiliated with the device.
Alex Chaub6ef8692018-01-09 14:16:36 +00006824 * @see #getSecondaryUsers(ComponentName)
Alex Chauaf9bb8d2017-12-06 14:38:25 +00006825 */
Alex Chau596c2882018-01-29 14:39:37 +00006826 public @UserOperationResult int logoutUser(@NonNull ComponentName admin) {
Alex Chauaf9bb8d2017-12-06 14:38:25 +00006827 throwIfParentInstance("logoutUser");
6828 try {
6829 return mService.logoutUser(admin);
6830 } catch (RemoteException re) {
6831 throw re.rethrowFromSystemServer();
6832 }
6833 }
6834
6835 /**
Alex Chaub6ef8692018-01-09 14:16:36 +00006836 * Called by a device owner to list all secondary users on the device. Managed profiles are not
6837 * considered as secondary users.
Alex Chauaf9bb8d2017-12-06 14:38:25 +00006838 * <p> Used for various user management APIs, including {@link #switchUser}, {@link #removeUser}
6839 * and {@link #stopUser}.
6840 *
6841 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6842 * @return list of other {@link UserHandle}s on the device.
6843 * @throws SecurityException if {@code admin} is not a device owner.
Alex Chaub6ef8692018-01-09 14:16:36 +00006844 * @see #removeUser(ComponentName, UserHandle)
6845 * @see #switchUser(ComponentName, UserHandle)
6846 * @see #startUserInBackground(ComponentName, UserHandle)
6847 * @see #stopUser(ComponentName, UserHandle)
Alex Chauaf9bb8d2017-12-06 14:38:25 +00006848 */
6849 public List<UserHandle> getSecondaryUsers(@NonNull ComponentName admin) {
6850 throwIfParentInstance("getSecondaryUsers");
6851 try {
6852 return mService.getSecondaryUsers(admin);
6853 } catch (RemoteException re) {
6854 throw re.rethrowFromSystemServer();
6855 }
6856 }
6857
6858 /**
Alex Chau8d6e18c2017-12-08 18:11:27 +00006859 * Checks if the profile owner is running in an ephemeral user.
6860 *
6861 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6862 * @return whether the profile owner is running in an ephemeral user.
6863 */
6864 public boolean isEphemeralUser(@NonNull ComponentName admin) {
6865 throwIfParentInstance("isEphemeralUser");
6866 try {
6867 return mService.isEphemeralUser(admin);
6868 } catch (RemoteException re) {
6869 throw re.rethrowFromSystemServer();
6870 }
6871 }
6872
6873 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00006874 * Retrieves the application restrictions for a given target application running in the calling
6875 * user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006876 * <p>
6877 * 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 +01006878 * application restrictions via {@link #setDelegatedScopes} with the
6879 * {@link #DELEGATION_APP_RESTRICTIONS} scope; otherwise a security exception will be thrown.
Robin Lee66e5d962014-04-09 16:44:21 +01006880 *
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07006881 * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
6882 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00006883 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006884 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01006885 * @param packageName The name of the package to fetch restricted settings of.
6886 * @return {@link Bundle} of settings corresponding to what was set last time
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006887 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty
6888 * {@link Bundle} if no restrictions have been set.
6889 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01006890 * @see #setDelegatedScopes
6891 * @see #DELEGATION_APP_RESTRICTIONS
Robin Lee66e5d962014-04-09 16:44:21 +01006892 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07006893 @WorkerThread
Makoto Onuki408e8e42016-10-25 12:10:27 -07006894 public @NonNull Bundle getApplicationRestrictions(
6895 @Nullable ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006896 throwIfParentInstance("getApplicationRestrictions");
Robin Lee66e5d962014-04-09 16:44:21 +01006897 if (mService != null) {
6898 try {
Edman Anjosf9946772016-11-28 16:35:15 +01006899 return mService.getApplicationRestrictions(admin, mContext.getPackageName(),
6900 packageName);
Robin Lee66e5d962014-04-09 16:44:21 +01006901 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006902 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01006903 }
6904 }
6905 return null;
6906 }
Amith Yamasanibe465322014-04-24 13:45:17 -07006907
6908 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05006909 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07006910 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006911 * The calling device admin must be a profile or device owner; if it is not, a security
6912 * exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07006913 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006914 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6915 * @param key The key of the restriction. See the constants in {@link android.os.UserManager}
6916 * for the list of keys.
6917 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanibe465322014-04-24 13:45:17 -07006918 */
Robin Lee25e26452015-06-02 09:56:29 -07006919 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006920 throwIfParentInstance("addUserRestriction");
Amith Yamasanibe465322014-04-24 13:45:17 -07006921 if (mService != null) {
6922 try {
6923 mService.setUserRestriction(admin, key, true);
6924 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006925 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07006926 }
6927 }
6928 }
6929
6930 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05006931 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07006932 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006933 * The calling device admin must be a profile or device owner; if it is not, a security
6934 * exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07006935 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006936 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6937 * @param key The key of the restriction. See the constants in {@link android.os.UserManager}
6938 * for the list of keys.
6939 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanibe465322014-04-24 13:45:17 -07006940 */
Robin Lee25e26452015-06-02 09:56:29 -07006941 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006942 throwIfParentInstance("clearUserRestriction");
Amith Yamasanibe465322014-04-24 13:45:17 -07006943 if (mService != null) {
6944 try {
6945 mService.setUserRestriction(admin, key, false);
6946 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006947 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07006948 }
6949 }
6950 }
Adam Connors010cfd42014-04-16 12:48:13 +01006951
6952 /**
Makoto Onuki3a3092f2015-10-30 11:07:51 -07006953 * Called by a profile or device owner to get user restrictions set with
6954 * {@link #addUserRestriction(ComponentName, String)}.
6955 * <p>
6956 * The target user may have more restrictions set by the system or other device owner / profile
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006957 * owner. To get all the user restrictions currently set, use
Makoto Onuki3a3092f2015-10-30 11:07:51 -07006958 * {@link UserManager#getUserRestrictions()}.
6959 *
6960 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006961 * @throws SecurityException if {@code admin} is not a device or profile owner.
Makoto Onuki3a3092f2015-10-30 11:07:51 -07006962 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006963 public @NonNull Bundle getUserRestrictions(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006964 throwIfParentInstance("getUserRestrictions");
Makoto Onuki3a3092f2015-10-30 11:07:51 -07006965 Bundle ret = null;
6966 if (mService != null) {
6967 try {
Sudheer Shanka549b9692016-03-30 17:12:07 -07006968 ret = mService.getUserRestrictions(admin);
6969 } catch (RemoteException e) {
6970 throw e.rethrowFromSystemServer();
6971 }
6972 }
6973 return ret == null ? new Bundle() : ret;
6974 }
6975
6976 /**
phweiss73145f42017-01-17 19:06:38 +01006977 * Called by any app to display a support dialog when a feature was disabled by an admin.
6978 * This returns an intent that can be used with {@link Context#startActivity(Intent)} to
6979 * display the dialog. It will tell the user that the feature indicated by {@code restriction}
6980 * was disabled by an admin, and include a link for more information. The default content of
6981 * the dialog can be changed by the restricting admin via
6982 * {@link #setShortSupportMessage(ComponentName, CharSequence)}. If the restriction is not
6983 * set (i.e. the feature is available), then the return value will be {@code null}.
6984 * @param restriction Indicates for which feature the dialog should be displayed. Can be a
6985 * user restriction from {@link UserManager}, e.g.
6986 * {@link UserManager#DISALLOW_ADJUST_VOLUME}, or one of the constants
Lenka Trochtova27fd8212018-04-10 11:01:58 +02006987 * {@link #POLICY_DISABLE_CAMERA}, {@link #POLICY_DISABLE_SCREEN_CAPTURE}.
phweiss73145f42017-01-17 19:06:38 +01006988 * @return Intent An intent to be used to start the dialog-activity if the restriction is
6989 * set by an admin, or null if the restriction does not exist or no admin set it.
6990 */
6991 public Intent createAdminSupportIntent(@NonNull String restriction) {
6992 throwIfParentInstance("createAdminSupportIntent");
6993 if (mService != null) {
6994 try {
6995 return mService.createAdminSupportIntent(restriction);
6996 } catch (RemoteException e) {
6997 throw e.rethrowFromSystemServer();
6998 }
6999 }
7000 return null;
7001 }
7002
7003 /**
Edman Anjos52088e42017-01-13 22:26:17 +01007004 * Hide or unhide packages. When a package is hidden it is unavailable for use, but the data and
7005 * actual package file remain. This function can be called by a device owner, profile owner, or
7006 * by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via
7007 * {@link #setDelegatedScopes}.
Julia Reynolds966881e2014-05-14 12:23:08 -04007008 *
Edman Anjos52088e42017-01-13 22:26:17 +01007009 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
7010 * {@code null} if the caller is a package access delegate.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07007011 * @param packageName The name of the package to hide or unhide.
7012 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007013 * unhidden.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07007014 * @return boolean Whether the hidden setting of the package was successfully updated.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007015 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01007016 * @see #setDelegatedScopes
7017 * @see #DELEGATION_PACKAGE_ACCESS
Julia Reynolds966881e2014-05-14 12:23:08 -04007018 */
Robin Lee25e26452015-06-02 09:56:29 -07007019 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07007020 boolean hidden) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007021 throwIfParentInstance("setApplicationHidden");
Julia Reynolds966881e2014-05-14 12:23:08 -04007022 if (mService != null) {
7023 try {
Edman Anjos52088e42017-01-13 22:26:17 +01007024 return mService.setApplicationHidden(admin, mContext.getPackageName(), packageName,
7025 hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04007026 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007027 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04007028 }
7029 }
7030 return false;
7031 }
7032
7033 /**
Edman Anjos52088e42017-01-13 22:26:17 +01007034 * Determine if a package is hidden. This function can be called by a device owner, profile
7035 * owner, or by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via
7036 * {@link #setDelegatedScopes}.
Julia Reynolds966881e2014-05-14 12:23:08 -04007037 *
Edman Anjos52088e42017-01-13 22:26:17 +01007038 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
7039 * {@code null} if the caller is a package access delegate.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07007040 * @param packageName The name of the package to retrieve the hidden status of.
7041 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007042 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01007043 * @see #setDelegatedScopes
7044 * @see #DELEGATION_PACKAGE_ACCESS
Julia Reynolds966881e2014-05-14 12:23:08 -04007045 */
Robin Lee25e26452015-06-02 09:56:29 -07007046 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007047 throwIfParentInstance("isApplicationHidden");
Julia Reynolds966881e2014-05-14 12:23:08 -04007048 if (mService != null) {
7049 try {
Edman Anjos52088e42017-01-13 22:26:17 +01007050 return mService.isApplicationHidden(admin, mContext.getPackageName(), packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04007051 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007052 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04007053 }
7054 }
7055 return false;
7056 }
7057
7058 /**
Edman Anjos52088e42017-01-13 22:26:17 +01007059 * Re-enable a system app that was disabled by default when the user was initialized. This
7060 * function can be called by a device owner, profile owner, or by a delegate given the
7061 * {@link #DELEGATION_ENABLE_SYSTEM_APP} scope via {@link #setDelegatedScopes}.
Adam Connors655be2a2014-07-14 09:01:25 +00007062 *
Edman Anjos52088e42017-01-13 22:26:17 +01007063 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
7064 * {@code null} if the caller is an enable system app delegate.
Makoto Onuki32b30572015-12-11 14:29:51 -08007065 * @param packageName The package to be re-enabled in the calling profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007066 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01007067 * @see #setDelegatedScopes
7068 * @see #DELEGATION_PACKAGE_ACCESS
Adam Connors655be2a2014-07-14 09:01:25 +00007069 */
Robin Lee25e26452015-06-02 09:56:29 -07007070 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007071 throwIfParentInstance("enableSystemApp");
Adam Connors655be2a2014-07-14 09:01:25 +00007072 if (mService != null) {
7073 try {
Edman Anjos52088e42017-01-13 22:26:17 +01007074 mService.enableSystemApp(admin, mContext.getPackageName(), packageName);
Adam Connors655be2a2014-07-14 09:01:25 +00007075 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007076 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00007077 }
7078 }
7079 }
7080
7081 /**
Edman Anjos52088e42017-01-13 22:26:17 +01007082 * Re-enable system apps by intent that were disabled by default when the user was initialized.
7083 * This function can be called by a device owner, profile owner, or by a delegate given the
7084 * {@link #DELEGATION_ENABLE_SYSTEM_APP} scope via {@link #setDelegatedScopes}.
Adam Connors655be2a2014-07-14 09:01:25 +00007085 *
Edman Anjos52088e42017-01-13 22:26:17 +01007086 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
7087 * {@code null} if the caller is an enable system app delegate.
Adam Connors655be2a2014-07-14 09:01:25 +00007088 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007089 * intent will be re-enabled in the calling profile.
Adam Connors655be2a2014-07-14 09:01:25 +00007090 * @return int The number of activities that matched the intent and were installed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007091 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01007092 * @see #setDelegatedScopes
7093 * @see #DELEGATION_PACKAGE_ACCESS
Adam Connors655be2a2014-07-14 09:01:25 +00007094 */
Robin Lee25e26452015-06-02 09:56:29 -07007095 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007096 throwIfParentInstance("enableSystemApp");
Adam Connors655be2a2014-07-14 09:01:25 +00007097 if (mService != null) {
7098 try {
Edman Anjos52088e42017-01-13 22:26:17 +01007099 return mService.enableSystemAppWithIntent(admin, mContext.getPackageName(), intent);
Adam Connors655be2a2014-07-14 09:01:25 +00007100 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007101 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00007102 }
7103 }
7104 return 0;
7105 }
7106
7107 /**
Alex Chau5343fcb2017-12-05 16:49:19 +00007108 * Install an existing package that has been installed in another user, or has been kept after
7109 * removal via {@link #setKeepUninstalledPackages}.
7110 * This function can be called by a device owner, profile owner or a delegate given
7111 * the {@link #DELEGATION_INSTALL_EXISTING_PACKAGE} scope via {@link #setDelegatedScopes}.
7112 * When called in a secondary user or managed profile, the user/profile must be affiliated with
Alex Chau443b6432017-12-13 12:44:31 +00007113 * the device. See {@link #isAffiliatedUser}.
Alex Chau5343fcb2017-12-05 16:49:19 +00007114 *
7115 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7116 * @param packageName The package to be installed in the calling profile.
7117 * @return {@code true} if the app is installed; {@code false} otherwise.
7118 * @throws SecurityException if {@code admin} is not the device owner, or the profile owner of
7119 * an affiliated user or profile.
7120 * @see #setKeepUninstalledPackages
7121 * @see #setDelegatedScopes
Alex Chau443b6432017-12-13 12:44:31 +00007122 * @see #isAffiliatedUser
Alex Chau5343fcb2017-12-05 16:49:19 +00007123 * @see #DELEGATION_PACKAGE_ACCESS
7124 */
7125 public boolean installExistingPackage(@NonNull ComponentName admin, String packageName) {
7126 throwIfParentInstance("installExistingPackage");
7127 if (mService != null) {
7128 try {
7129 return mService.installExistingPackage(admin, mContext.getPackageName(),
7130 packageName);
7131 } catch (RemoteException e) {
7132 throw e.rethrowFromSystemServer();
7133 }
7134 }
7135 return false;
7136 }
7137
7138 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00007139 * Called by a device owner or profile owner to disable account management for a specific type
7140 * of account.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007141 * <p>
7142 * The calling device admin must be a device owner or profile owner. If it is not, a security
7143 * exception will be thrown.
7144 * <p>
7145 * When account management is disabled for an account type, adding or removing an account of
7146 * that type will not be possible.
7147 * <p>
7148 * From {@link android.os.Build.VERSION_CODES#N} the profile or device owner can still use
Benjamin Franzb6c0ce42015-11-05 10:06:51 +00007149 * {@link android.accounts.AccountManager} APIs to add or remove accounts when account
7150 * management for a specific type is disabled.
7151 *
Sander Alewijnse650c3342014-05-08 18:00:50 +01007152 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7153 * @param accountType For which account management is disabled or enabled.
7154 * @param disabled The boolean indicating that account management will be disabled (true) or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007155 * enabled (false).
7156 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnse650c3342014-05-08 18:00:50 +01007157 */
Robin Lee25e26452015-06-02 09:56:29 -07007158 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01007159 boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007160 throwIfParentInstance("setAccountManagementDisabled");
Sander Alewijnse650c3342014-05-08 18:00:50 +01007161 if (mService != null) {
7162 try {
7163 mService.setAccountManagementDisabled(admin, accountType, disabled);
7164 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007165 throw e.rethrowFromSystemServer();
Sander Alewijnse650c3342014-05-08 18:00:50 +01007166 }
7167 }
7168 }
7169
7170 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01007171 * Gets the array of accounts for which account management is disabled by the profile owner.
7172 *
7173 * <p> Account management can be disabled/enabled by calling
7174 * {@link #setAccountManagementDisabled}.
7175 *
7176 * @return a list of account types for which account management has been disabled.
7177 *
7178 * @see #setAccountManagementDisabled
7179 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007180 public @Nullable String[] getAccountTypesWithManagementDisabled() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007181 throwIfParentInstance("getAccountTypesWithManagementDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07007182 return getAccountTypesWithManagementDisabledAsUser(myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01007183 }
7184
7185 /**
7186 * @see #getAccountTypesWithManagementDisabled()
7187 * @hide
7188 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007189 public @Nullable String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01007190 if (mService != null) {
7191 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01007192 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01007193 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007194 throw e.rethrowFromSystemServer();
Sander Alewijnse5c02db62014-05-07 10:46:57 +01007195 }
7196 }
7197
7198 return null;
7199 }
justinzhang511e0d82014-03-24 16:09:24 -04007200
7201 /**
Jason Monkd7b86212014-06-16 13:15:38 -04007202 * Sets which packages may enter lock task mode.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007203 * <p>
Esteban Talaverabdcada92017-02-01 14:20:06 +00007204 * Any packages that share uid with an allowed package will also be allowed to activate lock
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007205 * task. From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task
Esteban Talaverabdcada92017-02-01 14:20:06 +00007206 * package list results in locked tasks belonging to those packages to be finished.
7207 * <p>
Jason Parks3c13b642017-11-28 15:39:43 -06007208 * This function can only be called by the device owner, a profile owner of an affiliated user
7209 * or profile, or the profile owner when no device owner is set. See {@link #isAffiliatedUser}.
7210 * Any package set via this method will be cleared if the user becomes unaffiliated.
Jason Monkd7b86212014-06-16 13:15:38 -04007211 *
Jason Monkd7b86212014-06-16 13:15:38 -04007212 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04007213 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jason Parks3c13b642017-11-28 15:39:43 -06007214 * @throws SecurityException if {@code admin} is not the device owner, the profile owner of an
7215 * affiliated user or profile, or the profile owner when no device owner is set.
Alex Chau443b6432017-12-13 12:44:31 +00007216 * @see #isAffiliatedUser
Jason Monkd7b86212014-06-16 13:15:38 -04007217 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00007218 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
7219 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04007220 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04007221 */
Esteban Talaverabdcada92017-02-01 14:20:06 +00007222 public void setLockTaskPackages(@NonNull ComponentName admin, @NonNull String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04007223 throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007224 throwIfParentInstance("setLockTaskPackages");
justinzhang511e0d82014-03-24 16:09:24 -04007225 if (mService != null) {
7226 try {
Jason Monk48aacba2014-08-13 16:29:08 -04007227 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04007228 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007229 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04007230 }
7231 }
7232 }
7233
7234 /**
Esteban Talaverabdcada92017-02-01 14:20:06 +00007235 * Returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04007236 *
Jason Parks3c13b642017-11-28 15:39:43 -06007237 * @throws SecurityException if {@code admin} is not the device owner, the profile owner of an
7238 * affiliated user or profile, or the profile owner when no device owner is set.
Alex Chau443b6432017-12-13 12:44:31 +00007239 * @see #isAffiliatedUser
Esteban Talaverabdcada92017-02-01 14:20:06 +00007240 * @see #setLockTaskPackages
justinzhang511e0d82014-03-24 16:09:24 -04007241 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007242 public @NonNull String[] getLockTaskPackages(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007243 throwIfParentInstance("getLockTaskPackages");
justinzhang511e0d82014-03-24 16:09:24 -04007244 if (mService != null) {
7245 try {
Jason Monk48aacba2014-08-13 16:29:08 -04007246 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04007247 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007248 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04007249 }
7250 }
Esteban Talaverabdcada92017-02-01 14:20:06 +00007251 return new String[0];
justinzhang511e0d82014-03-24 16:09:24 -04007252 }
7253
7254 /**
7255 * This function lets the caller know whether the given component is allowed to start the
7256 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04007257 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04007258 */
Jason Monkd7b86212014-06-16 13:15:38 -04007259 public boolean isLockTaskPermitted(String pkg) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007260 throwIfParentInstance("isLockTaskPermitted");
justinzhang511e0d82014-03-24 16:09:24 -04007261 if (mService != null) {
7262 try {
Jason Monkd7b86212014-06-16 13:15:38 -04007263 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04007264 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007265 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04007266 }
7267 }
7268 return false;
7269 }
Julia Reynoldsda551652014-05-14 17:15:16 -04007270
7271 /**
Benjamin Franz78ae1062018-03-26 11:01:32 +01007272 * Sets which system features are enabled when the device runs in lock task mode. This method
7273 * doesn't affect the features when lock task mode is inactive. Any system features not included
7274 * in {@code flags} are implicitly disabled when calling this method. By default, only
7275 * {@link #LOCK_TASK_FEATURE_GLOBAL_ACTIONS} is enabled—all the other features are disabled. To
7276 * disable the global actions dialog, call this method omitting
7277 * {@link #LOCK_TASK_FEATURE_GLOBAL_ACTIONS}.
7278 *
7279 * <p>This method can only be called by the device owner, a profile owner of an affiliated
7280 * user or profile, or the profile owner when no device owner is set. See
7281 * {@link #isAffiliatedUser}.
7282 * Any features set using this method are cleared if the user becomes unaffiliated.
Charles Hee078db72017-10-19 18:03:20 +01007283 *
7284 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franz78ae1062018-03-26 11:01:32 +01007285 * @param flags The system features enabled during lock task mode.
Jason Parks3c13b642017-11-28 15:39:43 -06007286 * @throws SecurityException if {@code admin} is not the device owner, the profile owner of an
7287 * affiliated user or profile, or the profile owner when no device owner is set.
Alex Chau443b6432017-12-13 12:44:31 +00007288 * @see #isAffiliatedUser
Benjamin Franz78ae1062018-03-26 11:01:32 +01007289 **/
Charles Hee078db72017-10-19 18:03:20 +01007290 public void setLockTaskFeatures(@NonNull ComponentName admin, @LockTaskFeature int flags) {
7291 throwIfParentInstance("setLockTaskFeatures");
7292 if (mService != null) {
7293 try {
7294 mService.setLockTaskFeatures(admin, flags);
7295 } catch (RemoteException e) {
7296 throw e.rethrowFromSystemServer();
7297 }
7298 }
7299 }
7300
7301 /**
7302 * Gets which system features are enabled for LockTask mode.
7303 *
7304 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7305 * @return bitfield of flags. See {@link #setLockTaskFeatures(ComponentName, int)} for a list.
Jason Parks3c13b642017-11-28 15:39:43 -06007306 * @throws SecurityException if {@code admin} is not the device owner, the profile owner of an
7307 * affiliated user or profile, or the profile owner when no device owner is set.
Alex Chau443b6432017-12-13 12:44:31 +00007308 * @see #isAffiliatedUser
7309 * @see #setLockTaskFeatures
Charles Hee078db72017-10-19 18:03:20 +01007310 */
7311 public @LockTaskFeature int getLockTaskFeatures(@NonNull ComponentName admin) {
7312 throwIfParentInstance("getLockTaskFeatures");
7313 if (mService != null) {
7314 try {
7315 return mService.getLockTaskFeatures(admin);
7316 } catch (RemoteException e) {
7317 throw e.rethrowFromSystemServer();
7318 }
7319 }
7320 return 0;
7321 }
7322
7323 /**
yuemingw0de748d2017-11-15 19:22:27 +00007324 * Called by device owner to update {@link android.provider.Settings.Global} settings.
Benjamin Franz482bb232017-06-23 13:48:20 +01007325 * Validation that the value of the setting is in the correct form for the setting type should
7326 * be performed by the caller.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007327 * <p>
7328 * The settings that can be updated with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04007329 * <ul>
Benjamin Franz482bb232017-06-23 13:48:20 +01007330 * <li>{@link android.provider.Settings.Global#ADB_ENABLED}</li>
7331 * <li>{@link android.provider.Settings.Global#AUTO_TIME}</li>
7332 * <li>{@link android.provider.Settings.Global#AUTO_TIME_ZONE}</li>
7333 * <li>{@link android.provider.Settings.Global#DATA_ROAMING}</li>
7334 * <li>{@link android.provider.Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
7335 * <li>{@link android.provider.Settings.Global#WIFI_SLEEP_POLICY}</li>
7336 * <li>{@link android.provider.Settings.Global#STAY_ON_WHILE_PLUGGED_IN} This setting is only
7337 * available from {@link android.os.Build.VERSION_CODES#M} onwards and can only be set if
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007338 * {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
Benjamin Franz482bb232017-06-23 13:48:20 +01007339 * <li>{@link android.provider.Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li> This
7340 * setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04007341 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007342 * <p>
7343 * Changing the following settings has no effect as of {@link android.os.Build.VERSION_CODES#M}:
Esteban Talavera656fa7f2015-06-29 17:41:39 +01007344 * <ul>
Benjamin Franz482bb232017-06-23 13:48:20 +01007345 * <li>{@link android.provider.Settings.Global#BLUETOOTH_ON}. Use
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007346 * {@link android.bluetooth.BluetoothAdapter#enable()} and
7347 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
Benjamin Franz482bb232017-06-23 13:48:20 +01007348 * <li>{@link android.provider.Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
7349 * <li>{@link android.provider.Settings.Global#MODE_RINGER}. Use
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007350 * {@link android.media.AudioManager#setRingerMode(int)} instead.</li>
Benjamin Franz482bb232017-06-23 13:48:20 +01007351 * <li>{@link android.provider.Settings.Global#NETWORK_PREFERENCE}</li>
7352 * <li>{@link android.provider.Settings.Global#WIFI_ON}. Use
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007353 * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01007354 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04007355 *
7356 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7357 * @param setting The name of the setting to update.
7358 * @param value The value to update the setting to.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007359 * @throws SecurityException if {@code admin} is not a device owner.
Julia Reynoldsda551652014-05-14 17:15:16 -04007360 */
Robin Lee25e26452015-06-02 09:56:29 -07007361 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007362 throwIfParentInstance("setGlobalSetting");
Julia Reynoldsda551652014-05-14 17:15:16 -04007363 if (mService != null) {
7364 try {
7365 mService.setGlobalSetting(admin, setting, value);
7366 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007367 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04007368 }
7369 }
7370 }
7371
yuemingw93ffce62018-02-21 16:20:14 +00007372 /** @hide */
7373 @StringDef({
7374 Settings.System.SCREEN_BRIGHTNESS_MODE,
7375 Settings.System.SCREEN_BRIGHTNESS,
7376 Settings.System.SCREEN_OFF_TIMEOUT
7377 })
7378 @Retention(RetentionPolicy.SOURCE)
7379 public @interface SystemSettingsWhitelist {}
7380
Julia Reynoldsda551652014-05-14 17:15:16 -04007381 /**
yuemingwc0281f12018-03-28 15:58:49 +01007382 * Called by a device or profile owner to update {@link android.provider.Settings.System}
7383 * settings. Validation that the value of the setting is in the correct form for the setting
7384 * type should be performed by the caller.
yuemingw0de748d2017-11-15 19:22:27 +00007385 * <p>
yuemingwc0281f12018-03-28 15:58:49 +01007386 * The settings that can be updated by a device owner or profile owner of secondary user with
7387 * this method are:
yuemingw0de748d2017-11-15 19:22:27 +00007388 * <ul>
7389 * <li>{@link android.provider.Settings.System#SCREEN_BRIGHTNESS}</li>
7390 * <li>{@link android.provider.Settings.System#SCREEN_BRIGHTNESS_MODE}</li>
7391 * <li>{@link android.provider.Settings.System#SCREEN_OFF_TIMEOUT}</li>
7392 * </ul>
7393 * <p>
7394 *
7395 * @see android.provider.Settings.System#SCREEN_OFF_TIMEOUT
7396 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7397 * @param setting The name of the setting to update.
7398 * @param value The value to update the setting to.
yuemingwc0281f12018-03-28 15:58:49 +01007399 * @throws SecurityException if {@code admin} is not a device or profile owner.
yuemingw0de748d2017-11-15 19:22:27 +00007400 */
yuemingw93ffce62018-02-21 16:20:14 +00007401 public void setSystemSetting(@NonNull ComponentName admin,
7402 @NonNull @SystemSettingsWhitelist String setting, String value) {
yuemingw0de748d2017-11-15 19:22:27 +00007403 throwIfParentInstance("setSystemSetting");
7404 if (mService != null) {
7405 try {
7406 mService.setSystemSetting(admin, setting, value);
7407 } catch (RemoteException e) {
7408 throw e.rethrowFromSystemServer();
7409 }
7410 }
7411 }
7412
7413 /**
yuemingwe43cdf72017-10-12 16:52:11 +01007414 * Called by device owner to set the system wall clock time. This only takes effect if called
7415 * when {@link android.provider.Settings.Global#AUTO_TIME} is 0, otherwise {@code false} will be
7416 * returned.
7417 *
7418 * @param admin Which {@link DeviceAdminReceiver} this request is associated with
7419 * @param millis time in milliseconds since the Epoch
7420 * @return {@code true} if set time succeeded, {@code false} otherwise.
7421 * @throws SecurityException if {@code admin} is not a device owner.
7422 */
7423 public boolean setTime(@NonNull ComponentName admin, long millis) {
7424 throwIfParentInstance("setTime");
7425 if (mService != null) {
7426 try {
7427 return mService.setTime(admin, millis);
7428 } catch (RemoteException e) {
7429 throw e.rethrowFromSystemServer();
7430 }
7431 }
7432 return false;
7433 }
7434
7435 /**
7436 * Called by device owner to set the system's persistent default time zone. This only takes
7437 * effect if called when {@link android.provider.Settings.Global#AUTO_TIME_ZONE} is 0, otherwise
7438 * {@code false} will be returned.
7439 *
7440 * @see android.app.AlarmManager#setTimeZone(String)
7441 * @param admin Which {@link DeviceAdminReceiver} this request is associated with
7442 * @param timeZone one of the Olson ids from the list returned by
7443 * {@link java.util.TimeZone#getAvailableIDs}
7444 * @return {@code true} if set timezone succeeded, {@code false} otherwise.
7445 * @throws SecurityException if {@code admin} is not a device owner.
7446 */
7447 public boolean setTimeZone(@NonNull ComponentName admin, String timeZone) {
7448 throwIfParentInstance("setTimeZone");
7449 if (mService != null) {
7450 try {
7451 return mService.setTimeZone(admin, timeZone);
7452 } catch (RemoteException e) {
7453 throw e.rethrowFromSystemServer();
7454 }
7455 }
7456 return false;
7457 }
7458
7459 /**
Benjamin Franz482bb232017-06-23 13:48:20 +01007460 * Called by profile or device owners to update {@link android.provider.Settings.Secure}
7461 * settings. Validation that the value of the setting is in the correct form for the setting
7462 * type should be performed by the caller.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007463 * <p>
7464 * The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04007465 * <ul>
Benjamin Franz482bb232017-06-23 13:48:20 +01007466 * <li>{@link android.provider.Settings.Secure#DEFAULT_INPUT_METHOD}</li>
7467 * <li>{@link android.provider.Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04007468 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007469 * <p>
7470 * A device owner can additionally update the following settings:
Julia Reynolds82735bc2014-09-04 16:43:30 -04007471 * <ul>
Benjamin Franz482bb232017-06-23 13:48:20 +01007472 * <li>{@link android.provider.Settings.Secure#LOCATION_MODE}</li>
Julia Reynolds82735bc2014-09-04 16:43:30 -04007473 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007474 *
Suprabh Shukla0b1356f2017-02-21 14:33:50 -08007475 * <strong>Note: Starting from Android O, apps should no longer call this method with the
7476 * setting {@link android.provider.Settings.Secure#INSTALL_NON_MARKET_APPS}, which is
7477 * deprecated. Instead, device owners or profile owners should use the restriction
7478 * {@link UserManager#DISALLOW_INSTALL_UNKNOWN_SOURCES}.
7479 * If any app targeting {@link android.os.Build.VERSION_CODES#O} or higher calls this method
7480 * with {@link android.provider.Settings.Secure#INSTALL_NON_MARKET_APPS},
7481 * an {@link UnsupportedOperationException} is thrown.
7482 * </strong>
7483 *
Julia Reynoldsda551652014-05-14 17:15:16 -04007484 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7485 * @param setting The name of the setting to update.
7486 * @param value The value to update the setting to.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007487 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynoldsda551652014-05-14 17:15:16 -04007488 */
Robin Lee25e26452015-06-02 09:56:29 -07007489 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007490 throwIfParentInstance("setSecureSetting");
Julia Reynoldsda551652014-05-14 17:15:16 -04007491 if (mService != null) {
7492 try {
7493 mService.setSecureSetting(admin, setting, value);
7494 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007495 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04007496 }
7497 }
7498 }
7499
Amith Yamasanif20d6402014-05-24 15:34:37 -07007500 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007501 * Designates a specific service component as the provider for making permission requests of a
7502 * local or remote administrator of the user.
Amith Yamasanif20d6402014-05-24 15:34:37 -07007503 * <p/>
7504 * Only a profile owner can designate the restrictions provider.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007505 *
Amith Yamasanif20d6402014-05-24 15:34:37 -07007506 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07007507 * @param provider The component name of the service that implements
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007508 * {@link RestrictionsReceiver}. If this param is null, it removes the restrictions
7509 * provider previously assigned.
7510 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanif20d6402014-05-24 15:34:37 -07007511 */
Robin Lee25e26452015-06-02 09:56:29 -07007512 public void setRestrictionsProvider(@NonNull ComponentName admin,
7513 @Nullable ComponentName provider) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007514 throwIfParentInstance("setRestrictionsProvider");
Amith Yamasanif20d6402014-05-24 15:34:37 -07007515 if (mService != null) {
7516 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07007517 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07007518 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007519 throw re.rethrowFromSystemServer();
Amith Yamasanif20d6402014-05-24 15:34:37 -07007520 }
7521 }
7522 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04007523
7524 /**
7525 * Called by profile or device owners to set the master volume mute on or off.
Nicolas Prevotaef3ce22016-09-22 12:00:25 +01007526 * This has no effect when set on a managed profile.
Julia Reynolds4a21b252014-06-04 11:11:43 -04007527 *
7528 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7529 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007530 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds4a21b252014-06-04 11:11:43 -04007531 */
Robin Lee25e26452015-06-02 09:56:29 -07007532 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007533 throwIfParentInstance("setMasterVolumeMuted");
Julia Reynolds4a21b252014-06-04 11:11:43 -04007534 if (mService != null) {
7535 try {
7536 mService.setMasterVolumeMuted(admin, on);
7537 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007538 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04007539 }
7540 }
7541 }
7542
7543 /**
7544 * Called by profile or device owners to check whether the master volume mute is on or off.
7545 *
7546 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7547 * @return {@code true} if master volume is muted, {@code false} if it's not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007548 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds4a21b252014-06-04 11:11:43 -04007549 */
Robin Lee25e26452015-06-02 09:56:29 -07007550 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007551 throwIfParentInstance("isMasterVolumeMuted");
Julia Reynolds4a21b252014-06-04 11:11:43 -04007552 if (mService != null) {
7553 try {
7554 return mService.isMasterVolumeMuted(admin);
7555 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007556 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04007557 }
7558 }
7559 return false;
7560 }
Kenny Guyc13053b2014-05-29 14:17:17 +01007561
7562 /**
Edman Anjosa5f2fb12016-12-19 11:25:54 -08007563 * Change whether a user can uninstall a package. This function can be called by a device owner,
7564 * profile owner, or by a delegate given the {@link #DELEGATION_BLOCK_UNINSTALL} scope via
7565 * {@link #setDelegatedScopes}.
Kenny Guyc13053b2014-05-29 14:17:17 +01007566 *
Edman Anjosa5f2fb12016-12-19 11:25:54 -08007567 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
7568 * {@code null} if the caller is a block uninstall delegate.
Kenny Guyc13053b2014-05-29 14:17:17 +01007569 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01007570 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007571 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjosa5f2fb12016-12-19 11:25:54 -08007572 * @see #setDelegatedScopes
7573 * @see #DELEGATION_BLOCK_UNINSTALL
Kenny Guyc13053b2014-05-29 14:17:17 +01007574 */
Edman Anjosa5f2fb12016-12-19 11:25:54 -08007575 public void setUninstallBlocked(@Nullable ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01007576 boolean uninstallBlocked) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007577 throwIfParentInstance("setUninstallBlocked");
Kenny Guyc13053b2014-05-29 14:17:17 +01007578 if (mService != null) {
7579 try {
Edman Anjosa5f2fb12016-12-19 11:25:54 -08007580 mService.setUninstallBlocked(admin, mContext.getPackageName(), packageName,
7581 uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01007582 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007583 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01007584 }
7585 }
7586 }
7587
7588 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08007589 * Check whether the user has been blocked by device policy from uninstalling a package.
Rubin Xua97855b2014-11-07 05:41:00 +00007590 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00007591 * <p>
7592 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007593 * behavior of this API is changed such that passing {@code null} as the {@code admin} parameter
7594 * will return if any admin has blocked the uninstallation. Before L MR1, passing {@code null}
7595 * will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01007596 *
Robin Lee25e26452015-06-02 09:56:29 -07007597 * @param admin The name of the admin component whose blocking policy will be checked, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007598 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01007599 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00007600 * @return true if uninstallation is blocked.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007601 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyc13053b2014-05-29 14:17:17 +01007602 */
Robin Lee25e26452015-06-02 09:56:29 -07007603 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007604 throwIfParentInstance("isUninstallBlocked");
Kenny Guyc13053b2014-05-29 14:17:17 +01007605 if (mService != null) {
7606 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01007607 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01007608 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007609 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01007610 }
7611 }
7612 return false;
7613 }
Svetoslav976e8bd2014-07-16 15:12:03 -07007614
7615 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007616 * Called by the profile owner of a managed profile to enable widget providers from a given
7617 * package to be available in the parent profile. As a result the user will be able to add
7618 * widgets from the white-listed package running under the profile to a widget host which runs
7619 * under the parent profile, for example the home screen. Note that a package may have zero or
7620 * more provider components, where each component provides a different widget type.
Svetoslav976e8bd2014-07-16 15:12:03 -07007621 * <p>
7622 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07007623 *
7624 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7625 * @param packageName The package from which widget providers are white-listed.
7626 * @return Whether the package was added.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007627 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07007628 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
7629 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
7630 */
Robin Lee25e26452015-06-02 09:56:29 -07007631 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007632 throwIfParentInstance("addCrossProfileWidgetProvider");
Svetoslav976e8bd2014-07-16 15:12:03 -07007633 if (mService != null) {
7634 try {
7635 return mService.addCrossProfileWidgetProvider(admin, packageName);
7636 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007637 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07007638 }
7639 }
7640 return false;
7641 }
7642
7643 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07007644 * Called by the profile owner of a managed profile to disable widget providers from a given
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007645 * package to be available in the parent profile. For this method to take effect the package
7646 * should have been added via
7647 * {@link #addCrossProfileWidgetProvider( android.content.ComponentName, String)}.
Svetoslav976e8bd2014-07-16 15:12:03 -07007648 * <p>
7649 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07007650 *
7651 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007652 * @param packageName The package from which widget providers are no longer white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07007653 * @return Whether the package was removed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007654 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07007655 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
7656 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
7657 */
Esteban Talavera62399912016-01-11 15:37:55 +00007658 public boolean removeCrossProfileWidgetProvider(
7659 @NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007660 throwIfParentInstance("removeCrossProfileWidgetProvider");
Svetoslav976e8bd2014-07-16 15:12:03 -07007661 if (mService != null) {
7662 try {
7663 return mService.removeCrossProfileWidgetProvider(admin, packageName);
7664 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007665 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07007666 }
7667 }
7668 return false;
7669 }
7670
7671 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07007672 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07007673 * available in the parent profile.
7674 *
7675 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7676 * @return The white-listed package list.
Svetoslav976e8bd2014-07-16 15:12:03 -07007677 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
7678 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007679 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07007680 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007681 public @NonNull List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007682 throwIfParentInstance("getCrossProfileWidgetProviders");
Svetoslav976e8bd2014-07-16 15:12:03 -07007683 if (mService != null) {
7684 try {
7685 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
7686 if (providers != null) {
7687 return providers;
7688 }
7689 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007690 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07007691 }
7692 }
7693 return Collections.emptyList();
7694 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05007695
7696 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08007697 * Called by profile or device owners to set the user's photo.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05007698 *
7699 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7700 * @param icon the bitmap to set as the photo.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007701 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05007702 */
Robin Lee25e26452015-06-02 09:56:29 -07007703 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007704 throwIfParentInstance("setUserIcon");
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05007705 try {
7706 mService.setUserIcon(admin, icon);
7707 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007708 throw re.rethrowFromSystemServer();
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05007709 }
7710 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04007711
7712 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01007713 * Called by device owners to set a local system update policy. When a new policy is set,
7714 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu29b9a7d2018-01-11 09:24:02 +00007715 * <p>
7716 * If the supplied system update policy has freeze periods set but the freeze periods do not
7717 * meet 90-day maximum length or 60-day minimum separation requirement set out in
7718 * {@link SystemUpdatePolicy#setFreezePeriods},
7719 * {@link SystemUpdatePolicy.ValidationFailedException} will the thrown. Note that the system
7720 * keeps a record of freeze periods the device experienced previously, and combines them with
7721 * the new freeze periods to be set when checking the maximum freeze length and minimum freeze
7722 * separation constraints. As a result, freeze periods that passed validation during
7723 * {@link SystemUpdatePolicy#setFreezePeriods} might fail the additional checks here due to
7724 * the freeze period history. If this is causing issues during development,
7725 * {@code adb shell dpm clear-freeze-period-record} can be used to clear the record.
Rubin Xu8027a4f2015-03-10 17:52:37 +00007726 *
Robin Lee25e26452015-06-02 09:56:29 -07007727 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007728 * components in the device owner package can set system update policies and the most
7729 * recent policy takes effect.
Robin Lee25e26452015-06-02 09:56:29 -07007730 * @param policy the new policy, or {@code null} to clear the current policy.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007731 * @throws SecurityException if {@code admin} is not a device owner.
Rubin Xu29b9a7d2018-01-11 09:24:02 +00007732 * @throws IllegalArgumentException if the policy type or maintenance window is not valid.
7733 * @throws SystemUpdatePolicy.ValidationFailedException if the policy's freeze period does not
7734 * meet the requirement.
Rubin Xu5faad8e2015-04-20 17:43:48 +01007735 * @see SystemUpdatePolicy
Rubin Xu29b9a7d2018-01-11 09:24:02 +00007736 * @see SystemUpdatePolicy#setFreezePeriods(List)
Rubin Xu8027a4f2015-03-10 17:52:37 +00007737 */
Robin Lee25e26452015-06-02 09:56:29 -07007738 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007739 throwIfParentInstance("setSystemUpdatePolicy");
Rubin Xu8027a4f2015-03-10 17:52:37 +00007740 if (mService != null) {
7741 try {
Robin Lee25e26452015-06-02 09:56:29 -07007742 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00007743 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007744 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00007745 }
7746 }
7747 }
7748
7749 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01007750 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00007751 *
Robin Lee25e26452015-06-02 09:56:29 -07007752 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00007753 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007754 public @Nullable SystemUpdatePolicy getSystemUpdatePolicy() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007755 throwIfParentInstance("getSystemUpdatePolicy");
Rubin Xu8027a4f2015-03-10 17:52:37 +00007756 if (mService != null) {
7757 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01007758 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00007759 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007760 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00007761 }
7762 }
7763 return null;
7764 }
Benjamin Franze36087e2015-04-07 16:40:34 +01007765
7766 /**
Rubin Xu29b9a7d2018-01-11 09:24:02 +00007767 * Reset record of previous system update freeze period the device went through.
7768 * Only callable by ADB.
7769 * @hide
7770 */
7771 public void clearSystemUpdatePolicyFreezePeriodRecord() {
7772 throwIfParentInstance("clearSystemUpdatePolicyFreezePeriodRecord");
7773 if (mService == null) {
7774 return;
7775 }
7776 try {
7777 mService.clearSystemUpdatePolicyFreezePeriodRecord();
7778 } catch (RemoteException re) {
7779 throw re.rethrowFromSystemServer();
7780 }
7781 }
Pavel Grafov5bb5a622018-01-31 21:06:24 +00007782
Rubin Xu29b9a7d2018-01-11 09:24:02 +00007783 /**
Alex Chau7fbe61d2018-01-04 15:45:38 +00007784 * Called by a device owner or profile owner of secondary users that is affiliated with the
7785 * device to disable the keyguard altogether.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007786 * <p>
7787 * Setting the keyguard to disabled has the same effect as choosing "None" as the screen lock
7788 * type. However, this call has no effect if a password, pin or pattern is currently set. If a
7789 * password, pin or pattern is set after the keyguard was disabled, the keyguard stops being
7790 * disabled.
Benjamin Franze36087e2015-04-07 16:40:34 +01007791 *
Benjamin Franz32a3bf32017-08-04 15:01:52 +01007792 * <p>
Benjamin Franz64affcb2017-09-01 13:47:22 +01007793 * As of {@link android.os.Build.VERSION_CODES#P}, this call also dismisses the
Benjamin Franz32a3bf32017-08-04 15:01:52 +01007794 * keyguard if it is currently shown.
7795 *
Benjamin Franze36087e2015-04-07 16:40:34 +01007796 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01007797 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01007798 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007799 * place. {@code true} otherwise.
Alex Chau7fbe61d2018-01-04 15:45:38 +00007800 * @throws SecurityException if {@code admin} is not the device owner, or a profile owner of
7801 * secondary user that is affiliated with the device.
7802 * @see #isAffiliatedUser
7803 * @see #getSecondaryUsers
Benjamin Franze36087e2015-04-07 16:40:34 +01007804 */
Robin Lee25e26452015-06-02 09:56:29 -07007805 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007806 throwIfParentInstance("setKeyguardDisabled");
Benjamin Franze36087e2015-04-07 16:40:34 +01007807 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01007808 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01007809 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007810 throw re.rethrowFromSystemServer();
Benjamin Franze36087e2015-04-07 16:40:34 +01007811 }
7812 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00007813
7814 /**
Alex Chau7fbe61d2018-01-04 15:45:38 +00007815 * Called by device owner or profile owner of secondary users that is affiliated with the
7816 * device to disable the status bar. Disabling the status bar blocks notifications, quick
7817 * settings and other screen overlays that allow escaping from a single use device.
Charles Hee078db72017-10-19 18:03:20 +01007818 * <p>
7819 * <strong>Note:</strong> This method has no effect for LockTask mode. The behavior of the
7820 * status bar in LockTask mode can be configured with
7821 * {@link #setLockTaskFeatures(ComponentName, int)}. Calls to this method when the device is in
7822 * LockTask mode will be registered, but will only take effect when the device leaves LockTask
7823 * mode.
Benjamin Franzea2ec972015-03-16 17:18:09 +00007824 *
7825 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01007826 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007827 * @return {@code false} if attempting to disable the status bar failed. {@code true} otherwise.
Alex Chau7fbe61d2018-01-04 15:45:38 +00007828 * @throws SecurityException if {@code admin} is not the device owner, or a profile owner of
7829 * secondary user that is affiliated with the device.
7830 * @see #isAffiliatedUser
7831 * @see #getSecondaryUsers
Benjamin Franzea2ec972015-03-16 17:18:09 +00007832 */
Robin Lee25e26452015-06-02 09:56:29 -07007833 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007834 throwIfParentInstance("setStatusBarDisabled");
Benjamin Franzea2ec972015-03-16 17:18:09 +00007835 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01007836 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00007837 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007838 throw re.rethrowFromSystemServer();
Benjamin Franzea2ec972015-03-16 17:18:09 +00007839 }
7840 }
Rubin Xudc105cc2015-04-14 23:38:01 +01007841
7842 /**
Charles Hedea0c3b2017-01-13 10:04:12 +00007843 * Called by the system update service to notify device and profile owners of pending system
7844 * updates.
Rubin Xudc105cc2015-04-14 23:38:01 +01007845 *
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06007846 * This method should only be used when it is unknown whether the pending system
Charles Hedea0c3b2017-01-13 10:04:12 +00007847 * update is a security patch. Otherwise, use
7848 * {@link #notifyPendingSystemUpdate(long, boolean)}.
7849 *
7850 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()}
7851 * indicating when the current pending update was first available. {@code -1} if no
7852 * update is available.
7853 * @see #notifyPendingSystemUpdate(long, boolean)
Rubin Xudc105cc2015-04-14 23:38:01 +01007854 * @hide
7855 */
7856 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06007857 @RequiresPermission(android.Manifest.permission.NOTIFY_PENDING_SYSTEM_UPDATE)
Rubin Xudc105cc2015-04-14 23:38:01 +01007858 public void notifyPendingSystemUpdate(long updateReceivedTime) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007859 throwIfParentInstance("notifyPendingSystemUpdate");
Rubin Xudc105cc2015-04-14 23:38:01 +01007860 if (mService != null) {
7861 try {
Charles Hedea0c3b2017-01-13 10:04:12 +00007862 mService.notifyPendingSystemUpdate(SystemUpdateInfo.of(updateReceivedTime));
7863 } catch (RemoteException re) {
7864 throw re.rethrowFromSystemServer();
7865 }
7866 }
7867 }
7868
7869 /**
7870 * Called by the system update service to notify device and profile owners of pending system
7871 * updates.
7872 *
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06007873 * This method should be used instead of {@link #notifyPendingSystemUpdate(long)}
Charles Hedea0c3b2017-01-13 10:04:12 +00007874 * when it is known whether the pending system update is a security patch.
7875 *
7876 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()}
7877 * indicating when the current pending update was first available. {@code -1} if no
7878 * update is available.
7879 * @param isSecurityPatch {@code true} if this system update is purely a security patch;
7880 * {@code false} if not.
7881 * @see #notifyPendingSystemUpdate(long)
7882 * @hide
7883 */
7884 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06007885 @RequiresPermission(android.Manifest.permission.NOTIFY_PENDING_SYSTEM_UPDATE)
Charles Hedea0c3b2017-01-13 10:04:12 +00007886 public void notifyPendingSystemUpdate(long updateReceivedTime, boolean isSecurityPatch) {
7887 throwIfParentInstance("notifyPendingSystemUpdate");
7888 if (mService != null) {
7889 try {
7890 mService.notifyPendingSystemUpdate(SystemUpdateInfo.of(updateReceivedTime,
7891 isSecurityPatch));
Rubin Xudc105cc2015-04-14 23:38:01 +01007892 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007893 throw re.rethrowFromSystemServer();
Rubin Xudc105cc2015-04-14 23:38:01 +01007894 }
7895 }
7896 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04007897
7898 /**
Pavel Grafovd65799e2016-12-02 11:21:45 +00007899 * Called by device or profile owners to get information about a pending system update.
7900 *
7901 * @param admin Which profile or device owner this request is associated with.
7902 * @return Information about a pending system update or {@code null} if no update pending.
7903 * @throws SecurityException if {@code admin} is not a device or profile owner.
7904 * @see DeviceAdminReceiver#onSystemUpdatePending(Context, Intent, long)
7905 */
7906 public @Nullable SystemUpdateInfo getPendingSystemUpdate(@NonNull ComponentName admin) {
7907 throwIfParentInstance("getPendingSystemUpdate");
7908 try {
7909 return mService.getPendingSystemUpdate(admin);
7910 } catch (RemoteException re) {
7911 throw re.rethrowFromSystemServer();
7912 }
7913 }
7914
7915 /**
Edman Anjos52088e42017-01-13 22:26:17 +01007916 * Set the default response for future runtime permission requests by applications. This
7917 * function can be called by a device owner, profile owner, or by a delegate given the
7918 * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}.
7919 * The policy can allow for normal operation which prompts the user to grant a permission, or
7920 * can allow automatic granting or denying of runtime permission requests by an application.
7921 * This also applies to new permissions declared by app updates. When a permission is denied or
7922 * granted this way, the effect is equivalent to setting the permission * grant state via
7923 * {@link #setPermissionGrantState}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007924 * <p/>
7925 * As this policy only acts on runtime permission requests, it only applies to applications
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07007926 * built with a {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Benjamin Franz45dd6662015-07-08 14:24:14 +01007927 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07007928 * @param admin Which profile or device owner this request is associated with.
7929 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007930 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
7931 * @throws SecurityException if {@code admin} is not a device or profile owner.
Benjamin Franz45dd6662015-07-08 14:24:14 +01007932 * @see #setPermissionGrantState
Edman Anjos52088e42017-01-13 22:26:17 +01007933 * @see #setDelegatedScopes
7934 * @see #DELEGATION_PERMISSION_GRANT
Amith Yamasanid49489b2015-04-28 14:00:26 -07007935 */
Robin Lee25e26452015-06-02 09:56:29 -07007936 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007937 throwIfParentInstance("setPermissionPolicy");
Amith Yamasanid49489b2015-04-28 14:00:26 -07007938 try {
Edman Anjos52088e42017-01-13 22:26:17 +01007939 mService.setPermissionPolicy(admin, mContext.getPackageName(), policy);
Amith Yamasanid49489b2015-04-28 14:00:26 -07007940 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007941 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07007942 }
7943 }
7944
7945 /**
7946 * Returns the current runtime permission policy set by the device or profile owner. The
7947 * default is {@link #PERMISSION_POLICY_PROMPT}.
Edman Anjos52088e42017-01-13 22:26:17 +01007948 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07007949 * @param admin Which profile or device owner this request is associated with.
7950 * @return the current policy for future permission requests.
7951 */
Esteban Talavera28b95702015-06-24 15:23:42 +01007952 public int getPermissionPolicy(ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007953 throwIfParentInstance("getPermissionPolicy");
Amith Yamasanid49489b2015-04-28 14:00:26 -07007954 try {
7955 return mService.getPermissionPolicy(admin);
7956 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007957 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07007958 }
7959 }
7960
7961 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007962 * Sets the grant state of a runtime permission for a specific application. The state can be
7963 * {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it through the UI,
7964 * {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission is denied and the user
7965 * cannot manage it through the UI, and {@link #PERMISSION_GRANT_STATE_GRANTED granted} in which
Tony Mak329047b2018-02-28 14:17:17 +00007966 * the permission is granted and the user cannot manage it through the UI. This method can only
7967 * be called by a profile owner, device owner, or a delegate given the
Edman Anjos52088e42017-01-13 22:26:17 +01007968 * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007969 * <p/>
Tony Mak329047b2018-02-28 14:17:17 +00007970 * Note that user cannot manage other permissions in the affected group through the UI
7971 * either and their granted state will be kept as the current value. Thus, it's recommended that
7972 * you set the grant state of all the permissions in the affected group.
7973 * <p/>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007974 * Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not revoke
7975 * the permission. It retains the previous grant, if any.
7976 * <p/>
7977 * Permissions can be granted or revoked only for applications built with a
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07007978 * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07007979 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07007980 * @param admin Which profile or device owner this request is associated with.
7981 * @param packageName The application to grant or revoke a permission to.
7982 * @param permission The permission to grant or revoke.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007983 * @param grantState The permission grant state which is one of
7984 * {@link #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
7985 * {@link #PERMISSION_GRANT_STATE_GRANTED},
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07007986 * @return whether the permission was successfully granted or revoked.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007987 * @throws SecurityException if {@code admin} is not a device or profile owner.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07007988 * @see #PERMISSION_GRANT_STATE_DENIED
7989 * @see #PERMISSION_GRANT_STATE_DEFAULT
7990 * @see #PERMISSION_GRANT_STATE_GRANTED
Edman Anjos52088e42017-01-13 22:26:17 +01007991 * @see #setDelegatedScopes
7992 * @see #DELEGATION_PERMISSION_GRANT
Amith Yamasanid49489b2015-04-28 14:00:26 -07007993 */
Robin Lee25e26452015-06-02 09:56:29 -07007994 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07007995 String permission, int grantState) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007996 throwIfParentInstance("setPermissionGrantState");
Amith Yamasanid49489b2015-04-28 14:00:26 -07007997 try {
Edman Anjos52088e42017-01-13 22:26:17 +01007998 return mService.setPermissionGrantState(admin, mContext.getPackageName(), packageName,
7999 permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07008000 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008001 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07008002 }
8003 }
Amith Yamasani184b3752015-05-22 13:00:51 -07008004
8005 /**
Edman Anjos52088e42017-01-13 22:26:17 +01008006 * Returns the current grant state of a runtime permission for a specific application. This
8007 * function can be called by a device owner, profile owner, or by a delegate given the
8008 * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}.
Amith Yamasani184b3752015-05-22 13:00:51 -07008009 *
Edman Anjos52088e42017-01-13 22:26:17 +01008010 * @param admin Which profile or device owner this request is associated with, or {@code null}
8011 * if the caller is a permission grant delegate.
Amith Yamasani184b3752015-05-22 13:00:51 -07008012 * @param packageName The application to check the grant state for.
8013 * @param permission The permission to check for.
8014 * @return the current grant state specified by device policy. If the profile or device owner
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07008015 * has not set a grant state, the return value is
8016 * {@link #PERMISSION_GRANT_STATE_DEFAULT}. This does not indicate whether or not the
8017 * permission is currently granted for the package.
8018 * <p/>
8019 * If a grant state was set by the profile or device owner, then the return value will
8020 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or
8021 * {@link #PERMISSION_GRANT_STATE_GRANTED}, which indicates if the permission is
8022 * currently denied or granted.
8023 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasani184b3752015-05-22 13:00:51 -07008024 * @see #setPermissionGrantState(ComponentName, String, String, int)
8025 * @see PackageManager#checkPermission(String, String)
Edman Anjos52088e42017-01-13 22:26:17 +01008026 * @see #setDelegatedScopes
8027 * @see #DELEGATION_PERMISSION_GRANT
Amith Yamasani184b3752015-05-22 13:00:51 -07008028 */
Bartosz Fabianowski4b0624f2017-01-16 11:47:28 +01008029 public int getPermissionGrantState(@Nullable ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07008030 String permission) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008031 throwIfParentInstance("getPermissionGrantState");
Amith Yamasani184b3752015-05-22 13:00:51 -07008032 try {
Edman Anjos52088e42017-01-13 22:26:17 +01008033 return mService.getPermissionGrantState(admin, mContext.getPackageName(), packageName,
8034 permission);
Amith Yamasani184b3752015-05-22 13:00:51 -07008035 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008036 throw re.rethrowFromSystemServer();
Amith Yamasani184b3752015-05-22 13:00:51 -07008037 }
8038 }
Nicolas Prevot07387fe2015-10-30 17:53:30 +00008039
8040 /**
Esteban Talavera01576862016-12-15 11:16:44 +00008041 * Returns whether it is possible for the caller to initiate provisioning of a managed profile
8042 * or device, setting itself as the device or profile owner.
8043 *
Nicolas Prevot07387fe2015-10-30 17:53:30 +00008044 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
8045 * {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Esteban Talavera01576862016-12-15 11:16:44 +00008046 * @return whether provisioning a managed profile or device is possible.
Nicolas Prevot07387fe2015-10-30 17:53:30 +00008047 * @throws IllegalArgumentException if the supplied action is not valid.
8048 */
Esteban Talavera01576862016-12-15 11:16:44 +00008049 public boolean isProvisioningAllowed(@NonNull String action) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008050 throwIfParentInstance("isProvisioningAllowed");
Nicolas Prevot07387fe2015-10-30 17:53:30 +00008051 try {
Esteban Talavera01576862016-12-15 11:16:44 +00008052 return mService.isProvisioningAllowed(action, mContext.getPackageName());
Nicolas Prevot07387fe2015-10-30 17:53:30 +00008053 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008054 throw re.rethrowFromSystemServer();
Nicolas Prevot07387fe2015-10-30 17:53:30 +00008055 }
8056 }
Mahaver Chopra15a46b02015-11-11 14:54:35 +00008057
8058 /**
Esteban Talavera01576862016-12-15 11:16:44 +00008059 * Checks whether it is possible to initiate provisioning a managed device,
8060 * profile or user, setting the given package as owner.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00008061 *
8062 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
8063 * {@link #ACTION_PROVISION_MANAGED_PROFILE},
8064 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE},
8065 * {@link #ACTION_PROVISION_MANAGED_USER}
Esteban Talavera01576862016-12-15 11:16:44 +00008066 * @param packageName The package of the component that would be set as device, user, or profile
8067 * owner.
8068 * @return A {@link ProvisioningPreCondition} value indicating whether provisioning is allowed.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00008069 * @hide
8070 */
Esteban Talavera01576862016-12-15 11:16:44 +00008071 public @ProvisioningPreCondition int checkProvisioningPreCondition(
8072 String action, @NonNull String packageName) {
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00008073 try {
Esteban Talavera01576862016-12-15 11:16:44 +00008074 return mService.checkProvisioningPreCondition(action, packageName);
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00008075 } catch (RemoteException re) {
8076 throw re.rethrowFromSystemServer();
8077 }
8078 }
8079
8080 /**
Mahaver Chopra15a46b02015-11-11 14:54:35 +00008081 * Return if this user is a managed profile of another user. An admin can become the profile
8082 * owner of a managed profile with {@link #ACTION_PROVISION_MANAGED_PROFILE} and of a managed
Kenny Guyffa38402016-03-31 16:40:57 +01008083 * user with {@link #createAndManageUser}
Mahaver Chopra15a46b02015-11-11 14:54:35 +00008084 * @param admin Which profile owner this request is associated with.
8085 * @return if this user is a managed profile of another user.
8086 */
8087 public boolean isManagedProfile(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008088 throwIfParentInstance("isManagedProfile");
Mahaver Chopra15a46b02015-11-11 14:54:35 +00008089 try {
8090 return mService.isManagedProfile(admin);
8091 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008092 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00008093 }
8094 }
8095
8096 /**
8097 * @hide
8098 * Return if this user is a system-only user. An admin can manage a device from a system only
8099 * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}.
8100 * @param admin Which device owner this request is associated with.
8101 * @return if this user is a system-only user.
8102 */
8103 public boolean isSystemOnlyUser(@NonNull ComponentName admin) {
8104 try {
8105 return mService.isSystemOnlyUser(admin);
8106 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008107 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00008108 }
8109 }
Makoto Onukia31ebbc2015-11-23 17:15:21 -08008110
8111 /**
8112 * Called by device owner to get the MAC address of the Wi-Fi device.
8113 *
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08008114 * @param admin Which device owner this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07008115 * @return the MAC address of the Wi-Fi device, or null when the information is not available.
8116 * (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.)
8117 * <p>
8118 * The address will be in the {@code XX:XX:XX:XX:XX:XX} format.
8119 * @throws SecurityException if {@code admin} is not a device owner.
Makoto Onukia31ebbc2015-11-23 17:15:21 -08008120 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07008121 public @Nullable String getWifiMacAddress(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008122 throwIfParentInstance("getWifiMacAddress");
Makoto Onukia31ebbc2015-11-23 17:15:21 -08008123 try {
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08008124 return mService.getWifiMacAddress(admin);
Makoto Onukia31ebbc2015-11-23 17:15:21 -08008125 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008126 throw re.rethrowFromSystemServer();
Makoto Onukia31ebbc2015-11-23 17:15:21 -08008127 }
8128 }
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00008129
8130 /**
Mahaver Chopra1216ae52016-03-11 15:39:48 +00008131 * Called by device owner to reboot the device. If there is an ongoing call on the device,
8132 * throws an {@link IllegalStateException}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07008133 * @param admin Which device owner the request is associated with.
Mahaver Chopra1216ae52016-03-11 15:39:48 +00008134 * @throws IllegalStateException if device has an ongoing call.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07008135 * @throws SecurityException if {@code admin} is not a device owner.
Mahaver Chopra1216ae52016-03-11 15:39:48 +00008136 * @see TelephonyManager#CALL_STATE_IDLE
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00008137 */
8138 public void reboot(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008139 throwIfParentInstance("reboot");
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00008140 try {
8141 mService.reboot(admin);
8142 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008143 throw re.rethrowFromSystemServer();
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00008144 }
8145 }
Kenny Guy06de4e72015-12-22 12:07:39 +00008146
8147 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07008148 * Called by a device admin to set the short support message. This will be displayed to the user
8149 * in settings screens where funtionality has been disabled by the admin. The message should be
8150 * limited to a short statement such as "This setting is disabled by your administrator. Contact
8151 * someone@example.com for support." If the message is longer than 200 characters it may be
8152 * truncated.
8153 * <p>
8154 * If the short support message needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00008155 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
8156 * and set a new version of this string accordingly.
8157 *
Kenny Guy06de4e72015-12-22 12:07:39 +00008158 * @see #setLongSupportMessage
Kenny Guy06de4e72015-12-22 12:07:39 +00008159 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07008160 * @param message Short message to be displayed to the user in settings or null to clear the
8161 * existing message.
8162 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00008163 */
8164 public void setShortSupportMessage(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07008165 @Nullable CharSequence message) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008166 throwIfParentInstance("setShortSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00008167 if (mService != null) {
8168 try {
8169 mService.setShortSupportMessage(admin, message);
8170 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008171 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00008172 }
8173 }
8174 }
8175
8176 /**
8177 * Called by a device admin to get the short support message.
8178 *
8179 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07008180 * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)} or
8181 * null if no message has been set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07008182 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00008183 */
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07008184 public CharSequence getShortSupportMessage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008185 throwIfParentInstance("getShortSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00008186 if (mService != null) {
8187 try {
8188 return mService.getShortSupportMessage(admin);
8189 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008190 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00008191 }
8192 }
8193 return null;
8194 }
8195
8196 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07008197 * Called by a device admin to set the long support message. This will be displayed to the user
8198 * in the device administators settings screen.
8199 * <p>
8200 * If the long support message needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00008201 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
8202 * and set a new version of this string accordingly.
8203 *
Kenny Guy06de4e72015-12-22 12:07:39 +00008204 * @see #setShortSupportMessage
Kenny Guy06de4e72015-12-22 12:07:39 +00008205 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07008206 * @param message Long message to be displayed to the user in settings or null to clear the
8207 * existing message.
8208 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00008209 */
8210 public void setLongSupportMessage(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07008211 @Nullable CharSequence message) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008212 throwIfParentInstance("setLongSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00008213 if (mService != null) {
8214 try {
8215 mService.setLongSupportMessage(admin, message);
8216 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008217 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00008218 }
8219 }
8220 }
8221
8222 /**
8223 * Called by a device admin to get the long support message.
8224 *
8225 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07008226 * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)} or
8227 * null if no message has been set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07008228 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00008229 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07008230 public @Nullable CharSequence getLongSupportMessage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008231 throwIfParentInstance("getLongSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00008232 if (mService != null) {
8233 try {
8234 return mService.getLongSupportMessage(admin);
8235 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008236 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00008237 }
8238 }
8239 return null;
8240 }
8241
8242 /**
8243 * Called by the system to get the short support message.
8244 *
8245 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
8246 * @param userHandle user id the admin is running as.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07008247 * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)}
Kenny Guy06de4e72015-12-22 12:07:39 +00008248 *
8249 * @hide
8250 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07008251 public @Nullable CharSequence getShortSupportMessageForUser(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07008252 int userHandle) {
Kenny Guy06de4e72015-12-22 12:07:39 +00008253 if (mService != null) {
8254 try {
8255 return mService.getShortSupportMessageForUser(admin, userHandle);
8256 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008257 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00008258 }
8259 }
8260 return null;
8261 }
8262
8263
8264 /**
8265 * Called by the system to get the long support message.
8266 *
8267 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
8268 * @param userHandle user id the admin is running as.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07008269 * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)}
Kenny Guy06de4e72015-12-22 12:07:39 +00008270 *
8271 * @hide
8272 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07008273 public @Nullable CharSequence getLongSupportMessageForUser(
8274 @NonNull ComponentName admin, int userHandle) {
Kenny Guy06de4e72015-12-22 12:07:39 +00008275 if (mService != null) {
8276 try {
8277 return mService.getLongSupportMessageForUser(admin, userHandle);
8278 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008279 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00008280 }
8281 }
8282 return null;
8283 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00008284
8285 /**
Esteban Talavera62399912016-01-11 15:37:55 +00008286 * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager}
8287 * whose calls act on the parent profile.
Benjamin Franz66b45f02016-04-05 19:12:39 +01008288 *
8289 * <p>The following methods are supported for the parent instance, all other methods will
8290 * throw a SecurityException when called on the parent instance:
8291 * <ul>
8292 * <li>{@link #getPasswordQuality}</li>
8293 * <li>{@link #setPasswordQuality}</li>
8294 * <li>{@link #getPasswordMinimumLength}</li>
8295 * <li>{@link #setPasswordMinimumLength}</li>
8296 * <li>{@link #getPasswordMinimumUpperCase}</li>
8297 * <li>{@link #setPasswordMinimumUpperCase}</li>
8298 * <li>{@link #getPasswordMinimumLowerCase}</li>
8299 * <li>{@link #setPasswordMinimumLowerCase}</li>
8300 * <li>{@link #getPasswordMinimumLetters}</li>
8301 * <li>{@link #setPasswordMinimumLetters}</li>
8302 * <li>{@link #getPasswordMinimumNumeric}</li>
8303 * <li>{@link #setPasswordMinimumNumeric}</li>
8304 * <li>{@link #getPasswordMinimumSymbols}</li>
8305 * <li>{@link #setPasswordMinimumSymbols}</li>
8306 * <li>{@link #getPasswordMinimumNonLetter}</li>
8307 * <li>{@link #setPasswordMinimumNonLetter}</li>
8308 * <li>{@link #getPasswordHistoryLength}</li>
8309 * <li>{@link #setPasswordHistoryLength}</li>
8310 * <li>{@link #getPasswordExpirationTimeout}</li>
8311 * <li>{@link #setPasswordExpirationTimeout}</li>
8312 * <li>{@link #getPasswordExpiration}</li>
Charles He8c760562016-10-25 16:36:53 +01008313 * <li>{@link #getPasswordMaximumLength}</li>
Benjamin Franz66b45f02016-04-05 19:12:39 +01008314 * <li>{@link #isActivePasswordSufficient}</li>
8315 * <li>{@link #getCurrentFailedPasswordAttempts}</li>
8316 * <li>{@link #getMaximumFailedPasswordsForWipe}</li>
8317 * <li>{@link #setMaximumFailedPasswordsForWipe}</li>
8318 * <li>{@link #getMaximumTimeToLock}</li>
8319 * <li>{@link #setMaximumTimeToLock}</li>
8320 * <li>{@link #lockNow}</li>
8321 * <li>{@link #getKeyguardDisabledFeatures}</li>
8322 * <li>{@link #setKeyguardDisabledFeatures}</li>
8323 * <li>{@link #getTrustAgentConfiguration}</li>
8324 * <li>{@link #setTrustAgentConfiguration}</li>
Michal Karpinskia20d8bb2016-11-23 12:09:08 +00008325 * <li>{@link #getRequiredStrongAuthTimeout}</li>
8326 * <li>{@link #setRequiredStrongAuthTimeout}</li>
Benjamin Franz66b45f02016-04-05 19:12:39 +01008327 * </ul>
Clara Bayarri3e826ef2015-12-14 17:51:22 +00008328 *
8329 * @return a new instance of {@link DevicePolicyManager} that acts on the parent profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07008330 * @throws SecurityException if {@code admin} is not a profile owner.
Clara Bayarri3e826ef2015-12-14 17:51:22 +00008331 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07008332 public @NonNull DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008333 throwIfParentInstance("getParentProfileInstance");
Clara Bayarri3e826ef2015-12-14 17:51:22 +00008334 try {
8335 if (!mService.isManagedProfile(admin)) {
8336 throw new SecurityException("The current user does not have a parent profile.");
8337 }
Jeff Sharkey49ca5292016-05-10 12:54:45 -06008338 return new DevicePolicyManager(mContext, mService, true);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008339 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008340 throw e.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008341 }
8342 }
8343
8344 /**
Esteban Talaverad36dd152016-12-15 08:51:45 +00008345 * Called by device owner to control the security logging feature.
Michal Karpinski6235a942016-03-15 12:07:23 +00008346 *
8347 * <p> Security logs contain various information intended for security auditing purposes.
8348 * See {@link SecurityEvent} for details.
8349 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00008350 * <p><strong>Note:</strong> The device owner won't be able to retrieve security logs if there
8351 * are unaffiliated secondary users or profiles on the device, regardless of whether the
8352 * feature is enabled. Logs will be discarded if the internal buffer fills up while waiting for
8353 * all users to become affiliated. Therefore it's recommended that affiliation ids are set for
8354 * new users as soon as possible after provisioning via {@link #setAffiliationIds}.
Michal Karpinskib58e4962016-03-01 14:55:10 +00008355 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008356 * @param admin Which device owner this request is associated with.
Michal Karpinski6235a942016-03-15 12:07:23 +00008357 * @param enabled whether security logging should be enabled or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07008358 * @throws SecurityException if {@code admin} is not a device owner.
Alex Chau443b6432017-12-13 12:44:31 +00008359 * @see #setAffiliationIds
Michal Karpinski6235a942016-03-15 12:07:23 +00008360 * @see #retrieveSecurityLogs
8361 */
8362 public void setSecurityLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008363 throwIfParentInstance("setSecurityLoggingEnabled");
Michal Karpinski6235a942016-03-15 12:07:23 +00008364 try {
8365 mService.setSecurityLoggingEnabled(admin, enabled);
8366 } catch (RemoteException re) {
8367 throw re.rethrowFromSystemServer();
8368 }
8369 }
8370
8371 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00008372 * Return whether security logging is enabled or not by the device owner.
8373 *
8374 * <p>Can only be called by the device owner, otherwise a {@link SecurityException} will be
8375 * thrown.
8376 *
8377 * @param admin Which device owner this request is associated with.
8378 * @return {@code true} if security logging is enabled by device owner, {@code false} otherwise.
8379 * @throws SecurityException if {@code admin} is not a device owner.
8380 */
Bartosz Fabianowski0ec00002017-03-24 14:22:24 +01008381 public boolean isSecurityLoggingEnabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008382 throwIfParentInstance("isSecurityLoggingEnabled");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008383 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00008384 return mService.isSecurityLoggingEnabled(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008385 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008386 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008387 }
8388 }
8389
8390 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00008391 * Called by device owner to retrieve all new security logging entries since the last call to
8392 * this API after device boots.
8393 *
8394 * <p> Access to the logs is rate limited and it will only return new logs after the device
8395 * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}.
8396 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00008397 * <p>If there is any other user or profile on the device, it must be affiliated with the
Alex Chau443b6432017-12-13 12:44:31 +00008398 * device. Otherwise a {@link SecurityException} will be thrown. See {@link #isAffiliatedUser}.
Michal Karpinskib58e4962016-03-01 14:55:10 +00008399 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008400 * @param admin Which device owner this request is associated with.
Michal Karpinski6235a942016-03-15 12:07:23 +00008401 * @return the new batch of security logs which is a list of {@link SecurityEvent},
8402 * or {@code null} if rate limitation is exceeded or if logging is currently disabled.
Esteban Talaverad36dd152016-12-15 08:51:45 +00008403 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
Alex Chau443b6432017-12-13 12:44:31 +00008404 * profile or secondary user that is not affiliated with the device.
8405 * @see #isAffiliatedUser
Esteban Talaverad36dd152016-12-15 08:51:45 +00008406 * @see DeviceAdminReceiver#onSecurityLogsAvailable
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008407 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07008408 public @Nullable List<SecurityEvent> retrieveSecurityLogs(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008409 throwIfParentInstance("retrieveSecurityLogs");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008410 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00008411 ParceledListSlice<SecurityEvent> list = mService.retrieveSecurityLogs(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008412 if (list != null) {
8413 return list.getList();
8414 } else {
8415 // Rate limit exceeded.
8416 return null;
8417 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00008418 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008419 throw re.rethrowFromSystemServer();
Clara Bayarri3e826ef2015-12-14 17:51:22 +00008420 }
8421 }
Benjamin Franz59720bb2016-01-18 15:26:11 +00008422
8423 /**
Pavel Grafov5bb5a622018-01-31 21:06:24 +00008424 * Forces a batch of security logs to be fetched from logd and makes it available for DPC.
8425 * Only callable by ADB. If throttled, returns time to wait in milliseconds, otherwise 0.
8426 * @hide
8427 */
8428 public long forceSecurityLogs() {
8429 if (mService == null) {
8430 return 0;
8431 }
8432 try {
8433 return mService.forceSecurityLogs();
8434 } catch (RemoteException re) {
8435 throw re.rethrowFromSystemServer();
8436 }
8437 }
8438
8439 /**
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00008440 * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent
8441 * profile.
8442 *
8443 * @hide
8444 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07008445 public @NonNull DevicePolicyManager getParentProfileInstance(UserInfo uInfo) {
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00008446 mContext.checkSelfPermission(
8447 android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS);
8448 if (!uInfo.isManagedProfile()) {
8449 throw new SecurityException("The user " + uInfo.id
8450 + " does not have a parent profile.");
8451 }
Jeff Sharkey49ca5292016-05-10 12:54:45 -06008452 return new DevicePolicyManager(mContext, mService, true);
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00008453 }
8454
8455 /**
Sudheer Shanka5be44ff2018-01-23 15:15:03 -08008456 * Called by a device or profile owner to restrict packages from using metered data.
Sudheer Shanka04d61ae2018-01-17 12:16:57 -08008457 *
8458 * @param admin which {@link DeviceAdminReceiver} this request is associated with.
8459 * @param packageNames the list of package names to be restricted.
8460 * @return a list of package names which could not be restricted.
8461 * @throws SecurityException if {@code admin} is not a device or profile owner.
8462 */
Michael Wachenschwanz54164682018-03-08 16:23:52 -08008463 public @NonNull List<String> setMeteredDataDisabledPackages(@NonNull ComponentName admin,
Sudheer Shanka04d61ae2018-01-17 12:16:57 -08008464 @NonNull List<String> packageNames) {
8465 throwIfParentInstance("setMeteredDataDisabled");
8466 if (mService != null) {
8467 try {
Michael Wachenschwanz54164682018-03-08 16:23:52 -08008468 return mService.setMeteredDataDisabledPackages(admin, packageNames);
Sudheer Shanka04d61ae2018-01-17 12:16:57 -08008469 } catch (RemoteException re) {
8470 throw re.rethrowFromSystemServer();
8471 }
8472 }
8473 return packageNames;
8474 }
8475
8476 /**
8477 * Called by a device or profile owner to retrieve the list of packages which are restricted
Sudheer Shanka5be44ff2018-01-23 15:15:03 -08008478 * by the admin from using metered data.
Sudheer Shanka04d61ae2018-01-17 12:16:57 -08008479 *
8480 * @param admin which {@link DeviceAdminReceiver} this request is associated with.
8481 * @return the list of restricted package names.
8482 * @throws SecurityException if {@code admin} is not a device or profile owner.
8483 */
Michael Wachenschwanz54164682018-03-08 16:23:52 -08008484 public @NonNull List<String> getMeteredDataDisabledPackages(@NonNull ComponentName admin) {
Sudheer Shanka04d61ae2018-01-17 12:16:57 -08008485 throwIfParentInstance("getMeteredDataDisabled");
8486 if (mService != null) {
8487 try {
Michael Wachenschwanz54164682018-03-08 16:23:52 -08008488 return mService.getMeteredDataDisabledPackages(admin);
Sudheer Shanka04d61ae2018-01-17 12:16:57 -08008489 } catch (RemoteException re) {
8490 throw re.rethrowFromSystemServer();
8491 }
8492 }
8493 return new ArrayList<>();
8494 }
8495
8496 /**
Sudheer Shanka5be44ff2018-01-23 15:15:03 -08008497 * Called by the system to check if a package is restricted from using metered data
8498 * by {@param admin}.
8499 *
8500 * @param admin which {@link DeviceAdminReceiver} this request is associated with.
8501 * @param packageName the package whose restricted status is needed.
8502 * @param userId the user to which {@param packageName} belongs.
8503 * @return {@code true} if the package is restricted by admin, otherwise {@code false}
8504 * @throws SecurityException if the caller doesn't run with {@link Process#SYSTEM_UID}
8505 * @hide
8506 */
Michael Wachenschwanz54164682018-03-08 16:23:52 -08008507 public boolean isMeteredDataDisabledPackageForUser(@NonNull ComponentName admin,
8508 String packageName, @UserIdInt int userId) {
Sudheer Shanka5be44ff2018-01-23 15:15:03 -08008509 throwIfParentInstance("getMeteredDataDisabledForUser");
8510 if (mService != null) {
8511 try {
Michael Wachenschwanz54164682018-03-08 16:23:52 -08008512 return mService.isMeteredDataDisabledPackageForUser(admin, packageName, userId);
Sudheer Shanka5be44ff2018-01-23 15:15:03 -08008513 } catch (RemoteException re) {
8514 throw re.rethrowFromSystemServer();
8515 }
8516 }
8517 return false;
8518 }
8519
8520 /**
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008521 * Called by device owners to retrieve device logs from before the device's last reboot.
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008522 * <p>
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01008523 * <strong> This API is not supported on all devices. Calling this API on unsupported devices
8524 * will result in {@code null} being returned. The device logs are retrieved from a RAM region
8525 * which is not guaranteed to be corruption-free during power cycles, as a result be cautious
8526 * about data corruption when parsing. </strong>
Esteban Talaverad36dd152016-12-15 08:51:45 +00008527 *
8528 * <p>If there is any other user or profile on the device, it must be affiliated with the
Alex Chau443b6432017-12-13 12:44:31 +00008529 * device. Otherwise a {@link SecurityException} will be thrown. See {@link #isAffiliatedUser}.
Michal Karpinskib58e4962016-03-01 14:55:10 +00008530 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008531 * @param admin Which device owner this request is associated with.
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01008532 * @return Device logs from before the latest reboot of the system, or {@code null} if this API
8533 * is not supported on the device.
Esteban Talaverad36dd152016-12-15 08:51:45 +00008534 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
Alex Chau443b6432017-12-13 12:44:31 +00008535 * profile or secondary user that is not affiliated with the device.
8536 * @see #isAffiliatedUser
Esteban Talaverad36dd152016-12-15 08:51:45 +00008537 * @see #retrieveSecurityLogs
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008538 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07008539 public @Nullable List<SecurityEvent> retrievePreRebootSecurityLogs(
8540 @NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008541 throwIfParentInstance("retrievePreRebootSecurityLogs");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008542 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00008543 ParceledListSlice<SecurityEvent> list = mService.retrievePreRebootSecurityLogs(admin);
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01008544 if (list != null) {
8545 return list.getList();
8546 } else {
8547 return null;
8548 }
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008549 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008550 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008551 }
8552 }
8553
8554 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07008555 * Called by a profile owner of a managed profile to set the color used for customization. This
8556 * color is used as background color of the confirm credentials screen for that user. The
Clara Bayarri8d0bd7fa2016-03-30 14:59:58 +01008557 * default color is teal (#00796B).
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07008558 * <p>
8559 * The confirm credentials screen can be created using
Benjamin Franz59720bb2016-01-18 15:26:11 +00008560 * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}.
8561 *
8562 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinski74cd7302016-04-12 15:17:36 +01008563 * @param color The 24bit (0xRRGGBB) representation of the color to be used.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07008564 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz59720bb2016-01-18 15:26:11 +00008565 */
8566 public void setOrganizationColor(@NonNull ComponentName admin, int color) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008567 throwIfParentInstance("setOrganizationColor");
Benjamin Franz59720bb2016-01-18 15:26:11 +00008568 try {
Michal Karpinski74cd7302016-04-12 15:17:36 +01008569 // always enforce alpha channel to have 100% opacity
8570 color |= 0xFF000000;
Benjamin Franz59720bb2016-01-18 15:26:11 +00008571 mService.setOrganizationColor(admin, color);
8572 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008573 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00008574 }
8575 }
8576
8577 /**
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00008578 * @hide
8579 *
8580 * Sets the color used for customization.
8581 *
Michal Karpinski74cd7302016-04-12 15:17:36 +01008582 * @param color The 24bit (0xRRGGBB) representation of the color to be used.
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00008583 * @param userId which user to set the color to.
8584 * @RequiresPermission(allOf = {
8585 * Manifest.permission.MANAGE_USERS,
8586 * Manifest.permission.INTERACT_ACROSS_USERS_FULL})
8587 */
8588 public void setOrganizationColorForUser(@ColorInt int color, @UserIdInt int userId) {
8589 try {
Michal Karpinski74cd7302016-04-12 15:17:36 +01008590 // always enforce alpha channel to have 100% opacity
8591 color |= 0xFF000000;
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00008592 mService.setOrganizationColorForUser(color, userId);
8593 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008594 throw re.rethrowFromSystemServer();
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00008595 }
8596 }
8597
8598 /**
Benjamin Franz59720bb2016-01-18 15:26:11 +00008599 * Called by a profile owner of a managed profile to retrieve the color used for customization.
8600 * This color is used as background color of the confirm credentials screen for that user.
8601 *
8602 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinski74cd7302016-04-12 15:17:36 +01008603 * @return The 24bit (0xRRGGBB) representation of the color to be used.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07008604 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz59720bb2016-01-18 15:26:11 +00008605 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01008606 public @ColorInt int getOrganizationColor(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008607 throwIfParentInstance("getOrganizationColor");
Benjamin Franz59720bb2016-01-18 15:26:11 +00008608 try {
8609 return mService.getOrganizationColor(admin);
8610 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008611 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00008612 }
8613 }
8614
8615 /**
8616 * @hide
8617 * Retrieve the customization color for a given user.
8618 *
8619 * @param userHandle The user id of the user we're interested in.
Michal Karpinski74cd7302016-04-12 15:17:36 +01008620 * @return The 24bit (0xRRGGBB) representation of the color to be used.
Benjamin Franz59720bb2016-01-18 15:26:11 +00008621 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01008622 public @ColorInt int getOrganizationColorForUser(int userHandle) {
Benjamin Franz59720bb2016-01-18 15:26:11 +00008623 try {
8624 return mService.getOrganizationColorForUser(userHandle);
8625 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008626 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00008627 }
8628 }
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01008629
8630 /**
Wen ZHANG2be4cfc2017-09-21 18:29:43 +01008631 * Called by the device owner (since API 26) or profile owner (since API 24) to set the name of
8632 * the organization under management.
8633 *
8634 * <p>If the organization name needs to be localized, it is the responsibility of the {@link
8635 * DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast and set
8636 * a new version of this string accordingly.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00008637 *
8638 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
8639 * @param title The organization name or {@code null} to clear a previously set name.
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01008640 * @throws SecurityException if {@code admin} is not a device or profile owner.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00008641 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01008642 public void setOrganizationName(@NonNull ComponentName admin, @Nullable CharSequence title) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008643 throwIfParentInstance("setOrganizationName");
Benjamin Franz3e8a7092016-01-25 16:19:08 +00008644 try {
8645 mService.setOrganizationName(admin, title);
8646 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008647 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00008648 }
8649 }
8650
8651 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07008652 * Called by a profile owner of a managed profile to retrieve the name of the organization under
8653 * management.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00008654 *
8655 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
8656 * @return The organization name or {@code null} if none is set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07008657 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00008658 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07008659 public @Nullable CharSequence getOrganizationName(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008660 throwIfParentInstance("getOrganizationName");
Benjamin Franz3e8a7092016-01-25 16:19:08 +00008661 try {
8662 return mService.getOrganizationName(admin);
8663 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008664 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00008665 }
8666 }
8667
8668 /**
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01008669 * Called by the system to retrieve the name of the organization managing the device.
8670 *
8671 * @return The organization name or {@code null} if none is set.
8672 * @throws SecurityException if the caller is not the device owner, does not hold the
8673 * MANAGE_USERS permission and is not the system.
8674 *
8675 * @hide
8676 */
8677 @SystemApi
8678 @TestApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06008679 @SuppressLint("Doclava125")
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01008680 public @Nullable CharSequence getDeviceOwnerOrganizationName() {
8681 try {
8682 return mService.getDeviceOwnerOrganizationName();
8683 } catch (RemoteException re) {
8684 throw re.rethrowFromSystemServer();
8685 }
8686 }
8687
8688 /**
Benjamin Franz3e8a7092016-01-25 16:19:08 +00008689 * Retrieve the default title message used in the confirm credentials screen for a given user.
8690 *
8691 * @param userHandle The user id of the user we're interested in.
8692 * @return The organization name or {@code null} if none is set.
8693 *
8694 * @hide
8695 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07008696 public @Nullable CharSequence getOrganizationNameForUser(int userHandle) {
Benjamin Franz3e8a7092016-01-25 16:19:08 +00008697 try {
8698 return mService.getOrganizationNameForUser(userHandle);
8699 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008700 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00008701 }
8702 }
8703
8704 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00008705 * @return the {@link UserProvisioningState} for the current user - for unmanaged users will
8706 * return {@link #STATE_USER_UNMANAGED}
8707 * @hide
8708 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00008709 @SystemApi
Eric Sandness3780c092018-03-23 16:16:11 +00008710 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Alan Treadwayafad8782016-01-19 15:15:08 +00008711 @UserProvisioningState
8712 public int getUserProvisioningState() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008713 throwIfParentInstance("getUserProvisioningState");
Alan Treadwayafad8782016-01-19 15:15:08 +00008714 if (mService != null) {
8715 try {
8716 return mService.getUserProvisioningState();
8717 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008718 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00008719 }
8720 }
8721 return STATE_USER_UNMANAGED;
8722 }
8723
8724 /**
8725 * Set the {@link UserProvisioningState} for the supplied user, if they are managed.
8726 *
8727 * @param state to store
8728 * @param userHandle for user
8729 * @hide
8730 */
8731 public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) {
8732 if (mService != null) {
8733 try {
8734 mService.setUserProvisioningState(state, userHandle);
8735 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008736 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00008737 }
8738 }
8739 }
8740
8741 /**
Esteban Talaverac9bb3782016-11-11 15:41:14 +00008742 * Indicates the entity that controls the device or profile owner. Two users/profiles are
8743 * affiliated if the set of ids set by their device or profile owners intersect.
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01008744 *
Alex Chau443b6432017-12-13 12:44:31 +00008745 * <p>A user/profile that is affiliated with the device owner user is considered to be
8746 * affiliated with the device.
8747 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00008748 * <p><strong>Note:</strong> Features that depend on user affiliation (such as security logging
8749 * or {@link #bindDeviceAdminServiceAsUser}) won't be available when a secondary user or profile
8750 * is created, until it becomes affiliated. Therefore it is recommended that the appropriate
8751 * affiliation ids are set by its profile owner as soon as possible after the user/profile is
8752 * created.
8753 *
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01008754 * @param admin Which profile or device owner this request is associated with.
Tony Mak31657432017-04-25 09:29:55 +01008755 * @param ids A set of opaque non-empty affiliation ids.
Esteban Talaverac9bb3782016-11-11 15:41:14 +00008756 *
Tony Mak31657432017-04-25 09:29:55 +01008757 * @throws IllegalArgumentException if {@code ids} is null or contains an empty string.
Alex Chau443b6432017-12-13 12:44:31 +00008758 * @see #isAffiliatedUser
Tony Mak31657432017-04-25 09:29:55 +01008759 */
8760 public void setAffiliationIds(@NonNull ComponentName admin, @NonNull Set<String> ids) {
8761 throwIfParentInstance("setAffiliationIds");
8762 if (ids == null) {
8763 throw new IllegalArgumentException("ids must not be null");
8764 }
8765 try {
8766 mService.setAffiliationIds(admin, new ArrayList<>(ids));
8767 } catch (RemoteException e) {
8768 throw e.rethrowFromSystemServer();
8769 }
8770 }
8771
8772 /**
Tony Mak31657432017-04-25 09:29:55 +01008773 * Returns the set of affiliation ids previously set via {@link #setAffiliationIds}, or an
8774 * empty set if none have been set.
Esteban Talaverac9bb3782016-11-11 15:41:14 +00008775 */
Tony Mak31657432017-04-25 09:29:55 +01008776 public @NonNull Set<String> getAffiliationIds(@NonNull ComponentName admin) {
Tony Mak62cf5862017-05-02 13:50:18 +01008777 throwIfParentInstance("getAffiliationIds");
Esteban Talaverac9bb3782016-11-11 15:41:14 +00008778 try {
Tony Mak31657432017-04-25 09:29:55 +01008779 return new ArraySet<>(mService.getAffiliationIds(admin));
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01008780 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008781 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01008782 }
8783 }
8784
8785 /**
Esteban Talaverac9bb3782016-11-11 15:41:14 +00008786 * Returns whether this user/profile is affiliated with the device.
8787 * <p>
8788 * By definition, the user that the device owner runs on is always affiliated with the device.
8789 * Any other user/profile is considered affiliated with the device if the set specified by its
8790 * profile owner via {@link #setAffiliationIds} intersects with the device owner's.
Alex Chau443b6432017-12-13 12:44:31 +00008791 * @see #setAffiliationIds
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01008792 */
8793 public boolean isAffiliatedUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008794 throwIfParentInstance("isAffiliatedUser");
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01008795 try {
Esteban Talaverac9bb3782016-11-11 15:41:14 +00008796 return mService.isAffiliatedUser();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01008797 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008798 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01008799 }
8800 }
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08008801
8802 /**
8803 * @hide
8804 * Returns whether the uninstall for {@code packageName} for the current user is in queue
8805 * to be started
8806 * @param packageName the package to check for
8807 * @return whether the uninstall intent for {@code packageName} is pending
8808 */
8809 public boolean isUninstallInQueue(String packageName) {
8810 try {
8811 return mService.isUninstallInQueue(packageName);
8812 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008813 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08008814 }
8815 }
8816
8817 /**
8818 * @hide
8819 * @param packageName the package containing active DAs to be uninstalled
8820 */
8821 public void uninstallPackageWithActiveAdmins(String packageName) {
8822 try {
8823 mService.uninstallPackageWithActiveAdmins(packageName);
8824 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008825 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08008826 }
8827 }
Benjamin Franzbc33c822016-04-15 08:57:52 +01008828
Kenny Guy38dcca52016-04-19 13:09:18 +01008829 /**
8830 * @hide
8831 * Remove a test admin synchronously without sending it a broadcast about being removed.
8832 * If the admin is a profile owner or device owner it will still be removed.
8833 *
8834 * @param userHandle user id to remove the admin for.
8835 * @param admin The administration compononent to remove.
8836 * @throws SecurityException if the caller is not shell / root or the admin package
8837 * isn't a test application see {@link ApplicationInfo#FLAG_TEST_APP}.
8838 */
8839 public void forceRemoveActiveAdmin(ComponentName adminReceiver, int userHandle) {
8840 try {
8841 mService.forceRemoveActiveAdmin(adminReceiver, userHandle);
8842 } catch (RemoteException re) {
8843 throw re.rethrowFromSystemServer();
8844 }
8845 }
8846
Mahaver Chopra790d1982016-07-07 16:06:49 +01008847 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01008848 * Returns whether the device has been provisioned.
8849 *
8850 * <p>Not for use by third-party applications.
8851 *
Mahaver Chopra790d1982016-07-07 16:06:49 +01008852 * @hide
Mahaver Chopra790d1982016-07-07 16:06:49 +01008853 */
Lenka Trochtova5291ee72016-11-28 16:38:23 +01008854 @SystemApi
Eric Sandnessdf30c7d2018-03-27 09:56:40 +01008855 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Mahaver Chopra790d1982016-07-07 16:06:49 +01008856 public boolean isDeviceProvisioned() {
8857 try {
8858 return mService.isDeviceProvisioned();
8859 } catch (RemoteException re) {
8860 throw re.rethrowFromSystemServer();
8861 }
8862 }
8863
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01008864 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01008865 * Writes that the provisioning configuration has been applied.
8866 *
8867 * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS}
8868 * permission.
8869 *
8870 * <p>Not for use by third-party applications.
8871 *
8872 * @hide
8873 */
8874 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06008875 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01008876 public void setDeviceProvisioningConfigApplied() {
8877 try {
8878 mService.setDeviceProvisioningConfigApplied();
8879 } catch (RemoteException re) {
8880 throw re.rethrowFromSystemServer();
8881 }
8882 }
8883
8884 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01008885 * Returns whether the provisioning configuration has been applied.
8886 *
8887 * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS} permission.
8888 *
8889 * <p>Not for use by third-party applications.
8890 *
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01008891 * @return whether the provisioning configuration has been applied.
Lenka Trochtova5291ee72016-11-28 16:38:23 +01008892 *
8893 * @hide
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01008894 */
Lenka Trochtova5291ee72016-11-28 16:38:23 +01008895 @SystemApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06008896 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01008897 public boolean isDeviceProvisioningConfigApplied() {
8898 try {
8899 return mService.isDeviceProvisioningConfigApplied();
8900 } catch (RemoteException re) {
8901 throw re.rethrowFromSystemServer();
8902 }
8903 }
8904
Victor Chang9bfc65f2016-08-15 12:27:09 +01008905 /**
8906 * @hide
Victor Chang3577ed22016-08-25 18:49:26 +01008907 * Force update user setup completed status. This API has no effect on user build.
8908 * @throws {@link SecurityException} if the caller has no
Esteban Talavera01576862016-12-15 11:16:44 +00008909 * {@code android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS} or the caller is
8910 * not {@link UserHandle#SYSTEM_USER}
Victor Chang9bfc65f2016-08-15 12:27:09 +01008911 */
8912 public void forceUpdateUserSetupComplete() {
8913 try {
8914 mService.forceUpdateUserSetupComplete();
8915 } catch (RemoteException re) {
8916 throw re.rethrowFromSystemServer();
8917 }
8918 }
8919
Mathew Inwood4fb17d12018-08-14 14:25:44 +01008920 @UnsupportedAppUsage
Benjamin Franzbc33c822016-04-15 08:57:52 +01008921 private void throwIfParentInstance(String functionName) {
8922 if (mParentInstance) {
8923 throw new SecurityException(functionName + " cannot be called on the parent instance");
8924 }
8925 }
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02008926
8927 /**
Michal Karpinskib71fedc2017-01-05 15:21:38 +00008928 * Allows the device owner to enable or disable the backup service.
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02008929 *
Michal Karpinskib71fedc2017-01-05 15:21:38 +00008930 * <p> Backup service manages all backup and restore mechanisms on the device. Setting this to
8931 * false will prevent data from being backed up or restored.
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02008932 *
Michal Karpinskib71fedc2017-01-05 15:21:38 +00008933 * <p> Backup service is off by default when device owner is present.
8934 *
Rubin Xu0367f072017-04-24 20:17:16 +01008935 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
8936 * @param enabled {@code true} to enable the backup service, {@code false} to disable it.
Michal Karpinskib71fedc2017-01-05 15:21:38 +00008937 * @throws SecurityException if {@code admin} is not a device owner.
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02008938 */
8939 public void setBackupServiceEnabled(@NonNull ComponentName admin, boolean enabled) {
Esteban Talavera5b7f2d02017-02-17 09:45:24 +00008940 throwIfParentInstance("setBackupServiceEnabled");
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02008941 try {
8942 mService.setBackupServiceEnabled(admin, enabled);
8943 } catch (RemoteException re) {
8944 throw re.rethrowFromSystemServer();
8945 }
8946 }
8947
8948 /**
Michal Karpinskib71fedc2017-01-05 15:21:38 +00008949 * Return whether the backup service is enabled by the device owner.
8950 *
8951 * <p> Backup service manages all backup and restore mechanisms on the device.
8952 *
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02008953 * @return {@code true} if backup service is enabled, {@code false} otherwise.
Michal Karpinskib71fedc2017-01-05 15:21:38 +00008954 * @see #setBackupServiceEnabled
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02008955 */
8956 public boolean isBackupServiceEnabled(@NonNull ComponentName admin) {
Esteban Talavera5b7f2d02017-02-17 09:45:24 +00008957 throwIfParentInstance("isBackupServiceEnabled");
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02008958 try {
8959 return mService.isBackupServiceEnabled(admin);
8960 } catch (RemoteException re) {
8961 throw re.rethrowFromSystemServer();
8962 }
8963 }
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01008964
8965 /**
Lenka Trochtovac141d082017-12-20 14:45:16 +01008966 * Makes backups mandatory and enforces the usage of the specified backup transport.
8967 *
8968 * <p>When a {@code null} backup transport is specified, backups are made optional again.
8969 * <p>Only device owner can call this method.
8970 * <p>If backups were disabled and a non-null backup transport {@link ComponentName} is
8971 * specified, backups will be enabled.
Lenka Trochtova27fd8212018-04-10 11:01:58 +02008972 * <p> If the backup service is disabled after the mandatory backup transport has been set, the
8973 * mandatory backup transport is cleared.
Lenka Trochtovac141d082017-12-20 14:45:16 +01008974 *
Lenka Trochtova56681f72018-03-09 15:47:50 +01008975 * <p>NOTE: The method shouldn't be called on the main thread.
8976 *
Lenka Trochtovac141d082017-12-20 14:45:16 +01008977 * @param admin admin Which {@link DeviceAdminReceiver} this request is associated with.
8978 * @param backupTransportComponent The backup transport layer to be used for mandatory backups.
Lenka Trochtova56681f72018-03-09 15:47:50 +01008979 * @return {@code true} if the backup transport was successfully set; {@code false} otherwise.
Lenka Trochtovac141d082017-12-20 14:45:16 +01008980 * @throws SecurityException if {@code admin} is not a device owner.
Lenka Trochtova27fd8212018-04-10 11:01:58 +02008981 * @hide
Lenka Trochtovac141d082017-12-20 14:45:16 +01008982 */
Lenka Trochtova56681f72018-03-09 15:47:50 +01008983 @WorkerThread
8984 public boolean setMandatoryBackupTransport(
8985 @NonNull ComponentName admin,
8986 @Nullable ComponentName backupTransportComponent) {
Lenka Trochtova62900122018-01-23 14:55:46 +01008987 throwIfParentInstance("setMandatoryBackupTransport");
Lenka Trochtovac141d082017-12-20 14:45:16 +01008988 try {
Lenka Trochtova56681f72018-03-09 15:47:50 +01008989 return mService.setMandatoryBackupTransport(admin, backupTransportComponent);
Lenka Trochtovac141d082017-12-20 14:45:16 +01008990 } catch (RemoteException re) {
8991 throw re.rethrowFromSystemServer();
8992 }
8993 }
8994
8995 /**
8996 * Returns the backup transport which has to be used for backups if backups are mandatory or
8997 * {@code null} if backups are not mandatory.
8998 *
8999 * @return a {@link ComponentName} of the backup transport layer to be used if backups are
9000 * mandatory or {@code null} if backups are not mandatory.
Lenka Trochtova27fd8212018-04-10 11:01:58 +02009001 * @hide
Lenka Trochtovac141d082017-12-20 14:45:16 +01009002 */
Mathew Inwood4fb17d12018-08-14 14:25:44 +01009003 @UnsupportedAppUsage
Lenka Trochtovac141d082017-12-20 14:45:16 +01009004 public ComponentName getMandatoryBackupTransport() {
Lenka Trochtova62900122018-01-23 14:55:46 +01009005 throwIfParentInstance("getMandatoryBackupTransport");
Lenka Trochtovac141d082017-12-20 14:45:16 +01009006 try {
9007 return mService.getMandatoryBackupTransport();
9008 } catch (RemoteException re) {
9009 throw re.rethrowFromSystemServer();
9010 }
9011 }
9012
9013
9014 /**
Esteban Talaverad36dd152016-12-15 08:51:45 +00009015 * Called by a device owner to control the network logging feature.
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01009016 *
Robin Leea40a2fb2017-02-08 17:07:06 +00009017 * <p> Network logs contain DNS lookup and connect() library call events. The following library
9018 * functions are recorded while network logging is active:
9019 * <ul>
9020 * <li>{@code getaddrinfo()}</li>
9021 * <li>{@code gethostbyname()}</li>
9022 * <li>{@code connect()}</li>
9023 * </ul>
9024 *
9025 * <p> Network logging is a low-overhead tool for forensics but it is not guaranteed to use
9026 * full system call logging; event reporting is enabled by default for all processes but not
9027 * strongly enforced.
9028 * Events from applications using alternative implementations of libc, making direct kernel
9029 * calls, or deliberately obfuscating traffic may not be recorded.
9030 *
9031 * <p> Some common network events may not be reported. For example:
9032 * <ul>
9033 * <li>Applications may hardcode IP addresses to reduce the number of DNS lookups, or use
9034 * an alternative system for name resolution, and so avoid calling
9035 * {@code getaddrinfo()} or {@code gethostbyname}.</li>
9036 * <li>Applications may use datagram sockets for performance reasons, for example
9037 * for a game client. Calling {@code connect()} is unnecessary for this kind of
9038 * socket, so it will not trigger a network event.</li>
9039 * </ul>
9040 *
9041 * <p> It is possible to directly intercept layer 3 traffic leaving the device using an
9042 * always-on VPN service.
9043 * See {@link #setAlwaysOnVpnPackage(ComponentName, String, boolean)}
9044 * and {@link android.net.VpnService} for details.
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01009045 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00009046 * <p><strong>Note:</strong> The device owner won't be able to retrieve network logs if there
9047 * are unaffiliated secondary users or profiles on the device, regardless of whether the
9048 * feature is enabled. Logs will be discarded if the internal buffer fills up while waiting for
9049 * all users to become affiliated. Therefore it's recommended that affiliation ids are set for
9050 * new users as soon as possible after provisioning via {@link #setAffiliationIds}.
9051 *
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01009052 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
9053 * @param enabled whether network logging should be enabled or not.
Esteban Talaverad36dd152016-12-15 08:51:45 +00009054 * @throws SecurityException if {@code admin} is not a device owner.
Alex Chau443b6432017-12-13 12:44:31 +00009055 * @see #setAffiliationIds
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01009056 * @see #retrieveNetworkLogs
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01009057 */
9058 public void setNetworkLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
9059 throwIfParentInstance("setNetworkLoggingEnabled");
9060 try {
9061 mService.setNetworkLoggingEnabled(admin, enabled);
9062 } catch (RemoteException re) {
9063 throw re.rethrowFromSystemServer();
9064 }
9065 }
9066
9067 /**
9068 * Return whether network logging is enabled by a device owner.
9069 *
phweissa4e169e2016-11-24 16:20:57 +01009070 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Can only
9071 * be {@code null} if the caller has MANAGE_USERS permission.
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01009072 * @return {@code true} if network logging is enabled by device owner, {@code false} otherwise.
Esteban Talaverad36dd152016-12-15 08:51:45 +00009073 * @throws SecurityException if {@code admin} is not a device owner and caller has
phweissa4e169e2016-11-24 16:20:57 +01009074 * no MANAGE_USERS permission
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01009075 */
phweissa4e169e2016-11-24 16:20:57 +01009076 public boolean isNetworkLoggingEnabled(@Nullable ComponentName admin) {
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01009077 throwIfParentInstance("isNetworkLoggingEnabled");
9078 try {
9079 return mService.isNetworkLoggingEnabled(admin);
9080 } catch (RemoteException re) {
9081 throw re.rethrowFromSystemServer();
9082 }
9083 }
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01009084
9085 /**
Michal Karpinskia9ff2062016-11-03 15:46:17 +00009086 * Called by device owner to retrieve the most recent batch of network logging events.
9087 * A device owner has to provide a batchToken provided as part of
9088 * {@link DeviceAdminReceiver#onNetworkLogsAvailable} callback. If the token doesn't match the
9089 * token of the most recent available batch of logs, {@code null} will be returned.
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01009090 *
9091 * <p> {@link NetworkEvent} can be one of {@link DnsEvent} or {@link ConnectEvent}.
9092 *
9093 * <p> The list of network events is sorted chronologically, and contains at most 1200 events.
9094 *
9095 * <p> Access to the logs is rate limited and this method will only return a new batch of logs
9096 * after the device device owner has been notified via
9097 * {@link DeviceAdminReceiver#onNetworkLogsAvailable}.
9098 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00009099 * <p>If a secondary user or profile is created, calling this method will throw a
9100 * {@link SecurityException} until all users become affiliated again. It will also no longer be
9101 * possible to retrieve the network logs batch with the most recent batchToken provided
9102 * by {@link DeviceAdminReceiver#onNetworkLogsAvailable}. See
9103 * {@link DevicePolicyManager#setAffiliationIds}.
9104 *
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01009105 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinskia9ff2062016-11-03 15:46:17 +00009106 * @param batchToken A token of the batch to retrieve
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01009107 * @return A new batch of network logs which is a list of {@link NetworkEvent}. Returns
Michal Karpinskia9ff2062016-11-03 15:46:17 +00009108 * {@code null} if the batch represented by batchToken is no longer available or if
9109 * logging is disabled.
Esteban Talaverad36dd152016-12-15 08:51:45 +00009110 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
Alex Chau443b6432017-12-13 12:44:31 +00009111 * profile or secondary user that is not affiliated with the device.
9112 * @see #setAffiliationIds
Michal Karpinskia9ff2062016-11-03 15:46:17 +00009113 * @see DeviceAdminReceiver#onNetworkLogsAvailable
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01009114 */
Michal Karpinskia9ff2062016-11-03 15:46:17 +00009115 public @Nullable List<NetworkEvent> retrieveNetworkLogs(@NonNull ComponentName admin,
9116 long batchToken) {
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01009117 throwIfParentInstance("retrieveNetworkLogs");
9118 try {
Michal Karpinskia9ff2062016-11-03 15:46:17 +00009119 return mService.retrieveNetworkLogs(admin, batchToken);
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01009120 } catch (RemoteException re) {
9121 throw re.rethrowFromSystemServer();
9122 }
9123 }
Tony Mak46aabe52016-11-14 12:53:06 +00009124
9125 /**
Esteban Talavera2f897912017-01-26 10:30:48 +00009126 * Called by a device owner to bind to a service from a profile owner or vice versa.
9127 * See {@link #getBindDeviceAdminTargetUsers} for a definition of which
Esteban Talaverafc291bc2016-11-21 13:52:03 +00009128 * device/profile owners are allowed to bind to services of another profile/device owner.
9129 * <p>
Tony Makeda0a9a2017-04-25 12:07:14 +01009130 * The service must be protected by {@link android.Manifest.permission#BIND_DEVICE_ADMIN}.
9131 * Note that the {@link Context} used to obtain this
Tony Mak46aabe52016-11-14 12:53:06 +00009132 * {@link DevicePolicyManager} instance via {@link Context#getSystemService(Class)} will be used
9133 * to bind to the {@link android.app.Service}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00009134 *
Tony Mak46aabe52016-11-14 12:53:06 +00009135 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
9136 * @param serviceIntent Identifies the service to connect to. The Intent must specify either an
9137 * explicit component name or a package name to match an
9138 * {@link IntentFilter} published by a service.
Tony Makbf9928d2016-12-22 11:02:45 +00009139 * @param conn Receives information as the service is started and stopped in main thread. This
9140 * must be a valid {@link ServiceConnection} object; it must not be {@code null}.
Tony Mak46aabe52016-11-14 12:53:06 +00009141 * @param flags Operation options for the binding operation. See
9142 * {@link Context#bindService(Intent, ServiceConnection, int)}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00009143 * @param targetUser Which user to bind to. Must be one of the users returned by
9144 * {@link #getBindDeviceAdminTargetUsers}, otherwise a {@link SecurityException} will
9145 * be thrown.
Tony Mak46aabe52016-11-14 12:53:06 +00009146 * @return If you have successfully bound to the service, {@code true} is returned;
9147 * {@code false} is returned if the connection is not made and you will not
9148 * receive the service object.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00009149 *
Tony Mak46aabe52016-11-14 12:53:06 +00009150 * @see Context#bindService(Intent, ServiceConnection, int)
Esteban Talaverafc291bc2016-11-21 13:52:03 +00009151 * @see #getBindDeviceAdminTargetUsers(ComponentName)
Tony Mak46aabe52016-11-14 12:53:06 +00009152 */
9153 public boolean bindDeviceAdminServiceAsUser(
9154 @NonNull ComponentName admin, Intent serviceIntent, @NonNull ServiceConnection conn,
9155 @Context.BindServiceFlags int flags, @NonNull UserHandle targetUser) {
9156 throwIfParentInstance("bindDeviceAdminServiceAsUser");
9157 // Keep this in sync with ContextImpl.bindServiceCommon.
9158 try {
Tony Makbf9928d2016-12-22 11:02:45 +00009159 final IServiceConnection sd = mContext.getServiceDispatcher(
9160 conn, mContext.getMainThreadHandler(), flags);
Tony Mak46aabe52016-11-14 12:53:06 +00009161 serviceIntent.prepareToLeaveProcess(mContext);
9162 return mService.bindDeviceAdminServiceAsUser(admin,
9163 mContext.getIApplicationThread(), mContext.getActivityToken(), serviceIntent,
9164 sd, flags, targetUser.getIdentifier());
9165 } catch (RemoteException re) {
9166 throw re.rethrowFromSystemServer();
9167 }
9168 }
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01009169
9170 /**
Esteban Talaverafc291bc2016-11-21 13:52:03 +00009171 * Returns the list of target users that the calling device or profile owner can use when
9172 * calling {@link #bindDeviceAdminServiceAsUser}.
9173 * <p>
Esteban Talavera2f897912017-01-26 10:30:48 +00009174 * A device owner can bind to a service from a profile owner and vice versa, provided that:
Esteban Talaverafc291bc2016-11-21 13:52:03 +00009175 * <ul>
9176 * <li>Both belong to the same package name.
Esteban Talavera2f897912017-01-26 10:30:48 +00009177 * <li>Both users are affiliated. See {@link #setAffiliationIds}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00009178 * </ul>
9179 */
9180 public @NonNull List<UserHandle> getBindDeviceAdminTargetUsers(@NonNull ComponentName admin) {
9181 throwIfParentInstance("getBindDeviceAdminTargetUsers");
9182 try {
9183 return mService.getBindDeviceAdminTargetUsers(admin);
9184 } catch (RemoteException re) {
9185 throw re.rethrowFromSystemServer();
9186 }
9187 }
9188
9189 /**
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01009190 * Called by the system to get the time at which the device owner last retrieved security
9191 * logging entries.
9192 *
9193 * @return the time at which the device owner most recently retrieved security logging entries,
9194 * in milliseconds since epoch; -1 if security logging entries were never retrieved.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01009195 * @throws SecurityException if the caller is not the device owner, does not hold the
9196 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01009197 *
9198 * @hide
9199 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01009200 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01009201 public long getLastSecurityLogRetrievalTime() {
9202 try {
9203 return mService.getLastSecurityLogRetrievalTime();
9204 } catch (RemoteException re) {
9205 throw re.rethrowFromSystemServer();
9206 }
9207 }
9208
9209 /**
9210 * Called by the system to get the time at which the device owner last requested a bug report.
9211 *
9212 * @return the time at which the device owner most recently requested a bug report, in
9213 * milliseconds since epoch; -1 if a bug report was never requested.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01009214 * @throws SecurityException if the caller is not the device owner, does not hold the
9215 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01009216 *
9217 * @hide
9218 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01009219 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01009220 public long getLastBugReportRequestTime() {
9221 try {
9222 return mService.getLastBugReportRequestTime();
9223 } catch (RemoteException re) {
9224 throw re.rethrowFromSystemServer();
9225 }
9226 }
9227
9228 /**
9229 * Called by the system to get the time at which the device owner last retrieved network logging
9230 * events.
9231 *
9232 * @return the time at which the device owner most recently retrieved network logging events, in
9233 * milliseconds since epoch; -1 if network logging events were never retrieved.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01009234 * @throws SecurityException if the caller is not the device owner, does not hold the
9235 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01009236 *
9237 * @hide
9238 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01009239 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01009240 public long getLastNetworkLogRetrievalTime() {
9241 try {
9242 return mService.getLastNetworkLogRetrievalTime();
9243 } catch (RemoteException re) {
9244 throw re.rethrowFromSystemServer();
9245 }
9246 }
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01009247
9248 /**
Bartosz Fabianowski172f7802017-03-06 12:07:57 +01009249 * Called by the system to find out whether the current user's IME was set by the device/profile
9250 * owner or the user.
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01009251 *
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01009252 * @return {@code true} if the user's IME was set by the device or profile owner, {@code false}
9253 * otherwise.
Bartosz Fabianowski172f7802017-03-06 12:07:57 +01009254 * @throws SecurityException if the caller is not the device owner/profile owner.
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01009255 *
9256 * @hide
9257 */
9258 @TestApi
Bartosz Fabianowski172f7802017-03-06 12:07:57 +01009259 public boolean isCurrentInputMethodSetByOwner() {
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01009260 try {
Bartosz Fabianowski172f7802017-03-06 12:07:57 +01009261 return mService.isCurrentInputMethodSetByOwner();
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01009262 } catch (RemoteException re) {
9263 throw re.rethrowFromSystemServer();
9264 }
9265 }
Bartosz Fabianowski05dc9f72017-02-22 23:41:14 +01009266
Bartosz Fabianowski05dc9f72017-02-22 23:41:14 +01009267 /**
9268 * Called by the system to get a list of CA certificates that were installed by the device or
9269 * profile owner.
9270 *
Bartosz Fabianowski172f7802017-03-06 12:07:57 +01009271 * <p> The caller must be the target user's device owner/profile Owner or hold the
Bartosz Fabianowski05dc9f72017-02-22 23:41:14 +01009272 * {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} permission.
9273 *
9274 * @param user The user for whom to retrieve information.
9275 * @return list of aliases identifying CA certificates installed by the device or profile owner
9276 * @throws SecurityException if the caller does not have permission to retrieve information
9277 * about the given user's CA certificates.
9278 *
9279 * @hide
9280 */
9281 @TestApi
9282 public List<String> getOwnerInstalledCaCerts(@NonNull UserHandle user) {
9283 try {
9284 return mService.getOwnerInstalledCaCerts(user).getList();
9285 } catch (RemoteException re) {
9286 throw re.rethrowFromSystemServer();
9287 }
9288 }
Benjamin Franza77e3572017-06-23 12:01:44 +01009289
9290 /**
9291 * Called by the device owner or profile owner to clear application user data of a given
9292 * package. The behaviour of this is equivalent to the target application calling
9293 * {@link android.app.ActivityManager#clearApplicationUserData()}.
9294 *
9295 * <p><strong>Note:</strong> an application can store data outside of its application data, e.g.
9296 * external storage or user dictionary. This data will not be wiped by calling this API.
9297 *
9298 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
9299 * @param packageName The name of the package which will have its user data wiped.
Jeff Sharkey8439ac02017-12-12 17:26:23 -07009300 * @param executor The executor through which the listener should be invoked.
Alex Chau4a4285b2018-01-12 13:35:06 +00009301 * @param listener A callback object that will inform the caller when the clearing is done.
Benjamin Franza77e3572017-06-23 12:01:44 +01009302 * @throws SecurityException if the caller is not the device owner/profile owner.
Benjamin Franza77e3572017-06-23 12:01:44 +01009303 */
Alex Chau1033e382018-01-25 15:53:39 +00009304 public void clearApplicationUserData(@NonNull ComponentName admin,
Alex Chau4a4285b2018-01-12 13:35:06 +00009305 @NonNull String packageName, @NonNull @CallbackExecutor Executor executor,
9306 @NonNull OnClearApplicationUserDataListener listener) {
Benjamin Franza77e3572017-06-23 12:01:44 +01009307 throwIfParentInstance("clearAppData");
Jeff Sharkey8439ac02017-12-12 17:26:23 -07009308 Preconditions.checkNotNull(executor);
Alex Chau1033e382018-01-25 15:53:39 +00009309 Preconditions.checkNotNull(listener);
Benjamin Franza77e3572017-06-23 12:01:44 +01009310 try {
Alex Chau1033e382018-01-25 15:53:39 +00009311 mService.clearApplicationUserData(admin, packageName,
Benjamin Franza77e3572017-06-23 12:01:44 +01009312 new IPackageDataObserver.Stub() {
9313 public void onRemoveCompleted(String pkg, boolean succeeded) {
Jeff Sharkey8439ac02017-12-12 17:26:23 -07009314 executor.execute(() ->
Benjamin Franza77e3572017-06-23 12:01:44 +01009315 listener.onApplicationUserDataCleared(pkg, succeeded));
9316 }
9317 });
9318 } catch (RemoteException re) {
9319 throw re.rethrowFromSystemServer();
9320 }
9321 }
9322
9323 /**
Alex Chaud7958272017-12-08 11:30:52 +00009324 * Called by a device owner to specify whether logout is enabled for all secondary users. The
9325 * system may show a logout button that stops the user and switches back to the primary user.
Alex Chau04458852017-11-27 18:21:23 +00009326 *
9327 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Alex Chaud7958272017-12-08 11:30:52 +00009328 * @param enabled whether logout should be enabled or not.
Alex Chau04458852017-11-27 18:21:23 +00009329 * @throws SecurityException if {@code admin} is not a device owner.
9330 */
Alex Chaud7958272017-12-08 11:30:52 +00009331 public void setLogoutEnabled(@NonNull ComponentName admin, boolean enabled) {
9332 throwIfParentInstance("setLogoutEnabled");
Alex Chau04458852017-11-27 18:21:23 +00009333 try {
Alex Chaud7958272017-12-08 11:30:52 +00009334 mService.setLogoutEnabled(admin, enabled);
Alex Chau04458852017-11-27 18:21:23 +00009335 } catch (RemoteException re) {
9336 throw re.rethrowFromSystemServer();
9337 }
9338 }
9339
9340 /**
Alex Chaud7958272017-12-08 11:30:52 +00009341 * Returns whether logout is enabled by a device owner.
Alex Chau04458852017-11-27 18:21:23 +00009342 *
Alex Chaud7958272017-12-08 11:30:52 +00009343 * @return {@code true} if logout is enabled by device owner, {@code false} otherwise.
Alex Chau04458852017-11-27 18:21:23 +00009344 */
Alex Chaud7958272017-12-08 11:30:52 +00009345 public boolean isLogoutEnabled() {
9346 throwIfParentInstance("isLogoutEnabled");
Alex Chau04458852017-11-27 18:21:23 +00009347 try {
Alex Chaud7958272017-12-08 11:30:52 +00009348 return mService.isLogoutEnabled();
Alex Chau04458852017-11-27 18:21:23 +00009349 } catch (RemoteException re) {
9350 throw re.rethrowFromSystemServer();
9351 }
9352 }
9353
9354 /**
Benjamin Franza77e3572017-06-23 12:01:44 +01009355 * Callback used in {@link #clearApplicationUserData}
9356 * to indicate that the clearing of an application's user data is done.
9357 */
9358 public interface OnClearApplicationUserDataListener {
9359 /**
9360 * Method invoked when clearing the application user data has completed.
9361 *
9362 * @param packageName The name of the package which had its user data cleared.
9363 * @param succeeded Whether the clearing succeeded. Clearing fails for device administrator
9364 * apps and protected system packages.
9365 */
9366 void onApplicationUserDataCleared(String packageName, boolean succeeded);
9367 }
Alex Chaub6a9f942017-11-07 11:28:56 +08009368
9369 /**
9370 * Returns set of system apps that should be removed during provisioning.
9371 *
9372 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
9373 * @param userId ID of the user to be provisioned.
9374 * @param provisioningAction action indicating type of provisioning, should be one of
9375 * {@link #ACTION_PROVISION_MANAGED_DEVICE}, {@link #ACTION_PROVISION_MANAGED_PROFILE} or
9376 * {@link #ACTION_PROVISION_MANAGED_USER}.
9377 *
9378 * @hide
9379 */
9380 public Set<String> getDisallowedSystemApps(ComponentName admin, int userId,
9381 String provisioningAction) {
9382 try {
9383 return new ArraySet<>(
9384 mService.getDisallowedSystemApps(admin, userId, provisioningAction));
9385 } catch (RemoteException re) {
9386 throw re.rethrowFromSystemServer();
9387 }
9388 }
arangelov08841ef2017-11-23 15:29:42 +00009389
arangelov08841ef2017-11-23 15:29:42 +00009390 /**
arangelov8bae4ea2017-12-20 20:26:46 +00009391 * Changes the current administrator to another one. All policies from the current
9392 * administrator are migrated to the new administrator. The whole operation is atomic -
9393 * the transfer is either complete or not done at all.
arangelov08841ef2017-11-23 15:29:42 +00009394 *
arangelov8bae4ea2017-12-20 20:26:46 +00009395 * <p>Depending on the current administrator (device owner, profile owner), you have the
9396 * following expected behaviour:
arangelov08841ef2017-11-23 15:29:42 +00009397 * <ul>
9398 * <li>A device owner can only be transferred to a new device owner</li>
9399 * <li>A profile owner can only be transferred to a new profile owner</li>
arangelov08841ef2017-11-23 15:29:42 +00009400 * </ul>
9401 *
arangelov91201bd2018-01-04 17:10:21 +00009402 * <p>Use the {@code bundle} parameter to pass data to the new administrator. The data
arangelov8bae4ea2017-12-20 20:26:46 +00009403 * will be received in the
arangelov91201bd2018-01-04 17:10:21 +00009404 * {@link DeviceAdminReceiver#onTransferOwnershipComplete(Context, PersistableBundle)}
9405 * callback of the new administrator.
9406 *
9407 * <p>The transfer has failed if the original administrator is still the corresponding owner
9408 * after calling this method.
arangelov8bae4ea2017-12-20 20:26:46 +00009409 *
arangelov5149d7162018-01-11 19:48:14 +00009410 * <p>The incoming target administrator must have the
arangelovc8ee2632018-02-23 16:45:53 +00009411 * <code>&lt;support-transfer-ownership /&gt;</code> tag inside the
9412 * <code>&lt;device-admin&gt;&lt;/device-admin&gt;</code> tags in the xml file referenced by
9413 * {@link DeviceAdminReceiver#DEVICE_ADMIN_META_DATA}. Otherwise an
9414 * {@link IllegalArgumentException} will be thrown.
arangelov5149d7162018-01-11 19:48:14 +00009415 *
arangelov8bae4ea2017-12-20 20:26:46 +00009416 * @param admin which {@link DeviceAdminReceiver} this request is associated with
9417 * @param target which {@link DeviceAdminReceiver} we want the new administrator to be
9418 * @param bundle data to be sent to the new administrator
9419 * @throws SecurityException if {@code admin} is not a device owner nor a profile owner
arangelov91201bd2018-01-04 17:10:21 +00009420 * @throws IllegalArgumentException if {@code admin} or {@code target} is {@code null}, they
9421 * are components in the same package or {@code target} is not an active admin
arangelov08841ef2017-11-23 15:29:42 +00009422 */
arangelov8bae4ea2017-12-20 20:26:46 +00009423 public void transferOwnership(@NonNull ComponentName admin, @NonNull ComponentName target,
arangelov91201bd2018-01-04 17:10:21 +00009424 @Nullable PersistableBundle bundle) {
arangelov8bae4ea2017-12-20 20:26:46 +00009425 throwIfParentInstance("transferOwnership");
arangelov08841ef2017-11-23 15:29:42 +00009426 try {
arangelov8bae4ea2017-12-20 20:26:46 +00009427 mService.transferOwnership(admin, target, bundle);
arangelov08841ef2017-11-23 15:29:42 +00009428 } catch (RemoteException re) {
9429 throw re.rethrowFromSystemServer();
9430 }
9431 }
Alex Chau93ae42b2018-01-11 15:10:12 +00009432
9433 /**
9434 * Called by a device owner to specify the user session start message. This may be displayed
9435 * during a user switch.
9436 * <p>
9437 * The message should be limited to a short statement or it may be truncated.
9438 * <p>
9439 * If the message needs to be localized, it is the responsibility of the
9440 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
9441 * and set a new version of this message accordingly.
9442 *
9443 * @param admin which {@link DeviceAdminReceiver} this request is associated with.
9444 * @param startUserSessionMessage message for starting user session, or {@code null} to use
9445 * system default message.
9446 * @throws SecurityException if {@code admin} is not a device owner.
9447 */
9448 public void setStartUserSessionMessage(
9449 @NonNull ComponentName admin, @Nullable CharSequence startUserSessionMessage) {
9450 throwIfParentInstance("setStartUserSessionMessage");
9451 try {
9452 mService.setStartUserSessionMessage(admin, startUserSessionMessage);
9453 } catch (RemoteException re) {
9454 throw re.rethrowFromSystemServer();
9455 }
9456 }
9457
9458 /**
9459 * Called by a device owner to specify the user session end message. This may be displayed
9460 * during a user switch.
9461 * <p>
9462 * The message should be limited to a short statement or it may be truncated.
9463 * <p>
9464 * If the message needs to be localized, it is the responsibility of the
9465 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
9466 * and set a new version of this message accordingly.
9467 *
9468 * @param admin which {@link DeviceAdminReceiver} this request is associated with.
9469 * @param endUserSessionMessage message for ending user session, or {@code null} to use system
9470 * default message.
9471 * @throws SecurityException if {@code admin} is not a device owner.
9472 */
9473 public void setEndUserSessionMessage(
9474 @NonNull ComponentName admin, @Nullable CharSequence endUserSessionMessage) {
9475 throwIfParentInstance("setEndUserSessionMessage");
9476 try {
9477 mService.setEndUserSessionMessage(admin, endUserSessionMessage);
9478 } catch (RemoteException re) {
9479 throw re.rethrowFromSystemServer();
9480 }
9481 }
9482
9483 /**
9484 * Returns the user session start message.
9485 *
9486 * @param admin which {@link DeviceAdminReceiver} this request is associated with.
9487 * @throws SecurityException if {@code admin} is not a device owner.
9488 */
9489 public CharSequence getStartUserSessionMessage(@NonNull ComponentName admin) {
9490 throwIfParentInstance("getStartUserSessionMessage");
9491 try {
9492 return mService.getStartUserSessionMessage(admin);
9493 } catch (RemoteException re) {
9494 throw re.rethrowFromSystemServer();
9495 }
9496 }
9497
9498 /**
9499 * Returns the user session end message.
9500 *
9501 * @param admin which {@link DeviceAdminReceiver} this request is associated with.
9502 * @throws SecurityException if {@code admin} is not a device owner.
9503 */
9504 public CharSequence getEndUserSessionMessage(@NonNull ComponentName admin) {
9505 throwIfParentInstance("getEndUserSessionMessage");
9506 try {
9507 return mService.getEndUserSessionMessage(admin);
9508 } catch (RemoteException re) {
9509 throw re.rethrowFromSystemServer();
9510 }
9511 }
Vladislav Kuzkokov792d58f2018-01-15 15:04:05 +01009512
9513 /**
yuemingwe3d9c092018-01-11 12:11:44 +00009514 * Called by device owner to add an override APN.
9515 *
yuemingwedfd36a2018-02-26 14:25:35 +00009516 * <p>This method may returns {@code -1} if {@code apnSetting} conflicts with an existing
9517 * override APN. Update the existing conflicted APN with
9518 * {@link #updateOverrideApn(ComponentName, int, ApnSetting)} instead of adding a new entry.
yuemingw6586f052018-03-21 16:32:09 +00009519 * <p>Two override APNs are considered to conflict when all the following APIs return
9520 * the same values on both override APNs:
9521 * <ul>
9522 * <li>{@link ApnSetting#getOperatorNumeric()}</li>
9523 * <li>{@link ApnSetting#getApnName()}</li>
yuemingw9bf808c2018-04-09 16:41:54 +01009524 * <li>{@link ApnSetting#getProxyAddressAsString()}</li>
yuemingw6586f052018-03-21 16:32:09 +00009525 * <li>{@link ApnSetting#getProxyPort()}</li>
yuemingw9bf808c2018-04-09 16:41:54 +01009526 * <li>{@link ApnSetting#getMmsProxyAddressAsString()}</li>
yuemingw6586f052018-03-21 16:32:09 +00009527 * <li>{@link ApnSetting#getMmsProxyPort()}</li>
9528 * <li>{@link ApnSetting#getMmsc()}</li>
9529 * <li>{@link ApnSetting#isEnabled()}</li>
9530 * <li>{@link ApnSetting#getMvnoType()}</li>
9531 * <li>{@link ApnSetting#getProtocol()}</li>
9532 * <li>{@link ApnSetting#getRoamingProtocol()}</li>
9533 * </ul>
yuemingwedfd36a2018-02-26 14:25:35 +00009534 *
yuemingwe3d9c092018-01-11 12:11:44 +00009535 * @param admin which {@link DeviceAdminReceiver} this request is associated with
9536 * @param apnSetting the override APN to insert
9537 * @return The {@code id} of inserted override APN. Or {@code -1} when failed to insert into
9538 * the database.
9539 * @throws SecurityException if {@code admin} is not a device owner.
9540 *
9541 * @see #setOverrideApnsEnabled(ComponentName, boolean)
9542 */
9543 public int addOverrideApn(@NonNull ComponentName admin, @NonNull ApnSetting apnSetting) {
9544 throwIfParentInstance("addOverrideApn");
9545 if (mService != null) {
9546 try {
9547 return mService.addOverrideApn(admin, apnSetting);
9548 } catch (RemoteException e) {
9549 throw e.rethrowFromSystemServer();
9550 }
9551 }
9552 return -1;
9553 }
9554
9555 /**
9556 * Called by device owner to update an override APN.
9557 *
yuemingwedfd36a2018-02-26 14:25:35 +00009558 * <p>This method may returns {@code false} if there is no override APN with the given
9559 * {@code apnId}.
9560 * <p>This method may also returns {@code false} if {@code apnSetting} conflicts with an
9561 * existing override APN. Update the existing conflicted APN instead.
yuemingw6586f052018-03-21 16:32:09 +00009562 * <p>See {@link #addOverrideApn} for the definition of conflict.
yuemingwedfd36a2018-02-26 14:25:35 +00009563 *
yuemingwe3d9c092018-01-11 12:11:44 +00009564 * @param admin which {@link DeviceAdminReceiver} this request is associated with
9565 * @param apnId the {@code id} of the override APN to update
9566 * @param apnSetting the override APN to update
9567 * @return {@code true} if the required override APN is successfully updated,
9568 * {@code false} otherwise.
9569 * @throws SecurityException if {@code admin} is not a device owner.
9570 *
9571 * @see #setOverrideApnsEnabled(ComponentName, boolean)
9572 */
9573 public boolean updateOverrideApn(@NonNull ComponentName admin, int apnId,
9574 @NonNull ApnSetting apnSetting) {
9575 throwIfParentInstance("updateOverrideApn");
9576 if (mService != null) {
9577 try {
9578 return mService.updateOverrideApn(admin, apnId, apnSetting);
9579 } catch (RemoteException e) {
9580 throw e.rethrowFromSystemServer();
9581 }
9582 }
9583 return false;
9584 }
9585
9586 /**
9587 * Called by device owner to remove an override APN.
9588 *
yuemingwedfd36a2018-02-26 14:25:35 +00009589 * <p>This method may returns {@code false} if there is no override APN with the given
9590 * {@code apnId}.
9591 *
yuemingwe3d9c092018-01-11 12:11:44 +00009592 * @param admin which {@link DeviceAdminReceiver} this request is associated with
9593 * @param apnId the {@code id} of the override APN to remove
9594 * @return {@code true} if the required override APN is successfully removed, {@code false}
9595 * otherwise.
9596 * @throws SecurityException if {@code admin} is not a device owner.
9597 *
9598 * @see #setOverrideApnsEnabled(ComponentName, boolean)
9599 */
9600 public boolean removeOverrideApn(@NonNull ComponentName admin, int apnId) {
9601 throwIfParentInstance("removeOverrideApn");
9602 if (mService != null) {
9603 try {
9604 return mService.removeOverrideApn(admin, apnId);
9605 } catch (RemoteException e) {
9606 throw e.rethrowFromSystemServer();
9607 }
9608 }
9609 return false;
9610 }
9611
9612 /**
9613 * Called by device owner to get all override APNs inserted by device owner.
9614 *
9615 * @param admin which {@link DeviceAdminReceiver} this request is associated with
9616 * @return A list of override APNs inserted by device owner.
9617 * @throws SecurityException if {@code admin} is not a device owner.
9618 *
9619 * @see #setOverrideApnsEnabled(ComponentName, boolean)
9620 */
9621 public List<ApnSetting> getOverrideApns(@NonNull ComponentName admin) {
9622 throwIfParentInstance("getOverrideApns");
9623 if (mService != null) {
9624 try {
9625 return mService.getOverrideApns(admin);
9626 } catch (RemoteException e) {
9627 throw e.rethrowFromSystemServer();
9628 }
9629 }
9630 return Collections.emptyList();
9631 }
9632
9633 /**
9634 * Called by device owner to set if override APNs should be enabled.
9635 * <p> Override APNs are separated from other APNs on the device, and can only be inserted or
9636 * modified by the device owner. When enabled, only override APNs are in use, any other APNs
9637 * are ignored.
9638 *
9639 * @param admin which {@link DeviceAdminReceiver} this request is associated with
9640 * @param enabled {@code true} if override APNs should be enabled, {@code false} otherwise
9641 * @throws SecurityException if {@code admin} is not a device owner.
9642 */
9643 public void setOverrideApnsEnabled(@NonNull ComponentName admin, boolean enabled) {
9644 throwIfParentInstance("setOverrideApnEnabled");
9645 if (mService != null) {
9646 try {
9647 mService.setOverrideApnsEnabled(admin, enabled);
9648 } catch (RemoteException e) {
9649 throw e.rethrowFromSystemServer();
9650 }
9651 }
9652 }
9653
9654 /**
9655 * Called by device owner to check if override APNs are currently enabled.
9656 *
9657 * @param admin which {@link DeviceAdminReceiver} this request is associated with
9658 * @return {@code true} if override APNs are currently enabled, {@code false} otherwise.
9659 * @throws SecurityException if {@code admin} is not a device owner.
9660 *
9661 * @see #setOverrideApnsEnabled(ComponentName, boolean)
9662 */
9663 public boolean isOverrideApnEnabled(@NonNull ComponentName admin) {
9664 throwIfParentInstance("isOverrideApnEnabled");
9665 if (mService != null) {
9666 try {
9667 return mService.isOverrideApnEnabled(admin);
9668 } catch (RemoteException e) {
9669 throw e.rethrowFromSystemServer();
9670 }
9671 }
9672 return false;
9673 }
arangelov91201bd2018-01-04 17:10:21 +00009674
9675 /**
9676 * Returns the data passed from the current administrator to the new administrator during an
9677 * ownership transfer. This is the same {@code bundle} passed in
arangelovdc63bd72018-02-22 12:36:23 +00009678 * {@link #transferOwnership(ComponentName, ComponentName, PersistableBundle)}. The bundle is
9679 * persisted until the profile owner or device owner is removed.
9680 *
9681 * <p>This is the same <code>bundle</code> received in the
9682 * {@link DeviceAdminReceiver#onTransferOwnershipComplete(Context, PersistableBundle)}.
9683 * Use this method to retrieve it after the transfer as long as the new administrator is the
9684 * active device or profile owner.
arangelov91201bd2018-01-04 17:10:21 +00009685 *
9686 * <p>Returns <code>null</code> if no ownership transfer was started for the calling user.
9687 *
9688 * @see #transferOwnership
9689 * @see DeviceAdminReceiver#onTransferOwnershipComplete(Context, PersistableBundle)
arangelovdc63bd72018-02-22 12:36:23 +00009690 * @throws SecurityException if the caller is not a device or profile owner.
arangelov91201bd2018-01-04 17:10:21 +00009691 */
9692 @Nullable
9693 public PersistableBundle getTransferOwnershipBundle() {
9694 throwIfParentInstance("getTransferOwnershipBundle");
9695 try {
9696 return mService.getTransferOwnershipBundle();
9697 } catch (RemoteException re) {
9698 throw re.rethrowFromSystemServer();
9699 }
9700 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08009701}