blob: 5b78ce883763926295cec9416e5306e1160a8b34 [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;
Dianne Hackbornd6847842010-01-12 18:14:19 -080023import android.annotation.SdkConstant;
24import android.annotation.SdkConstant.SdkConstantType;
Justin Moreyb5deda72014-07-24 10:53:40 -050025import android.annotation.SystemApi;
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +010026import android.annotation.TestApi;
Nicolas Prevot8f7698a2016-02-11 16:05:33 +000027import android.annotation.UserIdInt;
Fyodor Kupolov4e9af062016-07-18 16:59:11 -070028import android.annotation.WorkerThread;
Jason Monkd7b86212014-06-16 13:15:38 -040029import android.app.Activity;
Tony Mak46aabe52016-11-14 12:53:06 +000030import android.app.IServiceConnection;
Michal Karpinski6235a942016-03-15 12:07:23 +000031import android.app.admin.SecurityLog.SecurityEvent;
Dianne Hackbornd6847842010-01-12 18:14:19 -080032import android.content.ComponentName;
33import android.content.Context;
Adam Connors010cfd42014-04-16 12:48:13 +010034import android.content.Intent;
Sander Alewijnsef475ca32014-02-17 15:13:58 +000035import android.content.IntentFilter;
Tony Mak46aabe52016-11-14 12:53:06 +000036import android.content.ServiceConnection;
Dianne Hackbornd6847842010-01-12 18:14:19 -080037import android.content.pm.PackageManager;
Victor Changcd14c0a2016-03-16 19:10:15 +000038import android.content.pm.PackageManager.NameNotFoundException;
Rubin Xuc3cd05f2016-01-11 12:11:35 +000039import android.content.pm.ParceledListSlice;
Sudheer Shanka978fc0d2016-01-28 13:51:10 +000040import android.content.pm.UserInfo;
Julia Reynoldsfca04ca2015-02-17 13:39:12 -050041import android.graphics.Bitmap;
Jason Monk03bc9912014-05-13 09:44:57 -040042import android.net.ProxyInfo;
Nicolas Prevot8b7991c2015-11-12 17:40:12 +000043import android.net.Uri;
Robin Lee66e5d962014-04-09 16:44:21 +010044import android.os.Bundle;
Victor Changc10f6692016-12-09 15:24:00 +000045import android.os.Parcelable;
Jim Millere303bf42014-08-26 17:12:29 -070046import android.os.PersistableBundle;
Adam Connors776c5552014-01-09 10:42:56 +000047import android.os.Process;
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080048import android.os.RemoteCallback;
Dianne Hackbornd6847842010-01-12 18:14:19 -080049import android.os.RemoteException;
Amith Yamasani599dd7c2012-09-14 23:20:08 -070050import android.os.UserHandle;
Julia Reynolds1e958392014-05-16 14:25:21 -040051import android.os.UserManager;
Ricky Wai494b95d2015-11-20 16:07:15 +000052import android.provider.ContactsContract.Directory;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000053import android.provider.Settings;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010054import android.security.Credentials;
Amith Yamasanid1d7c022014-08-19 17:03:41 -070055import android.service.restrictions.RestrictionsReceiver;
Mahaver Chopra1216ae52016-03-11 15:39:48 +000056import android.telephony.TelephonyManager;
Dianne Hackbornd6847842010-01-12 18:14:19 -080057import android.util.Log;
58
Makoto Onukicc4bbeb2015-09-17 10:28:24 -070059import com.android.internal.annotations.VisibleForTesting;
Maggie Benthallda51e682013-08-08 22:35:44 -040060import com.android.org.conscrypt.TrustedCertificateStore;
61
62import java.io.ByteArrayInputStream;
Dianne Hackbornd6847842010-01-12 18:14:19 -080063import java.io.IOException;
Alan Treadwayafad8782016-01-19 15:15:08 +000064import java.lang.annotation.Retention;
65import java.lang.annotation.RetentionPolicy;
Oscar Montemayor69238c62010-08-03 10:51:06 -070066import java.net.InetSocketAddress;
67import java.net.Proxy;
Robin Lee0d5ccb72014-09-12 17:41:44 +010068import java.security.KeyFactory;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000069import java.security.NoSuchAlgorithmException;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010070import java.security.PrivateKey;
71import java.security.cert.Certificate;
Maggie Benthallda51e682013-08-08 22:35:44 -040072import java.security.cert.CertificateException;
73import java.security.cert.CertificateFactory;
74import java.security.cert.X509Certificate;
Robin Lee0d5ccb72014-09-12 17:41:44 +010075import java.security.spec.InvalidKeySpecException;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000076import java.security.spec.PKCS8EncodedKeySpec;
Jim Miller604e7552014-07-18 19:00:02 -070077import java.util.ArrayList;
Rubin Xub4365912016-03-23 12:13:22 +000078import java.util.Arrays;
Svetoslav976e8bd2014-07-16 15:12:03 -070079import java.util.Collections;
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -080080import java.util.List;
Dianne Hackbornd6847842010-01-12 18:14:19 -080081
82/**
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000083 * Public interface for managing policies enforced on a device. Most clients of this class must be
Suprabh Shukla34d92ef2016-03-14 13:49:37 -070084 * registered with the system as a <a href="{@docRoot}guide/topics/admin/device-admin.html">device
85 * administrator</a>. Additionally, a device administrator may be registered as either a profile or
86 * device owner. A given method is accessible to all device administrators unless the documentation
87 * for that method specifies that it is restricted to either device or profile owners. Any
88 * application calling an api may only pass as an argument a device administrator component it
89 * owns. Otherwise, a {@link SecurityException} will be thrown.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080090 * <div class="special reference">
91 * <h3>Developer Guides</h3>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -070092 * <p>
93 * For more information about managing policies for device administration, read the <a href=
94 * "{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a> developer
95 * guide. </div>
Dianne Hackbornd6847842010-01-12 18:14:19 -080096 */
97public class DevicePolicyManager {
98 private static String TAG = "DevicePolicyManager";
Dianne Hackbornd6847842010-01-12 18:14:19 -080099
100 private final Context mContext;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800101 private final IDevicePolicyManager mService;
Esteban Talavera62399912016-01-11 15:37:55 +0000102 private final boolean mParentInstance;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700103
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600104 /** @hide */
105 public DevicePolicyManager(Context context, IDevicePolicyManager service) {
106 this(context, service, false);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800107 }
108
Dianne Hackborn87bba1e2010-02-26 17:25:54 -0800109 /** @hide */
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700110 @VisibleForTesting
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600111 protected DevicePolicyManager(Context context, IDevicePolicyManager service,
112 boolean parentInstance) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700113 mContext = context;
114 mService = service;
Esteban Talavera62399912016-01-11 15:37:55 +0000115 mParentInstance = parentInstance;
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700116 }
117
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700118 /** @hide test will override it. */
119 @VisibleForTesting
120 protected int myUserId() {
121 return UserHandle.myUserId();
122 }
123
Dianne Hackbornd6847842010-01-12 18:14:19 -0800124 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +0000125 * Activity action: Starts the provisioning flow which sets up a managed profile.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000126 *
Jessica Hummel9da60392014-05-21 12:32:57 +0100127 * <p>A managed profile allows data separation for example for the usage of a
128 * device as a personal and corporate device. The user which provisioning is started from and
129 * the managed profile share a launcher.
130 *
Andrew Solovay27f53372015-03-02 16:37:59 -0800131 * <p>This intent will typically be sent by a mobile device management application (MDM).
132 * Provisioning adds a managed profile and sets the MDM as the profile owner who has full
133 * control over the profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100134 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000135 * <p>It is possible to check if provisioning is allowed or not by querying the method
136 * {@link #isProvisioningAllowed(String)}.
137 *
138 * <p>In version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this intent must contain the
Nicolas Prevot18440252015-03-09 14:07:17 +0000139 * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700140 * As of {@link android.os.Build.VERSION_CODES#M}, it should contain the extra
Nicolas Prevot18440252015-03-09 14:07:17 +0000141 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only
142 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000143 *
Benjamin Franzea956242016-03-21 15:45:56 +0000144 * <p>The intent may also contain the following extras:
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000145 * <ul>
Benjamin Franzea956242016-03-21 15:45:56 +0000146 * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, optional </li>
147 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional, supported from
148 * {@link android.os.Build.VERSION_CODES#N}</li>
149 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
150 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
151 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Victor Chang51d84f92016-11-16 12:22:56 +0000152 * <li>{@link #EXTRA_PROVISIONING_SKIP_USER_CONSENT}, optional</li>
Victor Chang89ee2792016-11-23 12:10:55 +0000153 * <li>{@link #EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION}, optional</li>
Victor Changc10f6692016-12-09 15:24:00 +0000154 * <li>{@link #EXTRA_PROVISIONING_DISCLAIMERS}, optional</li>
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000155 * </ul>
Jessica Hummelf72078b2014-03-06 16:13:12 +0000156 *
Benjamin Franzea956242016-03-21 15:45:56 +0000157 * <p>When managed provisioning has completed, broadcasts are sent to the application specified
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000158 * in the provisioning intent. The
159 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the
160 * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in
161 * the primary profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100162 *
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000163 * <p>From version {@link android.os.Build.VERSION_CODES#O}, when managed provisioning has
164 * completed, along with the above broadcast, activity intent
165 * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the application specified in
166 * the provisioning intent.
167 *
Benjamin Franzea956242016-03-21 15:45:56 +0000168 * <p>If provisioning fails, the managedProfile is removed so the device returns to its
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100169 * previous state.
Alan Treadway4582f812015-07-28 11:49:35 +0100170 *
171 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
172 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
173 * the provisioning flow was successful, although this doesn't guarantee the full flow will
174 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
175 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000176 */
177 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
178 public static final String ACTION_PROVISION_MANAGED_PROFILE
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100179 = "android.app.action.PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000180
181 /**
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000182 * Activity action: Starts the provisioning flow which sets up a managed user.
183 *
184 * <p>This intent will typically be sent by a mobile device management application (MDM).
Makoto Onuki32b30572015-12-11 14:29:51 -0800185 * Provisioning configures the user as managed user and sets the MDM as the profile
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000186 * owner who has full control over the user. Provisioning can only happen before user setup has
187 * been completed. Use {@link #isProvisioningAllowed(String)} to check if provisioning is
188 * allowed.
189 *
Benjamin Franzea956242016-03-21 15:45:56 +0000190 * <p>The intent contains the following extras:
191 * <ul>
192 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
193 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
194 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
195 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
196 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
197 * </ul>
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000198 *
Benjamin Franzea956242016-03-21 15:45:56 +0000199 * <p>If provisioning fails, the device returns to its previous state.
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000200 *
201 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
202 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
203 * the provisioning flow was successful, although this doesn't guarantee the full flow will
204 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
205 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Benjamin Franzea956242016-03-21 15:45:56 +0000206 *
207 * @hide
Mahaver Chopra5e732562015-11-05 11:55:12 +0000208 */
209 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
210 public static final String ACTION_PROVISION_MANAGED_USER
211 = "android.app.action.PROVISION_MANAGED_USER";
212
213 /**
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100214 * Activity action: Starts the provisioning flow which sets up a managed device.
215 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
216 *
217 * <p> During device owner provisioning a device admin app is set as the owner of the device.
218 * A device owner has full control over the device. The device owner can not be modified by the
219 * user.
220 *
221 * <p> A typical use case would be a device that is owned by a company, but used by either an
222 * employee or client.
223 *
224 * <p> An intent with this action can be sent only on an unprovisioned device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000225 * It is possible to check if provisioning is allowed or not by querying the method
226 * {@link #isProvisioningAllowed(String)}.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100227 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000228 * <p>The intent contains the following extras:
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100229 * <ul>
230 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
231 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
232 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
Rubin Xua4f9dc12015-06-12 13:27:59 +0100233 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000234 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000235 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Victor Changc10f6692016-12-09 15:24:00 +0000236 * <li>{@link #EXTRA_PROVISIONING_DISCLAIMERS}, optional</li>
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100237 * </ul>
238 *
Benjamin Franzea956242016-03-21 15:45:56 +0000239 * <p>When device owner provisioning has completed, an intent of the type
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100240 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
241 * device owner.
242 *
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000243 * <p>From version {@link android.os.Build.VERSION_CODES#O}, when device owner provisioning has
244 * completed, along with the above broadcast, activity intent
245 * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the device owner.
246 *
Benjamin Franzea956242016-03-21 15:45:56 +0000247 * <p>If provisioning fails, the device is factory reset.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100248 *
Alan Treadway4582f812015-07-28 11:49:35 +0100249 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
250 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
251 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
252 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100253 */
254 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
255 public static final String ACTION_PROVISION_MANAGED_DEVICE
256 = "android.app.action.PROVISION_MANAGED_DEVICE";
257
258 /**
Alan Treadway46dd4492015-11-09 13:57:19 +0000259 * Activity action: Starts the provisioning flow which sets up a managed device.
Steven Ng980a1b62016-02-02 17:43:18 +0000260 *
261 * <p>During device owner provisioning, a device admin app is downloaded and set as the owner of
262 * the device. A device owner has full control over the device. The device owner can not be
263 * modified by the user and the only way of resetting the device is via factory reset.
264 *
265 * <p>A typical use case would be a device that is owned by a company, but used by either an
266 * employee or client.
267 *
268 * <p>The provisioning message should be sent to an unprovisioned device.
269 *
270 * <p>Unlike {@link #ACTION_PROVISION_MANAGED_DEVICE}, the provisioning message can only be sent
271 * by a privileged app with the permission
272 * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE}.
273 *
274 * <p>The provisioning intent contains the following properties:
275 * <ul>
276 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
277 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
278 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
279 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Victor Chang38cfd9c2017-01-04 17:41:11 +0000280 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL}, optional</li>
281 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI}, optional</li>
Steven Ng980a1b62016-02-02 17:43:18 +0000282 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
283 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
284 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
285 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
286 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
287 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
288 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
289 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
290 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
291 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
292 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
Victor Chang38cfd9c2017-01-04 17:41:11 +0000293 * <li>{@link #EXTRA_PROVISIONING_SUPPORT_URL}, optional</li>
294 * <li>{@link #EXTRA_PROVISIONING_ORGANIZATION_NAME}, optional</li>
Steven Ng980a1b62016-02-02 17:43:18 +0000295 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li></ul>
296 *
297 * @hide
298 */
299 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
300 @SystemApi
301 public static final String ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE =
302 "android.app.action.PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE";
303
304 /**
305 * Activity action: Starts the provisioning flow which sets up a managed device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000306 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
307 *
308 * <p>NOTE: This is only supported on split system user devices, and puts the device into a
309 * management state that is distinct from that reached by
310 * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system
311 * user, and only has control over device-wide policies, not individual users and their data.
312 * The primary benefit is that multiple non-system users are supported when provisioning using
313 * this form of device management.
314 *
Benjamin Franzea956242016-03-21 15:45:56 +0000315 * <p>During device owner provisioning a device admin app is set as the owner of the device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000316 * A device owner has full control over the device. The device owner can not be modified by the
317 * user.
318 *
Benjamin Franzea956242016-03-21 15:45:56 +0000319 * <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 +0000320 * employee or client.
321 *
Benjamin Franzea956242016-03-21 15:45:56 +0000322 * <p>An intent with this action can be sent only on an unprovisioned device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000323 * It is possible to check if provisioning is allowed or not by querying the method
324 * {@link #isProvisioningAllowed(String)}.
325 *
326 * <p>The intent contains the following extras:
327 * <ul>
328 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
329 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
330 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
331 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Benjamin Franzea956242016-03-21 15:45:56 +0000332 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
333 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Alan Treadway46dd4492015-11-09 13:57:19 +0000334 * </ul>
335 *
Benjamin Franzea956242016-03-21 15:45:56 +0000336 * <p>When device owner provisioning has completed, an intent of the type
Alan Treadway46dd4492015-11-09 13:57:19 +0000337 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
338 * device owner.
339 *
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000340 * <p>From version {@link android.os.Build.VERSION_CODES#O}, when device owner provisioning has
341 * completed, along with the above broadcast, activity intent
342 * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the device owner.
343 *
Benjamin Franzea956242016-03-21 15:45:56 +0000344 * <p>If provisioning fails, the device is factory reset.
Alan Treadway46dd4492015-11-09 13:57:19 +0000345 *
346 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
347 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
348 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
349 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
350 *
351 * @hide
352 */
353 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
354 public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE
355 = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE";
356
357 /**
Alan Treadwayafad8782016-01-19 15:15:08 +0000358 * Activity action: Finalizes management provisioning, should be used after user-setup
359 * has been completed and {@link #getUserProvisioningState()} returns one of:
360 * <ul>
361 * <li>{@link #STATE_USER_SETUP_INCOMPLETE}</li>
362 * <li>{@link #STATE_USER_SETUP_COMPLETE}</li>
363 * <li>{@link #STATE_USER_PROFILE_COMPLETE}</li>
364 * </ul>
365 *
366 * @hide
367 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +0000368 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +0000369 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
370 public static final String ACTION_PROVISION_FINALIZATION
371 = "android.app.action.PROVISION_FINALIZATION";
372
373 /**
Michal Karpinskiba244092016-02-25 17:28:24 +0000374 * Action: Bugreport sharing with device owner has been accepted by the user.
375 *
376 * @hide
377 */
378 public static final String ACTION_BUGREPORT_SHARING_ACCEPTED =
379 "com.android.server.action.BUGREPORT_SHARING_ACCEPTED";
380
381 /**
382 * Action: Bugreport sharing with device owner has been declined by the user.
383 *
384 * @hide
385 */
386 public static final String ACTION_BUGREPORT_SHARING_DECLINED =
387 "com.android.server.action.BUGREPORT_SHARING_DECLINED";
388
389 /**
Esteban Talavera01576862016-12-15 11:16:44 +0000390 * Action: Bugreport has been collected and is dispatched to {@code DevicePolicyManagerService}.
Michal Karpinskiba244092016-02-25 17:28:24 +0000391 *
392 * @hide
393 */
394 public static final String ACTION_REMOTE_BUGREPORT_DISPATCH =
395 "android.intent.action.REMOTE_BUGREPORT_DISPATCH";
396
397 /**
398 * Extra for shared bugreport's SHA-256 hash.
399 *
400 * @hide
401 */
402 public static final String EXTRA_REMOTE_BUGREPORT_HASH =
403 "android.intent.extra.REMOTE_BUGREPORT_HASH";
404
405 /**
406 * Extra for remote bugreport notification shown type.
407 *
408 * @hide
409 */
410 public static final String EXTRA_BUGREPORT_NOTIFICATION_TYPE =
411 "android.app.extra.bugreport_notification_type";
412
413 /**
414 * Notification type for a started remote bugreport flow.
415 *
416 * @hide
417 */
418 public static final int NOTIFICATION_BUGREPORT_STARTED = 1;
419
420 /**
421 * Notification type for a bugreport that has already been accepted to be shared, but is still
422 * being taken.
423 *
424 * @hide
425 */
426 public static final int NOTIFICATION_BUGREPORT_ACCEPTED_NOT_FINISHED = 2;
427
428 /**
429 * Notification type for a bugreport that has been taken and can be shared or declined.
430 *
431 * @hide
432 */
433 public static final int NOTIFICATION_BUGREPORT_FINISHED_NOT_ACCEPTED = 3;
434
435 /**
Michal Karpinski8f010dd2016-06-21 15:05:53 +0100436 * Default and maximum timeout in milliseconds after which unlocking with weak auth times out,
437 * i.e. the user has to use a strong authentication method like password, PIN or pattern.
438 *
439 * @hide
440 */
441 public static final long DEFAULT_STRONG_AUTH_TIMEOUT_MS = 72 * 60 * 60 * 1000; // 72h
442
443 /**
Rubin Xua4f9dc12015-06-12 13:27:59 +0100444 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100445 * allows a mobile device management application or NFC programmer application which starts
446 * managed provisioning to pass data to the management application instance after provisioning.
Rubin Xua4f9dc12015-06-12 13:27:59 +0100447 * <p>
448 * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that
449 * sends the intent to pass data to itself on the newly created profile.
450 * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same
451 * instance of the app on the primary user.
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100452 * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with
453 * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC
454 * message should contain a stringified {@link java.util.Properties} instance, whose string
455 * properties will be converted into a {@link android.os.PersistableBundle} and passed to the
456 * management application after provisioning.
457 *
Rubin Xua4f9dc12015-06-12 13:27:59 +0100458 * <p>
459 * In both cases the application receives the data in
Brian Carlstromf1fe51b2014-09-03 08:55:05 -0700460 * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action
461 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed
Rubin Xua4f9dc12015-06-12 13:27:59 +0100462 * during the managed provisioning.
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100463 */
464 public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE =
Esteban Talavera37f01842014-09-05 10:50:57 +0100465 "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE";
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100466
467 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100468 * A String extra holding the package name of the mobile device management application that
469 * will be set as the profile owner or device owner.
470 *
471 * <p>If an application starts provisioning directly via an intent with action
472 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
473 * application that started provisioning. The package will be set as profile owner in that case.
474 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000475 * <p>This package is set as device owner when device owner provisioning is started by an NFC
476 * message containing an NFC record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000477 *
478 * <p> When this extra is set, the application must have exactly one device admin receiver.
Robin Lee25e26452015-06-02 09:56:29 -0700479 * This receiver will be set as the profile or device owner and active admin.
Benjamin Franzea956242016-03-21 15:45:56 +0000480 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000481 * @see DeviceAdminReceiver
482 * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still
Nicolas Prevot8f78d6a2015-08-21 11:06:31 +0100483 * supported, but only if there is only one device admin receiver in the package that requires
484 * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000485 */
Nicolas Prevot18440252015-03-09 14:07:17 +0000486 @Deprecated
Jessica Hummelf72078b2014-03-06 16:13:12 +0000487 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100488 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000489
490 /**
Nicolas Prevot18440252015-03-09 14:07:17 +0000491 * A ComponentName extra indicating the device admin receiver of the mobile device management
492 * application that will be set as the profile owner or device owner and active admin.
493 *
494 * <p>If an application starts provisioning directly via an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100495 * {@link #ACTION_PROVISION_MANAGED_PROFILE} or
496 * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this
497 * component has to match the package name of the application that started provisioning.
Nicolas Prevot18440252015-03-09 14:07:17 +0000498 *
499 * <p>This component is set as device owner and active admin when device owner provisioning is
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100500 * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC
501 * message containing an NFC record with MIME type
Benjamin Franzea956242016-03-21 15:45:56 +0000502 * {@link #MIME_TYPE_PROVISIONING_NFC}. For the NFC record, the component name must be
Rubin Xu44ef750b2015-03-23 16:51:33 +0000503 * flattened to a string, via {@link ComponentName#flattenToShortString()}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000504 *
505 * @see DeviceAdminReceiver
506 */
507 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME
508 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME";
509
510 /**
Alexandra Gherghinaaaf2f3e2014-11-13 12:46:15 +0000511 * An {@link android.accounts.Account} extra holding the account to migrate during managed
512 * profile provisioning. If the account supplied is present in the primary user, it will be
513 * copied, along with its credentials to the managed profile and removed from the primary user.
514 *
515 * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}.
516 */
517
518 public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE
519 = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE";
520
521 /**
Victor Changaa9cbc02016-12-05 20:50:57 +0000522 * Boolean extra to indicate that the migrated account should be kept. This is used in
523 * conjunction with {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}. If it's set to {@code true},
524 * the account will not be removed from the primary user after it is migrated to the newly
525 * created user or profile.
Victor Chang89ee2792016-11-23 12:10:55 +0000526 *
527 * <p> Defaults to {@code false}
528 *
Victor Changaa9cbc02016-12-05 20:50:57 +0000529 * <p> Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
530 * {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}
Victor Chang89ee2792016-11-23 12:10:55 +0000531 */
532 public static final String EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION
533 = "android.app.extra.PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION";
534
535 /**
Jessica Hummele3da7902014-08-20 15:20:11 +0100536 * A String extra that, holds the email address of the account which a managed profile is
537 * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
538 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100539 *
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100540 * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}.
541 *
Jessica Hummele3da7902014-08-20 15:20:11 +0100542 * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning
543 * contains this extra, it is forwarded in the
544 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile
545 * device management application that was set as the profile owner during provisioning.
546 * It is usually used to avoid that the user has to enter their email address twice.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100547 */
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 /**
706 * A String extra holding a url to the website of the device's provider. The website can be
707 * opened in a browser during provisioning.
708 *
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}
912 */
913 public static final String EXTRA_PROVISIONING_DISCLAIMER_HEADER =
914 "android.app.extra.PROVISIONING_DISCLAIMER_HEADER";
915
916 /**
917 * A {@link Uri} extra pointing to disclaimer content.
918 *
919 * <h5>The following URI schemes are accepted:</h5>
920 * <ul>
921 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
922 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
923 * </ul>
924 *
925 * <p> Styled text is supported in the disclaimer content. The content is parsed by
926 * {@link android.text.Html#fromHtml(String)} and displayed in a
927 * {@link android.widget.TextView}.
928 *
929 * <p> If a <code>content:</code> URI is passed, URI is passed, the intent should have the flag
930 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
931 * {@link android.content.ClipData} of the intent too.
932 *
933 * <p> Use in Bundle {@link #EXTRA_PROVISIONING_DISCLAIMERS}
934 */
935 public static final String EXTRA_PROVISIONING_DISCLAIMER_CONTENT =
936 "android.app.extra.PROVISIONING_DISCLAIMER_CONTENT";
937
938 /**
Alan Treadway94de8c82016-01-11 10:25:23 +0000939 * A boolean extra indicating if user setup should be skipped, for when provisioning is started
940 * during setup-wizard.
941 *
942 * <p>If unspecified, defaults to {@code true} to match the behavior in
943 * {@link android.os.Build.VERSION_CODES#M} and earlier.
944 *
Alan Treadway1a538d02016-01-18 16:42:30 +0000945 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or
946 * {@link #ACTION_PROVISION_MANAGED_USER}.
Alan Treadway94de8c82016-01-11 10:25:23 +0000947 *
948 * @hide
949 */
950 public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP =
951 "android.app.extra.PROVISIONING_SKIP_USER_SETUP";
952
953 /**
Victor Chang51d84f92016-11-16 12:22:56 +0000954 * A boolean extra indicating if the user consent steps from the provisioning flow should be
955 * skipped. If unspecified, defaults to {@code false}.
956 *
957 * It can only be used by an existing device owner trying to create a managed profile via
958 * {@link #ACTION_PROVISION_MANAGED_PROFILE}. Otherwise it is ignored.
959 */
960 public static final String EXTRA_PROVISIONING_SKIP_USER_CONSENT =
961 "android.app.extra.PROVISIONING_SKIP_USER_CONSENT";
962
963 /**
Benjamin Franzea956242016-03-21 15:45:56 +0000964 * This MIME type is used for starting the device owner provisioning.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100965 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400966 * <p>During device owner provisioning a device admin app is set as the owner of the device.
967 * A device owner has full control over the device. The device owner can not be modified by the
968 * user and the only way of resetting the device is if the device owner app calls a factory
969 * reset.
970 *
971 * <p> A typical use case would be a device that is owned by a company, but used by either an
972 * employee or client.
973 *
Benjamin Franzea956242016-03-21 15:45:56 +0000974 * <p> The NFC message must be sent to an unprovisioned device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100975 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000976 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100977 * contains the following properties:
978 * <ul>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400979 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
980 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100981 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400982 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100983 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
984 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
985 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
986 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
987 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
988 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
989 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
990 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
991 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
992 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100993 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
994 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from
995 * {@link android.os.Build.VERSION_CODES#M} </li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100996 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000997 * <p>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700998 * As of {@link android.os.Build.VERSION_CODES#M}, the properties should contain
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400999 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of
1000 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only
1001 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -04001002 */
1003 public static final String MIME_TYPE_PROVISIONING_NFC
1004 = "application/com.android.managedprovisioning";
1005
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +01001006 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001007 * Activity action: ask the user to add a new device administrator to the system.
1008 * The desired policy is the ComponentName of the policy in the
1009 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
1010 * bring the user through adding the device administrator to the system (or
1011 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001012 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001013 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
1014 * field to provide the user with additional explanation (in addition
1015 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001016 *
1017 * <p>If your administrator is already active, this will ordinarily return immediately (without
1018 * user intervention). However, if your administrator has been updated and is requesting
1019 * additional uses-policy flags, the user will be presented with the new list. New policies
1020 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001021 */
1022 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1023 public static final String ACTION_ADD_DEVICE_ADMIN
1024 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001025
Dianne Hackbornd6847842010-01-12 18:14:19 -08001026 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001027 * @hide
1028 * Activity action: ask the user to add a new device administrator as the profile owner
Amith Yamasani814e9872015-03-23 14:04:53 -07001029 * for this user. Only system apps can launch this intent.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001030 *
Amith Yamasani814e9872015-03-23 14:04:53 -07001031 * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN}
1032 * extra field. This will invoke a UI to bring the user through adding the profile owner admin
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001033 * to remotely control restrictions on the user.
1034 *
Makoto Onukic8a5a552015-11-19 14:29:12 -08001035 * <p>The intent must be invoked via {@link Activity#startActivityForResult} to receive the
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001036 * result of whether or not the user approved the action. If approved, the result will
1037 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
1038 * as a profile owner.
1039 *
1040 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
1041 * field to provide the user with additional explanation (in addition
1042 * to your component's description) about what is being added.
1043 *
Amith Yamasani814e9872015-03-23 14:04:53 -07001044 * <p>If there is already a profile owner active or the caller is not a system app, the
1045 * operation will return a failure result.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001046 */
1047 @SystemApi
1048 public static final String ACTION_SET_PROFILE_OWNER
1049 = "android.app.action.SET_PROFILE_OWNER";
1050
1051 /**
1052 * @hide
1053 * Name of the profile owner admin that controls the user.
1054 */
1055 @SystemApi
1056 public static final String EXTRA_PROFILE_OWNER_NAME
1057 = "android.app.extra.PROFILE_OWNER_NAME";
1058
1059 /**
Nicolas Prevot00799002015-07-27 18:15:20 +01001060 * Broadcast action: send when any policy admin changes a policy.
Jim Miller284b62e2010-06-08 14:27:42 -07001061 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -07001062 *
Jim Miller284b62e2010-06-08 14:27:42 -07001063 * @hide
1064 */
1065 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
1066 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
1067
1068 /**
Tony Mak1970f972016-08-30 17:41:48 +01001069 * Broadcast action: sent when the device owner is set, changed or cleared.
Nicolas Prevot00799002015-07-27 18:15:20 +01001070 *
1071 * This broadcast is sent only to the primary user.
1072 * @see #ACTION_PROVISION_MANAGED_DEVICE
1073 */
1074 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1075 public static final String ACTION_DEVICE_OWNER_CHANGED
1076 = "android.app.action.DEVICE_OWNER_CHANGED";
1077
1078 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001079 * The ComponentName of the administrator component.
1080 *
1081 * @see #ACTION_ADD_DEVICE_ADMIN
1082 */
1083 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001084
Dianne Hackbornd6847842010-01-12 18:14:19 -08001085 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001086 * An optional CharSequence providing additional explanation for why the
1087 * admin is being added.
1088 *
1089 * @see #ACTION_ADD_DEVICE_ADMIN
1090 */
1091 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001092
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001093 /**
phweiss73145f42017-01-17 19:06:38 +01001094 * Constant to indicate the feature of disabling the camera. Used as argument to
1095 * {@link #createAdminSupportIntent(String)}.
1096 * @see #setCameraDisabled(ComponentName, boolean)
1097 */
1098 public static final String POLICY_DISABLE_CAMERA = "policy_disable_camera";
1099
1100 /**
1101 * Constant to indicate the feature of disabling screen captures. Used as argument to
1102 * {@link #createAdminSupportIntent(String)}.
1103 * @see #setScreenCaptureDisabled(ComponentName, boolean)
1104 */
1105 public static final String POLICY_DISABLE_SCREEN_CAPTURE = "policy_disable_screen_capture";
1106
1107 /**
1108 * A String indicating a specific restricted feature. Can be a user restriction from the
1109 * {@link UserManager}, e.g. {@link UserManager#DISALLOW_ADJUST_VOLUME}, or one of the values
1110 * {@link #POLICY_DISABLE_CAMERA} or {@link #POLICY_DISABLE_SCREEN_CAPTURE}.
1111 * @see #createAdminSupportIntent(String)
1112 * @hide
1113 */
1114 @TestApi
1115 public static final String EXTRA_RESTRICTION = "android.app.extra.RESTRICTION";
1116
1117 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001118 * Activity action: have the user enter a new password. This activity should
1119 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
1120 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
1121 * enter a new password that meets the current requirements. You can use
1122 * {@link #isActivePasswordSufficient()} to determine whether you need to
1123 * have the user select a new password in order to meet the current
1124 * constraints. Upon being resumed from this activity, you can check the new
1125 * password characteristics to see if they are sufficient.
Benjamin Franzc9921092016-01-08 17:17:44 +00001126 *
1127 * If the intent is launched from within a managed profile with a profile
1128 * owner built against {@link android.os.Build.VERSION_CODES#M} or before,
1129 * this will trigger entering a new password for the parent of the profile.
1130 * For all other cases it will trigger entering a new password for the user
1131 * or profile it is launched from.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001132 *
1133 * @see #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
Dianne Hackbornd6847842010-01-12 18:14:19 -08001134 */
1135 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1136 public static final String ACTION_SET_NEW_PASSWORD
1137 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001138
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001139 /**
Benjamin Franzc9921092016-01-08 17:17:44 +00001140 * Activity action: have the user enter a new password for the parent profile.
1141 * If the intent is launched from within a managed profile, this will trigger
1142 * entering a new password for the parent of the profile. In all other cases
1143 * the behaviour is identical to {@link #ACTION_SET_NEW_PASSWORD}.
1144 */
1145 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1146 public static final String ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
1147 = "android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD";
1148
1149 /**
phweissa0cb2512016-12-14 21:37:48 +01001150 * Broadcast action: Tell the status bar to open the device monitoring dialog, e.g. when
1151 * Network logging was enabled and the user tapped the notification.
1152 * <p class="note">This is a protected intent that can only be sent by the system.</p>
1153 * @hide
1154 */
1155 public static final String ACTION_SHOW_DEVICE_MONITORING_DIALOG
1156 = "android.app.action.SHOW_DEVICE_MONITORING_DIALOG";
1157
1158 /**
Edman Anjosf9946772016-11-28 16:35:15 +01001159 * Broadcast Action: Sent after application delegation scopes are changed. The new list of
1160 * delegation scopes will be sent in an extra identified by the {@link #EXTRA_DELEGATION_SCOPES}
1161 * key.
1162 *
1163 * <p class=”note”> Note: This is a protected intent that can only be sent by the system.</p>
1164 */
1165 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1166 public static final String ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED =
1167 "android.app.action.APPLICATION_DELEGATION_SCOPES_CHANGED";
1168
1169 /**
1170 * A list of Strings corresponding to the delegation scopes given to an app in the
1171 * {@link #ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED} broadcast.
1172 */
1173 public static final String EXTRA_DELEGATION_SCOPES = "android.app.extra.DELEGATION_SCOPES";
1174
1175 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +00001176 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
1177 * the parent profile to access intents sent from the managed profile.
1178 * That is, when an app in the managed profile calls
1179 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
1180 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001181 */
Nicolas Prevot86a96732014-09-08 12:13:05 +01001182 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001183
1184 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +00001185 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
1186 * the managed profile to access intents sent from the parent profile.
1187 * That is, when an app in the parent profile calls
1188 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
1189 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001190 */
Nicolas Prevot86a96732014-09-08 12:13:05 +01001191 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001192
Dianne Hackbornd6847842010-01-12 18:14:19 -08001193 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01001194 * Broadcast action: notify that a new local system update policy has been set by the device
1195 * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00001196 */
1197 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Rubin Xu5faad8e2015-04-20 17:43:48 +01001198 public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED
1199 = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED";
Rubin Xu8027a4f2015-03-10 17:52:37 +00001200
Amith Yamasanid49489b2015-04-28 14:00:26 -07001201 /**
1202 * Permission policy to prompt user for new permission requests for runtime permissions.
1203 * Already granted or denied permissions are not affected by this.
1204 */
1205 public static final int PERMISSION_POLICY_PROMPT = 0;
1206
1207 /**
1208 * Permission policy to always grant new permission requests for runtime permissions.
1209 * Already granted or denied permissions are not affected by this.
1210 */
1211 public static final int PERMISSION_POLICY_AUTO_GRANT = 1;
1212
1213 /**
1214 * Permission policy to always deny new permission requests for runtime permissions.
1215 * Already granted or denied permissions are not affected by this.
1216 */
1217 public static final int PERMISSION_POLICY_AUTO_DENY = 2;
1218
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07001219 /**
1220 * Runtime permission state: The user can manage the permission
1221 * through the UI.
1222 */
1223 public static final int PERMISSION_GRANT_STATE_DEFAULT = 0;
1224
1225 /**
1226 * Runtime permission state: The permission is granted to the app
1227 * and the user cannot manage the permission through the UI.
1228 */
1229 public static final int PERMISSION_GRANT_STATE_GRANTED = 1;
1230
1231 /**
1232 * Runtime permission state: The permission is denied to the app
1233 * and the user cannot manage the permission through the UI.
1234 */
1235 public static final int PERMISSION_GRANT_STATE_DENIED = 2;
Rubin Xu8027a4f2015-03-10 17:52:37 +00001236
1237 /**
Edman Anjosf9946772016-11-28 16:35:15 +01001238 * Delegation of certificate installation and management. This scope grants access to the
1239 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
1240 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair} APIs.
1241 */
1242 public static final String DELEGATION_CERT_INSTALL = "delegation-cert-install";
1243
1244 /**
1245 * Delegation of application restrictions management. This scope grants access to the
1246 * {@link #setApplicationRestrictions} and {@link #getApplicationRestrictions} APIs.
1247 */
1248 public static final String DELEGATION_APP_RESTRICTIONS = "delegation-app-restrictions";
1249
1250 /**
Edman Anjosa5f2fb12016-12-19 11:25:54 -08001251 * Delegation of application uninstall block. This scope grants access to the
1252 * {@link #setUninstallBlocked} API.
1253 */
1254 public static final String DELEGATION_BLOCK_UNINSTALL = "delegation-block-uninstall";
1255
1256 /**
Edman Anjos52088e42017-01-13 22:26:17 +01001257 * Delegation of permission policy and permission grant state. This scope grants access to the
1258 * {@link #setPermissionPolicy}, {@link #getPermissionGrantState},
1259 * and {@link #setPermissionGrantState} APIs.
1260 */
1261 public static final String DELEGATION_PERMISSION_GRANT = "delegation-permission-grant";
1262
1263 /**
1264 * Delegation of package access state. This scope grants access to the
1265 * {@link #isApplicationHidden}, {@link #setApplicationHidden}, {@link #isPackageSuspended}, and
1266 * {@link #setPackagesSuspended} APIs.
1267 */
1268 public static final String DELEGATION_PACKAGE_ACCESS = "delegation-package-access";
1269
1270 /**
1271 * Delegation for enabling system apps. This scope grants access to the {@link #enableSystemApp}
1272 * API.
1273 */
1274 public static final String DELEGATION_ENABLE_SYSTEM_APP = "delegation-enable-system-app";
1275
1276 /**
1277 * Delegation of management of uninstalled packages. This scope grants access to the
1278 * {@code #setKeepUninstalledPackages} and {@code #getKeepUninstalledPackages} APIs.
1279 * @hide
1280 */
1281 public static final String DELEGATION_KEEP_UNINSTALLED_PACKAGES =
1282 "delegation-keep-uninstalled-packages";
1283
1284 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00001285 * No management for current user in-effect. This is the default.
1286 * @hide
1287 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001288 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001289 public static final int STATE_USER_UNMANAGED = 0;
1290
1291 /**
1292 * Management partially setup, user setup needs to be completed.
1293 * @hide
1294 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001295 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001296 public static final int STATE_USER_SETUP_INCOMPLETE = 1;
1297
1298 /**
1299 * Management partially setup, user setup completed.
1300 * @hide
1301 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001302 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001303 public static final int STATE_USER_SETUP_COMPLETE = 2;
1304
1305 /**
1306 * Management setup and active on current user.
1307 * @hide
1308 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001309 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001310 public static final int STATE_USER_SETUP_FINALIZED = 3;
1311
1312 /**
1313 * Management partially setup on a managed profile.
1314 * @hide
1315 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001316 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001317 public static final int STATE_USER_PROFILE_COMPLETE = 4;
1318
1319 /**
1320 * @hide
1321 */
1322 @IntDef({STATE_USER_UNMANAGED, STATE_USER_SETUP_INCOMPLETE, STATE_USER_SETUP_COMPLETE,
1323 STATE_USER_SETUP_FINALIZED, STATE_USER_PROFILE_COMPLETE})
1324 @Retention(RetentionPolicy.SOURCE)
1325 public @interface UserProvisioningState {}
1326
1327 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001328 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001329 *
1330 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1331 * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and
1332 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when provisioning is allowed.
1333 *
1334 * @hide
1335 */
1336 public static final int CODE_OK = 0;
1337
1338 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001339 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001340 *
1341 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and
1342 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the device already has a device
1343 * owner.
1344 *
1345 * @hide
1346 */
1347 public static final int CODE_HAS_DEVICE_OWNER = 1;
1348
1349 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001350 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001351 *
1352 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1353 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user has a profile owner and for
1354 * {@link #ACTION_PROVISION_MANAGED_PROFILE} when the profile owner is already set.
1355 *
1356 * @hide
1357 */
1358 public static final int CODE_USER_HAS_PROFILE_OWNER = 2;
1359
1360 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001361 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001362 *
1363 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and
1364 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user isn't running.
1365 *
1366 * @hide
1367 */
1368 public static final int CODE_USER_NOT_RUNNING = 3;
1369
1370 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001371 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001372 *
1373 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1374 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the device has already been setup and
1375 * for {@link #ACTION_PROVISION_MANAGED_USER} if the user has already been setup.
1376 *
1377 * @hide
1378 */
1379 public static final int CODE_USER_SETUP_COMPLETED = 4;
1380
1381 /**
1382 * Code used to indicate that the device also has a user other than the system user.
1383 *
1384 * @hide
1385 */
1386 public static final int CODE_NONSYSTEM_USER_EXISTS = 5;
1387
1388 /**
1389 * Code used to indicate that device has an account that prevents provisioning.
1390 *
1391 * @hide
1392 */
1393 public static final int CODE_ACCOUNTS_NOT_EMPTY = 6;
1394
1395 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001396 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001397 *
1398 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and
1399 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the user is not a system user.
1400 *
1401 * @hide
1402 */
1403 public static final int CODE_NOT_SYSTEM_USER = 7;
1404
1405 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001406 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001407 *
1408 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1409 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} and {@link #ACTION_PROVISION_MANAGED_USER}
1410 * when the device is a watch and is already paired.
1411 *
1412 * @hide
1413 */
1414 public static final int CODE_HAS_PAIRED = 8;
1415
1416 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001417 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001418 *
1419 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} and
1420 * {@link #ACTION_PROVISION_MANAGED_USER} on devices which do not support managed users.
1421 *
1422 * @see {@link PackageManager#FEATURE_MANAGED_USERS}
1423 * @hide
1424 */
1425 public static final int CODE_MANAGED_USERS_NOT_SUPPORTED = 9;
1426
1427 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001428 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001429 *
1430 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} if the user is a system user.
1431 *
1432 * @hide
1433 */
1434 public static final int CODE_SYSTEM_USER = 10;
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} when the user cannot have more
1440 * managed profiles.
1441 *
1442 * @hide
1443 */
1444 public static final int CODE_CANNOT_ADD_MANAGED_PROFILE = 11;
1445
1446 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001447 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001448 *
1449 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} and
1450 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices not running with split system
1451 * user.
1452 *
1453 * @hide
1454 */
1455 public static final int CODE_NOT_SYSTEM_USER_SPLIT = 12;
1456
1457 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001458 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001459 *
1460 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1461 * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and
1462 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices which do no support device
1463 * admins.
1464 *
1465 * @hide
1466 */
1467 public static final int CODE_DEVICE_ADMIN_NOT_SUPPORTED = 13;
1468
1469 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001470 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001471 *
Esteban Talavera6c9116a2016-11-24 16:12:44 +00001472 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when the device the user is a
1473 * system user on a split system user device.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001474 *
1475 * @hide
1476 */
1477 public static final int CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER = 14;
1478
1479 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001480 * Result code for {@link #checkProvisioningPreCondition}.
1481 *
1482 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when adding a managed profile is
1483 * disallowed by {@link UserManager#DISALLOW_ADD_MANAGED_PROFILE}.
1484 *
1485 * @hide
1486 */
1487 public static final int CODE_ADD_MANAGED_PROFILE_DISALLOWED = 15;
1488
1489 /**
1490 * Result codes for {@link #checkProvisioningPreCondition} indicating all the provisioning pre
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001491 * conditions.
1492 *
1493 * @hide
1494 */
1495 @Retention(RetentionPolicy.SOURCE)
1496 @IntDef({CODE_OK, CODE_HAS_DEVICE_OWNER, CODE_USER_HAS_PROFILE_OWNER, CODE_USER_NOT_RUNNING,
1497 CODE_USER_SETUP_COMPLETED, CODE_NOT_SYSTEM_USER, CODE_HAS_PAIRED,
1498 CODE_MANAGED_USERS_NOT_SUPPORTED, CODE_SYSTEM_USER, CODE_CANNOT_ADD_MANAGED_PROFILE,
1499 CODE_NOT_SYSTEM_USER_SPLIT, CODE_DEVICE_ADMIN_NOT_SUPPORTED,
Esteban Talavera01576862016-12-15 11:16:44 +00001500 CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER, CODE_ADD_MANAGED_PROFILE_DISALLOWED})
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001501 public @interface ProvisioningPreCondition {}
1502
1503 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001504 * Return true if the given administrator component is currently active (enabled) in the system.
1505 *
1506 * @param admin The administrator component to check for.
1507 * @return {@code true} if {@code admin} is currently enabled in the system, {@code false}
1508 * otherwise
Dianne Hackbornd6847842010-01-12 18:14:19 -08001509 */
Robin Lee25e26452015-06-02 09:56:29 -07001510 public boolean isAdminActive(@NonNull ComponentName admin) {
Charles He8c760562016-10-25 16:36:53 +01001511 throwIfParentInstance("isAdminActive");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001512 return isAdminActiveAsUser(admin, myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001513 }
1514
1515 /**
1516 * @see #isAdminActive(ComponentName)
1517 * @hide
1518 */
Robin Lee25e26452015-06-02 09:56:29 -07001519 public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001520 if (mService != null) {
1521 try {
Robin Lee25e26452015-06-02 09:56:29 -07001522 return mService.isAdminActive(admin, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001523 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001524 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001525 }
1526 }
1527 return false;
1528 }
Charles Hedea0c3b2017-01-13 10:04:12 +00001529
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001530 /**
1531 * Return true if the given administrator component is currently being removed
1532 * for the user.
1533 * @hide
1534 */
Robin Lee25e26452015-06-02 09:56:29 -07001535 public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) {
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001536 if (mService != null) {
1537 try {
Robin Lee25e26452015-06-02 09:56:29 -07001538 return mService.isRemovingAdmin(admin, userId);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001539 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001540 throw e.rethrowFromSystemServer();
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001541 }
1542 }
1543 return false;
1544 }
1545
Dianne Hackbornd6847842010-01-12 18:14:19 -08001546 /**
Robin Lee25e26452015-06-02 09:56:29 -07001547 * Return a list of all currently active device administrators' component
1548 * names. If there are no administrators {@code null} may be
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001549 * returned.
1550 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07001551 public @Nullable List<ComponentName> getActiveAdmins() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001552 throwIfParentInstance("getActiveAdmins");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001553 return getActiveAdminsAsUser(myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001554 }
1555
1556 /**
1557 * @see #getActiveAdmins()
1558 * @hide
1559 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07001560 public @Nullable List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001561 if (mService != null) {
1562 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001563 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001564 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001565 throw e.rethrowFromSystemServer();
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001566 }
1567 }
1568 return null;
1569 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001570
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001571 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001572 * Used by package administration code to determine if a package can be stopped
1573 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001574 * @hide
1575 */
David Ouyang3a83a332017-01-11 16:36:40 -08001576 @SystemApi
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001577 public boolean packageHasActiveAdmins(String packageName) {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001578 return packageHasActiveAdmins(packageName, myUserId());
1579 }
1580
1581 /**
1582 * Used by package administration code to determine if a package can be stopped
1583 * or uninstalled.
1584 * @hide
1585 */
1586 public boolean packageHasActiveAdmins(String packageName, int userId) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001587 if (mService != null) {
1588 try {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001589 return mService.packageHasActiveAdmins(packageName, userId);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001590 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001591 throw e.rethrowFromSystemServer();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001592 }
1593 }
1594 return false;
1595 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001596
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001597 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001598 * Remove a current administration component. This can only be called
1599 * by the application that owns the administration component; if you
1600 * try to remove someone else's component, a security exception will be
1601 * thrown.
Esteban Talavera552a5612016-02-19 17:02:24 +00001602 *
1603 * <p>Note that the operation is not synchronous and the admin might still be active (as
1604 * indicated by {@link #getActiveAdmins()}) by the time this method returns.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001605 *
1606 * @param admin The administration compononent to remove.
1607 * @throws SecurityException if the caller is not in the owner application of {@code admin}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001608 */
Robin Lee25e26452015-06-02 09:56:29 -07001609 public void removeActiveAdmin(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001610 throwIfParentInstance("removeActiveAdmin");
Dianne Hackbornd6847842010-01-12 18:14:19 -08001611 if (mService != null) {
1612 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001613 mService.removeActiveAdmin(admin, myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001614 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001615 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001616 }
1617 }
1618 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001619
Dianne Hackbornd6847842010-01-12 18:14:19 -08001620 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001621 * Returns true if an administrator has been granted a particular device policy. This can be
1622 * used to check whether the administrator was activated under an earlier set of policies, but
1623 * requires additional policies after an upgrade.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001624 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001625 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be an
1626 * active administrator, or an exception will be thrown.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001627 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001628 * @throws SecurityException if {@code admin} is not an active administrator.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001629 */
Robin Lee25e26452015-06-02 09:56:29 -07001630 public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001631 throwIfParentInstance("hasGrantedPolicy");
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001632 if (mService != null) {
1633 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001634 return mService.hasGrantedPolicy(admin, usesPolicy, myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001635 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001636 throw e.rethrowFromSystemServer();
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001637 }
1638 }
1639 return false;
1640 }
1641
1642 /**
Clara Bayarria1771112015-12-18 16:29:18 +00001643 * Returns true if the Profile Challenge is available to use for the given profile user.
1644 *
1645 * @hide
1646 */
1647 public boolean isSeparateProfileChallengeAllowed(int userHandle) {
1648 if (mService != null) {
1649 try {
1650 return mService.isSeparateProfileChallengeAllowed(userHandle);
1651 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001652 throw e.rethrowFromSystemServer();
Clara Bayarria1771112015-12-18 16:29:18 +00001653 }
1654 }
1655 return false;
1656 }
1657
1658 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001659 * Constant for {@link #setPasswordQuality}: the policy has no requirements
1660 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001661 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001662 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001663 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001664
Dianne Hackbornd6847842010-01-12 18:14:19 -08001665 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -07001666 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
1667 * recognition technology. This implies technologies that can recognize the identity of
1668 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
1669 * Note that quality constants are ordered so that higher values are more restrictive.
1670 */
1671 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
1672
1673 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001674 * Constant for {@link #setPasswordQuality}: the policy requires some kind
Benjamin Franzc6a96532015-06-16 11:23:38 +01001675 * of password or pattern, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001676 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001677 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001678 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001679
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001680 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001681 * Constant for {@link #setPasswordQuality}: the user must have entered a
1682 * password containing at least numeric characters. Note that quality
1683 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001684 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001685 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001686
Dianne Hackbornd6847842010-01-12 18:14:19 -08001687 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001688 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -08001689 * password containing at least numeric characters with no repeating (4444)
1690 * or ordered (1234, 4321, 2468) sequences. Note that quality
1691 * constants are ordered so that higher values are more restrictive.
1692 */
1693 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
1694
1695 /**
1696 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001697 * password containing at least alphabetic (or other symbol) characters.
1698 * Note that quality constants are ordered so that higher values are more
1699 * restrictive.
1700 */
1701 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001702
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001703 /**
1704 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001705 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001706 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001707 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001708 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001709 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001710
Dianne Hackbornd6847842010-01-12 18:14:19 -08001711 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001712 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001713 * password containing at least a letter, a numerical digit and a special
1714 * symbol, by default. With this password quality, passwords can be
1715 * restricted to contain various sets of characters, like at least an
1716 * uppercase letter, etc. These are specified using various methods,
1717 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
1718 * that quality constants are ordered so that higher values are more
1719 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001720 */
1721 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
1722
1723 /**
Oleksandr Peletskyi0fdcd3d2016-01-13 16:49:56 +01001724 * Constant for {@link #setPasswordQuality}: the user is not allowed to
1725 * modify password. In case this password quality is set, the password is
1726 * managed by a profile owner. The profile owner can set any password,
1727 * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note
1728 * that quality constants are ordered so that higher values are more
1729 * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is
1730 * the highest.
1731 * @hide
1732 */
1733 public static final int PASSWORD_QUALITY_MANAGED = 0x80000;
1734
1735 /**
Makoto Onuki5e7e06702016-09-01 18:02:01 -07001736 * @hide
1737 *
1738 * adb shell dpm set-{device,profile}-owner will normally not allow installing an owner to
1739 * a user with accounts. {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED}
1740 * and {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} are the account features
1741 * used by authenticator to exempt their accounts from this:
1742 *
1743 * <ul>
1744 * <li>Non-test-only DO/PO still can't be installed when there are accounts.
1745 * <p>In order to make an apk test-only, add android:testOnly="true" to the
1746 * &lt;application&gt; tag in the manifest.
1747 *
1748 * <li>Test-only DO/PO can be installed even when there are accounts, as long as all the
1749 * accounts have the {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} feature.
1750 * Some authenticators claim to have any features, so to detect it, we also check
1751 * {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} and disallow installing
1752 * if any of the accounts have it.
1753 * </ul>
1754 */
1755 public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED =
1756 "android.account.DEVICE_OR_PROFILE_OWNER_ALLOWED";
1757
1758 /** @hide See {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} */
1759 public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED =
1760 "android.account.DEVICE_OR_PROFILE_OWNER_DISALLOWED";
1761
1762 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001763 * Called by an application that is administering the device to set the password restrictions it
1764 * is imposing. After setting this, the user will not be able to enter a new password that is
1765 * not at least as restrictive as what has been set. Note that the current password will remain
1766 * until the user has set a new one, so the change does not take place immediately. To prompt
1767 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
Esteban Talaverac1c83592016-02-17 17:56:15 +00001768 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after calling this method.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001769 * <p>
1770 * Quality constants are ordered so that higher values are more restrictive; thus the highest
1771 * requested quality constant (between the policy set here, the user's preference, and any other
1772 * considerations) is the one that is in effect.
1773 * <p>
1774 * The calling device admin must have requested
1775 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1776 * not, a security exception will be thrown.
1777 * <p>
1778 * This method can be called on the {@link DevicePolicyManager} instance returned by
1779 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1780 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001781 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001782 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001783 * @param quality The new desired quality. One of {@link #PASSWORD_QUALITY_UNSPECIFIED},
1784 * {@link #PASSWORD_QUALITY_SOMETHING}, {@link #PASSWORD_QUALITY_NUMERIC},
1785 * {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC},
1786 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} or {@link #PASSWORD_QUALITY_COMPLEX}.
1787 * @throws SecurityException if {@code admin} is not an active administrator or if {@code admin}
1788 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Dianne Hackbornd6847842010-01-12 18:14:19 -08001789 */
Robin Lee25e26452015-06-02 09:56:29 -07001790 public void setPasswordQuality(@NonNull ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001791 if (mService != null) {
1792 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001793 mService.setPasswordQuality(admin, quality, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001794 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001795 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001796 }
1797 }
1798 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001799
Dianne Hackbornd6847842010-01-12 18:14:19 -08001800 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001801 * Retrieve the current minimum password quality for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01001802 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00001803 * a separate challenge are not taken into account.
1804 *
1805 * <p>This method can be called on the {@link DevicePolicyManager} instance
1806 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1807 * restrictions on the parent profile.
1808 *
Robin Lee25e26452015-06-02 09:56:29 -07001809 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001810 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001811 */
Robin Lee25e26452015-06-02 09:56:29 -07001812 public int getPasswordQuality(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001813 return getPasswordQuality(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001814 }
1815
1816 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001817 public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001818 if (mService != null) {
1819 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001820 return mService.getPasswordQuality(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001821 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001822 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001823 }
1824 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001825 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001826 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001827
Dianne Hackbornd6847842010-01-12 18:14:19 -08001828 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001829 * Called by an application that is administering the device to set the minimum allowed password
1830 * length. After setting this, the user will not be able to enter a new password that is not at
1831 * least as restrictive as what has been set. Note that the current password will remain until
1832 * the user has set a new one, so the change does not take place immediately. To prompt the user
1833 * for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
1834 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
1835 * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC}
1836 * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC},
1837 * {@link #PASSWORD_QUALITY_ALPHANUMERIC}, or {@link #PASSWORD_QUALITY_COMPLEX} with
1838 * {@link #setPasswordQuality}.
1839 * <p>
1840 * The calling device admin must have requested
1841 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1842 * not, a security exception will be thrown.
1843 * <p>
1844 * This method can be called on the {@link DevicePolicyManager} instance returned by
1845 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1846 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001847 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001848 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001849 * @param length The new desired minimum password length. A value of 0 means there is no
1850 * restriction.
1851 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1852 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Dianne Hackbornd6847842010-01-12 18:14:19 -08001853 */
Robin Lee25e26452015-06-02 09:56:29 -07001854 public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001855 if (mService != null) {
1856 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001857 mService.setPasswordMinimumLength(admin, length, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001858 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001859 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001860 }
1861 }
1862 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001863
Dianne Hackbornd6847842010-01-12 18:14:19 -08001864 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001865 * Retrieve the current minimum password length for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01001866 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00001867 * a separate challenge are not taken into account.
1868 *
1869 * <p>This method can be called on the {@link DevicePolicyManager} instance
1870 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1871 * restrictions on the parent profile.
1872 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001873 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001874 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001875 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001876 */
Robin Lee25e26452015-06-02 09:56:29 -07001877 public int getPasswordMinimumLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001878 return getPasswordMinimumLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001879 }
1880
1881 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001882 public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001883 if (mService != null) {
1884 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001885 return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001886 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001887 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001888 }
1889 }
1890 return 0;
1891 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001892
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001893 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001894 * Called by an application that is administering the device to set the minimum number of upper
1895 * case letters required in the password. After setting this, the user will not be able to enter
1896 * a new password that is not at least as restrictive as what has been set. Note that the
1897 * current password will remain until the user has set a new one, so the change does not take
1898 * place immediately. To prompt the user for a new password, use
1899 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
1900 * setting this value. This constraint is only imposed if the administrator has also requested
1901 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001902 * <p>
1903 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001904 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1905 * not, a security exception will be thrown.
1906 * <p>
1907 * This method can be called on the {@link DevicePolicyManager} instance returned by
1908 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1909 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001910 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001911 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1912 * @param length The new desired minimum number of upper case letters required in the password.
1913 * A value of 0 means there is no restriction.
1914 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1915 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001916 */
Robin Lee25e26452015-06-02 09:56:29 -07001917 public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001918 if (mService != null) {
1919 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001920 mService.setPasswordMinimumUpperCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001921 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001922 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001923 }
1924 }
1925 }
1926
1927 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001928 * Retrieve the current number of upper case letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01001929 * for a particular admin or all admins that set restrictions on this user and
Esteban Talaverac1c83592016-02-17 17:56:15 +00001930 * its participating profiles. Restrictions on profiles that have a separate challenge
1931 * are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001932 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001933 * {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001934 * and only applies when the password quality is
1935 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001936 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001937 * <p>This method can be called on the {@link DevicePolicyManager} instance
1938 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1939 * restrictions on the parent profile.
1940 *
Robin Lee25e26452015-06-02 09:56:29 -07001941 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001942 * aggregate all admins.
1943 * @return The minimum number of upper case letters required in the
1944 * password.
1945 */
Robin Lee25e26452015-06-02 09:56:29 -07001946 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001947 return getPasswordMinimumUpperCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001948 }
1949
1950 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001951 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001952 if (mService != null) {
1953 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001954 return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001955 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001956 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001957 }
1958 }
1959 return 0;
1960 }
1961
1962 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001963 * Called by an application that is administering the device to set the minimum number of lower
1964 * case letters required in the password. After setting this, the user will not be able to enter
1965 * a new password that is not at least as restrictive as what has been set. Note that the
1966 * current password will remain until the user has set a new one, so the change does not take
1967 * place immediately. To prompt the user for a new password, use
1968 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
1969 * setting this value. This constraint is only imposed if the administrator has also requested
1970 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001971 * <p>
1972 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001973 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1974 * not, a security exception will be thrown.
1975 * <p>
1976 * This method can be called on the {@link DevicePolicyManager} instance returned by
1977 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1978 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001979 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001980 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1981 * @param length The new desired minimum number of lower case letters required in the password.
1982 * A value of 0 means there is no restriction.
1983 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1984 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001985 */
Robin Lee25e26452015-06-02 09:56:29 -07001986 public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001987 if (mService != null) {
1988 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001989 mService.setPasswordMinimumLowerCase(admin, length, 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 }
1995
1996 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001997 * Retrieve the current number of lower case letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01001998 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00001999 * and its participating profiles. Restrictions on profiles that have
2000 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01002001 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00002002 * {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002003 * and only applies when the password quality is
2004 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002005 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002006 * <p>This method can be called on the {@link DevicePolicyManager} instance
2007 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2008 * restrictions on the parent profile.
2009 *
Robin Lee25e26452015-06-02 09:56:29 -07002010 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002011 * aggregate all admins.
2012 * @return The minimum number of lower case letters required in the
2013 * password.
2014 */
Robin Lee25e26452015-06-02 09:56:29 -07002015 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002016 return getPasswordMinimumLowerCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002017 }
2018
2019 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002020 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002021 if (mService != null) {
2022 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002023 return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002024 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002025 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002026 }
2027 }
2028 return 0;
2029 }
2030
2031 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002032 * Called by an application that is administering the device to set the minimum number of
2033 * letters required in the password. After setting this, the user will not be able to enter a
2034 * new password that is not at least as restrictive as what has been set. Note that the current
2035 * password will remain until the user has set a new one, so the change does not take place
2036 * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
2037 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
2038 * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
2039 * {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002040 * <p>
2041 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002042 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2043 * not, a security exception will be thrown.
2044 * <p>
2045 * This method can be called on the {@link DevicePolicyManager} instance returned by
2046 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2047 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002048 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002049 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2050 * @param length The new desired minimum number of letters required in the password. A value of
2051 * 0 means there is no restriction.
2052 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2053 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002054 */
Robin Lee25e26452015-06-02 09:56:29 -07002055 public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002056 if (mService != null) {
2057 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002058 mService.setPasswordMinimumLetters(admin, length, 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 }
2064
2065 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002066 * Retrieve the current number of letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002067 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002068 * and its participating profiles. Restrictions on profiles that have
2069 * a separate challenge are not taken into account.
2070 * This is the same value as set by
2071 * {@link #setPasswordMinimumLetters(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002072 * and only applies when the password quality is
2073 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002074 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002075 * <p>This method can be called on the {@link DevicePolicyManager} instance
2076 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2077 * restrictions on the parent profile.
2078 *
Robin Lee25e26452015-06-02 09:56:29 -07002079 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002080 * aggregate all admins.
2081 * @return The minimum number of letters required in the password.
2082 */
Robin Lee25e26452015-06-02 09:56:29 -07002083 public int getPasswordMinimumLetters(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002084 return getPasswordMinimumLetters(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002085 }
2086
2087 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002088 public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002089 if (mService != null) {
2090 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002091 return mService.getPasswordMinimumLetters(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002092 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002093 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002094 }
2095 }
2096 return 0;
2097 }
2098
2099 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002100 * Called by an application that is administering the device to set the minimum number of
2101 * numerical digits required in the password. After setting this, the user will not be able to
2102 * enter a new password that is not at least as restrictive as what has been set. Note that the
2103 * current password will remain until the user has set a new one, so the change does not take
2104 * place immediately. To prompt the user for a new password, use
2105 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
2106 * setting this value. This constraint is only imposed if the administrator has also requested
2107 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002108 * <p>
2109 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002110 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2111 * not, a security exception will be thrown.
2112 * <p>
2113 * This method can be called on the {@link DevicePolicyManager} instance returned by
2114 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2115 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002116 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002117 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2118 * @param length The new desired minimum number of numerical digits required in the password. A
2119 * value of 0 means there is no restriction.
2120 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2121 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002122 */
Robin Lee25e26452015-06-02 09:56:29 -07002123 public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002124 if (mService != null) {
2125 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002126 mService.setPasswordMinimumNumeric(admin, length, 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 }
2132
2133 /**
2134 * Retrieve the current number of numerical digits required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002135 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002136 * and its participating profiles. Restrictions on profiles that have
2137 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01002138 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00002139 * {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002140 * and only applies when the password quality is
2141 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002142 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002143 * <p>This method can be called on the {@link DevicePolicyManager} instance
2144 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2145 * restrictions on the parent profile.
2146 *
Robin Lee25e26452015-06-02 09:56:29 -07002147 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002148 * aggregate all admins.
2149 * @return The minimum number of numerical digits required in the password.
2150 */
Robin Lee25e26452015-06-02 09:56:29 -07002151 public int getPasswordMinimumNumeric(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002152 return getPasswordMinimumNumeric(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002153 }
2154
2155 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002156 public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002157 if (mService != null) {
2158 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002159 return mService.getPasswordMinimumNumeric(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002160 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002161 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002162 }
2163 }
2164 return 0;
2165 }
2166
2167 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002168 * Called by an application that is administering the device to set the minimum number of
2169 * symbols required in the password. After setting this, the user will not be able to enter a
2170 * new password that is not at least as restrictive as what has been set. Note that the current
2171 * password will remain until the user has set a new one, so the change does not take place
2172 * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
2173 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
2174 * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
2175 * {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002176 * <p>
2177 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002178 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2179 * not, a security exception will be thrown.
2180 * <p>
2181 * This method can be called on the {@link DevicePolicyManager} instance returned by
2182 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2183 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002184 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002185 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2186 * @param length The new desired minimum number of symbols required in the password. A value of
2187 * 0 means there is no restriction.
2188 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2189 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002190 */
Robin Lee25e26452015-06-02 09:56:29 -07002191 public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002192 if (mService != null) {
2193 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002194 mService.setPasswordMinimumSymbols(admin, length, 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 }
2200
2201 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002202 * Retrieve the current number of symbols required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002203 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002204 * and its participating profiles. Restrictions on profiles that have
2205 * a separate challenge are not taken into account. This is the same value as
2206 * set by {@link #setPasswordMinimumSymbols(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002207 * and only applies when the password quality is
2208 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002209 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002210 * <p>This method can be called on the {@link DevicePolicyManager} instance
2211 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2212 * restrictions on the parent profile.
2213 *
Robin Lee25e26452015-06-02 09:56:29 -07002214 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002215 * aggregate all admins.
2216 * @return The minimum number of symbols required in the password.
2217 */
Robin Lee25e26452015-06-02 09:56:29 -07002218 public int getPasswordMinimumSymbols(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002219 return getPasswordMinimumSymbols(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002220 }
2221
2222 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002223 public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002224 if (mService != null) {
2225 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002226 return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002227 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002228 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002229 }
2230 }
2231 return 0;
2232 }
2233
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002234 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002235 * Called by an application that is administering the device to set the minimum number of
2236 * non-letter characters (numerical digits or symbols) required in the password. After setting
2237 * this, the user will not be able to enter a new password that is not at least as restrictive
2238 * as what has been set. Note that the current password will remain until the user has set a new
2239 * one, so the change does not take place immediately. To prompt the user for a new password,
2240 * use {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
2241 * setting this value. This constraint is only imposed if the administrator has also requested
2242 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002243 * <p>
2244 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002245 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2246 * not, a security exception will be thrown.
2247 * <p>
2248 * This method can be called on the {@link DevicePolicyManager} instance returned by
2249 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2250 * profile.
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002251 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002252 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2253 * @param length The new desired minimum number of letters required in the password. A value of
2254 * 0 means there is no restriction.
2255 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2256 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002257 */
Robin Lee25e26452015-06-02 09:56:29 -07002258 public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002259 if (mService != null) {
2260 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002261 mService.setPasswordMinimumNonLetter(admin, length, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002262 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002263 throw e.rethrowFromSystemServer();
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002264 }
2265 }
2266 }
2267
2268 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002269 * Retrieve the current number of non-letter characters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002270 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002271 * and its participating profiles. Restrictions on profiles that have
2272 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01002273 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00002274 * {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002275 * and only applies when the password quality is
2276 * {@link #PASSWORD_QUALITY_COMPLEX}.
2277 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002278 * <p>This method can be called on the {@link DevicePolicyManager} instance
2279 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2280 * restrictions on the parent profile.
2281 *
Robin Lee25e26452015-06-02 09:56:29 -07002282 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002283 * aggregate all admins.
2284 * @return The minimum number of letters required in the password.
2285 */
Robin Lee25e26452015-06-02 09:56:29 -07002286 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002287 return getPasswordMinimumNonLetter(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002288 }
2289
2290 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002291 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002292 if (mService != null) {
2293 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002294 return mService.getPasswordMinimumNonLetter(admin, userHandle, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002295 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002296 throw e.rethrowFromSystemServer();
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002297 }
2298 }
2299 return 0;
2300 }
2301
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002302 /**
2303 * Called by an application that is administering the device to set the length of the password
2304 * history. After setting this, the user will not be able to enter a new password that is the
2305 * same as any password in the history. Note that the current password will remain until the
2306 * user has set a new one, so the change does not take place immediately. To prompt the user for
2307 * a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
2308 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
2309 * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC}
2310 * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX} {@link #PASSWORD_QUALITY_ALPHABETIC}, or
2311 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} with {@link #setPasswordQuality}.
2312 * <p>
2313 * The calling device admin must have requested
2314 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2315 * not, a security exception will be thrown.
2316 * <p>
2317 * This method can be called on the {@link DevicePolicyManager} instance returned by
2318 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2319 * profile.
2320 *
2321 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2322 * @param length The new desired length of password history. A value of 0 means there is no
2323 * restriction.
2324 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2325 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
2326 */
Robin Lee25e26452015-06-02 09:56:29 -07002327 public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002328 if (mService != null) {
2329 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002330 mService.setPasswordHistoryLength(admin, length, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002331 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002332 throw e.rethrowFromSystemServer();
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002333 }
2334 }
2335 }
2336
2337 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002338 * Called by a device admin to set the password expiration timeout. Calling this method will
2339 * restart the countdown for password expiration for the given admin, as will changing the
2340 * device password (for all admins).
2341 * <p>
2342 * The provided timeout is the time delta in ms and will be added to the current time. For
2343 * example, to have the password expire 5 days from now, timeout would be 5 * 86400 * 1000 =
2344 * 432000000 ms for timeout.
2345 * <p>
2346 * To disable password expiration, a value of 0 may be used for timeout.
2347 * <p>
2348 * The calling device admin must have requested
2349 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this method; if it has
2350 * not, a security exception will be thrown.
2351 * <p>
2352 * Note that setting the password will automatically reset the expiration time for all active
2353 * admins. Active admins do not need to explicitly call this method in that case.
2354 * <p>
2355 * This method can be called on the {@link DevicePolicyManager} instance returned by
2356 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2357 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002358 *
Jim Millera4e28d12010-11-08 16:15:47 -08002359 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002360 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0 means
2361 * there is no restriction (unlimited).
2362 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2363 * does not use {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD}
Jim Millera4e28d12010-11-08 16:15:47 -08002364 */
Robin Lee25e26452015-06-02 09:56:29 -07002365 public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) {
Jim Millera4e28d12010-11-08 16:15:47 -08002366 if (mService != null) {
2367 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002368 mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08002369 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002370 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08002371 }
2372 }
2373 }
2374
2375 /**
Jim Miller6b857682011-02-16 16:27:41 -08002376 * Get the password expiration timeout for the given admin. The expiration timeout is the
2377 * recurring expiration timeout provided in the call to
2378 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
Esteban Talaverac1c83592016-02-17 17:56:15 +00002379 * aggregate of all participating policy administrators if {@code admin} is null. Admins that
2380 * have set restrictions on profiles that have a separate challenge are not taken into account.
2381 *
2382 * <p>This method can be called on the {@link DevicePolicyManager} instance
2383 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2384 * restrictions on the parent profile.
Jim Millera4e28d12010-11-08 16:15:47 -08002385 *
Robin Lee25e26452015-06-02 09:56:29 -07002386 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08002387 * @return The timeout for the given admin or the minimum of all timeouts
2388 */
Robin Lee25e26452015-06-02 09:56:29 -07002389 public long getPasswordExpirationTimeout(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08002390 if (mService != null) {
2391 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002392 return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08002393 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002394 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08002395 }
2396 }
2397 return 0;
2398 }
2399
2400 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002401 * Get the current password expiration time for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01002402 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00002403 * a separate challenge are not taken into account. If admin is {@code null}, then a composite
2404 * of all expiration times is returned - which will be the minimum of all of them.
2405 *
2406 * <p>This method can be called on the {@link DevicePolicyManager} instance
2407 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2408 * the password expiration for the parent profile.
Jim Millera4e28d12010-11-08 16:15:47 -08002409 *
Robin Lee25e26452015-06-02 09:56:29 -07002410 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002411 * @return The password expiration time, in milliseconds since epoch.
Jim Millera4e28d12010-11-08 16:15:47 -08002412 */
Robin Lee25e26452015-06-02 09:56:29 -07002413 public long getPasswordExpiration(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08002414 if (mService != null) {
2415 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002416 return mService.getPasswordExpiration(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08002417 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002418 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08002419 }
2420 }
2421 return 0;
2422 }
2423
2424 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002425 * Retrieve the current password history length for a particular admin or all admins that
Rubin Xud3609d42016-07-13 18:32:57 +01002426 * set restrictions on this user and its participating profiles. Restrictions on profiles that
Esteban Talaverac1c83592016-02-17 17:56:15 +00002427 * have a separate challenge are not taken into account.
2428 *
2429 * <p>This method can be called on the {@link DevicePolicyManager} instance
2430 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2431 * restrictions on the parent profile.
2432 *
Robin Lee25e26452015-06-02 09:56:29 -07002433 * @param admin The name of the admin component to check, or {@code null} to aggregate
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002434 * all admins.
2435 * @return The length of the password history
2436 */
Robin Lee25e26452015-06-02 09:56:29 -07002437 public int getPasswordHistoryLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002438 return getPasswordHistoryLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002439 }
2440
2441 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002442 public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002443 if (mService != null) {
2444 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002445 return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002446 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002447 throw e.rethrowFromSystemServer();
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002448 }
2449 }
2450 return 0;
2451 }
2452
Dianne Hackbornd6847842010-01-12 18:14:19 -08002453 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08002454 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08002455 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08002456 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08002457 * @return Returns the maximum length that the user can enter.
2458 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08002459 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08002460 // Kind-of arbitrary.
2461 return 16;
2462 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002463
Dianne Hackborn254cb442010-01-27 19:23:59 -08002464 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002465 * Determine whether the current password the user has set is sufficient to meet the policy
2466 * requirements (e.g. quality, minimum length) that have been requested by the admins of this
2467 * user and its participating profiles. Restrictions on profiles that have a separate challenge
Andrew Scull5daf2732016-11-14 15:02:45 +00002468 * are not taken into account. The user must be unlocked in order to perform the check.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002469 * <p>
2470 * The calling device admin must have requested
2471 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2472 * not, a security exception will be thrown.
2473 * <p>
2474 * This method can be called on the {@link DevicePolicyManager} instance returned by
2475 * {@link #getParentProfileInstance(ComponentName)} in order to determine if the password set on
2476 * the parent profile is sufficient.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002477 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01002478 * @return Returns true if the password meets the current requirements, else false.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002479 * @throws SecurityException if the calling application does not own an active administrator
2480 * that uses {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Andrew Scull5daf2732016-11-14 15:02:45 +00002481 * @throws InvalidStateException if the user is not unlocked.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002482 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002483 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002484 if (mService != null) {
2485 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00002486 return mService.isActivePasswordSufficient(myUserId(), mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002487 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002488 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002489 }
2490 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002491 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08002492 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002493
Dianne Hackbornd6847842010-01-12 18:14:19 -08002494 /**
Clara Bayarrid7693912016-01-22 17:26:31 +00002495 * Determine whether the current profile password the user has set is sufficient
Esteban Talaverac1c83592016-02-17 17:56:15 +00002496 * to meet the policy requirements (e.g. quality, minimum length) that have been
Clara Bayarrid7693912016-01-22 17:26:31 +00002497 * requested by the admins of the parent user and its profiles.
2498 *
2499 * @param userHandle the userId of the profile to check the password for.
2500 * @return Returns true if the password would meet the current requirements, else false.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002501 * @throws SecurityException if {@code userHandle} is not a managed profile.
Clara Bayarrid7693912016-01-22 17:26:31 +00002502 * @hide
2503 */
2504 public boolean isProfileActivePasswordSufficientForParent(int userHandle) {
2505 if (mService != null) {
2506 try {
2507 return mService.isProfileActivePasswordSufficientForParent(userHandle);
2508 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002509 throw e.rethrowFromSystemServer();
Clara Bayarrid7693912016-01-22 17:26:31 +00002510 }
2511 }
2512 return false;
2513 }
2514
2515 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002516 * Retrieve the number of times the user has failed at entering a password since that last
2517 * successful password entry.
2518 * <p>
2519 * This method can be called on the {@link DevicePolicyManager} instance returned by
2520 * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the number of failed
2521 * password attemts for the parent user.
2522 * <p>
2523 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN}
2524 * to be able to call this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002525 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002526 * @return The number of times user has entered an incorrect password since the last correct
2527 * password entry.
2528 * @throws SecurityException if the calling application does not own an active administrator
2529 * that uses {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002530 */
2531 public int getCurrentFailedPasswordAttempts() {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00002532 return getCurrentFailedPasswordAttempts(myUserId());
2533 }
2534
2535 /**
2536 * Retrieve the number of times the given user has failed at entering a
2537 * password since that last successful password entry.
2538 *
2539 * <p>The calling device admin must have requested
2540 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call this method; if it has
2541 * not and it is not the system uid, a security exception will be thrown.
2542 *
2543 * @hide
2544 */
2545 public int getCurrentFailedPasswordAttempts(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002546 if (mService != null) {
2547 try {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00002548 return mService.getCurrentFailedPasswordAttempts(userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002549 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002550 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002551 }
2552 }
2553 return -1;
2554 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002555
2556 /**
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002557 * Queries whether {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002558 *
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002559 * @return true if RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002560 * @hide
2561 */
2562 public boolean getDoNotAskCredentialsOnBoot() {
2563 if (mService != null) {
2564 try {
2565 return mService.getDoNotAskCredentialsOnBoot();
2566 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002567 throw e.rethrowFromSystemServer();
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002568 }
2569 }
2570 return false;
2571 }
2572
2573 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002574 * Setting this to a value greater than zero enables a built-in policy that will perform a
2575 * device or profile wipe after too many incorrect device-unlock passwords have been entered.
2576 * This built-in policy combines watching for failed passwords and wiping the device, and
2577 * requires that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002578 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002579 * <p>
2580 * To implement any other policy (e.g. wiping data for a particular application only, erasing or
2581 * revoking credentials, or reporting the failure to a server), you should implement
2582 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} instead. Do not
2583 * use this API, because if the maximum count is reached, the device or profile will be wiped
2584 * immediately, and your callback will not be invoked.
2585 * <p>
2586 * This method can be called on the {@link DevicePolicyManager} instance returned by
2587 * {@link #getParentProfileInstance(ComponentName)} in order to set a value on the parent
2588 * profile.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002589 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002590 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002591 * @param num The number of failed password attempts at which point the device or profile will
2592 * be wiped.
2593 * @throws SecurityException if {@code admin} is not an active administrator or does not use
2594 * both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
2595 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002596 */
Robin Lee25e26452015-06-02 09:56:29 -07002597 public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002598 if (mService != null) {
2599 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002600 mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002601 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002602 throw e.rethrowFromSystemServer();
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002603 }
2604 }
2605 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002606
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002607 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002608 * Retrieve the current maximum number of login attempts that are allowed before the device
Rubin Xud3609d42016-07-13 18:32:57 +01002609 * or profile is wiped, for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002610 * and its participating profiles. Restrictions on profiles that have a separate challenge are
2611 * not taken into account.
2612 *
2613 * <p>This method can be called on the {@link DevicePolicyManager} instance
2614 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2615 * the value for the parent profile.
2616 *
Robin Lee25e26452015-06-02 09:56:29 -07002617 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002618 * all admins.
2619 */
Robin Lee25e26452015-06-02 09:56:29 -07002620 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002621 return getMaximumFailedPasswordsForWipe(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002622 }
2623
2624 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002625 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08002626 if (mService != null) {
2627 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002628 return mService.getMaximumFailedPasswordsForWipe(
2629 admin, userHandle, mParentInstance);
Dianne Hackborn254cb442010-01-27 19:23:59 -08002630 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002631 throw e.rethrowFromSystemServer();
Dianne Hackborn254cb442010-01-27 19:23:59 -08002632 }
2633 }
2634 return 0;
2635 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002636
Dianne Hackborn254cb442010-01-27 19:23:59 -08002637 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002638 * Returns the profile with the smallest maximum failed passwords for wipe,
2639 * for the given user. So for primary user, it might return the primary or
2640 * a managed profile. For a secondary user, it would be the same as the
2641 * user passed in.
2642 * @hide Used only by Keyguard
2643 */
2644 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
2645 if (mService != null) {
2646 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002647 return mService.getProfileWithMinimumFailedPasswordsForWipe(
2648 userHandle, mParentInstance);
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002649 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002650 throw e.rethrowFromSystemServer();
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002651 }
2652 }
2653 return UserHandle.USER_NULL;
2654 }
2655
2656 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002657 * Flag for {@link #resetPassword}: don't allow other admins to change
2658 * the password again until the user has entered it.
2659 */
2660 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002661
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002662 /**
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002663 * Flag for {@link #resetPassword}: don't ask for user credentials on device boot.
2664 * If the flag is set, the device can be booted without asking for user password.
2665 * The absence of this flag does not change the current boot requirements. This flag
2666 * can be set by the device owner only. If the app is not the device owner, the flag
2667 * is ignored. Once the flag is set, it cannot be reverted back without resetting the
2668 * device to factory defaults.
2669 */
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002670 public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002;
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002671
2672 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002673 * Force a new device unlock password (the password needed to access the entire device, not for
2674 * individual accounts) on the user. This takes effect immediately.
2675 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002676 * <em>Note: This API has been limited as of {@link android.os.Build.VERSION_CODES#N} for
Makoto Onuki70f929e2015-11-11 12:40:15 -08002677 * device admins that are not device owner and not profile owner.
2678 * The password can now only be changed if there is currently no password set. Device owner
Ricky Wai977ade22016-05-24 15:02:41 +01002679 * and profile owner can still do this when user is unlocked and does not have a managed
2680 * profile.</em>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002681 * <p>
2682 * The given password must be sufficient for the current password quality and length constraints
2683 * as returned by {@link #getPasswordQuality(ComponentName)} and
2684 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then
2685 * it will be rejected and false returned. Note that the password may be a stronger quality
2686 * (containing alphanumeric characters when the requested quality is only numeric), in which
2687 * case the currently active quality will be increased to match.
2688 * <p>
2689 * Calling with a null or empty password will clear any existing PIN, pattern or password if the
Robin Leece5c4002016-03-23 17:05:03 +00002690 * current password constraints allow it. <em>Note: This will not work in
2691 * {@link android.os.Build.VERSION_CODES#N} and later for managed profiles, or for device admins
2692 * that are not device owner or profile owner. Once set, the password cannot be changed to null
2693 * or empty except by these admins.</em>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002694 * <p>
2695 * The calling device admin must have requested
2696 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call this method; if it has
2697 * not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002698 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01002699 * @param password The new password for the user. Null or empty clears the password.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002700 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002701 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
2702 * @return Returns true if the password was applied, or false if it is not acceptable for the
2703 * current constraints or if the user has not been decrypted yet.
2704 * @throws SecurityException if the calling application does not own an active administrator
2705 * that uses {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD}
Ricky Wai977ade22016-05-24 15:02:41 +01002706 * @throws IllegalStateException if the calling user is locked or has a managed profile.
Andrew Scull3f81f4e2016-07-29 16:29:58 +01002707 * @throws IllegalArgumentException if the password does not meet system requirements.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002708 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002709 public boolean resetPassword(String password, int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002710 throwIfParentInstance("resetPassword");
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002711 if (mService != null) {
2712 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002713 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002714 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002715 throw e.rethrowFromSystemServer();
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002716 }
2717 }
2718 return false;
2719 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002720
Dianne Hackbornd6847842010-01-12 18:14:19 -08002721 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002722 * Called by an application that is administering the device to set the maximum time for user
2723 * activity until the device will lock. This limits the length that the user can set. It takes
2724 * effect immediately.
2725 * <p>
2726 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
2727 * to be able to call this method; if it has not, a security exception will be thrown.
2728 * <p>
2729 * This method can be called on the {@link DevicePolicyManager} instance returned by
2730 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2731 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002732 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002733 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002734 * @param timeMs The new desired maximum time to lock in milliseconds. A value of 0 means there
2735 * is no restriction.
2736 * @throws SecurityException if {@code admin} is not an active administrator or it does not use
2737 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002738 */
Robin Lee25e26452015-06-02 09:56:29 -07002739 public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002740 if (mService != null) {
2741 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002742 mService.setMaximumTimeToLock(admin, timeMs, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002743 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002744 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002745 }
2746 }
2747 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002748
Dianne Hackbornd6847842010-01-12 18:14:19 -08002749 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002750 * Retrieve the current maximum time to unlock for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01002751 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00002752 * a separate challenge are not taken into account.
2753 *
2754 * <p>This method can be called on the {@link DevicePolicyManager} instance
2755 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2756 * restrictions on the parent profile.
2757 *
Robin Lee25e26452015-06-02 09:56:29 -07002758 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002759 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07002760 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07002761 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002762 */
Robin Lee25e26452015-06-02 09:56:29 -07002763 public long getMaximumTimeToLock(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002764 return getMaximumTimeToLock(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002765 }
2766
2767 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002768 public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002769 if (mService != null) {
2770 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002771 return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002772 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002773 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002774 }
2775 }
2776 return 0;
2777 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002778
Dianne Hackbornd6847842010-01-12 18:14:19 -08002779 /**
Ricky Wai035e9242016-03-18 16:43:31 +00002780 * Returns maximum time to lock that applied by all profiles in this user. We do this because we
2781 * do not have a separate timeout to lock for work challenge only.
2782 *
2783 * @hide
2784 */
2785 public long getMaximumTimeToLockForUserAndProfiles(int userHandle) {
2786 if (mService != null) {
2787 try {
2788 return mService.getMaximumTimeToLockForUserAndProfiles(userHandle);
2789 } catch (RemoteException e) {
2790 throw e.rethrowFromSystemServer();
2791 }
2792 }
2793 return 0;
2794 }
2795
2796 /**
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002797 * Called by a device/profile owner to set the timeout after which unlocking with secondary, non
2798 * strong auth (e.g. fingerprint, trust agents) times out, i.e. the user has to use a strong
2799 * authentication method like password, pin or pattern.
2800 *
2801 * <p>This timeout is used internally to reset the timer to require strong auth again after
2802 * specified timeout each time it has been successfully used.
2803 *
2804 * <p>Fingerprint can also be disabled altogether using {@link #KEYGUARD_DISABLE_FINGERPRINT}.
2805 *
2806 * <p>Trust agents can also be disabled altogether using {@link #KEYGUARD_DISABLE_TRUST_AGENTS}.
2807 *
2808 * <p>The calling device admin must be a device or profile owner. If it is not,
2809 * a {@link SecurityException} will be thrown.
2810 *
Michal Karpinski943aabd2016-10-06 11:09:25 +01002811 * <p>The calling device admin can verify the value it has set by calling
2812 * {@link #getRequiredStrongAuthTimeout(ComponentName)} and passing in its instance.
2813 *
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002814 * <p>This method can be called on the {@link DevicePolicyManager} instance returned by
2815 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2816 * profile.
2817 *
2818 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2819 * @param timeoutMs The new timeout, after which the user will have to unlock with strong
Michal Karpinski943aabd2016-10-06 11:09:25 +01002820 * authentication method. A value of 0 means the admin is not participating in
2821 * controlling the timeout.
2822 * The minimum and maximum timeouts are platform-defined and are typically 1 hour and
2823 * 72 hours, respectively. Though discouraged, the admin may choose to require strong
2824 * auth at all times using {@link #KEYGUARD_DISABLE_FINGERPRINT} and/or
2825 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002826 *
2827 * @throws SecurityException if {@code admin} is not a device or profile owner.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002828 */
2829 public void setRequiredStrongAuthTimeout(@NonNull ComponentName admin,
2830 long timeoutMs) {
2831 if (mService != null) {
2832 try {
2833 mService.setRequiredStrongAuthTimeout(admin, timeoutMs, mParentInstance);
2834 } catch (RemoteException e) {
2835 throw e.rethrowFromSystemServer();
2836 }
2837 }
2838 }
2839
2840 /**
2841 * Determine for how long the user will be able to use secondary, non strong auth for
2842 * authentication, since last strong method authentication (password, pin or pattern) was used.
2843 * After the returned timeout the user is required to use strong authentication method.
2844 *
2845 * <p>This method can be called on the {@link DevicePolicyManager} instance
2846 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2847 * restrictions on the parent profile.
2848 *
2849 * @param admin The name of the admin component to check, or {@code null} to aggregate
2850 * accross all participating admins.
Michal Karpinski943aabd2016-10-06 11:09:25 +01002851 * @return The timeout or 0 if not configured for the provided admin.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002852 */
2853 public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin) {
2854 return getRequiredStrongAuthTimeout(admin, myUserId());
2855 }
2856
2857 /** @hide per-user version */
2858 public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin, @UserIdInt int userId) {
2859 if (mService != null) {
2860 try {
2861 return mService.getRequiredStrongAuthTimeout(admin, userId, mParentInstance);
2862 } catch (RemoteException e) {
2863 throw e.rethrowFromSystemServer();
2864 }
2865 }
2866 return DEFAULT_STRONG_AUTH_TIMEOUT_MS;
2867 }
2868
2869 /**
Andrew Scull85a63bc2016-10-24 13:47:47 +01002870 * Flag for {@link #lockNow(int)}: also evict the user's credential encryption key from the
2871 * keyring. The user's credential will need to be entered again in order to derive the
2872 * credential encryption key that will be stored back in the keyring for future use.
2873 * <p>
2874 * This flag can only be used by a profile owner when locking a managed profile on an FBE
2875 * device.
2876 * <p>
2877 * In order to secure user data, the user will be stopped and restarted so apps should wait
2878 * until they are next run to perform further actions.
2879 */
2880 public static final int FLAG_EVICT_CE_KEY = 1;
2881
2882 /** @hide */
2883 @Retention(RetentionPolicy.SOURCE)
2884 @IntDef(flag=true, value={FLAG_EVICT_CE_KEY})
2885 public @interface LockNowFlag {}
2886
2887 /**
2888 * Make the device lock immediately, as if the lock screen timeout has expired at the point of
2889 * this call.
2890 * <p>
2891 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
2892 * to be able to call this method; if it has not, a security exception will be thrown.
2893 * <p>
2894 * This method can be called on the {@link DevicePolicyManager} instance returned by
2895 * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile.
2896 * <p>
2897 * Equivalent to calling {@link #lockNow(int)} with no flags.
2898 *
2899 * @throws SecurityException if the calling application does not own an active administrator
2900 * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
2901 */
2902 public void lockNow() {
2903 lockNow(0);
2904 }
2905
2906 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002907 * Make the device lock immediately, as if the lock screen timeout has expired at the point of
2908 * this call.
2909 * <p>
2910 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
2911 * to be able to call this method; if it has not, a security exception will be thrown.
2912 * <p>
2913 * This method can be called on the {@link DevicePolicyManager} instance returned by
2914 * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002915 *
Andrew Scull85a63bc2016-10-24 13:47:47 +01002916 * @param flags May be 0 or {@link #FLAG_EVICT_CE_KEY}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002917 * @throws SecurityException if the calling application does not own an active administrator
Andrew Scull85a63bc2016-10-24 13:47:47 +01002918 * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} or the
2919 * {@link #FLAG_EVICT_CE_KEY} flag is passed by an application that is not a profile
2920 * owner of a managed profile.
2921 * @throws IllegalArgumentException if the {@link #FLAG_EVICT_CE_KEY} flag is passed when
2922 * locking the parent profile.
2923 * @throws UnsupportedOperationException if the {@link #FLAG_EVICT_CE_KEY} flag is passed on a
2924 * non-FBE device.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002925 */
Andrew Scull85a63bc2016-10-24 13:47:47 +01002926 public void lockNow(@LockNowFlag int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002927 if (mService != null) {
2928 try {
Andrew Scull85a63bc2016-10-24 13:47:47 +01002929 mService.lockNow(flags, mParentInstance);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002930 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002931 throw e.rethrowFromSystemServer();
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002932 }
2933 }
2934 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002935
Dianne Hackbornd6847842010-01-12 18:14:19 -08002936 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07002937 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002938 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07002939 */
2940 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
2941
2942 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002943 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
2944 * data.
2945 *
Paul Crowley2934b262014-12-02 11:21:13 +00002946 * <p>This flag may only be set by device owner admins; if it is set by
2947 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002948 */
2949 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
2950
2951 /**
Suprabh Shukla556b05a2016-08-10 15:49:24 -07002952 * Ask that all user data be wiped. If called as a secondary user, the user will be removed and
2953 * other users will remain unaffected. Calling from the primary user will cause the device to
2954 * reboot, erasing all device data - including all the secondary users and their data - while
2955 * booting up.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002956 * <p>
2957 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to
2958 * be able to call this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002959 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002960 * @param flags Bit mask of additional options: currently supported flags are
2961 * {@link #WIPE_EXTERNAL_STORAGE} and {@link #WIPE_RESET_PROTECTION_DATA}.
2962 * @throws SecurityException if the calling application does not own an active administrator
2963 * that uses {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002964 */
2965 public void wipeData(int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002966 throwIfParentInstance("wipeData");
Dianne Hackbornd6847842010-01-12 18:14:19 -08002967 if (mService != null) {
2968 try {
Makoto Onuki70f929e2015-11-11 12:40:15 -08002969 mService.wipeData(flags);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002970 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002971 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002972 }
2973 }
2974 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002975
Dianne Hackbornd6847842010-01-12 18:14:19 -08002976 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07002977 * Called by an application that is administering the device to set the
2978 * global proxy and exclusion list.
2979 * <p>
2980 * The calling device admin must have requested
2981 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
2982 * this method; if it has not, a security exception will be thrown.
2983 * Only the first device admin can set the proxy. If a second admin attempts
2984 * to set the proxy, the {@link ComponentName} of the admin originally setting the
Robin Lee25e26452015-06-02 09:56:29 -07002985 * proxy will be returned. If successful in setting the proxy, {@code null} will
Oscar Montemayor69238c62010-08-03 10:51:06 -07002986 * be returned.
2987 * The method can be called repeatedly by the device admin alrady setting the
2988 * proxy to update the proxy and exclusion list.
2989 *
Robin Lee25e26452015-06-02 09:56:29 -07002990 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Oscar Montemayor69238c62010-08-03 10:51:06 -07002991 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
2992 * Pass Proxy.NO_PROXY to reset the proxy.
2993 * @param exclusionList a list of domains to be excluded from the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07002994 * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName}
2995 * of the device admin that sets the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08002996 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07002997 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07002998 public @Nullable ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec,
Oscar Montemayor69238c62010-08-03 10:51:06 -07002999 List<String> exclusionList ) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003000 throwIfParentInstance("setGlobalProxy");
Oscar Montemayor69238c62010-08-03 10:51:06 -07003001 if (proxySpec == null) {
3002 throw new NullPointerException();
3003 }
3004 if (mService != null) {
3005 try {
3006 String hostSpec;
3007 String exclSpec;
3008 if (proxySpec.equals(Proxy.NO_PROXY)) {
3009 hostSpec = null;
3010 exclSpec = null;
3011 } else {
3012 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
3013 throw new IllegalArgumentException();
3014 }
3015 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
3016 String hostName = sa.getHostName();
3017 int port = sa.getPort();
3018 StringBuilder hostBuilder = new StringBuilder();
3019 hostSpec = hostBuilder.append(hostName)
3020 .append(":").append(Integer.toString(port)).toString();
3021 if (exclusionList == null) {
3022 exclSpec = "";
3023 } else {
3024 StringBuilder listBuilder = new StringBuilder();
3025 boolean firstDomain = true;
3026 for (String exclDomain : exclusionList) {
3027 if (!firstDomain) {
3028 listBuilder = listBuilder.append(",");
3029 } else {
3030 firstDomain = false;
3031 }
3032 listBuilder = listBuilder.append(exclDomain.trim());
3033 }
3034 exclSpec = listBuilder.toString();
3035 }
Yuhao Zheng90704842014-02-28 17:22:45 -08003036 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
3037 != android.net.Proxy.PROXY_VALID)
3038 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07003039 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003040 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07003041 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003042 throw e.rethrowFromSystemServer();
Oscar Montemayor69238c62010-08-03 10:51:06 -07003043 }
3044 }
3045 return null;
3046 }
3047
3048 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003049 * Set a network-independent global HTTP proxy. This is not normally what you want for typical
3050 * HTTP proxies - they are generally network dependent. However if you're doing something
3051 * unusual like general internal filtering this may be useful. On a private network where the
3052 * proxy is not accessible, you may break HTTP using this.
3053 * <p>
3054 * This method requires the caller to be the device owner.
3055 * <p>
3056 * This proxy is only a recommendation and it is possible that some apps will ignore it.
Jason Monk03bc9912014-05-13 09:44:57 -04003057 *
Jason Monk03bc9912014-05-13 09:44:57 -04003058 * @see ProxyInfo
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003059 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3060 * @param proxyInfo The a {@link ProxyInfo} object defining the new global HTTP proxy. A
3061 * {@code null} value will clear the global HTTP proxy.
3062 * @throws SecurityException if {@code admin} is not the device owner.
Jason Monk03bc9912014-05-13 09:44:57 -04003063 */
Robin Lee25e26452015-06-02 09:56:29 -07003064 public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo
3065 proxyInfo) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003066 throwIfParentInstance("setRecommendedGlobalProxy");
Jason Monk03bc9912014-05-13 09:44:57 -04003067 if (mService != null) {
3068 try {
3069 mService.setRecommendedGlobalProxy(admin, proxyInfo);
3070 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003071 throw e.rethrowFromSystemServer();
Jason Monk03bc9912014-05-13 09:44:57 -04003072 }
3073 }
3074 }
3075
3076 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07003077 * Returns the component name setting the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07003078 * @return ComponentName object of the device admin that set the global proxy, or {@code null}
3079 * if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08003080 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07003081 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003082 public @Nullable ComponentName getGlobalProxyAdmin() {
Oscar Montemayor69238c62010-08-03 10:51:06 -07003083 if (mService != null) {
3084 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003085 return mService.getGlobalProxyAdmin(myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07003086 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003087 throw e.rethrowFromSystemServer();
Oscar Montemayor69238c62010-08-03 10:51:06 -07003088 }
3089 }
3090 return null;
3091 }
3092
3093 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08003094 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003095 * indicating that encryption is not supported.
3096 */
3097 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
3098
3099 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08003100 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003101 * indicating that encryption is supported, but is not currently active.
3102 */
3103 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
3104
3105 /**
Robin Lee3795fb02015-02-16 14:17:23 +00003106 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003107 * indicating that encryption is not currently active, but is currently
3108 * being activated. This is only reported by devices that support
3109 * encryption of data and only when the storage is currently
3110 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
3111 * to become encrypted will never return this value.
3112 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08003113 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003114
3115 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08003116 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003117 * indicating that encryption is active.
Amith Yamasani75db1252016-07-11 14:41:01 -07003118 * <p>
3119 * Also see {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003120 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08003121 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003122
3123 /**
Robin Lee3795fb02015-02-16 14:17:23 +00003124 * Result code for {@link #getStorageEncryptionStatus}:
3125 * indicating that encryption is active, but an encryption key has not
3126 * been set by the user.
3127 */
3128 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
3129
3130 /**
Makoto Onukid4c9e542016-02-25 18:17:30 -08003131 * Result code for {@link #getStorageEncryptionStatus}:
Amith Yamasani75db1252016-07-11 14:41:01 -07003132 * indicating that encryption is active and the encryption key is tied to the user or profile.
3133 * <p>
3134 * This value is only returned to apps targeting API level 24 and above. For apps targeting
3135 * earlier API levels, {@link #ENCRYPTION_STATUS_ACTIVE} is returned, even if the
3136 * encryption key is specific to the user or profile.
Makoto Onukid4c9e542016-02-25 18:17:30 -08003137 */
3138 public static final int ENCRYPTION_STATUS_ACTIVE_PER_USER = 5;
3139
3140 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003141 * Activity action: begin the process of encrypting data on the device. This activity should
3142 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
3143 * After resuming from this activity, use {@link #getStorageEncryption}
3144 * to check encryption status. However, on some devices this activity may never return, as
3145 * it may trigger a reboot and in some cases a complete data wipe of the device.
3146 */
3147 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
3148 public static final String ACTION_START_ENCRYPTION
3149 = "android.app.action.START_ENCRYPTION";
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003150 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07003151 * Widgets are enabled in keyguard
3152 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07003153 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07003154
3155 /**
Jim Miller50e62182014-04-23 17:25:00 -07003156 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07003157 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07003158 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
3159
3160 /**
3161 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
3162 */
3163 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
3164
3165 /**
Jim Miller50e62182014-04-23 17:25:00 -07003166 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
3167 */
3168 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
3169
3170 /**
3171 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
3172 */
3173 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
3174
3175 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02003176 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07003177 * (e.g. PIN/Pattern/Password).
3178 */
3179 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
3180
3181 /**
Jim Miller06e34502014-07-17 14:46:05 -07003182 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
3183 */
3184 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
3185
3186 /**
Adrian Roos7f06eed2016-02-05 15:21:02 -08003187 * Disable text entry into notifications on secure keyguard screens (e.g. PIN/Pattern/Password).
3188 */
3189 public static final int KEYGUARD_DISABLE_REMOTE_INPUT = 1 << 6;
3190
3191 /**
Jim Miller35207742012-11-02 15:33:20 -07003192 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07003193 */
3194 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07003195
3196 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003197 * Called by an application that is administering the device to request that the storage system
3198 * be encrypted.
3199 * <p>
3200 * When multiple device administrators attempt to control device encryption, the most secure,
3201 * supported setting will always be used. If any device administrator requests device
3202 * encryption, it will be enabled; Conversely, if a device administrator attempts to disable
3203 * device encryption while another device administrator has enabled it, the call to disable will
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003204 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003205 * <p>
3206 * This policy controls encryption of the secure (application data) storage area. Data written
3207 * to other storage areas may or may not be encrypted, and this policy does not require or
3208 * control the encryption of any other storage areas. There is one exception: If
3209 * {@link android.os.Environment#isExternalStorageEmulated()} is {@code true}, then the
3210 * directory returned by {@link android.os.Environment#getExternalStorageDirectory()} must be
3211 * written to disk within the encrypted storage area.
3212 * <p>
3213 * Important Note: On some devices, it is possible to encrypt storage without requiring the user
3214 * to create a device PIN or Password. In this case, the storage is encrypted, but the
3215 * encryption key may not be fully secured. For maximum security, the administrator should also
3216 * require (and check for) a pattern, PIN, or password.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003217 *
3218 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3219 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08003220 * @return the new request status (for all active admins) - will be one of
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003221 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
3222 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
3223 * {@link #getStorageEncryptionStatus()} to query the actual device state.
3224 * @throws SecurityException if {@code admin} is not an active administrator or does not use
3225 * {@link DeviceAdminInfo#USES_ENCRYPTED_STORAGE}
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003226 */
Robin Lee25e26452015-06-02 09:56:29 -07003227 public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003228 throwIfParentInstance("setStorageEncryption");
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003229 if (mService != null) {
3230 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003231 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003232 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003233 throw e.rethrowFromSystemServer();
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003234 }
3235 }
3236 return ENCRYPTION_STATUS_UNSUPPORTED;
3237 }
3238
3239 /**
3240 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08003241 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003242 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08003243 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
3244 * this will return the requested encryption setting as an aggregate of all active
3245 * administrators.
3246 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003247 */
Robin Lee25e26452015-06-02 09:56:29 -07003248 public boolean getStorageEncryption(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003249 throwIfParentInstance("getStorageEncryption");
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003250 if (mService != null) {
3251 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003252 return mService.getStorageEncryption(admin, myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003253 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003254 throw e.rethrowFromSystemServer();
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003255 }
3256 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08003257 return false;
3258 }
3259
3260 /**
3261 * Called by an application that is administering the device to
3262 * determine the current encryption status of the device.
Amith Yamasani75db1252016-07-11 14:41:01 -07003263 * <p>
Andy Stadler22dbfda2011-01-17 12:47:31 -08003264 * Depending on the returned status code, the caller may proceed in different
3265 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
3266 * storage system does not support encryption. If the
3267 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
3268 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00003269 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
3270 * storage system has enabled encryption but no password is set so further action
Amith Yamasani75db1252016-07-11 14:41:01 -07003271 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING},
3272 * {@link #ENCRYPTION_STATUS_ACTIVE} or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER},
3273 * no further action is required.
Andy Stadler22dbfda2011-01-17 12:47:31 -08003274 *
Robin Lee7e678712014-07-24 16:41:31 +01003275 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08003276 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00003277 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
Amith Yamasani75db1252016-07-11 14:41:01 -07003278 * {@link #ENCRYPTION_STATUS_ACTIVE}, or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08003279 */
3280 public int getStorageEncryptionStatus() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003281 throwIfParentInstance("getStorageEncryptionStatus");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003282 return getStorageEncryptionStatus(myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003283 }
3284
3285 /** @hide per-user version */
3286 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08003287 if (mService != null) {
3288 try {
Makoto Onukid4c9e542016-02-25 18:17:30 -08003289 return mService.getStorageEncryptionStatus(mContext.getPackageName(), userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08003290 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003291 throw e.rethrowFromSystemServer();
Andy Stadler22dbfda2011-01-17 12:47:31 -08003292 }
3293 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003294 return ENCRYPTION_STATUS_UNSUPPORTED;
3295 }
3296
3297 /**
Robin Lee2f7e1e42016-03-21 10:50:01 +00003298 * Mark a CA certificate as approved by the device user. This means that they have been notified
3299 * of the installation, were made aware of the risks, viewed the certificate and still wanted to
3300 * keep the certificate on the device.
3301 *
3302 * Calling with {@param approval} as {@code true} will cancel any ongoing warnings related to
3303 * this certificate.
3304 *
3305 * @hide
3306 */
3307 public boolean approveCaCert(String alias, int userHandle, boolean approval) {
3308 if (mService != null) {
3309 try {
3310 return mService.approveCaCert(alias, userHandle, approval);
3311 } catch (RemoteException e) {
3312 throw e.rethrowFromSystemServer();
3313 }
3314 }
3315 return false;
3316 }
3317
3318 /**
3319 * Check whether a CA certificate has been approved by the device user.
3320 *
3321 * @hide
3322 */
3323 public boolean isCaCertApproved(String alias, int userHandle) {
3324 if (mService != null) {
3325 try {
3326 return mService.isCaCertApproved(alias, userHandle);
3327 } catch (RemoteException e) {
3328 throw e.rethrowFromSystemServer();
3329 }
3330 }
3331 return false;
3332 }
3333
3334 /**
Robin Lee7e678712014-07-24 16:41:31 +01003335 * Installs the given certificate as a user CA.
3336 *
Edman Anjosf9946772016-11-28 16:35:15 +01003337 * The caller must be a profile or device owner on that user, or a delegate package given the
3338 * {@link #DELEGATION_CERT_INSTALL} scope via {@link #setDelegatedScopes}; otherwise a
3339 * security exception will be thrown.
3340 *
Robin Lee25e26452015-06-02 09:56:29 -07003341 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3342 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003343 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04003344 *
3345 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01003346 * interrupted, true otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003347 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3348 * owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003349 * @see #setDelegatedScopes
3350 * @see #DELEGATION_CERT_INSTALL
Maggie Benthallda51e682013-08-08 22:35:44 -04003351 */
Robin Lee25e26452015-06-02 09:56:29 -07003352 public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003353 throwIfParentInstance("installCaCert");
Maggie Benthallda51e682013-08-08 22:35:44 -04003354 if (mService != null) {
3355 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003356 return mService.installCaCert(admin, mContext.getPackageName(), certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04003357 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003358 throw e.rethrowFromSystemServer();
Maggie Benthallda51e682013-08-08 22:35:44 -04003359 }
3360 }
3361 return false;
3362 }
3363
3364 /**
Robin Lee7e678712014-07-24 16:41:31 +01003365 * Uninstalls the given certificate from trusted user CAs, if present.
3366 *
Edman Anjosf9946772016-11-28 16:35:15 +01003367 * The caller must be a profile or device owner on that user, or a delegate package given the
3368 * {@link #DELEGATION_CERT_INSTALL} scope via {@link #setDelegatedScopes}; otherwise a
3369 * security exception will be thrown.
3370 *
Robin Lee25e26452015-06-02 09:56:29 -07003371 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3372 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003373 * @param certBuffer encoded form of the certificate to remove.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003374 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3375 * owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003376 * @see #setDelegatedScopes
3377 * @see #DELEGATION_CERT_INSTALL
Maggie Benthallda51e682013-08-08 22:35:44 -04003378 */
Robin Lee25e26452015-06-02 09:56:29 -07003379 public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003380 throwIfParentInstance("uninstallCaCert");
Maggie Benthallda51e682013-08-08 22:35:44 -04003381 if (mService != null) {
3382 try {
Robin Lee306fe082014-06-19 14:04:24 +00003383 final String alias = getCaCertAlias(certBuffer);
Edman Anjosf9946772016-11-28 16:35:15 +01003384 mService.uninstallCaCerts(admin, mContext.getPackageName(), new String[] {alias});
Robin Lee306fe082014-06-19 14:04:24 +00003385 } catch (CertificateException e) {
3386 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04003387 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003388 throw e.rethrowFromSystemServer();
Maggie Benthallda51e682013-08-08 22:35:44 -04003389 }
3390 }
3391 }
3392
3393 /**
Robin Lee7e678712014-07-24 16:41:31 +01003394 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
3395 * If a user has installed any certificates by other means than device policy these will be
3396 * included too.
3397 *
Robin Lee25e26452015-06-02 09:56:29 -07003398 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3399 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003400 * @return a List of byte[] arrays, each encoding one user CA certificate.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003401 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3402 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04003403 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003404 public @NonNull List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) {
3405 final List<byte[]> certs = new ArrayList<byte[]>();
Benjamin Franzbc33c822016-04-15 08:57:52 +01003406 throwIfParentInstance("getInstalledCaCerts");
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003407 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01003408 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003409 mService.enforceCanManageCaCerts(admin, mContext.getPackageName());
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003410 final TrustedCertificateStore certStore = new TrustedCertificateStore();
3411 for (String alias : certStore.userAliases()) {
3412 try {
3413 certs.add(certStore.getCertificate(alias).getEncoded());
3414 } catch (CertificateException ce) {
3415 Log.w(TAG, "Could not encode certificate: " + alias, ce);
3416 }
3417 }
3418 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003419 throw re.rethrowFromSystemServer();
Robin Lee7e678712014-07-24 16:41:31 +01003420 }
3421 }
3422 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04003423 }
3424
3425 /**
Robin Lee7e678712014-07-24 16:41:31 +01003426 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
3427 * means other than device policy will also be removed, except for system CA certificates.
3428 *
Robin Lee25e26452015-06-02 09:56:29 -07003429 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3430 * {@code null} if calling from a delegated certificate installer.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003431 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3432 * owner.
Robin Lee7e678712014-07-24 16:41:31 +01003433 */
Robin Lee25e26452015-06-02 09:56:29 -07003434 public void uninstallAllUserCaCerts(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003435 throwIfParentInstance("uninstallAllUserCaCerts");
Robin Lee7e678712014-07-24 16:41:31 +01003436 if (mService != null) {
Robin Lee83881bd2015-06-09 16:04:38 -07003437 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003438 mService.uninstallCaCerts(admin, mContext.getPackageName(),
3439 new TrustedCertificateStore().userAliases() .toArray(new String[0]));
Robin Lee83881bd2015-06-09 16:04:38 -07003440 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003441 throw re.rethrowFromSystemServer();
Robin Lee7e678712014-07-24 16:41:31 +01003442 }
3443 }
3444 }
3445
3446 /**
3447 * Returns whether this certificate is installed as a trusted CA.
3448 *
Robin Lee25e26452015-06-02 09:56:29 -07003449 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3450 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003451 * @param certBuffer encoded form of the certificate to look up.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003452 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3453 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04003454 */
Robin Lee25e26452015-06-02 09:56:29 -07003455 public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003456 throwIfParentInstance("hasCaCertInstalled");
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003457 if (mService != null) {
3458 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003459 mService.enforceCanManageCaCerts(admin, mContext.getPackageName());
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003460 return getCaCertAlias(certBuffer) != null;
3461 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003462 throw re.rethrowFromSystemServer();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003463 } catch (CertificateException ce) {
3464 Log.w(TAG, "Could not parse certificate", ce);
3465 }
Maggie Benthallda51e682013-08-08 22:35:44 -04003466 }
3467 return false;
3468 }
3469
3470 /**
Robin Leece3399f2016-02-24 12:08:32 +00003471 * Called by a device or profile owner, or delegated certificate installer, to install a
3472 * certificate and corresponding private key. All apps within the profile will be able to access
3473 * the certificate and use the private key, given direct user approval.
3474 *
3475 * <p>Access to the installed credentials will not be granted to the caller of this API without
3476 * direct user approval. This is for security - should a certificate installer become
3477 * compromised, certificates it had already installed will be protected.
3478 *
3479 * <p>If the installer must have access to the credentials, call
Rubin Xub4365912016-03-23 12:13:22 +00003480 * {@link #installKeyPair(ComponentName, PrivateKey, Certificate[], String, boolean)} instead.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003481 *
Robin Lee25e26452015-06-02 09:56:29 -07003482 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3483 * {@code null} if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003484 * @param privKey The private key to install.
3485 * @param cert The certificate to install.
3486 * @param alias The private key alias under which to install the certificate. If a certificate
3487 * with that alias already exists, it will be overwritten.
3488 * @return {@code true} if the keys were installed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003489 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3490 * owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003491 * @see #setDelegatedScopes
3492 * @see #DELEGATION_CERT_INSTALL
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003493 */
Robin Leefbc65642015-08-03 16:21:22 +01003494 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
3495 @NonNull Certificate cert, @NonNull String alias) {
Rubin Xub4365912016-03-23 12:13:22 +00003496 return installKeyPair(admin, privKey, new Certificate[] {cert}, alias, false);
Robin Leece3399f2016-02-24 12:08:32 +00003497 }
3498
3499 /**
3500 * Called by a device or profile owner, or delegated certificate installer, to install a
Rubin Xub4365912016-03-23 12:13:22 +00003501 * certificate chain and corresponding private key for the leaf certificate. All apps within the
3502 * profile will be able to access the certificate chain and use the private key, given direct
3503 * user approval.
Robin Leece3399f2016-02-24 12:08:32 +00003504 *
Robin Leea1b290e2016-03-09 14:38:36 +00003505 * <p>The caller of this API may grant itself access to the certificate and private key
3506 * immediately, without user approval. It is a best practice not to request this unless strictly
3507 * necessary since it opens up additional security vulnerabilities.
Robin Leece3399f2016-02-24 12:08:32 +00003508 *
3509 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Robin Leea1b290e2016-03-09 14:38:36 +00003510 * {@code null} if calling from a delegated certificate installer.
Robin Leece3399f2016-02-24 12:08:32 +00003511 * @param privKey The private key to install.
Rubin Xub4365912016-03-23 12:13:22 +00003512 * @param certs The certificate chain to install. The chain should start with the leaf
3513 * certificate and include the chain of trust in order. This will be returned by
3514 * {@link android.security.KeyChain#getCertificateChain}.
Robin Leece3399f2016-02-24 12:08:32 +00003515 * @param alias The private key alias under which to install the certificate. If a certificate
Robin Leea1b290e2016-03-09 14:38:36 +00003516 * with that alias already exists, it will be overwritten.
Robin Leece3399f2016-02-24 12:08:32 +00003517 * @param requestAccess {@code true} to request that the calling app be granted access to the
Robin Leea1b290e2016-03-09 14:38:36 +00003518 * credentials immediately. Otherwise, access to the credentials will be gated by user
3519 * approval.
Robin Leece3399f2016-02-24 12:08:32 +00003520 * @return {@code true} if the keys were installed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003521 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3522 * owner.
Rubin Xub4365912016-03-23 12:13:22 +00003523 * @see android.security.KeyChain#getCertificateChain
Edman Anjosf9946772016-11-28 16:35:15 +01003524 * @see #setDelegatedScopes
3525 * @see #DELEGATION_CERT_INSTALL
Robin Leece3399f2016-02-24 12:08:32 +00003526 */
3527 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
Rubin Xub4365912016-03-23 12:13:22 +00003528 @NonNull Certificate[] certs, @NonNull String alias, boolean requestAccess) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003529 throwIfParentInstance("installKeyPair");
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003530 try {
Rubin Xub4365912016-03-23 12:13:22 +00003531 final byte[] pemCert = Credentials.convertToPem(certs[0]);
3532 byte[] pemChain = null;
3533 if (certs.length > 1) {
3534 pemChain = Credentials.convertToPem(Arrays.copyOfRange(certs, 1, certs.length));
3535 }
Robin Lee0d5ccb72014-09-12 17:41:44 +01003536 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
3537 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
Edman Anjosf9946772016-11-28 16:35:15 +01003538 return mService.installKeyPair(admin, mContext.getPackageName(), pkcs8Key, pemCert,
3539 pemChain, alias, requestAccess);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003540 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003541 throw e.rethrowFromSystemServer();
Robin Lee0d5ccb72014-09-12 17:41:44 +01003542 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
3543 Log.w(TAG, "Failed to obtain private key material", e);
3544 } catch (CertificateException | IOException e) {
3545 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003546 }
3547 return false;
3548 }
3549
3550 /**
Robin Leea1b290e2016-03-09 14:38:36 +00003551 * Called by a device or profile owner, or delegated certificate installer, to remove a
3552 * certificate and private key pair installed under a given alias.
Robin Leefbc65642015-08-03 16:21:22 +01003553 *
3554 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Robin Leea1b290e2016-03-09 14:38:36 +00003555 * {@code null} if calling from a delegated certificate installer.
Robin Leefbc65642015-08-03 16:21:22 +01003556 * @param alias The private key alias under which the certificate is installed.
Robin Leea1b290e2016-03-09 14:38:36 +00003557 * @return {@code true} if the private key alias no longer exists, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003558 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3559 * owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003560 * @see #setDelegatedScopes
3561 * @see #DELEGATION_CERT_INSTALL
Robin Leefbc65642015-08-03 16:21:22 +01003562 */
3563 public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003564 throwIfParentInstance("removeKeyPair");
Robin Leefbc65642015-08-03 16:21:22 +01003565 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003566 return mService.removeKeyPair(admin, mContext.getPackageName(), alias);
Robin Leefbc65642015-08-03 16:21:22 +01003567 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003568 throw e.rethrowFromSystemServer();
Robin Leefbc65642015-08-03 16:21:22 +01003569 }
Robin Leefbc65642015-08-03 16:21:22 +01003570 }
3571
3572 /**
Robin Lee25e26452015-06-02 09:56:29 -07003573 * @return the alias of a given CA certificate in the certificate store, or {@code null} if it
Robin Lee306fe082014-06-19 14:04:24 +00003574 * doesn't exist.
3575 */
3576 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
3577 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
3578 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
3579 new ByteArrayInputStream(certBuffer));
3580 return new TrustedCertificateStore().getCertificateAlias(cert);
3581 }
3582
3583 /**
Rubin Xuec32b562015-03-03 17:34:05 +00003584 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01003585 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00003586 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01003587 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00003588 * <p>
3589 * Delegated certificate installer is a per-user state. The delegated access is persistent until
3590 * it is later cleared by calling this method with a null value or uninstallling the certificate
3591 * installer.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003592 * <p>
Rubin Xuf03d0a62016-02-10 14:54:15 +00003593 * <b>Note:</b>Starting from {@link android.os.Build.VERSION_CODES#N}, if the caller
3594 * application's target SDK version is {@link android.os.Build.VERSION_CODES#N} or newer, the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003595 * supplied certificate installer package must be installed when calling this API, otherwise an
3596 * {@link IllegalArgumentException} will be thrown.
Rubin Xuec32b562015-03-03 17:34:05 +00003597 *
Robin Lee25e26452015-06-02 09:56:29 -07003598 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xuec32b562015-03-03 17:34:05 +00003599 * @param installerPackage The package name of the certificate installer which will be given
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003600 * access. If {@code null} is given the current package will be cleared.
3601 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003602 *
3603 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #setDelegatedScopes}
3604 * with the {@link #DELEGATION_CERT_INSTALL} scope instead.
Rubin Xuec32b562015-03-03 17:34:05 +00003605 */
Edman Anjosf9946772016-11-28 16:35:15 +01003606 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07003607 public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String
3608 installerPackage) throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003609 throwIfParentInstance("setCertInstallerPackage");
Rubin Xuec32b562015-03-03 17:34:05 +00003610 if (mService != null) {
3611 try {
Robin Lee25e26452015-06-02 09:56:29 -07003612 mService.setCertInstallerPackage(admin, installerPackage);
Rubin Xuec32b562015-03-03 17:34:05 +00003613 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003614 throw e.rethrowFromSystemServer();
Rubin Xuec32b562015-03-03 17:34:05 +00003615 }
3616 }
3617 }
3618
3619 /**
Edman Anjosf9946772016-11-28 16:35:15 +01003620 * Called by a profile owner or device owner to retrieve the certificate installer for the user,
3621 * or {@code null} if none is set. If there are multiple delegates this function will return one
3622 * of them.
Rubin Xuec32b562015-03-03 17:34:05 +00003623 *
Robin Lee25e26452015-06-02 09:56:29 -07003624 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003625 * @return The package name of the current delegated certificate installer, or {@code null} if
3626 * none is set.
3627 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003628 *
3629 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatePackages}
3630 * with the {@link #DELEGATION_CERT_INSTALL} scope instead.
Rubin Xuec32b562015-03-03 17:34:05 +00003631 */
Edman Anjosf9946772016-11-28 16:35:15 +01003632 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07003633 public @Nullable String getCertInstallerPackage(@NonNull ComponentName admin)
3634 throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003635 throwIfParentInstance("getCertInstallerPackage");
Rubin Xuec32b562015-03-03 17:34:05 +00003636 if (mService != null) {
3637 try {
Robin Lee25e26452015-06-02 09:56:29 -07003638 return mService.getCertInstallerPackage(admin);
Rubin Xuec32b562015-03-03 17:34:05 +00003639 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003640 throw e.rethrowFromSystemServer();
Rubin Xuec32b562015-03-03 17:34:05 +00003641 }
3642 }
3643 return null;
3644 }
3645
3646 /**
Edman Anjosf9946772016-11-28 16:35:15 +01003647 * Called by a profile owner or device owner to grant access to privileged APIs to another app.
3648 * Granted APIs are determined by {@code scopes}, which is a list of the {@code DELEGATION_*}
3649 * constants.
3650 * <p>
3651 * Delegated scopes are a per-user state. The delegated access is persistent until it is later
3652 * cleared by calling this method with an empty {@code scopes} list or uninstalling the
3653 * {@code delegatePackage}.
3654 *
3655 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3656 * @param delegatePackage The package name of the app which will be given access.
3657 * @param scopes The groups of privileged APIs whose access should be granted to
3658 * {@code delegatedPackage}.
3659 * @throws SecurityException if {@code admin} is not a device or a profile owner.
3660 */
3661 public void setDelegatedScopes(@NonNull ComponentName admin, @NonNull String delegatePackage,
3662 @NonNull List<String> scopes) {
3663 throwIfParentInstance("setDelegatedScopes");
3664 if (mService != null) {
3665 try {
3666 mService.setDelegatedScopes(admin, delegatePackage, scopes);
3667 } catch (RemoteException e) {
3668 throw e.rethrowFromSystemServer();
3669 }
3670 }
3671 }
3672
3673 /**
3674 * Called by a profile owner or device owner to retrieve a list of the scopes given to a
3675 * delegate package. Other apps can use this method to retrieve their own delegated scopes by
3676 * passing {@code null} for {@code admin} and their own package name as
3677 * {@code delegatedPackage}.
3678 *
3679 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3680 * {@code null} if the caller is {@code delegatedPackage}.
3681 * @param delegatedPackage The package name of the app whose scopes should be retrieved.
3682 * @return A list containing the scopes given to {@code delegatedPackage}.
3683 * @throws SecurityException if {@code admin} is not a device or a profile owner.
3684 */
3685 @NonNull
3686 public List<String> getDelegatedScopes(@NonNull ComponentName admin,
3687 @NonNull String delegatedPackage) {
3688 throwIfParentInstance("getDelegatedScopes");
3689 if (mService != null) {
3690 try {
3691 return mService.getDelegatedScopes(admin, delegatedPackage);
3692 } catch (RemoteException e) {
3693 throw e.rethrowFromSystemServer();
3694 }
3695 }
3696 return null;
3697 }
3698
3699 /**
3700 * Called by a profile owner or device owner to retrieve a list of delegate packages that were
3701 * granted a delegation scope.
3702 *
3703 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3704 * @param delegationScope The scope whose delegates should be retrieved.
3705 * @return A list of package names of the current delegated packages for
3706 {@code delegationScope}.
3707 * @throws SecurityException if {@code admin} is not a device or a profile owner.
3708 */
3709 @Nullable
3710 public List<String> getDelegatePackages(@NonNull ComponentName admin,
3711 @NonNull String delegationScope) {
3712 throwIfParentInstance("getDelegatePackages");
3713 if (mService != null) {
3714 try {
3715 return mService.getDelegatePackages(admin, delegationScope);
3716 } catch (RemoteException e) {
3717 throw e.rethrowFromSystemServer();
3718 }
3719 }
3720 return null;
3721 }
3722
3723 /**
Robin Lee244ce8e2016-01-05 18:03:46 +00003724 * Called by a device or profile owner to configure an always-on VPN connection through a
Robin Leedc679712016-05-03 13:23:03 +01003725 * specific application for the current user.
3726 *
3727 * @deprecated this version only exists for compability with previous developer preview builds.
3728 * TODO: delete once there are no longer any live references.
3729 * @hide
3730 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07003731 @Deprecated
Robin Leedc679712016-05-03 13:23:03 +01003732 public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage)
3733 throws NameNotFoundException, UnsupportedOperationException {
3734 setAlwaysOnVpnPackage(admin, vpnPackage, /* lockdownEnabled */ true);
3735 }
3736
3737 /**
3738 * Called by a device or profile owner to configure an always-on VPN connection through a
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003739 * specific application for the current user. This connection is automatically granted and
3740 * persisted after a reboot.
3741 * <p>
3742 * The designated package should declare a {@link android.net.VpnService} in its manifest
3743 * guarded by {@link android.Manifest.permission#BIND_VPN_SERVICE}, otherwise the call will
3744 * fail.
Robin Lee244ce8e2016-01-05 18:03:46 +00003745 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003746 * @param vpnPackage The package name for an installed VPN app on the device, or {@code null} to
Robin Leedc679712016-05-03 13:23:03 +01003747 * remove an existing always-on VPN configuration.
3748 * @param lockdownEnabled {@code true} to disallow networking when the VPN is not connected or
3749 * {@code false} otherwise. This carries the risk that any failure of the VPN provider
3750 * could break networking for all apps. This has no effect when clearing.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003751 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Robin Leeee5eb932016-04-05 16:27:15 +01003752 * @throws NameNotFoundException if {@code vpnPackage} is not installed.
3753 * @throws UnsupportedOperationException if {@code vpnPackage} exists but does not support being
3754 * set as always-on, or if always-on VPN is not available.
Robin Lee244ce8e2016-01-05 18:03:46 +00003755 */
Robin Leedc679712016-05-03 13:23:03 +01003756 public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage,
3757 boolean lockdownEnabled)
Robin Leeee5eb932016-04-05 16:27:15 +01003758 throws NameNotFoundException, UnsupportedOperationException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003759 throwIfParentInstance("setAlwaysOnVpnPackage");
Robin Lee244ce8e2016-01-05 18:03:46 +00003760 if (mService != null) {
3761 try {
Robin Leedc679712016-05-03 13:23:03 +01003762 if (!mService.setAlwaysOnVpnPackage(admin, vpnPackage, lockdownEnabled)) {
Robin Leeee5eb932016-04-05 16:27:15 +01003763 throw new NameNotFoundException(vpnPackage);
3764 }
Robin Lee244ce8e2016-01-05 18:03:46 +00003765 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003766 throw e.rethrowFromSystemServer();
Robin Lee244ce8e2016-01-05 18:03:46 +00003767 }
3768 }
Robin Lee244ce8e2016-01-05 18:03:46 +00003769 }
3770
3771 /**
3772 * Called by a device or profile owner to read the name of the package administering an
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003773 * always-on VPN connection for the current user. If there is no such package, or the always-on
3774 * VPN is provided by the system instead of by an application, {@code null} will be returned.
Robin Lee244ce8e2016-01-05 18:03:46 +00003775 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003776 * @return Package name of VPN controller responsible for always-on VPN, or {@code null} if none
3777 * is set.
3778 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Robin Lee244ce8e2016-01-05 18:03:46 +00003779 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003780 public @Nullable String getAlwaysOnVpnPackage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003781 throwIfParentInstance("getAlwaysOnVpnPackage");
Robin Lee244ce8e2016-01-05 18:03:46 +00003782 if (mService != null) {
3783 try {
3784 return mService.getAlwaysOnVpnPackage(admin);
3785 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003786 throw e.rethrowFromSystemServer();
Robin Lee244ce8e2016-01-05 18:03:46 +00003787 }
3788 }
3789 return null;
3790 }
3791
3792 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003793 * Called by an application that is administering the device to disable all cameras on the
3794 * device, for this user. After setting this, no applications running as this user will be able
3795 * to access any cameras on the device.
3796 * <p>
3797 * If the caller is device owner, then the restriction will be applied to all users.
3798 * <p>
3799 * The calling device admin must have requested
3800 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call this method; if it has
3801 * not, a security exception will be thrown.
Ben Komalo2447edd2011-05-09 16:05:33 -07003802 *
3803 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3804 * @param disabled Whether or not the camera should be disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003805 * @throws SecurityException if {@code admin} is not an active administrator or does not use
3806 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA}.
Ben Komalo2447edd2011-05-09 16:05:33 -07003807 */
Robin Lee25e26452015-06-02 09:56:29 -07003808 public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003809 throwIfParentInstance("setCameraDisabled");
Ben Komalo2447edd2011-05-09 16:05:33 -07003810 if (mService != null) {
3811 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003812 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07003813 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003814 throw e.rethrowFromSystemServer();
Ben Komalo2447edd2011-05-09 16:05:33 -07003815 }
3816 }
3817 }
3818
3819 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07003820 * Determine whether or not the device's cameras have been disabled for this user,
Makoto Onuki32b30572015-12-11 14:29:51 -08003821 * either by the calling admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07003822 * @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 -07003823 * have disabled the camera
3824 */
Robin Lee25e26452015-06-02 09:56:29 -07003825 public boolean getCameraDisabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003826 throwIfParentInstance("getCameraDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003827 return getCameraDisabled(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003828 }
3829
3830 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003831 public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07003832 if (mService != null) {
3833 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003834 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07003835 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003836 throw e.rethrowFromSystemServer();
Ben Komalo2447edd2011-05-09 16:05:33 -07003837 }
3838 }
3839 return false;
3840 }
3841
3842 /**
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003843 * Called by a device owner to request a bugreport.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003844 * <p>
Esteban Talaverad36dd152016-12-15 08:51:45 +00003845 * If the device contains secondary users or profiles, they must be affiliated with the device
3846 * owner user. Otherwise a {@link SecurityException} will be thrown. See
3847 * {@link #setAffiliationIds}.
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003848 *
3849 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003850 * @return {@code true} if the bugreport collection started successfully, or {@code false} if it
3851 * wasn't triggered because a previous bugreport operation is still active (either the
3852 * bugreport is still running or waiting for the user to share or decline)
Esteban Talaverad36dd152016-12-15 08:51:45 +00003853 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
3854 * profile or secondary user that is not affiliated with the device owner user.
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003855 */
3856 public boolean requestBugreport(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003857 throwIfParentInstance("requestBugreport");
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003858 if (mService != null) {
3859 try {
3860 return mService.requestBugreport(admin);
3861 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003862 throw e.rethrowFromSystemServer();
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003863 }
3864 }
3865 return false;
3866 }
3867
3868 /**
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07003869 * Determine whether or not creating a guest user has been disabled for the device
3870 *
3871 * @hide
3872 */
3873 public boolean getGuestUserDisabled(@Nullable ComponentName admin) {
3874 // Currently guest users can always be created if multi-user is enabled
3875 // TODO introduce a policy for guest user creation
3876 return false;
3877 }
3878
3879 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01003880 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
3881 * screen capture also prevents the content from being shown on display devices that do not have
3882 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
3883 * secure surfaces and secure displays.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003884 * <p>
3885 * The calling device admin must be a device or profile owner. If it is not, a security
3886 * exception will be thrown.
3887 * <p>
3888 * From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also blocks
3889 * assist requests for all activities of the relevant user.
Benjamin Franzc200f442015-06-25 18:20:04 +01003890 *
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003891 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003892 * @param disabled Whether screen capture is disabled or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003893 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003894 */
Robin Lee25e26452015-06-02 09:56:29 -07003895 public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003896 throwIfParentInstance("setScreenCaptureDisabled");
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003897 if (mService != null) {
3898 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003899 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003900 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003901 throw e.rethrowFromSystemServer();
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003902 }
3903 }
3904 }
3905
3906 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08003907 * Determine whether or not screen capture has been disabled by the calling
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003908 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07003909 * @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 +01003910 * have disabled screen capture.
3911 */
Robin Lee25e26452015-06-02 09:56:29 -07003912 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003913 throwIfParentInstance("getScreenCaptureDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003914 return getScreenCaptureDisabled(admin, myUserId());
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003915 }
3916
3917 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003918 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003919 if (mService != null) {
3920 try {
3921 return mService.getScreenCaptureDisabled(admin, userHandle);
3922 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003923 throw e.rethrowFromSystemServer();
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003924 }
3925 }
3926 return false;
3927 }
3928
3929 /**
Jason Parks841cb0a2017-01-17 15:25:17 -06003930 * Called by a device or profile owner to set whether auto time is required. If auto time is
3931 * 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 -07003932 * <p>
3933 * Note: if auto time is required the user can still manually set the time zone.
3934 * <p>
Jason Parks841cb0a2017-01-17 15:25:17 -06003935 * The calling device admin must be a device or profile owner. If it is not, a security
3936 * exception will be thrown.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003937 *
3938 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3939 * @param required Whether auto time is set required or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003940 * @throws SecurityException if {@code admin} is not a device owner.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003941 */
Robin Lee25e26452015-06-02 09:56:29 -07003942 public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003943 throwIfParentInstance("setAutoTimeRequired");
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003944 if (mService != null) {
3945 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003946 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003947 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003948 throw e.rethrowFromSystemServer();
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003949 }
3950 }
3951 }
3952
3953 /**
3954 * @return true if auto time is required.
3955 */
3956 public boolean getAutoTimeRequired() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003957 throwIfParentInstance("getAutoTimeRequired");
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003958 if (mService != null) {
3959 try {
3960 return mService.getAutoTimeRequired();
3961 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003962 throw e.rethrowFromSystemServer();
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003963 }
3964 }
3965 return false;
3966 }
3967
3968 /**
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003969 * Called by a device owner to set whether all users created on the device should be ephemeral.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003970 * <p>
3971 * The system user is exempt from this policy - it is never ephemeral.
3972 * <p>
3973 * The calling device admin must be the device owner. If it is not, a security exception will be
3974 * thrown.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003975 *
3976 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3977 * @param forceEphemeralUsers If true, all the existing users will be deleted and all
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003978 * subsequently created users will be ephemeral.
3979 * @throws SecurityException if {@code admin} is not a device owner.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003980 * @hide
3981 */
3982 public void setForceEphemeralUsers(
3983 @NonNull ComponentName admin, boolean forceEphemeralUsers) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003984 throwIfParentInstance("setForceEphemeralUsers");
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003985 if (mService != null) {
3986 try {
3987 mService.setForceEphemeralUsers(admin, forceEphemeralUsers);
3988 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003989 throw e.rethrowFromSystemServer();
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003990 }
3991 }
3992 }
3993
3994 /**
3995 * @return true if all users are created ephemeral.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003996 * @throws SecurityException if {@code admin} is not a device owner.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003997 * @hide
3998 */
3999 public boolean getForceEphemeralUsers(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004000 throwIfParentInstance("getForceEphemeralUsers");
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004001 if (mService != null) {
4002 try {
4003 return mService.getForceEphemeralUsers(admin);
4004 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004005 throw e.rethrowFromSystemServer();
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004006 }
4007 }
4008 return false;
4009 }
4010
4011 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07004012 * Called by an application that is administering the device to disable keyguard customizations,
4013 * such as widgets. After setting this, keyguard features will be disabled according to the
4014 * provided feature list.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004015 * <p>
4016 * The calling device admin must have requested
4017 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method;
4018 * if it has not, a security exception will be thrown.
4019 * <p>
4020 * Calling this from a managed profile before version {@link android.os.Build.VERSION_CODES#M}
4021 * will throw a security exception. From version {@link android.os.Build.VERSION_CODES#M} the
4022 * profile owner of a managed profile can set:
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00004023 * <ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00004024 * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which affects the parent user, but only if there
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004025 * is no separate challenge set on the managed profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00004026 * <li>{@link #KEYGUARD_DISABLE_FINGERPRINT} which affects the managed profile challenge if
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004027 * there is one, or the parent user otherwise.
4028 * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} which affects notifications generated
4029 * by applications in the managed profile.
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00004030 * </ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00004031 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} and {@link #KEYGUARD_DISABLE_FINGERPRINT} can also be
4032 * set on the {@link DevicePolicyManager} instance returned by
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004033 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
4034 * profile.
4035 * <p>
4036 * Requests to disable other features on a managed profile will be ignored.
4037 * <p>
4038 * The admin can check which features have been disabled by calling
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00004039 * {@link #getKeyguardDisabledFeatures(ComponentName)}
Amith Yamasani242f4b12014-10-14 16:06:13 -07004040 *
Jim Millerb8ec4702012-08-31 17:19:10 -07004041 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07004042 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004043 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
4044 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS},
4045 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
4046 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS},
4047 * {@link #KEYGUARD_DISABLE_FINGERPRINT}, {@link #KEYGUARD_DISABLE_FEATURES_ALL}
4048 * @throws SecurityException if {@code admin} is not an active administrator or does not user
4049 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES}
Jim Millerb8ec4702012-08-31 17:19:10 -07004050 */
Robin Lee25e26452015-06-02 09:56:29 -07004051 public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07004052 if (mService != null) {
4053 try {
Esteban Talavera62399912016-01-11 15:37:55 +00004054 mService.setKeyguardDisabledFeatures(admin, which, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07004055 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004056 throw e.rethrowFromSystemServer();
Jim Millerb8ec4702012-08-31 17:19:10 -07004057 }
4058 }
4059 }
4060
4061 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004062 * Determine whether or not features have been disabled in keyguard either by the calling
Rubin Xud3609d42016-07-13 18:32:57 +01004063 * admin, if specified, or all admins that set restrictions on this user and its participating
Esteban Talaverac1c83592016-02-17 17:56:15 +00004064 * profiles. Restrictions on profiles that have a separate challenge are not taken into account.
4065 *
4066 * <p>This method can be called on the {@link DevicePolicyManager} instance
4067 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
4068 * restrictions on the parent profile.
4069 *
Esteban Talavera62399912016-01-11 15:37:55 +00004070 * @param admin The name of the admin component to check, or {@code null} to check whether any
4071 * admins have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07004072 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
4073 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07004074 */
Robin Lee25e26452015-06-02 09:56:29 -07004075 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004076 return getKeyguardDisabledFeatures(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004077 }
4078
4079 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07004080 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07004081 if (mService != null) {
4082 try {
Esteban Talavera62399912016-01-11 15:37:55 +00004083 return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07004084 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004085 throw e.rethrowFromSystemServer();
Jim Millerb8ec4702012-08-31 17:19:10 -07004086 }
4087 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07004088 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07004089 }
4090
4091 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08004092 * @hide
4093 */
Robin Lee25e26452015-06-02 09:56:29 -07004094 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
4095 int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08004096 if (mService != null) {
4097 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01004098 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08004099 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004100 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08004101 }
4102 }
4103 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07004104
Dianne Hackbornd6847842010-01-12 18:14:19 -08004105 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01004106 * @hide
4107 */
Robin Lee25e26452015-06-02 09:56:29 -07004108 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004109 setActiveAdmin(policyReceiver, refreshing, myUserId());
Jessica Hummel6d36b602014-04-04 12:42:17 +01004110 }
4111
4112 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08004113 * @hide
4114 */
Robin Lee25e26452015-06-02 09:56:29 -07004115 public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08004116 if (mService != null) {
4117 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004118 mService.getRemoveWarning(admin, result, myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08004119 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004120 throw e.rethrowFromSystemServer();
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08004121 }
4122 }
4123 }
4124
4125 /**
4126 * @hide
4127 */
Andrew Scull5f9e6f32016-08-02 14:22:17 +01004128 public void setActivePasswordState(PasswordMetrics metrics, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08004129 if (mService != null) {
4130 try {
Andrew Scull5f9e6f32016-08-02 14:22:17 +01004131 mService.setActivePasswordState(metrics, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08004132 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004133 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08004134 }
4135 }
4136 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07004137
Dianne Hackbornd6847842010-01-12 18:14:19 -08004138 /**
4139 * @hide
4140 */
Andrew Scull5daf2732016-11-14 15:02:45 +00004141 public void reportPasswordChanged(@UserIdInt int userId) {
4142 if (mService != null) {
4143 try {
4144 mService.reportPasswordChanged(userId);
4145 } catch (RemoteException e) {
4146 throw e.rethrowFromSystemServer();
4147 }
4148 }
4149 }
4150
4151 /**
4152 * @hide
4153 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004154 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08004155 if (mService != null) {
4156 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004157 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08004158 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004159 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08004160 }
4161 }
4162 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07004163
Dianne Hackbornd6847842010-01-12 18:14:19 -08004164 /**
4165 * @hide
4166 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004167 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08004168 if (mService != null) {
4169 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004170 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08004171 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004172 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08004173 }
4174 }
4175 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07004176
4177 /**
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004178 * @hide
4179 */
4180 public void reportFailedFingerprintAttempt(int userHandle) {
4181 if (mService != null) {
4182 try {
4183 mService.reportFailedFingerprintAttempt(userHandle);
4184 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004185 throw e.rethrowFromSystemServer();
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004186 }
4187 }
4188 }
4189
4190 /**
4191 * @hide
4192 */
4193 public void reportSuccessfulFingerprintAttempt(int userHandle) {
4194 if (mService != null) {
4195 try {
4196 mService.reportSuccessfulFingerprintAttempt(userHandle);
4197 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004198 throw e.rethrowFromSystemServer();
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004199 }
4200 }
4201 }
4202
4203 /**
Michal Karpinski31502d32016-01-25 16:43:07 +00004204 * Should be called when keyguard has been dismissed.
4205 * @hide
4206 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004207 public void reportKeyguardDismissed(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00004208 if (mService != null) {
4209 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004210 mService.reportKeyguardDismissed(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00004211 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004212 throw e.rethrowFromSystemServer();
Michal Karpinski31502d32016-01-25 16:43:07 +00004213 }
4214 }
4215 }
4216
4217 /**
4218 * Should be called when keyguard view has been shown to the user.
4219 * @hide
4220 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004221 public void reportKeyguardSecured(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00004222 if (mService != null) {
4223 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004224 mService.reportKeyguardSecured(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00004225 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004226 throw e.rethrowFromSystemServer();
Michal Karpinski31502d32016-01-25 16:43:07 +00004227 }
4228 }
4229 }
4230
4231 /**
Amith Yamasani71e6c692013-03-24 17:39:28 -07004232 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00004233 * Sets the given package as the device owner.
Makoto Onukia52562c2015-10-01 16:12:31 -07004234 * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name.
4235 * @param who the component name to be registered as device owner.
Amith Yamasani71e6c692013-03-24 17:39:28 -07004236 * @return whether the package was successfully registered as the device owner.
4237 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00004238 * @throws IllegalStateException If the preconditions mentioned are not met.
Amith Yamasani71e6c692013-03-24 17:39:28 -07004239 */
Makoto Onukia52562c2015-10-01 16:12:31 -07004240 public boolean setDeviceOwner(ComponentName who) {
4241 return setDeviceOwner(who, null);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004242 }
4243
4244 /**
4245 * @hide
Makoto Onuki58b684f2015-09-04 10:48:16 -07004246 */
Makoto Onukia52562c2015-10-01 16:12:31 -07004247 public boolean setDeviceOwner(ComponentName who, int userId) {
4248 return setDeviceOwner(who, null, userId);
Makoto Onuki58b684f2015-09-04 10:48:16 -07004249 }
4250
4251 /**
4252 * @hide
4253 */
Makoto Onukia52562c2015-10-01 16:12:31 -07004254 public boolean setDeviceOwner(ComponentName who, String ownerName) {
4255 return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM);
Makoto Onuki58b684f2015-09-04 10:48:16 -07004256 }
4257
4258 /**
4259 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00004260 * Sets the given package as the device owner. The package must already be installed. There
4261 * must not already be a device owner.
4262 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
4263 * this method.
4264 * Calling this after the setup phase of the primary user has completed is allowed only if
4265 * the caller is the shell uid, and there are no additional users and no accounts.
Makoto Onukia52562c2015-10-01 16:12:31 -07004266 * @param who the component name to be registered as device owner.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004267 * @param ownerName the human readable name of the institution that owns this device.
Makoto Onuki58b684f2015-09-04 10:48:16 -07004268 * @param userId ID of the user on which the device owner runs.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004269 * @return whether the package was successfully registered as the device owner.
4270 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00004271 * @throws IllegalStateException If the preconditions mentioned are not met.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004272 */
Makoto Onukia52562c2015-10-01 16:12:31 -07004273 public boolean setDeviceOwner(ComponentName who, String ownerName, int userId)
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004274 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07004275 if (mService != null) {
4276 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07004277 return mService.setDeviceOwner(who, ownerName, userId);
Amith Yamasani71e6c692013-03-24 17:39:28 -07004278 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004279 throw re.rethrowFromSystemServer();
Amith Yamasani71e6c692013-03-24 17:39:28 -07004280 }
4281 }
4282 return false;
4283 }
4284
4285 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004286 * Used to determine if a particular package has been registered as a Device Owner app.
4287 * A device owner app is a special device admin that cannot be deactivated by the user, once
Robin Lee25e26452015-06-02 09:56:29 -07004288 * activated as a device admin. It also cannot be uninstalled. To check whether a particular
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004289 * package is currently registered as the device owner app, pass in the package name from
4290 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
Robin Lee25e26452015-06-02 09:56:29 -07004291 * admin apps that want to check whether they are also registered as the device owner app. The
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004292 * exact mechanism by which a device admin app is registered as a device owner app is defined by
4293 * the setup process.
4294 * @param packageName the package name of the app, to compare with the registered device owner
4295 * app, if any.
Makoto Onukic8a5a552015-11-19 14:29:12 -08004296 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07004297 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004298 public boolean isDeviceOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004299 throwIfParentInstance("isDeviceOwnerApp");
Makoto Onukic8a5a552015-11-19 14:29:12 -08004300 return isDeviceOwnerAppOnCallingUser(packageName);
4301 }
4302
4303 /**
4304 * @return true if a package is registered as device owner, only when it's running on the
4305 * calling user.
4306 *
4307 * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity.
4308 * @hide
4309 */
4310 public boolean isDeviceOwnerAppOnCallingUser(String packageName) {
4311 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true);
4312 }
4313
4314 /**
4315 * @return true if a package is registered as device owner, even if it's running on a different
4316 * user.
4317 *
4318 * <p>Requires the MANAGE_USERS permission.
4319 *
4320 * @hide
4321 */
4322 public boolean isDeviceOwnerAppOnAnyUser(String packageName) {
4323 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false);
4324 }
4325
4326 /**
4327 * @return device owner component name, only when it's running on the calling user.
4328 *
4329 * @hide
4330 */
4331 public ComponentName getDeviceOwnerComponentOnCallingUser() {
4332 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true);
4333 }
4334
4335 /**
4336 * @return device owner component name, even if it's running on a different user.
4337 *
4338 * <p>Requires the MANAGE_USERS permission.
4339 *
4340 * @hide
4341 */
Polina Bondarenko23561db2016-12-16 11:47:28 +01004342 @SystemApi
Makoto Onukic8a5a552015-11-19 14:29:12 -08004343 public ComponentName getDeviceOwnerComponentOnAnyUser() {
4344 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false);
4345 }
4346
4347 private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) {
Makoto Onuki70f929e2015-11-11 12:40:15 -08004348 if (packageName == null) {
4349 return false;
Amith Yamasani71e6c692013-03-24 17:39:28 -07004350 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08004351 final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly);
Makoto Onuki70f929e2015-11-11 12:40:15 -08004352 if (deviceOwner == null) {
4353 return false;
4354 }
4355 return packageName.equals(deviceOwner.getPackageName());
Amith Yamasani71e6c692013-03-24 17:39:28 -07004356 }
4357
Makoto Onukic8a5a552015-11-19 14:29:12 -08004358 private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) {
4359 if (mService != null) {
4360 try {
4361 return mService.getDeviceOwnerComponent(callingUserOnly);
4362 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004363 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08004364 }
4365 }
4366 return null;
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004367 }
4368
Jason Monkb0dced82014-06-06 14:36:20 -04004369 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08004370 * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's
4371 * no device owner.
4372 *
4373 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07004374 *
4375 * @hide
4376 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08004377 public int getDeviceOwnerUserId() {
4378 if (mService != null) {
4379 try {
4380 return mService.getDeviceOwnerUserId();
4381 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004382 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08004383 }
4384 }
4385 return UserHandle.USER_NULL;
Makoto Onukia52562c2015-10-01 16:12:31 -07004386 }
4387
4388 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004389 * Clears the current device owner. The caller must be the device owner. This function should be
4390 * used cautiously as once it is called it cannot be undone. The device owner can only be set as
4391 * a part of device setup before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04004392 *
4393 * @param packageName The package name of the device owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004394 * @throws SecurityException if the caller is not in {@code packageName} or {@code packageName}
4395 * does not own the current device owner component.
Jason Monkb0dced82014-06-06 14:36:20 -04004396 */
Jason Monk94d2cf92014-06-18 09:53:34 -04004397 public void clearDeviceOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004398 throwIfParentInstance("clearDeviceOwnerApp");
Jason Monkb0dced82014-06-06 14:36:20 -04004399 if (mService != null) {
4400 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04004401 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04004402 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004403 throw re.rethrowFromSystemServer();
Jason Monkb0dced82014-06-06 14:36:20 -04004404 }
4405 }
4406 }
4407
Makoto Onukia52562c2015-10-01 16:12:31 -07004408 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08004409 * Returns the device owner package name, only if it's running on the calling user.
4410 *
4411 * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity.
Makoto Onukia52562c2015-10-01 16:12:31 -07004412 *
4413 * @hide
4414 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01004415 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004416 public @Nullable String getDeviceOwner() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004417 throwIfParentInstance("getDeviceOwner");
Makoto Onukic8a5a552015-11-19 14:29:12 -08004418 final ComponentName name = getDeviceOwnerComponentOnCallingUser();
4419 return name != null ? name.getPackageName() : null;
Makoto Onukia52562c2015-10-01 16:12:31 -07004420 }
4421
4422 /**
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004423 * Called by the system to find out whether the device is managed by a Device Owner.
Makoto Onukic8a5a552015-11-19 14:29:12 -08004424 *
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004425 * @return whether the device is managed by a Device Owner.
4426 * @throws SecurityException if the caller is not the device owner, does not hold the
4427 * MANAGE_USERS permission and is not the system.
Makoto Onukia52562c2015-10-01 16:12:31 -07004428 *
4429 * @hide
4430 */
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004431 @SystemApi
4432 @TestApi
Makoto Onukic8a5a552015-11-19 14:29:12 -08004433 public boolean isDeviceManaged() {
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004434 try {
4435 return mService.hasDeviceOwner();
4436 } catch (RemoteException re) {
4437 throw re.rethrowFromSystemServer();
4438 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08004439 }
4440
4441 /**
4442 * Returns the device owner name. Note this method *will* return the device owner
4443 * name when it's running on a different user.
4444 *
4445 * <p>Requires the MANAGE_USERS permission.
4446 *
4447 * @hide
4448 */
Makoto Onukia2b274b2016-01-19 13:26:02 -08004449 @SystemApi
Makoto Onukic8a5a552015-11-19 14:29:12 -08004450 public String getDeviceOwnerNameOnAnyUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004451 throwIfParentInstance("getDeviceOwnerNameOnAnyUser");
Amith Yamasani71e6c692013-03-24 17:39:28 -07004452 if (mService != null) {
4453 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07004454 return mService.getDeviceOwnerName();
Amith Yamasani71e6c692013-03-24 17:39:28 -07004455 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004456 throw re.rethrowFromSystemServer();
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004457 }
4458 }
4459 return null;
4460 }
Adam Connors776c5552014-01-09 10:42:56 +00004461
4462 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04004463 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004464 * @deprecated Do not use
4465 * @removed
Julia Reynolds20118f12015-02-11 12:34:08 -05004466 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004467 @Deprecated
Julia Reynolds20118f12015-02-11 12:34:08 -05004468 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004469 public @Nullable String getDeviceInitializerApp() {
Julia Reynolds20118f12015-02-11 12:34:08 -05004470 return null;
4471 }
4472
4473 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004474 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004475 * @deprecated Do not use
4476 * @removed
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004477 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004478 @Deprecated
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004479 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004480 public @Nullable ComponentName getDeviceInitializerComponent() {
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004481 return null;
4482 }
4483
Julia Reynolds20118f12015-02-11 12:34:08 -05004484 /**
Adam Connors776c5552014-01-09 10:42:56 +00004485 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004486 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304487 * Sets the given component as an active admin and registers the package as the profile
4488 * owner for this user. The package must already be installed and there shouldn't be
4489 * an existing profile owner registered for this user. Also, this method must be called
4490 * before the user setup has been completed.
4491 * <p>
4492 * This method can only be called by system apps that hold MANAGE_USERS permission and
4493 * MANAGE_DEVICE_ADMINS permission.
4494 * @param admin The component to register as an active admin and profile owner.
4495 * @param ownerName The user-visible name of the entity that is managing this user.
4496 * @return whether the admin was successfully registered as the profile owner.
4497 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
4498 * the user has already been set up.
4499 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07004500 @Deprecated
Justin Morey80440cc2014-07-24 09:16:35 -05004501 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07004502 public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304503 throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004504 throwIfParentInstance("setActiveProfileOwner");
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304505 if (mService != null) {
4506 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004507 final int myUserId = myUserId();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304508 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004509 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304510 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004511 throw re.rethrowFromSystemServer();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304512 }
4513 }
4514 return false;
4515 }
4516
4517 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004518 * Clears the active profile owner and removes all user restrictions. The caller must be from
4519 * the same package as the active profile owner for this user, otherwise a SecurityException
4520 * will be thrown.
4521 * <p>
4522 * This doesn't work for managed profile owners.
Makoto Onuki5bf68022016-01-27 13:49:19 -08004523 *
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004524 * @param admin The component to remove as the profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004525 * @throws SecurityException if {@code admin} is not an active profile owner.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004526 */
Robin Lee25e26452015-06-02 09:56:29 -07004527 public void clearProfileOwner(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004528 throwIfParentInstance("clearProfileOwner");
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004529 if (mService != null) {
4530 try {
4531 mService.clearProfileOwner(admin);
4532 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004533 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004534 }
4535 }
4536 }
4537
4538 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05004539 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07004540 * Checks whether the user was already setup.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004541 */
4542 public boolean hasUserSetupCompleted() {
4543 if (mService != null) {
4544 try {
4545 return mService.hasUserSetupCompleted();
4546 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004547 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004548 }
4549 }
4550 return true;
4551 }
4552
4553 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004554 * @hide
4555 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00004556 * already be installed. There must not already be a profile owner for this user.
4557 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
4558 * this method.
4559 * Calling this after the setup phase of the specified user has completed is allowed only if:
4560 * - the caller is SYSTEM_UID.
4561 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004562 * @param admin the component name to be registered as profile owner.
4563 * @param ownerName the human readable name of the organisation associated with this DPM.
4564 * @param userHandle the userId to set the profile owner for.
4565 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00004566 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
4567 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004568 */
Robin Lee25e26452015-06-02 09:56:29 -07004569 public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName,
Robin Leeddd553f2015-04-30 14:18:22 +01004570 int userHandle) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00004571 if (mService != null) {
4572 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004573 if (ownerName == null) {
4574 ownerName = "";
4575 }
4576 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00004577 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004578 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004579 }
4580 }
4581 return false;
4582 }
4583
4584 /**
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004585 * Sets the device owner information to be shown on the lock screen.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004586 * <p>
4587 * If the device owner information is {@code null} or empty then the device owner info is
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004588 * cleared and the user owner info is shown on the lock screen if it is set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004589 * <p>
4590 * If the device owner information contains only whitespaces then the message on the lock screen
4591 * will be blank and the user will not be allowed to change it.
4592 * <p>
4593 * If the device owner information needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00004594 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
4595 * and set a new version of this string accordingly.
4596 *
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004597 * @param admin The name of the admin component to check.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004598 * @param info Device owner information which will be displayed instead of the user owner info.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004599 * @throws SecurityException if {@code admin} is not a device owner.
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004600 */
Andrei Stingaceanu16187902016-03-21 15:44:45 +00004601 public void setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, CharSequence info) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004602 throwIfParentInstance("setDeviceOwnerLockScreenInfo");
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004603 if (mService != null) {
4604 try {
Andrei Stingaceanu16187902016-03-21 15:44:45 +00004605 mService.setDeviceOwnerLockScreenInfo(admin, info);
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004606 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004607 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004608 }
4609 }
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004610 }
4611
4612 /**
4613 * @return The device owner information. If it is not set returns {@code null}.
4614 */
Andrei Stingaceanu16187902016-03-21 15:44:45 +00004615 public CharSequence getDeviceOwnerLockScreenInfo() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004616 throwIfParentInstance("getDeviceOwnerLockScreenInfo");
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004617 if (mService != null) {
4618 try {
4619 return mService.getDeviceOwnerLockScreenInfo();
4620 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004621 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004622 }
4623 }
4624 return null;
4625 }
4626
4627 /**
Edman Anjos52088e42017-01-13 22:26:17 +01004628 * Called by device or profile owners to suspend packages for this user. This function can be
4629 * called by a device owner, profile owner, or by a delegate given the
4630 * {@link #DELEGATION_PACKAGE_ACCESS} scope via {@link #setDelegatedScopes}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004631 * <p>
4632 * A suspended package will not be able to start activities. Its notifications will be hidden,
4633 * it will not show up in recents, will not be able to show toasts or dialogs or ring the
4634 * device.
4635 * <p>
4636 * The package must already be installed. If the package is uninstalled while suspended the
4637 * package will no longer be suspended. The admin can block this by using
Kenny Guy871f3eb2016-03-09 20:06:16 +00004638 * {@link #setUninstallBlocked}.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004639 *
Edman Anjos52088e42017-01-13 22:26:17 +01004640 * @param admin The name of the admin component to check, or {@code null} if the caller is a
4641 * package access delegate.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004642 * @param packageNames The package names to suspend or unsuspend.
4643 * @param suspended If set to {@code true} than the packages will be suspended, if set to
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004644 * {@code false} the packages will be unsuspended.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004645 * @return an array of package names for which the suspended status is not set as requested in
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004646 * this method.
4647 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01004648 * @see #setDelegatedScopes
4649 * @see #DELEGATION_PACKAGE_ACCESS
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004650 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004651 public @NonNull String[] setPackagesSuspended(@NonNull ComponentName admin,
4652 @NonNull String[] packageNames, boolean suspended) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004653 throwIfParentInstance("setPackagesSuspended");
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004654 if (mService != null) {
4655 try {
Edman Anjos52088e42017-01-13 22:26:17 +01004656 return mService.setPackagesSuspended(admin, mContext.getPackageName(), packageNames,
4657 suspended);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004658 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004659 throw re.rethrowFromSystemServer();
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004660 }
4661 }
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004662 return packageNames;
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004663 }
4664
4665 /**
Edman Anjos52088e42017-01-13 22:26:17 +01004666 * Determine if a package is suspended. This function can be called by a device owner, profile
4667 * owner, or by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via
4668 * {@link #setDelegatedScopes}.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004669 *
Edman Anjos52088e42017-01-13 22:26:17 +01004670 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
4671 * {@code null} if the caller is a package access delegate.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004672 * @param packageName The name of the package to retrieve the suspended status of.
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00004673 * @return {@code true} if the package is suspended or {@code false} if the package is not
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004674 * suspended, could not be found or an error occurred.
4675 * @throws SecurityException if {@code admin} is not a device or profile owner.
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004676 * @throws NameNotFoundException if the package could not be found.
Edman Anjos52088e42017-01-13 22:26:17 +01004677 * @see #setDelegatedScopes
4678 * @see #DELEGATION_PACKAGE_ACCESS
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004679 */
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004680 public boolean isPackageSuspended(@NonNull ComponentName admin, String packageName)
4681 throws NameNotFoundException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004682 throwIfParentInstance("isPackageSuspended");
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004683 if (mService != null) {
4684 try {
Edman Anjos52088e42017-01-13 22:26:17 +01004685 return mService.isPackageSuspended(admin, mContext.getPackageName(), packageName);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004686 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004687 throw e.rethrowFromSystemServer();
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004688 } catch (IllegalArgumentException ex) {
4689 throw new NameNotFoundException(packageName);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004690 }
4691 }
4692 return false;
4693 }
4694
4695 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004696 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
4697 * be used. Only the profile owner can call this.
4698 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01004699 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004700 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004701 * @throws SecurityException if {@code admin} is not a profile owner.
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004702 */
Robin Lee25e26452015-06-02 09:56:29 -07004703 public void setProfileEnabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004704 throwIfParentInstance("setProfileEnabled");
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004705 if (mService != null) {
4706 try {
4707 mService.setProfileEnabled(admin);
4708 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004709 throw e.rethrowFromSystemServer();
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004710 }
4711 }
4712 }
4713
4714 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004715 * Sets the name of the profile. In the device owner case it sets the name of the user which it
4716 * is called from. Only a profile owner or device owner can call this. If this is never called
4717 * by the profile or device owner, the name will be set to default values.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004718 *
4719 * @see #isProfileOwnerApp
4720 * @see #isDeviceOwnerApp
Robin Lee25e26452015-06-02 09:56:29 -07004721 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004722 * @param profileName The name of the profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004723 * @throws SecurityException if {@code admin} is not a device or profile owner.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004724 */
Robin Lee25e26452015-06-02 09:56:29 -07004725 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004726 throwIfParentInstance("setProfileName");
Jessica Hummel1333ea12014-06-23 11:20:10 +01004727 if (mService != null) {
4728 try {
Robin Lee25e26452015-06-02 09:56:29 -07004729 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07004730 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004731 throw e.rethrowFromSystemServer();
Fyodor Kupolov78f13142015-05-27 16:52:45 -07004732 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01004733 }
4734 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01004735
4736 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004737 * Used to determine if a particular package is registered as the profile owner for the
Makoto Onuki32b30572015-12-11 14:29:51 -08004738 * user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004739 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00004740 *
4741 * @param packageName The package name of the app to compare with the registered profile owner.
4742 * @return Whether or not the package is registered as the profile owner.
4743 */
4744 public boolean isProfileOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004745 throwIfParentInstance("isProfileOwnerApp");
Adam Connors776c5552014-01-09 10:42:56 +00004746 if (mService != null) {
4747 try {
Makoto Onuki90b89652016-01-28 14:44:18 -08004748 ComponentName profileOwner = mService.getProfileOwner(myUserId());
Nicolas Prevot90af6d72014-07-30 14:19:12 +01004749 return profileOwner != null
4750 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00004751 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004752 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004753 }
4754 }
4755 return false;
4756 }
4757
4758 /**
4759 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07004760 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00004761 * owner has been set for that user.
4762 * @throws IllegalArgumentException if the userId is invalid.
4763 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01004764 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004765 public @Nullable ComponentName getProfileOwner() throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004766 throwIfParentInstance("getProfileOwner");
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01004767 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
4768 }
4769
4770 /**
4771 * @see #getProfileOwner()
4772 * @hide
4773 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004774 public @Nullable ComponentName getProfileOwnerAsUser(final int userId)
4775 throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00004776 if (mService != null) {
4777 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01004778 return mService.getProfileOwner(userId);
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 null;
4784 }
4785
4786 /**
4787 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07004788 * @return the human readable name of the organisation associated with this DPM or {@code null}
4789 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00004790 * @throws IllegalArgumentException if the userId is invalid.
4791 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004792 public @Nullable String getProfileOwnerName() throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00004793 if (mService != null) {
4794 try {
4795 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
4796 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004797 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004798 }
4799 }
4800 return null;
4801 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004802
4803 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07004804 * @hide
Makoto Onukic8a5a552015-11-19 14:29:12 -08004805 * @param userId The user for whom to fetch the profile owner name, if any.
Amith Yamasani38f836b2014-08-20 14:51:15 -07004806 * @return the human readable name of the organisation associated with this profile owner or
4807 * null if one is not set.
4808 * @throws IllegalArgumentException if the userId is invalid.
4809 */
4810 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004811 public @Nullable String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004812 throwIfParentInstance("getProfileOwnerNameAsUser");
Amith Yamasani38f836b2014-08-20 14:51:15 -07004813 if (mService != null) {
4814 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02004815 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07004816 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004817 throw re.rethrowFromSystemServer();
Amith Yamasani38f836b2014-08-20 14:51:15 -07004818 }
4819 }
4820 return null;
4821 }
4822
4823 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004824 * Called by a profile owner or device owner to add a default intent handler activity for
4825 * intents that match a certain intent filter. This activity will remain the default intent
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004826 * handler even if the set of potential event handlers for the intent filter changes and if the
4827 * intent preferences are reset.
4828 * <p>
4829 * The default disambiguation mechanism takes over if the activity is not installed (anymore).
4830 * When the activity is (re)installed, it is automatically reset as default intent handler for
4831 * the filter.
4832 * <p>
4833 * The calling device admin must be a profile owner or device owner. If it is not, a security
4834 * exception will be thrown.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004835 *
4836 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4837 * @param filter The IntentFilter for which a default handler is added.
4838 * @param activity The Activity that is added as default intent handler.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004839 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004840 */
Robin Lee25e26452015-06-02 09:56:29 -07004841 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
4842 @NonNull ComponentName activity) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004843 throwIfParentInstance("addPersistentPreferredActivity");
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004844 if (mService != null) {
4845 try {
4846 mService.addPersistentPreferredActivity(admin, filter, activity);
4847 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004848 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004849 }
4850 }
4851 }
4852
4853 /**
4854 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00004855 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004856 * <p>
4857 * The calling device admin must be a profile owner. If it is not, a security exception will be
4858 * thrown.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004859 *
4860 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4861 * @param packageName The name of the package for which preferences are removed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004862 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004863 */
Robin Lee25e26452015-06-02 09:56:29 -07004864 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004865 String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004866 throwIfParentInstance("clearPackagePersistentPreferredActivities");
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004867 if (mService != null) {
4868 try {
4869 mService.clearPackagePersistentPreferredActivities(admin, packageName);
4870 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004871 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004872 }
4873 }
4874 }
Robin Lee66e5d962014-04-09 16:44:21 +01004875
4876 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00004877 * Called by a profile owner or device owner to grant permission to a package to manage
4878 * application restrictions for the calling user via {@link #setApplicationRestrictions} and
4879 * {@link #getApplicationRestrictions}.
4880 * <p>
4881 * This permission is persistent until it is later cleared by calling this method with a
4882 * {@code null} value or uninstalling the managing package.
Rubin Xuf03d0a62016-02-10 14:54:15 +00004883 * <p>
4884 * The supplied application restriction managing package must be installed when calling this
Victor Changcd14c0a2016-03-16 19:10:15 +00004885 * API, otherwise an {@link NameNotFoundException} will be thrown.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004886 *
4887 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4888 * @param packageName The package name which will be given access to application restrictions
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004889 * APIs. If {@code null} is given the current package will be cleared.
4890 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Changcd14c0a2016-03-16 19:10:15 +00004891 * @throws NameNotFoundException if {@code packageName} is not found
Edman Anjosf9946772016-11-28 16:35:15 +01004892 *
4893 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #setDelegatedScopes}
4894 * with the {@link #DELEGATION_APP_RESTRICTIONS} scope instead.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004895 */
Edman Anjosf9946772016-11-28 16:35:15 +01004896 @Deprecated
Esteban Talaverabf60f722015-12-10 16:26:44 +00004897 public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin,
Victor Changcd14c0a2016-03-16 19:10:15 +00004898 @Nullable String packageName) throws NameNotFoundException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004899 throwIfParentInstance("setApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00004900 if (mService != null) {
4901 try {
Victor Changcd14c0a2016-03-16 19:10:15 +00004902 if (!mService.setApplicationRestrictionsManagingPackage(admin, packageName)) {
4903 throw new NameNotFoundException(packageName);
4904 }
Esteban Talaverabf60f722015-12-10 16:26:44 +00004905 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004906 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00004907 }
4908 }
4909 }
4910
4911 /**
4912 * Called by a profile owner or device owner to retrieve the application restrictions managing
Edman Anjosf9946772016-11-28 16:35:15 +01004913 * package for the current user, or {@code null} if none is set. If there are multiple
4914 * delegates this function will return one of them.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004915 *
4916 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4917 * @return The package name allowed to manage application restrictions on the current user, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004918 * {@code null} if none is set.
4919 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01004920 *
4921 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatePackages}
4922 * with the {@link #DELEGATION_APP_RESTRICTIONS} scope instead.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004923 */
Edman Anjosf9946772016-11-28 16:35:15 +01004924 @Deprecated
4925 @Nullable
4926 public String getApplicationRestrictionsManagingPackage(
Makoto Onuki408e8e42016-10-25 12:10:27 -07004927 @NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004928 throwIfParentInstance("getApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00004929 if (mService != null) {
4930 try {
4931 return mService.getApplicationRestrictionsManagingPackage(admin);
4932 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004933 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00004934 }
4935 }
4936 return null;
4937 }
4938
4939 /**
Esteban Talavera96895ca2016-03-16 12:00:40 +00004940 * Called by any application to find out whether it has been granted permission via
4941 * {@link #setApplicationRestrictionsManagingPackage} to manage application restrictions
4942 * for the calling user.
4943 *
4944 * <p>This is done by comparing the calling Linux uid with the uid of the package specified by
4945 * that method.
Edman Anjosf9946772016-11-28 16:35:15 +01004946 *
4947 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatedScopes}
4948 * instead.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004949 */
Edman Anjosf9946772016-11-28 16:35:15 +01004950 @Deprecated
Esteban Talaverabf60f722015-12-10 16:26:44 +00004951 public boolean isCallerApplicationRestrictionsManagingPackage() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004952 throwIfParentInstance("isCallerApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00004953 if (mService != null) {
4954 try {
Edman Anjosf9946772016-11-28 16:35:15 +01004955 return mService.isCallerApplicationRestrictionsManagingPackage(
4956 mContext.getPackageName());
Esteban Talaverabf60f722015-12-10 16:26:44 +00004957 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004958 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00004959 }
4960 }
4961 return false;
4962 }
4963
4964 /**
4965 * Sets the application restrictions for a given target application running in the calling user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004966 * <p>
4967 * 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 +01004968 * application restrictions via {@link #setDelegatedScopes} with the
4969 * {@link #DELEGATION_APP_RESTRICTIONS} scope; otherwise a security exception will be thrown.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004970 * <p>
4971 * The provided {@link Bundle} consists of key-value pairs, where the types of values may be:
Esteban Talavera6b8e0642015-08-10 17:26:04 +01004972 * <ul>
4973 * <li>{@code boolean}
4974 * <li>{@code int}
4975 * <li>{@code String} or {@code String[]}
4976 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
4977 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004978 * <p>
4979 * If the restrictions are not available yet, but may be applied in the near future, the caller
4980 * can notify the target application of that by adding
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00004981 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004982 * <p>
4983 * The application restrictions are only made visible to the target application via
4984 * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or device
4985 * owner, and the application restrictions managing package via
Esteban Talaverabf60f722015-12-10 16:26:44 +00004986 * {@link #getApplicationRestrictions}.
Robin Lee66e5d962014-04-09 16:44:21 +01004987 *
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07004988 * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
4989 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00004990 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004991 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01004992 * @param packageName The name of the package to update restricted settings for.
4993 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004994 * set of active restrictions.
4995 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01004996 * @see #setDelegatedScopes
4997 * @see #DELEGATION_APP_RESTRICTIONS
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00004998 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01004999 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005000 @WorkerThread
Esteban Talaverabf60f722015-12-10 16:26:44 +00005001 public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01005002 Bundle settings) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005003 throwIfParentInstance("setApplicationRestrictions");
Robin Lee66e5d962014-04-09 16:44:21 +01005004 if (mService != null) {
5005 try {
Edman Anjosf9946772016-11-28 16:35:15 +01005006 mService.setApplicationRestrictions(admin, mContext.getPackageName(), packageName,
5007 settings);
Robin Lee66e5d962014-04-09 16:44:21 +01005008 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005009 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01005010 }
5011 }
5012 }
5013
5014 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005015 * Sets a list of configuration features to enable for a TrustAgent component. This is meant to
5016 * be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all trust
5017 * agents but those enabled by this function call. If flag
Jim Millere303bf42014-08-26 17:12:29 -07005018 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005019 * <p>
5020 * The calling device admin must have requested
5021 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method;
5022 * if not, a security exception will be thrown.
Tony Mak089d8402016-04-05 17:42:55 +01005023 * <p>
5024 * This method can be called on the {@link DevicePolicyManager} instance returned by
5025 * {@link #getParentProfileInstance(ComponentName)} in order to set the configuration for
5026 * the parent profile.
Jim Miller604e7552014-07-18 19:00:02 -07005027 *
5028 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07005029 * @param target Component name of the agent to be enabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005030 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent will be
5031 * strictly disabled according to the state of the
5032 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
5033 * <p>
5034 * If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all
5035 * admins, then it's up to the TrustAgent itself to aggregate the values from all
5036 * device admins.
5037 * <p>
5038 * Consult documentation for the specific TrustAgent to determine legal options
5039 * parameters.
5040 * @throws SecurityException if {@code admin} is not an active administrator or does not use
5041 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES}
Jim Miller604e7552014-07-18 19:00:02 -07005042 */
Robin Lee25e26452015-06-02 09:56:29 -07005043 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
5044 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07005045 if (mService != null) {
5046 try {
Tony Mak089d8402016-04-05 17:42:55 +01005047 mService.setTrustAgentConfiguration(admin, target, configuration, mParentInstance);
Jim Miller604e7552014-07-18 19:00:02 -07005048 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005049 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07005050 }
5051 }
5052 }
5053
5054 /**
Jim Millere303bf42014-08-26 17:12:29 -07005055 * Gets configuration for the given trust agent based on aggregating all calls to
5056 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
5057 * all device admins.
Tony Mak089d8402016-04-05 17:42:55 +01005058 * <p>
5059 * This method can be called on the {@link DevicePolicyManager} instance returned by
5060 * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the configuration set
5061 * on the parent profile.
Jim Miller604e7552014-07-18 19:00:02 -07005062 *
Jim Millerb5db57a2015-01-14 18:17:19 -08005063 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
5064 * this function returns a list of configurations for all admins that declare
5065 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
5066 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
5067 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
5068 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07005069 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07005070 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07005071 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005072 public @Nullable List<PersistableBundle> getTrustAgentConfiguration(
5073 @Nullable ComponentName admin, @NonNull ComponentName agent) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07005074 return getTrustAgentConfiguration(admin, agent, myUserId());
Jim Millere303bf42014-08-26 17:12:29 -07005075 }
5076
5077 /** @hide per-user version */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005078 public @Nullable List<PersistableBundle> getTrustAgentConfiguration(
5079 @Nullable ComponentName admin, @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07005080 if (mService != null) {
5081 try {
Tony Mak089d8402016-04-05 17:42:55 +01005082 return mService.getTrustAgentConfiguration(admin, agent, userHandle,
5083 mParentInstance);
Jim Miller604e7552014-07-18 19:00:02 -07005084 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005085 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07005086 }
5087 }
Jim Millere303bf42014-08-26 17:12:29 -07005088 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07005089 }
5090
5091 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005092 * Called by a profile owner of a managed profile to set whether caller-Id information from the
5093 * managed profile will be shown in the parent profile, for incoming calls.
5094 * <p>
5095 * The calling device admin must be a profile owner. If it is not, a security exception will be
5096 * thrown.
Adam Connors210fe212014-07-17 15:41:43 +01005097 *
Robin Lee25e26452015-06-02 09:56:29 -07005098 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01005099 * @param disabled If true caller-Id information in the managed profile is not displayed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005100 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors210fe212014-07-17 15:41:43 +01005101 */
Robin Lee25e26452015-06-02 09:56:29 -07005102 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005103 throwIfParentInstance("setCrossProfileCallerIdDisabled");
Adam Connors210fe212014-07-17 15:41:43 +01005104 if (mService != null) {
5105 try {
Robin Lee25e26452015-06-02 09:56:29 -07005106 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01005107 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005108 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01005109 }
5110 }
5111 }
5112
5113 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005114 * Called by a profile owner of a managed profile to determine whether or not caller-Id
5115 * information has been disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005116 * <p>
5117 * The calling device admin must be a profile owner. If it is not, a security exception will be
5118 * thrown.
Adam Connors210fe212014-07-17 15:41:43 +01005119 *
Robin Lee25e26452015-06-02 09:56:29 -07005120 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005121 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors210fe212014-07-17 15:41:43 +01005122 */
Robin Lee25e26452015-06-02 09:56:29 -07005123 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005124 throwIfParentInstance("getCrossProfileCallerIdDisabled");
Adam Connors210fe212014-07-17 15:41:43 +01005125 if (mService != null) {
5126 try {
Robin Lee25e26452015-06-02 09:56:29 -07005127 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01005128 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005129 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01005130 }
5131 }
5132 return false;
5133 }
5134
5135 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07005136 * Determine whether or not caller-Id information has been disabled.
5137 *
5138 * @param userHandle The user for whom to check the caller-id permission
5139 * @hide
5140 */
5141 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
5142 if (mService != null) {
5143 try {
5144 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
5145 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005146 throw e.rethrowFromSystemServer();
Amith Yamasani570002f2014-07-18 15:48:54 -07005147 }
5148 }
5149 return false;
5150 }
5151
5152 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005153 * Called by a profile owner of a managed profile to set whether contacts search from the
5154 * managed profile will be shown in the parent profile, for incoming calls.
5155 * <p>
5156 * The calling device admin must be a profile owner. If it is not, a security exception will be
5157 * thrown.
Victor Chang1060c6182016-01-04 20:16:23 +00005158 *
5159 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5160 * @param disabled If true contacts search in the managed profile is not displayed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005161 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Chang1060c6182016-01-04 20:16:23 +00005162 */
5163 public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin,
5164 boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005165 throwIfParentInstance("setCrossProfileContactsSearchDisabled");
Victor Chang1060c6182016-01-04 20:16:23 +00005166 if (mService != null) {
5167 try {
5168 mService.setCrossProfileContactsSearchDisabled(admin, disabled);
5169 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005170 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00005171 }
5172 }
5173 }
5174
5175 /**
5176 * Called by a profile owner of a managed profile to determine whether or not contacts search
5177 * has been disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005178 * <p>
5179 * The calling device admin must be a profile owner. If it is not, a security exception will be
5180 * thrown.
Victor Chang1060c6182016-01-04 20:16:23 +00005181 *
5182 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005183 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Chang1060c6182016-01-04 20:16:23 +00005184 */
5185 public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005186 throwIfParentInstance("getCrossProfileContactsSearchDisabled");
Victor Chang1060c6182016-01-04 20:16:23 +00005187 if (mService != null) {
5188 try {
5189 return mService.getCrossProfileContactsSearchDisabled(admin);
5190 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005191 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00005192 }
5193 }
5194 return false;
5195 }
5196
5197
5198 /**
5199 * Determine whether or not contacts search has been disabled.
5200 *
5201 * @param userHandle The user for whom to check the contacts search permission
5202 * @hide
5203 */
5204 public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) {
5205 if (mService != null) {
5206 try {
5207 return mService
5208 .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier());
5209 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005210 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00005211 }
5212 }
5213 return false;
5214 }
5215
5216 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005217 * Start Quick Contact on the managed profile for the user, if the policy allows.
Victor Chang97bdacc2016-01-21 22:24:11 +00005218 *
Makoto Onuki1040da12015-03-19 11:24:00 -07005219 * @hide
5220 */
5221 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
Victor Chang97bdacc2016-01-21 22:24:11 +00005222 boolean isContactIdIgnored, long directoryId, Intent originalIntent) {
Makoto Onuki1040da12015-03-19 11:24:00 -07005223 if (mService != null) {
5224 try {
Victor Chang97bdacc2016-01-21 22:24:11 +00005225 mService.startManagedQuickContact(actualLookupKey, actualContactId,
5226 isContactIdIgnored, directoryId, originalIntent);
Makoto Onuki1040da12015-03-19 11:24:00 -07005227 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005228 throw e.rethrowFromSystemServer();
Makoto Onuki1040da12015-03-19 11:24:00 -07005229 }
5230 }
5231 }
5232
5233 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005234 * Start Quick Contact on the managed profile for the user, if the policy allows.
Ricky Wai494b95d2015-11-20 16:07:15 +00005235 * @hide
5236 */
5237 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
5238 Intent originalIntent) {
Victor Chang97bdacc2016-01-21 22:24:11 +00005239 startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT,
Ricky Wai494b95d2015-11-20 16:07:15 +00005240 originalIntent);
5241 }
5242
5243 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005244 * Called by a profile owner of a managed profile to set whether bluetooth devices can access
5245 * enterprise contacts.
Ricky Wai778ba132015-03-31 14:21:22 +01005246 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005247 * The calling device admin must be a profile owner. If it is not, a security exception will be
5248 * thrown.
Ricky Wai778ba132015-03-31 14:21:22 +01005249 * <p>
5250 * This API works on managed profile only.
5251 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005252 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5253 * @param disabled If true, bluetooth devices cannot access enterprise contacts.
5254 * @throws SecurityException if {@code admin} is not a device or profile owner.
Ricky Wai778ba132015-03-31 14:21:22 +01005255 */
Robin Lee25e26452015-06-02 09:56:29 -07005256 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005257 throwIfParentInstance("setBluetoothContactSharingDisabled");
Ricky Wai778ba132015-03-31 14:21:22 +01005258 if (mService != null) {
5259 try {
Robin Lee25e26452015-06-02 09:56:29 -07005260 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01005261 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005262 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01005263 }
5264 }
5265 }
5266
5267 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005268 * Called by a profile owner of a managed profile to determine whether or not Bluetooth devices
5269 * cannot access enterprise contacts.
Ricky Wai778ba132015-03-31 14:21:22 +01005270 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005271 * The calling device admin must be a profile owner. If it is not, a security exception will be
5272 * thrown.
Ricky Wai778ba132015-03-31 14:21:22 +01005273 * <p>
5274 * This API works on managed profile only.
5275 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005276 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5277 * @throws SecurityException if {@code admin} is not a device or profile owner.
Ricky Wai778ba132015-03-31 14:21:22 +01005278 */
Robin Lee25e26452015-06-02 09:56:29 -07005279 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005280 throwIfParentInstance("getBluetoothContactSharingDisabled");
Ricky Wai778ba132015-03-31 14:21:22 +01005281 if (mService != null) {
5282 try {
Robin Lee25e26452015-06-02 09:56:29 -07005283 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01005284 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005285 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01005286 }
5287 }
5288 return true;
5289 }
5290
5291 /**
5292 * Determine whether or not Bluetooth devices cannot access contacts.
5293 * <p>
5294 * This API works on managed profile UserHandle only.
5295 *
5296 * @param userHandle The user for whom to check the caller-id permission
5297 * @hide
5298 */
5299 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
5300 if (mService != null) {
5301 try {
5302 return mService.getBluetoothContactSharingDisabledForUser(userHandle
5303 .getIdentifier());
5304 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005305 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01005306 }
5307 }
5308 return true;
5309 }
5310
5311 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005312 * Called by the profile owner of a managed profile so that some intents sent in the managed
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005313 * profile can also be resolved in the parent, or vice versa. Only activity intents are
5314 * supported.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00005315 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005316 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01005317 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005318 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01005319 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005320 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
5321 * @throws SecurityException if {@code admin} is not a device or profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005322 */
Robin Lee25e26452015-06-02 09:56:29 -07005323 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005324 throwIfParentInstance("addCrossProfileIntentFilter");
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005325 if (mService != null) {
5326 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01005327 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005328 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005329 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005330 }
5331 }
5332 }
5333
5334 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005335 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
5336 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01005337 * Only removes those that have been set by the profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005338 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005339 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005340 * @throws SecurityException if {@code admin} is not a device or profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005341 */
Robin Lee25e26452015-06-02 09:56:29 -07005342 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005343 throwIfParentInstance("clearCrossProfileIntentFilters");
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005344 if (mService != null) {
5345 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01005346 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005347 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005348 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005349 }
5350 }
5351 }
5352
5353 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005354 * Called by a profile or device owner to set the permitted accessibility services. When set by
5355 * a device owner or profile owner the restriction applies to all profiles of the user the
5356 * device owner or profile owner is an admin for. By default the user can use any accessiblity
5357 * service. When zero or more packages have been added, accessiblity services that are not in
5358 * the list and not part of the system can not be enabled by the user.
5359 * <p>
5360 * Calling with a null value for the list disables the restriction so that all services can be
5361 * used, calling with an empty list only allows the builtin system's services.
5362 * <p>
5363 * System accesibility services are always available to the user the list can't modify this.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005364 *
5365 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5366 * @param packageNames List of accessibility service package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005367 * @return true if setting the restriction succeeded. It fail if there is one or more non-system
5368 * accessibility services enabled, that are not in the list.
5369 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005370 */
Robin Lee25e26452015-06-02 09:56:29 -07005371 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005372 List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005373 throwIfParentInstance("setPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005374 if (mService != null) {
5375 try {
5376 return mService.setPermittedAccessibilityServices(admin, packageNames);
5377 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005378 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005379 }
5380 }
5381 return false;
5382 }
5383
5384 /**
5385 * Returns the list of permitted accessibility services set by this device or profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005386 * <p>
5387 * An empty list means no accessibility services except system services are allowed. Null means
5388 * all accessibility services are allowed.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005389 *
5390 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5391 * @return List of accessiblity service package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005392 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005393 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005394 public @Nullable List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005395 throwIfParentInstance("getPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005396 if (mService != null) {
5397 try {
5398 return mService.getPermittedAccessibilityServices(admin);
5399 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005400 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005401 }
5402 }
5403 return null;
5404 }
5405
5406 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00005407 * Called by the system to check if a specific accessibility service is disabled by admin.
5408 *
5409 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5410 * @param packageName Accessibility service package name that needs to be checked.
5411 * @param userHandle user id the admin is running as.
5412 * @return true if the accessibility service is permitted, otherwise false.
5413 *
5414 * @hide
5415 */
5416 public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin,
5417 @NonNull String packageName, int userHandle) {
5418 if (mService != null) {
5419 try {
5420 return mService.isAccessibilityServicePermittedByAdmin(admin, packageName,
5421 userHandle);
5422 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005423 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00005424 }
5425 }
5426 return false;
5427 }
5428
5429 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005430 * Returns the list of accessibility services permitted by the device or profiles
5431 * owners of this user.
5432 *
5433 * <p>Null means all accessibility services are allowed, if a non-null list is returned
5434 * it will contain the intersection of the permitted lists for any device or profile
5435 * owners that apply to this user. It will also include any system accessibility services.
5436 *
5437 * @param userId which user to check for.
5438 * @return List of accessiblity service package names.
5439 * @hide
5440 */
5441 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07005442 public @Nullable List<String> getPermittedAccessibilityServices(int userId) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005443 throwIfParentInstance("getPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005444 if (mService != null) {
5445 try {
5446 return mService.getPermittedAccessibilityServicesForUser(userId);
5447 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005448 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005449 }
5450 }
5451 return null;
5452 }
5453
5454 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005455 * Called by a profile or device owner to set the permitted input methods services. When set by
5456 * a device owner or profile owner the restriction applies to all profiles of the user the
5457 * device owner or profile owner is an admin for. By default the user can use any input method.
5458 * When zero or more packages have been added, input method that are not in the list and not
5459 * part of the system can not be enabled by the user. This method will fail if it is called for
5460 * a admin that is not for the foreground user or a profile of the foreground user.
5461 * <p>
5462 * Calling with a null value for the list disables the restriction so that all input methods can
5463 * be used, calling with an empty list disables all but the system's own input methods.
5464 * <p>
5465 * System input methods are always available to the user this method can't modify this.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005466 *
5467 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5468 * @param packageNames List of input method package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005469 * @return true if setting the restriction succeeded. It will fail if there are one or more
5470 * non-system input methods currently enabled that are not in the packageNames list.
5471 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005472 */
Robin Lee25e26452015-06-02 09:56:29 -07005473 public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005474 throwIfParentInstance("setPermittedInputMethods");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005475 if (mService != null) {
5476 try {
5477 return mService.setPermittedInputMethods(admin, packageNames);
5478 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005479 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005480 }
5481 }
5482 return false;
5483 }
5484
5485
5486 /**
5487 * Returns the list of permitted input methods set by this device or profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005488 * <p>
5489 * An empty list means no input methods except system input methods are allowed. Null means all
5490 * input methods are allowed.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005491 *
5492 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5493 * @return List of input method package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005494 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005495 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005496 public @Nullable List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005497 throwIfParentInstance("getPermittedInputMethods");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005498 if (mService != null) {
5499 try {
5500 return mService.getPermittedInputMethods(admin);
5501 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005502 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005503 }
5504 }
5505 return null;
5506 }
5507
5508 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00005509 * Called by the system to check if a specific input method is disabled by admin.
5510 *
5511 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5512 * @param packageName Input method package name that needs to be checked.
5513 * @param userHandle user id the admin is running as.
5514 * @return true if the input method is permitted, otherwise false.
5515 *
5516 * @hide
5517 */
5518 public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin,
5519 @NonNull String packageName, int userHandle) {
5520 if (mService != null) {
5521 try {
5522 return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle);
5523 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005524 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00005525 }
5526 }
5527 return false;
5528 }
5529
5530 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005531 * Returns the list of input methods permitted by the device or profiles
Makoto Onuki32b30572015-12-11 14:29:51 -08005532 * owners of the current user. (*Not* calling user, due to a limitation in InputMethodManager.)
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005533 *
5534 * <p>Null means all input methods are allowed, if a non-null list is returned
5535 * it will contain the intersection of the permitted lists for any device or profile
5536 * owners that apply to this user. It will also include any system input methods.
5537 *
5538 * @return List of input method package names.
5539 * @hide
5540 */
5541 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07005542 public @Nullable List<String> getPermittedInputMethodsForCurrentUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005543 throwIfParentInstance("getPermittedInputMethodsForCurrentUser");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005544 if (mService != null) {
5545 try {
5546 return mService.getPermittedInputMethodsForCurrentUser();
5547 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005548 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005549 }
5550 }
5551 return null;
5552 }
5553
5554 /**
Edman Anjos52088e42017-01-13 22:26:17 +01005555 * Get the list of apps to keep around as APKs even if no user has currently installed it. This
5556 * function can be called by a device owner or by a delegate given the
5557 * {@link #DELEGATION_KEEP_UNINSTALLED_PACKAGES} scope via {@link #setDelegatedScopes}.
5558 * <p>
5559 * Please note that packages returned in this method are not automatically pre-cached.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005560 *
Edman Anjos52088e42017-01-13 22:26:17 +01005561 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
5562 * {@code null} if the caller is a keep uninstalled packages delegate.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005563 * @return List of package names to keep cached.
Edman Anjos52088e42017-01-13 22:26:17 +01005564 * @see #setDelegatedScopes
5565 * @see #DELEGATION_KEEP_UNINSTALLED_PACKAGES
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005566 * @hide
5567 */
Edman Anjos52088e42017-01-13 22:26:17 +01005568 public @Nullable List<String> getKeepUninstalledPackages(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005569 throwIfParentInstance("getKeepUninstalledPackages");
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005570 if (mService != null) {
5571 try {
Edman Anjos52088e42017-01-13 22:26:17 +01005572 return mService.getKeepUninstalledPackages(admin, mContext.getPackageName());
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005573 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005574 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005575 }
5576 }
5577 return null;
5578 }
5579
5580 /**
Edman Anjos52088e42017-01-13 22:26:17 +01005581 * Set a list of apps to keep around as APKs even if no user has currently installed it. This
5582 * function can be called by a device owner or by a delegate given the
5583 * {@link #DELEGATION_KEEP_UNINSTALLED_PACKAGES} scope via {@link #setDelegatedScopes}.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005584 *
5585 * <p>Please note that setting this policy does not imply that specified apps will be
5586 * automatically pre-cached.</p>
5587 *
Edman Anjos52088e42017-01-13 22:26:17 +01005588 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
5589 * {@code null} if the caller is a keep uninstalled packages delegate.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005590 * @param packageNames List of package names to keep cached.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005591 * @throws SecurityException if {@code admin} is not a device owner.
Edman Anjos52088e42017-01-13 22:26:17 +01005592 * @see #setDelegatedScopes
5593 * @see #DELEGATION_KEEP_UNINSTALLED_PACKAGES
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005594 * @hide
5595 */
Edman Anjos52088e42017-01-13 22:26:17 +01005596 public void setKeepUninstalledPackages(@Nullable ComponentName admin,
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005597 @NonNull List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005598 throwIfParentInstance("setKeepUninstalledPackages");
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005599 if (mService != null) {
5600 try {
Edman Anjos52088e42017-01-13 22:26:17 +01005601 mService.setKeepUninstalledPackages(admin, mContext.getPackageName(), packageNames);
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005602 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005603 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005604 }
5605 }
5606 }
5607
5608 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04005609 * Called by a device owner to create a user with the specified name. The UserHandle returned
5610 * by this method should not be persisted as user handles are recycled as users are removed and
5611 * created. If you need to persist an identifier for this user, use
5612 * {@link UserManager#getSerialNumberForUser}.
5613 *
5614 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5615 * @param name the user's name
5616 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07005617 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
5618 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01005619 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005620 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01005621 * @removed From {@link android.os.Build.VERSION_CODES#N}
Julia Reynolds1e958392014-05-16 14:25:21 -04005622 */
Kenny Guy14f48e52015-06-29 15:12:36 +01005623 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07005624 public @Nullable UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04005625 return null;
5626 }
5627
5628 /**
Jason Monk03978a42014-06-10 15:05:30 -04005629 * Called by a device owner to create a user with the specified name. The UserHandle returned
5630 * by this method should not be persisted as user handles are recycled as users are removed and
5631 * created. If you need to persist an identifier for this user, use
5632 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
5633 * immediately.
5634 *
5635 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
5636 * as registered as an active admin on the new user. The profile owner package will be
5637 * installed on the new user if it already is installed on the device.
5638 *
5639 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
5640 * profileOwnerComponent when onEnable is called.
5641 *
5642 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5643 * @param name the user's name
5644 * @param ownerName the human readable name of the organisation associated with this DPM.
5645 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
5646 * the user.
5647 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
5648 * on the new user.
5649 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07005650 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
5651 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01005652 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005653 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01005654 * @removed From {@link android.os.Build.VERSION_CODES#N}
Jason Monk03978a42014-06-10 15:05:30 -04005655 */
Kenny Guy14f48e52015-06-29 15:12:36 +01005656 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07005657 public @Nullable UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
Robin Lee25e26452015-06-02 09:56:29 -07005658 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04005659 return null;
5660 }
5661
5662 /**
phweissa92e1212016-01-25 17:14:10 +01005663 * Flag used by {@link #createAndManageUser} to skip setup wizard after creating a new user.
phweiss343fb332016-01-25 14:48:59 +01005664 */
5665 public static final int SKIP_SETUP_WIZARD = 0x0001;
5666
5667 /**
Lenka Trochtovac8202c82016-01-26 15:11:09 +01005668 * Flag used by {@link #createAndManageUser} to specify that the user should be created
5669 * ephemeral.
5670 * @hide
5671 */
5672 public static final int MAKE_USER_EPHEMERAL = 0x0002;
5673
5674 /**
phweissa92e1212016-01-25 17:14:10 +01005675 * Called by a device owner to create a user with the specified name and a given component of
5676 * the calling package as profile owner. The UserHandle returned by this method should not be
5677 * persisted as user handles are recycled as users are removed and created. If you need to
5678 * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new
5679 * user will not be started in the background.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005680 * <p>
5681 * admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also a
5682 * DeviceAdminReceiver in the same package as admin, and will become the profile owner and will
5683 * be registered as an active admin on the new user. The profile owner package will be installed
5684 * on the new user.
5685 * <p>
5686 * If the adminExtras are not null, they will be stored on the device until the user is started
5687 * for the first time. Then the extras will be passed to the admin when onEnable is called.
phweiss343fb332016-01-25 14:48:59 +01005688 *
5689 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5690 * @param name The user's name.
phweissa92e1212016-01-25 17:14:10 +01005691 * @param profileOwner Which {@link DeviceAdminReceiver} will be profile owner. Has to be in the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005692 * same package as admin, otherwise no user is created and an
5693 * IllegalArgumentException is thrown.
phweiss343fb332016-01-25 14:48:59 +01005694 * @param adminExtras Extras that will be passed to onEnable of the admin receiver on the new
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005695 * user.
phweissa92e1212016-01-25 17:14:10 +01005696 * @param flags {@link #SKIP_SETUP_WIZARD} is supported.
phweiss343fb332016-01-25 14:48:59 +01005697 * @see UserHandle
5698 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
5699 * user could not be created.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005700 * @throws SecurityException if {@code admin} is not a device owner.
phweiss343fb332016-01-25 14:48:59 +01005701 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005702 public @Nullable UserHandle createAndManageUser(@NonNull ComponentName admin,
5703 @NonNull String name,
phweissa92e1212016-01-25 17:14:10 +01005704 @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras,
5705 int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005706 throwIfParentInstance("createAndManageUser");
phweiss343fb332016-01-25 14:48:59 +01005707 try {
phweissa92e1212016-01-25 17:14:10 +01005708 return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags);
phweiss343fb332016-01-25 14:48:59 +01005709 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005710 throw re.rethrowFromSystemServer();
phweiss343fb332016-01-25 14:48:59 +01005711 }
phweiss343fb332016-01-25 14:48:59 +01005712 }
5713
5714 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005715 * Called by a device owner to remove a user and all associated data. The primary user can not
5716 * be removed.
Julia Reynolds1e958392014-05-16 14:25:21 -04005717 *
5718 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5719 * @param userHandle the user to remove.
5720 * @return {@code true} if the user was removed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005721 * @throws SecurityException if {@code admin} is not a device owner.
Julia Reynolds1e958392014-05-16 14:25:21 -04005722 */
Robin Lee25e26452015-06-02 09:56:29 -07005723 public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005724 throwIfParentInstance("removeUser");
Julia Reynolds1e958392014-05-16 14:25:21 -04005725 try {
5726 return mService.removeUser(admin, userHandle);
5727 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005728 throw re.rethrowFromSystemServer();
Julia Reynolds1e958392014-05-16 14:25:21 -04005729 }
5730 }
5731
5732 /**
Jason Monk582d9112014-07-09 19:57:08 -04005733 * Called by a device owner to switch the specified user to the foreground.
5734 *
5735 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5736 * @param userHandle the user to switch to; null will switch to primary.
5737 * @return {@code true} if the switch was successful, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005738 * @throws SecurityException if {@code admin} is not a device owner.
Jason Monk582d9112014-07-09 19:57:08 -04005739 * @see Intent#ACTION_USER_FOREGROUND
5740 */
Robin Lee25e26452015-06-02 09:56:29 -07005741 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005742 throwIfParentInstance("switchUser");
Jason Monk582d9112014-07-09 19:57:08 -04005743 try {
5744 return mService.switchUser(admin, userHandle);
5745 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005746 throw re.rethrowFromSystemServer();
Jason Monk582d9112014-07-09 19:57:08 -04005747 }
5748 }
5749
5750 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00005751 * Retrieves the application restrictions for a given target application running in the calling
5752 * user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005753 * <p>
5754 * 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 +01005755 * application restrictions via {@link #setDelegatedScopes} with the
5756 * {@link #DELEGATION_APP_RESTRICTIONS} scope; otherwise a security exception will be thrown.
Robin Lee66e5d962014-04-09 16:44:21 +01005757 *
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005758 * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
5759 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00005760 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005761 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01005762 * @param packageName The name of the package to fetch restricted settings of.
5763 * @return {@link Bundle} of settings corresponding to what was set last time
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005764 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty
5765 * {@link Bundle} if no restrictions have been set.
5766 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01005767 * @see #setDelegatedScopes
5768 * @see #DELEGATION_APP_RESTRICTIONS
Robin Lee66e5d962014-04-09 16:44:21 +01005769 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005770 @WorkerThread
Makoto Onuki408e8e42016-10-25 12:10:27 -07005771 public @NonNull Bundle getApplicationRestrictions(
5772 @Nullable ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005773 throwIfParentInstance("getApplicationRestrictions");
Robin Lee66e5d962014-04-09 16:44:21 +01005774 if (mService != null) {
5775 try {
Edman Anjosf9946772016-11-28 16:35:15 +01005776 return mService.getApplicationRestrictions(admin, mContext.getPackageName(),
5777 packageName);
Robin Lee66e5d962014-04-09 16:44:21 +01005778 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005779 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01005780 }
5781 }
5782 return null;
5783 }
Amith Yamasanibe465322014-04-24 13:45:17 -07005784
5785 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05005786 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07005787 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005788 * The calling device admin must be a profile or device owner; if it is not, a security
5789 * exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07005790 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005791 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5792 * @param key The key of the restriction. See the constants in {@link android.os.UserManager}
5793 * for the list of keys.
5794 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanibe465322014-04-24 13:45:17 -07005795 */
Robin Lee25e26452015-06-02 09:56:29 -07005796 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005797 throwIfParentInstance("addUserRestriction");
Amith Yamasanibe465322014-04-24 13:45:17 -07005798 if (mService != null) {
5799 try {
5800 mService.setUserRestriction(admin, key, true);
5801 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005802 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07005803 }
5804 }
5805 }
5806
5807 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05005808 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07005809 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005810 * The calling device admin must be a profile or device owner; if it is not, a security
5811 * exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07005812 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005813 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5814 * @param key The key of the restriction. See the constants in {@link android.os.UserManager}
5815 * for the list of keys.
5816 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanibe465322014-04-24 13:45:17 -07005817 */
Robin Lee25e26452015-06-02 09:56:29 -07005818 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005819 throwIfParentInstance("clearUserRestriction");
Amith Yamasanibe465322014-04-24 13:45:17 -07005820 if (mService != null) {
5821 try {
5822 mService.setUserRestriction(admin, key, false);
5823 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005824 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07005825 }
5826 }
5827 }
Adam Connors010cfd42014-04-16 12:48:13 +01005828
5829 /**
Makoto Onuki3a3092f2015-10-30 11:07:51 -07005830 * Called by a profile or device owner to get user restrictions set with
5831 * {@link #addUserRestriction(ComponentName, String)}.
5832 * <p>
5833 * The target user may have more restrictions set by the system or other device owner / profile
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005834 * owner. To get all the user restrictions currently set, use
Makoto Onuki3a3092f2015-10-30 11:07:51 -07005835 * {@link UserManager#getUserRestrictions()}.
5836 *
5837 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005838 * @throws SecurityException if {@code admin} is not a device or profile owner.
Makoto Onuki3a3092f2015-10-30 11:07:51 -07005839 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005840 public @NonNull Bundle getUserRestrictions(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005841 throwIfParentInstance("getUserRestrictions");
Makoto Onuki3a3092f2015-10-30 11:07:51 -07005842 Bundle ret = null;
5843 if (mService != null) {
5844 try {
Sudheer Shanka549b9692016-03-30 17:12:07 -07005845 ret = mService.getUserRestrictions(admin);
5846 } catch (RemoteException e) {
5847 throw e.rethrowFromSystemServer();
5848 }
5849 }
5850 return ret == null ? new Bundle() : ret;
5851 }
5852
5853 /**
phweiss73145f42017-01-17 19:06:38 +01005854 * Called by any app to display a support dialog when a feature was disabled by an admin.
5855 * This returns an intent that can be used with {@link Context#startActivity(Intent)} to
5856 * display the dialog. It will tell the user that the feature indicated by {@code restriction}
5857 * was disabled by an admin, and include a link for more information. The default content of
5858 * the dialog can be changed by the restricting admin via
5859 * {@link #setShortSupportMessage(ComponentName, CharSequence)}. If the restriction is not
5860 * set (i.e. the feature is available), then the return value will be {@code null}.
5861 * @param restriction Indicates for which feature the dialog should be displayed. Can be a
5862 * user restriction from {@link UserManager}, e.g.
5863 * {@link UserManager#DISALLOW_ADJUST_VOLUME}, or one of the constants
5864 * {@link #POLICY_DISABLE_CAMERA} or {@link #POLICY_DISABLE_SCREEN_CAPTURE}.
5865 * @return Intent An intent to be used to start the dialog-activity if the restriction is
5866 * set by an admin, or null if the restriction does not exist or no admin set it.
5867 */
5868 public Intent createAdminSupportIntent(@NonNull String restriction) {
5869 throwIfParentInstance("createAdminSupportIntent");
5870 if (mService != null) {
5871 try {
5872 return mService.createAdminSupportIntent(restriction);
5873 } catch (RemoteException e) {
5874 throw e.rethrowFromSystemServer();
5875 }
5876 }
5877 return null;
5878 }
5879
5880 /**
Edman Anjos52088e42017-01-13 22:26:17 +01005881 * Hide or unhide packages. When a package is hidden it is unavailable for use, but the data and
5882 * actual package file remain. This function can be called by a device owner, profile owner, or
5883 * by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via
5884 * {@link #setDelegatedScopes}.
Julia Reynolds966881e2014-05-14 12:23:08 -04005885 *
Edman Anjos52088e42017-01-13 22:26:17 +01005886 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
5887 * {@code null} if the caller is a package access delegate.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005888 * @param packageName The name of the package to hide or unhide.
5889 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005890 * unhidden.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005891 * @return boolean Whether the hidden setting of the package was successfully updated.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005892 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01005893 * @see #setDelegatedScopes
5894 * @see #DELEGATION_PACKAGE_ACCESS
Julia Reynolds966881e2014-05-14 12:23:08 -04005895 */
Robin Lee25e26452015-06-02 09:56:29 -07005896 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005897 boolean hidden) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005898 throwIfParentInstance("setApplicationHidden");
Julia Reynolds966881e2014-05-14 12:23:08 -04005899 if (mService != null) {
5900 try {
Edman Anjos52088e42017-01-13 22:26:17 +01005901 return mService.setApplicationHidden(admin, mContext.getPackageName(), packageName,
5902 hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04005903 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005904 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04005905 }
5906 }
5907 return false;
5908 }
5909
5910 /**
Edman Anjos52088e42017-01-13 22:26:17 +01005911 * Determine if a package is hidden. This function can be called by a device owner, profile
5912 * owner, or by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via
5913 * {@link #setDelegatedScopes}.
Julia Reynolds966881e2014-05-14 12:23:08 -04005914 *
Edman Anjos52088e42017-01-13 22:26:17 +01005915 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
5916 * {@code null} if the caller is a package access delegate.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005917 * @param packageName The name of the package to retrieve the hidden status of.
5918 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005919 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01005920 * @see #setDelegatedScopes
5921 * @see #DELEGATION_PACKAGE_ACCESS
Julia Reynolds966881e2014-05-14 12:23:08 -04005922 */
Robin Lee25e26452015-06-02 09:56:29 -07005923 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005924 throwIfParentInstance("isApplicationHidden");
Julia Reynolds966881e2014-05-14 12:23:08 -04005925 if (mService != null) {
5926 try {
Edman Anjos52088e42017-01-13 22:26:17 +01005927 return mService.isApplicationHidden(admin, mContext.getPackageName(), packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04005928 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005929 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04005930 }
5931 }
5932 return false;
5933 }
5934
5935 /**
Edman Anjos52088e42017-01-13 22:26:17 +01005936 * Re-enable a system app that was disabled by default when the user was initialized. This
5937 * function can be called by a device owner, profile owner, or by a delegate given the
5938 * {@link #DELEGATION_ENABLE_SYSTEM_APP} scope via {@link #setDelegatedScopes}.
Adam Connors655be2a2014-07-14 09:01:25 +00005939 *
Edman Anjos52088e42017-01-13 22:26:17 +01005940 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
5941 * {@code null} if the caller is an enable system app delegate.
Makoto Onuki32b30572015-12-11 14:29:51 -08005942 * @param packageName The package to be re-enabled in the calling profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005943 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01005944 * @see #setDelegatedScopes
5945 * @see #DELEGATION_PACKAGE_ACCESS
Adam Connors655be2a2014-07-14 09:01:25 +00005946 */
Robin Lee25e26452015-06-02 09:56:29 -07005947 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005948 throwIfParentInstance("enableSystemApp");
Adam Connors655be2a2014-07-14 09:01:25 +00005949 if (mService != null) {
5950 try {
Edman Anjos52088e42017-01-13 22:26:17 +01005951 mService.enableSystemApp(admin, mContext.getPackageName(), packageName);
Adam Connors655be2a2014-07-14 09:01:25 +00005952 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005953 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00005954 }
5955 }
5956 }
5957
5958 /**
Edman Anjos52088e42017-01-13 22:26:17 +01005959 * Re-enable system apps by intent that were disabled by default when the user was initialized.
5960 * This function can be called by a device owner, profile owner, or by a delegate given the
5961 * {@link #DELEGATION_ENABLE_SYSTEM_APP} scope via {@link #setDelegatedScopes}.
Adam Connors655be2a2014-07-14 09:01:25 +00005962 *
Edman Anjos52088e42017-01-13 22:26:17 +01005963 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
5964 * {@code null} if the caller is an enable system app delegate.
Adam Connors655be2a2014-07-14 09:01:25 +00005965 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005966 * intent will be re-enabled in the calling profile.
Adam Connors655be2a2014-07-14 09:01:25 +00005967 * @return int The number of activities that matched the intent and were installed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005968 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01005969 * @see #setDelegatedScopes
5970 * @see #DELEGATION_PACKAGE_ACCESS
Adam Connors655be2a2014-07-14 09:01:25 +00005971 */
Robin Lee25e26452015-06-02 09:56:29 -07005972 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005973 throwIfParentInstance("enableSystemApp");
Adam Connors655be2a2014-07-14 09:01:25 +00005974 if (mService != null) {
5975 try {
Edman Anjos52088e42017-01-13 22:26:17 +01005976 return mService.enableSystemAppWithIntent(admin, mContext.getPackageName(), intent);
Adam Connors655be2a2014-07-14 09:01:25 +00005977 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005978 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00005979 }
5980 }
5981 return 0;
5982 }
5983
5984 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00005985 * Called by a device owner or profile owner to disable account management for a specific type
5986 * of account.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005987 * <p>
5988 * The calling device admin must be a device owner or profile owner. If it is not, a security
5989 * exception will be thrown.
5990 * <p>
5991 * When account management is disabled for an account type, adding or removing an account of
5992 * that type will not be possible.
5993 * <p>
5994 * From {@link android.os.Build.VERSION_CODES#N} the profile or device owner can still use
Benjamin Franzb6c0ce42015-11-05 10:06:51 +00005995 * {@link android.accounts.AccountManager} APIs to add or remove accounts when account
5996 * management for a specific type is disabled.
5997 *
Sander Alewijnse650c3342014-05-08 18:00:50 +01005998 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5999 * @param accountType For which account management is disabled or enabled.
6000 * @param disabled The boolean indicating that account management will be disabled (true) or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006001 * enabled (false).
6002 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnse650c3342014-05-08 18:00:50 +01006003 */
Robin Lee25e26452015-06-02 09:56:29 -07006004 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01006005 boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006006 throwIfParentInstance("setAccountManagementDisabled");
Sander Alewijnse650c3342014-05-08 18:00:50 +01006007 if (mService != null) {
6008 try {
6009 mService.setAccountManagementDisabled(admin, accountType, disabled);
6010 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006011 throw e.rethrowFromSystemServer();
Sander Alewijnse650c3342014-05-08 18:00:50 +01006012 }
6013 }
6014 }
6015
6016 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01006017 * Gets the array of accounts for which account management is disabled by the profile owner.
6018 *
6019 * <p> Account management can be disabled/enabled by calling
6020 * {@link #setAccountManagementDisabled}.
6021 *
6022 * @return a list of account types for which account management has been disabled.
6023 *
6024 * @see #setAccountManagementDisabled
6025 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006026 public @Nullable String[] getAccountTypesWithManagementDisabled() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006027 throwIfParentInstance("getAccountTypesWithManagementDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07006028 return getAccountTypesWithManagementDisabledAsUser(myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01006029 }
6030
6031 /**
6032 * @see #getAccountTypesWithManagementDisabled()
6033 * @hide
6034 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006035 public @Nullable String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01006036 if (mService != null) {
6037 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01006038 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01006039 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006040 throw e.rethrowFromSystemServer();
Sander Alewijnse5c02db62014-05-07 10:46:57 +01006041 }
6042 }
6043
6044 return null;
6045 }
justinzhang511e0d82014-03-24 16:09:24 -04006046
6047 /**
Jason Monkd7b86212014-06-16 13:15:38 -04006048 * Sets which packages may enter lock task mode.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006049 * <p>
6050 * Any packages that shares uid with an allowed package will also be allowed to activate lock
6051 * task. From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task
6052 * package list results in locked tasks belonging to those packages to be finished. This
6053 * function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04006054 *
Jason Monkd7b86212014-06-16 13:15:38 -04006055 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04006056 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006057 * @throws SecurityException if {@code admin} is not a device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04006058 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00006059 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
6060 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04006061 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04006062 */
Robin Lee25e26452015-06-02 09:56:29 -07006063 public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04006064 throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006065 throwIfParentInstance("setLockTaskPackages");
justinzhang511e0d82014-03-24 16:09:24 -04006066 if (mService != null) {
6067 try {
Jason Monk48aacba2014-08-13 16:29:08 -04006068 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04006069 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006070 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04006071 }
6072 }
6073 }
6074
6075 /**
Jason Monkd7b86212014-06-16 13:15:38 -04006076 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04006077 *
6078 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04006079 * @hide
6080 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006081 public @NonNull String[] getLockTaskPackages(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006082 throwIfParentInstance("getLockTaskPackages");
justinzhang511e0d82014-03-24 16:09:24 -04006083 if (mService != null) {
6084 try {
Jason Monk48aacba2014-08-13 16:29:08 -04006085 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04006086 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006087 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04006088 }
6089 }
6090 return null;
6091 }
6092
6093 /**
6094 * This function lets the caller know whether the given component is allowed to start the
6095 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04006096 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04006097 */
Jason Monkd7b86212014-06-16 13:15:38 -04006098 public boolean isLockTaskPermitted(String pkg) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006099 throwIfParentInstance("isLockTaskPermitted");
justinzhang511e0d82014-03-24 16:09:24 -04006100 if (mService != null) {
6101 try {
Jason Monkd7b86212014-06-16 13:15:38 -04006102 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04006103 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006104 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04006105 }
6106 }
6107 return false;
6108 }
Julia Reynoldsda551652014-05-14 17:15:16 -04006109
6110 /**
6111 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
6112 * 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 -07006113 * <p>
6114 * The settings that can be updated with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04006115 * <ul>
6116 * <li>{@link Settings.Global#ADB_ENABLED}</li>
6117 * <li>{@link Settings.Global#AUTO_TIME}</li>
6118 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04006119 * <li>{@link Settings.Global#DATA_ROAMING}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04006120 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04006121 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006122 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN} This setting is only available from
6123 * {@link android.os.Build.VERSION_CODES#M} onwards and can only be set if
6124 * {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
6125 * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li> This setting is only
6126 * available from {@link android.os.Build.VERSION_CODES#M} onwards.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04006127 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006128 * <p>
6129 * Changing the following settings has no effect as of {@link android.os.Build.VERSION_CODES#M}:
Esteban Talavera656fa7f2015-06-29 17:41:39 +01006130 * <ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006131 * <li>{@link Settings.Global#BLUETOOTH_ON}. Use
6132 * {@link android.bluetooth.BluetoothAdapter#enable()} and
6133 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01006134 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006135 * <li>{@link Settings.Global#MODE_RINGER}. Use
6136 * {@link android.media.AudioManager#setRingerMode(int)} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01006137 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006138 * <li>{@link Settings.Global#WIFI_ON}. Use
6139 * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01006140 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04006141 *
6142 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6143 * @param setting The name of the setting to update.
6144 * @param value The value to update the setting to.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006145 * @throws SecurityException if {@code admin} is not a device owner.
Julia Reynoldsda551652014-05-14 17:15:16 -04006146 */
Robin Lee25e26452015-06-02 09:56:29 -07006147 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006148 throwIfParentInstance("setGlobalSetting");
Julia Reynoldsda551652014-05-14 17:15:16 -04006149 if (mService != null) {
6150 try {
6151 mService.setGlobalSetting(admin, setting, value);
6152 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006153 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04006154 }
6155 }
6156 }
6157
6158 /**
6159 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
6160 * that the value of the setting is in the correct form for the setting type should be performed
6161 * by the caller.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006162 * <p>
6163 * The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04006164 * <ul>
6165 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07006166 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04006167 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
6168 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006169 * <p>
6170 * A device owner can additionally update the following settings:
Julia Reynolds82735bc2014-09-04 16:43:30 -04006171 * <ul>
6172 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
6173 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006174 *
Julia Reynoldsda551652014-05-14 17:15:16 -04006175 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6176 * @param setting The name of the setting to update.
6177 * @param value The value to update the setting to.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006178 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynoldsda551652014-05-14 17:15:16 -04006179 */
Robin Lee25e26452015-06-02 09:56:29 -07006180 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006181 throwIfParentInstance("setSecureSetting");
Julia Reynoldsda551652014-05-14 17:15:16 -04006182 if (mService != null) {
6183 try {
6184 mService.setSecureSetting(admin, setting, value);
6185 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006186 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04006187 }
6188 }
6189 }
6190
Amith Yamasanif20d6402014-05-24 15:34:37 -07006191 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006192 * Designates a specific service component as the provider for making permission requests of a
6193 * local or remote administrator of the user.
Amith Yamasanif20d6402014-05-24 15:34:37 -07006194 * <p/>
6195 * Only a profile owner can designate the restrictions provider.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006196 *
Amith Yamasanif20d6402014-05-24 15:34:37 -07006197 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07006198 * @param provider The component name of the service that implements
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006199 * {@link RestrictionsReceiver}. If this param is null, it removes the restrictions
6200 * provider previously assigned.
6201 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanif20d6402014-05-24 15:34:37 -07006202 */
Robin Lee25e26452015-06-02 09:56:29 -07006203 public void setRestrictionsProvider(@NonNull ComponentName admin,
6204 @Nullable ComponentName provider) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006205 throwIfParentInstance("setRestrictionsProvider");
Amith Yamasanif20d6402014-05-24 15:34:37 -07006206 if (mService != null) {
6207 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07006208 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07006209 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006210 throw re.rethrowFromSystemServer();
Amith Yamasanif20d6402014-05-24 15:34:37 -07006211 }
6212 }
6213 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04006214
6215 /**
6216 * Called by profile or device owners to set the master volume mute on or off.
Nicolas Prevotaef3ce22016-09-22 12:00:25 +01006217 * This has no effect when set on a managed profile.
Julia Reynolds4a21b252014-06-04 11:11:43 -04006218 *
6219 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6220 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006221 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds4a21b252014-06-04 11:11:43 -04006222 */
Robin Lee25e26452015-06-02 09:56:29 -07006223 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006224 throwIfParentInstance("setMasterVolumeMuted");
Julia Reynolds4a21b252014-06-04 11:11:43 -04006225 if (mService != null) {
6226 try {
6227 mService.setMasterVolumeMuted(admin, on);
6228 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006229 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04006230 }
6231 }
6232 }
6233
6234 /**
6235 * Called by profile or device owners to check whether the master volume mute is on or off.
6236 *
6237 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6238 * @return {@code true} if master volume is muted, {@code false} if it's not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006239 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds4a21b252014-06-04 11:11:43 -04006240 */
Robin Lee25e26452015-06-02 09:56:29 -07006241 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006242 throwIfParentInstance("isMasterVolumeMuted");
Julia Reynolds4a21b252014-06-04 11:11:43 -04006243 if (mService != null) {
6244 try {
6245 return mService.isMasterVolumeMuted(admin);
6246 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006247 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04006248 }
6249 }
6250 return false;
6251 }
Kenny Guyc13053b2014-05-29 14:17:17 +01006252
6253 /**
Edman Anjosa5f2fb12016-12-19 11:25:54 -08006254 * Change whether a user can uninstall a package. This function can be called by a device owner,
6255 * profile owner, or by a delegate given the {@link #DELEGATION_BLOCK_UNINSTALL} scope via
6256 * {@link #setDelegatedScopes}.
Kenny Guyc13053b2014-05-29 14:17:17 +01006257 *
Edman Anjosa5f2fb12016-12-19 11:25:54 -08006258 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
6259 * {@code null} if the caller is a block uninstall delegate.
Kenny Guyc13053b2014-05-29 14:17:17 +01006260 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01006261 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006262 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjosa5f2fb12016-12-19 11:25:54 -08006263 * @see #setDelegatedScopes
6264 * @see #DELEGATION_BLOCK_UNINSTALL
Kenny Guyc13053b2014-05-29 14:17:17 +01006265 */
Edman Anjosa5f2fb12016-12-19 11:25:54 -08006266 public void setUninstallBlocked(@Nullable ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01006267 boolean uninstallBlocked) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006268 throwIfParentInstance("setUninstallBlocked");
Kenny Guyc13053b2014-05-29 14:17:17 +01006269 if (mService != null) {
6270 try {
Edman Anjosa5f2fb12016-12-19 11:25:54 -08006271 mService.setUninstallBlocked(admin, mContext.getPackageName(), packageName,
6272 uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01006273 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006274 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01006275 }
6276 }
6277 }
6278
6279 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08006280 * Check whether the user has been blocked by device policy from uninstalling a package.
Rubin Xua97855b2014-11-07 05:41:00 +00006281 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00006282 * <p>
6283 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006284 * behavior of this API is changed such that passing {@code null} as the {@code admin} parameter
6285 * will return if any admin has blocked the uninstallation. Before L MR1, passing {@code null}
6286 * will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01006287 *
Robin Lee25e26452015-06-02 09:56:29 -07006288 * @param admin The name of the admin component whose blocking policy will be checked, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006289 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01006290 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00006291 * @return true if uninstallation is blocked.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006292 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyc13053b2014-05-29 14:17:17 +01006293 */
Robin Lee25e26452015-06-02 09:56:29 -07006294 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006295 throwIfParentInstance("isUninstallBlocked");
Kenny Guyc13053b2014-05-29 14:17:17 +01006296 if (mService != null) {
6297 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01006298 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01006299 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006300 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01006301 }
6302 }
6303 return false;
6304 }
Svetoslav976e8bd2014-07-16 15:12:03 -07006305
6306 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006307 * Called by the profile owner of a managed profile to enable widget providers from a given
6308 * package to be available in the parent profile. As a result the user will be able to add
6309 * widgets from the white-listed package running under the profile to a widget host which runs
6310 * under the parent profile, for example the home screen. Note that a package may have zero or
6311 * more provider components, where each component provides a different widget type.
Svetoslav976e8bd2014-07-16 15:12:03 -07006312 * <p>
6313 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07006314 *
6315 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6316 * @param packageName The package from which widget providers are white-listed.
6317 * @return Whether the package was added.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006318 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07006319 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
6320 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
6321 */
Robin Lee25e26452015-06-02 09:56:29 -07006322 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006323 throwIfParentInstance("addCrossProfileWidgetProvider");
Svetoslav976e8bd2014-07-16 15:12:03 -07006324 if (mService != null) {
6325 try {
6326 return mService.addCrossProfileWidgetProvider(admin, packageName);
6327 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006328 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07006329 }
6330 }
6331 return false;
6332 }
6333
6334 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07006335 * Called by the profile owner of a managed profile to disable widget providers from a given
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006336 * package to be available in the parent profile. For this method to take effect the package
6337 * should have been added via
6338 * {@link #addCrossProfileWidgetProvider( android.content.ComponentName, String)}.
Svetoslav976e8bd2014-07-16 15:12:03 -07006339 * <p>
6340 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07006341 *
6342 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006343 * @param packageName The package from which widget providers are no longer white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07006344 * @return Whether the package was removed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006345 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07006346 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
6347 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
6348 */
Esteban Talavera62399912016-01-11 15:37:55 +00006349 public boolean removeCrossProfileWidgetProvider(
6350 @NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006351 throwIfParentInstance("removeCrossProfileWidgetProvider");
Svetoslav976e8bd2014-07-16 15:12:03 -07006352 if (mService != null) {
6353 try {
6354 return mService.removeCrossProfileWidgetProvider(admin, packageName);
6355 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006356 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07006357 }
6358 }
6359 return false;
6360 }
6361
6362 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07006363 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07006364 * available in the parent profile.
6365 *
6366 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6367 * @return The white-listed package list.
Svetoslav976e8bd2014-07-16 15:12:03 -07006368 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
6369 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006370 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07006371 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006372 public @NonNull List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006373 throwIfParentInstance("getCrossProfileWidgetProviders");
Svetoslav976e8bd2014-07-16 15:12:03 -07006374 if (mService != null) {
6375 try {
6376 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
6377 if (providers != null) {
6378 return providers;
6379 }
6380 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006381 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07006382 }
6383 }
6384 return Collections.emptyList();
6385 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006386
6387 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08006388 * Called by profile or device owners to set the user's photo.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006389 *
6390 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6391 * @param icon the bitmap to set as the photo.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006392 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006393 */
Robin Lee25e26452015-06-02 09:56:29 -07006394 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006395 throwIfParentInstance("setUserIcon");
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006396 try {
6397 mService.setUserIcon(admin, icon);
6398 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006399 throw re.rethrowFromSystemServer();
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006400 }
6401 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04006402
6403 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01006404 * Called by device owners to set a local system update policy. When a new policy is set,
6405 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00006406 *
Robin Lee25e26452015-06-02 09:56:29 -07006407 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006408 * components in the device owner package can set system update policies and the most
6409 * recent policy takes effect.
Robin Lee25e26452015-06-02 09:56:29 -07006410 * @param policy the new policy, or {@code null} to clear the current policy.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006411 * @throws SecurityException if {@code admin} is not a device owner.
Rubin Xu5faad8e2015-04-20 17:43:48 +01006412 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00006413 */
Robin Lee25e26452015-06-02 09:56:29 -07006414 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006415 throwIfParentInstance("setSystemUpdatePolicy");
Rubin Xu8027a4f2015-03-10 17:52:37 +00006416 if (mService != null) {
6417 try {
Robin Lee25e26452015-06-02 09:56:29 -07006418 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00006419 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006420 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00006421 }
6422 }
6423 }
6424
6425 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01006426 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00006427 *
Robin Lee25e26452015-06-02 09:56:29 -07006428 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00006429 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006430 public @Nullable SystemUpdatePolicy getSystemUpdatePolicy() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006431 throwIfParentInstance("getSystemUpdatePolicy");
Rubin Xu8027a4f2015-03-10 17:52:37 +00006432 if (mService != null) {
6433 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01006434 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00006435 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006436 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00006437 }
6438 }
6439 return null;
6440 }
Benjamin Franze36087e2015-04-07 16:40:34 +01006441
6442 /**
6443 * Called by a device owner to disable the keyguard altogether.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006444 * <p>
6445 * Setting the keyguard to disabled has the same effect as choosing "None" as the screen lock
6446 * type. However, this call has no effect if a password, pin or pattern is currently set. If a
6447 * password, pin or pattern is set after the keyguard was disabled, the keyguard stops being
6448 * disabled.
Benjamin Franze36087e2015-04-07 16:40:34 +01006449 *
6450 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01006451 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01006452 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006453 * place. {@code true} otherwise.
6454 * @throws SecurityException if {@code admin} is not a device owner.
Benjamin Franze36087e2015-04-07 16:40:34 +01006455 */
Robin Lee25e26452015-06-02 09:56:29 -07006456 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006457 throwIfParentInstance("setKeyguardDisabled");
Benjamin Franze36087e2015-04-07 16:40:34 +01006458 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01006459 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01006460 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006461 throw re.rethrowFromSystemServer();
Benjamin Franze36087e2015-04-07 16:40:34 +01006462 }
6463 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00006464
6465 /**
Benjamin Franzbece8062015-05-06 12:14:31 +01006466 * Called by device owner to disable the status bar. Disabling the status bar blocks
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006467 * notifications, quick settings and other screen overlays that allow escaping from a single use
6468 * device.
Benjamin Franzea2ec972015-03-16 17:18:09 +00006469 *
6470 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01006471 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006472 * @return {@code false} if attempting to disable the status bar failed. {@code true} otherwise.
6473 * @throws SecurityException if {@code admin} is not a device owner.
Benjamin Franzea2ec972015-03-16 17:18:09 +00006474 */
Robin Lee25e26452015-06-02 09:56:29 -07006475 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006476 throwIfParentInstance("setStatusBarDisabled");
Benjamin Franzea2ec972015-03-16 17:18:09 +00006477 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01006478 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00006479 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006480 throw re.rethrowFromSystemServer();
Benjamin Franzea2ec972015-03-16 17:18:09 +00006481 }
6482 }
Rubin Xudc105cc2015-04-14 23:38:01 +01006483
6484 /**
Charles Hedea0c3b2017-01-13 10:04:12 +00006485 * Called by the system update service to notify device and profile owners of pending system
6486 * updates.
Rubin Xudc105cc2015-04-14 23:38:01 +01006487 *
Charles Hedea0c3b2017-01-13 10:04:12 +00006488 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
6489 * permission. This method should only be used when it is unknown whether the pending system
6490 * update is a security patch. Otherwise, use
6491 * {@link #notifyPendingSystemUpdate(long, boolean)}.
6492 *
6493 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()}
6494 * indicating when the current pending update was first available. {@code -1} if no
6495 * update is available.
6496 * @see #notifyPendingSystemUpdate(long, boolean)
Rubin Xudc105cc2015-04-14 23:38:01 +01006497 * @hide
6498 */
6499 @SystemApi
6500 public void notifyPendingSystemUpdate(long updateReceivedTime) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006501 throwIfParentInstance("notifyPendingSystemUpdate");
Rubin Xudc105cc2015-04-14 23:38:01 +01006502 if (mService != null) {
6503 try {
Charles Hedea0c3b2017-01-13 10:04:12 +00006504 mService.notifyPendingSystemUpdate(SystemUpdateInfo.of(updateReceivedTime));
6505 } catch (RemoteException re) {
6506 throw re.rethrowFromSystemServer();
6507 }
6508 }
6509 }
6510
6511 /**
6512 * Called by the system update service to notify device and profile owners of pending system
6513 * updates.
6514 *
6515 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
6516 * permission. This method should be used instead of {@link #notifyPendingSystemUpdate(long)}
6517 * when it is known whether the pending system update is a security patch.
6518 *
6519 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()}
6520 * indicating when the current pending update was first available. {@code -1} if no
6521 * update is available.
6522 * @param isSecurityPatch {@code true} if this system update is purely a security patch;
6523 * {@code false} if not.
6524 * @see #notifyPendingSystemUpdate(long)
6525 * @hide
6526 */
6527 @SystemApi
6528 public void notifyPendingSystemUpdate(long updateReceivedTime, boolean isSecurityPatch) {
6529 throwIfParentInstance("notifyPendingSystemUpdate");
6530 if (mService != null) {
6531 try {
6532 mService.notifyPendingSystemUpdate(SystemUpdateInfo.of(updateReceivedTime,
6533 isSecurityPatch));
Rubin Xudc105cc2015-04-14 23:38:01 +01006534 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006535 throw re.rethrowFromSystemServer();
Rubin Xudc105cc2015-04-14 23:38:01 +01006536 }
6537 }
6538 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04006539
6540 /**
Pavel Grafovd65799e2016-12-02 11:21:45 +00006541 * Called by device or profile owners to get information about a pending system update.
6542 *
6543 * @param admin Which profile or device owner this request is associated with.
6544 * @return Information about a pending system update or {@code null} if no update pending.
6545 * @throws SecurityException if {@code admin} is not a device or profile owner.
6546 * @see DeviceAdminReceiver#onSystemUpdatePending(Context, Intent, long)
6547 */
6548 public @Nullable SystemUpdateInfo getPendingSystemUpdate(@NonNull ComponentName admin) {
6549 throwIfParentInstance("getPendingSystemUpdate");
6550 try {
6551 return mService.getPendingSystemUpdate(admin);
6552 } catch (RemoteException re) {
6553 throw re.rethrowFromSystemServer();
6554 }
6555 }
6556
6557 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006558 * Set the default response for future runtime permission requests by applications. This
6559 * function can be called by a device owner, profile owner, or by a delegate given the
6560 * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}.
6561 * The policy can allow for normal operation which prompts the user to grant a permission, or
6562 * can allow automatic granting or denying of runtime permission requests by an application.
6563 * This also applies to new permissions declared by app updates. When a permission is denied or
6564 * granted this way, the effect is equivalent to setting the permission * grant state via
6565 * {@link #setPermissionGrantState}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006566 * <p/>
6567 * As this policy only acts on runtime permission requests, it only applies to applications
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07006568 * built with a {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Benjamin Franz45dd6662015-07-08 14:24:14 +01006569 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07006570 * @param admin Which profile or device owner this request is associated with.
6571 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006572 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
6573 * @throws SecurityException if {@code admin} is not a device or profile owner.
Benjamin Franz45dd6662015-07-08 14:24:14 +01006574 * @see #setPermissionGrantState
Edman Anjos52088e42017-01-13 22:26:17 +01006575 * @see #setDelegatedScopes
6576 * @see #DELEGATION_PERMISSION_GRANT
Amith Yamasanid49489b2015-04-28 14:00:26 -07006577 */
Robin Lee25e26452015-06-02 09:56:29 -07006578 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006579 throwIfParentInstance("setPermissionPolicy");
Amith Yamasanid49489b2015-04-28 14:00:26 -07006580 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006581 mService.setPermissionPolicy(admin, mContext.getPackageName(), policy);
Amith Yamasanid49489b2015-04-28 14:00:26 -07006582 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006583 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07006584 }
6585 }
6586
6587 /**
6588 * Returns the current runtime permission policy set by the device or profile owner. The
6589 * default is {@link #PERMISSION_POLICY_PROMPT}.
Edman Anjos52088e42017-01-13 22:26:17 +01006590 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07006591 * @param admin Which profile or device owner this request is associated with.
6592 * @return the current policy for future permission requests.
6593 */
Esteban Talavera28b95702015-06-24 15:23:42 +01006594 public int getPermissionPolicy(ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006595 throwIfParentInstance("getPermissionPolicy");
Amith Yamasanid49489b2015-04-28 14:00:26 -07006596 try {
6597 return mService.getPermissionPolicy(admin);
6598 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006599 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07006600 }
6601 }
6602
6603 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006604 * Sets the grant state of a runtime permission for a specific application. The state can be
6605 * {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it through the UI,
6606 * {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission is denied and the user
6607 * cannot manage it through the UI, and {@link #PERMISSION_GRANT_STATE_GRANTED granted} in which
6608 * the permission is granted and the user cannot manage it through the UI. This might affect all
6609 * permissions in a group that the runtime permission belongs to. This method can only be called
Edman Anjos52088e42017-01-13 22:26:17 +01006610 * by a profile owner, device owner, or a delegate given the
6611 * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006612 * <p/>
6613 * Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not revoke
6614 * the permission. It retains the previous grant, if any.
6615 * <p/>
6616 * Permissions can be granted or revoked only for applications built with a
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07006617 * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07006618 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07006619 * @param admin Which profile or device owner this request is associated with.
6620 * @param packageName The application to grant or revoke a permission to.
6621 * @param permission The permission to grant or revoke.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006622 * @param grantState The permission grant state which is one of
6623 * {@link #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
6624 * {@link #PERMISSION_GRANT_STATE_GRANTED},
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006625 * @return whether the permission was successfully granted or revoked.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006626 * @throws SecurityException if {@code admin} is not a device or profile owner.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006627 * @see #PERMISSION_GRANT_STATE_DENIED
6628 * @see #PERMISSION_GRANT_STATE_DEFAULT
6629 * @see #PERMISSION_GRANT_STATE_GRANTED
Edman Anjos52088e42017-01-13 22:26:17 +01006630 * @see #setDelegatedScopes
6631 * @see #DELEGATION_PERMISSION_GRANT
Amith Yamasanid49489b2015-04-28 14:00:26 -07006632 */
Robin Lee25e26452015-06-02 09:56:29 -07006633 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006634 String permission, int grantState) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006635 throwIfParentInstance("setPermissionGrantState");
Amith Yamasanid49489b2015-04-28 14:00:26 -07006636 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006637 return mService.setPermissionGrantState(admin, mContext.getPackageName(), packageName,
6638 permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07006639 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006640 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07006641 }
6642 }
Amith Yamasani184b3752015-05-22 13:00:51 -07006643
6644 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006645 * Returns the current grant state of a runtime permission for a specific application. This
6646 * function can be called by a device owner, profile owner, or by a delegate given the
6647 * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}.
Amith Yamasani184b3752015-05-22 13:00:51 -07006648 *
Edman Anjos52088e42017-01-13 22:26:17 +01006649 * @param admin Which profile or device owner this request is associated with, or {@code null}
6650 * if the caller is a permission grant delegate.
Amith Yamasani184b3752015-05-22 13:00:51 -07006651 * @param packageName The application to check the grant state for.
6652 * @param permission The permission to check for.
6653 * @return the current grant state specified by device policy. If the profile or device owner
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006654 * has not set a grant state, the return value is
6655 * {@link #PERMISSION_GRANT_STATE_DEFAULT}. This does not indicate whether or not the
6656 * permission is currently granted for the package.
6657 * <p/>
6658 * If a grant state was set by the profile or device owner, then the return value will
6659 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or
6660 * {@link #PERMISSION_GRANT_STATE_GRANTED}, which indicates if the permission is
6661 * currently denied or granted.
6662 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasani184b3752015-05-22 13:00:51 -07006663 * @see #setPermissionGrantState(ComponentName, String, String, int)
6664 * @see PackageManager#checkPermission(String, String)
Edman Anjos52088e42017-01-13 22:26:17 +01006665 * @see #setDelegatedScopes
6666 * @see #DELEGATION_PERMISSION_GRANT
Amith Yamasani184b3752015-05-22 13:00:51 -07006667 */
Bartosz Fabianowski4b0624f2017-01-16 11:47:28 +01006668 public int getPermissionGrantState(@Nullable ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07006669 String permission) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006670 throwIfParentInstance("getPermissionGrantState");
Amith Yamasani184b3752015-05-22 13:00:51 -07006671 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006672 return mService.getPermissionGrantState(admin, mContext.getPackageName(), packageName,
6673 permission);
Amith Yamasani184b3752015-05-22 13:00:51 -07006674 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006675 throw re.rethrowFromSystemServer();
Amith Yamasani184b3752015-05-22 13:00:51 -07006676 }
6677 }
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006678
6679 /**
Esteban Talavera01576862016-12-15 11:16:44 +00006680 * Returns whether it is possible for the caller to initiate provisioning of a managed profile
6681 * or device, setting itself as the device or profile owner.
6682 *
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006683 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
6684 * {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Esteban Talavera01576862016-12-15 11:16:44 +00006685 * @return whether provisioning a managed profile or device is possible.
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006686 * @throws IllegalArgumentException if the supplied action is not valid.
6687 */
Esteban Talavera01576862016-12-15 11:16:44 +00006688 public boolean isProvisioningAllowed(@NonNull String action) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006689 throwIfParentInstance("isProvisioningAllowed");
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006690 try {
Esteban Talavera01576862016-12-15 11:16:44 +00006691 return mService.isProvisioningAllowed(action, mContext.getPackageName());
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006692 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006693 throw re.rethrowFromSystemServer();
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006694 }
6695 }
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006696
6697 /**
Esteban Talavera01576862016-12-15 11:16:44 +00006698 * Checks whether it is possible to initiate provisioning a managed device,
6699 * profile or user, setting the given package as owner.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00006700 *
6701 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
6702 * {@link #ACTION_PROVISION_MANAGED_PROFILE},
6703 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE},
6704 * {@link #ACTION_PROVISION_MANAGED_USER}
Esteban Talavera01576862016-12-15 11:16:44 +00006705 * @param packageName The package of the component that would be set as device, user, or profile
6706 * owner.
6707 * @return A {@link ProvisioningPreCondition} value indicating whether provisioning is allowed.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00006708 * @hide
6709 */
Esteban Talavera01576862016-12-15 11:16:44 +00006710 public @ProvisioningPreCondition int checkProvisioningPreCondition(
6711 String action, @NonNull String packageName) {
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00006712 try {
Esteban Talavera01576862016-12-15 11:16:44 +00006713 return mService.checkProvisioningPreCondition(action, packageName);
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00006714 } catch (RemoteException re) {
6715 throw re.rethrowFromSystemServer();
6716 }
6717 }
6718
6719 /**
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006720 * Return if this user is a managed profile of another user. An admin can become the profile
6721 * owner of a managed profile with {@link #ACTION_PROVISION_MANAGED_PROFILE} and of a managed
Kenny Guyffa38402016-03-31 16:40:57 +01006722 * user with {@link #createAndManageUser}
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006723 * @param admin Which profile owner this request is associated with.
6724 * @return if this user is a managed profile of another user.
6725 */
6726 public boolean isManagedProfile(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006727 throwIfParentInstance("isManagedProfile");
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006728 try {
6729 return mService.isManagedProfile(admin);
6730 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006731 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006732 }
6733 }
6734
6735 /**
6736 * @hide
6737 * Return if this user is a system-only user. An admin can manage a device from a system only
6738 * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}.
6739 * @param admin Which device owner this request is associated with.
6740 * @return if this user is a system-only user.
6741 */
6742 public boolean isSystemOnlyUser(@NonNull ComponentName admin) {
6743 try {
6744 return mService.isSystemOnlyUser(admin);
6745 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006746 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006747 }
6748 }
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006749
6750 /**
6751 * Called by device owner to get the MAC address of the Wi-Fi device.
6752 *
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08006753 * @param admin Which device owner this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006754 * @return the MAC address of the Wi-Fi device, or null when the information is not available.
6755 * (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.)
6756 * <p>
6757 * The address will be in the {@code XX:XX:XX:XX:XX:XX} format.
6758 * @throws SecurityException if {@code admin} is not a device owner.
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006759 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006760 public @Nullable String getWifiMacAddress(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006761 throwIfParentInstance("getWifiMacAddress");
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006762 try {
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08006763 return mService.getWifiMacAddress(admin);
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006764 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006765 throw re.rethrowFromSystemServer();
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006766 }
6767 }
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00006768
6769 /**
Mahaver Chopra1216ae52016-03-11 15:39:48 +00006770 * Called by device owner to reboot the device. If there is an ongoing call on the device,
6771 * throws an {@link IllegalStateException}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006772 * @param admin Which device owner the request is associated with.
Mahaver Chopra1216ae52016-03-11 15:39:48 +00006773 * @throws IllegalStateException if device has an ongoing call.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006774 * @throws SecurityException if {@code admin} is not a device owner.
Mahaver Chopra1216ae52016-03-11 15:39:48 +00006775 * @see TelephonyManager#CALL_STATE_IDLE
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00006776 */
6777 public void reboot(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006778 throwIfParentInstance("reboot");
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00006779 try {
6780 mService.reboot(admin);
6781 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006782 throw re.rethrowFromSystemServer();
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00006783 }
6784 }
Kenny Guy06de4e72015-12-22 12:07:39 +00006785
6786 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006787 * Called by a device admin to set the short support message. This will be displayed to the user
6788 * in settings screens where funtionality has been disabled by the admin. The message should be
6789 * limited to a short statement such as "This setting is disabled by your administrator. Contact
6790 * someone@example.com for support." If the message is longer than 200 characters it may be
6791 * truncated.
6792 * <p>
6793 * If the short support message needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006794 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
6795 * and set a new version of this string accordingly.
6796 *
Kenny Guy06de4e72015-12-22 12:07:39 +00006797 * @see #setLongSupportMessage
Kenny Guy06de4e72015-12-22 12:07:39 +00006798 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006799 * @param message Short message to be displayed to the user in settings or null to clear the
6800 * existing message.
6801 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00006802 */
6803 public void setShortSupportMessage(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006804 @Nullable CharSequence message) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006805 throwIfParentInstance("setShortSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00006806 if (mService != null) {
6807 try {
6808 mService.setShortSupportMessage(admin, message);
6809 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006810 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006811 }
6812 }
6813 }
6814
6815 /**
6816 * Called by a device admin to get the short support message.
6817 *
6818 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006819 * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)} or
6820 * null if no message has been set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006821 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00006822 */
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006823 public CharSequence getShortSupportMessage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006824 throwIfParentInstance("getShortSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00006825 if (mService != null) {
6826 try {
6827 return mService.getShortSupportMessage(admin);
6828 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006829 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006830 }
6831 }
6832 return null;
6833 }
6834
6835 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006836 * Called by a device admin to set the long support message. This will be displayed to the user
6837 * in the device administators settings screen.
6838 * <p>
6839 * If the long support message needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006840 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
6841 * and set a new version of this string accordingly.
6842 *
Kenny Guy06de4e72015-12-22 12:07:39 +00006843 * @see #setShortSupportMessage
Kenny Guy06de4e72015-12-22 12:07:39 +00006844 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006845 * @param message Long message to be displayed to the user in settings or null to clear the
6846 * existing message.
6847 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00006848 */
6849 public void setLongSupportMessage(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006850 @Nullable CharSequence message) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006851 throwIfParentInstance("setLongSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00006852 if (mService != null) {
6853 try {
6854 mService.setLongSupportMessage(admin, message);
6855 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006856 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006857 }
6858 }
6859 }
6860
6861 /**
6862 * Called by a device admin to get the long support message.
6863 *
6864 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006865 * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)} or
6866 * null if no message has been set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006867 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00006868 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006869 public @Nullable CharSequence getLongSupportMessage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006870 throwIfParentInstance("getLongSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00006871 if (mService != null) {
6872 try {
6873 return mService.getLongSupportMessage(admin);
6874 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006875 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006876 }
6877 }
6878 return null;
6879 }
6880
6881 /**
6882 * Called by the system to get the short support message.
6883 *
6884 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6885 * @param userHandle user id the admin is running as.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006886 * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)}
Kenny Guy06de4e72015-12-22 12:07:39 +00006887 *
6888 * @hide
6889 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006890 public @Nullable CharSequence getShortSupportMessageForUser(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006891 int userHandle) {
Kenny Guy06de4e72015-12-22 12:07:39 +00006892 if (mService != null) {
6893 try {
6894 return mService.getShortSupportMessageForUser(admin, userHandle);
6895 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006896 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006897 }
6898 }
6899 return null;
6900 }
6901
6902
6903 /**
6904 * Called by the system to get the long support message.
6905 *
6906 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6907 * @param userHandle user id the admin is running as.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006908 * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)}
Kenny Guy06de4e72015-12-22 12:07:39 +00006909 *
6910 * @hide
6911 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006912 public @Nullable CharSequence getLongSupportMessageForUser(
6913 @NonNull ComponentName admin, int userHandle) {
Kenny Guy06de4e72015-12-22 12:07:39 +00006914 if (mService != null) {
6915 try {
6916 return mService.getLongSupportMessageForUser(admin, userHandle);
6917 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006918 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006919 }
6920 }
6921 return null;
6922 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006923
6924 /**
Esteban Talavera62399912016-01-11 15:37:55 +00006925 * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager}
6926 * whose calls act on the parent profile.
Benjamin Franz66b45f02016-04-05 19:12:39 +01006927 *
6928 * <p>The following methods are supported for the parent instance, all other methods will
6929 * throw a SecurityException when called on the parent instance:
6930 * <ul>
6931 * <li>{@link #getPasswordQuality}</li>
6932 * <li>{@link #setPasswordQuality}</li>
6933 * <li>{@link #getPasswordMinimumLength}</li>
6934 * <li>{@link #setPasswordMinimumLength}</li>
6935 * <li>{@link #getPasswordMinimumUpperCase}</li>
6936 * <li>{@link #setPasswordMinimumUpperCase}</li>
6937 * <li>{@link #getPasswordMinimumLowerCase}</li>
6938 * <li>{@link #setPasswordMinimumLowerCase}</li>
6939 * <li>{@link #getPasswordMinimumLetters}</li>
6940 * <li>{@link #setPasswordMinimumLetters}</li>
6941 * <li>{@link #getPasswordMinimumNumeric}</li>
6942 * <li>{@link #setPasswordMinimumNumeric}</li>
6943 * <li>{@link #getPasswordMinimumSymbols}</li>
6944 * <li>{@link #setPasswordMinimumSymbols}</li>
6945 * <li>{@link #getPasswordMinimumNonLetter}</li>
6946 * <li>{@link #setPasswordMinimumNonLetter}</li>
6947 * <li>{@link #getPasswordHistoryLength}</li>
6948 * <li>{@link #setPasswordHistoryLength}</li>
6949 * <li>{@link #getPasswordExpirationTimeout}</li>
6950 * <li>{@link #setPasswordExpirationTimeout}</li>
6951 * <li>{@link #getPasswordExpiration}</li>
Charles He8c760562016-10-25 16:36:53 +01006952 * <li>{@link #getPasswordMaximumLength}</li>
Benjamin Franz66b45f02016-04-05 19:12:39 +01006953 * <li>{@link #isActivePasswordSufficient}</li>
6954 * <li>{@link #getCurrentFailedPasswordAttempts}</li>
6955 * <li>{@link #getMaximumFailedPasswordsForWipe}</li>
6956 * <li>{@link #setMaximumFailedPasswordsForWipe}</li>
6957 * <li>{@link #getMaximumTimeToLock}</li>
6958 * <li>{@link #setMaximumTimeToLock}</li>
6959 * <li>{@link #lockNow}</li>
6960 * <li>{@link #getKeyguardDisabledFeatures}</li>
6961 * <li>{@link #setKeyguardDisabledFeatures}</li>
6962 * <li>{@link #getTrustAgentConfiguration}</li>
6963 * <li>{@link #setTrustAgentConfiguration}</li>
Michal Karpinskia20d8bb2016-11-23 12:09:08 +00006964 * <li>{@link #getRequiredStrongAuthTimeout}</li>
6965 * <li>{@link #setRequiredStrongAuthTimeout}</li>
Benjamin Franz66b45f02016-04-05 19:12:39 +01006966 * </ul>
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006967 *
6968 * @return a new instance of {@link DevicePolicyManager} that acts on the parent profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006969 * @throws SecurityException if {@code admin} is not a profile owner.
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006970 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006971 public @NonNull DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006972 throwIfParentInstance("getParentProfileInstance");
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006973 try {
6974 if (!mService.isManagedProfile(admin)) {
6975 throw new SecurityException("The current user does not have a parent profile.");
6976 }
Jeff Sharkey49ca5292016-05-10 12:54:45 -06006977 return new DevicePolicyManager(mContext, mService, true);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006978 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006979 throw e.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006980 }
6981 }
6982
6983 /**
Esteban Talaverad36dd152016-12-15 08:51:45 +00006984 * Called by device owner to control the security logging feature.
Michal Karpinski6235a942016-03-15 12:07:23 +00006985 *
6986 * <p> Security logs contain various information intended for security auditing purposes.
6987 * See {@link SecurityEvent} for details.
6988 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00006989 * <p><strong>Note:</strong> The device owner won't be able to retrieve security logs if there
6990 * are unaffiliated secondary users or profiles on the device, regardless of whether the
6991 * feature is enabled. Logs will be discarded if the internal buffer fills up while waiting for
6992 * all users to become affiliated. Therefore it's recommended that affiliation ids are set for
6993 * new users as soon as possible after provisioning via {@link #setAffiliationIds}.
Michal Karpinskib58e4962016-03-01 14:55:10 +00006994 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006995 * @param admin Which device owner this request is associated with.
Michal Karpinski6235a942016-03-15 12:07:23 +00006996 * @param enabled whether security logging should be enabled or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006997 * @throws SecurityException if {@code admin} is not a device owner.
Michal Karpinski6235a942016-03-15 12:07:23 +00006998 * @see #retrieveSecurityLogs
6999 */
7000 public void setSecurityLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007001 throwIfParentInstance("setSecurityLoggingEnabled");
Michal Karpinski6235a942016-03-15 12:07:23 +00007002 try {
7003 mService.setSecurityLoggingEnabled(admin, enabled);
7004 } catch (RemoteException re) {
7005 throw re.rethrowFromSystemServer();
7006 }
7007 }
7008
7009 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00007010 * Return whether security logging is enabled or not by the device owner.
7011 *
7012 * <p>Can only be called by the device owner, otherwise a {@link SecurityException} will be
7013 * thrown.
7014 *
7015 * @param admin Which device owner this request is associated with.
7016 * @return {@code true} if security logging is enabled by device owner, {@code false} otherwise.
7017 * @throws SecurityException if {@code admin} is not a device owner.
7018 */
7019 public boolean isSecurityLoggingEnabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007020 throwIfParentInstance("isSecurityLoggingEnabled");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007021 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00007022 return mService.isSecurityLoggingEnabled(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007023 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007024 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007025 }
7026 }
7027
7028 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00007029 * Called by device owner to retrieve all new security logging entries since the last call to
7030 * this API after device boots.
7031 *
7032 * <p> Access to the logs is rate limited and it will only return new logs after the device
7033 * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}.
7034 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00007035 * <p>If there is any other user or profile on the device, it must be affiliated with the
7036 * device owner. Otherwise a {@link SecurityException} will be thrown. See
7037 * {@link #setAffiliationIds}
Michal Karpinskib58e4962016-03-01 14:55:10 +00007038 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007039 * @param admin Which device owner this request is associated with.
Michal Karpinski6235a942016-03-15 12:07:23 +00007040 * @return the new batch of security logs which is a list of {@link SecurityEvent},
7041 * or {@code null} if rate limitation is exceeded or if logging is currently disabled.
Esteban Talaverad36dd152016-12-15 08:51:45 +00007042 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
7043 * profile or secondary user that is not affiliated with the device owner user.
7044 * @see DeviceAdminReceiver#onSecurityLogsAvailable
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007045 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007046 public @Nullable List<SecurityEvent> retrieveSecurityLogs(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007047 throwIfParentInstance("retrieveSecurityLogs");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007048 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00007049 ParceledListSlice<SecurityEvent> list = mService.retrieveSecurityLogs(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007050 if (list != null) {
7051 return list.getList();
7052 } else {
7053 // Rate limit exceeded.
7054 return null;
7055 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00007056 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007057 throw re.rethrowFromSystemServer();
Clara Bayarri3e826ef2015-12-14 17:51:22 +00007058 }
7059 }
Benjamin Franz59720bb2016-01-18 15:26:11 +00007060
7061 /**
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00007062 * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent
7063 * profile.
7064 *
7065 * @hide
7066 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007067 public @NonNull DevicePolicyManager getParentProfileInstance(UserInfo uInfo) {
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00007068 mContext.checkSelfPermission(
7069 android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS);
7070 if (!uInfo.isManagedProfile()) {
7071 throw new SecurityException("The user " + uInfo.id
7072 + " does not have a parent profile.");
7073 }
Jeff Sharkey49ca5292016-05-10 12:54:45 -06007074 return new DevicePolicyManager(mContext, mService, true);
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00007075 }
7076
7077 /**
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007078 * Called by device owners to retrieve device logs from before the device's last reboot.
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007079 * <p>
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01007080 * <strong> This API is not supported on all devices. Calling this API on unsupported devices
7081 * will result in {@code null} being returned. The device logs are retrieved from a RAM region
7082 * which is not guaranteed to be corruption-free during power cycles, as a result be cautious
7083 * about data corruption when parsing. </strong>
Esteban Talaverad36dd152016-12-15 08:51:45 +00007084 *
7085 * <p>If there is any other user or profile on the device, it must be affiliated with the
7086 * device owner. Otherwise a {@link SecurityException} will be thrown. See
7087 * {@link #setAffiliationIds}
Michal Karpinskib58e4962016-03-01 14:55:10 +00007088 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007089 * @param admin Which device owner this request is associated with.
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01007090 * @return Device logs from before the latest reboot of the system, or {@code null} if this API
7091 * is not supported on the device.
Esteban Talaverad36dd152016-12-15 08:51:45 +00007092 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
7093 * profile or secondary user that is not affiliated with the device owner user.
7094 * @see #retrieveSecurityLogs
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007095 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007096 public @Nullable List<SecurityEvent> retrievePreRebootSecurityLogs(
7097 @NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007098 throwIfParentInstance("retrievePreRebootSecurityLogs");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007099 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00007100 ParceledListSlice<SecurityEvent> list = mService.retrievePreRebootSecurityLogs(admin);
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01007101 if (list != null) {
7102 return list.getList();
7103 } else {
7104 return null;
7105 }
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007106 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007107 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007108 }
7109 }
7110
7111 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007112 * Called by a profile owner of a managed profile to set the color used for customization. This
7113 * color is used as background color of the confirm credentials screen for that user. The
Clara Bayarri8d0bd7fa2016-03-30 14:59:58 +01007114 * default color is teal (#00796B).
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007115 * <p>
7116 * The confirm credentials screen can be created using
Benjamin Franz59720bb2016-01-18 15:26:11 +00007117 * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}.
7118 *
7119 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinski74cd7302016-04-12 15:17:36 +01007120 * @param color The 24bit (0xRRGGBB) representation of the color to be used.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007121 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz59720bb2016-01-18 15:26:11 +00007122 */
7123 public void setOrganizationColor(@NonNull ComponentName admin, int color) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007124 throwIfParentInstance("setOrganizationColor");
Benjamin Franz59720bb2016-01-18 15:26:11 +00007125 try {
Michal Karpinski74cd7302016-04-12 15:17:36 +01007126 // always enforce alpha channel to have 100% opacity
7127 color |= 0xFF000000;
Benjamin Franz59720bb2016-01-18 15:26:11 +00007128 mService.setOrganizationColor(admin, color);
7129 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007130 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00007131 }
7132 }
7133
7134 /**
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00007135 * @hide
7136 *
7137 * Sets the color used for customization.
7138 *
Michal Karpinski74cd7302016-04-12 15:17:36 +01007139 * @param color The 24bit (0xRRGGBB) representation of the color to be used.
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00007140 * @param userId which user to set the color to.
7141 * @RequiresPermission(allOf = {
7142 * Manifest.permission.MANAGE_USERS,
7143 * Manifest.permission.INTERACT_ACROSS_USERS_FULL})
7144 */
7145 public void setOrganizationColorForUser(@ColorInt int color, @UserIdInt int userId) {
7146 try {
Michal Karpinski74cd7302016-04-12 15:17:36 +01007147 // always enforce alpha channel to have 100% opacity
7148 color |= 0xFF000000;
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00007149 mService.setOrganizationColorForUser(color, userId);
7150 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007151 throw re.rethrowFromSystemServer();
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00007152 }
7153 }
7154
7155 /**
Benjamin Franz59720bb2016-01-18 15:26:11 +00007156 * Called by a profile owner of a managed profile to retrieve the color used for customization.
7157 * This color is used as background color of the confirm credentials screen for that user.
7158 *
7159 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinski74cd7302016-04-12 15:17:36 +01007160 * @return The 24bit (0xRRGGBB) representation of the color to be used.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007161 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz59720bb2016-01-18 15:26:11 +00007162 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01007163 public @ColorInt int getOrganizationColor(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007164 throwIfParentInstance("getOrganizationColor");
Benjamin Franz59720bb2016-01-18 15:26:11 +00007165 try {
7166 return mService.getOrganizationColor(admin);
7167 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007168 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00007169 }
7170 }
7171
7172 /**
7173 * @hide
7174 * Retrieve the customization color for a given user.
7175 *
7176 * @param userHandle The user id of the user we're interested in.
Michal Karpinski74cd7302016-04-12 15:17:36 +01007177 * @return The 24bit (0xRRGGBB) representation of the color to be used.
Benjamin Franz59720bb2016-01-18 15:26:11 +00007178 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01007179 public @ColorInt int getOrganizationColorForUser(int userHandle) {
Benjamin Franz59720bb2016-01-18 15:26:11 +00007180 try {
7181 return mService.getOrganizationColorForUser(userHandle);
7182 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007183 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00007184 }
7185 }
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007186
7187 /**
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01007188 * Called by the device owner or profile owner to set the name of the organization under
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007189 * management.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007190 * <p>
7191 * If the organization name needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007192 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
7193 * and set a new version of this string accordingly.
7194 *
7195 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7196 * @param title The organization name or {@code null} to clear a previously set name.
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01007197 * @throws SecurityException if {@code admin} is not a device or profile owner.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007198 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01007199 public void setOrganizationName(@NonNull ComponentName admin, @Nullable CharSequence title) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007200 throwIfParentInstance("setOrganizationName");
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007201 try {
7202 mService.setOrganizationName(admin, title);
7203 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007204 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007205 }
7206 }
7207
7208 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007209 * Called by a profile owner of a managed profile to retrieve the name of the organization under
7210 * management.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007211 *
7212 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7213 * @return The organization name or {@code null} if none is set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007214 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007215 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007216 public @Nullable CharSequence getOrganizationName(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007217 throwIfParentInstance("getOrganizationName");
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007218 try {
7219 return mService.getOrganizationName(admin);
7220 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007221 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007222 }
7223 }
7224
7225 /**
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01007226 * Called by the system to retrieve the name of the organization managing the device.
7227 *
7228 * @return The organization name or {@code null} if none is set.
7229 * @throws SecurityException if the caller is not the device owner, does not hold the
7230 * MANAGE_USERS permission and is not the system.
7231 *
7232 * @hide
7233 */
7234 @SystemApi
7235 @TestApi
7236 public @Nullable CharSequence getDeviceOwnerOrganizationName() {
7237 try {
7238 return mService.getDeviceOwnerOrganizationName();
7239 } catch (RemoteException re) {
7240 throw re.rethrowFromSystemServer();
7241 }
7242 }
7243
7244 /**
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007245 * Retrieve the default title message used in the confirm credentials screen for a given user.
7246 *
7247 * @param userHandle The user id of the user we're interested in.
7248 * @return The organization name or {@code null} if none is set.
7249 *
7250 * @hide
7251 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007252 public @Nullable CharSequence getOrganizationNameForUser(int userHandle) {
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007253 try {
7254 return mService.getOrganizationNameForUser(userHandle);
7255 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007256 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007257 }
7258 }
7259
7260 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00007261 * @return the {@link UserProvisioningState} for the current user - for unmanaged users will
7262 * return {@link #STATE_USER_UNMANAGED}
7263 * @hide
7264 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00007265 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00007266 @UserProvisioningState
7267 public int getUserProvisioningState() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007268 throwIfParentInstance("getUserProvisioningState");
Alan Treadwayafad8782016-01-19 15:15:08 +00007269 if (mService != null) {
7270 try {
7271 return mService.getUserProvisioningState();
7272 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007273 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00007274 }
7275 }
7276 return STATE_USER_UNMANAGED;
7277 }
7278
7279 /**
7280 * Set the {@link UserProvisioningState} for the supplied user, if they are managed.
7281 *
7282 * @param state to store
7283 * @param userHandle for user
7284 * @hide
7285 */
7286 public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) {
7287 if (mService != null) {
7288 try {
7289 mService.setUserProvisioningState(state, userHandle);
7290 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007291 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00007292 }
7293 }
7294 }
7295
7296 /**
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007297 * Indicates the entity that controls the device or profile owner. Two users/profiles are
7298 * affiliated if the set of ids set by their device or profile owners intersect.
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007299 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00007300 * <p><strong>Note:</strong> Features that depend on user affiliation (such as security logging
7301 * or {@link #bindDeviceAdminServiceAsUser}) won't be available when a secondary user or profile
7302 * is created, until it becomes affiliated. Therefore it is recommended that the appropriate
7303 * affiliation ids are set by its profile owner as soon as possible after the user/profile is
7304 * created.
7305 *
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007306 * @param admin Which profile or device owner this request is associated with.
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007307 * @param ids A list of opaque non-empty affiliation ids. Duplicate elements will be ignored.
7308 *
7309 * @throws NullPointerException if {@code ids} is null or contains null elements.
7310 * @throws IllegalArgumentException if {@code ids} contains an empty string.
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007311 */
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007312 public void setAffiliationIds(@NonNull ComponentName admin, @NonNull List<String> ids) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007313 throwIfParentInstance("setAffiliationIds");
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007314 try {
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007315 mService.setAffiliationIds(admin, ids);
7316 } catch (RemoteException e) {
7317 throw e.rethrowFromSystemServer();
7318 }
7319 }
7320
7321 /**
7322 * Returns the list of affiliation ids previously set via {@link #setAffiliationIds}, or an
7323 * empty list if none have been set.
7324 */
7325 public @NonNull List<String> getAffiliationIds(@NonNull ComponentName admin) {
7326 throwIfParentInstance("getAffiliationIds");
7327 try {
7328 return mService.getAffiliationIds(admin);
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007329 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007330 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007331 }
7332 }
7333
7334 /**
7335 * @hide
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007336 * Returns whether this user/profile is affiliated with the device.
7337 * <p>
7338 * By definition, the user that the device owner runs on is always affiliated with the device.
7339 * Any other user/profile is considered affiliated with the device if the set specified by its
7340 * profile owner via {@link #setAffiliationIds} intersects with the device owner's.
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007341 *
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007342 */
7343 public boolean isAffiliatedUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007344 throwIfParentInstance("isAffiliatedUser");
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007345 try {
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007346 return mService.isAffiliatedUser();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007347 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007348 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007349 }
7350 }
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08007351
7352 /**
7353 * @hide
7354 * Returns whether the uninstall for {@code packageName} for the current user is in queue
7355 * to be started
7356 * @param packageName the package to check for
7357 * @return whether the uninstall intent for {@code packageName} is pending
7358 */
7359 public boolean isUninstallInQueue(String packageName) {
7360 try {
7361 return mService.isUninstallInQueue(packageName);
7362 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007363 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08007364 }
7365 }
7366
7367 /**
7368 * @hide
7369 * @param packageName the package containing active DAs to be uninstalled
7370 */
7371 public void uninstallPackageWithActiveAdmins(String packageName) {
7372 try {
7373 mService.uninstallPackageWithActiveAdmins(packageName);
7374 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007375 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08007376 }
7377 }
Benjamin Franzbc33c822016-04-15 08:57:52 +01007378
Kenny Guy38dcca52016-04-19 13:09:18 +01007379 /**
7380 * @hide
7381 * Remove a test admin synchronously without sending it a broadcast about being removed.
7382 * If the admin is a profile owner or device owner it will still be removed.
7383 *
7384 * @param userHandle user id to remove the admin for.
7385 * @param admin The administration compononent to remove.
7386 * @throws SecurityException if the caller is not shell / root or the admin package
7387 * isn't a test application see {@link ApplicationInfo#FLAG_TEST_APP}.
7388 */
7389 public void forceRemoveActiveAdmin(ComponentName adminReceiver, int userHandle) {
7390 try {
7391 mService.forceRemoveActiveAdmin(adminReceiver, userHandle);
7392 } catch (RemoteException re) {
7393 throw re.rethrowFromSystemServer();
7394 }
7395 }
7396
Mahaver Chopra790d1982016-07-07 16:06:49 +01007397 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007398 * Returns whether the device has been provisioned.
7399 *
7400 * <p>Not for use by third-party applications.
7401 *
Mahaver Chopra790d1982016-07-07 16:06:49 +01007402 * @hide
Mahaver Chopra790d1982016-07-07 16:06:49 +01007403 */
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007404 @SystemApi
Mahaver Chopra790d1982016-07-07 16:06:49 +01007405 public boolean isDeviceProvisioned() {
7406 try {
7407 return mService.isDeviceProvisioned();
7408 } catch (RemoteException re) {
7409 throw re.rethrowFromSystemServer();
7410 }
7411 }
7412
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007413 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007414 * Writes that the provisioning configuration has been applied.
7415 *
7416 * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS}
7417 * permission.
7418 *
7419 * <p>Not for use by third-party applications.
7420 *
7421 * @hide
7422 */
7423 @SystemApi
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007424 public void setDeviceProvisioningConfigApplied() {
7425 try {
7426 mService.setDeviceProvisioningConfigApplied();
7427 } catch (RemoteException re) {
7428 throw re.rethrowFromSystemServer();
7429 }
7430 }
7431
7432 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007433 * Returns whether the provisioning configuration has been applied.
7434 *
7435 * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS} permission.
7436 *
7437 * <p>Not for use by third-party applications.
7438 *
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007439 * @return whether the provisioning configuration has been applied.
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007440 *
7441 * @hide
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007442 */
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007443 @SystemApi
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007444 public boolean isDeviceProvisioningConfigApplied() {
7445 try {
7446 return mService.isDeviceProvisioningConfigApplied();
7447 } catch (RemoteException re) {
7448 throw re.rethrowFromSystemServer();
7449 }
7450 }
7451
Victor Chang9bfc65f2016-08-15 12:27:09 +01007452 /**
7453 * @hide
Victor Chang3577ed22016-08-25 18:49:26 +01007454 * Force update user setup completed status. This API has no effect on user build.
7455 * @throws {@link SecurityException} if the caller has no
Esteban Talavera01576862016-12-15 11:16:44 +00007456 * {@code android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS} or the caller is
7457 * not {@link UserHandle#SYSTEM_USER}
Victor Chang9bfc65f2016-08-15 12:27:09 +01007458 */
7459 public void forceUpdateUserSetupComplete() {
7460 try {
7461 mService.forceUpdateUserSetupComplete();
7462 } catch (RemoteException re) {
7463 throw re.rethrowFromSystemServer();
7464 }
7465 }
7466
Benjamin Franzbc33c822016-04-15 08:57:52 +01007467 private void throwIfParentInstance(String functionName) {
7468 if (mParentInstance) {
7469 throw new SecurityException(functionName + " cannot be called on the parent instance");
7470 }
7471 }
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007472
7473 /**
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007474 * Allows the device owner to enable or disable the backup service.
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007475 *
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007476 * <p> Backup service manages all backup and restore mechanisms on the device. Setting this to
7477 * false will prevent data from being backed up or restored.
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007478 *
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007479 * <p> Backup service is off by default when device owner is present.
7480 *
7481 * @throws SecurityException if {@code admin} is not a device owner.
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007482 */
7483 public void setBackupServiceEnabled(@NonNull ComponentName admin, boolean enabled) {
7484 try {
7485 mService.setBackupServiceEnabled(admin, enabled);
7486 } catch (RemoteException re) {
7487 throw re.rethrowFromSystemServer();
7488 }
7489 }
7490
7491 /**
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007492 * Return whether the backup service is enabled by the device owner.
7493 *
7494 * <p> Backup service manages all backup and restore mechanisms on the device.
7495 *
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007496 * @return {@code true} if backup service is enabled, {@code false} otherwise.
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007497 * @see #setBackupServiceEnabled
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007498 */
7499 public boolean isBackupServiceEnabled(@NonNull ComponentName admin) {
7500 try {
7501 return mService.isBackupServiceEnabled(admin);
7502 } catch (RemoteException re) {
7503 throw re.rethrowFromSystemServer();
7504 }
7505 }
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007506
7507 /**
Esteban Talaverad36dd152016-12-15 08:51:45 +00007508 * Called by a device owner to control the network logging feature.
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007509 *
7510 * <p> Network logs contain DNS lookup and connect() library call events.
7511 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00007512 * <p><strong>Note:</strong> The device owner won't be able to retrieve network logs if there
7513 * are unaffiliated secondary users or profiles on the device, regardless of whether the
7514 * feature is enabled. Logs will be discarded if the internal buffer fills up while waiting for
7515 * all users to become affiliated. Therefore it's recommended that affiliation ids are set for
7516 * new users as soon as possible after provisioning via {@link #setAffiliationIds}.
7517 *
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007518 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7519 * @param enabled whether network logging should be enabled or not.
Esteban Talaverad36dd152016-12-15 08:51:45 +00007520 * @throws SecurityException if {@code admin} is not a device owner.
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007521 * @see #retrieveNetworkLogs
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007522 */
7523 public void setNetworkLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
7524 throwIfParentInstance("setNetworkLoggingEnabled");
7525 try {
7526 mService.setNetworkLoggingEnabled(admin, enabled);
7527 } catch (RemoteException re) {
7528 throw re.rethrowFromSystemServer();
7529 }
7530 }
7531
7532 /**
7533 * Return whether network logging is enabled by a device owner.
7534 *
phweissa4e169e2016-11-24 16:20:57 +01007535 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Can only
7536 * be {@code null} if the caller has MANAGE_USERS permission.
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007537 * @return {@code true} if network logging is enabled by device owner, {@code false} otherwise.
Esteban Talaverad36dd152016-12-15 08:51:45 +00007538 * @throws SecurityException if {@code admin} is not a device owner and caller has
phweissa4e169e2016-11-24 16:20:57 +01007539 * no MANAGE_USERS permission
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007540 */
phweissa4e169e2016-11-24 16:20:57 +01007541 public boolean isNetworkLoggingEnabled(@Nullable ComponentName admin) {
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007542 throwIfParentInstance("isNetworkLoggingEnabled");
7543 try {
7544 return mService.isNetworkLoggingEnabled(admin);
7545 } catch (RemoteException re) {
7546 throw re.rethrowFromSystemServer();
7547 }
7548 }
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007549
7550 /**
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007551 * Called by device owner to retrieve the most recent batch of network logging events.
7552 * A device owner has to provide a batchToken provided as part of
7553 * {@link DeviceAdminReceiver#onNetworkLogsAvailable} callback. If the token doesn't match the
7554 * token of the most recent available batch of logs, {@code null} will be returned.
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007555 *
7556 * <p> {@link NetworkEvent} can be one of {@link DnsEvent} or {@link ConnectEvent}.
7557 *
7558 * <p> The list of network events is sorted chronologically, and contains at most 1200 events.
7559 *
7560 * <p> Access to the logs is rate limited and this method will only return a new batch of logs
7561 * after the device device owner has been notified via
7562 * {@link DeviceAdminReceiver#onNetworkLogsAvailable}.
7563 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00007564 * <p>If a secondary user or profile is created, calling this method will throw a
7565 * {@link SecurityException} until all users become affiliated again. It will also no longer be
7566 * possible to retrieve the network logs batch with the most recent batchToken provided
7567 * by {@link DeviceAdminReceiver#onNetworkLogsAvailable}. See
7568 * {@link DevicePolicyManager#setAffiliationIds}.
7569 *
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007570 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007571 * @param batchToken A token of the batch to retrieve
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007572 * @return A new batch of network logs which is a list of {@link NetworkEvent}. Returns
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007573 * {@code null} if the batch represented by batchToken is no longer available or if
7574 * logging is disabled.
Esteban Talaverad36dd152016-12-15 08:51:45 +00007575 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
7576 * profile or secondary user that is not affiliated with the device owner user.
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007577 * @see DeviceAdminReceiver#onNetworkLogsAvailable
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007578 */
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007579 public @Nullable List<NetworkEvent> retrieveNetworkLogs(@NonNull ComponentName admin,
7580 long batchToken) {
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007581 throwIfParentInstance("retrieveNetworkLogs");
7582 try {
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007583 return mService.retrieveNetworkLogs(admin, batchToken);
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007584 } catch (RemoteException re) {
7585 throw re.rethrowFromSystemServer();
7586 }
7587 }
Tony Mak46aabe52016-11-14 12:53:06 +00007588
7589 /**
Esteban Talavera2f897912017-01-26 10:30:48 +00007590 * Called by a device owner to bind to a service from a profile owner or vice versa.
7591 * See {@link #getBindDeviceAdminTargetUsers} for a definition of which
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007592 * device/profile owners are allowed to bind to services of another profile/device owner.
7593 * <p>
Tony Mak46aabe52016-11-14 12:53:06 +00007594 * The service must be unexported. Note that the {@link Context} used to obtain this
7595 * {@link DevicePolicyManager} instance via {@link Context#getSystemService(Class)} will be used
7596 * to bind to the {@link android.app.Service}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007597 *
Tony Mak46aabe52016-11-14 12:53:06 +00007598 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7599 * @param serviceIntent Identifies the service to connect to. The Intent must specify either an
7600 * explicit component name or a package name to match an
7601 * {@link IntentFilter} published by a service.
Tony Makbf9928d2016-12-22 11:02:45 +00007602 * @param conn Receives information as the service is started and stopped in main thread. This
7603 * must be a valid {@link ServiceConnection} object; it must not be {@code null}.
Tony Mak46aabe52016-11-14 12:53:06 +00007604 * @param flags Operation options for the binding operation. See
7605 * {@link Context#bindService(Intent, ServiceConnection, int)}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007606 * @param targetUser Which user to bind to. Must be one of the users returned by
7607 * {@link #getBindDeviceAdminTargetUsers}, otherwise a {@link SecurityException} will
7608 * be thrown.
Tony Mak46aabe52016-11-14 12:53:06 +00007609 * @return If you have successfully bound to the service, {@code true} is returned;
7610 * {@code false} is returned if the connection is not made and you will not
7611 * receive the service object.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007612 *
Tony Mak46aabe52016-11-14 12:53:06 +00007613 * @see Context#bindService(Intent, ServiceConnection, int)
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007614 * @see #getBindDeviceAdminTargetUsers(ComponentName)
Tony Mak46aabe52016-11-14 12:53:06 +00007615 */
7616 public boolean bindDeviceAdminServiceAsUser(
7617 @NonNull ComponentName admin, Intent serviceIntent, @NonNull ServiceConnection conn,
7618 @Context.BindServiceFlags int flags, @NonNull UserHandle targetUser) {
7619 throwIfParentInstance("bindDeviceAdminServiceAsUser");
7620 // Keep this in sync with ContextImpl.bindServiceCommon.
7621 try {
Tony Makbf9928d2016-12-22 11:02:45 +00007622 final IServiceConnection sd = mContext.getServiceDispatcher(
7623 conn, mContext.getMainThreadHandler(), flags);
Tony Mak46aabe52016-11-14 12:53:06 +00007624 serviceIntent.prepareToLeaveProcess(mContext);
7625 return mService.bindDeviceAdminServiceAsUser(admin,
7626 mContext.getIApplicationThread(), mContext.getActivityToken(), serviceIntent,
7627 sd, flags, targetUser.getIdentifier());
7628 } catch (RemoteException re) {
7629 throw re.rethrowFromSystemServer();
7630 }
7631 }
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007632
7633 /**
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007634 * Returns the list of target users that the calling device or profile owner can use when
7635 * calling {@link #bindDeviceAdminServiceAsUser}.
7636 * <p>
Esteban Talavera2f897912017-01-26 10:30:48 +00007637 * A device owner can bind to a service from a profile owner and vice versa, provided that:
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007638 * <ul>
7639 * <li>Both belong to the same package name.
Esteban Talavera2f897912017-01-26 10:30:48 +00007640 * <li>Both users are affiliated. See {@link #setAffiliationIds}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007641 * </ul>
7642 */
7643 public @NonNull List<UserHandle> getBindDeviceAdminTargetUsers(@NonNull ComponentName admin) {
7644 throwIfParentInstance("getBindDeviceAdminTargetUsers");
7645 try {
7646 return mService.getBindDeviceAdminTargetUsers(admin);
7647 } catch (RemoteException re) {
7648 throw re.rethrowFromSystemServer();
7649 }
7650 }
7651
7652 /**
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007653 * Called by the system to get the time at which the device owner last retrieved security
7654 * logging entries.
7655 *
7656 * @return the time at which the device owner most recently retrieved security logging entries,
7657 * in milliseconds since epoch; -1 if security logging entries were never retrieved.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007658 * @throws SecurityException if the caller is not the device owner, does not hold the
7659 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007660 *
7661 * @hide
7662 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007663 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007664 public long getLastSecurityLogRetrievalTime() {
7665 try {
7666 return mService.getLastSecurityLogRetrievalTime();
7667 } catch (RemoteException re) {
7668 throw re.rethrowFromSystemServer();
7669 }
7670 }
7671
7672 /**
7673 * Called by the system to get the time at which the device owner last requested a bug report.
7674 *
7675 * @return the time at which the device owner most recently requested a bug report, in
7676 * milliseconds since epoch; -1 if a bug report was never requested.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007677 * @throws SecurityException if the caller is not the device owner, does not hold the
7678 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007679 *
7680 * @hide
7681 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007682 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007683 public long getLastBugReportRequestTime() {
7684 try {
7685 return mService.getLastBugReportRequestTime();
7686 } catch (RemoteException re) {
7687 throw re.rethrowFromSystemServer();
7688 }
7689 }
7690
7691 /**
7692 * Called by the system to get the time at which the device owner last retrieved network logging
7693 * events.
7694 *
7695 * @return the time at which the device owner most recently retrieved network logging events, in
7696 * milliseconds since epoch; -1 if network logging events were never retrieved.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007697 * @throws SecurityException if the caller is not the device owner, does not hold the
7698 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007699 *
7700 * @hide
7701 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007702 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007703 public long getLastNetworkLogRetrievalTime() {
7704 try {
7705 return mService.getLastNetworkLogRetrievalTime();
7706 } catch (RemoteException re) {
7707 throw re.rethrowFromSystemServer();
7708 }
7709 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08007710}