blob: 8f76032b4c625833abac80fda2ce416b8c3f9de1 [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 Sharkeyd86b8fe2017-06-02 17:36:26 -060024import android.annotation.RequiresPermission;
Dianne Hackbornd6847842010-01-12 18:14:19 -080025import android.annotation.SdkConstant;
26import android.annotation.SdkConstant.SdkConstantType;
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060027import android.annotation.SuppressLint;
Justin Moreyb5deda72014-07-24 10:53:40 -050028import android.annotation.SystemApi;
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060029import android.annotation.SystemService;
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +010030import android.annotation.TestApi;
Nicolas Prevot8f7698a2016-02-11 16:05:33 +000031import android.annotation.UserIdInt;
Fyodor Kupolov4e9af062016-07-18 16:59:11 -070032import android.annotation.WorkerThread;
Jason Monkd7b86212014-06-16 13:15:38 -040033import android.app.Activity;
Tony Mak46aabe52016-11-14 12:53:06 +000034import android.app.IServiceConnection;
Rubin Xuaab7a412016-12-30 21:13:29 +000035import android.app.KeyguardManager;
Michal Karpinski6235a942016-03-15 12:07:23 +000036import android.app.admin.SecurityLog.SecurityEvent;
Dianne Hackbornd6847842010-01-12 18:14:19 -080037import android.content.ComponentName;
38import android.content.Context;
Adam Connors010cfd42014-04-16 12:48:13 +010039import android.content.Intent;
Sander Alewijnsef475ca32014-02-17 15:13:58 +000040import android.content.IntentFilter;
Tony Mak46aabe52016-11-14 12:53:06 +000041import android.content.ServiceConnection;
Victor Chang98607132017-01-27 11:51:56 +000042import android.content.pm.ApplicationInfo;
Benjamin Franza77e3572017-06-23 12:01:44 +010043import android.content.pm.IPackageDataObserver;
Dianne Hackbornd6847842010-01-12 18:14:19 -080044import android.content.pm.PackageManager;
Victor Changcd14c0a2016-03-16 19:10:15 +000045import android.content.pm.PackageManager.NameNotFoundException;
Rubin Xuc3cd05f2016-01-11 12:11:35 +000046import android.content.pm.ParceledListSlice;
Sudheer Shanka978fc0d2016-01-28 13:51:10 +000047import android.content.pm.UserInfo;
Julia Reynoldsfca04ca2015-02-17 13:39:12 -050048import android.graphics.Bitmap;
Jason Monk03bc9912014-05-13 09:44:57 -040049import android.net.ProxyInfo;
Nicolas Prevot8b7991c2015-11-12 17:40:12 +000050import android.net.Uri;
Robin Lee66e5d962014-04-09 16:44:21 +010051import android.os.Bundle;
Victor Changc10f6692016-12-09 15:24:00 +000052import android.os.Parcelable;
Jim Millere303bf42014-08-26 17:12:29 -070053import android.os.PersistableBundle;
Adam Connors776c5552014-01-09 10:42:56 +000054import android.os.Process;
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080055import android.os.RemoteCallback;
Dianne Hackbornd6847842010-01-12 18:14:19 -080056import android.os.RemoteException;
Amith Yamasani599dd7c2012-09-14 23:20:08 -070057import android.os.UserHandle;
Julia Reynolds1e958392014-05-16 14:25:21 -040058import android.os.UserManager;
Ricky Wai494b95d2015-11-20 16:07:15 +000059import android.provider.ContactsContract.Directory;
Eran Messeri852c8f12017-11-15 05:55:52 +000060import android.security.AttestedKeyPair;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010061import android.security.Credentials;
Eran Messeri852c8f12017-11-15 05:55:52 +000062import android.security.KeyChain;
63import android.security.KeyChainException;
Eran Messeria1730642017-12-11 17:48:47 +000064import android.security.keymaster.KeymasterCertificateChain;
65import android.security.keystore.AttestationUtils;
66import android.security.keystore.KeyAttestationException;
Eran Messeri852c8f12017-11-15 05:55:52 +000067import android.security.keystore.KeyGenParameterSpec;
68import android.security.keystore.ParcelableKeyGenParameterSpec;
Amith Yamasanid1d7c022014-08-19 17:03:41 -070069import android.service.restrictions.RestrictionsReceiver;
Mahaver Chopra1216ae52016-03-11 15:39:48 +000070import android.telephony.TelephonyManager;
yuemingwe3d9c092018-01-11 12:11:44 +000071import android.telephony.data.ApnSetting;
Tony Mak31657432017-04-25 09:29:55 +010072import android.util.ArraySet;
Dianne Hackbornd6847842010-01-12 18:14:19 -080073import android.util.Log;
74
yuemingwf7f67dc2017-09-08 14:23:53 +010075import com.android.internal.R;
Makoto Onukicc4bbeb2015-09-17 10:28:24 -070076import com.android.internal.annotations.VisibleForTesting;
yuemingwf7f67dc2017-09-08 14:23:53 +010077import com.android.internal.util.Preconditions;
Maggie Benthallda51e682013-08-08 22:35:44 -040078import com.android.org.conscrypt.TrustedCertificateStore;
79
80import java.io.ByteArrayInputStream;
Dianne Hackbornd6847842010-01-12 18:14:19 -080081import java.io.IOException;
Alan Treadwayafad8782016-01-19 15:15:08 +000082import java.lang.annotation.Retention;
83import java.lang.annotation.RetentionPolicy;
Oscar Montemayor69238c62010-08-03 10:51:06 -070084import java.net.InetSocketAddress;
85import java.net.Proxy;
Robin Lee0d5ccb72014-09-12 17:41:44 +010086import java.security.KeyFactory;
Eran Messeri852c8f12017-11-15 05:55:52 +000087import java.security.KeyPair;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000088import java.security.NoSuchAlgorithmException;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010089import java.security.PrivateKey;
90import java.security.cert.Certificate;
Maggie Benthallda51e682013-08-08 22:35:44 -040091import java.security.cert.CertificateException;
92import java.security.cert.CertificateFactory;
93import java.security.cert.X509Certificate;
Robin Lee0d5ccb72014-09-12 17:41:44 +010094import java.security.spec.InvalidKeySpecException;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000095import java.security.spec.PKCS8EncodedKeySpec;
Jim Miller604e7552014-07-18 19:00:02 -070096import java.util.ArrayList;
Rubin Xub4365912016-03-23 12:13:22 +000097import java.util.Arrays;
Svetoslav976e8bd2014-07-16 15:12:03 -070098import java.util.Collections;
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -080099import java.util.List;
Tony Mak31657432017-04-25 09:29:55 +0100100import java.util.Set;
Jeff Sharkey8439ac02017-12-12 17:26:23 -0700101import java.util.concurrent.Executor;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800102
103/**
Alexandra Gherghina541afcd2014-11-07 11:18:12 +0000104 * Public interface for managing policies enforced on a device. Most clients of this class must be
Suprabh Shukla34d92ef2016-03-14 13:49:37 -0700105 * registered with the system as a <a href="{@docRoot}guide/topics/admin/device-admin.html">device
106 * administrator</a>. Additionally, a device administrator may be registered as either a profile or
107 * device owner. A given method is accessible to all device administrators unless the documentation
108 * for that method specifies that it is restricted to either device or profile owners. Any
109 * application calling an api may only pass as an argument a device administrator component it
110 * owns. Otherwise, a {@link SecurityException} will be thrown.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -0800111 * <div class="special reference">
112 * <h3>Developer Guides</h3>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -0700113 * <p>
114 * For more information about managing policies for device administration, read the <a href=
115 * "{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a> developer
116 * guide. </div>
Dianne Hackbornd6847842010-01-12 18:14:19 -0800117 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -0600118@SystemService(Context.DEVICE_POLICY_SERVICE)
Dianne Hackbornd6847842010-01-12 18:14:19 -0800119public class DevicePolicyManager {
120 private static String TAG = "DevicePolicyManager";
Dianne Hackbornd6847842010-01-12 18:14:19 -0800121
122 private final Context mContext;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800123 private final IDevicePolicyManager mService;
Esteban Talavera62399912016-01-11 15:37:55 +0000124 private final boolean mParentInstance;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700125
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600126 /** @hide */
127 public DevicePolicyManager(Context context, IDevicePolicyManager service) {
128 this(context, service, false);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800129 }
130
Dianne Hackborn87bba1e2010-02-26 17:25:54 -0800131 /** @hide */
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700132 @VisibleForTesting
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600133 protected DevicePolicyManager(Context context, IDevicePolicyManager service,
134 boolean parentInstance) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700135 mContext = context;
136 mService = service;
Esteban Talavera62399912016-01-11 15:37:55 +0000137 mParentInstance = parentInstance;
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700138 }
139
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700140 /** @hide test will override it. */
141 @VisibleForTesting
142 protected int myUserId() {
143 return UserHandle.myUserId();
144 }
145
Dianne Hackbornd6847842010-01-12 18:14:19 -0800146 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +0000147 * Activity action: Starts the provisioning flow which sets up a managed profile.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000148 *
Jessica Hummel9da60392014-05-21 12:32:57 +0100149 * <p>A managed profile allows data separation for example for the usage of a
150 * device as a personal and corporate device. The user which provisioning is started from and
151 * the managed profile share a launcher.
152 *
Andrew Solovay27f53372015-03-02 16:37:59 -0800153 * <p>This intent will typically be sent by a mobile device management application (MDM).
154 * Provisioning adds a managed profile and sets the MDM as the profile owner who has full
155 * control over the profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100156 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000157 * <p>It is possible to check if provisioning is allowed or not by querying the method
158 * {@link #isProvisioningAllowed(String)}.
159 *
160 * <p>In version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this intent must contain the
Nicolas Prevot18440252015-03-09 14:07:17 +0000161 * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700162 * As of {@link android.os.Build.VERSION_CODES#M}, it should contain the extra
Nicolas Prevot18440252015-03-09 14:07:17 +0000163 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only
164 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000165 *
Benjamin Franzea956242016-03-21 15:45:56 +0000166 * <p>The intent may also contain the following extras:
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000167 * <ul>
Benjamin Franzea956242016-03-21 15:45:56 +0000168 * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, optional </li>
169 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional, supported from
170 * {@link android.os.Build.VERSION_CODES#N}</li>
171 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
172 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
173 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Victor Chang51d84f92016-11-16 12:22:56 +0000174 * <li>{@link #EXTRA_PROVISIONING_SKIP_USER_CONSENT}, optional</li>
Victor Chang89ee2792016-11-23 12:10:55 +0000175 * <li>{@link #EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION}, optional</li>
Victor Changc10f6692016-12-09 15:24:00 +0000176 * <li>{@link #EXTRA_PROVISIONING_DISCLAIMERS}, optional</li>
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000177 * </ul>
Jessica Hummelf72078b2014-03-06 16:13:12 +0000178 *
Benjamin Franzea956242016-03-21 15:45:56 +0000179 * <p>When managed provisioning has completed, broadcasts are sent to the application specified
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000180 * in the provisioning intent. The
181 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the
182 * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in
183 * the primary profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100184 *
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000185 * <p>From version {@link android.os.Build.VERSION_CODES#O}, when managed provisioning has
186 * completed, along with the above broadcast, activity intent
Esteban Talavera4047bae2017-06-28 11:03:09 +0100187 * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the profile owner.
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000188 *
Benjamin Franzea956242016-03-21 15:45:56 +0000189 * <p>If provisioning fails, the managedProfile is removed so the device returns to its
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100190 * previous state.
Alan Treadway4582f812015-07-28 11:49:35 +0100191 *
192 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
193 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
194 * the provisioning flow was successful, although this doesn't guarantee the full flow will
195 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
196 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000197 */
198 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
199 public static final String ACTION_PROVISION_MANAGED_PROFILE
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100200 = "android.app.action.PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000201
202 /**
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000203 * Activity action: Starts the provisioning flow which sets up a managed user.
204 *
205 * <p>This intent will typically be sent by a mobile device management application (MDM).
Makoto Onuki32b30572015-12-11 14:29:51 -0800206 * Provisioning configures the user as managed user and sets the MDM as the profile
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000207 * owner who has full control over the user. Provisioning can only happen before user setup has
208 * been completed. Use {@link #isProvisioningAllowed(String)} to check if provisioning is
209 * allowed.
210 *
Benjamin Franzea956242016-03-21 15:45:56 +0000211 * <p>The intent contains the following extras:
212 * <ul>
213 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
214 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
215 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
216 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
217 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
218 * </ul>
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000219 *
Benjamin Franzea956242016-03-21 15:45:56 +0000220 * <p>If provisioning fails, the device returns to its previous state.
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000221 *
222 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
223 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
224 * the provisioning flow was successful, although this doesn't guarantee the full flow will
225 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
226 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Benjamin Franzea956242016-03-21 15:45:56 +0000227 *
228 * @hide
Mahaver Chopra5e732562015-11-05 11:55:12 +0000229 */
230 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
231 public static final String ACTION_PROVISION_MANAGED_USER
232 = "android.app.action.PROVISION_MANAGED_USER";
233
234 /**
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100235 * Activity action: Starts the provisioning flow which sets up a managed device.
236 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
237 *
238 * <p> During device owner provisioning a device admin app is set as the owner of the device.
239 * A device owner has full control over the device. The device owner can not be modified by the
240 * user.
241 *
242 * <p> A typical use case would be a device that is owned by a company, but used by either an
243 * employee or client.
244 *
245 * <p> An intent with this action can be sent only on an unprovisioned device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000246 * It is possible to check if provisioning is allowed or not by querying the method
247 * {@link #isProvisioningAllowed(String)}.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100248 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000249 * <p>The intent contains the following extras:
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100250 * <ul>
251 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
252 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
253 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
Rubin Xua4f9dc12015-06-12 13:27:59 +0100254 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000255 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000256 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Victor Changc10f6692016-12-09 15:24:00 +0000257 * <li>{@link #EXTRA_PROVISIONING_DISCLAIMERS}, optional</li>
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100258 * </ul>
259 *
Benjamin Franzea956242016-03-21 15:45:56 +0000260 * <p>When device owner provisioning has completed, an intent of the type
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100261 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
262 * device owner.
263 *
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000264 * <p>From version {@link android.os.Build.VERSION_CODES#O}, when device owner provisioning has
265 * completed, along with the above broadcast, activity intent
266 * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the device owner.
267 *
Benjamin Franzea956242016-03-21 15:45:56 +0000268 * <p>If provisioning fails, the device is factory reset.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100269 *
Alan Treadway4582f812015-07-28 11:49:35 +0100270 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
271 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
272 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
273 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100274 */
275 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
276 public static final String ACTION_PROVISION_MANAGED_DEVICE
277 = "android.app.action.PROVISION_MANAGED_DEVICE";
278
279 /**
Victor Chang18800092017-04-11 19:41:43 +0100280 * Activity action: launch when user provisioning completed, i.e.
281 * {@link #getUserProvisioningState()} returns one of the complete state.
282 *
283 * <p> Please note that the API behavior is not necessarily consistent across various releases,
284 * and devices, as it's contract between SetupWizard and ManagedProvisioning. The default
285 * implementation is that ManagedProvisioning launches SetupWizard in NFC provisioning only.
286 *
287 * <p> The activity must be protected by permission
288 * {@link android.Manifest.permission#BIND_DEVICE_ADMIN}, and the process must hold
289 * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE} to be launched.
290 * Only one {@link ComponentName} in the entire system should be enabled, and the rest of the
291 * components are not started by this intent.
292 * @hide
293 */
294 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
Jeff Sharkey90396362017-06-12 16:26:53 -0600295 @SystemApi
Victor Chang18800092017-04-11 19:41:43 +0100296 public static final String ACTION_STATE_USER_SETUP_COMPLETE =
297 "android.app.action.STATE_USER_SETUP_COMPLETE";
298
299 /**
Alan Treadway46dd4492015-11-09 13:57:19 +0000300 * Activity action: Starts the provisioning flow which sets up a managed device.
Steven Ng980a1b62016-02-02 17:43:18 +0000301 *
302 * <p>During device owner provisioning, a device admin app is downloaded and set as the owner of
303 * the device. A device owner has full control over the device. The device owner can not be
304 * modified by the user and the only way of resetting the device is via factory reset.
305 *
306 * <p>A typical use case would be a device that is owned by a company, but used by either an
307 * employee or client.
308 *
309 * <p>The provisioning message should be sent to an unprovisioned device.
310 *
311 * <p>Unlike {@link #ACTION_PROVISION_MANAGED_DEVICE}, the provisioning message can only be sent
312 * by a privileged app with the permission
313 * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE}.
314 *
315 * <p>The provisioning intent contains the following properties:
316 * <ul>
317 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
318 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
319 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
320 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Victor Chang38cfd9c2017-01-04 17:41:11 +0000321 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL}, optional</li>
322 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI}, optional</li>
Steven Ng980a1b62016-02-02 17:43:18 +0000323 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
324 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
325 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
326 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
327 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
328 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
329 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
330 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
331 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
332 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
333 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
Victor Chang38cfd9c2017-01-04 17:41:11 +0000334 * <li>{@link #EXTRA_PROVISIONING_SUPPORT_URL}, optional</li>
335 * <li>{@link #EXTRA_PROVISIONING_ORGANIZATION_NAME}, optional</li>
Steven Ng980a1b62016-02-02 17:43:18 +0000336 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li></ul>
337 *
338 * @hide
339 */
340 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
341 @SystemApi
342 public static final String ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE =
343 "android.app.action.PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE";
344
345 /**
346 * Activity action: Starts the provisioning flow which sets up a managed device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000347 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
348 *
349 * <p>NOTE: This is only supported on split system user devices, and puts the device into a
350 * management state that is distinct from that reached by
351 * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system
352 * user, and only has control over device-wide policies, not individual users and their data.
353 * The primary benefit is that multiple non-system users are supported when provisioning using
354 * this form of device management.
355 *
Benjamin Franzea956242016-03-21 15:45:56 +0000356 * <p>During device owner provisioning a device admin app is set as the owner of the device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000357 * A device owner has full control over the device. The device owner can not be modified by the
358 * user.
359 *
Benjamin Franzea956242016-03-21 15:45:56 +0000360 * <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 +0000361 * employee or client.
362 *
Benjamin Franzea956242016-03-21 15:45:56 +0000363 * <p>An intent with this action can be sent only on an unprovisioned device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000364 * It is possible to check if provisioning is allowed or not by querying the method
365 * {@link #isProvisioningAllowed(String)}.
366 *
367 * <p>The intent contains the following extras:
368 * <ul>
369 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
370 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
371 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
372 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Benjamin Franzea956242016-03-21 15:45:56 +0000373 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
374 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Alan Treadway46dd4492015-11-09 13:57:19 +0000375 * </ul>
376 *
Benjamin Franzea956242016-03-21 15:45:56 +0000377 * <p>When device owner provisioning has completed, an intent of the type
Alan Treadway46dd4492015-11-09 13:57:19 +0000378 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
379 * device owner.
380 *
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000381 * <p>From version {@link android.os.Build.VERSION_CODES#O}, when device owner provisioning has
382 * completed, along with the above broadcast, activity intent
383 * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the device owner.
384 *
Benjamin Franzea956242016-03-21 15:45:56 +0000385 * <p>If provisioning fails, the device is factory reset.
Alan Treadway46dd4492015-11-09 13:57:19 +0000386 *
387 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
388 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
389 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
390 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
391 *
392 * @hide
393 */
394 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
395 public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE
396 = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE";
397
398 /**
Alan Treadwayafad8782016-01-19 15:15:08 +0000399 * Activity action: Finalizes management provisioning, should be used after user-setup
400 * has been completed and {@link #getUserProvisioningState()} returns one of:
401 * <ul>
402 * <li>{@link #STATE_USER_SETUP_INCOMPLETE}</li>
403 * <li>{@link #STATE_USER_SETUP_COMPLETE}</li>
404 * <li>{@link #STATE_USER_PROFILE_COMPLETE}</li>
405 * </ul>
406 *
407 * @hide
408 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +0000409 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +0000410 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
411 public static final String ACTION_PROVISION_FINALIZATION
412 = "android.app.action.PROVISION_FINALIZATION";
413
414 /**
Michal Karpinskiba244092016-02-25 17:28:24 +0000415 * Action: Bugreport sharing with device owner has been accepted by the user.
416 *
417 * @hide
418 */
419 public static final String ACTION_BUGREPORT_SHARING_ACCEPTED =
Rubin Xu7226c7d2017-02-06 17:18:50 +0000420 "com.android.server.action.REMOTE_BUGREPORT_SHARING_ACCEPTED";
Michal Karpinskiba244092016-02-25 17:28:24 +0000421
422 /**
423 * Action: Bugreport sharing with device owner has been declined by the user.
424 *
425 * @hide
426 */
427 public static final String ACTION_BUGREPORT_SHARING_DECLINED =
Rubin Xu7226c7d2017-02-06 17:18:50 +0000428 "com.android.server.action.REMOTE_BUGREPORT_SHARING_DECLINED";
Michal Karpinskiba244092016-02-25 17:28:24 +0000429
430 /**
Esteban Talavera01576862016-12-15 11:16:44 +0000431 * Action: Bugreport has been collected and is dispatched to {@code DevicePolicyManagerService}.
Michal Karpinskiba244092016-02-25 17:28:24 +0000432 *
433 * @hide
434 */
435 public static final String ACTION_REMOTE_BUGREPORT_DISPATCH =
436 "android.intent.action.REMOTE_BUGREPORT_DISPATCH";
437
438 /**
439 * Extra for shared bugreport's SHA-256 hash.
440 *
441 * @hide
442 */
443 public static final String EXTRA_REMOTE_BUGREPORT_HASH =
444 "android.intent.extra.REMOTE_BUGREPORT_HASH";
445
446 /**
447 * Extra for remote bugreport notification shown type.
448 *
449 * @hide
450 */
451 public static final String EXTRA_BUGREPORT_NOTIFICATION_TYPE =
452 "android.app.extra.bugreport_notification_type";
453
454 /**
455 * Notification type for a started remote bugreport flow.
456 *
457 * @hide
458 */
459 public static final int NOTIFICATION_BUGREPORT_STARTED = 1;
460
461 /**
462 * Notification type for a bugreport that has already been accepted to be shared, but is still
463 * being taken.
464 *
465 * @hide
466 */
467 public static final int NOTIFICATION_BUGREPORT_ACCEPTED_NOT_FINISHED = 2;
468
469 /**
470 * Notification type for a bugreport that has been taken and can be shared or declined.
471 *
472 * @hide
473 */
474 public static final int NOTIFICATION_BUGREPORT_FINISHED_NOT_ACCEPTED = 3;
475
476 /**
Michal Karpinski8f010dd2016-06-21 15:05:53 +0100477 * Default and maximum timeout in milliseconds after which unlocking with weak auth times out,
478 * i.e. the user has to use a strong authentication method like password, PIN or pattern.
479 *
480 * @hide
481 */
482 public static final long DEFAULT_STRONG_AUTH_TIMEOUT_MS = 72 * 60 * 60 * 1000; // 72h
483
484 /**
Rubin Xua4f9dc12015-06-12 13:27:59 +0100485 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100486 * allows a mobile device management application or NFC programmer application which starts
487 * managed provisioning to pass data to the management application instance after provisioning.
Rubin Xua4f9dc12015-06-12 13:27:59 +0100488 * <p>
489 * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that
490 * sends the intent to pass data to itself on the newly created profile.
491 * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same
492 * instance of the app on the primary user.
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100493 * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with
494 * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC
495 * message should contain a stringified {@link java.util.Properties} instance, whose string
496 * properties will be converted into a {@link android.os.PersistableBundle} and passed to the
497 * management application after provisioning.
498 *
Rubin Xua4f9dc12015-06-12 13:27:59 +0100499 * <p>
500 * In both cases the application receives the data in
Brian Carlstromf1fe51b2014-09-03 08:55:05 -0700501 * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action
502 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed
Rubin Xua4f9dc12015-06-12 13:27:59 +0100503 * during the managed provisioning.
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100504 */
505 public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE =
Esteban Talavera37f01842014-09-05 10:50:57 +0100506 "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE";
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100507
508 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100509 * A String extra holding the package name of the mobile device management application that
510 * will be set as the profile owner or device owner.
511 *
512 * <p>If an application starts provisioning directly via an intent with action
513 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
514 * application that started provisioning. The package will be set as profile owner in that case.
515 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000516 * <p>This package is set as device owner when device owner provisioning is started by an NFC
517 * message containing an NFC record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000518 *
519 * <p> When this extra is set, the application must have exactly one device admin receiver.
Robin Lee25e26452015-06-02 09:56:29 -0700520 * This receiver will be set as the profile or device owner and active admin.
Benjamin Franzea956242016-03-21 15:45:56 +0000521 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000522 * @see DeviceAdminReceiver
523 * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still
Nicolas Prevot8f78d6a2015-08-21 11:06:31 +0100524 * supported, but only if there is only one device admin receiver in the package that requires
525 * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000526 */
Nicolas Prevot18440252015-03-09 14:07:17 +0000527 @Deprecated
Jessica Hummelf72078b2014-03-06 16:13:12 +0000528 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100529 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000530
531 /**
Nicolas Prevot18440252015-03-09 14:07:17 +0000532 * A ComponentName extra indicating the device admin receiver of the mobile device management
533 * application that will be set as the profile owner or device owner and active admin.
534 *
535 * <p>If an application starts provisioning directly via an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100536 * {@link #ACTION_PROVISION_MANAGED_PROFILE} or
537 * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this
538 * component has to match the package name of the application that started provisioning.
Nicolas Prevot18440252015-03-09 14:07:17 +0000539 *
540 * <p>This component is set as device owner and active admin when device owner provisioning is
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100541 * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC
542 * message containing an NFC record with MIME type
Benjamin Franzea956242016-03-21 15:45:56 +0000543 * {@link #MIME_TYPE_PROVISIONING_NFC}. For the NFC record, the component name must be
Rubin Xu44ef750b2015-03-23 16:51:33 +0000544 * flattened to a string, via {@link ComponentName#flattenToShortString()}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000545 *
546 * @see DeviceAdminReceiver
547 */
548 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME
549 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME";
550
551 /**
Alexandra Gherghinaaaf2f3e2014-11-13 12:46:15 +0000552 * An {@link android.accounts.Account} extra holding the account to migrate during managed
553 * profile provisioning. If the account supplied is present in the primary user, it will be
554 * copied, along with its credentials to the managed profile and removed from the primary user.
555 *
556 * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}.
557 */
558
559 public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE
560 = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE";
561
562 /**
Victor Changaa9cbc02016-12-05 20:50:57 +0000563 * Boolean extra to indicate that the migrated account should be kept. This is used in
564 * conjunction with {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}. If it's set to {@code true},
565 * the account will not be removed from the primary user after it is migrated to the newly
566 * created user or profile.
Victor Chang89ee2792016-11-23 12:10:55 +0000567 *
568 * <p> Defaults to {@code false}
569 *
Victor Changaa9cbc02016-12-05 20:50:57 +0000570 * <p> Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
571 * {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}
Victor Chang89ee2792016-11-23 12:10:55 +0000572 */
573 public static final String EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION
574 = "android.app.extra.PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION";
575
576 /**
Mahaver761ce772017-03-13 16:40:45 +0000577 * @deprecated From {@link android.os.Build.VERSION_CODES#O}, never used while provisioning the
578 * device.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100579 */
Mahaver761ce772017-03-13 16:40:45 +0000580 @Deprecated
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100581 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
582 = "android.app.extra.PROVISIONING_EMAIL_ADDRESS";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100583
584 /**
Nicolas Prevotcd2d8592015-11-23 13:27:21 +0000585 * A integer extra indicating the predominant color to show during the provisioning.
586 * Refer to {@link android.graphics.Color} for how the color is represented.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000587 *
588 * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or
589 * {@link #ACTION_PROVISION_MANAGED_DEVICE}.
590 */
591 public static final String EXTRA_PROVISIONING_MAIN_COLOR =
592 "android.app.extra.PROVISIONING_MAIN_COLOR";
593
594 /**
Sander Alewijnse8c411562014-11-12 18:03:11 +0000595 * A Boolean extra that can be used by the mobile device management application to skip the
Robin Lee25e26452015-06-02 09:56:29 -0700596 * disabling of system apps during provisioning when set to {@code true}.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000597 *
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100598 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
599 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000600 */
Sander Alewijnse5a144252014-11-18 13:25:04 +0000601 public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED =
602 "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED";
Sander Alewijnse8c411562014-11-12 18:03:11 +0000603
604 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100605 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
606 * will be set to.
607 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000608 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
609 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100610 */
611 public static final String EXTRA_PROVISIONING_TIME_ZONE
Esteban Talavera37f01842014-09-05 10:50:57 +0100612 = "android.app.extra.PROVISIONING_TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100613
614 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100615 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
616 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100617 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000618 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
619 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100620 */
621 public static final String EXTRA_PROVISIONING_LOCAL_TIME
Esteban Talavera37f01842014-09-05 10:50:57 +0100622 = "android.app.extra.PROVISIONING_LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100623
624 /**
625 * A String extra holding the {@link java.util.Locale} that the device will be set to.
626 * Format: xx_yy, where xx is the language code, and yy the country code.
627 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000628 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
629 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100630 */
631 public static final String EXTRA_PROVISIONING_LOCALE
Esteban Talavera37f01842014-09-05 10:50:57 +0100632 = "android.app.extra.PROVISIONING_LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100633
634 /**
635 * A String extra holding the ssid of the wifi network that should be used during nfc device
636 * owner provisioning for downloading the mobile device management application.
637 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000638 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
639 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100640 */
641 public static final String EXTRA_PROVISIONING_WIFI_SSID
Esteban Talavera37f01842014-09-05 10:50:57 +0100642 = "android.app.extra.PROVISIONING_WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100643
644 /**
645 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
646 * is hidden or not.
647 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000648 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
649 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100650 */
651 public static final String EXTRA_PROVISIONING_WIFI_HIDDEN
Esteban Talavera37f01842014-09-05 10:50:57 +0100652 = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100653
654 /**
655 * A String extra indicating the security type of the wifi network in
Mahaver Chopra76b08a92015-10-08 17:58:45 +0100656 * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or
657 * {@code WEP}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100658 *
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_SECURITY_TYPE
Esteban Talavera37f01842014-09-05 10:50:57 +0100663 = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100664
665 /**
666 * A String extra holding the password of the wifi network in
667 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
668 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000669 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
670 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100671 */
672 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talavera37f01842014-09-05 10:50:57 +0100673 = "android.app.extra.PROVISIONING_WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100674
675 /**
676 * A String extra holding the proxy host for the wifi network in
677 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
678 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000679 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
680 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100681 */
682 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
Esteban Talavera37f01842014-09-05 10:50:57 +0100683 = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100684
685 /**
686 * An int extra holding the proxy port for the wifi network in
687 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
688 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000689 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
690 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100691 */
692 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
Esteban Talavera37f01842014-09-05 10:50:57 +0100693 = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100694
695 /**
696 * A String extra holding the proxy bypass for the wifi network in
697 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
698 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000699 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
700 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100701 */
702 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
Esteban Talavera37f01842014-09-05 10:50:57 +0100703 = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100704
705 /**
706 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
707 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
708 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000709 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
710 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100711 */
712 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
Esteban Talavera37f01842014-09-05 10:50:57 +0100713 = "android.app.extra.PROVISIONING_WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100714
715 /**
716 * A String extra holding a url that specifies the download location of the device admin
717 * package. When not provided it is assumed that the device admin package is already installed.
718 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000719 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
720 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100721 */
722 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talavera37f01842014-09-05 10:50:57 +0100723 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100724
725 /**
Victor Chang38cfd9c2017-01-04 17:41:11 +0000726 * A String extra holding the localized name of the organization under management.
727 *
728 * The name is displayed only during provisioning.
729 *
730 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE}
731 *
732 * @hide
733 */
734 @SystemApi
735 public static final String EXTRA_PROVISIONING_ORGANIZATION_NAME =
736 "android.app.extra.PROVISIONING_ORGANIZATION_NAME";
737
738 /**
Alejandro Fernándezbfd61932017-04-04 19:33:01 +0100739 * A String extra holding a url to the website of the device provider so the user can open it
740 * during provisioning. If the url is not HTTPS, an error will be shown.
Victor Chang38cfd9c2017-01-04 17:41:11 +0000741 *
742 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE}
743 *
744 * @hide
745 */
746 @SystemApi
747 public static final String EXTRA_PROVISIONING_SUPPORT_URL =
748 "android.app.extra.PROVISIONING_SUPPORT_URL";
749
750 /**
751 * A String extra holding the localized name of the device admin package. It should be the same
752 * as the app label of the package.
753 *
754 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE}
755 *
756 * @hide
757 */
758 @SystemApi
759 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL =
760 "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL";
761
762 /**
763 * A {@link Uri} extra pointing to the app icon of device admin package. This image will be
764 * shown during the provisioning.
765 * <h5>The following URI schemes are accepted:</h5>
766 * <ul>
767 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
768 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
769 * </ul>
770 *
771 * <p> It is the responsibility of the caller to provide an image with a reasonable
772 * pixel density for the device.
773 *
774 * <p> If a content: URI is passed, the intent should have the flag
775 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
776 * {@link android.content.ClipData} of the intent too.
777 *
778 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE}
779 *
780 * @hide
781 */
782 @SystemApi
783 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI =
784 "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI";
785
786 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400787 * An int extra holding a minimum required version code for the device admin package. If the
788 * device admin is already installed on the device, it will only be re-downloaded from
789 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the
790 * installed package is less than this version code.
791 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400792 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400793 * provisioning via an NFC bump.
794 */
795 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE
796 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE";
797
798 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100799 * A String extra holding a http cookie header which should be used in the http request to the
800 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
801 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000802 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
803 * provisioning via an NFC bump.
Sander Alewijnse681bce92014-07-24 16:46:26 +0100804 */
805 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talavera37f01842014-09-05 10:50:57 +0100806 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100807
808 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100809 * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of
810 * the file at download location specified in
811 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100812 *
Benjamin Franzea956242016-03-21 15:45:56 +0000813 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} must be
814 * present. The provided checksum must match the checksum of the file at the download
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100815 * location. If the checksum doesn't match an error will be shown to the user and the user will
816 * be asked to factory reset the device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100817 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000818 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
819 * provisioning via an NFC bump.
Rubin Xud92e7572015-05-18 17:01:13 +0100820 *
821 * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP}
822 * and {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1} only SHA-1 hash is supported.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700823 * Starting from {@link android.os.Build.VERSION_CODES#M}, this parameter accepts SHA-256 in
Rubin Xud92e7572015-05-18 17:01:13 +0100824 * addition to SHA-1. Support for SHA-1 is likely to be removed in future OS releases.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100825 */
826 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100827 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100828
829 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100830 * A String extra holding the URL-safe base64 encoded SHA-256 checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100831 * android package archive at the download location specified in {@link
832 * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
833 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100834 * <p>The signatures of an android package archive can be obtained using
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100835 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
836 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
837 *
Benjamin Franzea956242016-03-21 15:45:56 +0000838 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} must be
839 * present. The provided checksum must match the checksum of any signature of the file at
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100840 * the download location. If the checksum does not match an error will be shown to the user and
841 * the user will be asked to factory reset the device.
842 *
843 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
844 * provisioning via an NFC bump.
845 */
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100846 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM
847 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM";
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100848
849 /**
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000850 * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile
851 * has completed successfully.
852 *
853 * <p>The broadcast is limited to the primary profile, to the app specified in the provisioning
Nicolas Prevotebe2d992015-05-12 18:14:53 -0700854 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000855 *
Mahaver7074caf2016-11-29 20:52:18 +0000856 * <p>This intent will contain the following extras
857 * <ul>
858 * <li>{@link Intent#EXTRA_USER}, corresponds to the {@link UserHandle} of the managed
859 * profile.</li>
860 * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, corresponds to the account requested to
861 * be migrated at provisioning time, if any.</li>
862 * </ul>
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000863 */
864 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
865 public static final String ACTION_MANAGED_PROFILE_PROVISIONED
866 = "android.app.action.MANAGED_PROFILE_PROVISIONED";
867
868 /**
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000869 * Activity action: This activity action is sent to indicate that provisioning of a managed
870 * profile or managed device has completed successfully. It'll be sent at the same time as
871 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast but this will be
872 * delivered faster as it's an activity intent.
873 *
Esteban Talavera4047bae2017-06-28 11:03:09 +0100874 * <p>The intent is only sent to the new device or profile owner.
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000875 *
876 * @see #ACTION_PROVISION_MANAGED_PROFILE
877 * @see #ACTION_PROVISION_MANAGED_DEVICE
878 */
879 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
880 public static final String ACTION_PROVISIONING_SUCCESSFUL =
881 "android.app.action.PROVISIONING_SUCCESSFUL";
882
883 /**
Benjamin Franzea956242016-03-21 15:45:56 +0000884 * A boolean extra indicating whether device encryption can be skipped as part of device owner
885 * or managed profile provisioning.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500886 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400887 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100888 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Benjamin Franzea956242016-03-21 15:45:56 +0000889 *
890 * <p>From {@link android.os.Build.VERSION_CODES#N} onwards, this is also supported for an
891 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500892 */
893 public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION =
894 "android.app.extra.PROVISIONING_SKIP_ENCRYPTION";
895
896 /**
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000897 * A {@link Uri} extra pointing to a logo image. This image will be shown during the
898 * provisioning. If this extra is not passed, a default image will be shown.
899 * <h5>The following URI schemes are accepted:</h5>
900 * <ul>
901 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
902 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
903 * </ul>
904 *
Victor Changc10f6692016-12-09 15:24:00 +0000905 * <p> It is the responsibility of the caller to provide an image with a reasonable
Victor Chang38cfd9c2017-01-04 17:41:11 +0000906 * pixel density for the device.
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000907 *
908 * <p> If a content: URI is passed, the intent should have the flag
909 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
910 * {@link android.content.ClipData} of the intent too.
911 *
912 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or
913 * {@link #ACTION_PROVISION_MANAGED_DEVICE}
914 */
915 public static final String EXTRA_PROVISIONING_LOGO_URI =
916 "android.app.extra.PROVISIONING_LOGO_URI";
917
918 /**
Victor Changc10f6692016-12-09 15:24:00 +0000919 * A {@link Bundle}[] extra consisting of list of disclaimer headers and disclaimer contents.
920 * Each {@link Bundle} must have both {@link #EXTRA_PROVISIONING_DISCLAIMER_HEADER}
921 * as disclaimer header, and {@link #EXTRA_PROVISIONING_DISCLAIMER_CONTENT} as disclaimer
922 * content.
923 *
924 * <p> The extra typically contains one disclaimer from the company of mobile device
925 * management application (MDM), and one disclaimer from the organization.
926 *
927 * <p> Call {@link Bundle#putParcelableArray(String, Parcelable[])} to put the {@link Bundle}[]
928 *
929 * <p> Maximum 3 key-value pairs can be specified. The rest will be ignored.
930 *
931 * <p> Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or
932 * {@link #ACTION_PROVISION_MANAGED_DEVICE}
933 */
934 public static final String EXTRA_PROVISIONING_DISCLAIMERS =
935 "android.app.extra.PROVISIONING_DISCLAIMERS";
936
937 /**
938 * A String extra of localized disclaimer header.
939 *
940 * <p> The extra is typically the company name of mobile device management application (MDM)
941 * or the organization name.
942 *
943 * <p> Use in Bundle {@link #EXTRA_PROVISIONING_DISCLAIMERS}
Victor Chang98607132017-01-27 11:51:56 +0000944 *
945 * <p> System app, i.e. application with {@link ApplicationInfo#FLAG_SYSTEM}, can also insert a
946 * disclaimer by declaring an application-level meta-data in {@code AndroidManifest.xml}.
947 * Must use it with {@link #EXTRA_PROVISIONING_DISCLAIMER_CONTENT}. Here is the example:
948 *
949 * <pre>
950 * &lt;meta-data
951 * android:name="android.app.extra.PROVISIONING_DISCLAIMER_HEADER"
952 * android:resource="@string/disclaimer_header"
953 * /&gt;</pre>
Victor Changc10f6692016-12-09 15:24:00 +0000954 */
955 public static final String EXTRA_PROVISIONING_DISCLAIMER_HEADER =
956 "android.app.extra.PROVISIONING_DISCLAIMER_HEADER";
957
958 /**
959 * A {@link Uri} extra pointing to disclaimer content.
960 *
961 * <h5>The following URI schemes are accepted:</h5>
962 * <ul>
963 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
964 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
965 * </ul>
966 *
967 * <p> Styled text is supported in the disclaimer content. The content is parsed by
968 * {@link android.text.Html#fromHtml(String)} and displayed in a
969 * {@link android.widget.TextView}.
970 *
971 * <p> If a <code>content:</code> URI is passed, URI is passed, the intent should have the flag
972 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
973 * {@link android.content.ClipData} of the intent too.
974 *
975 * <p> Use in Bundle {@link #EXTRA_PROVISIONING_DISCLAIMERS}
Victor Chang98607132017-01-27 11:51:56 +0000976 *
977 * <p> System app, i.e. application with {@link ApplicationInfo#FLAG_SYSTEM}, can also insert a
978 * disclaimer by declaring an application-level meta-data in {@code AndroidManifest.xml}.
979 * Must use it with {@link #EXTRA_PROVISIONING_DISCLAIMER_HEADER}. Here is the example:
980 *
981 * <pre>
982 * &lt;meta-data
983 * android:name="android.app.extra.PROVISIONING_DISCLAIMER_CONTENT"
984 * android:resource="@string/disclaimer_content"
985 * /&gt;</pre>
Victor Changc10f6692016-12-09 15:24:00 +0000986 */
987 public static final String EXTRA_PROVISIONING_DISCLAIMER_CONTENT =
988 "android.app.extra.PROVISIONING_DISCLAIMER_CONTENT";
989
990 /**
Alan Treadway94de8c82016-01-11 10:25:23 +0000991 * A boolean extra indicating if user setup should be skipped, for when provisioning is started
992 * during setup-wizard.
993 *
994 * <p>If unspecified, defaults to {@code true} to match the behavior in
995 * {@link android.os.Build.VERSION_CODES#M} and earlier.
996 *
Alan Treadway1a538d02016-01-18 16:42:30 +0000997 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or
998 * {@link #ACTION_PROVISION_MANAGED_USER}.
Alan Treadway94de8c82016-01-11 10:25:23 +0000999 *
1000 * @hide
1001 */
1002 public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP =
1003 "android.app.extra.PROVISIONING_SKIP_USER_SETUP";
1004
1005 /**
Victor Chang51d84f92016-11-16 12:22:56 +00001006 * A boolean extra indicating if the user consent steps from the provisioning flow should be
1007 * skipped. If unspecified, defaults to {@code false}.
1008 *
1009 * It can only be used by an existing device owner trying to create a managed profile via
1010 * {@link #ACTION_PROVISION_MANAGED_PROFILE}. Otherwise it is ignored.
1011 */
1012 public static final String EXTRA_PROVISIONING_SKIP_USER_CONSENT =
1013 "android.app.extra.PROVISIONING_SKIP_USER_CONSENT";
1014
1015 /**
Benjamin Franzea956242016-03-21 15:45:56 +00001016 * This MIME type is used for starting the device owner provisioning.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +01001017 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -04001018 * <p>During device owner provisioning a device admin app is set as the owner of the device.
1019 * A device owner has full control over the device. The device owner can not be modified by the
1020 * user and the only way of resetting the device is if the device owner app calls a factory
1021 * reset.
1022 *
1023 * <p> A typical use case would be a device that is owned by a company, but used by either an
1024 * employee or client.
1025 *
Benjamin Franzea956242016-03-21 15:45:56 +00001026 * <p> The NFC message must be sent to an unprovisioned device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +01001027 *
Sander Alewijnse8c411562014-11-12 18:03:11 +00001028 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +01001029 * contains the following properties:
1030 * <ul>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -04001031 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
1032 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +01001033 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -04001034 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +01001035 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
1036 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
1037 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
1038 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
1039 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
1040 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
1041 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
1042 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
1043 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
1044 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Rubin Xu41f2ccb92015-08-05 16:29:13 +01001045 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
1046 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from
1047 * {@link android.os.Build.VERSION_CODES#M} </li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +01001048 *
Nicolas Prevot18440252015-03-09 14:07:17 +00001049 * <p>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07001050 * As of {@link android.os.Build.VERSION_CODES#M}, the properties should contain
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -04001051 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of
1052 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only
1053 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -04001054 */
1055 public static final String MIME_TYPE_PROVISIONING_NFC
1056 = "application/com.android.managedprovisioning";
1057
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +01001058 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001059 * Activity action: ask the user to add a new device administrator to the system.
1060 * The desired policy is the ComponentName of the policy in the
1061 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
1062 * bring the user through adding the device administrator to the system (or
1063 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001064 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001065 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
1066 * field to provide the user with additional explanation (in addition
1067 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001068 *
1069 * <p>If your administrator is already active, this will ordinarily return immediately (without
1070 * user intervention). However, if your administrator has been updated and is requesting
1071 * additional uses-policy flags, the user will be presented with the new list. New policies
1072 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001073 */
1074 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1075 public static final String ACTION_ADD_DEVICE_ADMIN
1076 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001077
Dianne Hackbornd6847842010-01-12 18:14:19 -08001078 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001079 * @hide
1080 * Activity action: ask the user to add a new device administrator as the profile owner
Amith Yamasani814e9872015-03-23 14:04:53 -07001081 * for this user. Only system apps can launch this intent.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001082 *
Amith Yamasani814e9872015-03-23 14:04:53 -07001083 * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN}
1084 * extra field. This will invoke a UI to bring the user through adding the profile owner admin
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001085 * to remotely control restrictions on the user.
1086 *
Makoto Onukic8a5a552015-11-19 14:29:12 -08001087 * <p>The intent must be invoked via {@link Activity#startActivityForResult} to receive the
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001088 * result of whether or not the user approved the action. If approved, the result will
1089 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
1090 * as a profile owner.
1091 *
1092 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
1093 * field to provide the user with additional explanation (in addition
1094 * to your component's description) about what is being added.
1095 *
Amith Yamasani814e9872015-03-23 14:04:53 -07001096 * <p>If there is already a profile owner active or the caller is not a system app, the
1097 * operation will return a failure result.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001098 */
1099 @SystemApi
1100 public static final String ACTION_SET_PROFILE_OWNER
1101 = "android.app.action.SET_PROFILE_OWNER";
1102
1103 /**
1104 * @hide
1105 * Name of the profile owner admin that controls the user.
1106 */
1107 @SystemApi
1108 public static final String EXTRA_PROFILE_OWNER_NAME
1109 = "android.app.extra.PROFILE_OWNER_NAME";
1110
1111 /**
Nicolas Prevot00799002015-07-27 18:15:20 +01001112 * Broadcast action: send when any policy admin changes a policy.
Jim Miller284b62e2010-06-08 14:27:42 -07001113 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -07001114 *
Jim Miller284b62e2010-06-08 14:27:42 -07001115 * @hide
1116 */
1117 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
1118 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
1119
1120 /**
Tony Mak1970f972016-08-30 17:41:48 +01001121 * Broadcast action: sent when the device owner is set, changed or cleared.
Nicolas Prevot00799002015-07-27 18:15:20 +01001122 *
1123 * This broadcast is sent only to the primary user.
1124 * @see #ACTION_PROVISION_MANAGED_DEVICE
arangelov8bae4ea2017-12-20 20:26:46 +00001125 * @see DevicePolicyManager#transferOwnership(ComponentName, ComponentName, PersistableBundle)
Nicolas Prevot00799002015-07-27 18:15:20 +01001126 */
1127 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1128 public static final String ACTION_DEVICE_OWNER_CHANGED
1129 = "android.app.action.DEVICE_OWNER_CHANGED";
1130
1131 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001132 * The ComponentName of the administrator component.
1133 *
1134 * @see #ACTION_ADD_DEVICE_ADMIN
1135 */
1136 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001137
Dianne Hackbornd6847842010-01-12 18:14:19 -08001138 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001139 * An optional CharSequence providing additional explanation for why the
1140 * admin is being added.
1141 *
1142 * @see #ACTION_ADD_DEVICE_ADMIN
1143 */
1144 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001145
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001146 /**
phweiss73145f42017-01-17 19:06:38 +01001147 * Constant to indicate the feature of disabling the camera. Used as argument to
1148 * {@link #createAdminSupportIntent(String)}.
1149 * @see #setCameraDisabled(ComponentName, boolean)
1150 */
1151 public static final String POLICY_DISABLE_CAMERA = "policy_disable_camera";
1152
1153 /**
1154 * Constant to indicate the feature of disabling screen captures. Used as argument to
1155 * {@link #createAdminSupportIntent(String)}.
1156 * @see #setScreenCaptureDisabled(ComponentName, boolean)
1157 */
1158 public static final String POLICY_DISABLE_SCREEN_CAPTURE = "policy_disable_screen_capture";
1159
1160 /**
Lenka Trochtova16a91c02018-01-17 11:03:30 +01001161 * Constant to indicate the feature of mandatory backups. Used as argument to
1162 * {@link #createAdminSupportIntent(String)}.
1163 * @see #setMandatoryBackupTransport(ComponentName, ComponentName)
1164 */
1165 public static final String POLICY_MANDATORY_BACKUPS = "policy_mandatory_backups";
1166
1167 /**
phweiss73145f42017-01-17 19:06:38 +01001168 * A String indicating a specific restricted feature. Can be a user restriction from the
1169 * {@link UserManager}, e.g. {@link UserManager#DISALLOW_ADJUST_VOLUME}, or one of the values
Lenka Trochtova16a91c02018-01-17 11:03:30 +01001170 * {@link #POLICY_DISABLE_CAMERA}, {@link #POLICY_DISABLE_SCREEN_CAPTURE} or
1171 * {@link #POLICY_MANDATORY_BACKUPS}.
phweiss73145f42017-01-17 19:06:38 +01001172 * @see #createAdminSupportIntent(String)
1173 * @hide
1174 */
1175 @TestApi
1176 public static final String EXTRA_RESTRICTION = "android.app.extra.RESTRICTION";
1177
1178 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001179 * Activity action: have the user enter a new password. This activity should
1180 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
1181 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
1182 * enter a new password that meets the current requirements. You can use
1183 * {@link #isActivePasswordSufficient()} to determine whether you need to
1184 * have the user select a new password in order to meet the current
1185 * constraints. Upon being resumed from this activity, you can check the new
1186 * password characteristics to see if they are sufficient.
Benjamin Franzc9921092016-01-08 17:17:44 +00001187 *
1188 * If the intent is launched from within a managed profile with a profile
1189 * owner built against {@link android.os.Build.VERSION_CODES#M} or before,
1190 * this will trigger entering a new password for the parent of the profile.
1191 * For all other cases it will trigger entering a new password for the user
1192 * or profile it is launched from.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001193 *
1194 * @see #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
Dianne Hackbornd6847842010-01-12 18:14:19 -08001195 */
1196 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1197 public static final String ACTION_SET_NEW_PASSWORD
1198 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001199
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001200 /**
Benjamin Franzc9921092016-01-08 17:17:44 +00001201 * Activity action: have the user enter a new password for the parent profile.
1202 * If the intent is launched from within a managed profile, this will trigger
1203 * entering a new password for the parent of the profile. In all other cases
1204 * the behaviour is identical to {@link #ACTION_SET_NEW_PASSWORD}.
1205 */
1206 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1207 public static final String ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
1208 = "android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD";
1209
1210 /**
phweissa0cb2512016-12-14 21:37:48 +01001211 * Broadcast action: Tell the status bar to open the device monitoring dialog, e.g. when
1212 * Network logging was enabled and the user tapped the notification.
1213 * <p class="note">This is a protected intent that can only be sent by the system.</p>
1214 * @hide
1215 */
1216 public static final String ACTION_SHOW_DEVICE_MONITORING_DIALOG
1217 = "android.app.action.SHOW_DEVICE_MONITORING_DIALOG";
1218
1219 /**
Edman Anjos9e62c312017-01-26 22:22:58 +01001220 * Broadcast Action: Sent after application delegation scopes are changed. The new delegation
1221 * scopes will be sent in an {@code ArrayList<String>} extra identified by the
1222 * {@link #EXTRA_DELEGATION_SCOPES} key.
Edman Anjosf9946772016-11-28 16:35:15 +01001223 *
1224 * <p class=”note”> Note: This is a protected intent that can only be sent by the system.</p>
1225 */
1226 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1227 public static final String ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED =
1228 "android.app.action.APPLICATION_DELEGATION_SCOPES_CHANGED";
1229
1230 /**
Edman Anjos9e62c312017-01-26 22:22:58 +01001231 * An {@code ArrayList<String>} corresponding to the delegation scopes given to an app in the
Edman Anjosf9946772016-11-28 16:35:15 +01001232 * {@link #ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED} broadcast.
1233 */
1234 public static final String EXTRA_DELEGATION_SCOPES = "android.app.extra.DELEGATION_SCOPES";
1235
1236 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +00001237 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
1238 * the parent profile to access intents sent from the managed profile.
1239 * That is, when an app in the managed profile calls
1240 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
1241 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001242 */
Nicolas Prevot86a96732014-09-08 12:13:05 +01001243 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001244
1245 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +00001246 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
1247 * the managed profile to access intents sent from the parent profile.
1248 * That is, when an app in the parent profile calls
1249 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
1250 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001251 */
Nicolas Prevot86a96732014-09-08 12:13:05 +01001252 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001253
Dianne Hackbornd6847842010-01-12 18:14:19 -08001254 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01001255 * Broadcast action: notify that a new local system update policy has been set by the device
1256 * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00001257 */
1258 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Rubin Xu5faad8e2015-04-20 17:43:48 +01001259 public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED
1260 = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED";
Rubin Xu8027a4f2015-03-10 17:52:37 +00001261
Amith Yamasanid49489b2015-04-28 14:00:26 -07001262 /**
Rubin Xucc391c22018-01-02 20:37:35 +00001263 * Broadcast action to notify ManagedProvisioning that
1264 * {@link UserManager#DISALLOW_SHARE_INTO_MANAGED_PROFILE} restriction has changed.
1265 * @hide
1266 */
1267 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1268 public static final String ACTION_DATA_SHARING_RESTRICTION_CHANGED =
1269 "android.app.action.DATA_SHARING_RESTRICTION_CHANGED";
1270
1271 /**
1272 * Broadcast action from ManagedProvisioning to notify that the latest change to
1273 * {@link UserManager#DISALLOW_SHARE_INTO_MANAGED_PROFILE} restriction has been successfully
1274 * applied (cross profile intent filters updated). Only usesd for CTS tests.
1275 * @hide
1276 */
1277 @TestApi
1278 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1279 public static final String ACTION_DATA_SHARING_RESTRICTION_APPLIED =
1280 "android.app.action.DATA_SHARING_RESTRICTION_APPLIED";
1281
1282 /**
Amith Yamasanid49489b2015-04-28 14:00:26 -07001283 * Permission policy to prompt user for new permission requests for runtime permissions.
1284 * Already granted or denied permissions are not affected by this.
1285 */
1286 public static final int PERMISSION_POLICY_PROMPT = 0;
1287
1288 /**
1289 * Permission policy to always grant new permission requests for runtime permissions.
1290 * Already granted or denied permissions are not affected by this.
1291 */
1292 public static final int PERMISSION_POLICY_AUTO_GRANT = 1;
1293
1294 /**
1295 * Permission policy to always deny new permission requests for runtime permissions.
1296 * Already granted or denied permissions are not affected by this.
1297 */
1298 public static final int PERMISSION_POLICY_AUTO_DENY = 2;
1299
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07001300 /**
1301 * Runtime permission state: The user can manage the permission
1302 * through the UI.
1303 */
1304 public static final int PERMISSION_GRANT_STATE_DEFAULT = 0;
1305
1306 /**
1307 * Runtime permission state: The permission is granted to the app
1308 * and the user cannot manage the permission through the UI.
1309 */
1310 public static final int PERMISSION_GRANT_STATE_GRANTED = 1;
1311
1312 /**
1313 * Runtime permission state: The permission is denied to the app
1314 * and the user cannot manage the permission through the UI.
1315 */
1316 public static final int PERMISSION_GRANT_STATE_DENIED = 2;
Rubin Xu8027a4f2015-03-10 17:52:37 +00001317
1318 /**
Edman Anjosf9946772016-11-28 16:35:15 +01001319 * Delegation of certificate installation and management. This scope grants access to the
1320 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
1321 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair} APIs.
1322 */
1323 public static final String DELEGATION_CERT_INSTALL = "delegation-cert-install";
1324
1325 /**
1326 * Delegation of application restrictions management. This scope grants access to the
1327 * {@link #setApplicationRestrictions} and {@link #getApplicationRestrictions} APIs.
1328 */
1329 public static final String DELEGATION_APP_RESTRICTIONS = "delegation-app-restrictions";
1330
1331 /**
Edman Anjosa5f2fb12016-12-19 11:25:54 -08001332 * Delegation of application uninstall block. This scope grants access to the
1333 * {@link #setUninstallBlocked} API.
1334 */
1335 public static final String DELEGATION_BLOCK_UNINSTALL = "delegation-block-uninstall";
1336
1337 /**
Edman Anjos52088e42017-01-13 22:26:17 +01001338 * Delegation of permission policy and permission grant state. This scope grants access to the
1339 * {@link #setPermissionPolicy}, {@link #getPermissionGrantState},
1340 * and {@link #setPermissionGrantState} APIs.
1341 */
1342 public static final String DELEGATION_PERMISSION_GRANT = "delegation-permission-grant";
1343
1344 /**
1345 * Delegation of package access state. This scope grants access to the
1346 * {@link #isApplicationHidden}, {@link #setApplicationHidden}, {@link #isPackageSuspended}, and
1347 * {@link #setPackagesSuspended} APIs.
1348 */
1349 public static final String DELEGATION_PACKAGE_ACCESS = "delegation-package-access";
1350
1351 /**
1352 * Delegation for enabling system apps. This scope grants access to the {@link #enableSystemApp}
1353 * API.
1354 */
1355 public static final String DELEGATION_ENABLE_SYSTEM_APP = "delegation-enable-system-app";
1356
1357 /**
Alex Chau5343fcb2017-12-05 16:49:19 +00001358 * Delegation for installing existing packages. This scope grants access to the
1359 * {@link #installExistingPackage} API.
1360 */
1361 public static final String DELEGATION_INSTALL_EXISTING_PACKAGE =
1362 "delegation-install-existing-package";
1363
1364 /**
Edman Anjos52088e42017-01-13 22:26:17 +01001365 * Delegation of management of uninstalled packages. This scope grants access to the
1366 * {@code #setKeepUninstalledPackages} and {@code #getKeepUninstalledPackages} APIs.
Edman Anjos52088e42017-01-13 22:26:17 +01001367 */
1368 public static final String DELEGATION_KEEP_UNINSTALLED_PACKAGES =
1369 "delegation-keep-uninstalled-packages";
1370
1371 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00001372 * No management for current user in-effect. This is the default.
1373 * @hide
1374 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001375 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001376 public static final int STATE_USER_UNMANAGED = 0;
1377
1378 /**
1379 * Management partially setup, user setup needs to be completed.
1380 * @hide
1381 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001382 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001383 public static final int STATE_USER_SETUP_INCOMPLETE = 1;
1384
1385 /**
1386 * Management partially setup, user setup completed.
1387 * @hide
1388 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001389 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001390 public static final int STATE_USER_SETUP_COMPLETE = 2;
1391
1392 /**
1393 * Management setup and active on current user.
1394 * @hide
1395 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001396 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001397 public static final int STATE_USER_SETUP_FINALIZED = 3;
1398
1399 /**
1400 * Management partially setup on a managed profile.
1401 * @hide
1402 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001403 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001404 public static final int STATE_USER_PROFILE_COMPLETE = 4;
1405
1406 /**
1407 * @hide
1408 */
Jeff Sharkeyce8db992017-12-13 20:05:05 -07001409 @IntDef(prefix = { "STATE_USER_" }, value = {
1410 STATE_USER_UNMANAGED,
1411 STATE_USER_SETUP_INCOMPLETE,
1412 STATE_USER_SETUP_COMPLETE,
1413 STATE_USER_SETUP_FINALIZED,
1414 STATE_USER_PROFILE_COMPLETE
1415 })
Alan Treadwayafad8782016-01-19 15:15:08 +00001416 @Retention(RetentionPolicy.SOURCE)
1417 public @interface UserProvisioningState {}
1418
1419 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001420 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001421 *
1422 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1423 * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and
1424 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when provisioning is allowed.
1425 *
1426 * @hide
1427 */
1428 public static final int CODE_OK = 0;
1429
1430 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001431 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001432 *
1433 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and
1434 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the device already has a device
1435 * owner.
1436 *
1437 * @hide
1438 */
1439 public static final int CODE_HAS_DEVICE_OWNER = 1;
1440
1441 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001442 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001443 *
1444 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1445 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user has a profile owner and for
1446 * {@link #ACTION_PROVISION_MANAGED_PROFILE} when the profile owner is already set.
1447 *
1448 * @hide
1449 */
1450 public static final int CODE_USER_HAS_PROFILE_OWNER = 2;
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} and
1456 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user isn't running.
1457 *
1458 * @hide
1459 */
1460 public static final int CODE_USER_NOT_RUNNING = 3;
1461
1462 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001463 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001464 *
1465 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1466 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the device has already been setup and
1467 * for {@link #ACTION_PROVISION_MANAGED_USER} if the user has already been setup.
1468 *
1469 * @hide
1470 */
1471 public static final int CODE_USER_SETUP_COMPLETED = 4;
1472
1473 /**
1474 * Code used to indicate that the device also has a user other than the system user.
1475 *
1476 * @hide
1477 */
1478 public static final int CODE_NONSYSTEM_USER_EXISTS = 5;
1479
1480 /**
1481 * Code used to indicate that device has an account that prevents provisioning.
1482 *
1483 * @hide
1484 */
1485 public static final int CODE_ACCOUNTS_NOT_EMPTY = 6;
1486
1487 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001488 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001489 *
1490 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and
1491 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the user is not a system user.
1492 *
1493 * @hide
1494 */
1495 public static final int CODE_NOT_SYSTEM_USER = 7;
1496
1497 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001498 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001499 *
1500 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1501 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} and {@link #ACTION_PROVISION_MANAGED_USER}
1502 * when the device is a watch and is already paired.
1503 *
1504 * @hide
1505 */
1506 public static final int CODE_HAS_PAIRED = 8;
1507
1508 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001509 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001510 *
1511 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} and
1512 * {@link #ACTION_PROVISION_MANAGED_USER} on devices which do not support managed users.
1513 *
1514 * @see {@link PackageManager#FEATURE_MANAGED_USERS}
1515 * @hide
1516 */
1517 public static final int CODE_MANAGED_USERS_NOT_SUPPORTED = 9;
1518
1519 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001520 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001521 *
1522 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} if the user is a system user.
1523 *
1524 * @hide
1525 */
1526 public static final int CODE_SYSTEM_USER = 10;
1527
1528 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001529 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001530 *
1531 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when the user cannot have more
1532 * managed profiles.
1533 *
1534 * @hide
1535 */
1536 public static final int CODE_CANNOT_ADD_MANAGED_PROFILE = 11;
1537
1538 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001539 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001540 *
1541 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} and
1542 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices not running with split system
1543 * user.
1544 *
1545 * @hide
1546 */
1547 public static final int CODE_NOT_SYSTEM_USER_SPLIT = 12;
1548
1549 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001550 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001551 *
1552 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1553 * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and
1554 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices which do no support device
1555 * admins.
1556 *
1557 * @hide
1558 */
1559 public static final int CODE_DEVICE_ADMIN_NOT_SUPPORTED = 13;
1560
1561 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001562 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001563 *
Esteban Talavera6c9116a2016-11-24 16:12:44 +00001564 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when the device the user is a
1565 * system user on a split system user device.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001566 *
1567 * @hide
1568 */
1569 public static final int CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER = 14;
1570
1571 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001572 * Result code for {@link #checkProvisioningPreCondition}.
1573 *
1574 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when adding a managed profile is
1575 * disallowed by {@link UserManager#DISALLOW_ADD_MANAGED_PROFILE}.
1576 *
1577 * @hide
1578 */
1579 public static final int CODE_ADD_MANAGED_PROFILE_DISALLOWED = 15;
1580
1581 /**
1582 * Result codes for {@link #checkProvisioningPreCondition} indicating all the provisioning pre
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001583 * conditions.
1584 *
1585 * @hide
1586 */
1587 @Retention(RetentionPolicy.SOURCE)
Jeff Sharkeyce8db992017-12-13 20:05:05 -07001588 @IntDef(prefix = { "CODE_" }, value = {
1589 CODE_OK, CODE_HAS_DEVICE_OWNER, CODE_USER_HAS_PROFILE_OWNER, CODE_USER_NOT_RUNNING,
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001590 CODE_USER_SETUP_COMPLETED, CODE_NOT_SYSTEM_USER, CODE_HAS_PAIRED,
1591 CODE_MANAGED_USERS_NOT_SUPPORTED, CODE_SYSTEM_USER, CODE_CANNOT_ADD_MANAGED_PROFILE,
1592 CODE_NOT_SYSTEM_USER_SPLIT, CODE_DEVICE_ADMIN_NOT_SUPPORTED,
Jeff Sharkeyce8db992017-12-13 20:05:05 -07001593 CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER, CODE_ADD_MANAGED_PROFILE_DISALLOWED
1594 })
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001595 public @interface ProvisioningPreCondition {}
1596
1597 /**
Charles Hee078db72017-10-19 18:03:20 +01001598 * Disable all configurable SystemUI features during LockTask mode. This includes,
1599 * <ul>
1600 * <li>system info area in the status bar (connectivity icons, clock, etc.)
1601 * <li>notifications (including alerts, icons, and the notification shade)
1602 * <li>Home button
1603 * <li>Recents button and UI
1604 * <li>global actions menu (i.e. power button menu)
1605 * <li>keyguard
1606 * </ul>
1607 *
1608 * This is the default configuration for LockTask.
1609 *
1610 * @see #setLockTaskFeatures(ComponentName, int)
1611 */
1612 public static final int LOCK_TASK_FEATURE_NONE = 0;
1613
1614 /**
1615 * Enable the system info area in the status bar during LockTask mode. The system info area
1616 * usually occupies the right side of the status bar (although this can differ across OEMs). It
1617 * includes all system information indicators, such as date and time, connectivity, battery,
1618 * vibration mode, etc.
1619 *
1620 * @see #setLockTaskFeatures(ComponentName, int)
1621 */
1622 public static final int LOCK_TASK_FEATURE_SYSTEM_INFO = 1;
1623
1624 /**
1625 * Enable notifications during LockTask mode. This includes notification icons on the status
1626 * bar, heads-up notifications, and the expandable notification shade. Note that the Quick
1627 * Settings panel will still be disabled.
1628 *
1629 * @see #setLockTaskFeatures(ComponentName, int)
1630 */
1631 public static final int LOCK_TASK_FEATURE_NOTIFICATIONS = 1 << 1;
1632
1633 /**
1634 * Enable the Home button during LockTask mode. Note that if a custom launcher is used, it has
1635 * to be registered as the default launcher with
1636 * {@link #addPersistentPreferredActivity(ComponentName, IntentFilter, ComponentName)}, and its
1637 * package needs to be whitelisted for LockTask with
1638 * {@link #setLockTaskPackages(ComponentName, String[])}.
1639 *
1640 * @see #setLockTaskFeatures(ComponentName, int)
1641 */
1642 public static final int LOCK_TASK_FEATURE_HOME = 1 << 2;
1643
1644 /**
1645 * Enable the Recents button and the Recents screen during LockTask mode.
1646 *
1647 * @see #setLockTaskFeatures(ComponentName, int)
1648 */
1649 public static final int LOCK_TASK_FEATURE_RECENTS = 1 << 3;
1650
1651 /**
1652 * Enable the global actions dialog during LockTask mode. This is the dialog that shows up when
1653 * the user long-presses the power button, for example. Note that the user may not be able to
1654 * power off the device if this flag is not set.
1655 *
1656 * @see #setLockTaskFeatures(ComponentName, int)
1657 */
1658 public static final int LOCK_TASK_FEATURE_GLOBAL_ACTIONS = 1 << 4;
1659
1660 /**
1661 * Enable the keyguard during LockTask mode. Note that if the keyguard is already disabled with
1662 * {@link #setKeyguardDisabled(ComponentName, boolean)}, setting this flag will have no effect.
1663 * If this flag is not set, the keyguard will not be shown even if the user has a lock screen
1664 * credential.
1665 *
1666 * @see #setLockTaskFeatures(ComponentName, int)
1667 */
1668 public static final int LOCK_TASK_FEATURE_KEYGUARD = 1 << 5;
1669
1670 /**
1671 * Flags supplied to {@link #setLockTaskFeatures(ComponentName, int)}.
1672 *
1673 * @hide
1674 */
1675 @Retention(RetentionPolicy.SOURCE)
Jeff Sharkeyce8db992017-12-13 20:05:05 -07001676 @IntDef(flag = true, prefix = { "LOCK_TASK_FEATURE_" }, value = {
1677 LOCK_TASK_FEATURE_NONE,
1678 LOCK_TASK_FEATURE_SYSTEM_INFO,
1679 LOCK_TASK_FEATURE_NOTIFICATIONS,
1680 LOCK_TASK_FEATURE_HOME,
1681 LOCK_TASK_FEATURE_RECENTS,
1682 LOCK_TASK_FEATURE_GLOBAL_ACTIONS,
1683 LOCK_TASK_FEATURE_KEYGUARD
1684 })
Charles Hee078db72017-10-19 18:03:20 +01001685 public @interface LockTaskFeature {}
1686
1687 /**
Makoto Onukifc73d792017-03-22 14:22:35 -07001688 * Service action: Action for a service that device owner and profile owner can optionally
1689 * own. If a device owner or a profile owner has such a service, the system tries to keep
1690 * a bound connection to it, in order to keep their process always running.
Makoto Onukife739702017-04-25 13:26:21 -07001691 * The service must be protected with the {@link android.Manifest.permission#BIND_DEVICE_ADMIN}
1692 * permission.
Makoto Onukifc73d792017-03-22 14:22:35 -07001693 */
1694 @SdkConstant(SdkConstantType.SERVICE_ACTION)
1695 public static final String ACTION_DEVICE_ADMIN_SERVICE
1696 = "android.app.action.DEVICE_ADMIN_SERVICE";
1697
Eran Messeri94d56762017-12-21 20:50:54 +00001698 /** @hide */
1699 @Retention(RetentionPolicy.SOURCE)
1700 @IntDef(flag = true, prefix = {"ID_TYPE_"}, value = {
1701 ID_TYPE_BASE_INFO,
1702 ID_TYPE_SERIAL,
1703 ID_TYPE_IMEI,
1704 ID_TYPE_MEID
1705 })
1706 public @interface AttestationIdType {}
1707
1708 /**
1709 * Specifies that the device should attest its manufacturer details. For use with
1710 * {@link #generateKeyPair}.
1711 *
1712 * @see #generateKeyPair
1713 */
1714 public static final int ID_TYPE_BASE_INFO = 1;
1715
1716 /**
1717 * Specifies that the device should attest its serial number. For use with
1718 * {@link #generateKeyPair}.
1719 *
1720 * @see #generateKeyPair
1721 */
1722 public static final int ID_TYPE_SERIAL = 2;
1723
1724 /**
1725 * Specifies that the device should attest its IMEI. For use with {@link #generateKeyPair}.
1726 *
1727 * @see #generateKeyPair
1728 */
1729 public static final int ID_TYPE_IMEI = 4;
1730
1731 /**
1732 * Specifies that the device should attest its MEID. For use with {@link #generateKeyPair}.
1733 *
1734 * @see #generateKeyPair
1735 */
1736 public static final int ID_TYPE_MEID = 8;
1737
Makoto Onukifc73d792017-03-22 14:22:35 -07001738 /**
arangelov8bae4ea2017-12-20 20:26:46 +00001739 * Broadcast action: sent when the profile owner is set, changed or cleared.
1740 *
1741 * This broadcast is sent only to the user managed by the new profile owner.
1742 * @see DevicePolicyManager#transferOwnership(ComponentName, ComponentName, PersistableBundle)
1743 */
1744 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1745 public static final String ACTION_PROFILE_OWNER_CHANGED =
1746 "android.app.action.PROFILE_OWNER_CHANGED";
1747
1748 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001749 * Return true if the given administrator component is currently active (enabled) in the system.
1750 *
1751 * @param admin The administrator component to check for.
1752 * @return {@code true} if {@code admin} is currently enabled in the system, {@code false}
1753 * otherwise
Dianne Hackbornd6847842010-01-12 18:14:19 -08001754 */
Robin Lee25e26452015-06-02 09:56:29 -07001755 public boolean isAdminActive(@NonNull ComponentName admin) {
Charles He8c760562016-10-25 16:36:53 +01001756 throwIfParentInstance("isAdminActive");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001757 return isAdminActiveAsUser(admin, myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001758 }
1759
1760 /**
1761 * @see #isAdminActive(ComponentName)
1762 * @hide
1763 */
Robin Lee25e26452015-06-02 09:56:29 -07001764 public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001765 if (mService != null) {
1766 try {
Robin Lee25e26452015-06-02 09:56:29 -07001767 return mService.isAdminActive(admin, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001768 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001769 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001770 }
1771 }
1772 return false;
1773 }
Charles Hedea0c3b2017-01-13 10:04:12 +00001774
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001775 /**
1776 * Return true if the given administrator component is currently being removed
1777 * for the user.
1778 * @hide
1779 */
Robin Lee25e26452015-06-02 09:56:29 -07001780 public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) {
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001781 if (mService != null) {
1782 try {
Robin Lee25e26452015-06-02 09:56:29 -07001783 return mService.isRemovingAdmin(admin, userId);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001784 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001785 throw e.rethrowFromSystemServer();
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001786 }
1787 }
1788 return false;
1789 }
1790
Dianne Hackbornd6847842010-01-12 18:14:19 -08001791 /**
Robin Lee25e26452015-06-02 09:56:29 -07001792 * Return a list of all currently active device administrators' component
1793 * names. If there are no administrators {@code null} may be
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001794 * returned.
1795 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07001796 public @Nullable List<ComponentName> getActiveAdmins() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001797 throwIfParentInstance("getActiveAdmins");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001798 return getActiveAdminsAsUser(myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001799 }
1800
1801 /**
1802 * @see #getActiveAdmins()
1803 * @hide
1804 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07001805 public @Nullable List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001806 if (mService != null) {
1807 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001808 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001809 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001810 throw e.rethrowFromSystemServer();
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001811 }
1812 }
1813 return null;
1814 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001815
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001816 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001817 * Used by package administration code to determine if a package can be stopped
1818 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001819 * @hide
1820 */
David Ouyang3a83a332017-01-11 16:36:40 -08001821 @SystemApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06001822 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001823 public boolean packageHasActiveAdmins(String packageName) {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001824 return packageHasActiveAdmins(packageName, myUserId());
1825 }
1826
1827 /**
1828 * Used by package administration code to determine if a package can be stopped
1829 * or uninstalled.
1830 * @hide
1831 */
1832 public boolean packageHasActiveAdmins(String packageName, int userId) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001833 if (mService != null) {
1834 try {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001835 return mService.packageHasActiveAdmins(packageName, userId);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001836 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001837 throw e.rethrowFromSystemServer();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001838 }
1839 }
1840 return false;
1841 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001842
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001843 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001844 * Remove a current administration component. This can only be called
1845 * by the application that owns the administration component; if you
1846 * try to remove someone else's component, a security exception will be
1847 * thrown.
Esteban Talavera552a5612016-02-19 17:02:24 +00001848 *
1849 * <p>Note that the operation is not synchronous and the admin might still be active (as
1850 * indicated by {@link #getActiveAdmins()}) by the time this method returns.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001851 *
1852 * @param admin The administration compononent to remove.
1853 * @throws SecurityException if the caller is not in the owner application of {@code admin}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001854 */
Robin Lee25e26452015-06-02 09:56:29 -07001855 public void removeActiveAdmin(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001856 throwIfParentInstance("removeActiveAdmin");
Dianne Hackbornd6847842010-01-12 18:14:19 -08001857 if (mService != null) {
1858 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001859 mService.removeActiveAdmin(admin, myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001860 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001861 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001862 }
1863 }
1864 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001865
Dianne Hackbornd6847842010-01-12 18:14:19 -08001866 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001867 * Returns true if an administrator has been granted a particular device policy. This can be
1868 * used to check whether the administrator was activated under an earlier set of policies, but
1869 * requires additional policies after an upgrade.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001870 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001871 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be an
1872 * active administrator, or an exception will be thrown.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001873 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001874 * @throws SecurityException if {@code admin} is not an active administrator.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001875 */
Robin Lee25e26452015-06-02 09:56:29 -07001876 public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001877 throwIfParentInstance("hasGrantedPolicy");
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001878 if (mService != null) {
1879 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001880 return mService.hasGrantedPolicy(admin, usesPolicy, myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001881 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001882 throw e.rethrowFromSystemServer();
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001883 }
1884 }
1885 return false;
1886 }
1887
1888 /**
Clara Bayarria1771112015-12-18 16:29:18 +00001889 * Returns true if the Profile Challenge is available to use for the given profile user.
1890 *
1891 * @hide
1892 */
1893 public boolean isSeparateProfileChallengeAllowed(int userHandle) {
1894 if (mService != null) {
1895 try {
1896 return mService.isSeparateProfileChallengeAllowed(userHandle);
1897 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001898 throw e.rethrowFromSystemServer();
Clara Bayarria1771112015-12-18 16:29:18 +00001899 }
1900 }
1901 return false;
1902 }
1903
1904 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001905 * Constant for {@link #setPasswordQuality}: the policy has no requirements
1906 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001907 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001908 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001909 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001910
Dianne Hackbornd6847842010-01-12 18:14:19 -08001911 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -07001912 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
1913 * recognition technology. This implies technologies that can recognize the identity of
1914 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
1915 * Note that quality constants are ordered so that higher values are more restrictive.
1916 */
1917 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
1918
1919 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001920 * Constant for {@link #setPasswordQuality}: the policy requires some kind
Benjamin Franzc6a96532015-06-16 11:23:38 +01001921 * of password or pattern, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001922 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001923 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001924 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001925
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001926 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001927 * Constant for {@link #setPasswordQuality}: the user must have entered a
1928 * password containing at least numeric characters. Note that quality
1929 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001930 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001931 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001932
Dianne Hackbornd6847842010-01-12 18:14:19 -08001933 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001934 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -08001935 * password containing at least numeric characters with no repeating (4444)
1936 * or ordered (1234, 4321, 2468) sequences. Note that quality
1937 * constants are ordered so that higher values are more restrictive.
1938 */
1939 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
1940
1941 /**
1942 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001943 * password containing at least alphabetic (or other symbol) characters.
1944 * Note that quality constants are ordered so that higher values are more
1945 * restrictive.
1946 */
1947 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001948
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001949 /**
1950 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001951 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001952 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001953 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001954 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001955 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001956
Dianne Hackbornd6847842010-01-12 18:14:19 -08001957 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001958 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001959 * password containing at least a letter, a numerical digit and a special
1960 * symbol, by default. With this password quality, passwords can be
1961 * restricted to contain various sets of characters, like at least an
1962 * uppercase letter, etc. These are specified using various methods,
1963 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
1964 * that quality constants are ordered so that higher values are more
1965 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001966 */
1967 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
1968
1969 /**
Oleksandr Peletskyi0fdcd3d2016-01-13 16:49:56 +01001970 * Constant for {@link #setPasswordQuality}: the user is not allowed to
1971 * modify password. In case this password quality is set, the password is
1972 * managed by a profile owner. The profile owner can set any password,
1973 * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note
1974 * that quality constants are ordered so that higher values are more
1975 * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is
1976 * the highest.
1977 * @hide
1978 */
1979 public static final int PASSWORD_QUALITY_MANAGED = 0x80000;
1980
1981 /**
Makoto Onuki5e7e06702016-09-01 18:02:01 -07001982 * @hide
1983 *
1984 * adb shell dpm set-{device,profile}-owner will normally not allow installing an owner to
1985 * a user with accounts. {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED}
1986 * and {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} are the account features
1987 * used by authenticator to exempt their accounts from this:
1988 *
1989 * <ul>
1990 * <li>Non-test-only DO/PO still can't be installed when there are accounts.
1991 * <p>In order to make an apk test-only, add android:testOnly="true" to the
1992 * &lt;application&gt; tag in the manifest.
1993 *
1994 * <li>Test-only DO/PO can be installed even when there are accounts, as long as all the
1995 * accounts have the {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} feature.
1996 * Some authenticators claim to have any features, so to detect it, we also check
1997 * {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} and disallow installing
1998 * if any of the accounts have it.
1999 * </ul>
2000 */
Makoto Onuki47c203d2017-02-13 16:21:19 -08002001 @SystemApi
2002 @TestApi
Makoto Onuki5e7e06702016-09-01 18:02:01 -07002003 public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED =
2004 "android.account.DEVICE_OR_PROFILE_OWNER_ALLOWED";
2005
2006 /** @hide See {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} */
Makoto Onuki47c203d2017-02-13 16:21:19 -08002007 @SystemApi
2008 @TestApi
Makoto Onuki5e7e06702016-09-01 18:02:01 -07002009 public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED =
2010 "android.account.DEVICE_OR_PROFILE_OWNER_DISALLOWED";
2011
2012 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002013 * Called by an application that is administering the device to set the password restrictions it
2014 * is imposing. After setting this, the user will not be able to enter a new password that is
2015 * not at least as restrictive as what has been set. Note that the current password will remain
2016 * until the user has set a new one, so the change does not take place immediately. To prompt
2017 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
Esteban Talaverac1c83592016-02-17 17:56:15 +00002018 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after calling this method.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002019 * <p>
2020 * Quality constants are ordered so that higher values are more restrictive; thus the highest
2021 * requested quality constant (between the policy set here, the user's preference, and any other
2022 * considerations) is the one that is in effect.
2023 * <p>
2024 * The calling device admin must have requested
2025 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2026 * not, a security exception will be thrown.
2027 * <p>
2028 * This method can be called on the {@link DevicePolicyManager} instance returned by
2029 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2030 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002031 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002032 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002033 * @param quality The new desired quality. One of {@link #PASSWORD_QUALITY_UNSPECIFIED},
2034 * {@link #PASSWORD_QUALITY_SOMETHING}, {@link #PASSWORD_QUALITY_NUMERIC},
2035 * {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC},
2036 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} or {@link #PASSWORD_QUALITY_COMPLEX}.
2037 * @throws SecurityException if {@code admin} is not an active administrator or if {@code admin}
2038 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002039 */
Robin Lee25e26452015-06-02 09:56:29 -07002040 public void setPasswordQuality(@NonNull ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002041 if (mService != null) {
2042 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00002043 mService.setPasswordQuality(admin, quality, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002044 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002045 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002046 }
2047 }
2048 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002049
Dianne Hackbornd6847842010-01-12 18:14:19 -08002050 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002051 * Retrieve the current minimum password quality for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01002052 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00002053 * a separate challenge are not taken into account.
2054 *
2055 * <p>This method can be called on the {@link DevicePolicyManager} instance
2056 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2057 * restrictions on the parent profile.
2058 *
Robin Lee25e26452015-06-02 09:56:29 -07002059 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002060 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002061 */
Robin Lee25e26452015-06-02 09:56:29 -07002062 public int getPasswordQuality(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002063 return getPasswordQuality(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002064 }
2065
2066 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002067 public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002068 if (mService != null) {
2069 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00002070 return mService.getPasswordQuality(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002071 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002072 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002073 }
2074 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08002075 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -08002076 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002077
Dianne Hackbornd6847842010-01-12 18:14:19 -08002078 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002079 * Called by an application that is administering the device to set the minimum allowed password
2080 * length. After setting this, the user will not be able to enter a new password that is not at
2081 * least as restrictive as what has been set. Note that the current password will remain until
2082 * the user has set a new one, so the change does not take place immediately. To prompt the user
2083 * for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
2084 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
2085 * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC}
2086 * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC},
2087 * {@link #PASSWORD_QUALITY_ALPHANUMERIC}, or {@link #PASSWORD_QUALITY_COMPLEX} with
2088 * {@link #setPasswordQuality}.
2089 * <p>
2090 * The calling device admin must have requested
2091 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2092 * not, a security exception will be thrown.
2093 * <p>
2094 * This method can be called on the {@link DevicePolicyManager} instance returned by
2095 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2096 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002097 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002098 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002099 * @param length The new desired minimum password length. A value of 0 means there is no
2100 * restriction.
2101 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2102 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002103 */
Robin Lee25e26452015-06-02 09:56:29 -07002104 public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002105 if (mService != null) {
2106 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002107 mService.setPasswordMinimumLength(admin, length, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002108 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002109 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002110 }
2111 }
2112 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002113
Dianne Hackbornd6847842010-01-12 18:14:19 -08002114 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002115 * Retrieve the current minimum password length for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01002116 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00002117 * a separate challenge are not taken into account.
2118 *
2119 * <p>This method can be called on the {@link DevicePolicyManager} instance
2120 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2121 * restrictions on the parent profile.
2122 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01002123 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07002124 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002125 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002126 */
Robin Lee25e26452015-06-02 09:56:29 -07002127 public int getPasswordMinimumLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002128 return getPasswordMinimumLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002129 }
2130
2131 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002132 public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002133 if (mService != null) {
2134 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002135 return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002136 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002137 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002138 }
2139 }
2140 return 0;
2141 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002142
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002143 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002144 * Called by an application that is administering the device to set the minimum number of upper
2145 * case letters required in the password. After setting this, the user will not be able to enter
2146 * a new password that is not at least as restrictive as what has been set. Note that the
2147 * current password will remain until the user has set a new one, so the change does not take
2148 * place immediately. To prompt the user for a new password, use
2149 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
2150 * setting this value. This constraint is only imposed if the administrator has also requested
2151 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002152 * <p>
2153 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002154 * {@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.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002160 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002161 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2162 * @param length The new desired minimum number of upper case letters required in the password.
2163 * A value of 0 means there is no 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}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002166 */
Robin Lee25e26452015-06-02 09:56:29 -07002167 public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002168 if (mService != null) {
2169 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002170 mService.setPasswordMinimumUpperCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002171 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002172 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002173 }
2174 }
2175 }
2176
2177 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002178 * Retrieve the current number of upper case letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002179 * for a particular admin or all admins that set restrictions on this user and
Esteban Talaverac1c83592016-02-17 17:56:15 +00002180 * its participating profiles. Restrictions on profiles that have a separate challenge
2181 * are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01002182 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00002183 * {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002184 * and only applies when the password quality is
2185 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002186 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002187 * <p>This method can be called on the {@link DevicePolicyManager} instance
2188 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2189 * restrictions on the parent profile.
2190 *
Robin Lee25e26452015-06-02 09:56:29 -07002191 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002192 * aggregate all admins.
2193 * @return The minimum number of upper case letters required in the
2194 * password.
2195 */
Robin Lee25e26452015-06-02 09:56:29 -07002196 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002197 return getPasswordMinimumUpperCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002198 }
2199
2200 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002201 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002202 if (mService != null) {
2203 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002204 return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002205 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002206 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002207 }
2208 }
2209 return 0;
2210 }
2211
2212 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002213 * Called by an application that is administering the device to set the minimum number of lower
2214 * case letters required in the password. After setting this, the user will not be able to enter
2215 * a new password that is not at least as restrictive as what has been set. Note that the
2216 * current password will remain until the user has set a new one, so the change does not take
2217 * place immediately. To prompt the user for a new password, use
2218 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
2219 * setting this value. This constraint is only imposed if the administrator has also requested
2220 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002221 * <p>
2222 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002223 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2224 * not, a security exception will be thrown.
2225 * <p>
2226 * This method can be called on the {@link DevicePolicyManager} instance returned by
2227 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2228 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002229 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002230 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2231 * @param length The new desired minimum number of lower case letters required in the password.
2232 * A value of 0 means there is no restriction.
2233 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2234 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002235 */
Robin Lee25e26452015-06-02 09:56:29 -07002236 public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002237 if (mService != null) {
2238 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002239 mService.setPasswordMinimumLowerCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002240 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002241 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002242 }
2243 }
2244 }
2245
2246 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002247 * Retrieve the current number of lower case letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002248 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002249 * and its participating profiles. Restrictions on profiles that have
2250 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01002251 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00002252 * {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002253 * and only applies when the password quality is
2254 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002255 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002256 * <p>This method can be called on the {@link DevicePolicyManager} instance
2257 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2258 * restrictions on the parent profile.
2259 *
Robin Lee25e26452015-06-02 09:56:29 -07002260 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002261 * aggregate all admins.
2262 * @return The minimum number of lower case letters required in the
2263 * password.
2264 */
Robin Lee25e26452015-06-02 09:56:29 -07002265 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002266 return getPasswordMinimumLowerCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002267 }
2268
2269 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002270 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002271 if (mService != null) {
2272 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002273 return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002274 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002275 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002276 }
2277 }
2278 return 0;
2279 }
2280
2281 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002282 * Called by an application that is administering the device to set the minimum number of
2283 * letters required in the password. After setting this, the user will not be able to enter a
2284 * new password that is not at least as restrictive as what has been set. Note that the current
2285 * password will remain until the user has set a new one, so the change does not take place
2286 * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
2287 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
2288 * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
2289 * {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002290 * <p>
2291 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002292 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2293 * not, a security exception will be thrown.
2294 * <p>
2295 * This method can be called on the {@link DevicePolicyManager} instance returned by
2296 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2297 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002298 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002299 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2300 * @param length The new desired minimum number of letters required in the password. A value of
2301 * 0 means there is no restriction.
2302 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2303 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002304 */
Robin Lee25e26452015-06-02 09:56:29 -07002305 public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002306 if (mService != null) {
2307 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002308 mService.setPasswordMinimumLetters(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002309 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002310 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002311 }
2312 }
2313 }
2314
2315 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002316 * Retrieve the current number of letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002317 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002318 * and its participating profiles. Restrictions on profiles that have
2319 * a separate challenge are not taken into account.
2320 * This is the same value as set by
2321 * {@link #setPasswordMinimumLetters(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002322 * and only applies when the password quality is
2323 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002324 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002325 * <p>This method can be called on the {@link DevicePolicyManager} instance
2326 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2327 * restrictions on the parent profile.
2328 *
Robin Lee25e26452015-06-02 09:56:29 -07002329 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002330 * aggregate all admins.
2331 * @return The minimum number of letters required in the password.
2332 */
Robin Lee25e26452015-06-02 09:56:29 -07002333 public int getPasswordMinimumLetters(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002334 return getPasswordMinimumLetters(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002335 }
2336
2337 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002338 public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002339 if (mService != null) {
2340 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002341 return mService.getPasswordMinimumLetters(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002342 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002343 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002344 }
2345 }
2346 return 0;
2347 }
2348
2349 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002350 * Called by an application that is administering the device to set the minimum number of
2351 * numerical digits required in the password. After setting this, the user will not be able to
2352 * enter a new password that is not at least as restrictive as what has been set. Note that the
2353 * current password will remain until the user has set a new one, so the change does not take
2354 * place immediately. To prompt the user for a new password, use
2355 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
2356 * setting this value. This constraint is only imposed if the administrator has also requested
2357 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002358 * <p>
2359 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002360 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2361 * not, a security exception will be thrown.
2362 * <p>
2363 * This method can be called on the {@link DevicePolicyManager} instance returned by
2364 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2365 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002366 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002367 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2368 * @param length The new desired minimum number of numerical digits required in the password. A
2369 * value of 0 means there is no restriction.
2370 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2371 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002372 */
Robin Lee25e26452015-06-02 09:56:29 -07002373 public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002374 if (mService != null) {
2375 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002376 mService.setPasswordMinimumNumeric(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002377 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002378 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002379 }
2380 }
2381 }
2382
2383 /**
2384 * Retrieve the current number of numerical digits required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002385 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002386 * and its participating profiles. Restrictions on profiles that have
2387 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01002388 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00002389 * {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002390 * and only applies when the password quality is
2391 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002392 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002393 * <p>This method can be called on the {@link DevicePolicyManager} instance
2394 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2395 * restrictions on the parent profile.
2396 *
Robin Lee25e26452015-06-02 09:56:29 -07002397 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002398 * aggregate all admins.
2399 * @return The minimum number of numerical digits required in the password.
2400 */
Robin Lee25e26452015-06-02 09:56:29 -07002401 public int getPasswordMinimumNumeric(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002402 return getPasswordMinimumNumeric(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002403 }
2404
2405 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002406 public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002407 if (mService != null) {
2408 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002409 return mService.getPasswordMinimumNumeric(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002410 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002411 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002412 }
2413 }
2414 return 0;
2415 }
2416
2417 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002418 * Called by an application that is administering the device to set the minimum number of
2419 * symbols required in the password. After setting this, the user will not be able to enter a
2420 * new password that is not at least as restrictive as what has been set. Note that the current
2421 * password will remain until the user has set a new one, so the change does not take place
2422 * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
2423 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
2424 * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
2425 * {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002426 * <p>
2427 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002428 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2429 * not, a security exception will be thrown.
2430 * <p>
2431 * This method can be called on the {@link DevicePolicyManager} instance returned by
2432 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2433 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002434 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002435 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2436 * @param length The new desired minimum number of symbols required in the password. A value of
2437 * 0 means there is no restriction.
2438 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2439 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002440 */
Robin Lee25e26452015-06-02 09:56:29 -07002441 public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002442 if (mService != null) {
2443 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002444 mService.setPasswordMinimumSymbols(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002445 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002446 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002447 }
2448 }
2449 }
2450
2451 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002452 * Retrieve the current number of symbols required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002453 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002454 * and its participating profiles. Restrictions on profiles that have
2455 * a separate challenge are not taken into account. This is the same value as
2456 * set by {@link #setPasswordMinimumSymbols(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 symbols required in the password.
2467 */
Robin Lee25e26452015-06-02 09:56:29 -07002468 public int getPasswordMinimumSymbols(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002469 return getPasswordMinimumSymbols(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002470 }
2471
2472 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002473 public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002474 if (mService != null) {
2475 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002476 return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002477 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002478 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002479 }
2480 }
2481 return 0;
2482 }
2483
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002484 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002485 * Called by an application that is administering the device to set the minimum number of
2486 * non-letter characters (numerical digits or symbols) required in the password. After setting
2487 * this, the user will not be able to enter a new password that is not at least as restrictive
2488 * as what has been set. Note that the current password will remain until the user has set a new
2489 * one, so the change does not take place immediately. To prompt the user for a new password,
2490 * use {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
2491 * setting this value. This constraint is only imposed if the administrator has also requested
2492 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002493 * <p>
2494 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002495 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2496 * not, a security exception will be thrown.
2497 * <p>
2498 * This method can be called on the {@link DevicePolicyManager} instance returned by
2499 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2500 * profile.
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002501 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002502 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2503 * @param length The new desired minimum number of letters required in the password. A value of
2504 * 0 means there is no restriction.
2505 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2506 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002507 */
Robin Lee25e26452015-06-02 09:56:29 -07002508 public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002509 if (mService != null) {
2510 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002511 mService.setPasswordMinimumNonLetter(admin, length, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002512 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002513 throw e.rethrowFromSystemServer();
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002514 }
2515 }
2516 }
2517
2518 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002519 * Retrieve the current number of non-letter characters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002520 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002521 * and its participating profiles. Restrictions on profiles that have
2522 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01002523 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00002524 * {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002525 * and only applies when the password quality is
2526 * {@link #PASSWORD_QUALITY_COMPLEX}.
2527 *
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 Lopyrevc8577402010-06-04 17:15:02 -07002533 * aggregate all admins.
2534 * @return The minimum number of letters required in the password.
2535 */
Robin Lee25e26452015-06-02 09:56:29 -07002536 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002537 return getPasswordMinimumNonLetter(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002538 }
2539
2540 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002541 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002542 if (mService != null) {
2543 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002544 return mService.getPasswordMinimumNonLetter(admin, userHandle, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002545 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002546 throw e.rethrowFromSystemServer();
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002547 }
2548 }
2549 return 0;
2550 }
2551
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002552 /**
2553 * Called by an application that is administering the device to set the length of the password
2554 * history. After setting this, the user will not be able to enter a new password that is the
2555 * same as any password in the history. Note that the current password will remain until the
2556 * user has set a new one, so the change does not take place immediately. To prompt the user for
2557 * a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
2558 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
2559 * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC}
2560 * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX} {@link #PASSWORD_QUALITY_ALPHABETIC}, or
2561 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} with {@link #setPasswordQuality}.
2562 * <p>
2563 * The calling device admin must have requested
2564 * {@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.
2570 *
2571 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2572 * @param length The new desired length of password history. A value of 0 means there is no
2573 * 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}
2576 */
Robin Lee25e26452015-06-02 09:56:29 -07002577 public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002578 if (mService != null) {
2579 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002580 mService.setPasswordHistoryLength(admin, length, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002581 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002582 throw e.rethrowFromSystemServer();
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002583 }
2584 }
2585 }
2586
2587 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002588 * Called by a device admin to set the password expiration timeout. Calling this method will
2589 * restart the countdown for password expiration for the given admin, as will changing the
2590 * device password (for all admins).
2591 * <p>
2592 * The provided timeout is the time delta in ms and will be added to the current time. For
2593 * example, to have the password expire 5 days from now, timeout would be 5 * 86400 * 1000 =
2594 * 432000000 ms for timeout.
2595 * <p>
2596 * To disable password expiration, a value of 0 may be used for timeout.
2597 * <p>
2598 * The calling device admin must have requested
2599 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this method; if it has
2600 * not, a security exception will be thrown.
2601 * <p>
2602 * Note that setting the password will automatically reset the expiration time for all active
2603 * admins. Active admins do not need to explicitly call this method in that case.
2604 * <p>
2605 * This method can be called on the {@link DevicePolicyManager} instance returned by
2606 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2607 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002608 *
Jim Millera4e28d12010-11-08 16:15:47 -08002609 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002610 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0 means
2611 * there is no restriction (unlimited).
2612 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2613 * does not use {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD}
Jim Millera4e28d12010-11-08 16:15:47 -08002614 */
Robin Lee25e26452015-06-02 09:56:29 -07002615 public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) {
Jim Millera4e28d12010-11-08 16:15:47 -08002616 if (mService != null) {
2617 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002618 mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08002619 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002620 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08002621 }
2622 }
2623 }
2624
2625 /**
Jim Miller6b857682011-02-16 16:27:41 -08002626 * Get the password expiration timeout for the given admin. The expiration timeout is the
2627 * recurring expiration timeout provided in the call to
2628 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
Esteban Talaverac1c83592016-02-17 17:56:15 +00002629 * aggregate of all participating policy administrators if {@code admin} is null. Admins that
2630 * have set restrictions on profiles that have a separate challenge are not taken into account.
2631 *
2632 * <p>This method can be called on the {@link DevicePolicyManager} instance
2633 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2634 * restrictions on the parent profile.
Jim Millera4e28d12010-11-08 16:15:47 -08002635 *
Robin Lee25e26452015-06-02 09:56:29 -07002636 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08002637 * @return The timeout for the given admin or the minimum of all timeouts
2638 */
Robin Lee25e26452015-06-02 09:56:29 -07002639 public long getPasswordExpirationTimeout(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08002640 if (mService != null) {
2641 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002642 return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08002643 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002644 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08002645 }
2646 }
2647 return 0;
2648 }
2649
2650 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002651 * Get the current password expiration time for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01002652 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00002653 * a separate challenge are not taken into account. If admin is {@code null}, then a composite
2654 * of all expiration times is returned - which will be the minimum of all of them.
2655 *
2656 * <p>This method can be called on the {@link DevicePolicyManager} instance
2657 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2658 * the password expiration for the parent profile.
Jim Millera4e28d12010-11-08 16:15:47 -08002659 *
Robin Lee25e26452015-06-02 09:56:29 -07002660 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002661 * @return The password expiration time, in milliseconds since epoch.
Jim Millera4e28d12010-11-08 16:15:47 -08002662 */
Robin Lee25e26452015-06-02 09:56:29 -07002663 public long getPasswordExpiration(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08002664 if (mService != null) {
2665 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002666 return mService.getPasswordExpiration(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08002667 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002668 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08002669 }
2670 }
2671 return 0;
2672 }
2673
2674 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002675 * Retrieve the current password history length for a particular admin or all admins that
Rubin Xud3609d42016-07-13 18:32:57 +01002676 * set restrictions on this user and its participating profiles. Restrictions on profiles that
Esteban Talaverac1c83592016-02-17 17:56:15 +00002677 * have a separate challenge are not taken into account.
2678 *
2679 * <p>This method can be called on the {@link DevicePolicyManager} instance
2680 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2681 * restrictions on the parent profile.
2682 *
Robin Lee25e26452015-06-02 09:56:29 -07002683 * @param admin The name of the admin component to check, or {@code null} to aggregate
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002684 * all admins.
2685 * @return The length of the password history
2686 */
Robin Lee25e26452015-06-02 09:56:29 -07002687 public int getPasswordHistoryLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002688 return getPasswordHistoryLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002689 }
2690
2691 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002692 public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002693 if (mService != null) {
2694 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002695 return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002696 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002697 throw e.rethrowFromSystemServer();
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002698 }
2699 }
2700 return 0;
2701 }
2702
Dianne Hackbornd6847842010-01-12 18:14:19 -08002703 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08002704 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08002705 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08002706 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08002707 * @return Returns the maximum length that the user can enter.
2708 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08002709 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08002710 // Kind-of arbitrary.
2711 return 16;
2712 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002713
Dianne Hackborn254cb442010-01-27 19:23:59 -08002714 /**
Alexandru-Andrei Rotaru7f31bb02017-09-07 16:29:48 +01002715 * The maximum number of characters allowed in the password blacklist.
2716 */
2717 private static final int PASSWORD_BLACKLIST_CHARACTER_LIMIT = 128 * 1000;
2718
2719 /**
2720 * Throws an exception if the password blacklist is too large.
2721 *
2722 * @hide
2723 */
2724 public static void enforcePasswordBlacklistSize(List<String> blacklist) {
2725 if (blacklist == null) {
2726 return;
2727 }
2728 long characterCount = 0;
2729 for (final String item : blacklist) {
2730 characterCount += item.length();
2731 }
2732 if (characterCount > PASSWORD_BLACKLIST_CHARACTER_LIMIT) {
2733 throw new IllegalArgumentException("128 thousand blacklist character limit exceeded by "
2734 + (characterCount - PASSWORD_BLACKLIST_CHARACTER_LIMIT) + " characters");
2735 }
2736 }
2737
2738 /**
2739 * Called by an application that is administering the device to blacklist passwords.
2740 * <p>
2741 * Any blacklisted password or PIN is prevented from being enrolled by the user or the admin.
2742 * Note that the match against the blacklist is case insensitive. The blacklist applies for all
2743 * password qualities requested by {@link #setPasswordQuality} however it is not taken into
2744 * consideration by {@link #isActivePasswordSufficient}.
2745 * <p>
2746 * The blacklist can be cleared by passing {@code null} or an empty list. The blacklist is
2747 * given a name that is used to track which blacklist is currently set by calling {@link
2748 * #getPasswordBlacklistName}. If the blacklist is being cleared, the name is ignored and {@link
2749 * #getPasswordBlacklistName} will return {@code null}. The name can only be {@code null} when
2750 * the blacklist is being cleared.
2751 * <p>
2752 * The blacklist is limited to a total of 128 thousand characters rather than limiting to a
2753 * number of entries.
2754 * <p>
2755 * This method can be called on the {@link DevicePolicyManager} instance returned by
2756 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2757 * profile.
2758 *
2759 * @param admin the {@link DeviceAdminReceiver} this request is associated with
2760 * @param name name to associate with the blacklist
2761 * @param blacklist list of passwords to blacklist or {@code null} to clear the blacklist
2762 * @return whether the new blacklist was successfully installed
2763 * @throws SecurityException if {@code admin} is not a device or profile owner
2764 * @throws IllegalArgumentException if the blacklist surpasses the character limit
2765 * @throws NullPointerException if {@code name} is {@code null} when setting a non-empty list
2766 *
2767 * @see #getPasswordBlacklistName
2768 * @see #isActivePasswordSufficient
2769 * @see #resetPasswordWithToken
Alexandru-Andrei Rotaru7f31bb02017-09-07 16:29:48 +01002770 */
2771 public boolean setPasswordBlacklist(@NonNull ComponentName admin, @Nullable String name,
2772 @Nullable List<String> blacklist) {
2773 enforcePasswordBlacklistSize(blacklist);
2774
2775 try {
2776 return mService.setPasswordBlacklist(admin, name, blacklist, mParentInstance);
2777 } catch (RemoteException re) {
2778 throw re.rethrowFromSystemServer();
2779 }
2780 }
2781
2782 /**
2783 * Get the name of the password blacklist set by the given admin.
2784 *
2785 * @param admin the {@link DeviceAdminReceiver} this request is associated with
2786 * @return the name of the blacklist or {@code null} if no blacklist is set
2787 *
2788 * @see #setPasswordBlacklist
Alexandru-Andrei Rotaru7f31bb02017-09-07 16:29:48 +01002789 */
2790 public @Nullable String getPasswordBlacklistName(@NonNull ComponentName admin) {
2791 try {
2792 return mService.getPasswordBlacklistName(admin, myUserId(), mParentInstance);
2793 } catch (RemoteException re) {
2794 throw re.rethrowFromSystemServer();
2795 }
2796 }
2797
2798 /**
2799 * Test if a given password is blacklisted.
2800 *
2801 * @param userId the user to valiate for
2802 * @param password the password to check against the blacklist
2803 * @return whether the password is blacklisted
2804 *
2805 * @see #setPasswordBlacklist
2806 *
2807 * @hide
2808 */
2809 @RequiresPermission(android.Manifest.permission.TEST_BLACKLISTED_PASSWORD)
2810 public boolean isPasswordBlacklisted(@UserIdInt int userId, @NonNull String password) {
2811 try {
2812 return mService.isPasswordBlacklisted(userId, password);
2813 } catch (RemoteException re) {
2814 throw re.rethrowFromSystemServer();
2815 }
2816 }
2817
2818 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002819 * Determine whether the current password the user has set is sufficient to meet the policy
2820 * requirements (e.g. quality, minimum length) that have been requested by the admins of this
2821 * user and its participating profiles. Restrictions on profiles that have a separate challenge
Alexandru-Andrei Rotaru7f31bb02017-09-07 16:29:48 +01002822 * are not taken into account. The user must be unlocked in order to perform the check. The
2823 * password blacklist is not considered when checking sufficiency.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002824 * <p>
2825 * The calling device admin must have requested
2826 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2827 * not, a security exception will be thrown.
2828 * <p>
2829 * This method can be called on the {@link DevicePolicyManager} instance returned by
2830 * {@link #getParentProfileInstance(ComponentName)} in order to determine if the password set on
2831 * the parent profile is sufficient.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002832 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01002833 * @return Returns true if the password meets the current requirements, else false.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002834 * @throws SecurityException if the calling application does not own an active administrator
2835 * that uses {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Rubin Xu7cf45092017-08-28 11:47:35 +01002836 * @throws IllegalStateException if the user is not unlocked.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002837 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002838 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002839 if (mService != null) {
2840 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00002841 return mService.isActivePasswordSufficient(myUserId(), mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002842 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002843 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002844 }
2845 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002846 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08002847 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002848
Dianne Hackbornd6847842010-01-12 18:14:19 -08002849 /**
Pavel Grafovc4f87e92017-10-26 16:34:25 +01002850 * When called by a profile owner of a managed profile returns true if the profile uses unified
2851 * challenge with its parent user.
2852 *
2853 * <strong>Note: This method is not concerned with password quality and will return false if
2854 * the profile has empty password as a separate challenge.
2855 *
2856 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2857 * @throws SecurityException if {@code admin} is not a profile owner of a managed profile.
2858 * @see UserManager#DISALLOW_UNIFIED_PASSWORD
2859 */
2860 public boolean isUsingUnifiedPassword(@NonNull ComponentName admin) {
Pavel Grafov3b27ed02017-12-18 18:02:47 +00002861 throwIfParentInstance("isUsingUnifiedPassword");
Pavel Grafovc4f87e92017-10-26 16:34:25 +01002862 if (mService != null) {
2863 try {
2864 return mService.isUsingUnifiedPassword(admin);
2865 } catch (RemoteException e) {
2866 throw e.rethrowFromSystemServer();
2867 }
2868 }
2869 return true;
2870 }
2871
2872 /**
Clara Bayarrid7693912016-01-22 17:26:31 +00002873 * Determine whether the current profile password the user has set is sufficient
Esteban Talaverac1c83592016-02-17 17:56:15 +00002874 * to meet the policy requirements (e.g. quality, minimum length) that have been
Clara Bayarrid7693912016-01-22 17:26:31 +00002875 * requested by the admins of the parent user and its profiles.
2876 *
2877 * @param userHandle the userId of the profile to check the password for.
2878 * @return Returns true if the password would meet the current requirements, else false.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002879 * @throws SecurityException if {@code userHandle} is not a managed profile.
Clara Bayarrid7693912016-01-22 17:26:31 +00002880 * @hide
2881 */
2882 public boolean isProfileActivePasswordSufficientForParent(int userHandle) {
2883 if (mService != null) {
2884 try {
2885 return mService.isProfileActivePasswordSufficientForParent(userHandle);
2886 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002887 throw e.rethrowFromSystemServer();
Clara Bayarrid7693912016-01-22 17:26:31 +00002888 }
2889 }
2890 return false;
2891 }
2892
2893 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002894 * Retrieve the number of times the user has failed at entering a password since that last
2895 * successful password entry.
2896 * <p>
2897 * This method can be called on the {@link DevicePolicyManager} instance returned by
2898 * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the number of failed
2899 * password attemts for the parent user.
2900 * <p>
2901 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN}
2902 * to be able to call this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002903 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002904 * @return The number of times user has entered an incorrect password since the last correct
2905 * password entry.
2906 * @throws SecurityException if the calling application does not own an active administrator
2907 * that uses {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002908 */
2909 public int getCurrentFailedPasswordAttempts() {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00002910 return getCurrentFailedPasswordAttempts(myUserId());
2911 }
2912
2913 /**
2914 * Retrieve the number of times the given user has failed at entering a
2915 * password since that last successful password entry.
2916 *
2917 * <p>The calling device admin must have requested
2918 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call this method; if it has
2919 * not and it is not the system uid, a security exception will be thrown.
2920 *
2921 * @hide
2922 */
2923 public int getCurrentFailedPasswordAttempts(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002924 if (mService != null) {
2925 try {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00002926 return mService.getCurrentFailedPasswordAttempts(userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002927 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002928 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002929 }
2930 }
2931 return -1;
2932 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002933
2934 /**
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002935 * Queries whether {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002936 *
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002937 * @return true if RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002938 * @hide
2939 */
2940 public boolean getDoNotAskCredentialsOnBoot() {
2941 if (mService != null) {
2942 try {
2943 return mService.getDoNotAskCredentialsOnBoot();
2944 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002945 throw e.rethrowFromSystemServer();
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002946 }
2947 }
2948 return false;
2949 }
2950
2951 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002952 * Setting this to a value greater than zero enables a built-in policy that will perform a
2953 * device or profile wipe after too many incorrect device-unlock passwords have been entered.
2954 * This built-in policy combines watching for failed passwords and wiping the device, and
2955 * requires that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002956 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002957 * <p>
2958 * To implement any other policy (e.g. wiping data for a particular application only, erasing or
2959 * revoking credentials, or reporting the failure to a server), you should implement
2960 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} instead. Do not
2961 * use this API, because if the maximum count is reached, the device or profile will be wiped
2962 * immediately, and your callback will not be invoked.
2963 * <p>
2964 * This method can be called on the {@link DevicePolicyManager} instance returned by
2965 * {@link #getParentProfileInstance(ComponentName)} in order to set a value on the parent
2966 * profile.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002967 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002968 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002969 * @param num The number of failed password attempts at which point the device or profile will
2970 * be wiped.
2971 * @throws SecurityException if {@code admin} is not an active administrator or does not use
2972 * both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
2973 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002974 */
Robin Lee25e26452015-06-02 09:56:29 -07002975 public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002976 if (mService != null) {
2977 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002978 mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002979 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002980 throw e.rethrowFromSystemServer();
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002981 }
2982 }
2983 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002984
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002985 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002986 * Retrieve the current maximum number of login attempts that are allowed before the device
Rubin Xud3609d42016-07-13 18:32:57 +01002987 * or profile is wiped, for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002988 * and its participating profiles. Restrictions on profiles that have a separate challenge are
2989 * not taken into account.
2990 *
2991 * <p>This method can be called on the {@link DevicePolicyManager} instance
2992 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2993 * the value for the parent profile.
2994 *
Robin Lee25e26452015-06-02 09:56:29 -07002995 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002996 * all admins.
2997 */
Robin Lee25e26452015-06-02 09:56:29 -07002998 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002999 return getMaximumFailedPasswordsForWipe(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003000 }
3001
3002 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003003 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08003004 if (mService != null) {
3005 try {
Esteban Talavera62399912016-01-11 15:37:55 +00003006 return mService.getMaximumFailedPasswordsForWipe(
3007 admin, userHandle, mParentInstance);
Dianne Hackborn254cb442010-01-27 19:23:59 -08003008 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003009 throw e.rethrowFromSystemServer();
Dianne Hackborn254cb442010-01-27 19:23:59 -08003010 }
3011 }
3012 return 0;
3013 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003014
Dianne Hackborn254cb442010-01-27 19:23:59 -08003015 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07003016 * Returns the profile with the smallest maximum failed passwords for wipe,
3017 * for the given user. So for primary user, it might return the primary or
3018 * a managed profile. For a secondary user, it would be the same as the
3019 * user passed in.
3020 * @hide Used only by Keyguard
3021 */
3022 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
3023 if (mService != null) {
3024 try {
Esteban Talavera62399912016-01-11 15:37:55 +00003025 return mService.getProfileWithMinimumFailedPasswordsForWipe(
3026 userHandle, mParentInstance);
Amith Yamasani3a3d2122014-10-29 11:41:31 -07003027 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003028 throw e.rethrowFromSystemServer();
Amith Yamasani3a3d2122014-10-29 11:41:31 -07003029 }
3030 }
3031 return UserHandle.USER_NULL;
3032 }
3033
3034 /**
Benjamin Miller1aed7882017-08-15 18:04:20 +02003035 * Flag for {@link #resetPasswordWithToken} and {@link #resetPassword}: don't allow other admins
3036 * to change the password again until the user has entered it.
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08003037 */
3038 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003039
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08003040 /**
Benjamin Miller1aed7882017-08-15 18:04:20 +02003041 * Flag for {@link #resetPasswordWithToken} and {@link #resetPassword}: don't ask for user
3042 * credentials on device boot.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04003043 * If the flag is set, the device can be booted without asking for user password.
3044 * The absence of this flag does not change the current boot requirements. This flag
3045 * can be set by the device owner only. If the app is not the device owner, the flag
3046 * is ignored. Once the flag is set, it cannot be reverted back without resetting the
3047 * device to factory defaults.
3048 */
Craig Lafayette4e401fa2015-05-07 10:24:02 -04003049 public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002;
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04003050
3051 /**
Benjamin Miller1aed7882017-08-15 18:04:20 +02003052 * Force a new password for device unlock (the password needed to access the entire device) or
3053 * the work profile challenge on the current user. This takes effect immediately.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003054 * <p>
Rubin Xuaab7a412016-12-30 21:13:29 +00003055 * <em>For device owner and profile owners targeting SDK level
3056 * {@link android.os.Build.VERSION_CODES#O} or above, this API is no longer available and will
3057 * throw {@link SecurityException}. Please use the new API {@link #resetPasswordWithToken}
3058 * instead. </em>
3059 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003060 * <em>Note: This API has been limited as of {@link android.os.Build.VERSION_CODES#N} for
Makoto Onuki70f929e2015-11-11 12:40:15 -08003061 * device admins that are not device owner and not profile owner.
3062 * The password can now only be changed if there is currently no password set. Device owner
Ricky Wai977ade22016-05-24 15:02:41 +01003063 * and profile owner can still do this when user is unlocked and does not have a managed
3064 * profile.</em>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003065 * <p>
3066 * The given password must be sufficient for the current password quality and length constraints
3067 * as returned by {@link #getPasswordQuality(ComponentName)} and
3068 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then
3069 * it will be rejected and false returned. Note that the password may be a stronger quality
3070 * (containing alphanumeric characters when the requested quality is only numeric), in which
3071 * case the currently active quality will be increased to match.
3072 * <p>
3073 * Calling with a null or empty password will clear any existing PIN, pattern or password if the
Robin Leece5c4002016-03-23 17:05:03 +00003074 * current password constraints allow it. <em>Note: This will not work in
3075 * {@link android.os.Build.VERSION_CODES#N} and later for managed profiles, or for device admins
3076 * that are not device owner or profile owner. Once set, the password cannot be changed to null
3077 * or empty except by these admins.</em>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003078 * <p>
3079 * The calling device admin must have requested
3080 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call this method; if it has
3081 * not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003082 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01003083 * @param password The new password for the user. Null or empty clears the password.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04003084 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003085 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
3086 * @return Returns true if the password was applied, or false if it is not acceptable for the
3087 * current constraints or if the user has not been decrypted yet.
3088 * @throws SecurityException if the calling application does not own an active administrator
3089 * that uses {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD}
Ricky Wai977ade22016-05-24 15:02:41 +01003090 * @throws IllegalStateException if the calling user is locked or has a managed profile.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08003091 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08003092 public boolean resetPassword(String password, int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003093 throwIfParentInstance("resetPassword");
Dianne Hackborndf83afa2010-01-20 13:37:26 -08003094 if (mService != null) {
3095 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003096 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08003097 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003098 throw e.rethrowFromSystemServer();
Dianne Hackborndf83afa2010-01-20 13:37:26 -08003099 }
3100 }
3101 return false;
3102 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003103
Dianne Hackbornd6847842010-01-12 18:14:19 -08003104 /**
Rubin Xuaab7a412016-12-30 21:13:29 +00003105 * 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 +01003106 * device lockscreen password (if called by device owner), or managed profile challenge (if
3107 * called by profile owner), via {@link #resetPasswordWithToken}.
Rubin Xuaab7a412016-12-30 21:13:29 +00003108 * <p>
3109 * If the user currently has a lockscreen password, the provisioned token will not be
3110 * immediately usable; it only becomes active after the user performs a confirm credential
3111 * operation, which can be triggered by {@link KeyguardManager#createConfirmDeviceCredentialIntent}.
3112 * If the user has no lockscreen password, the token is activated immediately. In all cases,
3113 * the active state of the current token can be checked by {@link #isResetPasswordTokenActive}.
3114 * For security reasons, un-activated tokens are only stored in memory and will be lost once
3115 * the device reboots. In this case a new token needs to be provisioned again.
3116 * <p>
3117 * Once provisioned and activated, the token will remain effective even if the user changes
3118 * or clears the lockscreen password.
3119 * <p>
3120 * <em>This token is highly sensitive and should be treated at the same level as user
Rubin Xuf7b036d2017-04-05 18:37:07 +01003121 * credentials. In particular, NEVER store this token on device in plaintext. Do not store
3122 * the plaintext token in device-encrypted storage if it will be needed to reset password on
3123 * file-based encryption devices before user unlocks. Consider carefully how any password token
3124 * will be stored on your server and who will need access to them. Tokens may be the subject of
3125 * legal access requests.
Rubin Xuaab7a412016-12-30 21:13:29 +00003126 * </em>
3127 *
3128 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3129 * @param token a secure token a least 32-byte long, which must be generated by a
3130 * cryptographically strong random number generator.
3131 * @return true if the operation is successful, false otherwise.
Benjamin Miller1aed7882017-08-15 18:04:20 +02003132 * @throws SecurityException if admin is not a device or profile owner.
Rubin Xuaab7a412016-12-30 21:13:29 +00003133 * @throws IllegalArgumentException if the supplied token is invalid.
Rubin Xuaab7a412016-12-30 21:13:29 +00003134 */
3135 public boolean setResetPasswordToken(ComponentName admin, byte[] token) {
3136 throwIfParentInstance("setResetPasswordToken");
3137 if (mService != null) {
3138 try {
3139 return mService.setResetPasswordToken(admin, token);
3140 } catch (RemoteException e) {
3141 throw e.rethrowFromSystemServer();
3142 }
3143 }
3144 return false;
3145 }
3146
3147 /**
3148 * Called by a profile or device owner to revoke the current password reset token.
3149 *
3150 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3151 * @return true if the operation is successful, false otherwise.
Benjamin Miller1aed7882017-08-15 18:04:20 +02003152 * @throws SecurityException if admin is not a device or profile owner.
Rubin Xuaab7a412016-12-30 21:13:29 +00003153 */
3154 public boolean clearResetPasswordToken(ComponentName admin) {
3155 throwIfParentInstance("clearResetPasswordToken");
3156 if (mService != null) {
3157 try {
3158 return mService.clearResetPasswordToken(admin);
3159 } catch (RemoteException e) {
3160 throw e.rethrowFromSystemServer();
3161 }
3162 }
3163 return false;
3164 }
3165
3166 /**
3167 * Called by a profile or device owner to check if the current reset password token is active.
3168 *
3169 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3170 * @return true if the token is active, false otherwise.
Benjamin Miller1aed7882017-08-15 18:04:20 +02003171 * @throws SecurityException if admin is not a device or profile owner.
Rubin Xuaab7a412016-12-30 21:13:29 +00003172 * @throws IllegalStateException if no token has been set.
3173 */
3174 public boolean isResetPasswordTokenActive(ComponentName admin) {
3175 throwIfParentInstance("isResetPasswordTokenActive");
3176 if (mService != null) {
3177 try {
3178 return mService.isResetPasswordTokenActive(admin);
3179 } catch (RemoteException e) {
3180 throw e.rethrowFromSystemServer();
3181 }
3182 }
3183 return false;
3184 }
3185
3186 /**
Esteban Talavera7e4cbad2017-03-30 17:59:50 +01003187 * Called by device or profile owner to force set a new device unlock password or a managed
3188 * profile challenge on current user. This takes effect immediately.
Rubin Xuaab7a412016-12-30 21:13:29 +00003189 * <p>
3190 * Unlike {@link #resetPassword}, this API can change the password even before the user or
3191 * device is unlocked or decrypted. The supplied token must have been previously provisioned via
3192 * {@link #setResetPasswordToken}, and in active state {@link #isResetPasswordTokenActive}.
3193 * <p>
3194 * The given password must be sufficient for the current password quality and length constraints
3195 * as returned by {@link #getPasswordQuality(ComponentName)} and
3196 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then
Benjamin Miller1aed7882017-08-15 18:04:20 +02003197 * it will be rejected and false returned. Note that the password may be a stronger quality, for
3198 * example, a password containing alphanumeric characters when the requested quality is only
3199 * numeric.
Rubin Xuaab7a412016-12-30 21:13:29 +00003200 * <p>
Benjamin Miller1aed7882017-08-15 18:04:20 +02003201 * Calling with a {@code null} or empty password will clear any existing PIN, pattern or
3202 * password if the current password constraints allow it.
Rubin Xuaab7a412016-12-30 21:13:29 +00003203 *
3204 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Miller1aed7882017-08-15 18:04:20 +02003205 * @param password The new password for the user. {@code null} or empty clears the password.
3206 * @param token the password reset token previously provisioned by
3207 * {@link #setResetPasswordToken}.
Rubin Xuaab7a412016-12-30 21:13:29 +00003208 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Benjamin Miller1aed7882017-08-15 18:04:20 +02003209 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
Rubin Xuaab7a412016-12-30 21:13:29 +00003210 * @return Returns true if the password was applied, or false if it is not acceptable for the
3211 * current constraints.
Benjamin Miller1aed7882017-08-15 18:04:20 +02003212 * @throws SecurityException if admin is not a device or profile owner.
Rubin Xuaab7a412016-12-30 21:13:29 +00003213 * @throws IllegalStateException if the provided token is not valid.
Rubin Xuaab7a412016-12-30 21:13:29 +00003214 */
3215 public boolean resetPasswordWithToken(@NonNull ComponentName admin, String password,
3216 byte[] token, int flags) {
3217 throwIfParentInstance("resetPassword");
3218 if (mService != null) {
3219 try {
3220 return mService.resetPasswordWithToken(admin, password, token, flags);
3221 } catch (RemoteException e) {
3222 throw e.rethrowFromSystemServer();
3223 }
3224 }
3225 return false;
3226 }
3227
3228 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003229 * Called by an application that is administering the device to set the maximum time for user
3230 * activity until the device will lock. This limits the length that the user can set. It takes
3231 * effect immediately.
3232 * <p>
3233 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
3234 * to be able to call this method; if it has not, a security exception will be thrown.
3235 * <p>
3236 * This method can be called on the {@link DevicePolicyManager} instance returned by
3237 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
3238 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00003239 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08003240 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003241 * @param timeMs The new desired maximum time to lock in milliseconds. A value of 0 means there
3242 * is no restriction.
3243 * @throws SecurityException if {@code admin} is not an active administrator or it does not use
3244 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
Dianne Hackbornd6847842010-01-12 18:14:19 -08003245 */
Robin Lee25e26452015-06-02 09:56:29 -07003246 public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003247 if (mService != null) {
3248 try {
Esteban Talavera62399912016-01-11 15:37:55 +00003249 mService.setMaximumTimeToLock(admin, timeMs, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003250 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003251 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003252 }
3253 }
3254 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003255
Dianne Hackbornd6847842010-01-12 18:14:19 -08003256 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00003257 * Retrieve the current maximum time to unlock for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01003258 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00003259 * a separate challenge are not taken into account.
3260 *
3261 * <p>This method can be called on the {@link DevicePolicyManager} instance
3262 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
3263 * restrictions on the parent profile.
3264 *
Robin Lee25e26452015-06-02 09:56:29 -07003265 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08003266 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07003267 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07003268 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08003269 */
Robin Lee25e26452015-06-02 09:56:29 -07003270 public long getMaximumTimeToLock(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003271 return getMaximumTimeToLock(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003272 }
3273
3274 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003275 public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003276 if (mService != null) {
3277 try {
Esteban Talavera62399912016-01-11 15:37:55 +00003278 return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003279 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003280 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003281 }
3282 }
3283 return 0;
3284 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003285
Dianne Hackbornd6847842010-01-12 18:14:19 -08003286 /**
Michal Karpinski8f010dd2016-06-21 15:05:53 +01003287 * Called by a device/profile owner to set the timeout after which unlocking with secondary, non
3288 * strong auth (e.g. fingerprint, trust agents) times out, i.e. the user has to use a strong
3289 * authentication method like password, pin or pattern.
3290 *
3291 * <p>This timeout is used internally to reset the timer to require strong auth again after
3292 * specified timeout each time it has been successfully used.
3293 *
3294 * <p>Fingerprint can also be disabled altogether using {@link #KEYGUARD_DISABLE_FINGERPRINT}.
3295 *
3296 * <p>Trust agents can also be disabled altogether using {@link #KEYGUARD_DISABLE_TRUST_AGENTS}.
3297 *
3298 * <p>The calling device admin must be a device or profile owner. If it is not,
3299 * a {@link SecurityException} will be thrown.
3300 *
Michal Karpinski943aabd2016-10-06 11:09:25 +01003301 * <p>The calling device admin can verify the value it has set by calling
3302 * {@link #getRequiredStrongAuthTimeout(ComponentName)} and passing in its instance.
3303 *
Michal Karpinski8f010dd2016-06-21 15:05:53 +01003304 * <p>This method can be called on the {@link DevicePolicyManager} instance returned by
3305 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
3306 * profile.
3307 *
3308 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xu5d39ea72017-04-24 20:26:30 +01003309 * @param timeoutMs The new timeout in milliseconds, after which the user will have to unlock
3310 * with strong authentication method. A value of 0 means the admin is not participating
3311 * in controlling the timeout.
Michal Karpinski943aabd2016-10-06 11:09:25 +01003312 * The minimum and maximum timeouts are platform-defined and are typically 1 hour and
3313 * 72 hours, respectively. Though discouraged, the admin may choose to require strong
3314 * auth at all times using {@link #KEYGUARD_DISABLE_FINGERPRINT} and/or
3315 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01003316 *
3317 * @throws SecurityException if {@code admin} is not a device or profile owner.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01003318 */
3319 public void setRequiredStrongAuthTimeout(@NonNull ComponentName admin,
3320 long timeoutMs) {
3321 if (mService != null) {
3322 try {
3323 mService.setRequiredStrongAuthTimeout(admin, timeoutMs, mParentInstance);
3324 } catch (RemoteException e) {
3325 throw e.rethrowFromSystemServer();
3326 }
3327 }
3328 }
3329
3330 /**
3331 * Determine for how long the user will be able to use secondary, non strong auth for
3332 * authentication, since last strong method authentication (password, pin or pattern) was used.
3333 * After the returned timeout the user is required to use strong authentication method.
3334 *
3335 * <p>This method can be called on the {@link DevicePolicyManager} instance
3336 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
3337 * restrictions on the parent profile.
3338 *
3339 * @param admin The name of the admin component to check, or {@code null} to aggregate
3340 * accross all participating admins.
Rubin Xu5d39ea72017-04-24 20:26:30 +01003341 * @return The timeout in milliseconds or 0 if not configured for the provided admin.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01003342 */
3343 public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin) {
3344 return getRequiredStrongAuthTimeout(admin, myUserId());
3345 }
3346
3347 /** @hide per-user version */
3348 public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin, @UserIdInt int userId) {
3349 if (mService != null) {
3350 try {
3351 return mService.getRequiredStrongAuthTimeout(admin, userId, mParentInstance);
3352 } catch (RemoteException e) {
3353 throw e.rethrowFromSystemServer();
3354 }
3355 }
3356 return DEFAULT_STRONG_AUTH_TIMEOUT_MS;
3357 }
3358
3359 /**
Andrew Scull85a63bc2016-10-24 13:47:47 +01003360 * Flag for {@link #lockNow(int)}: also evict the user's credential encryption key from the
3361 * keyring. The user's credential will need to be entered again in order to derive the
3362 * credential encryption key that will be stored back in the keyring for future use.
3363 * <p>
Andrew Scull17e1b5d2017-04-25 14:44:24 +01003364 * This flag can only be used by a profile owner when locking a managed profile when
3365 * {@link #getStorageEncryptionStatus} returns {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}.
Andrew Scull85a63bc2016-10-24 13:47:47 +01003366 * <p>
3367 * In order to secure user data, the user will be stopped and restarted so apps should wait
3368 * until they are next run to perform further actions.
3369 */
Andrew Scull17e1b5d2017-04-25 14:44:24 +01003370 public static final int FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY = 1;
3371
Andrew Scull85a63bc2016-10-24 13:47:47 +01003372 /** @hide */
3373 @Retention(RetentionPolicy.SOURCE)
Jeff Sharkeyce8db992017-12-13 20:05:05 -07003374 @IntDef(flag = true, prefix = { "FLAG_EVICT_" }, value = {
3375 FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY
3376 })
Andrew Scull85a63bc2016-10-24 13:47:47 +01003377 public @interface LockNowFlag {}
3378
3379 /**
3380 * Make the device lock immediately, as if the lock screen timeout has expired at the point of
3381 * this call.
3382 * <p>
3383 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
3384 * to be able to call this method; if it has not, a security exception will be thrown.
3385 * <p>
3386 * This method can be called on the {@link DevicePolicyManager} instance returned by
3387 * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile.
3388 * <p>
3389 * Equivalent to calling {@link #lockNow(int)} with no flags.
3390 *
3391 * @throws SecurityException if the calling application does not own an active administrator
3392 * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
3393 */
3394 public void lockNow() {
3395 lockNow(0);
3396 }
3397
3398 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003399 * Make the device lock immediately, as if the lock screen timeout has expired at the point of
3400 * this call.
3401 * <p>
3402 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
3403 * to be able to call this method; if it has not, a security exception will be thrown.
3404 * <p>
3405 * This method can be called on the {@link DevicePolicyManager} instance returned by
3406 * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003407 *
Andrew Scull17e1b5d2017-04-25 14:44:24 +01003408 * @param flags May be 0 or {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003409 * @throws SecurityException if the calling application does not own an active administrator
Andrew Scull85a63bc2016-10-24 13:47:47 +01003410 * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} or the
Andrew Scull17e1b5d2017-04-25 14:44:24 +01003411 * {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY} flag is passed by an application
3412 * that is not a profile
Andrew Scull85a63bc2016-10-24 13:47:47 +01003413 * owner of a managed profile.
Andrew Scull17e1b5d2017-04-25 14:44:24 +01003414 * @throws IllegalArgumentException if the {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY} flag is
3415 * passed when locking the parent profile.
3416 * @throws UnsupportedOperationException if the {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY}
3417 * flag is passed when {@link #getStorageEncryptionStatus} does not return
3418 * {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08003419 */
Andrew Scull85a63bc2016-10-24 13:47:47 +01003420 public void lockNow(@LockNowFlag int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -08003421 if (mService != null) {
3422 try {
Andrew Scull85a63bc2016-10-24 13:47:47 +01003423 mService.lockNow(flags, mParentInstance);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08003424 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003425 throw e.rethrowFromSystemServer();
Dianne Hackborndf83afa2010-01-20 13:37:26 -08003426 }
3427 }
3428 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003429
Dianne Hackbornd6847842010-01-12 18:14:19 -08003430 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07003431 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00003432 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07003433 */
3434 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
3435
3436 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00003437 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
3438 * data.
3439 *
Paul Crowley2934b262014-12-02 11:21:13 +00003440 * <p>This flag may only be set by device owner admins; if it is set by
3441 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00003442 */
3443 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
3444
3445 /**
yinxuf4f9cec2017-06-19 10:28:19 -07003446 * Flag for {@link #wipeData(int)}: also erase the device's eUICC data.
3447 *
3448 * TODO(b/35851809): make this public.
3449 * @hide
3450 */
3451 public static final int WIPE_EUICC = 0x0004;
3452
yuemingwf7f67dc2017-09-08 14:23:53 +01003453
yinxuf4f9cec2017-06-19 10:28:19 -07003454 /**
Suprabh Shukla556b05a2016-08-10 15:49:24 -07003455 * Ask that all user data be wiped. If called as a secondary user, the user will be removed and
3456 * other users will remain unaffected. Calling from the primary user will cause the device to
3457 * reboot, erasing all device data - including all the secondary users and their data - while
3458 * booting up.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003459 * <p>
3460 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to
3461 * be able to call this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003462 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003463 * @param flags Bit mask of additional options: currently supported flags are
3464 * {@link #WIPE_EXTERNAL_STORAGE} and {@link #WIPE_RESET_PROTECTION_DATA}.
3465 * @throws SecurityException if the calling application does not own an active administrator
3466 * that uses {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}
Dianne Hackbornd6847842010-01-12 18:14:19 -08003467 */
3468 public void wipeData(int flags) {
yuemingw22800192017-11-07 15:19:45 +00003469 throwIfParentInstance("wipeData");
yuemingwf7f67dc2017-09-08 14:23:53 +01003470 final String wipeReasonForUser = mContext.getString(
3471 R.string.work_profile_deleted_description_dpm_wipe);
3472 wipeDataInternal(flags, wipeReasonForUser);
3473 }
3474
3475 /**
3476 * Ask that all user data be wiped. If called as a secondary user, the user will be removed and
3477 * other users will remain unaffected, the provided reason for wiping data can be shown to
3478 * user. Calling from the primary user will cause the device to reboot, erasing all device data
3479 * - including all the secondary users and their data - while booting up. In this case, we don't
3480 * show the reason to the user since the device would be factory reset.
3481 * <p>
3482 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to
3483 * be able to call this method; if it has not, a security exception will be thrown.
3484 *
3485 * @param flags Bit mask of additional options: currently supported flags are
3486 * {@link #WIPE_EXTERNAL_STORAGE} and {@link #WIPE_RESET_PROTECTION_DATA}.
3487 * @param reason a string that contains the reason for wiping data, which can be
3488 * presented to the user.
3489 * @throws SecurityException if the calling application does not own an active administrator
3490 * that uses {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}
3491 * @throws IllegalArgumentException if the input reason string is null or empty.
3492 */
3493 public void wipeDataWithReason(int flags, @NonNull CharSequence reason) {
yuemingw22800192017-11-07 15:19:45 +00003494 throwIfParentInstance("wipeDataWithReason");
yuemingwf7f67dc2017-09-08 14:23:53 +01003495 Preconditions.checkNotNull(reason, "CharSequence is null");
3496 wipeDataInternal(flags, reason.toString());
3497 }
3498
3499 /**
3500 * Internal function for both {@link #wipeData(int)} and
3501 * {@link #wipeDataWithReason(int, CharSequence)} to call.
3502 *
3503 * @see #wipeData(int)
3504 * @see #wipeDataWithReason(int, CharSequence)
3505 * @hide
3506 */
3507 private void wipeDataInternal(int flags, @NonNull String wipeReasonForUser) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003508 if (mService != null) {
3509 try {
yuemingwf7f67dc2017-09-08 14:23:53 +01003510 mService.wipeDataWithReason(flags, wipeReasonForUser);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003511 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003512 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003513 }
3514 }
3515 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003516
Dianne Hackbornd6847842010-01-12 18:14:19 -08003517 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07003518 * Called by an application that is administering the device to set the
3519 * global proxy and exclusion list.
3520 * <p>
3521 * The calling device admin must have requested
3522 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
3523 * this method; if it has not, a security exception will be thrown.
3524 * Only the first device admin can set the proxy. If a second admin attempts
3525 * to set the proxy, the {@link ComponentName} of the admin originally setting the
Robin Lee25e26452015-06-02 09:56:29 -07003526 * proxy will be returned. If successful in setting the proxy, {@code null} will
Oscar Montemayor69238c62010-08-03 10:51:06 -07003527 * be returned.
3528 * The method can be called repeatedly by the device admin alrady setting the
3529 * proxy to update the proxy and exclusion list.
3530 *
Robin Lee25e26452015-06-02 09:56:29 -07003531 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Oscar Montemayor69238c62010-08-03 10:51:06 -07003532 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
3533 * Pass Proxy.NO_PROXY to reset the proxy.
3534 * @param exclusionList a list of domains to be excluded from the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07003535 * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName}
3536 * of the device admin that sets the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08003537 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07003538 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003539 public @Nullable ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec,
Oscar Montemayor69238c62010-08-03 10:51:06 -07003540 List<String> exclusionList ) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003541 throwIfParentInstance("setGlobalProxy");
Oscar Montemayor69238c62010-08-03 10:51:06 -07003542 if (proxySpec == null) {
3543 throw new NullPointerException();
3544 }
3545 if (mService != null) {
3546 try {
3547 String hostSpec;
3548 String exclSpec;
3549 if (proxySpec.equals(Proxy.NO_PROXY)) {
3550 hostSpec = null;
3551 exclSpec = null;
3552 } else {
3553 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
3554 throw new IllegalArgumentException();
3555 }
3556 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
3557 String hostName = sa.getHostName();
3558 int port = sa.getPort();
3559 StringBuilder hostBuilder = new StringBuilder();
3560 hostSpec = hostBuilder.append(hostName)
3561 .append(":").append(Integer.toString(port)).toString();
3562 if (exclusionList == null) {
3563 exclSpec = "";
3564 } else {
3565 StringBuilder listBuilder = new StringBuilder();
3566 boolean firstDomain = true;
3567 for (String exclDomain : exclusionList) {
3568 if (!firstDomain) {
3569 listBuilder = listBuilder.append(",");
3570 } else {
3571 firstDomain = false;
3572 }
3573 listBuilder = listBuilder.append(exclDomain.trim());
3574 }
3575 exclSpec = listBuilder.toString();
3576 }
Yuhao Zheng90704842014-02-28 17:22:45 -08003577 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
3578 != android.net.Proxy.PROXY_VALID)
3579 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07003580 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003581 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07003582 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003583 throw e.rethrowFromSystemServer();
Oscar Montemayor69238c62010-08-03 10:51:06 -07003584 }
3585 }
3586 return null;
3587 }
3588
3589 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003590 * Set a network-independent global HTTP proxy. This is not normally what you want for typical
3591 * HTTP proxies - they are generally network dependent. However if you're doing something
3592 * unusual like general internal filtering this may be useful. On a private network where the
3593 * proxy is not accessible, you may break HTTP using this.
3594 * <p>
3595 * This method requires the caller to be the device owner.
3596 * <p>
3597 * This proxy is only a recommendation and it is possible that some apps will ignore it.
Jason Monk03bc9912014-05-13 09:44:57 -04003598 *
Jason Monk03bc9912014-05-13 09:44:57 -04003599 * @see ProxyInfo
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003600 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3601 * @param proxyInfo The a {@link ProxyInfo} object defining the new global HTTP proxy. A
3602 * {@code null} value will clear the global HTTP proxy.
3603 * @throws SecurityException if {@code admin} is not the device owner.
Jason Monk03bc9912014-05-13 09:44:57 -04003604 */
Robin Lee25e26452015-06-02 09:56:29 -07003605 public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo
3606 proxyInfo) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003607 throwIfParentInstance("setRecommendedGlobalProxy");
Jason Monk03bc9912014-05-13 09:44:57 -04003608 if (mService != null) {
3609 try {
3610 mService.setRecommendedGlobalProxy(admin, proxyInfo);
3611 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003612 throw e.rethrowFromSystemServer();
Jason Monk03bc9912014-05-13 09:44:57 -04003613 }
3614 }
3615 }
3616
3617 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07003618 * Returns the component name setting the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07003619 * @return ComponentName object of the device admin that set the global proxy, or {@code null}
3620 * if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08003621 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07003622 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003623 public @Nullable ComponentName getGlobalProxyAdmin() {
Oscar Montemayor69238c62010-08-03 10:51:06 -07003624 if (mService != null) {
3625 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003626 return mService.getGlobalProxyAdmin(myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07003627 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003628 throw e.rethrowFromSystemServer();
Oscar Montemayor69238c62010-08-03 10:51:06 -07003629 }
3630 }
3631 return null;
3632 }
3633
3634 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08003635 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003636 * indicating that encryption is not supported.
3637 */
3638 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
3639
3640 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08003641 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003642 * indicating that encryption is supported, but is not currently active.
3643 */
3644 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
3645
3646 /**
Robin Lee3795fb02015-02-16 14:17:23 +00003647 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003648 * indicating that encryption is not currently active, but is currently
3649 * being activated. This is only reported by devices that support
3650 * encryption of data and only when the storage is currently
3651 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
3652 * to become encrypted will never return this value.
3653 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08003654 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003655
3656 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08003657 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003658 * indicating that encryption is active.
Amith Yamasani75db1252016-07-11 14:41:01 -07003659 * <p>
3660 * Also see {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003661 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08003662 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003663
3664 /**
Robin Lee3795fb02015-02-16 14:17:23 +00003665 * Result code for {@link #getStorageEncryptionStatus}:
3666 * indicating that encryption is active, but an encryption key has not
3667 * been set by the user.
3668 */
3669 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
3670
3671 /**
Makoto Onukid4c9e542016-02-25 18:17:30 -08003672 * Result code for {@link #getStorageEncryptionStatus}:
Amith Yamasani75db1252016-07-11 14:41:01 -07003673 * indicating that encryption is active and the encryption key is tied to the user or profile.
3674 * <p>
3675 * This value is only returned to apps targeting API level 24 and above. For apps targeting
3676 * earlier API levels, {@link #ENCRYPTION_STATUS_ACTIVE} is returned, even if the
3677 * encryption key is specific to the user or profile.
Makoto Onukid4c9e542016-02-25 18:17:30 -08003678 */
3679 public static final int ENCRYPTION_STATUS_ACTIVE_PER_USER = 5;
3680
3681 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003682 * Activity action: begin the process of encrypting data on the device. This activity should
3683 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
3684 * After resuming from this activity, use {@link #getStorageEncryption}
3685 * to check encryption status. However, on some devices this activity may never return, as
3686 * it may trigger a reboot and in some cases a complete data wipe of the device.
3687 */
3688 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
3689 public static final String ACTION_START_ENCRYPTION
3690 = "android.app.action.START_ENCRYPTION";
Alex Chaub6a9f942017-11-07 11:28:56 +08003691
3692 /**
3693 * Broadcast action: notify managed provisioning that new managed user is created.
3694 *
3695 * @hide
3696 */
3697 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
3698 public static final String ACTION_MANAGED_USER_CREATED =
3699 "android.app.action.MANAGED_USER_CREATED";
3700
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003701 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07003702 * Widgets are enabled in keyguard
3703 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07003704 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07003705
3706 /**
Jim Miller50e62182014-04-23 17:25:00 -07003707 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07003708 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07003709 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
3710
3711 /**
3712 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
3713 */
3714 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
3715
3716 /**
Jim Miller50e62182014-04-23 17:25:00 -07003717 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
3718 */
3719 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
3720
3721 /**
3722 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
3723 */
3724 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
3725
3726 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02003727 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07003728 * (e.g. PIN/Pattern/Password).
3729 */
3730 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
3731
3732 /**
Jim Miller06e34502014-07-17 14:46:05 -07003733 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
3734 */
3735 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
3736
3737 /**
Adrian Roos7f06eed2016-02-05 15:21:02 -08003738 * Disable text entry into notifications on secure keyguard screens (e.g. PIN/Pattern/Password).
3739 */
3740 public static final int KEYGUARD_DISABLE_REMOTE_INPUT = 1 << 6;
3741
3742 /**
Jim Miller35207742012-11-02 15:33:20 -07003743 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07003744 */
3745 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07003746
3747 /**
Robin Leeacdeac62017-02-21 22:13:38 +00003748 * Keyguard features that when set on a managed profile that doesn't have its own challenge will
3749 * affect the profile's parent user. These can also be set on the managed profile's parent
3750 * {@link DevicePolicyManager} instance.
3751 *
3752 * @hide
3753 */
3754 public static final int PROFILE_KEYGUARD_FEATURES_AFFECT_OWNER =
3755 DevicePolicyManager.KEYGUARD_DISABLE_TRUST_AGENTS
3756 | DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT;
3757
3758 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003759 * Called by an application that is administering the device to request that the storage system
3760 * be encrypted.
3761 * <p>
3762 * When multiple device administrators attempt to control device encryption, the most secure,
3763 * supported setting will always be used. If any device administrator requests device
3764 * encryption, it will be enabled; Conversely, if a device administrator attempts to disable
3765 * device encryption while another device administrator has enabled it, the call to disable will
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003766 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003767 * <p>
3768 * This policy controls encryption of the secure (application data) storage area. Data written
3769 * to other storage areas may or may not be encrypted, and this policy does not require or
3770 * control the encryption of any other storage areas. There is one exception: If
3771 * {@link android.os.Environment#isExternalStorageEmulated()} is {@code true}, then the
3772 * directory returned by {@link android.os.Environment#getExternalStorageDirectory()} must be
3773 * written to disk within the encrypted storage area.
3774 * <p>
3775 * Important Note: On some devices, it is possible to encrypt storage without requiring the user
3776 * to create a device PIN or Password. In this case, the storage is encrypted, but the
3777 * encryption key may not be fully secured. For maximum security, the administrator should also
3778 * require (and check for) a pattern, PIN, or password.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003779 *
3780 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3781 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08003782 * @return the new request status (for all active admins) - will be one of
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003783 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
3784 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
3785 * {@link #getStorageEncryptionStatus()} to query the actual device state.
3786 * @throws SecurityException if {@code admin} is not an active administrator or does not use
3787 * {@link DeviceAdminInfo#USES_ENCRYPTED_STORAGE}
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003788 */
Robin Lee25e26452015-06-02 09:56:29 -07003789 public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003790 throwIfParentInstance("setStorageEncryption");
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003791 if (mService != null) {
3792 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003793 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003794 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003795 throw e.rethrowFromSystemServer();
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003796 }
3797 }
3798 return ENCRYPTION_STATUS_UNSUPPORTED;
3799 }
3800
3801 /**
3802 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08003803 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003804 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08003805 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
3806 * this will return the requested encryption setting as an aggregate of all active
3807 * administrators.
3808 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003809 */
Robin Lee25e26452015-06-02 09:56:29 -07003810 public boolean getStorageEncryption(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003811 throwIfParentInstance("getStorageEncryption");
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003812 if (mService != null) {
3813 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003814 return mService.getStorageEncryption(admin, myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003815 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003816 throw e.rethrowFromSystemServer();
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003817 }
3818 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08003819 return false;
3820 }
3821
3822 /**
3823 * Called by an application that is administering the device to
3824 * determine the current encryption status of the device.
Amith Yamasani75db1252016-07-11 14:41:01 -07003825 * <p>
Andy Stadler22dbfda2011-01-17 12:47:31 -08003826 * Depending on the returned status code, the caller may proceed in different
3827 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
3828 * storage system does not support encryption. If the
3829 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
3830 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00003831 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
3832 * storage system has enabled encryption but no password is set so further action
Amith Yamasani75db1252016-07-11 14:41:01 -07003833 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING},
3834 * {@link #ENCRYPTION_STATUS_ACTIVE} or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER},
3835 * no further action is required.
Andy Stadler22dbfda2011-01-17 12:47:31 -08003836 *
Robin Lee7e678712014-07-24 16:41:31 +01003837 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08003838 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00003839 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
Amith Yamasani75db1252016-07-11 14:41:01 -07003840 * {@link #ENCRYPTION_STATUS_ACTIVE}, or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08003841 */
3842 public int getStorageEncryptionStatus() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003843 throwIfParentInstance("getStorageEncryptionStatus");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003844 return getStorageEncryptionStatus(myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003845 }
3846
3847 /** @hide per-user version */
3848 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08003849 if (mService != null) {
3850 try {
Makoto Onukid4c9e542016-02-25 18:17:30 -08003851 return mService.getStorageEncryptionStatus(mContext.getPackageName(), userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08003852 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003853 throw e.rethrowFromSystemServer();
Andy Stadler22dbfda2011-01-17 12:47:31 -08003854 }
3855 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003856 return ENCRYPTION_STATUS_UNSUPPORTED;
3857 }
3858
3859 /**
Robin Lee2f7e1e42016-03-21 10:50:01 +00003860 * Mark a CA certificate as approved by the device user. This means that they have been notified
3861 * of the installation, were made aware of the risks, viewed the certificate and still wanted to
3862 * keep the certificate on the device.
3863 *
3864 * Calling with {@param approval} as {@code true} will cancel any ongoing warnings related to
3865 * this certificate.
3866 *
3867 * @hide
3868 */
3869 public boolean approveCaCert(String alias, int userHandle, boolean approval) {
3870 if (mService != null) {
3871 try {
3872 return mService.approveCaCert(alias, userHandle, approval);
3873 } catch (RemoteException e) {
3874 throw e.rethrowFromSystemServer();
3875 }
3876 }
3877 return false;
3878 }
3879
3880 /**
3881 * Check whether a CA certificate has been approved by the device user.
3882 *
3883 * @hide
3884 */
3885 public boolean isCaCertApproved(String alias, int userHandle) {
3886 if (mService != null) {
3887 try {
3888 return mService.isCaCertApproved(alias, userHandle);
3889 } catch (RemoteException e) {
3890 throw e.rethrowFromSystemServer();
3891 }
3892 }
3893 return false;
3894 }
3895
3896 /**
Robin Lee7e678712014-07-24 16:41:31 +01003897 * Installs the given certificate as a user CA.
3898 *
Edman Anjosf9946772016-11-28 16:35:15 +01003899 * The caller must be a profile or device owner on that user, or a delegate package given the
3900 * {@link #DELEGATION_CERT_INSTALL} scope via {@link #setDelegatedScopes}; otherwise a
3901 * security exception will be thrown.
3902 *
Robin Lee25e26452015-06-02 09:56:29 -07003903 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3904 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003905 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04003906 *
3907 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01003908 * interrupted, true otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003909 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3910 * owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003911 * @see #setDelegatedScopes
3912 * @see #DELEGATION_CERT_INSTALL
Maggie Benthallda51e682013-08-08 22:35:44 -04003913 */
Robin Lee25e26452015-06-02 09:56:29 -07003914 public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003915 throwIfParentInstance("installCaCert");
Maggie Benthallda51e682013-08-08 22:35:44 -04003916 if (mService != null) {
3917 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003918 return mService.installCaCert(admin, mContext.getPackageName(), certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04003919 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003920 throw e.rethrowFromSystemServer();
Maggie Benthallda51e682013-08-08 22:35:44 -04003921 }
3922 }
3923 return false;
3924 }
3925
3926 /**
Robin Lee7e678712014-07-24 16:41:31 +01003927 * Uninstalls the given certificate from trusted user CAs, if present.
3928 *
Edman Anjosf9946772016-11-28 16:35:15 +01003929 * The caller must be a profile or device owner on that user, or a delegate package given the
3930 * {@link #DELEGATION_CERT_INSTALL} scope via {@link #setDelegatedScopes}; otherwise a
3931 * security exception will be thrown.
3932 *
Robin Lee25e26452015-06-02 09:56:29 -07003933 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3934 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003935 * @param certBuffer encoded form of the certificate to remove.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003936 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3937 * owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003938 * @see #setDelegatedScopes
3939 * @see #DELEGATION_CERT_INSTALL
Maggie Benthallda51e682013-08-08 22:35:44 -04003940 */
Robin Lee25e26452015-06-02 09:56:29 -07003941 public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003942 throwIfParentInstance("uninstallCaCert");
Maggie Benthallda51e682013-08-08 22:35:44 -04003943 if (mService != null) {
3944 try {
Robin Lee306fe082014-06-19 14:04:24 +00003945 final String alias = getCaCertAlias(certBuffer);
Edman Anjosf9946772016-11-28 16:35:15 +01003946 mService.uninstallCaCerts(admin, mContext.getPackageName(), new String[] {alias});
Robin Lee306fe082014-06-19 14:04:24 +00003947 } catch (CertificateException e) {
3948 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04003949 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003950 throw e.rethrowFromSystemServer();
Maggie Benthallda51e682013-08-08 22:35:44 -04003951 }
3952 }
3953 }
3954
3955 /**
Robin Lee7e678712014-07-24 16:41:31 +01003956 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
3957 * If a user has installed any certificates by other means than device policy these will be
3958 * included too.
3959 *
Robin Lee25e26452015-06-02 09:56:29 -07003960 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3961 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003962 * @return a List of byte[] arrays, each encoding one user CA certificate.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003963 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3964 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04003965 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003966 public @NonNull List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) {
3967 final List<byte[]> certs = new ArrayList<byte[]>();
Benjamin Franzbc33c822016-04-15 08:57:52 +01003968 throwIfParentInstance("getInstalledCaCerts");
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003969 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01003970 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003971 mService.enforceCanManageCaCerts(admin, mContext.getPackageName());
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003972 final TrustedCertificateStore certStore = new TrustedCertificateStore();
3973 for (String alias : certStore.userAliases()) {
3974 try {
3975 certs.add(certStore.getCertificate(alias).getEncoded());
3976 } catch (CertificateException ce) {
3977 Log.w(TAG, "Could not encode certificate: " + alias, ce);
3978 }
3979 }
3980 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003981 throw re.rethrowFromSystemServer();
Robin Lee7e678712014-07-24 16:41:31 +01003982 }
3983 }
3984 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04003985 }
3986
3987 /**
Robin Lee7e678712014-07-24 16:41:31 +01003988 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
3989 * means other than device policy will also be removed, except for system CA certificates.
3990 *
Robin Lee25e26452015-06-02 09:56:29 -07003991 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3992 * {@code null} if calling from a delegated certificate installer.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003993 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3994 * owner.
Robin Lee7e678712014-07-24 16:41:31 +01003995 */
Robin Lee25e26452015-06-02 09:56:29 -07003996 public void uninstallAllUserCaCerts(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003997 throwIfParentInstance("uninstallAllUserCaCerts");
Robin Lee7e678712014-07-24 16:41:31 +01003998 if (mService != null) {
Robin Lee83881bd2015-06-09 16:04:38 -07003999 try {
Edman Anjosf9946772016-11-28 16:35:15 +01004000 mService.uninstallCaCerts(admin, mContext.getPackageName(),
4001 new TrustedCertificateStore().userAliases() .toArray(new String[0]));
Robin Lee83881bd2015-06-09 16:04:38 -07004002 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004003 throw re.rethrowFromSystemServer();
Robin Lee7e678712014-07-24 16:41:31 +01004004 }
4005 }
4006 }
4007
4008 /**
4009 * Returns whether this certificate is installed as a trusted CA.
4010 *
Robin Lee25e26452015-06-02 09:56:29 -07004011 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
4012 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01004013 * @param certBuffer encoded form of the certificate to look up.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004014 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
4015 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04004016 */
Robin Lee25e26452015-06-02 09:56:29 -07004017 public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004018 throwIfParentInstance("hasCaCertInstalled");
Esteban Talavera808f6ef2014-08-28 17:15:54 +01004019 if (mService != null) {
4020 try {
Edman Anjosf9946772016-11-28 16:35:15 +01004021 mService.enforceCanManageCaCerts(admin, mContext.getPackageName());
Esteban Talavera808f6ef2014-08-28 17:15:54 +01004022 return getCaCertAlias(certBuffer) != null;
4023 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004024 throw re.rethrowFromSystemServer();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01004025 } catch (CertificateException ce) {
4026 Log.w(TAG, "Could not parse certificate", ce);
4027 }
Maggie Benthallda51e682013-08-08 22:35:44 -04004028 }
4029 return false;
4030 }
4031
4032 /**
Robin Leece3399f2016-02-24 12:08:32 +00004033 * Called by a device or profile owner, or delegated certificate installer, to install a
4034 * certificate and corresponding private key. All apps within the profile will be able to access
4035 * the certificate and use the private key, given direct user approval.
4036 *
4037 * <p>Access to the installed credentials will not be granted to the caller of this API without
4038 * direct user approval. This is for security - should a certificate installer become
4039 * compromised, certificates it had already installed will be protected.
4040 *
4041 * <p>If the installer must have access to the credentials, call
Rubin Xub4365912016-03-23 12:13:22 +00004042 * {@link #installKeyPair(ComponentName, PrivateKey, Certificate[], String, boolean)} instead.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01004043 *
Robin Lee25e26452015-06-02 09:56:29 -07004044 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
4045 * {@code null} if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01004046 * @param privKey The private key to install.
4047 * @param cert The certificate to install.
4048 * @param alias The private key alias under which to install the certificate. If a certificate
4049 * with that alias already exists, it will be overwritten.
4050 * @return {@code true} if the keys were installed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004051 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
4052 * owner.
Edman Anjosf9946772016-11-28 16:35:15 +01004053 * @see #setDelegatedScopes
4054 * @see #DELEGATION_CERT_INSTALL
Bernhard Bauer26408cc2014-09-08 14:07:31 +01004055 */
Robin Leefbc65642015-08-03 16:21:22 +01004056 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
4057 @NonNull Certificate cert, @NonNull String alias) {
Rubin Xub4365912016-03-23 12:13:22 +00004058 return installKeyPair(admin, privKey, new Certificate[] {cert}, alias, false);
Robin Leece3399f2016-02-24 12:08:32 +00004059 }
4060
4061 /**
4062 * Called by a device or profile owner, or delegated certificate installer, to install a
Rubin Xub4365912016-03-23 12:13:22 +00004063 * certificate chain and corresponding private key for the leaf certificate. All apps within the
4064 * profile will be able to access the certificate chain and use the private key, given direct
4065 * user approval.
Robin Leece3399f2016-02-24 12:08:32 +00004066 *
Robin Leea1b290e2016-03-09 14:38:36 +00004067 * <p>The caller of this API may grant itself access to the certificate and private key
4068 * immediately, without user approval. It is a best practice not to request this unless strictly
4069 * necessary since it opens up additional security vulnerabilities.
Robin Leece3399f2016-02-24 12:08:32 +00004070 *
4071 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Robin Leea1b290e2016-03-09 14:38:36 +00004072 * {@code null} if calling from a delegated certificate installer.
Robin Leece3399f2016-02-24 12:08:32 +00004073 * @param privKey The private key to install.
Rubin Xub4365912016-03-23 12:13:22 +00004074 * @param certs The certificate chain to install. The chain should start with the leaf
4075 * certificate and include the chain of trust in order. This will be returned by
4076 * {@link android.security.KeyChain#getCertificateChain}.
Robin Leece3399f2016-02-24 12:08:32 +00004077 * @param alias The private key alias under which to install the certificate. If a certificate
Robin Leea1b290e2016-03-09 14:38:36 +00004078 * with that alias already exists, it will be overwritten.
Robin Leece3399f2016-02-24 12:08:32 +00004079 * @param requestAccess {@code true} to request that the calling app be granted access to the
Robin Leea1b290e2016-03-09 14:38:36 +00004080 * credentials immediately. Otherwise, access to the credentials will be gated by user
4081 * approval.
Robin Leece3399f2016-02-24 12:08:32 +00004082 * @return {@code true} if the keys were installed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004083 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
4084 * owner.
Rubin Xub4365912016-03-23 12:13:22 +00004085 * @see android.security.KeyChain#getCertificateChain
Edman Anjosf9946772016-11-28 16:35:15 +01004086 * @see #setDelegatedScopes
4087 * @see #DELEGATION_CERT_INSTALL
Robin Leece3399f2016-02-24 12:08:32 +00004088 */
4089 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
Rubin Xub4365912016-03-23 12:13:22 +00004090 @NonNull Certificate[] certs, @NonNull String alias, boolean requestAccess) {
Eran Messeri19d19042017-11-20 12:48:52 +00004091 return installKeyPair(admin, privKey, certs, alias, requestAccess, true);
4092 }
4093
4094 /**
4095 * Called by a device or profile owner, or delegated certificate installer, to install a
4096 * certificate chain and corresponding private key for the leaf certificate. All apps within the
4097 * profile will be able to access the certificate chain and use the private key, given direct
4098 * user approval (if the user is allowed to select the private key).
4099 *
4100 * <p>The caller of this API may grant itself access to the certificate and private key
4101 * immediately, without user approval. It is a best practice not to request this unless strictly
4102 * necessary since it opens up additional security vulnerabilities.
4103 *
4104 * <p>Whether this key is offered to the user for approval at all or not depends on the
4105 * {@code isUserSelectable} parameter.
4106 *
4107 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
4108 * {@code null} if calling from a delegated certificate installer.
4109 * @param privKey The private key to install.
4110 * @param certs The certificate chain to install. The chain should start with the leaf
4111 * certificate and include the chain of trust in order. This will be returned by
4112 * {@link android.security.KeyChain#getCertificateChain}.
4113 * @param alias The private key alias under which to install the certificate. If a certificate
4114 * with that alias already exists, it will be overwritten.
4115 * @param requestAccess {@code true} to request that the calling app be granted access to the
4116 * credentials immediately. Otherwise, access to the credentials will be gated by user
4117 * approval.
4118 * @param isUserSelectable {@code true} to indicate that a user can select this key via the
4119 * Certificate Selection prompt, false to indicate that this key can only be granted
4120 * access by implementing
4121 * {@link android.app.admin.DeviceAdminReceiver#onChoosePrivateKeyAlias}.
4122 * @return {@code true} if the keys were installed, {@code false} otherwise.
4123 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
4124 * owner.
4125 * @see android.security.KeyChain#getCertificateChain
4126 * @see #setDelegatedScopes
4127 * @see #DELEGATION_CERT_INSTALL
4128 */
4129 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
4130 @NonNull Certificate[] certs, @NonNull String alias, boolean requestAccess,
4131 boolean isUserSelectable) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004132 throwIfParentInstance("installKeyPair");
Bernhard Bauer26408cc2014-09-08 14:07:31 +01004133 try {
Rubin Xub4365912016-03-23 12:13:22 +00004134 final byte[] pemCert = Credentials.convertToPem(certs[0]);
4135 byte[] pemChain = null;
4136 if (certs.length > 1) {
4137 pemChain = Credentials.convertToPem(Arrays.copyOfRange(certs, 1, certs.length));
4138 }
Robin Lee0d5ccb72014-09-12 17:41:44 +01004139 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
4140 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
Edman Anjosf9946772016-11-28 16:35:15 +01004141 return mService.installKeyPair(admin, mContext.getPackageName(), pkcs8Key, pemCert,
Eran Messeri19d19042017-11-20 12:48:52 +00004142 pemChain, alias, requestAccess, isUserSelectable);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01004143 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004144 throw e.rethrowFromSystemServer();
Robin Lee0d5ccb72014-09-12 17:41:44 +01004145 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
4146 Log.w(TAG, "Failed to obtain private key material", e);
4147 } catch (CertificateException | IOException e) {
4148 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01004149 }
4150 return false;
4151 }
4152
4153 /**
Robin Leea1b290e2016-03-09 14:38:36 +00004154 * Called by a device or profile owner, or delegated certificate installer, to remove a
4155 * certificate and private key pair installed under a given alias.
Robin Leefbc65642015-08-03 16:21:22 +01004156 *
4157 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Robin Leea1b290e2016-03-09 14:38:36 +00004158 * {@code null} if calling from a delegated certificate installer.
Robin Leefbc65642015-08-03 16:21:22 +01004159 * @param alias The private key alias under which the certificate is installed.
Robin Leea1b290e2016-03-09 14:38:36 +00004160 * @return {@code true} if the private key alias no longer exists, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004161 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
4162 * owner.
Edman Anjosf9946772016-11-28 16:35:15 +01004163 * @see #setDelegatedScopes
4164 * @see #DELEGATION_CERT_INSTALL
Robin Leefbc65642015-08-03 16:21:22 +01004165 */
4166 public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004167 throwIfParentInstance("removeKeyPair");
Robin Leefbc65642015-08-03 16:21:22 +01004168 try {
Edman Anjosf9946772016-11-28 16:35:15 +01004169 return mService.removeKeyPair(admin, mContext.getPackageName(), alias);
Robin Leefbc65642015-08-03 16:21:22 +01004170 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004171 throw e.rethrowFromSystemServer();
Robin Leefbc65642015-08-03 16:21:22 +01004172 }
Robin Leefbc65642015-08-03 16:21:22 +01004173 }
4174
4175 /**
Eran Messeri852c8f12017-11-15 05:55:52 +00004176 * Called by a device or profile owner, or delegated certificate installer, to generate a
4177 * new private/public key pair. If the device supports key generation via secure hardware,
4178 * this method is useful for creating a key in KeyChain that never left the secure hardware.
4179 *
4180 * Access to the key is controlled the same way as in {@link #installKeyPair}.
4181 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
4182 * {@code null} if calling from a delegated certificate installer.
4183 * @param algorithm The key generation algorithm, see {@link java.security.KeyPairGenerator}.
4184 * @param keySpec Specification of the key to generate, see
4185 * {@link java.security.KeyPairGenerator}.
Eran Messeri94d56762017-12-21 20:50:54 +00004186 * @param idAttestationFlags A bitmask of all the identifiers that should be included in the
4187 * attestation record ({@code ID_TYPE_BASE_INFO}, {@code ID_TYPE_SERIAL},
4188 * {@code ID_TYPE_IMEI} and {@code ID_TYPE_MEID}), or {@code 0} if no device
4189 * identification is required in the attestation record.
4190 * Device owner, profile owner and their delegated certificate installer can use
4191 * {@link #ID_TYPE_BASE_INFO} to request inclusion of the general device information
4192 * including manufacturer, model, brand, device and product in the attestation record.
4193 * Only device owner and their delegated certificate installer can use
4194 * {@link #ID_TYPE_SERIAL}, {@link #ID_TYPE_IMEI} and {@link #ID_TYPE_MEID} to request
4195 * unique device identifiers to be attested.
4196 * <p>
4197 * If any of {@link #ID_TYPE_SERIAL}, {@link #ID_TYPE_IMEI} and {@link #ID_TYPE_MEID}
4198 * is set, it is implicitly assumed that {@link #ID_TYPE_BASE_INFO} is also set.
4199 * <p>
4200 * If any flag is specified, then an attestation challenge must be included in the
4201 * {@code keySpec}.
Eran Messeri852c8f12017-11-15 05:55:52 +00004202 * @return A non-null {@code AttestedKeyPair} if the key generation succeeded, null otherwise.
4203 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
Eran Messeri94d56762017-12-21 20:50:54 +00004204 * owner. If Device ID attestation is requested (using {@link #ID_TYPE_SERIAL},
4205 * {@link #ID_TYPE_IMEI} or {@link #ID_TYPE_MEID}), the caller must be the Device Owner
4206 * or the Certificate Installer delegate.
4207 * @throws IllegalArgumentException if the alias in {@code keySpec} is empty, if the
Eran Messeri852c8f12017-11-15 05:55:52 +00004208 * algorithm specification in {@code keySpec} is not {@code RSAKeyGenParameterSpec}
Eran Messeri94d56762017-12-21 20:50:54 +00004209 * or {@code ECGenParameterSpec}, or if Device ID attestation was requested but the
4210 * {@code keySpec} does not contain an attestation challenge.
4211 * @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 Messeriecf0f222017-12-11 12:32:13 +00004255
4256 /**
4257 * Called by a device or profile owner, or delegated certificate installer, to associate
4258 * certificates with a key pair that was generated using {@link #generateKeyPair}, and
4259 * set whether the key is available for the user to choose in the certificate selection
4260 * prompt.
4261 *
4262 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
4263 * {@code null} if calling from a delegated certificate installer.
4264 * @param alias The private key alias under which to install the certificate. The {@code alias}
4265 * should denote an existing private key. If a certificate with that alias already
4266 * exists, it will be overwritten.
4267 * @param certs The certificate chain to install. The chain should start with the leaf
4268 * certificate and include the chain of trust in order. This will be returned by
4269 * {@link android.security.KeyChain#getCertificateChain}.
4270 * @param isUserSelectable {@code true} to indicate that a user can select this key via the
4271 * certificate selection prompt, {@code false} to indicate that this key can only be
4272 * granted access by implementing
4273 * {@link android.app.admin.DeviceAdminReceiver#onChoosePrivateKeyAlias}.
4274 * @return {@code true} if the provided {@code alias} exists and the certificates has been
4275 * successfully associated with it, {@code false} otherwise.
4276 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
4277 * owner, or {@code admin} is null but the calling application is not a delegated
4278 * certificate installer.
4279 */
4280 public boolean setKeyPairCertificate(@Nullable ComponentName admin,
4281 @NonNull String alias, @NonNull List<Certificate> certs, boolean isUserSelectable) {
4282 throwIfParentInstance("setKeyPairCertificate");
4283 try {
4284 final byte[] pemCert = Credentials.convertToPem(certs.get(0));
4285 byte[] pemChain = null;
4286 if (certs.size() > 1) {
4287 pemChain = Credentials.convertToPem(
4288 certs.subList(1, certs.size()).toArray(new Certificate[0]));
4289 }
4290 return mService.setKeyPairCertificate(admin, mContext.getPackageName(), alias, pemCert,
4291 pemChain, isUserSelectable);
4292 } catch (RemoteException e) {
4293 throw e.rethrowFromSystemServer();
4294 } catch (CertificateException | IOException e) {
4295 Log.w(TAG, "Could not pem-encode certificate", e);
4296 }
4297 return false;
4298 }
4299
4300
Eran Messeri852c8f12017-11-15 05:55:52 +00004301 /**
Robin Lee25e26452015-06-02 09:56:29 -07004302 * @return the alias of a given CA certificate in the certificate store, or {@code null} if it
Robin Lee306fe082014-06-19 14:04:24 +00004303 * doesn't exist.
4304 */
4305 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
4306 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
4307 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
4308 new ByteArrayInputStream(certBuffer));
4309 return new TrustedCertificateStore().getCertificateAlias(cert);
4310 }
4311
4312 /**
Rubin Xuec32b562015-03-03 17:34:05 +00004313 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01004314 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00004315 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01004316 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00004317 * <p>
4318 * Delegated certificate installer is a per-user state. The delegated access is persistent until
4319 * it is later cleared by calling this method with a null value or uninstallling the certificate
4320 * installer.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004321 * <p>
Rubin Xuf03d0a62016-02-10 14:54:15 +00004322 * <b>Note:</b>Starting from {@link android.os.Build.VERSION_CODES#N}, if the caller
4323 * application's target SDK version is {@link android.os.Build.VERSION_CODES#N} or newer, the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004324 * supplied certificate installer package must be installed when calling this API, otherwise an
4325 * {@link IllegalArgumentException} will be thrown.
Rubin Xuec32b562015-03-03 17:34:05 +00004326 *
Robin Lee25e26452015-06-02 09:56:29 -07004327 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xuec32b562015-03-03 17:34:05 +00004328 * @param installerPackage The package name of the certificate installer which will be given
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004329 * access. If {@code null} is given the current package will be cleared.
4330 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01004331 *
4332 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #setDelegatedScopes}
4333 * with the {@link #DELEGATION_CERT_INSTALL} scope instead.
Rubin Xuec32b562015-03-03 17:34:05 +00004334 */
Edman Anjosf9946772016-11-28 16:35:15 +01004335 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07004336 public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String
4337 installerPackage) throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004338 throwIfParentInstance("setCertInstallerPackage");
Rubin Xuec32b562015-03-03 17:34:05 +00004339 if (mService != null) {
4340 try {
Robin Lee25e26452015-06-02 09:56:29 -07004341 mService.setCertInstallerPackage(admin, installerPackage);
Rubin Xuec32b562015-03-03 17:34:05 +00004342 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004343 throw e.rethrowFromSystemServer();
Rubin Xuec32b562015-03-03 17:34:05 +00004344 }
4345 }
4346 }
4347
4348 /**
Edman Anjosf9946772016-11-28 16:35:15 +01004349 * Called by a profile owner or device owner to retrieve the certificate installer for the user,
4350 * or {@code null} if none is set. If there are multiple delegates this function will return one
4351 * of them.
Rubin Xuec32b562015-03-03 17:34:05 +00004352 *
Robin Lee25e26452015-06-02 09:56:29 -07004353 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004354 * @return The package name of the current delegated certificate installer, or {@code null} if
4355 * none is set.
4356 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01004357 *
4358 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatePackages}
4359 * with the {@link #DELEGATION_CERT_INSTALL} scope instead.
Rubin Xuec32b562015-03-03 17:34:05 +00004360 */
Edman Anjosf9946772016-11-28 16:35:15 +01004361 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07004362 public @Nullable String getCertInstallerPackage(@NonNull ComponentName admin)
4363 throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004364 throwIfParentInstance("getCertInstallerPackage");
Rubin Xuec32b562015-03-03 17:34:05 +00004365 if (mService != null) {
4366 try {
Robin Lee25e26452015-06-02 09:56:29 -07004367 return mService.getCertInstallerPackage(admin);
Rubin Xuec32b562015-03-03 17:34:05 +00004368 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004369 throw e.rethrowFromSystemServer();
Rubin Xuec32b562015-03-03 17:34:05 +00004370 }
4371 }
4372 return null;
4373 }
4374
4375 /**
Edman Anjosf9946772016-11-28 16:35:15 +01004376 * Called by a profile owner or device owner to grant access to privileged APIs to another app.
4377 * Granted APIs are determined by {@code scopes}, which is a list of the {@code DELEGATION_*}
4378 * constants.
4379 * <p>
Edman Anjos9e62c312017-01-26 22:22:58 +01004380 * A broadcast with the {@link #ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED} action will be
4381 * sent to the {@code delegatePackage} with its new scopes in an {@code ArrayList<String>} extra
4382 * under the {@link #EXTRA_DELEGATION_SCOPES} key. The broadcast is sent with the
4383 * {@link Intent#FLAG_RECEIVER_REGISTERED_ONLY} flag.
4384 * <p>
Edman Anjosf9946772016-11-28 16:35:15 +01004385 * Delegated scopes are a per-user state. The delegated access is persistent until it is later
4386 * cleared by calling this method with an empty {@code scopes} list or uninstalling the
4387 * {@code delegatePackage}.
4388 *
4389 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4390 * @param delegatePackage The package name of the app which will be given access.
4391 * @param scopes The groups of privileged APIs whose access should be granted to
4392 * {@code delegatedPackage}.
4393 * @throws SecurityException if {@code admin} is not a device or a profile owner.
4394 */
4395 public void setDelegatedScopes(@NonNull ComponentName admin, @NonNull String delegatePackage,
4396 @NonNull List<String> scopes) {
4397 throwIfParentInstance("setDelegatedScopes");
4398 if (mService != null) {
4399 try {
4400 mService.setDelegatedScopes(admin, delegatePackage, scopes);
4401 } catch (RemoteException e) {
4402 throw e.rethrowFromSystemServer();
4403 }
4404 }
4405 }
4406
4407 /**
4408 * Called by a profile owner or device owner to retrieve a list of the scopes given to a
4409 * delegate package. Other apps can use this method to retrieve their own delegated scopes by
4410 * passing {@code null} for {@code admin} and their own package name as
4411 * {@code delegatedPackage}.
4412 *
4413 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
4414 * {@code null} if the caller is {@code delegatedPackage}.
4415 * @param delegatedPackage The package name of the app whose scopes should be retrieved.
4416 * @return A list containing the scopes given to {@code delegatedPackage}.
4417 * @throws SecurityException if {@code admin} is not a device or a profile owner.
4418 */
4419 @NonNull
Edman Anjos9e62c312017-01-26 22:22:58 +01004420 public List<String> getDelegatedScopes(@Nullable ComponentName admin,
Edman Anjosf9946772016-11-28 16:35:15 +01004421 @NonNull String delegatedPackage) {
4422 throwIfParentInstance("getDelegatedScopes");
4423 if (mService != null) {
4424 try {
4425 return mService.getDelegatedScopes(admin, delegatedPackage);
4426 } catch (RemoteException e) {
4427 throw e.rethrowFromSystemServer();
4428 }
4429 }
4430 return null;
4431 }
4432
4433 /**
4434 * Called by a profile owner or device owner to retrieve a list of delegate packages that were
4435 * granted a delegation scope.
4436 *
4437 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4438 * @param delegationScope The scope whose delegates should be retrieved.
4439 * @return A list of package names of the current delegated packages for
4440 {@code delegationScope}.
4441 * @throws SecurityException if {@code admin} is not a device or a profile owner.
4442 */
4443 @Nullable
4444 public List<String> getDelegatePackages(@NonNull ComponentName admin,
4445 @NonNull String delegationScope) {
4446 throwIfParentInstance("getDelegatePackages");
4447 if (mService != null) {
4448 try {
4449 return mService.getDelegatePackages(admin, delegationScope);
4450 } catch (RemoteException e) {
4451 throw e.rethrowFromSystemServer();
4452 }
4453 }
4454 return null;
4455 }
4456
4457 /**
Robin Lee244ce8e2016-01-05 18:03:46 +00004458 * Called by a device or profile owner to configure an always-on VPN connection through a
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004459 * specific application for the current user. This connection is automatically granted and
4460 * persisted after a reboot.
4461 * <p>
Charles He36738632017-05-15 17:07:18 +01004462 * To support the always-on feature, an app must
4463 * <ul>
4464 * <li>declare a {@link android.net.VpnService} in its manifest, guarded by
4465 * {@link android.Manifest.permission#BIND_VPN_SERVICE};</li>
4466 * <li>target {@link android.os.Build.VERSION_CODES#N API 24} or above; and</li>
4467 * <li><i>not</i> explicitly opt out of the feature through
Charles Hec57a01c2017-08-15 15:30:22 +01004468 * {@link android.net.VpnService#SERVICE_META_DATA_SUPPORTS_ALWAYS_ON}.</li>
Charles He36738632017-05-15 17:07:18 +01004469 * </ul>
4470 * The call will fail if called with the package name of an unsupported VPN app.
Robin Lee244ce8e2016-01-05 18:03:46 +00004471 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004472 * @param vpnPackage The package name for an installed VPN app on the device, or {@code null} to
Robin Leedc679712016-05-03 13:23:03 +01004473 * remove an existing always-on VPN configuration.
4474 * @param lockdownEnabled {@code true} to disallow networking when the VPN is not connected or
4475 * {@code false} otherwise. This carries the risk that any failure of the VPN provider
4476 * could break networking for all apps. This has no effect when clearing.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004477 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Robin Leeee5eb932016-04-05 16:27:15 +01004478 * @throws NameNotFoundException if {@code vpnPackage} is not installed.
4479 * @throws UnsupportedOperationException if {@code vpnPackage} exists but does not support being
4480 * set as always-on, or if always-on VPN is not available.
Robin Lee244ce8e2016-01-05 18:03:46 +00004481 */
Robin Leedc679712016-05-03 13:23:03 +01004482 public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage,
4483 boolean lockdownEnabled)
Robin Leeee5eb932016-04-05 16:27:15 +01004484 throws NameNotFoundException, UnsupportedOperationException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004485 throwIfParentInstance("setAlwaysOnVpnPackage");
Robin Lee244ce8e2016-01-05 18:03:46 +00004486 if (mService != null) {
4487 try {
Robin Leedc679712016-05-03 13:23:03 +01004488 if (!mService.setAlwaysOnVpnPackage(admin, vpnPackage, lockdownEnabled)) {
Robin Leeee5eb932016-04-05 16:27:15 +01004489 throw new NameNotFoundException(vpnPackage);
4490 }
Robin Lee244ce8e2016-01-05 18:03:46 +00004491 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004492 throw e.rethrowFromSystemServer();
Robin Lee244ce8e2016-01-05 18:03:46 +00004493 }
4494 }
Robin Lee244ce8e2016-01-05 18:03:46 +00004495 }
4496
4497 /**
4498 * Called by a device or profile owner to read the name of the package administering an
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004499 * always-on VPN connection for the current user. If there is no such package, or the always-on
4500 * VPN is provided by the system instead of by an application, {@code null} will be returned.
Robin Lee244ce8e2016-01-05 18:03:46 +00004501 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004502 * @return Package name of VPN controller responsible for always-on VPN, or {@code null} if none
4503 * is set.
4504 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Robin Lee244ce8e2016-01-05 18:03:46 +00004505 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004506 public @Nullable String getAlwaysOnVpnPackage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004507 throwIfParentInstance("getAlwaysOnVpnPackage");
Robin Lee244ce8e2016-01-05 18:03:46 +00004508 if (mService != null) {
4509 try {
4510 return mService.getAlwaysOnVpnPackage(admin);
4511 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004512 throw e.rethrowFromSystemServer();
Robin Lee244ce8e2016-01-05 18:03:46 +00004513 }
4514 }
4515 return null;
4516 }
4517
4518 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004519 * Called by an application that is administering the device to disable all cameras on the
4520 * device, for this user. After setting this, no applications running as this user will be able
4521 * to access any cameras on the device.
4522 * <p>
4523 * If the caller is device owner, then the restriction will be applied to all users.
4524 * <p>
4525 * The calling device admin must have requested
4526 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call this method; if it has
4527 * not, a security exception will be thrown.
Ben Komalo2447edd2011-05-09 16:05:33 -07004528 *
4529 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4530 * @param disabled Whether or not the camera should be disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004531 * @throws SecurityException if {@code admin} is not an active administrator or does not use
4532 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA}.
Ben Komalo2447edd2011-05-09 16:05:33 -07004533 */
Robin Lee25e26452015-06-02 09:56:29 -07004534 public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004535 throwIfParentInstance("setCameraDisabled");
Ben Komalo2447edd2011-05-09 16:05:33 -07004536 if (mService != null) {
4537 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08004538 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07004539 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004540 throw e.rethrowFromSystemServer();
Ben Komalo2447edd2011-05-09 16:05:33 -07004541 }
4542 }
4543 }
4544
4545 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07004546 * Determine whether or not the device's cameras have been disabled for this user,
Makoto Onuki32b30572015-12-11 14:29:51 -08004547 * either by the calling admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07004548 * @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 -07004549 * have disabled the camera
4550 */
Robin Lee25e26452015-06-02 09:56:29 -07004551 public boolean getCameraDisabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004552 throwIfParentInstance("getCameraDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004553 return getCameraDisabled(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004554 }
4555
4556 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07004557 public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07004558 if (mService != null) {
4559 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004560 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07004561 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004562 throw e.rethrowFromSystemServer();
Ben Komalo2447edd2011-05-09 16:05:33 -07004563 }
4564 }
4565 return false;
4566 }
4567
4568 /**
Michal Karpinski3fc437e2015-12-15 10:09:00 +00004569 * Called by a device owner to request a bugreport.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004570 * <p>
Alex Chau443b6432017-12-13 12:44:31 +00004571 * If the device contains secondary users or profiles, they must be affiliated with the device.
4572 * Otherwise a {@link SecurityException} will be thrown. See {@link #isAffiliatedUser}.
Michal Karpinski3fc437e2015-12-15 10:09:00 +00004573 *
4574 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004575 * @return {@code true} if the bugreport collection started successfully, or {@code false} if it
4576 * wasn't triggered because a previous bugreport operation is still active (either the
4577 * bugreport is still running or waiting for the user to share or decline)
Esteban Talaverad36dd152016-12-15 08:51:45 +00004578 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
Alex Chau443b6432017-12-13 12:44:31 +00004579 * profile or secondary user that is not affiliated with the device.
4580 * @see #isAffiliatedUser
Michal Karpinski3fc437e2015-12-15 10:09:00 +00004581 */
4582 public boolean requestBugreport(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004583 throwIfParentInstance("requestBugreport");
Michal Karpinski3fc437e2015-12-15 10:09:00 +00004584 if (mService != null) {
4585 try {
4586 return mService.requestBugreport(admin);
4587 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004588 throw e.rethrowFromSystemServer();
Michal Karpinski3fc437e2015-12-15 10:09:00 +00004589 }
4590 }
4591 return false;
4592 }
4593
4594 /**
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07004595 * Determine whether or not creating a guest user has been disabled for the device
4596 *
4597 * @hide
4598 */
4599 public boolean getGuestUserDisabled(@Nullable ComponentName admin) {
4600 // Currently guest users can always be created if multi-user is enabled
4601 // TODO introduce a policy for guest user creation
4602 return false;
4603 }
4604
4605 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01004606 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
4607 * screen capture also prevents the content from being shown on display devices that do not have
4608 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
4609 * secure surfaces and secure displays.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004610 * <p>
4611 * The calling device admin must be a device or profile owner. If it is not, a security
4612 * exception will be thrown.
4613 * <p>
4614 * From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also blocks
4615 * assist requests for all activities of the relevant user.
Benjamin Franzc200f442015-06-25 18:20:04 +01004616 *
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004617 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004618 * @param disabled Whether screen capture is disabled or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004619 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004620 */
Robin Lee25e26452015-06-02 09:56:29 -07004621 public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004622 throwIfParentInstance("setScreenCaptureDisabled");
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004623 if (mService != null) {
4624 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08004625 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004626 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004627 throw e.rethrowFromSystemServer();
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004628 }
4629 }
4630 }
4631
4632 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004633 * Determine whether or not screen capture has been disabled by the calling
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004634 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07004635 * @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 +01004636 * have disabled screen capture.
4637 */
Robin Lee25e26452015-06-02 09:56:29 -07004638 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004639 throwIfParentInstance("getScreenCaptureDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004640 return getScreenCaptureDisabled(admin, myUserId());
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004641 }
4642
4643 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07004644 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004645 if (mService != null) {
4646 try {
4647 return mService.getScreenCaptureDisabled(admin, userHandle);
4648 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004649 throw e.rethrowFromSystemServer();
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004650 }
4651 }
4652 return false;
4653 }
4654
4655 /**
Jason Parks841cb0a2017-01-17 15:25:17 -06004656 * Called by a device or profile owner to set whether auto time is required. If auto time is
4657 * 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 -07004658 * <p>
4659 * Note: if auto time is required the user can still manually set the time zone.
4660 * <p>
Jason Parks841cb0a2017-01-17 15:25:17 -06004661 * The calling device admin must be a device or profile owner. If it is not, a security
4662 * exception will be thrown.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004663 *
4664 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4665 * @param required Whether auto time is set required or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004666 * @throws SecurityException if {@code admin} is not a device owner.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004667 */
Robin Lee25e26452015-06-02 09:56:29 -07004668 public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004669 throwIfParentInstance("setAutoTimeRequired");
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004670 if (mService != null) {
4671 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08004672 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004673 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004674 throw e.rethrowFromSystemServer();
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004675 }
4676 }
4677 }
4678
4679 /**
4680 * @return true if auto time is required.
4681 */
4682 public boolean getAutoTimeRequired() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004683 throwIfParentInstance("getAutoTimeRequired");
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004684 if (mService != null) {
4685 try {
4686 return mService.getAutoTimeRequired();
4687 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004688 throw e.rethrowFromSystemServer();
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004689 }
4690 }
4691 return false;
4692 }
4693
4694 /**
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004695 * Called by a device owner to set whether all users created on the device should be ephemeral.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004696 * <p>
4697 * The system user is exempt from this policy - it is never ephemeral.
4698 * <p>
4699 * The calling device admin must be the device owner. If it is not, a security exception will be
4700 * thrown.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004701 *
4702 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4703 * @param forceEphemeralUsers If true, all the existing users will be deleted and all
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004704 * subsequently created users will be ephemeral.
4705 * @throws SecurityException if {@code admin} is not a device owner.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004706 * @hide
4707 */
4708 public void setForceEphemeralUsers(
4709 @NonNull ComponentName admin, boolean forceEphemeralUsers) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004710 throwIfParentInstance("setForceEphemeralUsers");
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004711 if (mService != null) {
4712 try {
4713 mService.setForceEphemeralUsers(admin, forceEphemeralUsers);
4714 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004715 throw e.rethrowFromSystemServer();
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004716 }
4717 }
4718 }
4719
4720 /**
4721 * @return true if all users are created ephemeral.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004722 * @throws SecurityException if {@code admin} is not a device owner.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004723 * @hide
4724 */
4725 public boolean getForceEphemeralUsers(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004726 throwIfParentInstance("getForceEphemeralUsers");
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004727 if (mService != null) {
4728 try {
4729 return mService.getForceEphemeralUsers(admin);
4730 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004731 throw e.rethrowFromSystemServer();
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004732 }
4733 }
4734 return false;
4735 }
4736
4737 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07004738 * Called by an application that is administering the device to disable keyguard customizations,
4739 * such as widgets. After setting this, keyguard features will be disabled according to the
4740 * provided feature list.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004741 * <p>
4742 * The calling device admin must have requested
4743 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method;
4744 * if it has not, a security exception will be thrown.
4745 * <p>
4746 * Calling this from a managed profile before version {@link android.os.Build.VERSION_CODES#M}
4747 * will throw a security exception. From version {@link android.os.Build.VERSION_CODES#M} the
4748 * profile owner of a managed profile can set:
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00004749 * <ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00004750 * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which affects the parent user, but only if there
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004751 * is no separate challenge set on the managed profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00004752 * <li>{@link #KEYGUARD_DISABLE_FINGERPRINT} which affects the managed profile challenge if
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004753 * there is one, or the parent user otherwise.
4754 * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} which affects notifications generated
4755 * by applications in the managed profile.
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00004756 * </ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00004757 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} and {@link #KEYGUARD_DISABLE_FINGERPRINT} can also be
4758 * set on the {@link DevicePolicyManager} instance returned by
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004759 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
4760 * profile.
4761 * <p>
4762 * Requests to disable other features on a managed profile will be ignored.
4763 * <p>
4764 * The admin can check which features have been disabled by calling
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00004765 * {@link #getKeyguardDisabledFeatures(ComponentName)}
Amith Yamasani242f4b12014-10-14 16:06:13 -07004766 *
Jim Millerb8ec4702012-08-31 17:19:10 -07004767 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07004768 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004769 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
4770 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS},
4771 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
4772 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS},
4773 * {@link #KEYGUARD_DISABLE_FINGERPRINT}, {@link #KEYGUARD_DISABLE_FEATURES_ALL}
4774 * @throws SecurityException if {@code admin} is not an active administrator or does not user
4775 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES}
Jim Millerb8ec4702012-08-31 17:19:10 -07004776 */
Robin Lee25e26452015-06-02 09:56:29 -07004777 public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07004778 if (mService != null) {
4779 try {
Esteban Talavera62399912016-01-11 15:37:55 +00004780 mService.setKeyguardDisabledFeatures(admin, which, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07004781 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004782 throw e.rethrowFromSystemServer();
Jim Millerb8ec4702012-08-31 17:19:10 -07004783 }
4784 }
4785 }
4786
4787 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004788 * Determine whether or not features have been disabled in keyguard either by the calling
Rubin Xud3609d42016-07-13 18:32:57 +01004789 * admin, if specified, or all admins that set restrictions on this user and its participating
Esteban Talaverac1c83592016-02-17 17:56:15 +00004790 * profiles. Restrictions on profiles that have a separate challenge are not taken into account.
4791 *
4792 * <p>This method can be called on the {@link DevicePolicyManager} instance
4793 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
4794 * restrictions on the parent profile.
4795 *
Esteban Talavera62399912016-01-11 15:37:55 +00004796 * @param admin The name of the admin component to check, or {@code null} to check whether any
4797 * admins have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07004798 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
4799 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07004800 */
Robin Lee25e26452015-06-02 09:56:29 -07004801 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004802 return getKeyguardDisabledFeatures(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004803 }
4804
4805 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07004806 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07004807 if (mService != null) {
4808 try {
Esteban Talavera62399912016-01-11 15:37:55 +00004809 return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07004810 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004811 throw e.rethrowFromSystemServer();
Jim Millerb8ec4702012-08-31 17:19:10 -07004812 }
4813 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07004814 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07004815 }
4816
4817 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08004818 * @hide
4819 */
Robin Lee25e26452015-06-02 09:56:29 -07004820 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
4821 int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08004822 if (mService != null) {
4823 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01004824 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08004825 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004826 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08004827 }
4828 }
4829 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07004830
Dianne Hackbornd6847842010-01-12 18:14:19 -08004831 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01004832 * @hide
4833 */
Robin Lee25e26452015-06-02 09:56:29 -07004834 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004835 setActiveAdmin(policyReceiver, refreshing, myUserId());
Jessica Hummel6d36b602014-04-04 12:42:17 +01004836 }
4837
4838 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08004839 * @hide
4840 */
Robin Lee25e26452015-06-02 09:56:29 -07004841 public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08004842 if (mService != null) {
4843 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004844 mService.getRemoveWarning(admin, result, myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08004845 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004846 throw e.rethrowFromSystemServer();
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08004847 }
4848 }
4849 }
4850
4851 /**
4852 * @hide
4853 */
Andrew Scull5f9e6f32016-08-02 14:22:17 +01004854 public void setActivePasswordState(PasswordMetrics metrics, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08004855 if (mService != null) {
4856 try {
Andrew Scull5f9e6f32016-08-02 14:22:17 +01004857 mService.setActivePasswordState(metrics, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08004858 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004859 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08004860 }
4861 }
4862 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07004863
Dianne Hackbornd6847842010-01-12 18:14:19 -08004864 /**
4865 * @hide
4866 */
Andrew Scull5daf2732016-11-14 15:02:45 +00004867 public void reportPasswordChanged(@UserIdInt int userId) {
4868 if (mService != null) {
4869 try {
4870 mService.reportPasswordChanged(userId);
4871 } catch (RemoteException e) {
4872 throw e.rethrowFromSystemServer();
4873 }
4874 }
4875 }
4876
4877 /**
4878 * @hide
4879 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004880 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08004881 if (mService != null) {
4882 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004883 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08004884 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004885 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08004886 }
4887 }
4888 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07004889
Dianne Hackbornd6847842010-01-12 18:14:19 -08004890 /**
4891 * @hide
4892 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004893 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08004894 if (mService != null) {
4895 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004896 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08004897 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004898 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08004899 }
4900 }
4901 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07004902
4903 /**
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004904 * @hide
4905 */
4906 public void reportFailedFingerprintAttempt(int userHandle) {
4907 if (mService != null) {
4908 try {
4909 mService.reportFailedFingerprintAttempt(userHandle);
4910 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004911 throw e.rethrowFromSystemServer();
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004912 }
4913 }
4914 }
4915
4916 /**
4917 * @hide
4918 */
4919 public void reportSuccessfulFingerprintAttempt(int userHandle) {
4920 if (mService != null) {
4921 try {
4922 mService.reportSuccessfulFingerprintAttempt(userHandle);
4923 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004924 throw e.rethrowFromSystemServer();
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004925 }
4926 }
4927 }
4928
4929 /**
Michal Karpinski31502d32016-01-25 16:43:07 +00004930 * Should be called when keyguard has been dismissed.
4931 * @hide
4932 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004933 public void reportKeyguardDismissed(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00004934 if (mService != null) {
4935 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004936 mService.reportKeyguardDismissed(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00004937 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004938 throw e.rethrowFromSystemServer();
Michal Karpinski31502d32016-01-25 16:43:07 +00004939 }
4940 }
4941 }
4942
4943 /**
4944 * Should be called when keyguard view has been shown to the user.
4945 * @hide
4946 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004947 public void reportKeyguardSecured(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00004948 if (mService != null) {
4949 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004950 mService.reportKeyguardSecured(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00004951 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004952 throw e.rethrowFromSystemServer();
Michal Karpinski31502d32016-01-25 16:43:07 +00004953 }
4954 }
4955 }
4956
4957 /**
Amith Yamasani71e6c692013-03-24 17:39:28 -07004958 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00004959 * Sets the given package as the device owner.
Makoto Onukia52562c2015-10-01 16:12:31 -07004960 * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name.
4961 * @param who the component name to be registered as device owner.
Amith Yamasani71e6c692013-03-24 17:39:28 -07004962 * @return whether the package was successfully registered as the device owner.
4963 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00004964 * @throws IllegalStateException If the preconditions mentioned are not met.
Amith Yamasani71e6c692013-03-24 17:39:28 -07004965 */
Makoto Onukia52562c2015-10-01 16:12:31 -07004966 public boolean setDeviceOwner(ComponentName who) {
4967 return setDeviceOwner(who, null);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004968 }
4969
4970 /**
4971 * @hide
Makoto Onuki58b684f2015-09-04 10:48:16 -07004972 */
Makoto Onukia52562c2015-10-01 16:12:31 -07004973 public boolean setDeviceOwner(ComponentName who, int userId) {
4974 return setDeviceOwner(who, null, userId);
Makoto Onuki58b684f2015-09-04 10:48:16 -07004975 }
4976
4977 /**
4978 * @hide
4979 */
Makoto Onukia52562c2015-10-01 16:12:31 -07004980 public boolean setDeviceOwner(ComponentName who, String ownerName) {
4981 return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM);
Makoto Onuki58b684f2015-09-04 10:48:16 -07004982 }
4983
4984 /**
4985 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00004986 * Sets the given package as the device owner. The package must already be installed. There
4987 * must not already be a device owner.
4988 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
4989 * this method.
4990 * Calling this after the setup phase of the primary user has completed is allowed only if
4991 * the caller is the shell uid, and there are no additional users and no accounts.
Makoto Onukia52562c2015-10-01 16:12:31 -07004992 * @param who the component name to be registered as device owner.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004993 * @param ownerName the human readable name of the institution that owns this device.
Makoto Onuki58b684f2015-09-04 10:48:16 -07004994 * @param userId ID of the user on which the device owner runs.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004995 * @return whether the package was successfully registered as the device owner.
4996 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00004997 * @throws IllegalStateException If the preconditions mentioned are not met.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004998 */
Makoto Onukia52562c2015-10-01 16:12:31 -07004999 public boolean setDeviceOwner(ComponentName who, String ownerName, int userId)
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04005000 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07005001 if (mService != null) {
5002 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07005003 return mService.setDeviceOwner(who, ownerName, userId);
Amith Yamasani71e6c692013-03-24 17:39:28 -07005004 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005005 throw re.rethrowFromSystemServer();
Amith Yamasani71e6c692013-03-24 17:39:28 -07005006 }
5007 }
5008 return false;
5009 }
5010
5011 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07005012 * Used to determine if a particular package has been registered as a Device Owner app.
5013 * A device owner app is a special device admin that cannot be deactivated by the user, once
Robin Lee25e26452015-06-02 09:56:29 -07005014 * activated as a device admin. It also cannot be uninstalled. To check whether a particular
Amith Yamasani3b458ad2013-04-18 18:40:07 -07005015 * package is currently registered as the device owner app, pass in the package name from
5016 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
Robin Lee25e26452015-06-02 09:56:29 -07005017 * admin apps that want to check whether they are also registered as the device owner app. The
Amith Yamasani3b458ad2013-04-18 18:40:07 -07005018 * exact mechanism by which a device admin app is registered as a device owner app is defined by
5019 * the setup process.
5020 * @param packageName the package name of the app, to compare with the registered device owner
5021 * app, if any.
Makoto Onukic8a5a552015-11-19 14:29:12 -08005022 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07005023 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07005024 public boolean isDeviceOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005025 throwIfParentInstance("isDeviceOwnerApp");
Makoto Onukic8a5a552015-11-19 14:29:12 -08005026 return isDeviceOwnerAppOnCallingUser(packageName);
5027 }
5028
5029 /**
5030 * @return true if a package is registered as device owner, only when it's running on the
5031 * calling user.
5032 *
5033 * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity.
5034 * @hide
5035 */
5036 public boolean isDeviceOwnerAppOnCallingUser(String packageName) {
5037 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true);
5038 }
5039
5040 /**
5041 * @return true if a package is registered as device owner, even if it's running on a different
5042 * user.
5043 *
5044 * <p>Requires the MANAGE_USERS permission.
5045 *
5046 * @hide
5047 */
5048 public boolean isDeviceOwnerAppOnAnyUser(String packageName) {
5049 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false);
5050 }
5051
5052 /**
5053 * @return device owner component name, only when it's running on the calling user.
5054 *
5055 * @hide
5056 */
5057 public ComponentName getDeviceOwnerComponentOnCallingUser() {
5058 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true);
5059 }
5060
5061 /**
5062 * @return device owner component name, even if it's running on a different user.
5063 *
Makoto Onukic8a5a552015-11-19 14:29:12 -08005064 * @hide
5065 */
Polina Bondarenko23561db2016-12-16 11:47:28 +01005066 @SystemApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06005067 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Makoto Onukic8a5a552015-11-19 14:29:12 -08005068 public ComponentName getDeviceOwnerComponentOnAnyUser() {
5069 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false);
5070 }
5071
5072 private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) {
Makoto Onuki70f929e2015-11-11 12:40:15 -08005073 if (packageName == null) {
5074 return false;
Amith Yamasani71e6c692013-03-24 17:39:28 -07005075 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08005076 final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly);
Makoto Onuki70f929e2015-11-11 12:40:15 -08005077 if (deviceOwner == null) {
5078 return false;
5079 }
5080 return packageName.equals(deviceOwner.getPackageName());
Amith Yamasani71e6c692013-03-24 17:39:28 -07005081 }
5082
Makoto Onukic8a5a552015-11-19 14:29:12 -08005083 private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) {
5084 if (mService != null) {
5085 try {
5086 return mService.getDeviceOwnerComponent(callingUserOnly);
5087 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005088 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08005089 }
5090 }
5091 return null;
Amith Yamasani3b458ad2013-04-18 18:40:07 -07005092 }
5093
Jason Monkb0dced82014-06-06 14:36:20 -04005094 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08005095 * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's
5096 * no device owner.
5097 *
5098 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07005099 *
5100 * @hide
5101 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08005102 public int getDeviceOwnerUserId() {
5103 if (mService != null) {
5104 try {
5105 return mService.getDeviceOwnerUserId();
5106 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005107 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08005108 }
5109 }
5110 return UserHandle.USER_NULL;
Makoto Onukia52562c2015-10-01 16:12:31 -07005111 }
5112
5113 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005114 * Clears the current device owner. The caller must be the device owner. This function should be
5115 * 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 +00005116 * a part of device setup, before it completes.
5117 * <p>
5118 * While some policies previously set by the device owner will be cleared by this method, it is
5119 * a best-effort process and some other policies will still remain in place after the device
5120 * owner is cleared.
Jason Monk94d2cf92014-06-18 09:53:34 -04005121 *
5122 * @param packageName The package name of the device owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005123 * @throws SecurityException if the caller is not in {@code packageName} or {@code packageName}
5124 * does not own the current device owner component.
Esteban Talaveraa5b09632017-02-10 16:15:24 +00005125 *
5126 * @deprecated This method is expected to be used for testing purposes only. The device owner
5127 * will lose control of the device and its data after calling it. In order to protect any
5128 * sensitive data that remains on the device, it is advised that the device owner factory resets
5129 * the device instead of calling this method. See {@link #wipeData(int)}.
Jason Monkb0dced82014-06-06 14:36:20 -04005130 */
Esteban Talaveraa5b09632017-02-10 16:15:24 +00005131 @Deprecated
Jason Monk94d2cf92014-06-18 09:53:34 -04005132 public void clearDeviceOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005133 throwIfParentInstance("clearDeviceOwnerApp");
Jason Monkb0dced82014-06-06 14:36:20 -04005134 if (mService != null) {
5135 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04005136 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04005137 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005138 throw re.rethrowFromSystemServer();
Jason Monkb0dced82014-06-06 14:36:20 -04005139 }
5140 }
5141 }
5142
Makoto Onukia52562c2015-10-01 16:12:31 -07005143 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08005144 * Returns the device owner package name, only if it's running on the calling user.
5145 *
5146 * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity.
Makoto Onukia52562c2015-10-01 16:12:31 -07005147 *
5148 * @hide
5149 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01005150 @SystemApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06005151 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Makoto Onuki408e8e42016-10-25 12:10:27 -07005152 public @Nullable String getDeviceOwner() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005153 throwIfParentInstance("getDeviceOwner");
Makoto Onukic8a5a552015-11-19 14:29:12 -08005154 final ComponentName name = getDeviceOwnerComponentOnCallingUser();
5155 return name != null ? name.getPackageName() : null;
Makoto Onukia52562c2015-10-01 16:12:31 -07005156 }
5157
5158 /**
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01005159 * Called by the system to find out whether the device is managed by a Device Owner.
Makoto Onukic8a5a552015-11-19 14:29:12 -08005160 *
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01005161 * @return whether the device is managed by a Device Owner.
5162 * @throws SecurityException if the caller is not the device owner, does not hold the
5163 * MANAGE_USERS permission and is not the system.
Makoto Onukia52562c2015-10-01 16:12:31 -07005164 *
5165 * @hide
5166 */
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01005167 @SystemApi
5168 @TestApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06005169 @SuppressLint("Doclava125")
Makoto Onukic8a5a552015-11-19 14:29:12 -08005170 public boolean isDeviceManaged() {
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01005171 try {
5172 return mService.hasDeviceOwner();
5173 } catch (RemoteException re) {
5174 throw re.rethrowFromSystemServer();
5175 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08005176 }
5177
5178 /**
5179 * Returns the device owner name. Note this method *will* return the device owner
5180 * name when it's running on a different user.
5181 *
Makoto Onukic8a5a552015-11-19 14:29:12 -08005182 * @hide
5183 */
Makoto Onukia2b274b2016-01-19 13:26:02 -08005184 @SystemApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06005185 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Makoto Onukic8a5a552015-11-19 14:29:12 -08005186 public String getDeviceOwnerNameOnAnyUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005187 throwIfParentInstance("getDeviceOwnerNameOnAnyUser");
Amith Yamasani71e6c692013-03-24 17:39:28 -07005188 if (mService != null) {
5189 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07005190 return mService.getDeviceOwnerName();
Amith Yamasani71e6c692013-03-24 17:39:28 -07005191 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005192 throw re.rethrowFromSystemServer();
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04005193 }
5194 }
5195 return null;
5196 }
Adam Connors776c5552014-01-09 10:42:56 +00005197
5198 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04005199 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04005200 * @deprecated Do not use
5201 * @removed
Julia Reynolds20118f12015-02-11 12:34:08 -05005202 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04005203 @Deprecated
Julia Reynolds20118f12015-02-11 12:34:08 -05005204 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06005205 @SuppressLint("Doclava125")
Makoto Onuki408e8e42016-10-25 12:10:27 -07005206 public @Nullable String getDeviceInitializerApp() {
Julia Reynolds20118f12015-02-11 12:34:08 -05005207 return null;
5208 }
5209
5210 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04005211 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04005212 * @deprecated Do not use
5213 * @removed
Julia Reynoldseaafdf722015-04-02 08:49:47 -04005214 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04005215 @Deprecated
Julia Reynoldseaafdf722015-04-02 08:49:47 -04005216 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06005217 @SuppressLint("Doclava125")
Makoto Onuki408e8e42016-10-25 12:10:27 -07005218 public @Nullable ComponentName getDeviceInitializerComponent() {
Julia Reynoldseaafdf722015-04-02 08:49:47 -04005219 return null;
5220 }
5221
Julia Reynolds20118f12015-02-11 12:34:08 -05005222 /**
Adam Connors776c5552014-01-09 10:42:56 +00005223 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07005224 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05305225 * Sets the given component as an active admin and registers the package as the profile
5226 * owner for this user. The package must already be installed and there shouldn't be
5227 * an existing profile owner registered for this user. Also, this method must be called
5228 * before the user setup has been completed.
5229 * <p>
5230 * This method can only be called by system apps that hold MANAGE_USERS permission and
5231 * MANAGE_DEVICE_ADMINS permission.
5232 * @param admin The component to register as an active admin and profile owner.
5233 * @param ownerName The user-visible name of the entity that is managing this user.
5234 * @return whether the admin was successfully registered as the profile owner.
5235 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
5236 * the user has already been set up.
5237 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07005238 @Deprecated
Justin Morey80440cc2014-07-24 09:16:35 -05005239 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06005240 @RequiresPermission(android.Manifest.permission.MANAGE_DEVICE_ADMINS)
Robin Lee25e26452015-06-02 09:56:29 -07005241 public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05305242 throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005243 throwIfParentInstance("setActiveProfileOwner");
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05305244 if (mService != null) {
5245 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07005246 final int myUserId = myUserId();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05305247 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07005248 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05305249 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005250 throw re.rethrowFromSystemServer();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05305251 }
5252 }
5253 return false;
5254 }
5255
5256 /**
Esteban Talaveraa5b09632017-02-10 16:15:24 +00005257 * Clears the active profile owner. The caller must be the profile owner of this user, otherwise
5258 * a SecurityException will be thrown. This method is not available to managed profile owners.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005259 * <p>
Esteban Talaveraa5b09632017-02-10 16:15:24 +00005260 * While some policies previously set by the profile owner will be cleared by this method, it is
5261 * a best-effort process and some other policies will still remain in place after the profile
5262 * owner is cleared.
Makoto Onuki5bf68022016-01-27 13:49:19 -08005263 *
Amith Yamasanibf3a9462014-07-28 14:26:42 -07005264 * @param admin The component to remove as the profile owner.
Esteban Talaveraa5b09632017-02-10 16:15:24 +00005265 * @throws SecurityException if {@code admin} is not an active profile owner, or the method is
5266 * being called from a managed profile.
5267 *
5268 * @deprecated This method is expected to be used for testing purposes only. The profile owner
5269 * will lose control of the user and its data after calling it. In order to protect any
5270 * sensitive data that remains on this user, it is advised that the profile owner deletes it
5271 * instead of calling this method. See {@link #wipeData(int)}.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07005272 */
Esteban Talaveraa5b09632017-02-10 16:15:24 +00005273 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07005274 public void clearProfileOwner(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005275 throwIfParentInstance("clearProfileOwner");
Amith Yamasanibf3a9462014-07-28 14:26:42 -07005276 if (mService != null) {
5277 try {
5278 mService.clearProfileOwner(admin);
5279 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005280 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07005281 }
5282 }
5283 }
5284
5285 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05005286 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07005287 * Checks whether the user was already setup.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07005288 */
5289 public boolean hasUserSetupCompleted() {
5290 if (mService != null) {
5291 try {
5292 return mService.hasUserSetupCompleted();
5293 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005294 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07005295 }
5296 }
5297 return true;
5298 }
5299
5300 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07005301 * @hide
5302 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00005303 * already be installed. There must not already be a profile owner for this user.
5304 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
5305 * this method.
5306 * Calling this after the setup phase of the specified user has completed is allowed only if:
5307 * - the caller is SYSTEM_UID.
5308 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07005309 * @param admin the component name to be registered as profile owner.
5310 * @param ownerName the human readable name of the organisation associated with this DPM.
5311 * @param userHandle the userId to set the profile owner for.
5312 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00005313 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
5314 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07005315 */
Robin Lee25e26452015-06-02 09:56:29 -07005316 public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName,
Robin Leeddd553f2015-04-30 14:18:22 +01005317 int userHandle) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00005318 if (mService != null) {
5319 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07005320 if (ownerName == null) {
5321 ownerName = "";
5322 }
5323 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00005324 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005325 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00005326 }
5327 }
5328 return false;
5329 }
5330
5331 /**
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00005332 * Sets the device owner information to be shown on the lock screen.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005333 * <p>
5334 * If the device owner information is {@code null} or empty then the device owner info is
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00005335 * cleared and the user owner info is shown on the lock screen if it is set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005336 * <p>
5337 * If the device owner information contains only whitespaces then the message on the lock screen
5338 * will be blank and the user will not be allowed to change it.
5339 * <p>
5340 * If the device owner information needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00005341 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
5342 * and set a new version of this string accordingly.
5343 *
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00005344 * @param admin The name of the admin component to check.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005345 * @param info Device owner information which will be displayed instead of the user owner info.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005346 * @throws SecurityException if {@code admin} is not a device owner.
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00005347 */
Andrei Stingaceanu16187902016-03-21 15:44:45 +00005348 public void setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, CharSequence info) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005349 throwIfParentInstance("setDeviceOwnerLockScreenInfo");
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00005350 if (mService != null) {
5351 try {
Andrei Stingaceanu16187902016-03-21 15:44:45 +00005352 mService.setDeviceOwnerLockScreenInfo(admin, info);
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00005353 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005354 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00005355 }
5356 }
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00005357 }
5358
5359 /**
5360 * @return The device owner information. If it is not set returns {@code null}.
5361 */
Andrei Stingaceanu16187902016-03-21 15:44:45 +00005362 public CharSequence getDeviceOwnerLockScreenInfo() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005363 throwIfParentInstance("getDeviceOwnerLockScreenInfo");
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00005364 if (mService != null) {
5365 try {
5366 return mService.getDeviceOwnerLockScreenInfo();
5367 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005368 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00005369 }
5370 }
5371 return null;
5372 }
5373
5374 /**
Edman Anjos52088e42017-01-13 22:26:17 +01005375 * Called by device or profile owners to suspend packages for this user. This function can be
5376 * called by a device owner, profile owner, or by a delegate given the
5377 * {@link #DELEGATION_PACKAGE_ACCESS} scope via {@link #setDelegatedScopes}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005378 * <p>
5379 * A suspended package will not be able to start activities. Its notifications will be hidden,
5380 * it will not show up in recents, will not be able to show toasts or dialogs or ring the
5381 * device.
5382 * <p>
5383 * The package must already be installed. If the package is uninstalled while suspended the
5384 * package will no longer be suspended. The admin can block this by using
Kenny Guy871f3eb2016-03-09 20:06:16 +00005385 * {@link #setUninstallBlocked}.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00005386 *
Edman Anjos52088e42017-01-13 22:26:17 +01005387 * @param admin The name of the admin component to check, or {@code null} if the caller is a
5388 * package access delegate.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00005389 * @param packageNames The package names to suspend or unsuspend.
5390 * @param suspended If set to {@code true} than the packages will be suspended, if set to
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005391 * {@code false} the packages will be unsuspended.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00005392 * @return an array of package names for which the suspended status is not set as requested in
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005393 * this method.
5394 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01005395 * @see #setDelegatedScopes
5396 * @see #DELEGATION_PACKAGE_ACCESS
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00005397 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005398 public @NonNull String[] setPackagesSuspended(@NonNull ComponentName admin,
5399 @NonNull String[] packageNames, boolean suspended) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005400 throwIfParentInstance("setPackagesSuspended");
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00005401 if (mService != null) {
5402 try {
Edman Anjos52088e42017-01-13 22:26:17 +01005403 return mService.setPackagesSuspended(admin, mContext.getPackageName(), packageNames,
5404 suspended);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00005405 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005406 throw re.rethrowFromSystemServer();
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00005407 }
5408 }
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00005409 return packageNames;
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00005410 }
5411
5412 /**
Edman Anjos52088e42017-01-13 22:26:17 +01005413 * Determine if a package is suspended. This function can be called by a device owner, profile
5414 * owner, or by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via
5415 * {@link #setDelegatedScopes}.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00005416 *
Edman Anjos52088e42017-01-13 22:26:17 +01005417 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
5418 * {@code null} if the caller is a package access delegate.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00005419 * @param packageName The name of the package to retrieve the suspended status of.
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00005420 * @return {@code true} if the package is suspended or {@code false} if the package is not
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005421 * suspended, could not be found or an error occurred.
5422 * @throws SecurityException if {@code admin} is not a device or profile owner.
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00005423 * @throws NameNotFoundException if the package could not be found.
Edman Anjos52088e42017-01-13 22:26:17 +01005424 * @see #setDelegatedScopes
5425 * @see #DELEGATION_PACKAGE_ACCESS
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00005426 */
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00005427 public boolean isPackageSuspended(@NonNull ComponentName admin, String packageName)
5428 throws NameNotFoundException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005429 throwIfParentInstance("isPackageSuspended");
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00005430 if (mService != null) {
5431 try {
Edman Anjos52088e42017-01-13 22:26:17 +01005432 return mService.isPackageSuspended(admin, mContext.getPackageName(), packageName);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00005433 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005434 throw e.rethrowFromSystemServer();
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00005435 } catch (IllegalArgumentException ex) {
5436 throw new NameNotFoundException(packageName);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00005437 }
5438 }
5439 return false;
5440 }
5441
5442 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01005443 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
5444 * be used. Only the profile owner can call this.
5445 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01005446 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01005447 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005448 * @throws SecurityException if {@code admin} is not a profile owner.
Alexandra Gherghina512675b2014-04-02 11:23:54 +01005449 */
Robin Lee25e26452015-06-02 09:56:29 -07005450 public void setProfileEnabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005451 throwIfParentInstance("setProfileEnabled");
Alexandra Gherghina512675b2014-04-02 11:23:54 +01005452 if (mService != null) {
5453 try {
5454 mService.setProfileEnabled(admin);
5455 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005456 throw e.rethrowFromSystemServer();
Alexandra Gherghina512675b2014-04-02 11:23:54 +01005457 }
5458 }
5459 }
5460
5461 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005462 * Sets the name of the profile. In the device owner case it sets the name of the user which it
5463 * is called from. Only a profile owner or device owner can call this. If this is never called
5464 * by the profile or device owner, the name will be set to default values.
Jessica Hummel1333ea12014-06-23 11:20:10 +01005465 *
5466 * @see #isProfileOwnerApp
5467 * @see #isDeviceOwnerApp
Robin Lee25e26452015-06-02 09:56:29 -07005468 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01005469 * @param profileName The name of the profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005470 * @throws SecurityException if {@code admin} is not a device or profile owner.
Jessica Hummel1333ea12014-06-23 11:20:10 +01005471 */
Robin Lee25e26452015-06-02 09:56:29 -07005472 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005473 throwIfParentInstance("setProfileName");
Jessica Hummel1333ea12014-06-23 11:20:10 +01005474 if (mService != null) {
5475 try {
Robin Lee25e26452015-06-02 09:56:29 -07005476 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07005477 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005478 throw e.rethrowFromSystemServer();
Fyodor Kupolov78f13142015-05-27 16:52:45 -07005479 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01005480 }
5481 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01005482
5483 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005484 * Used to determine if a particular package is registered as the profile owner for the
Makoto Onuki32b30572015-12-11 14:29:51 -08005485 * user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005486 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00005487 *
5488 * @param packageName The package name of the app to compare with the registered profile owner.
5489 * @return Whether or not the package is registered as the profile owner.
5490 */
5491 public boolean isProfileOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005492 throwIfParentInstance("isProfileOwnerApp");
Adam Connors776c5552014-01-09 10:42:56 +00005493 if (mService != null) {
5494 try {
Makoto Onuki90b89652016-01-28 14:44:18 -08005495 ComponentName profileOwner = mService.getProfileOwner(myUserId());
Nicolas Prevot90af6d72014-07-30 14:19:12 +01005496 return profileOwner != null
5497 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00005498 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005499 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00005500 }
5501 }
5502 return false;
5503 }
5504
5505 /**
5506 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07005507 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00005508 * owner has been set for that user.
5509 * @throws IllegalArgumentException if the userId is invalid.
5510 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01005511 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07005512 public @Nullable ComponentName getProfileOwner() throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005513 throwIfParentInstance("getProfileOwner");
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01005514 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
5515 }
5516
5517 /**
5518 * @see #getProfileOwner()
5519 * @hide
5520 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005521 public @Nullable ComponentName getProfileOwnerAsUser(final int userId)
5522 throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00005523 if (mService != null) {
5524 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01005525 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00005526 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005527 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00005528 }
5529 }
5530 return null;
5531 }
5532
5533 /**
5534 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07005535 * @return the human readable name of the organisation associated with this DPM or {@code null}
5536 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00005537 * @throws IllegalArgumentException if the userId is invalid.
5538 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005539 public @Nullable String getProfileOwnerName() throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00005540 if (mService != null) {
5541 try {
5542 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
5543 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005544 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00005545 }
5546 }
5547 return null;
5548 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005549
5550 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07005551 * @hide
Makoto Onukic8a5a552015-11-19 14:29:12 -08005552 * @param userId The user for whom to fetch the profile owner name, if any.
Amith Yamasani38f836b2014-08-20 14:51:15 -07005553 * @return the human readable name of the organisation associated with this profile owner or
5554 * null if one is not set.
5555 * @throws IllegalArgumentException if the userId is invalid.
5556 */
5557 @SystemApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06005558 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Makoto Onuki408e8e42016-10-25 12:10:27 -07005559 public @Nullable String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005560 throwIfParentInstance("getProfileOwnerNameAsUser");
Amith Yamasani38f836b2014-08-20 14:51:15 -07005561 if (mService != null) {
5562 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02005563 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07005564 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005565 throw re.rethrowFromSystemServer();
Amith Yamasani38f836b2014-08-20 14:51:15 -07005566 }
5567 }
5568 return null;
5569 }
5570
5571 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005572 * Called by a profile owner or device owner to add a default intent handler activity for
5573 * intents that match a certain intent filter. This activity will remain the default intent
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005574 * handler even if the set of potential event handlers for the intent filter changes and if the
5575 * intent preferences are reset.
5576 * <p>
5577 * The default disambiguation mechanism takes over if the activity is not installed (anymore).
5578 * When the activity is (re)installed, it is automatically reset as default intent handler for
5579 * the filter.
5580 * <p>
5581 * The calling device admin must be a profile owner or device owner. If it is not, a security
5582 * exception will be thrown.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005583 *
5584 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5585 * @param filter The IntentFilter for which a default handler is added.
5586 * @param activity The Activity that is added as default intent handler.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005587 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005588 */
Robin Lee25e26452015-06-02 09:56:29 -07005589 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
5590 @NonNull ComponentName activity) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005591 throwIfParentInstance("addPersistentPreferredActivity");
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005592 if (mService != null) {
5593 try {
5594 mService.addPersistentPreferredActivity(admin, filter, activity);
5595 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005596 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005597 }
5598 }
5599 }
5600
5601 /**
5602 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00005603 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005604 * <p>
5605 * The calling device admin must be a profile owner. If it is not, a security exception will be
5606 * thrown.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005607 *
5608 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5609 * @param packageName The name of the package for which preferences are removed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005610 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005611 */
Robin Lee25e26452015-06-02 09:56:29 -07005612 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005613 String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005614 throwIfParentInstance("clearPackagePersistentPreferredActivities");
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005615 if (mService != null) {
5616 try {
5617 mService.clearPackagePersistentPreferredActivities(admin, packageName);
5618 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005619 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005620 }
5621 }
5622 }
Robin Lee66e5d962014-04-09 16:44:21 +01005623
5624 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00005625 * Called by a profile owner or device owner to grant permission to a package to manage
5626 * application restrictions for the calling user via {@link #setApplicationRestrictions} and
5627 * {@link #getApplicationRestrictions}.
5628 * <p>
5629 * This permission is persistent until it is later cleared by calling this method with a
5630 * {@code null} value or uninstalling the managing package.
Rubin Xuf03d0a62016-02-10 14:54:15 +00005631 * <p>
5632 * The supplied application restriction managing package must be installed when calling this
Victor Changcd14c0a2016-03-16 19:10:15 +00005633 * API, otherwise an {@link NameNotFoundException} will be thrown.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005634 *
5635 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5636 * @param packageName The package name which will be given access to application restrictions
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005637 * APIs. If {@code null} is given the current package will be cleared.
5638 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Changcd14c0a2016-03-16 19:10:15 +00005639 * @throws NameNotFoundException if {@code packageName} is not found
Edman Anjosf9946772016-11-28 16:35:15 +01005640 *
5641 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #setDelegatedScopes}
5642 * with the {@link #DELEGATION_APP_RESTRICTIONS} scope instead.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005643 */
Edman Anjosf9946772016-11-28 16:35:15 +01005644 @Deprecated
Esteban Talaverabf60f722015-12-10 16:26:44 +00005645 public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin,
Victor Changcd14c0a2016-03-16 19:10:15 +00005646 @Nullable String packageName) throws NameNotFoundException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005647 throwIfParentInstance("setApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00005648 if (mService != null) {
5649 try {
Victor Changcd14c0a2016-03-16 19:10:15 +00005650 if (!mService.setApplicationRestrictionsManagingPackage(admin, packageName)) {
5651 throw new NameNotFoundException(packageName);
5652 }
Esteban Talaverabf60f722015-12-10 16:26:44 +00005653 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005654 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00005655 }
5656 }
5657 }
5658
5659 /**
5660 * Called by a profile owner or device owner to retrieve the application restrictions managing
Edman Anjosf9946772016-11-28 16:35:15 +01005661 * package for the current user, or {@code null} if none is set. If there are multiple
5662 * delegates this function will return one of them.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005663 *
5664 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5665 * @return The package name allowed to manage application restrictions on the current user, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005666 * {@code null} if none is set.
5667 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01005668 *
5669 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatePackages}
5670 * with the {@link #DELEGATION_APP_RESTRICTIONS} scope instead.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005671 */
Edman Anjosf9946772016-11-28 16:35:15 +01005672 @Deprecated
5673 @Nullable
5674 public String getApplicationRestrictionsManagingPackage(
Makoto Onuki408e8e42016-10-25 12:10:27 -07005675 @NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005676 throwIfParentInstance("getApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00005677 if (mService != null) {
5678 try {
5679 return mService.getApplicationRestrictionsManagingPackage(admin);
5680 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005681 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00005682 }
5683 }
5684 return null;
5685 }
5686
5687 /**
Esteban Talavera96895ca2016-03-16 12:00:40 +00005688 * Called by any application to find out whether it has been granted permission via
5689 * {@link #setApplicationRestrictionsManagingPackage} to manage application restrictions
5690 * for the calling user.
5691 *
5692 * <p>This is done by comparing the calling Linux uid with the uid of the package specified by
5693 * that method.
Edman Anjosf9946772016-11-28 16:35:15 +01005694 *
5695 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatedScopes}
5696 * instead.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005697 */
Edman Anjosf9946772016-11-28 16:35:15 +01005698 @Deprecated
Esteban Talaverabf60f722015-12-10 16:26:44 +00005699 public boolean isCallerApplicationRestrictionsManagingPackage() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005700 throwIfParentInstance("isCallerApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00005701 if (mService != null) {
5702 try {
Edman Anjosf9946772016-11-28 16:35:15 +01005703 return mService.isCallerApplicationRestrictionsManagingPackage(
5704 mContext.getPackageName());
Esteban Talaverabf60f722015-12-10 16:26:44 +00005705 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005706 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00005707 }
5708 }
5709 return false;
5710 }
5711
5712 /**
5713 * Sets the application restrictions for a given target application running in the calling user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005714 * <p>
5715 * 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 +01005716 * application restrictions via {@link #setDelegatedScopes} with the
5717 * {@link #DELEGATION_APP_RESTRICTIONS} scope; otherwise a security exception will be thrown.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005718 * <p>
5719 * The provided {@link Bundle} consists of key-value pairs, where the types of values may be:
Esteban Talavera6b8e0642015-08-10 17:26:04 +01005720 * <ul>
5721 * <li>{@code boolean}
5722 * <li>{@code int}
5723 * <li>{@code String} or {@code String[]}
5724 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
5725 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005726 * <p>
5727 * If the restrictions are not available yet, but may be applied in the near future, the caller
5728 * can notify the target application of that by adding
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00005729 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005730 * <p>
5731 * The application restrictions are only made visible to the target application via
5732 * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or device
5733 * owner, and the application restrictions managing package via
Esteban Talaverabf60f722015-12-10 16:26:44 +00005734 * {@link #getApplicationRestrictions}.
Robin Lee66e5d962014-04-09 16:44:21 +01005735 *
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005736 * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
5737 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00005738 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005739 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01005740 * @param packageName The name of the package to update restricted settings for.
5741 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005742 * set of active restrictions.
5743 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01005744 * @see #setDelegatedScopes
5745 * @see #DELEGATION_APP_RESTRICTIONS
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00005746 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01005747 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005748 @WorkerThread
Esteban Talaverabf60f722015-12-10 16:26:44 +00005749 public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01005750 Bundle settings) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005751 throwIfParentInstance("setApplicationRestrictions");
Robin Lee66e5d962014-04-09 16:44:21 +01005752 if (mService != null) {
5753 try {
Edman Anjosf9946772016-11-28 16:35:15 +01005754 mService.setApplicationRestrictions(admin, mContext.getPackageName(), packageName,
5755 settings);
Robin Lee66e5d962014-04-09 16:44:21 +01005756 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005757 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01005758 }
5759 }
5760 }
5761
5762 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005763 * Sets a list of configuration features to enable for a TrustAgent component. This is meant to
5764 * be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all trust
5765 * agents but those enabled by this function call. If flag
Jim Millere303bf42014-08-26 17:12:29 -07005766 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005767 * <p>
5768 * The calling device admin must have requested
5769 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method;
5770 * if not, a security exception will be thrown.
Tony Mak089d8402016-04-05 17:42:55 +01005771 * <p>
5772 * This method can be called on the {@link DevicePolicyManager} instance returned by
5773 * {@link #getParentProfileInstance(ComponentName)} in order to set the configuration for
5774 * the parent profile.
Jim Miller604e7552014-07-18 19:00:02 -07005775 *
5776 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07005777 * @param target Component name of the agent to be enabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005778 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent will be
5779 * strictly disabled according to the state of the
5780 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
5781 * <p>
5782 * If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all
5783 * admins, then it's up to the TrustAgent itself to aggregate the values from all
5784 * device admins.
5785 * <p>
5786 * Consult documentation for the specific TrustAgent to determine legal options
5787 * parameters.
5788 * @throws SecurityException if {@code admin} is not an active administrator or does not use
5789 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES}
Jim Miller604e7552014-07-18 19:00:02 -07005790 */
Robin Lee25e26452015-06-02 09:56:29 -07005791 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
5792 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07005793 if (mService != null) {
5794 try {
Tony Mak089d8402016-04-05 17:42:55 +01005795 mService.setTrustAgentConfiguration(admin, target, configuration, mParentInstance);
Jim Miller604e7552014-07-18 19:00:02 -07005796 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005797 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07005798 }
5799 }
5800 }
5801
5802 /**
Jim Millere303bf42014-08-26 17:12:29 -07005803 * Gets configuration for the given trust agent based on aggregating all calls to
5804 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
5805 * all device admins.
Tony Mak089d8402016-04-05 17:42:55 +01005806 * <p>
5807 * This method can be called on the {@link DevicePolicyManager} instance returned by
5808 * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the configuration set
5809 * on the parent profile.
Jim Miller604e7552014-07-18 19:00:02 -07005810 *
Jim Millerb5db57a2015-01-14 18:17:19 -08005811 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
5812 * this function returns a list of configurations for all admins that declare
5813 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
5814 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
5815 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
5816 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07005817 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07005818 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07005819 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005820 public @Nullable List<PersistableBundle> getTrustAgentConfiguration(
5821 @Nullable ComponentName admin, @NonNull ComponentName agent) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07005822 return getTrustAgentConfiguration(admin, agent, myUserId());
Jim Millere303bf42014-08-26 17:12:29 -07005823 }
5824
5825 /** @hide per-user version */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005826 public @Nullable List<PersistableBundle> getTrustAgentConfiguration(
5827 @Nullable ComponentName admin, @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07005828 if (mService != null) {
5829 try {
Tony Mak089d8402016-04-05 17:42:55 +01005830 return mService.getTrustAgentConfiguration(admin, agent, userHandle,
5831 mParentInstance);
Jim Miller604e7552014-07-18 19:00:02 -07005832 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005833 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07005834 }
5835 }
Jim Millere303bf42014-08-26 17:12:29 -07005836 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07005837 }
5838
5839 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005840 * Called by a profile owner of a managed profile to set whether caller-Id information from the
5841 * managed profile will be shown in the parent profile, for incoming calls.
5842 * <p>
5843 * The calling device admin must be a profile owner. If it is not, a security exception will be
5844 * thrown.
Adam Connors210fe212014-07-17 15:41:43 +01005845 *
Robin Lee25e26452015-06-02 09:56:29 -07005846 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01005847 * @param disabled If true caller-Id information in the managed profile is not displayed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005848 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors210fe212014-07-17 15:41:43 +01005849 */
Robin Lee25e26452015-06-02 09:56:29 -07005850 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005851 throwIfParentInstance("setCrossProfileCallerIdDisabled");
Adam Connors210fe212014-07-17 15:41:43 +01005852 if (mService != null) {
5853 try {
Robin Lee25e26452015-06-02 09:56:29 -07005854 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01005855 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005856 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01005857 }
5858 }
5859 }
5860
5861 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005862 * Called by a profile owner of a managed profile to determine whether or not caller-Id
5863 * information has been disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005864 * <p>
5865 * The calling device admin must be a profile owner. If it is not, a security exception will be
5866 * thrown.
Adam Connors210fe212014-07-17 15:41:43 +01005867 *
Robin Lee25e26452015-06-02 09:56:29 -07005868 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005869 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors210fe212014-07-17 15:41:43 +01005870 */
Robin Lee25e26452015-06-02 09:56:29 -07005871 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005872 throwIfParentInstance("getCrossProfileCallerIdDisabled");
Adam Connors210fe212014-07-17 15:41:43 +01005873 if (mService != null) {
5874 try {
Robin Lee25e26452015-06-02 09:56:29 -07005875 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01005876 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005877 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01005878 }
5879 }
5880 return false;
5881 }
5882
5883 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07005884 * Determine whether or not caller-Id information has been disabled.
5885 *
5886 * @param userHandle The user for whom to check the caller-id permission
5887 * @hide
5888 */
5889 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
5890 if (mService != null) {
5891 try {
5892 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
5893 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005894 throw e.rethrowFromSystemServer();
Amith Yamasani570002f2014-07-18 15:48:54 -07005895 }
5896 }
5897 return false;
5898 }
5899
5900 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005901 * Called by a profile owner of a managed profile to set whether contacts search from the
5902 * managed profile will be shown in the parent profile, for incoming calls.
5903 * <p>
5904 * The calling device admin must be a profile owner. If it is not, a security exception will be
5905 * thrown.
Victor Chang1060c6182016-01-04 20:16:23 +00005906 *
5907 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5908 * @param disabled If true contacts search in the managed profile is not displayed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005909 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Chang1060c6182016-01-04 20:16:23 +00005910 */
5911 public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin,
5912 boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005913 throwIfParentInstance("setCrossProfileContactsSearchDisabled");
Victor Chang1060c6182016-01-04 20:16:23 +00005914 if (mService != null) {
5915 try {
5916 mService.setCrossProfileContactsSearchDisabled(admin, disabled);
5917 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005918 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00005919 }
5920 }
5921 }
5922
5923 /**
5924 * Called by a profile owner of a managed profile to determine whether or not contacts search
5925 * has been disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005926 * <p>
5927 * The calling device admin must be a profile owner. If it is not, a security exception will be
5928 * thrown.
Victor Chang1060c6182016-01-04 20:16:23 +00005929 *
5930 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005931 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Chang1060c6182016-01-04 20:16:23 +00005932 */
5933 public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005934 throwIfParentInstance("getCrossProfileContactsSearchDisabled");
Victor Chang1060c6182016-01-04 20:16:23 +00005935 if (mService != null) {
5936 try {
5937 return mService.getCrossProfileContactsSearchDisabled(admin);
5938 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005939 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00005940 }
5941 }
5942 return false;
5943 }
5944
5945
5946 /**
5947 * Determine whether or not contacts search has been disabled.
5948 *
5949 * @param userHandle The user for whom to check the contacts search permission
5950 * @hide
5951 */
5952 public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) {
5953 if (mService != null) {
5954 try {
5955 return mService
5956 .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier());
5957 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005958 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00005959 }
5960 }
5961 return false;
5962 }
5963
5964 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005965 * Start Quick Contact on the managed profile for the user, if the policy allows.
Victor Chang97bdacc2016-01-21 22:24:11 +00005966 *
Makoto Onuki1040da12015-03-19 11:24:00 -07005967 * @hide
5968 */
5969 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
Victor Chang97bdacc2016-01-21 22:24:11 +00005970 boolean isContactIdIgnored, long directoryId, Intent originalIntent) {
Makoto Onuki1040da12015-03-19 11:24:00 -07005971 if (mService != null) {
5972 try {
Victor Chang97bdacc2016-01-21 22:24:11 +00005973 mService.startManagedQuickContact(actualLookupKey, actualContactId,
5974 isContactIdIgnored, directoryId, originalIntent);
Makoto Onuki1040da12015-03-19 11:24:00 -07005975 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005976 throw e.rethrowFromSystemServer();
Makoto Onuki1040da12015-03-19 11:24:00 -07005977 }
5978 }
5979 }
5980
5981 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005982 * Start Quick Contact on the managed profile for the user, if the policy allows.
Ricky Wai494b95d2015-11-20 16:07:15 +00005983 * @hide
5984 */
5985 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
5986 Intent originalIntent) {
Victor Chang97bdacc2016-01-21 22:24:11 +00005987 startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT,
Ricky Wai494b95d2015-11-20 16:07:15 +00005988 originalIntent);
5989 }
5990
5991 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005992 * Called by a profile owner of a managed profile to set whether bluetooth devices can access
5993 * enterprise contacts.
Ricky Wai778ba132015-03-31 14:21:22 +01005994 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005995 * The calling device admin must be a profile owner. If it is not, a security exception will be
5996 * thrown.
Ricky Wai778ba132015-03-31 14:21:22 +01005997 * <p>
5998 * This API works on managed profile only.
5999 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006000 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6001 * @param disabled If true, bluetooth devices cannot access enterprise contacts.
6002 * @throws SecurityException if {@code admin} is not a device or profile owner.
Ricky Wai778ba132015-03-31 14:21:22 +01006003 */
Robin Lee25e26452015-06-02 09:56:29 -07006004 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006005 throwIfParentInstance("setBluetoothContactSharingDisabled");
Ricky Wai778ba132015-03-31 14:21:22 +01006006 if (mService != null) {
6007 try {
Robin Lee25e26452015-06-02 09:56:29 -07006008 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01006009 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006010 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01006011 }
6012 }
6013 }
6014
6015 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006016 * Called by a profile owner of a managed profile to determine whether or not Bluetooth devices
6017 * cannot access enterprise contacts.
Ricky Wai778ba132015-03-31 14:21:22 +01006018 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006019 * The calling device admin must be a profile owner. If it is not, a security exception will be
6020 * thrown.
Ricky Wai778ba132015-03-31 14:21:22 +01006021 * <p>
6022 * This API works on managed profile only.
6023 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006024 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6025 * @throws SecurityException if {@code admin} is not a device or profile owner.
Ricky Wai778ba132015-03-31 14:21:22 +01006026 */
Robin Lee25e26452015-06-02 09:56:29 -07006027 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006028 throwIfParentInstance("getBluetoothContactSharingDisabled");
Ricky Wai778ba132015-03-31 14:21:22 +01006029 if (mService != null) {
6030 try {
Robin Lee25e26452015-06-02 09:56:29 -07006031 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01006032 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006033 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01006034 }
6035 }
6036 return true;
6037 }
6038
6039 /**
6040 * Determine whether or not Bluetooth devices cannot access contacts.
6041 * <p>
6042 * This API works on managed profile UserHandle only.
6043 *
6044 * @param userHandle The user for whom to check the caller-id permission
6045 * @hide
6046 */
6047 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
6048 if (mService != null) {
6049 try {
6050 return mService.getBluetoothContactSharingDisabledForUser(userHandle
6051 .getIdentifier());
6052 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006053 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01006054 }
6055 }
6056 return true;
6057 }
6058
6059 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07006060 * Called by the profile owner of a managed profile so that some intents sent in the managed
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006061 * profile can also be resolved in the parent, or vice versa. Only activity intents are
6062 * supported.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00006063 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00006064 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01006065 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006066 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01006067 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006068 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
6069 * @throws SecurityException if {@code admin} is not a device or profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00006070 */
Robin Lee25e26452015-06-02 09:56:29 -07006071 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006072 throwIfParentInstance("addCrossProfileIntentFilter");
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00006073 if (mService != null) {
6074 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01006075 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00006076 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006077 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00006078 }
6079 }
6080 }
6081
6082 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07006083 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
6084 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01006085 * Only removes those that have been set by the profile owner.
Rubin Xucc391c22018-01-02 20:37:35 +00006086 * <p>
6087 * <em>Note</em>: A list of default cross profile intent filters are set up by the system when
6088 * the profile is created, some of them ensure the proper functioning of the profile, while
6089 * others enable sharing of data from the parent to the managed profile for user convenience.
6090 * These default intent filters are not cleared when this API is called. If the default cross
6091 * profile data sharing is not desired, they can be disabled with
6092 * {@link UserManager#DISALLOW_SHARE_INTO_MANAGED_PROFILE}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006093 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00006094 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006095 * @throws SecurityException if {@code admin} is not a device or profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00006096 */
Robin Lee25e26452015-06-02 09:56:29 -07006097 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006098 throwIfParentInstance("clearCrossProfileIntentFilters");
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00006099 if (mService != null) {
6100 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01006101 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00006102 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006103 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00006104 }
6105 }
6106 }
6107
6108 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006109 * Called by a profile or device owner to set the permitted accessibility services. When set by
6110 * a device owner or profile owner the restriction applies to all profiles of the user the
6111 * device owner or profile owner is an admin for. By default the user can use any accessiblity
6112 * service. When zero or more packages have been added, accessiblity services that are not in
6113 * the list and not part of the system can not be enabled by the user.
6114 * <p>
6115 * Calling with a null value for the list disables the restriction so that all services can be
6116 * used, calling with an empty list only allows the builtin system's services.
6117 * <p>
Esteban Talavera7e4cbad2017-03-30 17:59:50 +01006118 * System accessibility services are always available to the user the list can't modify this.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006119 *
6120 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6121 * @param packageNames List of accessibility service package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006122 * @return true if setting the restriction succeeded. It fail if there is one or more non-system
6123 * accessibility services enabled, that are not in the list.
6124 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006125 */
Robin Lee25e26452015-06-02 09:56:29 -07006126 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006127 List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006128 throwIfParentInstance("setPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006129 if (mService != null) {
6130 try {
6131 return mService.setPermittedAccessibilityServices(admin, packageNames);
6132 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006133 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006134 }
6135 }
6136 return false;
6137 }
6138
6139 /**
6140 * Returns the list of permitted accessibility services set by this device or profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006141 * <p>
6142 * An empty list means no accessibility services except system services are allowed. Null means
6143 * all accessibility services are allowed.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006144 *
6145 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6146 * @return List of accessiblity service package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006147 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006148 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006149 public @Nullable List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006150 throwIfParentInstance("getPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006151 if (mService != null) {
6152 try {
6153 return mService.getPermittedAccessibilityServices(admin);
6154 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006155 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006156 }
6157 }
6158 return null;
6159 }
6160
6161 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00006162 * Called by the system to check if a specific accessibility service is disabled by admin.
6163 *
6164 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6165 * @param packageName Accessibility service package name that needs to be checked.
6166 * @param userHandle user id the admin is running as.
6167 * @return true if the accessibility service is permitted, otherwise false.
6168 *
6169 * @hide
6170 */
6171 public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin,
6172 @NonNull String packageName, int userHandle) {
6173 if (mService != null) {
6174 try {
6175 return mService.isAccessibilityServicePermittedByAdmin(admin, packageName,
6176 userHandle);
6177 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006178 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00006179 }
6180 }
6181 return false;
6182 }
6183
6184 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006185 * Returns the list of accessibility services permitted by the device or profiles
6186 * owners of this user.
6187 *
6188 * <p>Null means all accessibility services are allowed, if a non-null list is returned
6189 * it will contain the intersection of the permitted lists for any device or profile
6190 * owners that apply to this user. It will also include any system accessibility services.
6191 *
6192 * @param userId which user to check for.
6193 * @return List of accessiblity service package names.
6194 * @hide
6195 */
6196 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07006197 public @Nullable List<String> getPermittedAccessibilityServices(int userId) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006198 throwIfParentInstance("getPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006199 if (mService != null) {
6200 try {
6201 return mService.getPermittedAccessibilityServicesForUser(userId);
6202 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006203 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006204 }
6205 }
6206 return null;
6207 }
6208
6209 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006210 * Called by a profile or device owner to set the permitted input methods services. When set by
6211 * a device owner or profile owner the restriction applies to all profiles of the user the
6212 * device owner or profile owner is an admin for. By default the user can use any input method.
6213 * When zero or more packages have been added, input method that are not in the list and not
6214 * part of the system can not be enabled by the user. This method will fail if it is called for
6215 * a admin that is not for the foreground user or a profile of the foreground user.
6216 * <p>
6217 * Calling with a null value for the list disables the restriction so that all input methods can
6218 * be used, calling with an empty list disables all but the system's own input methods.
6219 * <p>
6220 * System input methods are always available to the user this method can't modify this.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006221 *
6222 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6223 * @param packageNames List of input method package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006224 * @return true if setting the restriction succeeded. It will fail if there are one or more
6225 * non-system input methods currently enabled that are not in the packageNames list.
6226 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006227 */
Esteban Talavera7e4cbad2017-03-30 17:59:50 +01006228 public boolean setPermittedInputMethods(
6229 @NonNull ComponentName admin, List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006230 throwIfParentInstance("setPermittedInputMethods");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006231 if (mService != null) {
6232 try {
6233 return mService.setPermittedInputMethods(admin, packageNames);
6234 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006235 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006236 }
6237 }
6238 return false;
6239 }
6240
6241
6242 /**
6243 * Returns the list of permitted input methods set by this device or profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006244 * <p>
6245 * An empty list means no input methods except system input methods are allowed. Null means all
6246 * input methods are allowed.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006247 *
6248 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6249 * @return List of input method package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006250 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006251 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006252 public @Nullable List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006253 throwIfParentInstance("getPermittedInputMethods");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006254 if (mService != null) {
6255 try {
6256 return mService.getPermittedInputMethods(admin);
6257 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006258 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006259 }
6260 }
6261 return null;
6262 }
6263
6264 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00006265 * Called by the system to check if a specific input method is disabled by admin.
6266 *
6267 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6268 * @param packageName Input method package name that needs to be checked.
6269 * @param userHandle user id the admin is running as.
6270 * @return true if the input method is permitted, otherwise false.
6271 *
6272 * @hide
6273 */
6274 public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin,
6275 @NonNull String packageName, int userHandle) {
6276 if (mService != null) {
6277 try {
6278 return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle);
6279 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006280 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00006281 }
6282 }
6283 return false;
6284 }
6285
6286 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006287 * Returns the list of input methods permitted by the device or profiles
Makoto Onuki32b30572015-12-11 14:29:51 -08006288 * owners of the current user. (*Not* calling user, due to a limitation in InputMethodManager.)
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006289 *
6290 * <p>Null means all input methods are allowed, if a non-null list is returned
6291 * it will contain the intersection of the permitted lists for any device or profile
6292 * owners that apply to this user. It will also include any system input methods.
6293 *
6294 * @return List of input method package names.
6295 * @hide
6296 */
6297 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07006298 public @Nullable List<String> getPermittedInputMethodsForCurrentUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006299 throwIfParentInstance("getPermittedInputMethodsForCurrentUser");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006300 if (mService != null) {
6301 try {
6302 return mService.getPermittedInputMethodsForCurrentUser();
6303 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006304 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01006305 }
6306 }
6307 return null;
6308 }
6309
6310 /**
Esteban Talavera7e4cbad2017-03-30 17:59:50 +01006311 * Called by a profile owner of a managed profile to set the packages that are allowed to use
6312 * a {@link android.service.notification.NotificationListenerService} in the primary user to
6313 * see notifications from the managed profile. By default all packages are permitted by this
6314 * policy. When zero or more packages have been added, notification listeners installed on the
6315 * primary user that are not in the list and are not part of the system won't receive events
6316 * for managed profile notifications.
6317 * <p>
6318 * Calling with a {@code null} value for the list disables the restriction so that all
6319 * notification listener services be used. Calling with an empty list disables all but the
6320 * system's own notification listeners. System notification listener services are always
6321 * available to the user.
6322 * <p>
6323 * If a device or profile owner want to stop notification listeners in their user from seeing
6324 * that user's notifications they should prevent that service from running instead (e.g. via
6325 * {@link #setApplicationHidden(ComponentName, String, boolean)})
6326 *
6327 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6328 * @param packageList List of package names to whitelist
6329 * @return true if setting the restriction succeeded. It will fail if called outside a managed
6330 * profile
6331 * @throws SecurityException if {@code admin} is not a profile owner.
6332 *
6333 * @see android.service.notification.NotificationListenerService
6334 */
6335 public boolean setPermittedCrossProfileNotificationListeners(
6336 @NonNull ComponentName admin, @Nullable List<String> packageList) {
6337 throwIfParentInstance("setPermittedCrossProfileNotificationListeners");
6338 if (mService != null) {
6339 try {
6340 return mService.setPermittedCrossProfileNotificationListeners(admin, packageList);
6341 } catch (RemoteException e) {
6342 throw e.rethrowFromSystemServer();
6343 }
6344 }
6345 return false;
6346 }
6347
6348 /**
6349 * Returns the list of packages installed on the primary user that allowed to use a
6350 * {@link android.service.notification.NotificationListenerService} to receive
6351 * notifications from this managed profile, as set by the profile owner.
6352 * <p>
6353 * An empty list means no notification listener services except system ones are allowed.
6354 * A {@code null} return value indicates that all notification listeners are allowed.
6355 */
6356 public @Nullable List<String> getPermittedCrossProfileNotificationListeners(
6357 @NonNull ComponentName admin) {
6358 throwIfParentInstance("getPermittedCrossProfileNotificationListeners");
6359 if (mService != null) {
6360 try {
6361 return mService.getPermittedCrossProfileNotificationListeners(admin);
6362 } catch (RemoteException e) {
6363 throw e.rethrowFromSystemServer();
6364 }
6365 }
6366 return null;
6367 }
6368
6369 /**
6370 * Returns true if {@code NotificationListenerServices} from the given package are allowed to
6371 * receive events for notifications from the given user id. Can only be called by the system uid
6372 *
6373 * @see #setPermittedCrossProfileNotificationListeners(ComponentName, List)
6374 *
6375 * @hide
6376 */
6377 public boolean isNotificationListenerServicePermitted(
6378 @NonNull String packageName, @UserIdInt int userId) {
6379 if (mService != null) {
6380 try {
6381 return mService.isNotificationListenerServicePermitted(packageName, userId);
6382 } catch (RemoteException e) {
6383 throw e.rethrowFromSystemServer();
6384 }
6385 }
6386 return true;
6387 }
6388
6389 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006390 * Get the list of apps to keep around as APKs even if no user has currently installed it. This
6391 * function can be called by a device owner or by a delegate given the
6392 * {@link #DELEGATION_KEEP_UNINSTALLED_PACKAGES} scope via {@link #setDelegatedScopes}.
6393 * <p>
6394 * Please note that packages returned in this method are not automatically pre-cached.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08006395 *
Edman Anjos52088e42017-01-13 22:26:17 +01006396 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
6397 * {@code null} if the caller is a keep uninstalled packages delegate.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08006398 * @return List of package names to keep cached.
Edman Anjos52088e42017-01-13 22:26:17 +01006399 * @see #setDelegatedScopes
6400 * @see #DELEGATION_KEEP_UNINSTALLED_PACKAGES
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08006401 */
Edman Anjos52088e42017-01-13 22:26:17 +01006402 public @Nullable List<String> getKeepUninstalledPackages(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006403 throwIfParentInstance("getKeepUninstalledPackages");
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08006404 if (mService != null) {
6405 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006406 return mService.getKeepUninstalledPackages(admin, mContext.getPackageName());
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08006407 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006408 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08006409 }
6410 }
6411 return null;
6412 }
6413
6414 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006415 * Set a list of apps to keep around as APKs even if no user has currently installed it. This
6416 * function can be called by a device owner or by a delegate given the
6417 * {@link #DELEGATION_KEEP_UNINSTALLED_PACKAGES} scope via {@link #setDelegatedScopes}.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08006418 *
6419 * <p>Please note that setting this policy does not imply that specified apps will be
6420 * automatically pre-cached.</p>
6421 *
Edman Anjos52088e42017-01-13 22:26:17 +01006422 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
6423 * {@code null} if the caller is a keep uninstalled packages delegate.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08006424 * @param packageNames List of package names to keep cached.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006425 * @throws SecurityException if {@code admin} is not a device owner.
Edman Anjos52088e42017-01-13 22:26:17 +01006426 * @see #setDelegatedScopes
6427 * @see #DELEGATION_KEEP_UNINSTALLED_PACKAGES
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08006428 */
Edman Anjos52088e42017-01-13 22:26:17 +01006429 public void setKeepUninstalledPackages(@Nullable ComponentName admin,
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08006430 @NonNull List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006431 throwIfParentInstance("setKeepUninstalledPackages");
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08006432 if (mService != null) {
6433 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006434 mService.setKeepUninstalledPackages(admin, mContext.getPackageName(), packageNames);
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08006435 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006436 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08006437 }
6438 }
6439 }
6440
6441 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04006442 * Called by a device owner to create a user with the specified name. The UserHandle returned
6443 * by this method should not be persisted as user handles are recycled as users are removed and
6444 * created. If you need to persist an identifier for this user, use
6445 * {@link UserManager#getSerialNumberForUser}.
6446 *
6447 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6448 * @param name the user's name
6449 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07006450 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
6451 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01006452 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07006453 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01006454 * @removed From {@link android.os.Build.VERSION_CODES#N}
Julia Reynolds1e958392014-05-16 14:25:21 -04006455 */
Kenny Guy14f48e52015-06-29 15:12:36 +01006456 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07006457 public @Nullable UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04006458 return null;
6459 }
6460
6461 /**
Jason Monk03978a42014-06-10 15:05:30 -04006462 * Called by a device owner to create a user with the specified name. The UserHandle returned
6463 * by this method should not be persisted as user handles are recycled as users are removed and
6464 * created. If you need to persist an identifier for this user, use
6465 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
6466 * immediately.
6467 *
6468 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
6469 * as registered as an active admin on the new user. The profile owner package will be
6470 * installed on the new user if it already is installed on the device.
6471 *
6472 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
6473 * profileOwnerComponent when onEnable is called.
6474 *
6475 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6476 * @param name the user's name
6477 * @param ownerName the human readable name of the organisation associated with this DPM.
6478 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
6479 * the user.
6480 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
6481 * on the new user.
6482 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07006483 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
6484 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01006485 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07006486 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01006487 * @removed From {@link android.os.Build.VERSION_CODES#N}
Jason Monk03978a42014-06-10 15:05:30 -04006488 */
Kenny Guy14f48e52015-06-29 15:12:36 +01006489 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07006490 public @Nullable UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
Robin Lee25e26452015-06-02 09:56:29 -07006491 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04006492 return null;
6493 }
6494
6495 /**
phweissa92e1212016-01-25 17:14:10 +01006496 * Flag used by {@link #createAndManageUser} to skip setup wizard after creating a new user.
phweiss343fb332016-01-25 14:48:59 +01006497 */
6498 public static final int SKIP_SETUP_WIZARD = 0x0001;
6499
6500 /**
Lenka Trochtovac8202c82016-01-26 15:11:09 +01006501 * Flag used by {@link #createAndManageUser} to specify that the user should be created
Alex Chau6badae62017-10-27 17:46:16 +01006502 * ephemeral. Ephemeral users will be removed after switching to another user or rebooting the
6503 * device.
Lenka Trochtovac8202c82016-01-26 15:11:09 +01006504 */
6505 public static final int MAKE_USER_EPHEMERAL = 0x0002;
6506
6507 /**
Christine Franks361b8252017-06-23 18:12:46 -07006508 * Flag used by {@link #createAndManageUser} to specify that the user should be created as a
6509 * demo user.
6510 * @hide
6511 */
6512 public static final int MAKE_USER_DEMO = 0x0004;
6513
6514 /**
Alex Chaub6a9f942017-11-07 11:28:56 +08006515 * Flag used by {@link #createAndManageUser} to specify that the newly created user should skip
6516 * the disabling of system apps during provisioning.
6517 */
6518 public static final int LEAVE_ALL_SYSTEM_APPS_ENABLED = 0x0010;
6519
6520 /**
Benjamin Franz77c94a92017-08-09 14:16:03 +01006521 * @hide
6522 */
Jeff Sharkeyce8db992017-12-13 20:05:05 -07006523 @IntDef(flag = true, prefix = { "SKIP_", "MAKE_USER_", "START_", "LEAVE_" }, value = {
6524 SKIP_SETUP_WIZARD,
6525 MAKE_USER_EPHEMERAL,
6526 MAKE_USER_DEMO,
Jeff Sharkeyce8db992017-12-13 20:05:05 -07006527 LEAVE_ALL_SYSTEM_APPS_ENABLED
6528 })
Benjamin Franz77c94a92017-08-09 14:16:03 +01006529 @Retention(RetentionPolicy.SOURCE)
6530 public @interface CreateAndManageUserFlags {}
6531
6532
6533 /**
phweissa92e1212016-01-25 17:14:10 +01006534 * Called by a device owner to create a user with the specified name and a given component of
6535 * the calling package as profile owner. The UserHandle returned by this method should not be
6536 * persisted as user handles are recycled as users are removed and created. If you need to
6537 * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new
6538 * user will not be started in the background.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006539 * <p>
6540 * admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also a
6541 * DeviceAdminReceiver in the same package as admin, and will become the profile owner and will
6542 * be registered as an active admin on the new user. The profile owner package will be installed
6543 * on the new user.
6544 * <p>
6545 * If the adminExtras are not null, they will be stored on the device until the user is started
6546 * for the first time. Then the extras will be passed to the admin when onEnable is called.
phweiss343fb332016-01-25 14:48:59 +01006547 *
6548 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6549 * @param name The user's name.
phweissa92e1212016-01-25 17:14:10 +01006550 * @param profileOwner Which {@link DeviceAdminReceiver} will be profile owner. Has to be in the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006551 * same package as admin, otherwise no user is created and an
6552 * IllegalArgumentException is thrown.
phweiss343fb332016-01-25 14:48:59 +01006553 * @param adminExtras Extras that will be passed to onEnable of the admin receiver on the new
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006554 * user.
Alex Chaub6ef8692018-01-09 14:16:36 +00006555 * @param flags {@link #SKIP_SETUP_WIZARD}, {@link #MAKE_USER_EPHEMERAL} and
6556 * {@link #LEAVE_ALL_SYSTEM_APPS_ENABLED} are supported.
phweiss343fb332016-01-25 14:48:59 +01006557 * @see UserHandle
6558 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
6559 * user could not be created.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006560 * @throws SecurityException if {@code admin} is not a device owner.
phweiss343fb332016-01-25 14:48:59 +01006561 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006562 public @Nullable UserHandle createAndManageUser(@NonNull ComponentName admin,
6563 @NonNull String name,
phweissa92e1212016-01-25 17:14:10 +01006564 @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras,
Benjamin Franz77c94a92017-08-09 14:16:03 +01006565 @CreateAndManageUserFlags int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006566 throwIfParentInstance("createAndManageUser");
phweiss343fb332016-01-25 14:48:59 +01006567 try {
phweissa92e1212016-01-25 17:14:10 +01006568 return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags);
phweiss343fb332016-01-25 14:48:59 +01006569 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006570 throw re.rethrowFromSystemServer();
phweiss343fb332016-01-25 14:48:59 +01006571 }
phweiss343fb332016-01-25 14:48:59 +01006572 }
6573
6574 /**
Alex Chaub6ef8692018-01-09 14:16:36 +00006575 * Called by a device owner to remove a user/profile and all associated data. The primary user
6576 * can not be removed.
Julia Reynolds1e958392014-05-16 14:25:21 -04006577 *
6578 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6579 * @param userHandle the user to remove.
6580 * @return {@code true} if the user was removed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006581 * @throws SecurityException if {@code admin} is not a device owner.
Julia Reynolds1e958392014-05-16 14:25:21 -04006582 */
Alex Chauaf9bb8d2017-12-06 14:38:25 +00006583 public boolean removeUser(@NonNull ComponentName admin, @NonNull UserHandle userHandle) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006584 throwIfParentInstance("removeUser");
Julia Reynolds1e958392014-05-16 14:25:21 -04006585 try {
6586 return mService.removeUser(admin, userHandle);
6587 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006588 throw re.rethrowFromSystemServer();
Julia Reynolds1e958392014-05-16 14:25:21 -04006589 }
6590 }
6591
6592 /**
Alex Chaub6ef8692018-01-09 14:16:36 +00006593 * Called by a device owner to switch the specified secondary user to the foreground.
Jason Monk582d9112014-07-09 19:57:08 -04006594 *
6595 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6596 * @param userHandle the user to switch to; null will switch to primary.
6597 * @return {@code true} if the switch was successful, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006598 * @throws SecurityException if {@code admin} is not a device owner.
Jason Monk582d9112014-07-09 19:57:08 -04006599 * @see Intent#ACTION_USER_FOREGROUND
Alex Chaub6ef8692018-01-09 14:16:36 +00006600 * @see #getSecondaryUsers(ComponentName)
Jason Monk582d9112014-07-09 19:57:08 -04006601 */
Robin Lee25e26452015-06-02 09:56:29 -07006602 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006603 throwIfParentInstance("switchUser");
Jason Monk582d9112014-07-09 19:57:08 -04006604 try {
6605 return mService.switchUser(admin, userHandle);
6606 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006607 throw re.rethrowFromSystemServer();
Jason Monk582d9112014-07-09 19:57:08 -04006608 }
6609 }
6610
6611 /**
Alex Chaub6ef8692018-01-09 14:16:36 +00006612 * Called by a device owner to start the specified secondary user in background.
6613 *
6614 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6615 * @param userHandle the user to be stopped.
6616 * @return {@code true} if the user can be started, {@code false} otherwise.
6617 * @throws SecurityException if {@code admin} is not a device owner.
6618 * @see #getSecondaryUsers(ComponentName)
6619 */
6620 public boolean startUserInBackground(
6621 @NonNull ComponentName admin, @NonNull UserHandle userHandle) {
6622 throwIfParentInstance("startUserInBackground");
6623 try {
6624 return mService.startUserInBackground(admin, userHandle);
6625 } catch (RemoteException re) {
6626 throw re.rethrowFromSystemServer();
6627 }
6628 }
6629
6630 /**
Alex Chauaf9bb8d2017-12-06 14:38:25 +00006631 * Called by a device owner to stop the specified secondary user.
Alex Chauaf9bb8d2017-12-06 14:38:25 +00006632 *
6633 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6634 * @param userHandle the user to be stopped.
6635 * @return {@code true} if the user can be stopped, {@code false} otherwise.
6636 * @throws SecurityException if {@code admin} is not a device owner.
Alex Chaub6ef8692018-01-09 14:16:36 +00006637 * @see #getSecondaryUsers(ComponentName)
Alex Chauaf9bb8d2017-12-06 14:38:25 +00006638 */
6639 public boolean stopUser(@NonNull ComponentName admin, @NonNull UserHandle userHandle) {
6640 throwIfParentInstance("stopUser");
6641 try {
6642 return mService.stopUser(admin, userHandle);
6643 } catch (RemoteException re) {
6644 throw re.rethrowFromSystemServer();
6645 }
6646 }
6647
6648 /**
Alex Chaub6ef8692018-01-09 14:16:36 +00006649 * Called by a profile owner of secondary user that is affiliated with the device to stop the
6650 * calling user and switch back to primary.
Alex Chauaf9bb8d2017-12-06 14:38:25 +00006651 *
6652 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6653 * @return {@code true} if the exit was successful, {@code false} otherwise.
Alex Chau443b6432017-12-13 12:44:31 +00006654 * @throws SecurityException if {@code admin} is not a profile owner affiliated with the device.
Alex Chaub6ef8692018-01-09 14:16:36 +00006655 * @see #getSecondaryUsers(ComponentName)
Alex Chauaf9bb8d2017-12-06 14:38:25 +00006656 */
6657 public boolean logoutUser(@NonNull ComponentName admin) {
6658 throwIfParentInstance("logoutUser");
6659 try {
6660 return mService.logoutUser(admin);
6661 } catch (RemoteException re) {
6662 throw re.rethrowFromSystemServer();
6663 }
6664 }
6665
6666 /**
Alex Chaub6ef8692018-01-09 14:16:36 +00006667 * Called by a device owner to list all secondary users on the device. Managed profiles are not
6668 * considered as secondary users.
Alex Chauaf9bb8d2017-12-06 14:38:25 +00006669 * <p> Used for various user management APIs, including {@link #switchUser}, {@link #removeUser}
6670 * and {@link #stopUser}.
6671 *
6672 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6673 * @return list of other {@link UserHandle}s on the device.
6674 * @throws SecurityException if {@code admin} is not a device owner.
Alex Chaub6ef8692018-01-09 14:16:36 +00006675 * @see #removeUser(ComponentName, UserHandle)
6676 * @see #switchUser(ComponentName, UserHandle)
6677 * @see #startUserInBackground(ComponentName, UserHandle)
6678 * @see #stopUser(ComponentName, UserHandle)
Alex Chauaf9bb8d2017-12-06 14:38:25 +00006679 */
6680 public List<UserHandle> getSecondaryUsers(@NonNull ComponentName admin) {
6681 throwIfParentInstance("getSecondaryUsers");
6682 try {
6683 return mService.getSecondaryUsers(admin);
6684 } catch (RemoteException re) {
6685 throw re.rethrowFromSystemServer();
6686 }
6687 }
6688
6689 /**
Alex Chau8d6e18c2017-12-08 18:11:27 +00006690 * Checks if the profile owner is running in an ephemeral user.
6691 *
6692 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6693 * @return whether the profile owner is running in an ephemeral user.
6694 */
6695 public boolean isEphemeralUser(@NonNull ComponentName admin) {
6696 throwIfParentInstance("isEphemeralUser");
6697 try {
6698 return mService.isEphemeralUser(admin);
6699 } catch (RemoteException re) {
6700 throw re.rethrowFromSystemServer();
6701 }
6702 }
6703
6704 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00006705 * Retrieves the application restrictions for a given target application running in the calling
6706 * user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006707 * <p>
6708 * 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 +01006709 * application restrictions via {@link #setDelegatedScopes} with the
6710 * {@link #DELEGATION_APP_RESTRICTIONS} scope; otherwise a security exception will be thrown.
Robin Lee66e5d962014-04-09 16:44:21 +01006711 *
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07006712 * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
6713 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00006714 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006715 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01006716 * @param packageName The name of the package to fetch restricted settings of.
6717 * @return {@link Bundle} of settings corresponding to what was set last time
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006718 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty
6719 * {@link Bundle} if no restrictions have been set.
6720 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01006721 * @see #setDelegatedScopes
6722 * @see #DELEGATION_APP_RESTRICTIONS
Robin Lee66e5d962014-04-09 16:44:21 +01006723 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07006724 @WorkerThread
Makoto Onuki408e8e42016-10-25 12:10:27 -07006725 public @NonNull Bundle getApplicationRestrictions(
6726 @Nullable ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006727 throwIfParentInstance("getApplicationRestrictions");
Robin Lee66e5d962014-04-09 16:44:21 +01006728 if (mService != null) {
6729 try {
Edman Anjosf9946772016-11-28 16:35:15 +01006730 return mService.getApplicationRestrictions(admin, mContext.getPackageName(),
6731 packageName);
Robin Lee66e5d962014-04-09 16:44:21 +01006732 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006733 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01006734 }
6735 }
6736 return null;
6737 }
Amith Yamasanibe465322014-04-24 13:45:17 -07006738
6739 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05006740 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07006741 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006742 * The calling device admin must be a profile or device owner; if it is not, a security
6743 * exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07006744 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006745 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6746 * @param key The key of the restriction. See the constants in {@link android.os.UserManager}
6747 * for the list of keys.
6748 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanibe465322014-04-24 13:45:17 -07006749 */
Robin Lee25e26452015-06-02 09:56:29 -07006750 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006751 throwIfParentInstance("addUserRestriction");
Amith Yamasanibe465322014-04-24 13:45:17 -07006752 if (mService != null) {
6753 try {
6754 mService.setUserRestriction(admin, key, true);
6755 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006756 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07006757 }
6758 }
6759 }
6760
6761 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05006762 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07006763 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006764 * The calling device admin must be a profile or device owner; if it is not, a security
6765 * exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07006766 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006767 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6768 * @param key The key of the restriction. See the constants in {@link android.os.UserManager}
6769 * for the list of keys.
6770 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanibe465322014-04-24 13:45:17 -07006771 */
Robin Lee25e26452015-06-02 09:56:29 -07006772 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006773 throwIfParentInstance("clearUserRestriction");
Amith Yamasanibe465322014-04-24 13:45:17 -07006774 if (mService != null) {
6775 try {
6776 mService.setUserRestriction(admin, key, false);
6777 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006778 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07006779 }
6780 }
6781 }
Adam Connors010cfd42014-04-16 12:48:13 +01006782
6783 /**
Makoto Onuki3a3092f2015-10-30 11:07:51 -07006784 * Called by a profile or device owner to get user restrictions set with
6785 * {@link #addUserRestriction(ComponentName, String)}.
6786 * <p>
6787 * The target user may have more restrictions set by the system or other device owner / profile
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006788 * owner. To get all the user restrictions currently set, use
Makoto Onuki3a3092f2015-10-30 11:07:51 -07006789 * {@link UserManager#getUserRestrictions()}.
6790 *
6791 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006792 * @throws SecurityException if {@code admin} is not a device or profile owner.
Makoto Onuki3a3092f2015-10-30 11:07:51 -07006793 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006794 public @NonNull Bundle getUserRestrictions(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006795 throwIfParentInstance("getUserRestrictions");
Makoto Onuki3a3092f2015-10-30 11:07:51 -07006796 Bundle ret = null;
6797 if (mService != null) {
6798 try {
Sudheer Shanka549b9692016-03-30 17:12:07 -07006799 ret = mService.getUserRestrictions(admin);
6800 } catch (RemoteException e) {
6801 throw e.rethrowFromSystemServer();
6802 }
6803 }
6804 return ret == null ? new Bundle() : ret;
6805 }
6806
6807 /**
phweiss73145f42017-01-17 19:06:38 +01006808 * Called by any app to display a support dialog when a feature was disabled by an admin.
6809 * This returns an intent that can be used with {@link Context#startActivity(Intent)} to
6810 * display the dialog. It will tell the user that the feature indicated by {@code restriction}
6811 * was disabled by an admin, and include a link for more information. The default content of
6812 * the dialog can be changed by the restricting admin via
6813 * {@link #setShortSupportMessage(ComponentName, CharSequence)}. If the restriction is not
6814 * set (i.e. the feature is available), then the return value will be {@code null}.
6815 * @param restriction Indicates for which feature the dialog should be displayed. Can be a
6816 * user restriction from {@link UserManager}, e.g.
6817 * {@link UserManager#DISALLOW_ADJUST_VOLUME}, or one of the constants
Lenka Trochtova16a91c02018-01-17 11:03:30 +01006818 * {@link #POLICY_DISABLE_CAMERA}, {@link #POLICY_DISABLE_SCREEN_CAPTURE} or
6819 * {@link #POLICY_MANDATORY_BACKUPS}.
phweiss73145f42017-01-17 19:06:38 +01006820 * @return Intent An intent to be used to start the dialog-activity if the restriction is
6821 * set by an admin, or null if the restriction does not exist or no admin set it.
6822 */
6823 public Intent createAdminSupportIntent(@NonNull String restriction) {
6824 throwIfParentInstance("createAdminSupportIntent");
6825 if (mService != null) {
6826 try {
6827 return mService.createAdminSupportIntent(restriction);
6828 } catch (RemoteException e) {
6829 throw e.rethrowFromSystemServer();
6830 }
6831 }
6832 return null;
6833 }
6834
6835 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006836 * Hide or unhide packages. When a package is hidden it is unavailable for use, but the data and
6837 * actual package file remain. This function can be called by a device owner, profile owner, or
6838 * by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via
6839 * {@link #setDelegatedScopes}.
Julia Reynolds966881e2014-05-14 12:23:08 -04006840 *
Edman Anjos52088e42017-01-13 22:26:17 +01006841 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
6842 * {@code null} if the caller is a package access delegate.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07006843 * @param packageName The name of the package to hide or unhide.
6844 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006845 * unhidden.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07006846 * @return boolean Whether the hidden setting of the package was successfully updated.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006847 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01006848 * @see #setDelegatedScopes
6849 * @see #DELEGATION_PACKAGE_ACCESS
Julia Reynolds966881e2014-05-14 12:23:08 -04006850 */
Robin Lee25e26452015-06-02 09:56:29 -07006851 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07006852 boolean hidden) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006853 throwIfParentInstance("setApplicationHidden");
Julia Reynolds966881e2014-05-14 12:23:08 -04006854 if (mService != null) {
6855 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006856 return mService.setApplicationHidden(admin, mContext.getPackageName(), packageName,
6857 hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04006858 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006859 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04006860 }
6861 }
6862 return false;
6863 }
6864
6865 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006866 * Determine if a package is hidden. This function can be called by a device owner, profile
6867 * owner, or by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via
6868 * {@link #setDelegatedScopes}.
Julia Reynolds966881e2014-05-14 12:23:08 -04006869 *
Edman Anjos52088e42017-01-13 22:26:17 +01006870 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
6871 * {@code null} if the caller is a package access delegate.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07006872 * @param packageName The name of the package to retrieve the hidden status of.
6873 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006874 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01006875 * @see #setDelegatedScopes
6876 * @see #DELEGATION_PACKAGE_ACCESS
Julia Reynolds966881e2014-05-14 12:23:08 -04006877 */
Robin Lee25e26452015-06-02 09:56:29 -07006878 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006879 throwIfParentInstance("isApplicationHidden");
Julia Reynolds966881e2014-05-14 12:23:08 -04006880 if (mService != null) {
6881 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006882 return mService.isApplicationHidden(admin, mContext.getPackageName(), packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04006883 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006884 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04006885 }
6886 }
6887 return false;
6888 }
6889
6890 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006891 * Re-enable a system app that was disabled by default when the user was initialized. This
6892 * function can be called by a device owner, profile owner, or by a delegate given the
6893 * {@link #DELEGATION_ENABLE_SYSTEM_APP} scope via {@link #setDelegatedScopes}.
Adam Connors655be2a2014-07-14 09:01:25 +00006894 *
Edman Anjos52088e42017-01-13 22:26:17 +01006895 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
6896 * {@code null} if the caller is an enable system app delegate.
Makoto Onuki32b30572015-12-11 14:29:51 -08006897 * @param packageName The package to be re-enabled in the calling profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006898 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01006899 * @see #setDelegatedScopes
6900 * @see #DELEGATION_PACKAGE_ACCESS
Adam Connors655be2a2014-07-14 09:01:25 +00006901 */
Robin Lee25e26452015-06-02 09:56:29 -07006902 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006903 throwIfParentInstance("enableSystemApp");
Adam Connors655be2a2014-07-14 09:01:25 +00006904 if (mService != null) {
6905 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006906 mService.enableSystemApp(admin, mContext.getPackageName(), packageName);
Adam Connors655be2a2014-07-14 09:01:25 +00006907 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006908 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00006909 }
6910 }
6911 }
6912
6913 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006914 * Re-enable system apps by intent that were disabled by default when the user was initialized.
6915 * This function can be called by a device owner, profile owner, or by a delegate given the
6916 * {@link #DELEGATION_ENABLE_SYSTEM_APP} scope via {@link #setDelegatedScopes}.
Adam Connors655be2a2014-07-14 09:01:25 +00006917 *
Edman Anjos52088e42017-01-13 22:26:17 +01006918 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
6919 * {@code null} if the caller is an enable system app delegate.
Adam Connors655be2a2014-07-14 09:01:25 +00006920 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006921 * intent will be re-enabled in the calling profile.
Adam Connors655be2a2014-07-14 09:01:25 +00006922 * @return int The number of activities that matched the intent and were installed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006923 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01006924 * @see #setDelegatedScopes
6925 * @see #DELEGATION_PACKAGE_ACCESS
Adam Connors655be2a2014-07-14 09:01:25 +00006926 */
Robin Lee25e26452015-06-02 09:56:29 -07006927 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006928 throwIfParentInstance("enableSystemApp");
Adam Connors655be2a2014-07-14 09:01:25 +00006929 if (mService != null) {
6930 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006931 return mService.enableSystemAppWithIntent(admin, mContext.getPackageName(), intent);
Adam Connors655be2a2014-07-14 09:01:25 +00006932 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006933 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00006934 }
6935 }
6936 return 0;
6937 }
6938
6939 /**
Alex Chau5343fcb2017-12-05 16:49:19 +00006940 * Install an existing package that has been installed in another user, or has been kept after
6941 * removal via {@link #setKeepUninstalledPackages}.
6942 * This function can be called by a device owner, profile owner or a delegate given
6943 * the {@link #DELEGATION_INSTALL_EXISTING_PACKAGE} scope via {@link #setDelegatedScopes}.
6944 * When called in a secondary user or managed profile, the user/profile must be affiliated with
Alex Chau443b6432017-12-13 12:44:31 +00006945 * the device. See {@link #isAffiliatedUser}.
Alex Chau5343fcb2017-12-05 16:49:19 +00006946 *
6947 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6948 * @param packageName The package to be installed in the calling profile.
6949 * @return {@code true} if the app is installed; {@code false} otherwise.
6950 * @throws SecurityException if {@code admin} is not the device owner, or the profile owner of
6951 * an affiliated user or profile.
6952 * @see #setKeepUninstalledPackages
6953 * @see #setDelegatedScopes
Alex Chau443b6432017-12-13 12:44:31 +00006954 * @see #isAffiliatedUser
Alex Chau5343fcb2017-12-05 16:49:19 +00006955 * @see #DELEGATION_PACKAGE_ACCESS
6956 */
6957 public boolean installExistingPackage(@NonNull ComponentName admin, String packageName) {
6958 throwIfParentInstance("installExistingPackage");
6959 if (mService != null) {
6960 try {
6961 return mService.installExistingPackage(admin, mContext.getPackageName(),
6962 packageName);
6963 } catch (RemoteException e) {
6964 throw e.rethrowFromSystemServer();
6965 }
6966 }
6967 return false;
6968 }
6969
6970 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00006971 * Called by a device owner or profile owner to disable account management for a specific type
6972 * of account.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006973 * <p>
6974 * The calling device admin must be a device owner or profile owner. If it is not, a security
6975 * exception will be thrown.
6976 * <p>
6977 * When account management is disabled for an account type, adding or removing an account of
6978 * that type will not be possible.
6979 * <p>
6980 * From {@link android.os.Build.VERSION_CODES#N} the profile or device owner can still use
Benjamin Franzb6c0ce42015-11-05 10:06:51 +00006981 * {@link android.accounts.AccountManager} APIs to add or remove accounts when account
6982 * management for a specific type is disabled.
6983 *
Sander Alewijnse650c3342014-05-08 18:00:50 +01006984 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6985 * @param accountType For which account management is disabled or enabled.
6986 * @param disabled The boolean indicating that account management will be disabled (true) or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006987 * enabled (false).
6988 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnse650c3342014-05-08 18:00:50 +01006989 */
Robin Lee25e26452015-06-02 09:56:29 -07006990 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01006991 boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006992 throwIfParentInstance("setAccountManagementDisabled");
Sander Alewijnse650c3342014-05-08 18:00:50 +01006993 if (mService != null) {
6994 try {
6995 mService.setAccountManagementDisabled(admin, accountType, disabled);
6996 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006997 throw e.rethrowFromSystemServer();
Sander Alewijnse650c3342014-05-08 18:00:50 +01006998 }
6999 }
7000 }
7001
7002 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01007003 * Gets the array of accounts for which account management is disabled by the profile owner.
7004 *
7005 * <p> Account management can be disabled/enabled by calling
7006 * {@link #setAccountManagementDisabled}.
7007 *
7008 * @return a list of account types for which account management has been disabled.
7009 *
7010 * @see #setAccountManagementDisabled
7011 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007012 public @Nullable String[] getAccountTypesWithManagementDisabled() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007013 throwIfParentInstance("getAccountTypesWithManagementDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07007014 return getAccountTypesWithManagementDisabledAsUser(myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01007015 }
7016
7017 /**
7018 * @see #getAccountTypesWithManagementDisabled()
7019 * @hide
7020 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007021 public @Nullable String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01007022 if (mService != null) {
7023 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01007024 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01007025 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007026 throw e.rethrowFromSystemServer();
Sander Alewijnse5c02db62014-05-07 10:46:57 +01007027 }
7028 }
7029
7030 return null;
7031 }
justinzhang511e0d82014-03-24 16:09:24 -04007032
7033 /**
Jason Monkd7b86212014-06-16 13:15:38 -04007034 * Sets which packages may enter lock task mode.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007035 * <p>
Esteban Talaverabdcada92017-02-01 14:20:06 +00007036 * Any packages that share uid with an allowed package will also be allowed to activate lock
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007037 * task. From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task
Esteban Talaverabdcada92017-02-01 14:20:06 +00007038 * package list results in locked tasks belonging to those packages to be finished.
7039 * <p>
Jason Parks3c13b642017-11-28 15:39:43 -06007040 * This function can only be called by the device owner, a profile owner of an affiliated user
7041 * or profile, or the profile owner when no device owner is set. See {@link #isAffiliatedUser}.
7042 * Any package set via this method will be cleared if the user becomes unaffiliated.
Jason Monkd7b86212014-06-16 13:15:38 -04007043 *
Jason Monkd7b86212014-06-16 13:15:38 -04007044 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04007045 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jason Parks3c13b642017-11-28 15:39:43 -06007046 * @throws SecurityException if {@code admin} is not the device owner, the profile owner of an
7047 * affiliated user or profile, or the profile owner when no device owner is set.
Alex Chau443b6432017-12-13 12:44:31 +00007048 * @see #isAffiliatedUser
Jason Monkd7b86212014-06-16 13:15:38 -04007049 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00007050 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
7051 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04007052 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04007053 */
Esteban Talaverabdcada92017-02-01 14:20:06 +00007054 public void setLockTaskPackages(@NonNull ComponentName admin, @NonNull String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04007055 throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007056 throwIfParentInstance("setLockTaskPackages");
justinzhang511e0d82014-03-24 16:09:24 -04007057 if (mService != null) {
7058 try {
Jason Monk48aacba2014-08-13 16:29:08 -04007059 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04007060 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007061 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04007062 }
7063 }
7064 }
7065
7066 /**
Esteban Talaverabdcada92017-02-01 14:20:06 +00007067 * Returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04007068 *
Jason Parks3c13b642017-11-28 15:39:43 -06007069 * @throws SecurityException if {@code admin} is not the device owner, the profile owner of an
7070 * affiliated user or profile, or the profile owner when no device owner is set.
Alex Chau443b6432017-12-13 12:44:31 +00007071 * @see #isAffiliatedUser
Esteban Talaverabdcada92017-02-01 14:20:06 +00007072 * @see #setLockTaskPackages
justinzhang511e0d82014-03-24 16:09:24 -04007073 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007074 public @NonNull String[] getLockTaskPackages(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007075 throwIfParentInstance("getLockTaskPackages");
justinzhang511e0d82014-03-24 16:09:24 -04007076 if (mService != null) {
7077 try {
Jason Monk48aacba2014-08-13 16:29:08 -04007078 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04007079 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007080 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04007081 }
7082 }
Esteban Talaverabdcada92017-02-01 14:20:06 +00007083 return new String[0];
justinzhang511e0d82014-03-24 16:09:24 -04007084 }
7085
7086 /**
7087 * This function lets the caller know whether the given component is allowed to start the
7088 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04007089 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04007090 */
Jason Monkd7b86212014-06-16 13:15:38 -04007091 public boolean isLockTaskPermitted(String pkg) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007092 throwIfParentInstance("isLockTaskPermitted");
justinzhang511e0d82014-03-24 16:09:24 -04007093 if (mService != null) {
7094 try {
Jason Monkd7b86212014-06-16 13:15:38 -04007095 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04007096 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007097 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04007098 }
7099 }
7100 return false;
7101 }
Julia Reynoldsda551652014-05-14 17:15:16 -04007102
7103 /**
Charles Hee078db72017-10-19 18:03:20 +01007104 * Sets which system features to enable for LockTask mode.
7105 * <p>
7106 * Feature flags set through this method will only take effect for the duration when the device
7107 * is in LockTask mode. If this method is not called, none of the features listed here will be
7108 * enabled.
7109 * <p>
Jason Parks3c13b642017-11-28 15:39:43 -06007110 * This function can only be called by the device owner, a profile owner of an affiliated user
7111 * or profile, or the profile owner when no device owner is set. See {@link #isAffiliatedUser}.
7112 * Any features set via this method will be cleared if the user becomes unaffiliated.
Charles Hee078db72017-10-19 18:03:20 +01007113 *
7114 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7115 * @param flags Bitfield of feature flags:
7116 * {@link #LOCK_TASK_FEATURE_NONE} (default),
7117 * {@link #LOCK_TASK_FEATURE_SYSTEM_INFO},
7118 * {@link #LOCK_TASK_FEATURE_NOTIFICATIONS},
7119 * {@link #LOCK_TASK_FEATURE_HOME},
7120 * {@link #LOCK_TASK_FEATURE_RECENTS},
7121 * {@link #LOCK_TASK_FEATURE_GLOBAL_ACTIONS},
7122 * {@link #LOCK_TASK_FEATURE_KEYGUARD}
Jason Parks3c13b642017-11-28 15:39:43 -06007123 * @throws SecurityException if {@code admin} is not the device owner, the profile owner of an
7124 * affiliated user or profile, or the profile owner when no device owner is set.
Alex Chau443b6432017-12-13 12:44:31 +00007125 * @see #isAffiliatedUser
Jason Parks3c13b642017-11-28 15:39:43 -06007126 * @throws SecurityException if {@code admin} is not the device owner or the profile owner.
Charles Hee078db72017-10-19 18:03:20 +01007127 */
7128 public void setLockTaskFeatures(@NonNull ComponentName admin, @LockTaskFeature int flags) {
7129 throwIfParentInstance("setLockTaskFeatures");
7130 if (mService != null) {
7131 try {
7132 mService.setLockTaskFeatures(admin, flags);
7133 } catch (RemoteException e) {
7134 throw e.rethrowFromSystemServer();
7135 }
7136 }
7137 }
7138
7139 /**
7140 * Gets which system features are enabled for LockTask mode.
7141 *
7142 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7143 * @return bitfield of flags. See {@link #setLockTaskFeatures(ComponentName, int)} for a list.
Jason Parks3c13b642017-11-28 15:39:43 -06007144 * @throws SecurityException if {@code admin} is not the device owner, the profile owner of an
7145 * affiliated user or profile, or the profile owner when no device owner is set.
Alex Chau443b6432017-12-13 12:44:31 +00007146 * @see #isAffiliatedUser
7147 * @see #setLockTaskFeatures
Charles Hee078db72017-10-19 18:03:20 +01007148 */
7149 public @LockTaskFeature int getLockTaskFeatures(@NonNull ComponentName admin) {
7150 throwIfParentInstance("getLockTaskFeatures");
7151 if (mService != null) {
7152 try {
7153 return mService.getLockTaskFeatures(admin);
7154 } catch (RemoteException e) {
7155 throw e.rethrowFromSystemServer();
7156 }
7157 }
7158 return 0;
7159 }
7160
7161 /**
yuemingw0de748d2017-11-15 19:22:27 +00007162 * Called by device owner to update {@link android.provider.Settings.Global} settings.
Benjamin Franz482bb232017-06-23 13:48:20 +01007163 * Validation that the value of the setting is in the correct form for the setting type should
7164 * be performed by the caller.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007165 * <p>
7166 * The settings that can be updated with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04007167 * <ul>
Benjamin Franz482bb232017-06-23 13:48:20 +01007168 * <li>{@link android.provider.Settings.Global#ADB_ENABLED}</li>
7169 * <li>{@link android.provider.Settings.Global#AUTO_TIME}</li>
7170 * <li>{@link android.provider.Settings.Global#AUTO_TIME_ZONE}</li>
7171 * <li>{@link android.provider.Settings.Global#DATA_ROAMING}</li>
7172 * <li>{@link android.provider.Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
7173 * <li>{@link android.provider.Settings.Global#WIFI_SLEEP_POLICY}</li>
7174 * <li>{@link android.provider.Settings.Global#STAY_ON_WHILE_PLUGGED_IN} This setting is only
7175 * available from {@link android.os.Build.VERSION_CODES#M} onwards and can only be set if
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007176 * {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
Benjamin Franz482bb232017-06-23 13:48:20 +01007177 * <li>{@link android.provider.Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li> This
7178 * setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04007179 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007180 * <p>
7181 * Changing the following settings has no effect as of {@link android.os.Build.VERSION_CODES#M}:
Esteban Talavera656fa7f2015-06-29 17:41:39 +01007182 * <ul>
Benjamin Franz482bb232017-06-23 13:48:20 +01007183 * <li>{@link android.provider.Settings.Global#BLUETOOTH_ON}. Use
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007184 * {@link android.bluetooth.BluetoothAdapter#enable()} and
7185 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
Benjamin Franz482bb232017-06-23 13:48:20 +01007186 * <li>{@link android.provider.Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
7187 * <li>{@link android.provider.Settings.Global#MODE_RINGER}. Use
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007188 * {@link android.media.AudioManager#setRingerMode(int)} instead.</li>
Benjamin Franz482bb232017-06-23 13:48:20 +01007189 * <li>{@link android.provider.Settings.Global#NETWORK_PREFERENCE}</li>
7190 * <li>{@link android.provider.Settings.Global#WIFI_ON}. Use
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007191 * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01007192 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04007193 *
7194 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7195 * @param setting The name of the setting to update.
7196 * @param value The value to update the setting to.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007197 * @throws SecurityException if {@code admin} is not a device owner.
Julia Reynoldsda551652014-05-14 17:15:16 -04007198 */
Robin Lee25e26452015-06-02 09:56:29 -07007199 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007200 throwIfParentInstance("setGlobalSetting");
Julia Reynoldsda551652014-05-14 17:15:16 -04007201 if (mService != null) {
7202 try {
7203 mService.setGlobalSetting(admin, setting, value);
7204 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007205 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04007206 }
7207 }
7208 }
7209
7210 /**
yuemingw0de748d2017-11-15 19:22:27 +00007211 * Called by device owner to update {@link android.provider.Settings.System} settings.
7212 * Validation that the value of the setting is in the correct form for the setting type should
7213 * be performed by the caller.
7214 * <p>
7215 * The settings that can be updated with this method are:
7216 * <ul>
7217 * <li>{@link android.provider.Settings.System#SCREEN_BRIGHTNESS}</li>
7218 * <li>{@link android.provider.Settings.System#SCREEN_BRIGHTNESS_MODE}</li>
7219 * <li>{@link android.provider.Settings.System#SCREEN_OFF_TIMEOUT}</li>
7220 * </ul>
7221 * <p>
7222 *
7223 * @see android.provider.Settings.System#SCREEN_OFF_TIMEOUT
7224 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7225 * @param setting The name of the setting to update.
7226 * @param value The value to update the setting to.
7227 * @throws SecurityException if {@code admin} is not a device owner.
7228 */
7229 public void setSystemSetting(@NonNull ComponentName admin, @NonNull String setting,
7230 String value) {
7231 throwIfParentInstance("setSystemSetting");
7232 if (mService != null) {
7233 try {
7234 mService.setSystemSetting(admin, setting, value);
7235 } catch (RemoteException e) {
7236 throw e.rethrowFromSystemServer();
7237 }
7238 }
7239 }
7240
7241 /**
yuemingwe43cdf72017-10-12 16:52:11 +01007242 * Called by device owner to set the system wall clock time. This only takes effect if called
7243 * when {@link android.provider.Settings.Global#AUTO_TIME} is 0, otherwise {@code false} will be
7244 * returned.
7245 *
7246 * @param admin Which {@link DeviceAdminReceiver} this request is associated with
7247 * @param millis time in milliseconds since the Epoch
7248 * @return {@code true} if set time succeeded, {@code false} otherwise.
7249 * @throws SecurityException if {@code admin} is not a device owner.
7250 */
7251 public boolean setTime(@NonNull ComponentName admin, long millis) {
7252 throwIfParentInstance("setTime");
7253 if (mService != null) {
7254 try {
7255 return mService.setTime(admin, millis);
7256 } catch (RemoteException e) {
7257 throw e.rethrowFromSystemServer();
7258 }
7259 }
7260 return false;
7261 }
7262
7263 /**
7264 * Called by device owner to set the system's persistent default time zone. This only takes
7265 * effect if called when {@link android.provider.Settings.Global#AUTO_TIME_ZONE} is 0, otherwise
7266 * {@code false} will be returned.
7267 *
7268 * @see android.app.AlarmManager#setTimeZone(String)
7269 * @param admin Which {@link DeviceAdminReceiver} this request is associated with
7270 * @param timeZone one of the Olson ids from the list returned by
7271 * {@link java.util.TimeZone#getAvailableIDs}
7272 * @return {@code true} if set timezone succeeded, {@code false} otherwise.
7273 * @throws SecurityException if {@code admin} is not a device owner.
7274 */
7275 public boolean setTimeZone(@NonNull ComponentName admin, String timeZone) {
7276 throwIfParentInstance("setTimeZone");
7277 if (mService != null) {
7278 try {
7279 return mService.setTimeZone(admin, timeZone);
7280 } catch (RemoteException e) {
7281 throw e.rethrowFromSystemServer();
7282 }
7283 }
7284 return false;
7285 }
7286
7287 /**
Benjamin Franz482bb232017-06-23 13:48:20 +01007288 * Called by profile or device owners to update {@link android.provider.Settings.Secure}
7289 * settings. Validation that the value of the setting is in the correct form for the setting
7290 * type should be performed by the caller.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007291 * <p>
7292 * The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04007293 * <ul>
Benjamin Franz482bb232017-06-23 13:48:20 +01007294 * <li>{@link android.provider.Settings.Secure#DEFAULT_INPUT_METHOD}</li>
7295 * <li>{@link android.provider.Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04007296 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007297 * <p>
7298 * A device owner can additionally update the following settings:
Julia Reynolds82735bc2014-09-04 16:43:30 -04007299 * <ul>
Benjamin Franz482bb232017-06-23 13:48:20 +01007300 * <li>{@link android.provider.Settings.Secure#LOCATION_MODE}</li>
Julia Reynolds82735bc2014-09-04 16:43:30 -04007301 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007302 *
Suprabh Shukla0b1356f2017-02-21 14:33:50 -08007303 * <strong>Note: Starting from Android O, apps should no longer call this method with the
7304 * setting {@link android.provider.Settings.Secure#INSTALL_NON_MARKET_APPS}, which is
7305 * deprecated. Instead, device owners or profile owners should use the restriction
7306 * {@link UserManager#DISALLOW_INSTALL_UNKNOWN_SOURCES}.
7307 * If any app targeting {@link android.os.Build.VERSION_CODES#O} or higher calls this method
7308 * with {@link android.provider.Settings.Secure#INSTALL_NON_MARKET_APPS},
7309 * an {@link UnsupportedOperationException} is thrown.
7310 * </strong>
7311 *
Julia Reynoldsda551652014-05-14 17:15:16 -04007312 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7313 * @param setting The name of the setting to update.
7314 * @param value The value to update the setting to.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007315 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynoldsda551652014-05-14 17:15:16 -04007316 */
Robin Lee25e26452015-06-02 09:56:29 -07007317 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007318 throwIfParentInstance("setSecureSetting");
Julia Reynoldsda551652014-05-14 17:15:16 -04007319 if (mService != null) {
7320 try {
7321 mService.setSecureSetting(admin, setting, value);
7322 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007323 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04007324 }
7325 }
7326 }
7327
Amith Yamasanif20d6402014-05-24 15:34:37 -07007328 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007329 * Designates a specific service component as the provider for making permission requests of a
7330 * local or remote administrator of the user.
Amith Yamasanif20d6402014-05-24 15:34:37 -07007331 * <p/>
7332 * Only a profile owner can designate the restrictions provider.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007333 *
Amith Yamasanif20d6402014-05-24 15:34:37 -07007334 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07007335 * @param provider The component name of the service that implements
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007336 * {@link RestrictionsReceiver}. If this param is null, it removes the restrictions
7337 * provider previously assigned.
7338 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanif20d6402014-05-24 15:34:37 -07007339 */
Robin Lee25e26452015-06-02 09:56:29 -07007340 public void setRestrictionsProvider(@NonNull ComponentName admin,
7341 @Nullable ComponentName provider) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007342 throwIfParentInstance("setRestrictionsProvider");
Amith Yamasanif20d6402014-05-24 15:34:37 -07007343 if (mService != null) {
7344 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07007345 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07007346 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007347 throw re.rethrowFromSystemServer();
Amith Yamasanif20d6402014-05-24 15:34:37 -07007348 }
7349 }
7350 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04007351
7352 /**
7353 * Called by profile or device owners to set the master volume mute on or off.
Nicolas Prevotaef3ce22016-09-22 12:00:25 +01007354 * This has no effect when set on a managed profile.
Julia Reynolds4a21b252014-06-04 11:11:43 -04007355 *
7356 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7357 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007358 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds4a21b252014-06-04 11:11:43 -04007359 */
Robin Lee25e26452015-06-02 09:56:29 -07007360 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007361 throwIfParentInstance("setMasterVolumeMuted");
Julia Reynolds4a21b252014-06-04 11:11:43 -04007362 if (mService != null) {
7363 try {
7364 mService.setMasterVolumeMuted(admin, on);
7365 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007366 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04007367 }
7368 }
7369 }
7370
7371 /**
7372 * Called by profile or device owners to check whether the master volume mute is on or off.
7373 *
7374 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7375 * @return {@code true} if master volume is muted, {@code false} if it's not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007376 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds4a21b252014-06-04 11:11:43 -04007377 */
Robin Lee25e26452015-06-02 09:56:29 -07007378 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007379 throwIfParentInstance("isMasterVolumeMuted");
Julia Reynolds4a21b252014-06-04 11:11:43 -04007380 if (mService != null) {
7381 try {
7382 return mService.isMasterVolumeMuted(admin);
7383 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007384 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04007385 }
7386 }
7387 return false;
7388 }
Kenny Guyc13053b2014-05-29 14:17:17 +01007389
7390 /**
Edman Anjosa5f2fb12016-12-19 11:25:54 -08007391 * Change whether a user can uninstall a package. This function can be called by a device owner,
7392 * profile owner, or by a delegate given the {@link #DELEGATION_BLOCK_UNINSTALL} scope via
7393 * {@link #setDelegatedScopes}.
Kenny Guyc13053b2014-05-29 14:17:17 +01007394 *
Edman Anjosa5f2fb12016-12-19 11:25:54 -08007395 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
7396 * {@code null} if the caller is a block uninstall delegate.
Kenny Guyc13053b2014-05-29 14:17:17 +01007397 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01007398 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007399 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjosa5f2fb12016-12-19 11:25:54 -08007400 * @see #setDelegatedScopes
7401 * @see #DELEGATION_BLOCK_UNINSTALL
Kenny Guyc13053b2014-05-29 14:17:17 +01007402 */
Edman Anjosa5f2fb12016-12-19 11:25:54 -08007403 public void setUninstallBlocked(@Nullable ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01007404 boolean uninstallBlocked) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007405 throwIfParentInstance("setUninstallBlocked");
Kenny Guyc13053b2014-05-29 14:17:17 +01007406 if (mService != null) {
7407 try {
Edman Anjosa5f2fb12016-12-19 11:25:54 -08007408 mService.setUninstallBlocked(admin, mContext.getPackageName(), packageName,
7409 uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01007410 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007411 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01007412 }
7413 }
7414 }
7415
7416 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08007417 * Check whether the user has been blocked by device policy from uninstalling a package.
Rubin Xua97855b2014-11-07 05:41:00 +00007418 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00007419 * <p>
7420 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007421 * behavior of this API is changed such that passing {@code null} as the {@code admin} parameter
7422 * will return if any admin has blocked the uninstallation. Before L MR1, passing {@code null}
7423 * will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01007424 *
Robin Lee25e26452015-06-02 09:56:29 -07007425 * @param admin The name of the admin component whose blocking policy will be checked, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007426 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01007427 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00007428 * @return true if uninstallation is blocked.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007429 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyc13053b2014-05-29 14:17:17 +01007430 */
Robin Lee25e26452015-06-02 09:56:29 -07007431 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007432 throwIfParentInstance("isUninstallBlocked");
Kenny Guyc13053b2014-05-29 14:17:17 +01007433 if (mService != null) {
7434 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01007435 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01007436 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007437 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01007438 }
7439 }
7440 return false;
7441 }
Svetoslav976e8bd2014-07-16 15:12:03 -07007442
7443 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007444 * Called by the profile owner of a managed profile to enable widget providers from a given
7445 * package to be available in the parent profile. As a result the user will be able to add
7446 * widgets from the white-listed package running under the profile to a widget host which runs
7447 * under the parent profile, for example the home screen. Note that a package may have zero or
7448 * more provider components, where each component provides a different widget type.
Svetoslav976e8bd2014-07-16 15:12:03 -07007449 * <p>
7450 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07007451 *
7452 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7453 * @param packageName The package from which widget providers are white-listed.
7454 * @return Whether the package was added.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007455 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07007456 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
7457 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
7458 */
Robin Lee25e26452015-06-02 09:56:29 -07007459 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007460 throwIfParentInstance("addCrossProfileWidgetProvider");
Svetoslav976e8bd2014-07-16 15:12:03 -07007461 if (mService != null) {
7462 try {
7463 return mService.addCrossProfileWidgetProvider(admin, packageName);
7464 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007465 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07007466 }
7467 }
7468 return false;
7469 }
7470
7471 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07007472 * Called by the profile owner of a managed profile to disable widget providers from a given
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007473 * package to be available in the parent profile. For this method to take effect the package
7474 * should have been added via
7475 * {@link #addCrossProfileWidgetProvider( android.content.ComponentName, String)}.
Svetoslav976e8bd2014-07-16 15:12:03 -07007476 * <p>
7477 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07007478 *
7479 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007480 * @param packageName The package from which widget providers are no longer white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07007481 * @return Whether the package was removed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007482 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07007483 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
7484 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
7485 */
Esteban Talavera62399912016-01-11 15:37:55 +00007486 public boolean removeCrossProfileWidgetProvider(
7487 @NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007488 throwIfParentInstance("removeCrossProfileWidgetProvider");
Svetoslav976e8bd2014-07-16 15:12:03 -07007489 if (mService != null) {
7490 try {
7491 return mService.removeCrossProfileWidgetProvider(admin, packageName);
7492 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007493 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07007494 }
7495 }
7496 return false;
7497 }
7498
7499 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07007500 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07007501 * available in the parent profile.
7502 *
7503 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7504 * @return The white-listed package list.
Svetoslav976e8bd2014-07-16 15:12:03 -07007505 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
7506 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007507 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07007508 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007509 public @NonNull List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007510 throwIfParentInstance("getCrossProfileWidgetProviders");
Svetoslav976e8bd2014-07-16 15:12:03 -07007511 if (mService != null) {
7512 try {
7513 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
7514 if (providers != null) {
7515 return providers;
7516 }
7517 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007518 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07007519 }
7520 }
7521 return Collections.emptyList();
7522 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05007523
7524 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08007525 * Called by profile or device owners to set the user's photo.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05007526 *
7527 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7528 * @param icon the bitmap to set as the photo.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007529 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05007530 */
Robin Lee25e26452015-06-02 09:56:29 -07007531 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007532 throwIfParentInstance("setUserIcon");
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05007533 try {
7534 mService.setUserIcon(admin, icon);
7535 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007536 throw re.rethrowFromSystemServer();
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05007537 }
7538 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04007539
7540 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01007541 * Called by device owners to set a local system update policy. When a new policy is set,
7542 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00007543 *
Robin Lee25e26452015-06-02 09:56:29 -07007544 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007545 * components in the device owner package can set system update policies and the most
7546 * recent policy takes effect.
Robin Lee25e26452015-06-02 09:56:29 -07007547 * @param policy the new policy, or {@code null} to clear the current policy.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007548 * @throws SecurityException if {@code admin} is not a device owner.
Rubin Xu5faad8e2015-04-20 17:43:48 +01007549 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00007550 */
Robin Lee25e26452015-06-02 09:56:29 -07007551 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007552 throwIfParentInstance("setSystemUpdatePolicy");
Rubin Xu8027a4f2015-03-10 17:52:37 +00007553 if (mService != null) {
7554 try {
Robin Lee25e26452015-06-02 09:56:29 -07007555 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00007556 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007557 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00007558 }
7559 }
7560 }
7561
7562 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01007563 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00007564 *
Robin Lee25e26452015-06-02 09:56:29 -07007565 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00007566 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007567 public @Nullable SystemUpdatePolicy getSystemUpdatePolicy() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007568 throwIfParentInstance("getSystemUpdatePolicy");
Rubin Xu8027a4f2015-03-10 17:52:37 +00007569 if (mService != null) {
7570 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01007571 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00007572 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007573 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00007574 }
7575 }
7576 return null;
7577 }
Benjamin Franze36087e2015-04-07 16:40:34 +01007578
7579 /**
Alex Chau7fbe61d2018-01-04 15:45:38 +00007580 * Called by a device owner or profile owner of secondary users that is affiliated with the
7581 * device to disable the keyguard altogether.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007582 * <p>
7583 * Setting the keyguard to disabled has the same effect as choosing "None" as the screen lock
7584 * type. However, this call has no effect if a password, pin or pattern is currently set. If a
7585 * password, pin or pattern is set after the keyguard was disabled, the keyguard stops being
7586 * disabled.
Benjamin Franze36087e2015-04-07 16:40:34 +01007587 *
Benjamin Franz32a3bf32017-08-04 15:01:52 +01007588 * <p>
Benjamin Franz64affcb2017-09-01 13:47:22 +01007589 * As of {@link android.os.Build.VERSION_CODES#P}, this call also dismisses the
Benjamin Franz32a3bf32017-08-04 15:01:52 +01007590 * keyguard if it is currently shown.
7591 *
Benjamin Franze36087e2015-04-07 16:40:34 +01007592 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01007593 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01007594 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007595 * place. {@code true} otherwise.
Alex Chau7fbe61d2018-01-04 15:45:38 +00007596 * @throws SecurityException if {@code admin} is not the device owner, or a profile owner of
7597 * secondary user that is affiliated with the device.
7598 * @see #isAffiliatedUser
7599 * @see #getSecondaryUsers
Benjamin Franze36087e2015-04-07 16:40:34 +01007600 */
Robin Lee25e26452015-06-02 09:56:29 -07007601 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007602 throwIfParentInstance("setKeyguardDisabled");
Benjamin Franze36087e2015-04-07 16:40:34 +01007603 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01007604 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01007605 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007606 throw re.rethrowFromSystemServer();
Benjamin Franze36087e2015-04-07 16:40:34 +01007607 }
7608 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00007609
7610 /**
Alex Chau7fbe61d2018-01-04 15:45:38 +00007611 * Called by device owner or profile owner of secondary users that is affiliated with the
7612 * device to disable the status bar. Disabling the status bar blocks notifications, quick
7613 * settings and other screen overlays that allow escaping from a single use device.
Charles Hee078db72017-10-19 18:03:20 +01007614 * <p>
7615 * <strong>Note:</strong> This method has no effect for LockTask mode. The behavior of the
7616 * status bar in LockTask mode can be configured with
7617 * {@link #setLockTaskFeatures(ComponentName, int)}. Calls to this method when the device is in
7618 * LockTask mode will be registered, but will only take effect when the device leaves LockTask
7619 * mode.
Benjamin Franzea2ec972015-03-16 17:18:09 +00007620 *
7621 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01007622 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007623 * @return {@code false} if attempting to disable the status bar failed. {@code true} otherwise.
Alex Chau7fbe61d2018-01-04 15:45:38 +00007624 * @throws SecurityException if {@code admin} is not the device owner, or a profile owner of
7625 * secondary user that is affiliated with the device.
7626 * @see #isAffiliatedUser
7627 * @see #getSecondaryUsers
Benjamin Franzea2ec972015-03-16 17:18:09 +00007628 */
Robin Lee25e26452015-06-02 09:56:29 -07007629 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007630 throwIfParentInstance("setStatusBarDisabled");
Benjamin Franzea2ec972015-03-16 17:18:09 +00007631 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01007632 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00007633 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007634 throw re.rethrowFromSystemServer();
Benjamin Franzea2ec972015-03-16 17:18:09 +00007635 }
7636 }
Rubin Xudc105cc2015-04-14 23:38:01 +01007637
7638 /**
Charles Hedea0c3b2017-01-13 10:04:12 +00007639 * Called by the system update service to notify device and profile owners of pending system
7640 * updates.
Rubin Xudc105cc2015-04-14 23:38:01 +01007641 *
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06007642 * This method should only be used when it is unknown whether the pending system
Charles Hedea0c3b2017-01-13 10:04:12 +00007643 * update is a security patch. Otherwise, use
7644 * {@link #notifyPendingSystemUpdate(long, boolean)}.
7645 *
7646 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()}
7647 * indicating when the current pending update was first available. {@code -1} if no
7648 * update is available.
7649 * @see #notifyPendingSystemUpdate(long, boolean)
Rubin Xudc105cc2015-04-14 23:38:01 +01007650 * @hide
7651 */
7652 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06007653 @RequiresPermission(android.Manifest.permission.NOTIFY_PENDING_SYSTEM_UPDATE)
Rubin Xudc105cc2015-04-14 23:38:01 +01007654 public void notifyPendingSystemUpdate(long updateReceivedTime) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007655 throwIfParentInstance("notifyPendingSystemUpdate");
Rubin Xudc105cc2015-04-14 23:38:01 +01007656 if (mService != null) {
7657 try {
Charles Hedea0c3b2017-01-13 10:04:12 +00007658 mService.notifyPendingSystemUpdate(SystemUpdateInfo.of(updateReceivedTime));
7659 } catch (RemoteException re) {
7660 throw re.rethrowFromSystemServer();
7661 }
7662 }
7663 }
7664
7665 /**
7666 * Called by the system update service to notify device and profile owners of pending system
7667 * updates.
7668 *
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06007669 * This method should be used instead of {@link #notifyPendingSystemUpdate(long)}
Charles Hedea0c3b2017-01-13 10:04:12 +00007670 * when it is known whether the pending system update is a security patch.
7671 *
7672 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()}
7673 * indicating when the current pending update was first available. {@code -1} if no
7674 * update is available.
7675 * @param isSecurityPatch {@code true} if this system update is purely a security patch;
7676 * {@code false} if not.
7677 * @see #notifyPendingSystemUpdate(long)
7678 * @hide
7679 */
7680 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06007681 @RequiresPermission(android.Manifest.permission.NOTIFY_PENDING_SYSTEM_UPDATE)
Charles Hedea0c3b2017-01-13 10:04:12 +00007682 public void notifyPendingSystemUpdate(long updateReceivedTime, boolean isSecurityPatch) {
7683 throwIfParentInstance("notifyPendingSystemUpdate");
7684 if (mService != null) {
7685 try {
7686 mService.notifyPendingSystemUpdate(SystemUpdateInfo.of(updateReceivedTime,
7687 isSecurityPatch));
Rubin Xudc105cc2015-04-14 23:38:01 +01007688 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007689 throw re.rethrowFromSystemServer();
Rubin Xudc105cc2015-04-14 23:38:01 +01007690 }
7691 }
7692 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04007693
7694 /**
Pavel Grafovd65799e2016-12-02 11:21:45 +00007695 * Called by device or profile owners to get information about a pending system update.
7696 *
7697 * @param admin Which profile or device owner this request is associated with.
7698 * @return Information about a pending system update or {@code null} if no update pending.
7699 * @throws SecurityException if {@code admin} is not a device or profile owner.
7700 * @see DeviceAdminReceiver#onSystemUpdatePending(Context, Intent, long)
7701 */
7702 public @Nullable SystemUpdateInfo getPendingSystemUpdate(@NonNull ComponentName admin) {
7703 throwIfParentInstance("getPendingSystemUpdate");
7704 try {
7705 return mService.getPendingSystemUpdate(admin);
7706 } catch (RemoteException re) {
7707 throw re.rethrowFromSystemServer();
7708 }
7709 }
7710
7711 /**
Edman Anjos52088e42017-01-13 22:26:17 +01007712 * Set the default response for future runtime permission requests by applications. This
7713 * function can be called by a device owner, profile owner, or by a delegate given the
7714 * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}.
7715 * The policy can allow for normal operation which prompts the user to grant a permission, or
7716 * can allow automatic granting or denying of runtime permission requests by an application.
7717 * This also applies to new permissions declared by app updates. When a permission is denied or
7718 * granted this way, the effect is equivalent to setting the permission * grant state via
7719 * {@link #setPermissionGrantState}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007720 * <p/>
7721 * As this policy only acts on runtime permission requests, it only applies to applications
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07007722 * built with a {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Benjamin Franz45dd6662015-07-08 14:24:14 +01007723 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07007724 * @param admin Which profile or device owner this request is associated with.
7725 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007726 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
7727 * @throws SecurityException if {@code admin} is not a device or profile owner.
Benjamin Franz45dd6662015-07-08 14:24:14 +01007728 * @see #setPermissionGrantState
Edman Anjos52088e42017-01-13 22:26:17 +01007729 * @see #setDelegatedScopes
7730 * @see #DELEGATION_PERMISSION_GRANT
Amith Yamasanid49489b2015-04-28 14:00:26 -07007731 */
Robin Lee25e26452015-06-02 09:56:29 -07007732 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007733 throwIfParentInstance("setPermissionPolicy");
Amith Yamasanid49489b2015-04-28 14:00:26 -07007734 try {
Edman Anjos52088e42017-01-13 22:26:17 +01007735 mService.setPermissionPolicy(admin, mContext.getPackageName(), policy);
Amith Yamasanid49489b2015-04-28 14:00:26 -07007736 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007737 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07007738 }
7739 }
7740
7741 /**
7742 * Returns the current runtime permission policy set by the device or profile owner. The
7743 * default is {@link #PERMISSION_POLICY_PROMPT}.
Edman Anjos52088e42017-01-13 22:26:17 +01007744 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07007745 * @param admin Which profile or device owner this request is associated with.
7746 * @return the current policy for future permission requests.
7747 */
Esteban Talavera28b95702015-06-24 15:23:42 +01007748 public int getPermissionPolicy(ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007749 throwIfParentInstance("getPermissionPolicy");
Amith Yamasanid49489b2015-04-28 14:00:26 -07007750 try {
7751 return mService.getPermissionPolicy(admin);
7752 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007753 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07007754 }
7755 }
7756
7757 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007758 * Sets the grant state of a runtime permission for a specific application. The state can be
7759 * {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it through the UI,
7760 * {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission is denied and the user
7761 * cannot manage it through the UI, and {@link #PERMISSION_GRANT_STATE_GRANTED granted} in which
7762 * the permission is granted and the user cannot manage it through the UI. This might affect all
7763 * permissions in a group that the runtime permission belongs to. This method can only be called
Edman Anjos52088e42017-01-13 22:26:17 +01007764 * by a profile owner, device owner, or a delegate given the
7765 * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007766 * <p/>
7767 * Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not revoke
7768 * the permission. It retains the previous grant, if any.
7769 * <p/>
7770 * Permissions can be granted or revoked only for applications built with a
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07007771 * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07007772 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07007773 * @param admin Which profile or device owner this request is associated with.
7774 * @param packageName The application to grant or revoke a permission to.
7775 * @param permission The permission to grant or revoke.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007776 * @param grantState The permission grant state which is one of
7777 * {@link #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
7778 * {@link #PERMISSION_GRANT_STATE_GRANTED},
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07007779 * @return whether the permission was successfully granted or revoked.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007780 * @throws SecurityException if {@code admin} is not a device or profile owner.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07007781 * @see #PERMISSION_GRANT_STATE_DENIED
7782 * @see #PERMISSION_GRANT_STATE_DEFAULT
7783 * @see #PERMISSION_GRANT_STATE_GRANTED
Edman Anjos52088e42017-01-13 22:26:17 +01007784 * @see #setDelegatedScopes
7785 * @see #DELEGATION_PERMISSION_GRANT
Amith Yamasanid49489b2015-04-28 14:00:26 -07007786 */
Robin Lee25e26452015-06-02 09:56:29 -07007787 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07007788 String permission, int grantState) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007789 throwIfParentInstance("setPermissionGrantState");
Amith Yamasanid49489b2015-04-28 14:00:26 -07007790 try {
Edman Anjos52088e42017-01-13 22:26:17 +01007791 return mService.setPermissionGrantState(admin, mContext.getPackageName(), packageName,
7792 permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07007793 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007794 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07007795 }
7796 }
Amith Yamasani184b3752015-05-22 13:00:51 -07007797
7798 /**
Edman Anjos52088e42017-01-13 22:26:17 +01007799 * Returns the current grant state of a runtime permission for a specific application. This
7800 * function can be called by a device owner, profile owner, or by a delegate given the
7801 * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}.
Amith Yamasani184b3752015-05-22 13:00:51 -07007802 *
Edman Anjos52088e42017-01-13 22:26:17 +01007803 * @param admin Which profile or device owner this request is associated with, or {@code null}
7804 * if the caller is a permission grant delegate.
Amith Yamasani184b3752015-05-22 13:00:51 -07007805 * @param packageName The application to check the grant state for.
7806 * @param permission The permission to check for.
7807 * @return the current grant state specified by device policy. If the profile or device owner
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007808 * has not set a grant state, the return value is
7809 * {@link #PERMISSION_GRANT_STATE_DEFAULT}. This does not indicate whether or not the
7810 * permission is currently granted for the package.
7811 * <p/>
7812 * If a grant state was set by the profile or device owner, then the return value will
7813 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or
7814 * {@link #PERMISSION_GRANT_STATE_GRANTED}, which indicates if the permission is
7815 * currently denied or granted.
7816 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasani184b3752015-05-22 13:00:51 -07007817 * @see #setPermissionGrantState(ComponentName, String, String, int)
7818 * @see PackageManager#checkPermission(String, String)
Edman Anjos52088e42017-01-13 22:26:17 +01007819 * @see #setDelegatedScopes
7820 * @see #DELEGATION_PERMISSION_GRANT
Amith Yamasani184b3752015-05-22 13:00:51 -07007821 */
Bartosz Fabianowski4b0624f2017-01-16 11:47:28 +01007822 public int getPermissionGrantState(@Nullable ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07007823 String permission) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007824 throwIfParentInstance("getPermissionGrantState");
Amith Yamasani184b3752015-05-22 13:00:51 -07007825 try {
Edman Anjos52088e42017-01-13 22:26:17 +01007826 return mService.getPermissionGrantState(admin, mContext.getPackageName(), packageName,
7827 permission);
Amith Yamasani184b3752015-05-22 13:00:51 -07007828 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007829 throw re.rethrowFromSystemServer();
Amith Yamasani184b3752015-05-22 13:00:51 -07007830 }
7831 }
Nicolas Prevot07387fe2015-10-30 17:53:30 +00007832
7833 /**
Esteban Talavera01576862016-12-15 11:16:44 +00007834 * Returns whether it is possible for the caller to initiate provisioning of a managed profile
7835 * or device, setting itself as the device or profile owner.
7836 *
Nicolas Prevot07387fe2015-10-30 17:53:30 +00007837 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
7838 * {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Esteban Talavera01576862016-12-15 11:16:44 +00007839 * @return whether provisioning a managed profile or device is possible.
Nicolas Prevot07387fe2015-10-30 17:53:30 +00007840 * @throws IllegalArgumentException if the supplied action is not valid.
7841 */
Esteban Talavera01576862016-12-15 11:16:44 +00007842 public boolean isProvisioningAllowed(@NonNull String action) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007843 throwIfParentInstance("isProvisioningAllowed");
Nicolas Prevot07387fe2015-10-30 17:53:30 +00007844 try {
Esteban Talavera01576862016-12-15 11:16:44 +00007845 return mService.isProvisioningAllowed(action, mContext.getPackageName());
Nicolas Prevot07387fe2015-10-30 17:53:30 +00007846 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007847 throw re.rethrowFromSystemServer();
Nicolas Prevot07387fe2015-10-30 17:53:30 +00007848 }
7849 }
Mahaver Chopra15a46b02015-11-11 14:54:35 +00007850
7851 /**
Esteban Talavera01576862016-12-15 11:16:44 +00007852 * Checks whether it is possible to initiate provisioning a managed device,
7853 * profile or user, setting the given package as owner.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00007854 *
7855 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
7856 * {@link #ACTION_PROVISION_MANAGED_PROFILE},
7857 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE},
7858 * {@link #ACTION_PROVISION_MANAGED_USER}
Esteban Talavera01576862016-12-15 11:16:44 +00007859 * @param packageName The package of the component that would be set as device, user, or profile
7860 * owner.
7861 * @return A {@link ProvisioningPreCondition} value indicating whether provisioning is allowed.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00007862 * @hide
7863 */
Esteban Talavera01576862016-12-15 11:16:44 +00007864 public @ProvisioningPreCondition int checkProvisioningPreCondition(
7865 String action, @NonNull String packageName) {
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00007866 try {
Esteban Talavera01576862016-12-15 11:16:44 +00007867 return mService.checkProvisioningPreCondition(action, packageName);
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00007868 } catch (RemoteException re) {
7869 throw re.rethrowFromSystemServer();
7870 }
7871 }
7872
7873 /**
Mahaver Chopra15a46b02015-11-11 14:54:35 +00007874 * Return if this user is a managed profile of another user. An admin can become the profile
7875 * owner of a managed profile with {@link #ACTION_PROVISION_MANAGED_PROFILE} and of a managed
Kenny Guyffa38402016-03-31 16:40:57 +01007876 * user with {@link #createAndManageUser}
Mahaver Chopra15a46b02015-11-11 14:54:35 +00007877 * @param admin Which profile owner this request is associated with.
7878 * @return if this user is a managed profile of another user.
7879 */
7880 public boolean isManagedProfile(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007881 throwIfParentInstance("isManagedProfile");
Mahaver Chopra15a46b02015-11-11 14:54:35 +00007882 try {
7883 return mService.isManagedProfile(admin);
7884 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007885 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00007886 }
7887 }
7888
7889 /**
7890 * @hide
7891 * Return if this user is a system-only user. An admin can manage a device from a system only
7892 * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}.
7893 * @param admin Which device owner this request is associated with.
7894 * @return if this user is a system-only user.
7895 */
7896 public boolean isSystemOnlyUser(@NonNull ComponentName admin) {
7897 try {
7898 return mService.isSystemOnlyUser(admin);
7899 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007900 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00007901 }
7902 }
Makoto Onukia31ebbc2015-11-23 17:15:21 -08007903
7904 /**
7905 * Called by device owner to get the MAC address of the Wi-Fi device.
7906 *
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08007907 * @param admin Which device owner this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007908 * @return the MAC address of the Wi-Fi device, or null when the information is not available.
7909 * (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.)
7910 * <p>
7911 * The address will be in the {@code XX:XX:XX:XX:XX:XX} format.
7912 * @throws SecurityException if {@code admin} is not a device owner.
Makoto Onukia31ebbc2015-11-23 17:15:21 -08007913 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007914 public @Nullable String getWifiMacAddress(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007915 throwIfParentInstance("getWifiMacAddress");
Makoto Onukia31ebbc2015-11-23 17:15:21 -08007916 try {
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08007917 return mService.getWifiMacAddress(admin);
Makoto Onukia31ebbc2015-11-23 17:15:21 -08007918 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007919 throw re.rethrowFromSystemServer();
Makoto Onukia31ebbc2015-11-23 17:15:21 -08007920 }
7921 }
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00007922
7923 /**
Mahaver Chopra1216ae52016-03-11 15:39:48 +00007924 * Called by device owner to reboot the device. If there is an ongoing call on the device,
7925 * throws an {@link IllegalStateException}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007926 * @param admin Which device owner the request is associated with.
Mahaver Chopra1216ae52016-03-11 15:39:48 +00007927 * @throws IllegalStateException if device has an ongoing call.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007928 * @throws SecurityException if {@code admin} is not a device owner.
Mahaver Chopra1216ae52016-03-11 15:39:48 +00007929 * @see TelephonyManager#CALL_STATE_IDLE
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00007930 */
7931 public void reboot(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007932 throwIfParentInstance("reboot");
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00007933 try {
7934 mService.reboot(admin);
7935 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007936 throw re.rethrowFromSystemServer();
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00007937 }
7938 }
Kenny Guy06de4e72015-12-22 12:07:39 +00007939
7940 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007941 * Called by a device admin to set the short support message. This will be displayed to the user
7942 * in settings screens where funtionality has been disabled by the admin. The message should be
7943 * limited to a short statement such as "This setting is disabled by your administrator. Contact
7944 * someone@example.com for support." If the message is longer than 200 characters it may be
7945 * truncated.
7946 * <p>
7947 * If the short support message needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007948 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
7949 * and set a new version of this string accordingly.
7950 *
Kenny Guy06de4e72015-12-22 12:07:39 +00007951 * @see #setLongSupportMessage
Kenny Guy06de4e72015-12-22 12:07:39 +00007952 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007953 * @param message Short message to be displayed to the user in settings or null to clear the
7954 * existing message.
7955 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00007956 */
7957 public void setShortSupportMessage(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007958 @Nullable CharSequence message) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007959 throwIfParentInstance("setShortSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00007960 if (mService != null) {
7961 try {
7962 mService.setShortSupportMessage(admin, message);
7963 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007964 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00007965 }
7966 }
7967 }
7968
7969 /**
7970 * Called by a device admin to get the short support message.
7971 *
7972 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007973 * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)} or
7974 * null if no message has been set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007975 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00007976 */
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007977 public CharSequence getShortSupportMessage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007978 throwIfParentInstance("getShortSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00007979 if (mService != null) {
7980 try {
7981 return mService.getShortSupportMessage(admin);
7982 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007983 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00007984 }
7985 }
7986 return null;
7987 }
7988
7989 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007990 * Called by a device admin to set the long support message. This will be displayed to the user
7991 * in the device administators settings screen.
7992 * <p>
7993 * If the long support message needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007994 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
7995 * and set a new version of this string accordingly.
7996 *
Kenny Guy06de4e72015-12-22 12:07:39 +00007997 * @see #setShortSupportMessage
Kenny Guy06de4e72015-12-22 12:07:39 +00007998 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007999 * @param message Long message to be displayed to the user in settings or null to clear the
8000 * existing message.
8001 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00008002 */
8003 public void setLongSupportMessage(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07008004 @Nullable CharSequence message) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008005 throwIfParentInstance("setLongSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00008006 if (mService != null) {
8007 try {
8008 mService.setLongSupportMessage(admin, message);
8009 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008010 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00008011 }
8012 }
8013 }
8014
8015 /**
8016 * Called by a device admin to get the long support message.
8017 *
8018 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07008019 * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)} or
8020 * null if no message has been set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07008021 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00008022 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07008023 public @Nullable CharSequence getLongSupportMessage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008024 throwIfParentInstance("getLongSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00008025 if (mService != null) {
8026 try {
8027 return mService.getLongSupportMessage(admin);
8028 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008029 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00008030 }
8031 }
8032 return null;
8033 }
8034
8035 /**
8036 * Called by the system to get the short support message.
8037 *
8038 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
8039 * @param userHandle user id the admin is running as.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07008040 * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)}
Kenny Guy06de4e72015-12-22 12:07:39 +00008041 *
8042 * @hide
8043 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07008044 public @Nullable CharSequence getShortSupportMessageForUser(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07008045 int userHandle) {
Kenny Guy06de4e72015-12-22 12:07:39 +00008046 if (mService != null) {
8047 try {
8048 return mService.getShortSupportMessageForUser(admin, userHandle);
8049 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008050 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00008051 }
8052 }
8053 return null;
8054 }
8055
8056
8057 /**
8058 * Called by the system to get the long support message.
8059 *
8060 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
8061 * @param userHandle user id the admin is running as.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07008062 * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)}
Kenny Guy06de4e72015-12-22 12:07:39 +00008063 *
8064 * @hide
8065 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07008066 public @Nullable CharSequence getLongSupportMessageForUser(
8067 @NonNull ComponentName admin, int userHandle) {
Kenny Guy06de4e72015-12-22 12:07:39 +00008068 if (mService != null) {
8069 try {
8070 return mService.getLongSupportMessageForUser(admin, userHandle);
8071 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008072 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00008073 }
8074 }
8075 return null;
8076 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00008077
8078 /**
Esteban Talavera62399912016-01-11 15:37:55 +00008079 * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager}
8080 * whose calls act on the parent profile.
Benjamin Franz66b45f02016-04-05 19:12:39 +01008081 *
8082 * <p>The following methods are supported for the parent instance, all other methods will
8083 * throw a SecurityException when called on the parent instance:
8084 * <ul>
8085 * <li>{@link #getPasswordQuality}</li>
8086 * <li>{@link #setPasswordQuality}</li>
8087 * <li>{@link #getPasswordMinimumLength}</li>
8088 * <li>{@link #setPasswordMinimumLength}</li>
8089 * <li>{@link #getPasswordMinimumUpperCase}</li>
8090 * <li>{@link #setPasswordMinimumUpperCase}</li>
8091 * <li>{@link #getPasswordMinimumLowerCase}</li>
8092 * <li>{@link #setPasswordMinimumLowerCase}</li>
8093 * <li>{@link #getPasswordMinimumLetters}</li>
8094 * <li>{@link #setPasswordMinimumLetters}</li>
8095 * <li>{@link #getPasswordMinimumNumeric}</li>
8096 * <li>{@link #setPasswordMinimumNumeric}</li>
8097 * <li>{@link #getPasswordMinimumSymbols}</li>
8098 * <li>{@link #setPasswordMinimumSymbols}</li>
8099 * <li>{@link #getPasswordMinimumNonLetter}</li>
8100 * <li>{@link #setPasswordMinimumNonLetter}</li>
8101 * <li>{@link #getPasswordHistoryLength}</li>
8102 * <li>{@link #setPasswordHistoryLength}</li>
8103 * <li>{@link #getPasswordExpirationTimeout}</li>
8104 * <li>{@link #setPasswordExpirationTimeout}</li>
8105 * <li>{@link #getPasswordExpiration}</li>
Charles He8c760562016-10-25 16:36:53 +01008106 * <li>{@link #getPasswordMaximumLength}</li>
Benjamin Franz66b45f02016-04-05 19:12:39 +01008107 * <li>{@link #isActivePasswordSufficient}</li>
8108 * <li>{@link #getCurrentFailedPasswordAttempts}</li>
8109 * <li>{@link #getMaximumFailedPasswordsForWipe}</li>
8110 * <li>{@link #setMaximumFailedPasswordsForWipe}</li>
8111 * <li>{@link #getMaximumTimeToLock}</li>
8112 * <li>{@link #setMaximumTimeToLock}</li>
8113 * <li>{@link #lockNow}</li>
8114 * <li>{@link #getKeyguardDisabledFeatures}</li>
8115 * <li>{@link #setKeyguardDisabledFeatures}</li>
8116 * <li>{@link #getTrustAgentConfiguration}</li>
8117 * <li>{@link #setTrustAgentConfiguration}</li>
Michal Karpinskia20d8bb2016-11-23 12:09:08 +00008118 * <li>{@link #getRequiredStrongAuthTimeout}</li>
8119 * <li>{@link #setRequiredStrongAuthTimeout}</li>
Benjamin Franz66b45f02016-04-05 19:12:39 +01008120 * </ul>
Clara Bayarri3e826ef2015-12-14 17:51:22 +00008121 *
8122 * @return a new instance of {@link DevicePolicyManager} that acts on the parent profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07008123 * @throws SecurityException if {@code admin} is not a profile owner.
Clara Bayarri3e826ef2015-12-14 17:51:22 +00008124 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07008125 public @NonNull DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008126 throwIfParentInstance("getParentProfileInstance");
Clara Bayarri3e826ef2015-12-14 17:51:22 +00008127 try {
8128 if (!mService.isManagedProfile(admin)) {
8129 throw new SecurityException("The current user does not have a parent profile.");
8130 }
Jeff Sharkey49ca5292016-05-10 12:54:45 -06008131 return new DevicePolicyManager(mContext, mService, true);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008132 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008133 throw e.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008134 }
8135 }
8136
8137 /**
Esteban Talaverad36dd152016-12-15 08:51:45 +00008138 * Called by device owner to control the security logging feature.
Michal Karpinski6235a942016-03-15 12:07:23 +00008139 *
8140 * <p> Security logs contain various information intended for security auditing purposes.
8141 * See {@link SecurityEvent} for details.
8142 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00008143 * <p><strong>Note:</strong> The device owner won't be able to retrieve security logs if there
8144 * are unaffiliated secondary users or profiles on the device, regardless of whether the
8145 * feature is enabled. Logs will be discarded if the internal buffer fills up while waiting for
8146 * all users to become affiliated. Therefore it's recommended that affiliation ids are set for
8147 * new users as soon as possible after provisioning via {@link #setAffiliationIds}.
Michal Karpinskib58e4962016-03-01 14:55:10 +00008148 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008149 * @param admin Which device owner this request is associated with.
Michal Karpinski6235a942016-03-15 12:07:23 +00008150 * @param enabled whether security logging should be enabled or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07008151 * @throws SecurityException if {@code admin} is not a device owner.
Alex Chau443b6432017-12-13 12:44:31 +00008152 * @see #setAffiliationIds
Michal Karpinski6235a942016-03-15 12:07:23 +00008153 * @see #retrieveSecurityLogs
8154 */
8155 public void setSecurityLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008156 throwIfParentInstance("setSecurityLoggingEnabled");
Michal Karpinski6235a942016-03-15 12:07:23 +00008157 try {
8158 mService.setSecurityLoggingEnabled(admin, enabled);
8159 } catch (RemoteException re) {
8160 throw re.rethrowFromSystemServer();
8161 }
8162 }
8163
8164 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00008165 * Return whether security logging is enabled or not by the device owner.
8166 *
8167 * <p>Can only be called by the device owner, otherwise a {@link SecurityException} will be
8168 * thrown.
8169 *
8170 * @param admin Which device owner this request is associated with.
8171 * @return {@code true} if security logging is enabled by device owner, {@code false} otherwise.
8172 * @throws SecurityException if {@code admin} is not a device owner.
8173 */
Bartosz Fabianowski0ec00002017-03-24 14:22:24 +01008174 public boolean isSecurityLoggingEnabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008175 throwIfParentInstance("isSecurityLoggingEnabled");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008176 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00008177 return mService.isSecurityLoggingEnabled(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008178 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008179 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008180 }
8181 }
8182
8183 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00008184 * Called by device owner to retrieve all new security logging entries since the last call to
8185 * this API after device boots.
8186 *
8187 * <p> Access to the logs is rate limited and it will only return new logs after the device
8188 * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}.
8189 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00008190 * <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 +00008191 * device. Otherwise a {@link SecurityException} will be thrown. See {@link #isAffiliatedUser}.
Michal Karpinskib58e4962016-03-01 14:55:10 +00008192 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008193 * @param admin Which device owner this request is associated with.
Michal Karpinski6235a942016-03-15 12:07:23 +00008194 * @return the new batch of security logs which is a list of {@link SecurityEvent},
8195 * or {@code null} if rate limitation is exceeded or if logging is currently disabled.
Esteban Talaverad36dd152016-12-15 08:51:45 +00008196 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
Alex Chau443b6432017-12-13 12:44:31 +00008197 * profile or secondary user that is not affiliated with the device.
8198 * @see #isAffiliatedUser
Esteban Talaverad36dd152016-12-15 08:51:45 +00008199 * @see DeviceAdminReceiver#onSecurityLogsAvailable
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008200 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07008201 public @Nullable List<SecurityEvent> retrieveSecurityLogs(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008202 throwIfParentInstance("retrieveSecurityLogs");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008203 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00008204 ParceledListSlice<SecurityEvent> list = mService.retrieveSecurityLogs(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008205 if (list != null) {
8206 return list.getList();
8207 } else {
8208 // Rate limit exceeded.
8209 return null;
8210 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00008211 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008212 throw re.rethrowFromSystemServer();
Clara Bayarri3e826ef2015-12-14 17:51:22 +00008213 }
8214 }
Benjamin Franz59720bb2016-01-18 15:26:11 +00008215
8216 /**
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00008217 * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent
8218 * profile.
8219 *
8220 * @hide
8221 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07008222 public @NonNull DevicePolicyManager getParentProfileInstance(UserInfo uInfo) {
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00008223 mContext.checkSelfPermission(
8224 android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS);
8225 if (!uInfo.isManagedProfile()) {
8226 throw new SecurityException("The user " + uInfo.id
8227 + " does not have a parent profile.");
8228 }
Jeff Sharkey49ca5292016-05-10 12:54:45 -06008229 return new DevicePolicyManager(mContext, mService, true);
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00008230 }
8231
8232 /**
Sudheer Shanka04d61ae2018-01-17 12:16:57 -08008233 * Called by a device or profile owner to restrict packages from accessing metered data.
8234 *
8235 * @param admin which {@link DeviceAdminReceiver} this request is associated with.
8236 * @param packageNames the list of package names to be restricted.
8237 * @return a list of package names which could not be restricted.
8238 * @throws SecurityException if {@code admin} is not a device or profile owner.
8239 */
8240 public @NonNull List<String> setMeteredDataDisabled(@NonNull ComponentName admin,
8241 @NonNull List<String> packageNames) {
8242 throwIfParentInstance("setMeteredDataDisabled");
8243 if (mService != null) {
8244 try {
8245 return mService.setMeteredDataDisabled(admin, packageNames);
8246 } catch (RemoteException re) {
8247 throw re.rethrowFromSystemServer();
8248 }
8249 }
8250 return packageNames;
8251 }
8252
8253 /**
8254 * Called by a device or profile owner to retrieve the list of packages which are restricted
8255 * by the admin from accessing metered data.
8256 *
8257 * @param admin which {@link DeviceAdminReceiver} this request is associated with.
8258 * @return the list of restricted package names.
8259 * @throws SecurityException if {@code admin} is not a device or profile owner.
8260 */
8261 public @NonNull List<String> getMeteredDataDisabled(@NonNull ComponentName admin) {
8262 throwIfParentInstance("getMeteredDataDisabled");
8263 if (mService != null) {
8264 try {
8265 return mService.getMeteredDataDisabled(admin);
8266 } catch (RemoteException re) {
8267 throw re.rethrowFromSystemServer();
8268 }
8269 }
8270 return new ArrayList<>();
8271 }
8272
8273 /**
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008274 * Called by device owners to retrieve device logs from before the device's last reboot.
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008275 * <p>
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01008276 * <strong> This API is not supported on all devices. Calling this API on unsupported devices
8277 * will result in {@code null} being returned. The device logs are retrieved from a RAM region
8278 * which is not guaranteed to be corruption-free during power cycles, as a result be cautious
8279 * about data corruption when parsing. </strong>
Esteban Talaverad36dd152016-12-15 08:51:45 +00008280 *
8281 * <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 +00008282 * device. Otherwise a {@link SecurityException} will be thrown. See {@link #isAffiliatedUser}.
Michal Karpinskib58e4962016-03-01 14:55:10 +00008283 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008284 * @param admin Which device owner this request is associated with.
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01008285 * @return Device logs from before the latest reboot of the system, or {@code null} if this API
8286 * is not supported on the device.
Esteban Talaverad36dd152016-12-15 08:51:45 +00008287 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
Alex Chau443b6432017-12-13 12:44:31 +00008288 * profile or secondary user that is not affiliated with the device.
8289 * @see #isAffiliatedUser
Esteban Talaverad36dd152016-12-15 08:51:45 +00008290 * @see #retrieveSecurityLogs
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008291 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07008292 public @Nullable List<SecurityEvent> retrievePreRebootSecurityLogs(
8293 @NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008294 throwIfParentInstance("retrievePreRebootSecurityLogs");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008295 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00008296 ParceledListSlice<SecurityEvent> list = mService.retrievePreRebootSecurityLogs(admin);
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01008297 if (list != null) {
8298 return list.getList();
8299 } else {
8300 return null;
8301 }
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008302 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008303 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00008304 }
8305 }
8306
8307 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07008308 * Called by a profile owner of a managed profile to set the color used for customization. This
8309 * color is used as background color of the confirm credentials screen for that user. The
Clara Bayarri8d0bd7fa2016-03-30 14:59:58 +01008310 * default color is teal (#00796B).
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07008311 * <p>
8312 * The confirm credentials screen can be created using
Benjamin Franz59720bb2016-01-18 15:26:11 +00008313 * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}.
8314 *
8315 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinski74cd7302016-04-12 15:17:36 +01008316 * @param color The 24bit (0xRRGGBB) representation of the color to be used.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07008317 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz59720bb2016-01-18 15:26:11 +00008318 */
8319 public void setOrganizationColor(@NonNull ComponentName admin, int color) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008320 throwIfParentInstance("setOrganizationColor");
Benjamin Franz59720bb2016-01-18 15:26:11 +00008321 try {
Michal Karpinski74cd7302016-04-12 15:17:36 +01008322 // always enforce alpha channel to have 100% opacity
8323 color |= 0xFF000000;
Benjamin Franz59720bb2016-01-18 15:26:11 +00008324 mService.setOrganizationColor(admin, color);
8325 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008326 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00008327 }
8328 }
8329
8330 /**
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00008331 * @hide
8332 *
8333 * Sets the color used for customization.
8334 *
Michal Karpinski74cd7302016-04-12 15:17:36 +01008335 * @param color The 24bit (0xRRGGBB) representation of the color to be used.
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00008336 * @param userId which user to set the color to.
8337 * @RequiresPermission(allOf = {
8338 * Manifest.permission.MANAGE_USERS,
8339 * Manifest.permission.INTERACT_ACROSS_USERS_FULL})
8340 */
8341 public void setOrganizationColorForUser(@ColorInt int color, @UserIdInt int userId) {
8342 try {
Michal Karpinski74cd7302016-04-12 15:17:36 +01008343 // always enforce alpha channel to have 100% opacity
8344 color |= 0xFF000000;
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00008345 mService.setOrganizationColorForUser(color, userId);
8346 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008347 throw re.rethrowFromSystemServer();
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00008348 }
8349 }
8350
8351 /**
Benjamin Franz59720bb2016-01-18 15:26:11 +00008352 * Called by a profile owner of a managed profile to retrieve the color used for customization.
8353 * This color is used as background color of the confirm credentials screen for that user.
8354 *
8355 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinski74cd7302016-04-12 15:17:36 +01008356 * @return The 24bit (0xRRGGBB) representation of the color to be used.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07008357 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz59720bb2016-01-18 15:26:11 +00008358 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01008359 public @ColorInt int getOrganizationColor(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008360 throwIfParentInstance("getOrganizationColor");
Benjamin Franz59720bb2016-01-18 15:26:11 +00008361 try {
8362 return mService.getOrganizationColor(admin);
8363 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008364 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00008365 }
8366 }
8367
8368 /**
8369 * @hide
8370 * Retrieve the customization color for a given user.
8371 *
8372 * @param userHandle The user id of the user we're interested in.
Michal Karpinski74cd7302016-04-12 15:17:36 +01008373 * @return The 24bit (0xRRGGBB) representation of the color to be used.
Benjamin Franz59720bb2016-01-18 15:26:11 +00008374 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01008375 public @ColorInt int getOrganizationColorForUser(int userHandle) {
Benjamin Franz59720bb2016-01-18 15:26:11 +00008376 try {
8377 return mService.getOrganizationColorForUser(userHandle);
8378 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008379 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00008380 }
8381 }
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01008382
8383 /**
Wen ZHANG2be4cfc2017-09-21 18:29:43 +01008384 * Called by the device owner (since API 26) or profile owner (since API 24) to set the name of
8385 * the organization under management.
8386 *
8387 * <p>If the organization name needs to be localized, it is the responsibility of the {@link
8388 * DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast and set
8389 * a new version of this string accordingly.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00008390 *
8391 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
8392 * @param title The organization name or {@code null} to clear a previously set name.
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01008393 * @throws SecurityException if {@code admin} is not a device or profile owner.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00008394 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01008395 public void setOrganizationName(@NonNull ComponentName admin, @Nullable CharSequence title) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008396 throwIfParentInstance("setOrganizationName");
Benjamin Franz3e8a7092016-01-25 16:19:08 +00008397 try {
8398 mService.setOrganizationName(admin, title);
8399 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008400 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00008401 }
8402 }
8403
8404 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07008405 * Called by a profile owner of a managed profile to retrieve the name of the organization under
8406 * management.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00008407 *
8408 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
8409 * @return The organization name or {@code null} if none is set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07008410 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00008411 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07008412 public @Nullable CharSequence getOrganizationName(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008413 throwIfParentInstance("getOrganizationName");
Benjamin Franz3e8a7092016-01-25 16:19:08 +00008414 try {
8415 return mService.getOrganizationName(admin);
8416 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008417 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00008418 }
8419 }
8420
8421 /**
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01008422 * Called by the system to retrieve the name of the organization managing the device.
8423 *
8424 * @return The organization name or {@code null} if none is set.
8425 * @throws SecurityException if the caller is not the device owner, does not hold the
8426 * MANAGE_USERS permission and is not the system.
8427 *
8428 * @hide
8429 */
8430 @SystemApi
8431 @TestApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06008432 @SuppressLint("Doclava125")
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01008433 public @Nullable CharSequence getDeviceOwnerOrganizationName() {
8434 try {
8435 return mService.getDeviceOwnerOrganizationName();
8436 } catch (RemoteException re) {
8437 throw re.rethrowFromSystemServer();
8438 }
8439 }
8440
8441 /**
Benjamin Franz3e8a7092016-01-25 16:19:08 +00008442 * Retrieve the default title message used in the confirm credentials screen for a given user.
8443 *
8444 * @param userHandle The user id of the user we're interested in.
8445 * @return The organization name or {@code null} if none is set.
8446 *
8447 * @hide
8448 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07008449 public @Nullable CharSequence getOrganizationNameForUser(int userHandle) {
Benjamin Franz3e8a7092016-01-25 16:19:08 +00008450 try {
8451 return mService.getOrganizationNameForUser(userHandle);
8452 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008453 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00008454 }
8455 }
8456
8457 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00008458 * @return the {@link UserProvisioningState} for the current user - for unmanaged users will
8459 * return {@link #STATE_USER_UNMANAGED}
8460 * @hide
8461 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00008462 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00008463 @UserProvisioningState
8464 public int getUserProvisioningState() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008465 throwIfParentInstance("getUserProvisioningState");
Alan Treadwayafad8782016-01-19 15:15:08 +00008466 if (mService != null) {
8467 try {
8468 return mService.getUserProvisioningState();
8469 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008470 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00008471 }
8472 }
8473 return STATE_USER_UNMANAGED;
8474 }
8475
8476 /**
8477 * Set the {@link UserProvisioningState} for the supplied user, if they are managed.
8478 *
8479 * @param state to store
8480 * @param userHandle for user
8481 * @hide
8482 */
8483 public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) {
8484 if (mService != null) {
8485 try {
8486 mService.setUserProvisioningState(state, userHandle);
8487 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008488 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00008489 }
8490 }
8491 }
8492
8493 /**
Esteban Talaverac9bb3782016-11-11 15:41:14 +00008494 * Indicates the entity that controls the device or profile owner. Two users/profiles are
8495 * affiliated if the set of ids set by their device or profile owners intersect.
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01008496 *
Alex Chau443b6432017-12-13 12:44:31 +00008497 * <p>A user/profile that is affiliated with the device owner user is considered to be
8498 * affiliated with the device.
8499 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00008500 * <p><strong>Note:</strong> Features that depend on user affiliation (such as security logging
8501 * or {@link #bindDeviceAdminServiceAsUser}) won't be available when a secondary user or profile
8502 * is created, until it becomes affiliated. Therefore it is recommended that the appropriate
8503 * affiliation ids are set by its profile owner as soon as possible after the user/profile is
8504 * created.
8505 *
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01008506 * @param admin Which profile or device owner this request is associated with.
Tony Mak31657432017-04-25 09:29:55 +01008507 * @param ids A set of opaque non-empty affiliation ids.
Esteban Talaverac9bb3782016-11-11 15:41:14 +00008508 *
Tony Mak31657432017-04-25 09:29:55 +01008509 * @throws IllegalArgumentException if {@code ids} is null or contains an empty string.
Alex Chau443b6432017-12-13 12:44:31 +00008510 * @see #isAffiliatedUser
Tony Mak31657432017-04-25 09:29:55 +01008511 */
8512 public void setAffiliationIds(@NonNull ComponentName admin, @NonNull Set<String> ids) {
8513 throwIfParentInstance("setAffiliationIds");
8514 if (ids == null) {
8515 throw new IllegalArgumentException("ids must not be null");
8516 }
8517 try {
8518 mService.setAffiliationIds(admin, new ArrayList<>(ids));
8519 } catch (RemoteException e) {
8520 throw e.rethrowFromSystemServer();
8521 }
8522 }
8523
8524 /**
Tony Mak31657432017-04-25 09:29:55 +01008525 * Returns the set of affiliation ids previously set via {@link #setAffiliationIds}, or an
8526 * empty set if none have been set.
Esteban Talaverac9bb3782016-11-11 15:41:14 +00008527 */
Tony Mak31657432017-04-25 09:29:55 +01008528 public @NonNull Set<String> getAffiliationIds(@NonNull ComponentName admin) {
Tony Mak62cf5862017-05-02 13:50:18 +01008529 throwIfParentInstance("getAffiliationIds");
Esteban Talaverac9bb3782016-11-11 15:41:14 +00008530 try {
Tony Mak31657432017-04-25 09:29:55 +01008531 return new ArraySet<>(mService.getAffiliationIds(admin));
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01008532 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008533 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01008534 }
8535 }
8536
8537 /**
Esteban Talaverac9bb3782016-11-11 15:41:14 +00008538 * Returns whether this user/profile is affiliated with the device.
8539 * <p>
8540 * By definition, the user that the device owner runs on is always affiliated with the device.
8541 * Any other user/profile is considered affiliated with the device if the set specified by its
8542 * profile owner via {@link #setAffiliationIds} intersects with the device owner's.
Alex Chau443b6432017-12-13 12:44:31 +00008543 * @see #setAffiliationIds
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01008544 */
8545 public boolean isAffiliatedUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01008546 throwIfParentInstance("isAffiliatedUser");
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01008547 try {
Esteban Talaverac9bb3782016-11-11 15:41:14 +00008548 return mService.isAffiliatedUser();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01008549 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008550 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01008551 }
8552 }
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08008553
8554 /**
8555 * @hide
8556 * Returns whether the uninstall for {@code packageName} for the current user is in queue
8557 * to be started
8558 * @param packageName the package to check for
8559 * @return whether the uninstall intent for {@code packageName} is pending
8560 */
8561 public boolean isUninstallInQueue(String packageName) {
8562 try {
8563 return mService.isUninstallInQueue(packageName);
8564 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008565 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08008566 }
8567 }
8568
8569 /**
8570 * @hide
8571 * @param packageName the package containing active DAs to be uninstalled
8572 */
8573 public void uninstallPackageWithActiveAdmins(String packageName) {
8574 try {
8575 mService.uninstallPackageWithActiveAdmins(packageName);
8576 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07008577 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08008578 }
8579 }
Benjamin Franzbc33c822016-04-15 08:57:52 +01008580
Kenny Guy38dcca52016-04-19 13:09:18 +01008581 /**
8582 * @hide
8583 * Remove a test admin synchronously without sending it a broadcast about being removed.
8584 * If the admin is a profile owner or device owner it will still be removed.
8585 *
8586 * @param userHandle user id to remove the admin for.
8587 * @param admin The administration compononent to remove.
8588 * @throws SecurityException if the caller is not shell / root or the admin package
8589 * isn't a test application see {@link ApplicationInfo#FLAG_TEST_APP}.
8590 */
8591 public void forceRemoveActiveAdmin(ComponentName adminReceiver, int userHandle) {
8592 try {
8593 mService.forceRemoveActiveAdmin(adminReceiver, userHandle);
8594 } catch (RemoteException re) {
8595 throw re.rethrowFromSystemServer();
8596 }
8597 }
8598
Mahaver Chopra790d1982016-07-07 16:06:49 +01008599 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01008600 * Returns whether the device has been provisioned.
8601 *
8602 * <p>Not for use by third-party applications.
8603 *
Mahaver Chopra790d1982016-07-07 16:06:49 +01008604 * @hide
Mahaver Chopra790d1982016-07-07 16:06:49 +01008605 */
Lenka Trochtova5291ee72016-11-28 16:38:23 +01008606 @SystemApi
Mahaver Chopra790d1982016-07-07 16:06:49 +01008607 public boolean isDeviceProvisioned() {
8608 try {
8609 return mService.isDeviceProvisioned();
8610 } catch (RemoteException re) {
8611 throw re.rethrowFromSystemServer();
8612 }
8613 }
8614
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01008615 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01008616 * Writes that the provisioning configuration has been applied.
8617 *
8618 * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS}
8619 * permission.
8620 *
8621 * <p>Not for use by third-party applications.
8622 *
8623 * @hide
8624 */
8625 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06008626 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01008627 public void setDeviceProvisioningConfigApplied() {
8628 try {
8629 mService.setDeviceProvisioningConfigApplied();
8630 } catch (RemoteException re) {
8631 throw re.rethrowFromSystemServer();
8632 }
8633 }
8634
8635 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01008636 * Returns whether the provisioning configuration has been applied.
8637 *
8638 * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS} permission.
8639 *
8640 * <p>Not for use by third-party applications.
8641 *
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01008642 * @return whether the provisioning configuration has been applied.
Lenka Trochtova5291ee72016-11-28 16:38:23 +01008643 *
8644 * @hide
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01008645 */
Lenka Trochtova5291ee72016-11-28 16:38:23 +01008646 @SystemApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06008647 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01008648 public boolean isDeviceProvisioningConfigApplied() {
8649 try {
8650 return mService.isDeviceProvisioningConfigApplied();
8651 } catch (RemoteException re) {
8652 throw re.rethrowFromSystemServer();
8653 }
8654 }
8655
Victor Chang9bfc65f2016-08-15 12:27:09 +01008656 /**
8657 * @hide
Victor Chang3577ed22016-08-25 18:49:26 +01008658 * Force update user setup completed status. This API has no effect on user build.
8659 * @throws {@link SecurityException} if the caller has no
Esteban Talavera01576862016-12-15 11:16:44 +00008660 * {@code android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS} or the caller is
8661 * not {@link UserHandle#SYSTEM_USER}
Victor Chang9bfc65f2016-08-15 12:27:09 +01008662 */
8663 public void forceUpdateUserSetupComplete() {
8664 try {
8665 mService.forceUpdateUserSetupComplete();
8666 } catch (RemoteException re) {
8667 throw re.rethrowFromSystemServer();
8668 }
8669 }
8670
Benjamin Franzbc33c822016-04-15 08:57:52 +01008671 private void throwIfParentInstance(String functionName) {
8672 if (mParentInstance) {
8673 throw new SecurityException(functionName + " cannot be called on the parent instance");
8674 }
8675 }
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02008676
8677 /**
Michal Karpinskib71fedc2017-01-05 15:21:38 +00008678 * Allows the device owner to enable or disable the backup service.
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02008679 *
Michal Karpinskib71fedc2017-01-05 15:21:38 +00008680 * <p> Backup service manages all backup and restore mechanisms on the device. Setting this to
8681 * false will prevent data from being backed up or restored.
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02008682 *
Michal Karpinskib71fedc2017-01-05 15:21:38 +00008683 * <p> Backup service is off by default when device owner is present.
8684 *
Lenka Trochtovac141d082017-12-20 14:45:16 +01008685 * <p> If backups are made mandatory by specifying a non-null mandatory backup transport using
8686 * the {@link DevicePolicyManager#setMandatoryBackupTransport} method, the backup service is
8687 * automatically enabled.
8688 *
8689 * <p> If the backup service is disabled using this method after the mandatory backup transport
8690 * has been set, the mandatory backup transport is cleared.
8691 *
Rubin Xu0367f072017-04-24 20:17:16 +01008692 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
8693 * @param enabled {@code true} to enable the backup service, {@code false} to disable it.
Michal Karpinskib71fedc2017-01-05 15:21:38 +00008694 * @throws SecurityException if {@code admin} is not a device owner.
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02008695 */
8696 public void setBackupServiceEnabled(@NonNull ComponentName admin, boolean enabled) {
Esteban Talavera5b7f2d02017-02-17 09:45:24 +00008697 throwIfParentInstance("setBackupServiceEnabled");
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02008698 try {
8699 mService.setBackupServiceEnabled(admin, enabled);
8700 } catch (RemoteException re) {
8701 throw re.rethrowFromSystemServer();
8702 }
8703 }
8704
8705 /**
Michal Karpinskib71fedc2017-01-05 15:21:38 +00008706 * Return whether the backup service is enabled by the device owner.
8707 *
8708 * <p> Backup service manages all backup and restore mechanisms on the device.
8709 *
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02008710 * @return {@code true} if backup service is enabled, {@code false} otherwise.
Michal Karpinskib71fedc2017-01-05 15:21:38 +00008711 * @see #setBackupServiceEnabled
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02008712 */
8713 public boolean isBackupServiceEnabled(@NonNull ComponentName admin) {
Esteban Talavera5b7f2d02017-02-17 09:45:24 +00008714 throwIfParentInstance("isBackupServiceEnabled");
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02008715 try {
8716 return mService.isBackupServiceEnabled(admin);
8717 } catch (RemoteException re) {
8718 throw re.rethrowFromSystemServer();
8719 }
8720 }
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01008721
8722 /**
Lenka Trochtovac141d082017-12-20 14:45:16 +01008723 * Makes backups mandatory and enforces the usage of the specified backup transport.
8724 *
8725 * <p>When a {@code null} backup transport is specified, backups are made optional again.
8726 * <p>Only device owner can call this method.
8727 * <p>If backups were disabled and a non-null backup transport {@link ComponentName} is
8728 * specified, backups will be enabled.
8729 *
8730 * @param admin admin Which {@link DeviceAdminReceiver} this request is associated with.
8731 * @param backupTransportComponent The backup transport layer to be used for mandatory backups.
8732 * @throws SecurityException if {@code admin} is not a device owner.
8733 */
8734 public void setMandatoryBackupTransport(
8735 @NonNull ComponentName admin, @Nullable ComponentName backupTransportComponent) {
8736 try {
8737 mService.setMandatoryBackupTransport(admin, backupTransportComponent);
8738 } catch (RemoteException re) {
8739 throw re.rethrowFromSystemServer();
8740 }
8741 }
8742
8743 /**
8744 * Returns the backup transport which has to be used for backups if backups are mandatory or
8745 * {@code null} if backups are not mandatory.
8746 *
8747 * @return a {@link ComponentName} of the backup transport layer to be used if backups are
8748 * mandatory or {@code null} if backups are not mandatory.
8749 */
8750 public ComponentName getMandatoryBackupTransport() {
8751 try {
8752 return mService.getMandatoryBackupTransport();
8753 } catch (RemoteException re) {
8754 throw re.rethrowFromSystemServer();
8755 }
8756 }
8757
8758
8759 /**
Esteban Talaverad36dd152016-12-15 08:51:45 +00008760 * Called by a device owner to control the network logging feature.
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01008761 *
Robin Leea40a2fb2017-02-08 17:07:06 +00008762 * <p> Network logs contain DNS lookup and connect() library call events. The following library
8763 * functions are recorded while network logging is active:
8764 * <ul>
8765 * <li>{@code getaddrinfo()}</li>
8766 * <li>{@code gethostbyname()}</li>
8767 * <li>{@code connect()}</li>
8768 * </ul>
8769 *
8770 * <p> Network logging is a low-overhead tool for forensics but it is not guaranteed to use
8771 * full system call logging; event reporting is enabled by default for all processes but not
8772 * strongly enforced.
8773 * Events from applications using alternative implementations of libc, making direct kernel
8774 * calls, or deliberately obfuscating traffic may not be recorded.
8775 *
8776 * <p> Some common network events may not be reported. For example:
8777 * <ul>
8778 * <li>Applications may hardcode IP addresses to reduce the number of DNS lookups, or use
8779 * an alternative system for name resolution, and so avoid calling
8780 * {@code getaddrinfo()} or {@code gethostbyname}.</li>
8781 * <li>Applications may use datagram sockets for performance reasons, for example
8782 * for a game client. Calling {@code connect()} is unnecessary for this kind of
8783 * socket, so it will not trigger a network event.</li>
8784 * </ul>
8785 *
8786 * <p> It is possible to directly intercept layer 3 traffic leaving the device using an
8787 * always-on VPN service.
8788 * See {@link #setAlwaysOnVpnPackage(ComponentName, String, boolean)}
8789 * and {@link android.net.VpnService} for details.
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01008790 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00008791 * <p><strong>Note:</strong> The device owner won't be able to retrieve network logs if there
8792 * are unaffiliated secondary users or profiles on the device, regardless of whether the
8793 * feature is enabled. Logs will be discarded if the internal buffer fills up while waiting for
8794 * all users to become affiliated. Therefore it's recommended that affiliation ids are set for
8795 * new users as soon as possible after provisioning via {@link #setAffiliationIds}.
8796 *
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01008797 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
8798 * @param enabled whether network logging should be enabled or not.
Esteban Talaverad36dd152016-12-15 08:51:45 +00008799 * @throws SecurityException if {@code admin} is not a device owner.
Alex Chau443b6432017-12-13 12:44:31 +00008800 * @see #setAffiliationIds
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01008801 * @see #retrieveNetworkLogs
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01008802 */
8803 public void setNetworkLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
8804 throwIfParentInstance("setNetworkLoggingEnabled");
8805 try {
8806 mService.setNetworkLoggingEnabled(admin, enabled);
8807 } catch (RemoteException re) {
8808 throw re.rethrowFromSystemServer();
8809 }
8810 }
8811
8812 /**
8813 * Return whether network logging is enabled by a device owner.
8814 *
phweissa4e169e2016-11-24 16:20:57 +01008815 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Can only
8816 * be {@code null} if the caller has MANAGE_USERS permission.
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01008817 * @return {@code true} if network logging is enabled by device owner, {@code false} otherwise.
Esteban Talaverad36dd152016-12-15 08:51:45 +00008818 * @throws SecurityException if {@code admin} is not a device owner and caller has
phweissa4e169e2016-11-24 16:20:57 +01008819 * no MANAGE_USERS permission
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01008820 */
phweissa4e169e2016-11-24 16:20:57 +01008821 public boolean isNetworkLoggingEnabled(@Nullable ComponentName admin) {
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01008822 throwIfParentInstance("isNetworkLoggingEnabled");
8823 try {
8824 return mService.isNetworkLoggingEnabled(admin);
8825 } catch (RemoteException re) {
8826 throw re.rethrowFromSystemServer();
8827 }
8828 }
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01008829
8830 /**
Michal Karpinskia9ff2062016-11-03 15:46:17 +00008831 * Called by device owner to retrieve the most recent batch of network logging events.
8832 * A device owner has to provide a batchToken provided as part of
8833 * {@link DeviceAdminReceiver#onNetworkLogsAvailable} callback. If the token doesn't match the
8834 * token of the most recent available batch of logs, {@code null} will be returned.
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01008835 *
8836 * <p> {@link NetworkEvent} can be one of {@link DnsEvent} or {@link ConnectEvent}.
8837 *
8838 * <p> The list of network events is sorted chronologically, and contains at most 1200 events.
8839 *
8840 * <p> Access to the logs is rate limited and this method will only return a new batch of logs
8841 * after the device device owner has been notified via
8842 * {@link DeviceAdminReceiver#onNetworkLogsAvailable}.
8843 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00008844 * <p>If a secondary user or profile is created, calling this method will throw a
8845 * {@link SecurityException} until all users become affiliated again. It will also no longer be
8846 * possible to retrieve the network logs batch with the most recent batchToken provided
8847 * by {@link DeviceAdminReceiver#onNetworkLogsAvailable}. See
8848 * {@link DevicePolicyManager#setAffiliationIds}.
8849 *
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01008850 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinskia9ff2062016-11-03 15:46:17 +00008851 * @param batchToken A token of the batch to retrieve
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01008852 * @return A new batch of network logs which is a list of {@link NetworkEvent}. Returns
Michal Karpinskia9ff2062016-11-03 15:46:17 +00008853 * {@code null} if the batch represented by batchToken is no longer available or if
8854 * logging is disabled.
Esteban Talaverad36dd152016-12-15 08:51:45 +00008855 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
Alex Chau443b6432017-12-13 12:44:31 +00008856 * profile or secondary user that is not affiliated with the device.
8857 * @see #setAffiliationIds
Michal Karpinskia9ff2062016-11-03 15:46:17 +00008858 * @see DeviceAdminReceiver#onNetworkLogsAvailable
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01008859 */
Michal Karpinskia9ff2062016-11-03 15:46:17 +00008860 public @Nullable List<NetworkEvent> retrieveNetworkLogs(@NonNull ComponentName admin,
8861 long batchToken) {
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01008862 throwIfParentInstance("retrieveNetworkLogs");
8863 try {
Michal Karpinskia9ff2062016-11-03 15:46:17 +00008864 return mService.retrieveNetworkLogs(admin, batchToken);
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01008865 } catch (RemoteException re) {
8866 throw re.rethrowFromSystemServer();
8867 }
8868 }
Tony Mak46aabe52016-11-14 12:53:06 +00008869
8870 /**
Esteban Talavera2f897912017-01-26 10:30:48 +00008871 * Called by a device owner to bind to a service from a profile owner or vice versa.
8872 * See {@link #getBindDeviceAdminTargetUsers} for a definition of which
Esteban Talaverafc291bc2016-11-21 13:52:03 +00008873 * device/profile owners are allowed to bind to services of another profile/device owner.
8874 * <p>
Tony Makeda0a9a2017-04-25 12:07:14 +01008875 * The service must be protected by {@link android.Manifest.permission#BIND_DEVICE_ADMIN}.
8876 * Note that the {@link Context} used to obtain this
Tony Mak46aabe52016-11-14 12:53:06 +00008877 * {@link DevicePolicyManager} instance via {@link Context#getSystemService(Class)} will be used
8878 * to bind to the {@link android.app.Service}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00008879 *
Tony Mak46aabe52016-11-14 12:53:06 +00008880 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
8881 * @param serviceIntent Identifies the service to connect to. The Intent must specify either an
8882 * explicit component name or a package name to match an
8883 * {@link IntentFilter} published by a service.
Tony Makbf9928d2016-12-22 11:02:45 +00008884 * @param conn Receives information as the service is started and stopped in main thread. This
8885 * must be a valid {@link ServiceConnection} object; it must not be {@code null}.
Tony Mak46aabe52016-11-14 12:53:06 +00008886 * @param flags Operation options for the binding operation. See
8887 * {@link Context#bindService(Intent, ServiceConnection, int)}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00008888 * @param targetUser Which user to bind to. Must be one of the users returned by
8889 * {@link #getBindDeviceAdminTargetUsers}, otherwise a {@link SecurityException} will
8890 * be thrown.
Tony Mak46aabe52016-11-14 12:53:06 +00008891 * @return If you have successfully bound to the service, {@code true} is returned;
8892 * {@code false} is returned if the connection is not made and you will not
8893 * receive the service object.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00008894 *
Tony Mak46aabe52016-11-14 12:53:06 +00008895 * @see Context#bindService(Intent, ServiceConnection, int)
Esteban Talaverafc291bc2016-11-21 13:52:03 +00008896 * @see #getBindDeviceAdminTargetUsers(ComponentName)
Tony Mak46aabe52016-11-14 12:53:06 +00008897 */
8898 public boolean bindDeviceAdminServiceAsUser(
8899 @NonNull ComponentName admin, Intent serviceIntent, @NonNull ServiceConnection conn,
8900 @Context.BindServiceFlags int flags, @NonNull UserHandle targetUser) {
8901 throwIfParentInstance("bindDeviceAdminServiceAsUser");
8902 // Keep this in sync with ContextImpl.bindServiceCommon.
8903 try {
Tony Makbf9928d2016-12-22 11:02:45 +00008904 final IServiceConnection sd = mContext.getServiceDispatcher(
8905 conn, mContext.getMainThreadHandler(), flags);
Tony Mak46aabe52016-11-14 12:53:06 +00008906 serviceIntent.prepareToLeaveProcess(mContext);
8907 return mService.bindDeviceAdminServiceAsUser(admin,
8908 mContext.getIApplicationThread(), mContext.getActivityToken(), serviceIntent,
8909 sd, flags, targetUser.getIdentifier());
8910 } catch (RemoteException re) {
8911 throw re.rethrowFromSystemServer();
8912 }
8913 }
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01008914
8915 /**
Esteban Talaverafc291bc2016-11-21 13:52:03 +00008916 * Returns the list of target users that the calling device or profile owner can use when
8917 * calling {@link #bindDeviceAdminServiceAsUser}.
8918 * <p>
Esteban Talavera2f897912017-01-26 10:30:48 +00008919 * A device owner can bind to a service from a profile owner and vice versa, provided that:
Esteban Talaverafc291bc2016-11-21 13:52:03 +00008920 * <ul>
8921 * <li>Both belong to the same package name.
Esteban Talavera2f897912017-01-26 10:30:48 +00008922 * <li>Both users are affiliated. See {@link #setAffiliationIds}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00008923 * </ul>
8924 */
8925 public @NonNull List<UserHandle> getBindDeviceAdminTargetUsers(@NonNull ComponentName admin) {
8926 throwIfParentInstance("getBindDeviceAdminTargetUsers");
8927 try {
8928 return mService.getBindDeviceAdminTargetUsers(admin);
8929 } catch (RemoteException re) {
8930 throw re.rethrowFromSystemServer();
8931 }
8932 }
8933
8934 /**
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01008935 * Called by the system to get the time at which the device owner last retrieved security
8936 * logging entries.
8937 *
8938 * @return the time at which the device owner most recently retrieved security logging entries,
8939 * in milliseconds since epoch; -1 if security logging entries were never retrieved.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01008940 * @throws SecurityException if the caller is not the device owner, does not hold the
8941 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01008942 *
8943 * @hide
8944 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01008945 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01008946 public long getLastSecurityLogRetrievalTime() {
8947 try {
8948 return mService.getLastSecurityLogRetrievalTime();
8949 } catch (RemoteException re) {
8950 throw re.rethrowFromSystemServer();
8951 }
8952 }
8953
8954 /**
8955 * Called by the system to get the time at which the device owner last requested a bug report.
8956 *
8957 * @return the time at which the device owner most recently requested a bug report, in
8958 * milliseconds since epoch; -1 if a bug report was never requested.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01008959 * @throws SecurityException if the caller is not the device owner, does not hold the
8960 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01008961 *
8962 * @hide
8963 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01008964 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01008965 public long getLastBugReportRequestTime() {
8966 try {
8967 return mService.getLastBugReportRequestTime();
8968 } catch (RemoteException re) {
8969 throw re.rethrowFromSystemServer();
8970 }
8971 }
8972
8973 /**
8974 * Called by the system to get the time at which the device owner last retrieved network logging
8975 * events.
8976 *
8977 * @return the time at which the device owner most recently retrieved network logging events, in
8978 * milliseconds since epoch; -1 if network logging events were never retrieved.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01008979 * @throws SecurityException if the caller is not the device owner, does not hold the
8980 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01008981 *
8982 * @hide
8983 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01008984 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01008985 public long getLastNetworkLogRetrievalTime() {
8986 try {
8987 return mService.getLastNetworkLogRetrievalTime();
8988 } catch (RemoteException re) {
8989 throw re.rethrowFromSystemServer();
8990 }
8991 }
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01008992
8993 /**
Bartosz Fabianowski172f7802017-03-06 12:07:57 +01008994 * Called by the system to find out whether the current user's IME was set by the device/profile
8995 * owner or the user.
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01008996 *
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01008997 * @return {@code true} if the user's IME was set by the device or profile owner, {@code false}
8998 * otherwise.
Bartosz Fabianowski172f7802017-03-06 12:07:57 +01008999 * @throws SecurityException if the caller is not the device owner/profile owner.
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01009000 *
9001 * @hide
9002 */
9003 @TestApi
Bartosz Fabianowski172f7802017-03-06 12:07:57 +01009004 public boolean isCurrentInputMethodSetByOwner() {
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01009005 try {
Bartosz Fabianowski172f7802017-03-06 12:07:57 +01009006 return mService.isCurrentInputMethodSetByOwner();
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01009007 } catch (RemoteException re) {
9008 throw re.rethrowFromSystemServer();
9009 }
9010 }
Bartosz Fabianowski05dc9f72017-02-22 23:41:14 +01009011
Bartosz Fabianowski05dc9f72017-02-22 23:41:14 +01009012 /**
9013 * Called by the system to get a list of CA certificates that were installed by the device or
9014 * profile owner.
9015 *
Bartosz Fabianowski172f7802017-03-06 12:07:57 +01009016 * <p> The caller must be the target user's device owner/profile Owner or hold the
Bartosz Fabianowski05dc9f72017-02-22 23:41:14 +01009017 * {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} permission.
9018 *
9019 * @param user The user for whom to retrieve information.
9020 * @return list of aliases identifying CA certificates installed by the device or profile owner
9021 * @throws SecurityException if the caller does not have permission to retrieve information
9022 * about the given user's CA certificates.
9023 *
9024 * @hide
9025 */
9026 @TestApi
9027 public List<String> getOwnerInstalledCaCerts(@NonNull UserHandle user) {
9028 try {
9029 return mService.getOwnerInstalledCaCerts(user).getList();
9030 } catch (RemoteException re) {
9031 throw re.rethrowFromSystemServer();
9032 }
9033 }
Benjamin Franza77e3572017-06-23 12:01:44 +01009034
9035 /**
9036 * Called by the device owner or profile owner to clear application user data of a given
9037 * package. The behaviour of this is equivalent to the target application calling
9038 * {@link android.app.ActivityManager#clearApplicationUserData()}.
9039 *
9040 * <p><strong>Note:</strong> an application can store data outside of its application data, e.g.
9041 * external storage or user dictionary. This data will not be wiped by calling this API.
9042 *
9043 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
9044 * @param packageName The name of the package which will have its user data wiped.
Jeff Sharkey8439ac02017-12-12 17:26:23 -07009045 * @param executor The executor through which the listener should be invoked.
Alex Chau4a4285b2018-01-12 13:35:06 +00009046 * @param listener A callback object that will inform the caller when the clearing is done.
Benjamin Franza77e3572017-06-23 12:01:44 +01009047 * @throws SecurityException if the caller is not the device owner/profile owner.
9048 * @return whether the clearing succeeded.
9049 */
9050 public boolean clearApplicationUserData(@NonNull ComponentName admin,
Alex Chau4a4285b2018-01-12 13:35:06 +00009051 @NonNull String packageName, @NonNull @CallbackExecutor Executor executor,
9052 @NonNull OnClearApplicationUserDataListener listener) {
Benjamin Franza77e3572017-06-23 12:01:44 +01009053 throwIfParentInstance("clearAppData");
Jeff Sharkey8439ac02017-12-12 17:26:23 -07009054 Preconditions.checkNotNull(executor);
Benjamin Franza77e3572017-06-23 12:01:44 +01009055 try {
9056 return mService.clearApplicationUserData(admin, packageName,
9057 new IPackageDataObserver.Stub() {
9058 public void onRemoveCompleted(String pkg, boolean succeeded) {
Jeff Sharkey8439ac02017-12-12 17:26:23 -07009059 executor.execute(() ->
Benjamin Franza77e3572017-06-23 12:01:44 +01009060 listener.onApplicationUserDataCleared(pkg, succeeded));
9061 }
9062 });
9063 } catch (RemoteException re) {
9064 throw re.rethrowFromSystemServer();
9065 }
9066 }
9067
9068 /**
Alex Chaud7958272017-12-08 11:30:52 +00009069 * Called by a device owner to specify whether logout is enabled for all secondary users. The
9070 * system may show a logout button that stops the user and switches back to the primary user.
Alex Chau04458852017-11-27 18:21:23 +00009071 *
9072 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Alex Chaud7958272017-12-08 11:30:52 +00009073 * @param enabled whether logout should be enabled or not.
Alex Chau04458852017-11-27 18:21:23 +00009074 * @throws SecurityException if {@code admin} is not a device owner.
9075 */
Alex Chaud7958272017-12-08 11:30:52 +00009076 public void setLogoutEnabled(@NonNull ComponentName admin, boolean enabled) {
9077 throwIfParentInstance("setLogoutEnabled");
Alex Chau04458852017-11-27 18:21:23 +00009078 try {
Alex Chaud7958272017-12-08 11:30:52 +00009079 mService.setLogoutEnabled(admin, enabled);
Alex Chau04458852017-11-27 18:21:23 +00009080 } catch (RemoteException re) {
9081 throw re.rethrowFromSystemServer();
9082 }
9083 }
9084
9085 /**
Alex Chaud7958272017-12-08 11:30:52 +00009086 * Returns whether logout is enabled by a device owner.
Alex Chau04458852017-11-27 18:21:23 +00009087 *
Alex Chaud7958272017-12-08 11:30:52 +00009088 * @return {@code true} if logout is enabled by device owner, {@code false} otherwise.
Alex Chau04458852017-11-27 18:21:23 +00009089 */
Alex Chaud7958272017-12-08 11:30:52 +00009090 public boolean isLogoutEnabled() {
9091 throwIfParentInstance("isLogoutEnabled");
Alex Chau04458852017-11-27 18:21:23 +00009092 try {
Alex Chaud7958272017-12-08 11:30:52 +00009093 return mService.isLogoutEnabled();
Alex Chau04458852017-11-27 18:21:23 +00009094 } catch (RemoteException re) {
9095 throw re.rethrowFromSystemServer();
9096 }
9097 }
9098
9099 /**
Benjamin Franza77e3572017-06-23 12:01:44 +01009100 * Callback used in {@link #clearApplicationUserData}
9101 * to indicate that the clearing of an application's user data is done.
9102 */
9103 public interface OnClearApplicationUserDataListener {
9104 /**
9105 * Method invoked when clearing the application user data has completed.
9106 *
9107 * @param packageName The name of the package which had its user data cleared.
9108 * @param succeeded Whether the clearing succeeded. Clearing fails for device administrator
9109 * apps and protected system packages.
9110 */
9111 void onApplicationUserDataCleared(String packageName, boolean succeeded);
9112 }
Alex Chaub6a9f942017-11-07 11:28:56 +08009113
9114 /**
9115 * Returns set of system apps that should be removed during provisioning.
9116 *
9117 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
9118 * @param userId ID of the user to be provisioned.
9119 * @param provisioningAction action indicating type of provisioning, should be one of
9120 * {@link #ACTION_PROVISION_MANAGED_DEVICE}, {@link #ACTION_PROVISION_MANAGED_PROFILE} or
9121 * {@link #ACTION_PROVISION_MANAGED_USER}.
9122 *
9123 * @hide
9124 */
9125 public Set<String> getDisallowedSystemApps(ComponentName admin, int userId,
9126 String provisioningAction) {
9127 try {
9128 return new ArraySet<>(
9129 mService.getDisallowedSystemApps(admin, userId, provisioningAction));
9130 } catch (RemoteException re) {
9131 throw re.rethrowFromSystemServer();
9132 }
9133 }
arangelov08841ef2017-11-23 15:29:42 +00009134
arangelov08841ef2017-11-23 15:29:42 +00009135 /**
arangelov8bae4ea2017-12-20 20:26:46 +00009136 * Changes the current administrator to another one. All policies from the current
9137 * administrator are migrated to the new administrator. The whole operation is atomic -
9138 * the transfer is either complete or not done at all.
arangelov08841ef2017-11-23 15:29:42 +00009139 *
arangelov8bae4ea2017-12-20 20:26:46 +00009140 * <p>Depending on the current administrator (device owner, profile owner), you have the
9141 * following expected behaviour:
arangelov08841ef2017-11-23 15:29:42 +00009142 * <ul>
9143 * <li>A device owner can only be transferred to a new device owner</li>
9144 * <li>A profile owner can only be transferred to a new profile owner</li>
arangelov08841ef2017-11-23 15:29:42 +00009145 * </ul>
9146 *
arangelov91201bd2018-01-04 17:10:21 +00009147 * <p>Use the {@code bundle} parameter to pass data to the new administrator. The data
arangelov8bae4ea2017-12-20 20:26:46 +00009148 * will be received in the
arangelov91201bd2018-01-04 17:10:21 +00009149 * {@link DeviceAdminReceiver#onTransferOwnershipComplete(Context, PersistableBundle)}
9150 * callback of the new administrator.
9151 *
9152 * <p>The transfer has failed if the original administrator is still the corresponding owner
9153 * after calling this method.
arangelov8bae4ea2017-12-20 20:26:46 +00009154 *
arangelov5149d7162018-01-11 19:48:14 +00009155 * <p>The incoming target administrator must have the
9156 * {@link DeviceAdminReceiver#SUPPORT_TRANSFER_OWNERSHIP_META_DATA} <code>meta-data</code> tag
9157 * included in its corresponding <code>receiver</code> component with a value of {@code true}.
9158 * Otherwise an {@link IllegalArgumentException} will be thrown.
9159 *
arangelov8bae4ea2017-12-20 20:26:46 +00009160 * @param admin which {@link DeviceAdminReceiver} this request is associated with
9161 * @param target which {@link DeviceAdminReceiver} we want the new administrator to be
9162 * @param bundle data to be sent to the new administrator
9163 * @throws SecurityException if {@code admin} is not a device owner nor a profile owner
arangelov91201bd2018-01-04 17:10:21 +00009164 * @throws IllegalArgumentException if {@code admin} or {@code target} is {@code null}, they
9165 * are components in the same package or {@code target} is not an active admin
arangelov08841ef2017-11-23 15:29:42 +00009166 */
arangelov8bae4ea2017-12-20 20:26:46 +00009167 public void transferOwnership(@NonNull ComponentName admin, @NonNull ComponentName target,
arangelov91201bd2018-01-04 17:10:21 +00009168 @Nullable PersistableBundle bundle) {
arangelov8bae4ea2017-12-20 20:26:46 +00009169 throwIfParentInstance("transferOwnership");
arangelov08841ef2017-11-23 15:29:42 +00009170 try {
arangelov8bae4ea2017-12-20 20:26:46 +00009171 mService.transferOwnership(admin, target, bundle);
arangelov08841ef2017-11-23 15:29:42 +00009172 } catch (RemoteException re) {
9173 throw re.rethrowFromSystemServer();
9174 }
9175 }
Alex Chau93ae42b2018-01-11 15:10:12 +00009176
9177 /**
9178 * Called by a device owner to specify the user session start message. This may be displayed
9179 * during a user switch.
9180 * <p>
9181 * The message should be limited to a short statement or it may be truncated.
9182 * <p>
9183 * If the message needs to be localized, it is the responsibility of the
9184 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
9185 * and set a new version of this message accordingly.
9186 *
9187 * @param admin which {@link DeviceAdminReceiver} this request is associated with.
9188 * @param startUserSessionMessage message for starting user session, or {@code null} to use
9189 * system default message.
9190 * @throws SecurityException if {@code admin} is not a device owner.
9191 */
9192 public void setStartUserSessionMessage(
9193 @NonNull ComponentName admin, @Nullable CharSequence startUserSessionMessage) {
9194 throwIfParentInstance("setStartUserSessionMessage");
9195 try {
9196 mService.setStartUserSessionMessage(admin, startUserSessionMessage);
9197 } catch (RemoteException re) {
9198 throw re.rethrowFromSystemServer();
9199 }
9200 }
9201
9202 /**
9203 * Called by a device owner to specify the user session end message. This may be displayed
9204 * during a user switch.
9205 * <p>
9206 * The message should be limited to a short statement or it may be truncated.
9207 * <p>
9208 * If the message needs to be localized, it is the responsibility of the
9209 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
9210 * and set a new version of this message accordingly.
9211 *
9212 * @param admin which {@link DeviceAdminReceiver} this request is associated with.
9213 * @param endUserSessionMessage message for ending user session, or {@code null} to use system
9214 * default message.
9215 * @throws SecurityException if {@code admin} is not a device owner.
9216 */
9217 public void setEndUserSessionMessage(
9218 @NonNull ComponentName admin, @Nullable CharSequence endUserSessionMessage) {
9219 throwIfParentInstance("setEndUserSessionMessage");
9220 try {
9221 mService.setEndUserSessionMessage(admin, endUserSessionMessage);
9222 } catch (RemoteException re) {
9223 throw re.rethrowFromSystemServer();
9224 }
9225 }
9226
9227 /**
9228 * Returns the user session start message.
9229 *
9230 * @param admin which {@link DeviceAdminReceiver} this request is associated with.
9231 * @throws SecurityException if {@code admin} is not a device owner.
9232 */
9233 public CharSequence getStartUserSessionMessage(@NonNull ComponentName admin) {
9234 throwIfParentInstance("getStartUserSessionMessage");
9235 try {
9236 return mService.getStartUserSessionMessage(admin);
9237 } catch (RemoteException re) {
9238 throw re.rethrowFromSystemServer();
9239 }
9240 }
9241
9242 /**
9243 * Returns the user session end message.
9244 *
9245 * @param admin which {@link DeviceAdminReceiver} this request is associated with.
9246 * @throws SecurityException if {@code admin} is not a device owner.
9247 */
9248 public CharSequence getEndUserSessionMessage(@NonNull ComponentName admin) {
9249 throwIfParentInstance("getEndUserSessionMessage");
9250 try {
9251 return mService.getEndUserSessionMessage(admin);
9252 } catch (RemoteException re) {
9253 throw re.rethrowFromSystemServer();
9254 }
9255 }
Vladislav Kuzkokov792d58f2018-01-15 15:04:05 +01009256
9257 /**
9258 * Allows/disallows printing.
9259 *
Vladislav Kuzkokov635ea802018-01-19 17:35:31 +01009260 * Called by a device owner or a profile owner.
9261 * Device owner changes policy for all users. Profile owner can override it if present.
9262 * Printing is enabled by default. If {@code FEATURE_PRINTING} is absent, the call is ignored.
9263 *
Vladislav Kuzkokov792d58f2018-01-15 15:04:05 +01009264 * @param admin which {@link DeviceAdminReceiver} this request is associated with.
9265 * @param enabled whether printing should be allowed or not.
9266 * @throws SecurityException if {@code admin} is neither device, nor profile owner.
Vladislav Kuzkokov792d58f2018-01-15 15:04:05 +01009267 */
9268 public void setPrintingEnabled(@NonNull ComponentName admin, boolean enabled) {
9269 try {
9270 mService.setPrintingEnabled(admin, enabled);
9271 } catch (RemoteException re) {
9272 throw re.rethrowFromSystemServer();
9273 }
9274 }
9275
9276 /**
Vladislav Kuzkokov635ea802018-01-19 17:35:31 +01009277 * Returns whether printing is enabled for this user.
9278 *
9279 * Always {@code false} if {@code FEATURE_PRINTING} is absent.
9280 * Otherwise, {@code true} by default.
Vladislav Kuzkokov792d58f2018-01-15 15:04:05 +01009281 *
9282 * @return {@code true} iff printing is enabled.
Vladislav Kuzkokov792d58f2018-01-15 15:04:05 +01009283 */
9284 public boolean isPrintingEnabled() {
9285 try {
9286 return mService.isPrintingEnabled();
9287 } catch (RemoteException re) {
9288 throw re.rethrowFromSystemServer();
9289 }
9290 }
9291
9292 /**
yuemingwe3d9c092018-01-11 12:11:44 +00009293 * Called by device owner to add an override APN.
9294 *
9295 * @param admin which {@link DeviceAdminReceiver} this request is associated with
9296 * @param apnSetting the override APN to insert
9297 * @return The {@code id} of inserted override APN. Or {@code -1} when failed to insert into
9298 * the database.
9299 * @throws SecurityException if {@code admin} is not a device owner.
9300 *
9301 * @see #setOverrideApnsEnabled(ComponentName, boolean)
9302 */
9303 public int addOverrideApn(@NonNull ComponentName admin, @NonNull ApnSetting apnSetting) {
9304 throwIfParentInstance("addOverrideApn");
9305 if (mService != null) {
9306 try {
9307 return mService.addOverrideApn(admin, apnSetting);
9308 } catch (RemoteException e) {
9309 throw e.rethrowFromSystemServer();
9310 }
9311 }
9312 return -1;
9313 }
9314
9315 /**
9316 * Called by device owner to update an override APN.
9317 *
9318 * @param admin which {@link DeviceAdminReceiver} this request is associated with
9319 * @param apnId the {@code id} of the override APN to update
9320 * @param apnSetting the override APN to update
9321 * @return {@code true} if the required override APN is successfully updated,
9322 * {@code false} otherwise.
9323 * @throws SecurityException if {@code admin} is not a device owner.
9324 *
9325 * @see #setOverrideApnsEnabled(ComponentName, boolean)
9326 */
9327 public boolean updateOverrideApn(@NonNull ComponentName admin, int apnId,
9328 @NonNull ApnSetting apnSetting) {
9329 throwIfParentInstance("updateOverrideApn");
9330 if (mService != null) {
9331 try {
9332 return mService.updateOverrideApn(admin, apnId, apnSetting);
9333 } catch (RemoteException e) {
9334 throw e.rethrowFromSystemServer();
9335 }
9336 }
9337 return false;
9338 }
9339
9340 /**
9341 * Called by device owner to remove an override APN.
9342 *
9343 * @param admin which {@link DeviceAdminReceiver} this request is associated with
9344 * @param apnId the {@code id} of the override APN to remove
9345 * @return {@code true} if the required override APN is successfully removed, {@code false}
9346 * otherwise.
9347 * @throws SecurityException if {@code admin} is not a device owner.
9348 *
9349 * @see #setOverrideApnsEnabled(ComponentName, boolean)
9350 */
9351 public boolean removeOverrideApn(@NonNull ComponentName admin, int apnId) {
9352 throwIfParentInstance("removeOverrideApn");
9353 if (mService != null) {
9354 try {
9355 return mService.removeOverrideApn(admin, apnId);
9356 } catch (RemoteException e) {
9357 throw e.rethrowFromSystemServer();
9358 }
9359 }
9360 return false;
9361 }
9362
9363 /**
9364 * Called by device owner to get all override APNs inserted by device owner.
9365 *
9366 * @param admin which {@link DeviceAdminReceiver} this request is associated with
9367 * @return A list of override APNs inserted by device owner.
9368 * @throws SecurityException if {@code admin} is not a device owner.
9369 *
9370 * @see #setOverrideApnsEnabled(ComponentName, boolean)
9371 */
9372 public List<ApnSetting> getOverrideApns(@NonNull ComponentName admin) {
9373 throwIfParentInstance("getOverrideApns");
9374 if (mService != null) {
9375 try {
9376 return mService.getOverrideApns(admin);
9377 } catch (RemoteException e) {
9378 throw e.rethrowFromSystemServer();
9379 }
9380 }
9381 return Collections.emptyList();
9382 }
9383
9384 /**
9385 * Called by device owner to set if override APNs should be enabled.
9386 * <p> Override APNs are separated from other APNs on the device, and can only be inserted or
9387 * modified by the device owner. When enabled, only override APNs are in use, any other APNs
9388 * are ignored.
9389 *
9390 * @param admin which {@link DeviceAdminReceiver} this request is associated with
9391 * @param enabled {@code true} if override APNs should be enabled, {@code false} otherwise
9392 * @throws SecurityException if {@code admin} is not a device owner.
9393 */
9394 public void setOverrideApnsEnabled(@NonNull ComponentName admin, boolean enabled) {
9395 throwIfParentInstance("setOverrideApnEnabled");
9396 if (mService != null) {
9397 try {
9398 mService.setOverrideApnsEnabled(admin, enabled);
9399 } catch (RemoteException e) {
9400 throw e.rethrowFromSystemServer();
9401 }
9402 }
9403 }
9404
9405 /**
9406 * Called by device owner to check if override APNs are currently enabled.
9407 *
9408 * @param admin which {@link DeviceAdminReceiver} this request is associated with
9409 * @return {@code true} if override APNs are currently enabled, {@code false} otherwise.
9410 * @throws SecurityException if {@code admin} is not a device owner.
9411 *
9412 * @see #setOverrideApnsEnabled(ComponentName, boolean)
9413 */
9414 public boolean isOverrideApnEnabled(@NonNull ComponentName admin) {
9415 throwIfParentInstance("isOverrideApnEnabled");
9416 if (mService != null) {
9417 try {
9418 return mService.isOverrideApnEnabled(admin);
9419 } catch (RemoteException e) {
9420 throw e.rethrowFromSystemServer();
9421 }
9422 }
9423 return false;
9424 }
arangelov91201bd2018-01-04 17:10:21 +00009425
9426 /**
9427 * Returns the data passed from the current administrator to the new administrator during an
9428 * ownership transfer. This is the same {@code bundle} passed in
9429 * {@link #transferOwnership(ComponentName, ComponentName, PersistableBundle)}.
9430 *
9431 * <p>Returns <code>null</code> if no ownership transfer was started for the calling user.
9432 *
9433 * @see #transferOwnership
9434 * @see DeviceAdminReceiver#onTransferOwnershipComplete(Context, PersistableBundle)
9435 */
9436 @Nullable
9437 public PersistableBundle getTransferOwnershipBundle() {
9438 throwIfParentInstance("getTransferOwnershipBundle");
9439 try {
9440 return mService.getTransferOwnershipBundle();
9441 } catch (RemoteException re) {
9442 throw re.rethrowFromSystemServer();
9443 }
9444 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08009445}