blob: 18a006ffff318865c08499b810977518aa65353f [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
3309 * accross 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.
3893 *
Edman Anjosf9946772016-11-28 16:35:15 +01003894 * The caller must be a profile or device owner on that user, or a delegate package given the
3895 * {@link #DELEGATION_CERT_INSTALL} scope via {@link #setDelegatedScopes}; otherwise a
3896 * security exception will be thrown.
3897 *
Robin Lee25e26452015-06-02 09:56:29 -07003898 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3899 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003900 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04003901 *
3902 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01003903 * interrupted, true otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003904 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3905 * owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003906 * @see #setDelegatedScopes
3907 * @see #DELEGATION_CERT_INSTALL
Maggie Benthallda51e682013-08-08 22:35:44 -04003908 */
Robin Lee25e26452015-06-02 09:56:29 -07003909 public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003910 throwIfParentInstance("installCaCert");
Maggie Benthallda51e682013-08-08 22:35:44 -04003911 if (mService != null) {
3912 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003913 return mService.installCaCert(admin, mContext.getPackageName(), certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04003914 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003915 throw e.rethrowFromSystemServer();
Maggie Benthallda51e682013-08-08 22:35:44 -04003916 }
3917 }
3918 return false;
3919 }
3920
3921 /**
Robin Lee7e678712014-07-24 16:41:31 +01003922 * Uninstalls the given certificate from trusted user CAs, if present.
3923 *
Edman Anjosf9946772016-11-28 16:35:15 +01003924 * The caller must be a profile or device owner on that user, or a delegate package given the
3925 * {@link #DELEGATION_CERT_INSTALL} scope via {@link #setDelegatedScopes}; otherwise a
3926 * security exception will be thrown.
3927 *
Robin Lee25e26452015-06-02 09:56:29 -07003928 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3929 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003930 * @param certBuffer encoded form of the certificate to remove.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003931 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3932 * owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003933 * @see #setDelegatedScopes
3934 * @see #DELEGATION_CERT_INSTALL
Maggie Benthallda51e682013-08-08 22:35:44 -04003935 */
Robin Lee25e26452015-06-02 09:56:29 -07003936 public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003937 throwIfParentInstance("uninstallCaCert");
Maggie Benthallda51e682013-08-08 22:35:44 -04003938 if (mService != null) {
3939 try {
Robin Lee306fe082014-06-19 14:04:24 +00003940 final String alias = getCaCertAlias(certBuffer);
Edman Anjosf9946772016-11-28 16:35:15 +01003941 mService.uninstallCaCerts(admin, mContext.getPackageName(), new String[] {alias});
Robin Lee306fe082014-06-19 14:04:24 +00003942 } catch (CertificateException e) {
3943 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04003944 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003945 throw e.rethrowFromSystemServer();
Maggie Benthallda51e682013-08-08 22:35:44 -04003946 }
3947 }
3948 }
3949
3950 /**
Robin Lee7e678712014-07-24 16:41:31 +01003951 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
3952 * If a user has installed any certificates by other means than device policy these will be
3953 * included too.
3954 *
Robin Lee25e26452015-06-02 09:56:29 -07003955 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3956 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003957 * @return a List of byte[] arrays, each encoding one user CA certificate.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003958 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3959 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04003960 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003961 public @NonNull List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) {
3962 final List<byte[]> certs = new ArrayList<byte[]>();
Benjamin Franzbc33c822016-04-15 08:57:52 +01003963 throwIfParentInstance("getInstalledCaCerts");
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003964 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01003965 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003966 mService.enforceCanManageCaCerts(admin, mContext.getPackageName());
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003967 final TrustedCertificateStore certStore = new TrustedCertificateStore();
3968 for (String alias : certStore.userAliases()) {
3969 try {
3970 certs.add(certStore.getCertificate(alias).getEncoded());
3971 } catch (CertificateException ce) {
3972 Log.w(TAG, "Could not encode certificate: " + alias, ce);
3973 }
3974 }
3975 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003976 throw re.rethrowFromSystemServer();
Robin Lee7e678712014-07-24 16:41:31 +01003977 }
3978 }
3979 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04003980 }
3981
3982 /**
Robin Lee7e678712014-07-24 16:41:31 +01003983 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
3984 * means other than device policy will also be removed, except for system CA certificates.
3985 *
Robin Lee25e26452015-06-02 09:56:29 -07003986 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3987 * {@code null} if calling from a delegated certificate installer.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003988 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3989 * owner.
Robin Lee7e678712014-07-24 16:41:31 +01003990 */
Robin Lee25e26452015-06-02 09:56:29 -07003991 public void uninstallAllUserCaCerts(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003992 throwIfParentInstance("uninstallAllUserCaCerts");
Robin Lee7e678712014-07-24 16:41:31 +01003993 if (mService != null) {
Robin Lee83881bd2015-06-09 16:04:38 -07003994 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003995 mService.uninstallCaCerts(admin, mContext.getPackageName(),
3996 new TrustedCertificateStore().userAliases() .toArray(new String[0]));
Robin Lee83881bd2015-06-09 16:04:38 -07003997 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003998 throw re.rethrowFromSystemServer();
Robin Lee7e678712014-07-24 16:41:31 +01003999 }
4000 }
4001 }
4002
4003 /**
4004 * Returns whether this certificate is installed as a trusted CA.
4005 *
Robin Lee25e26452015-06-02 09:56:29 -07004006 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
4007 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01004008 * @param certBuffer encoded form of the certificate to look up.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004009 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
4010 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04004011 */
Robin Lee25e26452015-06-02 09:56:29 -07004012 public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004013 throwIfParentInstance("hasCaCertInstalled");
Esteban Talavera808f6ef2014-08-28 17:15:54 +01004014 if (mService != null) {
4015 try {
Edman Anjosf9946772016-11-28 16:35:15 +01004016 mService.enforceCanManageCaCerts(admin, mContext.getPackageName());
Esteban Talavera808f6ef2014-08-28 17:15:54 +01004017 return getCaCertAlias(certBuffer) != null;
4018 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004019 throw re.rethrowFromSystemServer();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01004020 } catch (CertificateException ce) {
4021 Log.w(TAG, "Could not parse certificate", ce);
4022 }
Maggie Benthallda51e682013-08-08 22:35:44 -04004023 }
4024 return false;
4025 }
4026
4027 /**
Robin Leece3399f2016-02-24 12:08:32 +00004028 * Called by a device or profile owner, or delegated certificate installer, to install a
4029 * certificate and corresponding private key. All apps within the profile will be able to access
4030 * the certificate and use the private key, given direct user approval.
4031 *
4032 * <p>Access to the installed credentials will not be granted to the caller of this API without
4033 * direct user approval. This is for security - should a certificate installer become
4034 * compromised, certificates it had already installed will be protected.
4035 *
4036 * <p>If the installer must have access to the credentials, call
Rubin Xub4365912016-03-23 12:13:22 +00004037 * {@link #installKeyPair(ComponentName, PrivateKey, Certificate[], String, boolean)} instead.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01004038 *
Robin Lee25e26452015-06-02 09:56:29 -07004039 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
4040 * {@code null} if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01004041 * @param privKey The private key to install.
4042 * @param cert The certificate to install.
4043 * @param alias The private key alias under which to install the certificate. If a certificate
4044 * with that alias already exists, it will be overwritten.
4045 * @return {@code true} if the keys were installed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004046 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
4047 * owner.
Edman Anjosf9946772016-11-28 16:35:15 +01004048 * @see #setDelegatedScopes
4049 * @see #DELEGATION_CERT_INSTALL
Bernhard Bauer26408cc2014-09-08 14:07:31 +01004050 */
Robin Leefbc65642015-08-03 16:21:22 +01004051 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
4052 @NonNull Certificate cert, @NonNull String alias) {
Rubin Xub4365912016-03-23 12:13:22 +00004053 return installKeyPair(admin, privKey, new Certificate[] {cert}, alias, false);
Robin Leece3399f2016-02-24 12:08:32 +00004054 }
4055
4056 /**
4057 * Called by a device or profile owner, or delegated certificate installer, to install a
Rubin Xub4365912016-03-23 12:13:22 +00004058 * certificate chain and corresponding private key for the leaf certificate. All apps within the
4059 * profile will be able to access the certificate chain and use the private key, given direct
4060 * user approval.
Robin Leece3399f2016-02-24 12:08:32 +00004061 *
Robin Leea1b290e2016-03-09 14:38:36 +00004062 * <p>The caller of this API may grant itself access to the certificate and private key
4063 * immediately, without user approval. It is a best practice not to request this unless strictly
4064 * necessary since it opens up additional security vulnerabilities.
Robin Leece3399f2016-02-24 12:08:32 +00004065 *
4066 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Robin Leea1b290e2016-03-09 14:38:36 +00004067 * {@code null} if calling from a delegated certificate installer.
Robin Leece3399f2016-02-24 12:08:32 +00004068 * @param privKey The private key to install.
Rubin Xub4365912016-03-23 12:13:22 +00004069 * @param certs The certificate chain to install. The chain should start with the leaf
4070 * certificate and include the chain of trust in order. This will be returned by
4071 * {@link android.security.KeyChain#getCertificateChain}.
Robin Leece3399f2016-02-24 12:08:32 +00004072 * @param alias The private key alias under which to install the certificate. If a certificate
Robin Leea1b290e2016-03-09 14:38:36 +00004073 * with that alias already exists, it will be overwritten.
Robin Leece3399f2016-02-24 12:08:32 +00004074 * @param requestAccess {@code true} to request that the calling app be granted access to the
Robin Leea1b290e2016-03-09 14:38:36 +00004075 * credentials immediately. Otherwise, access to the credentials will be gated by user
4076 * approval.
Robin Leece3399f2016-02-24 12:08:32 +00004077 * @return {@code true} if the keys were installed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004078 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
4079 * owner.
Rubin Xub4365912016-03-23 12:13:22 +00004080 * @see android.security.KeyChain#getCertificateChain
Edman Anjosf9946772016-11-28 16:35:15 +01004081 * @see #setDelegatedScopes
4082 * @see #DELEGATION_CERT_INSTALL
Robin Leece3399f2016-02-24 12:08:32 +00004083 */
4084 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
Rubin Xub4365912016-03-23 12:13:22 +00004085 @NonNull Certificate[] certs, @NonNull String alias, boolean requestAccess) {
Eran Messerif15d4f42018-03-23 13:32:17 +00004086 int flags = INSTALLKEY_SET_USER_SELECTABLE;
4087 if (requestAccess) {
4088 flags |= INSTALLKEY_REQUEST_CREDENTIALS_ACCESS;
4089 }
4090 return installKeyPair(admin, privKey, certs, alias, flags);
Eran Messeri19d19042017-11-20 12:48:52 +00004091 }
4092
4093 /**
4094 * Called by a device or profile owner, or delegated certificate installer, to install a
4095 * certificate chain and corresponding private key for the leaf certificate. All apps within the
4096 * profile will be able to access the certificate chain and use the private key, given direct
4097 * user approval (if the user is allowed to select the private key).
4098 *
4099 * <p>The caller of this API may grant itself access to the certificate and private key
4100 * immediately, without user approval. It is a best practice not to request this unless strictly
4101 * necessary since it opens up additional security vulnerabilities.
4102 *
Benjamin Miller8040fd12018-04-16 15:52:15 +00004103 * <p>Include {@link #INSTALLKEY_SET_USER_SELECTABLE} in the {@code flags} argument to allow
4104 * the user to select the key from a dialog.
Eran Messeri19d19042017-11-20 12:48:52 +00004105 *
4106 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
4107 * {@code null} if calling from a delegated certificate installer.
4108 * @param privKey The private key to install.
4109 * @param certs The certificate chain to install. The chain should start with the leaf
4110 * certificate and include the chain of trust in order. This will be returned by
4111 * {@link android.security.KeyChain#getCertificateChain}.
4112 * @param alias The private key alias under which to install the certificate. If a certificate
4113 * with that alias already exists, it will be overwritten.
Eran Messerif15d4f42018-03-23 13:32:17 +00004114 * @param flags Flags to request that the calling app be granted access to the credentials
4115 * and set the key to be user-selectable. See {@link #INSTALLKEY_SET_USER_SELECTABLE} and
4116 * {@link #INSTALLKEY_REQUEST_CREDENTIALS_ACCESS}.
Eran Messeri19d19042017-11-20 12:48:52 +00004117 * @return {@code true} if the keys were installed, {@code false} otherwise.
4118 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
4119 * owner.
4120 * @see android.security.KeyChain#getCertificateChain
4121 * @see #setDelegatedScopes
4122 * @see #DELEGATION_CERT_INSTALL
4123 */
4124 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
Eran Messerif15d4f42018-03-23 13:32:17 +00004125 @NonNull Certificate[] certs, @NonNull String alias, int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004126 throwIfParentInstance("installKeyPair");
Eran Messerif15d4f42018-03-23 13:32:17 +00004127 boolean requestAccess = (flags & INSTALLKEY_REQUEST_CREDENTIALS_ACCESS)
4128 == INSTALLKEY_REQUEST_CREDENTIALS_ACCESS;
4129 boolean isUserSelectable = (flags & INSTALLKEY_SET_USER_SELECTABLE)
4130 == INSTALLKEY_SET_USER_SELECTABLE;
Bernhard Bauer26408cc2014-09-08 14:07:31 +01004131 try {
Rubin Xub4365912016-03-23 12:13:22 +00004132 final byte[] pemCert = Credentials.convertToPem(certs[0]);
4133 byte[] pemChain = null;
4134 if (certs.length > 1) {
4135 pemChain = Credentials.convertToPem(Arrays.copyOfRange(certs, 1, certs.length));
4136 }
Robin Lee0d5ccb72014-09-12 17:41:44 +01004137 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
4138 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
Edman Anjosf9946772016-11-28 16:35:15 +01004139 return mService.installKeyPair(admin, mContext.getPackageName(), pkcs8Key, pemCert,
Eran Messeri19d19042017-11-20 12:48:52 +00004140 pemChain, alias, requestAccess, isUserSelectable);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01004141 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004142 throw e.rethrowFromSystemServer();
Robin Lee0d5ccb72014-09-12 17:41:44 +01004143 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
4144 Log.w(TAG, "Failed to obtain private key material", e);
4145 } catch (CertificateException | IOException e) {
4146 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01004147 }
4148 return false;
4149 }
4150
4151 /**
Robin Leea1b290e2016-03-09 14:38:36 +00004152 * Called by a device or profile owner, or delegated certificate installer, to remove a
4153 * certificate and private key pair installed under a given alias.
Robin Leefbc65642015-08-03 16:21:22 +01004154 *
4155 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Robin Leea1b290e2016-03-09 14:38:36 +00004156 * {@code null} if calling from a delegated certificate installer.
Robin Leefbc65642015-08-03 16:21:22 +01004157 * @param alias The private key alias under which the certificate is installed.
Robin Leea1b290e2016-03-09 14:38:36 +00004158 * @return {@code true} if the private key alias no longer exists, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004159 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
4160 * owner.
Edman Anjosf9946772016-11-28 16:35:15 +01004161 * @see #setDelegatedScopes
4162 * @see #DELEGATION_CERT_INSTALL
Robin Leefbc65642015-08-03 16:21:22 +01004163 */
4164 public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004165 throwIfParentInstance("removeKeyPair");
Robin Leefbc65642015-08-03 16:21:22 +01004166 try {
Edman Anjosf9946772016-11-28 16:35:15 +01004167 return mService.removeKeyPair(admin, mContext.getPackageName(), alias);
Robin Leefbc65642015-08-03 16:21:22 +01004168 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004169 throw e.rethrowFromSystemServer();
Robin Leefbc65642015-08-03 16:21:22 +01004170 }
Robin Leefbc65642015-08-03 16:21:22 +01004171 }
4172
4173 /**
Eran Messeri852c8f12017-11-15 05:55:52 +00004174 * Called by a device or profile owner, or delegated certificate installer, to generate a
4175 * new private/public key pair. If the device supports key generation via secure hardware,
4176 * this method is useful for creating a key in KeyChain that never left the secure hardware.
4177 *
4178 * Access to the key is controlled the same way as in {@link #installKeyPair}.
4179 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
4180 * {@code null} if calling from a delegated certificate installer.
4181 * @param algorithm The key generation algorithm, see {@link java.security.KeyPairGenerator}.
4182 * @param keySpec Specification of the key to generate, see
4183 * {@link java.security.KeyPairGenerator}.
Eran Messeri94d56762017-12-21 20:50:54 +00004184 * @param idAttestationFlags A bitmask of all the identifiers that should be included in the
4185 * attestation record ({@code ID_TYPE_BASE_INFO}, {@code ID_TYPE_SERIAL},
4186 * {@code ID_TYPE_IMEI} and {@code ID_TYPE_MEID}), or {@code 0} if no device
4187 * identification is required in the attestation record.
4188 * Device owner, profile owner and their delegated certificate installer can use
4189 * {@link #ID_TYPE_BASE_INFO} to request inclusion of the general device information
4190 * including manufacturer, model, brand, device and product in the attestation record.
4191 * Only device owner and their delegated certificate installer can use
4192 * {@link #ID_TYPE_SERIAL}, {@link #ID_TYPE_IMEI} and {@link #ID_TYPE_MEID} to request
4193 * unique device identifiers to be attested.
4194 * <p>
4195 * If any of {@link #ID_TYPE_SERIAL}, {@link #ID_TYPE_IMEI} and {@link #ID_TYPE_MEID}
4196 * is set, it is implicitly assumed that {@link #ID_TYPE_BASE_INFO} is also set.
4197 * <p>
4198 * If any flag is specified, then an attestation challenge must be included in the
4199 * {@code keySpec}.
Eran Messeri852c8f12017-11-15 05:55:52 +00004200 * @return A non-null {@code AttestedKeyPair} if the key generation succeeded, null otherwise.
4201 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
Eran Messeri94d56762017-12-21 20:50:54 +00004202 * owner. If Device ID attestation is requested (using {@link #ID_TYPE_SERIAL},
4203 * {@link #ID_TYPE_IMEI} or {@link #ID_TYPE_MEID}), the caller must be the Device Owner
4204 * or the Certificate Installer delegate.
4205 * @throws IllegalArgumentException if the alias in {@code keySpec} is empty, if the
Eran Messeri852c8f12017-11-15 05:55:52 +00004206 * algorithm specification in {@code keySpec} is not {@code RSAKeyGenParameterSpec}
Eran Messeri94d56762017-12-21 20:50:54 +00004207 * or {@code ECGenParameterSpec}, or if Device ID attestation was requested but the
4208 * {@code keySpec} does not contain an attestation challenge.
Eran Messeri61692392018-03-26 16:43:14 +01004209 * @throws UnsupportedOperationException if Device ID attestation was requested but the
4210 * underlying hardware does not support it.
Eran Messeri94d56762017-12-21 20:50:54 +00004211 * @see KeyGenParameterSpec.Builder#setAttestationChallenge(byte[])
Eran Messeri852c8f12017-11-15 05:55:52 +00004212 */
4213 public AttestedKeyPair generateKeyPair(@Nullable ComponentName admin,
Eran Messeri94d56762017-12-21 20:50:54 +00004214 @NonNull String algorithm, @NonNull KeyGenParameterSpec keySpec,
4215 @AttestationIdType int idAttestationFlags) {
Eran Messeri852c8f12017-11-15 05:55:52 +00004216 throwIfParentInstance("generateKeyPair");
4217 try {
4218 final ParcelableKeyGenParameterSpec parcelableSpec =
4219 new ParcelableKeyGenParameterSpec(keySpec);
Eran Messeria1730642017-12-11 17:48:47 +00004220 KeymasterCertificateChain attestationChain = new KeymasterCertificateChain();
Eran Messeri94d56762017-12-21 20:50:54 +00004221
4222 // Translate ID attestation flags to values used by AttestationUtils
Eran Messeri852c8f12017-11-15 05:55:52 +00004223 final boolean success = mService.generateKeyPair(
Eran Messeri94d56762017-12-21 20:50:54 +00004224 admin, mContext.getPackageName(), algorithm, parcelableSpec,
4225 idAttestationFlags, attestationChain);
Eran Messeri852c8f12017-11-15 05:55:52 +00004226 if (!success) {
4227 Log.e(TAG, "Error generating key via DevicePolicyManagerService.");
4228 return null;
4229 }
4230
Eran Messeria1730642017-12-11 17:48:47 +00004231 final String alias = keySpec.getKeystoreAlias();
4232 final KeyPair keyPair = KeyChain.getKeyPair(mContext, alias);
4233 Certificate[] outputChain = null;
4234 try {
4235 if (AttestationUtils.isChainValid(attestationChain)) {
4236 outputChain = AttestationUtils.parseCertificateChain(attestationChain);
4237 }
4238 } catch (KeyAttestationException e) {
4239 Log.e(TAG, "Error parsing attestation chain for alias " + alias, e);
4240 mService.removeKeyPair(admin, mContext.getPackageName(), alias);
4241 return null;
4242 }
4243 return new AttestedKeyPair(keyPair, outputChain);
Eran Messeri852c8f12017-11-15 05:55:52 +00004244 } catch (RemoteException e) {
4245 throw e.rethrowFromSystemServer();
4246 } catch (KeyChainException e) {
4247 Log.w(TAG, "Failed to generate key", e);
4248 } catch (InterruptedException e) {
4249 Log.w(TAG, "Interrupted while generating key", e);
4250 Thread.currentThread().interrupt();
4251 }
4252 return null;
4253 }
4254
Eran Messeriadaf68c2018-03-27 19:34:03 +01004255 /**
4256 * Returns {@code true} if the device supports attestation of device identifiers in addition
4257 * to key attestation.
4258 * @return {@code true} if Device ID attestation is supported.
4259 */
4260 public boolean isDeviceIdAttestationSupported() {
4261 PackageManager pm = mContext.getPackageManager();
4262 return pm.hasSystemFeature(PackageManager.FEATURE_DEVICE_ID_ATTESTATION);
4263 }
Eran Messeriecf0f222017-12-11 12:32:13 +00004264
4265 /**
4266 * Called by a device or profile owner, or delegated certificate installer, to associate
4267 * certificates with a key pair that was generated using {@link #generateKeyPair}, and
4268 * set whether the key is available for the user to choose in the certificate selection
4269 * prompt.
4270 *
4271 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
4272 * {@code null} if calling from a delegated certificate installer.
4273 * @param alias The private key alias under which to install the certificate. The {@code alias}
4274 * should denote an existing private key. If a certificate with that alias already
4275 * exists, it will be overwritten.
4276 * @param certs The certificate chain to install. The chain should start with the leaf
4277 * certificate and include the chain of trust in order. This will be returned by
4278 * {@link android.security.KeyChain#getCertificateChain}.
4279 * @param isUserSelectable {@code true} to indicate that a user can select this key via the
4280 * certificate selection prompt, {@code false} to indicate that this key can only be
4281 * granted access by implementing
4282 * {@link android.app.admin.DeviceAdminReceiver#onChoosePrivateKeyAlias}.
4283 * @return {@code true} if the provided {@code alias} exists and the certificates has been
4284 * successfully associated with it, {@code false} otherwise.
4285 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
4286 * owner, or {@code admin} is null but the calling application is not a delegated
4287 * certificate installer.
4288 */
4289 public boolean setKeyPairCertificate(@Nullable ComponentName admin,
4290 @NonNull String alias, @NonNull List<Certificate> certs, boolean isUserSelectable) {
4291 throwIfParentInstance("setKeyPairCertificate");
4292 try {
4293 final byte[] pemCert = Credentials.convertToPem(certs.get(0));
4294 byte[] pemChain = null;
4295 if (certs.size() > 1) {
4296 pemChain = Credentials.convertToPem(
4297 certs.subList(1, certs.size()).toArray(new Certificate[0]));
4298 }
4299 return mService.setKeyPairCertificate(admin, mContext.getPackageName(), alias, pemCert,
4300 pemChain, isUserSelectable);
4301 } catch (RemoteException e) {
4302 throw e.rethrowFromSystemServer();
4303 } catch (CertificateException | IOException e) {
4304 Log.w(TAG, "Could not pem-encode certificate", e);
4305 }
4306 return false;
4307 }
4308
4309
Eran Messeri852c8f12017-11-15 05:55:52 +00004310 /**
Robin Lee25e26452015-06-02 09:56:29 -07004311 * @return the alias of a given CA certificate in the certificate store, or {@code null} if it
Robin Lee306fe082014-06-19 14:04:24 +00004312 * doesn't exist.
4313 */
4314 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
4315 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
4316 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
4317 new ByteArrayInputStream(certBuffer));
4318 return new TrustedCertificateStore().getCertificateAlias(cert);
4319 }
4320
4321 /**
Rubin Xuec32b562015-03-03 17:34:05 +00004322 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01004323 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00004324 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01004325 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00004326 * <p>
4327 * Delegated certificate installer is a per-user state. The delegated access is persistent until
4328 * it is later cleared by calling this method with a null value or uninstallling the certificate
4329 * installer.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004330 * <p>
Rubin Xuf03d0a62016-02-10 14:54:15 +00004331 * <b>Note:</b>Starting from {@link android.os.Build.VERSION_CODES#N}, if the caller
4332 * application's target SDK version is {@link android.os.Build.VERSION_CODES#N} or newer, the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004333 * supplied certificate installer package must be installed when calling this API, otherwise an
4334 * {@link IllegalArgumentException} will be thrown.
Rubin Xuec32b562015-03-03 17:34:05 +00004335 *
Robin Lee25e26452015-06-02 09:56:29 -07004336 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xuec32b562015-03-03 17:34:05 +00004337 * @param installerPackage The package name of the certificate installer which will be given
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004338 * access. If {@code null} is given the current package will be cleared.
4339 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01004340 *
4341 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #setDelegatedScopes}
4342 * with the {@link #DELEGATION_CERT_INSTALL} scope instead.
Rubin Xuec32b562015-03-03 17:34:05 +00004343 */
Edman Anjosf9946772016-11-28 16:35:15 +01004344 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07004345 public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String
4346 installerPackage) throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004347 throwIfParentInstance("setCertInstallerPackage");
Rubin Xuec32b562015-03-03 17:34:05 +00004348 if (mService != null) {
4349 try {
Robin Lee25e26452015-06-02 09:56:29 -07004350 mService.setCertInstallerPackage(admin, installerPackage);
Rubin Xuec32b562015-03-03 17:34:05 +00004351 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004352 throw e.rethrowFromSystemServer();
Rubin Xuec32b562015-03-03 17:34:05 +00004353 }
4354 }
4355 }
4356
4357 /**
Edman Anjosf9946772016-11-28 16:35:15 +01004358 * Called by a profile owner or device owner to retrieve the certificate installer for the user,
4359 * or {@code null} if none is set. If there are multiple delegates this function will return one
4360 * of them.
Rubin Xuec32b562015-03-03 17:34:05 +00004361 *
Robin Lee25e26452015-06-02 09:56:29 -07004362 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004363 * @return The package name of the current delegated certificate installer, or {@code null} if
4364 * none is set.
4365 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01004366 *
4367 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatePackages}
4368 * with the {@link #DELEGATION_CERT_INSTALL} scope instead.
Rubin Xuec32b562015-03-03 17:34:05 +00004369 */
Edman Anjosf9946772016-11-28 16:35:15 +01004370 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07004371 public @Nullable String getCertInstallerPackage(@NonNull ComponentName admin)
4372 throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004373 throwIfParentInstance("getCertInstallerPackage");
Rubin Xuec32b562015-03-03 17:34:05 +00004374 if (mService != null) {
4375 try {
Robin Lee25e26452015-06-02 09:56:29 -07004376 return mService.getCertInstallerPackage(admin);
Rubin Xuec32b562015-03-03 17:34:05 +00004377 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004378 throw e.rethrowFromSystemServer();
Rubin Xuec32b562015-03-03 17:34:05 +00004379 }
4380 }
4381 return null;
4382 }
4383
4384 /**
Edman Anjosf9946772016-11-28 16:35:15 +01004385 * Called by a profile owner or device owner to grant access to privileged APIs to another app.
4386 * Granted APIs are determined by {@code scopes}, which is a list of the {@code DELEGATION_*}
4387 * constants.
4388 * <p>
Edman Anjos9e62c312017-01-26 22:22:58 +01004389 * A broadcast with the {@link #ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED} action will be
4390 * sent to the {@code delegatePackage} with its new scopes in an {@code ArrayList<String>} extra
4391 * under the {@link #EXTRA_DELEGATION_SCOPES} key. The broadcast is sent with the
4392 * {@link Intent#FLAG_RECEIVER_REGISTERED_ONLY} flag.
4393 * <p>
Edman Anjosf9946772016-11-28 16:35:15 +01004394 * Delegated scopes are a per-user state. The delegated access is persistent until it is later
4395 * cleared by calling this method with an empty {@code scopes} list or uninstalling the
4396 * {@code delegatePackage}.
4397 *
4398 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4399 * @param delegatePackage The package name of the app which will be given access.
4400 * @param scopes The groups of privileged APIs whose access should be granted to
4401 * {@code delegatedPackage}.
4402 * @throws SecurityException if {@code admin} is not a device or a profile owner.
4403 */
4404 public void setDelegatedScopes(@NonNull ComponentName admin, @NonNull String delegatePackage,
4405 @NonNull List<String> scopes) {
4406 throwIfParentInstance("setDelegatedScopes");
4407 if (mService != null) {
4408 try {
4409 mService.setDelegatedScopes(admin, delegatePackage, scopes);
4410 } catch (RemoteException e) {
4411 throw e.rethrowFromSystemServer();
4412 }
4413 }
4414 }
4415
4416 /**
4417 * Called by a profile owner or device owner to retrieve a list of the scopes given to a
4418 * delegate package. Other apps can use this method to retrieve their own delegated scopes by
4419 * passing {@code null} for {@code admin} and their own package name as
4420 * {@code delegatedPackage}.
4421 *
4422 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
4423 * {@code null} if the caller is {@code delegatedPackage}.
4424 * @param delegatedPackage The package name of the app whose scopes should be retrieved.
4425 * @return A list containing the scopes given to {@code delegatedPackage}.
4426 * @throws SecurityException if {@code admin} is not a device or a profile owner.
4427 */
4428 @NonNull
Edman Anjos9e62c312017-01-26 22:22:58 +01004429 public List<String> getDelegatedScopes(@Nullable ComponentName admin,
Edman Anjosf9946772016-11-28 16:35:15 +01004430 @NonNull String delegatedPackage) {
4431 throwIfParentInstance("getDelegatedScopes");
4432 if (mService != null) {
4433 try {
4434 return mService.getDelegatedScopes(admin, delegatedPackage);
4435 } catch (RemoteException e) {
4436 throw e.rethrowFromSystemServer();
4437 }
4438 }
4439 return null;
4440 }
4441
4442 /**
4443 * Called by a profile owner or device owner to retrieve a list of delegate packages that were
4444 * granted a delegation scope.
4445 *
4446 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4447 * @param delegationScope The scope whose delegates should be retrieved.
4448 * @return A list of package names of the current delegated packages for
4449 {@code delegationScope}.
4450 * @throws SecurityException if {@code admin} is not a device or a profile owner.
4451 */
4452 @Nullable
4453 public List<String> getDelegatePackages(@NonNull ComponentName admin,
4454 @NonNull String delegationScope) {
4455 throwIfParentInstance("getDelegatePackages");
4456 if (mService != null) {
4457 try {
4458 return mService.getDelegatePackages(admin, delegationScope);
4459 } catch (RemoteException e) {
4460 throw e.rethrowFromSystemServer();
4461 }
4462 }
4463 return null;
4464 }
4465
4466 /**
Pavel Grafov2b608492019-01-25 08:50:06 +00004467 * Service-specific error code used in implementation of {@code setAlwaysOnVpnPackage} methods.
4468 * @hide
4469 */
4470 public static final int ERROR_VPN_PACKAGE_NOT_FOUND = 1;
4471
4472 /**
Robin Lee244ce8e2016-01-05 18:03:46 +00004473 * Called by a device or profile owner to configure an always-on VPN connection through a
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004474 * specific application for the current user. This connection is automatically granted and
4475 * persisted after a reboot.
Pavel Grafov2b608492019-01-25 08:50:06 +00004476 * <p> To support the always-on feature, an app must
Charles He36738632017-05-15 17:07:18 +01004477 * <ul>
4478 * <li>declare a {@link android.net.VpnService} in its manifest, guarded by
4479 * {@link android.Manifest.permission#BIND_VPN_SERVICE};</li>
4480 * <li>target {@link android.os.Build.VERSION_CODES#N API 24} or above; and</li>
4481 * <li><i>not</i> explicitly opt out of the feature through
Charles Hec57a01c2017-08-15 15:30:22 +01004482 * {@link android.net.VpnService#SERVICE_META_DATA_SUPPORTS_ALWAYS_ON}.</li>
Charles He36738632017-05-15 17:07:18 +01004483 * </ul>
4484 * The call will fail if called with the package name of an unsupported VPN app.
Pavel Grafov2b608492019-01-25 08:50:06 +00004485 * <p> Enabling lockdown via {@code lockdownEnabled} argument carries the risk that any failure
4486 * of the VPN provider could break networking for all apps.
Robin Lee244ce8e2016-01-05 18:03:46 +00004487 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004488 * @param vpnPackage The package name for an installed VPN app on the device, or {@code null} to
Robin Leedc679712016-05-03 13:23:03 +01004489 * remove an existing always-on VPN configuration.
4490 * @param lockdownEnabled {@code true} to disallow networking when the VPN is not connected or
Pavel Grafov2b608492019-01-25 08:50:06 +00004491 * {@code false} otherwise. This has no effect when clearing.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004492 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Robin Leeee5eb932016-04-05 16:27:15 +01004493 * @throws NameNotFoundException if {@code vpnPackage} is not installed.
4494 * @throws UnsupportedOperationException if {@code vpnPackage} exists but does not support being
4495 * set as always-on, or if always-on VPN is not available.
Pavel Grafov2b608492019-01-25 08:50:06 +00004496 * @see #setAlwaysOnVpnPackage(ComponentName, String, boolean, List)
Robin Lee244ce8e2016-01-05 18:03:46 +00004497 */
Robin Leedc679712016-05-03 13:23:03 +01004498 public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage,
Pavel Grafov2b608492019-01-25 08:50:06 +00004499 boolean lockdownEnabled) throws NameNotFoundException {
4500 setAlwaysOnVpnPackage(admin, vpnPackage, lockdownEnabled, Collections.emptyList());
4501 }
4502
4503 /**
4504 * A version of {@link #setAlwaysOnVpnPackage(ComponentName, String, boolean)} that allows the
4505 * admin to specify a set of apps that should be able to access the network directly when VPN
4506 * is not connected. When VPN connects these apps switch over to VPN if allowed to use that VPN.
4507 * System apps can always bypass VPN.
4508 * <p> Note that the system doesn't update the whitelist when packages are installed or
4509 * uninstalled, the admin app must call this method to keep the list up to date.
4510 *
4511 * @param vpnPackage package name for an installed VPN app on the device, or {@code null}
4512 * to remove an existing always-on VPN configuration
4513 * @param lockdownEnabled {@code true} to disallow networking when the VPN is not connected or
4514 * {@code false} otherwise. This has no effect when clearing.
4515 * @param lockdownWhitelist Packages that will be able to access the network directly when VPN
4516 * is in lockdown mode but not connected. Has no effect when clearing.
4517 * @throws SecurityException if {@code admin} is not a device or a profile
4518 * owner.
4519 * @throws NameNotFoundException if {@code vpnPackage} or one of
4520 * {@code lockdownWhitelist} is not installed.
4521 * @throws UnsupportedOperationException if {@code vpnPackage} exists but does
4522 * not support being set as always-on, or if always-on VPN is not
4523 * available.
4524 */
4525 public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage,
4526 boolean lockdownEnabled, @Nullable List<String> lockdownWhitelist)
4527 throws NameNotFoundException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004528 throwIfParentInstance("setAlwaysOnVpnPackage");
Robin Lee244ce8e2016-01-05 18:03:46 +00004529 if (mService != null) {
4530 try {
Pavel Grafov2b608492019-01-25 08:50:06 +00004531 mService.setAlwaysOnVpnPackage(
4532 admin, vpnPackage, lockdownEnabled, lockdownWhitelist);
4533 } catch (ServiceSpecificException e) {
4534 switch (e.errorCode) {
4535 case ERROR_VPN_PACKAGE_NOT_FOUND:
4536 throw new NameNotFoundException(e.getMessage());
4537 default:
4538 throw new RuntimeException(
4539 "Unknown error setting always-on VPN: " + e.errorCode, e);
Robin Leeee5eb932016-04-05 16:27:15 +01004540 }
Robin Lee244ce8e2016-01-05 18:03:46 +00004541 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004542 throw e.rethrowFromSystemServer();
Robin Lee244ce8e2016-01-05 18:03:46 +00004543 }
4544 }
Robin Lee244ce8e2016-01-05 18:03:46 +00004545 }
4546
4547 /**
Pavel Grafov2b608492019-01-25 08:50:06 +00004548 * Called by device or profile owner to query whether current always-on VPN is configured in
4549 * lockdown mode. Returns {@code false} when no always-on configuration is set.
4550 *
4551 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4552 *
4553 * @throws SecurityException if {@code admin} is not a device or a profile owner.
4554 *
4555 * @see #setAlwaysOnVpnPackage(ComponentName, String, boolean)
4556 */
4557 public boolean isAlwaysOnVpnLockdownEnabled(@NonNull ComponentName admin) {
4558 throwIfParentInstance("isAlwaysOnVpnLockdownEnabled");
4559 if (mService != null) {
4560 try {
4561 return mService.isAlwaysOnVpnLockdownEnabled(admin);
4562 } catch (RemoteException e) {
4563 throw e.rethrowFromSystemServer();
4564 }
4565 }
4566 return false;
4567 }
4568
4569 /**
4570 * Called by device or profile owner to query the list of packages that are allowed to access
4571 * the network directly when always-on VPN is in lockdown mode but not connected. Returns
4572 * {@code null} when always-on VPN is not active or not in lockdown mode.
4573 *
4574 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4575 *
4576 * @throws SecurityException if {@code admin} is not a device or a profile owner.
4577 *
4578 * @see #setAlwaysOnVpnPackage(ComponentName, String, boolean, List)
4579 */
4580 public @Nullable List<String> getAlwaysOnVpnLockdownWhitelist(@NonNull ComponentName admin) {
4581 throwIfParentInstance("getAlwaysOnVpnLockdownWhitelist");
4582 if (mService != null) {
4583 try {
4584 return mService.getAlwaysOnVpnLockdownWhitelist(admin);
4585 } catch (RemoteException e) {
4586 throw e.rethrowFromSystemServer();
4587 }
4588 }
4589 return null;
4590 }
4591
4592 /**
Robin Lee244ce8e2016-01-05 18:03:46 +00004593 * Called by a device or profile owner to read the name of the package administering an
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004594 * always-on VPN connection for the current user. If there is no such package, or the always-on
4595 * VPN is provided by the system instead of by an application, {@code null} will be returned.
Robin Lee244ce8e2016-01-05 18:03:46 +00004596 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004597 * @return Package name of VPN controller responsible for always-on VPN, or {@code null} if none
4598 * is set.
4599 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Robin Lee244ce8e2016-01-05 18:03:46 +00004600 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004601 public @Nullable String getAlwaysOnVpnPackage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004602 throwIfParentInstance("getAlwaysOnVpnPackage");
Robin Lee244ce8e2016-01-05 18:03:46 +00004603 if (mService != null) {
4604 try {
4605 return mService.getAlwaysOnVpnPackage(admin);
4606 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004607 throw e.rethrowFromSystemServer();
Robin Lee244ce8e2016-01-05 18:03:46 +00004608 }
4609 }
4610 return null;
4611 }
4612
4613 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004614 * Called by an application that is administering the device to disable all cameras on the
4615 * device, for this user. After setting this, no applications running as this user will be able
4616 * to access any cameras on the device.
4617 * <p>
4618 * If the caller is device owner, then the restriction will be applied to all users.
4619 * <p>
4620 * The calling device admin must have requested
4621 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call this method; if it has
4622 * not, a security exception will be thrown.
Ben Komalo2447edd2011-05-09 16:05:33 -07004623 *
4624 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4625 * @param disabled Whether or not the camera should be disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004626 * @throws SecurityException if {@code admin} is not an active administrator or does not use
4627 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA}.
Ben Komalo2447edd2011-05-09 16:05:33 -07004628 */
Robin Lee25e26452015-06-02 09:56:29 -07004629 public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004630 throwIfParentInstance("setCameraDisabled");
Ben Komalo2447edd2011-05-09 16:05:33 -07004631 if (mService != null) {
4632 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08004633 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07004634 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004635 throw e.rethrowFromSystemServer();
Ben Komalo2447edd2011-05-09 16:05:33 -07004636 }
4637 }
4638 }
4639
4640 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07004641 * Determine whether or not the device's cameras have been disabled for this user,
Makoto Onuki32b30572015-12-11 14:29:51 -08004642 * either by the calling admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07004643 * @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 -07004644 * have disabled the camera
4645 */
Robin Lee25e26452015-06-02 09:56:29 -07004646 public boolean getCameraDisabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004647 throwIfParentInstance("getCameraDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004648 return getCameraDisabled(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004649 }
4650
4651 /** @hide per-user version */
Mathew Inwood4fb17d12018-08-14 14:25:44 +01004652 @UnsupportedAppUsage
Robin Lee25e26452015-06-02 09:56:29 -07004653 public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07004654 if (mService != null) {
4655 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004656 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07004657 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004658 throw e.rethrowFromSystemServer();
Ben Komalo2447edd2011-05-09 16:05:33 -07004659 }
4660 }
4661 return false;
4662 }
4663
4664 /**
Michal Karpinski3fc437e2015-12-15 10:09:00 +00004665 * Called by a device owner to request a bugreport.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004666 * <p>
Alex Chau443b6432017-12-13 12:44:31 +00004667 * If the device contains secondary users or profiles, they must be affiliated with the device.
4668 * Otherwise a {@link SecurityException} will be thrown. See {@link #isAffiliatedUser}.
Michal Karpinski3fc437e2015-12-15 10:09:00 +00004669 *
4670 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004671 * @return {@code true} if the bugreport collection started successfully, or {@code false} if it
4672 * wasn't triggered because a previous bugreport operation is still active (either the
4673 * bugreport is still running or waiting for the user to share or decline)
Esteban Talaverad36dd152016-12-15 08:51:45 +00004674 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
Alex Chau443b6432017-12-13 12:44:31 +00004675 * profile or secondary user that is not affiliated with the device.
4676 * @see #isAffiliatedUser
Michal Karpinski3fc437e2015-12-15 10:09:00 +00004677 */
4678 public boolean requestBugreport(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004679 throwIfParentInstance("requestBugreport");
Michal Karpinski3fc437e2015-12-15 10:09:00 +00004680 if (mService != null) {
4681 try {
4682 return mService.requestBugreport(admin);
4683 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004684 throw e.rethrowFromSystemServer();
Michal Karpinski3fc437e2015-12-15 10:09:00 +00004685 }
4686 }
4687 return false;
4688 }
4689
4690 /**
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07004691 * Determine whether or not creating a guest user has been disabled for the device
4692 *
4693 * @hide
4694 */
4695 public boolean getGuestUserDisabled(@Nullable ComponentName admin) {
4696 // Currently guest users can always be created if multi-user is enabled
4697 // TODO introduce a policy for guest user creation
4698 return false;
4699 }
4700
4701 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01004702 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
4703 * screen capture also prevents the content from being shown on display devices that do not have
4704 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
4705 * secure surfaces and secure displays.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004706 * <p>
4707 * The calling device admin must be a device or profile owner. If it is not, a security
4708 * exception will be thrown.
4709 * <p>
4710 * From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also blocks
4711 * assist requests for all activities of the relevant user.
Benjamin Franzc200f442015-06-25 18:20:04 +01004712 *
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004713 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004714 * @param disabled Whether screen capture is disabled or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004715 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004716 */
Robin Lee25e26452015-06-02 09:56:29 -07004717 public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004718 throwIfParentInstance("setScreenCaptureDisabled");
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004719 if (mService != null) {
4720 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08004721 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004722 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004723 throw e.rethrowFromSystemServer();
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004724 }
4725 }
4726 }
4727
4728 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004729 * Determine whether or not screen capture has been disabled by the calling
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004730 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07004731 * @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 +01004732 * have disabled screen capture.
4733 */
Robin Lee25e26452015-06-02 09:56:29 -07004734 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004735 throwIfParentInstance("getScreenCaptureDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004736 return getScreenCaptureDisabled(admin, myUserId());
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004737 }
4738
4739 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07004740 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004741 if (mService != null) {
4742 try {
4743 return mService.getScreenCaptureDisabled(admin, userHandle);
4744 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004745 throw e.rethrowFromSystemServer();
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004746 }
4747 }
4748 return false;
4749 }
4750
4751 /**
Jason Parks841cb0a2017-01-17 15:25:17 -06004752 * Called by a device or profile owner to set whether auto time is required. If auto time is
4753 * 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 -07004754 * <p>
4755 * Note: if auto time is required the user can still manually set the time zone.
4756 * <p>
Jason Parks841cb0a2017-01-17 15:25:17 -06004757 * The calling device admin must be a device or profile owner. If it is not, a security
4758 * exception will be thrown.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004759 *
4760 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4761 * @param required Whether auto time is set required or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004762 * @throws SecurityException if {@code admin} is not a device owner.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004763 */
Robin Lee25e26452015-06-02 09:56:29 -07004764 public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004765 throwIfParentInstance("setAutoTimeRequired");
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004766 if (mService != null) {
4767 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08004768 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004769 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004770 throw e.rethrowFromSystemServer();
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004771 }
4772 }
4773 }
4774
4775 /**
4776 * @return true if auto time is required.
4777 */
4778 public boolean getAutoTimeRequired() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004779 throwIfParentInstance("getAutoTimeRequired");
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004780 if (mService != null) {
4781 try {
4782 return mService.getAutoTimeRequired();
4783 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004784 throw e.rethrowFromSystemServer();
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004785 }
4786 }
4787 return false;
4788 }
4789
4790 /**
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004791 * Called by a device owner to set whether all users created on the device should be ephemeral.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004792 * <p>
4793 * The system user is exempt from this policy - it is never ephemeral.
4794 * <p>
4795 * The calling device admin must be the device owner. If it is not, a security exception will be
4796 * thrown.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004797 *
4798 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4799 * @param forceEphemeralUsers If true, all the existing users will be deleted and all
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004800 * subsequently created users will be ephemeral.
4801 * @throws SecurityException if {@code admin} is not a device owner.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004802 * @hide
4803 */
4804 public void setForceEphemeralUsers(
4805 @NonNull ComponentName admin, boolean forceEphemeralUsers) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004806 throwIfParentInstance("setForceEphemeralUsers");
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004807 if (mService != null) {
4808 try {
4809 mService.setForceEphemeralUsers(admin, forceEphemeralUsers);
4810 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004811 throw e.rethrowFromSystemServer();
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004812 }
4813 }
4814 }
4815
4816 /**
4817 * @return true if all users are created ephemeral.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004818 * @throws SecurityException if {@code admin} is not a device owner.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004819 * @hide
4820 */
4821 public boolean getForceEphemeralUsers(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004822 throwIfParentInstance("getForceEphemeralUsers");
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004823 if (mService != null) {
4824 try {
4825 return mService.getForceEphemeralUsers(admin);
4826 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004827 throw e.rethrowFromSystemServer();
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004828 }
4829 }
4830 return false;
4831 }
4832
4833 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07004834 * Called by an application that is administering the device to disable keyguard customizations,
4835 * such as widgets. After setting this, keyguard features will be disabled according to the
4836 * provided feature list.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004837 * <p>
4838 * The calling device admin must have requested
4839 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method;
4840 * if it has not, a security exception will be thrown.
4841 * <p>
4842 * Calling this from a managed profile before version {@link android.os.Build.VERSION_CODES#M}
4843 * will throw a security exception. From version {@link android.os.Build.VERSION_CODES#M} the
4844 * profile owner of a managed profile can set:
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00004845 * <ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00004846 * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which affects the parent user, but only if there
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004847 * is no separate challenge set on the managed profile.
Rubin Xuc418d5a2018-05-02 12:18:18 +01004848 * <li>{@link #KEYGUARD_DISABLE_FINGERPRINT}, {@link #KEYGUARD_DISABLE_FACE} or
4849 * {@link #KEYGUARD_DISABLE_IRIS} which affects the managed profile challenge if
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004850 * there is one, or the parent user otherwise.
4851 * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} which affects notifications generated
4852 * by applications in the managed profile.
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00004853 * </ul>
Rubin Xuc418d5a2018-05-02 12:18:18 +01004854 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, {@link #KEYGUARD_DISABLE_FINGERPRINT},
4855 * {@link #KEYGUARD_DISABLE_FACE} and {@link #KEYGUARD_DISABLE_IRIS} can also be
Esteban Talaverac1c83592016-02-17 17:56:15 +00004856 * set on the {@link DevicePolicyManager} instance returned by
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004857 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
4858 * profile.
4859 * <p>
4860 * Requests to disable other features on a managed profile will be ignored.
4861 * <p>
4862 * The admin can check which features have been disabled by calling
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00004863 * {@link #getKeyguardDisabledFeatures(ComponentName)}
Amith Yamasani242f4b12014-10-14 16:06:13 -07004864 *
Jim Millerb8ec4702012-08-31 17:19:10 -07004865 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xuc418d5a2018-05-02 12:18:18 +01004866 * @param which The disabled features flag which can be either
4867 * {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
4868 * {@link #KEYGUARD_DISABLE_FEATURES_ALL}, or a combination of
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004869 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
4870 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS},
4871 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
4872 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS},
Rubin Xuc418d5a2018-05-02 12:18:18 +01004873 * {@link #KEYGUARD_DISABLE_FINGERPRINT},
4874 * {@link #KEYGUARD_DISABLE_FACE},
4875 * {@link #KEYGUARD_DISABLE_IRIS}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004876 * @throws SecurityException if {@code admin} is not an active administrator or does not user
4877 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES}
Jim Millerb8ec4702012-08-31 17:19:10 -07004878 */
Robin Lee25e26452015-06-02 09:56:29 -07004879 public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07004880 if (mService != null) {
4881 try {
Esteban Talavera62399912016-01-11 15:37:55 +00004882 mService.setKeyguardDisabledFeatures(admin, which, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07004883 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004884 throw e.rethrowFromSystemServer();
Jim Millerb8ec4702012-08-31 17:19:10 -07004885 }
4886 }
4887 }
4888
4889 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004890 * Determine whether or not features have been disabled in keyguard either by the calling
Rubin Xud3609d42016-07-13 18:32:57 +01004891 * admin, if specified, or all admins that set restrictions on this user and its participating
Esteban Talaverac1c83592016-02-17 17:56:15 +00004892 * profiles. Restrictions on profiles that have a separate challenge are not taken into account.
4893 *
4894 * <p>This method can be called on the {@link DevicePolicyManager} instance
4895 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
4896 * restrictions on the parent profile.
4897 *
Esteban Talavera62399912016-01-11 15:37:55 +00004898 * @param admin The name of the admin component to check, or {@code null} to check whether any
4899 * admins have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07004900 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
4901 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07004902 */
Robin Lee25e26452015-06-02 09:56:29 -07004903 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004904 return getKeyguardDisabledFeatures(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004905 }
4906
4907 /** @hide per-user version */
Mathew Inwood4fb17d12018-08-14 14:25:44 +01004908 @UnsupportedAppUsage
Robin Lee25e26452015-06-02 09:56:29 -07004909 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07004910 if (mService != null) {
4911 try {
Esteban Talavera62399912016-01-11 15:37:55 +00004912 return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07004913 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004914 throw e.rethrowFromSystemServer();
Jim Millerb8ec4702012-08-31 17:19:10 -07004915 }
4916 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07004917 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07004918 }
4919
4920 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08004921 * @hide
4922 */
Mathew Inwood4fb17d12018-08-14 14:25:44 +01004923 @UnsupportedAppUsage
Robin Lee25e26452015-06-02 09:56:29 -07004924 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
4925 int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08004926 if (mService != null) {
4927 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01004928 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08004929 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004930 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08004931 }
4932 }
4933 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07004934
Dianne Hackbornd6847842010-01-12 18:14:19 -08004935 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01004936 * @hide
4937 */
Mathew Inwood4fb17d12018-08-14 14:25:44 +01004938 @UnsupportedAppUsage
Robin Lee25e26452015-06-02 09:56:29 -07004939 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004940 setActiveAdmin(policyReceiver, refreshing, myUserId());
Jessica Hummel6d36b602014-04-04 12:42:17 +01004941 }
4942
4943 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08004944 * @hide
4945 */
Robin Lee25e26452015-06-02 09:56:29 -07004946 public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08004947 if (mService != null) {
4948 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004949 mService.getRemoveWarning(admin, result, myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08004950 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004951 throw e.rethrowFromSystemServer();
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08004952 }
4953 }
4954 }
4955
4956 /**
4957 * @hide
4958 */
Mathew Inwood4fb17d12018-08-14 14:25:44 +01004959 @UnsupportedAppUsage
Andrew Scull5f9e6f32016-08-02 14:22:17 +01004960 public void setActivePasswordState(PasswordMetrics metrics, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08004961 if (mService != null) {
4962 try {
Andrew Scull5f9e6f32016-08-02 14:22:17 +01004963 mService.setActivePasswordState(metrics, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08004964 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004965 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08004966 }
4967 }
4968 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07004969
Dianne Hackbornd6847842010-01-12 18:14:19 -08004970 /**
4971 * @hide
4972 */
Andrew Scull5daf2732016-11-14 15:02:45 +00004973 public void reportPasswordChanged(@UserIdInt int userId) {
4974 if (mService != null) {
4975 try {
4976 mService.reportPasswordChanged(userId);
4977 } catch (RemoteException e) {
4978 throw e.rethrowFromSystemServer();
4979 }
4980 }
4981 }
4982
4983 /**
4984 * @hide
4985 */
Mathew Inwood4fb17d12018-08-14 14:25:44 +01004986 @UnsupportedAppUsage
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004987 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08004988 if (mService != null) {
4989 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004990 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08004991 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004992 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08004993 }
4994 }
4995 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07004996
Dianne Hackbornd6847842010-01-12 18:14:19 -08004997 /**
4998 * @hide
4999 */
Mathew Inwood4fb17d12018-08-14 14:25:44 +01005000 @UnsupportedAppUsage
Amith Yamasani599dd7c2012-09-14 23:20:08 -07005001 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08005002 if (mService != null) {
5003 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07005004 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08005005 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005006 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08005007 }
5008 }
5009 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07005010
5011 /**
Michal Karpinskied5c8f02016-02-09 15:43:41 +00005012 * @hide
5013 */
5014 public void reportFailedFingerprintAttempt(int userHandle) {
5015 if (mService != null) {
5016 try {
5017 mService.reportFailedFingerprintAttempt(userHandle);
5018 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005019 throw e.rethrowFromSystemServer();
Michal Karpinskied5c8f02016-02-09 15:43:41 +00005020 }
5021 }
5022 }
5023
5024 /**
5025 * @hide
5026 */
5027 public void reportSuccessfulFingerprintAttempt(int userHandle) {
5028 if (mService != null) {
5029 try {
5030 mService.reportSuccessfulFingerprintAttempt(userHandle);
5031 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005032 throw e.rethrowFromSystemServer();
Michal Karpinskied5c8f02016-02-09 15:43:41 +00005033 }
5034 }
5035 }
5036
5037 /**
Michal Karpinski31502d32016-01-25 16:43:07 +00005038 * Should be called when keyguard has been dismissed.
5039 * @hide
5040 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00005041 public void reportKeyguardDismissed(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00005042 if (mService != null) {
5043 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00005044 mService.reportKeyguardDismissed(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00005045 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005046 throw e.rethrowFromSystemServer();
Michal Karpinski31502d32016-01-25 16:43:07 +00005047 }
5048 }
5049 }
5050
5051 /**
5052 * Should be called when keyguard view has been shown to the user.
5053 * @hide
5054 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00005055 public void reportKeyguardSecured(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00005056 if (mService != null) {
5057 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00005058 mService.reportKeyguardSecured(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00005059 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005060 throw e.rethrowFromSystemServer();
Michal Karpinski31502d32016-01-25 16:43:07 +00005061 }
5062 }
5063 }
5064
5065 /**
Amith Yamasani71e6c692013-03-24 17:39:28 -07005066 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00005067 * Sets the given package as the device owner.
Makoto Onukia52562c2015-10-01 16:12:31 -07005068 * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name.
5069 * @param who the component name to be registered as device owner.
Amith Yamasani71e6c692013-03-24 17:39:28 -07005070 * @return whether the package was successfully registered as the device owner.
5071 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00005072 * @throws IllegalStateException If the preconditions mentioned are not met.
Amith Yamasani71e6c692013-03-24 17:39:28 -07005073 */
Makoto Onukia52562c2015-10-01 16:12:31 -07005074 public boolean setDeviceOwner(ComponentName who) {
5075 return setDeviceOwner(who, null);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04005076 }
5077
5078 /**
5079 * @hide
Makoto Onuki58b684f2015-09-04 10:48:16 -07005080 */
Makoto Onukia52562c2015-10-01 16:12:31 -07005081 public boolean setDeviceOwner(ComponentName who, int userId) {
5082 return setDeviceOwner(who, null, userId);
Makoto Onuki58b684f2015-09-04 10:48:16 -07005083 }
5084
5085 /**
5086 * @hide
5087 */
Makoto Onukia52562c2015-10-01 16:12:31 -07005088 public boolean setDeviceOwner(ComponentName who, String ownerName) {
5089 return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM);
Makoto Onuki58b684f2015-09-04 10:48:16 -07005090 }
5091
5092 /**
5093 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00005094 * Sets the given package as the device owner. The package must already be installed. There
5095 * must not already be a device owner.
5096 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
5097 * this method.
5098 * Calling this after the setup phase of the primary user has completed is allowed only if
5099 * the caller is the shell uid, and there are no additional users and no accounts.
Makoto Onukia52562c2015-10-01 16:12:31 -07005100 * @param who the component name to be registered as device owner.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04005101 * @param ownerName the human readable name of the institution that owns this device.
Makoto Onuki58b684f2015-09-04 10:48:16 -07005102 * @param userId ID of the user on which the device owner runs.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04005103 * @return whether the package was successfully registered as the device owner.
5104 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00005105 * @throws IllegalStateException If the preconditions mentioned are not met.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04005106 */
Makoto Onukia52562c2015-10-01 16:12:31 -07005107 public boolean setDeviceOwner(ComponentName who, String ownerName, int userId)
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04005108 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07005109 if (mService != null) {
5110 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07005111 return mService.setDeviceOwner(who, ownerName, userId);
Amith Yamasani71e6c692013-03-24 17:39:28 -07005112 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005113 throw re.rethrowFromSystemServer();
Amith Yamasani71e6c692013-03-24 17:39:28 -07005114 }
5115 }
5116 return false;
5117 }
5118
5119 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07005120 * Used to determine if a particular package has been registered as a Device Owner app.
5121 * A device owner app is a special device admin that cannot be deactivated by the user, once
Robin Lee25e26452015-06-02 09:56:29 -07005122 * activated as a device admin. It also cannot be uninstalled. To check whether a particular
Amith Yamasani3b458ad2013-04-18 18:40:07 -07005123 * package is currently registered as the device owner app, pass in the package name from
5124 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
Robin Lee25e26452015-06-02 09:56:29 -07005125 * admin apps that want to check whether they are also registered as the device owner app. The
Amith Yamasani3b458ad2013-04-18 18:40:07 -07005126 * exact mechanism by which a device admin app is registered as a device owner app is defined by
5127 * the setup process.
5128 * @param packageName the package name of the app, to compare with the registered device owner
5129 * app, if any.
Makoto Onukic8a5a552015-11-19 14:29:12 -08005130 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07005131 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07005132 public boolean isDeviceOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005133 throwIfParentInstance("isDeviceOwnerApp");
Makoto Onukic8a5a552015-11-19 14:29:12 -08005134 return isDeviceOwnerAppOnCallingUser(packageName);
5135 }
5136
5137 /**
5138 * @return true if a package is registered as device owner, only when it's running on the
5139 * calling user.
5140 *
5141 * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity.
5142 * @hide
5143 */
5144 public boolean isDeviceOwnerAppOnCallingUser(String packageName) {
5145 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true);
5146 }
5147
5148 /**
5149 * @return true if a package is registered as device owner, even if it's running on a different
5150 * user.
5151 *
5152 * <p>Requires the MANAGE_USERS permission.
5153 *
5154 * @hide
5155 */
5156 public boolean isDeviceOwnerAppOnAnyUser(String packageName) {
5157 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false);
5158 }
5159
5160 /**
5161 * @return device owner component name, only when it's running on the calling user.
5162 *
5163 * @hide
5164 */
5165 public ComponentName getDeviceOwnerComponentOnCallingUser() {
5166 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true);
5167 }
5168
5169 /**
5170 * @return device owner component name, even if it's running on a different user.
5171 *
Makoto Onukic8a5a552015-11-19 14:29:12 -08005172 * @hide
5173 */
Polina Bondarenko23561db2016-12-16 11:47:28 +01005174 @SystemApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06005175 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Makoto Onukic8a5a552015-11-19 14:29:12 -08005176 public ComponentName getDeviceOwnerComponentOnAnyUser() {
5177 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false);
5178 }
5179
5180 private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) {
Makoto Onuki70f929e2015-11-11 12:40:15 -08005181 if (packageName == null) {
5182 return false;
Amith Yamasani71e6c692013-03-24 17:39:28 -07005183 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08005184 final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly);
Makoto Onuki70f929e2015-11-11 12:40:15 -08005185 if (deviceOwner == null) {
5186 return false;
5187 }
5188 return packageName.equals(deviceOwner.getPackageName());
Amith Yamasani71e6c692013-03-24 17:39:28 -07005189 }
5190
Makoto Onukic8a5a552015-11-19 14:29:12 -08005191 private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) {
5192 if (mService != null) {
5193 try {
5194 return mService.getDeviceOwnerComponent(callingUserOnly);
5195 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005196 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08005197 }
5198 }
5199 return null;
Amith Yamasani3b458ad2013-04-18 18:40:07 -07005200 }
5201
Jason Monkb0dced82014-06-06 14:36:20 -04005202 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08005203 * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's
5204 * no device owner.
5205 *
5206 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07005207 *
5208 * @hide
5209 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08005210 public int getDeviceOwnerUserId() {
5211 if (mService != null) {
5212 try {
5213 return mService.getDeviceOwnerUserId();
5214 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005215 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08005216 }
5217 }
5218 return UserHandle.USER_NULL;
Makoto Onukia52562c2015-10-01 16:12:31 -07005219 }
5220
5221 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005222 * Clears the current device owner. The caller must be the device owner. This function should be
5223 * 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 +00005224 * a part of device setup, before it completes.
5225 * <p>
5226 * While some policies previously set by the device owner will be cleared by this method, it is
5227 * a best-effort process and some other policies will still remain in place after the device
5228 * owner is cleared.
Jason Monk94d2cf92014-06-18 09:53:34 -04005229 *
5230 * @param packageName The package name of the device owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005231 * @throws SecurityException if the caller is not in {@code packageName} or {@code packageName}
5232 * does not own the current device owner component.
Esteban Talaveraa5b09632017-02-10 16:15:24 +00005233 *
5234 * @deprecated This method is expected to be used for testing purposes only. The device owner
5235 * will lose control of the device and its data after calling it. In order to protect any
5236 * sensitive data that remains on the device, it is advised that the device owner factory resets
5237 * the device instead of calling this method. See {@link #wipeData(int)}.
Jason Monkb0dced82014-06-06 14:36:20 -04005238 */
Esteban Talaveraa5b09632017-02-10 16:15:24 +00005239 @Deprecated
Jason Monk94d2cf92014-06-18 09:53:34 -04005240 public void clearDeviceOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005241 throwIfParentInstance("clearDeviceOwnerApp");
Jason Monkb0dced82014-06-06 14:36:20 -04005242 if (mService != null) {
5243 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04005244 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04005245 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005246 throw re.rethrowFromSystemServer();
Jason Monkb0dced82014-06-06 14:36:20 -04005247 }
5248 }
5249 }
5250
Makoto Onukia52562c2015-10-01 16:12:31 -07005251 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08005252 * Returns the device owner package name, only if it's running on the calling user.
5253 *
5254 * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity.
Makoto Onukia52562c2015-10-01 16:12:31 -07005255 *
5256 * @hide
5257 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01005258 @SystemApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06005259 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Makoto Onuki408e8e42016-10-25 12:10:27 -07005260 public @Nullable String getDeviceOwner() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005261 throwIfParentInstance("getDeviceOwner");
Makoto Onukic8a5a552015-11-19 14:29:12 -08005262 final ComponentName name = getDeviceOwnerComponentOnCallingUser();
5263 return name != null ? name.getPackageName() : null;
Makoto Onukia52562c2015-10-01 16:12:31 -07005264 }
5265
5266 /**
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01005267 * Called by the system to find out whether the device is managed by a Device Owner.
Makoto Onukic8a5a552015-11-19 14:29:12 -08005268 *
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01005269 * @return whether the device is managed by a Device Owner.
5270 * @throws SecurityException if the caller is not the device owner, does not hold the
5271 * MANAGE_USERS permission and is not the system.
Makoto Onukia52562c2015-10-01 16:12:31 -07005272 *
5273 * @hide
5274 */
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01005275 @SystemApi
5276 @TestApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06005277 @SuppressLint("Doclava125")
Makoto Onukic8a5a552015-11-19 14:29:12 -08005278 public boolean isDeviceManaged() {
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01005279 try {
5280 return mService.hasDeviceOwner();
5281 } catch (RemoteException re) {
5282 throw re.rethrowFromSystemServer();
5283 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08005284 }
5285
5286 /**
5287 * Returns the device owner name. Note this method *will* return the device owner
5288 * name when it's running on a different user.
5289 *
Makoto Onukic8a5a552015-11-19 14:29:12 -08005290 * @hide
5291 */
Makoto Onukia2b274b2016-01-19 13:26:02 -08005292 @SystemApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06005293 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Makoto Onukic8a5a552015-11-19 14:29:12 -08005294 public String getDeviceOwnerNameOnAnyUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005295 throwIfParentInstance("getDeviceOwnerNameOnAnyUser");
Amith Yamasani71e6c692013-03-24 17:39:28 -07005296 if (mService != null) {
5297 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07005298 return mService.getDeviceOwnerName();
Amith Yamasani71e6c692013-03-24 17:39:28 -07005299 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005300 throw re.rethrowFromSystemServer();
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04005301 }
5302 }
5303 return null;
5304 }
Adam Connors776c5552014-01-09 10:42:56 +00005305
5306 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04005307 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04005308 * @deprecated Do not use
5309 * @removed
Julia Reynolds20118f12015-02-11 12:34:08 -05005310 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04005311 @Deprecated
Julia Reynolds20118f12015-02-11 12:34:08 -05005312 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06005313 @SuppressLint("Doclava125")
Makoto Onuki408e8e42016-10-25 12:10:27 -07005314 public @Nullable String getDeviceInitializerApp() {
Julia Reynolds20118f12015-02-11 12:34:08 -05005315 return null;
5316 }
5317
5318 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04005319 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04005320 * @deprecated Do not use
5321 * @removed
Julia Reynoldseaafdf722015-04-02 08:49:47 -04005322 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04005323 @Deprecated
Julia Reynoldseaafdf722015-04-02 08:49:47 -04005324 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06005325 @SuppressLint("Doclava125")
Makoto Onuki408e8e42016-10-25 12:10:27 -07005326 public @Nullable ComponentName getDeviceInitializerComponent() {
Julia Reynoldseaafdf722015-04-02 08:49:47 -04005327 return null;
5328 }
5329
Julia Reynolds20118f12015-02-11 12:34:08 -05005330 /**
Adam Connors776c5552014-01-09 10:42:56 +00005331 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07005332 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05305333 * Sets the given component as an active admin and registers the package as the profile
5334 * owner for this user. The package must already be installed and there shouldn't be
5335 * an existing profile owner registered for this user. Also, this method must be called
5336 * before the user setup has been completed.
5337 * <p>
5338 * This method can only be called by system apps that hold MANAGE_USERS permission and
5339 * MANAGE_DEVICE_ADMINS permission.
5340 * @param admin The component to register as an active admin and profile owner.
5341 * @param ownerName The user-visible name of the entity that is managing this user.
5342 * @return whether the admin was successfully registered as the profile owner.
5343 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
5344 * the user has already been set up.
5345 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07005346 @Deprecated
Justin Morey80440cc2014-07-24 09:16:35 -05005347 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06005348 @RequiresPermission(android.Manifest.permission.MANAGE_DEVICE_ADMINS)
Robin Lee25e26452015-06-02 09:56:29 -07005349 public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05305350 throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005351 throwIfParentInstance("setActiveProfileOwner");
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05305352 if (mService != null) {
5353 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07005354 final int myUserId = myUserId();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05305355 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07005356 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05305357 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005358 throw re.rethrowFromSystemServer();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05305359 }
5360 }
5361 return false;
5362 }
5363
5364 /**
Esteban Talaveraa5b09632017-02-10 16:15:24 +00005365 * Clears the active profile owner. The caller must be the profile owner of this user, otherwise
5366 * a SecurityException will be thrown. This method is not available to managed profile owners.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005367 * <p>
Esteban Talaveraa5b09632017-02-10 16:15:24 +00005368 * While some policies previously set by the profile owner will be cleared by this method, it is
5369 * a best-effort process and some other policies will still remain in place after the profile
5370 * owner is cleared.
Makoto Onuki5bf68022016-01-27 13:49:19 -08005371 *
Amith Yamasanibf3a9462014-07-28 14:26:42 -07005372 * @param admin The component to remove as the profile owner.
Esteban Talaveraa5b09632017-02-10 16:15:24 +00005373 * @throws SecurityException if {@code admin} is not an active profile owner, or the method is
5374 * being called from a managed profile.
5375 *
5376 * @deprecated This method is expected to be used for testing purposes only. The profile owner
5377 * will lose control of the user and its data after calling it. In order to protect any
5378 * sensitive data that remains on this user, it is advised that the profile owner deletes it
5379 * instead of calling this method. See {@link #wipeData(int)}.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07005380 */
Esteban Talaveraa5b09632017-02-10 16:15:24 +00005381 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07005382 public void clearProfileOwner(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005383 throwIfParentInstance("clearProfileOwner");
Amith Yamasanibf3a9462014-07-28 14:26:42 -07005384 if (mService != null) {
5385 try {
5386 mService.clearProfileOwner(admin);
5387 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005388 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07005389 }
5390 }
5391 }
5392
5393 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05005394 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07005395 * Checks whether the user was already setup.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07005396 */
5397 public boolean hasUserSetupCompleted() {
5398 if (mService != null) {
5399 try {
5400 return mService.hasUserSetupCompleted();
5401 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005402 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07005403 }
5404 }
5405 return true;
5406 }
5407
5408 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07005409 * @hide
5410 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00005411 * already be installed. There must not already be a profile owner for this user.
5412 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
5413 * this method.
5414 * Calling this after the setup phase of the specified user has completed is allowed only if:
5415 * - the caller is SYSTEM_UID.
5416 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07005417 * @param admin the component name to be registered as profile owner.
5418 * @param ownerName the human readable name of the organisation associated with this DPM.
5419 * @param userHandle the userId to set the profile owner for.
5420 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00005421 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
5422 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07005423 */
Robin Lee25e26452015-06-02 09:56:29 -07005424 public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName,
Robin Leeddd553f2015-04-30 14:18:22 +01005425 int userHandle) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00005426 if (mService != null) {
5427 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07005428 if (ownerName == null) {
5429 ownerName = "";
5430 }
5431 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00005432 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005433 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00005434 }
5435 }
5436 return false;
5437 }
5438
5439 /**
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00005440 * Sets the device owner information to be shown on the lock screen.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005441 * <p>
5442 * If the device owner information is {@code null} or empty then the device owner info is
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00005443 * cleared and the user owner info is shown on the lock screen if it is set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005444 * <p>
5445 * If the device owner information contains only whitespaces then the message on the lock screen
5446 * will be blank and the user will not be allowed to change it.
5447 * <p>
5448 * If the device owner information needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00005449 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
5450 * and set a new version of this string accordingly.
5451 *
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00005452 * @param admin The name of the admin component to check.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005453 * @param info Device owner information which will be displayed instead of the user owner info.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005454 * @throws SecurityException if {@code admin} is not a device owner.
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00005455 */
Andrei Stingaceanu16187902016-03-21 15:44:45 +00005456 public void setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, CharSequence info) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005457 throwIfParentInstance("setDeviceOwnerLockScreenInfo");
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00005458 if (mService != null) {
5459 try {
Andrei Stingaceanu16187902016-03-21 15:44:45 +00005460 mService.setDeviceOwnerLockScreenInfo(admin, info);
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00005461 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005462 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00005463 }
5464 }
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00005465 }
5466
5467 /**
5468 * @return The device owner information. If it is not set returns {@code null}.
5469 */
Andrei Stingaceanu16187902016-03-21 15:44:45 +00005470 public CharSequence getDeviceOwnerLockScreenInfo() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005471 throwIfParentInstance("getDeviceOwnerLockScreenInfo");
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00005472 if (mService != null) {
5473 try {
5474 return mService.getDeviceOwnerLockScreenInfo();
5475 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005476 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00005477 }
5478 }
5479 return null;
5480 }
5481
5482 /**
Edman Anjos52088e42017-01-13 22:26:17 +01005483 * Called by device or profile owners to suspend packages for this user. This function can be
5484 * called by a device owner, profile owner, or by a delegate given the
5485 * {@link #DELEGATION_PACKAGE_ACCESS} scope via {@link #setDelegatedScopes}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005486 * <p>
5487 * A suspended package will not be able to start activities. Its notifications will be hidden,
5488 * it will not show up in recents, will not be able to show toasts or dialogs or ring the
5489 * device.
5490 * <p>
5491 * The package must already be installed. If the package is uninstalled while suspended the
5492 * package will no longer be suspended. The admin can block this by using
Kenny Guy871f3eb2016-03-09 20:06:16 +00005493 * {@link #setUninstallBlocked}.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00005494 *
Edman Anjos52088e42017-01-13 22:26:17 +01005495 * @param admin The name of the admin component to check, or {@code null} if the caller is a
5496 * package access delegate.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00005497 * @param packageNames The package names to suspend or unsuspend.
5498 * @param suspended If set to {@code true} than the packages will be suspended, if set to
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005499 * {@code false} the packages will be unsuspended.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00005500 * @return an array of package names for which the suspended status is not set as requested in
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005501 * this method.
5502 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01005503 * @see #setDelegatedScopes
5504 * @see #DELEGATION_PACKAGE_ACCESS
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00005505 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005506 public @NonNull String[] setPackagesSuspended(@NonNull ComponentName admin,
5507 @NonNull String[] packageNames, boolean suspended) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005508 throwIfParentInstance("setPackagesSuspended");
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00005509 if (mService != null) {
5510 try {
Edman Anjos52088e42017-01-13 22:26:17 +01005511 return mService.setPackagesSuspended(admin, mContext.getPackageName(), packageNames,
5512 suspended);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00005513 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005514 throw re.rethrowFromSystemServer();
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00005515 }
5516 }
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00005517 return packageNames;
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00005518 }
5519
5520 /**
Edman Anjos52088e42017-01-13 22:26:17 +01005521 * Determine if a package is suspended. This function can be called by a device owner, profile
5522 * owner, or by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via
5523 * {@link #setDelegatedScopes}.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00005524 *
Edman Anjos52088e42017-01-13 22:26:17 +01005525 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
5526 * {@code null} if the caller is a package access delegate.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00005527 * @param packageName The name of the package to retrieve the suspended status of.
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00005528 * @return {@code true} if the package is suspended or {@code false} if the package is not
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005529 * suspended, could not be found or an error occurred.
5530 * @throws SecurityException if {@code admin} is not a device or profile owner.
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00005531 * @throws NameNotFoundException if the package could not be found.
Edman Anjos52088e42017-01-13 22:26:17 +01005532 * @see #setDelegatedScopes
5533 * @see #DELEGATION_PACKAGE_ACCESS
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00005534 */
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00005535 public boolean isPackageSuspended(@NonNull ComponentName admin, String packageName)
5536 throws NameNotFoundException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005537 throwIfParentInstance("isPackageSuspended");
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00005538 if (mService != null) {
5539 try {
Edman Anjos52088e42017-01-13 22:26:17 +01005540 return mService.isPackageSuspended(admin, mContext.getPackageName(), packageName);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00005541 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005542 throw e.rethrowFromSystemServer();
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00005543 } catch (IllegalArgumentException ex) {
5544 throw new NameNotFoundException(packageName);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00005545 }
5546 }
5547 return false;
5548 }
5549
5550 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01005551 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
5552 * be used. Only the profile owner can call this.
5553 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01005554 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01005555 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005556 * @throws SecurityException if {@code admin} is not a profile owner.
Alexandra Gherghina512675b2014-04-02 11:23:54 +01005557 */
Robin Lee25e26452015-06-02 09:56:29 -07005558 public void setProfileEnabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005559 throwIfParentInstance("setProfileEnabled");
Alexandra Gherghina512675b2014-04-02 11:23:54 +01005560 if (mService != null) {
5561 try {
5562 mService.setProfileEnabled(admin);
5563 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005564 throw e.rethrowFromSystemServer();
Alexandra Gherghina512675b2014-04-02 11:23:54 +01005565 }
5566 }
5567 }
5568
5569 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005570 * Sets the name of the profile. In the device owner case it sets the name of the user which it
5571 * is called from. Only a profile owner or device owner can call this. If this is never called
5572 * by the profile or device owner, the name will be set to default values.
Jessica Hummel1333ea12014-06-23 11:20:10 +01005573 *
5574 * @see #isProfileOwnerApp
5575 * @see #isDeviceOwnerApp
Robin Lee25e26452015-06-02 09:56:29 -07005576 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01005577 * @param profileName The name of the profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005578 * @throws SecurityException if {@code admin} is not a device or profile owner.
Jessica Hummel1333ea12014-06-23 11:20:10 +01005579 */
Robin Lee25e26452015-06-02 09:56:29 -07005580 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005581 throwIfParentInstance("setProfileName");
Jessica Hummel1333ea12014-06-23 11:20:10 +01005582 if (mService != null) {
5583 try {
Robin Lee25e26452015-06-02 09:56:29 -07005584 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07005585 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005586 throw e.rethrowFromSystemServer();
Fyodor Kupolov78f13142015-05-27 16:52:45 -07005587 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01005588 }
5589 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01005590
5591 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005592 * Used to determine if a particular package is registered as the profile owner for the
Makoto Onuki32b30572015-12-11 14:29:51 -08005593 * user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005594 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00005595 *
5596 * @param packageName The package name of the app to compare with the registered profile owner.
5597 * @return Whether or not the package is registered as the profile owner.
5598 */
5599 public boolean isProfileOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005600 throwIfParentInstance("isProfileOwnerApp");
Adam Connors776c5552014-01-09 10:42:56 +00005601 if (mService != null) {
5602 try {
Makoto Onuki90b89652016-01-28 14:44:18 -08005603 ComponentName profileOwner = mService.getProfileOwner(myUserId());
Nicolas Prevot90af6d72014-07-30 14:19:12 +01005604 return profileOwner != null
5605 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00005606 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005607 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00005608 }
5609 }
5610 return false;
5611 }
5612
5613 /**
5614 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07005615 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00005616 * owner has been set for that user.
5617 * @throws IllegalArgumentException if the userId is invalid.
5618 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01005619 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07005620 public @Nullable ComponentName getProfileOwner() throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005621 throwIfParentInstance("getProfileOwner");
Jeff Sharkeyad357d12018-02-02 13:25:31 -07005622 return getProfileOwnerAsUser(mContext.getUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01005623 }
5624
5625 /**
5626 * @see #getProfileOwner()
5627 * @hide
5628 */
Mathew Inwood4fb17d12018-08-14 14:25:44 +01005629 @UnsupportedAppUsage
Makoto Onuki408e8e42016-10-25 12:10:27 -07005630 public @Nullable ComponentName getProfileOwnerAsUser(final int userId)
5631 throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00005632 if (mService != null) {
5633 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01005634 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00005635 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005636 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00005637 }
5638 }
5639 return null;
5640 }
5641
5642 /**
5643 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07005644 * @return the human readable name of the organisation associated with this DPM or {@code null}
5645 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00005646 * @throws IllegalArgumentException if the userId is invalid.
5647 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005648 public @Nullable String getProfileOwnerName() throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00005649 if (mService != null) {
5650 try {
Jeff Sharkeyad357d12018-02-02 13:25:31 -07005651 return mService.getProfileOwnerName(mContext.getUserId());
Adam Connors776c5552014-01-09 10:42:56 +00005652 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005653 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00005654 }
5655 }
5656 return null;
5657 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005658
5659 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07005660 * @hide
Makoto Onukic8a5a552015-11-19 14:29:12 -08005661 * @param userId The user for whom to fetch the profile owner name, if any.
Amith Yamasani38f836b2014-08-20 14:51:15 -07005662 * @return the human readable name of the organisation associated with this profile owner or
5663 * null if one is not set.
5664 * @throws IllegalArgumentException if the userId is invalid.
5665 */
5666 @SystemApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06005667 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Makoto Onuki408e8e42016-10-25 12:10:27 -07005668 public @Nullable String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005669 throwIfParentInstance("getProfileOwnerNameAsUser");
Amith Yamasani38f836b2014-08-20 14:51:15 -07005670 if (mService != null) {
5671 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02005672 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07005673 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005674 throw re.rethrowFromSystemServer();
Amith Yamasani38f836b2014-08-20 14:51:15 -07005675 }
5676 }
5677 return null;
5678 }
5679
5680 /**
Tony Mak329047b2018-02-28 14:17:17 +00005681 * Called by a profile owner or device owner to set a default activity that the system selects
5682 * to handle intents that match the given {@link IntentFilter}. This activity will remain the
5683 * default intent handler even if the set of potential event handlers for the intent filter
5684 * changes and if the intent preferences are reset.
5685 * <p>
5686 * Note that the caller should still declare the activity in the manifest, the API just sets
5687 * the activity to be the default one to handle the given intent filter.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005688 * <p>
5689 * The default disambiguation mechanism takes over if the activity is not installed (anymore).
5690 * When the activity is (re)installed, it is automatically reset as default intent handler for
5691 * the filter.
5692 * <p>
5693 * The calling device admin must be a profile owner or device owner. If it is not, a security
5694 * exception will be thrown.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005695 *
5696 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5697 * @param filter The IntentFilter for which a default handler is added.
5698 * @param activity The Activity that is added as default intent handler.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005699 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005700 */
Robin Lee25e26452015-06-02 09:56:29 -07005701 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
5702 @NonNull ComponentName activity) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005703 throwIfParentInstance("addPersistentPreferredActivity");
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005704 if (mService != null) {
5705 try {
5706 mService.addPersistentPreferredActivity(admin, filter, activity);
5707 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005708 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005709 }
5710 }
5711 }
5712
5713 /**
5714 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00005715 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005716 * <p>
5717 * The calling device admin must be a profile owner. If it is not, a security exception will be
5718 * thrown.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005719 *
5720 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5721 * @param packageName The name of the package for which preferences are removed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005722 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005723 */
Robin Lee25e26452015-06-02 09:56:29 -07005724 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005725 String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005726 throwIfParentInstance("clearPackagePersistentPreferredActivities");
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005727 if (mService != null) {
5728 try {
5729 mService.clearPackagePersistentPreferredActivities(admin, packageName);
5730 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005731 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005732 }
5733 }
5734 }
Robin Lee66e5d962014-04-09 16:44:21 +01005735
5736 /**
Christine Franks26449ed2018-02-22 16:19:26 -08005737 * Called by a device owner to set the default SMS application.
5738 * <p>
5739 * The calling device admin must be a device owner. If it is not, a security exception will be
5740 * thrown.
5741 *
5742 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5743 * @param packageName The name of the package to set as the default SMS application.
5744 * @throws SecurityException if {@code admin} is not a device owner.
5745 *
5746 * @hide
5747 */
Mathew Inwood4fb17d12018-08-14 14:25:44 +01005748 @UnsupportedAppUsage
Christine Franks26449ed2018-02-22 16:19:26 -08005749 public void setDefaultSmsApplication(@NonNull ComponentName admin, String packageName) {
5750 throwIfParentInstance("setDefaultSmsApplication");
5751 if (mService != null) {
5752 try {
5753 mService.setDefaultSmsApplication(admin, packageName);
5754 } catch (RemoteException e) {
5755 throw e.rethrowFromSystemServer();
5756 }
5757 }
5758 }
5759
5760 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00005761 * Called by a profile owner or device owner to grant permission to a package to manage
5762 * application restrictions for the calling user via {@link #setApplicationRestrictions} and
5763 * {@link #getApplicationRestrictions}.
5764 * <p>
5765 * This permission is persistent until it is later cleared by calling this method with a
5766 * {@code null} value or uninstalling the managing package.
Rubin Xuf03d0a62016-02-10 14:54:15 +00005767 * <p>
5768 * The supplied application restriction managing package must be installed when calling this
Victor Changcd14c0a2016-03-16 19:10:15 +00005769 * API, otherwise an {@link NameNotFoundException} will be thrown.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005770 *
5771 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5772 * @param packageName The package name which will be given access to application restrictions
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005773 * APIs. If {@code null} is given the current package will be cleared.
5774 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Changcd14c0a2016-03-16 19:10:15 +00005775 * @throws NameNotFoundException if {@code packageName} is not found
Edman Anjosf9946772016-11-28 16:35:15 +01005776 *
5777 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #setDelegatedScopes}
5778 * with the {@link #DELEGATION_APP_RESTRICTIONS} scope instead.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005779 */
Edman Anjosf9946772016-11-28 16:35:15 +01005780 @Deprecated
Esteban Talaverabf60f722015-12-10 16:26:44 +00005781 public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin,
Victor Changcd14c0a2016-03-16 19:10:15 +00005782 @Nullable String packageName) throws NameNotFoundException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005783 throwIfParentInstance("setApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00005784 if (mService != null) {
5785 try {
Victor Changcd14c0a2016-03-16 19:10:15 +00005786 if (!mService.setApplicationRestrictionsManagingPackage(admin, packageName)) {
5787 throw new NameNotFoundException(packageName);
5788 }
Esteban Talaverabf60f722015-12-10 16:26:44 +00005789 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005790 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00005791 }
5792 }
5793 }
5794
5795 /**
5796 * Called by a profile owner or device owner to retrieve the application restrictions managing
Edman Anjosf9946772016-11-28 16:35:15 +01005797 * package for the current user, or {@code null} if none is set. If there are multiple
5798 * delegates this function will return one of them.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005799 *
5800 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5801 * @return The package name allowed to manage application restrictions on the current user, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005802 * {@code null} if none is set.
5803 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01005804 *
5805 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatePackages}
5806 * with the {@link #DELEGATION_APP_RESTRICTIONS} scope instead.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005807 */
Edman Anjosf9946772016-11-28 16:35:15 +01005808 @Deprecated
5809 @Nullable
5810 public String getApplicationRestrictionsManagingPackage(
Makoto Onuki408e8e42016-10-25 12:10:27 -07005811 @NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005812 throwIfParentInstance("getApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00005813 if (mService != null) {
5814 try {
5815 return mService.getApplicationRestrictionsManagingPackage(admin);
5816 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005817 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00005818 }
5819 }
5820 return null;
5821 }
5822
5823 /**
Esteban Talavera96895ca2016-03-16 12:00:40 +00005824 * Called by any application to find out whether it has been granted permission via
5825 * {@link #setApplicationRestrictionsManagingPackage} to manage application restrictions
5826 * for the calling user.
5827 *
5828 * <p>This is done by comparing the calling Linux uid with the uid of the package specified by
5829 * that method.
Edman Anjosf9946772016-11-28 16:35:15 +01005830 *
5831 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatedScopes}
5832 * instead.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005833 */
Edman Anjosf9946772016-11-28 16:35:15 +01005834 @Deprecated
Esteban Talaverabf60f722015-12-10 16:26:44 +00005835 public boolean isCallerApplicationRestrictionsManagingPackage() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005836 throwIfParentInstance("isCallerApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00005837 if (mService != null) {
5838 try {
Edman Anjosf9946772016-11-28 16:35:15 +01005839 return mService.isCallerApplicationRestrictionsManagingPackage(
5840 mContext.getPackageName());
Esteban Talaverabf60f722015-12-10 16:26:44 +00005841 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005842 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00005843 }
5844 }
5845 return false;
5846 }
5847
5848 /**
5849 * Sets the application restrictions for a given target application running in the calling user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005850 * <p>
5851 * 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 +01005852 * application restrictions via {@link #setDelegatedScopes} with the
5853 * {@link #DELEGATION_APP_RESTRICTIONS} scope; otherwise a security exception will be thrown.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005854 * <p>
5855 * The provided {@link Bundle} consists of key-value pairs, where the types of values may be:
Esteban Talavera6b8e0642015-08-10 17:26:04 +01005856 * <ul>
5857 * <li>{@code boolean}
5858 * <li>{@code int}
5859 * <li>{@code String} or {@code String[]}
5860 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
5861 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005862 * <p>
5863 * If the restrictions are not available yet, but may be applied in the near future, the caller
5864 * can notify the target application of that by adding
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00005865 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005866 * <p>
5867 * The application restrictions are only made visible to the target application via
5868 * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or device
5869 * owner, and the application restrictions managing package via
Esteban Talaverabf60f722015-12-10 16:26:44 +00005870 * {@link #getApplicationRestrictions}.
Robin Lee66e5d962014-04-09 16:44:21 +01005871 *
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005872 * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
5873 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00005874 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005875 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01005876 * @param packageName The name of the package to update restricted settings for.
5877 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005878 * set of active restrictions.
5879 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01005880 * @see #setDelegatedScopes
5881 * @see #DELEGATION_APP_RESTRICTIONS
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00005882 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01005883 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005884 @WorkerThread
Esteban Talaverabf60f722015-12-10 16:26:44 +00005885 public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01005886 Bundle settings) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005887 throwIfParentInstance("setApplicationRestrictions");
Robin Lee66e5d962014-04-09 16:44:21 +01005888 if (mService != null) {
5889 try {
Edman Anjosf9946772016-11-28 16:35:15 +01005890 mService.setApplicationRestrictions(admin, mContext.getPackageName(), packageName,
5891 settings);
Robin Lee66e5d962014-04-09 16:44:21 +01005892 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005893 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01005894 }
5895 }
5896 }
5897
5898 /**
Rubin Xu50ac2412018-03-02 15:25:28 +00005899 * Sets a list of configuration features to enable for a trust agent component. This is meant to
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005900 * be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all trust
5901 * agents but those enabled by this function call. If flag
Jim Millere303bf42014-08-26 17:12:29 -07005902 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005903 * <p>
Rubin Xu50ac2412018-03-02 15:25:28 +00005904 * For any specific trust agent, whether it is disabled or not depends on the aggregated state
5905 * of each admin's {@link #KEYGUARD_DISABLE_TRUST_AGENTS} setting and its trust agent
5906 * configuration as set by this function call. In particular: if any admin sets
5907 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} and does not additionally set any
5908 * trust agent configuration, the trust agent is disabled completely. Otherwise, the trust agent
5909 * will receive the list of configurations from all admins who set
5910 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} and aggregate the configurations to determine its
5911 * behavior. The exact meaning of aggregation is trust-agent-specific.
5912 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005913 * The calling device admin must have requested
5914 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method;
5915 * if not, a security exception will be thrown.
Tony Mak089d8402016-04-05 17:42:55 +01005916 * <p>
5917 * This method can be called on the {@link DevicePolicyManager} instance returned by
5918 * {@link #getParentProfileInstance(ComponentName)} in order to set the configuration for
5919 * the parent profile.
Jim Miller604e7552014-07-18 19:00:02 -07005920 *
5921 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xu50ac2412018-03-02 15:25:28 +00005922 * @param target Component name of the agent to be configured.
5923 * @param configuration Trust-agent-specific feature configuration bundle. Please consult
5924 * documentation of the specific trust agent to determine the interpretation of this
5925 * bundle.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005926 * @throws SecurityException if {@code admin} is not an active administrator or does not use
5927 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES}
Jim Miller604e7552014-07-18 19:00:02 -07005928 */
Robin Lee25e26452015-06-02 09:56:29 -07005929 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
5930 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07005931 if (mService != null) {
5932 try {
Tony Mak089d8402016-04-05 17:42:55 +01005933 mService.setTrustAgentConfiguration(admin, target, configuration, mParentInstance);
Jim Miller604e7552014-07-18 19:00:02 -07005934 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005935 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07005936 }
5937 }
5938 }
5939
5940 /**
Jim Millere303bf42014-08-26 17:12:29 -07005941 * Gets configuration for the given trust agent based on aggregating all calls to
5942 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
5943 * all device admins.
Tony Mak089d8402016-04-05 17:42:55 +01005944 * <p>
5945 * This method can be called on the {@link DevicePolicyManager} instance returned by
5946 * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the configuration set
5947 * on the parent profile.
Jim Miller604e7552014-07-18 19:00:02 -07005948 *
Jim Millerb5db57a2015-01-14 18:17:19 -08005949 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
5950 * this function returns a list of configurations for all admins that declare
5951 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
5952 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
5953 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
5954 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07005955 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07005956 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07005957 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005958 public @Nullable List<PersistableBundle> getTrustAgentConfiguration(
5959 @Nullable ComponentName admin, @NonNull ComponentName agent) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07005960 return getTrustAgentConfiguration(admin, agent, myUserId());
Jim Millere303bf42014-08-26 17:12:29 -07005961 }
5962
5963 /** @hide per-user version */
Mathew Inwood4fb17d12018-08-14 14:25:44 +01005964 @UnsupportedAppUsage
Makoto Onuki408e8e42016-10-25 12:10:27 -07005965 public @Nullable List<PersistableBundle> getTrustAgentConfiguration(
5966 @Nullable ComponentName admin, @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07005967 if (mService != null) {
5968 try {
Tony Mak089d8402016-04-05 17:42:55 +01005969 return mService.getTrustAgentConfiguration(admin, agent, userHandle,
5970 mParentInstance);
Jim Miller604e7552014-07-18 19:00:02 -07005971 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005972 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07005973 }
5974 }
Jim Millere303bf42014-08-26 17:12:29 -07005975 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07005976 }
5977
5978 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005979 * Called by a profile owner of a managed profile to set whether caller-Id information from the
5980 * managed profile will be shown in the parent profile, for incoming calls.
5981 * <p>
5982 * The calling device admin must be a profile owner. If it is not, a security exception will be
5983 * thrown.
Adam Connors210fe212014-07-17 15:41:43 +01005984 *
Robin Lee25e26452015-06-02 09:56:29 -07005985 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01005986 * @param disabled If true caller-Id information in the managed profile is not displayed.
Tony Mak329047b2018-02-28 14:17:17 +00005987 * @throws SecurityException if {@code admin} is not a profile owner.
Adam Connors210fe212014-07-17 15:41:43 +01005988 */
Robin Lee25e26452015-06-02 09:56:29 -07005989 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005990 throwIfParentInstance("setCrossProfileCallerIdDisabled");
Adam Connors210fe212014-07-17 15:41:43 +01005991 if (mService != null) {
5992 try {
Robin Lee25e26452015-06-02 09:56:29 -07005993 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01005994 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005995 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01005996 }
5997 }
5998 }
5999
6000 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07006001 * Called by a profile owner of a managed profile to determine whether or not caller-Id
6002 * information has been disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006003 * <p>
6004 * The calling device admin must be a profile owner. If it is not, a security exception will be
6005 * thrown.
Adam Connors210fe212014-07-17 15:41:43 +01006006 *
Robin Lee25e26452015-06-02 09:56:29 -07006007 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Tony Mak329047b2018-02-28 14:17:17 +00006008 * @throws SecurityException if {@code admin} is not a profile owner.
Adam Connors210fe212014-07-17 15:41:43 +01006009 */
Robin Lee25e26452015-06-02 09:56:29 -07006010 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006011 throwIfParentInstance("getCrossProfileCallerIdDisabled");
Adam Connors210fe212014-07-17 15:41:43 +01006012 if (mService != null) {
6013 try {
Robin Lee25e26452015-06-02 09:56:29 -07006014 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01006015 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006016 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01006017 }
6018 }
6019 return false;
6020 }
6021
6022 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07006023 * Determine whether or not caller-Id information has been disabled.
6024 *
6025 * @param userHandle The user for whom to check the caller-id permission
6026 * @hide
6027 */
6028 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
6029 if (mService != null) {
6030 try {
6031 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
6032 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006033 throw e.rethrowFromSystemServer();
Amith Yamasani570002f2014-07-18 15:48:54 -07006034 }
6035 }
6036 return false;
6037 }
6038
6039 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006040 * Called by a profile owner of a managed profile to set whether contacts search from the
6041 * managed profile will be shown in the parent profile, for incoming calls.
6042 * <p>
6043 * The calling device admin must be a profile owner. If it is not, a security exception will be
6044 * thrown.
Victor Chang1060c6182016-01-04 20:16:23 +00006045 *
6046 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6047 * @param disabled If true contacts search in the managed profile is not displayed.
Tony Mak329047b2018-02-28 14:17:17 +00006048 * @throws SecurityException if {@code admin} is not a profile owner.
Victor Chang1060c6182016-01-04 20:16:23 +00006049 */
6050 public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin,
6051 boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006052 throwIfParentInstance("setCrossProfileContactsSearchDisabled");
Victor Chang1060c6182016-01-04 20:16:23 +00006053 if (mService != null) {
6054 try {
6055 mService.setCrossProfileContactsSearchDisabled(admin, disabled);
6056 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006057 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00006058 }
6059 }
6060 }
6061
6062 /**
6063 * Called by a profile owner of a managed profile to determine whether or not contacts search
6064 * has been disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006065 * <p>
6066 * The calling device admin must be a profile owner. If it is not, a security exception will be
6067 * thrown.
Victor Chang1060c6182016-01-04 20:16:23 +00006068 *
6069 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Tony Mak329047b2018-02-28 14:17:17 +00006070 * @throws SecurityException if {@code admin} is not a profile owner.
Victor Chang1060c6182016-01-04 20:16:23 +00006071 */
6072 public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006073 throwIfParentInstance("getCrossProfileContactsSearchDisabled");
Victor Chang1060c6182016-01-04 20:16:23 +00006074 if (mService != null) {
6075 try {
6076 return mService.getCrossProfileContactsSearchDisabled(admin);
6077 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006078 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00006079 }
6080 }
6081 return false;
6082 }
6083
6084
6085 /**
6086 * Determine whether or not contacts search has been disabled.
6087 *
6088 * @param userHandle The user for whom to check the contacts search permission
6089 * @hide
6090 */
6091 public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) {
6092 if (mService != null) {
6093 try {
6094 return mService
6095 .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier());
6096 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006097 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00006098 }
6099 }
6100 return false;
6101 }
6102
6103 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08006104 * Start Quick Contact on the managed profile for the user, if the policy allows.
Victor Chang97bdacc2016-01-21 22:24:11 +00006105 *
Makoto Onuki1040da12015-03-19 11:24:00 -07006106 * @hide
6107 */
6108 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
Victor Chang97bdacc2016-01-21 22:24:11 +00006109 boolean isContactIdIgnored, long directoryId, Intent originalIntent) {
Makoto Onuki1040da12015-03-19 11:24:00 -07006110 if (mService != null) {
6111 try {
Victor Chang97bdacc2016-01-21 22:24:11 +00006112 mService.startManagedQuickContact(actualLookupKey, actualContactId,
6113 isContactIdIgnored, directoryId, originalIntent);
Makoto Onuki1040da12015-03-19 11:24:00 -07006114 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006115 throw e.rethrowFromSystemServer();
Makoto Onuki1040da12015-03-19 11:24:00 -07006116 }
6117 }
6118 }
6119
6120 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08006121 * Start Quick Contact on the managed profile for the user, if the policy allows.
Ricky Wai494b95d2015-11-20 16:07:15 +00006122 * @hide
6123 */
6124 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
6125 Intent originalIntent) {
Victor Chang97bdacc2016-01-21 22:24:11 +00006126 startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT,
Ricky Wai494b95d2015-11-20 16:07:15 +00006127 originalIntent);
6128 }
6129
6130 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006131 * Called by a profile owner of a managed profile to set whether bluetooth devices can access
6132 * enterprise contacts.
Ricky Wai778ba132015-03-31 14:21:22 +01006133 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006134 * The calling device admin must be a profile owner. If it is not, a security exception will be
6135 * thrown.
Ricky Wai778ba132015-03-31 14:21:22 +01006136 * <p>
6137 * This API works on managed profile only.
6138 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006139 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6140 * @param disabled If true, bluetooth devices cannot access enterprise contacts.
Tony Mak329047b2018-02-28 14:17:17 +00006141 * @throws SecurityException if {@code admin} is not a profile owner.
Ricky Wai778ba132015-03-31 14:21:22 +01006142 */
Robin Lee25e26452015-06-02 09:56:29 -07006143 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006144 throwIfParentInstance("setBluetoothContactSharingDisabled");
Ricky Wai778ba132015-03-31 14:21:22 +01006145 if (mService != null) {
6146 try {
Robin Lee25e26452015-06-02 09:56:29 -07006147 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01006148 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006149 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01006150 }
6151 }
6152 }
6153
6154 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006155 * Called by a profile owner of a managed profile to determine whether or not Bluetooth devices
6156 * cannot access enterprise contacts.
Ricky Wai778ba132015-03-31 14:21:22 +01006157 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006158 * The calling device admin must be a profile owner. If it is not, a security exception will be
6159 * thrown.
Ricky Wai778ba132015-03-31 14:21:22 +01006160 * <p>
6161 * This API works on managed profile only.
6162 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006163 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Tony Mak329047b2018-02-28 14:17:17 +00006164 * @throws SecurityException if {@code admin} is not a profile owner.
Ricky Wai778ba132015-03-31 14:21:22 +01006165 */
Robin Lee25e26452015-06-02 09:56:29 -07006166 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006167 throwIfParentInstance("getBluetoothContactSharingDisabled");
Ricky Wai778ba132015-03-31 14:21:22 +01006168 if (mService != null) {
6169 try {
Robin Lee25e26452015-06-02 09:56:29 -07006170 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01006171 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006172 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01006173 }
6174 }
6175 return true;
6176 }
6177
6178 /**
6179 * Determine whether or not Bluetooth devices cannot access contacts.
6180 * <p>
6181 * This API works on managed profile UserHandle only.
6182 *
6183 * @param userHandle The user for whom to check the caller-id permission
6184 * @hide
6185 */
6186 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
6187 if (mService != null) {
6188 try {
6189 return mService.getBluetoothContactSharingDisabledForUser(userHandle
6190 .getIdentifier());
6191 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006192 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01006193 }
6194 }
6195 return true;
6196 }
6197
6198 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07006199 * Called by the profile owner of a managed profile so that some intents sent in the managed
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006200 * profile can also be resolved in the parent, or vice versa. Only activity intents are
6201 * supported.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00006202 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00006203 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01006204 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006205 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01006206 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006207 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
6208 * @throws SecurityException if {@code admin} is not a device or profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00006209 */
Robin Lee25e26452015-06-02 09:56:29 -07006210 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006211 throwIfParentInstance("addCrossProfileIntentFilter");
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00006212 if (mService != null) {
6213 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01006214 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00006215 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006216 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00006217 }
6218 }
6219 }
6220
6221 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07006222 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
6223 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01006224 * Only removes those that have been set by the profile owner.
Rubin Xucc391c22018-01-02 20:37:35 +00006225 * <p>
6226 * <em>Note</em>: A list of default cross profile intent filters are set up by the system when
6227 * the profile is created, some of them ensure the proper functioning of the profile, while
6228 * others enable sharing of data from the parent to the managed profile for user convenience.
6229 * These default intent filters are not cleared when this API is called. If the default cross
6230 * profile data sharing is not desired, they can be disabled with
6231 * {@link UserManager#DISALLOW_SHARE_INTO_MANAGED_PROFILE}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006232 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00006233 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Tony Mak329047b2018-02-28 14:17:17 +00006234 * @throws SecurityException if {@code admin} is not a profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00006235 */
Robin Lee25e26452015-06-02 09:56:29 -07006236 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006237 throwIfParentInstance("clearCrossProfileIntentFilters");
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00006238 if (mService != null) {
6239 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01006240 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00006241 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006242 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00006243 }
6244 }
6245 }
6246
6247 /**
Tony Mak329047b2018-02-28 14:17:17 +00006248 * Called by a profile or device owner to set the permitted
6249 * {@link android.accessibilityservice.AccessibilityService}. When set by
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006250 * a device owner or profile owner the restriction applies to all profiles of the user the
Tony Mak329047b2018-02-28 14:17:17 +00006251 * device owner or profile owner is an admin for. By default, the user can use any accessibility
6252 * service. When zero or more packages have been added, accessibility services that are not in
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006253 * the list and not part of the system can not be enabled by the user.
6254 * <p>
6255 * Calling with a null value for the list disables the restriction so that all services can be
Tony Mak329047b2018-02-28 14:17:17 +00006256 * used, calling with an empty list only allows the built-in system services. Any non-system
6257 * accessibility service that's currently enabled must be included in the list.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006258 * <p>
Esteban Talavera7e4cbad2017-03-30 17:59:50 +01006259 * System accessibility services are always available to the user the list can't modify this.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006260 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6261 * @param packageNames List of accessibility service package names.
Tony Mak329047b2018-02-28 14:17:17 +00006262 * @return {@code true} if the operation succeeded, or {@code false} if the list didn't
6263 * contain every enabled non-system accessibility service.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006264 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006265 */
Robin Lee25e26452015-06-02 09:56:29 -07006266 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006267 List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006268 throwIfParentInstance("setPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006269 if (mService != null) {
6270 try {
6271 return mService.setPermittedAccessibilityServices(admin, packageNames);
6272 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006273 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006274 }
6275 }
6276 return false;
6277 }
6278
6279 /**
6280 * Returns the list of permitted accessibility services set by this device or profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006281 * <p>
6282 * An empty list means no accessibility services except system services are allowed. Null means
6283 * all accessibility services are allowed.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006284 *
6285 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6286 * @return List of accessiblity service package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006287 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006288 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006289 public @Nullable List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006290 throwIfParentInstance("getPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006291 if (mService != null) {
6292 try {
6293 return mService.getPermittedAccessibilityServices(admin);
6294 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006295 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006296 }
6297 }
6298 return null;
6299 }
6300
6301 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00006302 * Called by the system to check if a specific accessibility service is disabled by admin.
6303 *
6304 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6305 * @param packageName Accessibility service package name that needs to be checked.
6306 * @param userHandle user id the admin is running as.
6307 * @return true if the accessibility service is permitted, otherwise false.
6308 *
6309 * @hide
6310 */
6311 public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin,
6312 @NonNull String packageName, int userHandle) {
6313 if (mService != null) {
6314 try {
6315 return mService.isAccessibilityServicePermittedByAdmin(admin, packageName,
6316 userHandle);
6317 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006318 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00006319 }
6320 }
6321 return false;
6322 }
6323
6324 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006325 * Returns the list of accessibility services permitted by the device or profiles
6326 * owners of this user.
6327 *
6328 * <p>Null means all accessibility services are allowed, if a non-null list is returned
6329 * it will contain the intersection of the permitted lists for any device or profile
6330 * owners that apply to this user. It will also include any system accessibility services.
6331 *
6332 * @param userId which user to check for.
6333 * @return List of accessiblity service package names.
6334 * @hide
6335 */
6336 @SystemApi
Eric Sandness5ab98de2018-04-03 18:12:39 +01006337 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Makoto Onuki408e8e42016-10-25 12:10:27 -07006338 public @Nullable List<String> getPermittedAccessibilityServices(int userId) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006339 throwIfParentInstance("getPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006340 if (mService != null) {
6341 try {
6342 return mService.getPermittedAccessibilityServicesForUser(userId);
6343 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006344 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006345 }
6346 }
6347 return null;
6348 }
6349
6350 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006351 * Called by a profile or device owner to set the permitted input methods services. When set by
6352 * a device owner or profile owner the restriction applies to all profiles of the user the
Tony Mak329047b2018-02-28 14:17:17 +00006353 * 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 -07006354 * When zero or more packages have been added, input method that are not in the list and not
6355 * 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 +00006356 * a admin that is not for the foreground user or a profile of the foreground user. Any
6357 * non-system input method service that's currently enabled must be included in the list.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006358 * <p>
6359 * Calling with a null value for the list disables the restriction so that all input methods can
6360 * be used, calling with an empty list disables all but the system's own input methods.
6361 * <p>
6362 * System input methods are always available to the user this method can't modify this.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006363 *
6364 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6365 * @param packageNames List of input method package names.
Tony Mak329047b2018-02-28 14:17:17 +00006366 * @return {@code true} if the operation succeeded, or {@code false} if the list didn't
6367 * contain every enabled non-system input method service.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006368 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006369 */
Esteban Talavera7e4cbad2017-03-30 17:59:50 +01006370 public boolean setPermittedInputMethods(
6371 @NonNull ComponentName admin, List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006372 throwIfParentInstance("setPermittedInputMethods");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006373 if (mService != null) {
6374 try {
6375 return mService.setPermittedInputMethods(admin, packageNames);
6376 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006377 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006378 }
6379 }
6380 return false;
6381 }
6382
6383
6384 /**
6385 * Returns the list of permitted input methods set by this device or profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006386 * <p>
6387 * An empty list means no input methods except system input methods are allowed. Null means all
6388 * input methods are allowed.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006389 *
6390 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6391 * @return List of input method package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006392 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006393 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006394 public @Nullable List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006395 throwIfParentInstance("getPermittedInputMethods");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006396 if (mService != null) {
6397 try {
6398 return mService.getPermittedInputMethods(admin);
6399 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006400 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006401 }
6402 }
6403 return null;
6404 }
6405
6406 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00006407 * Called by the system to check if a specific input method is disabled by admin.
6408 *
6409 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6410 * @param packageName Input method package name that needs to be checked.
6411 * @param userHandle user id the admin is running as.
6412 * @return true if the input method is permitted, otherwise false.
6413 *
6414 * @hide
6415 */
6416 public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin,
6417 @NonNull String packageName, int userHandle) {
6418 if (mService != null) {
6419 try {
6420 return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle);
6421 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006422 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00006423 }
6424 }
6425 return false;
6426 }
6427
6428 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006429 * Returns the list of input methods permitted by the device or profiles
Makoto Onuki32b30572015-12-11 14:29:51 -08006430 * owners of the current user. (*Not* calling user, due to a limitation in InputMethodManager.)
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006431 *
6432 * <p>Null means all input methods are allowed, if a non-null list is returned
6433 * it will contain the intersection of the permitted lists for any device or profile
6434 * owners that apply to this user. It will also include any system input methods.
6435 *
6436 * @return List of input method package names.
6437 * @hide
6438 */
6439 @SystemApi
Eric Sandness57378932018-03-27 13:22:52 +01006440 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Makoto Onuki408e8e42016-10-25 12:10:27 -07006441 public @Nullable List<String> getPermittedInputMethodsForCurrentUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006442 throwIfParentInstance("getPermittedInputMethodsForCurrentUser");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006443 if (mService != null) {
6444 try {
6445 return mService.getPermittedInputMethodsForCurrentUser();
6446 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006447 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006448 }
6449 }
6450 return null;
6451 }
6452
6453 /**
Esteban Talavera7e4cbad2017-03-30 17:59:50 +01006454 * Called by a profile owner of a managed profile to set the packages that are allowed to use
6455 * a {@link android.service.notification.NotificationListenerService} in the primary user to
6456 * see notifications from the managed profile. By default all packages are permitted by this
6457 * policy. When zero or more packages have been added, notification listeners installed on the
6458 * primary user that are not in the list and are not part of the system won't receive events
6459 * for managed profile notifications.
6460 * <p>
6461 * Calling with a {@code null} value for the list disables the restriction so that all
6462 * notification listener services be used. Calling with an empty list disables all but the
6463 * system's own notification listeners. System notification listener services are always
6464 * available to the user.
6465 * <p>
6466 * If a device or profile owner want to stop notification listeners in their user from seeing
6467 * that user's notifications they should prevent that service from running instead (e.g. via
6468 * {@link #setApplicationHidden(ComponentName, String, boolean)})
6469 *
6470 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6471 * @param packageList List of package names to whitelist
6472 * @return true if setting the restriction succeeded. It will fail if called outside a managed
6473 * profile
6474 * @throws SecurityException if {@code admin} is not a profile owner.
6475 *
6476 * @see android.service.notification.NotificationListenerService
6477 */
6478 public boolean setPermittedCrossProfileNotificationListeners(
6479 @NonNull ComponentName admin, @Nullable List<String> packageList) {
6480 throwIfParentInstance("setPermittedCrossProfileNotificationListeners");
6481 if (mService != null) {
6482 try {
6483 return mService.setPermittedCrossProfileNotificationListeners(admin, packageList);
6484 } catch (RemoteException e) {
6485 throw e.rethrowFromSystemServer();
6486 }
6487 }
6488 return false;
6489 }
6490
6491 /**
6492 * Returns the list of packages installed on the primary user that allowed to use a
6493 * {@link android.service.notification.NotificationListenerService} to receive
6494 * notifications from this managed profile, as set by the profile owner.
6495 * <p>
6496 * An empty list means no notification listener services except system ones are allowed.
6497 * A {@code null} return value indicates that all notification listeners are allowed.
6498 */
6499 public @Nullable List<String> getPermittedCrossProfileNotificationListeners(
6500 @NonNull ComponentName admin) {
6501 throwIfParentInstance("getPermittedCrossProfileNotificationListeners");
6502 if (mService != null) {
6503 try {
6504 return mService.getPermittedCrossProfileNotificationListeners(admin);
6505 } catch (RemoteException e) {
6506 throw e.rethrowFromSystemServer();
6507 }
6508 }
6509 return null;
6510 }
6511
6512 /**
6513 * Returns true if {@code NotificationListenerServices} from the given package are allowed to
6514 * receive events for notifications from the given user id. Can only be called by the system uid
6515 *
6516 * @see #setPermittedCrossProfileNotificationListeners(ComponentName, List)
6517 *
6518 * @hide
6519 */
6520 public boolean isNotificationListenerServicePermitted(
6521 @NonNull String packageName, @UserIdInt int userId) {
6522 if (mService != null) {
6523 try {
6524 return mService.isNotificationListenerServicePermitted(packageName, userId);
6525 } catch (RemoteException e) {
6526 throw e.rethrowFromSystemServer();
6527 }
6528 }
6529 return true;
6530 }
6531
6532 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006533 * Get the list of apps to keep around as APKs even if no user has currently installed it. This
6534 * function can be called by a device owner or by a delegate given the
6535 * {@link #DELEGATION_KEEP_UNINSTALLED_PACKAGES} scope via {@link #setDelegatedScopes}.
6536 * <p>
6537 * Please note that packages returned in this method are not automatically pre-cached.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08006538 *
Edman Anjos52088e42017-01-13 22:26:17 +01006539 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
6540 * {@code null} if the caller is a keep uninstalled packages delegate.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08006541 * @return List of package names to keep cached.
Edman Anjos52088e42017-01-13 22:26:17 +01006542 * @see #setDelegatedScopes
6543 * @see #DELEGATION_KEEP_UNINSTALLED_PACKAGES
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08006544 */
Edman Anjos52088e42017-01-13 22:26:17 +01006545 public @Nullable List<String> getKeepUninstalledPackages(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006546 throwIfParentInstance("getKeepUninstalledPackages");
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08006547 if (mService != null) {
6548 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006549 return mService.getKeepUninstalledPackages(admin, mContext.getPackageName());
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08006550 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006551 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08006552 }
6553 }
6554 return null;
6555 }
6556
6557 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006558 * Set a list of apps to keep around as APKs even if no user has currently installed it. This
6559 * function can be called by a device owner or by a delegate given the
6560 * {@link #DELEGATION_KEEP_UNINSTALLED_PACKAGES} scope via {@link #setDelegatedScopes}.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08006561 *
6562 * <p>Please note that setting this policy does not imply that specified apps will be
6563 * automatically pre-cached.</p>
6564 *
Edman Anjos52088e42017-01-13 22:26:17 +01006565 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
6566 * {@code null} if the caller is a keep uninstalled packages delegate.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08006567 * @param packageNames List of package names to keep cached.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006568 * @throws SecurityException if {@code admin} is not a device owner.
Edman Anjos52088e42017-01-13 22:26:17 +01006569 * @see #setDelegatedScopes
6570 * @see #DELEGATION_KEEP_UNINSTALLED_PACKAGES
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08006571 */
Edman Anjos52088e42017-01-13 22:26:17 +01006572 public void setKeepUninstalledPackages(@Nullable ComponentName admin,
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08006573 @NonNull List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006574 throwIfParentInstance("setKeepUninstalledPackages");
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08006575 if (mService != null) {
6576 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006577 mService.setKeepUninstalledPackages(admin, mContext.getPackageName(), packageNames);
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08006578 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006579 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08006580 }
6581 }
6582 }
6583
6584 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04006585 * Called by a device owner to create a user with the specified name. The UserHandle returned
6586 * by this method should not be persisted as user handles are recycled as users are removed and
6587 * created. If you need to persist an identifier for this user, use
6588 * {@link UserManager#getSerialNumberForUser}.
6589 *
6590 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6591 * @param name the user's name
6592 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07006593 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
6594 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01006595 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07006596 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01006597 * @removed From {@link android.os.Build.VERSION_CODES#N}
Julia Reynolds1e958392014-05-16 14:25:21 -04006598 */
Kenny Guy14f48e52015-06-29 15:12:36 +01006599 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07006600 public @Nullable UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04006601 return null;
6602 }
6603
6604 /**
Jason Monk03978a42014-06-10 15:05:30 -04006605 * Called by a device owner to create a user with the specified name. The UserHandle returned
6606 * by this method should not be persisted as user handles are recycled as users are removed and
6607 * created. If you need to persist an identifier for this user, use
6608 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
6609 * immediately.
6610 *
6611 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
6612 * as registered as an active admin on the new user. The profile owner package will be
6613 * installed on the new user if it already is installed on the device.
6614 *
6615 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
6616 * profileOwnerComponent when onEnable is called.
6617 *
6618 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6619 * @param name the user's name
6620 * @param ownerName the human readable name of the organisation associated with this DPM.
6621 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
6622 * the user.
6623 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
6624 * on the new user.
6625 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07006626 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
6627 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01006628 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07006629 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01006630 * @removed From {@link android.os.Build.VERSION_CODES#N}
Jason Monk03978a42014-06-10 15:05:30 -04006631 */
Kenny Guy14f48e52015-06-29 15:12:36 +01006632 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07006633 public @Nullable UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
Robin Lee25e26452015-06-02 09:56:29 -07006634 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04006635 return null;
6636 }
6637
6638 /**
phweissa92e1212016-01-25 17:14:10 +01006639 * Flag used by {@link #createAndManageUser} to skip setup wizard after creating a new user.
phweiss343fb332016-01-25 14:48:59 +01006640 */
6641 public static final int SKIP_SETUP_WIZARD = 0x0001;
6642
6643 /**
Lenka Trochtovac8202c82016-01-26 15:11:09 +01006644 * Flag used by {@link #createAndManageUser} to specify that the user should be created
Alex Chau6badae62017-10-27 17:46:16 +01006645 * ephemeral. Ephemeral users will be removed after switching to another user or rebooting the
6646 * device.
Lenka Trochtovac8202c82016-01-26 15:11:09 +01006647 */
6648 public static final int MAKE_USER_EPHEMERAL = 0x0002;
6649
6650 /**
Christine Franks361b8252017-06-23 18:12:46 -07006651 * Flag used by {@link #createAndManageUser} to specify that the user should be created as a
6652 * demo user.
6653 * @hide
6654 */
6655 public static final int MAKE_USER_DEMO = 0x0004;
6656
6657 /**
Alex Chaub6a9f942017-11-07 11:28:56 +08006658 * Flag used by {@link #createAndManageUser} to specify that the newly created user should skip
6659 * the disabling of system apps during provisioning.
6660 */
6661 public static final int LEAVE_ALL_SYSTEM_APPS_ENABLED = 0x0010;
6662
6663 /**
Benjamin Franz77c94a92017-08-09 14:16:03 +01006664 * @hide
6665 */
Jeff Sharkeyce8db992017-12-13 20:05:05 -07006666 @IntDef(flag = true, prefix = { "SKIP_", "MAKE_USER_", "START_", "LEAVE_" }, value = {
6667 SKIP_SETUP_WIZARD,
6668 MAKE_USER_EPHEMERAL,
6669 MAKE_USER_DEMO,
Jeff Sharkeyce8db992017-12-13 20:05:05 -07006670 LEAVE_ALL_SYSTEM_APPS_ENABLED
6671 })
Benjamin Franz77c94a92017-08-09 14:16:03 +01006672 @Retention(RetentionPolicy.SOURCE)
6673 public @interface CreateAndManageUserFlags {}
6674
6675
6676 /**
phweissa92e1212016-01-25 17:14:10 +01006677 * Called by a device owner to create a user with the specified name and a given component of
6678 * the calling package as profile owner. The UserHandle returned by this method should not be
6679 * persisted as user handles are recycled as users are removed and created. If you need to
6680 * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new
6681 * user will not be started in the background.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006682 * <p>
6683 * admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also a
6684 * DeviceAdminReceiver in the same package as admin, and will become the profile owner and will
6685 * be registered as an active admin on the new user. The profile owner package will be installed
6686 * on the new user.
6687 * <p>
6688 * If the adminExtras are not null, they will be stored on the device until the user is started
6689 * for the first time. Then the extras will be passed to the admin when onEnable is called.
Alex Chau89386ba2018-02-13 11:09:17 +08006690 * <p>From {@link android.os.Build.VERSION_CODES#P} onwards, if targeting
6691 * {@link android.os.Build.VERSION_CODES#P}, throws {@link UserOperationException} instead of
6692 * returning {@code null} on failure.
phweiss343fb332016-01-25 14:48:59 +01006693 *
6694 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6695 * @param name The user's name.
phweissa92e1212016-01-25 17:14:10 +01006696 * @param profileOwner Which {@link DeviceAdminReceiver} will be profile owner. Has to be in the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006697 * same package as admin, otherwise no user is created and an
6698 * IllegalArgumentException is thrown.
phweiss343fb332016-01-25 14:48:59 +01006699 * @param adminExtras Extras that will be passed to onEnable of the admin receiver on the new
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006700 * user.
Alex Chaub6ef8692018-01-09 14:16:36 +00006701 * @param flags {@link #SKIP_SETUP_WIZARD}, {@link #MAKE_USER_EPHEMERAL} and
6702 * {@link #LEAVE_ALL_SYSTEM_APPS_ENABLED} are supported.
phweiss343fb332016-01-25 14:48:59 +01006703 * @see UserHandle
6704 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
6705 * user could not be created.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006706 * @throws SecurityException if {@code admin} is not a device owner.
Alex Chau89386ba2018-02-13 11:09:17 +08006707 * @throws UserOperationException if the user could not be created and the calling app is
6708 * targeting {@link android.os.Build.VERSION_CODES#P} and running on
6709 * {@link android.os.Build.VERSION_CODES#P}.
phweiss343fb332016-01-25 14:48:59 +01006710 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006711 public @Nullable UserHandle createAndManageUser(@NonNull ComponentName admin,
6712 @NonNull String name,
phweissa92e1212016-01-25 17:14:10 +01006713 @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras,
Benjamin Franz77c94a92017-08-09 14:16:03 +01006714 @CreateAndManageUserFlags int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006715 throwIfParentInstance("createAndManageUser");
phweiss343fb332016-01-25 14:48:59 +01006716 try {
phweissa92e1212016-01-25 17:14:10 +01006717 return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags);
Alex Chau89386ba2018-02-13 11:09:17 +08006718 } catch (ServiceSpecificException e) {
6719 throw new UserOperationException(e.getMessage(), e.errorCode);
phweiss343fb332016-01-25 14:48:59 +01006720 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006721 throw re.rethrowFromSystemServer();
phweiss343fb332016-01-25 14:48:59 +01006722 }
phweiss343fb332016-01-25 14:48:59 +01006723 }
6724
6725 /**
Alex Chaub6ef8692018-01-09 14:16:36 +00006726 * Called by a device owner to remove a user/profile and all associated data. The primary user
6727 * can not be removed.
Julia Reynolds1e958392014-05-16 14:25:21 -04006728 *
6729 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6730 * @param userHandle the user to remove.
6731 * @return {@code true} if the user was removed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006732 * @throws SecurityException if {@code admin} is not a device owner.
Julia Reynolds1e958392014-05-16 14:25:21 -04006733 */
Alex Chauaf9bb8d2017-12-06 14:38:25 +00006734 public boolean removeUser(@NonNull ComponentName admin, @NonNull UserHandle userHandle) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006735 throwIfParentInstance("removeUser");
Julia Reynolds1e958392014-05-16 14:25:21 -04006736 try {
6737 return mService.removeUser(admin, userHandle);
6738 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006739 throw re.rethrowFromSystemServer();
Julia Reynolds1e958392014-05-16 14:25:21 -04006740 }
6741 }
6742
6743 /**
Alex Chaub6ef8692018-01-09 14:16:36 +00006744 * Called by a device owner to switch the specified secondary user to the foreground.
Jason Monk582d9112014-07-09 19:57:08 -04006745 *
6746 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6747 * @param userHandle the user to switch to; null will switch to primary.
6748 * @return {@code true} if the switch was successful, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006749 * @throws SecurityException if {@code admin} is not a device owner.
Jason Monk582d9112014-07-09 19:57:08 -04006750 * @see Intent#ACTION_USER_FOREGROUND
Alex Chaub6ef8692018-01-09 14:16:36 +00006751 * @see #getSecondaryUsers(ComponentName)
Jason Monk582d9112014-07-09 19:57:08 -04006752 */
Robin Lee25e26452015-06-02 09:56:29 -07006753 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006754 throwIfParentInstance("switchUser");
Jason Monk582d9112014-07-09 19:57:08 -04006755 try {
6756 return mService.switchUser(admin, userHandle);
6757 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006758 throw re.rethrowFromSystemServer();
Jason Monk582d9112014-07-09 19:57:08 -04006759 }
6760 }
6761
6762 /**
Alex Chaub6ef8692018-01-09 14:16:36 +00006763 * Called by a device owner to start the specified secondary user in background.
6764 *
6765 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Alex Chau596c2882018-01-29 14:39:37 +00006766 * @param userHandle the user to be started in background.
6767 * @return one of the following result codes:
Alex Chau89386ba2018-02-13 11:09:17 +08006768 * {@link UserManager#USER_OPERATION_ERROR_UNKNOWN},
6769 * {@link UserManager#USER_OPERATION_SUCCESS},
6770 * {@link UserManager#USER_OPERATION_ERROR_MANAGED_PROFILE},
6771 * {@link UserManager#USER_OPERATION_ERROR_MAX_RUNNING_USERS},
Alex Chaub6ef8692018-01-09 14:16:36 +00006772 * @throws SecurityException if {@code admin} is not a device owner.
6773 * @see #getSecondaryUsers(ComponentName)
6774 */
Alex Chau596c2882018-01-29 14:39:37 +00006775 public @UserOperationResult int startUserInBackground(
Alex Chaub6ef8692018-01-09 14:16:36 +00006776 @NonNull ComponentName admin, @NonNull UserHandle userHandle) {
6777 throwIfParentInstance("startUserInBackground");
6778 try {
6779 return mService.startUserInBackground(admin, userHandle);
6780 } catch (RemoteException re) {
6781 throw re.rethrowFromSystemServer();
6782 }
6783 }
6784
6785 /**
Alex Chauaf9bb8d2017-12-06 14:38:25 +00006786 * Called by a device owner to stop the specified secondary user.
Alex Chauaf9bb8d2017-12-06 14:38:25 +00006787 *
6788 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6789 * @param userHandle the user to be stopped.
Alex Chau596c2882018-01-29 14:39:37 +00006790 * @return one of the following result codes:
Alex Chau89386ba2018-02-13 11:09:17 +08006791 * {@link UserManager#USER_OPERATION_ERROR_UNKNOWN},
6792 * {@link UserManager#USER_OPERATION_SUCCESS},
6793 * {@link UserManager#USER_OPERATION_ERROR_MANAGED_PROFILE},
6794 * {@link UserManager#USER_OPERATION_ERROR_CURRENT_USER}
Alex Chauaf9bb8d2017-12-06 14:38:25 +00006795 * @throws SecurityException if {@code admin} is not a device owner.
Alex Chaub6ef8692018-01-09 14:16:36 +00006796 * @see #getSecondaryUsers(ComponentName)
Alex Chauaf9bb8d2017-12-06 14:38:25 +00006797 */
Alex Chau596c2882018-01-29 14:39:37 +00006798 public @UserOperationResult int stopUser(
6799 @NonNull ComponentName admin, @NonNull UserHandle userHandle) {
Alex Chauaf9bb8d2017-12-06 14:38:25 +00006800 throwIfParentInstance("stopUser");
6801 try {
6802 return mService.stopUser(admin, userHandle);
6803 } catch (RemoteException re) {
6804 throw re.rethrowFromSystemServer();
6805 }
6806 }
6807
6808 /**
Alex Chaub6ef8692018-01-09 14:16:36 +00006809 * Called by a profile owner of secondary user that is affiliated with the device to stop the
6810 * calling user and switch back to primary.
Alex Chauaf9bb8d2017-12-06 14:38:25 +00006811 *
6812 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Alex Chau596c2882018-01-29 14:39:37 +00006813 * @return one of the following result codes:
Alex Chau89386ba2018-02-13 11:09:17 +08006814 * {@link UserManager#USER_OPERATION_ERROR_UNKNOWN},
6815 * {@link UserManager#USER_OPERATION_SUCCESS},
6816 * {@link UserManager#USER_OPERATION_ERROR_MANAGED_PROFILE},
6817 * {@link UserManager#USER_OPERATION_ERROR_CURRENT_USER}
Alex Chau443b6432017-12-13 12:44:31 +00006818 * @throws SecurityException if {@code admin} is not a profile owner affiliated with the device.
Alex Chaub6ef8692018-01-09 14:16:36 +00006819 * @see #getSecondaryUsers(ComponentName)
Alex Chauaf9bb8d2017-12-06 14:38:25 +00006820 */
Alex Chau596c2882018-01-29 14:39:37 +00006821 public @UserOperationResult int logoutUser(@NonNull ComponentName admin) {
Alex Chauaf9bb8d2017-12-06 14:38:25 +00006822 throwIfParentInstance("logoutUser");
6823 try {
6824 return mService.logoutUser(admin);
6825 } catch (RemoteException re) {
6826 throw re.rethrowFromSystemServer();
6827 }
6828 }
6829
6830 /**
Alex Chaub6ef8692018-01-09 14:16:36 +00006831 * Called by a device owner to list all secondary users on the device. Managed profiles are not
6832 * considered as secondary users.
Alex Chauaf9bb8d2017-12-06 14:38:25 +00006833 * <p> Used for various user management APIs, including {@link #switchUser}, {@link #removeUser}
6834 * and {@link #stopUser}.
6835 *
6836 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6837 * @return list of other {@link UserHandle}s on the device.
6838 * @throws SecurityException if {@code admin} is not a device owner.
Alex Chaub6ef8692018-01-09 14:16:36 +00006839 * @see #removeUser(ComponentName, UserHandle)
6840 * @see #switchUser(ComponentName, UserHandle)
6841 * @see #startUserInBackground(ComponentName, UserHandle)
6842 * @see #stopUser(ComponentName, UserHandle)
Alex Chauaf9bb8d2017-12-06 14:38:25 +00006843 */
6844 public List<UserHandle> getSecondaryUsers(@NonNull ComponentName admin) {
6845 throwIfParentInstance("getSecondaryUsers");
6846 try {
6847 return mService.getSecondaryUsers(admin);
6848 } catch (RemoteException re) {
6849 throw re.rethrowFromSystemServer();
6850 }
6851 }
6852
6853 /**
Alex Chau8d6e18c2017-12-08 18:11:27 +00006854 * Checks if the profile owner is running in an ephemeral user.
6855 *
6856 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6857 * @return whether the profile owner is running in an ephemeral user.
6858 */
6859 public boolean isEphemeralUser(@NonNull ComponentName admin) {
6860 throwIfParentInstance("isEphemeralUser");
6861 try {
6862 return mService.isEphemeralUser(admin);
6863 } catch (RemoteException re) {
6864 throw re.rethrowFromSystemServer();
6865 }
6866 }
6867
6868 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00006869 * Retrieves the application restrictions for a given target application running in the calling
6870 * user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006871 * <p>
6872 * 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 +01006873 * application restrictions via {@link #setDelegatedScopes} with the
6874 * {@link #DELEGATION_APP_RESTRICTIONS} scope; otherwise a security exception will be thrown.
Robin Lee66e5d962014-04-09 16:44:21 +01006875 *
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07006876 * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
6877 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00006878 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006879 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01006880 * @param packageName The name of the package to fetch restricted settings of.
6881 * @return {@link Bundle} of settings corresponding to what was set last time
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006882 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty
6883 * {@link Bundle} if no restrictions have been set.
6884 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01006885 * @see #setDelegatedScopes
6886 * @see #DELEGATION_APP_RESTRICTIONS
Robin Lee66e5d962014-04-09 16:44:21 +01006887 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07006888 @WorkerThread
Makoto Onuki408e8e42016-10-25 12:10:27 -07006889 public @NonNull Bundle getApplicationRestrictions(
6890 @Nullable ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006891 throwIfParentInstance("getApplicationRestrictions");
Robin Lee66e5d962014-04-09 16:44:21 +01006892 if (mService != null) {
6893 try {
Edman Anjosf9946772016-11-28 16:35:15 +01006894 return mService.getApplicationRestrictions(admin, mContext.getPackageName(),
6895 packageName);
Robin Lee66e5d962014-04-09 16:44:21 +01006896 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006897 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01006898 }
6899 }
6900 return null;
6901 }
Amith Yamasanibe465322014-04-24 13:45:17 -07006902
6903 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05006904 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07006905 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006906 * The calling device admin must be a profile or device owner; if it is not, a security
6907 * exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07006908 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006909 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6910 * @param key The key of the restriction. See the constants in {@link android.os.UserManager}
6911 * for the list of keys.
6912 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanibe465322014-04-24 13:45:17 -07006913 */
Robin Lee25e26452015-06-02 09:56:29 -07006914 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006915 throwIfParentInstance("addUserRestriction");
Amith Yamasanibe465322014-04-24 13:45:17 -07006916 if (mService != null) {
6917 try {
6918 mService.setUserRestriction(admin, key, true);
6919 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006920 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07006921 }
6922 }
6923 }
6924
6925 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05006926 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07006927 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006928 * The calling device admin must be a profile or device owner; if it is not, a security
6929 * exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07006930 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006931 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6932 * @param key The key of the restriction. See the constants in {@link android.os.UserManager}
6933 * for the list of keys.
6934 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanibe465322014-04-24 13:45:17 -07006935 */
Robin Lee25e26452015-06-02 09:56:29 -07006936 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006937 throwIfParentInstance("clearUserRestriction");
Amith Yamasanibe465322014-04-24 13:45:17 -07006938 if (mService != null) {
6939 try {
6940 mService.setUserRestriction(admin, key, false);
6941 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006942 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07006943 }
6944 }
6945 }
Adam Connors010cfd42014-04-16 12:48:13 +01006946
6947 /**
Makoto Onuki3a3092f2015-10-30 11:07:51 -07006948 * Called by a profile or device owner to get user restrictions set with
6949 * {@link #addUserRestriction(ComponentName, String)}.
6950 * <p>
6951 * The target user may have more restrictions set by the system or other device owner / profile
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006952 * owner. To get all the user restrictions currently set, use
Makoto Onuki3a3092f2015-10-30 11:07:51 -07006953 * {@link UserManager#getUserRestrictions()}.
6954 *
6955 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006956 * @throws SecurityException if {@code admin} is not a device or profile owner.
Makoto Onuki3a3092f2015-10-30 11:07:51 -07006957 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006958 public @NonNull Bundle getUserRestrictions(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006959 throwIfParentInstance("getUserRestrictions");
Makoto Onuki3a3092f2015-10-30 11:07:51 -07006960 Bundle ret = null;
6961 if (mService != null) {
6962 try {
Sudheer Shanka549b9692016-03-30 17:12:07 -07006963 ret = mService.getUserRestrictions(admin);
6964 } catch (RemoteException e) {
6965 throw e.rethrowFromSystemServer();
6966 }
6967 }
6968 return ret == null ? new Bundle() : ret;
6969 }
6970
6971 /**
phweiss73145f42017-01-17 19:06:38 +01006972 * Called by any app to display a support dialog when a feature was disabled by an admin.
6973 * This returns an intent that can be used with {@link Context#startActivity(Intent)} to
6974 * display the dialog. It will tell the user that the feature indicated by {@code restriction}
6975 * was disabled by an admin, and include a link for more information. The default content of
6976 * the dialog can be changed by the restricting admin via
6977 * {@link #setShortSupportMessage(ComponentName, CharSequence)}. If the restriction is not
6978 * set (i.e. the feature is available), then the return value will be {@code null}.
6979 * @param restriction Indicates for which feature the dialog should be displayed. Can be a
6980 * user restriction from {@link UserManager}, e.g.
6981 * {@link UserManager#DISALLOW_ADJUST_VOLUME}, or one of the constants
Lenka Trochtova27fd8212018-04-10 11:01:58 +02006982 * {@link #POLICY_DISABLE_CAMERA}, {@link #POLICY_DISABLE_SCREEN_CAPTURE}.
phweiss73145f42017-01-17 19:06:38 +01006983 * @return Intent An intent to be used to start the dialog-activity if the restriction is
6984 * set by an admin, or null if the restriction does not exist or no admin set it.
6985 */
6986 public Intent createAdminSupportIntent(@NonNull String restriction) {
6987 throwIfParentInstance("createAdminSupportIntent");
6988 if (mService != null) {
6989 try {
6990 return mService.createAdminSupportIntent(restriction);
6991 } catch (RemoteException e) {
6992 throw e.rethrowFromSystemServer();
6993 }
6994 }
6995 return null;
6996 }
6997
6998 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006999 * Hide or unhide packages. When a package is hidden it is unavailable for use, but the data and
7000 * actual package file remain. This function can be called by a device owner, profile owner, or
7001 * by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via
7002 * {@link #setDelegatedScopes}.
Julia Reynolds966881e2014-05-14 12:23:08 -04007003 *
Edman Anjos52088e42017-01-13 22:26:17 +01007004 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
7005 * {@code null} if the caller is a package access delegate.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07007006 * @param packageName The name of the package to hide or unhide.
7007 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007008 * unhidden.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07007009 * @return boolean Whether the hidden setting of the package was successfully updated.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007010 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01007011 * @see #setDelegatedScopes
7012 * @see #DELEGATION_PACKAGE_ACCESS
Julia Reynolds966881e2014-05-14 12:23:08 -04007013 */
Robin Lee25e26452015-06-02 09:56:29 -07007014 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07007015 boolean hidden) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007016 throwIfParentInstance("setApplicationHidden");
Julia Reynolds966881e2014-05-14 12:23:08 -04007017 if (mService != null) {
7018 try {
Edman Anjos52088e42017-01-13 22:26:17 +01007019 return mService.setApplicationHidden(admin, mContext.getPackageName(), packageName,
7020 hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04007021 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007022 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04007023 }
7024 }
7025 return false;
7026 }
7027
7028 /**
Edman Anjos52088e42017-01-13 22:26:17 +01007029 * Determine if a package is hidden. This function can be called by a device owner, profile
7030 * owner, or by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via
7031 * {@link #setDelegatedScopes}.
Julia Reynolds966881e2014-05-14 12:23:08 -04007032 *
Edman Anjos52088e42017-01-13 22:26:17 +01007033 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
7034 * {@code null} if the caller is a package access delegate.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07007035 * @param packageName The name of the package to retrieve the hidden status of.
7036 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007037 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01007038 * @see #setDelegatedScopes
7039 * @see #DELEGATION_PACKAGE_ACCESS
Julia Reynolds966881e2014-05-14 12:23:08 -04007040 */
Robin Lee25e26452015-06-02 09:56:29 -07007041 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007042 throwIfParentInstance("isApplicationHidden");
Julia Reynolds966881e2014-05-14 12:23:08 -04007043 if (mService != null) {
7044 try {
Edman Anjos52088e42017-01-13 22:26:17 +01007045 return mService.isApplicationHidden(admin, mContext.getPackageName(), packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04007046 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007047 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04007048 }
7049 }
7050 return false;
7051 }
7052
7053 /**
Edman Anjos52088e42017-01-13 22:26:17 +01007054 * Re-enable a system app that was disabled by default when the user was initialized. This
7055 * function can be called by a device owner, profile owner, or by a delegate given the
7056 * {@link #DELEGATION_ENABLE_SYSTEM_APP} scope via {@link #setDelegatedScopes}.
Adam Connors655be2a2014-07-14 09:01:25 +00007057 *
Edman Anjos52088e42017-01-13 22:26:17 +01007058 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
7059 * {@code null} if the caller is an enable system app delegate.
Makoto Onuki32b30572015-12-11 14:29:51 -08007060 * @param packageName The package to be re-enabled in the calling profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007061 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01007062 * @see #setDelegatedScopes
7063 * @see #DELEGATION_PACKAGE_ACCESS
Adam Connors655be2a2014-07-14 09:01:25 +00007064 */
Robin Lee25e26452015-06-02 09:56:29 -07007065 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007066 throwIfParentInstance("enableSystemApp");
Adam Connors655be2a2014-07-14 09:01:25 +00007067 if (mService != null) {
7068 try {
Edman Anjos52088e42017-01-13 22:26:17 +01007069 mService.enableSystemApp(admin, mContext.getPackageName(), packageName);
Adam Connors655be2a2014-07-14 09:01:25 +00007070 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007071 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00007072 }
7073 }
7074 }
7075
7076 /**
Edman Anjos52088e42017-01-13 22:26:17 +01007077 * Re-enable system apps by intent that were disabled by default when the user was initialized.
7078 * This function can be called by a device owner, profile owner, or by a delegate given the
7079 * {@link #DELEGATION_ENABLE_SYSTEM_APP} scope via {@link #setDelegatedScopes}.
Adam Connors655be2a2014-07-14 09:01:25 +00007080 *
Edman Anjos52088e42017-01-13 22:26:17 +01007081 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
7082 * {@code null} if the caller is an enable system app delegate.
Adam Connors655be2a2014-07-14 09:01:25 +00007083 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007084 * intent will be re-enabled in the calling profile.
Adam Connors655be2a2014-07-14 09:01:25 +00007085 * @return int The number of activities that matched the intent and were installed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007086 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01007087 * @see #setDelegatedScopes
7088 * @see #DELEGATION_PACKAGE_ACCESS
Adam Connors655be2a2014-07-14 09:01:25 +00007089 */
Robin Lee25e26452015-06-02 09:56:29 -07007090 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007091 throwIfParentInstance("enableSystemApp");
Adam Connors655be2a2014-07-14 09:01:25 +00007092 if (mService != null) {
7093 try {
Edman Anjos52088e42017-01-13 22:26:17 +01007094 return mService.enableSystemAppWithIntent(admin, mContext.getPackageName(), intent);
Adam Connors655be2a2014-07-14 09:01:25 +00007095 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007096 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00007097 }
7098 }
7099 return 0;
7100 }
7101
7102 /**
Alex Chau5343fcb2017-12-05 16:49:19 +00007103 * Install an existing package that has been installed in another user, or has been kept after
7104 * removal via {@link #setKeepUninstalledPackages}.
7105 * This function can be called by a device owner, profile owner or a delegate given
7106 * the {@link #DELEGATION_INSTALL_EXISTING_PACKAGE} scope via {@link #setDelegatedScopes}.
7107 * When called in a secondary user or managed profile, the user/profile must be affiliated with
Alex Chau443b6432017-12-13 12:44:31 +00007108 * the device. See {@link #isAffiliatedUser}.
Alex Chau5343fcb2017-12-05 16:49:19 +00007109 *
7110 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7111 * @param packageName The package to be installed in the calling profile.
7112 * @return {@code true} if the app is installed; {@code false} otherwise.
7113 * @throws SecurityException if {@code admin} is not the device owner, or the profile owner of
7114 * an affiliated user or profile.
7115 * @see #setKeepUninstalledPackages
7116 * @see #setDelegatedScopes
Alex Chau443b6432017-12-13 12:44:31 +00007117 * @see #isAffiliatedUser
Alex Chau5343fcb2017-12-05 16:49:19 +00007118 * @see #DELEGATION_PACKAGE_ACCESS
7119 */
7120 public boolean installExistingPackage(@NonNull ComponentName admin, String packageName) {
7121 throwIfParentInstance("installExistingPackage");
7122 if (mService != null) {
7123 try {
7124 return mService.installExistingPackage(admin, mContext.getPackageName(),
7125 packageName);
7126 } catch (RemoteException e) {
7127 throw e.rethrowFromSystemServer();
7128 }
7129 }
7130 return false;
7131 }
7132
7133 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00007134 * Called by a device owner or profile owner to disable account management for a specific type
7135 * of account.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007136 * <p>
7137 * The calling device admin must be a device owner or profile owner. If it is not, a security
7138 * exception will be thrown.
7139 * <p>
7140 * When account management is disabled for an account type, adding or removing an account of
7141 * that type will not be possible.
7142 * <p>
7143 * From {@link android.os.Build.VERSION_CODES#N} the profile or device owner can still use
Benjamin Franzb6c0ce42015-11-05 10:06:51 +00007144 * {@link android.accounts.AccountManager} APIs to add or remove accounts when account
7145 * management for a specific type is disabled.
7146 *
Sander Alewijnse650c3342014-05-08 18:00:50 +01007147 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7148 * @param accountType For which account management is disabled or enabled.
7149 * @param disabled The boolean indicating that account management will be disabled (true) or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007150 * enabled (false).
7151 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnse650c3342014-05-08 18:00:50 +01007152 */
Robin Lee25e26452015-06-02 09:56:29 -07007153 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01007154 boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007155 throwIfParentInstance("setAccountManagementDisabled");
Sander Alewijnse650c3342014-05-08 18:00:50 +01007156 if (mService != null) {
7157 try {
7158 mService.setAccountManagementDisabled(admin, accountType, disabled);
7159 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007160 throw e.rethrowFromSystemServer();
Sander Alewijnse650c3342014-05-08 18:00:50 +01007161 }
7162 }
7163 }
7164
7165 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01007166 * Gets the array of accounts for which account management is disabled by the profile owner.
7167 *
7168 * <p> Account management can be disabled/enabled by calling
7169 * {@link #setAccountManagementDisabled}.
7170 *
7171 * @return a list of account types for which account management has been disabled.
7172 *
7173 * @see #setAccountManagementDisabled
7174 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007175 public @Nullable String[] getAccountTypesWithManagementDisabled() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007176 throwIfParentInstance("getAccountTypesWithManagementDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07007177 return getAccountTypesWithManagementDisabledAsUser(myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01007178 }
7179
7180 /**
7181 * @see #getAccountTypesWithManagementDisabled()
7182 * @hide
7183 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007184 public @Nullable String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01007185 if (mService != null) {
7186 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01007187 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01007188 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007189 throw e.rethrowFromSystemServer();
Sander Alewijnse5c02db62014-05-07 10:46:57 +01007190 }
7191 }
7192
7193 return null;
7194 }
justinzhang511e0d82014-03-24 16:09:24 -04007195
7196 /**
Jason Monkd7b86212014-06-16 13:15:38 -04007197 * Sets which packages may enter lock task mode.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007198 * <p>
Esteban Talaverabdcada92017-02-01 14:20:06 +00007199 * Any packages that share uid with an allowed package will also be allowed to activate lock
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007200 * task. From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task
Esteban Talaverabdcada92017-02-01 14:20:06 +00007201 * package list results in locked tasks belonging to those packages to be finished.
7202 * <p>
Jason Parks3c13b642017-11-28 15:39:43 -06007203 * This function can only be called by the device owner, a profile owner of an affiliated user
7204 * or profile, or the profile owner when no device owner is set. See {@link #isAffiliatedUser}.
7205 * Any package set via this method will be cleared if the user becomes unaffiliated.
Jason Monkd7b86212014-06-16 13:15:38 -04007206 *
Jason Monkd7b86212014-06-16 13:15:38 -04007207 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04007208 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jason Parks3c13b642017-11-28 15:39:43 -06007209 * @throws SecurityException if {@code admin} is not the device owner, the profile owner of an
7210 * affiliated user or profile, or the profile owner when no device owner is set.
Alex Chau443b6432017-12-13 12:44:31 +00007211 * @see #isAffiliatedUser
Jason Monkd7b86212014-06-16 13:15:38 -04007212 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00007213 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
7214 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04007215 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04007216 */
Esteban Talaverabdcada92017-02-01 14:20:06 +00007217 public void setLockTaskPackages(@NonNull ComponentName admin, @NonNull String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04007218 throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007219 throwIfParentInstance("setLockTaskPackages");
justinzhang511e0d82014-03-24 16:09:24 -04007220 if (mService != null) {
7221 try {
Jason Monk48aacba2014-08-13 16:29:08 -04007222 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04007223 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007224 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04007225 }
7226 }
7227 }
7228
7229 /**
Esteban Talaverabdcada92017-02-01 14:20:06 +00007230 * Returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04007231 *
Jason Parks3c13b642017-11-28 15:39:43 -06007232 * @throws SecurityException if {@code admin} is not the device owner, the profile owner of an
7233 * affiliated user or profile, or the profile owner when no device owner is set.
Alex Chau443b6432017-12-13 12:44:31 +00007234 * @see #isAffiliatedUser
Esteban Talaverabdcada92017-02-01 14:20:06 +00007235 * @see #setLockTaskPackages
justinzhang511e0d82014-03-24 16:09:24 -04007236 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007237 public @NonNull String[] getLockTaskPackages(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007238 throwIfParentInstance("getLockTaskPackages");
justinzhang511e0d82014-03-24 16:09:24 -04007239 if (mService != null) {
7240 try {
Jason Monk48aacba2014-08-13 16:29:08 -04007241 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04007242 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007243 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04007244 }
7245 }
Esteban Talaverabdcada92017-02-01 14:20:06 +00007246 return new String[0];
justinzhang511e0d82014-03-24 16:09:24 -04007247 }
7248
7249 /**
7250 * This function lets the caller know whether the given component is allowed to start the
7251 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04007252 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04007253 */
Jason Monkd7b86212014-06-16 13:15:38 -04007254 public boolean isLockTaskPermitted(String pkg) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007255 throwIfParentInstance("isLockTaskPermitted");
justinzhang511e0d82014-03-24 16:09:24 -04007256 if (mService != null) {
7257 try {
Jason Monkd7b86212014-06-16 13:15:38 -04007258 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04007259 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007260 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04007261 }
7262 }
7263 return false;
7264 }
Julia Reynoldsda551652014-05-14 17:15:16 -04007265
7266 /**
Benjamin Franz78ae1062018-03-26 11:01:32 +01007267 * Sets which system features are enabled when the device runs in lock task mode. This method
7268 * doesn't affect the features when lock task mode is inactive. Any system features not included
7269 * in {@code flags} are implicitly disabled when calling this method. By default, only
7270 * {@link #LOCK_TASK_FEATURE_GLOBAL_ACTIONS} is enabled—all the other features are disabled. To
7271 * disable the global actions dialog, call this method omitting
7272 * {@link #LOCK_TASK_FEATURE_GLOBAL_ACTIONS}.
7273 *
7274 * <p>This method can only be called by the device owner, a profile owner of an affiliated
7275 * user or profile, or the profile owner when no device owner is set. See
7276 * {@link #isAffiliatedUser}.
7277 * Any features set using this method are cleared if the user becomes unaffiliated.
Charles Hee078db72017-10-19 18:03:20 +01007278 *
7279 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franz78ae1062018-03-26 11:01:32 +01007280 * @param flags The system features enabled during lock task mode.
Jason Parks3c13b642017-11-28 15:39:43 -06007281 * @throws SecurityException if {@code admin} is not the device owner, the profile owner of an
7282 * affiliated user or profile, or the profile owner when no device owner is set.
Alex Chau443b6432017-12-13 12:44:31 +00007283 * @see #isAffiliatedUser
Benjamin Franz78ae1062018-03-26 11:01:32 +01007284 **/
Charles Hee078db72017-10-19 18:03:20 +01007285 public void setLockTaskFeatures(@NonNull ComponentName admin, @LockTaskFeature int flags) {
7286 throwIfParentInstance("setLockTaskFeatures");
7287 if (mService != null) {
7288 try {
7289 mService.setLockTaskFeatures(admin, flags);
7290 } catch (RemoteException e) {
7291 throw e.rethrowFromSystemServer();
7292 }
7293 }
7294 }
7295
7296 /**
7297 * Gets which system features are enabled for LockTask mode.
7298 *
7299 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7300 * @return bitfield of flags. See {@link #setLockTaskFeatures(ComponentName, int)} for a list.
Jason Parks3c13b642017-11-28 15:39:43 -06007301 * @throws SecurityException if {@code admin} is not the device owner, the profile owner of an
7302 * affiliated user or profile, or the profile owner when no device owner is set.
Alex Chau443b6432017-12-13 12:44:31 +00007303 * @see #isAffiliatedUser
7304 * @see #setLockTaskFeatures
Charles Hee078db72017-10-19 18:03:20 +01007305 */
7306 public @LockTaskFeature int getLockTaskFeatures(@NonNull ComponentName admin) {
7307 throwIfParentInstance("getLockTaskFeatures");
7308 if (mService != null) {
7309 try {
7310 return mService.getLockTaskFeatures(admin);
7311 } catch (RemoteException e) {
7312 throw e.rethrowFromSystemServer();
7313 }
7314 }
7315 return 0;
7316 }
7317
7318 /**
yuemingw0de748d2017-11-15 19:22:27 +00007319 * Called by device owner to update {@link android.provider.Settings.Global} settings.
Benjamin Franz482bb232017-06-23 13:48:20 +01007320 * Validation that the value of the setting is in the correct form for the setting type should
7321 * be performed by the caller.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007322 * <p>
7323 * The settings that can be updated with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04007324 * <ul>
Benjamin Franz482bb232017-06-23 13:48:20 +01007325 * <li>{@link android.provider.Settings.Global#ADB_ENABLED}</li>
7326 * <li>{@link android.provider.Settings.Global#AUTO_TIME}</li>
7327 * <li>{@link android.provider.Settings.Global#AUTO_TIME_ZONE}</li>
7328 * <li>{@link android.provider.Settings.Global#DATA_ROAMING}</li>
7329 * <li>{@link android.provider.Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
7330 * <li>{@link android.provider.Settings.Global#WIFI_SLEEP_POLICY}</li>
7331 * <li>{@link android.provider.Settings.Global#STAY_ON_WHILE_PLUGGED_IN} This setting is only
7332 * available from {@link android.os.Build.VERSION_CODES#M} onwards and can only be set if
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007333 * {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
Benjamin Franz482bb232017-06-23 13:48:20 +01007334 * <li>{@link android.provider.Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li> This
7335 * setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04007336 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007337 * <p>
7338 * Changing the following settings has no effect as of {@link android.os.Build.VERSION_CODES#M}:
Esteban Talavera656fa7f2015-06-29 17:41:39 +01007339 * <ul>
Benjamin Franz482bb232017-06-23 13:48:20 +01007340 * <li>{@link android.provider.Settings.Global#BLUETOOTH_ON}. Use
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007341 * {@link android.bluetooth.BluetoothAdapter#enable()} and
7342 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
Benjamin Franz482bb232017-06-23 13:48:20 +01007343 * <li>{@link android.provider.Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
7344 * <li>{@link android.provider.Settings.Global#MODE_RINGER}. Use
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007345 * {@link android.media.AudioManager#setRingerMode(int)} instead.</li>
Benjamin Franz482bb232017-06-23 13:48:20 +01007346 * <li>{@link android.provider.Settings.Global#NETWORK_PREFERENCE}</li>
7347 * <li>{@link android.provider.Settings.Global#WIFI_ON}. Use
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007348 * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01007349 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04007350 *
7351 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7352 * @param setting The name of the setting to update.
7353 * @param value The value to update the setting to.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007354 * @throws SecurityException if {@code admin} is not a device owner.
Julia Reynoldsda551652014-05-14 17:15:16 -04007355 */
Robin Lee25e26452015-06-02 09:56:29 -07007356 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007357 throwIfParentInstance("setGlobalSetting");
Julia Reynoldsda551652014-05-14 17:15:16 -04007358 if (mService != null) {
7359 try {
7360 mService.setGlobalSetting(admin, setting, value);
7361 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007362 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04007363 }
7364 }
7365 }
7366
yuemingw93ffce62018-02-21 16:20:14 +00007367 /** @hide */
7368 @StringDef({
7369 Settings.System.SCREEN_BRIGHTNESS_MODE,
7370 Settings.System.SCREEN_BRIGHTNESS,
7371 Settings.System.SCREEN_OFF_TIMEOUT
7372 })
7373 @Retention(RetentionPolicy.SOURCE)
7374 public @interface SystemSettingsWhitelist {}
7375
Julia Reynoldsda551652014-05-14 17:15:16 -04007376 /**
yuemingwc0281f12018-03-28 15:58:49 +01007377 * Called by a device or profile owner to update {@link android.provider.Settings.System}
7378 * settings. Validation that the value of the setting is in the correct form for the setting
7379 * type should be performed by the caller.
yuemingw0de748d2017-11-15 19:22:27 +00007380 * <p>
yuemingwc0281f12018-03-28 15:58:49 +01007381 * The settings that can be updated by a device owner or profile owner of secondary user with
7382 * this method are:
yuemingw0de748d2017-11-15 19:22:27 +00007383 * <ul>
7384 * <li>{@link android.provider.Settings.System#SCREEN_BRIGHTNESS}</li>
7385 * <li>{@link android.provider.Settings.System#SCREEN_BRIGHTNESS_MODE}</li>
7386 * <li>{@link android.provider.Settings.System#SCREEN_OFF_TIMEOUT}</li>
7387 * </ul>
7388 * <p>
7389 *
7390 * @see android.provider.Settings.System#SCREEN_OFF_TIMEOUT
7391 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7392 * @param setting The name of the setting to update.
7393 * @param value The value to update the setting to.
yuemingwc0281f12018-03-28 15:58:49 +01007394 * @throws SecurityException if {@code admin} is not a device or profile owner.
yuemingw0de748d2017-11-15 19:22:27 +00007395 */
yuemingw93ffce62018-02-21 16:20:14 +00007396 public void setSystemSetting(@NonNull ComponentName admin,
7397 @NonNull @SystemSettingsWhitelist String setting, String value) {
yuemingw0de748d2017-11-15 19:22:27 +00007398 throwIfParentInstance("setSystemSetting");
7399 if (mService != null) {
7400 try {
7401 mService.setSystemSetting(admin, setting, value);
7402 } catch (RemoteException e) {
7403 throw e.rethrowFromSystemServer();
7404 }
7405 }
7406 }
7407
7408 /**
yuemingwe43cdf72017-10-12 16:52:11 +01007409 * Called by device owner to set the system wall clock time. This only takes effect if called
7410 * when {@link android.provider.Settings.Global#AUTO_TIME} is 0, otherwise {@code false} will be
7411 * returned.
7412 *
7413 * @param admin Which {@link DeviceAdminReceiver} this request is associated with
7414 * @param millis time in milliseconds since the Epoch
7415 * @return {@code true} if set time succeeded, {@code false} otherwise.
7416 * @throws SecurityException if {@code admin} is not a device owner.
7417 */
7418 public boolean setTime(@NonNull ComponentName admin, long millis) {
7419 throwIfParentInstance("setTime");
7420 if (mService != null) {
7421 try {
7422 return mService.setTime(admin, millis);
7423 } catch (RemoteException e) {
7424 throw e.rethrowFromSystemServer();
7425 }
7426 }
7427 return false;
7428 }
7429
7430 /**
7431 * Called by device owner to set the system's persistent default time zone. This only takes
7432 * effect if called when {@link android.provider.Settings.Global#AUTO_TIME_ZONE} is 0, otherwise
7433 * {@code false} will be returned.
7434 *
7435 * @see android.app.AlarmManager#setTimeZone(String)
7436 * @param admin Which {@link DeviceAdminReceiver} this request is associated with
7437 * @param timeZone one of the Olson ids from the list returned by
7438 * {@link java.util.TimeZone#getAvailableIDs}
7439 * @return {@code true} if set timezone succeeded, {@code false} otherwise.
7440 * @throws SecurityException if {@code admin} is not a device owner.
7441 */
7442 public boolean setTimeZone(@NonNull ComponentName admin, String timeZone) {
7443 throwIfParentInstance("setTimeZone");
7444 if (mService != null) {
7445 try {
7446 return mService.setTimeZone(admin, timeZone);
7447 } catch (RemoteException e) {
7448 throw e.rethrowFromSystemServer();
7449 }
7450 }
7451 return false;
7452 }
7453
7454 /**
Benjamin Franz482bb232017-06-23 13:48:20 +01007455 * Called by profile or device owners to update {@link android.provider.Settings.Secure}
7456 * settings. Validation that the value of the setting is in the correct form for the setting
7457 * type should be performed by the caller.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007458 * <p>
7459 * The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04007460 * <ul>
Benjamin Franz482bb232017-06-23 13:48:20 +01007461 * <li>{@link android.provider.Settings.Secure#DEFAULT_INPUT_METHOD}</li>
7462 * <li>{@link android.provider.Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04007463 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007464 * <p>
7465 * A device owner can additionally update the following settings:
Julia Reynolds82735bc2014-09-04 16:43:30 -04007466 * <ul>
Benjamin Franz482bb232017-06-23 13:48:20 +01007467 * <li>{@link android.provider.Settings.Secure#LOCATION_MODE}</li>
Julia Reynolds82735bc2014-09-04 16:43:30 -04007468 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007469 *
Suprabh Shukla0b1356f2017-02-21 14:33:50 -08007470 * <strong>Note: Starting from Android O, apps should no longer call this method with the
7471 * setting {@link android.provider.Settings.Secure#INSTALL_NON_MARKET_APPS}, which is
7472 * deprecated. Instead, device owners or profile owners should use the restriction
7473 * {@link UserManager#DISALLOW_INSTALL_UNKNOWN_SOURCES}.
7474 * If any app targeting {@link android.os.Build.VERSION_CODES#O} or higher calls this method
7475 * with {@link android.provider.Settings.Secure#INSTALL_NON_MARKET_APPS},
7476 * an {@link UnsupportedOperationException} is thrown.
7477 * </strong>
7478 *
Julia Reynoldsda551652014-05-14 17:15:16 -04007479 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7480 * @param setting The name of the setting to update.
7481 * @param value The value to update the setting to.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007482 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynoldsda551652014-05-14 17:15:16 -04007483 */
Robin Lee25e26452015-06-02 09:56:29 -07007484 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007485 throwIfParentInstance("setSecureSetting");
Julia Reynoldsda551652014-05-14 17:15:16 -04007486 if (mService != null) {
7487 try {
7488 mService.setSecureSetting(admin, setting, value);
7489 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007490 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04007491 }
7492 }
7493 }
7494
Amith Yamasanif20d6402014-05-24 15:34:37 -07007495 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007496 * Designates a specific service component as the provider for making permission requests of a
7497 * local or remote administrator of the user.
Amith Yamasanif20d6402014-05-24 15:34:37 -07007498 * <p/>
7499 * Only a profile owner can designate the restrictions provider.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007500 *
Amith Yamasanif20d6402014-05-24 15:34:37 -07007501 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07007502 * @param provider The component name of the service that implements
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007503 * {@link RestrictionsReceiver}. If this param is null, it removes the restrictions
7504 * provider previously assigned.
7505 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanif20d6402014-05-24 15:34:37 -07007506 */
Robin Lee25e26452015-06-02 09:56:29 -07007507 public void setRestrictionsProvider(@NonNull ComponentName admin,
7508 @Nullable ComponentName provider) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007509 throwIfParentInstance("setRestrictionsProvider");
Amith Yamasanif20d6402014-05-24 15:34:37 -07007510 if (mService != null) {
7511 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07007512 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07007513 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007514 throw re.rethrowFromSystemServer();
Amith Yamasanif20d6402014-05-24 15:34:37 -07007515 }
7516 }
7517 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04007518
7519 /**
7520 * Called by profile or device owners to set the master volume mute on or off.
Nicolas Prevotaef3ce22016-09-22 12:00:25 +01007521 * This has no effect when set on a managed profile.
Julia Reynolds4a21b252014-06-04 11:11:43 -04007522 *
7523 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7524 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007525 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds4a21b252014-06-04 11:11:43 -04007526 */
Robin Lee25e26452015-06-02 09:56:29 -07007527 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007528 throwIfParentInstance("setMasterVolumeMuted");
Julia Reynolds4a21b252014-06-04 11:11:43 -04007529 if (mService != null) {
7530 try {
7531 mService.setMasterVolumeMuted(admin, on);
7532 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007533 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04007534 }
7535 }
7536 }
7537
7538 /**
7539 * Called by profile or device owners to check whether the master volume mute is on or off.
7540 *
7541 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7542 * @return {@code true} if master volume is muted, {@code false} if it's not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007543 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds4a21b252014-06-04 11:11:43 -04007544 */
Robin Lee25e26452015-06-02 09:56:29 -07007545 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007546 throwIfParentInstance("isMasterVolumeMuted");
Julia Reynolds4a21b252014-06-04 11:11:43 -04007547 if (mService != null) {
7548 try {
7549 return mService.isMasterVolumeMuted(admin);
7550 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007551 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04007552 }
7553 }
7554 return false;
7555 }
Kenny Guyc13053b2014-05-29 14:17:17 +01007556
7557 /**
Edman Anjosa5f2fb12016-12-19 11:25:54 -08007558 * Change whether a user can uninstall a package. This function can be called by a device owner,
7559 * profile owner, or by a delegate given the {@link #DELEGATION_BLOCK_UNINSTALL} scope via
7560 * {@link #setDelegatedScopes}.
Kenny Guyc13053b2014-05-29 14:17:17 +01007561 *
Edman Anjosa5f2fb12016-12-19 11:25:54 -08007562 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
7563 * {@code null} if the caller is a block uninstall delegate.
Kenny Guyc13053b2014-05-29 14:17:17 +01007564 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01007565 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007566 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjosa5f2fb12016-12-19 11:25:54 -08007567 * @see #setDelegatedScopes
7568 * @see #DELEGATION_BLOCK_UNINSTALL
Kenny Guyc13053b2014-05-29 14:17:17 +01007569 */
Edman Anjosa5f2fb12016-12-19 11:25:54 -08007570 public void setUninstallBlocked(@Nullable ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01007571 boolean uninstallBlocked) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007572 throwIfParentInstance("setUninstallBlocked");
Kenny Guyc13053b2014-05-29 14:17:17 +01007573 if (mService != null) {
7574 try {
Edman Anjosa5f2fb12016-12-19 11:25:54 -08007575 mService.setUninstallBlocked(admin, mContext.getPackageName(), packageName,
7576 uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01007577 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007578 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01007579 }
7580 }
7581 }
7582
7583 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08007584 * Check whether the user has been blocked by device policy from uninstalling a package.
Rubin Xua97855b2014-11-07 05:41:00 +00007585 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00007586 * <p>
7587 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007588 * behavior of this API is changed such that passing {@code null} as the {@code admin} parameter
7589 * will return if any admin has blocked the uninstallation. Before L MR1, passing {@code null}
7590 * will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01007591 *
Robin Lee25e26452015-06-02 09:56:29 -07007592 * @param admin The name of the admin component whose blocking policy will be checked, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007593 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01007594 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00007595 * @return true if uninstallation is blocked.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007596 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyc13053b2014-05-29 14:17:17 +01007597 */
Robin Lee25e26452015-06-02 09:56:29 -07007598 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007599 throwIfParentInstance("isUninstallBlocked");
Kenny Guyc13053b2014-05-29 14:17:17 +01007600 if (mService != null) {
7601 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01007602 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01007603 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007604 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01007605 }
7606 }
7607 return false;
7608 }
Svetoslav976e8bd2014-07-16 15:12:03 -07007609
7610 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007611 * Called by the profile owner of a managed profile to enable widget providers from a given
7612 * package to be available in the parent profile. As a result the user will be able to add
7613 * widgets from the white-listed package running under the profile to a widget host which runs
7614 * under the parent profile, for example the home screen. Note that a package may have zero or
7615 * more provider components, where each component provides a different widget type.
Svetoslav976e8bd2014-07-16 15:12:03 -07007616 * <p>
7617 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07007618 *
7619 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7620 * @param packageName The package from which widget providers are white-listed.
7621 * @return Whether the package was added.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007622 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07007623 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
7624 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
7625 */
Robin Lee25e26452015-06-02 09:56:29 -07007626 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007627 throwIfParentInstance("addCrossProfileWidgetProvider");
Svetoslav976e8bd2014-07-16 15:12:03 -07007628 if (mService != null) {
7629 try {
7630 return mService.addCrossProfileWidgetProvider(admin, packageName);
7631 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007632 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07007633 }
7634 }
7635 return false;
7636 }
7637
7638 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07007639 * Called by the profile owner of a managed profile to disable widget providers from a given
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007640 * package to be available in the parent profile. For this method to take effect the package
7641 * should have been added via
7642 * {@link #addCrossProfileWidgetProvider( android.content.ComponentName, String)}.
Svetoslav976e8bd2014-07-16 15:12:03 -07007643 * <p>
7644 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07007645 *
7646 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007647 * @param packageName The package from which widget providers are no longer white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07007648 * @return Whether the package was removed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007649 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07007650 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
7651 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
7652 */
Esteban Talavera62399912016-01-11 15:37:55 +00007653 public boolean removeCrossProfileWidgetProvider(
7654 @NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007655 throwIfParentInstance("removeCrossProfileWidgetProvider");
Svetoslav976e8bd2014-07-16 15:12:03 -07007656 if (mService != null) {
7657 try {
7658 return mService.removeCrossProfileWidgetProvider(admin, packageName);
7659 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007660 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07007661 }
7662 }
7663 return false;
7664 }
7665
7666 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07007667 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07007668 * available in the parent profile.
7669 *
7670 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7671 * @return The white-listed package list.
Svetoslav976e8bd2014-07-16 15:12:03 -07007672 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
7673 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007674 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07007675 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007676 public @NonNull List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007677 throwIfParentInstance("getCrossProfileWidgetProviders");
Svetoslav976e8bd2014-07-16 15:12:03 -07007678 if (mService != null) {
7679 try {
7680 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
7681 if (providers != null) {
7682 return providers;
7683 }
7684 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007685 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07007686 }
7687 }
7688 return Collections.emptyList();
7689 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05007690
7691 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08007692 * Called by profile or device owners to set the user's photo.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05007693 *
7694 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7695 * @param icon the bitmap to set as the photo.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007696 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05007697 */
Robin Lee25e26452015-06-02 09:56:29 -07007698 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007699 throwIfParentInstance("setUserIcon");
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05007700 try {
7701 mService.setUserIcon(admin, icon);
7702 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007703 throw re.rethrowFromSystemServer();
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05007704 }
7705 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04007706
7707 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01007708 * Called by device owners to set a local system update policy. When a new policy is set,
7709 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu29b9a7d2018-01-11 09:24:02 +00007710 * <p>
7711 * If the supplied system update policy has freeze periods set but the freeze periods do not
7712 * meet 90-day maximum length or 60-day minimum separation requirement set out in
7713 * {@link SystemUpdatePolicy#setFreezePeriods},
7714 * {@link SystemUpdatePolicy.ValidationFailedException} will the thrown. Note that the system
7715 * keeps a record of freeze periods the device experienced previously, and combines them with
7716 * the new freeze periods to be set when checking the maximum freeze length and minimum freeze
7717 * separation constraints. As a result, freeze periods that passed validation during
7718 * {@link SystemUpdatePolicy#setFreezePeriods} might fail the additional checks here due to
7719 * the freeze period history. If this is causing issues during development,
7720 * {@code adb shell dpm clear-freeze-period-record} can be used to clear the record.
Rubin Xu8027a4f2015-03-10 17:52:37 +00007721 *
Robin Lee25e26452015-06-02 09:56:29 -07007722 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007723 * components in the device owner package can set system update policies and the most
7724 * recent policy takes effect.
Robin Lee25e26452015-06-02 09:56:29 -07007725 * @param policy the new policy, or {@code null} to clear the current policy.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007726 * @throws SecurityException if {@code admin} is not a device owner.
Rubin Xu29b9a7d2018-01-11 09:24:02 +00007727 * @throws IllegalArgumentException if the policy type or maintenance window is not valid.
7728 * @throws SystemUpdatePolicy.ValidationFailedException if the policy's freeze period does not
7729 * meet the requirement.
Rubin Xu5faad8e2015-04-20 17:43:48 +01007730 * @see SystemUpdatePolicy
Rubin Xu29b9a7d2018-01-11 09:24:02 +00007731 * @see SystemUpdatePolicy#setFreezePeriods(List)
Rubin Xu8027a4f2015-03-10 17:52:37 +00007732 */
Robin Lee25e26452015-06-02 09:56:29 -07007733 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007734 throwIfParentInstance("setSystemUpdatePolicy");
Rubin Xu8027a4f2015-03-10 17:52:37 +00007735 if (mService != null) {
7736 try {
Robin Lee25e26452015-06-02 09:56:29 -07007737 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00007738 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007739 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00007740 }
7741 }
7742 }
7743
7744 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01007745 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00007746 *
Robin Lee25e26452015-06-02 09:56:29 -07007747 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00007748 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007749 public @Nullable SystemUpdatePolicy getSystemUpdatePolicy() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007750 throwIfParentInstance("getSystemUpdatePolicy");
Rubin Xu8027a4f2015-03-10 17:52:37 +00007751 if (mService != null) {
7752 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01007753 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00007754 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007755 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00007756 }
7757 }
7758 return null;
7759 }
Benjamin Franze36087e2015-04-07 16:40:34 +01007760
7761 /**
Rubin Xu29b9a7d2018-01-11 09:24:02 +00007762 * Reset record of previous system update freeze period the device went through.
7763 * Only callable by ADB.
7764 * @hide
7765 */
7766 public void clearSystemUpdatePolicyFreezePeriodRecord() {
7767 throwIfParentInstance("clearSystemUpdatePolicyFreezePeriodRecord");
7768 if (mService == null) {
7769 return;
7770 }
7771 try {
7772 mService.clearSystemUpdatePolicyFreezePeriodRecord();
7773 } catch (RemoteException re) {
7774 throw re.rethrowFromSystemServer();
7775 }
7776 }
Pavel Grafov5bb5a622018-01-31 21:06:24 +00007777
Rubin Xu29b9a7d2018-01-11 09:24:02 +00007778 /**
Alex Chau7fbe61d2018-01-04 15:45:38 +00007779 * Called by a device owner or profile owner of secondary users that is affiliated with the
7780 * device to disable the keyguard altogether.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007781 * <p>
7782 * Setting the keyguard to disabled has the same effect as choosing "None" as the screen lock
7783 * type. However, this call has no effect if a password, pin or pattern is currently set. If a
7784 * password, pin or pattern is set after the keyguard was disabled, the keyguard stops being
7785 * disabled.
Benjamin Franze36087e2015-04-07 16:40:34 +01007786 *
Benjamin Franz32a3bf32017-08-04 15:01:52 +01007787 * <p>
Benjamin Franz64affcb2017-09-01 13:47:22 +01007788 * As of {@link android.os.Build.VERSION_CODES#P}, this call also dismisses the
Benjamin Franz32a3bf32017-08-04 15:01:52 +01007789 * keyguard if it is currently shown.
7790 *
Benjamin Franze36087e2015-04-07 16:40:34 +01007791 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01007792 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01007793 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007794 * place. {@code true} otherwise.
Alex Chau7fbe61d2018-01-04 15:45:38 +00007795 * @throws SecurityException if {@code admin} is not the device owner, or a profile owner of
7796 * secondary user that is affiliated with the device.
7797 * @see #isAffiliatedUser
7798 * @see #getSecondaryUsers
Benjamin Franze36087e2015-04-07 16:40:34 +01007799 */
Robin Lee25e26452015-06-02 09:56:29 -07007800 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007801 throwIfParentInstance("setKeyguardDisabled");
Benjamin Franze36087e2015-04-07 16:40:34 +01007802 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01007803 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01007804 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007805 throw re.rethrowFromSystemServer();
Benjamin Franze36087e2015-04-07 16:40:34 +01007806 }
7807 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00007808
7809 /**
Alex Chau7fbe61d2018-01-04 15:45:38 +00007810 * Called by device owner or profile owner of secondary users that is affiliated with the
7811 * device to disable the status bar. Disabling the status bar blocks notifications, quick
7812 * settings and other screen overlays that allow escaping from a single use device.
Charles Hee078db72017-10-19 18:03:20 +01007813 * <p>
7814 * <strong>Note:</strong> This method has no effect for LockTask mode. The behavior of the
7815 * status bar in LockTask mode can be configured with
7816 * {@link #setLockTaskFeatures(ComponentName, int)}. Calls to this method when the device is in
7817 * LockTask mode will be registered, but will only take effect when the device leaves LockTask
7818 * mode.
Benjamin Franzea2ec972015-03-16 17:18:09 +00007819 *
7820 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01007821 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007822 * @return {@code false} if attempting to disable the status bar failed. {@code true} otherwise.
Alex Chau7fbe61d2018-01-04 15:45:38 +00007823 * @throws SecurityException if {@code admin} is not the device owner, or a profile owner of
7824 * secondary user that is affiliated with the device.
7825 * @see #isAffiliatedUser
7826 * @see #getSecondaryUsers
Benjamin Franzea2ec972015-03-16 17:18:09 +00007827 */
Robin Lee25e26452015-06-02 09:56:29 -07007828 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007829 throwIfParentInstance("setStatusBarDisabled");
Benjamin Franzea2ec972015-03-16 17:18:09 +00007830 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01007831 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00007832 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007833 throw re.rethrowFromSystemServer();
Benjamin Franzea2ec972015-03-16 17:18:09 +00007834 }
7835 }
Rubin Xudc105cc2015-04-14 23:38:01 +01007836
7837 /**
Charles Hedea0c3b2017-01-13 10:04:12 +00007838 * Called by the system update service to notify device and profile owners of pending system
7839 * updates.
Rubin Xudc105cc2015-04-14 23:38:01 +01007840 *
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06007841 * This method should only be used when it is unknown whether the pending system
Charles Hedea0c3b2017-01-13 10:04:12 +00007842 * update is a security patch. Otherwise, use
7843 * {@link #notifyPendingSystemUpdate(long, boolean)}.
7844 *
7845 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()}
7846 * indicating when the current pending update was first available. {@code -1} if no
7847 * update is available.
7848 * @see #notifyPendingSystemUpdate(long, boolean)
Rubin Xudc105cc2015-04-14 23:38:01 +01007849 * @hide
7850 */
7851 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06007852 @RequiresPermission(android.Manifest.permission.NOTIFY_PENDING_SYSTEM_UPDATE)
Rubin Xudc105cc2015-04-14 23:38:01 +01007853 public void notifyPendingSystemUpdate(long updateReceivedTime) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007854 throwIfParentInstance("notifyPendingSystemUpdate");
Rubin Xudc105cc2015-04-14 23:38:01 +01007855 if (mService != null) {
7856 try {
Charles Hedea0c3b2017-01-13 10:04:12 +00007857 mService.notifyPendingSystemUpdate(SystemUpdateInfo.of(updateReceivedTime));
7858 } catch (RemoteException re) {
7859 throw re.rethrowFromSystemServer();
7860 }
7861 }
7862 }
7863
7864 /**
7865 * Called by the system update service to notify device and profile owners of pending system
7866 * updates.
7867 *
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06007868 * This method should be used instead of {@link #notifyPendingSystemUpdate(long)}
Charles Hedea0c3b2017-01-13 10:04:12 +00007869 * when it is known whether the pending system update is a security patch.
7870 *
7871 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()}
7872 * indicating when the current pending update was first available. {@code -1} if no
7873 * update is available.
7874 * @param isSecurityPatch {@code true} if this system update is purely a security patch;
7875 * {@code false} if not.
7876 * @see #notifyPendingSystemUpdate(long)
7877 * @hide
7878 */
7879 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06007880 @RequiresPermission(android.Manifest.permission.NOTIFY_PENDING_SYSTEM_UPDATE)
Charles Hedea0c3b2017-01-13 10:04:12 +00007881 public void notifyPendingSystemUpdate(long updateReceivedTime, boolean isSecurityPatch) {
7882 throwIfParentInstance("notifyPendingSystemUpdate");
7883 if (mService != null) {
7884 try {
7885 mService.notifyPendingSystemUpdate(SystemUpdateInfo.of(updateReceivedTime,
7886 isSecurityPatch));
Rubin Xudc105cc2015-04-14 23:38:01 +01007887 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007888 throw re.rethrowFromSystemServer();
Rubin Xudc105cc2015-04-14 23:38:01 +01007889 }
7890 }
7891 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04007892
7893 /**
Pavel Grafovd65799e2016-12-02 11:21:45 +00007894 * Called by device or profile owners to get information about a pending system update.
7895 *
7896 * @param admin Which profile or device owner this request is associated with.
7897 * @return Information about a pending system update or {@code null} if no update pending.
7898 * @throws SecurityException if {@code admin} is not a device or profile owner.
7899 * @see DeviceAdminReceiver#onSystemUpdatePending(Context, Intent, long)
7900 */
7901 public @Nullable SystemUpdateInfo getPendingSystemUpdate(@NonNull ComponentName admin) {
7902 throwIfParentInstance("getPendingSystemUpdate");
7903 try {
7904 return mService.getPendingSystemUpdate(admin);
7905 } catch (RemoteException re) {
7906 throw re.rethrowFromSystemServer();
7907 }
7908 }
7909
7910 /**
Edman Anjos52088e42017-01-13 22:26:17 +01007911 * Set the default response for future runtime permission requests by applications. This
7912 * function can be called by a device owner, profile owner, or by a delegate given the
7913 * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}.
7914 * The policy can allow for normal operation which prompts the user to grant a permission, or
7915 * can allow automatic granting or denying of runtime permission requests by an application.
7916 * This also applies to new permissions declared by app updates. When a permission is denied or
7917 * granted this way, the effect is equivalent to setting the permission * grant state via
7918 * {@link #setPermissionGrantState}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007919 * <p/>
7920 * As this policy only acts on runtime permission requests, it only applies to applications
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07007921 * built with a {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Benjamin Franz45dd6662015-07-08 14:24:14 +01007922 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07007923 * @param admin Which profile or device owner this request is associated with.
7924 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007925 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
7926 * @throws SecurityException if {@code admin} is not a device or profile owner.
Benjamin Franz45dd6662015-07-08 14:24:14 +01007927 * @see #setPermissionGrantState
Edman Anjos52088e42017-01-13 22:26:17 +01007928 * @see #setDelegatedScopes
7929 * @see #DELEGATION_PERMISSION_GRANT
Amith Yamasanid49489b2015-04-28 14:00:26 -07007930 */
Robin Lee25e26452015-06-02 09:56:29 -07007931 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007932 throwIfParentInstance("setPermissionPolicy");
Amith Yamasanid49489b2015-04-28 14:00:26 -07007933 try {
Edman Anjos52088e42017-01-13 22:26:17 +01007934 mService.setPermissionPolicy(admin, mContext.getPackageName(), policy);
Amith Yamasanid49489b2015-04-28 14:00:26 -07007935 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007936 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07007937 }
7938 }
7939
7940 /**
7941 * Returns the current runtime permission policy set by the device or profile owner. The
7942 * default is {@link #PERMISSION_POLICY_PROMPT}.
Edman Anjos52088e42017-01-13 22:26:17 +01007943 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07007944 * @param admin Which profile or device owner this request is associated with.
7945 * @return the current policy for future permission requests.
7946 */
Esteban Talavera28b95702015-06-24 15:23:42 +01007947 public int getPermissionPolicy(ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007948 throwIfParentInstance("getPermissionPolicy");
Amith Yamasanid49489b2015-04-28 14:00:26 -07007949 try {
7950 return mService.getPermissionPolicy(admin);
7951 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007952 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07007953 }
7954 }
7955
7956 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007957 * Sets the grant state of a runtime permission for a specific application. The state can be
7958 * {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it through the UI,
7959 * {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission is denied and the user
7960 * cannot manage it through the UI, and {@link #PERMISSION_GRANT_STATE_GRANTED granted} in which
Tony Mak329047b2018-02-28 14:17:17 +00007961 * the permission is granted and the user cannot manage it through the UI. This method can only
7962 * be called by a profile owner, device owner, or a delegate given the
Edman Anjos52088e42017-01-13 22:26:17 +01007963 * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007964 * <p/>
Tony Mak329047b2018-02-28 14:17:17 +00007965 * Note that user cannot manage other permissions in the affected group through the UI
7966 * either and their granted state will be kept as the current value. Thus, it's recommended that
7967 * you set the grant state of all the permissions in the affected group.
7968 * <p/>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007969 * Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not revoke
7970 * the permission. It retains the previous grant, if any.
7971 * <p/>
7972 * Permissions can be granted or revoked only for applications built with a
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07007973 * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07007974 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07007975 * @param admin Which profile or device owner this request is associated with.
7976 * @param packageName The application to grant or revoke a permission to.
7977 * @param permission The permission to grant or revoke.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007978 * @param grantState The permission grant state which is one of
7979 * {@link #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
7980 * {@link #PERMISSION_GRANT_STATE_GRANTED},
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07007981 * @return whether the permission was successfully granted or revoked.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007982 * @throws SecurityException if {@code admin} is not a device or profile owner.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07007983 * @see #PERMISSION_GRANT_STATE_DENIED
7984 * @see #PERMISSION_GRANT_STATE_DEFAULT
7985 * @see #PERMISSION_GRANT_STATE_GRANTED
Edman Anjos52088e42017-01-13 22:26:17 +01007986 * @see #setDelegatedScopes
7987 * @see #DELEGATION_PERMISSION_GRANT
Amith Yamasanid49489b2015-04-28 14:00:26 -07007988 */
Robin Lee25e26452015-06-02 09:56:29 -07007989 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07007990 String permission, int grantState) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007991 throwIfParentInstance("setPermissionGrantState");
Amith Yamasanid49489b2015-04-28 14:00:26 -07007992 try {
Edman Anjos52088e42017-01-13 22:26:17 +01007993 return mService.setPermissionGrantState(admin, mContext.getPackageName(), packageName,
7994 permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07007995 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007996 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07007997 }
7998 }
Amith Yamasani184b3752015-05-22 13:00:51 -07007999
8000 /**
Edman Anjos52088e42017-01-13 22:26:17 +01008001 * Returns the current grant state of a runtime permission for a specific application. This
8002 * function can be called by a device owner, profile owner, or by a delegate given the
8003 * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}.
Amith Yamasani184b3752015-05-22 13:00:51 -07008004 *
Edman Anjos52088e42017-01-13 22:26:17 +01008005 * @param admin Which profile or device owner this request is associated with, or {@code null}
8006 * if the caller is a permission grant delegate.
Amith Yamasani184b3752015-05-22 13:00:51 -07008007 * @param packageName The application to check the grant state for.
8008 * @param permission The permission to check for.
8009 * @return the current grant state specified by device policy. If the profile or device owner
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07008010 * has not set a grant state, the return value is
8011 * {@link #PERMISSION_GRANT_STATE_DEFAULT}. This does not indicate whether or not the
8012 * permission is currently granted for the package.
8013 * <p/>
8014 * If a grant state was set by the profile or device owner, then the return value will
8015 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or
8016 * {@link #PERMISSION_GRANT_STATE_GRANTED}, which indicates if the permission is
8017 * currently denied or granted.
8018 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasani184b3752015-05-22 13:00:51 -07008019 * @see #setPermissionGrantState(ComponentName, String, String, int)
8020 * @see PackageManager#checkPermission(String, String)
Edman Anjos52088e42017-01-13 22:26:17 +01008021 * @see #setDelegatedScopes
8022 * @see #DELEGATION_PERMISSION_GRANT
Amith Yamasani184b3752015-05-22 13:00:51 -07008023 */
Bartosz Fabianowski4b0624f2017-01-16 11:47:28 +01008024 public int getPermissionGrantState(@Nullable ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07008025 String permission) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008026 throwIfParentInstance("getPermissionGrantState");
Amith Yamasani184b3752015-05-22 13:00:51 -07008027 try {
Edman Anjos52088e42017-01-13 22:26:17 +01008028 return mService.getPermissionGrantState(admin, mContext.getPackageName(), packageName,
8029 permission);
Amith Yamasani184b3752015-05-22 13:00:51 -07008030 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008031 throw re.rethrowFromSystemServer();
Amith Yamasani184b3752015-05-22 13:00:51 -07008032 }
8033 }
Nicolas Prevot07387fe2015-10-30 17:53:30 +00008034
8035 /**
Esteban Talavera01576862016-12-15 11:16:44 +00008036 * Returns whether it is possible for the caller to initiate provisioning of a managed profile
8037 * or device, setting itself as the device or profile owner.
8038 *
Nicolas Prevot07387fe2015-10-30 17:53:30 +00008039 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
8040 * {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Esteban Talavera01576862016-12-15 11:16:44 +00008041 * @return whether provisioning a managed profile or device is possible.
Nicolas Prevot07387fe2015-10-30 17:53:30 +00008042 * @throws IllegalArgumentException if the supplied action is not valid.
8043 */
Esteban Talavera01576862016-12-15 11:16:44 +00008044 public boolean isProvisioningAllowed(@NonNull String action) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008045 throwIfParentInstance("isProvisioningAllowed");
Nicolas Prevot07387fe2015-10-30 17:53:30 +00008046 try {
Esteban Talavera01576862016-12-15 11:16:44 +00008047 return mService.isProvisioningAllowed(action, mContext.getPackageName());
Nicolas Prevot07387fe2015-10-30 17:53:30 +00008048 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008049 throw re.rethrowFromSystemServer();
Nicolas Prevot07387fe2015-10-30 17:53:30 +00008050 }
8051 }
Mahaver Chopra15a46b02015-11-11 14:54:35 +00008052
8053 /**
Esteban Talavera01576862016-12-15 11:16:44 +00008054 * Checks whether it is possible to initiate provisioning a managed device,
8055 * profile or user, setting the given package as owner.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00008056 *
8057 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
8058 * {@link #ACTION_PROVISION_MANAGED_PROFILE},
8059 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE},
8060 * {@link #ACTION_PROVISION_MANAGED_USER}
Esteban Talavera01576862016-12-15 11:16:44 +00008061 * @param packageName The package of the component that would be set as device, user, or profile
8062 * owner.
8063 * @return A {@link ProvisioningPreCondition} value indicating whether provisioning is allowed.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00008064 * @hide
8065 */
Esteban Talavera01576862016-12-15 11:16:44 +00008066 public @ProvisioningPreCondition int checkProvisioningPreCondition(
8067 String action, @NonNull String packageName) {
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00008068 try {
Esteban Talavera01576862016-12-15 11:16:44 +00008069 return mService.checkProvisioningPreCondition(action, packageName);
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00008070 } catch (RemoteException re) {
8071 throw re.rethrowFromSystemServer();
8072 }
8073 }
8074
8075 /**
Mahaver Chopra15a46b02015-11-11 14:54:35 +00008076 * Return if this user is a managed profile of another user. An admin can become the profile
8077 * owner of a managed profile with {@link #ACTION_PROVISION_MANAGED_PROFILE} and of a managed
Kenny Guyffa38402016-03-31 16:40:57 +01008078 * user with {@link #createAndManageUser}
Mahaver Chopra15a46b02015-11-11 14:54:35 +00008079 * @param admin Which profile owner this request is associated with.
8080 * @return if this user is a managed profile of another user.
8081 */
8082 public boolean isManagedProfile(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008083 throwIfParentInstance("isManagedProfile");
Mahaver Chopra15a46b02015-11-11 14:54:35 +00008084 try {
8085 return mService.isManagedProfile(admin);
8086 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008087 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00008088 }
8089 }
8090
8091 /**
8092 * @hide
8093 * Return if this user is a system-only user. An admin can manage a device from a system only
8094 * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}.
8095 * @param admin Which device owner this request is associated with.
8096 * @return if this user is a system-only user.
8097 */
8098 public boolean isSystemOnlyUser(@NonNull ComponentName admin) {
8099 try {
8100 return mService.isSystemOnlyUser(admin);
8101 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008102 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00008103 }
8104 }
Makoto Onukia31ebbc2015-11-23 17:15:21 -08008105
8106 /**
8107 * Called by device owner to get the MAC address of the Wi-Fi device.
8108 *
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08008109 * @param admin Which device owner this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07008110 * @return the MAC address of the Wi-Fi device, or null when the information is not available.
8111 * (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.)
8112 * <p>
8113 * The address will be in the {@code XX:XX:XX:XX:XX:XX} format.
8114 * @throws SecurityException if {@code admin} is not a device owner.
Makoto Onukia31ebbc2015-11-23 17:15:21 -08008115 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07008116 public @Nullable String getWifiMacAddress(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008117 throwIfParentInstance("getWifiMacAddress");
Makoto Onukia31ebbc2015-11-23 17:15:21 -08008118 try {
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08008119 return mService.getWifiMacAddress(admin);
Makoto Onukia31ebbc2015-11-23 17:15:21 -08008120 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008121 throw re.rethrowFromSystemServer();
Makoto Onukia31ebbc2015-11-23 17:15:21 -08008122 }
8123 }
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00008124
8125 /**
Mahaver Chopra1216ae52016-03-11 15:39:48 +00008126 * Called by device owner to reboot the device. If there is an ongoing call on the device,
8127 * throws an {@link IllegalStateException}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07008128 * @param admin Which device owner the request is associated with.
Mahaver Chopra1216ae52016-03-11 15:39:48 +00008129 * @throws IllegalStateException if device has an ongoing call.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07008130 * @throws SecurityException if {@code admin} is not a device owner.
Mahaver Chopra1216ae52016-03-11 15:39:48 +00008131 * @see TelephonyManager#CALL_STATE_IDLE
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00008132 */
8133 public void reboot(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008134 throwIfParentInstance("reboot");
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00008135 try {
8136 mService.reboot(admin);
8137 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008138 throw re.rethrowFromSystemServer();
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00008139 }
8140 }
Kenny Guy06de4e72015-12-22 12:07:39 +00008141
8142 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07008143 * Called by a device admin to set the short support message. This will be displayed to the user
8144 * in settings screens where funtionality has been disabled by the admin. The message should be
8145 * limited to a short statement such as "This setting is disabled by your administrator. Contact
8146 * someone@example.com for support." If the message is longer than 200 characters it may be
8147 * truncated.
8148 * <p>
8149 * If the short support message needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00008150 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
8151 * and set a new version of this string accordingly.
8152 *
Kenny Guy06de4e72015-12-22 12:07:39 +00008153 * @see #setLongSupportMessage
Kenny Guy06de4e72015-12-22 12:07:39 +00008154 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07008155 * @param message Short message to be displayed to the user in settings or null to clear the
8156 * existing message.
8157 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00008158 */
8159 public void setShortSupportMessage(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07008160 @Nullable CharSequence message) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008161 throwIfParentInstance("setShortSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00008162 if (mService != null) {
8163 try {
8164 mService.setShortSupportMessage(admin, message);
8165 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008166 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00008167 }
8168 }
8169 }
8170
8171 /**
8172 * Called by a device admin to get the short support message.
8173 *
8174 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07008175 * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)} or
8176 * null if no message has been set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07008177 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00008178 */
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07008179 public CharSequence getShortSupportMessage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008180 throwIfParentInstance("getShortSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00008181 if (mService != null) {
8182 try {
8183 return mService.getShortSupportMessage(admin);
8184 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008185 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00008186 }
8187 }
8188 return null;
8189 }
8190
8191 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07008192 * Called by a device admin to set the long support message. This will be displayed to the user
8193 * in the device administators settings screen.
8194 * <p>
8195 * If the long support message needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00008196 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
8197 * and set a new version of this string accordingly.
8198 *
Kenny Guy06de4e72015-12-22 12:07:39 +00008199 * @see #setShortSupportMessage
Kenny Guy06de4e72015-12-22 12:07:39 +00008200 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07008201 * @param message Long message to be displayed to the user in settings or null to clear the
8202 * existing message.
8203 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00008204 */
8205 public void setLongSupportMessage(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07008206 @Nullable CharSequence message) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008207 throwIfParentInstance("setLongSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00008208 if (mService != null) {
8209 try {
8210 mService.setLongSupportMessage(admin, message);
8211 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008212 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00008213 }
8214 }
8215 }
8216
8217 /**
8218 * Called by a device admin to get the long support message.
8219 *
8220 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07008221 * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)} or
8222 * null if no message has been set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07008223 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00008224 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07008225 public @Nullable CharSequence getLongSupportMessage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008226 throwIfParentInstance("getLongSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00008227 if (mService != null) {
8228 try {
8229 return mService.getLongSupportMessage(admin);
8230 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008231 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00008232 }
8233 }
8234 return null;
8235 }
8236
8237 /**
8238 * Called by the system to get the short support message.
8239 *
8240 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
8241 * @param userHandle user id the admin is running as.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07008242 * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)}
Kenny Guy06de4e72015-12-22 12:07:39 +00008243 *
8244 * @hide
8245 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07008246 public @Nullable CharSequence getShortSupportMessageForUser(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07008247 int userHandle) {
Kenny Guy06de4e72015-12-22 12:07:39 +00008248 if (mService != null) {
8249 try {
8250 return mService.getShortSupportMessageForUser(admin, userHandle);
8251 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008252 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00008253 }
8254 }
8255 return null;
8256 }
8257
8258
8259 /**
8260 * Called by the system to get the long support message.
8261 *
8262 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
8263 * @param userHandle user id the admin is running as.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07008264 * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)}
Kenny Guy06de4e72015-12-22 12:07:39 +00008265 *
8266 * @hide
8267 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07008268 public @Nullable CharSequence getLongSupportMessageForUser(
8269 @NonNull ComponentName admin, int userHandle) {
Kenny Guy06de4e72015-12-22 12:07:39 +00008270 if (mService != null) {
8271 try {
8272 return mService.getLongSupportMessageForUser(admin, userHandle);
8273 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008274 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00008275 }
8276 }
8277 return null;
8278 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00008279
8280 /**
Esteban Talavera62399912016-01-11 15:37:55 +00008281 * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager}
8282 * whose calls act on the parent profile.
Benjamin Franz66b45f02016-04-05 19:12:39 +01008283 *
8284 * <p>The following methods are supported for the parent instance, all other methods will
8285 * throw a SecurityException when called on the parent instance:
8286 * <ul>
8287 * <li>{@link #getPasswordQuality}</li>
8288 * <li>{@link #setPasswordQuality}</li>
8289 * <li>{@link #getPasswordMinimumLength}</li>
8290 * <li>{@link #setPasswordMinimumLength}</li>
8291 * <li>{@link #getPasswordMinimumUpperCase}</li>
8292 * <li>{@link #setPasswordMinimumUpperCase}</li>
8293 * <li>{@link #getPasswordMinimumLowerCase}</li>
8294 * <li>{@link #setPasswordMinimumLowerCase}</li>
8295 * <li>{@link #getPasswordMinimumLetters}</li>
8296 * <li>{@link #setPasswordMinimumLetters}</li>
8297 * <li>{@link #getPasswordMinimumNumeric}</li>
8298 * <li>{@link #setPasswordMinimumNumeric}</li>
8299 * <li>{@link #getPasswordMinimumSymbols}</li>
8300 * <li>{@link #setPasswordMinimumSymbols}</li>
8301 * <li>{@link #getPasswordMinimumNonLetter}</li>
8302 * <li>{@link #setPasswordMinimumNonLetter}</li>
8303 * <li>{@link #getPasswordHistoryLength}</li>
8304 * <li>{@link #setPasswordHistoryLength}</li>
8305 * <li>{@link #getPasswordExpirationTimeout}</li>
8306 * <li>{@link #setPasswordExpirationTimeout}</li>
8307 * <li>{@link #getPasswordExpiration}</li>
Charles He8c760562016-10-25 16:36:53 +01008308 * <li>{@link #getPasswordMaximumLength}</li>
Benjamin Franz66b45f02016-04-05 19:12:39 +01008309 * <li>{@link #isActivePasswordSufficient}</li>
8310 * <li>{@link #getCurrentFailedPasswordAttempts}</li>
8311 * <li>{@link #getMaximumFailedPasswordsForWipe}</li>
8312 * <li>{@link #setMaximumFailedPasswordsForWipe}</li>
8313 * <li>{@link #getMaximumTimeToLock}</li>
8314 * <li>{@link #setMaximumTimeToLock}</li>
8315 * <li>{@link #lockNow}</li>
8316 * <li>{@link #getKeyguardDisabledFeatures}</li>
8317 * <li>{@link #setKeyguardDisabledFeatures}</li>
8318 * <li>{@link #getTrustAgentConfiguration}</li>
8319 * <li>{@link #setTrustAgentConfiguration}</li>
Michal Karpinskia20d8bb2016-11-23 12:09:08 +00008320 * <li>{@link #getRequiredStrongAuthTimeout}</li>
8321 * <li>{@link #setRequiredStrongAuthTimeout}</li>
Benjamin Franz66b45f02016-04-05 19:12:39 +01008322 * </ul>
Clara Bayarri3e826ef2015-12-14 17:51:22 +00008323 *
8324 * @return a new instance of {@link DevicePolicyManager} that acts on the parent profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07008325 * @throws SecurityException if {@code admin} is not a profile owner.
Clara Bayarri3e826ef2015-12-14 17:51:22 +00008326 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07008327 public @NonNull DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008328 throwIfParentInstance("getParentProfileInstance");
Clara Bayarri3e826ef2015-12-14 17:51:22 +00008329 try {
8330 if (!mService.isManagedProfile(admin)) {
8331 throw new SecurityException("The current user does not have a parent profile.");
8332 }
Jeff Sharkey49ca5292016-05-10 12:54:45 -06008333 return new DevicePolicyManager(mContext, mService, true);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008334 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008335 throw e.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008336 }
8337 }
8338
8339 /**
Esteban Talaverad36dd152016-12-15 08:51:45 +00008340 * Called by device owner to control the security logging feature.
Michal Karpinski6235a942016-03-15 12:07:23 +00008341 *
8342 * <p> Security logs contain various information intended for security auditing purposes.
8343 * See {@link SecurityEvent} for details.
8344 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00008345 * <p><strong>Note:</strong> The device owner won't be able to retrieve security logs if there
8346 * are unaffiliated secondary users or profiles on the device, regardless of whether the
8347 * feature is enabled. Logs will be discarded if the internal buffer fills up while waiting for
8348 * all users to become affiliated. Therefore it's recommended that affiliation ids are set for
8349 * new users as soon as possible after provisioning via {@link #setAffiliationIds}.
Michal Karpinskib58e4962016-03-01 14:55:10 +00008350 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008351 * @param admin Which device owner this request is associated with.
Michal Karpinski6235a942016-03-15 12:07:23 +00008352 * @param enabled whether security logging should be enabled or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07008353 * @throws SecurityException if {@code admin} is not a device owner.
Alex Chau443b6432017-12-13 12:44:31 +00008354 * @see #setAffiliationIds
Michal Karpinski6235a942016-03-15 12:07:23 +00008355 * @see #retrieveSecurityLogs
8356 */
8357 public void setSecurityLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008358 throwIfParentInstance("setSecurityLoggingEnabled");
Michal Karpinski6235a942016-03-15 12:07:23 +00008359 try {
8360 mService.setSecurityLoggingEnabled(admin, enabled);
8361 } catch (RemoteException re) {
8362 throw re.rethrowFromSystemServer();
8363 }
8364 }
8365
8366 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00008367 * Return whether security logging is enabled or not by the device owner.
8368 *
8369 * <p>Can only be called by the device owner, otherwise a {@link SecurityException} will be
8370 * thrown.
8371 *
8372 * @param admin Which device owner this request is associated with.
8373 * @return {@code true} if security logging is enabled by device owner, {@code false} otherwise.
8374 * @throws SecurityException if {@code admin} is not a device owner.
8375 */
Bartosz Fabianowski0ec00002017-03-24 14:22:24 +01008376 public boolean isSecurityLoggingEnabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008377 throwIfParentInstance("isSecurityLoggingEnabled");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008378 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00008379 return mService.isSecurityLoggingEnabled(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008380 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008381 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008382 }
8383 }
8384
8385 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00008386 * Called by device owner to retrieve all new security logging entries since the last call to
8387 * this API after device boots.
8388 *
8389 * <p> Access to the logs is rate limited and it will only return new logs after the device
8390 * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}.
8391 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00008392 * <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 +00008393 * device. Otherwise a {@link SecurityException} will be thrown. See {@link #isAffiliatedUser}.
Michal Karpinskib58e4962016-03-01 14:55:10 +00008394 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008395 * @param admin Which device owner this request is associated with.
Michal Karpinski6235a942016-03-15 12:07:23 +00008396 * @return the new batch of security logs which is a list of {@link SecurityEvent},
8397 * or {@code null} if rate limitation is exceeded or if logging is currently disabled.
Esteban Talaverad36dd152016-12-15 08:51:45 +00008398 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
Alex Chau443b6432017-12-13 12:44:31 +00008399 * profile or secondary user that is not affiliated with the device.
8400 * @see #isAffiliatedUser
Esteban Talaverad36dd152016-12-15 08:51:45 +00008401 * @see DeviceAdminReceiver#onSecurityLogsAvailable
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008402 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07008403 public @Nullable List<SecurityEvent> retrieveSecurityLogs(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008404 throwIfParentInstance("retrieveSecurityLogs");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008405 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00008406 ParceledListSlice<SecurityEvent> list = mService.retrieveSecurityLogs(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008407 if (list != null) {
8408 return list.getList();
8409 } else {
8410 // Rate limit exceeded.
8411 return null;
8412 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00008413 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008414 throw re.rethrowFromSystemServer();
Clara Bayarri3e826ef2015-12-14 17:51:22 +00008415 }
8416 }
Benjamin Franz59720bb2016-01-18 15:26:11 +00008417
8418 /**
Pavel Grafov5bb5a622018-01-31 21:06:24 +00008419 * Forces a batch of security logs to be fetched from logd and makes it available for DPC.
8420 * Only callable by ADB. If throttled, returns time to wait in milliseconds, otherwise 0.
8421 * @hide
8422 */
8423 public long forceSecurityLogs() {
8424 if (mService == null) {
8425 return 0;
8426 }
8427 try {
8428 return mService.forceSecurityLogs();
8429 } catch (RemoteException re) {
8430 throw re.rethrowFromSystemServer();
8431 }
8432 }
8433
8434 /**
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00008435 * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent
8436 * profile.
8437 *
8438 * @hide
8439 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07008440 public @NonNull DevicePolicyManager getParentProfileInstance(UserInfo uInfo) {
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00008441 mContext.checkSelfPermission(
8442 android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS);
8443 if (!uInfo.isManagedProfile()) {
8444 throw new SecurityException("The user " + uInfo.id
8445 + " does not have a parent profile.");
8446 }
Jeff Sharkey49ca5292016-05-10 12:54:45 -06008447 return new DevicePolicyManager(mContext, mService, true);
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00008448 }
8449
8450 /**
Sudheer Shanka5be44ff2018-01-23 15:15:03 -08008451 * Called by a device or profile owner to restrict packages from using metered data.
Sudheer Shanka04d61ae2018-01-17 12:16:57 -08008452 *
8453 * @param admin which {@link DeviceAdminReceiver} this request is associated with.
8454 * @param packageNames the list of package names to be restricted.
8455 * @return a list of package names which could not be restricted.
8456 * @throws SecurityException if {@code admin} is not a device or profile owner.
8457 */
Michael Wachenschwanz54164682018-03-08 16:23:52 -08008458 public @NonNull List<String> setMeteredDataDisabledPackages(@NonNull ComponentName admin,
Sudheer Shanka04d61ae2018-01-17 12:16:57 -08008459 @NonNull List<String> packageNames) {
8460 throwIfParentInstance("setMeteredDataDisabled");
8461 if (mService != null) {
8462 try {
Michael Wachenschwanz54164682018-03-08 16:23:52 -08008463 return mService.setMeteredDataDisabledPackages(admin, packageNames);
Sudheer Shanka04d61ae2018-01-17 12:16:57 -08008464 } catch (RemoteException re) {
8465 throw re.rethrowFromSystemServer();
8466 }
8467 }
8468 return packageNames;
8469 }
8470
8471 /**
8472 * Called by a device or profile owner to retrieve the list of packages which are restricted
Sudheer Shanka5be44ff2018-01-23 15:15:03 -08008473 * by the admin from using metered data.
Sudheer Shanka04d61ae2018-01-17 12:16:57 -08008474 *
8475 * @param admin which {@link DeviceAdminReceiver} this request is associated with.
8476 * @return the list of restricted package names.
8477 * @throws SecurityException if {@code admin} is not a device or profile owner.
8478 */
Michael Wachenschwanz54164682018-03-08 16:23:52 -08008479 public @NonNull List<String> getMeteredDataDisabledPackages(@NonNull ComponentName admin) {
Sudheer Shanka04d61ae2018-01-17 12:16:57 -08008480 throwIfParentInstance("getMeteredDataDisabled");
8481 if (mService != null) {
8482 try {
Michael Wachenschwanz54164682018-03-08 16:23:52 -08008483 return mService.getMeteredDataDisabledPackages(admin);
Sudheer Shanka04d61ae2018-01-17 12:16:57 -08008484 } catch (RemoteException re) {
8485 throw re.rethrowFromSystemServer();
8486 }
8487 }
8488 return new ArrayList<>();
8489 }
8490
8491 /**
Sudheer Shanka5be44ff2018-01-23 15:15:03 -08008492 * Called by the system to check if a package is restricted from using metered data
8493 * by {@param admin}.
8494 *
8495 * @param admin which {@link DeviceAdminReceiver} this request is associated with.
8496 * @param packageName the package whose restricted status is needed.
8497 * @param userId the user to which {@param packageName} belongs.
8498 * @return {@code true} if the package is restricted by admin, otherwise {@code false}
8499 * @throws SecurityException if the caller doesn't run with {@link Process#SYSTEM_UID}
8500 * @hide
8501 */
Michael Wachenschwanz54164682018-03-08 16:23:52 -08008502 public boolean isMeteredDataDisabledPackageForUser(@NonNull ComponentName admin,
8503 String packageName, @UserIdInt int userId) {
Sudheer Shanka5be44ff2018-01-23 15:15:03 -08008504 throwIfParentInstance("getMeteredDataDisabledForUser");
8505 if (mService != null) {
8506 try {
Michael Wachenschwanz54164682018-03-08 16:23:52 -08008507 return mService.isMeteredDataDisabledPackageForUser(admin, packageName, userId);
Sudheer Shanka5be44ff2018-01-23 15:15:03 -08008508 } catch (RemoteException re) {
8509 throw re.rethrowFromSystemServer();
8510 }
8511 }
8512 return false;
8513 }
8514
8515 /**
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008516 * Called by device owners to retrieve device logs from before the device's last reboot.
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008517 * <p>
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01008518 * <strong> This API is not supported on all devices. Calling this API on unsupported devices
8519 * will result in {@code null} being returned. The device logs are retrieved from a RAM region
8520 * which is not guaranteed to be corruption-free during power cycles, as a result be cautious
8521 * about data corruption when parsing. </strong>
Esteban Talaverad36dd152016-12-15 08:51:45 +00008522 *
8523 * <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 +00008524 * device. Otherwise a {@link SecurityException} will be thrown. See {@link #isAffiliatedUser}.
Michal Karpinskib58e4962016-03-01 14:55:10 +00008525 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008526 * @param admin Which device owner this request is associated with.
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01008527 * @return Device logs from before the latest reboot of the system, or {@code null} if this API
8528 * is not supported on the device.
Esteban Talaverad36dd152016-12-15 08:51:45 +00008529 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
Alex Chau443b6432017-12-13 12:44:31 +00008530 * profile or secondary user that is not affiliated with the device.
8531 * @see #isAffiliatedUser
Esteban Talaverad36dd152016-12-15 08:51:45 +00008532 * @see #retrieveSecurityLogs
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008533 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07008534 public @Nullable List<SecurityEvent> retrievePreRebootSecurityLogs(
8535 @NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008536 throwIfParentInstance("retrievePreRebootSecurityLogs");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008537 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00008538 ParceledListSlice<SecurityEvent> list = mService.retrievePreRebootSecurityLogs(admin);
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01008539 if (list != null) {
8540 return list.getList();
8541 } else {
8542 return null;
8543 }
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008544 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008545 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008546 }
8547 }
8548
8549 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07008550 * Called by a profile owner of a managed profile to set the color used for customization. This
8551 * color is used as background color of the confirm credentials screen for that user. The
Clara Bayarri8d0bd7fa2016-03-30 14:59:58 +01008552 * default color is teal (#00796B).
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07008553 * <p>
8554 * The confirm credentials screen can be created using
Benjamin Franz59720bb2016-01-18 15:26:11 +00008555 * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}.
8556 *
8557 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinski74cd7302016-04-12 15:17:36 +01008558 * @param color The 24bit (0xRRGGBB) representation of the color to be used.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07008559 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz59720bb2016-01-18 15:26:11 +00008560 */
8561 public void setOrganizationColor(@NonNull ComponentName admin, int color) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008562 throwIfParentInstance("setOrganizationColor");
Benjamin Franz59720bb2016-01-18 15:26:11 +00008563 try {
Michal Karpinski74cd7302016-04-12 15:17:36 +01008564 // always enforce alpha channel to have 100% opacity
8565 color |= 0xFF000000;
Benjamin Franz59720bb2016-01-18 15:26:11 +00008566 mService.setOrganizationColor(admin, color);
8567 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008568 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00008569 }
8570 }
8571
8572 /**
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00008573 * @hide
8574 *
8575 * Sets the color used for customization.
8576 *
Michal Karpinski74cd7302016-04-12 15:17:36 +01008577 * @param color The 24bit (0xRRGGBB) representation of the color to be used.
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00008578 * @param userId which user to set the color to.
8579 * @RequiresPermission(allOf = {
8580 * Manifest.permission.MANAGE_USERS,
8581 * Manifest.permission.INTERACT_ACROSS_USERS_FULL})
8582 */
8583 public void setOrganizationColorForUser(@ColorInt int color, @UserIdInt int userId) {
8584 try {
Michal Karpinski74cd7302016-04-12 15:17:36 +01008585 // always enforce alpha channel to have 100% opacity
8586 color |= 0xFF000000;
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00008587 mService.setOrganizationColorForUser(color, userId);
8588 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008589 throw re.rethrowFromSystemServer();
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00008590 }
8591 }
8592
8593 /**
Benjamin Franz59720bb2016-01-18 15:26:11 +00008594 * Called by a profile owner of a managed profile to retrieve the color used for customization.
8595 * This color is used as background color of the confirm credentials screen for that user.
8596 *
8597 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinski74cd7302016-04-12 15:17:36 +01008598 * @return The 24bit (0xRRGGBB) representation of the color to be used.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07008599 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz59720bb2016-01-18 15:26:11 +00008600 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01008601 public @ColorInt int getOrganizationColor(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008602 throwIfParentInstance("getOrganizationColor");
Benjamin Franz59720bb2016-01-18 15:26:11 +00008603 try {
8604 return mService.getOrganizationColor(admin);
8605 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008606 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00008607 }
8608 }
8609
8610 /**
8611 * @hide
8612 * Retrieve the customization color for a given user.
8613 *
8614 * @param userHandle The user id of the user we're interested in.
Michal Karpinski74cd7302016-04-12 15:17:36 +01008615 * @return The 24bit (0xRRGGBB) representation of the color to be used.
Benjamin Franz59720bb2016-01-18 15:26:11 +00008616 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01008617 public @ColorInt int getOrganizationColorForUser(int userHandle) {
Benjamin Franz59720bb2016-01-18 15:26:11 +00008618 try {
8619 return mService.getOrganizationColorForUser(userHandle);
8620 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008621 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00008622 }
8623 }
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01008624
8625 /**
Wen ZHANG2be4cfc2017-09-21 18:29:43 +01008626 * Called by the device owner (since API 26) or profile owner (since API 24) to set the name of
8627 * the organization under management.
8628 *
8629 * <p>If the organization name needs to be localized, it is the responsibility of the {@link
8630 * DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast and set
8631 * a new version of this string accordingly.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00008632 *
8633 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
8634 * @param title The organization name or {@code null} to clear a previously set name.
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01008635 * @throws SecurityException if {@code admin} is not a device or profile owner.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00008636 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01008637 public void setOrganizationName(@NonNull ComponentName admin, @Nullable CharSequence title) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008638 throwIfParentInstance("setOrganizationName");
Benjamin Franz3e8a7092016-01-25 16:19:08 +00008639 try {
8640 mService.setOrganizationName(admin, title);
8641 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008642 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00008643 }
8644 }
8645
8646 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07008647 * Called by a profile owner of a managed profile to retrieve the name of the organization under
8648 * management.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00008649 *
8650 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
8651 * @return The organization name or {@code null} if none is set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07008652 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00008653 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07008654 public @Nullable CharSequence getOrganizationName(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008655 throwIfParentInstance("getOrganizationName");
Benjamin Franz3e8a7092016-01-25 16:19:08 +00008656 try {
8657 return mService.getOrganizationName(admin);
8658 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008659 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00008660 }
8661 }
8662
8663 /**
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01008664 * Called by the system to retrieve the name of the organization managing the device.
8665 *
8666 * @return The organization name or {@code null} if none is set.
8667 * @throws SecurityException if the caller is not the device owner, does not hold the
8668 * MANAGE_USERS permission and is not the system.
8669 *
8670 * @hide
8671 */
8672 @SystemApi
8673 @TestApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06008674 @SuppressLint("Doclava125")
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01008675 public @Nullable CharSequence getDeviceOwnerOrganizationName() {
8676 try {
8677 return mService.getDeviceOwnerOrganizationName();
8678 } catch (RemoteException re) {
8679 throw re.rethrowFromSystemServer();
8680 }
8681 }
8682
8683 /**
Benjamin Franz3e8a7092016-01-25 16:19:08 +00008684 * Retrieve the default title message used in the confirm credentials screen for a given user.
8685 *
8686 * @param userHandle The user id of the user we're interested in.
8687 * @return The organization name or {@code null} if none is set.
8688 *
8689 * @hide
8690 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07008691 public @Nullable CharSequence getOrganizationNameForUser(int userHandle) {
Benjamin Franz3e8a7092016-01-25 16:19:08 +00008692 try {
8693 return mService.getOrganizationNameForUser(userHandle);
8694 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008695 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00008696 }
8697 }
8698
8699 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00008700 * @return the {@link UserProvisioningState} for the current user - for unmanaged users will
8701 * return {@link #STATE_USER_UNMANAGED}
8702 * @hide
8703 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00008704 @SystemApi
Eric Sandness3780c092018-03-23 16:16:11 +00008705 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Alan Treadwayafad8782016-01-19 15:15:08 +00008706 @UserProvisioningState
8707 public int getUserProvisioningState() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008708 throwIfParentInstance("getUserProvisioningState");
Alan Treadwayafad8782016-01-19 15:15:08 +00008709 if (mService != null) {
8710 try {
8711 return mService.getUserProvisioningState();
8712 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008713 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00008714 }
8715 }
8716 return STATE_USER_UNMANAGED;
8717 }
8718
8719 /**
8720 * Set the {@link UserProvisioningState} for the supplied user, if they are managed.
8721 *
8722 * @param state to store
8723 * @param userHandle for user
8724 * @hide
8725 */
8726 public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) {
8727 if (mService != null) {
8728 try {
8729 mService.setUserProvisioningState(state, userHandle);
8730 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008731 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00008732 }
8733 }
8734 }
8735
8736 /**
Esteban Talaverac9bb3782016-11-11 15:41:14 +00008737 * Indicates the entity that controls the device or profile owner. Two users/profiles are
8738 * affiliated if the set of ids set by their device or profile owners intersect.
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01008739 *
Alex Chau443b6432017-12-13 12:44:31 +00008740 * <p>A user/profile that is affiliated with the device owner user is considered to be
8741 * affiliated with the device.
8742 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00008743 * <p><strong>Note:</strong> Features that depend on user affiliation (such as security logging
8744 * or {@link #bindDeviceAdminServiceAsUser}) won't be available when a secondary user or profile
8745 * is created, until it becomes affiliated. Therefore it is recommended that the appropriate
8746 * affiliation ids are set by its profile owner as soon as possible after the user/profile is
8747 * created.
8748 *
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01008749 * @param admin Which profile or device owner this request is associated with.
Tony Mak31657432017-04-25 09:29:55 +01008750 * @param ids A set of opaque non-empty affiliation ids.
Esteban Talaverac9bb3782016-11-11 15:41:14 +00008751 *
Tony Mak31657432017-04-25 09:29:55 +01008752 * @throws IllegalArgumentException if {@code ids} is null or contains an empty string.
Alex Chau443b6432017-12-13 12:44:31 +00008753 * @see #isAffiliatedUser
Tony Mak31657432017-04-25 09:29:55 +01008754 */
8755 public void setAffiliationIds(@NonNull ComponentName admin, @NonNull Set<String> ids) {
8756 throwIfParentInstance("setAffiliationIds");
8757 if (ids == null) {
8758 throw new IllegalArgumentException("ids must not be null");
8759 }
8760 try {
8761 mService.setAffiliationIds(admin, new ArrayList<>(ids));
8762 } catch (RemoteException e) {
8763 throw e.rethrowFromSystemServer();
8764 }
8765 }
8766
8767 /**
Tony Mak31657432017-04-25 09:29:55 +01008768 * Returns the set of affiliation ids previously set via {@link #setAffiliationIds}, or an
8769 * empty set if none have been set.
Esteban Talaverac9bb3782016-11-11 15:41:14 +00008770 */
Tony Mak31657432017-04-25 09:29:55 +01008771 public @NonNull Set<String> getAffiliationIds(@NonNull ComponentName admin) {
Tony Mak62cf5862017-05-02 13:50:18 +01008772 throwIfParentInstance("getAffiliationIds");
Esteban Talaverac9bb3782016-11-11 15:41:14 +00008773 try {
Tony Mak31657432017-04-25 09:29:55 +01008774 return new ArraySet<>(mService.getAffiliationIds(admin));
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01008775 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008776 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01008777 }
8778 }
8779
8780 /**
Esteban Talaverac9bb3782016-11-11 15:41:14 +00008781 * Returns whether this user/profile is affiliated with the device.
8782 * <p>
8783 * By definition, the user that the device owner runs on is always affiliated with the device.
8784 * Any other user/profile is considered affiliated with the device if the set specified by its
8785 * profile owner via {@link #setAffiliationIds} intersects with the device owner's.
Alex Chau443b6432017-12-13 12:44:31 +00008786 * @see #setAffiliationIds
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01008787 */
8788 public boolean isAffiliatedUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008789 throwIfParentInstance("isAffiliatedUser");
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01008790 try {
Esteban Talaverac9bb3782016-11-11 15:41:14 +00008791 return mService.isAffiliatedUser();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01008792 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008793 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01008794 }
8795 }
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08008796
8797 /**
8798 * @hide
8799 * Returns whether the uninstall for {@code packageName} for the current user is in queue
8800 * to be started
8801 * @param packageName the package to check for
8802 * @return whether the uninstall intent for {@code packageName} is pending
8803 */
8804 public boolean isUninstallInQueue(String packageName) {
8805 try {
8806 return mService.isUninstallInQueue(packageName);
8807 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008808 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08008809 }
8810 }
8811
8812 /**
8813 * @hide
8814 * @param packageName the package containing active DAs to be uninstalled
8815 */
8816 public void uninstallPackageWithActiveAdmins(String packageName) {
8817 try {
8818 mService.uninstallPackageWithActiveAdmins(packageName);
8819 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008820 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08008821 }
8822 }
Benjamin Franzbc33c822016-04-15 08:57:52 +01008823
Kenny Guy38dcca52016-04-19 13:09:18 +01008824 /**
8825 * @hide
8826 * Remove a test admin synchronously without sending it a broadcast about being removed.
8827 * If the admin is a profile owner or device owner it will still be removed.
8828 *
8829 * @param userHandle user id to remove the admin for.
8830 * @param admin The administration compononent to remove.
8831 * @throws SecurityException if the caller is not shell / root or the admin package
8832 * isn't a test application see {@link ApplicationInfo#FLAG_TEST_APP}.
8833 */
8834 public void forceRemoveActiveAdmin(ComponentName adminReceiver, int userHandle) {
8835 try {
8836 mService.forceRemoveActiveAdmin(adminReceiver, userHandle);
8837 } catch (RemoteException re) {
8838 throw re.rethrowFromSystemServer();
8839 }
8840 }
8841
Mahaver Chopra790d1982016-07-07 16:06:49 +01008842 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01008843 * Returns whether the device has been provisioned.
8844 *
8845 * <p>Not for use by third-party applications.
8846 *
Mahaver Chopra790d1982016-07-07 16:06:49 +01008847 * @hide
Mahaver Chopra790d1982016-07-07 16:06:49 +01008848 */
Lenka Trochtova5291ee72016-11-28 16:38:23 +01008849 @SystemApi
Eric Sandnessdf30c7d2018-03-27 09:56:40 +01008850 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Mahaver Chopra790d1982016-07-07 16:06:49 +01008851 public boolean isDeviceProvisioned() {
8852 try {
8853 return mService.isDeviceProvisioned();
8854 } catch (RemoteException re) {
8855 throw re.rethrowFromSystemServer();
8856 }
8857 }
8858
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01008859 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01008860 * Writes that the provisioning configuration has been applied.
8861 *
8862 * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS}
8863 * permission.
8864 *
8865 * <p>Not for use by third-party applications.
8866 *
8867 * @hide
8868 */
8869 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06008870 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01008871 public void setDeviceProvisioningConfigApplied() {
8872 try {
8873 mService.setDeviceProvisioningConfigApplied();
8874 } catch (RemoteException re) {
8875 throw re.rethrowFromSystemServer();
8876 }
8877 }
8878
8879 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01008880 * Returns whether the provisioning configuration has been applied.
8881 *
8882 * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS} permission.
8883 *
8884 * <p>Not for use by third-party applications.
8885 *
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01008886 * @return whether the provisioning configuration has been applied.
Lenka Trochtova5291ee72016-11-28 16:38:23 +01008887 *
8888 * @hide
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01008889 */
Lenka Trochtova5291ee72016-11-28 16:38:23 +01008890 @SystemApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06008891 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01008892 public boolean isDeviceProvisioningConfigApplied() {
8893 try {
8894 return mService.isDeviceProvisioningConfigApplied();
8895 } catch (RemoteException re) {
8896 throw re.rethrowFromSystemServer();
8897 }
8898 }
8899
Victor Chang9bfc65f2016-08-15 12:27:09 +01008900 /**
8901 * @hide
Victor Chang3577ed22016-08-25 18:49:26 +01008902 * Force update user setup completed status. This API has no effect on user build.
8903 * @throws {@link SecurityException} if the caller has no
Esteban Talavera01576862016-12-15 11:16:44 +00008904 * {@code android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS} or the caller is
8905 * not {@link UserHandle#SYSTEM_USER}
Victor Chang9bfc65f2016-08-15 12:27:09 +01008906 */
8907 public void forceUpdateUserSetupComplete() {
8908 try {
8909 mService.forceUpdateUserSetupComplete();
8910 } catch (RemoteException re) {
8911 throw re.rethrowFromSystemServer();
8912 }
8913 }
8914
Mathew Inwood4fb17d12018-08-14 14:25:44 +01008915 @UnsupportedAppUsage
Benjamin Franzbc33c822016-04-15 08:57:52 +01008916 private void throwIfParentInstance(String functionName) {
8917 if (mParentInstance) {
8918 throw new SecurityException(functionName + " cannot be called on the parent instance");
8919 }
8920 }
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02008921
8922 /**
Michal Karpinskib71fedc2017-01-05 15:21:38 +00008923 * Allows the device owner to enable or disable the backup service.
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02008924 *
Michal Karpinskib71fedc2017-01-05 15:21:38 +00008925 * <p> Backup service manages all backup and restore mechanisms on the device. Setting this to
8926 * false will prevent data from being backed up or restored.
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02008927 *
Michal Karpinskib71fedc2017-01-05 15:21:38 +00008928 * <p> Backup service is off by default when device owner is present.
8929 *
Rubin Xu0367f072017-04-24 20:17:16 +01008930 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
8931 * @param enabled {@code true} to enable the backup service, {@code false} to disable it.
Michal Karpinskib71fedc2017-01-05 15:21:38 +00008932 * @throws SecurityException if {@code admin} is not a device owner.
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02008933 */
8934 public void setBackupServiceEnabled(@NonNull ComponentName admin, boolean enabled) {
Esteban Talavera5b7f2d02017-02-17 09:45:24 +00008935 throwIfParentInstance("setBackupServiceEnabled");
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02008936 try {
8937 mService.setBackupServiceEnabled(admin, enabled);
8938 } catch (RemoteException re) {
8939 throw re.rethrowFromSystemServer();
8940 }
8941 }
8942
8943 /**
Michal Karpinskib71fedc2017-01-05 15:21:38 +00008944 * Return whether the backup service is enabled by the device owner.
8945 *
8946 * <p> Backup service manages all backup and restore mechanisms on the device.
8947 *
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02008948 * @return {@code true} if backup service is enabled, {@code false} otherwise.
Michal Karpinskib71fedc2017-01-05 15:21:38 +00008949 * @see #setBackupServiceEnabled
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02008950 */
8951 public boolean isBackupServiceEnabled(@NonNull ComponentName admin) {
Esteban Talavera5b7f2d02017-02-17 09:45:24 +00008952 throwIfParentInstance("isBackupServiceEnabled");
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02008953 try {
8954 return mService.isBackupServiceEnabled(admin);
8955 } catch (RemoteException re) {
8956 throw re.rethrowFromSystemServer();
8957 }
8958 }
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01008959
8960 /**
Lenka Trochtovac141d082017-12-20 14:45:16 +01008961 * Makes backups mandatory and enforces the usage of the specified backup transport.
8962 *
8963 * <p>When a {@code null} backup transport is specified, backups are made optional again.
8964 * <p>Only device owner can call this method.
8965 * <p>If backups were disabled and a non-null backup transport {@link ComponentName} is
8966 * specified, backups will be enabled.
Lenka Trochtova27fd8212018-04-10 11:01:58 +02008967 * <p> If the backup service is disabled after the mandatory backup transport has been set, the
8968 * mandatory backup transport is cleared.
Lenka Trochtovac141d082017-12-20 14:45:16 +01008969 *
Lenka Trochtova56681f72018-03-09 15:47:50 +01008970 * <p>NOTE: The method shouldn't be called on the main thread.
8971 *
Lenka Trochtovac141d082017-12-20 14:45:16 +01008972 * @param admin admin Which {@link DeviceAdminReceiver} this request is associated with.
8973 * @param backupTransportComponent The backup transport layer to be used for mandatory backups.
Lenka Trochtova56681f72018-03-09 15:47:50 +01008974 * @return {@code true} if the backup transport was successfully set; {@code false} otherwise.
Lenka Trochtovac141d082017-12-20 14:45:16 +01008975 * @throws SecurityException if {@code admin} is not a device owner.
Lenka Trochtova27fd8212018-04-10 11:01:58 +02008976 * @hide
Lenka Trochtovac141d082017-12-20 14:45:16 +01008977 */
Lenka Trochtova56681f72018-03-09 15:47:50 +01008978 @WorkerThread
8979 public boolean setMandatoryBackupTransport(
8980 @NonNull ComponentName admin,
8981 @Nullable ComponentName backupTransportComponent) {
Lenka Trochtova62900122018-01-23 14:55:46 +01008982 throwIfParentInstance("setMandatoryBackupTransport");
Lenka Trochtovac141d082017-12-20 14:45:16 +01008983 try {
Lenka Trochtova56681f72018-03-09 15:47:50 +01008984 return mService.setMandatoryBackupTransport(admin, backupTransportComponent);
Lenka Trochtovac141d082017-12-20 14:45:16 +01008985 } catch (RemoteException re) {
8986 throw re.rethrowFromSystemServer();
8987 }
8988 }
8989
8990 /**
8991 * Returns the backup transport which has to be used for backups if backups are mandatory or
8992 * {@code null} if backups are not mandatory.
8993 *
8994 * @return a {@link ComponentName} of the backup transport layer to be used if backups are
8995 * mandatory or {@code null} if backups are not mandatory.
Lenka Trochtova27fd8212018-04-10 11:01:58 +02008996 * @hide
Lenka Trochtovac141d082017-12-20 14:45:16 +01008997 */
Mathew Inwood4fb17d12018-08-14 14:25:44 +01008998 @UnsupportedAppUsage
Lenka Trochtovac141d082017-12-20 14:45:16 +01008999 public ComponentName getMandatoryBackupTransport() {
Lenka Trochtova62900122018-01-23 14:55:46 +01009000 throwIfParentInstance("getMandatoryBackupTransport");
Lenka Trochtovac141d082017-12-20 14:45:16 +01009001 try {
9002 return mService.getMandatoryBackupTransport();
9003 } catch (RemoteException re) {
9004 throw re.rethrowFromSystemServer();
9005 }
9006 }
9007
9008
9009 /**
Esteban Talaverad36dd152016-12-15 08:51:45 +00009010 * Called by a device owner to control the network logging feature.
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01009011 *
Robin Leea40a2fb2017-02-08 17:07:06 +00009012 * <p> Network logs contain DNS lookup and connect() library call events. The following library
9013 * functions are recorded while network logging is active:
9014 * <ul>
9015 * <li>{@code getaddrinfo()}</li>
9016 * <li>{@code gethostbyname()}</li>
9017 * <li>{@code connect()}</li>
9018 * </ul>
9019 *
9020 * <p> Network logging is a low-overhead tool for forensics but it is not guaranteed to use
9021 * full system call logging; event reporting is enabled by default for all processes but not
9022 * strongly enforced.
9023 * Events from applications using alternative implementations of libc, making direct kernel
9024 * calls, or deliberately obfuscating traffic may not be recorded.
9025 *
9026 * <p> Some common network events may not be reported. For example:
9027 * <ul>
9028 * <li>Applications may hardcode IP addresses to reduce the number of DNS lookups, or use
9029 * an alternative system for name resolution, and so avoid calling
9030 * {@code getaddrinfo()} or {@code gethostbyname}.</li>
9031 * <li>Applications may use datagram sockets for performance reasons, for example
9032 * for a game client. Calling {@code connect()} is unnecessary for this kind of
9033 * socket, so it will not trigger a network event.</li>
9034 * </ul>
9035 *
9036 * <p> It is possible to directly intercept layer 3 traffic leaving the device using an
9037 * always-on VPN service.
9038 * See {@link #setAlwaysOnVpnPackage(ComponentName, String, boolean)}
9039 * and {@link android.net.VpnService} for details.
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01009040 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00009041 * <p><strong>Note:</strong> The device owner won't be able to retrieve network logs if there
9042 * are unaffiliated secondary users or profiles on the device, regardless of whether the
9043 * feature is enabled. Logs will be discarded if the internal buffer fills up while waiting for
9044 * all users to become affiliated. Therefore it's recommended that affiliation ids are set for
9045 * new users as soon as possible after provisioning via {@link #setAffiliationIds}.
9046 *
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01009047 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
9048 * @param enabled whether network logging should be enabled or not.
Esteban Talaverad36dd152016-12-15 08:51:45 +00009049 * @throws SecurityException if {@code admin} is not a device owner.
Alex Chau443b6432017-12-13 12:44:31 +00009050 * @see #setAffiliationIds
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01009051 * @see #retrieveNetworkLogs
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01009052 */
9053 public void setNetworkLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
9054 throwIfParentInstance("setNetworkLoggingEnabled");
9055 try {
9056 mService.setNetworkLoggingEnabled(admin, enabled);
9057 } catch (RemoteException re) {
9058 throw re.rethrowFromSystemServer();
9059 }
9060 }
9061
9062 /**
9063 * Return whether network logging is enabled by a device owner.
9064 *
phweissa4e169e2016-11-24 16:20:57 +01009065 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Can only
9066 * be {@code null} if the caller has MANAGE_USERS permission.
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01009067 * @return {@code true} if network logging is enabled by device owner, {@code false} otherwise.
Esteban Talaverad36dd152016-12-15 08:51:45 +00009068 * @throws SecurityException if {@code admin} is not a device owner and caller has
phweissa4e169e2016-11-24 16:20:57 +01009069 * no MANAGE_USERS permission
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01009070 */
phweissa4e169e2016-11-24 16:20:57 +01009071 public boolean isNetworkLoggingEnabled(@Nullable ComponentName admin) {
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01009072 throwIfParentInstance("isNetworkLoggingEnabled");
9073 try {
9074 return mService.isNetworkLoggingEnabled(admin);
9075 } catch (RemoteException re) {
9076 throw re.rethrowFromSystemServer();
9077 }
9078 }
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01009079
9080 /**
Michal Karpinskia9ff2062016-11-03 15:46:17 +00009081 * Called by device owner to retrieve the most recent batch of network logging events.
9082 * A device owner has to provide a batchToken provided as part of
9083 * {@link DeviceAdminReceiver#onNetworkLogsAvailable} callback. If the token doesn't match the
9084 * token of the most recent available batch of logs, {@code null} will be returned.
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01009085 *
9086 * <p> {@link NetworkEvent} can be one of {@link DnsEvent} or {@link ConnectEvent}.
9087 *
9088 * <p> The list of network events is sorted chronologically, and contains at most 1200 events.
9089 *
9090 * <p> Access to the logs is rate limited and this method will only return a new batch of logs
9091 * after the device device owner has been notified via
9092 * {@link DeviceAdminReceiver#onNetworkLogsAvailable}.
9093 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00009094 * <p>If a secondary user or profile is created, calling this method will throw a
9095 * {@link SecurityException} until all users become affiliated again. It will also no longer be
9096 * possible to retrieve the network logs batch with the most recent batchToken provided
9097 * by {@link DeviceAdminReceiver#onNetworkLogsAvailable}. See
9098 * {@link DevicePolicyManager#setAffiliationIds}.
9099 *
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01009100 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinskia9ff2062016-11-03 15:46:17 +00009101 * @param batchToken A token of the batch to retrieve
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01009102 * @return A new batch of network logs which is a list of {@link NetworkEvent}. Returns
Michal Karpinskia9ff2062016-11-03 15:46:17 +00009103 * {@code null} if the batch represented by batchToken is no longer available or if
9104 * logging is disabled.
Esteban Talaverad36dd152016-12-15 08:51:45 +00009105 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
Alex Chau443b6432017-12-13 12:44:31 +00009106 * profile or secondary user that is not affiliated with the device.
9107 * @see #setAffiliationIds
Michal Karpinskia9ff2062016-11-03 15:46:17 +00009108 * @see DeviceAdminReceiver#onNetworkLogsAvailable
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01009109 */
Michal Karpinskia9ff2062016-11-03 15:46:17 +00009110 public @Nullable List<NetworkEvent> retrieveNetworkLogs(@NonNull ComponentName admin,
9111 long batchToken) {
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01009112 throwIfParentInstance("retrieveNetworkLogs");
9113 try {
Michal Karpinskia9ff2062016-11-03 15:46:17 +00009114 return mService.retrieveNetworkLogs(admin, batchToken);
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01009115 } catch (RemoteException re) {
9116 throw re.rethrowFromSystemServer();
9117 }
9118 }
Tony Mak46aabe52016-11-14 12:53:06 +00009119
9120 /**
Esteban Talavera2f897912017-01-26 10:30:48 +00009121 * Called by a device owner to bind to a service from a profile owner or vice versa.
9122 * See {@link #getBindDeviceAdminTargetUsers} for a definition of which
Esteban Talaverafc291bc2016-11-21 13:52:03 +00009123 * device/profile owners are allowed to bind to services of another profile/device owner.
9124 * <p>
Tony Makeda0a9a2017-04-25 12:07:14 +01009125 * The service must be protected by {@link android.Manifest.permission#BIND_DEVICE_ADMIN}.
9126 * Note that the {@link Context} used to obtain this
Tony Mak46aabe52016-11-14 12:53:06 +00009127 * {@link DevicePolicyManager} instance via {@link Context#getSystemService(Class)} will be used
9128 * to bind to the {@link android.app.Service}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00009129 *
Tony Mak46aabe52016-11-14 12:53:06 +00009130 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
9131 * @param serviceIntent Identifies the service to connect to. The Intent must specify either an
9132 * explicit component name or a package name to match an
9133 * {@link IntentFilter} published by a service.
Tony Makbf9928d2016-12-22 11:02:45 +00009134 * @param conn Receives information as the service is started and stopped in main thread. This
9135 * must be a valid {@link ServiceConnection} object; it must not be {@code null}.
Tony Mak46aabe52016-11-14 12:53:06 +00009136 * @param flags Operation options for the binding operation. See
9137 * {@link Context#bindService(Intent, ServiceConnection, int)}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00009138 * @param targetUser Which user to bind to. Must be one of the users returned by
9139 * {@link #getBindDeviceAdminTargetUsers}, otherwise a {@link SecurityException} will
9140 * be thrown.
Tony Mak46aabe52016-11-14 12:53:06 +00009141 * @return If you have successfully bound to the service, {@code true} is returned;
9142 * {@code false} is returned if the connection is not made and you will not
9143 * receive the service object.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00009144 *
Tony Mak46aabe52016-11-14 12:53:06 +00009145 * @see Context#bindService(Intent, ServiceConnection, int)
Esteban Talaverafc291bc2016-11-21 13:52:03 +00009146 * @see #getBindDeviceAdminTargetUsers(ComponentName)
Tony Mak46aabe52016-11-14 12:53:06 +00009147 */
9148 public boolean bindDeviceAdminServiceAsUser(
9149 @NonNull ComponentName admin, Intent serviceIntent, @NonNull ServiceConnection conn,
9150 @Context.BindServiceFlags int flags, @NonNull UserHandle targetUser) {
9151 throwIfParentInstance("bindDeviceAdminServiceAsUser");
9152 // Keep this in sync with ContextImpl.bindServiceCommon.
9153 try {
Tony Makbf9928d2016-12-22 11:02:45 +00009154 final IServiceConnection sd = mContext.getServiceDispatcher(
9155 conn, mContext.getMainThreadHandler(), flags);
Tony Mak46aabe52016-11-14 12:53:06 +00009156 serviceIntent.prepareToLeaveProcess(mContext);
9157 return mService.bindDeviceAdminServiceAsUser(admin,
9158 mContext.getIApplicationThread(), mContext.getActivityToken(), serviceIntent,
9159 sd, flags, targetUser.getIdentifier());
9160 } catch (RemoteException re) {
9161 throw re.rethrowFromSystemServer();
9162 }
9163 }
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01009164
9165 /**
Esteban Talaverafc291bc2016-11-21 13:52:03 +00009166 * Returns the list of target users that the calling device or profile owner can use when
9167 * calling {@link #bindDeviceAdminServiceAsUser}.
9168 * <p>
Esteban Talavera2f897912017-01-26 10:30:48 +00009169 * A device owner can bind to a service from a profile owner and vice versa, provided that:
Esteban Talaverafc291bc2016-11-21 13:52:03 +00009170 * <ul>
9171 * <li>Both belong to the same package name.
Esteban Talavera2f897912017-01-26 10:30:48 +00009172 * <li>Both users are affiliated. See {@link #setAffiliationIds}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00009173 * </ul>
9174 */
9175 public @NonNull List<UserHandle> getBindDeviceAdminTargetUsers(@NonNull ComponentName admin) {
9176 throwIfParentInstance("getBindDeviceAdminTargetUsers");
9177 try {
9178 return mService.getBindDeviceAdminTargetUsers(admin);
9179 } catch (RemoteException re) {
9180 throw re.rethrowFromSystemServer();
9181 }
9182 }
9183
9184 /**
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01009185 * Called by the system to get the time at which the device owner last retrieved security
9186 * logging entries.
9187 *
9188 * @return the time at which the device owner most recently retrieved security logging entries,
9189 * in milliseconds since epoch; -1 if security logging entries were never retrieved.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01009190 * @throws SecurityException if the caller is not the device owner, does not hold the
9191 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01009192 *
9193 * @hide
9194 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01009195 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01009196 public long getLastSecurityLogRetrievalTime() {
9197 try {
9198 return mService.getLastSecurityLogRetrievalTime();
9199 } catch (RemoteException re) {
9200 throw re.rethrowFromSystemServer();
9201 }
9202 }
9203
9204 /**
9205 * Called by the system to get the time at which the device owner last requested a bug report.
9206 *
9207 * @return the time at which the device owner most recently requested a bug report, in
9208 * milliseconds since epoch; -1 if a bug report was never requested.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01009209 * @throws SecurityException if the caller is not the device owner, does not hold the
9210 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01009211 *
9212 * @hide
9213 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01009214 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01009215 public long getLastBugReportRequestTime() {
9216 try {
9217 return mService.getLastBugReportRequestTime();
9218 } catch (RemoteException re) {
9219 throw re.rethrowFromSystemServer();
9220 }
9221 }
9222
9223 /**
9224 * Called by the system to get the time at which the device owner last retrieved network logging
9225 * events.
9226 *
9227 * @return the time at which the device owner most recently retrieved network logging events, in
9228 * milliseconds since epoch; -1 if network logging events were never retrieved.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01009229 * @throws SecurityException if the caller is not the device owner, does not hold the
9230 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01009231 *
9232 * @hide
9233 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01009234 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01009235 public long getLastNetworkLogRetrievalTime() {
9236 try {
9237 return mService.getLastNetworkLogRetrievalTime();
9238 } catch (RemoteException re) {
9239 throw re.rethrowFromSystemServer();
9240 }
9241 }
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01009242
9243 /**
Bartosz Fabianowski172f7802017-03-06 12:07:57 +01009244 * Called by the system to find out whether the current user's IME was set by the device/profile
9245 * owner or the user.
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01009246 *
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01009247 * @return {@code true} if the user's IME was set by the device or profile owner, {@code false}
9248 * otherwise.
Bartosz Fabianowski172f7802017-03-06 12:07:57 +01009249 * @throws SecurityException if the caller is not the device owner/profile owner.
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01009250 *
9251 * @hide
9252 */
9253 @TestApi
Bartosz Fabianowski172f7802017-03-06 12:07:57 +01009254 public boolean isCurrentInputMethodSetByOwner() {
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01009255 try {
Bartosz Fabianowski172f7802017-03-06 12:07:57 +01009256 return mService.isCurrentInputMethodSetByOwner();
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01009257 } catch (RemoteException re) {
9258 throw re.rethrowFromSystemServer();
9259 }
9260 }
Bartosz Fabianowski05dc9f72017-02-22 23:41:14 +01009261
Bartosz Fabianowski05dc9f72017-02-22 23:41:14 +01009262 /**
9263 * Called by the system to get a list of CA certificates that were installed by the device or
9264 * profile owner.
9265 *
Bartosz Fabianowski172f7802017-03-06 12:07:57 +01009266 * <p> The caller must be the target user's device owner/profile Owner or hold the
Bartosz Fabianowski05dc9f72017-02-22 23:41:14 +01009267 * {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} permission.
9268 *
9269 * @param user The user for whom to retrieve information.
9270 * @return list of aliases identifying CA certificates installed by the device or profile owner
9271 * @throws SecurityException if the caller does not have permission to retrieve information
9272 * about the given user's CA certificates.
9273 *
9274 * @hide
9275 */
9276 @TestApi
9277 public List<String> getOwnerInstalledCaCerts(@NonNull UserHandle user) {
9278 try {
9279 return mService.getOwnerInstalledCaCerts(user).getList();
9280 } catch (RemoteException re) {
9281 throw re.rethrowFromSystemServer();
9282 }
9283 }
Benjamin Franza77e3572017-06-23 12:01:44 +01009284
9285 /**
9286 * Called by the device owner or profile owner to clear application user data of a given
9287 * package. The behaviour of this is equivalent to the target application calling
9288 * {@link android.app.ActivityManager#clearApplicationUserData()}.
9289 *
9290 * <p><strong>Note:</strong> an application can store data outside of its application data, e.g.
9291 * external storage or user dictionary. This data will not be wiped by calling this API.
9292 *
9293 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
9294 * @param packageName The name of the package which will have its user data wiped.
Jeff Sharkey8439ac02017-12-12 17:26:23 -07009295 * @param executor The executor through which the listener should be invoked.
Alex Chau4a4285b2018-01-12 13:35:06 +00009296 * @param listener A callback object that will inform the caller when the clearing is done.
Benjamin Franza77e3572017-06-23 12:01:44 +01009297 * @throws SecurityException if the caller is not the device owner/profile owner.
Benjamin Franza77e3572017-06-23 12:01:44 +01009298 */
Alex Chau1033e382018-01-25 15:53:39 +00009299 public void clearApplicationUserData(@NonNull ComponentName admin,
Alex Chau4a4285b2018-01-12 13:35:06 +00009300 @NonNull String packageName, @NonNull @CallbackExecutor Executor executor,
9301 @NonNull OnClearApplicationUserDataListener listener) {
Benjamin Franza77e3572017-06-23 12:01:44 +01009302 throwIfParentInstance("clearAppData");
Jeff Sharkey8439ac02017-12-12 17:26:23 -07009303 Preconditions.checkNotNull(executor);
Alex Chau1033e382018-01-25 15:53:39 +00009304 Preconditions.checkNotNull(listener);
Benjamin Franza77e3572017-06-23 12:01:44 +01009305 try {
Alex Chau1033e382018-01-25 15:53:39 +00009306 mService.clearApplicationUserData(admin, packageName,
Benjamin Franza77e3572017-06-23 12:01:44 +01009307 new IPackageDataObserver.Stub() {
9308 public void onRemoveCompleted(String pkg, boolean succeeded) {
Jeff Sharkey8439ac02017-12-12 17:26:23 -07009309 executor.execute(() ->
Benjamin Franza77e3572017-06-23 12:01:44 +01009310 listener.onApplicationUserDataCleared(pkg, succeeded));
9311 }
9312 });
9313 } catch (RemoteException re) {
9314 throw re.rethrowFromSystemServer();
9315 }
9316 }
9317
9318 /**
Alex Chaud7958272017-12-08 11:30:52 +00009319 * Called by a device owner to specify whether logout is enabled for all secondary users. The
9320 * system may show a logout button that stops the user and switches back to the primary user.
Alex Chau04458852017-11-27 18:21:23 +00009321 *
9322 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Alex Chaud7958272017-12-08 11:30:52 +00009323 * @param enabled whether logout should be enabled or not.
Alex Chau04458852017-11-27 18:21:23 +00009324 * @throws SecurityException if {@code admin} is not a device owner.
9325 */
Alex Chaud7958272017-12-08 11:30:52 +00009326 public void setLogoutEnabled(@NonNull ComponentName admin, boolean enabled) {
9327 throwIfParentInstance("setLogoutEnabled");
Alex Chau04458852017-11-27 18:21:23 +00009328 try {
Alex Chaud7958272017-12-08 11:30:52 +00009329 mService.setLogoutEnabled(admin, enabled);
Alex Chau04458852017-11-27 18:21:23 +00009330 } catch (RemoteException re) {
9331 throw re.rethrowFromSystemServer();
9332 }
9333 }
9334
9335 /**
Alex Chaud7958272017-12-08 11:30:52 +00009336 * Returns whether logout is enabled by a device owner.
Alex Chau04458852017-11-27 18:21:23 +00009337 *
Alex Chaud7958272017-12-08 11:30:52 +00009338 * @return {@code true} if logout is enabled by device owner, {@code false} otherwise.
Alex Chau04458852017-11-27 18:21:23 +00009339 */
Alex Chaud7958272017-12-08 11:30:52 +00009340 public boolean isLogoutEnabled() {
9341 throwIfParentInstance("isLogoutEnabled");
Alex Chau04458852017-11-27 18:21:23 +00009342 try {
Alex Chaud7958272017-12-08 11:30:52 +00009343 return mService.isLogoutEnabled();
Alex Chau04458852017-11-27 18:21:23 +00009344 } catch (RemoteException re) {
9345 throw re.rethrowFromSystemServer();
9346 }
9347 }
9348
9349 /**
Benjamin Franza77e3572017-06-23 12:01:44 +01009350 * Callback used in {@link #clearApplicationUserData}
9351 * to indicate that the clearing of an application's user data is done.
9352 */
9353 public interface OnClearApplicationUserDataListener {
9354 /**
9355 * Method invoked when clearing the application user data has completed.
9356 *
9357 * @param packageName The name of the package which had its user data cleared.
9358 * @param succeeded Whether the clearing succeeded. Clearing fails for device administrator
9359 * apps and protected system packages.
9360 */
9361 void onApplicationUserDataCleared(String packageName, boolean succeeded);
9362 }
Alex Chaub6a9f942017-11-07 11:28:56 +08009363
9364 /**
9365 * Returns set of system apps that should be removed during provisioning.
9366 *
9367 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
9368 * @param userId ID of the user to be provisioned.
9369 * @param provisioningAction action indicating type of provisioning, should be one of
9370 * {@link #ACTION_PROVISION_MANAGED_DEVICE}, {@link #ACTION_PROVISION_MANAGED_PROFILE} or
9371 * {@link #ACTION_PROVISION_MANAGED_USER}.
9372 *
9373 * @hide
9374 */
9375 public Set<String> getDisallowedSystemApps(ComponentName admin, int userId,
9376 String provisioningAction) {
9377 try {
9378 return new ArraySet<>(
9379 mService.getDisallowedSystemApps(admin, userId, provisioningAction));
9380 } catch (RemoteException re) {
9381 throw re.rethrowFromSystemServer();
9382 }
9383 }
arangelov08841ef2017-11-23 15:29:42 +00009384
arangelov08841ef2017-11-23 15:29:42 +00009385 /**
arangelov8bae4ea2017-12-20 20:26:46 +00009386 * Changes the current administrator to another one. All policies from the current
9387 * administrator are migrated to the new administrator. The whole operation is atomic -
9388 * the transfer is either complete or not done at all.
arangelov08841ef2017-11-23 15:29:42 +00009389 *
arangelov8bae4ea2017-12-20 20:26:46 +00009390 * <p>Depending on the current administrator (device owner, profile owner), you have the
9391 * following expected behaviour:
arangelov08841ef2017-11-23 15:29:42 +00009392 * <ul>
9393 * <li>A device owner can only be transferred to a new device owner</li>
9394 * <li>A profile owner can only be transferred to a new profile owner</li>
arangelov08841ef2017-11-23 15:29:42 +00009395 * </ul>
9396 *
arangelov91201bd2018-01-04 17:10:21 +00009397 * <p>Use the {@code bundle} parameter to pass data to the new administrator. The data
arangelov8bae4ea2017-12-20 20:26:46 +00009398 * will be received in the
arangelov91201bd2018-01-04 17:10:21 +00009399 * {@link DeviceAdminReceiver#onTransferOwnershipComplete(Context, PersistableBundle)}
9400 * callback of the new administrator.
9401 *
9402 * <p>The transfer has failed if the original administrator is still the corresponding owner
9403 * after calling this method.
arangelov8bae4ea2017-12-20 20:26:46 +00009404 *
arangelov5149d7162018-01-11 19:48:14 +00009405 * <p>The incoming target administrator must have the
arangelovc8ee2632018-02-23 16:45:53 +00009406 * <code>&lt;support-transfer-ownership /&gt;</code> tag inside the
9407 * <code>&lt;device-admin&gt;&lt;/device-admin&gt;</code> tags in the xml file referenced by
9408 * {@link DeviceAdminReceiver#DEVICE_ADMIN_META_DATA}. Otherwise an
9409 * {@link IllegalArgumentException} will be thrown.
arangelov5149d7162018-01-11 19:48:14 +00009410 *
arangelov8bae4ea2017-12-20 20:26:46 +00009411 * @param admin which {@link DeviceAdminReceiver} this request is associated with
9412 * @param target which {@link DeviceAdminReceiver} we want the new administrator to be
9413 * @param bundle data to be sent to the new administrator
9414 * @throws SecurityException if {@code admin} is not a device owner nor a profile owner
arangelov91201bd2018-01-04 17:10:21 +00009415 * @throws IllegalArgumentException if {@code admin} or {@code target} is {@code null}, they
9416 * are components in the same package or {@code target} is not an active admin
arangelov08841ef2017-11-23 15:29:42 +00009417 */
arangelov8bae4ea2017-12-20 20:26:46 +00009418 public void transferOwnership(@NonNull ComponentName admin, @NonNull ComponentName target,
arangelov91201bd2018-01-04 17:10:21 +00009419 @Nullable PersistableBundle bundle) {
arangelov8bae4ea2017-12-20 20:26:46 +00009420 throwIfParentInstance("transferOwnership");
arangelov08841ef2017-11-23 15:29:42 +00009421 try {
arangelov8bae4ea2017-12-20 20:26:46 +00009422 mService.transferOwnership(admin, target, bundle);
arangelov08841ef2017-11-23 15:29:42 +00009423 } catch (RemoteException re) {
9424 throw re.rethrowFromSystemServer();
9425 }
9426 }
Alex Chau93ae42b2018-01-11 15:10:12 +00009427
9428 /**
9429 * Called by a device owner to specify the user session start message. This may be displayed
9430 * during a user switch.
9431 * <p>
9432 * The message should be limited to a short statement or it may be truncated.
9433 * <p>
9434 * If the message needs to be localized, it is the responsibility of the
9435 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
9436 * and set a new version of this message accordingly.
9437 *
9438 * @param admin which {@link DeviceAdminReceiver} this request is associated with.
9439 * @param startUserSessionMessage message for starting user session, or {@code null} to use
9440 * system default message.
9441 * @throws SecurityException if {@code admin} is not a device owner.
9442 */
9443 public void setStartUserSessionMessage(
9444 @NonNull ComponentName admin, @Nullable CharSequence startUserSessionMessage) {
9445 throwIfParentInstance("setStartUserSessionMessage");
9446 try {
9447 mService.setStartUserSessionMessage(admin, startUserSessionMessage);
9448 } catch (RemoteException re) {
9449 throw re.rethrowFromSystemServer();
9450 }
9451 }
9452
9453 /**
9454 * Called by a device owner to specify the user session end message. This may be displayed
9455 * during a user switch.
9456 * <p>
9457 * The message should be limited to a short statement or it may be truncated.
9458 * <p>
9459 * If the message needs to be localized, it is the responsibility of the
9460 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
9461 * and set a new version of this message accordingly.
9462 *
9463 * @param admin which {@link DeviceAdminReceiver} this request is associated with.
9464 * @param endUserSessionMessage message for ending user session, or {@code null} to use system
9465 * default message.
9466 * @throws SecurityException if {@code admin} is not a device owner.
9467 */
9468 public void setEndUserSessionMessage(
9469 @NonNull ComponentName admin, @Nullable CharSequence endUserSessionMessage) {
9470 throwIfParentInstance("setEndUserSessionMessage");
9471 try {
9472 mService.setEndUserSessionMessage(admin, endUserSessionMessage);
9473 } catch (RemoteException re) {
9474 throw re.rethrowFromSystemServer();
9475 }
9476 }
9477
9478 /**
9479 * Returns the user session start message.
9480 *
9481 * @param admin which {@link DeviceAdminReceiver} this request is associated with.
9482 * @throws SecurityException if {@code admin} is not a device owner.
9483 */
9484 public CharSequence getStartUserSessionMessage(@NonNull ComponentName admin) {
9485 throwIfParentInstance("getStartUserSessionMessage");
9486 try {
9487 return mService.getStartUserSessionMessage(admin);
9488 } catch (RemoteException re) {
9489 throw re.rethrowFromSystemServer();
9490 }
9491 }
9492
9493 /**
9494 * Returns the user session end message.
9495 *
9496 * @param admin which {@link DeviceAdminReceiver} this request is associated with.
9497 * @throws SecurityException if {@code admin} is not a device owner.
9498 */
9499 public CharSequence getEndUserSessionMessage(@NonNull ComponentName admin) {
9500 throwIfParentInstance("getEndUserSessionMessage");
9501 try {
9502 return mService.getEndUserSessionMessage(admin);
9503 } catch (RemoteException re) {
9504 throw re.rethrowFromSystemServer();
9505 }
9506 }
Vladislav Kuzkokov792d58f2018-01-15 15:04:05 +01009507
9508 /**
yuemingwe3d9c092018-01-11 12:11:44 +00009509 * Called by device owner to add an override APN.
9510 *
yuemingwedfd36a2018-02-26 14:25:35 +00009511 * <p>This method may returns {@code -1} if {@code apnSetting} conflicts with an existing
9512 * override APN. Update the existing conflicted APN with
9513 * {@link #updateOverrideApn(ComponentName, int, ApnSetting)} instead of adding a new entry.
yuemingw6586f052018-03-21 16:32:09 +00009514 * <p>Two override APNs are considered to conflict when all the following APIs return
9515 * the same values on both override APNs:
9516 * <ul>
9517 * <li>{@link ApnSetting#getOperatorNumeric()}</li>
9518 * <li>{@link ApnSetting#getApnName()}</li>
yuemingw9bf808c2018-04-09 16:41:54 +01009519 * <li>{@link ApnSetting#getProxyAddressAsString()}</li>
yuemingw6586f052018-03-21 16:32:09 +00009520 * <li>{@link ApnSetting#getProxyPort()}</li>
yuemingw9bf808c2018-04-09 16:41:54 +01009521 * <li>{@link ApnSetting#getMmsProxyAddressAsString()}</li>
yuemingw6586f052018-03-21 16:32:09 +00009522 * <li>{@link ApnSetting#getMmsProxyPort()}</li>
9523 * <li>{@link ApnSetting#getMmsc()}</li>
9524 * <li>{@link ApnSetting#isEnabled()}</li>
9525 * <li>{@link ApnSetting#getMvnoType()}</li>
9526 * <li>{@link ApnSetting#getProtocol()}</li>
9527 * <li>{@link ApnSetting#getRoamingProtocol()}</li>
9528 * </ul>
yuemingwedfd36a2018-02-26 14:25:35 +00009529 *
yuemingwe3d9c092018-01-11 12:11:44 +00009530 * @param admin which {@link DeviceAdminReceiver} this request is associated with
9531 * @param apnSetting the override APN to insert
9532 * @return The {@code id} of inserted override APN. Or {@code -1} when failed to insert into
9533 * the database.
9534 * @throws SecurityException if {@code admin} is not a device owner.
9535 *
9536 * @see #setOverrideApnsEnabled(ComponentName, boolean)
9537 */
9538 public int addOverrideApn(@NonNull ComponentName admin, @NonNull ApnSetting apnSetting) {
9539 throwIfParentInstance("addOverrideApn");
9540 if (mService != null) {
9541 try {
9542 return mService.addOverrideApn(admin, apnSetting);
9543 } catch (RemoteException e) {
9544 throw e.rethrowFromSystemServer();
9545 }
9546 }
9547 return -1;
9548 }
9549
9550 /**
9551 * Called by device owner to update an override APN.
9552 *
yuemingwedfd36a2018-02-26 14:25:35 +00009553 * <p>This method may returns {@code false} if there is no override APN with the given
9554 * {@code apnId}.
9555 * <p>This method may also returns {@code false} if {@code apnSetting} conflicts with an
9556 * existing override APN. Update the existing conflicted APN instead.
yuemingw6586f052018-03-21 16:32:09 +00009557 * <p>See {@link #addOverrideApn} for the definition of conflict.
yuemingwedfd36a2018-02-26 14:25:35 +00009558 *
yuemingwe3d9c092018-01-11 12:11:44 +00009559 * @param admin which {@link DeviceAdminReceiver} this request is associated with
9560 * @param apnId the {@code id} of the override APN to update
9561 * @param apnSetting the override APN to update
9562 * @return {@code true} if the required override APN is successfully updated,
9563 * {@code false} otherwise.
9564 * @throws SecurityException if {@code admin} is not a device owner.
9565 *
9566 * @see #setOverrideApnsEnabled(ComponentName, boolean)
9567 */
9568 public boolean updateOverrideApn(@NonNull ComponentName admin, int apnId,
9569 @NonNull ApnSetting apnSetting) {
9570 throwIfParentInstance("updateOverrideApn");
9571 if (mService != null) {
9572 try {
9573 return mService.updateOverrideApn(admin, apnId, apnSetting);
9574 } catch (RemoteException e) {
9575 throw e.rethrowFromSystemServer();
9576 }
9577 }
9578 return false;
9579 }
9580
9581 /**
9582 * Called by device owner to remove an override APN.
9583 *
yuemingwedfd36a2018-02-26 14:25:35 +00009584 * <p>This method may returns {@code false} if there is no override APN with the given
9585 * {@code apnId}.
9586 *
yuemingwe3d9c092018-01-11 12:11:44 +00009587 * @param admin which {@link DeviceAdminReceiver} this request is associated with
9588 * @param apnId the {@code id} of the override APN to remove
9589 * @return {@code true} if the required override APN is successfully removed, {@code false}
9590 * otherwise.
9591 * @throws SecurityException if {@code admin} is not a device owner.
9592 *
9593 * @see #setOverrideApnsEnabled(ComponentName, boolean)
9594 */
9595 public boolean removeOverrideApn(@NonNull ComponentName admin, int apnId) {
9596 throwIfParentInstance("removeOverrideApn");
9597 if (mService != null) {
9598 try {
9599 return mService.removeOverrideApn(admin, apnId);
9600 } catch (RemoteException e) {
9601 throw e.rethrowFromSystemServer();
9602 }
9603 }
9604 return false;
9605 }
9606
9607 /**
9608 * Called by device owner to get all override APNs inserted by device owner.
9609 *
9610 * @param admin which {@link DeviceAdminReceiver} this request is associated with
9611 * @return A list of override APNs inserted by device owner.
9612 * @throws SecurityException if {@code admin} is not a device owner.
9613 *
9614 * @see #setOverrideApnsEnabled(ComponentName, boolean)
9615 */
9616 public List<ApnSetting> getOverrideApns(@NonNull ComponentName admin) {
9617 throwIfParentInstance("getOverrideApns");
9618 if (mService != null) {
9619 try {
9620 return mService.getOverrideApns(admin);
9621 } catch (RemoteException e) {
9622 throw e.rethrowFromSystemServer();
9623 }
9624 }
9625 return Collections.emptyList();
9626 }
9627
9628 /**
9629 * Called by device owner to set if override APNs should be enabled.
9630 * <p> Override APNs are separated from other APNs on the device, and can only be inserted or
9631 * modified by the device owner. When enabled, only override APNs are in use, any other APNs
9632 * are ignored.
9633 *
9634 * @param admin which {@link DeviceAdminReceiver} this request is associated with
9635 * @param enabled {@code true} if override APNs should be enabled, {@code false} otherwise
9636 * @throws SecurityException if {@code admin} is not a device owner.
9637 */
9638 public void setOverrideApnsEnabled(@NonNull ComponentName admin, boolean enabled) {
9639 throwIfParentInstance("setOverrideApnEnabled");
9640 if (mService != null) {
9641 try {
9642 mService.setOverrideApnsEnabled(admin, enabled);
9643 } catch (RemoteException e) {
9644 throw e.rethrowFromSystemServer();
9645 }
9646 }
9647 }
9648
9649 /**
9650 * Called by device owner to check if override APNs are currently enabled.
9651 *
9652 * @param admin which {@link DeviceAdminReceiver} this request is associated with
9653 * @return {@code true} if override APNs are currently enabled, {@code false} otherwise.
9654 * @throws SecurityException if {@code admin} is not a device owner.
9655 *
9656 * @see #setOverrideApnsEnabled(ComponentName, boolean)
9657 */
9658 public boolean isOverrideApnEnabled(@NonNull ComponentName admin) {
9659 throwIfParentInstance("isOverrideApnEnabled");
9660 if (mService != null) {
9661 try {
9662 return mService.isOverrideApnEnabled(admin);
9663 } catch (RemoteException e) {
9664 throw e.rethrowFromSystemServer();
9665 }
9666 }
9667 return false;
9668 }
arangelov91201bd2018-01-04 17:10:21 +00009669
9670 /**
9671 * Returns the data passed from the current administrator to the new administrator during an
9672 * ownership transfer. This is the same {@code bundle} passed in
arangelovdc63bd72018-02-22 12:36:23 +00009673 * {@link #transferOwnership(ComponentName, ComponentName, PersistableBundle)}. The bundle is
9674 * persisted until the profile owner or device owner is removed.
9675 *
9676 * <p>This is the same <code>bundle</code> received in the
9677 * {@link DeviceAdminReceiver#onTransferOwnershipComplete(Context, PersistableBundle)}.
9678 * Use this method to retrieve it after the transfer as long as the new administrator is the
9679 * active device or profile owner.
arangelov91201bd2018-01-04 17:10:21 +00009680 *
9681 * <p>Returns <code>null</code> if no ownership transfer was started for the calling user.
9682 *
9683 * @see #transferOwnership
9684 * @see DeviceAdminReceiver#onTransferOwnershipComplete(Context, PersistableBundle)
arangelovdc63bd72018-02-22 12:36:23 +00009685 * @throws SecurityException if the caller is not a device or profile owner.
arangelov91201bd2018-01-04 17:10:21 +00009686 */
9687 @Nullable
9688 public PersistableBundle getTransferOwnershipBundle() {
9689 throwIfParentInstance("getTransferOwnershipBundle");
9690 try {
9691 return mService.getTransferOwnershipBundle();
9692 } catch (RemoteException re) {
9693 throw re.rethrowFromSystemServer();
9694 }
9695 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08009696}