blob: b6c6f5b0c0356f27298c867de08da11f6a0cf1ce [file] [log] [blame]
Dianne Hackbornd6847842010-01-12 18:14:19 -08001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Dianne Hackborn87bba1e2010-02-26 17:25:54 -080017package android.app.admin;
Dianne Hackbornd6847842010-01-12 18:14:19 -080018
Nicolas Prevot8f7698a2016-02-11 16:05:33 +000019import android.annotation.ColorInt;
Alan Treadwayafad8782016-01-19 15:15:08 +000020import android.annotation.IntDef;
Robin Lee25e26452015-06-02 09:56:29 -070021import android.annotation.NonNull;
22import android.annotation.Nullable;
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060023import android.annotation.RequiresPermission;
Dianne Hackbornd6847842010-01-12 18:14:19 -080024import android.annotation.SdkConstant;
25import android.annotation.SdkConstant.SdkConstantType;
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060026import android.annotation.SuppressLint;
Justin Moreyb5deda72014-07-24 10:53:40 -050027import android.annotation.SystemApi;
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060028import android.annotation.SystemService;
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +010029import android.annotation.TestApi;
Nicolas Prevot8f7698a2016-02-11 16:05:33 +000030import android.annotation.UserIdInt;
Fyodor Kupolov4e9af062016-07-18 16:59:11 -070031import android.annotation.WorkerThread;
Jason Monkd7b86212014-06-16 13:15:38 -040032import android.app.Activity;
Tony Mak46aabe52016-11-14 12:53:06 +000033import android.app.IServiceConnection;
Rubin Xuaab7a412016-12-30 21:13:29 +000034import android.app.KeyguardManager;
Michal Karpinski6235a942016-03-15 12:07:23 +000035import android.app.admin.SecurityLog.SecurityEvent;
Dianne Hackbornd6847842010-01-12 18:14:19 -080036import android.content.ComponentName;
37import android.content.Context;
Adam Connors010cfd42014-04-16 12:48:13 +010038import android.content.Intent;
Sander Alewijnsef475ca32014-02-17 15:13:58 +000039import android.content.IntentFilter;
Tony Mak46aabe52016-11-14 12:53:06 +000040import android.content.ServiceConnection;
Victor Chang98607132017-01-27 11:51:56 +000041import android.content.pm.ApplicationInfo;
Dianne Hackbornd6847842010-01-12 18:14:19 -080042import android.content.pm.PackageManager;
Victor Changcd14c0a2016-03-16 19:10:15 +000043import android.content.pm.PackageManager.NameNotFoundException;
Rubin Xuc3cd05f2016-01-11 12:11:35 +000044import android.content.pm.ParceledListSlice;
Sudheer Shanka978fc0d2016-01-28 13:51:10 +000045import android.content.pm.UserInfo;
Julia Reynoldsfca04ca2015-02-17 13:39:12 -050046import android.graphics.Bitmap;
Jason Monk03bc9912014-05-13 09:44:57 -040047import android.net.ProxyInfo;
Nicolas Prevot8b7991c2015-11-12 17:40:12 +000048import android.net.Uri;
Robin Lee66e5d962014-04-09 16:44:21 +010049import android.os.Bundle;
Victor Changc10f6692016-12-09 15:24:00 +000050import android.os.Parcelable;
Jim Millere303bf42014-08-26 17:12:29 -070051import android.os.PersistableBundle;
Adam Connors776c5552014-01-09 10:42:56 +000052import android.os.Process;
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080053import android.os.RemoteCallback;
Dianne Hackbornd6847842010-01-12 18:14:19 -080054import android.os.RemoteException;
Amith Yamasani599dd7c2012-09-14 23:20:08 -070055import android.os.UserHandle;
Julia Reynolds1e958392014-05-16 14:25:21 -040056import android.os.UserManager;
Ricky Wai494b95d2015-11-20 16:07:15 +000057import android.provider.ContactsContract.Directory;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000058import android.provider.Settings;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010059import android.security.Credentials;
Amith Yamasanid1d7c022014-08-19 17:03:41 -070060import android.service.restrictions.RestrictionsReceiver;
Mahaver Chopra1216ae52016-03-11 15:39:48 +000061import android.telephony.TelephonyManager;
Tony Mak31657432017-04-25 09:29:55 +010062import android.util.ArraySet;
Dianne Hackbornd6847842010-01-12 18:14:19 -080063import android.util.Log;
64
Makoto Onukicc4bbeb2015-09-17 10:28:24 -070065import com.android.internal.annotations.VisibleForTesting;
Maggie Benthallda51e682013-08-08 22:35:44 -040066import com.android.org.conscrypt.TrustedCertificateStore;
67
68import java.io.ByteArrayInputStream;
Dianne Hackbornd6847842010-01-12 18:14:19 -080069import java.io.IOException;
Alan Treadwayafad8782016-01-19 15:15:08 +000070import java.lang.annotation.Retention;
71import java.lang.annotation.RetentionPolicy;
Oscar Montemayor69238c62010-08-03 10:51:06 -070072import java.net.InetSocketAddress;
73import java.net.Proxy;
Robin Lee0d5ccb72014-09-12 17:41:44 +010074import java.security.KeyFactory;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000075import java.security.NoSuchAlgorithmException;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010076import java.security.PrivateKey;
77import java.security.cert.Certificate;
Maggie Benthallda51e682013-08-08 22:35:44 -040078import java.security.cert.CertificateException;
79import java.security.cert.CertificateFactory;
80import java.security.cert.X509Certificate;
Robin Lee0d5ccb72014-09-12 17:41:44 +010081import java.security.spec.InvalidKeySpecException;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000082import java.security.spec.PKCS8EncodedKeySpec;
Jim Miller604e7552014-07-18 19:00:02 -070083import java.util.ArrayList;
Rubin Xub4365912016-03-23 12:13:22 +000084import java.util.Arrays;
Svetoslav976e8bd2014-07-16 15:12:03 -070085import java.util.Collections;
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -080086import java.util.List;
Tony Mak31657432017-04-25 09:29:55 +010087import java.util.Set;
Dianne Hackbornd6847842010-01-12 18:14:19 -080088
89/**
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000090 * Public interface for managing policies enforced on a device. Most clients of this class must be
Suprabh Shukla34d92ef2016-03-14 13:49:37 -070091 * registered with the system as a <a href="{@docRoot}guide/topics/admin/device-admin.html">device
92 * administrator</a>. Additionally, a device administrator may be registered as either a profile or
93 * device owner. A given method is accessible to all device administrators unless the documentation
94 * for that method specifies that it is restricted to either device or profile owners. Any
95 * application calling an api may only pass as an argument a device administrator component it
96 * owns. Otherwise, a {@link SecurityException} will be thrown.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080097 * <div class="special reference">
98 * <h3>Developer Guides</h3>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -070099 * <p>
100 * For more information about managing policies for device administration, read the <a href=
101 * "{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a> developer
102 * guide. </div>
Dianne Hackbornd6847842010-01-12 18:14:19 -0800103 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -0600104@SystemService(Context.DEVICE_POLICY_SERVICE)
Dianne Hackbornd6847842010-01-12 18:14:19 -0800105public class DevicePolicyManager {
106 private static String TAG = "DevicePolicyManager";
Dianne Hackbornd6847842010-01-12 18:14:19 -0800107
108 private final Context mContext;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800109 private final IDevicePolicyManager mService;
Esteban Talavera62399912016-01-11 15:37:55 +0000110 private final boolean mParentInstance;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700111
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600112 /** @hide */
113 public DevicePolicyManager(Context context, IDevicePolicyManager service) {
114 this(context, service, false);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800115 }
116
Dianne Hackborn87bba1e2010-02-26 17:25:54 -0800117 /** @hide */
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700118 @VisibleForTesting
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600119 protected DevicePolicyManager(Context context, IDevicePolicyManager service,
120 boolean parentInstance) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700121 mContext = context;
122 mService = service;
Esteban Talavera62399912016-01-11 15:37:55 +0000123 mParentInstance = parentInstance;
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700124 }
125
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700126 /** @hide test will override it. */
127 @VisibleForTesting
128 protected int myUserId() {
129 return UserHandle.myUserId();
130 }
131
Dianne Hackbornd6847842010-01-12 18:14:19 -0800132 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +0000133 * Activity action: Starts the provisioning flow which sets up a managed profile.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000134 *
Jessica Hummel9da60392014-05-21 12:32:57 +0100135 * <p>A managed profile allows data separation for example for the usage of a
136 * device as a personal and corporate device. The user which provisioning is started from and
137 * the managed profile share a launcher.
138 *
Andrew Solovay27f53372015-03-02 16:37:59 -0800139 * <p>This intent will typically be sent by a mobile device management application (MDM).
140 * Provisioning adds a managed profile and sets the MDM as the profile owner who has full
141 * control over the profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100142 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000143 * <p>It is possible to check if provisioning is allowed or not by querying the method
144 * {@link #isProvisioningAllowed(String)}.
145 *
146 * <p>In version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this intent must contain the
Nicolas Prevot18440252015-03-09 14:07:17 +0000147 * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700148 * As of {@link android.os.Build.VERSION_CODES#M}, it should contain the extra
Nicolas Prevot18440252015-03-09 14:07:17 +0000149 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only
150 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000151 *
Benjamin Franzea956242016-03-21 15:45:56 +0000152 * <p>The intent may also contain the following extras:
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000153 * <ul>
Benjamin Franzea956242016-03-21 15:45:56 +0000154 * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, optional </li>
155 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional, supported from
156 * {@link android.os.Build.VERSION_CODES#N}</li>
157 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
158 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
159 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Victor Chang51d84f92016-11-16 12:22:56 +0000160 * <li>{@link #EXTRA_PROVISIONING_SKIP_USER_CONSENT}, optional</li>
Victor Chang89ee2792016-11-23 12:10:55 +0000161 * <li>{@link #EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION}, optional</li>
Victor Changc10f6692016-12-09 15:24:00 +0000162 * <li>{@link #EXTRA_PROVISIONING_DISCLAIMERS}, optional</li>
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000163 * </ul>
Jessica Hummelf72078b2014-03-06 16:13:12 +0000164 *
Benjamin Franzea956242016-03-21 15:45:56 +0000165 * <p>When managed provisioning has completed, broadcasts are sent to the application specified
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000166 * in the provisioning intent. The
167 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the
168 * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in
169 * the primary profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100170 *
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000171 * <p>From version {@link android.os.Build.VERSION_CODES#O}, when managed provisioning has
172 * completed, along with the above broadcast, activity intent
173 * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the application specified in
174 * the provisioning intent.
175 *
Benjamin Franzea956242016-03-21 15:45:56 +0000176 * <p>If provisioning fails, the managedProfile is removed so the device returns to its
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100177 * previous state.
Alan Treadway4582f812015-07-28 11:49:35 +0100178 *
179 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
180 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
181 * the provisioning flow was successful, although this doesn't guarantee the full flow will
182 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
183 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000184 */
185 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
186 public static final String ACTION_PROVISION_MANAGED_PROFILE
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100187 = "android.app.action.PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000188
189 /**
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000190 * Activity action: Starts the provisioning flow which sets up a managed user.
191 *
192 * <p>This intent will typically be sent by a mobile device management application (MDM).
Makoto Onuki32b30572015-12-11 14:29:51 -0800193 * Provisioning configures the user as managed user and sets the MDM as the profile
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000194 * owner who has full control over the user. Provisioning can only happen before user setup has
195 * been completed. Use {@link #isProvisioningAllowed(String)} to check if provisioning is
196 * allowed.
197 *
Benjamin Franzea956242016-03-21 15:45:56 +0000198 * <p>The intent contains the following extras:
199 * <ul>
200 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
201 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
202 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
203 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
204 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
205 * </ul>
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000206 *
Benjamin Franzea956242016-03-21 15:45:56 +0000207 * <p>If provisioning fails, the device returns to its previous state.
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000208 *
209 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
210 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
211 * the provisioning flow was successful, although this doesn't guarantee the full flow will
212 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
213 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Benjamin Franzea956242016-03-21 15:45:56 +0000214 *
215 * @hide
Mahaver Chopra5e732562015-11-05 11:55:12 +0000216 */
217 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
218 public static final String ACTION_PROVISION_MANAGED_USER
219 = "android.app.action.PROVISION_MANAGED_USER";
220
221 /**
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100222 * Activity action: Starts the provisioning flow which sets up a managed device.
223 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
224 *
225 * <p> During device owner provisioning a device admin app is set as the owner of the device.
226 * A device owner has full control over the device. The device owner can not be modified by the
227 * user.
228 *
229 * <p> A typical use case would be a device that is owned by a company, but used by either an
230 * employee or client.
231 *
232 * <p> An intent with this action can be sent only on an unprovisioned device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000233 * It is possible to check if provisioning is allowed or not by querying the method
234 * {@link #isProvisioningAllowed(String)}.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100235 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000236 * <p>The intent contains the following extras:
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100237 * <ul>
238 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
239 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
240 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
Rubin Xua4f9dc12015-06-12 13:27:59 +0100241 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000242 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000243 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Victor Changc10f6692016-12-09 15:24:00 +0000244 * <li>{@link #EXTRA_PROVISIONING_DISCLAIMERS}, optional</li>
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100245 * </ul>
246 *
Benjamin Franzea956242016-03-21 15:45:56 +0000247 * <p>When device owner provisioning has completed, an intent of the type
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100248 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
249 * device owner.
250 *
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000251 * <p>From version {@link android.os.Build.VERSION_CODES#O}, when device owner provisioning has
252 * completed, along with the above broadcast, activity intent
253 * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the device owner.
254 *
Benjamin Franzea956242016-03-21 15:45:56 +0000255 * <p>If provisioning fails, the device is factory reset.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100256 *
Alan Treadway4582f812015-07-28 11:49:35 +0100257 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
258 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
259 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
260 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100261 */
262 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
263 public static final String ACTION_PROVISION_MANAGED_DEVICE
264 = "android.app.action.PROVISION_MANAGED_DEVICE";
265
266 /**
Alan Treadway46dd4492015-11-09 13:57:19 +0000267 * Activity action: Starts the provisioning flow which sets up a managed device.
Steven Ng980a1b62016-02-02 17:43:18 +0000268 *
269 * <p>During device owner provisioning, a device admin app is downloaded and set as the owner of
270 * the device. A device owner has full control over the device. The device owner can not be
271 * modified by the user and the only way of resetting the device is via factory reset.
272 *
273 * <p>A typical use case would be a device that is owned by a company, but used by either an
274 * employee or client.
275 *
276 * <p>The provisioning message should be sent to an unprovisioned device.
277 *
278 * <p>Unlike {@link #ACTION_PROVISION_MANAGED_DEVICE}, the provisioning message can only be sent
279 * by a privileged app with the permission
280 * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE}.
281 *
282 * <p>The provisioning intent contains the following properties:
283 * <ul>
284 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
285 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
286 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
287 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Victor Chang38cfd9c2017-01-04 17:41:11 +0000288 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL}, optional</li>
289 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI}, optional</li>
Steven Ng980a1b62016-02-02 17:43:18 +0000290 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
291 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
292 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
293 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
294 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
295 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
296 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
297 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
298 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
299 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
300 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
Victor Chang38cfd9c2017-01-04 17:41:11 +0000301 * <li>{@link #EXTRA_PROVISIONING_SUPPORT_URL}, optional</li>
302 * <li>{@link #EXTRA_PROVISIONING_ORGANIZATION_NAME}, optional</li>
Steven Ng980a1b62016-02-02 17:43:18 +0000303 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li></ul>
304 *
305 * @hide
306 */
307 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
308 @SystemApi
309 public static final String ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE =
310 "android.app.action.PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE";
311
312 /**
313 * Activity action: Starts the provisioning flow which sets up a managed device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000314 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
315 *
316 * <p>NOTE: This is only supported on split system user devices, and puts the device into a
317 * management state that is distinct from that reached by
318 * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system
319 * user, and only has control over device-wide policies, not individual users and their data.
320 * The primary benefit is that multiple non-system users are supported when provisioning using
321 * this form of device management.
322 *
Benjamin Franzea956242016-03-21 15:45:56 +0000323 * <p>During device owner provisioning a device admin app is set as the owner of the device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000324 * A device owner has full control over the device. The device owner can not be modified by the
325 * user.
326 *
Benjamin Franzea956242016-03-21 15:45:56 +0000327 * <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 +0000328 * employee or client.
329 *
Benjamin Franzea956242016-03-21 15:45:56 +0000330 * <p>An intent with this action can be sent only on an unprovisioned device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000331 * It is possible to check if provisioning is allowed or not by querying the method
332 * {@link #isProvisioningAllowed(String)}.
333 *
334 * <p>The intent contains the following extras:
335 * <ul>
336 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
337 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
338 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
339 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Benjamin Franzea956242016-03-21 15:45:56 +0000340 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
341 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Alan Treadway46dd4492015-11-09 13:57:19 +0000342 * </ul>
343 *
Benjamin Franzea956242016-03-21 15:45:56 +0000344 * <p>When device owner provisioning has completed, an intent of the type
Alan Treadway46dd4492015-11-09 13:57:19 +0000345 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
346 * device owner.
347 *
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000348 * <p>From version {@link android.os.Build.VERSION_CODES#O}, when device owner provisioning has
349 * completed, along with the above broadcast, activity intent
350 * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the device owner.
351 *
Benjamin Franzea956242016-03-21 15:45:56 +0000352 * <p>If provisioning fails, the device is factory reset.
Alan Treadway46dd4492015-11-09 13:57:19 +0000353 *
354 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
355 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
356 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
357 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
358 *
359 * @hide
360 */
361 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
362 public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE
363 = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE";
364
365 /**
Alan Treadwayafad8782016-01-19 15:15:08 +0000366 * Activity action: Finalizes management provisioning, should be used after user-setup
367 * has been completed and {@link #getUserProvisioningState()} returns one of:
368 * <ul>
369 * <li>{@link #STATE_USER_SETUP_INCOMPLETE}</li>
370 * <li>{@link #STATE_USER_SETUP_COMPLETE}</li>
371 * <li>{@link #STATE_USER_PROFILE_COMPLETE}</li>
372 * </ul>
373 *
374 * @hide
375 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +0000376 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +0000377 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
378 public static final String ACTION_PROVISION_FINALIZATION
379 = "android.app.action.PROVISION_FINALIZATION";
380
381 /**
Michal Karpinskiba244092016-02-25 17:28:24 +0000382 * Action: Bugreport sharing with device owner has been accepted by the user.
383 *
384 * @hide
385 */
386 public static final String ACTION_BUGREPORT_SHARING_ACCEPTED =
Rubin Xu7226c7d2017-02-06 17:18:50 +0000387 "com.android.server.action.REMOTE_BUGREPORT_SHARING_ACCEPTED";
Michal Karpinskiba244092016-02-25 17:28:24 +0000388
389 /**
390 * Action: Bugreport sharing with device owner has been declined by the user.
391 *
392 * @hide
393 */
394 public static final String ACTION_BUGREPORT_SHARING_DECLINED =
Rubin Xu7226c7d2017-02-06 17:18:50 +0000395 "com.android.server.action.REMOTE_BUGREPORT_SHARING_DECLINED";
Michal Karpinskiba244092016-02-25 17:28:24 +0000396
397 /**
Esteban Talavera01576862016-12-15 11:16:44 +0000398 * Action: Bugreport has been collected and is dispatched to {@code DevicePolicyManagerService}.
Michal Karpinskiba244092016-02-25 17:28:24 +0000399 *
400 * @hide
401 */
402 public static final String ACTION_REMOTE_BUGREPORT_DISPATCH =
403 "android.intent.action.REMOTE_BUGREPORT_DISPATCH";
404
405 /**
406 * Extra for shared bugreport's SHA-256 hash.
407 *
408 * @hide
409 */
410 public static final String EXTRA_REMOTE_BUGREPORT_HASH =
411 "android.intent.extra.REMOTE_BUGREPORT_HASH";
412
413 /**
414 * Extra for remote bugreport notification shown type.
415 *
416 * @hide
417 */
418 public static final String EXTRA_BUGREPORT_NOTIFICATION_TYPE =
419 "android.app.extra.bugreport_notification_type";
420
421 /**
422 * Notification type for a started remote bugreport flow.
423 *
424 * @hide
425 */
426 public static final int NOTIFICATION_BUGREPORT_STARTED = 1;
427
428 /**
429 * Notification type for a bugreport that has already been accepted to be shared, but is still
430 * being taken.
431 *
432 * @hide
433 */
434 public static final int NOTIFICATION_BUGREPORT_ACCEPTED_NOT_FINISHED = 2;
435
436 /**
437 * Notification type for a bugreport that has been taken and can be shared or declined.
438 *
439 * @hide
440 */
441 public static final int NOTIFICATION_BUGREPORT_FINISHED_NOT_ACCEPTED = 3;
442
443 /**
Michal Karpinski8f010dd2016-06-21 15:05:53 +0100444 * Default and maximum timeout in milliseconds after which unlocking with weak auth times out,
445 * i.e. the user has to use a strong authentication method like password, PIN or pattern.
446 *
447 * @hide
448 */
449 public static final long DEFAULT_STRONG_AUTH_TIMEOUT_MS = 72 * 60 * 60 * 1000; // 72h
450
451 /**
Rubin Xua4f9dc12015-06-12 13:27:59 +0100452 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100453 * allows a mobile device management application or NFC programmer application which starts
454 * managed provisioning to pass data to the management application instance after provisioning.
Rubin Xua4f9dc12015-06-12 13:27:59 +0100455 * <p>
456 * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that
457 * sends the intent to pass data to itself on the newly created profile.
458 * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same
459 * instance of the app on the primary user.
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100460 * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with
461 * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC
462 * message should contain a stringified {@link java.util.Properties} instance, whose string
463 * properties will be converted into a {@link android.os.PersistableBundle} and passed to the
464 * management application after provisioning.
465 *
Rubin Xua4f9dc12015-06-12 13:27:59 +0100466 * <p>
467 * In both cases the application receives the data in
Brian Carlstromf1fe51b2014-09-03 08:55:05 -0700468 * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action
469 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed
Rubin Xua4f9dc12015-06-12 13:27:59 +0100470 * during the managed provisioning.
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100471 */
472 public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE =
Esteban Talavera37f01842014-09-05 10:50:57 +0100473 "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE";
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100474
475 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100476 * A String extra holding the package name of the mobile device management application that
477 * will be set as the profile owner or device owner.
478 *
479 * <p>If an application starts provisioning directly via an intent with action
480 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
481 * application that started provisioning. The package will be set as profile owner in that case.
482 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000483 * <p>This package is set as device owner when device owner provisioning is started by an NFC
484 * message containing an NFC record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000485 *
486 * <p> When this extra is set, the application must have exactly one device admin receiver.
Robin Lee25e26452015-06-02 09:56:29 -0700487 * This receiver will be set as the profile or device owner and active admin.
Benjamin Franzea956242016-03-21 15:45:56 +0000488 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000489 * @see DeviceAdminReceiver
490 * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still
Nicolas Prevot8f78d6a2015-08-21 11:06:31 +0100491 * supported, but only if there is only one device admin receiver in the package that requires
492 * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000493 */
Nicolas Prevot18440252015-03-09 14:07:17 +0000494 @Deprecated
Jessica Hummelf72078b2014-03-06 16:13:12 +0000495 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100496 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000497
498 /**
Nicolas Prevot18440252015-03-09 14:07:17 +0000499 * A ComponentName extra indicating the device admin receiver of the mobile device management
500 * application that will be set as the profile owner or device owner and active admin.
501 *
502 * <p>If an application starts provisioning directly via an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100503 * {@link #ACTION_PROVISION_MANAGED_PROFILE} or
504 * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this
505 * component has to match the package name of the application that started provisioning.
Nicolas Prevot18440252015-03-09 14:07:17 +0000506 *
507 * <p>This component is set as device owner and active admin when device owner provisioning is
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100508 * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC
509 * message containing an NFC record with MIME type
Benjamin Franzea956242016-03-21 15:45:56 +0000510 * {@link #MIME_TYPE_PROVISIONING_NFC}. For the NFC record, the component name must be
Rubin Xu44ef750b2015-03-23 16:51:33 +0000511 * flattened to a string, via {@link ComponentName#flattenToShortString()}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000512 *
513 * @see DeviceAdminReceiver
514 */
515 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME
516 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME";
517
518 /**
Alexandra Gherghinaaaf2f3e2014-11-13 12:46:15 +0000519 * An {@link android.accounts.Account} extra holding the account to migrate during managed
520 * profile provisioning. If the account supplied is present in the primary user, it will be
521 * copied, along with its credentials to the managed profile and removed from the primary user.
522 *
523 * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}.
524 */
525
526 public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE
527 = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE";
528
529 /**
Victor Changaa9cbc02016-12-05 20:50:57 +0000530 * Boolean extra to indicate that the migrated account should be kept. This is used in
531 * conjunction with {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}. If it's set to {@code true},
532 * the account will not be removed from the primary user after it is migrated to the newly
533 * created user or profile.
Victor Chang89ee2792016-11-23 12:10:55 +0000534 *
535 * <p> Defaults to {@code false}
536 *
Victor Changaa9cbc02016-12-05 20:50:57 +0000537 * <p> Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
538 * {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}
Victor Chang89ee2792016-11-23 12:10:55 +0000539 */
540 public static final String EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION
541 = "android.app.extra.PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION";
542
543 /**
Mahaver761ce772017-03-13 16:40:45 +0000544 * @deprecated From {@link android.os.Build.VERSION_CODES#O}, never used while provisioning the
545 * device.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100546 */
Mahaver761ce772017-03-13 16:40:45 +0000547 @Deprecated
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100548 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
549 = "android.app.extra.PROVISIONING_EMAIL_ADDRESS";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100550
551 /**
Nicolas Prevotcd2d8592015-11-23 13:27:21 +0000552 * A integer extra indicating the predominant color to show during the provisioning.
553 * Refer to {@link android.graphics.Color} for how the color is represented.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000554 *
555 * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or
556 * {@link #ACTION_PROVISION_MANAGED_DEVICE}.
557 */
558 public static final String EXTRA_PROVISIONING_MAIN_COLOR =
559 "android.app.extra.PROVISIONING_MAIN_COLOR";
560
561 /**
Sander Alewijnse8c411562014-11-12 18:03:11 +0000562 * A Boolean extra that can be used by the mobile device management application to skip the
Robin Lee25e26452015-06-02 09:56:29 -0700563 * disabling of system apps during provisioning when set to {@code true}.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000564 *
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100565 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
566 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000567 */
Sander Alewijnse5a144252014-11-18 13:25:04 +0000568 public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED =
569 "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED";
Sander Alewijnse8c411562014-11-12 18:03:11 +0000570
571 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100572 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
573 * will be set to.
574 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000575 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
576 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100577 */
578 public static final String EXTRA_PROVISIONING_TIME_ZONE
Esteban Talavera37f01842014-09-05 10:50:57 +0100579 = "android.app.extra.PROVISIONING_TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100580
581 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100582 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
583 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100584 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000585 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
586 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100587 */
588 public static final String EXTRA_PROVISIONING_LOCAL_TIME
Esteban Talavera37f01842014-09-05 10:50:57 +0100589 = "android.app.extra.PROVISIONING_LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100590
591 /**
592 * A String extra holding the {@link java.util.Locale} that the device will be set to.
593 * Format: xx_yy, where xx is the language code, and yy the country code.
594 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000595 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
596 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100597 */
598 public static final String EXTRA_PROVISIONING_LOCALE
Esteban Talavera37f01842014-09-05 10:50:57 +0100599 = "android.app.extra.PROVISIONING_LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100600
601 /**
602 * A String extra holding the ssid of the wifi network that should be used during nfc device
603 * owner provisioning for downloading the mobile device management application.
604 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000605 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
606 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100607 */
608 public static final String EXTRA_PROVISIONING_WIFI_SSID
Esteban Talavera37f01842014-09-05 10:50:57 +0100609 = "android.app.extra.PROVISIONING_WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100610
611 /**
612 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
613 * is hidden or not.
614 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000615 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
616 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100617 */
618 public static final String EXTRA_PROVISIONING_WIFI_HIDDEN
Esteban Talavera37f01842014-09-05 10:50:57 +0100619 = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100620
621 /**
622 * A String extra indicating the security type of the wifi network in
Mahaver Chopra76b08a92015-10-08 17:58:45 +0100623 * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or
624 * {@code WEP}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100625 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000626 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
627 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100628 */
629 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
Esteban Talavera37f01842014-09-05 10:50:57 +0100630 = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100631
632 /**
633 * A String extra holding the password of the wifi network in
634 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
635 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000636 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
637 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100638 */
639 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talavera37f01842014-09-05 10:50:57 +0100640 = "android.app.extra.PROVISIONING_WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100641
642 /**
643 * A String extra holding the proxy host for the wifi network in
644 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
645 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000646 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
647 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100648 */
649 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
Esteban Talavera37f01842014-09-05 10:50:57 +0100650 = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100651
652 /**
653 * An int extra holding the proxy port for the wifi network in
654 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
655 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000656 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
657 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100658 */
659 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
Esteban Talavera37f01842014-09-05 10:50:57 +0100660 = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100661
662 /**
663 * A String extra holding the proxy bypass for the wifi network in
664 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
665 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000666 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
667 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100668 */
669 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
Esteban Talavera37f01842014-09-05 10:50:57 +0100670 = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100671
672 /**
673 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
674 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
675 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000676 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
677 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100678 */
679 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
Esteban Talavera37f01842014-09-05 10:50:57 +0100680 = "android.app.extra.PROVISIONING_WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100681
682 /**
683 * A String extra holding a url that specifies the download location of the device admin
684 * package. When not provided it is assumed that the device admin package is already installed.
685 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000686 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
687 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100688 */
689 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talavera37f01842014-09-05 10:50:57 +0100690 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100691
692 /**
Victor Chang38cfd9c2017-01-04 17:41:11 +0000693 * A String extra holding the localized name of the organization under management.
694 *
695 * The name is displayed only during provisioning.
696 *
697 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE}
698 *
699 * @hide
700 */
701 @SystemApi
702 public static final String EXTRA_PROVISIONING_ORGANIZATION_NAME =
703 "android.app.extra.PROVISIONING_ORGANIZATION_NAME";
704
705 /**
Alejandro Fernándezbfd61932017-04-04 19:33:01 +0100706 * A String extra holding a url to the website of the device provider so the user can open it
707 * during provisioning. If the url is not HTTPS, an error will be shown.
Victor Chang38cfd9c2017-01-04 17:41:11 +0000708 *
709 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE}
710 *
711 * @hide
712 */
713 @SystemApi
714 public static final String EXTRA_PROVISIONING_SUPPORT_URL =
715 "android.app.extra.PROVISIONING_SUPPORT_URL";
716
717 /**
718 * A String extra holding the localized name of the device admin package. It should be the same
719 * as the app label of the package.
720 *
721 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE}
722 *
723 * @hide
724 */
725 @SystemApi
726 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL =
727 "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL";
728
729 /**
730 * A {@link Uri} extra pointing to the app icon of device admin package. This image will be
731 * shown during the provisioning.
732 * <h5>The following URI schemes are accepted:</h5>
733 * <ul>
734 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
735 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
736 * </ul>
737 *
738 * <p> It is the responsibility of the caller to provide an image with a reasonable
739 * pixel density for the device.
740 *
741 * <p> If a content: URI is passed, the intent should have the flag
742 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
743 * {@link android.content.ClipData} of the intent too.
744 *
745 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE}
746 *
747 * @hide
748 */
749 @SystemApi
750 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI =
751 "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI";
752
753 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400754 * An int extra holding a minimum required version code for the device admin package. If the
755 * device admin is already installed on the device, it will only be re-downloaded from
756 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the
757 * installed package is less than this version code.
758 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400759 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400760 * provisioning via an NFC bump.
761 */
762 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE
763 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE";
764
765 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100766 * A String extra holding a http cookie header which should be used in the http request to the
767 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
768 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000769 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
770 * provisioning via an NFC bump.
Sander Alewijnse681bce92014-07-24 16:46:26 +0100771 */
772 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talavera37f01842014-09-05 10:50:57 +0100773 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100774
775 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100776 * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of
777 * the file at download location specified in
778 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100779 *
Benjamin Franzea956242016-03-21 15:45:56 +0000780 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} must be
781 * present. The provided checksum must match the checksum of the file at the download
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100782 * location. If the checksum doesn't match an error will be shown to the user and the user will
783 * be asked to factory reset the device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100784 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000785 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
786 * provisioning via an NFC bump.
Rubin Xud92e7572015-05-18 17:01:13 +0100787 *
788 * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP}
789 * and {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1} only SHA-1 hash is supported.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700790 * Starting from {@link android.os.Build.VERSION_CODES#M}, this parameter accepts SHA-256 in
Rubin Xud92e7572015-05-18 17:01:13 +0100791 * addition to SHA-1. Support for SHA-1 is likely to be removed in future OS releases.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100792 */
793 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100794 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100795
796 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100797 * A String extra holding the URL-safe base64 encoded SHA-256 checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100798 * android package archive at the download location specified in {@link
799 * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
800 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100801 * <p>The signatures of an android package archive can be obtained using
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100802 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
803 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
804 *
Benjamin Franzea956242016-03-21 15:45:56 +0000805 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} must be
806 * present. The provided checksum must match the checksum of any signature of the file at
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100807 * the download location. If the checksum does not match an error will be shown to the user and
808 * the user will be asked to factory reset the device.
809 *
810 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
811 * provisioning via an NFC bump.
812 */
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100813 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM
814 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM";
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100815
816 /**
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000817 * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile
818 * has completed successfully.
819 *
820 * <p>The broadcast is limited to the primary profile, to the app specified in the provisioning
Nicolas Prevotebe2d992015-05-12 18:14:53 -0700821 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000822 *
Mahaver7074caf2016-11-29 20:52:18 +0000823 * <p>This intent will contain the following extras
824 * <ul>
825 * <li>{@link Intent#EXTRA_USER}, corresponds to the {@link UserHandle} of the managed
826 * profile.</li>
827 * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, corresponds to the account requested to
828 * be migrated at provisioning time, if any.</li>
829 * </ul>
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000830 */
831 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
832 public static final String ACTION_MANAGED_PROFILE_PROVISIONED
833 = "android.app.action.MANAGED_PROFILE_PROVISIONED";
834
835 /**
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000836 * Activity action: This activity action is sent to indicate that provisioning of a managed
837 * profile or managed device has completed successfully. It'll be sent at the same time as
838 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast but this will be
839 * delivered faster as it's an activity intent.
840 *
841 * <p>The intent is only sent to the application on the profile that requested provisioning. In
842 * the device owner case the profile is the primary user.
843 *
844 * @see #ACTION_PROVISION_MANAGED_PROFILE
845 * @see #ACTION_PROVISION_MANAGED_DEVICE
846 */
847 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
848 public static final String ACTION_PROVISIONING_SUCCESSFUL =
849 "android.app.action.PROVISIONING_SUCCESSFUL";
850
851 /**
Benjamin Franzea956242016-03-21 15:45:56 +0000852 * A boolean extra indicating whether device encryption can be skipped as part of device owner
853 * or managed profile provisioning.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500854 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400855 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100856 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Benjamin Franzea956242016-03-21 15:45:56 +0000857 *
858 * <p>From {@link android.os.Build.VERSION_CODES#N} onwards, this is also supported for an
859 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500860 */
861 public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION =
862 "android.app.extra.PROVISIONING_SKIP_ENCRYPTION";
863
864 /**
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000865 * A {@link Uri} extra pointing to a logo image. This image will be shown during the
866 * provisioning. If this extra is not passed, a default image will be shown.
867 * <h5>The following URI schemes are accepted:</h5>
868 * <ul>
869 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
870 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
871 * </ul>
872 *
Victor Changc10f6692016-12-09 15:24:00 +0000873 * <p> It is the responsibility of the caller to provide an image with a reasonable
Victor Chang38cfd9c2017-01-04 17:41:11 +0000874 * pixel density for the device.
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000875 *
876 * <p> If a content: URI is passed, the intent should have the flag
877 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
878 * {@link android.content.ClipData} of the intent too.
879 *
880 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or
881 * {@link #ACTION_PROVISION_MANAGED_DEVICE}
882 */
883 public static final String EXTRA_PROVISIONING_LOGO_URI =
884 "android.app.extra.PROVISIONING_LOGO_URI";
885
886 /**
Victor Changc10f6692016-12-09 15:24:00 +0000887 * A {@link Bundle}[] extra consisting of list of disclaimer headers and disclaimer contents.
888 * Each {@link Bundle} must have both {@link #EXTRA_PROVISIONING_DISCLAIMER_HEADER}
889 * as disclaimer header, and {@link #EXTRA_PROVISIONING_DISCLAIMER_CONTENT} as disclaimer
890 * content.
891 *
892 * <p> The extra typically contains one disclaimer from the company of mobile device
893 * management application (MDM), and one disclaimer from the organization.
894 *
895 * <p> Call {@link Bundle#putParcelableArray(String, Parcelable[])} to put the {@link Bundle}[]
896 *
897 * <p> Maximum 3 key-value pairs can be specified. The rest will be ignored.
898 *
899 * <p> Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or
900 * {@link #ACTION_PROVISION_MANAGED_DEVICE}
901 */
902 public static final String EXTRA_PROVISIONING_DISCLAIMERS =
903 "android.app.extra.PROVISIONING_DISCLAIMERS";
904
905 /**
906 * A String extra of localized disclaimer header.
907 *
908 * <p> The extra is typically the company name of mobile device management application (MDM)
909 * or the organization name.
910 *
911 * <p> Use in Bundle {@link #EXTRA_PROVISIONING_DISCLAIMERS}
Victor Chang98607132017-01-27 11:51:56 +0000912 *
913 * <p> System app, i.e. application with {@link ApplicationInfo#FLAG_SYSTEM}, can also insert a
914 * disclaimer by declaring an application-level meta-data in {@code AndroidManifest.xml}.
915 * Must use it with {@link #EXTRA_PROVISIONING_DISCLAIMER_CONTENT}. Here is the example:
916 *
917 * <pre>
918 * &lt;meta-data
919 * android:name="android.app.extra.PROVISIONING_DISCLAIMER_HEADER"
920 * android:resource="@string/disclaimer_header"
921 * /&gt;</pre>
Victor Changc10f6692016-12-09 15:24:00 +0000922 */
923 public static final String EXTRA_PROVISIONING_DISCLAIMER_HEADER =
924 "android.app.extra.PROVISIONING_DISCLAIMER_HEADER";
925
926 /**
927 * A {@link Uri} extra pointing to disclaimer content.
928 *
929 * <h5>The following URI schemes are accepted:</h5>
930 * <ul>
931 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
932 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
933 * </ul>
934 *
935 * <p> Styled text is supported in the disclaimer content. The content is parsed by
936 * {@link android.text.Html#fromHtml(String)} and displayed in a
937 * {@link android.widget.TextView}.
938 *
939 * <p> If a <code>content:</code> URI is passed, URI is passed, the intent should have the flag
940 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
941 * {@link android.content.ClipData} of the intent too.
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_HEADER}. Here is the example:
948 *
949 * <pre>
950 * &lt;meta-data
951 * android:name="android.app.extra.PROVISIONING_DISCLAIMER_CONTENT"
952 * android:resource="@string/disclaimer_content"
953 * /&gt;</pre>
Victor Changc10f6692016-12-09 15:24:00 +0000954 */
955 public static final String EXTRA_PROVISIONING_DISCLAIMER_CONTENT =
956 "android.app.extra.PROVISIONING_DISCLAIMER_CONTENT";
957
958 /**
Alan Treadway94de8c82016-01-11 10:25:23 +0000959 * A boolean extra indicating if user setup should be skipped, for when provisioning is started
960 * during setup-wizard.
961 *
962 * <p>If unspecified, defaults to {@code true} to match the behavior in
963 * {@link android.os.Build.VERSION_CODES#M} and earlier.
964 *
Alan Treadway1a538d02016-01-18 16:42:30 +0000965 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or
966 * {@link #ACTION_PROVISION_MANAGED_USER}.
Alan Treadway94de8c82016-01-11 10:25:23 +0000967 *
968 * @hide
969 */
970 public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP =
971 "android.app.extra.PROVISIONING_SKIP_USER_SETUP";
972
973 /**
Victor Chang51d84f92016-11-16 12:22:56 +0000974 * A boolean extra indicating if the user consent steps from the provisioning flow should be
975 * skipped. If unspecified, defaults to {@code false}.
976 *
977 * It can only be used by an existing device owner trying to create a managed profile via
978 * {@link #ACTION_PROVISION_MANAGED_PROFILE}. Otherwise it is ignored.
979 */
980 public static final String EXTRA_PROVISIONING_SKIP_USER_CONSENT =
981 "android.app.extra.PROVISIONING_SKIP_USER_CONSENT";
982
983 /**
Benjamin Franzea956242016-03-21 15:45:56 +0000984 * This MIME type is used for starting the device owner provisioning.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100985 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400986 * <p>During device owner provisioning a device admin app is set as the owner of the device.
987 * A device owner has full control over the device. The device owner can not be modified by the
988 * user and the only way of resetting the device is if the device owner app calls a factory
989 * reset.
990 *
991 * <p> A typical use case would be a device that is owned by a company, but used by either an
992 * employee or client.
993 *
Benjamin Franzea956242016-03-21 15:45:56 +0000994 * <p> The NFC message must be sent to an unprovisioned device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100995 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000996 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100997 * contains the following properties:
998 * <ul>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400999 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
1000 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +01001001 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -04001002 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +01001003 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
1004 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
1005 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
1006 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
1007 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
1008 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
1009 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
1010 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
1011 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
1012 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Rubin Xu41f2ccb92015-08-05 16:29:13 +01001013 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
1014 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from
1015 * {@link android.os.Build.VERSION_CODES#M} </li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +01001016 *
Nicolas Prevot18440252015-03-09 14:07:17 +00001017 * <p>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07001018 * As of {@link android.os.Build.VERSION_CODES#M}, the properties should contain
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -04001019 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of
1020 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only
1021 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -04001022 */
1023 public static final String MIME_TYPE_PROVISIONING_NFC
1024 = "application/com.android.managedprovisioning";
1025
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +01001026 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001027 * Activity action: ask the user to add a new device administrator to the system.
1028 * The desired policy is the ComponentName of the policy in the
1029 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
1030 * bring the user through adding the device administrator to the system (or
1031 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001032 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001033 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
1034 * field to provide the user with additional explanation (in addition
1035 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001036 *
1037 * <p>If your administrator is already active, this will ordinarily return immediately (without
1038 * user intervention). However, if your administrator has been updated and is requesting
1039 * additional uses-policy flags, the user will be presented with the new list. New policies
1040 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001041 */
1042 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1043 public static final String ACTION_ADD_DEVICE_ADMIN
1044 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001045
Dianne Hackbornd6847842010-01-12 18:14:19 -08001046 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001047 * @hide
1048 * Activity action: ask the user to add a new device administrator as the profile owner
Amith Yamasani814e9872015-03-23 14:04:53 -07001049 * for this user. Only system apps can launch this intent.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001050 *
Amith Yamasani814e9872015-03-23 14:04:53 -07001051 * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN}
1052 * extra field. This will invoke a UI to bring the user through adding the profile owner admin
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001053 * to remotely control restrictions on the user.
1054 *
Makoto Onukic8a5a552015-11-19 14:29:12 -08001055 * <p>The intent must be invoked via {@link Activity#startActivityForResult} to receive the
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001056 * result of whether or not the user approved the action. If approved, the result will
1057 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
1058 * as a profile owner.
1059 *
1060 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
1061 * field to provide the user with additional explanation (in addition
1062 * to your component's description) about what is being added.
1063 *
Amith Yamasani814e9872015-03-23 14:04:53 -07001064 * <p>If there is already a profile owner active or the caller is not a system app, the
1065 * operation will return a failure result.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001066 */
1067 @SystemApi
1068 public static final String ACTION_SET_PROFILE_OWNER
1069 = "android.app.action.SET_PROFILE_OWNER";
1070
1071 /**
1072 * @hide
1073 * Name of the profile owner admin that controls the user.
1074 */
1075 @SystemApi
1076 public static final String EXTRA_PROFILE_OWNER_NAME
1077 = "android.app.extra.PROFILE_OWNER_NAME";
1078
1079 /**
Nicolas Prevot00799002015-07-27 18:15:20 +01001080 * Broadcast action: send when any policy admin changes a policy.
Jim Miller284b62e2010-06-08 14:27:42 -07001081 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -07001082 *
Jim Miller284b62e2010-06-08 14:27:42 -07001083 * @hide
1084 */
1085 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
1086 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
1087
1088 /**
Tony Mak1970f972016-08-30 17:41:48 +01001089 * Broadcast action: sent when the device owner is set, changed or cleared.
Nicolas Prevot00799002015-07-27 18:15:20 +01001090 *
1091 * This broadcast is sent only to the primary user.
1092 * @see #ACTION_PROVISION_MANAGED_DEVICE
1093 */
1094 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1095 public static final String ACTION_DEVICE_OWNER_CHANGED
1096 = "android.app.action.DEVICE_OWNER_CHANGED";
1097
1098 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001099 * The ComponentName of the administrator component.
1100 *
1101 * @see #ACTION_ADD_DEVICE_ADMIN
1102 */
1103 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001104
Dianne Hackbornd6847842010-01-12 18:14:19 -08001105 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001106 * An optional CharSequence providing additional explanation for why the
1107 * admin is being added.
1108 *
1109 * @see #ACTION_ADD_DEVICE_ADMIN
1110 */
1111 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001112
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001113 /**
phweiss73145f42017-01-17 19:06:38 +01001114 * Constant to indicate the feature of disabling the camera. Used as argument to
1115 * {@link #createAdminSupportIntent(String)}.
1116 * @see #setCameraDisabled(ComponentName, boolean)
1117 */
1118 public static final String POLICY_DISABLE_CAMERA = "policy_disable_camera";
1119
1120 /**
1121 * Constant to indicate the feature of disabling screen captures. Used as argument to
1122 * {@link #createAdminSupportIntent(String)}.
1123 * @see #setScreenCaptureDisabled(ComponentName, boolean)
1124 */
1125 public static final String POLICY_DISABLE_SCREEN_CAPTURE = "policy_disable_screen_capture";
1126
1127 /**
1128 * A String indicating a specific restricted feature. Can be a user restriction from the
1129 * {@link UserManager}, e.g. {@link UserManager#DISALLOW_ADJUST_VOLUME}, or one of the values
1130 * {@link #POLICY_DISABLE_CAMERA} or {@link #POLICY_DISABLE_SCREEN_CAPTURE}.
1131 * @see #createAdminSupportIntent(String)
1132 * @hide
1133 */
1134 @TestApi
1135 public static final String EXTRA_RESTRICTION = "android.app.extra.RESTRICTION";
1136
1137 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001138 * Activity action: have the user enter a new password. This activity should
1139 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
1140 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
1141 * enter a new password that meets the current requirements. You can use
1142 * {@link #isActivePasswordSufficient()} to determine whether you need to
1143 * have the user select a new password in order to meet the current
1144 * constraints. Upon being resumed from this activity, you can check the new
1145 * password characteristics to see if they are sufficient.
Benjamin Franzc9921092016-01-08 17:17:44 +00001146 *
1147 * If the intent is launched from within a managed profile with a profile
1148 * owner built against {@link android.os.Build.VERSION_CODES#M} or before,
1149 * this will trigger entering a new password for the parent of the profile.
1150 * For all other cases it will trigger entering a new password for the user
1151 * or profile it is launched from.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001152 *
1153 * @see #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
Dianne Hackbornd6847842010-01-12 18:14:19 -08001154 */
1155 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1156 public static final String ACTION_SET_NEW_PASSWORD
1157 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001158
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001159 /**
Benjamin Franzc9921092016-01-08 17:17:44 +00001160 * Activity action: have the user enter a new password for the parent profile.
1161 * If the intent is launched from within a managed profile, this will trigger
1162 * entering a new password for the parent of the profile. In all other cases
1163 * the behaviour is identical to {@link #ACTION_SET_NEW_PASSWORD}.
1164 */
1165 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1166 public static final String ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
1167 = "android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD";
1168
1169 /**
phweissa0cb2512016-12-14 21:37:48 +01001170 * Broadcast action: Tell the status bar to open the device monitoring dialog, e.g. when
1171 * Network logging was enabled and the user tapped the notification.
1172 * <p class="note">This is a protected intent that can only be sent by the system.</p>
1173 * @hide
1174 */
1175 public static final String ACTION_SHOW_DEVICE_MONITORING_DIALOG
1176 = "android.app.action.SHOW_DEVICE_MONITORING_DIALOG";
1177
1178 /**
Edman Anjos9e62c312017-01-26 22:22:58 +01001179 * Broadcast Action: Sent after application delegation scopes are changed. The new delegation
1180 * scopes will be sent in an {@code ArrayList<String>} extra identified by the
1181 * {@link #EXTRA_DELEGATION_SCOPES} key.
Edman Anjosf9946772016-11-28 16:35:15 +01001182 *
1183 * <p class=”note”> Note: This is a protected intent that can only be sent by the system.</p>
1184 */
1185 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1186 public static final String ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED =
1187 "android.app.action.APPLICATION_DELEGATION_SCOPES_CHANGED";
1188
1189 /**
Edman Anjos9e62c312017-01-26 22:22:58 +01001190 * An {@code ArrayList<String>} corresponding to the delegation scopes given to an app in the
Edman Anjosf9946772016-11-28 16:35:15 +01001191 * {@link #ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED} broadcast.
1192 */
1193 public static final String EXTRA_DELEGATION_SCOPES = "android.app.extra.DELEGATION_SCOPES";
1194
1195 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +00001196 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
1197 * the parent profile to access intents sent from the managed profile.
1198 * That is, when an app in the managed profile calls
1199 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
1200 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001201 */
Nicolas Prevot86a96732014-09-08 12:13:05 +01001202 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001203
1204 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +00001205 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
1206 * the managed profile to access intents sent from the parent profile.
1207 * That is, when an app in the parent profile calls
1208 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
1209 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001210 */
Nicolas Prevot86a96732014-09-08 12:13:05 +01001211 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001212
Dianne Hackbornd6847842010-01-12 18:14:19 -08001213 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01001214 * Broadcast action: notify that a new local system update policy has been set by the device
1215 * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00001216 */
1217 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Rubin Xu5faad8e2015-04-20 17:43:48 +01001218 public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED
1219 = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED";
Rubin Xu8027a4f2015-03-10 17:52:37 +00001220
Amith Yamasanid49489b2015-04-28 14:00:26 -07001221 /**
1222 * Permission policy to prompt user for new permission requests for runtime permissions.
1223 * Already granted or denied permissions are not affected by this.
1224 */
1225 public static final int PERMISSION_POLICY_PROMPT = 0;
1226
1227 /**
1228 * Permission policy to always grant new permission requests for runtime permissions.
1229 * Already granted or denied permissions are not affected by this.
1230 */
1231 public static final int PERMISSION_POLICY_AUTO_GRANT = 1;
1232
1233 /**
1234 * Permission policy to always deny new permission requests for runtime permissions.
1235 * Already granted or denied permissions are not affected by this.
1236 */
1237 public static final int PERMISSION_POLICY_AUTO_DENY = 2;
1238
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07001239 /**
1240 * Runtime permission state: The user can manage the permission
1241 * through the UI.
1242 */
1243 public static final int PERMISSION_GRANT_STATE_DEFAULT = 0;
1244
1245 /**
1246 * Runtime permission state: The permission is granted to the app
1247 * and the user cannot manage the permission through the UI.
1248 */
1249 public static final int PERMISSION_GRANT_STATE_GRANTED = 1;
1250
1251 /**
1252 * Runtime permission state: The permission is denied to the app
1253 * and the user cannot manage the permission through the UI.
1254 */
1255 public static final int PERMISSION_GRANT_STATE_DENIED = 2;
Rubin Xu8027a4f2015-03-10 17:52:37 +00001256
1257 /**
Edman Anjosf9946772016-11-28 16:35:15 +01001258 * Delegation of certificate installation and management. This scope grants access to the
1259 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
1260 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair} APIs.
1261 */
1262 public static final String DELEGATION_CERT_INSTALL = "delegation-cert-install";
1263
1264 /**
1265 * Delegation of application restrictions management. This scope grants access to the
1266 * {@link #setApplicationRestrictions} and {@link #getApplicationRestrictions} APIs.
1267 */
1268 public static final String DELEGATION_APP_RESTRICTIONS = "delegation-app-restrictions";
1269
1270 /**
Edman Anjosa5f2fb12016-12-19 11:25:54 -08001271 * Delegation of application uninstall block. This scope grants access to the
1272 * {@link #setUninstallBlocked} API.
1273 */
1274 public static final String DELEGATION_BLOCK_UNINSTALL = "delegation-block-uninstall";
1275
1276 /**
Edman Anjos52088e42017-01-13 22:26:17 +01001277 * Delegation of permission policy and permission grant state. This scope grants access to the
1278 * {@link #setPermissionPolicy}, {@link #getPermissionGrantState},
1279 * and {@link #setPermissionGrantState} APIs.
1280 */
1281 public static final String DELEGATION_PERMISSION_GRANT = "delegation-permission-grant";
1282
1283 /**
1284 * Delegation of package access state. This scope grants access to the
1285 * {@link #isApplicationHidden}, {@link #setApplicationHidden}, {@link #isPackageSuspended}, and
1286 * {@link #setPackagesSuspended} APIs.
1287 */
1288 public static final String DELEGATION_PACKAGE_ACCESS = "delegation-package-access";
1289
1290 /**
1291 * Delegation for enabling system apps. This scope grants access to the {@link #enableSystemApp}
1292 * API.
1293 */
1294 public static final String DELEGATION_ENABLE_SYSTEM_APP = "delegation-enable-system-app";
1295
1296 /**
1297 * Delegation of management of uninstalled packages. This scope grants access to the
1298 * {@code #setKeepUninstalledPackages} and {@code #getKeepUninstalledPackages} APIs.
1299 * @hide
1300 */
1301 public static final String DELEGATION_KEEP_UNINSTALLED_PACKAGES =
1302 "delegation-keep-uninstalled-packages";
1303
1304 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00001305 * No management for current user in-effect. This is the default.
1306 * @hide
1307 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001308 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001309 public static final int STATE_USER_UNMANAGED = 0;
1310
1311 /**
1312 * Management partially setup, user setup needs to be completed.
1313 * @hide
1314 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001315 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001316 public static final int STATE_USER_SETUP_INCOMPLETE = 1;
1317
1318 /**
1319 * Management partially setup, user setup completed.
1320 * @hide
1321 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001322 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001323 public static final int STATE_USER_SETUP_COMPLETE = 2;
1324
1325 /**
1326 * Management setup and active on current user.
1327 * @hide
1328 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001329 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001330 public static final int STATE_USER_SETUP_FINALIZED = 3;
1331
1332 /**
1333 * Management partially setup on a managed profile.
1334 * @hide
1335 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001336 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001337 public static final int STATE_USER_PROFILE_COMPLETE = 4;
1338
1339 /**
1340 * @hide
1341 */
1342 @IntDef({STATE_USER_UNMANAGED, STATE_USER_SETUP_INCOMPLETE, STATE_USER_SETUP_COMPLETE,
1343 STATE_USER_SETUP_FINALIZED, STATE_USER_PROFILE_COMPLETE})
1344 @Retention(RetentionPolicy.SOURCE)
1345 public @interface UserProvisioningState {}
1346
1347 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001348 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001349 *
1350 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1351 * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and
1352 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when provisioning is allowed.
1353 *
1354 * @hide
1355 */
1356 public static final int CODE_OK = 0;
1357
1358 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001359 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001360 *
1361 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and
1362 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the device already has a device
1363 * owner.
1364 *
1365 * @hide
1366 */
1367 public static final int CODE_HAS_DEVICE_OWNER = 1;
1368
1369 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001370 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001371 *
1372 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1373 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user has a profile owner and for
1374 * {@link #ACTION_PROVISION_MANAGED_PROFILE} when the profile owner is already set.
1375 *
1376 * @hide
1377 */
1378 public static final int CODE_USER_HAS_PROFILE_OWNER = 2;
1379
1380 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001381 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001382 *
1383 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and
1384 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user isn't running.
1385 *
1386 * @hide
1387 */
1388 public static final int CODE_USER_NOT_RUNNING = 3;
1389
1390 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001391 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001392 *
1393 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1394 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the device has already been setup and
1395 * for {@link #ACTION_PROVISION_MANAGED_USER} if the user has already been setup.
1396 *
1397 * @hide
1398 */
1399 public static final int CODE_USER_SETUP_COMPLETED = 4;
1400
1401 /**
1402 * Code used to indicate that the device also has a user other than the system user.
1403 *
1404 * @hide
1405 */
1406 public static final int CODE_NONSYSTEM_USER_EXISTS = 5;
1407
1408 /**
1409 * Code used to indicate that device has an account that prevents provisioning.
1410 *
1411 * @hide
1412 */
1413 public static final int CODE_ACCOUNTS_NOT_EMPTY = 6;
1414
1415 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001416 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001417 *
1418 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and
1419 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the user is not a system user.
1420 *
1421 * @hide
1422 */
1423 public static final int CODE_NOT_SYSTEM_USER = 7;
1424
1425 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001426 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001427 *
1428 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1429 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} and {@link #ACTION_PROVISION_MANAGED_USER}
1430 * when the device is a watch and is already paired.
1431 *
1432 * @hide
1433 */
1434 public static final int CODE_HAS_PAIRED = 8;
1435
1436 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001437 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001438 *
1439 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} and
1440 * {@link #ACTION_PROVISION_MANAGED_USER} on devices which do not support managed users.
1441 *
1442 * @see {@link PackageManager#FEATURE_MANAGED_USERS}
1443 * @hide
1444 */
1445 public static final int CODE_MANAGED_USERS_NOT_SUPPORTED = 9;
1446
1447 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001448 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001449 *
1450 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} if the user is a system user.
1451 *
1452 * @hide
1453 */
1454 public static final int CODE_SYSTEM_USER = 10;
1455
1456 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001457 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001458 *
1459 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when the user cannot have more
1460 * managed profiles.
1461 *
1462 * @hide
1463 */
1464 public static final int CODE_CANNOT_ADD_MANAGED_PROFILE = 11;
1465
1466 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001467 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001468 *
1469 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} and
1470 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices not running with split system
1471 * user.
1472 *
1473 * @hide
1474 */
1475 public static final int CODE_NOT_SYSTEM_USER_SPLIT = 12;
1476
1477 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001478 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001479 *
1480 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1481 * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and
1482 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices which do no support device
1483 * admins.
1484 *
1485 * @hide
1486 */
1487 public static final int CODE_DEVICE_ADMIN_NOT_SUPPORTED = 13;
1488
1489 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001490 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001491 *
Esteban Talavera6c9116a2016-11-24 16:12:44 +00001492 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when the device the user is a
1493 * system user on a split system user device.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001494 *
1495 * @hide
1496 */
1497 public static final int CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER = 14;
1498
1499 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001500 * Result code for {@link #checkProvisioningPreCondition}.
1501 *
1502 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when adding a managed profile is
1503 * disallowed by {@link UserManager#DISALLOW_ADD_MANAGED_PROFILE}.
1504 *
1505 * @hide
1506 */
1507 public static final int CODE_ADD_MANAGED_PROFILE_DISALLOWED = 15;
1508
1509 /**
1510 * Result codes for {@link #checkProvisioningPreCondition} indicating all the provisioning pre
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001511 * conditions.
1512 *
1513 * @hide
1514 */
1515 @Retention(RetentionPolicy.SOURCE)
1516 @IntDef({CODE_OK, CODE_HAS_DEVICE_OWNER, CODE_USER_HAS_PROFILE_OWNER, CODE_USER_NOT_RUNNING,
1517 CODE_USER_SETUP_COMPLETED, CODE_NOT_SYSTEM_USER, CODE_HAS_PAIRED,
1518 CODE_MANAGED_USERS_NOT_SUPPORTED, CODE_SYSTEM_USER, CODE_CANNOT_ADD_MANAGED_PROFILE,
1519 CODE_NOT_SYSTEM_USER_SPLIT, CODE_DEVICE_ADMIN_NOT_SUPPORTED,
Esteban Talavera01576862016-12-15 11:16:44 +00001520 CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER, CODE_ADD_MANAGED_PROFILE_DISALLOWED})
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001521 public @interface ProvisioningPreCondition {}
1522
1523 /**
Makoto Onukifc73d792017-03-22 14:22:35 -07001524 * Service action: Action for a service that device owner and profile owner can optionally
1525 * own. If a device owner or a profile owner has such a service, the system tries to keep
1526 * a bound connection to it, in order to keep their process always running.
Makoto Onukife739702017-04-25 13:26:21 -07001527 * The service must be protected with the {@link android.Manifest.permission#BIND_DEVICE_ADMIN}
1528 * permission.
Makoto Onukifc73d792017-03-22 14:22:35 -07001529 */
1530 @SdkConstant(SdkConstantType.SERVICE_ACTION)
1531 public static final String ACTION_DEVICE_ADMIN_SERVICE
1532 = "android.app.action.DEVICE_ADMIN_SERVICE";
1533
1534 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001535 * Return true if the given administrator component is currently active (enabled) in the system.
1536 *
1537 * @param admin The administrator component to check for.
1538 * @return {@code true} if {@code admin} is currently enabled in the system, {@code false}
1539 * otherwise
Dianne Hackbornd6847842010-01-12 18:14:19 -08001540 */
Robin Lee25e26452015-06-02 09:56:29 -07001541 public boolean isAdminActive(@NonNull ComponentName admin) {
Charles He8c760562016-10-25 16:36:53 +01001542 throwIfParentInstance("isAdminActive");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001543 return isAdminActiveAsUser(admin, myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001544 }
1545
1546 /**
1547 * @see #isAdminActive(ComponentName)
1548 * @hide
1549 */
Robin Lee25e26452015-06-02 09:56:29 -07001550 public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001551 if (mService != null) {
1552 try {
Robin Lee25e26452015-06-02 09:56:29 -07001553 return mService.isAdminActive(admin, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001554 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001555 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001556 }
1557 }
1558 return false;
1559 }
Charles Hedea0c3b2017-01-13 10:04:12 +00001560
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001561 /**
1562 * Return true if the given administrator component is currently being removed
1563 * for the user.
1564 * @hide
1565 */
Robin Lee25e26452015-06-02 09:56:29 -07001566 public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) {
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001567 if (mService != null) {
1568 try {
Robin Lee25e26452015-06-02 09:56:29 -07001569 return mService.isRemovingAdmin(admin, userId);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001570 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001571 throw e.rethrowFromSystemServer();
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001572 }
1573 }
1574 return false;
1575 }
1576
Dianne Hackbornd6847842010-01-12 18:14:19 -08001577 /**
Robin Lee25e26452015-06-02 09:56:29 -07001578 * Return a list of all currently active device administrators' component
1579 * names. If there are no administrators {@code null} may be
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001580 * returned.
1581 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07001582 public @Nullable List<ComponentName> getActiveAdmins() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001583 throwIfParentInstance("getActiveAdmins");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001584 return getActiveAdminsAsUser(myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001585 }
1586
1587 /**
1588 * @see #getActiveAdmins()
1589 * @hide
1590 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07001591 public @Nullable List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001592 if (mService != null) {
1593 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001594 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001595 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001596 throw e.rethrowFromSystemServer();
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001597 }
1598 }
1599 return null;
1600 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001601
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001602 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001603 * Used by package administration code to determine if a package can be stopped
1604 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001605 * @hide
1606 */
David Ouyang3a83a332017-01-11 16:36:40 -08001607 @SystemApi
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001608 public boolean packageHasActiveAdmins(String packageName) {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001609 return packageHasActiveAdmins(packageName, myUserId());
1610 }
1611
1612 /**
1613 * Used by package administration code to determine if a package can be stopped
1614 * or uninstalled.
1615 * @hide
1616 */
1617 public boolean packageHasActiveAdmins(String packageName, int userId) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001618 if (mService != null) {
1619 try {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001620 return mService.packageHasActiveAdmins(packageName, userId);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001621 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001622 throw e.rethrowFromSystemServer();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001623 }
1624 }
1625 return false;
1626 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001627
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001628 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001629 * Remove a current administration component. This can only be called
1630 * by the application that owns the administration component; if you
1631 * try to remove someone else's component, a security exception will be
1632 * thrown.
Esteban Talavera552a5612016-02-19 17:02:24 +00001633 *
1634 * <p>Note that the operation is not synchronous and the admin might still be active (as
1635 * indicated by {@link #getActiveAdmins()}) by the time this method returns.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001636 *
1637 * @param admin The administration compononent to remove.
1638 * @throws SecurityException if the caller is not in the owner application of {@code admin}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001639 */
Robin Lee25e26452015-06-02 09:56:29 -07001640 public void removeActiveAdmin(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001641 throwIfParentInstance("removeActiveAdmin");
Dianne Hackbornd6847842010-01-12 18:14:19 -08001642 if (mService != null) {
1643 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001644 mService.removeActiveAdmin(admin, myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001645 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001646 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001647 }
1648 }
1649 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001650
Dianne Hackbornd6847842010-01-12 18:14:19 -08001651 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001652 * Returns true if an administrator has been granted a particular device policy. This can be
1653 * used to check whether the administrator was activated under an earlier set of policies, but
1654 * requires additional policies after an upgrade.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001655 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001656 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be an
1657 * active administrator, or an exception will be thrown.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001658 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001659 * @throws SecurityException if {@code admin} is not an active administrator.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001660 */
Robin Lee25e26452015-06-02 09:56:29 -07001661 public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001662 throwIfParentInstance("hasGrantedPolicy");
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001663 if (mService != null) {
1664 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001665 return mService.hasGrantedPolicy(admin, usesPolicy, myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001666 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001667 throw e.rethrowFromSystemServer();
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001668 }
1669 }
1670 return false;
1671 }
1672
1673 /**
Clara Bayarria1771112015-12-18 16:29:18 +00001674 * Returns true if the Profile Challenge is available to use for the given profile user.
1675 *
1676 * @hide
1677 */
1678 public boolean isSeparateProfileChallengeAllowed(int userHandle) {
1679 if (mService != null) {
1680 try {
1681 return mService.isSeparateProfileChallengeAllowed(userHandle);
1682 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001683 throw e.rethrowFromSystemServer();
Clara Bayarria1771112015-12-18 16:29:18 +00001684 }
1685 }
1686 return false;
1687 }
1688
1689 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001690 * Constant for {@link #setPasswordQuality}: the policy has no requirements
1691 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001692 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001693 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001694 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001695
Dianne Hackbornd6847842010-01-12 18:14:19 -08001696 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -07001697 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
1698 * recognition technology. This implies technologies that can recognize the identity of
1699 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
1700 * Note that quality constants are ordered so that higher values are more restrictive.
1701 */
1702 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
1703
1704 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001705 * Constant for {@link #setPasswordQuality}: the policy requires some kind
Benjamin Franzc6a96532015-06-16 11:23:38 +01001706 * of password or pattern, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001707 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001708 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001709 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001710
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001711 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001712 * Constant for {@link #setPasswordQuality}: the user must have entered a
1713 * password containing at least numeric characters. Note that quality
1714 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001715 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001716 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001717
Dianne Hackbornd6847842010-01-12 18:14:19 -08001718 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001719 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -08001720 * password containing at least numeric characters with no repeating (4444)
1721 * or ordered (1234, 4321, 2468) sequences. Note that quality
1722 * constants are ordered so that higher values are more restrictive.
1723 */
1724 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
1725
1726 /**
1727 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001728 * password containing at least alphabetic (or other symbol) characters.
1729 * Note that quality constants are ordered so that higher values are more
1730 * restrictive.
1731 */
1732 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001733
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001734 /**
1735 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001736 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001737 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001738 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001739 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001740 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001741
Dianne Hackbornd6847842010-01-12 18:14:19 -08001742 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001743 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001744 * password containing at least a letter, a numerical digit and a special
1745 * symbol, by default. With this password quality, passwords can be
1746 * restricted to contain various sets of characters, like at least an
1747 * uppercase letter, etc. These are specified using various methods,
1748 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
1749 * that quality constants are ordered so that higher values are more
1750 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001751 */
1752 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
1753
1754 /**
Oleksandr Peletskyi0fdcd3d2016-01-13 16:49:56 +01001755 * Constant for {@link #setPasswordQuality}: the user is not allowed to
1756 * modify password. In case this password quality is set, the password is
1757 * managed by a profile owner. The profile owner can set any password,
1758 * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note
1759 * that quality constants are ordered so that higher values are more
1760 * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is
1761 * the highest.
1762 * @hide
1763 */
1764 public static final int PASSWORD_QUALITY_MANAGED = 0x80000;
1765
1766 /**
Makoto Onuki5e7e06702016-09-01 18:02:01 -07001767 * @hide
1768 *
1769 * adb shell dpm set-{device,profile}-owner will normally not allow installing an owner to
1770 * a user with accounts. {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED}
1771 * and {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} are the account features
1772 * used by authenticator to exempt their accounts from this:
1773 *
1774 * <ul>
1775 * <li>Non-test-only DO/PO still can't be installed when there are accounts.
1776 * <p>In order to make an apk test-only, add android:testOnly="true" to the
1777 * &lt;application&gt; tag in the manifest.
1778 *
1779 * <li>Test-only DO/PO can be installed even when there are accounts, as long as all the
1780 * accounts have the {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} feature.
1781 * Some authenticators claim to have any features, so to detect it, we also check
1782 * {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} and disallow installing
1783 * if any of the accounts have it.
1784 * </ul>
1785 */
Makoto Onuki47c203d2017-02-13 16:21:19 -08001786 @SystemApi
1787 @TestApi
Makoto Onuki5e7e06702016-09-01 18:02:01 -07001788 public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED =
1789 "android.account.DEVICE_OR_PROFILE_OWNER_ALLOWED";
1790
1791 /** @hide See {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} */
Makoto Onuki47c203d2017-02-13 16:21:19 -08001792 @SystemApi
1793 @TestApi
Makoto Onuki5e7e06702016-09-01 18:02:01 -07001794 public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED =
1795 "android.account.DEVICE_OR_PROFILE_OWNER_DISALLOWED";
1796
1797 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001798 * Called by an application that is administering the device to set the password restrictions it
1799 * is imposing. After setting this, the user will not be able to enter a new password that is
1800 * not at least as restrictive as what has been set. Note that the current password will remain
1801 * until the user has set a new one, so the change does not take place immediately. To prompt
1802 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
Esteban Talaverac1c83592016-02-17 17:56:15 +00001803 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after calling this method.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001804 * <p>
1805 * Quality constants are ordered so that higher values are more restrictive; thus the highest
1806 * requested quality constant (between the policy set here, the user's preference, and any other
1807 * considerations) is the one that is in effect.
1808 * <p>
1809 * The calling device admin must have requested
1810 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1811 * not, a security exception will be thrown.
1812 * <p>
1813 * This method can be called on the {@link DevicePolicyManager} instance returned by
1814 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1815 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001816 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001817 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001818 * @param quality The new desired quality. One of {@link #PASSWORD_QUALITY_UNSPECIFIED},
1819 * {@link #PASSWORD_QUALITY_SOMETHING}, {@link #PASSWORD_QUALITY_NUMERIC},
1820 * {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC},
1821 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} or {@link #PASSWORD_QUALITY_COMPLEX}.
1822 * @throws SecurityException if {@code admin} is not an active administrator or if {@code admin}
1823 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Dianne Hackbornd6847842010-01-12 18:14:19 -08001824 */
Robin Lee25e26452015-06-02 09:56:29 -07001825 public void setPasswordQuality(@NonNull ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001826 if (mService != null) {
1827 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001828 mService.setPasswordQuality(admin, quality, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001829 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001830 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001831 }
1832 }
1833 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001834
Dianne Hackbornd6847842010-01-12 18:14:19 -08001835 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001836 * Retrieve the current minimum password quality for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01001837 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00001838 * a separate challenge are not taken into account.
1839 *
1840 * <p>This method can be called on the {@link DevicePolicyManager} instance
1841 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1842 * restrictions on the parent profile.
1843 *
Robin Lee25e26452015-06-02 09:56:29 -07001844 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001845 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001846 */
Robin Lee25e26452015-06-02 09:56:29 -07001847 public int getPasswordQuality(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001848 return getPasswordQuality(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001849 }
1850
1851 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001852 public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001853 if (mService != null) {
1854 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001855 return mService.getPasswordQuality(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001856 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001857 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001858 }
1859 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001860 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001861 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001862
Dianne Hackbornd6847842010-01-12 18:14:19 -08001863 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001864 * Called by an application that is administering the device to set the minimum allowed password
1865 * length. After setting this, the user will not be able to enter a new password that is not at
1866 * least as restrictive as what has been set. Note that the current password will remain until
1867 * the user has set a new one, so the change does not take place immediately. To prompt the user
1868 * for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
1869 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
1870 * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC}
1871 * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC},
1872 * {@link #PASSWORD_QUALITY_ALPHANUMERIC}, or {@link #PASSWORD_QUALITY_COMPLEX} with
1873 * {@link #setPasswordQuality}.
1874 * <p>
1875 * The calling device admin must have requested
1876 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1877 * not, a security exception will be thrown.
1878 * <p>
1879 * This method can be called on the {@link DevicePolicyManager} instance returned by
1880 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1881 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001882 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001883 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001884 * @param length The new desired minimum password length. A value of 0 means there is no
1885 * restriction.
1886 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1887 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Dianne Hackbornd6847842010-01-12 18:14:19 -08001888 */
Robin Lee25e26452015-06-02 09:56:29 -07001889 public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001890 if (mService != null) {
1891 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001892 mService.setPasswordMinimumLength(admin, length, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001893 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001894 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001895 }
1896 }
1897 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001898
Dianne Hackbornd6847842010-01-12 18:14:19 -08001899 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001900 * Retrieve the current minimum password length for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01001901 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00001902 * a separate challenge are not taken into account.
1903 *
1904 * <p>This method can be called on the {@link DevicePolicyManager} instance
1905 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1906 * restrictions on the parent profile.
1907 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001908 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001909 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001910 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001911 */
Robin Lee25e26452015-06-02 09:56:29 -07001912 public int getPasswordMinimumLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001913 return getPasswordMinimumLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001914 }
1915
1916 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001917 public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001918 if (mService != null) {
1919 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001920 return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001921 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001922 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001923 }
1924 }
1925 return 0;
1926 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001927
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001928 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001929 * Called by an application that is administering the device to set the minimum number of upper
1930 * case letters required in the password. After setting this, the user will not be able to enter
1931 * a new password that is not at least as restrictive as what has been set. Note that the
1932 * current password will remain until the user has set a new one, so the change does not take
1933 * place immediately. To prompt the user for a new password, use
1934 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
1935 * setting this value. This constraint is only imposed if the administrator has also requested
1936 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001937 * <p>
1938 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001939 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1940 * not, a security exception will be thrown.
1941 * <p>
1942 * This method can be called on the {@link DevicePolicyManager} instance returned by
1943 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1944 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001945 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001946 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1947 * @param length The new desired minimum number of upper case letters required in the password.
1948 * A value of 0 means there is no restriction.
1949 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1950 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001951 */
Robin Lee25e26452015-06-02 09:56:29 -07001952 public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001953 if (mService != null) {
1954 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001955 mService.setPasswordMinimumUpperCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001956 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001957 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001958 }
1959 }
1960 }
1961
1962 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001963 * Retrieve the current number of upper case letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01001964 * for a particular admin or all admins that set restrictions on this user and
Esteban Talaverac1c83592016-02-17 17:56:15 +00001965 * its participating profiles. Restrictions on profiles that have a separate challenge
1966 * are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001967 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001968 * {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001969 * and only applies when the password quality is
1970 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001971 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001972 * <p>This method can be called on the {@link DevicePolicyManager} instance
1973 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1974 * restrictions on the parent profile.
1975 *
Robin Lee25e26452015-06-02 09:56:29 -07001976 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001977 * aggregate all admins.
1978 * @return The minimum number of upper case letters required in the
1979 * password.
1980 */
Robin Lee25e26452015-06-02 09:56:29 -07001981 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001982 return getPasswordMinimumUpperCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001983 }
1984
1985 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001986 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001987 if (mService != null) {
1988 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001989 return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001990 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001991 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001992 }
1993 }
1994 return 0;
1995 }
1996
1997 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001998 * Called by an application that is administering the device to set the minimum number of lower
1999 * case letters required in the password. After setting this, the user will not be able to enter
2000 * a new password that is not at least as restrictive as what has been set. Note that the
2001 * current password will remain until the user has set a new one, so the change does not take
2002 * place immediately. To prompt the user for a new password, use
2003 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
2004 * setting this value. This constraint is only imposed if the administrator has also requested
2005 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002006 * <p>
2007 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002008 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2009 * not, a security exception will be thrown.
2010 * <p>
2011 * This method can be called on the {@link DevicePolicyManager} instance returned by
2012 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2013 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002014 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002015 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2016 * @param length The new desired minimum number of lower case letters required in the password.
2017 * A value of 0 means there is no restriction.
2018 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2019 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002020 */
Robin Lee25e26452015-06-02 09:56:29 -07002021 public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002022 if (mService != null) {
2023 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002024 mService.setPasswordMinimumLowerCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002025 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002026 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002027 }
2028 }
2029 }
2030
2031 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002032 * Retrieve the current number of lower case letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002033 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002034 * and its participating profiles. Restrictions on profiles that have
2035 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01002036 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00002037 * {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002038 * and only applies when the password quality is
2039 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002040 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002041 * <p>This method can be called on the {@link DevicePolicyManager} instance
2042 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2043 * restrictions on the parent profile.
2044 *
Robin Lee25e26452015-06-02 09:56:29 -07002045 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002046 * aggregate all admins.
2047 * @return The minimum number of lower case letters required in the
2048 * password.
2049 */
Robin Lee25e26452015-06-02 09:56:29 -07002050 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002051 return getPasswordMinimumLowerCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002052 }
2053
2054 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002055 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002056 if (mService != null) {
2057 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002058 return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002059 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002060 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002061 }
2062 }
2063 return 0;
2064 }
2065
2066 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002067 * Called by an application that is administering the device to set the minimum number of
2068 * letters required in the password. After setting this, the user will not be able to enter a
2069 * new password that is not at least as restrictive as what has been set. Note that the current
2070 * password will remain until the user has set a new one, so the change does not take place
2071 * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
2072 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
2073 * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
2074 * {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002075 * <p>
2076 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002077 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2078 * not, a security exception will be thrown.
2079 * <p>
2080 * This method can be called on the {@link DevicePolicyManager} instance returned by
2081 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2082 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002083 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002084 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2085 * @param length The new desired minimum number of letters required in the password. A value of
2086 * 0 means there is no restriction.
2087 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2088 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002089 */
Robin Lee25e26452015-06-02 09:56:29 -07002090 public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002091 if (mService != null) {
2092 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002093 mService.setPasswordMinimumLetters(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002094 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002095 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002096 }
2097 }
2098 }
2099
2100 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002101 * Retrieve the current number of letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002102 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002103 * and its participating profiles. Restrictions on profiles that have
2104 * a separate challenge are not taken into account.
2105 * This is the same value as set by
2106 * {@link #setPasswordMinimumLetters(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002107 * and only applies when the password quality is
2108 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002109 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002110 * <p>This method can be called on the {@link DevicePolicyManager} instance
2111 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2112 * restrictions on the parent profile.
2113 *
Robin Lee25e26452015-06-02 09:56:29 -07002114 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002115 * aggregate all admins.
2116 * @return The minimum number of letters required in the password.
2117 */
Robin Lee25e26452015-06-02 09:56:29 -07002118 public int getPasswordMinimumLetters(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002119 return getPasswordMinimumLetters(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002120 }
2121
2122 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002123 public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002124 if (mService != null) {
2125 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002126 return mService.getPasswordMinimumLetters(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002127 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002128 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002129 }
2130 }
2131 return 0;
2132 }
2133
2134 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002135 * Called by an application that is administering the device to set the minimum number of
2136 * numerical digits required in the password. After setting this, the user will not be able to
2137 * enter a new password that is not at least as restrictive as what has been set. Note that the
2138 * current password will remain until the user has set a new one, so the change does not take
2139 * place immediately. To prompt the user for a new password, use
2140 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
2141 * setting this value. This constraint is only imposed if the administrator has also requested
2142 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002143 * <p>
2144 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002145 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2146 * not, a security exception will be thrown.
2147 * <p>
2148 * This method can be called on the {@link DevicePolicyManager} instance returned by
2149 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2150 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002151 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002152 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2153 * @param length The new desired minimum number of numerical digits required in the password. A
2154 * value of 0 means there is no restriction.
2155 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2156 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002157 */
Robin Lee25e26452015-06-02 09:56:29 -07002158 public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002159 if (mService != null) {
2160 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002161 mService.setPasswordMinimumNumeric(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002162 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002163 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002164 }
2165 }
2166 }
2167
2168 /**
2169 * Retrieve the current number of numerical digits required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002170 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002171 * and its participating profiles. Restrictions on profiles that have
2172 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01002173 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00002174 * {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002175 * and only applies when the password quality is
2176 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002177 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002178 * <p>This method can be called on the {@link DevicePolicyManager} instance
2179 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2180 * restrictions on the parent profile.
2181 *
Robin Lee25e26452015-06-02 09:56:29 -07002182 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002183 * aggregate all admins.
2184 * @return The minimum number of numerical digits required in the password.
2185 */
Robin Lee25e26452015-06-02 09:56:29 -07002186 public int getPasswordMinimumNumeric(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002187 return getPasswordMinimumNumeric(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002188 }
2189
2190 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002191 public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002192 if (mService != null) {
2193 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002194 return mService.getPasswordMinimumNumeric(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002195 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002196 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002197 }
2198 }
2199 return 0;
2200 }
2201
2202 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002203 * Called by an application that is administering the device to set the minimum number of
2204 * symbols required in the password. After setting this, the user will not be able to enter a
2205 * new password that is not at least as restrictive as what has been set. Note that the current
2206 * password will remain until the user has set a new one, so the change does not take place
2207 * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
2208 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
2209 * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
2210 * {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002211 * <p>
2212 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002213 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2214 * not, a security exception will be thrown.
2215 * <p>
2216 * This method can be called on the {@link DevicePolicyManager} instance returned by
2217 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2218 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002219 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002220 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2221 * @param length The new desired minimum number of symbols required in the password. A value of
2222 * 0 means there is no restriction.
2223 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2224 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002225 */
Robin Lee25e26452015-06-02 09:56:29 -07002226 public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002227 if (mService != null) {
2228 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002229 mService.setPasswordMinimumSymbols(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002230 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002231 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002232 }
2233 }
2234 }
2235
2236 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002237 * Retrieve the current number of symbols required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002238 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002239 * and its participating profiles. Restrictions on profiles that have
2240 * a separate challenge are not taken into account. This is the same value as
2241 * set by {@link #setPasswordMinimumSymbols(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002242 * and only applies when the password quality is
2243 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002244 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002245 * <p>This method can be called on the {@link DevicePolicyManager} instance
2246 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2247 * restrictions on the parent profile.
2248 *
Robin Lee25e26452015-06-02 09:56:29 -07002249 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002250 * aggregate all admins.
2251 * @return The minimum number of symbols required in the password.
2252 */
Robin Lee25e26452015-06-02 09:56:29 -07002253 public int getPasswordMinimumSymbols(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002254 return getPasswordMinimumSymbols(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002255 }
2256
2257 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002258 public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002259 if (mService != null) {
2260 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002261 return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002262 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002263 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002264 }
2265 }
2266 return 0;
2267 }
2268
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002269 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002270 * Called by an application that is administering the device to set the minimum number of
2271 * non-letter characters (numerical digits or symbols) required in the password. After setting
2272 * this, the user will not be able to enter a new password that is not at least as restrictive
2273 * as what has been set. Note that the current password will remain until the user has set a new
2274 * one, so the change does not take place immediately. To prompt the user for a new password,
2275 * use {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
2276 * setting this value. This constraint is only imposed if the administrator has also requested
2277 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002278 * <p>
2279 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002280 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2281 * not, a security exception will be thrown.
2282 * <p>
2283 * This method can be called on the {@link DevicePolicyManager} instance returned by
2284 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2285 * profile.
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002286 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002287 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2288 * @param length The new desired minimum number of letters required in the password. A value of
2289 * 0 means there is no restriction.
2290 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2291 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002292 */
Robin Lee25e26452015-06-02 09:56:29 -07002293 public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002294 if (mService != null) {
2295 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002296 mService.setPasswordMinimumNonLetter(admin, length, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002297 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002298 throw e.rethrowFromSystemServer();
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002299 }
2300 }
2301 }
2302
2303 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002304 * Retrieve the current number of non-letter characters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002305 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002306 * and its participating profiles. Restrictions on profiles that have
2307 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01002308 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00002309 * {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002310 * and only applies when the password quality is
2311 * {@link #PASSWORD_QUALITY_COMPLEX}.
2312 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002313 * <p>This method can be called on the {@link DevicePolicyManager} instance
2314 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2315 * restrictions on the parent profile.
2316 *
Robin Lee25e26452015-06-02 09:56:29 -07002317 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002318 * aggregate all admins.
2319 * @return The minimum number of letters required in the password.
2320 */
Robin Lee25e26452015-06-02 09:56:29 -07002321 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002322 return getPasswordMinimumNonLetter(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002323 }
2324
2325 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002326 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002327 if (mService != null) {
2328 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002329 return mService.getPasswordMinimumNonLetter(admin, userHandle, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002330 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002331 throw e.rethrowFromSystemServer();
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002332 }
2333 }
2334 return 0;
2335 }
2336
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002337 /**
2338 * Called by an application that is administering the device to set the length of the password
2339 * history. After setting this, the user will not be able to enter a new password that is the
2340 * same as any password in the history. Note that the current password will remain until the
2341 * user has set a new one, so the change does not take place immediately. To prompt the user for
2342 * a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
2343 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
2344 * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC}
2345 * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX} {@link #PASSWORD_QUALITY_ALPHABETIC}, or
2346 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} with {@link #setPasswordQuality}.
2347 * <p>
2348 * The calling device admin must have requested
2349 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2350 * not, a security exception will be thrown.
2351 * <p>
2352 * This method can be called on the {@link DevicePolicyManager} instance returned by
2353 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2354 * profile.
2355 *
2356 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2357 * @param length The new desired length of password history. A value of 0 means there is no
2358 * restriction.
2359 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2360 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
2361 */
Robin Lee25e26452015-06-02 09:56:29 -07002362 public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002363 if (mService != null) {
2364 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002365 mService.setPasswordHistoryLength(admin, length, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002366 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002367 throw e.rethrowFromSystemServer();
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002368 }
2369 }
2370 }
2371
2372 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002373 * Called by a device admin to set the password expiration timeout. Calling this method will
2374 * restart the countdown for password expiration for the given admin, as will changing the
2375 * device password (for all admins).
2376 * <p>
2377 * The provided timeout is the time delta in ms and will be added to the current time. For
2378 * example, to have the password expire 5 days from now, timeout would be 5 * 86400 * 1000 =
2379 * 432000000 ms for timeout.
2380 * <p>
2381 * To disable password expiration, a value of 0 may be used for timeout.
2382 * <p>
2383 * The calling device admin must have requested
2384 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this method; if it has
2385 * not, a security exception will be thrown.
2386 * <p>
2387 * Note that setting the password will automatically reset the expiration time for all active
2388 * admins. Active admins do not need to explicitly call this method in that case.
2389 * <p>
2390 * This method can be called on the {@link DevicePolicyManager} instance returned by
2391 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2392 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002393 *
Jim Millera4e28d12010-11-08 16:15:47 -08002394 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002395 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0 means
2396 * there is no restriction (unlimited).
2397 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2398 * does not use {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD}
Jim Millera4e28d12010-11-08 16:15:47 -08002399 */
Robin Lee25e26452015-06-02 09:56:29 -07002400 public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) {
Jim Millera4e28d12010-11-08 16:15:47 -08002401 if (mService != null) {
2402 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002403 mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08002404 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002405 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08002406 }
2407 }
2408 }
2409
2410 /**
Jim Miller6b857682011-02-16 16:27:41 -08002411 * Get the password expiration timeout for the given admin. The expiration timeout is the
2412 * recurring expiration timeout provided in the call to
2413 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
Esteban Talaverac1c83592016-02-17 17:56:15 +00002414 * aggregate of all participating policy administrators if {@code admin} is null. Admins that
2415 * have set restrictions on profiles that have a separate challenge are not taken into account.
2416 *
2417 * <p>This method can be called on the {@link DevicePolicyManager} instance
2418 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2419 * restrictions on the parent profile.
Jim Millera4e28d12010-11-08 16:15:47 -08002420 *
Robin Lee25e26452015-06-02 09:56:29 -07002421 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08002422 * @return The timeout for the given admin or the minimum of all timeouts
2423 */
Robin Lee25e26452015-06-02 09:56:29 -07002424 public long getPasswordExpirationTimeout(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08002425 if (mService != null) {
2426 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002427 return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08002428 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002429 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08002430 }
2431 }
2432 return 0;
2433 }
2434
2435 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002436 * Get the current password expiration time for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01002437 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00002438 * a separate challenge are not taken into account. If admin is {@code null}, then a composite
2439 * of all expiration times is returned - which will be the minimum of all of them.
2440 *
2441 * <p>This method can be called on the {@link DevicePolicyManager} instance
2442 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2443 * the password expiration for the parent profile.
Jim Millera4e28d12010-11-08 16:15:47 -08002444 *
Robin Lee25e26452015-06-02 09:56:29 -07002445 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002446 * @return The password expiration time, in milliseconds since epoch.
Jim Millera4e28d12010-11-08 16:15:47 -08002447 */
Robin Lee25e26452015-06-02 09:56:29 -07002448 public long getPasswordExpiration(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08002449 if (mService != null) {
2450 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002451 return mService.getPasswordExpiration(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08002452 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002453 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08002454 }
2455 }
2456 return 0;
2457 }
2458
2459 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002460 * Retrieve the current password history length for a particular admin or all admins that
Rubin Xud3609d42016-07-13 18:32:57 +01002461 * set restrictions on this user and its participating profiles. Restrictions on profiles that
Esteban Talaverac1c83592016-02-17 17:56:15 +00002462 * have a separate challenge are not taken into account.
2463 *
2464 * <p>This method can be called on the {@link DevicePolicyManager} instance
2465 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2466 * restrictions on the parent profile.
2467 *
Robin Lee25e26452015-06-02 09:56:29 -07002468 * @param admin The name of the admin component to check, or {@code null} to aggregate
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002469 * all admins.
2470 * @return The length of the password history
2471 */
Robin Lee25e26452015-06-02 09:56:29 -07002472 public int getPasswordHistoryLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002473 return getPasswordHistoryLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002474 }
2475
2476 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002477 public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002478 if (mService != null) {
2479 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002480 return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002481 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002482 throw e.rethrowFromSystemServer();
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002483 }
2484 }
2485 return 0;
2486 }
2487
Dianne Hackbornd6847842010-01-12 18:14:19 -08002488 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08002489 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08002490 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08002491 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08002492 * @return Returns the maximum length that the user can enter.
2493 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08002494 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08002495 // Kind-of arbitrary.
2496 return 16;
2497 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002498
Dianne Hackborn254cb442010-01-27 19:23:59 -08002499 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002500 * Determine whether the current password the user has set is sufficient to meet the policy
2501 * requirements (e.g. quality, minimum length) that have been requested by the admins of this
2502 * user and its participating profiles. Restrictions on profiles that have a separate challenge
Andrew Scull5daf2732016-11-14 15:02:45 +00002503 * are not taken into account. The user must be unlocked in order to perform the check.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002504 * <p>
2505 * The calling device admin must have requested
2506 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2507 * not, a security exception will be thrown.
2508 * <p>
2509 * This method can be called on the {@link DevicePolicyManager} instance returned by
2510 * {@link #getParentProfileInstance(ComponentName)} in order to determine if the password set on
2511 * the parent profile is sufficient.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002512 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01002513 * @return Returns true if the password meets the current requirements, else false.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002514 * @throws SecurityException if the calling application does not own an active administrator
2515 * that uses {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Andrew Scull5daf2732016-11-14 15:02:45 +00002516 * @throws InvalidStateException if the user is not unlocked.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002517 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002518 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002519 if (mService != null) {
2520 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00002521 return mService.isActivePasswordSufficient(myUserId(), mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002522 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002523 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002524 }
2525 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002526 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08002527 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002528
Dianne Hackbornd6847842010-01-12 18:14:19 -08002529 /**
Clara Bayarrid7693912016-01-22 17:26:31 +00002530 * Determine whether the current profile password the user has set is sufficient
Esteban Talaverac1c83592016-02-17 17:56:15 +00002531 * to meet the policy requirements (e.g. quality, minimum length) that have been
Clara Bayarrid7693912016-01-22 17:26:31 +00002532 * requested by the admins of the parent user and its profiles.
2533 *
2534 * @param userHandle the userId of the profile to check the password for.
2535 * @return Returns true if the password would meet the current requirements, else false.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002536 * @throws SecurityException if {@code userHandle} is not a managed profile.
Clara Bayarrid7693912016-01-22 17:26:31 +00002537 * @hide
2538 */
2539 public boolean isProfileActivePasswordSufficientForParent(int userHandle) {
2540 if (mService != null) {
2541 try {
2542 return mService.isProfileActivePasswordSufficientForParent(userHandle);
2543 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002544 throw e.rethrowFromSystemServer();
Clara Bayarrid7693912016-01-22 17:26:31 +00002545 }
2546 }
2547 return false;
2548 }
2549
2550 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002551 * Retrieve the number of times the user has failed at entering a password since that last
2552 * successful password entry.
2553 * <p>
2554 * This method can be called on the {@link DevicePolicyManager} instance returned by
2555 * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the number of failed
2556 * password attemts for the parent user.
2557 * <p>
2558 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN}
2559 * to be able to call this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002560 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002561 * @return The number of times user has entered an incorrect password since the last correct
2562 * password entry.
2563 * @throws SecurityException if the calling application does not own an active administrator
2564 * that uses {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002565 */
2566 public int getCurrentFailedPasswordAttempts() {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00002567 return getCurrentFailedPasswordAttempts(myUserId());
2568 }
2569
2570 /**
2571 * Retrieve the number of times the given user has failed at entering a
2572 * password since that last successful password entry.
2573 *
2574 * <p>The calling device admin must have requested
2575 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call this method; if it has
2576 * not and it is not the system uid, a security exception will be thrown.
2577 *
2578 * @hide
2579 */
2580 public int getCurrentFailedPasswordAttempts(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002581 if (mService != null) {
2582 try {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00002583 return mService.getCurrentFailedPasswordAttempts(userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002584 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002585 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002586 }
2587 }
2588 return -1;
2589 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002590
2591 /**
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002592 * Queries whether {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002593 *
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002594 * @return true if RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002595 * @hide
2596 */
2597 public boolean getDoNotAskCredentialsOnBoot() {
2598 if (mService != null) {
2599 try {
2600 return mService.getDoNotAskCredentialsOnBoot();
2601 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002602 throw e.rethrowFromSystemServer();
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002603 }
2604 }
2605 return false;
2606 }
2607
2608 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002609 * Setting this to a value greater than zero enables a built-in policy that will perform a
2610 * device or profile wipe after too many incorrect device-unlock passwords have been entered.
2611 * This built-in policy combines watching for failed passwords and wiping the device, and
2612 * requires that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002613 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002614 * <p>
2615 * To implement any other policy (e.g. wiping data for a particular application only, erasing or
2616 * revoking credentials, or reporting the failure to a server), you should implement
2617 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} instead. Do not
2618 * use this API, because if the maximum count is reached, the device or profile will be wiped
2619 * immediately, and your callback will not be invoked.
2620 * <p>
2621 * This method can be called on the {@link DevicePolicyManager} instance returned by
2622 * {@link #getParentProfileInstance(ComponentName)} in order to set a value on the parent
2623 * profile.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002624 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002625 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002626 * @param num The number of failed password attempts at which point the device or profile will
2627 * be wiped.
2628 * @throws SecurityException if {@code admin} is not an active administrator or does not use
2629 * both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
2630 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002631 */
Robin Lee25e26452015-06-02 09:56:29 -07002632 public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002633 if (mService != null) {
2634 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002635 mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002636 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002637 throw e.rethrowFromSystemServer();
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002638 }
2639 }
2640 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002641
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002642 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002643 * Retrieve the current maximum number of login attempts that are allowed before the device
Rubin Xud3609d42016-07-13 18:32:57 +01002644 * or profile is wiped, for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002645 * and its participating profiles. Restrictions on profiles that have a separate challenge are
2646 * not taken into account.
2647 *
2648 * <p>This method can be called on the {@link DevicePolicyManager} instance
2649 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2650 * the value for the parent profile.
2651 *
Robin Lee25e26452015-06-02 09:56:29 -07002652 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002653 * all admins.
2654 */
Robin Lee25e26452015-06-02 09:56:29 -07002655 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002656 return getMaximumFailedPasswordsForWipe(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002657 }
2658
2659 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002660 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08002661 if (mService != null) {
2662 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002663 return mService.getMaximumFailedPasswordsForWipe(
2664 admin, userHandle, mParentInstance);
Dianne Hackborn254cb442010-01-27 19:23:59 -08002665 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002666 throw e.rethrowFromSystemServer();
Dianne Hackborn254cb442010-01-27 19:23:59 -08002667 }
2668 }
2669 return 0;
2670 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002671
Dianne Hackborn254cb442010-01-27 19:23:59 -08002672 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002673 * Returns the profile with the smallest maximum failed passwords for wipe,
2674 * for the given user. So for primary user, it might return the primary or
2675 * a managed profile. For a secondary user, it would be the same as the
2676 * user passed in.
2677 * @hide Used only by Keyguard
2678 */
2679 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
2680 if (mService != null) {
2681 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002682 return mService.getProfileWithMinimumFailedPasswordsForWipe(
2683 userHandle, mParentInstance);
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002684 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002685 throw e.rethrowFromSystemServer();
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002686 }
2687 }
2688 return UserHandle.USER_NULL;
2689 }
2690
2691 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002692 * Flag for {@link #resetPassword}: don't allow other admins to change
2693 * the password again until the user has entered it.
2694 */
2695 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002696
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002697 /**
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002698 * Flag for {@link #resetPassword}: don't ask for user credentials on device boot.
2699 * If the flag is set, the device can be booted without asking for user password.
2700 * The absence of this flag does not change the current boot requirements. This flag
2701 * can be set by the device owner only. If the app is not the device owner, the flag
2702 * is ignored. Once the flag is set, it cannot be reverted back without resetting the
2703 * device to factory defaults.
2704 */
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002705 public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002;
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002706
2707 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002708 * Force a new device unlock password (the password needed to access the entire device, not for
2709 * individual accounts) on the user. This takes effect immediately.
2710 * <p>
Rubin Xuaab7a412016-12-30 21:13:29 +00002711 * <em>For device owner and profile owners targeting SDK level
2712 * {@link android.os.Build.VERSION_CODES#O} or above, this API is no longer available and will
2713 * throw {@link SecurityException}. Please use the new API {@link #resetPasswordWithToken}
2714 * instead. </em>
2715 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002716 * <em>Note: This API has been limited as of {@link android.os.Build.VERSION_CODES#N} for
Makoto Onuki70f929e2015-11-11 12:40:15 -08002717 * device admins that are not device owner and not profile owner.
2718 * The password can now only be changed if there is currently no password set. Device owner
Ricky Wai977ade22016-05-24 15:02:41 +01002719 * and profile owner can still do this when user is unlocked and does not have a managed
2720 * profile.</em>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002721 * <p>
2722 * The given password must be sufficient for the current password quality and length constraints
2723 * as returned by {@link #getPasswordQuality(ComponentName)} and
2724 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then
2725 * it will be rejected and false returned. Note that the password may be a stronger quality
2726 * (containing alphanumeric characters when the requested quality is only numeric), in which
2727 * case the currently active quality will be increased to match.
2728 * <p>
2729 * Calling with a null or empty password will clear any existing PIN, pattern or password if the
Robin Leece5c4002016-03-23 17:05:03 +00002730 * current password constraints allow it. <em>Note: This will not work in
2731 * {@link android.os.Build.VERSION_CODES#N} and later for managed profiles, or for device admins
2732 * that are not device owner or profile owner. Once set, the password cannot be changed to null
2733 * or empty except by these admins.</em>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002734 * <p>
2735 * The calling device admin must have requested
2736 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call this method; if it has
2737 * not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002738 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01002739 * @param password The new password for the user. Null or empty clears the password.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002740 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002741 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
2742 * @return Returns true if the password was applied, or false if it is not acceptable for the
2743 * current constraints or if the user has not been decrypted yet.
2744 * @throws SecurityException if the calling application does not own an active administrator
2745 * that uses {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD}
Ricky Wai977ade22016-05-24 15:02:41 +01002746 * @throws IllegalStateException if the calling user is locked or has a managed profile.
Andrew Scull3f81f4e2016-07-29 16:29:58 +01002747 * @throws IllegalArgumentException if the password does not meet system requirements.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002748 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002749 public boolean resetPassword(String password, int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002750 throwIfParentInstance("resetPassword");
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002751 if (mService != null) {
2752 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002753 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002754 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002755 throw e.rethrowFromSystemServer();
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002756 }
2757 }
2758 return false;
2759 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002760
Dianne Hackbornd6847842010-01-12 18:14:19 -08002761 /**
Rubin Xuaab7a412016-12-30 21:13:29 +00002762 * Called by a profile or device owner to provision a token which can later be used to reset the
Esteban Talavera9c6458d2017-03-30 17:59:50 +01002763 * device lockscreen password (if called by device owner), or managed profile challenge (if
2764 * called by profile owner), via {@link #resetPasswordWithToken}.
Rubin Xuaab7a412016-12-30 21:13:29 +00002765 * <p>
2766 * If the user currently has a lockscreen password, the provisioned token will not be
2767 * immediately usable; it only becomes active after the user performs a confirm credential
2768 * operation, which can be triggered by {@link KeyguardManager#createConfirmDeviceCredentialIntent}.
2769 * If the user has no lockscreen password, the token is activated immediately. In all cases,
2770 * the active state of the current token can be checked by {@link #isResetPasswordTokenActive}.
2771 * For security reasons, un-activated tokens are only stored in memory and will be lost once
2772 * the device reboots. In this case a new token needs to be provisioned again.
2773 * <p>
2774 * Once provisioned and activated, the token will remain effective even if the user changes
2775 * or clears the lockscreen password.
2776 * <p>
2777 * <em>This token is highly sensitive and should be treated at the same level as user
Rubin Xuf7b036d2017-04-05 18:37:07 +01002778 * credentials. In particular, NEVER store this token on device in plaintext. Do not store
2779 * the plaintext token in device-encrypted storage if it will be needed to reset password on
2780 * file-based encryption devices before user unlocks. Consider carefully how any password token
2781 * will be stored on your server and who will need access to them. Tokens may be the subject of
2782 * legal access requests.
Rubin Xuaab7a412016-12-30 21:13:29 +00002783 * </em>
2784 *
2785 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2786 * @param token a secure token a least 32-byte long, which must be generated by a
2787 * cryptographically strong random number generator.
2788 * @return true if the operation is successful, false otherwise.
2789 * @throws IllegalArgumentException if the supplied token is invalid.
2790 * @throws SecurityException
2791 */
2792 public boolean setResetPasswordToken(ComponentName admin, byte[] token) {
2793 throwIfParentInstance("setResetPasswordToken");
2794 if (mService != null) {
2795 try {
2796 return mService.setResetPasswordToken(admin, token);
2797 } catch (RemoteException e) {
2798 throw e.rethrowFromSystemServer();
2799 }
2800 }
2801 return false;
2802 }
2803
2804 /**
2805 * Called by a profile or device owner to revoke the current password reset token.
2806 *
2807 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2808 * @return true if the operation is successful, false otherwise.
2809 */
2810 public boolean clearResetPasswordToken(ComponentName admin) {
2811 throwIfParentInstance("clearResetPasswordToken");
2812 if (mService != null) {
2813 try {
2814 return mService.clearResetPasswordToken(admin);
2815 } catch (RemoteException e) {
2816 throw e.rethrowFromSystemServer();
2817 }
2818 }
2819 return false;
2820 }
2821
2822 /**
2823 * Called by a profile or device owner to check if the current reset password token is active.
2824 *
2825 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2826 * @return true if the token is active, false otherwise.
2827 * @throws IllegalStateException if no token has been set.
2828 */
2829 public boolean isResetPasswordTokenActive(ComponentName admin) {
2830 throwIfParentInstance("isResetPasswordTokenActive");
2831 if (mService != null) {
2832 try {
2833 return mService.isResetPasswordTokenActive(admin);
2834 } catch (RemoteException e) {
2835 throw e.rethrowFromSystemServer();
2836 }
2837 }
2838 return false;
2839 }
2840
2841 /**
Esteban Talavera9c6458d2017-03-30 17:59:50 +01002842 * Called by device or profile owner to force set a new device unlock password or a managed
2843 * profile challenge on current user. This takes effect immediately.
Rubin Xuaab7a412016-12-30 21:13:29 +00002844 * <p>
2845 * Unlike {@link #resetPassword}, this API can change the password even before the user or
2846 * device is unlocked or decrypted. The supplied token must have been previously provisioned via
2847 * {@link #setResetPasswordToken}, and in active state {@link #isResetPasswordTokenActive}.
2848 * <p>
2849 * The given password must be sufficient for the current password quality and length constraints
2850 * as returned by {@link #getPasswordQuality(ComponentName)} and
2851 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then
2852 * it will be rejected and false returned. Note that the password may be a stronger quality
2853 * (containing alphanumeric characters when the requested quality is only numeric), in which
2854 * case the currently active quality will be increased to match.
2855 * <p>
2856 * Calling with a null or empty password will clear any existing PIN, pattern or password if the
2857 * current password constraints allow it.
2858 *
2859 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2860 * @param password The new password for the user. Null or empty clears the password.
2861 * @param token the password reset token previously provisioned by #setResetPasswordToken.
2862 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
2863 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
2864 * @return Returns true if the password was applied, or false if it is not acceptable for the
2865 * current constraints.
2866 * @throws SecurityException if the calling application does not own an active administrator
2867 * that uses {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD}
2868 * @throws IllegalStateException if the provided token is not valid.
2869 * @throws IllegalArgumentException if the password does not meet system requirements.
2870 */
2871 public boolean resetPasswordWithToken(@NonNull ComponentName admin, String password,
2872 byte[] token, int flags) {
2873 throwIfParentInstance("resetPassword");
2874 if (mService != null) {
2875 try {
2876 return mService.resetPasswordWithToken(admin, password, token, flags);
2877 } catch (RemoteException e) {
2878 throw e.rethrowFromSystemServer();
2879 }
2880 }
2881 return false;
2882 }
2883
2884 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002885 * Called by an application that is administering the device to set the maximum time for user
2886 * activity until the device will lock. This limits the length that the user can set. It takes
2887 * effect immediately.
2888 * <p>
2889 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
2890 * to be able to call this method; if it has not, a security exception will be thrown.
2891 * <p>
2892 * This method can be called on the {@link DevicePolicyManager} instance returned by
2893 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2894 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002895 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002896 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002897 * @param timeMs The new desired maximum time to lock in milliseconds. A value of 0 means there
2898 * is no restriction.
2899 * @throws SecurityException if {@code admin} is not an active administrator or it does not use
2900 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002901 */
Robin Lee25e26452015-06-02 09:56:29 -07002902 public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002903 if (mService != null) {
2904 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002905 mService.setMaximumTimeToLock(admin, timeMs, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002906 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002907 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002908 }
2909 }
2910 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002911
Dianne Hackbornd6847842010-01-12 18:14:19 -08002912 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002913 * Retrieve the current maximum time to unlock for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01002914 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00002915 * a separate challenge are not taken into account.
2916 *
2917 * <p>This method can be called on the {@link DevicePolicyManager} instance
2918 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2919 * restrictions on the parent profile.
2920 *
Robin Lee25e26452015-06-02 09:56:29 -07002921 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002922 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07002923 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07002924 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002925 */
Robin Lee25e26452015-06-02 09:56:29 -07002926 public long getMaximumTimeToLock(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002927 return getMaximumTimeToLock(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002928 }
2929
2930 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002931 public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002932 if (mService != null) {
2933 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002934 return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002935 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002936 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002937 }
2938 }
2939 return 0;
2940 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002941
Dianne Hackbornd6847842010-01-12 18:14:19 -08002942 /**
Ricky Wai035e9242016-03-18 16:43:31 +00002943 * Returns maximum time to lock that applied by all profiles in this user. We do this because we
2944 * do not have a separate timeout to lock for work challenge only.
2945 *
2946 * @hide
2947 */
2948 public long getMaximumTimeToLockForUserAndProfiles(int userHandle) {
2949 if (mService != null) {
2950 try {
2951 return mService.getMaximumTimeToLockForUserAndProfiles(userHandle);
2952 } catch (RemoteException e) {
2953 throw e.rethrowFromSystemServer();
2954 }
2955 }
2956 return 0;
2957 }
2958
2959 /**
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002960 * Called by a device/profile owner to set the timeout after which unlocking with secondary, non
2961 * strong auth (e.g. fingerprint, trust agents) times out, i.e. the user has to use a strong
2962 * authentication method like password, pin or pattern.
2963 *
2964 * <p>This timeout is used internally to reset the timer to require strong auth again after
2965 * specified timeout each time it has been successfully used.
2966 *
2967 * <p>Fingerprint can also be disabled altogether using {@link #KEYGUARD_DISABLE_FINGERPRINT}.
2968 *
2969 * <p>Trust agents can also be disabled altogether using {@link #KEYGUARD_DISABLE_TRUST_AGENTS}.
2970 *
2971 * <p>The calling device admin must be a device or profile owner. If it is not,
2972 * a {@link SecurityException} will be thrown.
2973 *
Michal Karpinski943aabd2016-10-06 11:09:25 +01002974 * <p>The calling device admin can verify the value it has set by calling
2975 * {@link #getRequiredStrongAuthTimeout(ComponentName)} and passing in its instance.
2976 *
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002977 * <p>This method can be called on the {@link DevicePolicyManager} instance returned by
2978 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2979 * profile.
2980 *
2981 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xu5d39ea72017-04-24 20:26:30 +01002982 * @param timeoutMs The new timeout in milliseconds, after which the user will have to unlock
2983 * with strong authentication method. A value of 0 means the admin is not participating
2984 * in controlling the timeout.
Michal Karpinski943aabd2016-10-06 11:09:25 +01002985 * The minimum and maximum timeouts are platform-defined and are typically 1 hour and
2986 * 72 hours, respectively. Though discouraged, the admin may choose to require strong
2987 * auth at all times using {@link #KEYGUARD_DISABLE_FINGERPRINT} and/or
2988 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002989 *
2990 * @throws SecurityException if {@code admin} is not a device or profile owner.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002991 */
2992 public void setRequiredStrongAuthTimeout(@NonNull ComponentName admin,
2993 long timeoutMs) {
2994 if (mService != null) {
2995 try {
2996 mService.setRequiredStrongAuthTimeout(admin, timeoutMs, mParentInstance);
2997 } catch (RemoteException e) {
2998 throw e.rethrowFromSystemServer();
2999 }
3000 }
3001 }
3002
3003 /**
3004 * Determine for how long the user will be able to use secondary, non strong auth for
3005 * authentication, since last strong method authentication (password, pin or pattern) was used.
3006 * After the returned timeout the user is required to use strong authentication method.
3007 *
3008 * <p>This method can be called on the {@link DevicePolicyManager} instance
3009 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
3010 * restrictions on the parent profile.
3011 *
3012 * @param admin The name of the admin component to check, or {@code null} to aggregate
3013 * accross all participating admins.
Rubin Xu5d39ea72017-04-24 20:26:30 +01003014 * @return The timeout in milliseconds or 0 if not configured for the provided admin.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01003015 */
3016 public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin) {
3017 return getRequiredStrongAuthTimeout(admin, myUserId());
3018 }
3019
3020 /** @hide per-user version */
3021 public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin, @UserIdInt int userId) {
3022 if (mService != null) {
3023 try {
3024 return mService.getRequiredStrongAuthTimeout(admin, userId, mParentInstance);
3025 } catch (RemoteException e) {
3026 throw e.rethrowFromSystemServer();
3027 }
3028 }
3029 return DEFAULT_STRONG_AUTH_TIMEOUT_MS;
3030 }
3031
3032 /**
Andrew Scull85a63bc2016-10-24 13:47:47 +01003033 * Flag for {@link #lockNow(int)}: also evict the user's credential encryption key from the
3034 * keyring. The user's credential will need to be entered again in order to derive the
3035 * credential encryption key that will be stored back in the keyring for future use.
3036 * <p>
Andrew Scull17e1b5d2017-04-25 14:44:24 +01003037 * This flag can only be used by a profile owner when locking a managed profile when
3038 * {@link #getStorageEncryptionStatus} returns {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}.
Andrew Scull85a63bc2016-10-24 13:47:47 +01003039 * <p>
3040 * In order to secure user data, the user will be stopped and restarted so apps should wait
3041 * until they are next run to perform further actions.
3042 */
Andrew Scull17e1b5d2017-04-25 14:44:24 +01003043 public static final int FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY = 1;
3044
Andrew Scull85a63bc2016-10-24 13:47:47 +01003045 /** @hide */
3046 @Retention(RetentionPolicy.SOURCE)
Andrew Scull17e1b5d2017-04-25 14:44:24 +01003047 @IntDef(flag=true, value={FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY})
Andrew Scull85a63bc2016-10-24 13:47:47 +01003048 public @interface LockNowFlag {}
3049
3050 /**
3051 * Make the device lock immediately, as if the lock screen timeout has expired at the point of
3052 * this call.
3053 * <p>
3054 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
3055 * to be able to call this method; if it has not, a security exception will be thrown.
3056 * <p>
3057 * This method can be called on the {@link DevicePolicyManager} instance returned by
3058 * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile.
3059 * <p>
3060 * Equivalent to calling {@link #lockNow(int)} with no flags.
3061 *
3062 * @throws SecurityException if the calling application does not own an active administrator
3063 * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
3064 */
3065 public void lockNow() {
3066 lockNow(0);
3067 }
3068
3069 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003070 * Make the device lock immediately, as if the lock screen timeout has expired at the point of
3071 * this call.
3072 * <p>
3073 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
3074 * to be able to call this method; if it has not, a security exception will be thrown.
3075 * <p>
3076 * This method can be called on the {@link DevicePolicyManager} instance returned by
3077 * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003078 *
Andrew Scull17e1b5d2017-04-25 14:44:24 +01003079 * @param flags May be 0 or {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003080 * @throws SecurityException if the calling application does not own an active administrator
Andrew Scull85a63bc2016-10-24 13:47:47 +01003081 * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} or the
Andrew Scull17e1b5d2017-04-25 14:44:24 +01003082 * {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY} flag is passed by an application
3083 * that is not a profile
Andrew Scull85a63bc2016-10-24 13:47:47 +01003084 * owner of a managed profile.
Andrew Scull17e1b5d2017-04-25 14:44:24 +01003085 * @throws IllegalArgumentException if the {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY} flag is
3086 * passed when locking the parent profile.
3087 * @throws UnsupportedOperationException if the {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY}
3088 * flag is passed when {@link #getStorageEncryptionStatus} does not return
3089 * {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08003090 */
Andrew Scull85a63bc2016-10-24 13:47:47 +01003091 public void lockNow(@LockNowFlag int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -08003092 if (mService != null) {
3093 try {
Andrew Scull85a63bc2016-10-24 13:47:47 +01003094 mService.lockNow(flags, mParentInstance);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08003095 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003096 throw e.rethrowFromSystemServer();
Dianne Hackborndf83afa2010-01-20 13:37:26 -08003097 }
3098 }
3099 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003100
Dianne Hackbornd6847842010-01-12 18:14:19 -08003101 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07003102 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00003103 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07003104 */
3105 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
3106
3107 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00003108 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
3109 * data.
3110 *
Paul Crowley2934b262014-12-02 11:21:13 +00003111 * <p>This flag may only be set by device owner admins; if it is set by
3112 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00003113 */
3114 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
3115
3116 /**
Suprabh Shukla556b05a2016-08-10 15:49:24 -07003117 * Ask that all user data be wiped. If called as a secondary user, the user will be removed and
3118 * other users will remain unaffected. Calling from the primary user will cause the device to
3119 * reboot, erasing all device data - including all the secondary users and their data - while
3120 * booting up.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003121 * <p>
3122 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to
3123 * be able to call this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003124 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003125 * @param flags Bit mask of additional options: currently supported flags are
3126 * {@link #WIPE_EXTERNAL_STORAGE} and {@link #WIPE_RESET_PROTECTION_DATA}.
3127 * @throws SecurityException if the calling application does not own an active administrator
3128 * that uses {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}
Dianne Hackbornd6847842010-01-12 18:14:19 -08003129 */
3130 public void wipeData(int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003131 throwIfParentInstance("wipeData");
Dianne Hackbornd6847842010-01-12 18:14:19 -08003132 if (mService != null) {
3133 try {
Makoto Onuki70f929e2015-11-11 12:40:15 -08003134 mService.wipeData(flags);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003135 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003136 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003137 }
3138 }
3139 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003140
Dianne Hackbornd6847842010-01-12 18:14:19 -08003141 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07003142 * Called by an application that is administering the device to set the
3143 * global proxy and exclusion list.
3144 * <p>
3145 * The calling device admin must have requested
3146 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
3147 * this method; if it has not, a security exception will be thrown.
3148 * Only the first device admin can set the proxy. If a second admin attempts
3149 * to set the proxy, the {@link ComponentName} of the admin originally setting the
Robin Lee25e26452015-06-02 09:56:29 -07003150 * proxy will be returned. If successful in setting the proxy, {@code null} will
Oscar Montemayor69238c62010-08-03 10:51:06 -07003151 * be returned.
3152 * The method can be called repeatedly by the device admin alrady setting the
3153 * proxy to update the proxy and exclusion list.
3154 *
Robin Lee25e26452015-06-02 09:56:29 -07003155 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Oscar Montemayor69238c62010-08-03 10:51:06 -07003156 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
3157 * Pass Proxy.NO_PROXY to reset the proxy.
3158 * @param exclusionList a list of domains to be excluded from the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07003159 * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName}
3160 * of the device admin that sets the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08003161 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07003162 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003163 public @Nullable ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec,
Oscar Montemayor69238c62010-08-03 10:51:06 -07003164 List<String> exclusionList ) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003165 throwIfParentInstance("setGlobalProxy");
Oscar Montemayor69238c62010-08-03 10:51:06 -07003166 if (proxySpec == null) {
3167 throw new NullPointerException();
3168 }
3169 if (mService != null) {
3170 try {
3171 String hostSpec;
3172 String exclSpec;
3173 if (proxySpec.equals(Proxy.NO_PROXY)) {
3174 hostSpec = null;
3175 exclSpec = null;
3176 } else {
3177 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
3178 throw new IllegalArgumentException();
3179 }
3180 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
3181 String hostName = sa.getHostName();
3182 int port = sa.getPort();
3183 StringBuilder hostBuilder = new StringBuilder();
3184 hostSpec = hostBuilder.append(hostName)
3185 .append(":").append(Integer.toString(port)).toString();
3186 if (exclusionList == null) {
3187 exclSpec = "";
3188 } else {
3189 StringBuilder listBuilder = new StringBuilder();
3190 boolean firstDomain = true;
3191 for (String exclDomain : exclusionList) {
3192 if (!firstDomain) {
3193 listBuilder = listBuilder.append(",");
3194 } else {
3195 firstDomain = false;
3196 }
3197 listBuilder = listBuilder.append(exclDomain.trim());
3198 }
3199 exclSpec = listBuilder.toString();
3200 }
Yuhao Zheng90704842014-02-28 17:22:45 -08003201 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
3202 != android.net.Proxy.PROXY_VALID)
3203 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07003204 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003205 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07003206 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003207 throw e.rethrowFromSystemServer();
Oscar Montemayor69238c62010-08-03 10:51:06 -07003208 }
3209 }
3210 return null;
3211 }
3212
3213 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003214 * Set a network-independent global HTTP proxy. This is not normally what you want for typical
3215 * HTTP proxies - they are generally network dependent. However if you're doing something
3216 * unusual like general internal filtering this may be useful. On a private network where the
3217 * proxy is not accessible, you may break HTTP using this.
3218 * <p>
3219 * This method requires the caller to be the device owner.
3220 * <p>
3221 * This proxy is only a recommendation and it is possible that some apps will ignore it.
Jason Monk03bc9912014-05-13 09:44:57 -04003222 *
Jason Monk03bc9912014-05-13 09:44:57 -04003223 * @see ProxyInfo
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003224 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3225 * @param proxyInfo The a {@link ProxyInfo} object defining the new global HTTP proxy. A
3226 * {@code null} value will clear the global HTTP proxy.
3227 * @throws SecurityException if {@code admin} is not the device owner.
Jason Monk03bc9912014-05-13 09:44:57 -04003228 */
Robin Lee25e26452015-06-02 09:56:29 -07003229 public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo
3230 proxyInfo) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003231 throwIfParentInstance("setRecommendedGlobalProxy");
Jason Monk03bc9912014-05-13 09:44:57 -04003232 if (mService != null) {
3233 try {
3234 mService.setRecommendedGlobalProxy(admin, proxyInfo);
3235 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003236 throw e.rethrowFromSystemServer();
Jason Monk03bc9912014-05-13 09:44:57 -04003237 }
3238 }
3239 }
3240
3241 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07003242 * Returns the component name setting the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07003243 * @return ComponentName object of the device admin that set the global proxy, or {@code null}
3244 * if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08003245 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07003246 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003247 public @Nullable ComponentName getGlobalProxyAdmin() {
Oscar Montemayor69238c62010-08-03 10:51:06 -07003248 if (mService != null) {
3249 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003250 return mService.getGlobalProxyAdmin(myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07003251 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003252 throw e.rethrowFromSystemServer();
Oscar Montemayor69238c62010-08-03 10:51:06 -07003253 }
3254 }
3255 return null;
3256 }
3257
3258 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08003259 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003260 * indicating that encryption is not supported.
3261 */
3262 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
3263
3264 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08003265 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003266 * indicating that encryption is supported, but is not currently active.
3267 */
3268 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
3269
3270 /**
Robin Lee3795fb02015-02-16 14:17:23 +00003271 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003272 * indicating that encryption is not currently active, but is currently
3273 * being activated. This is only reported by devices that support
3274 * encryption of data and only when the storage is currently
3275 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
3276 * to become encrypted will never return this value.
3277 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08003278 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003279
3280 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08003281 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003282 * indicating that encryption is active.
Amith Yamasani75db1252016-07-11 14:41:01 -07003283 * <p>
3284 * Also see {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003285 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08003286 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003287
3288 /**
Robin Lee3795fb02015-02-16 14:17:23 +00003289 * Result code for {@link #getStorageEncryptionStatus}:
3290 * indicating that encryption is active, but an encryption key has not
3291 * been set by the user.
3292 */
3293 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
3294
3295 /**
Makoto Onukid4c9e542016-02-25 18:17:30 -08003296 * Result code for {@link #getStorageEncryptionStatus}:
Amith Yamasani75db1252016-07-11 14:41:01 -07003297 * indicating that encryption is active and the encryption key is tied to the user or profile.
3298 * <p>
3299 * This value is only returned to apps targeting API level 24 and above. For apps targeting
3300 * earlier API levels, {@link #ENCRYPTION_STATUS_ACTIVE} is returned, even if the
3301 * encryption key is specific to the user or profile.
Makoto Onukid4c9e542016-02-25 18:17:30 -08003302 */
3303 public static final int ENCRYPTION_STATUS_ACTIVE_PER_USER = 5;
3304
3305 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003306 * Activity action: begin the process of encrypting data on the device. This activity should
3307 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
3308 * After resuming from this activity, use {@link #getStorageEncryption}
3309 * to check encryption status. However, on some devices this activity may never return, as
3310 * it may trigger a reboot and in some cases a complete data wipe of the device.
3311 */
3312 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
3313 public static final String ACTION_START_ENCRYPTION
3314 = "android.app.action.START_ENCRYPTION";
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003315 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07003316 * Widgets are enabled in keyguard
3317 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07003318 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07003319
3320 /**
Jim Miller50e62182014-04-23 17:25:00 -07003321 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07003322 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07003323 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
3324
3325 /**
3326 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
3327 */
3328 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
3329
3330 /**
Jim Miller50e62182014-04-23 17:25:00 -07003331 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
3332 */
3333 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
3334
3335 /**
3336 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
3337 */
3338 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
3339
3340 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02003341 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07003342 * (e.g. PIN/Pattern/Password).
3343 */
3344 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
3345
3346 /**
Jim Miller06e34502014-07-17 14:46:05 -07003347 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
3348 */
3349 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
3350
3351 /**
Adrian Roos7f06eed2016-02-05 15:21:02 -08003352 * Disable text entry into notifications on secure keyguard screens (e.g. PIN/Pattern/Password).
3353 */
3354 public static final int KEYGUARD_DISABLE_REMOTE_INPUT = 1 << 6;
3355
3356 /**
Jim Miller35207742012-11-02 15:33:20 -07003357 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07003358 */
3359 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07003360
3361 /**
Robin Leeacdeac62017-02-21 22:13:38 +00003362 * Keyguard features that when set on a managed profile that doesn't have its own challenge will
3363 * affect the profile's parent user. These can also be set on the managed profile's parent
3364 * {@link DevicePolicyManager} instance.
3365 *
3366 * @hide
3367 */
3368 public static final int PROFILE_KEYGUARD_FEATURES_AFFECT_OWNER =
3369 DevicePolicyManager.KEYGUARD_DISABLE_TRUST_AGENTS
3370 | DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT;
3371
3372 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003373 * Called by an application that is administering the device to request that the storage system
3374 * be encrypted.
3375 * <p>
3376 * When multiple device administrators attempt to control device encryption, the most secure,
3377 * supported setting will always be used. If any device administrator requests device
3378 * encryption, it will be enabled; Conversely, if a device administrator attempts to disable
3379 * device encryption while another device administrator has enabled it, the call to disable will
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003380 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003381 * <p>
3382 * This policy controls encryption of the secure (application data) storage area. Data written
3383 * to other storage areas may or may not be encrypted, and this policy does not require or
3384 * control the encryption of any other storage areas. There is one exception: If
3385 * {@link android.os.Environment#isExternalStorageEmulated()} is {@code true}, then the
3386 * directory returned by {@link android.os.Environment#getExternalStorageDirectory()} must be
3387 * written to disk within the encrypted storage area.
3388 * <p>
3389 * Important Note: On some devices, it is possible to encrypt storage without requiring the user
3390 * to create a device PIN or Password. In this case, the storage is encrypted, but the
3391 * encryption key may not be fully secured. For maximum security, the administrator should also
3392 * require (and check for) a pattern, PIN, or password.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003393 *
3394 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3395 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08003396 * @return the new request status (for all active admins) - will be one of
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003397 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
3398 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
3399 * {@link #getStorageEncryptionStatus()} to query the actual device state.
3400 * @throws SecurityException if {@code admin} is not an active administrator or does not use
3401 * {@link DeviceAdminInfo#USES_ENCRYPTED_STORAGE}
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003402 */
Robin Lee25e26452015-06-02 09:56:29 -07003403 public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003404 throwIfParentInstance("setStorageEncryption");
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003405 if (mService != null) {
3406 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003407 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003408 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003409 throw e.rethrowFromSystemServer();
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003410 }
3411 }
3412 return ENCRYPTION_STATUS_UNSUPPORTED;
3413 }
3414
3415 /**
3416 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08003417 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003418 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08003419 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
3420 * this will return the requested encryption setting as an aggregate of all active
3421 * administrators.
3422 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003423 */
Robin Lee25e26452015-06-02 09:56:29 -07003424 public boolean getStorageEncryption(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003425 throwIfParentInstance("getStorageEncryption");
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003426 if (mService != null) {
3427 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003428 return mService.getStorageEncryption(admin, myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003429 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003430 throw e.rethrowFromSystemServer();
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003431 }
3432 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08003433 return false;
3434 }
3435
3436 /**
3437 * Called by an application that is administering the device to
3438 * determine the current encryption status of the device.
Amith Yamasani75db1252016-07-11 14:41:01 -07003439 * <p>
Andy Stadler22dbfda2011-01-17 12:47:31 -08003440 * Depending on the returned status code, the caller may proceed in different
3441 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
3442 * storage system does not support encryption. If the
3443 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
3444 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00003445 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
3446 * storage system has enabled encryption but no password is set so further action
Amith Yamasani75db1252016-07-11 14:41:01 -07003447 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING},
3448 * {@link #ENCRYPTION_STATUS_ACTIVE} or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER},
3449 * no further action is required.
Andy Stadler22dbfda2011-01-17 12:47:31 -08003450 *
Robin Lee7e678712014-07-24 16:41:31 +01003451 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08003452 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00003453 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
Amith Yamasani75db1252016-07-11 14:41:01 -07003454 * {@link #ENCRYPTION_STATUS_ACTIVE}, or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08003455 */
3456 public int getStorageEncryptionStatus() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003457 throwIfParentInstance("getStorageEncryptionStatus");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003458 return getStorageEncryptionStatus(myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003459 }
3460
3461 /** @hide per-user version */
3462 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08003463 if (mService != null) {
3464 try {
Makoto Onukid4c9e542016-02-25 18:17:30 -08003465 return mService.getStorageEncryptionStatus(mContext.getPackageName(), userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08003466 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003467 throw e.rethrowFromSystemServer();
Andy Stadler22dbfda2011-01-17 12:47:31 -08003468 }
3469 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003470 return ENCRYPTION_STATUS_UNSUPPORTED;
3471 }
3472
3473 /**
Robin Lee2f7e1e42016-03-21 10:50:01 +00003474 * Mark a CA certificate as approved by the device user. This means that they have been notified
3475 * of the installation, were made aware of the risks, viewed the certificate and still wanted to
3476 * keep the certificate on the device.
3477 *
3478 * Calling with {@param approval} as {@code true} will cancel any ongoing warnings related to
3479 * this certificate.
3480 *
3481 * @hide
3482 */
3483 public boolean approveCaCert(String alias, int userHandle, boolean approval) {
3484 if (mService != null) {
3485 try {
3486 return mService.approveCaCert(alias, userHandle, approval);
3487 } catch (RemoteException e) {
3488 throw e.rethrowFromSystemServer();
3489 }
3490 }
3491 return false;
3492 }
3493
3494 /**
3495 * Check whether a CA certificate has been approved by the device user.
3496 *
3497 * @hide
3498 */
3499 public boolean isCaCertApproved(String alias, int userHandle) {
3500 if (mService != null) {
3501 try {
3502 return mService.isCaCertApproved(alias, userHandle);
3503 } catch (RemoteException e) {
3504 throw e.rethrowFromSystemServer();
3505 }
3506 }
3507 return false;
3508 }
3509
3510 /**
Robin Lee7e678712014-07-24 16:41:31 +01003511 * Installs the given certificate as a user CA.
3512 *
Edman Anjosf9946772016-11-28 16:35:15 +01003513 * The caller must be a profile or device owner on that user, or a delegate package given the
3514 * {@link #DELEGATION_CERT_INSTALL} scope via {@link #setDelegatedScopes}; otherwise a
3515 * security exception will be thrown.
3516 *
Robin Lee25e26452015-06-02 09:56:29 -07003517 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3518 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003519 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04003520 *
3521 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01003522 * interrupted, true otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003523 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3524 * owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003525 * @see #setDelegatedScopes
3526 * @see #DELEGATION_CERT_INSTALL
Maggie Benthallda51e682013-08-08 22:35:44 -04003527 */
Robin Lee25e26452015-06-02 09:56:29 -07003528 public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003529 throwIfParentInstance("installCaCert");
Maggie Benthallda51e682013-08-08 22:35:44 -04003530 if (mService != null) {
3531 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003532 return mService.installCaCert(admin, mContext.getPackageName(), certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04003533 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003534 throw e.rethrowFromSystemServer();
Maggie Benthallda51e682013-08-08 22:35:44 -04003535 }
3536 }
3537 return false;
3538 }
3539
3540 /**
Robin Lee7e678712014-07-24 16:41:31 +01003541 * Uninstalls the given certificate from trusted user CAs, if present.
3542 *
Edman Anjosf9946772016-11-28 16:35:15 +01003543 * The caller must be a profile or device owner on that user, or a delegate package given the
3544 * {@link #DELEGATION_CERT_INSTALL} scope via {@link #setDelegatedScopes}; otherwise a
3545 * security exception will be thrown.
3546 *
Robin Lee25e26452015-06-02 09:56:29 -07003547 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3548 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003549 * @param certBuffer encoded form of the certificate to remove.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003550 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3551 * owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003552 * @see #setDelegatedScopes
3553 * @see #DELEGATION_CERT_INSTALL
Maggie Benthallda51e682013-08-08 22:35:44 -04003554 */
Robin Lee25e26452015-06-02 09:56:29 -07003555 public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003556 throwIfParentInstance("uninstallCaCert");
Maggie Benthallda51e682013-08-08 22:35:44 -04003557 if (mService != null) {
3558 try {
Robin Lee306fe082014-06-19 14:04:24 +00003559 final String alias = getCaCertAlias(certBuffer);
Edman Anjosf9946772016-11-28 16:35:15 +01003560 mService.uninstallCaCerts(admin, mContext.getPackageName(), new String[] {alias});
Robin Lee306fe082014-06-19 14:04:24 +00003561 } catch (CertificateException e) {
3562 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04003563 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003564 throw e.rethrowFromSystemServer();
Maggie Benthallda51e682013-08-08 22:35:44 -04003565 }
3566 }
3567 }
3568
3569 /**
Robin Lee7e678712014-07-24 16:41:31 +01003570 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
3571 * If a user has installed any certificates by other means than device policy these will be
3572 * included too.
3573 *
Robin Lee25e26452015-06-02 09:56:29 -07003574 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3575 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003576 * @return a List of byte[] arrays, each encoding one user CA certificate.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003577 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3578 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04003579 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003580 public @NonNull List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) {
3581 final List<byte[]> certs = new ArrayList<byte[]>();
Benjamin Franzbc33c822016-04-15 08:57:52 +01003582 throwIfParentInstance("getInstalledCaCerts");
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003583 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01003584 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003585 mService.enforceCanManageCaCerts(admin, mContext.getPackageName());
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003586 final TrustedCertificateStore certStore = new TrustedCertificateStore();
3587 for (String alias : certStore.userAliases()) {
3588 try {
3589 certs.add(certStore.getCertificate(alias).getEncoded());
3590 } catch (CertificateException ce) {
3591 Log.w(TAG, "Could not encode certificate: " + alias, ce);
3592 }
3593 }
3594 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003595 throw re.rethrowFromSystemServer();
Robin Lee7e678712014-07-24 16:41:31 +01003596 }
3597 }
3598 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04003599 }
3600
3601 /**
Robin Lee7e678712014-07-24 16:41:31 +01003602 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
3603 * means other than device policy will also be removed, except for system CA certificates.
3604 *
Robin Lee25e26452015-06-02 09:56:29 -07003605 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3606 * {@code null} if calling from a delegated certificate installer.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003607 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3608 * owner.
Robin Lee7e678712014-07-24 16:41:31 +01003609 */
Robin Lee25e26452015-06-02 09:56:29 -07003610 public void uninstallAllUserCaCerts(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003611 throwIfParentInstance("uninstallAllUserCaCerts");
Robin Lee7e678712014-07-24 16:41:31 +01003612 if (mService != null) {
Robin Lee83881bd2015-06-09 16:04:38 -07003613 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003614 mService.uninstallCaCerts(admin, mContext.getPackageName(),
3615 new TrustedCertificateStore().userAliases() .toArray(new String[0]));
Robin Lee83881bd2015-06-09 16:04:38 -07003616 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003617 throw re.rethrowFromSystemServer();
Robin Lee7e678712014-07-24 16:41:31 +01003618 }
3619 }
3620 }
3621
3622 /**
3623 * Returns whether this certificate is installed as a trusted CA.
3624 *
Robin Lee25e26452015-06-02 09:56:29 -07003625 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3626 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003627 * @param certBuffer encoded form of the certificate to look up.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003628 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3629 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04003630 */
Robin Lee25e26452015-06-02 09:56:29 -07003631 public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003632 throwIfParentInstance("hasCaCertInstalled");
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003633 if (mService != null) {
3634 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003635 mService.enforceCanManageCaCerts(admin, mContext.getPackageName());
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003636 return getCaCertAlias(certBuffer) != null;
3637 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003638 throw re.rethrowFromSystemServer();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003639 } catch (CertificateException ce) {
3640 Log.w(TAG, "Could not parse certificate", ce);
3641 }
Maggie Benthallda51e682013-08-08 22:35:44 -04003642 }
3643 return false;
3644 }
3645
3646 /**
Robin Leece3399f2016-02-24 12:08:32 +00003647 * Called by a device or profile owner, or delegated certificate installer, to install a
3648 * certificate and corresponding private key. All apps within the profile will be able to access
3649 * the certificate and use the private key, given direct user approval.
3650 *
3651 * <p>Access to the installed credentials will not be granted to the caller of this API without
3652 * direct user approval. This is for security - should a certificate installer become
3653 * compromised, certificates it had already installed will be protected.
3654 *
3655 * <p>If the installer must have access to the credentials, call
Rubin Xub4365912016-03-23 12:13:22 +00003656 * {@link #installKeyPair(ComponentName, PrivateKey, Certificate[], String, boolean)} instead.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003657 *
Robin Lee25e26452015-06-02 09:56:29 -07003658 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3659 * {@code null} if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003660 * @param privKey The private key to install.
3661 * @param cert The certificate to install.
3662 * @param alias The private key alias under which to install the certificate. If a certificate
3663 * with that alias already exists, it will be overwritten.
3664 * @return {@code true} if the keys were installed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003665 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3666 * owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003667 * @see #setDelegatedScopes
3668 * @see #DELEGATION_CERT_INSTALL
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003669 */
Robin Leefbc65642015-08-03 16:21:22 +01003670 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
3671 @NonNull Certificate cert, @NonNull String alias) {
Rubin Xub4365912016-03-23 12:13:22 +00003672 return installKeyPair(admin, privKey, new Certificate[] {cert}, alias, false);
Robin Leece3399f2016-02-24 12:08:32 +00003673 }
3674
3675 /**
3676 * Called by a device or profile owner, or delegated certificate installer, to install a
Rubin Xub4365912016-03-23 12:13:22 +00003677 * certificate chain and corresponding private key for the leaf certificate. All apps within the
3678 * profile will be able to access the certificate chain and use the private key, given direct
3679 * user approval.
Robin Leece3399f2016-02-24 12:08:32 +00003680 *
Robin Leea1b290e2016-03-09 14:38:36 +00003681 * <p>The caller of this API may grant itself access to the certificate and private key
3682 * immediately, without user approval. It is a best practice not to request this unless strictly
3683 * necessary since it opens up additional security vulnerabilities.
Robin Leece3399f2016-02-24 12:08:32 +00003684 *
3685 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Robin Leea1b290e2016-03-09 14:38:36 +00003686 * {@code null} if calling from a delegated certificate installer.
Robin Leece3399f2016-02-24 12:08:32 +00003687 * @param privKey The private key to install.
Rubin Xub4365912016-03-23 12:13:22 +00003688 * @param certs The certificate chain to install. The chain should start with the leaf
3689 * certificate and include the chain of trust in order. This will be returned by
3690 * {@link android.security.KeyChain#getCertificateChain}.
Robin Leece3399f2016-02-24 12:08:32 +00003691 * @param alias The private key alias under which to install the certificate. If a certificate
Robin Leea1b290e2016-03-09 14:38:36 +00003692 * with that alias already exists, it will be overwritten.
Robin Leece3399f2016-02-24 12:08:32 +00003693 * @param requestAccess {@code true} to request that the calling app be granted access to the
Robin Leea1b290e2016-03-09 14:38:36 +00003694 * credentials immediately. Otherwise, access to the credentials will be gated by user
3695 * approval.
Robin Leece3399f2016-02-24 12:08:32 +00003696 * @return {@code true} if the keys were installed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003697 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3698 * owner.
Rubin Xub4365912016-03-23 12:13:22 +00003699 * @see android.security.KeyChain#getCertificateChain
Edman Anjosf9946772016-11-28 16:35:15 +01003700 * @see #setDelegatedScopes
3701 * @see #DELEGATION_CERT_INSTALL
Robin Leece3399f2016-02-24 12:08:32 +00003702 */
3703 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
Rubin Xub4365912016-03-23 12:13:22 +00003704 @NonNull Certificate[] certs, @NonNull String alias, boolean requestAccess) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003705 throwIfParentInstance("installKeyPair");
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003706 try {
Rubin Xub4365912016-03-23 12:13:22 +00003707 final byte[] pemCert = Credentials.convertToPem(certs[0]);
3708 byte[] pemChain = null;
3709 if (certs.length > 1) {
3710 pemChain = Credentials.convertToPem(Arrays.copyOfRange(certs, 1, certs.length));
3711 }
Robin Lee0d5ccb72014-09-12 17:41:44 +01003712 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
3713 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
Edman Anjosf9946772016-11-28 16:35:15 +01003714 return mService.installKeyPair(admin, mContext.getPackageName(), pkcs8Key, pemCert,
3715 pemChain, alias, requestAccess);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003716 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003717 throw e.rethrowFromSystemServer();
Robin Lee0d5ccb72014-09-12 17:41:44 +01003718 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
3719 Log.w(TAG, "Failed to obtain private key material", e);
3720 } catch (CertificateException | IOException e) {
3721 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003722 }
3723 return false;
3724 }
3725
3726 /**
Robin Leea1b290e2016-03-09 14:38:36 +00003727 * Called by a device or profile owner, or delegated certificate installer, to remove a
3728 * certificate and private key pair installed under a given alias.
Robin Leefbc65642015-08-03 16:21:22 +01003729 *
3730 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Robin Leea1b290e2016-03-09 14:38:36 +00003731 * {@code null} if calling from a delegated certificate installer.
Robin Leefbc65642015-08-03 16:21:22 +01003732 * @param alias The private key alias under which the certificate is installed.
Robin Leea1b290e2016-03-09 14:38:36 +00003733 * @return {@code true} if the private key alias no longer exists, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003734 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3735 * owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003736 * @see #setDelegatedScopes
3737 * @see #DELEGATION_CERT_INSTALL
Robin Leefbc65642015-08-03 16:21:22 +01003738 */
3739 public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003740 throwIfParentInstance("removeKeyPair");
Robin Leefbc65642015-08-03 16:21:22 +01003741 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003742 return mService.removeKeyPair(admin, mContext.getPackageName(), alias);
Robin Leefbc65642015-08-03 16:21:22 +01003743 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003744 throw e.rethrowFromSystemServer();
Robin Leefbc65642015-08-03 16:21:22 +01003745 }
Robin Leefbc65642015-08-03 16:21:22 +01003746 }
3747
3748 /**
Robin Lee25e26452015-06-02 09:56:29 -07003749 * @return the alias of a given CA certificate in the certificate store, or {@code null} if it
Robin Lee306fe082014-06-19 14:04:24 +00003750 * doesn't exist.
3751 */
3752 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
3753 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
3754 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
3755 new ByteArrayInputStream(certBuffer));
3756 return new TrustedCertificateStore().getCertificateAlias(cert);
3757 }
3758
3759 /**
Rubin Xuec32b562015-03-03 17:34:05 +00003760 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01003761 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00003762 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01003763 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00003764 * <p>
3765 * Delegated certificate installer is a per-user state. The delegated access is persistent until
3766 * it is later cleared by calling this method with a null value or uninstallling the certificate
3767 * installer.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003768 * <p>
Rubin Xuf03d0a62016-02-10 14:54:15 +00003769 * <b>Note:</b>Starting from {@link android.os.Build.VERSION_CODES#N}, if the caller
3770 * application's target SDK version is {@link android.os.Build.VERSION_CODES#N} or newer, the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003771 * supplied certificate installer package must be installed when calling this API, otherwise an
3772 * {@link IllegalArgumentException} will be thrown.
Rubin Xuec32b562015-03-03 17:34:05 +00003773 *
Robin Lee25e26452015-06-02 09:56:29 -07003774 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xuec32b562015-03-03 17:34:05 +00003775 * @param installerPackage The package name of the certificate installer which will be given
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003776 * access. If {@code null} is given the current package will be cleared.
3777 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003778 *
3779 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #setDelegatedScopes}
3780 * with the {@link #DELEGATION_CERT_INSTALL} scope instead.
Rubin Xuec32b562015-03-03 17:34:05 +00003781 */
Edman Anjosf9946772016-11-28 16:35:15 +01003782 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07003783 public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String
3784 installerPackage) throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003785 throwIfParentInstance("setCertInstallerPackage");
Rubin Xuec32b562015-03-03 17:34:05 +00003786 if (mService != null) {
3787 try {
Robin Lee25e26452015-06-02 09:56:29 -07003788 mService.setCertInstallerPackage(admin, installerPackage);
Rubin Xuec32b562015-03-03 17:34:05 +00003789 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003790 throw e.rethrowFromSystemServer();
Rubin Xuec32b562015-03-03 17:34:05 +00003791 }
3792 }
3793 }
3794
3795 /**
Edman Anjosf9946772016-11-28 16:35:15 +01003796 * Called by a profile owner or device owner to retrieve the certificate installer for the user,
3797 * or {@code null} if none is set. If there are multiple delegates this function will return one
3798 * of them.
Rubin Xuec32b562015-03-03 17:34:05 +00003799 *
Robin Lee25e26452015-06-02 09:56:29 -07003800 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003801 * @return The package name of the current delegated certificate installer, or {@code null} if
3802 * none is set.
3803 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003804 *
3805 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatePackages}
3806 * with the {@link #DELEGATION_CERT_INSTALL} scope instead.
Rubin Xuec32b562015-03-03 17:34:05 +00003807 */
Edman Anjosf9946772016-11-28 16:35:15 +01003808 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07003809 public @Nullable String getCertInstallerPackage(@NonNull ComponentName admin)
3810 throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003811 throwIfParentInstance("getCertInstallerPackage");
Rubin Xuec32b562015-03-03 17:34:05 +00003812 if (mService != null) {
3813 try {
Robin Lee25e26452015-06-02 09:56:29 -07003814 return mService.getCertInstallerPackage(admin);
Rubin Xuec32b562015-03-03 17:34:05 +00003815 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003816 throw e.rethrowFromSystemServer();
Rubin Xuec32b562015-03-03 17:34:05 +00003817 }
3818 }
3819 return null;
3820 }
3821
3822 /**
Edman Anjosf9946772016-11-28 16:35:15 +01003823 * Called by a profile owner or device owner to grant access to privileged APIs to another app.
3824 * Granted APIs are determined by {@code scopes}, which is a list of the {@code DELEGATION_*}
3825 * constants.
3826 * <p>
Edman Anjos9e62c312017-01-26 22:22:58 +01003827 * A broadcast with the {@link #ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED} action will be
3828 * sent to the {@code delegatePackage} with its new scopes in an {@code ArrayList<String>} extra
3829 * under the {@link #EXTRA_DELEGATION_SCOPES} key. The broadcast is sent with the
3830 * {@link Intent#FLAG_RECEIVER_REGISTERED_ONLY} flag.
3831 * <p>
Edman Anjosf9946772016-11-28 16:35:15 +01003832 * Delegated scopes are a per-user state. The delegated access is persistent until it is later
3833 * cleared by calling this method with an empty {@code scopes} list or uninstalling the
3834 * {@code delegatePackage}.
3835 *
3836 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3837 * @param delegatePackage The package name of the app which will be given access.
3838 * @param scopes The groups of privileged APIs whose access should be granted to
3839 * {@code delegatedPackage}.
3840 * @throws SecurityException if {@code admin} is not a device or a profile owner.
3841 */
3842 public void setDelegatedScopes(@NonNull ComponentName admin, @NonNull String delegatePackage,
3843 @NonNull List<String> scopes) {
3844 throwIfParentInstance("setDelegatedScopes");
3845 if (mService != null) {
3846 try {
3847 mService.setDelegatedScopes(admin, delegatePackage, scopes);
3848 } catch (RemoteException e) {
3849 throw e.rethrowFromSystemServer();
3850 }
3851 }
3852 }
3853
3854 /**
3855 * Called by a profile owner or device owner to retrieve a list of the scopes given to a
3856 * delegate package. Other apps can use this method to retrieve their own delegated scopes by
3857 * passing {@code null} for {@code admin} and their own package name as
3858 * {@code delegatedPackage}.
3859 *
3860 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3861 * {@code null} if the caller is {@code delegatedPackage}.
3862 * @param delegatedPackage The package name of the app whose scopes should be retrieved.
3863 * @return A list containing the scopes given to {@code delegatedPackage}.
3864 * @throws SecurityException if {@code admin} is not a device or a profile owner.
3865 */
3866 @NonNull
Edman Anjos9e62c312017-01-26 22:22:58 +01003867 public List<String> getDelegatedScopes(@Nullable ComponentName admin,
Edman Anjosf9946772016-11-28 16:35:15 +01003868 @NonNull String delegatedPackage) {
3869 throwIfParentInstance("getDelegatedScopes");
3870 if (mService != null) {
3871 try {
3872 return mService.getDelegatedScopes(admin, delegatedPackage);
3873 } catch (RemoteException e) {
3874 throw e.rethrowFromSystemServer();
3875 }
3876 }
3877 return null;
3878 }
3879
3880 /**
3881 * Called by a profile owner or device owner to retrieve a list of delegate packages that were
3882 * granted a delegation scope.
3883 *
3884 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3885 * @param delegationScope The scope whose delegates should be retrieved.
3886 * @return A list of package names of the current delegated packages for
3887 {@code delegationScope}.
3888 * @throws SecurityException if {@code admin} is not a device or a profile owner.
3889 */
3890 @Nullable
3891 public List<String> getDelegatePackages(@NonNull ComponentName admin,
3892 @NonNull String delegationScope) {
3893 throwIfParentInstance("getDelegatePackages");
3894 if (mService != null) {
3895 try {
3896 return mService.getDelegatePackages(admin, delegationScope);
3897 } catch (RemoteException e) {
3898 throw e.rethrowFromSystemServer();
3899 }
3900 }
3901 return null;
3902 }
3903
3904 /**
Robin Lee244ce8e2016-01-05 18:03:46 +00003905 * Called by a device or profile owner to configure an always-on VPN connection through a
Robin Leedc679712016-05-03 13:23:03 +01003906 * specific application for the current user.
3907 *
3908 * @deprecated this version only exists for compability with previous developer preview builds.
3909 * TODO: delete once there are no longer any live references.
3910 * @hide
3911 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07003912 @Deprecated
Robin Leedc679712016-05-03 13:23:03 +01003913 public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage)
3914 throws NameNotFoundException, UnsupportedOperationException {
3915 setAlwaysOnVpnPackage(admin, vpnPackage, /* lockdownEnabled */ true);
3916 }
3917
3918 /**
3919 * Called by a device or profile owner to configure an always-on VPN connection through a
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003920 * specific application for the current user. This connection is automatically granted and
3921 * persisted after a reboot.
3922 * <p>
3923 * The designated package should declare a {@link android.net.VpnService} in its manifest
3924 * guarded by {@link android.Manifest.permission#BIND_VPN_SERVICE}, otherwise the call will
3925 * fail.
Robin Lee244ce8e2016-01-05 18:03:46 +00003926 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003927 * @param vpnPackage The package name for an installed VPN app on the device, or {@code null} to
Robin Leedc679712016-05-03 13:23:03 +01003928 * remove an existing always-on VPN configuration.
3929 * @param lockdownEnabled {@code true} to disallow networking when the VPN is not connected or
3930 * {@code false} otherwise. This carries the risk that any failure of the VPN provider
3931 * could break networking for all apps. This has no effect when clearing.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003932 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Robin Leeee5eb932016-04-05 16:27:15 +01003933 * @throws NameNotFoundException if {@code vpnPackage} is not installed.
3934 * @throws UnsupportedOperationException if {@code vpnPackage} exists but does not support being
3935 * set as always-on, or if always-on VPN is not available.
Robin Lee244ce8e2016-01-05 18:03:46 +00003936 */
Robin Leedc679712016-05-03 13:23:03 +01003937 public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage,
3938 boolean lockdownEnabled)
Robin Leeee5eb932016-04-05 16:27:15 +01003939 throws NameNotFoundException, UnsupportedOperationException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003940 throwIfParentInstance("setAlwaysOnVpnPackage");
Robin Lee244ce8e2016-01-05 18:03:46 +00003941 if (mService != null) {
3942 try {
Robin Leedc679712016-05-03 13:23:03 +01003943 if (!mService.setAlwaysOnVpnPackage(admin, vpnPackage, lockdownEnabled)) {
Robin Leeee5eb932016-04-05 16:27:15 +01003944 throw new NameNotFoundException(vpnPackage);
3945 }
Robin Lee244ce8e2016-01-05 18:03:46 +00003946 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003947 throw e.rethrowFromSystemServer();
Robin Lee244ce8e2016-01-05 18:03:46 +00003948 }
3949 }
Robin Lee244ce8e2016-01-05 18:03:46 +00003950 }
3951
3952 /**
3953 * Called by a device or profile owner to read the name of the package administering an
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003954 * always-on VPN connection for the current user. If there is no such package, or the always-on
3955 * VPN is provided by the system instead of by an application, {@code null} will be returned.
Robin Lee244ce8e2016-01-05 18:03:46 +00003956 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003957 * @return Package name of VPN controller responsible for always-on VPN, or {@code null} if none
3958 * is set.
3959 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Robin Lee244ce8e2016-01-05 18:03:46 +00003960 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003961 public @Nullable String getAlwaysOnVpnPackage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003962 throwIfParentInstance("getAlwaysOnVpnPackage");
Robin Lee244ce8e2016-01-05 18:03:46 +00003963 if (mService != null) {
3964 try {
3965 return mService.getAlwaysOnVpnPackage(admin);
3966 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003967 throw e.rethrowFromSystemServer();
Robin Lee244ce8e2016-01-05 18:03:46 +00003968 }
3969 }
3970 return null;
3971 }
3972
3973 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003974 * Called by an application that is administering the device to disable all cameras on the
3975 * device, for this user. After setting this, no applications running as this user will be able
3976 * to access any cameras on the device.
3977 * <p>
3978 * If the caller is device owner, then the restriction will be applied to all users.
3979 * <p>
3980 * The calling device admin must have requested
3981 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call this method; if it has
3982 * not, a security exception will be thrown.
Ben Komalo2447edd2011-05-09 16:05:33 -07003983 *
3984 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3985 * @param disabled Whether or not the camera should be disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003986 * @throws SecurityException if {@code admin} is not an active administrator or does not use
3987 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA}.
Ben Komalo2447edd2011-05-09 16:05:33 -07003988 */
Robin Lee25e26452015-06-02 09:56:29 -07003989 public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003990 throwIfParentInstance("setCameraDisabled");
Ben Komalo2447edd2011-05-09 16:05:33 -07003991 if (mService != null) {
3992 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003993 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07003994 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003995 throw e.rethrowFromSystemServer();
Ben Komalo2447edd2011-05-09 16:05:33 -07003996 }
3997 }
3998 }
3999
4000 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07004001 * Determine whether or not the device's cameras have been disabled for this user,
Makoto Onuki32b30572015-12-11 14:29:51 -08004002 * either by the calling admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07004003 * @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 -07004004 * have disabled the camera
4005 */
Robin Lee25e26452015-06-02 09:56:29 -07004006 public boolean getCameraDisabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004007 throwIfParentInstance("getCameraDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004008 return getCameraDisabled(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004009 }
4010
4011 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07004012 public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07004013 if (mService != null) {
4014 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004015 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07004016 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004017 throw e.rethrowFromSystemServer();
Ben Komalo2447edd2011-05-09 16:05:33 -07004018 }
4019 }
4020 return false;
4021 }
4022
4023 /**
Michal Karpinski3fc437e2015-12-15 10:09:00 +00004024 * Called by a device owner to request a bugreport.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004025 * <p>
Esteban Talaverad36dd152016-12-15 08:51:45 +00004026 * If the device contains secondary users or profiles, they must be affiliated with the device
4027 * owner user. Otherwise a {@link SecurityException} will be thrown. See
4028 * {@link #setAffiliationIds}.
Michal Karpinski3fc437e2015-12-15 10:09:00 +00004029 *
4030 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004031 * @return {@code true} if the bugreport collection started successfully, or {@code false} if it
4032 * wasn't triggered because a previous bugreport operation is still active (either the
4033 * bugreport is still running or waiting for the user to share or decline)
Esteban Talaverad36dd152016-12-15 08:51:45 +00004034 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
4035 * profile or secondary user that is not affiliated with the device owner user.
Michal Karpinski3fc437e2015-12-15 10:09:00 +00004036 */
4037 public boolean requestBugreport(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004038 throwIfParentInstance("requestBugreport");
Michal Karpinski3fc437e2015-12-15 10:09:00 +00004039 if (mService != null) {
4040 try {
4041 return mService.requestBugreport(admin);
4042 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004043 throw e.rethrowFromSystemServer();
Michal Karpinski3fc437e2015-12-15 10:09:00 +00004044 }
4045 }
4046 return false;
4047 }
4048
4049 /**
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07004050 * Determine whether or not creating a guest user has been disabled for the device
4051 *
4052 * @hide
4053 */
4054 public boolean getGuestUserDisabled(@Nullable ComponentName admin) {
4055 // Currently guest users can always be created if multi-user is enabled
4056 // TODO introduce a policy for guest user creation
4057 return false;
4058 }
4059
4060 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01004061 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
4062 * screen capture also prevents the content from being shown on display devices that do not have
4063 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
4064 * secure surfaces and secure displays.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004065 * <p>
4066 * The calling device admin must be a device or profile owner. If it is not, a security
4067 * exception will be thrown.
4068 * <p>
4069 * From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also blocks
4070 * assist requests for all activities of the relevant user.
Benjamin Franzc200f442015-06-25 18:20:04 +01004071 *
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004072 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004073 * @param disabled Whether screen capture is disabled or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004074 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004075 */
Robin Lee25e26452015-06-02 09:56:29 -07004076 public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004077 throwIfParentInstance("setScreenCaptureDisabled");
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004078 if (mService != null) {
4079 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08004080 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004081 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004082 throw e.rethrowFromSystemServer();
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004083 }
4084 }
4085 }
4086
4087 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004088 * Determine whether or not screen capture has been disabled by the calling
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004089 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07004090 * @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 +01004091 * have disabled screen capture.
4092 */
Robin Lee25e26452015-06-02 09:56:29 -07004093 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004094 throwIfParentInstance("getScreenCaptureDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004095 return getScreenCaptureDisabled(admin, myUserId());
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004096 }
4097
4098 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07004099 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004100 if (mService != null) {
4101 try {
4102 return mService.getScreenCaptureDisabled(admin, userHandle);
4103 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004104 throw e.rethrowFromSystemServer();
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004105 }
4106 }
4107 return false;
4108 }
4109
4110 /**
Jason Parks841cb0a2017-01-17 15:25:17 -06004111 * Called by a device or profile owner to set whether auto time is required. If auto time is
4112 * 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 -07004113 * <p>
4114 * Note: if auto time is required the user can still manually set the time zone.
4115 * <p>
Jason Parks841cb0a2017-01-17 15:25:17 -06004116 * The calling device admin must be a device or profile owner. If it is not, a security
4117 * exception will be thrown.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004118 *
4119 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4120 * @param required Whether auto time is set required or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004121 * @throws SecurityException if {@code admin} is not a device owner.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004122 */
Robin Lee25e26452015-06-02 09:56:29 -07004123 public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004124 throwIfParentInstance("setAutoTimeRequired");
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004125 if (mService != null) {
4126 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08004127 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004128 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004129 throw e.rethrowFromSystemServer();
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004130 }
4131 }
4132 }
4133
4134 /**
4135 * @return true if auto time is required.
4136 */
4137 public boolean getAutoTimeRequired() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004138 throwIfParentInstance("getAutoTimeRequired");
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004139 if (mService != null) {
4140 try {
4141 return mService.getAutoTimeRequired();
4142 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004143 throw e.rethrowFromSystemServer();
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004144 }
4145 }
4146 return false;
4147 }
4148
4149 /**
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004150 * Called by a device owner to set whether all users created on the device should be ephemeral.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004151 * <p>
4152 * The system user is exempt from this policy - it is never ephemeral.
4153 * <p>
4154 * The calling device admin must be the device owner. If it is not, a security exception will be
4155 * thrown.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004156 *
4157 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4158 * @param forceEphemeralUsers If true, all the existing users will be deleted and all
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004159 * subsequently created users will be ephemeral.
4160 * @throws SecurityException if {@code admin} is not a device owner.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004161 * @hide
4162 */
4163 public void setForceEphemeralUsers(
4164 @NonNull ComponentName admin, boolean forceEphemeralUsers) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004165 throwIfParentInstance("setForceEphemeralUsers");
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004166 if (mService != null) {
4167 try {
4168 mService.setForceEphemeralUsers(admin, forceEphemeralUsers);
4169 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004170 throw e.rethrowFromSystemServer();
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004171 }
4172 }
4173 }
4174
4175 /**
4176 * @return true if all users are created ephemeral.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004177 * @throws SecurityException if {@code admin} is not a device owner.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004178 * @hide
4179 */
4180 public boolean getForceEphemeralUsers(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004181 throwIfParentInstance("getForceEphemeralUsers");
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004182 if (mService != null) {
4183 try {
4184 return mService.getForceEphemeralUsers(admin);
4185 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004186 throw e.rethrowFromSystemServer();
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004187 }
4188 }
4189 return false;
4190 }
4191
4192 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07004193 * Called by an application that is administering the device to disable keyguard customizations,
4194 * such as widgets. After setting this, keyguard features will be disabled according to the
4195 * provided feature list.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004196 * <p>
4197 * The calling device admin must have requested
4198 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method;
4199 * if it has not, a security exception will be thrown.
4200 * <p>
4201 * Calling this from a managed profile before version {@link android.os.Build.VERSION_CODES#M}
4202 * will throw a security exception. From version {@link android.os.Build.VERSION_CODES#M} the
4203 * profile owner of a managed profile can set:
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00004204 * <ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00004205 * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which affects the parent user, but only if there
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004206 * is no separate challenge set on the managed profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00004207 * <li>{@link #KEYGUARD_DISABLE_FINGERPRINT} which affects the managed profile challenge if
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004208 * there is one, or the parent user otherwise.
4209 * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} which affects notifications generated
4210 * by applications in the managed profile.
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00004211 * </ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00004212 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} and {@link #KEYGUARD_DISABLE_FINGERPRINT} can also be
4213 * set on the {@link DevicePolicyManager} instance returned by
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004214 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
4215 * profile.
4216 * <p>
4217 * Requests to disable other features on a managed profile will be ignored.
4218 * <p>
4219 * The admin can check which features have been disabled by calling
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00004220 * {@link #getKeyguardDisabledFeatures(ComponentName)}
Amith Yamasani242f4b12014-10-14 16:06:13 -07004221 *
Jim Millerb8ec4702012-08-31 17:19:10 -07004222 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07004223 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004224 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
4225 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS},
4226 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
4227 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS},
4228 * {@link #KEYGUARD_DISABLE_FINGERPRINT}, {@link #KEYGUARD_DISABLE_FEATURES_ALL}
4229 * @throws SecurityException if {@code admin} is not an active administrator or does not user
4230 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES}
Jim Millerb8ec4702012-08-31 17:19:10 -07004231 */
Robin Lee25e26452015-06-02 09:56:29 -07004232 public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07004233 if (mService != null) {
4234 try {
Esteban Talavera62399912016-01-11 15:37:55 +00004235 mService.setKeyguardDisabledFeatures(admin, which, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07004236 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004237 throw e.rethrowFromSystemServer();
Jim Millerb8ec4702012-08-31 17:19:10 -07004238 }
4239 }
4240 }
4241
4242 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004243 * Determine whether or not features have been disabled in keyguard either by the calling
Rubin Xud3609d42016-07-13 18:32:57 +01004244 * admin, if specified, or all admins that set restrictions on this user and its participating
Esteban Talaverac1c83592016-02-17 17:56:15 +00004245 * profiles. Restrictions on profiles that have a separate challenge are not taken into account.
4246 *
4247 * <p>This method can be called on the {@link DevicePolicyManager} instance
4248 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
4249 * restrictions on the parent profile.
4250 *
Esteban Talavera62399912016-01-11 15:37:55 +00004251 * @param admin The name of the admin component to check, or {@code null} to check whether any
4252 * admins have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07004253 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
4254 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07004255 */
Robin Lee25e26452015-06-02 09:56:29 -07004256 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004257 return getKeyguardDisabledFeatures(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004258 }
4259
4260 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07004261 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07004262 if (mService != null) {
4263 try {
Esteban Talavera62399912016-01-11 15:37:55 +00004264 return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07004265 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004266 throw e.rethrowFromSystemServer();
Jim Millerb8ec4702012-08-31 17:19:10 -07004267 }
4268 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07004269 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07004270 }
4271
4272 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08004273 * @hide
4274 */
Robin Lee25e26452015-06-02 09:56:29 -07004275 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
4276 int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08004277 if (mService != null) {
4278 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01004279 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08004280 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004281 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08004282 }
4283 }
4284 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07004285
Dianne Hackbornd6847842010-01-12 18:14:19 -08004286 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01004287 * @hide
4288 */
Robin Lee25e26452015-06-02 09:56:29 -07004289 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004290 setActiveAdmin(policyReceiver, refreshing, myUserId());
Jessica Hummel6d36b602014-04-04 12:42:17 +01004291 }
4292
4293 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08004294 * @hide
4295 */
Robin Lee25e26452015-06-02 09:56:29 -07004296 public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08004297 if (mService != null) {
4298 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004299 mService.getRemoveWarning(admin, result, myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08004300 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004301 throw e.rethrowFromSystemServer();
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08004302 }
4303 }
4304 }
4305
4306 /**
4307 * @hide
4308 */
Andrew Scull5f9e6f32016-08-02 14:22:17 +01004309 public void setActivePasswordState(PasswordMetrics metrics, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08004310 if (mService != null) {
4311 try {
Andrew Scull5f9e6f32016-08-02 14:22:17 +01004312 mService.setActivePasswordState(metrics, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08004313 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004314 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08004315 }
4316 }
4317 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07004318
Dianne Hackbornd6847842010-01-12 18:14:19 -08004319 /**
4320 * @hide
4321 */
Andrew Scull5daf2732016-11-14 15:02:45 +00004322 public void reportPasswordChanged(@UserIdInt int userId) {
4323 if (mService != null) {
4324 try {
4325 mService.reportPasswordChanged(userId);
4326 } catch (RemoteException e) {
4327 throw e.rethrowFromSystemServer();
4328 }
4329 }
4330 }
4331
4332 /**
4333 * @hide
4334 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004335 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08004336 if (mService != null) {
4337 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004338 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08004339 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004340 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08004341 }
4342 }
4343 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07004344
Dianne Hackbornd6847842010-01-12 18:14:19 -08004345 /**
4346 * @hide
4347 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004348 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08004349 if (mService != null) {
4350 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004351 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08004352 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004353 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08004354 }
4355 }
4356 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07004357
4358 /**
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004359 * @hide
4360 */
4361 public void reportFailedFingerprintAttempt(int userHandle) {
4362 if (mService != null) {
4363 try {
4364 mService.reportFailedFingerprintAttempt(userHandle);
4365 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004366 throw e.rethrowFromSystemServer();
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004367 }
4368 }
4369 }
4370
4371 /**
4372 * @hide
4373 */
4374 public void reportSuccessfulFingerprintAttempt(int userHandle) {
4375 if (mService != null) {
4376 try {
4377 mService.reportSuccessfulFingerprintAttempt(userHandle);
4378 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004379 throw e.rethrowFromSystemServer();
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004380 }
4381 }
4382 }
4383
4384 /**
Michal Karpinski31502d32016-01-25 16:43:07 +00004385 * Should be called when keyguard has been dismissed.
4386 * @hide
4387 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004388 public void reportKeyguardDismissed(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00004389 if (mService != null) {
4390 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004391 mService.reportKeyguardDismissed(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00004392 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004393 throw e.rethrowFromSystemServer();
Michal Karpinski31502d32016-01-25 16:43:07 +00004394 }
4395 }
4396 }
4397
4398 /**
4399 * Should be called when keyguard view has been shown to the user.
4400 * @hide
4401 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004402 public void reportKeyguardSecured(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00004403 if (mService != null) {
4404 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004405 mService.reportKeyguardSecured(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00004406 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004407 throw e.rethrowFromSystemServer();
Michal Karpinski31502d32016-01-25 16:43:07 +00004408 }
4409 }
4410 }
4411
4412 /**
Amith Yamasani71e6c692013-03-24 17:39:28 -07004413 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00004414 * Sets the given package as the device owner.
Makoto Onukia52562c2015-10-01 16:12:31 -07004415 * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name.
4416 * @param who the component name to be registered as device owner.
Amith Yamasani71e6c692013-03-24 17:39:28 -07004417 * @return whether the package was successfully registered as the device owner.
4418 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00004419 * @throws IllegalStateException If the preconditions mentioned are not met.
Amith Yamasani71e6c692013-03-24 17:39:28 -07004420 */
Makoto Onukia52562c2015-10-01 16:12:31 -07004421 public boolean setDeviceOwner(ComponentName who) {
4422 return setDeviceOwner(who, null);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004423 }
4424
4425 /**
4426 * @hide
Makoto Onuki58b684f2015-09-04 10:48:16 -07004427 */
Makoto Onukia52562c2015-10-01 16:12:31 -07004428 public boolean setDeviceOwner(ComponentName who, int userId) {
4429 return setDeviceOwner(who, null, userId);
Makoto Onuki58b684f2015-09-04 10:48:16 -07004430 }
4431
4432 /**
4433 * @hide
4434 */
Makoto Onukia52562c2015-10-01 16:12:31 -07004435 public boolean setDeviceOwner(ComponentName who, String ownerName) {
4436 return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM);
Makoto Onuki58b684f2015-09-04 10:48:16 -07004437 }
4438
4439 /**
4440 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00004441 * Sets the given package as the device owner. The package must already be installed. There
4442 * must not already be a device owner.
4443 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
4444 * this method.
4445 * Calling this after the setup phase of the primary user has completed is allowed only if
4446 * the caller is the shell uid, and there are no additional users and no accounts.
Makoto Onukia52562c2015-10-01 16:12:31 -07004447 * @param who the component name to be registered as device owner.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004448 * @param ownerName the human readable name of the institution that owns this device.
Makoto Onuki58b684f2015-09-04 10:48:16 -07004449 * @param userId ID of the user on which the device owner runs.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004450 * @return whether the package was successfully registered as the device owner.
4451 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00004452 * @throws IllegalStateException If the preconditions mentioned are not met.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004453 */
Makoto Onukia52562c2015-10-01 16:12:31 -07004454 public boolean setDeviceOwner(ComponentName who, String ownerName, int userId)
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004455 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07004456 if (mService != null) {
4457 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07004458 return mService.setDeviceOwner(who, ownerName, userId);
Amith Yamasani71e6c692013-03-24 17:39:28 -07004459 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004460 throw re.rethrowFromSystemServer();
Amith Yamasani71e6c692013-03-24 17:39:28 -07004461 }
4462 }
4463 return false;
4464 }
4465
4466 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004467 * Used to determine if a particular package has been registered as a Device Owner app.
4468 * A device owner app is a special device admin that cannot be deactivated by the user, once
Robin Lee25e26452015-06-02 09:56:29 -07004469 * activated as a device admin. It also cannot be uninstalled. To check whether a particular
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004470 * package is currently registered as the device owner app, pass in the package name from
4471 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
Robin Lee25e26452015-06-02 09:56:29 -07004472 * admin apps that want to check whether they are also registered as the device owner app. The
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004473 * exact mechanism by which a device admin app is registered as a device owner app is defined by
4474 * the setup process.
4475 * @param packageName the package name of the app, to compare with the registered device owner
4476 * app, if any.
Makoto Onukic8a5a552015-11-19 14:29:12 -08004477 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07004478 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004479 public boolean isDeviceOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004480 throwIfParentInstance("isDeviceOwnerApp");
Makoto Onukic8a5a552015-11-19 14:29:12 -08004481 return isDeviceOwnerAppOnCallingUser(packageName);
4482 }
4483
4484 /**
4485 * @return true if a package is registered as device owner, only when it's running on the
4486 * calling user.
4487 *
4488 * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity.
4489 * @hide
4490 */
4491 public boolean isDeviceOwnerAppOnCallingUser(String packageName) {
4492 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true);
4493 }
4494
4495 /**
4496 * @return true if a package is registered as device owner, even if it's running on a different
4497 * user.
4498 *
4499 * <p>Requires the MANAGE_USERS permission.
4500 *
4501 * @hide
4502 */
4503 public boolean isDeviceOwnerAppOnAnyUser(String packageName) {
4504 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false);
4505 }
4506
4507 /**
4508 * @return device owner component name, only when it's running on the calling user.
4509 *
4510 * @hide
4511 */
4512 public ComponentName getDeviceOwnerComponentOnCallingUser() {
4513 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true);
4514 }
4515
4516 /**
4517 * @return device owner component name, even if it's running on a different user.
4518 *
4519 * <p>Requires the MANAGE_USERS permission.
4520 *
4521 * @hide
4522 */
Polina Bondarenko23561db2016-12-16 11:47:28 +01004523 @SystemApi
Makoto Onukic8a5a552015-11-19 14:29:12 -08004524 public ComponentName getDeviceOwnerComponentOnAnyUser() {
4525 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false);
4526 }
4527
4528 private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) {
Makoto Onuki70f929e2015-11-11 12:40:15 -08004529 if (packageName == null) {
4530 return false;
Amith Yamasani71e6c692013-03-24 17:39:28 -07004531 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08004532 final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly);
Makoto Onuki70f929e2015-11-11 12:40:15 -08004533 if (deviceOwner == null) {
4534 return false;
4535 }
4536 return packageName.equals(deviceOwner.getPackageName());
Amith Yamasani71e6c692013-03-24 17:39:28 -07004537 }
4538
Makoto Onukic8a5a552015-11-19 14:29:12 -08004539 private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) {
4540 if (mService != null) {
4541 try {
4542 return mService.getDeviceOwnerComponent(callingUserOnly);
4543 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004544 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08004545 }
4546 }
4547 return null;
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004548 }
4549
Jason Monkb0dced82014-06-06 14:36:20 -04004550 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08004551 * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's
4552 * no device owner.
4553 *
4554 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07004555 *
4556 * @hide
4557 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08004558 public int getDeviceOwnerUserId() {
4559 if (mService != null) {
4560 try {
4561 return mService.getDeviceOwnerUserId();
4562 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004563 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08004564 }
4565 }
4566 return UserHandle.USER_NULL;
Makoto Onukia52562c2015-10-01 16:12:31 -07004567 }
4568
4569 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004570 * Clears the current device owner. The caller must be the device owner. This function should be
4571 * 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 +00004572 * a part of device setup, before it completes.
4573 * <p>
4574 * While some policies previously set by the device owner will be cleared by this method, it is
4575 * a best-effort process and some other policies will still remain in place after the device
4576 * owner is cleared.
Jason Monk94d2cf92014-06-18 09:53:34 -04004577 *
4578 * @param packageName The package name of the device owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004579 * @throws SecurityException if the caller is not in {@code packageName} or {@code packageName}
4580 * does not own the current device owner component.
Esteban Talaveraa5b09632017-02-10 16:15:24 +00004581 *
4582 * @deprecated This method is expected to be used for testing purposes only. The device owner
4583 * will lose control of the device and its data after calling it. In order to protect any
4584 * sensitive data that remains on the device, it is advised that the device owner factory resets
4585 * the device instead of calling this method. See {@link #wipeData(int)}.
Jason Monkb0dced82014-06-06 14:36:20 -04004586 */
Esteban Talaveraa5b09632017-02-10 16:15:24 +00004587 @Deprecated
Jason Monk94d2cf92014-06-18 09:53:34 -04004588 public void clearDeviceOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004589 throwIfParentInstance("clearDeviceOwnerApp");
Jason Monkb0dced82014-06-06 14:36:20 -04004590 if (mService != null) {
4591 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04004592 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04004593 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004594 throw re.rethrowFromSystemServer();
Jason Monkb0dced82014-06-06 14:36:20 -04004595 }
4596 }
4597 }
4598
Makoto Onukia52562c2015-10-01 16:12:31 -07004599 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08004600 * Returns the device owner package name, only if it's running on the calling user.
4601 *
4602 * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity.
Makoto Onukia52562c2015-10-01 16:12:31 -07004603 *
4604 * @hide
4605 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01004606 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004607 public @Nullable String getDeviceOwner() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004608 throwIfParentInstance("getDeviceOwner");
Makoto Onukic8a5a552015-11-19 14:29:12 -08004609 final ComponentName name = getDeviceOwnerComponentOnCallingUser();
4610 return name != null ? name.getPackageName() : null;
Makoto Onukia52562c2015-10-01 16:12:31 -07004611 }
4612
4613 /**
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004614 * Called by the system to find out whether the device is managed by a Device Owner.
Makoto Onukic8a5a552015-11-19 14:29:12 -08004615 *
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004616 * @return whether the device is managed by a Device Owner.
4617 * @throws SecurityException if the caller is not the device owner, does not hold the
4618 * MANAGE_USERS permission and is not the system.
Makoto Onukia52562c2015-10-01 16:12:31 -07004619 *
4620 * @hide
4621 */
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004622 @SystemApi
4623 @TestApi
Makoto Onukic8a5a552015-11-19 14:29:12 -08004624 public boolean isDeviceManaged() {
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004625 try {
4626 return mService.hasDeviceOwner();
4627 } catch (RemoteException re) {
4628 throw re.rethrowFromSystemServer();
4629 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08004630 }
4631
4632 /**
4633 * Returns the device owner name. Note this method *will* return the device owner
4634 * name when it's running on a different user.
4635 *
4636 * <p>Requires the MANAGE_USERS permission.
4637 *
4638 * @hide
4639 */
Makoto Onukia2b274b2016-01-19 13:26:02 -08004640 @SystemApi
Makoto Onukic8a5a552015-11-19 14:29:12 -08004641 public String getDeviceOwnerNameOnAnyUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004642 throwIfParentInstance("getDeviceOwnerNameOnAnyUser");
Amith Yamasani71e6c692013-03-24 17:39:28 -07004643 if (mService != null) {
4644 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07004645 return mService.getDeviceOwnerName();
Amith Yamasani71e6c692013-03-24 17:39:28 -07004646 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004647 throw re.rethrowFromSystemServer();
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004648 }
4649 }
4650 return null;
4651 }
Adam Connors776c5552014-01-09 10:42:56 +00004652
4653 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04004654 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004655 * @deprecated Do not use
4656 * @removed
Julia Reynolds20118f12015-02-11 12:34:08 -05004657 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004658 @Deprecated
Julia Reynolds20118f12015-02-11 12:34:08 -05004659 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06004660 @SuppressLint("Doclava125")
Makoto Onuki408e8e42016-10-25 12:10:27 -07004661 public @Nullable String getDeviceInitializerApp() {
Julia Reynolds20118f12015-02-11 12:34:08 -05004662 return null;
4663 }
4664
4665 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004666 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004667 * @deprecated Do not use
4668 * @removed
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004669 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004670 @Deprecated
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004671 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06004672 @SuppressLint("Doclava125")
Makoto Onuki408e8e42016-10-25 12:10:27 -07004673 public @Nullable ComponentName getDeviceInitializerComponent() {
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004674 return null;
4675 }
4676
Julia Reynolds20118f12015-02-11 12:34:08 -05004677 /**
Adam Connors776c5552014-01-09 10:42:56 +00004678 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004679 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304680 * Sets the given component as an active admin and registers the package as the profile
4681 * owner for this user. The package must already be installed and there shouldn't be
4682 * an existing profile owner registered for this user. Also, this method must be called
4683 * before the user setup has been completed.
4684 * <p>
4685 * This method can only be called by system apps that hold MANAGE_USERS permission and
4686 * MANAGE_DEVICE_ADMINS permission.
4687 * @param admin The component to register as an active admin and profile owner.
4688 * @param ownerName The user-visible name of the entity that is managing this user.
4689 * @return whether the admin was successfully registered as the profile owner.
4690 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
4691 * the user has already been set up.
4692 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07004693 @Deprecated
Justin Morey80440cc2014-07-24 09:16:35 -05004694 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06004695 @RequiresPermission(android.Manifest.permission.MANAGE_DEVICE_ADMINS)
Robin Lee25e26452015-06-02 09:56:29 -07004696 public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304697 throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004698 throwIfParentInstance("setActiveProfileOwner");
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304699 if (mService != null) {
4700 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004701 final int myUserId = myUserId();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304702 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004703 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304704 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004705 throw re.rethrowFromSystemServer();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304706 }
4707 }
4708 return false;
4709 }
4710
4711 /**
Esteban Talaveraa5b09632017-02-10 16:15:24 +00004712 * Clears the active profile owner. The caller must be the profile owner of this user, otherwise
4713 * a SecurityException will be thrown. This method is not available to managed profile owners.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004714 * <p>
Esteban Talaveraa5b09632017-02-10 16:15:24 +00004715 * While some policies previously set by the profile owner will be cleared by this method, it is
4716 * a best-effort process and some other policies will still remain in place after the profile
4717 * owner is cleared.
Makoto Onuki5bf68022016-01-27 13:49:19 -08004718 *
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004719 * @param admin The component to remove as the profile owner.
Esteban Talaveraa5b09632017-02-10 16:15:24 +00004720 * @throws SecurityException if {@code admin} is not an active profile owner, or the method is
4721 * being called from a managed profile.
4722 *
4723 * @deprecated This method is expected to be used for testing purposes only. The profile owner
4724 * will lose control of the user and its data after calling it. In order to protect any
4725 * sensitive data that remains on this user, it is advised that the profile owner deletes it
4726 * instead of calling this method. See {@link #wipeData(int)}.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004727 */
Esteban Talaveraa5b09632017-02-10 16:15:24 +00004728 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07004729 public void clearProfileOwner(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004730 throwIfParentInstance("clearProfileOwner");
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004731 if (mService != null) {
4732 try {
4733 mService.clearProfileOwner(admin);
4734 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004735 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004736 }
4737 }
4738 }
4739
4740 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05004741 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07004742 * Checks whether the user was already setup.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004743 */
4744 public boolean hasUserSetupCompleted() {
4745 if (mService != null) {
4746 try {
4747 return mService.hasUserSetupCompleted();
4748 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004749 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004750 }
4751 }
4752 return true;
4753 }
4754
4755 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004756 * @hide
4757 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00004758 * already be installed. There must not already be a profile owner for this user.
4759 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
4760 * this method.
4761 * Calling this after the setup phase of the specified user has completed is allowed only if:
4762 * - the caller is SYSTEM_UID.
4763 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004764 * @param admin the component name to be registered as profile owner.
4765 * @param ownerName the human readable name of the organisation associated with this DPM.
4766 * @param userHandle the userId to set the profile owner for.
4767 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00004768 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
4769 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004770 */
Robin Lee25e26452015-06-02 09:56:29 -07004771 public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName,
Robin Leeddd553f2015-04-30 14:18:22 +01004772 int userHandle) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00004773 if (mService != null) {
4774 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004775 if (ownerName == null) {
4776 ownerName = "";
4777 }
4778 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00004779 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004780 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004781 }
4782 }
4783 return false;
4784 }
4785
4786 /**
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004787 * Sets the device owner information to be shown on the lock screen.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004788 * <p>
4789 * If the device owner information is {@code null} or empty then the device owner info is
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004790 * cleared and the user owner info is shown on the lock screen if it is set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004791 * <p>
4792 * If the device owner information contains only whitespaces then the message on the lock screen
4793 * will be blank and the user will not be allowed to change it.
4794 * <p>
4795 * If the device owner information needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00004796 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
4797 * and set a new version of this string accordingly.
4798 *
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004799 * @param admin The name of the admin component to check.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004800 * @param info Device owner information which will be displayed instead of the user owner info.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004801 * @throws SecurityException if {@code admin} is not a device owner.
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004802 */
Andrei Stingaceanu16187902016-03-21 15:44:45 +00004803 public void setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, CharSequence info) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004804 throwIfParentInstance("setDeviceOwnerLockScreenInfo");
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004805 if (mService != null) {
4806 try {
Andrei Stingaceanu16187902016-03-21 15:44:45 +00004807 mService.setDeviceOwnerLockScreenInfo(admin, info);
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004808 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004809 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004810 }
4811 }
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004812 }
4813
4814 /**
4815 * @return The device owner information. If it is not set returns {@code null}.
4816 */
Andrei Stingaceanu16187902016-03-21 15:44:45 +00004817 public CharSequence getDeviceOwnerLockScreenInfo() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004818 throwIfParentInstance("getDeviceOwnerLockScreenInfo");
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004819 if (mService != null) {
4820 try {
4821 return mService.getDeviceOwnerLockScreenInfo();
4822 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004823 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004824 }
4825 }
4826 return null;
4827 }
4828
4829 /**
Edman Anjos52088e42017-01-13 22:26:17 +01004830 * Called by device or profile owners to suspend packages for this user. This function can be
4831 * called by a device owner, profile owner, or by a delegate given the
4832 * {@link #DELEGATION_PACKAGE_ACCESS} scope via {@link #setDelegatedScopes}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004833 * <p>
4834 * A suspended package will not be able to start activities. Its notifications will be hidden,
4835 * it will not show up in recents, will not be able to show toasts or dialogs or ring the
4836 * device.
4837 * <p>
4838 * The package must already be installed. If the package is uninstalled while suspended the
4839 * package will no longer be suspended. The admin can block this by using
Kenny Guy871f3eb2016-03-09 20:06:16 +00004840 * {@link #setUninstallBlocked}.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004841 *
Edman Anjos52088e42017-01-13 22:26:17 +01004842 * @param admin The name of the admin component to check, or {@code null} if the caller is a
4843 * package access delegate.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004844 * @param packageNames The package names to suspend or unsuspend.
4845 * @param suspended If set to {@code true} than the packages will be suspended, if set to
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004846 * {@code false} the packages will be unsuspended.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004847 * @return an array of package names for which the suspended status is not set as requested in
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004848 * this method.
4849 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01004850 * @see #setDelegatedScopes
4851 * @see #DELEGATION_PACKAGE_ACCESS
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004852 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004853 public @NonNull String[] setPackagesSuspended(@NonNull ComponentName admin,
4854 @NonNull String[] packageNames, boolean suspended) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004855 throwIfParentInstance("setPackagesSuspended");
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004856 if (mService != null) {
4857 try {
Edman Anjos52088e42017-01-13 22:26:17 +01004858 return mService.setPackagesSuspended(admin, mContext.getPackageName(), packageNames,
4859 suspended);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004860 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004861 throw re.rethrowFromSystemServer();
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004862 }
4863 }
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004864 return packageNames;
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004865 }
4866
4867 /**
Edman Anjos52088e42017-01-13 22:26:17 +01004868 * Determine if a package is suspended. This function can be called by a device owner, profile
4869 * owner, or by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via
4870 * {@link #setDelegatedScopes}.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004871 *
Edman Anjos52088e42017-01-13 22:26:17 +01004872 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
4873 * {@code null} if the caller is a package access delegate.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004874 * @param packageName The name of the package to retrieve the suspended status of.
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00004875 * @return {@code true} if the package is suspended or {@code false} if the package is not
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004876 * suspended, could not be found or an error occurred.
4877 * @throws SecurityException if {@code admin} is not a device or profile owner.
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004878 * @throws NameNotFoundException if the package could not be found.
Edman Anjos52088e42017-01-13 22:26:17 +01004879 * @see #setDelegatedScopes
4880 * @see #DELEGATION_PACKAGE_ACCESS
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004881 */
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004882 public boolean isPackageSuspended(@NonNull ComponentName admin, String packageName)
4883 throws NameNotFoundException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004884 throwIfParentInstance("isPackageSuspended");
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004885 if (mService != null) {
4886 try {
Edman Anjos52088e42017-01-13 22:26:17 +01004887 return mService.isPackageSuspended(admin, mContext.getPackageName(), packageName);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004888 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004889 throw e.rethrowFromSystemServer();
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004890 } catch (IllegalArgumentException ex) {
4891 throw new NameNotFoundException(packageName);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004892 }
4893 }
4894 return false;
4895 }
4896
4897 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004898 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
4899 * be used. Only the profile owner can call this.
4900 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01004901 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004902 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004903 * @throws SecurityException if {@code admin} is not a profile owner.
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004904 */
Robin Lee25e26452015-06-02 09:56:29 -07004905 public void setProfileEnabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004906 throwIfParentInstance("setProfileEnabled");
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004907 if (mService != null) {
4908 try {
4909 mService.setProfileEnabled(admin);
4910 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004911 throw e.rethrowFromSystemServer();
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004912 }
4913 }
4914 }
4915
4916 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004917 * Sets the name of the profile. In the device owner case it sets the name of the user which it
4918 * is called from. Only a profile owner or device owner can call this. If this is never called
4919 * by the profile or device owner, the name will be set to default values.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004920 *
4921 * @see #isProfileOwnerApp
4922 * @see #isDeviceOwnerApp
Robin Lee25e26452015-06-02 09:56:29 -07004923 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004924 * @param profileName The name of the profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004925 * @throws SecurityException if {@code admin} is not a device or profile owner.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004926 */
Robin Lee25e26452015-06-02 09:56:29 -07004927 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004928 throwIfParentInstance("setProfileName");
Jessica Hummel1333ea12014-06-23 11:20:10 +01004929 if (mService != null) {
4930 try {
Robin Lee25e26452015-06-02 09:56:29 -07004931 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07004932 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004933 throw e.rethrowFromSystemServer();
Fyodor Kupolov78f13142015-05-27 16:52:45 -07004934 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01004935 }
4936 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01004937
4938 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004939 * Used to determine if a particular package is registered as the profile owner for the
Makoto Onuki32b30572015-12-11 14:29:51 -08004940 * user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004941 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00004942 *
4943 * @param packageName The package name of the app to compare with the registered profile owner.
4944 * @return Whether or not the package is registered as the profile owner.
4945 */
4946 public boolean isProfileOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004947 throwIfParentInstance("isProfileOwnerApp");
Adam Connors776c5552014-01-09 10:42:56 +00004948 if (mService != null) {
4949 try {
Makoto Onuki90b89652016-01-28 14:44:18 -08004950 ComponentName profileOwner = mService.getProfileOwner(myUserId());
Nicolas Prevot90af6d72014-07-30 14:19:12 +01004951 return profileOwner != null
4952 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00004953 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004954 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004955 }
4956 }
4957 return false;
4958 }
4959
4960 /**
4961 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07004962 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00004963 * owner has been set for that user.
4964 * @throws IllegalArgumentException if the userId is invalid.
4965 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01004966 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004967 public @Nullable ComponentName getProfileOwner() throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004968 throwIfParentInstance("getProfileOwner");
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01004969 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
4970 }
4971
4972 /**
4973 * @see #getProfileOwner()
4974 * @hide
4975 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004976 public @Nullable ComponentName getProfileOwnerAsUser(final int userId)
4977 throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00004978 if (mService != null) {
4979 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01004980 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00004981 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004982 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004983 }
4984 }
4985 return null;
4986 }
4987
4988 /**
4989 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07004990 * @return the human readable name of the organisation associated with this DPM or {@code null}
4991 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00004992 * @throws IllegalArgumentException if the userId is invalid.
4993 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004994 public @Nullable String getProfileOwnerName() throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00004995 if (mService != null) {
4996 try {
4997 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
4998 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004999 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00005000 }
5001 }
5002 return null;
5003 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005004
5005 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07005006 * @hide
Makoto Onukic8a5a552015-11-19 14:29:12 -08005007 * @param userId The user for whom to fetch the profile owner name, if any.
Amith Yamasani38f836b2014-08-20 14:51:15 -07005008 * @return the human readable name of the organisation associated with this profile owner or
5009 * null if one is not set.
5010 * @throws IllegalArgumentException if the userId is invalid.
5011 */
5012 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07005013 public @Nullable String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005014 throwIfParentInstance("getProfileOwnerNameAsUser");
Amith Yamasani38f836b2014-08-20 14:51:15 -07005015 if (mService != null) {
5016 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02005017 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07005018 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005019 throw re.rethrowFromSystemServer();
Amith Yamasani38f836b2014-08-20 14:51:15 -07005020 }
5021 }
5022 return null;
5023 }
5024
5025 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005026 * Called by a profile owner or device owner to add a default intent handler activity for
5027 * intents that match a certain intent filter. This activity will remain the default intent
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005028 * handler even if the set of potential event handlers for the intent filter changes and if the
5029 * intent preferences are reset.
5030 * <p>
5031 * The default disambiguation mechanism takes over if the activity is not installed (anymore).
5032 * When the activity is (re)installed, it is automatically reset as default intent handler for
5033 * the filter.
5034 * <p>
5035 * The calling device admin must be a profile owner or device owner. If it is not, a security
5036 * exception will be thrown.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005037 *
5038 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5039 * @param filter The IntentFilter for which a default handler is added.
5040 * @param activity The Activity that is added as default intent handler.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005041 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005042 */
Robin Lee25e26452015-06-02 09:56:29 -07005043 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
5044 @NonNull ComponentName activity) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005045 throwIfParentInstance("addPersistentPreferredActivity");
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005046 if (mService != null) {
5047 try {
5048 mService.addPersistentPreferredActivity(admin, filter, activity);
5049 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005050 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005051 }
5052 }
5053 }
5054
5055 /**
5056 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00005057 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005058 * <p>
5059 * The calling device admin must be a profile owner. If it is not, a security exception will be
5060 * thrown.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005061 *
5062 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5063 * @param packageName The name of the package for which preferences are removed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005064 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005065 */
Robin Lee25e26452015-06-02 09:56:29 -07005066 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005067 String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005068 throwIfParentInstance("clearPackagePersistentPreferredActivities");
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005069 if (mService != null) {
5070 try {
5071 mService.clearPackagePersistentPreferredActivities(admin, packageName);
5072 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005073 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005074 }
5075 }
5076 }
Robin Lee66e5d962014-04-09 16:44:21 +01005077
5078 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00005079 * Called by a profile owner or device owner to grant permission to a package to manage
5080 * application restrictions for the calling user via {@link #setApplicationRestrictions} and
5081 * {@link #getApplicationRestrictions}.
5082 * <p>
5083 * This permission is persistent until it is later cleared by calling this method with a
5084 * {@code null} value or uninstalling the managing package.
Rubin Xuf03d0a62016-02-10 14:54:15 +00005085 * <p>
5086 * The supplied application restriction managing package must be installed when calling this
Victor Changcd14c0a2016-03-16 19:10:15 +00005087 * API, otherwise an {@link NameNotFoundException} will be thrown.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005088 *
5089 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5090 * @param packageName The package name which will be given access to application restrictions
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005091 * APIs. If {@code null} is given the current package will be cleared.
5092 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Changcd14c0a2016-03-16 19:10:15 +00005093 * @throws NameNotFoundException if {@code packageName} is not found
Edman Anjosf9946772016-11-28 16:35:15 +01005094 *
5095 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #setDelegatedScopes}
5096 * with the {@link #DELEGATION_APP_RESTRICTIONS} scope instead.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005097 */
Edman Anjosf9946772016-11-28 16:35:15 +01005098 @Deprecated
Esteban Talaverabf60f722015-12-10 16:26:44 +00005099 public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin,
Victor Changcd14c0a2016-03-16 19:10:15 +00005100 @Nullable String packageName) throws NameNotFoundException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005101 throwIfParentInstance("setApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00005102 if (mService != null) {
5103 try {
Victor Changcd14c0a2016-03-16 19:10:15 +00005104 if (!mService.setApplicationRestrictionsManagingPackage(admin, packageName)) {
5105 throw new NameNotFoundException(packageName);
5106 }
Esteban Talaverabf60f722015-12-10 16:26:44 +00005107 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005108 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00005109 }
5110 }
5111 }
5112
5113 /**
5114 * Called by a profile owner or device owner to retrieve the application restrictions managing
Edman Anjosf9946772016-11-28 16:35:15 +01005115 * package for the current user, or {@code null} if none is set. If there are multiple
5116 * delegates this function will return one of them.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005117 *
5118 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5119 * @return The package name allowed to manage application restrictions on the current user, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005120 * {@code null} if none is set.
5121 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01005122 *
5123 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatePackages}
5124 * with the {@link #DELEGATION_APP_RESTRICTIONS} scope instead.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005125 */
Edman Anjosf9946772016-11-28 16:35:15 +01005126 @Deprecated
5127 @Nullable
5128 public String getApplicationRestrictionsManagingPackage(
Makoto Onuki408e8e42016-10-25 12:10:27 -07005129 @NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005130 throwIfParentInstance("getApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00005131 if (mService != null) {
5132 try {
5133 return mService.getApplicationRestrictionsManagingPackage(admin);
5134 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005135 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00005136 }
5137 }
5138 return null;
5139 }
5140
5141 /**
Esteban Talavera96895ca2016-03-16 12:00:40 +00005142 * Called by any application to find out whether it has been granted permission via
5143 * {@link #setApplicationRestrictionsManagingPackage} to manage application restrictions
5144 * for the calling user.
5145 *
5146 * <p>This is done by comparing the calling Linux uid with the uid of the package specified by
5147 * that method.
Edman Anjosf9946772016-11-28 16:35:15 +01005148 *
5149 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatedScopes}
5150 * instead.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005151 */
Edman Anjosf9946772016-11-28 16:35:15 +01005152 @Deprecated
Esteban Talaverabf60f722015-12-10 16:26:44 +00005153 public boolean isCallerApplicationRestrictionsManagingPackage() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005154 throwIfParentInstance("isCallerApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00005155 if (mService != null) {
5156 try {
Edman Anjosf9946772016-11-28 16:35:15 +01005157 return mService.isCallerApplicationRestrictionsManagingPackage(
5158 mContext.getPackageName());
Esteban Talaverabf60f722015-12-10 16:26:44 +00005159 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005160 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00005161 }
5162 }
5163 return false;
5164 }
5165
5166 /**
5167 * Sets the application restrictions for a given target application running in the calling user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005168 * <p>
5169 * 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 +01005170 * application restrictions via {@link #setDelegatedScopes} with the
5171 * {@link #DELEGATION_APP_RESTRICTIONS} scope; otherwise a security exception will be thrown.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005172 * <p>
5173 * The provided {@link Bundle} consists of key-value pairs, where the types of values may be:
Esteban Talavera6b8e0642015-08-10 17:26:04 +01005174 * <ul>
5175 * <li>{@code boolean}
5176 * <li>{@code int}
5177 * <li>{@code String} or {@code String[]}
5178 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
5179 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005180 * <p>
5181 * If the restrictions are not available yet, but may be applied in the near future, the caller
5182 * can notify the target application of that by adding
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00005183 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005184 * <p>
5185 * The application restrictions are only made visible to the target application via
5186 * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or device
5187 * owner, and the application restrictions managing package via
Esteban Talaverabf60f722015-12-10 16:26:44 +00005188 * {@link #getApplicationRestrictions}.
Robin Lee66e5d962014-04-09 16:44:21 +01005189 *
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005190 * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
5191 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00005192 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005193 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01005194 * @param packageName The name of the package to update restricted settings for.
5195 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005196 * set of active restrictions.
5197 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01005198 * @see #setDelegatedScopes
5199 * @see #DELEGATION_APP_RESTRICTIONS
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00005200 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01005201 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005202 @WorkerThread
Esteban Talaverabf60f722015-12-10 16:26:44 +00005203 public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01005204 Bundle settings) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005205 throwIfParentInstance("setApplicationRestrictions");
Robin Lee66e5d962014-04-09 16:44:21 +01005206 if (mService != null) {
5207 try {
Edman Anjosf9946772016-11-28 16:35:15 +01005208 mService.setApplicationRestrictions(admin, mContext.getPackageName(), packageName,
5209 settings);
Robin Lee66e5d962014-04-09 16:44:21 +01005210 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005211 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01005212 }
5213 }
5214 }
5215
5216 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005217 * Sets a list of configuration features to enable for a TrustAgent component. This is meant to
5218 * be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all trust
5219 * agents but those enabled by this function call. If flag
Jim Millere303bf42014-08-26 17:12:29 -07005220 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005221 * <p>
5222 * The calling device admin must have requested
5223 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method;
5224 * if not, a security exception will be thrown.
Tony Mak089d8402016-04-05 17:42:55 +01005225 * <p>
5226 * This method can be called on the {@link DevicePolicyManager} instance returned by
5227 * {@link #getParentProfileInstance(ComponentName)} in order to set the configuration for
5228 * the parent profile.
Jim Miller604e7552014-07-18 19:00:02 -07005229 *
5230 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07005231 * @param target Component name of the agent to be enabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005232 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent will be
5233 * strictly disabled according to the state of the
5234 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
5235 * <p>
5236 * If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all
5237 * admins, then it's up to the TrustAgent itself to aggregate the values from all
5238 * device admins.
5239 * <p>
5240 * Consult documentation for the specific TrustAgent to determine legal options
5241 * parameters.
5242 * @throws SecurityException if {@code admin} is not an active administrator or does not use
5243 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES}
Jim Miller604e7552014-07-18 19:00:02 -07005244 */
Robin Lee25e26452015-06-02 09:56:29 -07005245 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
5246 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07005247 if (mService != null) {
5248 try {
Tony Mak089d8402016-04-05 17:42:55 +01005249 mService.setTrustAgentConfiguration(admin, target, configuration, mParentInstance);
Jim Miller604e7552014-07-18 19:00:02 -07005250 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005251 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07005252 }
5253 }
5254 }
5255
5256 /**
Jim Millere303bf42014-08-26 17:12:29 -07005257 * Gets configuration for the given trust agent based on aggregating all calls to
5258 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
5259 * all device admins.
Tony Mak089d8402016-04-05 17:42:55 +01005260 * <p>
5261 * This method can be called on the {@link DevicePolicyManager} instance returned by
5262 * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the configuration set
5263 * on the parent profile.
Jim Miller604e7552014-07-18 19:00:02 -07005264 *
Jim Millerb5db57a2015-01-14 18:17:19 -08005265 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
5266 * this function returns a list of configurations for all admins that declare
5267 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
5268 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
5269 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
5270 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07005271 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07005272 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07005273 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005274 public @Nullable List<PersistableBundle> getTrustAgentConfiguration(
5275 @Nullable ComponentName admin, @NonNull ComponentName agent) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07005276 return getTrustAgentConfiguration(admin, agent, myUserId());
Jim Millere303bf42014-08-26 17:12:29 -07005277 }
5278
5279 /** @hide per-user version */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005280 public @Nullable List<PersistableBundle> getTrustAgentConfiguration(
5281 @Nullable ComponentName admin, @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07005282 if (mService != null) {
5283 try {
Tony Mak089d8402016-04-05 17:42:55 +01005284 return mService.getTrustAgentConfiguration(admin, agent, userHandle,
5285 mParentInstance);
Jim Miller604e7552014-07-18 19:00:02 -07005286 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005287 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07005288 }
5289 }
Jim Millere303bf42014-08-26 17:12:29 -07005290 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07005291 }
5292
5293 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005294 * Called by a profile owner of a managed profile to set whether caller-Id information from the
5295 * managed profile will be shown in the parent profile, for incoming calls.
5296 * <p>
5297 * The calling device admin must be a profile owner. If it is not, a security exception will be
5298 * thrown.
Adam Connors210fe212014-07-17 15:41:43 +01005299 *
Robin Lee25e26452015-06-02 09:56:29 -07005300 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01005301 * @param disabled If true caller-Id information in the managed profile is not displayed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005302 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors210fe212014-07-17 15:41:43 +01005303 */
Robin Lee25e26452015-06-02 09:56:29 -07005304 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005305 throwIfParentInstance("setCrossProfileCallerIdDisabled");
Adam Connors210fe212014-07-17 15:41:43 +01005306 if (mService != null) {
5307 try {
Robin Lee25e26452015-06-02 09:56:29 -07005308 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01005309 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005310 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01005311 }
5312 }
5313 }
5314
5315 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005316 * Called by a profile owner of a managed profile to determine whether or not caller-Id
5317 * information has been disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005318 * <p>
5319 * The calling device admin must be a profile owner. If it is not, a security exception will be
5320 * thrown.
Adam Connors210fe212014-07-17 15:41:43 +01005321 *
Robin Lee25e26452015-06-02 09:56:29 -07005322 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005323 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors210fe212014-07-17 15:41:43 +01005324 */
Robin Lee25e26452015-06-02 09:56:29 -07005325 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005326 throwIfParentInstance("getCrossProfileCallerIdDisabled");
Adam Connors210fe212014-07-17 15:41:43 +01005327 if (mService != null) {
5328 try {
Robin Lee25e26452015-06-02 09:56:29 -07005329 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01005330 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005331 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01005332 }
5333 }
5334 return false;
5335 }
5336
5337 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07005338 * Determine whether or not caller-Id information has been disabled.
5339 *
5340 * @param userHandle The user for whom to check the caller-id permission
5341 * @hide
5342 */
5343 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
5344 if (mService != null) {
5345 try {
5346 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
5347 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005348 throw e.rethrowFromSystemServer();
Amith Yamasani570002f2014-07-18 15:48:54 -07005349 }
5350 }
5351 return false;
5352 }
5353
5354 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005355 * Called by a profile owner of a managed profile to set whether contacts search from the
5356 * managed profile will be shown in the parent profile, for incoming calls.
5357 * <p>
5358 * The calling device admin must be a profile owner. If it is not, a security exception will be
5359 * thrown.
Victor Chang1060c6182016-01-04 20:16:23 +00005360 *
5361 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5362 * @param disabled If true contacts search in the managed profile is not displayed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005363 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Chang1060c6182016-01-04 20:16:23 +00005364 */
5365 public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin,
5366 boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005367 throwIfParentInstance("setCrossProfileContactsSearchDisabled");
Victor Chang1060c6182016-01-04 20:16:23 +00005368 if (mService != null) {
5369 try {
5370 mService.setCrossProfileContactsSearchDisabled(admin, disabled);
5371 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005372 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00005373 }
5374 }
5375 }
5376
5377 /**
5378 * Called by a profile owner of a managed profile to determine whether or not contacts search
5379 * has been disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005380 * <p>
5381 * The calling device admin must be a profile owner. If it is not, a security exception will be
5382 * thrown.
Victor Chang1060c6182016-01-04 20:16:23 +00005383 *
5384 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005385 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Chang1060c6182016-01-04 20:16:23 +00005386 */
5387 public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005388 throwIfParentInstance("getCrossProfileContactsSearchDisabled");
Victor Chang1060c6182016-01-04 20:16:23 +00005389 if (mService != null) {
5390 try {
5391 return mService.getCrossProfileContactsSearchDisabled(admin);
5392 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005393 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00005394 }
5395 }
5396 return false;
5397 }
5398
5399
5400 /**
5401 * Determine whether or not contacts search has been disabled.
5402 *
5403 * @param userHandle The user for whom to check the contacts search permission
5404 * @hide
5405 */
5406 public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) {
5407 if (mService != null) {
5408 try {
5409 return mService
5410 .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier());
5411 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005412 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00005413 }
5414 }
5415 return false;
5416 }
5417
5418 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005419 * Start Quick Contact on the managed profile for the user, if the policy allows.
Victor Chang97bdacc2016-01-21 22:24:11 +00005420 *
Makoto Onuki1040da12015-03-19 11:24:00 -07005421 * @hide
5422 */
5423 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
Victor Chang97bdacc2016-01-21 22:24:11 +00005424 boolean isContactIdIgnored, long directoryId, Intent originalIntent) {
Makoto Onuki1040da12015-03-19 11:24:00 -07005425 if (mService != null) {
5426 try {
Victor Chang97bdacc2016-01-21 22:24:11 +00005427 mService.startManagedQuickContact(actualLookupKey, actualContactId,
5428 isContactIdIgnored, directoryId, originalIntent);
Makoto Onuki1040da12015-03-19 11:24:00 -07005429 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005430 throw e.rethrowFromSystemServer();
Makoto Onuki1040da12015-03-19 11:24:00 -07005431 }
5432 }
5433 }
5434
5435 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005436 * Start Quick Contact on the managed profile for the user, if the policy allows.
Ricky Wai494b95d2015-11-20 16:07:15 +00005437 * @hide
5438 */
5439 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
5440 Intent originalIntent) {
Victor Chang97bdacc2016-01-21 22:24:11 +00005441 startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT,
Ricky Wai494b95d2015-11-20 16:07:15 +00005442 originalIntent);
5443 }
5444
5445 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005446 * Called by a profile owner of a managed profile to set whether bluetooth devices can access
5447 * enterprise contacts.
Ricky Wai778ba132015-03-31 14:21:22 +01005448 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005449 * The calling device admin must be a profile owner. If it is not, a security exception will be
5450 * thrown.
Ricky Wai778ba132015-03-31 14:21:22 +01005451 * <p>
5452 * This API works on managed profile only.
5453 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005454 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5455 * @param disabled If true, bluetooth devices cannot access enterprise contacts.
5456 * @throws SecurityException if {@code admin} is not a device or profile owner.
Ricky Wai778ba132015-03-31 14:21:22 +01005457 */
Robin Lee25e26452015-06-02 09:56:29 -07005458 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005459 throwIfParentInstance("setBluetoothContactSharingDisabled");
Ricky Wai778ba132015-03-31 14:21:22 +01005460 if (mService != null) {
5461 try {
Robin Lee25e26452015-06-02 09:56:29 -07005462 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01005463 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005464 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01005465 }
5466 }
5467 }
5468
5469 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005470 * Called by a profile owner of a managed profile to determine whether or not Bluetooth devices
5471 * cannot access enterprise contacts.
Ricky Wai778ba132015-03-31 14:21:22 +01005472 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005473 * The calling device admin must be a profile owner. If it is not, a security exception will be
5474 * thrown.
Ricky Wai778ba132015-03-31 14:21:22 +01005475 * <p>
5476 * This API works on managed profile only.
5477 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005478 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5479 * @throws SecurityException if {@code admin} is not a device or profile owner.
Ricky Wai778ba132015-03-31 14:21:22 +01005480 */
Robin Lee25e26452015-06-02 09:56:29 -07005481 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005482 throwIfParentInstance("getBluetoothContactSharingDisabled");
Ricky Wai778ba132015-03-31 14:21:22 +01005483 if (mService != null) {
5484 try {
Robin Lee25e26452015-06-02 09:56:29 -07005485 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01005486 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005487 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01005488 }
5489 }
5490 return true;
5491 }
5492
5493 /**
5494 * Determine whether or not Bluetooth devices cannot access contacts.
5495 * <p>
5496 * This API works on managed profile UserHandle only.
5497 *
5498 * @param userHandle The user for whom to check the caller-id permission
5499 * @hide
5500 */
5501 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
5502 if (mService != null) {
5503 try {
5504 return mService.getBluetoothContactSharingDisabledForUser(userHandle
5505 .getIdentifier());
5506 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005507 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01005508 }
5509 }
5510 return true;
5511 }
5512
5513 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005514 * Called by the profile owner of a managed profile so that some intents sent in the managed
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005515 * profile can also be resolved in the parent, or vice versa. Only activity intents are
5516 * supported.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00005517 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005518 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01005519 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005520 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01005521 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005522 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
5523 * @throws SecurityException if {@code admin} is not a device or profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005524 */
Robin Lee25e26452015-06-02 09:56:29 -07005525 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005526 throwIfParentInstance("addCrossProfileIntentFilter");
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005527 if (mService != null) {
5528 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01005529 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005530 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005531 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005532 }
5533 }
5534 }
5535
5536 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005537 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
5538 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01005539 * Only removes those that have been set by the profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005540 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005541 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005542 * @throws SecurityException if {@code admin} is not a device or profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005543 */
Robin Lee25e26452015-06-02 09:56:29 -07005544 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005545 throwIfParentInstance("clearCrossProfileIntentFilters");
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005546 if (mService != null) {
5547 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01005548 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005549 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005550 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005551 }
5552 }
5553 }
5554
5555 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005556 * Called by a profile or device owner to set the permitted accessibility services. When set by
5557 * a device owner or profile owner the restriction applies to all profiles of the user the
5558 * device owner or profile owner is an admin for. By default the user can use any accessiblity
5559 * service. When zero or more packages have been added, accessiblity services that are not in
5560 * the list and not part of the system can not be enabled by the user.
5561 * <p>
5562 * Calling with a null value for the list disables the restriction so that all services can be
5563 * used, calling with an empty list only allows the builtin system's services.
5564 * <p>
Esteban Talavera9c6458d2017-03-30 17:59:50 +01005565 * System accessibility services are always available to the user the list can't modify this.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005566 *
5567 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5568 * @param packageNames List of accessibility service package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005569 * @return true if setting the restriction succeeded. It fail if there is one or more non-system
5570 * accessibility services enabled, that are not in the list.
5571 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005572 */
Robin Lee25e26452015-06-02 09:56:29 -07005573 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005574 List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005575 throwIfParentInstance("setPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005576 if (mService != null) {
5577 try {
5578 return mService.setPermittedAccessibilityServices(admin, packageNames);
5579 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005580 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005581 }
5582 }
5583 return false;
5584 }
5585
5586 /**
5587 * Returns the list of permitted accessibility services set by this device or profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005588 * <p>
5589 * An empty list means no accessibility services except system services are allowed. Null means
5590 * all accessibility services are allowed.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005591 *
5592 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5593 * @return List of accessiblity service package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005594 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005595 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005596 public @Nullable List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005597 throwIfParentInstance("getPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005598 if (mService != null) {
5599 try {
5600 return mService.getPermittedAccessibilityServices(admin);
5601 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005602 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005603 }
5604 }
5605 return null;
5606 }
5607
5608 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00005609 * Called by the system to check if a specific accessibility service is disabled by admin.
5610 *
5611 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5612 * @param packageName Accessibility service package name that needs to be checked.
5613 * @param userHandle user id the admin is running as.
5614 * @return true if the accessibility service is permitted, otherwise false.
5615 *
5616 * @hide
5617 */
5618 public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin,
5619 @NonNull String packageName, int userHandle) {
5620 if (mService != null) {
5621 try {
5622 return mService.isAccessibilityServicePermittedByAdmin(admin, packageName,
5623 userHandle);
5624 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005625 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00005626 }
5627 }
5628 return false;
5629 }
5630
5631 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005632 * Returns the list of accessibility services permitted by the device or profiles
5633 * owners of this user.
5634 *
5635 * <p>Null means all accessibility services are allowed, if a non-null list is returned
5636 * it will contain the intersection of the permitted lists for any device or profile
5637 * owners that apply to this user. It will also include any system accessibility services.
5638 *
5639 * @param userId which user to check for.
5640 * @return List of accessiblity service package names.
5641 * @hide
5642 */
5643 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07005644 public @Nullable List<String> getPermittedAccessibilityServices(int userId) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005645 throwIfParentInstance("getPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005646 if (mService != null) {
5647 try {
5648 return mService.getPermittedAccessibilityServicesForUser(userId);
5649 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005650 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005651 }
5652 }
5653 return null;
5654 }
5655
5656 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005657 * Called by a profile or device owner to set the permitted input methods services. When set by
5658 * a device owner or profile owner the restriction applies to all profiles of the user the
5659 * device owner or profile owner is an admin for. By default the user can use any input method.
5660 * When zero or more packages have been added, input method that are not in the list and not
5661 * part of the system can not be enabled by the user. This method will fail if it is called for
5662 * a admin that is not for the foreground user or a profile of the foreground user.
5663 * <p>
5664 * Calling with a null value for the list disables the restriction so that all input methods can
5665 * be used, calling with an empty list disables all but the system's own input methods.
5666 * <p>
5667 * System input methods are always available to the user this method can't modify this.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005668 *
5669 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5670 * @param packageNames List of input method package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005671 * @return true if setting the restriction succeeded. It will fail if there are one or more
5672 * non-system input methods currently enabled that are not in the packageNames list.
5673 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005674 */
Esteban Talavera9c6458d2017-03-30 17:59:50 +01005675 public boolean setPermittedInputMethods(
5676 @NonNull ComponentName admin, List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005677 throwIfParentInstance("setPermittedInputMethods");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005678 if (mService != null) {
5679 try {
5680 return mService.setPermittedInputMethods(admin, packageNames);
5681 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005682 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005683 }
5684 }
5685 return false;
5686 }
5687
5688
5689 /**
5690 * Returns the list of permitted input methods set by this device or profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005691 * <p>
5692 * An empty list means no input methods except system input methods are allowed. Null means all
5693 * input methods are allowed.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005694 *
5695 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5696 * @return List of input method package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005697 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005698 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005699 public @Nullable List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005700 throwIfParentInstance("getPermittedInputMethods");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005701 if (mService != null) {
5702 try {
5703 return mService.getPermittedInputMethods(admin);
5704 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005705 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005706 }
5707 }
5708 return null;
5709 }
5710
5711 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00005712 * Called by the system to check if a specific input method is disabled by admin.
5713 *
5714 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5715 * @param packageName Input method package name that needs to be checked.
5716 * @param userHandle user id the admin is running as.
5717 * @return true if the input method is permitted, otherwise false.
5718 *
5719 * @hide
5720 */
5721 public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin,
5722 @NonNull String packageName, int userHandle) {
5723 if (mService != null) {
5724 try {
5725 return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle);
5726 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005727 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00005728 }
5729 }
5730 return false;
5731 }
5732
5733 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005734 * Returns the list of input methods permitted by the device or profiles
Makoto Onuki32b30572015-12-11 14:29:51 -08005735 * owners of the current user. (*Not* calling user, due to a limitation in InputMethodManager.)
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005736 *
5737 * <p>Null means all input methods are allowed, if a non-null list is returned
5738 * it will contain the intersection of the permitted lists for any device or profile
5739 * owners that apply to this user. It will also include any system input methods.
5740 *
5741 * @return List of input method package names.
5742 * @hide
5743 */
5744 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07005745 public @Nullable List<String> getPermittedInputMethodsForCurrentUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005746 throwIfParentInstance("getPermittedInputMethodsForCurrentUser");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005747 if (mService != null) {
5748 try {
5749 return mService.getPermittedInputMethodsForCurrentUser();
5750 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005751 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005752 }
5753 }
5754 return null;
5755 }
5756
5757 /**
Esteban Talavera9c6458d2017-03-30 17:59:50 +01005758 * Called by a profile owner of a managed profile to set the packages that are allowed to use
5759 * a {@link android.service.notification.NotificationListenerService} in the primary user to
5760 * see notifications from the managed profile. By default all packages are permitted by this
5761 * policy. When zero or more packages have been added, notification listeners installed on the
5762 * primary user that are not in the list and are not part of the system won't receive events
5763 * for managed profile notifications.
5764 * <p>
5765 * Calling with a {@code null} value for the list disables the restriction so that all
5766 * notification listener services be used. Calling with an empty list disables all but the
5767 * system's own notification listeners. System notification listener services are always
5768 * available to the user.
5769 * <p>
5770 * If a device or profile owner want to stop notification listeners in their user from seeing
5771 * that user's notifications they should prevent that service from running instead (e.g. via
5772 * {@link #setApplicationHidden(ComponentName, String, boolean)})
5773 *
5774 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5775 * @param packageList List of package names to whitelist
5776 * @return true if setting the restriction succeeded. It will fail if called outside a managed
5777 * profile
5778 * @throws SecurityException if {@code admin} is not a profile owner.
5779 *
5780 * @see android.service.notification.NotificationListenerService
5781 */
5782 public boolean setPermittedCrossProfileNotificationListeners(
5783 @NonNull ComponentName admin, @Nullable List<String> packageList) {
5784 throwIfParentInstance("setPermittedCrossProfileNotificationListeners");
5785 if (mService != null) {
5786 try {
5787 return mService.setPermittedCrossProfileNotificationListeners(admin, packageList);
5788 } catch (RemoteException e) {
5789 throw e.rethrowFromSystemServer();
5790 }
5791 }
5792 return false;
5793 }
5794
5795 /**
5796 * Returns the list of packages installed on the primary user that allowed to use a
5797 * {@link android.service.notification.NotificationListenerService} to receive
5798 * notifications from this managed profile, as set by the profile owner.
5799 * <p>
5800 * An empty list means no notification listener services except system ones are allowed.
5801 * A {@code null} return value indicates that all notification listeners are allowed.
5802 */
5803 public @Nullable List<String> getPermittedCrossProfileNotificationListeners(
5804 @NonNull ComponentName admin) {
5805 throwIfParentInstance("getPermittedCrossProfileNotificationListeners");
5806 if (mService != null) {
5807 try {
5808 return mService.getPermittedCrossProfileNotificationListeners(admin);
5809 } catch (RemoteException e) {
5810 throw e.rethrowFromSystemServer();
5811 }
5812 }
5813 return null;
5814 }
5815
5816 /**
5817 * Returns true if {@code NotificationListenerServices} from the given package are allowed to
5818 * receive events for notifications from the given user id. Can only be called by the system uid
5819 *
5820 * @see #setPermittedCrossProfileNotificationListeners(ComponentName, List)
5821 *
5822 * @hide
5823 */
5824 public boolean isNotificationListenerServicePermitted(
5825 @NonNull String packageName, @UserIdInt int userId) {
5826 if (mService != null) {
5827 try {
5828 return mService.isNotificationListenerServicePermitted(packageName, userId);
5829 } catch (RemoteException e) {
5830 throw e.rethrowFromSystemServer();
5831 }
5832 }
5833 return true;
5834 }
5835
5836 /**
Edman Anjos52088e42017-01-13 22:26:17 +01005837 * Get the list of apps to keep around as APKs even if no user has currently installed it. This
5838 * function can be called by a device owner or by a delegate given the
5839 * {@link #DELEGATION_KEEP_UNINSTALLED_PACKAGES} scope via {@link #setDelegatedScopes}.
5840 * <p>
5841 * Please note that packages returned in this method are not automatically pre-cached.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005842 *
Edman Anjos52088e42017-01-13 22:26:17 +01005843 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
5844 * {@code null} if the caller is a keep uninstalled packages delegate.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005845 * @return List of package names to keep cached.
Edman Anjos52088e42017-01-13 22:26:17 +01005846 * @see #setDelegatedScopes
5847 * @see #DELEGATION_KEEP_UNINSTALLED_PACKAGES
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005848 * @hide
5849 */
Edman Anjos52088e42017-01-13 22:26:17 +01005850 public @Nullable List<String> getKeepUninstalledPackages(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005851 throwIfParentInstance("getKeepUninstalledPackages");
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005852 if (mService != null) {
5853 try {
Edman Anjos52088e42017-01-13 22:26:17 +01005854 return mService.getKeepUninstalledPackages(admin, mContext.getPackageName());
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005855 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005856 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005857 }
5858 }
5859 return null;
5860 }
5861
5862 /**
Edman Anjos52088e42017-01-13 22:26:17 +01005863 * Set a list of apps to keep around as APKs even if no user has currently installed it. This
5864 * function can be called by a device owner or by a delegate given the
5865 * {@link #DELEGATION_KEEP_UNINSTALLED_PACKAGES} scope via {@link #setDelegatedScopes}.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005866 *
5867 * <p>Please note that setting this policy does not imply that specified apps will be
5868 * automatically pre-cached.</p>
5869 *
Edman Anjos52088e42017-01-13 22:26:17 +01005870 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
5871 * {@code null} if the caller is a keep uninstalled packages delegate.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005872 * @param packageNames List of package names to keep cached.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005873 * @throws SecurityException if {@code admin} is not a device owner.
Edman Anjos52088e42017-01-13 22:26:17 +01005874 * @see #setDelegatedScopes
5875 * @see #DELEGATION_KEEP_UNINSTALLED_PACKAGES
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005876 * @hide
5877 */
Edman Anjos52088e42017-01-13 22:26:17 +01005878 public void setKeepUninstalledPackages(@Nullable ComponentName admin,
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005879 @NonNull List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005880 throwIfParentInstance("setKeepUninstalledPackages");
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005881 if (mService != null) {
5882 try {
Edman Anjos52088e42017-01-13 22:26:17 +01005883 mService.setKeepUninstalledPackages(admin, mContext.getPackageName(), packageNames);
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005884 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005885 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005886 }
5887 }
5888 }
5889
5890 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04005891 * Called by a device owner to create a user with the specified name. The UserHandle returned
5892 * by this method should not be persisted as user handles are recycled as users are removed and
5893 * created. If you need to persist an identifier for this user, use
5894 * {@link UserManager#getSerialNumberForUser}.
5895 *
5896 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5897 * @param name the user's name
5898 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07005899 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
5900 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01005901 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005902 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01005903 * @removed From {@link android.os.Build.VERSION_CODES#N}
Julia Reynolds1e958392014-05-16 14:25:21 -04005904 */
Kenny Guy14f48e52015-06-29 15:12:36 +01005905 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07005906 public @Nullable UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04005907 return null;
5908 }
5909
5910 /**
Jason Monk03978a42014-06-10 15:05:30 -04005911 * Called by a device owner to create a user with the specified name. The UserHandle returned
5912 * by this method should not be persisted as user handles are recycled as users are removed and
5913 * created. If you need to persist an identifier for this user, use
5914 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
5915 * immediately.
5916 *
5917 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
5918 * as registered as an active admin on the new user. The profile owner package will be
5919 * installed on the new user if it already is installed on the device.
5920 *
5921 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
5922 * profileOwnerComponent when onEnable is called.
5923 *
5924 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5925 * @param name the user's name
5926 * @param ownerName the human readable name of the organisation associated with this DPM.
5927 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
5928 * the user.
5929 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
5930 * on the new user.
5931 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07005932 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
5933 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01005934 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005935 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01005936 * @removed From {@link android.os.Build.VERSION_CODES#N}
Jason Monk03978a42014-06-10 15:05:30 -04005937 */
Kenny Guy14f48e52015-06-29 15:12:36 +01005938 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07005939 public @Nullable UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
Robin Lee25e26452015-06-02 09:56:29 -07005940 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04005941 return null;
5942 }
5943
5944 /**
phweissa92e1212016-01-25 17:14:10 +01005945 * Flag used by {@link #createAndManageUser} to skip setup wizard after creating a new user.
phweiss343fb332016-01-25 14:48:59 +01005946 */
5947 public static final int SKIP_SETUP_WIZARD = 0x0001;
5948
5949 /**
Lenka Trochtovac8202c82016-01-26 15:11:09 +01005950 * Flag used by {@link #createAndManageUser} to specify that the user should be created
5951 * ephemeral.
5952 * @hide
5953 */
5954 public static final int MAKE_USER_EPHEMERAL = 0x0002;
5955
5956 /**
phweissa92e1212016-01-25 17:14:10 +01005957 * Called by a device owner to create a user with the specified name and a given component of
5958 * the calling package as profile owner. The UserHandle returned by this method should not be
5959 * persisted as user handles are recycled as users are removed and created. If you need to
5960 * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new
5961 * user will not be started in the background.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005962 * <p>
5963 * admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also a
5964 * DeviceAdminReceiver in the same package as admin, and will become the profile owner and will
5965 * be registered as an active admin on the new user. The profile owner package will be installed
5966 * on the new user.
5967 * <p>
5968 * If the adminExtras are not null, they will be stored on the device until the user is started
5969 * for the first time. Then the extras will be passed to the admin when onEnable is called.
phweiss343fb332016-01-25 14:48:59 +01005970 *
5971 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5972 * @param name The user's name.
phweissa92e1212016-01-25 17:14:10 +01005973 * @param profileOwner Which {@link DeviceAdminReceiver} will be profile owner. Has to be in the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005974 * same package as admin, otherwise no user is created and an
5975 * IllegalArgumentException is thrown.
phweiss343fb332016-01-25 14:48:59 +01005976 * @param adminExtras Extras that will be passed to onEnable of the admin receiver on the new
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005977 * user.
phweissa92e1212016-01-25 17:14:10 +01005978 * @param flags {@link #SKIP_SETUP_WIZARD} is supported.
phweiss343fb332016-01-25 14:48:59 +01005979 * @see UserHandle
5980 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
5981 * user could not be created.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005982 * @throws SecurityException if {@code admin} is not a device owner.
phweiss343fb332016-01-25 14:48:59 +01005983 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005984 public @Nullable UserHandle createAndManageUser(@NonNull ComponentName admin,
5985 @NonNull String name,
phweissa92e1212016-01-25 17:14:10 +01005986 @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras,
5987 int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005988 throwIfParentInstance("createAndManageUser");
phweiss343fb332016-01-25 14:48:59 +01005989 try {
phweissa92e1212016-01-25 17:14:10 +01005990 return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags);
phweiss343fb332016-01-25 14:48:59 +01005991 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005992 throw re.rethrowFromSystemServer();
phweiss343fb332016-01-25 14:48:59 +01005993 }
phweiss343fb332016-01-25 14:48:59 +01005994 }
5995
5996 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005997 * Called by a device owner to remove a user and all associated data. The primary user can not
5998 * be removed.
Julia Reynolds1e958392014-05-16 14:25:21 -04005999 *
6000 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6001 * @param userHandle the user to remove.
6002 * @return {@code true} if the user was removed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006003 * @throws SecurityException if {@code admin} is not a device owner.
Julia Reynolds1e958392014-05-16 14:25:21 -04006004 */
Robin Lee25e26452015-06-02 09:56:29 -07006005 public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006006 throwIfParentInstance("removeUser");
Julia Reynolds1e958392014-05-16 14:25:21 -04006007 try {
6008 return mService.removeUser(admin, userHandle);
6009 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006010 throw re.rethrowFromSystemServer();
Julia Reynolds1e958392014-05-16 14:25:21 -04006011 }
6012 }
6013
6014 /**
Jason Monk582d9112014-07-09 19:57:08 -04006015 * Called by a device owner to switch the specified user to the foreground.
6016 *
6017 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6018 * @param userHandle the user to switch to; null will switch to primary.
6019 * @return {@code true} if the switch was successful, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006020 * @throws SecurityException if {@code admin} is not a device owner.
Jason Monk582d9112014-07-09 19:57:08 -04006021 * @see Intent#ACTION_USER_FOREGROUND
6022 */
Robin Lee25e26452015-06-02 09:56:29 -07006023 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006024 throwIfParentInstance("switchUser");
Jason Monk582d9112014-07-09 19:57:08 -04006025 try {
6026 return mService.switchUser(admin, userHandle);
6027 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006028 throw re.rethrowFromSystemServer();
Jason Monk582d9112014-07-09 19:57:08 -04006029 }
6030 }
6031
6032 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00006033 * Retrieves the application restrictions for a given target application running in the calling
6034 * user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006035 * <p>
6036 * 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 +01006037 * application restrictions via {@link #setDelegatedScopes} with the
6038 * {@link #DELEGATION_APP_RESTRICTIONS} scope; otherwise a security exception will be thrown.
Robin Lee66e5d962014-04-09 16:44:21 +01006039 *
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07006040 * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
6041 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00006042 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006043 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01006044 * @param packageName The name of the package to fetch restricted settings of.
6045 * @return {@link Bundle} of settings corresponding to what was set last time
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006046 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty
6047 * {@link Bundle} if no restrictions have been set.
6048 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01006049 * @see #setDelegatedScopes
6050 * @see #DELEGATION_APP_RESTRICTIONS
Robin Lee66e5d962014-04-09 16:44:21 +01006051 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07006052 @WorkerThread
Makoto Onuki408e8e42016-10-25 12:10:27 -07006053 public @NonNull Bundle getApplicationRestrictions(
6054 @Nullable ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006055 throwIfParentInstance("getApplicationRestrictions");
Robin Lee66e5d962014-04-09 16:44:21 +01006056 if (mService != null) {
6057 try {
Edman Anjosf9946772016-11-28 16:35:15 +01006058 return mService.getApplicationRestrictions(admin, mContext.getPackageName(),
6059 packageName);
Robin Lee66e5d962014-04-09 16:44:21 +01006060 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006061 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01006062 }
6063 }
6064 return null;
6065 }
Amith Yamasanibe465322014-04-24 13:45:17 -07006066
6067 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05006068 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07006069 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006070 * The calling device admin must be a profile or device owner; if it is not, a security
6071 * exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07006072 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006073 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6074 * @param key The key of the restriction. See the constants in {@link android.os.UserManager}
6075 * for the list of keys.
6076 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanibe465322014-04-24 13:45:17 -07006077 */
Robin Lee25e26452015-06-02 09:56:29 -07006078 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006079 throwIfParentInstance("addUserRestriction");
Amith Yamasanibe465322014-04-24 13:45:17 -07006080 if (mService != null) {
6081 try {
6082 mService.setUserRestriction(admin, key, true);
6083 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006084 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07006085 }
6086 }
6087 }
6088
6089 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05006090 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07006091 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006092 * The calling device admin must be a profile or device owner; if it is not, a security
6093 * exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07006094 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006095 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6096 * @param key The key of the restriction. See the constants in {@link android.os.UserManager}
6097 * for the list of keys.
6098 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanibe465322014-04-24 13:45:17 -07006099 */
Robin Lee25e26452015-06-02 09:56:29 -07006100 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006101 throwIfParentInstance("clearUserRestriction");
Amith Yamasanibe465322014-04-24 13:45:17 -07006102 if (mService != null) {
6103 try {
6104 mService.setUserRestriction(admin, key, false);
6105 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006106 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07006107 }
6108 }
6109 }
Adam Connors010cfd42014-04-16 12:48:13 +01006110
6111 /**
Makoto Onuki3a3092f2015-10-30 11:07:51 -07006112 * Called by a profile or device owner to get user restrictions set with
6113 * {@link #addUserRestriction(ComponentName, String)}.
6114 * <p>
6115 * The target user may have more restrictions set by the system or other device owner / profile
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006116 * owner. To get all the user restrictions currently set, use
Makoto Onuki3a3092f2015-10-30 11:07:51 -07006117 * {@link UserManager#getUserRestrictions()}.
6118 *
6119 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006120 * @throws SecurityException if {@code admin} is not a device or profile owner.
Makoto Onuki3a3092f2015-10-30 11:07:51 -07006121 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006122 public @NonNull Bundle getUserRestrictions(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006123 throwIfParentInstance("getUserRestrictions");
Makoto Onuki3a3092f2015-10-30 11:07:51 -07006124 Bundle ret = null;
6125 if (mService != null) {
6126 try {
Sudheer Shanka549b9692016-03-30 17:12:07 -07006127 ret = mService.getUserRestrictions(admin);
6128 } catch (RemoteException e) {
6129 throw e.rethrowFromSystemServer();
6130 }
6131 }
6132 return ret == null ? new Bundle() : ret;
6133 }
6134
6135 /**
phweiss73145f42017-01-17 19:06:38 +01006136 * Called by any app to display a support dialog when a feature was disabled by an admin.
6137 * This returns an intent that can be used with {@link Context#startActivity(Intent)} to
6138 * display the dialog. It will tell the user that the feature indicated by {@code restriction}
6139 * was disabled by an admin, and include a link for more information. The default content of
6140 * the dialog can be changed by the restricting admin via
6141 * {@link #setShortSupportMessage(ComponentName, CharSequence)}. If the restriction is not
6142 * set (i.e. the feature is available), then the return value will be {@code null}.
6143 * @param restriction Indicates for which feature the dialog should be displayed. Can be a
6144 * user restriction from {@link UserManager}, e.g.
6145 * {@link UserManager#DISALLOW_ADJUST_VOLUME}, or one of the constants
6146 * {@link #POLICY_DISABLE_CAMERA} or {@link #POLICY_DISABLE_SCREEN_CAPTURE}.
6147 * @return Intent An intent to be used to start the dialog-activity if the restriction is
6148 * set by an admin, or null if the restriction does not exist or no admin set it.
6149 */
6150 public Intent createAdminSupportIntent(@NonNull String restriction) {
6151 throwIfParentInstance("createAdminSupportIntent");
6152 if (mService != null) {
6153 try {
6154 return mService.createAdminSupportIntent(restriction);
6155 } catch (RemoteException e) {
6156 throw e.rethrowFromSystemServer();
6157 }
6158 }
6159 return null;
6160 }
6161
6162 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006163 * Hide or unhide packages. When a package is hidden it is unavailable for use, but the data and
6164 * actual package file remain. This function can be called by a device owner, profile owner, or
6165 * by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via
6166 * {@link #setDelegatedScopes}.
Julia Reynolds966881e2014-05-14 12:23:08 -04006167 *
Edman Anjos52088e42017-01-13 22:26:17 +01006168 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
6169 * {@code null} if the caller is a package access delegate.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07006170 * @param packageName The name of the package to hide or unhide.
6171 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006172 * unhidden.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07006173 * @return boolean Whether the hidden setting of the package was successfully updated.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006174 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01006175 * @see #setDelegatedScopes
6176 * @see #DELEGATION_PACKAGE_ACCESS
Julia Reynolds966881e2014-05-14 12:23:08 -04006177 */
Robin Lee25e26452015-06-02 09:56:29 -07006178 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07006179 boolean hidden) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006180 throwIfParentInstance("setApplicationHidden");
Julia Reynolds966881e2014-05-14 12:23:08 -04006181 if (mService != null) {
6182 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006183 return mService.setApplicationHidden(admin, mContext.getPackageName(), packageName,
6184 hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04006185 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006186 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04006187 }
6188 }
6189 return false;
6190 }
6191
6192 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006193 * Determine if a package is hidden. This function can be called by a device owner, profile
6194 * owner, or by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via
6195 * {@link #setDelegatedScopes}.
Julia Reynolds966881e2014-05-14 12:23:08 -04006196 *
Edman Anjos52088e42017-01-13 22:26:17 +01006197 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
6198 * {@code null} if the caller is a package access delegate.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07006199 * @param packageName The name of the package to retrieve the hidden status of.
6200 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006201 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01006202 * @see #setDelegatedScopes
6203 * @see #DELEGATION_PACKAGE_ACCESS
Julia Reynolds966881e2014-05-14 12:23:08 -04006204 */
Robin Lee25e26452015-06-02 09:56:29 -07006205 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006206 throwIfParentInstance("isApplicationHidden");
Julia Reynolds966881e2014-05-14 12:23:08 -04006207 if (mService != null) {
6208 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006209 return mService.isApplicationHidden(admin, mContext.getPackageName(), packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04006210 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006211 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04006212 }
6213 }
6214 return false;
6215 }
6216
6217 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006218 * Re-enable a system app that was disabled by default when the user was initialized. This
6219 * function can be called by a device owner, profile owner, or by a delegate given the
6220 * {@link #DELEGATION_ENABLE_SYSTEM_APP} scope via {@link #setDelegatedScopes}.
Adam Connors655be2a2014-07-14 09:01:25 +00006221 *
Edman Anjos52088e42017-01-13 22:26:17 +01006222 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
6223 * {@code null} if the caller is an enable system app delegate.
Makoto Onuki32b30572015-12-11 14:29:51 -08006224 * @param packageName The package to be re-enabled in the calling profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006225 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01006226 * @see #setDelegatedScopes
6227 * @see #DELEGATION_PACKAGE_ACCESS
Adam Connors655be2a2014-07-14 09:01:25 +00006228 */
Robin Lee25e26452015-06-02 09:56:29 -07006229 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006230 throwIfParentInstance("enableSystemApp");
Adam Connors655be2a2014-07-14 09:01:25 +00006231 if (mService != null) {
6232 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006233 mService.enableSystemApp(admin, mContext.getPackageName(), packageName);
Adam Connors655be2a2014-07-14 09:01:25 +00006234 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006235 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00006236 }
6237 }
6238 }
6239
6240 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006241 * Re-enable system apps by intent that were disabled by default when the user was initialized.
6242 * This function can be called by a device owner, profile owner, or by a delegate given the
6243 * {@link #DELEGATION_ENABLE_SYSTEM_APP} scope via {@link #setDelegatedScopes}.
Adam Connors655be2a2014-07-14 09:01:25 +00006244 *
Edman Anjos52088e42017-01-13 22:26:17 +01006245 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
6246 * {@code null} if the caller is an enable system app delegate.
Adam Connors655be2a2014-07-14 09:01:25 +00006247 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006248 * intent will be re-enabled in the calling profile.
Adam Connors655be2a2014-07-14 09:01:25 +00006249 * @return int The number of activities that matched the intent and were installed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006250 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01006251 * @see #setDelegatedScopes
6252 * @see #DELEGATION_PACKAGE_ACCESS
Adam Connors655be2a2014-07-14 09:01:25 +00006253 */
Robin Lee25e26452015-06-02 09:56:29 -07006254 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006255 throwIfParentInstance("enableSystemApp");
Adam Connors655be2a2014-07-14 09:01:25 +00006256 if (mService != null) {
6257 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006258 return mService.enableSystemAppWithIntent(admin, mContext.getPackageName(), intent);
Adam Connors655be2a2014-07-14 09:01:25 +00006259 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006260 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00006261 }
6262 }
6263 return 0;
6264 }
6265
6266 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00006267 * Called by a device owner or profile owner to disable account management for a specific type
6268 * of account.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006269 * <p>
6270 * The calling device admin must be a device owner or profile owner. If it is not, a security
6271 * exception will be thrown.
6272 * <p>
6273 * When account management is disabled for an account type, adding or removing an account of
6274 * that type will not be possible.
6275 * <p>
6276 * From {@link android.os.Build.VERSION_CODES#N} the profile or device owner can still use
Benjamin Franzb6c0ce42015-11-05 10:06:51 +00006277 * {@link android.accounts.AccountManager} APIs to add or remove accounts when account
6278 * management for a specific type is disabled.
6279 *
Sander Alewijnse650c3342014-05-08 18:00:50 +01006280 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6281 * @param accountType For which account management is disabled or enabled.
6282 * @param disabled The boolean indicating that account management will be disabled (true) or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006283 * enabled (false).
6284 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnse650c3342014-05-08 18:00:50 +01006285 */
Robin Lee25e26452015-06-02 09:56:29 -07006286 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01006287 boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006288 throwIfParentInstance("setAccountManagementDisabled");
Sander Alewijnse650c3342014-05-08 18:00:50 +01006289 if (mService != null) {
6290 try {
6291 mService.setAccountManagementDisabled(admin, accountType, disabled);
6292 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006293 throw e.rethrowFromSystemServer();
Sander Alewijnse650c3342014-05-08 18:00:50 +01006294 }
6295 }
6296 }
6297
6298 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01006299 * Gets the array of accounts for which account management is disabled by the profile owner.
6300 *
6301 * <p> Account management can be disabled/enabled by calling
6302 * {@link #setAccountManagementDisabled}.
6303 *
6304 * @return a list of account types for which account management has been disabled.
6305 *
6306 * @see #setAccountManagementDisabled
6307 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006308 public @Nullable String[] getAccountTypesWithManagementDisabled() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006309 throwIfParentInstance("getAccountTypesWithManagementDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07006310 return getAccountTypesWithManagementDisabledAsUser(myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01006311 }
6312
6313 /**
6314 * @see #getAccountTypesWithManagementDisabled()
6315 * @hide
6316 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006317 public @Nullable String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01006318 if (mService != null) {
6319 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01006320 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01006321 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006322 throw e.rethrowFromSystemServer();
Sander Alewijnse5c02db62014-05-07 10:46:57 +01006323 }
6324 }
6325
6326 return null;
6327 }
justinzhang511e0d82014-03-24 16:09:24 -04006328
6329 /**
Jason Monkd7b86212014-06-16 13:15:38 -04006330 * Sets which packages may enter lock task mode.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006331 * <p>
Esteban Talaverabdcada92017-02-01 14:20:06 +00006332 * Any packages that share uid with an allowed package will also be allowed to activate lock
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006333 * task. From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task
Esteban Talaverabdcada92017-02-01 14:20:06 +00006334 * package list results in locked tasks belonging to those packages to be finished.
6335 * <p>
6336 * This function can only be called by the device owner or by a profile owner of a user/profile
6337 * that is affiliated with the device owner user. See {@link #setAffiliationIds}. Any packages
6338 * set via this method will be cleared if the user becomes unaffiliated.
Jason Monkd7b86212014-06-16 13:15:38 -04006339 *
Jason Monkd7b86212014-06-16 13:15:38 -04006340 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04006341 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Esteban Talaverabdcada92017-02-01 14:20:06 +00006342 * @throws SecurityException if {@code admin} is not the device owner, or the profile owner of
6343 * an affiliated user or profile.
Jason Monkd7b86212014-06-16 13:15:38 -04006344 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00006345 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
6346 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04006347 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04006348 */
Esteban Talaverabdcada92017-02-01 14:20:06 +00006349 public void setLockTaskPackages(@NonNull ComponentName admin, @NonNull String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04006350 throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006351 throwIfParentInstance("setLockTaskPackages");
justinzhang511e0d82014-03-24 16:09:24 -04006352 if (mService != null) {
6353 try {
Jason Monk48aacba2014-08-13 16:29:08 -04006354 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04006355 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006356 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04006357 }
6358 }
6359 }
6360
6361 /**
Esteban Talaverabdcada92017-02-01 14:20:06 +00006362 * Returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04006363 *
Esteban Talaverabdcada92017-02-01 14:20:06 +00006364 * @throws SecurityException if {@code admin} is not the device owner, or the profile owner of
6365 * an affiliated user or profile.
6366 * @see #setLockTaskPackages
justinzhang511e0d82014-03-24 16:09:24 -04006367 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006368 public @NonNull String[] getLockTaskPackages(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006369 throwIfParentInstance("getLockTaskPackages");
justinzhang511e0d82014-03-24 16:09:24 -04006370 if (mService != null) {
6371 try {
Jason Monk48aacba2014-08-13 16:29:08 -04006372 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04006373 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006374 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04006375 }
6376 }
Esteban Talaverabdcada92017-02-01 14:20:06 +00006377 return new String[0];
justinzhang511e0d82014-03-24 16:09:24 -04006378 }
6379
6380 /**
6381 * This function lets the caller know whether the given component is allowed to start the
6382 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04006383 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04006384 */
Jason Monkd7b86212014-06-16 13:15:38 -04006385 public boolean isLockTaskPermitted(String pkg) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006386 throwIfParentInstance("isLockTaskPermitted");
justinzhang511e0d82014-03-24 16:09:24 -04006387 if (mService != null) {
6388 try {
Jason Monkd7b86212014-06-16 13:15:38 -04006389 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04006390 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006391 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04006392 }
6393 }
6394 return false;
6395 }
Julia Reynoldsda551652014-05-14 17:15:16 -04006396
6397 /**
6398 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
6399 * of the setting is in the correct form for the setting type should be performed by the caller.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006400 * <p>
6401 * The settings that can be updated with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04006402 * <ul>
6403 * <li>{@link Settings.Global#ADB_ENABLED}</li>
6404 * <li>{@link Settings.Global#AUTO_TIME}</li>
6405 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04006406 * <li>{@link Settings.Global#DATA_ROAMING}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04006407 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04006408 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006409 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN} This setting is only available from
6410 * {@link android.os.Build.VERSION_CODES#M} onwards and can only be set if
6411 * {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
6412 * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li> This setting is only
6413 * available from {@link android.os.Build.VERSION_CODES#M} onwards.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04006414 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006415 * <p>
6416 * Changing the following settings has no effect as of {@link android.os.Build.VERSION_CODES#M}:
Esteban Talavera656fa7f2015-06-29 17:41:39 +01006417 * <ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006418 * <li>{@link Settings.Global#BLUETOOTH_ON}. Use
6419 * {@link android.bluetooth.BluetoothAdapter#enable()} and
6420 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01006421 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006422 * <li>{@link Settings.Global#MODE_RINGER}. Use
6423 * {@link android.media.AudioManager#setRingerMode(int)} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01006424 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006425 * <li>{@link Settings.Global#WIFI_ON}. Use
6426 * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01006427 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04006428 *
6429 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6430 * @param setting The name of the setting to update.
6431 * @param value The value to update the setting to.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006432 * @throws SecurityException if {@code admin} is not a device owner.
Julia Reynoldsda551652014-05-14 17:15:16 -04006433 */
Robin Lee25e26452015-06-02 09:56:29 -07006434 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006435 throwIfParentInstance("setGlobalSetting");
Julia Reynoldsda551652014-05-14 17:15:16 -04006436 if (mService != null) {
6437 try {
6438 mService.setGlobalSetting(admin, setting, value);
6439 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006440 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04006441 }
6442 }
6443 }
6444
6445 /**
6446 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
6447 * that the value of the setting is in the correct form for the setting type should be performed
6448 * by the caller.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006449 * <p>
6450 * The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04006451 * <ul>
6452 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
6453 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
6454 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006455 * <p>
6456 * A device owner can additionally update the following settings:
Julia Reynolds82735bc2014-09-04 16:43:30 -04006457 * <ul>
6458 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
6459 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006460 *
Suprabh Shukla0b1356f2017-02-21 14:33:50 -08006461 * <strong>Note: Starting from Android O, apps should no longer call this method with the
6462 * setting {@link android.provider.Settings.Secure#INSTALL_NON_MARKET_APPS}, which is
6463 * deprecated. Instead, device owners or profile owners should use the restriction
6464 * {@link UserManager#DISALLOW_INSTALL_UNKNOWN_SOURCES}.
6465 * If any app targeting {@link android.os.Build.VERSION_CODES#O} or higher calls this method
6466 * with {@link android.provider.Settings.Secure#INSTALL_NON_MARKET_APPS},
6467 * an {@link UnsupportedOperationException} is thrown.
6468 * </strong>
6469 *
Julia Reynoldsda551652014-05-14 17:15:16 -04006470 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6471 * @param setting The name of the setting to update.
6472 * @param value The value to update the setting to.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006473 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynoldsda551652014-05-14 17:15:16 -04006474 */
Robin Lee25e26452015-06-02 09:56:29 -07006475 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006476 throwIfParentInstance("setSecureSetting");
Julia Reynoldsda551652014-05-14 17:15:16 -04006477 if (mService != null) {
6478 try {
6479 mService.setSecureSetting(admin, setting, value);
6480 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006481 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04006482 }
6483 }
6484 }
6485
Amith Yamasanif20d6402014-05-24 15:34:37 -07006486 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006487 * Designates a specific service component as the provider for making permission requests of a
6488 * local or remote administrator of the user.
Amith Yamasanif20d6402014-05-24 15:34:37 -07006489 * <p/>
6490 * Only a profile owner can designate the restrictions provider.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006491 *
Amith Yamasanif20d6402014-05-24 15:34:37 -07006492 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07006493 * @param provider The component name of the service that implements
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006494 * {@link RestrictionsReceiver}. If this param is null, it removes the restrictions
6495 * provider previously assigned.
6496 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanif20d6402014-05-24 15:34:37 -07006497 */
Robin Lee25e26452015-06-02 09:56:29 -07006498 public void setRestrictionsProvider(@NonNull ComponentName admin,
6499 @Nullable ComponentName provider) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006500 throwIfParentInstance("setRestrictionsProvider");
Amith Yamasanif20d6402014-05-24 15:34:37 -07006501 if (mService != null) {
6502 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07006503 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07006504 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006505 throw re.rethrowFromSystemServer();
Amith Yamasanif20d6402014-05-24 15:34:37 -07006506 }
6507 }
6508 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04006509
6510 /**
6511 * Called by profile or device owners to set the master volume mute on or off.
Nicolas Prevotaef3ce22016-09-22 12:00:25 +01006512 * This has no effect when set on a managed profile.
Julia Reynolds4a21b252014-06-04 11:11:43 -04006513 *
6514 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6515 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006516 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds4a21b252014-06-04 11:11:43 -04006517 */
Robin Lee25e26452015-06-02 09:56:29 -07006518 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006519 throwIfParentInstance("setMasterVolumeMuted");
Julia Reynolds4a21b252014-06-04 11:11:43 -04006520 if (mService != null) {
6521 try {
6522 mService.setMasterVolumeMuted(admin, on);
6523 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006524 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04006525 }
6526 }
6527 }
6528
6529 /**
6530 * Called by profile or device owners to check whether the master volume mute is on or off.
6531 *
6532 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6533 * @return {@code true} if master volume is muted, {@code false} if it's not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006534 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds4a21b252014-06-04 11:11:43 -04006535 */
Robin Lee25e26452015-06-02 09:56:29 -07006536 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006537 throwIfParentInstance("isMasterVolumeMuted");
Julia Reynolds4a21b252014-06-04 11:11:43 -04006538 if (mService != null) {
6539 try {
6540 return mService.isMasterVolumeMuted(admin);
6541 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006542 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04006543 }
6544 }
6545 return false;
6546 }
Kenny Guyc13053b2014-05-29 14:17:17 +01006547
6548 /**
Edman Anjosa5f2fb12016-12-19 11:25:54 -08006549 * Change whether a user can uninstall a package. This function can be called by a device owner,
6550 * profile owner, or by a delegate given the {@link #DELEGATION_BLOCK_UNINSTALL} scope via
6551 * {@link #setDelegatedScopes}.
Kenny Guyc13053b2014-05-29 14:17:17 +01006552 *
Edman Anjosa5f2fb12016-12-19 11:25:54 -08006553 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
6554 * {@code null} if the caller is a block uninstall delegate.
Kenny Guyc13053b2014-05-29 14:17:17 +01006555 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01006556 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006557 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjosa5f2fb12016-12-19 11:25:54 -08006558 * @see #setDelegatedScopes
6559 * @see #DELEGATION_BLOCK_UNINSTALL
Kenny Guyc13053b2014-05-29 14:17:17 +01006560 */
Edman Anjosa5f2fb12016-12-19 11:25:54 -08006561 public void setUninstallBlocked(@Nullable ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01006562 boolean uninstallBlocked) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006563 throwIfParentInstance("setUninstallBlocked");
Kenny Guyc13053b2014-05-29 14:17:17 +01006564 if (mService != null) {
6565 try {
Edman Anjosa5f2fb12016-12-19 11:25:54 -08006566 mService.setUninstallBlocked(admin, mContext.getPackageName(), packageName,
6567 uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01006568 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006569 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01006570 }
6571 }
6572 }
6573
6574 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08006575 * Check whether the user has been blocked by device policy from uninstalling a package.
Rubin Xua97855b2014-11-07 05:41:00 +00006576 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00006577 * <p>
6578 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006579 * behavior of this API is changed such that passing {@code null} as the {@code admin} parameter
6580 * will return if any admin has blocked the uninstallation. Before L MR1, passing {@code null}
6581 * will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01006582 *
Robin Lee25e26452015-06-02 09:56:29 -07006583 * @param admin The name of the admin component whose blocking policy will be checked, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006584 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01006585 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00006586 * @return true if uninstallation is blocked.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006587 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyc13053b2014-05-29 14:17:17 +01006588 */
Robin Lee25e26452015-06-02 09:56:29 -07006589 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006590 throwIfParentInstance("isUninstallBlocked");
Kenny Guyc13053b2014-05-29 14:17:17 +01006591 if (mService != null) {
6592 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01006593 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01006594 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006595 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01006596 }
6597 }
6598 return false;
6599 }
Svetoslav976e8bd2014-07-16 15:12:03 -07006600
6601 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006602 * Called by the profile owner of a managed profile to enable widget providers from a given
6603 * package to be available in the parent profile. As a result the user will be able to add
6604 * widgets from the white-listed package running under the profile to a widget host which runs
6605 * under the parent profile, for example the home screen. Note that a package may have zero or
6606 * more provider components, where each component provides a different widget type.
Svetoslav976e8bd2014-07-16 15:12:03 -07006607 * <p>
6608 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07006609 *
6610 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6611 * @param packageName The package from which widget providers are white-listed.
6612 * @return Whether the package was added.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006613 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07006614 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
6615 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
6616 */
Robin Lee25e26452015-06-02 09:56:29 -07006617 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006618 throwIfParentInstance("addCrossProfileWidgetProvider");
Svetoslav976e8bd2014-07-16 15:12:03 -07006619 if (mService != null) {
6620 try {
6621 return mService.addCrossProfileWidgetProvider(admin, packageName);
6622 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006623 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07006624 }
6625 }
6626 return false;
6627 }
6628
6629 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07006630 * Called by the profile owner of a managed profile to disable widget providers from a given
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006631 * package to be available in the parent profile. For this method to take effect the package
6632 * should have been added via
6633 * {@link #addCrossProfileWidgetProvider( android.content.ComponentName, String)}.
Svetoslav976e8bd2014-07-16 15:12:03 -07006634 * <p>
6635 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07006636 *
6637 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006638 * @param packageName The package from which widget providers are no longer white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07006639 * @return Whether the package was removed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006640 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07006641 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
6642 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
6643 */
Esteban Talavera62399912016-01-11 15:37:55 +00006644 public boolean removeCrossProfileWidgetProvider(
6645 @NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006646 throwIfParentInstance("removeCrossProfileWidgetProvider");
Svetoslav976e8bd2014-07-16 15:12:03 -07006647 if (mService != null) {
6648 try {
6649 return mService.removeCrossProfileWidgetProvider(admin, packageName);
6650 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006651 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07006652 }
6653 }
6654 return false;
6655 }
6656
6657 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07006658 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07006659 * available in the parent profile.
6660 *
6661 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6662 * @return The white-listed package list.
Svetoslav976e8bd2014-07-16 15:12:03 -07006663 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
6664 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006665 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07006666 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006667 public @NonNull List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006668 throwIfParentInstance("getCrossProfileWidgetProviders");
Svetoslav976e8bd2014-07-16 15:12:03 -07006669 if (mService != null) {
6670 try {
6671 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
6672 if (providers != null) {
6673 return providers;
6674 }
6675 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006676 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07006677 }
6678 }
6679 return Collections.emptyList();
6680 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006681
6682 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08006683 * Called by profile or device owners to set the user's photo.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006684 *
6685 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6686 * @param icon the bitmap to set as the photo.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006687 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006688 */
Robin Lee25e26452015-06-02 09:56:29 -07006689 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006690 throwIfParentInstance("setUserIcon");
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006691 try {
6692 mService.setUserIcon(admin, icon);
6693 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006694 throw re.rethrowFromSystemServer();
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006695 }
6696 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04006697
6698 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01006699 * Called by device owners to set a local system update policy. When a new policy is set,
6700 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00006701 *
Robin Lee25e26452015-06-02 09:56:29 -07006702 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006703 * components in the device owner package can set system update policies and the most
6704 * recent policy takes effect.
Robin Lee25e26452015-06-02 09:56:29 -07006705 * @param policy the new policy, or {@code null} to clear the current policy.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006706 * @throws SecurityException if {@code admin} is not a device owner.
Rubin Xu5faad8e2015-04-20 17:43:48 +01006707 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00006708 */
Robin Lee25e26452015-06-02 09:56:29 -07006709 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006710 throwIfParentInstance("setSystemUpdatePolicy");
Rubin Xu8027a4f2015-03-10 17:52:37 +00006711 if (mService != null) {
6712 try {
Robin Lee25e26452015-06-02 09:56:29 -07006713 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00006714 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006715 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00006716 }
6717 }
6718 }
6719
6720 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01006721 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00006722 *
Robin Lee25e26452015-06-02 09:56:29 -07006723 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00006724 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006725 public @Nullable SystemUpdatePolicy getSystemUpdatePolicy() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006726 throwIfParentInstance("getSystemUpdatePolicy");
Rubin Xu8027a4f2015-03-10 17:52:37 +00006727 if (mService != null) {
6728 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01006729 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00006730 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006731 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00006732 }
6733 }
6734 return null;
6735 }
Benjamin Franze36087e2015-04-07 16:40:34 +01006736
6737 /**
6738 * Called by a device owner to disable the keyguard altogether.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006739 * <p>
6740 * Setting the keyguard to disabled has the same effect as choosing "None" as the screen lock
6741 * type. However, this call has no effect if a password, pin or pattern is currently set. If a
6742 * password, pin or pattern is set after the keyguard was disabled, the keyguard stops being
6743 * disabled.
Benjamin Franze36087e2015-04-07 16:40:34 +01006744 *
6745 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01006746 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01006747 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006748 * place. {@code true} otherwise.
6749 * @throws SecurityException if {@code admin} is not a device owner.
Benjamin Franze36087e2015-04-07 16:40:34 +01006750 */
Robin Lee25e26452015-06-02 09:56:29 -07006751 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006752 throwIfParentInstance("setKeyguardDisabled");
Benjamin Franze36087e2015-04-07 16:40:34 +01006753 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01006754 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01006755 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006756 throw re.rethrowFromSystemServer();
Benjamin Franze36087e2015-04-07 16:40:34 +01006757 }
6758 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00006759
6760 /**
Benjamin Franzbece8062015-05-06 12:14:31 +01006761 * Called by device owner to disable the status bar. Disabling the status bar blocks
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006762 * notifications, quick settings and other screen overlays that allow escaping from a single use
6763 * device.
Benjamin Franzea2ec972015-03-16 17:18:09 +00006764 *
6765 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01006766 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006767 * @return {@code false} if attempting to disable the status bar failed. {@code true} otherwise.
6768 * @throws SecurityException if {@code admin} is not a device owner.
Benjamin Franzea2ec972015-03-16 17:18:09 +00006769 */
Robin Lee25e26452015-06-02 09:56:29 -07006770 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006771 throwIfParentInstance("setStatusBarDisabled");
Benjamin Franzea2ec972015-03-16 17:18:09 +00006772 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01006773 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00006774 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006775 throw re.rethrowFromSystemServer();
Benjamin Franzea2ec972015-03-16 17:18:09 +00006776 }
6777 }
Rubin Xudc105cc2015-04-14 23:38:01 +01006778
6779 /**
Charles Hedea0c3b2017-01-13 10:04:12 +00006780 * Called by the system update service to notify device and profile owners of pending system
6781 * updates.
Rubin Xudc105cc2015-04-14 23:38:01 +01006782 *
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06006783 * This method should only be used when it is unknown whether the pending system
Charles Hedea0c3b2017-01-13 10:04:12 +00006784 * update is a security patch. Otherwise, use
6785 * {@link #notifyPendingSystemUpdate(long, boolean)}.
6786 *
6787 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()}
6788 * indicating when the current pending update was first available. {@code -1} if no
6789 * update is available.
6790 * @see #notifyPendingSystemUpdate(long, boolean)
Rubin Xudc105cc2015-04-14 23:38:01 +01006791 * @hide
6792 */
6793 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06006794 @RequiresPermission(android.Manifest.permission.NOTIFY_PENDING_SYSTEM_UPDATE)
Rubin Xudc105cc2015-04-14 23:38:01 +01006795 public void notifyPendingSystemUpdate(long updateReceivedTime) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006796 throwIfParentInstance("notifyPendingSystemUpdate");
Rubin Xudc105cc2015-04-14 23:38:01 +01006797 if (mService != null) {
6798 try {
Charles Hedea0c3b2017-01-13 10:04:12 +00006799 mService.notifyPendingSystemUpdate(SystemUpdateInfo.of(updateReceivedTime));
6800 } catch (RemoteException re) {
6801 throw re.rethrowFromSystemServer();
6802 }
6803 }
6804 }
6805
6806 /**
6807 * Called by the system update service to notify device and profile owners of pending system
6808 * updates.
6809 *
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06006810 * This method should be used instead of {@link #notifyPendingSystemUpdate(long)}
Charles Hedea0c3b2017-01-13 10:04:12 +00006811 * when it is known whether the pending system update is a security patch.
6812 *
6813 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()}
6814 * indicating when the current pending update was first available. {@code -1} if no
6815 * update is available.
6816 * @param isSecurityPatch {@code true} if this system update is purely a security patch;
6817 * {@code false} if not.
6818 * @see #notifyPendingSystemUpdate(long)
6819 * @hide
6820 */
6821 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06006822 @RequiresPermission(android.Manifest.permission.NOTIFY_PENDING_SYSTEM_UPDATE)
Charles Hedea0c3b2017-01-13 10:04:12 +00006823 public void notifyPendingSystemUpdate(long updateReceivedTime, boolean isSecurityPatch) {
6824 throwIfParentInstance("notifyPendingSystemUpdate");
6825 if (mService != null) {
6826 try {
6827 mService.notifyPendingSystemUpdate(SystemUpdateInfo.of(updateReceivedTime,
6828 isSecurityPatch));
Rubin Xudc105cc2015-04-14 23:38:01 +01006829 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006830 throw re.rethrowFromSystemServer();
Rubin Xudc105cc2015-04-14 23:38:01 +01006831 }
6832 }
6833 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04006834
6835 /**
Pavel Grafovd65799e2016-12-02 11:21:45 +00006836 * Called by device or profile owners to get information about a pending system update.
6837 *
6838 * @param admin Which profile or device owner this request is associated with.
6839 * @return Information about a pending system update or {@code null} if no update pending.
6840 * @throws SecurityException if {@code admin} is not a device or profile owner.
6841 * @see DeviceAdminReceiver#onSystemUpdatePending(Context, Intent, long)
6842 */
6843 public @Nullable SystemUpdateInfo getPendingSystemUpdate(@NonNull ComponentName admin) {
6844 throwIfParentInstance("getPendingSystemUpdate");
6845 try {
6846 return mService.getPendingSystemUpdate(admin);
6847 } catch (RemoteException re) {
6848 throw re.rethrowFromSystemServer();
6849 }
6850 }
6851
6852 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006853 * Set the default response for future runtime permission requests by applications. This
6854 * function can be called by a device owner, profile owner, or by a delegate given the
6855 * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}.
6856 * The policy can allow for normal operation which prompts the user to grant a permission, or
6857 * can allow automatic granting or denying of runtime permission requests by an application.
6858 * This also applies to new permissions declared by app updates. When a permission is denied or
6859 * granted this way, the effect is equivalent to setting the permission * grant state via
6860 * {@link #setPermissionGrantState}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006861 * <p/>
6862 * As this policy only acts on runtime permission requests, it only applies to applications
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07006863 * built with a {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Benjamin Franz45dd6662015-07-08 14:24:14 +01006864 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07006865 * @param admin Which profile or device owner this request is associated with.
6866 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006867 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
6868 * @throws SecurityException if {@code admin} is not a device or profile owner.
Benjamin Franz45dd6662015-07-08 14:24:14 +01006869 * @see #setPermissionGrantState
Edman Anjos52088e42017-01-13 22:26:17 +01006870 * @see #setDelegatedScopes
6871 * @see #DELEGATION_PERMISSION_GRANT
Amith Yamasanid49489b2015-04-28 14:00:26 -07006872 */
Robin Lee25e26452015-06-02 09:56:29 -07006873 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006874 throwIfParentInstance("setPermissionPolicy");
Amith Yamasanid49489b2015-04-28 14:00:26 -07006875 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006876 mService.setPermissionPolicy(admin, mContext.getPackageName(), policy);
Amith Yamasanid49489b2015-04-28 14:00:26 -07006877 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006878 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07006879 }
6880 }
6881
6882 /**
6883 * Returns the current runtime permission policy set by the device or profile owner. The
6884 * default is {@link #PERMISSION_POLICY_PROMPT}.
Edman Anjos52088e42017-01-13 22:26:17 +01006885 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07006886 * @param admin Which profile or device owner this request is associated with.
6887 * @return the current policy for future permission requests.
6888 */
Esteban Talavera28b95702015-06-24 15:23:42 +01006889 public int getPermissionPolicy(ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006890 throwIfParentInstance("getPermissionPolicy");
Amith Yamasanid49489b2015-04-28 14:00:26 -07006891 try {
6892 return mService.getPermissionPolicy(admin);
6893 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006894 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07006895 }
6896 }
6897
6898 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006899 * Sets the grant state of a runtime permission for a specific application. The state can be
6900 * {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it through the UI,
6901 * {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission is denied and the user
6902 * cannot manage it through the UI, and {@link #PERMISSION_GRANT_STATE_GRANTED granted} in which
6903 * the permission is granted and the user cannot manage it through the UI. This might affect all
6904 * permissions in a group that the runtime permission belongs to. This method can only be called
Edman Anjos52088e42017-01-13 22:26:17 +01006905 * by a profile owner, device owner, or a delegate given the
6906 * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006907 * <p/>
6908 * Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not revoke
6909 * the permission. It retains the previous grant, if any.
6910 * <p/>
6911 * Permissions can be granted or revoked only for applications built with a
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07006912 * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07006913 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07006914 * @param admin Which profile or device owner this request is associated with.
6915 * @param packageName The application to grant or revoke a permission to.
6916 * @param permission The permission to grant or revoke.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006917 * @param grantState The permission grant state which is one of
6918 * {@link #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
6919 * {@link #PERMISSION_GRANT_STATE_GRANTED},
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006920 * @return whether the permission was successfully granted or revoked.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006921 * @throws SecurityException if {@code admin} is not a device or profile owner.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006922 * @see #PERMISSION_GRANT_STATE_DENIED
6923 * @see #PERMISSION_GRANT_STATE_DEFAULT
6924 * @see #PERMISSION_GRANT_STATE_GRANTED
Edman Anjos52088e42017-01-13 22:26:17 +01006925 * @see #setDelegatedScopes
6926 * @see #DELEGATION_PERMISSION_GRANT
Amith Yamasanid49489b2015-04-28 14:00:26 -07006927 */
Robin Lee25e26452015-06-02 09:56:29 -07006928 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006929 String permission, int grantState) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006930 throwIfParentInstance("setPermissionGrantState");
Amith Yamasanid49489b2015-04-28 14:00:26 -07006931 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006932 return mService.setPermissionGrantState(admin, mContext.getPackageName(), packageName,
6933 permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07006934 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006935 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07006936 }
6937 }
Amith Yamasani184b3752015-05-22 13:00:51 -07006938
6939 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006940 * Returns the current grant state of a runtime permission for a specific application. This
6941 * function can be called by a device owner, profile owner, or by a delegate given the
6942 * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}.
Amith Yamasani184b3752015-05-22 13:00:51 -07006943 *
Edman Anjos52088e42017-01-13 22:26:17 +01006944 * @param admin Which profile or device owner this request is associated with, or {@code null}
6945 * if the caller is a permission grant delegate.
Amith Yamasani184b3752015-05-22 13:00:51 -07006946 * @param packageName The application to check the grant state for.
6947 * @param permission The permission to check for.
6948 * @return the current grant state specified by device policy. If the profile or device owner
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006949 * has not set a grant state, the return value is
6950 * {@link #PERMISSION_GRANT_STATE_DEFAULT}. This does not indicate whether or not the
6951 * permission is currently granted for the package.
6952 * <p/>
6953 * If a grant state was set by the profile or device owner, then the return value will
6954 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or
6955 * {@link #PERMISSION_GRANT_STATE_GRANTED}, which indicates if the permission is
6956 * currently denied or granted.
6957 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasani184b3752015-05-22 13:00:51 -07006958 * @see #setPermissionGrantState(ComponentName, String, String, int)
6959 * @see PackageManager#checkPermission(String, String)
Edman Anjos52088e42017-01-13 22:26:17 +01006960 * @see #setDelegatedScopes
6961 * @see #DELEGATION_PERMISSION_GRANT
Amith Yamasani184b3752015-05-22 13:00:51 -07006962 */
Bartosz Fabianowski4b0624f2017-01-16 11:47:28 +01006963 public int getPermissionGrantState(@Nullable ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07006964 String permission) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006965 throwIfParentInstance("getPermissionGrantState");
Amith Yamasani184b3752015-05-22 13:00:51 -07006966 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006967 return mService.getPermissionGrantState(admin, mContext.getPackageName(), packageName,
6968 permission);
Amith Yamasani184b3752015-05-22 13:00:51 -07006969 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006970 throw re.rethrowFromSystemServer();
Amith Yamasani184b3752015-05-22 13:00:51 -07006971 }
6972 }
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006973
6974 /**
Esteban Talavera01576862016-12-15 11:16:44 +00006975 * Returns whether it is possible for the caller to initiate provisioning of a managed profile
6976 * or device, setting itself as the device or profile owner.
6977 *
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006978 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
6979 * {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Esteban Talavera01576862016-12-15 11:16:44 +00006980 * @return whether provisioning a managed profile or device is possible.
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006981 * @throws IllegalArgumentException if the supplied action is not valid.
6982 */
Esteban Talavera01576862016-12-15 11:16:44 +00006983 public boolean isProvisioningAllowed(@NonNull String action) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006984 throwIfParentInstance("isProvisioningAllowed");
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006985 try {
Esteban Talavera01576862016-12-15 11:16:44 +00006986 return mService.isProvisioningAllowed(action, mContext.getPackageName());
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006987 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006988 throw re.rethrowFromSystemServer();
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006989 }
6990 }
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006991
6992 /**
Esteban Talavera01576862016-12-15 11:16:44 +00006993 * Checks whether it is possible to initiate provisioning a managed device,
6994 * profile or user, setting the given package as owner.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00006995 *
6996 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
6997 * {@link #ACTION_PROVISION_MANAGED_PROFILE},
6998 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE},
6999 * {@link #ACTION_PROVISION_MANAGED_USER}
Esteban Talavera01576862016-12-15 11:16:44 +00007000 * @param packageName The package of the component that would be set as device, user, or profile
7001 * owner.
7002 * @return A {@link ProvisioningPreCondition} value indicating whether provisioning is allowed.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00007003 * @hide
7004 */
Esteban Talavera01576862016-12-15 11:16:44 +00007005 public @ProvisioningPreCondition int checkProvisioningPreCondition(
7006 String action, @NonNull String packageName) {
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00007007 try {
Esteban Talavera01576862016-12-15 11:16:44 +00007008 return mService.checkProvisioningPreCondition(action, packageName);
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00007009 } catch (RemoteException re) {
7010 throw re.rethrowFromSystemServer();
7011 }
7012 }
7013
7014 /**
Mahaver Chopra15a46b02015-11-11 14:54:35 +00007015 * Return if this user is a managed profile of another user. An admin can become the profile
7016 * owner of a managed profile with {@link #ACTION_PROVISION_MANAGED_PROFILE} and of a managed
Kenny Guyffa38402016-03-31 16:40:57 +01007017 * user with {@link #createAndManageUser}
Mahaver Chopra15a46b02015-11-11 14:54:35 +00007018 * @param admin Which profile owner this request is associated with.
7019 * @return if this user is a managed profile of another user.
7020 */
7021 public boolean isManagedProfile(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007022 throwIfParentInstance("isManagedProfile");
Mahaver Chopra15a46b02015-11-11 14:54:35 +00007023 try {
7024 return mService.isManagedProfile(admin);
7025 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007026 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00007027 }
7028 }
7029
7030 /**
7031 * @hide
7032 * Return if this user is a system-only user. An admin can manage a device from a system only
7033 * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}.
7034 * @param admin Which device owner this request is associated with.
7035 * @return if this user is a system-only user.
7036 */
7037 public boolean isSystemOnlyUser(@NonNull ComponentName admin) {
7038 try {
7039 return mService.isSystemOnlyUser(admin);
7040 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007041 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00007042 }
7043 }
Makoto Onukia31ebbc2015-11-23 17:15:21 -08007044
7045 /**
7046 * Called by device owner to get the MAC address of the Wi-Fi device.
7047 *
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08007048 * @param admin Which device owner this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007049 * @return the MAC address of the Wi-Fi device, or null when the information is not available.
7050 * (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.)
7051 * <p>
7052 * The address will be in the {@code XX:XX:XX:XX:XX:XX} format.
7053 * @throws SecurityException if {@code admin} is not a device owner.
Makoto Onukia31ebbc2015-11-23 17:15:21 -08007054 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007055 public @Nullable String getWifiMacAddress(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007056 throwIfParentInstance("getWifiMacAddress");
Makoto Onukia31ebbc2015-11-23 17:15:21 -08007057 try {
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08007058 return mService.getWifiMacAddress(admin);
Makoto Onukia31ebbc2015-11-23 17:15:21 -08007059 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007060 throw re.rethrowFromSystemServer();
Makoto Onukia31ebbc2015-11-23 17:15:21 -08007061 }
7062 }
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00007063
7064 /**
Mahaver Chopra1216ae52016-03-11 15:39:48 +00007065 * Called by device owner to reboot the device. If there is an ongoing call on the device,
7066 * throws an {@link IllegalStateException}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007067 * @param admin Which device owner the request is associated with.
Mahaver Chopra1216ae52016-03-11 15:39:48 +00007068 * @throws IllegalStateException if device has an ongoing call.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007069 * @throws SecurityException if {@code admin} is not a device owner.
Mahaver Chopra1216ae52016-03-11 15:39:48 +00007070 * @see TelephonyManager#CALL_STATE_IDLE
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00007071 */
7072 public void reboot(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007073 throwIfParentInstance("reboot");
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00007074 try {
7075 mService.reboot(admin);
7076 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007077 throw re.rethrowFromSystemServer();
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00007078 }
7079 }
Kenny Guy06de4e72015-12-22 12:07:39 +00007080
7081 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007082 * Called by a device admin to set the short support message. This will be displayed to the user
7083 * in settings screens where funtionality has been disabled by the admin. The message should be
7084 * limited to a short statement such as "This setting is disabled by your administrator. Contact
7085 * someone@example.com for support." If the message is longer than 200 characters it may be
7086 * truncated.
7087 * <p>
7088 * If the short support message needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007089 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
7090 * and set a new version of this string accordingly.
7091 *
Kenny Guy06de4e72015-12-22 12:07:39 +00007092 * @see #setLongSupportMessage
Kenny Guy06de4e72015-12-22 12:07:39 +00007093 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007094 * @param message Short message to be displayed to the user in settings or null to clear the
7095 * existing message.
7096 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00007097 */
7098 public void setShortSupportMessage(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007099 @Nullable CharSequence message) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007100 throwIfParentInstance("setShortSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00007101 if (mService != null) {
7102 try {
7103 mService.setShortSupportMessage(admin, message);
7104 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007105 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00007106 }
7107 }
7108 }
7109
7110 /**
7111 * Called by a device admin to get the short support message.
7112 *
7113 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007114 * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)} or
7115 * null if no message has been set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007116 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00007117 */
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007118 public CharSequence getShortSupportMessage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007119 throwIfParentInstance("getShortSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00007120 if (mService != null) {
7121 try {
7122 return mService.getShortSupportMessage(admin);
7123 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007124 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00007125 }
7126 }
7127 return null;
7128 }
7129
7130 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007131 * Called by a device admin to set the long support message. This will be displayed to the user
7132 * in the device administators settings screen.
7133 * <p>
7134 * If the long support message needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007135 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
7136 * and set a new version of this string accordingly.
7137 *
Kenny Guy06de4e72015-12-22 12:07:39 +00007138 * @see #setShortSupportMessage
Kenny Guy06de4e72015-12-22 12:07:39 +00007139 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007140 * @param message Long message to be displayed to the user in settings or null to clear the
7141 * existing message.
7142 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00007143 */
7144 public void setLongSupportMessage(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007145 @Nullable CharSequence message) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007146 throwIfParentInstance("setLongSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00007147 if (mService != null) {
7148 try {
7149 mService.setLongSupportMessage(admin, message);
7150 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007151 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00007152 }
7153 }
7154 }
7155
7156 /**
7157 * Called by a device admin to get the long support message.
7158 *
7159 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007160 * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)} or
7161 * null if no message has been set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007162 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00007163 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007164 public @Nullable CharSequence getLongSupportMessage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007165 throwIfParentInstance("getLongSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00007166 if (mService != null) {
7167 try {
7168 return mService.getLongSupportMessage(admin);
7169 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007170 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00007171 }
7172 }
7173 return null;
7174 }
7175
7176 /**
7177 * Called by the system to get the short support message.
7178 *
7179 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7180 * @param userHandle user id the admin is running as.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007181 * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)}
Kenny Guy06de4e72015-12-22 12:07:39 +00007182 *
7183 * @hide
7184 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007185 public @Nullable CharSequence getShortSupportMessageForUser(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007186 int userHandle) {
Kenny Guy06de4e72015-12-22 12:07:39 +00007187 if (mService != null) {
7188 try {
7189 return mService.getShortSupportMessageForUser(admin, userHandle);
7190 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007191 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00007192 }
7193 }
7194 return null;
7195 }
7196
7197
7198 /**
7199 * Called by the system to get the long support message.
7200 *
7201 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7202 * @param userHandle user id the admin is running as.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007203 * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)}
Kenny Guy06de4e72015-12-22 12:07:39 +00007204 *
7205 * @hide
7206 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007207 public @Nullable CharSequence getLongSupportMessageForUser(
7208 @NonNull ComponentName admin, int userHandle) {
Kenny Guy06de4e72015-12-22 12:07:39 +00007209 if (mService != null) {
7210 try {
7211 return mService.getLongSupportMessageForUser(admin, userHandle);
7212 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007213 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00007214 }
7215 }
7216 return null;
7217 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00007218
7219 /**
Esteban Talavera62399912016-01-11 15:37:55 +00007220 * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager}
7221 * whose calls act on the parent profile.
Benjamin Franz66b45f02016-04-05 19:12:39 +01007222 *
7223 * <p>The following methods are supported for the parent instance, all other methods will
7224 * throw a SecurityException when called on the parent instance:
7225 * <ul>
7226 * <li>{@link #getPasswordQuality}</li>
7227 * <li>{@link #setPasswordQuality}</li>
7228 * <li>{@link #getPasswordMinimumLength}</li>
7229 * <li>{@link #setPasswordMinimumLength}</li>
7230 * <li>{@link #getPasswordMinimumUpperCase}</li>
7231 * <li>{@link #setPasswordMinimumUpperCase}</li>
7232 * <li>{@link #getPasswordMinimumLowerCase}</li>
7233 * <li>{@link #setPasswordMinimumLowerCase}</li>
7234 * <li>{@link #getPasswordMinimumLetters}</li>
7235 * <li>{@link #setPasswordMinimumLetters}</li>
7236 * <li>{@link #getPasswordMinimumNumeric}</li>
7237 * <li>{@link #setPasswordMinimumNumeric}</li>
7238 * <li>{@link #getPasswordMinimumSymbols}</li>
7239 * <li>{@link #setPasswordMinimumSymbols}</li>
7240 * <li>{@link #getPasswordMinimumNonLetter}</li>
7241 * <li>{@link #setPasswordMinimumNonLetter}</li>
7242 * <li>{@link #getPasswordHistoryLength}</li>
7243 * <li>{@link #setPasswordHistoryLength}</li>
7244 * <li>{@link #getPasswordExpirationTimeout}</li>
7245 * <li>{@link #setPasswordExpirationTimeout}</li>
7246 * <li>{@link #getPasswordExpiration}</li>
Charles He8c760562016-10-25 16:36:53 +01007247 * <li>{@link #getPasswordMaximumLength}</li>
Benjamin Franz66b45f02016-04-05 19:12:39 +01007248 * <li>{@link #isActivePasswordSufficient}</li>
7249 * <li>{@link #getCurrentFailedPasswordAttempts}</li>
7250 * <li>{@link #getMaximumFailedPasswordsForWipe}</li>
7251 * <li>{@link #setMaximumFailedPasswordsForWipe}</li>
7252 * <li>{@link #getMaximumTimeToLock}</li>
7253 * <li>{@link #setMaximumTimeToLock}</li>
7254 * <li>{@link #lockNow}</li>
7255 * <li>{@link #getKeyguardDisabledFeatures}</li>
7256 * <li>{@link #setKeyguardDisabledFeatures}</li>
7257 * <li>{@link #getTrustAgentConfiguration}</li>
7258 * <li>{@link #setTrustAgentConfiguration}</li>
Michal Karpinskia20d8bb2016-11-23 12:09:08 +00007259 * <li>{@link #getRequiredStrongAuthTimeout}</li>
7260 * <li>{@link #setRequiredStrongAuthTimeout}</li>
Benjamin Franz66b45f02016-04-05 19:12:39 +01007261 * </ul>
Clara Bayarri3e826ef2015-12-14 17:51:22 +00007262 *
7263 * @return a new instance of {@link DevicePolicyManager} that acts on the parent profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007264 * @throws SecurityException if {@code admin} is not a profile owner.
Clara Bayarri3e826ef2015-12-14 17:51:22 +00007265 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007266 public @NonNull DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007267 throwIfParentInstance("getParentProfileInstance");
Clara Bayarri3e826ef2015-12-14 17:51:22 +00007268 try {
7269 if (!mService.isManagedProfile(admin)) {
7270 throw new SecurityException("The current user does not have a parent profile.");
7271 }
Jeff Sharkey49ca5292016-05-10 12:54:45 -06007272 return new DevicePolicyManager(mContext, mService, true);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007273 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007274 throw e.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007275 }
7276 }
7277
7278 /**
Esteban Talaverad36dd152016-12-15 08:51:45 +00007279 * Called by device owner to control the security logging feature.
Michal Karpinski6235a942016-03-15 12:07:23 +00007280 *
7281 * <p> Security logs contain various information intended for security auditing purposes.
7282 * See {@link SecurityEvent} for details.
7283 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00007284 * <p><strong>Note:</strong> The device owner won't be able to retrieve security logs if there
7285 * are unaffiliated secondary users or profiles on the device, regardless of whether the
7286 * feature is enabled. Logs will be discarded if the internal buffer fills up while waiting for
7287 * all users to become affiliated. Therefore it's recommended that affiliation ids are set for
7288 * new users as soon as possible after provisioning via {@link #setAffiliationIds}.
Michal Karpinskib58e4962016-03-01 14:55:10 +00007289 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007290 * @param admin Which device owner this request is associated with.
Michal Karpinski6235a942016-03-15 12:07:23 +00007291 * @param enabled whether security logging should be enabled or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007292 * @throws SecurityException if {@code admin} is not a device owner.
Michal Karpinski6235a942016-03-15 12:07:23 +00007293 * @see #retrieveSecurityLogs
7294 */
7295 public void setSecurityLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007296 throwIfParentInstance("setSecurityLoggingEnabled");
Michal Karpinski6235a942016-03-15 12:07:23 +00007297 try {
7298 mService.setSecurityLoggingEnabled(admin, enabled);
7299 } catch (RemoteException re) {
7300 throw re.rethrowFromSystemServer();
7301 }
7302 }
7303
7304 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00007305 * Return whether security logging is enabled or not by the device owner.
7306 *
7307 * <p>Can only be called by the device owner, otherwise a {@link SecurityException} will be
7308 * thrown.
7309 *
7310 * @param admin Which device owner this request is associated with.
7311 * @return {@code true} if security logging is enabled by device owner, {@code false} otherwise.
7312 * @throws SecurityException if {@code admin} is not a device owner.
7313 */
Bartosz Fabianowski0ec00002017-03-24 14:22:24 +01007314 public boolean isSecurityLoggingEnabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007315 throwIfParentInstance("isSecurityLoggingEnabled");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007316 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00007317 return mService.isSecurityLoggingEnabled(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007318 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007319 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007320 }
7321 }
7322
7323 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00007324 * Called by device owner to retrieve all new security logging entries since the last call to
7325 * this API after device boots.
7326 *
7327 * <p> Access to the logs is rate limited and it will only return new logs after the device
7328 * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}.
7329 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00007330 * <p>If there is any other user or profile on the device, it must be affiliated with the
7331 * device owner. Otherwise a {@link SecurityException} will be thrown. See
7332 * {@link #setAffiliationIds}
Michal Karpinskib58e4962016-03-01 14:55:10 +00007333 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007334 * @param admin Which device owner this request is associated with.
Michal Karpinski6235a942016-03-15 12:07:23 +00007335 * @return the new batch of security logs which is a list of {@link SecurityEvent},
7336 * or {@code null} if rate limitation is exceeded or if logging is currently disabled.
Esteban Talaverad36dd152016-12-15 08:51:45 +00007337 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
7338 * profile or secondary user that is not affiliated with the device owner user.
7339 * @see DeviceAdminReceiver#onSecurityLogsAvailable
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007340 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007341 public @Nullable List<SecurityEvent> retrieveSecurityLogs(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007342 throwIfParentInstance("retrieveSecurityLogs");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007343 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00007344 ParceledListSlice<SecurityEvent> list = mService.retrieveSecurityLogs(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007345 if (list != null) {
7346 return list.getList();
7347 } else {
7348 // Rate limit exceeded.
7349 return null;
7350 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00007351 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007352 throw re.rethrowFromSystemServer();
Clara Bayarri3e826ef2015-12-14 17:51:22 +00007353 }
7354 }
Benjamin Franz59720bb2016-01-18 15:26:11 +00007355
7356 /**
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00007357 * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent
7358 * profile.
7359 *
7360 * @hide
7361 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007362 public @NonNull DevicePolicyManager getParentProfileInstance(UserInfo uInfo) {
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00007363 mContext.checkSelfPermission(
7364 android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS);
7365 if (!uInfo.isManagedProfile()) {
7366 throw new SecurityException("The user " + uInfo.id
7367 + " does not have a parent profile.");
7368 }
Jeff Sharkey49ca5292016-05-10 12:54:45 -06007369 return new DevicePolicyManager(mContext, mService, true);
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00007370 }
7371
7372 /**
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007373 * Called by device owners to retrieve device logs from before the device's last reboot.
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007374 * <p>
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01007375 * <strong> This API is not supported on all devices. Calling this API on unsupported devices
7376 * will result in {@code null} being returned. The device logs are retrieved from a RAM region
7377 * which is not guaranteed to be corruption-free during power cycles, as a result be cautious
7378 * about data corruption when parsing. </strong>
Esteban Talaverad36dd152016-12-15 08:51:45 +00007379 *
7380 * <p>If there is any other user or profile on the device, it must be affiliated with the
7381 * device owner. Otherwise a {@link SecurityException} will be thrown. See
7382 * {@link #setAffiliationIds}
Michal Karpinskib58e4962016-03-01 14:55:10 +00007383 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007384 * @param admin Which device owner this request is associated with.
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01007385 * @return Device logs from before the latest reboot of the system, or {@code null} if this API
7386 * is not supported on the device.
Esteban Talaverad36dd152016-12-15 08:51:45 +00007387 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
7388 * profile or secondary user that is not affiliated with the device owner user.
7389 * @see #retrieveSecurityLogs
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007390 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007391 public @Nullable List<SecurityEvent> retrievePreRebootSecurityLogs(
7392 @NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007393 throwIfParentInstance("retrievePreRebootSecurityLogs");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007394 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00007395 ParceledListSlice<SecurityEvent> list = mService.retrievePreRebootSecurityLogs(admin);
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01007396 if (list != null) {
7397 return list.getList();
7398 } else {
7399 return null;
7400 }
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007401 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007402 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007403 }
7404 }
7405
7406 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007407 * Called by a profile owner of a managed profile to set the color used for customization. This
7408 * color is used as background color of the confirm credentials screen for that user. The
Clara Bayarri8d0bd7fa2016-03-30 14:59:58 +01007409 * default color is teal (#00796B).
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007410 * <p>
7411 * The confirm credentials screen can be created using
Benjamin Franz59720bb2016-01-18 15:26:11 +00007412 * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}.
7413 *
7414 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinski74cd7302016-04-12 15:17:36 +01007415 * @param color The 24bit (0xRRGGBB) representation of the color to be used.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007416 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz59720bb2016-01-18 15:26:11 +00007417 */
7418 public void setOrganizationColor(@NonNull ComponentName admin, int color) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007419 throwIfParentInstance("setOrganizationColor");
Benjamin Franz59720bb2016-01-18 15:26:11 +00007420 try {
Michal Karpinski74cd7302016-04-12 15:17:36 +01007421 // always enforce alpha channel to have 100% opacity
7422 color |= 0xFF000000;
Benjamin Franz59720bb2016-01-18 15:26:11 +00007423 mService.setOrganizationColor(admin, color);
7424 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007425 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00007426 }
7427 }
7428
7429 /**
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00007430 * @hide
7431 *
7432 * Sets the color used for customization.
7433 *
Michal Karpinski74cd7302016-04-12 15:17:36 +01007434 * @param color The 24bit (0xRRGGBB) representation of the color to be used.
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00007435 * @param userId which user to set the color to.
7436 * @RequiresPermission(allOf = {
7437 * Manifest.permission.MANAGE_USERS,
7438 * Manifest.permission.INTERACT_ACROSS_USERS_FULL})
7439 */
7440 public void setOrganizationColorForUser(@ColorInt int color, @UserIdInt int userId) {
7441 try {
Michal Karpinski74cd7302016-04-12 15:17:36 +01007442 // always enforce alpha channel to have 100% opacity
7443 color |= 0xFF000000;
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00007444 mService.setOrganizationColorForUser(color, userId);
7445 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007446 throw re.rethrowFromSystemServer();
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00007447 }
7448 }
7449
7450 /**
Benjamin Franz59720bb2016-01-18 15:26:11 +00007451 * Called by a profile owner of a managed profile to retrieve the color used for customization.
7452 * This color is used as background color of the confirm credentials screen for that user.
7453 *
7454 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinski74cd7302016-04-12 15:17:36 +01007455 * @return The 24bit (0xRRGGBB) representation of the color to be used.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007456 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz59720bb2016-01-18 15:26:11 +00007457 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01007458 public @ColorInt int getOrganizationColor(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007459 throwIfParentInstance("getOrganizationColor");
Benjamin Franz59720bb2016-01-18 15:26:11 +00007460 try {
7461 return mService.getOrganizationColor(admin);
7462 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007463 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00007464 }
7465 }
7466
7467 /**
7468 * @hide
7469 * Retrieve the customization color for a given user.
7470 *
7471 * @param userHandle The user id of the user we're interested in.
Michal Karpinski74cd7302016-04-12 15:17:36 +01007472 * @return The 24bit (0xRRGGBB) representation of the color to be used.
Benjamin Franz59720bb2016-01-18 15:26:11 +00007473 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01007474 public @ColorInt int getOrganizationColorForUser(int userHandle) {
Benjamin Franz59720bb2016-01-18 15:26:11 +00007475 try {
7476 return mService.getOrganizationColorForUser(userHandle);
7477 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007478 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00007479 }
7480 }
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007481
7482 /**
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01007483 * Called by the device owner or profile owner to set the name of the organization under
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007484 * management.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007485 * <p>
7486 * If the organization name needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007487 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
7488 * and set a new version of this string accordingly.
7489 *
7490 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7491 * @param title The organization name or {@code null} to clear a previously set name.
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01007492 * @throws SecurityException if {@code admin} is not a device or profile owner.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007493 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01007494 public void setOrganizationName(@NonNull ComponentName admin, @Nullable CharSequence title) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007495 throwIfParentInstance("setOrganizationName");
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007496 try {
7497 mService.setOrganizationName(admin, title);
7498 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007499 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007500 }
7501 }
7502
7503 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007504 * Called by a profile owner of a managed profile to retrieve the name of the organization under
7505 * management.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007506 *
7507 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7508 * @return The organization name or {@code null} if none is set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007509 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007510 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007511 public @Nullable CharSequence getOrganizationName(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007512 throwIfParentInstance("getOrganizationName");
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007513 try {
7514 return mService.getOrganizationName(admin);
7515 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007516 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007517 }
7518 }
7519
7520 /**
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01007521 * Called by the system to retrieve the name of the organization managing the device.
7522 *
7523 * @return The organization name or {@code null} if none is set.
7524 * @throws SecurityException if the caller is not the device owner, does not hold the
7525 * MANAGE_USERS permission and is not the system.
7526 *
7527 * @hide
7528 */
7529 @SystemApi
7530 @TestApi
7531 public @Nullable CharSequence getDeviceOwnerOrganizationName() {
7532 try {
7533 return mService.getDeviceOwnerOrganizationName();
7534 } catch (RemoteException re) {
7535 throw re.rethrowFromSystemServer();
7536 }
7537 }
7538
7539 /**
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007540 * Retrieve the default title message used in the confirm credentials screen for a given user.
7541 *
7542 * @param userHandle The user id of the user we're interested in.
7543 * @return The organization name or {@code null} if none is set.
7544 *
7545 * @hide
7546 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007547 public @Nullable CharSequence getOrganizationNameForUser(int userHandle) {
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007548 try {
7549 return mService.getOrganizationNameForUser(userHandle);
7550 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007551 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007552 }
7553 }
7554
7555 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00007556 * @return the {@link UserProvisioningState} for the current user - for unmanaged users will
7557 * return {@link #STATE_USER_UNMANAGED}
7558 * @hide
7559 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00007560 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00007561 @UserProvisioningState
7562 public int getUserProvisioningState() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007563 throwIfParentInstance("getUserProvisioningState");
Alan Treadwayafad8782016-01-19 15:15:08 +00007564 if (mService != null) {
7565 try {
7566 return mService.getUserProvisioningState();
7567 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007568 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00007569 }
7570 }
7571 return STATE_USER_UNMANAGED;
7572 }
7573
7574 /**
7575 * Set the {@link UserProvisioningState} for the supplied user, if they are managed.
7576 *
7577 * @param state to store
7578 * @param userHandle for user
7579 * @hide
7580 */
7581 public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) {
7582 if (mService != null) {
7583 try {
7584 mService.setUserProvisioningState(state, userHandle);
7585 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007586 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00007587 }
7588 }
7589 }
7590
7591 /**
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007592 * Indicates the entity that controls the device or profile owner. Two users/profiles are
7593 * affiliated if the set of ids set by their device or profile owners intersect.
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007594 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00007595 * <p><strong>Note:</strong> Features that depend on user affiliation (such as security logging
7596 * or {@link #bindDeviceAdminServiceAsUser}) won't be available when a secondary user or profile
7597 * is created, until it becomes affiliated. Therefore it is recommended that the appropriate
7598 * affiliation ids are set by its profile owner as soon as possible after the user/profile is
7599 * created.
7600 *
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007601 * @param admin Which profile or device owner this request is associated with.
Tony Mak31657432017-04-25 09:29:55 +01007602 * @param ids A set of opaque non-empty affiliation ids.
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007603 *
Tony Mak31657432017-04-25 09:29:55 +01007604 * @throws IllegalArgumentException if {@code ids} is null or contains an empty string.
7605 */
7606 public void setAffiliationIds(@NonNull ComponentName admin, @NonNull Set<String> ids) {
7607 throwIfParentInstance("setAffiliationIds");
7608 if (ids == null) {
7609 throw new IllegalArgumentException("ids must not be null");
7610 }
7611 try {
7612 mService.setAffiliationIds(admin, new ArrayList<>(ids));
7613 } catch (RemoteException e) {
7614 throw e.rethrowFromSystemServer();
7615 }
7616 }
7617
7618 /**
Tony Mak31657432017-04-25 09:29:55 +01007619 * Returns the set of affiliation ids previously set via {@link #setAffiliationIds}, or an
7620 * empty set if none have been set.
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007621 */
Tony Mak31657432017-04-25 09:29:55 +01007622 public @NonNull Set<String> getAffiliationIds(@NonNull ComponentName admin) {
Tony Mak62cf5862017-05-02 13:50:18 +01007623 throwIfParentInstance("getAffiliationIds");
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007624 try {
Tony Mak31657432017-04-25 09:29:55 +01007625 return new ArraySet<>(mService.getAffiliationIds(admin));
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007626 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007627 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007628 }
7629 }
7630
7631 /**
7632 * @hide
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007633 * Returns whether this user/profile is affiliated with the device.
7634 * <p>
7635 * By definition, the user that the device owner runs on is always affiliated with the device.
7636 * Any other user/profile is considered affiliated with the device if the set specified by its
7637 * profile owner via {@link #setAffiliationIds} intersects with the device owner's.
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007638 *
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007639 */
7640 public boolean isAffiliatedUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007641 throwIfParentInstance("isAffiliatedUser");
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007642 try {
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007643 return mService.isAffiliatedUser();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007644 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007645 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007646 }
7647 }
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08007648
7649 /**
7650 * @hide
7651 * Returns whether the uninstall for {@code packageName} for the current user is in queue
7652 * to be started
7653 * @param packageName the package to check for
7654 * @return whether the uninstall intent for {@code packageName} is pending
7655 */
7656 public boolean isUninstallInQueue(String packageName) {
7657 try {
7658 return mService.isUninstallInQueue(packageName);
7659 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007660 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08007661 }
7662 }
7663
7664 /**
7665 * @hide
7666 * @param packageName the package containing active DAs to be uninstalled
7667 */
7668 public void uninstallPackageWithActiveAdmins(String packageName) {
7669 try {
7670 mService.uninstallPackageWithActiveAdmins(packageName);
7671 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007672 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08007673 }
7674 }
Benjamin Franzbc33c822016-04-15 08:57:52 +01007675
Kenny Guy38dcca52016-04-19 13:09:18 +01007676 /**
7677 * @hide
7678 * Remove a test admin synchronously without sending it a broadcast about being removed.
7679 * If the admin is a profile owner or device owner it will still be removed.
7680 *
7681 * @param userHandle user id to remove the admin for.
7682 * @param admin The administration compononent to remove.
7683 * @throws SecurityException if the caller is not shell / root or the admin package
7684 * isn't a test application see {@link ApplicationInfo#FLAG_TEST_APP}.
7685 */
7686 public void forceRemoveActiveAdmin(ComponentName adminReceiver, int userHandle) {
7687 try {
7688 mService.forceRemoveActiveAdmin(adminReceiver, userHandle);
7689 } catch (RemoteException re) {
7690 throw re.rethrowFromSystemServer();
7691 }
7692 }
7693
Mahaver Chopra790d1982016-07-07 16:06:49 +01007694 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007695 * Returns whether the device has been provisioned.
7696 *
7697 * <p>Not for use by third-party applications.
7698 *
Mahaver Chopra790d1982016-07-07 16:06:49 +01007699 * @hide
Mahaver Chopra790d1982016-07-07 16:06:49 +01007700 */
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007701 @SystemApi
Mahaver Chopra790d1982016-07-07 16:06:49 +01007702 public boolean isDeviceProvisioned() {
7703 try {
7704 return mService.isDeviceProvisioned();
7705 } catch (RemoteException re) {
7706 throw re.rethrowFromSystemServer();
7707 }
7708 }
7709
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007710 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007711 * Writes that the provisioning configuration has been applied.
7712 *
7713 * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS}
7714 * permission.
7715 *
7716 * <p>Not for use by third-party applications.
7717 *
7718 * @hide
7719 */
7720 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06007721 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007722 public void setDeviceProvisioningConfigApplied() {
7723 try {
7724 mService.setDeviceProvisioningConfigApplied();
7725 } catch (RemoteException re) {
7726 throw re.rethrowFromSystemServer();
7727 }
7728 }
7729
7730 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007731 * Returns whether the provisioning configuration has been applied.
7732 *
7733 * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS} permission.
7734 *
7735 * <p>Not for use by third-party applications.
7736 *
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007737 * @return whether the provisioning configuration has been applied.
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007738 *
7739 * @hide
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007740 */
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007741 @SystemApi
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007742 public boolean isDeviceProvisioningConfigApplied() {
7743 try {
7744 return mService.isDeviceProvisioningConfigApplied();
7745 } catch (RemoteException re) {
7746 throw re.rethrowFromSystemServer();
7747 }
7748 }
7749
Victor Chang9bfc65f2016-08-15 12:27:09 +01007750 /**
7751 * @hide
Victor Chang3577ed22016-08-25 18:49:26 +01007752 * Force update user setup completed status. This API has no effect on user build.
7753 * @throws {@link SecurityException} if the caller has no
Esteban Talavera01576862016-12-15 11:16:44 +00007754 * {@code android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS} or the caller is
7755 * not {@link UserHandle#SYSTEM_USER}
Victor Chang9bfc65f2016-08-15 12:27:09 +01007756 */
7757 public void forceUpdateUserSetupComplete() {
7758 try {
7759 mService.forceUpdateUserSetupComplete();
7760 } catch (RemoteException re) {
7761 throw re.rethrowFromSystemServer();
7762 }
7763 }
7764
Benjamin Franzbc33c822016-04-15 08:57:52 +01007765 private void throwIfParentInstance(String functionName) {
7766 if (mParentInstance) {
7767 throw new SecurityException(functionName + " cannot be called on the parent instance");
7768 }
7769 }
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007770
7771 /**
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007772 * Allows the device owner to enable or disable the backup service.
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007773 *
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007774 * <p> Backup service manages all backup and restore mechanisms on the device. Setting this to
7775 * false will prevent data from being backed up or restored.
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007776 *
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007777 * <p> Backup service is off by default when device owner is present.
7778 *
Rubin Xu0367f072017-04-24 20:17:16 +01007779 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7780 * @param enabled {@code true} to enable the backup service, {@code false} to disable it.
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007781 * @throws SecurityException if {@code admin} is not a device owner.
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007782 */
7783 public void setBackupServiceEnabled(@NonNull ComponentName admin, boolean enabled) {
Esteban Talavera5b7f2d02017-02-17 09:45:24 +00007784 throwIfParentInstance("setBackupServiceEnabled");
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007785 try {
7786 mService.setBackupServiceEnabled(admin, enabled);
7787 } catch (RemoteException re) {
7788 throw re.rethrowFromSystemServer();
7789 }
7790 }
7791
7792 /**
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007793 * Return whether the backup service is enabled by the device owner.
7794 *
7795 * <p> Backup service manages all backup and restore mechanisms on the device.
7796 *
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007797 * @return {@code true} if backup service is enabled, {@code false} otherwise.
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007798 * @see #setBackupServiceEnabled
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007799 */
7800 public boolean isBackupServiceEnabled(@NonNull ComponentName admin) {
Esteban Talavera5b7f2d02017-02-17 09:45:24 +00007801 throwIfParentInstance("isBackupServiceEnabled");
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007802 try {
7803 return mService.isBackupServiceEnabled(admin);
7804 } catch (RemoteException re) {
7805 throw re.rethrowFromSystemServer();
7806 }
7807 }
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007808
7809 /**
Esteban Talaverad36dd152016-12-15 08:51:45 +00007810 * Called by a device owner to control the network logging feature.
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007811 *
Robin Leea40a2fb2017-02-08 17:07:06 +00007812 * <p> Network logs contain DNS lookup and connect() library call events. The following library
7813 * functions are recorded while network logging is active:
7814 * <ul>
7815 * <li>{@code getaddrinfo()}</li>
7816 * <li>{@code gethostbyname()}</li>
7817 * <li>{@code connect()}</li>
7818 * </ul>
7819 *
7820 * <p> Network logging is a low-overhead tool for forensics but it is not guaranteed to use
7821 * full system call logging; event reporting is enabled by default for all processes but not
7822 * strongly enforced.
7823 * Events from applications using alternative implementations of libc, making direct kernel
7824 * calls, or deliberately obfuscating traffic may not be recorded.
7825 *
7826 * <p> Some common network events may not be reported. For example:
7827 * <ul>
7828 * <li>Applications may hardcode IP addresses to reduce the number of DNS lookups, or use
7829 * an alternative system for name resolution, and so avoid calling
7830 * {@code getaddrinfo()} or {@code gethostbyname}.</li>
7831 * <li>Applications may use datagram sockets for performance reasons, for example
7832 * for a game client. Calling {@code connect()} is unnecessary for this kind of
7833 * socket, so it will not trigger a network event.</li>
7834 * </ul>
7835 *
7836 * <p> It is possible to directly intercept layer 3 traffic leaving the device using an
7837 * always-on VPN service.
7838 * See {@link #setAlwaysOnVpnPackage(ComponentName, String, boolean)}
7839 * and {@link android.net.VpnService} for details.
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007840 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00007841 * <p><strong>Note:</strong> The device owner won't be able to retrieve network logs if there
7842 * are unaffiliated secondary users or profiles on the device, regardless of whether the
7843 * feature is enabled. Logs will be discarded if the internal buffer fills up while waiting for
7844 * all users to become affiliated. Therefore it's recommended that affiliation ids are set for
7845 * new users as soon as possible after provisioning via {@link #setAffiliationIds}.
7846 *
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007847 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7848 * @param enabled whether network logging should be enabled or not.
Esteban Talaverad36dd152016-12-15 08:51:45 +00007849 * @throws SecurityException if {@code admin} is not a device owner.
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007850 * @see #retrieveNetworkLogs
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007851 */
7852 public void setNetworkLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
7853 throwIfParentInstance("setNetworkLoggingEnabled");
7854 try {
7855 mService.setNetworkLoggingEnabled(admin, enabled);
7856 } catch (RemoteException re) {
7857 throw re.rethrowFromSystemServer();
7858 }
7859 }
7860
7861 /**
7862 * Return whether network logging is enabled by a device owner.
7863 *
phweissa4e169e2016-11-24 16:20:57 +01007864 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Can only
7865 * be {@code null} if the caller has MANAGE_USERS permission.
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007866 * @return {@code true} if network logging is enabled by device owner, {@code false} otherwise.
Esteban Talaverad36dd152016-12-15 08:51:45 +00007867 * @throws SecurityException if {@code admin} is not a device owner and caller has
phweissa4e169e2016-11-24 16:20:57 +01007868 * no MANAGE_USERS permission
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007869 */
phweissa4e169e2016-11-24 16:20:57 +01007870 public boolean isNetworkLoggingEnabled(@Nullable ComponentName admin) {
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007871 throwIfParentInstance("isNetworkLoggingEnabled");
7872 try {
7873 return mService.isNetworkLoggingEnabled(admin);
7874 } catch (RemoteException re) {
7875 throw re.rethrowFromSystemServer();
7876 }
7877 }
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007878
7879 /**
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007880 * Called by device owner to retrieve the most recent batch of network logging events.
7881 * A device owner has to provide a batchToken provided as part of
7882 * {@link DeviceAdminReceiver#onNetworkLogsAvailable} callback. If the token doesn't match the
7883 * token of the most recent available batch of logs, {@code null} will be returned.
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007884 *
7885 * <p> {@link NetworkEvent} can be one of {@link DnsEvent} or {@link ConnectEvent}.
7886 *
7887 * <p> The list of network events is sorted chronologically, and contains at most 1200 events.
7888 *
7889 * <p> Access to the logs is rate limited and this method will only return a new batch of logs
7890 * after the device device owner has been notified via
7891 * {@link DeviceAdminReceiver#onNetworkLogsAvailable}.
7892 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00007893 * <p>If a secondary user or profile is created, calling this method will throw a
7894 * {@link SecurityException} until all users become affiliated again. It will also no longer be
7895 * possible to retrieve the network logs batch with the most recent batchToken provided
7896 * by {@link DeviceAdminReceiver#onNetworkLogsAvailable}. See
7897 * {@link DevicePolicyManager#setAffiliationIds}.
7898 *
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007899 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007900 * @param batchToken A token of the batch to retrieve
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007901 * @return A new batch of network logs which is a list of {@link NetworkEvent}. Returns
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007902 * {@code null} if the batch represented by batchToken is no longer available or if
7903 * logging is disabled.
Esteban Talaverad36dd152016-12-15 08:51:45 +00007904 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
7905 * profile or secondary user that is not affiliated with the device owner user.
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007906 * @see DeviceAdminReceiver#onNetworkLogsAvailable
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007907 */
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007908 public @Nullable List<NetworkEvent> retrieveNetworkLogs(@NonNull ComponentName admin,
7909 long batchToken) {
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007910 throwIfParentInstance("retrieveNetworkLogs");
7911 try {
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007912 return mService.retrieveNetworkLogs(admin, batchToken);
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007913 } catch (RemoteException re) {
7914 throw re.rethrowFromSystemServer();
7915 }
7916 }
Tony Mak46aabe52016-11-14 12:53:06 +00007917
7918 /**
Esteban Talavera2f897912017-01-26 10:30:48 +00007919 * Called by a device owner to bind to a service from a profile owner or vice versa.
7920 * See {@link #getBindDeviceAdminTargetUsers} for a definition of which
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007921 * device/profile owners are allowed to bind to services of another profile/device owner.
7922 * <p>
Tony Makeda0a9a2017-04-25 12:07:14 +01007923 * The service must be protected by {@link android.Manifest.permission#BIND_DEVICE_ADMIN}.
7924 * Note that the {@link Context} used to obtain this
Tony Mak46aabe52016-11-14 12:53:06 +00007925 * {@link DevicePolicyManager} instance via {@link Context#getSystemService(Class)} will be used
7926 * to bind to the {@link android.app.Service}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007927 *
Tony Mak46aabe52016-11-14 12:53:06 +00007928 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7929 * @param serviceIntent Identifies the service to connect to. The Intent must specify either an
7930 * explicit component name or a package name to match an
7931 * {@link IntentFilter} published by a service.
Tony Makbf9928d2016-12-22 11:02:45 +00007932 * @param conn Receives information as the service is started and stopped in main thread. This
7933 * must be a valid {@link ServiceConnection} object; it must not be {@code null}.
Tony Mak46aabe52016-11-14 12:53:06 +00007934 * @param flags Operation options for the binding operation. See
7935 * {@link Context#bindService(Intent, ServiceConnection, int)}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007936 * @param targetUser Which user to bind to. Must be one of the users returned by
7937 * {@link #getBindDeviceAdminTargetUsers}, otherwise a {@link SecurityException} will
7938 * be thrown.
Tony Mak46aabe52016-11-14 12:53:06 +00007939 * @return If you have successfully bound to the service, {@code true} is returned;
7940 * {@code false} is returned if the connection is not made and you will not
7941 * receive the service object.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007942 *
Tony Mak46aabe52016-11-14 12:53:06 +00007943 * @see Context#bindService(Intent, ServiceConnection, int)
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007944 * @see #getBindDeviceAdminTargetUsers(ComponentName)
Tony Mak46aabe52016-11-14 12:53:06 +00007945 */
7946 public boolean bindDeviceAdminServiceAsUser(
7947 @NonNull ComponentName admin, Intent serviceIntent, @NonNull ServiceConnection conn,
7948 @Context.BindServiceFlags int flags, @NonNull UserHandle targetUser) {
7949 throwIfParentInstance("bindDeviceAdminServiceAsUser");
7950 // Keep this in sync with ContextImpl.bindServiceCommon.
7951 try {
Tony Makbf9928d2016-12-22 11:02:45 +00007952 final IServiceConnection sd = mContext.getServiceDispatcher(
7953 conn, mContext.getMainThreadHandler(), flags);
Tony Mak46aabe52016-11-14 12:53:06 +00007954 serviceIntent.prepareToLeaveProcess(mContext);
7955 return mService.bindDeviceAdminServiceAsUser(admin,
7956 mContext.getIApplicationThread(), mContext.getActivityToken(), serviceIntent,
7957 sd, flags, targetUser.getIdentifier());
7958 } catch (RemoteException re) {
7959 throw re.rethrowFromSystemServer();
7960 }
7961 }
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007962
7963 /**
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007964 * Returns the list of target users that the calling device or profile owner can use when
7965 * calling {@link #bindDeviceAdminServiceAsUser}.
7966 * <p>
Esteban Talavera2f897912017-01-26 10:30:48 +00007967 * A device owner can bind to a service from a profile owner and vice versa, provided that:
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007968 * <ul>
7969 * <li>Both belong to the same package name.
Esteban Talavera2f897912017-01-26 10:30:48 +00007970 * <li>Both users are affiliated. See {@link #setAffiliationIds}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007971 * </ul>
7972 */
7973 public @NonNull List<UserHandle> getBindDeviceAdminTargetUsers(@NonNull ComponentName admin) {
7974 throwIfParentInstance("getBindDeviceAdminTargetUsers");
7975 try {
7976 return mService.getBindDeviceAdminTargetUsers(admin);
7977 } catch (RemoteException re) {
7978 throw re.rethrowFromSystemServer();
7979 }
7980 }
7981
7982 /**
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007983 * Called by the system to get the time at which the device owner last retrieved security
7984 * logging entries.
7985 *
7986 * @return the time at which the device owner most recently retrieved security logging entries,
7987 * in milliseconds since epoch; -1 if security logging entries were never retrieved.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007988 * @throws SecurityException if the caller is not the device owner, does not hold the
7989 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007990 *
7991 * @hide
7992 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007993 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007994 public long getLastSecurityLogRetrievalTime() {
7995 try {
7996 return mService.getLastSecurityLogRetrievalTime();
7997 } catch (RemoteException re) {
7998 throw re.rethrowFromSystemServer();
7999 }
8000 }
8001
8002 /**
8003 * Called by the system to get the time at which the device owner last requested a bug report.
8004 *
8005 * @return the time at which the device owner most recently requested a bug report, in
8006 * milliseconds since epoch; -1 if a bug report was never requested.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01008007 * @throws SecurityException if the caller is not the device owner, does not hold the
8008 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01008009 *
8010 * @hide
8011 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01008012 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01008013 public long getLastBugReportRequestTime() {
8014 try {
8015 return mService.getLastBugReportRequestTime();
8016 } catch (RemoteException re) {
8017 throw re.rethrowFromSystemServer();
8018 }
8019 }
8020
8021 /**
8022 * Called by the system to get the time at which the device owner last retrieved network logging
8023 * events.
8024 *
8025 * @return the time at which the device owner most recently retrieved network logging events, in
8026 * milliseconds since epoch; -1 if network logging events were never retrieved.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01008027 * @throws SecurityException if the caller is not the device owner, does not hold the
8028 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01008029 *
8030 * @hide
8031 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01008032 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01008033 public long getLastNetworkLogRetrievalTime() {
8034 try {
8035 return mService.getLastNetworkLogRetrievalTime();
8036 } catch (RemoteException re) {
8037 throw re.rethrowFromSystemServer();
8038 }
8039 }
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01008040
8041 /**
Bartosz Fabianowski172f7802017-03-06 12:07:57 +01008042 * Called by the system to find out whether the current user's IME was set by the device/profile
8043 * owner or the user.
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01008044 *
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01008045 * @return {@code true} if the user's IME was set by the device or profile owner, {@code false}
8046 * otherwise.
Bartosz Fabianowski172f7802017-03-06 12:07:57 +01008047 * @throws SecurityException if the caller is not the device owner/profile owner.
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01008048 *
8049 * @hide
8050 */
8051 @TestApi
Bartosz Fabianowski172f7802017-03-06 12:07:57 +01008052 public boolean isCurrentInputMethodSetByOwner() {
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01008053 try {
Bartosz Fabianowski172f7802017-03-06 12:07:57 +01008054 return mService.isCurrentInputMethodSetByOwner();
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01008055 } catch (RemoteException re) {
8056 throw re.rethrowFromSystemServer();
8057 }
8058 }
Bartosz Fabianowski05dc9f72017-02-22 23:41:14 +01008059
Bartosz Fabianowski05dc9f72017-02-22 23:41:14 +01008060 /**
8061 * Called by the system to get a list of CA certificates that were installed by the device or
8062 * profile owner.
8063 *
Bartosz Fabianowski172f7802017-03-06 12:07:57 +01008064 * <p> The caller must be the target user's device owner/profile Owner or hold the
Bartosz Fabianowski05dc9f72017-02-22 23:41:14 +01008065 * {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} permission.
8066 *
8067 * @param user The user for whom to retrieve information.
8068 * @return list of aliases identifying CA certificates installed by the device or profile owner
8069 * @throws SecurityException if the caller does not have permission to retrieve information
8070 * about the given user's CA certificates.
8071 *
8072 * @hide
8073 */
8074 @TestApi
8075 public List<String> getOwnerInstalledCaCerts(@NonNull UserHandle user) {
8076 try {
8077 return mService.getOwnerInstalledCaCerts(user).getList();
8078 } catch (RemoteException re) {
8079 throw re.rethrowFromSystemServer();
8080 }
8081 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08008082}