blob: bb3b4a4625fc9a438ac6d25757e199f667a4c5c8 [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;
Rubin Xuaab7a412016-12-30 21:13:29 +000031import android.app.KeyguardManager;
Michal Karpinski6235a942016-03-15 12:07:23 +000032import android.app.admin.SecurityLog.SecurityEvent;
Dianne Hackbornd6847842010-01-12 18:14:19 -080033import android.content.ComponentName;
34import android.content.Context;
Adam Connors010cfd42014-04-16 12:48:13 +010035import android.content.Intent;
Sander Alewijnsef475ca32014-02-17 15:13:58 +000036import android.content.IntentFilter;
Tony Mak46aabe52016-11-14 12:53:06 +000037import android.content.ServiceConnection;
Victor Chang98607132017-01-27 11:51:56 +000038import android.content.pm.ApplicationInfo;
Dianne Hackbornd6847842010-01-12 18:14:19 -080039import android.content.pm.PackageManager;
Victor Changcd14c0a2016-03-16 19:10:15 +000040import android.content.pm.PackageManager.NameNotFoundException;
Rubin Xuc3cd05f2016-01-11 12:11:35 +000041import android.content.pm.ParceledListSlice;
Sudheer Shanka978fc0d2016-01-28 13:51:10 +000042import android.content.pm.UserInfo;
Julia Reynoldsfca04ca2015-02-17 13:39:12 -050043import android.graphics.Bitmap;
Jason Monk03bc9912014-05-13 09:44:57 -040044import android.net.ProxyInfo;
Nicolas Prevot8b7991c2015-11-12 17:40:12 +000045import android.net.Uri;
Robin Lee66e5d962014-04-09 16:44:21 +010046import android.os.Bundle;
Victor Changc10f6692016-12-09 15:24:00 +000047import android.os.Parcelable;
Jim Millere303bf42014-08-26 17:12:29 -070048import android.os.PersistableBundle;
Adam Connors776c5552014-01-09 10:42:56 +000049import android.os.Process;
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080050import android.os.RemoteCallback;
Dianne Hackbornd6847842010-01-12 18:14:19 -080051import android.os.RemoteException;
Amith Yamasani599dd7c2012-09-14 23:20:08 -070052import android.os.UserHandle;
Julia Reynolds1e958392014-05-16 14:25:21 -040053import android.os.UserManager;
Ricky Wai494b95d2015-11-20 16:07:15 +000054import android.provider.ContactsContract.Directory;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000055import android.provider.Settings;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010056import android.security.Credentials;
Amith Yamasanid1d7c022014-08-19 17:03:41 -070057import android.service.restrictions.RestrictionsReceiver;
Mahaver Chopra1216ae52016-03-11 15:39:48 +000058import android.telephony.TelephonyManager;
Tony Mak31657432017-04-25 09:29:55 +010059import android.util.ArraySet;
Dianne Hackbornd6847842010-01-12 18:14:19 -080060import android.util.Log;
61
Makoto Onukicc4bbeb2015-09-17 10:28:24 -070062import com.android.internal.annotations.VisibleForTesting;
Maggie Benthallda51e682013-08-08 22:35:44 -040063import com.android.org.conscrypt.TrustedCertificateStore;
64
65import java.io.ByteArrayInputStream;
Dianne Hackbornd6847842010-01-12 18:14:19 -080066import java.io.IOException;
Alan Treadwayafad8782016-01-19 15:15:08 +000067import java.lang.annotation.Retention;
68import java.lang.annotation.RetentionPolicy;
Oscar Montemayor69238c62010-08-03 10:51:06 -070069import java.net.InetSocketAddress;
70import java.net.Proxy;
Robin Lee0d5ccb72014-09-12 17:41:44 +010071import java.security.KeyFactory;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000072import java.security.NoSuchAlgorithmException;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010073import java.security.PrivateKey;
74import java.security.cert.Certificate;
Maggie Benthallda51e682013-08-08 22:35:44 -040075import java.security.cert.CertificateException;
76import java.security.cert.CertificateFactory;
77import java.security.cert.X509Certificate;
Robin Lee0d5ccb72014-09-12 17:41:44 +010078import java.security.spec.InvalidKeySpecException;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000079import java.security.spec.PKCS8EncodedKeySpec;
Jim Miller604e7552014-07-18 19:00:02 -070080import java.util.ArrayList;
Rubin Xub4365912016-03-23 12:13:22 +000081import java.util.Arrays;
Svetoslav976e8bd2014-07-16 15:12:03 -070082import java.util.Collections;
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -080083import java.util.List;
Tony Mak31657432017-04-25 09:29:55 +010084import java.util.Set;
Dianne Hackbornd6847842010-01-12 18:14:19 -080085
86/**
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000087 * Public interface for managing policies enforced on a device. Most clients of this class must be
Suprabh Shukla34d92ef2016-03-14 13:49:37 -070088 * registered with the system as a <a href="{@docRoot}guide/topics/admin/device-admin.html">device
89 * administrator</a>. Additionally, a device administrator may be registered as either a profile or
90 * device owner. A given method is accessible to all device administrators unless the documentation
91 * for that method specifies that it is restricted to either device or profile owners. Any
92 * application calling an api may only pass as an argument a device administrator component it
93 * owns. Otherwise, a {@link SecurityException} will be thrown.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080094 * <div class="special reference">
95 * <h3>Developer Guides</h3>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -070096 * <p>
97 * For more information about managing policies for device administration, read the <a href=
98 * "{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a> developer
99 * guide. </div>
Dianne Hackbornd6847842010-01-12 18:14:19 -0800100 */
101public class DevicePolicyManager {
102 private static String TAG = "DevicePolicyManager";
Dianne Hackbornd6847842010-01-12 18:14:19 -0800103
104 private final Context mContext;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800105 private final IDevicePolicyManager mService;
Esteban Talavera62399912016-01-11 15:37:55 +0000106 private final boolean mParentInstance;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700107
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600108 /** @hide */
109 public DevicePolicyManager(Context context, IDevicePolicyManager service) {
110 this(context, service, false);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800111 }
112
Dianne Hackborn87bba1e2010-02-26 17:25:54 -0800113 /** @hide */
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700114 @VisibleForTesting
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600115 protected DevicePolicyManager(Context context, IDevicePolicyManager service,
116 boolean parentInstance) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700117 mContext = context;
118 mService = service;
Esteban Talavera62399912016-01-11 15:37:55 +0000119 mParentInstance = parentInstance;
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700120 }
121
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700122 /** @hide test will override it. */
123 @VisibleForTesting
124 protected int myUserId() {
125 return UserHandle.myUserId();
126 }
127
Dianne Hackbornd6847842010-01-12 18:14:19 -0800128 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +0000129 * Activity action: Starts the provisioning flow which sets up a managed profile.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000130 *
Jessica Hummel9da60392014-05-21 12:32:57 +0100131 * <p>A managed profile allows data separation for example for the usage of a
132 * device as a personal and corporate device. The user which provisioning is started from and
133 * the managed profile share a launcher.
134 *
Andrew Solovay27f53372015-03-02 16:37:59 -0800135 * <p>This intent will typically be sent by a mobile device management application (MDM).
136 * Provisioning adds a managed profile and sets the MDM as the profile owner who has full
137 * control over the profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100138 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000139 * <p>It is possible to check if provisioning is allowed or not by querying the method
140 * {@link #isProvisioningAllowed(String)}.
141 *
142 * <p>In version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this intent must contain the
Nicolas Prevot18440252015-03-09 14:07:17 +0000143 * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700144 * As of {@link android.os.Build.VERSION_CODES#M}, it should contain the extra
Nicolas Prevot18440252015-03-09 14:07:17 +0000145 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only
146 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000147 *
Benjamin Franzea956242016-03-21 15:45:56 +0000148 * <p>The intent may also contain the following extras:
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000149 * <ul>
Benjamin Franzea956242016-03-21 15:45:56 +0000150 * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, optional </li>
151 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional, supported from
152 * {@link android.os.Build.VERSION_CODES#N}</li>
153 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
154 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
155 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Victor Chang51d84f92016-11-16 12:22:56 +0000156 * <li>{@link #EXTRA_PROVISIONING_SKIP_USER_CONSENT}, optional</li>
Victor Chang89ee2792016-11-23 12:10:55 +0000157 * <li>{@link #EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION}, optional</li>
Victor Changc10f6692016-12-09 15:24:00 +0000158 * <li>{@link #EXTRA_PROVISIONING_DISCLAIMERS}, optional</li>
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000159 * </ul>
Jessica Hummelf72078b2014-03-06 16:13:12 +0000160 *
Benjamin Franzea956242016-03-21 15:45:56 +0000161 * <p>When managed provisioning has completed, broadcasts are sent to the application specified
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000162 * in the provisioning intent. The
163 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the
164 * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in
165 * the primary profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100166 *
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000167 * <p>From version {@link android.os.Build.VERSION_CODES#O}, when managed provisioning has
168 * completed, along with the above broadcast, activity intent
169 * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the application specified in
170 * the provisioning intent.
171 *
Benjamin Franzea956242016-03-21 15:45:56 +0000172 * <p>If provisioning fails, the managedProfile is removed so the device returns to its
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100173 * previous state.
Alan Treadway4582f812015-07-28 11:49:35 +0100174 *
175 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
176 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
177 * the provisioning flow was successful, although this doesn't guarantee the full flow will
178 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
179 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000180 */
181 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
182 public static final String ACTION_PROVISION_MANAGED_PROFILE
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100183 = "android.app.action.PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000184
185 /**
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000186 * Activity action: Starts the provisioning flow which sets up a managed user.
187 *
188 * <p>This intent will typically be sent by a mobile device management application (MDM).
Makoto Onuki32b30572015-12-11 14:29:51 -0800189 * Provisioning configures the user as managed user and sets the MDM as the profile
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000190 * owner who has full control over the user. Provisioning can only happen before user setup has
191 * been completed. Use {@link #isProvisioningAllowed(String)} to check if provisioning is
192 * allowed.
193 *
Benjamin Franzea956242016-03-21 15:45:56 +0000194 * <p>The intent contains the following extras:
195 * <ul>
196 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
197 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
198 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
199 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
200 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
201 * </ul>
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000202 *
Benjamin Franzea956242016-03-21 15:45:56 +0000203 * <p>If provisioning fails, the device returns to its previous state.
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000204 *
205 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
206 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
207 * the provisioning flow was successful, although this doesn't guarantee the full flow will
208 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
209 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Benjamin Franzea956242016-03-21 15:45:56 +0000210 *
211 * @hide
Mahaver Chopra5e732562015-11-05 11:55:12 +0000212 */
213 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
214 public static final String ACTION_PROVISION_MANAGED_USER
215 = "android.app.action.PROVISION_MANAGED_USER";
216
217 /**
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100218 * Activity action: Starts the provisioning flow which sets up a managed device.
219 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
220 *
221 * <p> During device owner provisioning a device admin app is set as the owner of the device.
222 * A device owner has full control over the device. The device owner can not be modified by the
223 * user.
224 *
225 * <p> A typical use case would be a device that is owned by a company, but used by either an
226 * employee or client.
227 *
228 * <p> An intent with this action can be sent only on an unprovisioned device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000229 * It is possible to check if provisioning is allowed or not by querying the method
230 * {@link #isProvisioningAllowed(String)}.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100231 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000232 * <p>The intent contains the following extras:
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100233 * <ul>
234 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
235 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
236 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
Rubin Xua4f9dc12015-06-12 13:27:59 +0100237 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000238 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000239 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Victor Changc10f6692016-12-09 15:24:00 +0000240 * <li>{@link #EXTRA_PROVISIONING_DISCLAIMERS}, optional</li>
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100241 * </ul>
242 *
Benjamin Franzea956242016-03-21 15:45:56 +0000243 * <p>When device owner provisioning has completed, an intent of the type
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100244 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
245 * device owner.
246 *
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000247 * <p>From version {@link android.os.Build.VERSION_CODES#O}, when device owner provisioning has
248 * completed, along with the above broadcast, activity intent
249 * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the device owner.
250 *
Benjamin Franzea956242016-03-21 15:45:56 +0000251 * <p>If provisioning fails, the device is factory reset.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100252 *
Alan Treadway4582f812015-07-28 11:49:35 +0100253 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
254 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
255 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
256 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100257 */
258 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
259 public static final String ACTION_PROVISION_MANAGED_DEVICE
260 = "android.app.action.PROVISION_MANAGED_DEVICE";
261
262 /**
Alan Treadway46dd4492015-11-09 13:57:19 +0000263 * Activity action: Starts the provisioning flow which sets up a managed device.
Steven Ng980a1b62016-02-02 17:43:18 +0000264 *
265 * <p>During device owner provisioning, a device admin app is downloaded and set as the owner of
266 * the device. A device owner has full control over the device. The device owner can not be
267 * modified by the user and the only way of resetting the device is via factory reset.
268 *
269 * <p>A typical use case would be a device that is owned by a company, but used by either an
270 * employee or client.
271 *
272 * <p>The provisioning message should be sent to an unprovisioned device.
273 *
274 * <p>Unlike {@link #ACTION_PROVISION_MANAGED_DEVICE}, the provisioning message can only be sent
275 * by a privileged app with the permission
276 * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE}.
277 *
278 * <p>The provisioning intent contains the following properties:
279 * <ul>
280 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
281 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
282 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
283 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Victor Chang38cfd9c2017-01-04 17:41:11 +0000284 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL}, optional</li>
285 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI}, optional</li>
Steven Ng980a1b62016-02-02 17:43:18 +0000286 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
287 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
288 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
289 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
290 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
291 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
292 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
293 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
294 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
295 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
296 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
Victor Chang38cfd9c2017-01-04 17:41:11 +0000297 * <li>{@link #EXTRA_PROVISIONING_SUPPORT_URL}, optional</li>
298 * <li>{@link #EXTRA_PROVISIONING_ORGANIZATION_NAME}, optional</li>
Steven Ng980a1b62016-02-02 17:43:18 +0000299 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li></ul>
300 *
301 * @hide
302 */
303 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
304 @SystemApi
305 public static final String ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE =
306 "android.app.action.PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE";
307
308 /**
309 * Activity action: Starts the provisioning flow which sets up a managed device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000310 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
311 *
312 * <p>NOTE: This is only supported on split system user devices, and puts the device into a
313 * management state that is distinct from that reached by
314 * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system
315 * user, and only has control over device-wide policies, not individual users and their data.
316 * The primary benefit is that multiple non-system users are supported when provisioning using
317 * this form of device management.
318 *
Benjamin Franzea956242016-03-21 15:45:56 +0000319 * <p>During device owner provisioning a device admin app is set as the owner of the device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000320 * A device owner has full control over the device. The device owner can not be modified by the
321 * user.
322 *
Benjamin Franzea956242016-03-21 15:45:56 +0000323 * <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 +0000324 * employee or client.
325 *
Benjamin Franzea956242016-03-21 15:45:56 +0000326 * <p>An intent with this action can be sent only on an unprovisioned device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000327 * It is possible to check if provisioning is allowed or not by querying the method
328 * {@link #isProvisioningAllowed(String)}.
329 *
330 * <p>The intent contains the following extras:
331 * <ul>
332 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
333 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
334 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
335 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Benjamin Franzea956242016-03-21 15:45:56 +0000336 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
337 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Alan Treadway46dd4492015-11-09 13:57:19 +0000338 * </ul>
339 *
Benjamin Franzea956242016-03-21 15:45:56 +0000340 * <p>When device owner provisioning has completed, an intent of the type
Alan Treadway46dd4492015-11-09 13:57:19 +0000341 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
342 * device owner.
343 *
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000344 * <p>From version {@link android.os.Build.VERSION_CODES#O}, when device owner provisioning has
345 * completed, along with the above broadcast, activity intent
346 * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the device owner.
347 *
Benjamin Franzea956242016-03-21 15:45:56 +0000348 * <p>If provisioning fails, the device is factory reset.
Alan Treadway46dd4492015-11-09 13:57:19 +0000349 *
350 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
351 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
352 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
353 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
354 *
355 * @hide
356 */
357 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
358 public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE
359 = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE";
360
361 /**
Alan Treadwayafad8782016-01-19 15:15:08 +0000362 * Activity action: Finalizes management provisioning, should be used after user-setup
363 * has been completed and {@link #getUserProvisioningState()} returns one of:
364 * <ul>
365 * <li>{@link #STATE_USER_SETUP_INCOMPLETE}</li>
366 * <li>{@link #STATE_USER_SETUP_COMPLETE}</li>
367 * <li>{@link #STATE_USER_PROFILE_COMPLETE}</li>
368 * </ul>
369 *
370 * @hide
371 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +0000372 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +0000373 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
374 public static final String ACTION_PROVISION_FINALIZATION
375 = "android.app.action.PROVISION_FINALIZATION";
376
377 /**
Michal Karpinskiba244092016-02-25 17:28:24 +0000378 * Action: Bugreport sharing with device owner has been accepted by the user.
379 *
380 * @hide
381 */
382 public static final String ACTION_BUGREPORT_SHARING_ACCEPTED =
Rubin Xu7226c7d2017-02-06 17:18:50 +0000383 "com.android.server.action.REMOTE_BUGREPORT_SHARING_ACCEPTED";
Michal Karpinskiba244092016-02-25 17:28:24 +0000384
385 /**
386 * Action: Bugreport sharing with device owner has been declined by the user.
387 *
388 * @hide
389 */
390 public static final String ACTION_BUGREPORT_SHARING_DECLINED =
Rubin Xu7226c7d2017-02-06 17:18:50 +0000391 "com.android.server.action.REMOTE_BUGREPORT_SHARING_DECLINED";
Michal Karpinskiba244092016-02-25 17:28:24 +0000392
393 /**
Esteban Talavera01576862016-12-15 11:16:44 +0000394 * Action: Bugreport has been collected and is dispatched to {@code DevicePolicyManagerService}.
Michal Karpinskiba244092016-02-25 17:28:24 +0000395 *
396 * @hide
397 */
398 public static final String ACTION_REMOTE_BUGREPORT_DISPATCH =
399 "android.intent.action.REMOTE_BUGREPORT_DISPATCH";
400
401 /**
402 * Extra for shared bugreport's SHA-256 hash.
403 *
404 * @hide
405 */
406 public static final String EXTRA_REMOTE_BUGREPORT_HASH =
407 "android.intent.extra.REMOTE_BUGREPORT_HASH";
408
409 /**
410 * Extra for remote bugreport notification shown type.
411 *
412 * @hide
413 */
414 public static final String EXTRA_BUGREPORT_NOTIFICATION_TYPE =
415 "android.app.extra.bugreport_notification_type";
416
417 /**
418 * Notification type for a started remote bugreport flow.
419 *
420 * @hide
421 */
422 public static final int NOTIFICATION_BUGREPORT_STARTED = 1;
423
424 /**
425 * Notification type for a bugreport that has already been accepted to be shared, but is still
426 * being taken.
427 *
428 * @hide
429 */
430 public static final int NOTIFICATION_BUGREPORT_ACCEPTED_NOT_FINISHED = 2;
431
432 /**
433 * Notification type for a bugreport that has been taken and can be shared or declined.
434 *
435 * @hide
436 */
437 public static final int NOTIFICATION_BUGREPORT_FINISHED_NOT_ACCEPTED = 3;
438
439 /**
Michal Karpinski8f010dd2016-06-21 15:05:53 +0100440 * Default and maximum timeout in milliseconds after which unlocking with weak auth times out,
441 * i.e. the user has to use a strong authentication method like password, PIN or pattern.
442 *
443 * @hide
444 */
445 public static final long DEFAULT_STRONG_AUTH_TIMEOUT_MS = 72 * 60 * 60 * 1000; // 72h
446
447 /**
Rubin Xua4f9dc12015-06-12 13:27:59 +0100448 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100449 * allows a mobile device management application or NFC programmer application which starts
450 * managed provisioning to pass data to the management application instance after provisioning.
Rubin Xua4f9dc12015-06-12 13:27:59 +0100451 * <p>
452 * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that
453 * sends the intent to pass data to itself on the newly created profile.
454 * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same
455 * instance of the app on the primary user.
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100456 * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with
457 * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC
458 * message should contain a stringified {@link java.util.Properties} instance, whose string
459 * properties will be converted into a {@link android.os.PersistableBundle} and passed to the
460 * management application after provisioning.
461 *
Rubin Xua4f9dc12015-06-12 13:27:59 +0100462 * <p>
463 * In both cases the application receives the data in
Brian Carlstromf1fe51b2014-09-03 08:55:05 -0700464 * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action
465 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed
Rubin Xua4f9dc12015-06-12 13:27:59 +0100466 * during the managed provisioning.
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100467 */
468 public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE =
Esteban Talavera37f01842014-09-05 10:50:57 +0100469 "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE";
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100470
471 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100472 * A String extra holding the package name of the mobile device management application that
473 * will be set as the profile owner or device owner.
474 *
475 * <p>If an application starts provisioning directly via an intent with action
476 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
477 * application that started provisioning. The package will be set as profile owner in that case.
478 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000479 * <p>This package is set as device owner when device owner provisioning is started by an NFC
480 * message containing an NFC record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000481 *
482 * <p> When this extra is set, the application must have exactly one device admin receiver.
Robin Lee25e26452015-06-02 09:56:29 -0700483 * This receiver will be set as the profile or device owner and active admin.
Benjamin Franzea956242016-03-21 15:45:56 +0000484 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000485 * @see DeviceAdminReceiver
486 * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still
Nicolas Prevot8f78d6a2015-08-21 11:06:31 +0100487 * supported, but only if there is only one device admin receiver in the package that requires
488 * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000489 */
Nicolas Prevot18440252015-03-09 14:07:17 +0000490 @Deprecated
Jessica Hummelf72078b2014-03-06 16:13:12 +0000491 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100492 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000493
494 /**
Nicolas Prevot18440252015-03-09 14:07:17 +0000495 * A ComponentName extra indicating the device admin receiver of the mobile device management
496 * application that will be set as the profile owner or device owner and active admin.
497 *
498 * <p>If an application starts provisioning directly via an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100499 * {@link #ACTION_PROVISION_MANAGED_PROFILE} or
500 * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this
501 * component has to match the package name of the application that started provisioning.
Nicolas Prevot18440252015-03-09 14:07:17 +0000502 *
503 * <p>This component is set as device owner and active admin when device owner provisioning is
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100504 * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC
505 * message containing an NFC record with MIME type
Benjamin Franzea956242016-03-21 15:45:56 +0000506 * {@link #MIME_TYPE_PROVISIONING_NFC}. For the NFC record, the component name must be
Rubin Xu44ef750b2015-03-23 16:51:33 +0000507 * flattened to a string, via {@link ComponentName#flattenToShortString()}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000508 *
509 * @see DeviceAdminReceiver
510 */
511 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME
512 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME";
513
514 /**
Alexandra Gherghinaaaf2f3e2014-11-13 12:46:15 +0000515 * An {@link android.accounts.Account} extra holding the account to migrate during managed
516 * profile provisioning. If the account supplied is present in the primary user, it will be
517 * copied, along with its credentials to the managed profile and removed from the primary user.
518 *
519 * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}.
520 */
521
522 public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE
523 = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE";
524
525 /**
Victor Changaa9cbc02016-12-05 20:50:57 +0000526 * Boolean extra to indicate that the migrated account should be kept. This is used in
527 * conjunction with {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}. If it's set to {@code true},
528 * the account will not be removed from the primary user after it is migrated to the newly
529 * created user or profile.
Victor Chang89ee2792016-11-23 12:10:55 +0000530 *
531 * <p> Defaults to {@code false}
532 *
Victor Changaa9cbc02016-12-05 20:50:57 +0000533 * <p> Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
534 * {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}
Victor Chang89ee2792016-11-23 12:10:55 +0000535 */
536 public static final String EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION
537 = "android.app.extra.PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION";
538
539 /**
Mahaver761ce772017-03-13 16:40:45 +0000540 * @deprecated From {@link android.os.Build.VERSION_CODES#O}, never used while provisioning the
541 * device.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100542 */
Mahaver761ce772017-03-13 16:40:45 +0000543 @Deprecated
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100544 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
545 = "android.app.extra.PROVISIONING_EMAIL_ADDRESS";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100546
547 /**
Nicolas Prevotcd2d8592015-11-23 13:27:21 +0000548 * A integer extra indicating the predominant color to show during the provisioning.
549 * Refer to {@link android.graphics.Color} for how the color is represented.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000550 *
551 * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or
552 * {@link #ACTION_PROVISION_MANAGED_DEVICE}.
553 */
554 public static final String EXTRA_PROVISIONING_MAIN_COLOR =
555 "android.app.extra.PROVISIONING_MAIN_COLOR";
556
557 /**
Sander Alewijnse8c411562014-11-12 18:03:11 +0000558 * A Boolean extra that can be used by the mobile device management application to skip the
Robin Lee25e26452015-06-02 09:56:29 -0700559 * disabling of system apps during provisioning when set to {@code true}.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000560 *
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100561 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
562 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000563 */
Sander Alewijnse5a144252014-11-18 13:25:04 +0000564 public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED =
565 "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED";
Sander Alewijnse8c411562014-11-12 18:03:11 +0000566
567 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100568 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
569 * will be set to.
570 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000571 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
572 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100573 */
574 public static final String EXTRA_PROVISIONING_TIME_ZONE
Esteban Talavera37f01842014-09-05 10:50:57 +0100575 = "android.app.extra.PROVISIONING_TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100576
577 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100578 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
579 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100580 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000581 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
582 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100583 */
584 public static final String EXTRA_PROVISIONING_LOCAL_TIME
Esteban Talavera37f01842014-09-05 10:50:57 +0100585 = "android.app.extra.PROVISIONING_LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100586
587 /**
588 * A String extra holding the {@link java.util.Locale} that the device will be set to.
589 * Format: xx_yy, where xx is the language code, and yy the country code.
590 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000591 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
592 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100593 */
594 public static final String EXTRA_PROVISIONING_LOCALE
Esteban Talavera37f01842014-09-05 10:50:57 +0100595 = "android.app.extra.PROVISIONING_LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100596
597 /**
598 * A String extra holding the ssid of the wifi network that should be used during nfc device
599 * owner provisioning for downloading the mobile device management application.
600 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000601 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
602 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100603 */
604 public static final String EXTRA_PROVISIONING_WIFI_SSID
Esteban Talavera37f01842014-09-05 10:50:57 +0100605 = "android.app.extra.PROVISIONING_WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100606
607 /**
608 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
609 * is hidden or not.
610 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000611 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
612 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100613 */
614 public static final String EXTRA_PROVISIONING_WIFI_HIDDEN
Esteban Talavera37f01842014-09-05 10:50:57 +0100615 = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100616
617 /**
618 * A String extra indicating the security type of the wifi network in
Mahaver Chopra76b08a92015-10-08 17:58:45 +0100619 * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or
620 * {@code WEP}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100621 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000622 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
623 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100624 */
625 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
Esteban Talavera37f01842014-09-05 10:50:57 +0100626 = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100627
628 /**
629 * A String extra holding the password of the wifi network in
630 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
631 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000632 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
633 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100634 */
635 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talavera37f01842014-09-05 10:50:57 +0100636 = "android.app.extra.PROVISIONING_WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100637
638 /**
639 * A String extra holding the proxy host for the wifi network in
640 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
641 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000642 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
643 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100644 */
645 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
Esteban Talavera37f01842014-09-05 10:50:57 +0100646 = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100647
648 /**
649 * An int extra holding the proxy port for the wifi network in
650 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
651 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000652 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
653 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100654 */
655 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
Esteban Talavera37f01842014-09-05 10:50:57 +0100656 = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100657
658 /**
659 * A String extra holding the proxy bypass for the wifi network in
660 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
661 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000662 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
663 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100664 */
665 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
Esteban Talavera37f01842014-09-05 10:50:57 +0100666 = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100667
668 /**
669 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
670 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
671 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000672 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
673 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100674 */
675 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
Esteban Talavera37f01842014-09-05 10:50:57 +0100676 = "android.app.extra.PROVISIONING_WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100677
678 /**
679 * A String extra holding a url that specifies the download location of the device admin
680 * package. When not provided it is assumed that the device admin package is already installed.
681 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000682 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
683 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100684 */
685 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talavera37f01842014-09-05 10:50:57 +0100686 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100687
688 /**
Victor Chang38cfd9c2017-01-04 17:41:11 +0000689 * A String extra holding the localized name of the organization under management.
690 *
691 * The name is displayed only during provisioning.
692 *
693 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE}
694 *
695 * @hide
696 */
697 @SystemApi
698 public static final String EXTRA_PROVISIONING_ORGANIZATION_NAME =
699 "android.app.extra.PROVISIONING_ORGANIZATION_NAME";
700
701 /**
Alejandro Fernándezbfd61932017-04-04 19:33:01 +0100702 * A String extra holding a url to the website of the device provider so the user can open it
703 * during provisioning. If the url is not HTTPS, an error will be shown.
Victor Chang38cfd9c2017-01-04 17:41:11 +0000704 *
705 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE}
706 *
707 * @hide
708 */
709 @SystemApi
710 public static final String EXTRA_PROVISIONING_SUPPORT_URL =
711 "android.app.extra.PROVISIONING_SUPPORT_URL";
712
713 /**
714 * A String extra holding the localized name of the device admin package. It should be the same
715 * as the app label of the package.
716 *
717 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE}
718 *
719 * @hide
720 */
721 @SystemApi
722 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL =
723 "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL";
724
725 /**
726 * A {@link Uri} extra pointing to the app icon of device admin package. This image will be
727 * shown during the provisioning.
728 * <h5>The following URI schemes are accepted:</h5>
729 * <ul>
730 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
731 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
732 * </ul>
733 *
734 * <p> It is the responsibility of the caller to provide an image with a reasonable
735 * pixel density for the device.
736 *
737 * <p> If a content: URI is passed, the intent should have the flag
738 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
739 * {@link android.content.ClipData} of the intent too.
740 *
741 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE}
742 *
743 * @hide
744 */
745 @SystemApi
746 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI =
747 "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI";
748
749 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400750 * An int extra holding a minimum required version code for the device admin package. If the
751 * device admin is already installed on the device, it will only be re-downloaded from
752 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the
753 * installed package is less than this version code.
754 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400755 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400756 * provisioning via an NFC bump.
757 */
758 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE
759 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE";
760
761 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100762 * A String extra holding a http cookie header which should be used in the http request to the
763 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
764 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000765 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
766 * provisioning via an NFC bump.
Sander Alewijnse681bce92014-07-24 16:46:26 +0100767 */
768 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talavera37f01842014-09-05 10:50:57 +0100769 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100770
771 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100772 * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of
773 * the file at download location specified in
774 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100775 *
Benjamin Franzea956242016-03-21 15:45:56 +0000776 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} must be
777 * present. The provided checksum must match the checksum of the file at the download
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100778 * location. If the checksum doesn't match an error will be shown to the user and the user will
779 * be asked to factory reset the device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100780 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000781 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
782 * provisioning via an NFC bump.
Rubin Xud92e7572015-05-18 17:01:13 +0100783 *
784 * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP}
785 * and {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1} only SHA-1 hash is supported.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700786 * Starting from {@link android.os.Build.VERSION_CODES#M}, this parameter accepts SHA-256 in
Rubin Xud92e7572015-05-18 17:01:13 +0100787 * addition to SHA-1. Support for SHA-1 is likely to be removed in future OS releases.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100788 */
789 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100790 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100791
792 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100793 * A String extra holding the URL-safe base64 encoded SHA-256 checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100794 * android package archive at the download location specified in {@link
795 * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
796 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100797 * <p>The signatures of an android package archive can be obtained using
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100798 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
799 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
800 *
Benjamin Franzea956242016-03-21 15:45:56 +0000801 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} must be
802 * present. The provided checksum must match the checksum of any signature of the file at
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100803 * the download location. If the checksum does not match an error will be shown to the user and
804 * the user will be asked to factory reset the device.
805 *
806 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
807 * provisioning via an NFC bump.
808 */
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100809 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM
810 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM";
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100811
812 /**
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000813 * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile
814 * has completed successfully.
815 *
816 * <p>The broadcast is limited to the primary profile, to the app specified in the provisioning
Nicolas Prevotebe2d992015-05-12 18:14:53 -0700817 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000818 *
Mahaver7074caf2016-11-29 20:52:18 +0000819 * <p>This intent will contain the following extras
820 * <ul>
821 * <li>{@link Intent#EXTRA_USER}, corresponds to the {@link UserHandle} of the managed
822 * profile.</li>
823 * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, corresponds to the account requested to
824 * be migrated at provisioning time, if any.</li>
825 * </ul>
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000826 */
827 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
828 public static final String ACTION_MANAGED_PROFILE_PROVISIONED
829 = "android.app.action.MANAGED_PROFILE_PROVISIONED";
830
831 /**
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000832 * Activity action: This activity action is sent to indicate that provisioning of a managed
833 * profile or managed device has completed successfully. It'll be sent at the same time as
834 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast but this will be
835 * delivered faster as it's an activity intent.
836 *
837 * <p>The intent is only sent to the application on the profile that requested provisioning. In
838 * the device owner case the profile is the primary user.
839 *
840 * @see #ACTION_PROVISION_MANAGED_PROFILE
841 * @see #ACTION_PROVISION_MANAGED_DEVICE
842 */
843 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
844 public static final String ACTION_PROVISIONING_SUCCESSFUL =
845 "android.app.action.PROVISIONING_SUCCESSFUL";
846
847 /**
Benjamin Franzea956242016-03-21 15:45:56 +0000848 * A boolean extra indicating whether device encryption can be skipped as part of device owner
849 * or managed profile provisioning.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500850 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400851 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100852 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Benjamin Franzea956242016-03-21 15:45:56 +0000853 *
854 * <p>From {@link android.os.Build.VERSION_CODES#N} onwards, this is also supported for an
855 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500856 */
857 public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION =
858 "android.app.extra.PROVISIONING_SKIP_ENCRYPTION";
859
860 /**
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000861 * A {@link Uri} extra pointing to a logo image. This image will be shown during the
862 * provisioning. If this extra is not passed, a default image will be shown.
863 * <h5>The following URI schemes are accepted:</h5>
864 * <ul>
865 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
866 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
867 * </ul>
868 *
Victor Changc10f6692016-12-09 15:24:00 +0000869 * <p> It is the responsibility of the caller to provide an image with a reasonable
Victor Chang38cfd9c2017-01-04 17:41:11 +0000870 * pixel density for the device.
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000871 *
872 * <p> If a content: URI is passed, the intent should have the flag
873 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
874 * {@link android.content.ClipData} of the intent too.
875 *
876 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or
877 * {@link #ACTION_PROVISION_MANAGED_DEVICE}
878 */
879 public static final String EXTRA_PROVISIONING_LOGO_URI =
880 "android.app.extra.PROVISIONING_LOGO_URI";
881
882 /**
Victor Changc10f6692016-12-09 15:24:00 +0000883 * A {@link Bundle}[] extra consisting of list of disclaimer headers and disclaimer contents.
884 * Each {@link Bundle} must have both {@link #EXTRA_PROVISIONING_DISCLAIMER_HEADER}
885 * as disclaimer header, and {@link #EXTRA_PROVISIONING_DISCLAIMER_CONTENT} as disclaimer
886 * content.
887 *
888 * <p> The extra typically contains one disclaimer from the company of mobile device
889 * management application (MDM), and one disclaimer from the organization.
890 *
891 * <p> Call {@link Bundle#putParcelableArray(String, Parcelable[])} to put the {@link Bundle}[]
892 *
893 * <p> Maximum 3 key-value pairs can be specified. The rest will be ignored.
894 *
895 * <p> Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or
896 * {@link #ACTION_PROVISION_MANAGED_DEVICE}
897 */
898 public static final String EXTRA_PROVISIONING_DISCLAIMERS =
899 "android.app.extra.PROVISIONING_DISCLAIMERS";
900
901 /**
902 * A String extra of localized disclaimer header.
903 *
904 * <p> The extra is typically the company name of mobile device management application (MDM)
905 * or the organization name.
906 *
907 * <p> Use in Bundle {@link #EXTRA_PROVISIONING_DISCLAIMERS}
Victor Chang98607132017-01-27 11:51:56 +0000908 *
909 * <p> System app, i.e. application with {@link ApplicationInfo#FLAG_SYSTEM}, can also insert a
910 * disclaimer by declaring an application-level meta-data in {@code AndroidManifest.xml}.
911 * Must use it with {@link #EXTRA_PROVISIONING_DISCLAIMER_CONTENT}. Here is the example:
912 *
913 * <pre>
914 * &lt;meta-data
915 * android:name="android.app.extra.PROVISIONING_DISCLAIMER_HEADER"
916 * android:resource="@string/disclaimer_header"
917 * /&gt;</pre>
Victor Changc10f6692016-12-09 15:24:00 +0000918 */
919 public static final String EXTRA_PROVISIONING_DISCLAIMER_HEADER =
920 "android.app.extra.PROVISIONING_DISCLAIMER_HEADER";
921
922 /**
923 * A {@link Uri} extra pointing to disclaimer content.
924 *
925 * <h5>The following URI schemes are accepted:</h5>
926 * <ul>
927 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
928 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
929 * </ul>
930 *
931 * <p> Styled text is supported in the disclaimer content. The content is parsed by
932 * {@link android.text.Html#fromHtml(String)} and displayed in a
933 * {@link android.widget.TextView}.
934 *
935 * <p> If a <code>content:</code> URI is passed, URI is passed, the intent should have the flag
936 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
937 * {@link android.content.ClipData} of the intent too.
938 *
939 * <p> Use in Bundle {@link #EXTRA_PROVISIONING_DISCLAIMERS}
Victor Chang98607132017-01-27 11:51:56 +0000940 *
941 * <p> System app, i.e. application with {@link ApplicationInfo#FLAG_SYSTEM}, can also insert a
942 * disclaimer by declaring an application-level meta-data in {@code AndroidManifest.xml}.
943 * Must use it with {@link #EXTRA_PROVISIONING_DISCLAIMER_HEADER}. Here is the example:
944 *
945 * <pre>
946 * &lt;meta-data
947 * android:name="android.app.extra.PROVISIONING_DISCLAIMER_CONTENT"
948 * android:resource="@string/disclaimer_content"
949 * /&gt;</pre>
Victor Changc10f6692016-12-09 15:24:00 +0000950 */
951 public static final String EXTRA_PROVISIONING_DISCLAIMER_CONTENT =
952 "android.app.extra.PROVISIONING_DISCLAIMER_CONTENT";
953
954 /**
Alan Treadway94de8c82016-01-11 10:25:23 +0000955 * A boolean extra indicating if user setup should be skipped, for when provisioning is started
956 * during setup-wizard.
957 *
958 * <p>If unspecified, defaults to {@code true} to match the behavior in
959 * {@link android.os.Build.VERSION_CODES#M} and earlier.
960 *
Alan Treadway1a538d02016-01-18 16:42:30 +0000961 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or
962 * {@link #ACTION_PROVISION_MANAGED_USER}.
Alan Treadway94de8c82016-01-11 10:25:23 +0000963 *
964 * @hide
965 */
966 public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP =
967 "android.app.extra.PROVISIONING_SKIP_USER_SETUP";
968
969 /**
Victor Chang51d84f92016-11-16 12:22:56 +0000970 * A boolean extra indicating if the user consent steps from the provisioning flow should be
971 * skipped. If unspecified, defaults to {@code false}.
972 *
973 * It can only be used by an existing device owner trying to create a managed profile via
974 * {@link #ACTION_PROVISION_MANAGED_PROFILE}. Otherwise it is ignored.
975 */
976 public static final String EXTRA_PROVISIONING_SKIP_USER_CONSENT =
977 "android.app.extra.PROVISIONING_SKIP_USER_CONSENT";
978
979 /**
Benjamin Franzea956242016-03-21 15:45:56 +0000980 * This MIME type is used for starting the device owner provisioning.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100981 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400982 * <p>During device owner provisioning a device admin app is set as the owner of the device.
983 * A device owner has full control over the device. The device owner can not be modified by the
984 * user and the only way of resetting the device is if the device owner app calls a factory
985 * reset.
986 *
987 * <p> A typical use case would be a device that is owned by a company, but used by either an
988 * employee or client.
989 *
Benjamin Franzea956242016-03-21 15:45:56 +0000990 * <p> The NFC message must be sent to an unprovisioned device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100991 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000992 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100993 * contains the following properties:
994 * <ul>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400995 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
996 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100997 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400998 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100999 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
1000 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
1001 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
1002 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
1003 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
1004 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
1005 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
1006 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
1007 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
1008 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Rubin Xu41f2ccb92015-08-05 16:29:13 +01001009 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
1010 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from
1011 * {@link android.os.Build.VERSION_CODES#M} </li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +01001012 *
Nicolas Prevot18440252015-03-09 14:07:17 +00001013 * <p>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07001014 * As of {@link android.os.Build.VERSION_CODES#M}, the properties should contain
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -04001015 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of
1016 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only
1017 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -04001018 */
1019 public static final String MIME_TYPE_PROVISIONING_NFC
1020 = "application/com.android.managedprovisioning";
1021
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +01001022 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001023 * Activity action: ask the user to add a new device administrator to the system.
1024 * The desired policy is the ComponentName of the policy in the
1025 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
1026 * bring the user through adding the device administrator to the system (or
1027 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001028 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001029 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
1030 * field to provide the user with additional explanation (in addition
1031 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001032 *
1033 * <p>If your administrator is already active, this will ordinarily return immediately (without
1034 * user intervention). However, if your administrator has been updated and is requesting
1035 * additional uses-policy flags, the user will be presented with the new list. New policies
1036 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001037 */
1038 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1039 public static final String ACTION_ADD_DEVICE_ADMIN
1040 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001041
Dianne Hackbornd6847842010-01-12 18:14:19 -08001042 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001043 * @hide
1044 * Activity action: ask the user to add a new device administrator as the profile owner
Amith Yamasani814e9872015-03-23 14:04:53 -07001045 * for this user. Only system apps can launch this intent.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001046 *
Amith Yamasani814e9872015-03-23 14:04:53 -07001047 * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN}
1048 * extra field. This will invoke a UI to bring the user through adding the profile owner admin
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001049 * to remotely control restrictions on the user.
1050 *
Makoto Onukic8a5a552015-11-19 14:29:12 -08001051 * <p>The intent must be invoked via {@link Activity#startActivityForResult} to receive the
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001052 * result of whether or not the user approved the action. If approved, the result will
1053 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
1054 * as a profile owner.
1055 *
1056 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
1057 * field to provide the user with additional explanation (in addition
1058 * to your component's description) about what is being added.
1059 *
Amith Yamasani814e9872015-03-23 14:04:53 -07001060 * <p>If there is already a profile owner active or the caller is not a system app, the
1061 * operation will return a failure result.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001062 */
1063 @SystemApi
1064 public static final String ACTION_SET_PROFILE_OWNER
1065 = "android.app.action.SET_PROFILE_OWNER";
1066
1067 /**
1068 * @hide
1069 * Name of the profile owner admin that controls the user.
1070 */
1071 @SystemApi
1072 public static final String EXTRA_PROFILE_OWNER_NAME
1073 = "android.app.extra.PROFILE_OWNER_NAME";
1074
1075 /**
Nicolas Prevot00799002015-07-27 18:15:20 +01001076 * Broadcast action: send when any policy admin changes a policy.
Jim Miller284b62e2010-06-08 14:27:42 -07001077 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -07001078 *
Jim Miller284b62e2010-06-08 14:27:42 -07001079 * @hide
1080 */
1081 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
1082 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
1083
1084 /**
Tony Mak1970f972016-08-30 17:41:48 +01001085 * Broadcast action: sent when the device owner is set, changed or cleared.
Nicolas Prevot00799002015-07-27 18:15:20 +01001086 *
1087 * This broadcast is sent only to the primary user.
1088 * @see #ACTION_PROVISION_MANAGED_DEVICE
1089 */
1090 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1091 public static final String ACTION_DEVICE_OWNER_CHANGED
1092 = "android.app.action.DEVICE_OWNER_CHANGED";
1093
1094 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001095 * The ComponentName of the administrator component.
1096 *
1097 * @see #ACTION_ADD_DEVICE_ADMIN
1098 */
1099 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001100
Dianne Hackbornd6847842010-01-12 18:14:19 -08001101 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001102 * An optional CharSequence providing additional explanation for why the
1103 * admin is being added.
1104 *
1105 * @see #ACTION_ADD_DEVICE_ADMIN
1106 */
1107 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001108
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001109 /**
phweiss73145f42017-01-17 19:06:38 +01001110 * Constant to indicate the feature of disabling the camera. Used as argument to
1111 * {@link #createAdminSupportIntent(String)}.
1112 * @see #setCameraDisabled(ComponentName, boolean)
1113 */
1114 public static final String POLICY_DISABLE_CAMERA = "policy_disable_camera";
1115
1116 /**
1117 * Constant to indicate the feature of disabling screen captures. Used as argument to
1118 * {@link #createAdminSupportIntent(String)}.
1119 * @see #setScreenCaptureDisabled(ComponentName, boolean)
1120 */
1121 public static final String POLICY_DISABLE_SCREEN_CAPTURE = "policy_disable_screen_capture";
1122
1123 /**
1124 * A String indicating a specific restricted feature. Can be a user restriction from the
1125 * {@link UserManager}, e.g. {@link UserManager#DISALLOW_ADJUST_VOLUME}, or one of the values
1126 * {@link #POLICY_DISABLE_CAMERA} or {@link #POLICY_DISABLE_SCREEN_CAPTURE}.
1127 * @see #createAdminSupportIntent(String)
1128 * @hide
1129 */
1130 @TestApi
1131 public static final String EXTRA_RESTRICTION = "android.app.extra.RESTRICTION";
1132
1133 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001134 * Activity action: have the user enter a new password. This activity should
1135 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
1136 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
1137 * enter a new password that meets the current requirements. You can use
1138 * {@link #isActivePasswordSufficient()} to determine whether you need to
1139 * have the user select a new password in order to meet the current
1140 * constraints. Upon being resumed from this activity, you can check the new
1141 * password characteristics to see if they are sufficient.
Benjamin Franzc9921092016-01-08 17:17:44 +00001142 *
1143 * If the intent is launched from within a managed profile with a profile
1144 * owner built against {@link android.os.Build.VERSION_CODES#M} or before,
1145 * this will trigger entering a new password for the parent of the profile.
1146 * For all other cases it will trigger entering a new password for the user
1147 * or profile it is launched from.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001148 *
1149 * @see #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
Dianne Hackbornd6847842010-01-12 18:14:19 -08001150 */
1151 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1152 public static final String ACTION_SET_NEW_PASSWORD
1153 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001154
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001155 /**
Benjamin Franzc9921092016-01-08 17:17:44 +00001156 * Activity action: have the user enter a new password for the parent profile.
1157 * If the intent is launched from within a managed profile, this will trigger
1158 * entering a new password for the parent of the profile. In all other cases
1159 * the behaviour is identical to {@link #ACTION_SET_NEW_PASSWORD}.
1160 */
1161 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1162 public static final String ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
1163 = "android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD";
1164
1165 /**
phweissa0cb2512016-12-14 21:37:48 +01001166 * Broadcast action: Tell the status bar to open the device monitoring dialog, e.g. when
1167 * Network logging was enabled and the user tapped the notification.
1168 * <p class="note">This is a protected intent that can only be sent by the system.</p>
1169 * @hide
1170 */
1171 public static final String ACTION_SHOW_DEVICE_MONITORING_DIALOG
1172 = "android.app.action.SHOW_DEVICE_MONITORING_DIALOG";
1173
1174 /**
Edman Anjos9e62c312017-01-26 22:22:58 +01001175 * Broadcast Action: Sent after application delegation scopes are changed. The new delegation
1176 * scopes will be sent in an {@code ArrayList<String>} extra identified by the
1177 * {@link #EXTRA_DELEGATION_SCOPES} key.
Edman Anjosf9946772016-11-28 16:35:15 +01001178 *
1179 * <p class=”note”> Note: This is a protected intent that can only be sent by the system.</p>
1180 */
1181 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1182 public static final String ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED =
1183 "android.app.action.APPLICATION_DELEGATION_SCOPES_CHANGED";
1184
1185 /**
Edman Anjos9e62c312017-01-26 22:22:58 +01001186 * An {@code ArrayList<String>} corresponding to the delegation scopes given to an app in the
Edman Anjosf9946772016-11-28 16:35:15 +01001187 * {@link #ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED} broadcast.
1188 */
1189 public static final String EXTRA_DELEGATION_SCOPES = "android.app.extra.DELEGATION_SCOPES";
1190
1191 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +00001192 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
1193 * the parent profile to access intents sent from the managed profile.
1194 * That is, when an app in the managed profile calls
1195 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
1196 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001197 */
Nicolas Prevot86a96732014-09-08 12:13:05 +01001198 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001199
1200 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +00001201 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
1202 * the managed profile to access intents sent from the parent profile.
1203 * That is, when an app in the parent profile calls
1204 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
1205 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001206 */
Nicolas Prevot86a96732014-09-08 12:13:05 +01001207 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001208
Dianne Hackbornd6847842010-01-12 18:14:19 -08001209 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01001210 * Broadcast action: notify that a new local system update policy has been set by the device
1211 * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00001212 */
1213 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Rubin Xu5faad8e2015-04-20 17:43:48 +01001214 public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED
1215 = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED";
Rubin Xu8027a4f2015-03-10 17:52:37 +00001216
Amith Yamasanid49489b2015-04-28 14:00:26 -07001217 /**
1218 * Permission policy to prompt user for new permission requests for runtime permissions.
1219 * Already granted or denied permissions are not affected by this.
1220 */
1221 public static final int PERMISSION_POLICY_PROMPT = 0;
1222
1223 /**
1224 * Permission policy to always grant new permission requests for runtime permissions.
1225 * Already granted or denied permissions are not affected by this.
1226 */
1227 public static final int PERMISSION_POLICY_AUTO_GRANT = 1;
1228
1229 /**
1230 * Permission policy to always deny new permission requests for runtime permissions.
1231 * Already granted or denied permissions are not affected by this.
1232 */
1233 public static final int PERMISSION_POLICY_AUTO_DENY = 2;
1234
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07001235 /**
1236 * Runtime permission state: The user can manage the permission
1237 * through the UI.
1238 */
1239 public static final int PERMISSION_GRANT_STATE_DEFAULT = 0;
1240
1241 /**
1242 * Runtime permission state: The permission is granted to the app
1243 * and the user cannot manage the permission through the UI.
1244 */
1245 public static final int PERMISSION_GRANT_STATE_GRANTED = 1;
1246
1247 /**
1248 * Runtime permission state: The permission is denied to the app
1249 * and the user cannot manage the permission through the UI.
1250 */
1251 public static final int PERMISSION_GRANT_STATE_DENIED = 2;
Rubin Xu8027a4f2015-03-10 17:52:37 +00001252
1253 /**
Edman Anjosf9946772016-11-28 16:35:15 +01001254 * Delegation of certificate installation and management. This scope grants access to the
1255 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
1256 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair} APIs.
1257 */
1258 public static final String DELEGATION_CERT_INSTALL = "delegation-cert-install";
1259
1260 /**
1261 * Delegation of application restrictions management. This scope grants access to the
1262 * {@link #setApplicationRestrictions} and {@link #getApplicationRestrictions} APIs.
1263 */
1264 public static final String DELEGATION_APP_RESTRICTIONS = "delegation-app-restrictions";
1265
1266 /**
Edman Anjosa5f2fb12016-12-19 11:25:54 -08001267 * Delegation of application uninstall block. This scope grants access to the
1268 * {@link #setUninstallBlocked} API.
1269 */
1270 public static final String DELEGATION_BLOCK_UNINSTALL = "delegation-block-uninstall";
1271
1272 /**
Edman Anjos52088e42017-01-13 22:26:17 +01001273 * Delegation of permission policy and permission grant state. This scope grants access to the
1274 * {@link #setPermissionPolicy}, {@link #getPermissionGrantState},
1275 * and {@link #setPermissionGrantState} APIs.
1276 */
1277 public static final String DELEGATION_PERMISSION_GRANT = "delegation-permission-grant";
1278
1279 /**
1280 * Delegation of package access state. This scope grants access to the
1281 * {@link #isApplicationHidden}, {@link #setApplicationHidden}, {@link #isPackageSuspended}, and
1282 * {@link #setPackagesSuspended} APIs.
1283 */
1284 public static final String DELEGATION_PACKAGE_ACCESS = "delegation-package-access";
1285
1286 /**
1287 * Delegation for enabling system apps. This scope grants access to the {@link #enableSystemApp}
1288 * API.
1289 */
1290 public static final String DELEGATION_ENABLE_SYSTEM_APP = "delegation-enable-system-app";
1291
1292 /**
1293 * Delegation of management of uninstalled packages. This scope grants access to the
1294 * {@code #setKeepUninstalledPackages} and {@code #getKeepUninstalledPackages} APIs.
1295 * @hide
1296 */
1297 public static final String DELEGATION_KEEP_UNINSTALLED_PACKAGES =
1298 "delegation-keep-uninstalled-packages";
1299
1300 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00001301 * No management for current user in-effect. This is the default.
1302 * @hide
1303 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001304 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001305 public static final int STATE_USER_UNMANAGED = 0;
1306
1307 /**
1308 * Management partially setup, user setup needs to be completed.
1309 * @hide
1310 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001311 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001312 public static final int STATE_USER_SETUP_INCOMPLETE = 1;
1313
1314 /**
1315 * Management partially setup, user setup completed.
1316 * @hide
1317 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001318 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001319 public static final int STATE_USER_SETUP_COMPLETE = 2;
1320
1321 /**
1322 * Management setup and active on current user.
1323 * @hide
1324 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001325 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001326 public static final int STATE_USER_SETUP_FINALIZED = 3;
1327
1328 /**
1329 * Management partially setup on a managed profile.
1330 * @hide
1331 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001332 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001333 public static final int STATE_USER_PROFILE_COMPLETE = 4;
1334
1335 /**
1336 * @hide
1337 */
1338 @IntDef({STATE_USER_UNMANAGED, STATE_USER_SETUP_INCOMPLETE, STATE_USER_SETUP_COMPLETE,
1339 STATE_USER_SETUP_FINALIZED, STATE_USER_PROFILE_COMPLETE})
1340 @Retention(RetentionPolicy.SOURCE)
1341 public @interface UserProvisioningState {}
1342
1343 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001344 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001345 *
1346 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1347 * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and
1348 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when provisioning is allowed.
1349 *
1350 * @hide
1351 */
1352 public static final int CODE_OK = 0;
1353
1354 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001355 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001356 *
1357 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and
1358 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the device already has a device
1359 * owner.
1360 *
1361 * @hide
1362 */
1363 public static final int CODE_HAS_DEVICE_OWNER = 1;
1364
1365 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001366 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001367 *
1368 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1369 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user has a profile owner and for
1370 * {@link #ACTION_PROVISION_MANAGED_PROFILE} when the profile owner is already set.
1371 *
1372 * @hide
1373 */
1374 public static final int CODE_USER_HAS_PROFILE_OWNER = 2;
1375
1376 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001377 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001378 *
1379 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and
1380 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user isn't running.
1381 *
1382 * @hide
1383 */
1384 public static final int CODE_USER_NOT_RUNNING = 3;
1385
1386 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001387 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001388 *
1389 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1390 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the device has already been setup and
1391 * for {@link #ACTION_PROVISION_MANAGED_USER} if the user has already been setup.
1392 *
1393 * @hide
1394 */
1395 public static final int CODE_USER_SETUP_COMPLETED = 4;
1396
1397 /**
1398 * Code used to indicate that the device also has a user other than the system user.
1399 *
1400 * @hide
1401 */
1402 public static final int CODE_NONSYSTEM_USER_EXISTS = 5;
1403
1404 /**
1405 * Code used to indicate that device has an account that prevents provisioning.
1406 *
1407 * @hide
1408 */
1409 public static final int CODE_ACCOUNTS_NOT_EMPTY = 6;
1410
1411 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001412 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001413 *
1414 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and
1415 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the user is not a system user.
1416 *
1417 * @hide
1418 */
1419 public static final int CODE_NOT_SYSTEM_USER = 7;
1420
1421 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001422 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001423 *
1424 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1425 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} and {@link #ACTION_PROVISION_MANAGED_USER}
1426 * when the device is a watch and is already paired.
1427 *
1428 * @hide
1429 */
1430 public static final int CODE_HAS_PAIRED = 8;
1431
1432 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001433 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001434 *
1435 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} and
1436 * {@link #ACTION_PROVISION_MANAGED_USER} on devices which do not support managed users.
1437 *
1438 * @see {@link PackageManager#FEATURE_MANAGED_USERS}
1439 * @hide
1440 */
1441 public static final int CODE_MANAGED_USERS_NOT_SUPPORTED = 9;
1442
1443 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001444 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001445 *
1446 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} if the user is a system user.
1447 *
1448 * @hide
1449 */
1450 public static final int CODE_SYSTEM_USER = 10;
1451
1452 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001453 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001454 *
1455 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when the user cannot have more
1456 * managed profiles.
1457 *
1458 * @hide
1459 */
1460 public static final int CODE_CANNOT_ADD_MANAGED_PROFILE = 11;
1461
1462 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001463 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001464 *
1465 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} and
1466 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices not running with split system
1467 * user.
1468 *
1469 * @hide
1470 */
1471 public static final int CODE_NOT_SYSTEM_USER_SPLIT = 12;
1472
1473 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001474 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001475 *
1476 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1477 * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and
1478 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices which do no support device
1479 * admins.
1480 *
1481 * @hide
1482 */
1483 public static final int CODE_DEVICE_ADMIN_NOT_SUPPORTED = 13;
1484
1485 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001486 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001487 *
Esteban Talavera6c9116a2016-11-24 16:12:44 +00001488 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when the device the user is a
1489 * system user on a split system user device.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001490 *
1491 * @hide
1492 */
1493 public static final int CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER = 14;
1494
1495 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001496 * Result code for {@link #checkProvisioningPreCondition}.
1497 *
1498 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when adding a managed profile is
1499 * disallowed by {@link UserManager#DISALLOW_ADD_MANAGED_PROFILE}.
1500 *
1501 * @hide
1502 */
1503 public static final int CODE_ADD_MANAGED_PROFILE_DISALLOWED = 15;
1504
1505 /**
1506 * Result codes for {@link #checkProvisioningPreCondition} indicating all the provisioning pre
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001507 * conditions.
1508 *
1509 * @hide
1510 */
1511 @Retention(RetentionPolicy.SOURCE)
1512 @IntDef({CODE_OK, CODE_HAS_DEVICE_OWNER, CODE_USER_HAS_PROFILE_OWNER, CODE_USER_NOT_RUNNING,
1513 CODE_USER_SETUP_COMPLETED, CODE_NOT_SYSTEM_USER, CODE_HAS_PAIRED,
1514 CODE_MANAGED_USERS_NOT_SUPPORTED, CODE_SYSTEM_USER, CODE_CANNOT_ADD_MANAGED_PROFILE,
1515 CODE_NOT_SYSTEM_USER_SPLIT, CODE_DEVICE_ADMIN_NOT_SUPPORTED,
Esteban Talavera01576862016-12-15 11:16:44 +00001516 CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER, CODE_ADD_MANAGED_PROFILE_DISALLOWED})
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001517 public @interface ProvisioningPreCondition {}
1518
1519 /**
Makoto Onukifc73d792017-03-22 14:22:35 -07001520 * Service action: Action for a service that device owner and profile owner can optionally
1521 * own. If a device owner or a profile owner has such a service, the system tries to keep
1522 * a bound connection to it, in order to keep their process always running.
1523 * The service must not be exported.
1524 */
1525 @SdkConstant(SdkConstantType.SERVICE_ACTION)
1526 public static final String ACTION_DEVICE_ADMIN_SERVICE
1527 = "android.app.action.DEVICE_ADMIN_SERVICE";
1528
1529 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001530 * Return true if the given administrator component is currently active (enabled) in the system.
1531 *
1532 * @param admin The administrator component to check for.
1533 * @return {@code true} if {@code admin} is currently enabled in the system, {@code false}
1534 * otherwise
Dianne Hackbornd6847842010-01-12 18:14:19 -08001535 */
Robin Lee25e26452015-06-02 09:56:29 -07001536 public boolean isAdminActive(@NonNull ComponentName admin) {
Charles He8c760562016-10-25 16:36:53 +01001537 throwIfParentInstance("isAdminActive");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001538 return isAdminActiveAsUser(admin, myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001539 }
1540
1541 /**
1542 * @see #isAdminActive(ComponentName)
1543 * @hide
1544 */
Robin Lee25e26452015-06-02 09:56:29 -07001545 public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001546 if (mService != null) {
1547 try {
Robin Lee25e26452015-06-02 09:56:29 -07001548 return mService.isAdminActive(admin, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001549 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001550 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001551 }
1552 }
1553 return false;
1554 }
Charles Hedea0c3b2017-01-13 10:04:12 +00001555
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001556 /**
1557 * Return true if the given administrator component is currently being removed
1558 * for the user.
1559 * @hide
1560 */
Robin Lee25e26452015-06-02 09:56:29 -07001561 public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) {
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001562 if (mService != null) {
1563 try {
Robin Lee25e26452015-06-02 09:56:29 -07001564 return mService.isRemovingAdmin(admin, userId);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001565 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001566 throw e.rethrowFromSystemServer();
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001567 }
1568 }
1569 return false;
1570 }
1571
Dianne Hackbornd6847842010-01-12 18:14:19 -08001572 /**
Robin Lee25e26452015-06-02 09:56:29 -07001573 * Return a list of all currently active device administrators' component
1574 * names. If there are no administrators {@code null} may be
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001575 * returned.
1576 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07001577 public @Nullable List<ComponentName> getActiveAdmins() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001578 throwIfParentInstance("getActiveAdmins");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001579 return getActiveAdminsAsUser(myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001580 }
1581
1582 /**
1583 * @see #getActiveAdmins()
1584 * @hide
1585 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07001586 public @Nullable List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001587 if (mService != null) {
1588 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001589 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001590 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001591 throw e.rethrowFromSystemServer();
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001592 }
1593 }
1594 return null;
1595 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001596
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001597 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001598 * Used by package administration code to determine if a package can be stopped
1599 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001600 * @hide
1601 */
David Ouyang3a83a332017-01-11 16:36:40 -08001602 @SystemApi
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001603 public boolean packageHasActiveAdmins(String packageName) {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001604 return packageHasActiveAdmins(packageName, myUserId());
1605 }
1606
1607 /**
1608 * Used by package administration code to determine if a package can be stopped
1609 * or uninstalled.
1610 * @hide
1611 */
1612 public boolean packageHasActiveAdmins(String packageName, int userId) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001613 if (mService != null) {
1614 try {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001615 return mService.packageHasActiveAdmins(packageName, userId);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001616 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001617 throw e.rethrowFromSystemServer();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001618 }
1619 }
1620 return false;
1621 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001622
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001623 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001624 * Remove a current administration component. This can only be called
1625 * by the application that owns the administration component; if you
1626 * try to remove someone else's component, a security exception will be
1627 * thrown.
Esteban Talavera552a5612016-02-19 17:02:24 +00001628 *
1629 * <p>Note that the operation is not synchronous and the admin might still be active (as
1630 * indicated by {@link #getActiveAdmins()}) by the time this method returns.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001631 *
1632 * @param admin The administration compononent to remove.
1633 * @throws SecurityException if the caller is not in the owner application of {@code admin}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001634 */
Robin Lee25e26452015-06-02 09:56:29 -07001635 public void removeActiveAdmin(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001636 throwIfParentInstance("removeActiveAdmin");
Dianne Hackbornd6847842010-01-12 18:14:19 -08001637 if (mService != null) {
1638 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001639 mService.removeActiveAdmin(admin, myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001640 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001641 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001642 }
1643 }
1644 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001645
Dianne Hackbornd6847842010-01-12 18:14:19 -08001646 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001647 * Returns true if an administrator has been granted a particular device policy. This can be
1648 * used to check whether the administrator was activated under an earlier set of policies, but
1649 * requires additional policies after an upgrade.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001650 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001651 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be an
1652 * active administrator, or an exception will be thrown.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001653 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001654 * @throws SecurityException if {@code admin} is not an active administrator.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001655 */
Robin Lee25e26452015-06-02 09:56:29 -07001656 public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001657 throwIfParentInstance("hasGrantedPolicy");
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001658 if (mService != null) {
1659 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001660 return mService.hasGrantedPolicy(admin, usesPolicy, myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001661 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001662 throw e.rethrowFromSystemServer();
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001663 }
1664 }
1665 return false;
1666 }
1667
1668 /**
Clara Bayarria1771112015-12-18 16:29:18 +00001669 * Returns true if the Profile Challenge is available to use for the given profile user.
1670 *
1671 * @hide
1672 */
1673 public boolean isSeparateProfileChallengeAllowed(int userHandle) {
1674 if (mService != null) {
1675 try {
1676 return mService.isSeparateProfileChallengeAllowed(userHandle);
1677 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001678 throw e.rethrowFromSystemServer();
Clara Bayarria1771112015-12-18 16:29:18 +00001679 }
1680 }
1681 return false;
1682 }
1683
1684 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001685 * Constant for {@link #setPasswordQuality}: the policy has no requirements
1686 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001687 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001688 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001689 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001690
Dianne Hackbornd6847842010-01-12 18:14:19 -08001691 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -07001692 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
1693 * recognition technology. This implies technologies that can recognize the identity of
1694 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
1695 * Note that quality constants are ordered so that higher values are more restrictive.
1696 */
1697 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
1698
1699 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001700 * Constant for {@link #setPasswordQuality}: the policy requires some kind
Benjamin Franzc6a96532015-06-16 11:23:38 +01001701 * of password or pattern, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001702 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001703 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001704 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001705
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001706 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001707 * Constant for {@link #setPasswordQuality}: the user must have entered a
1708 * password containing at least numeric characters. Note that quality
1709 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001710 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001711 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001712
Dianne Hackbornd6847842010-01-12 18:14:19 -08001713 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001714 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -08001715 * password containing at least numeric characters with no repeating (4444)
1716 * or ordered (1234, 4321, 2468) sequences. Note that quality
1717 * constants are ordered so that higher values are more restrictive.
1718 */
1719 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
1720
1721 /**
1722 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001723 * password containing at least alphabetic (or other symbol) characters.
1724 * Note that quality constants are ordered so that higher values are more
1725 * restrictive.
1726 */
1727 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001728
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001729 /**
1730 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001731 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001732 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001733 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001734 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001735 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001736
Dianne Hackbornd6847842010-01-12 18:14:19 -08001737 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001738 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001739 * password containing at least a letter, a numerical digit and a special
1740 * symbol, by default. With this password quality, passwords can be
1741 * restricted to contain various sets of characters, like at least an
1742 * uppercase letter, etc. These are specified using various methods,
1743 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
1744 * that quality constants are ordered so that higher values are more
1745 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001746 */
1747 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
1748
1749 /**
Oleksandr Peletskyi0fdcd3d2016-01-13 16:49:56 +01001750 * Constant for {@link #setPasswordQuality}: the user is not allowed to
1751 * modify password. In case this password quality is set, the password is
1752 * managed by a profile owner. The profile owner can set any password,
1753 * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note
1754 * that quality constants are ordered so that higher values are more
1755 * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is
1756 * the highest.
1757 * @hide
1758 */
1759 public static final int PASSWORD_QUALITY_MANAGED = 0x80000;
1760
1761 /**
Makoto Onuki5e7e06702016-09-01 18:02:01 -07001762 * @hide
1763 *
1764 * adb shell dpm set-{device,profile}-owner will normally not allow installing an owner to
1765 * a user with accounts. {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED}
1766 * and {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} are the account features
1767 * used by authenticator to exempt their accounts from this:
1768 *
1769 * <ul>
1770 * <li>Non-test-only DO/PO still can't be installed when there are accounts.
1771 * <p>In order to make an apk test-only, add android:testOnly="true" to the
1772 * &lt;application&gt; tag in the manifest.
1773 *
1774 * <li>Test-only DO/PO can be installed even when there are accounts, as long as all the
1775 * accounts have the {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} feature.
1776 * Some authenticators claim to have any features, so to detect it, we also check
1777 * {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} and disallow installing
1778 * if any of the accounts have it.
1779 * </ul>
1780 */
Makoto Onuki47c203d2017-02-13 16:21:19 -08001781 @SystemApi
1782 @TestApi
Makoto Onuki5e7e06702016-09-01 18:02:01 -07001783 public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED =
1784 "android.account.DEVICE_OR_PROFILE_OWNER_ALLOWED";
1785
1786 /** @hide See {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} */
Makoto Onuki47c203d2017-02-13 16:21:19 -08001787 @SystemApi
1788 @TestApi
Makoto Onuki5e7e06702016-09-01 18:02:01 -07001789 public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED =
1790 "android.account.DEVICE_OR_PROFILE_OWNER_DISALLOWED";
1791
1792 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001793 * Called by an application that is administering the device to set the password restrictions it
1794 * is imposing. After setting this, the user will not be able to enter a new password that is
1795 * not at least as restrictive as what has been set. Note that the current password will remain
1796 * until the user has set a new one, so the change does not take place immediately. To prompt
1797 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
Esteban Talaverac1c83592016-02-17 17:56:15 +00001798 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after calling this method.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001799 * <p>
1800 * Quality constants are ordered so that higher values are more restrictive; thus the highest
1801 * requested quality constant (between the policy set here, the user's preference, and any other
1802 * considerations) is the one that is in effect.
1803 * <p>
1804 * The calling device admin must have requested
1805 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1806 * not, a security exception will be thrown.
1807 * <p>
1808 * This method can be called on the {@link DevicePolicyManager} instance returned by
1809 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1810 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001811 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001812 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001813 * @param quality The new desired quality. One of {@link #PASSWORD_QUALITY_UNSPECIFIED},
1814 * {@link #PASSWORD_QUALITY_SOMETHING}, {@link #PASSWORD_QUALITY_NUMERIC},
1815 * {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC},
1816 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} or {@link #PASSWORD_QUALITY_COMPLEX}.
1817 * @throws SecurityException if {@code admin} is not an active administrator or if {@code admin}
1818 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Dianne Hackbornd6847842010-01-12 18:14:19 -08001819 */
Robin Lee25e26452015-06-02 09:56:29 -07001820 public void setPasswordQuality(@NonNull ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001821 if (mService != null) {
1822 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001823 mService.setPasswordQuality(admin, quality, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001824 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001825 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001826 }
1827 }
1828 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001829
Dianne Hackbornd6847842010-01-12 18:14:19 -08001830 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001831 * Retrieve the current minimum password quality for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01001832 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00001833 * a separate challenge are not taken into account.
1834 *
1835 * <p>This method can be called on the {@link DevicePolicyManager} instance
1836 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1837 * restrictions on the parent profile.
1838 *
Robin Lee25e26452015-06-02 09:56:29 -07001839 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001840 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001841 */
Robin Lee25e26452015-06-02 09:56:29 -07001842 public int getPasswordQuality(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001843 return getPasswordQuality(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001844 }
1845
1846 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001847 public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001848 if (mService != null) {
1849 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001850 return mService.getPasswordQuality(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001851 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001852 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001853 }
1854 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001855 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001856 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001857
Dianne Hackbornd6847842010-01-12 18:14:19 -08001858 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001859 * Called by an application that is administering the device to set the minimum allowed password
1860 * length. After setting this, the user will not be able to enter a new password that is not at
1861 * least as restrictive as what has been set. Note that the current password will remain until
1862 * the user has set a new one, so the change does not take place immediately. To prompt the user
1863 * for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
1864 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
1865 * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC}
1866 * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC},
1867 * {@link #PASSWORD_QUALITY_ALPHANUMERIC}, or {@link #PASSWORD_QUALITY_COMPLEX} with
1868 * {@link #setPasswordQuality}.
1869 * <p>
1870 * The calling device admin must have requested
1871 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1872 * not, a security exception will be thrown.
1873 * <p>
1874 * This method can be called on the {@link DevicePolicyManager} instance returned by
1875 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1876 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001877 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001878 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001879 * @param length The new desired minimum password length. A value of 0 means there is no
1880 * restriction.
1881 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1882 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Dianne Hackbornd6847842010-01-12 18:14:19 -08001883 */
Robin Lee25e26452015-06-02 09:56:29 -07001884 public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001885 if (mService != null) {
1886 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001887 mService.setPasswordMinimumLength(admin, length, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001888 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001889 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001890 }
1891 }
1892 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001893
Dianne Hackbornd6847842010-01-12 18:14:19 -08001894 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001895 * Retrieve the current minimum password length for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01001896 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00001897 * a separate challenge are not taken into account.
1898 *
1899 * <p>This method can be called on the {@link DevicePolicyManager} instance
1900 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1901 * restrictions on the parent profile.
1902 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001903 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001904 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001905 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001906 */
Robin Lee25e26452015-06-02 09:56:29 -07001907 public int getPasswordMinimumLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001908 return getPasswordMinimumLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001909 }
1910
1911 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001912 public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001913 if (mService != null) {
1914 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001915 return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001916 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001917 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001918 }
1919 }
1920 return 0;
1921 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001922
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001923 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001924 * Called by an application that is administering the device to set the minimum number of upper
1925 * case letters required in the password. After setting this, the user will not be able to enter
1926 * a new password that is not at least as restrictive as what has been set. Note that the
1927 * current password will remain until the user has set a new one, so the change does not take
1928 * place immediately. To prompt the user for a new password, use
1929 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
1930 * setting this value. This constraint is only imposed if the administrator has also requested
1931 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001932 * <p>
1933 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001934 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1935 * not, a security exception will be thrown.
1936 * <p>
1937 * This method can be called on the {@link DevicePolicyManager} instance returned by
1938 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1939 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001940 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001941 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1942 * @param length The new desired minimum number of upper case letters required in the password.
1943 * A value of 0 means there is no restriction.
1944 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1945 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001946 */
Robin Lee25e26452015-06-02 09:56:29 -07001947 public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001948 if (mService != null) {
1949 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001950 mService.setPasswordMinimumUpperCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001951 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001952 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001953 }
1954 }
1955 }
1956
1957 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001958 * Retrieve the current number of upper case letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01001959 * for a particular admin or all admins that set restrictions on this user and
Esteban Talaverac1c83592016-02-17 17:56:15 +00001960 * its participating profiles. Restrictions on profiles that have a separate challenge
1961 * are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001962 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001963 * {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001964 * and only applies when the password quality is
1965 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001966 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001967 * <p>This method can be called on the {@link DevicePolicyManager} instance
1968 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1969 * restrictions on the parent profile.
1970 *
Robin Lee25e26452015-06-02 09:56:29 -07001971 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001972 * aggregate all admins.
1973 * @return The minimum number of upper case letters required in the
1974 * password.
1975 */
Robin Lee25e26452015-06-02 09:56:29 -07001976 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001977 return getPasswordMinimumUpperCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001978 }
1979
1980 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001981 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001982 if (mService != null) {
1983 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001984 return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001985 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001986 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001987 }
1988 }
1989 return 0;
1990 }
1991
1992 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001993 * Called by an application that is administering the device to set the minimum number of lower
1994 * case letters required in the password. After setting this, the user will not be able to enter
1995 * a new password that is not at least as restrictive as what has been set. Note that the
1996 * current password will remain until the user has set a new one, so the change does not take
1997 * place immediately. To prompt the user for a new password, use
1998 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
1999 * setting this value. This constraint is only imposed if the administrator has also requested
2000 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002001 * <p>
2002 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002003 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2004 * not, a security exception will be thrown.
2005 * <p>
2006 * This method can be called on the {@link DevicePolicyManager} instance returned by
2007 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2008 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002009 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002010 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2011 * @param length The new desired minimum number of lower case letters required in the password.
2012 * A value of 0 means there is no restriction.
2013 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2014 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002015 */
Robin Lee25e26452015-06-02 09:56:29 -07002016 public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002017 if (mService != null) {
2018 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002019 mService.setPasswordMinimumLowerCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002020 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002021 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002022 }
2023 }
2024 }
2025
2026 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002027 * Retrieve the current number of lower case letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002028 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002029 * and its participating profiles. Restrictions on profiles that have
2030 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01002031 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00002032 * {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002033 * and only applies when the password quality is
2034 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002035 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002036 * <p>This method can be called on the {@link DevicePolicyManager} instance
2037 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2038 * restrictions on the parent profile.
2039 *
Robin Lee25e26452015-06-02 09:56:29 -07002040 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002041 * aggregate all admins.
2042 * @return The minimum number of lower case letters required in the
2043 * password.
2044 */
Robin Lee25e26452015-06-02 09:56:29 -07002045 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002046 return getPasswordMinimumLowerCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002047 }
2048
2049 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002050 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002051 if (mService != null) {
2052 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002053 return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002054 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002055 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002056 }
2057 }
2058 return 0;
2059 }
2060
2061 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002062 * Called by an application that is administering the device to set the minimum number of
2063 * letters required in the password. After setting this, the user will not be able to enter a
2064 * new password that is not at least as restrictive as what has been set. Note that the current
2065 * password will remain until the user has set a new one, so the change does not take place
2066 * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
2067 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
2068 * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
2069 * {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002070 * <p>
2071 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002072 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2073 * not, a security exception will be thrown.
2074 * <p>
2075 * This method can be called on the {@link DevicePolicyManager} instance returned by
2076 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2077 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002078 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002079 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2080 * @param length The new desired minimum number of letters required in the password. A value of
2081 * 0 means there is no restriction.
2082 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2083 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002084 */
Robin Lee25e26452015-06-02 09:56:29 -07002085 public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002086 if (mService != null) {
2087 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002088 mService.setPasswordMinimumLetters(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002089 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002090 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002091 }
2092 }
2093 }
2094
2095 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002096 * Retrieve the current number of letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002097 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002098 * and its participating profiles. Restrictions on profiles that have
2099 * a separate challenge are not taken into account.
2100 * This is the same value as set by
2101 * {@link #setPasswordMinimumLetters(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002102 * and only applies when the password quality is
2103 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002104 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002105 * <p>This method can be called on the {@link DevicePolicyManager} instance
2106 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2107 * restrictions on the parent profile.
2108 *
Robin Lee25e26452015-06-02 09:56:29 -07002109 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002110 * aggregate all admins.
2111 * @return The minimum number of letters required in the password.
2112 */
Robin Lee25e26452015-06-02 09:56:29 -07002113 public int getPasswordMinimumLetters(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002114 return getPasswordMinimumLetters(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002115 }
2116
2117 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002118 public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002119 if (mService != null) {
2120 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002121 return mService.getPasswordMinimumLetters(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002122 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002123 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002124 }
2125 }
2126 return 0;
2127 }
2128
2129 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002130 * Called by an application that is administering the device to set the minimum number of
2131 * numerical digits required in the password. After setting this, the user will not be able to
2132 * enter a new password that is not at least as restrictive as what has been set. Note that the
2133 * current password will remain until the user has set a new one, so the change does not take
2134 * place immediately. To prompt the user for a new password, use
2135 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
2136 * setting this value. This constraint is only imposed if the administrator has also requested
2137 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002138 * <p>
2139 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002140 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2141 * not, a security exception will be thrown.
2142 * <p>
2143 * This method can be called on the {@link DevicePolicyManager} instance returned by
2144 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2145 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002146 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002147 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2148 * @param length The new desired minimum number of numerical digits required in the password. A
2149 * value of 0 means there is no restriction.
2150 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2151 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002152 */
Robin Lee25e26452015-06-02 09:56:29 -07002153 public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002154 if (mService != null) {
2155 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002156 mService.setPasswordMinimumNumeric(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002157 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002158 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002159 }
2160 }
2161 }
2162
2163 /**
2164 * Retrieve the current number of numerical digits required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002165 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002166 * and its participating profiles. Restrictions on profiles that have
2167 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01002168 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00002169 * {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002170 * and only applies when the password quality is
2171 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002172 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002173 * <p>This method can be called on the {@link DevicePolicyManager} instance
2174 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2175 * restrictions on the parent profile.
2176 *
Robin Lee25e26452015-06-02 09:56:29 -07002177 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002178 * aggregate all admins.
2179 * @return The minimum number of numerical digits required in the password.
2180 */
Robin Lee25e26452015-06-02 09:56:29 -07002181 public int getPasswordMinimumNumeric(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002182 return getPasswordMinimumNumeric(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002183 }
2184
2185 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002186 public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002187 if (mService != null) {
2188 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002189 return mService.getPasswordMinimumNumeric(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002190 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002191 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002192 }
2193 }
2194 return 0;
2195 }
2196
2197 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002198 * Called by an application that is administering the device to set the minimum number of
2199 * symbols required in the password. After setting this, the user will not be able to enter a
2200 * new password that is not at least as restrictive as what has been set. Note that the current
2201 * password will remain until the user has set a new one, so the change does not take place
2202 * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
2203 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
2204 * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
2205 * {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002206 * <p>
2207 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002208 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2209 * not, a security exception will be thrown.
2210 * <p>
2211 * This method can be called on the {@link DevicePolicyManager} instance returned by
2212 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2213 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002214 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002215 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2216 * @param length The new desired minimum number of symbols required in the password. A value of
2217 * 0 means there is no restriction.
2218 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2219 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002220 */
Robin Lee25e26452015-06-02 09:56:29 -07002221 public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002222 if (mService != null) {
2223 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002224 mService.setPasswordMinimumSymbols(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002225 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002226 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002227 }
2228 }
2229 }
2230
2231 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002232 * Retrieve the current number of symbols required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002233 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002234 * and its participating profiles. Restrictions on profiles that have
2235 * a separate challenge are not taken into account. This is the same value as
2236 * set by {@link #setPasswordMinimumSymbols(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002237 * and only applies when the password quality is
2238 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002239 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002240 * <p>This method can be called on the {@link DevicePolicyManager} instance
2241 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2242 * restrictions on the parent profile.
2243 *
Robin Lee25e26452015-06-02 09:56:29 -07002244 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002245 * aggregate all admins.
2246 * @return The minimum number of symbols required in the password.
2247 */
Robin Lee25e26452015-06-02 09:56:29 -07002248 public int getPasswordMinimumSymbols(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002249 return getPasswordMinimumSymbols(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002250 }
2251
2252 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002253 public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002254 if (mService != null) {
2255 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002256 return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002257 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002258 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002259 }
2260 }
2261 return 0;
2262 }
2263
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002264 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002265 * Called by an application that is administering the device to set the minimum number of
2266 * non-letter characters (numerical digits or symbols) required in the password. After setting
2267 * this, the user will not be able to enter a new password that is not at least as restrictive
2268 * as what has been set. Note that the current password will remain until the user has set a new
2269 * one, so the change does not take place immediately. To prompt the user for a new password,
2270 * use {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
2271 * setting this value. This constraint is only imposed if the administrator has also requested
2272 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002273 * <p>
2274 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002275 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2276 * not, a security exception will be thrown.
2277 * <p>
2278 * This method can be called on the {@link DevicePolicyManager} instance returned by
2279 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2280 * profile.
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002281 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002282 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2283 * @param length The new desired minimum number of letters required in the password. A value of
2284 * 0 means there is no restriction.
2285 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2286 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002287 */
Robin Lee25e26452015-06-02 09:56:29 -07002288 public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002289 if (mService != null) {
2290 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002291 mService.setPasswordMinimumNonLetter(admin, length, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002292 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002293 throw e.rethrowFromSystemServer();
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002294 }
2295 }
2296 }
2297
2298 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002299 * Retrieve the current number of non-letter characters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002300 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002301 * and its participating profiles. Restrictions on profiles that have
2302 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01002303 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00002304 * {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002305 * and only applies when the password quality is
2306 * {@link #PASSWORD_QUALITY_COMPLEX}.
2307 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002308 * <p>This method can be called on the {@link DevicePolicyManager} instance
2309 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2310 * restrictions on the parent profile.
2311 *
Robin Lee25e26452015-06-02 09:56:29 -07002312 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002313 * aggregate all admins.
2314 * @return The minimum number of letters required in the password.
2315 */
Robin Lee25e26452015-06-02 09:56:29 -07002316 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002317 return getPasswordMinimumNonLetter(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002318 }
2319
2320 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002321 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002322 if (mService != null) {
2323 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002324 return mService.getPasswordMinimumNonLetter(admin, userHandle, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002325 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002326 throw e.rethrowFromSystemServer();
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002327 }
2328 }
2329 return 0;
2330 }
2331
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002332 /**
2333 * Called by an application that is administering the device to set the length of the password
2334 * history. After setting this, the user will not be able to enter a new password that is the
2335 * same as any password in the history. Note that the current password will remain until the
2336 * user has set a new one, so the change does not take place immediately. To prompt the user for
2337 * a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
2338 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
2339 * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC}
2340 * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX} {@link #PASSWORD_QUALITY_ALPHABETIC}, or
2341 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} with {@link #setPasswordQuality}.
2342 * <p>
2343 * The calling device admin must have requested
2344 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2345 * not, a security exception will be thrown.
2346 * <p>
2347 * This method can be called on the {@link DevicePolicyManager} instance returned by
2348 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2349 * profile.
2350 *
2351 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2352 * @param length The new desired length of password history. A value of 0 means there is no
2353 * restriction.
2354 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2355 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
2356 */
Robin Lee25e26452015-06-02 09:56:29 -07002357 public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002358 if (mService != null) {
2359 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002360 mService.setPasswordHistoryLength(admin, length, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002361 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002362 throw e.rethrowFromSystemServer();
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002363 }
2364 }
2365 }
2366
2367 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002368 * Called by a device admin to set the password expiration timeout. Calling this method will
2369 * restart the countdown for password expiration for the given admin, as will changing the
2370 * device password (for all admins).
2371 * <p>
2372 * The provided timeout is the time delta in ms and will be added to the current time. For
2373 * example, to have the password expire 5 days from now, timeout would be 5 * 86400 * 1000 =
2374 * 432000000 ms for timeout.
2375 * <p>
2376 * To disable password expiration, a value of 0 may be used for timeout.
2377 * <p>
2378 * The calling device admin must have requested
2379 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this method; if it has
2380 * not, a security exception will be thrown.
2381 * <p>
2382 * Note that setting the password will automatically reset the expiration time for all active
2383 * admins. Active admins do not need to explicitly call this method in that case.
2384 * <p>
2385 * This method can be called on the {@link DevicePolicyManager} instance returned by
2386 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2387 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002388 *
Jim Millera4e28d12010-11-08 16:15:47 -08002389 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002390 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0 means
2391 * there is no restriction (unlimited).
2392 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2393 * does not use {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD}
Jim Millera4e28d12010-11-08 16:15:47 -08002394 */
Robin Lee25e26452015-06-02 09:56:29 -07002395 public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) {
Jim Millera4e28d12010-11-08 16:15:47 -08002396 if (mService != null) {
2397 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002398 mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08002399 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002400 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08002401 }
2402 }
2403 }
2404
2405 /**
Jim Miller6b857682011-02-16 16:27:41 -08002406 * Get the password expiration timeout for the given admin. The expiration timeout is the
2407 * recurring expiration timeout provided in the call to
2408 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
Esteban Talaverac1c83592016-02-17 17:56:15 +00002409 * aggregate of all participating policy administrators if {@code admin} is null. Admins that
2410 * have set restrictions on profiles that have a separate challenge are not taken into account.
2411 *
2412 * <p>This method can be called on the {@link DevicePolicyManager} instance
2413 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2414 * restrictions on the parent profile.
Jim Millera4e28d12010-11-08 16:15:47 -08002415 *
Robin Lee25e26452015-06-02 09:56:29 -07002416 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08002417 * @return The timeout for the given admin or the minimum of all timeouts
2418 */
Robin Lee25e26452015-06-02 09:56:29 -07002419 public long getPasswordExpirationTimeout(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08002420 if (mService != null) {
2421 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002422 return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08002423 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002424 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08002425 }
2426 }
2427 return 0;
2428 }
2429
2430 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002431 * Get the current password expiration time for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01002432 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00002433 * a separate challenge are not taken into account. If admin is {@code null}, then a composite
2434 * of all expiration times is returned - which will be the minimum of all of them.
2435 *
2436 * <p>This method can be called on the {@link DevicePolicyManager} instance
2437 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2438 * the password expiration for the parent profile.
Jim Millera4e28d12010-11-08 16:15:47 -08002439 *
Robin Lee25e26452015-06-02 09:56:29 -07002440 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002441 * @return The password expiration time, in milliseconds since epoch.
Jim Millera4e28d12010-11-08 16:15:47 -08002442 */
Robin Lee25e26452015-06-02 09:56:29 -07002443 public long getPasswordExpiration(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08002444 if (mService != null) {
2445 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002446 return mService.getPasswordExpiration(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08002447 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002448 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08002449 }
2450 }
2451 return 0;
2452 }
2453
2454 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002455 * Retrieve the current password history length for a particular admin or all admins that
Rubin Xud3609d42016-07-13 18:32:57 +01002456 * set restrictions on this user and its participating profiles. Restrictions on profiles that
Esteban Talaverac1c83592016-02-17 17:56:15 +00002457 * have a separate challenge are not taken into account.
2458 *
2459 * <p>This method can be called on the {@link DevicePolicyManager} instance
2460 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2461 * restrictions on the parent profile.
2462 *
Robin Lee25e26452015-06-02 09:56:29 -07002463 * @param admin The name of the admin component to check, or {@code null} to aggregate
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002464 * all admins.
2465 * @return The length of the password history
2466 */
Robin Lee25e26452015-06-02 09:56:29 -07002467 public int getPasswordHistoryLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002468 return getPasswordHistoryLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002469 }
2470
2471 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002472 public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002473 if (mService != null) {
2474 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002475 return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002476 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002477 throw e.rethrowFromSystemServer();
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002478 }
2479 }
2480 return 0;
2481 }
2482
Dianne Hackbornd6847842010-01-12 18:14:19 -08002483 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08002484 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08002485 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08002486 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08002487 * @return Returns the maximum length that the user can enter.
2488 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08002489 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08002490 // Kind-of arbitrary.
2491 return 16;
2492 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002493
Dianne Hackborn254cb442010-01-27 19:23:59 -08002494 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002495 * Determine whether the current password the user has set is sufficient to meet the policy
2496 * requirements (e.g. quality, minimum length) that have been requested by the admins of this
2497 * user and its participating profiles. Restrictions on profiles that have a separate challenge
Andrew Scull5daf2732016-11-14 15:02:45 +00002498 * are not taken into account. The user must be unlocked in order to perform the check.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002499 * <p>
2500 * The calling device admin must have requested
2501 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2502 * not, a security exception will be thrown.
2503 * <p>
2504 * This method can be called on the {@link DevicePolicyManager} instance returned by
2505 * {@link #getParentProfileInstance(ComponentName)} in order to determine if the password set on
2506 * the parent profile is sufficient.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002507 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01002508 * @return Returns true if the password meets the current requirements, else false.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002509 * @throws SecurityException if the calling application does not own an active administrator
2510 * that uses {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Andrew Scull5daf2732016-11-14 15:02:45 +00002511 * @throws InvalidStateException if the user is not unlocked.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002512 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002513 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002514 if (mService != null) {
2515 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00002516 return mService.isActivePasswordSufficient(myUserId(), mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002517 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002518 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002519 }
2520 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002521 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08002522 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002523
Dianne Hackbornd6847842010-01-12 18:14:19 -08002524 /**
Clara Bayarrid7693912016-01-22 17:26:31 +00002525 * Determine whether the current profile password the user has set is sufficient
Esteban Talaverac1c83592016-02-17 17:56:15 +00002526 * to meet the policy requirements (e.g. quality, minimum length) that have been
Clara Bayarrid7693912016-01-22 17:26:31 +00002527 * requested by the admins of the parent user and its profiles.
2528 *
2529 * @param userHandle the userId of the profile to check the password for.
2530 * @return Returns true if the password would meet the current requirements, else false.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002531 * @throws SecurityException if {@code userHandle} is not a managed profile.
Clara Bayarrid7693912016-01-22 17:26:31 +00002532 * @hide
2533 */
2534 public boolean isProfileActivePasswordSufficientForParent(int userHandle) {
2535 if (mService != null) {
2536 try {
2537 return mService.isProfileActivePasswordSufficientForParent(userHandle);
2538 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002539 throw e.rethrowFromSystemServer();
Clara Bayarrid7693912016-01-22 17:26:31 +00002540 }
2541 }
2542 return false;
2543 }
2544
2545 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002546 * Retrieve the number of times the user has failed at entering a password since that last
2547 * successful password entry.
2548 * <p>
2549 * This method can be called on the {@link DevicePolicyManager} instance returned by
2550 * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the number of failed
2551 * password attemts for the parent user.
2552 * <p>
2553 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN}
2554 * to be able to call this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002555 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002556 * @return The number of times user has entered an incorrect password since the last correct
2557 * password entry.
2558 * @throws SecurityException if the calling application does not own an active administrator
2559 * that uses {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002560 */
2561 public int getCurrentFailedPasswordAttempts() {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00002562 return getCurrentFailedPasswordAttempts(myUserId());
2563 }
2564
2565 /**
2566 * Retrieve the number of times the given user has failed at entering a
2567 * password since that last successful password entry.
2568 *
2569 * <p>The calling device admin must have requested
2570 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call this method; if it has
2571 * not and it is not the system uid, a security exception will be thrown.
2572 *
2573 * @hide
2574 */
2575 public int getCurrentFailedPasswordAttempts(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002576 if (mService != null) {
2577 try {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00002578 return mService.getCurrentFailedPasswordAttempts(userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002579 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002580 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002581 }
2582 }
2583 return -1;
2584 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002585
2586 /**
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002587 * Queries whether {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002588 *
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002589 * @return true if RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002590 * @hide
2591 */
2592 public boolean getDoNotAskCredentialsOnBoot() {
2593 if (mService != null) {
2594 try {
2595 return mService.getDoNotAskCredentialsOnBoot();
2596 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002597 throw e.rethrowFromSystemServer();
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002598 }
2599 }
2600 return false;
2601 }
2602
2603 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002604 * Setting this to a value greater than zero enables a built-in policy that will perform a
2605 * device or profile wipe after too many incorrect device-unlock passwords have been entered.
2606 * This built-in policy combines watching for failed passwords and wiping the device, and
2607 * requires that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002608 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002609 * <p>
2610 * To implement any other policy (e.g. wiping data for a particular application only, erasing or
2611 * revoking credentials, or reporting the failure to a server), you should implement
2612 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} instead. Do not
2613 * use this API, because if the maximum count is reached, the device or profile will be wiped
2614 * immediately, and your callback will not be invoked.
2615 * <p>
2616 * This method can be called on the {@link DevicePolicyManager} instance returned by
2617 * {@link #getParentProfileInstance(ComponentName)} in order to set a value on the parent
2618 * profile.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002619 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002620 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002621 * @param num The number of failed password attempts at which point the device or profile will
2622 * be wiped.
2623 * @throws SecurityException if {@code admin} is not an active administrator or does not use
2624 * both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
2625 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002626 */
Robin Lee25e26452015-06-02 09:56:29 -07002627 public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002628 if (mService != null) {
2629 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002630 mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002631 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002632 throw e.rethrowFromSystemServer();
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002633 }
2634 }
2635 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002636
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002637 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002638 * Retrieve the current maximum number of login attempts that are allowed before the device
Rubin Xud3609d42016-07-13 18:32:57 +01002639 * or profile is wiped, for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002640 * and its participating profiles. Restrictions on profiles that have a separate challenge are
2641 * not taken into account.
2642 *
2643 * <p>This method can be called on the {@link DevicePolicyManager} instance
2644 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2645 * the value for the parent profile.
2646 *
Robin Lee25e26452015-06-02 09:56:29 -07002647 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002648 * all admins.
2649 */
Robin Lee25e26452015-06-02 09:56:29 -07002650 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002651 return getMaximumFailedPasswordsForWipe(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002652 }
2653
2654 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002655 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08002656 if (mService != null) {
2657 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002658 return mService.getMaximumFailedPasswordsForWipe(
2659 admin, userHandle, mParentInstance);
Dianne Hackborn254cb442010-01-27 19:23:59 -08002660 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002661 throw e.rethrowFromSystemServer();
Dianne Hackborn254cb442010-01-27 19:23:59 -08002662 }
2663 }
2664 return 0;
2665 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002666
Dianne Hackborn254cb442010-01-27 19:23:59 -08002667 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002668 * Returns the profile with the smallest maximum failed passwords for wipe,
2669 * for the given user. So for primary user, it might return the primary or
2670 * a managed profile. For a secondary user, it would be the same as the
2671 * user passed in.
2672 * @hide Used only by Keyguard
2673 */
2674 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
2675 if (mService != null) {
2676 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002677 return mService.getProfileWithMinimumFailedPasswordsForWipe(
2678 userHandle, mParentInstance);
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002679 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002680 throw e.rethrowFromSystemServer();
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002681 }
2682 }
2683 return UserHandle.USER_NULL;
2684 }
2685
2686 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002687 * Flag for {@link #resetPassword}: don't allow other admins to change
2688 * the password again until the user has entered it.
2689 */
2690 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002691
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002692 /**
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002693 * Flag for {@link #resetPassword}: don't ask for user credentials on device boot.
2694 * If the flag is set, the device can be booted without asking for user password.
2695 * The absence of this flag does not change the current boot requirements. This flag
2696 * can be set by the device owner only. If the app is not the device owner, the flag
2697 * is ignored. Once the flag is set, it cannot be reverted back without resetting the
2698 * device to factory defaults.
2699 */
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002700 public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002;
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002701
2702 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002703 * Force a new device unlock password (the password needed to access the entire device, not for
2704 * individual accounts) on the user. This takes effect immediately.
2705 * <p>
Rubin Xuaab7a412016-12-30 21:13:29 +00002706 * <em>For device owner and profile owners targeting SDK level
2707 * {@link android.os.Build.VERSION_CODES#O} or above, this API is no longer available and will
2708 * throw {@link SecurityException}. Please use the new API {@link #resetPasswordWithToken}
2709 * instead. </em>
2710 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002711 * <em>Note: This API has been limited as of {@link android.os.Build.VERSION_CODES#N} for
Makoto Onuki70f929e2015-11-11 12:40:15 -08002712 * device admins that are not device owner and not profile owner.
2713 * The password can now only be changed if there is currently no password set. Device owner
Ricky Wai977ade22016-05-24 15:02:41 +01002714 * and profile owner can still do this when user is unlocked and does not have a managed
2715 * profile.</em>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002716 * <p>
2717 * The given password must be sufficient for the current password quality and length constraints
2718 * as returned by {@link #getPasswordQuality(ComponentName)} and
2719 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then
2720 * it will be rejected and false returned. Note that the password may be a stronger quality
2721 * (containing alphanumeric characters when the requested quality is only numeric), in which
2722 * case the currently active quality will be increased to match.
2723 * <p>
2724 * Calling with a null or empty password will clear any existing PIN, pattern or password if the
Robin Leece5c4002016-03-23 17:05:03 +00002725 * current password constraints allow it. <em>Note: This will not work in
2726 * {@link android.os.Build.VERSION_CODES#N} and later for managed profiles, or for device admins
2727 * that are not device owner or profile owner. Once set, the password cannot be changed to null
2728 * or empty except by these admins.</em>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002729 * <p>
2730 * The calling device admin must have requested
2731 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call this method; if it has
2732 * not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002733 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01002734 * @param password The new password for the user. Null or empty clears the password.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002735 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002736 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
2737 * @return Returns true if the password was applied, or false if it is not acceptable for the
2738 * current constraints or if the user has not been decrypted yet.
2739 * @throws SecurityException if the calling application does not own an active administrator
2740 * that uses {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD}
Ricky Wai977ade22016-05-24 15:02:41 +01002741 * @throws IllegalStateException if the calling user is locked or has a managed profile.
Andrew Scull3f81f4e2016-07-29 16:29:58 +01002742 * @throws IllegalArgumentException if the password does not meet system requirements.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002743 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002744 public boolean resetPassword(String password, int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002745 throwIfParentInstance("resetPassword");
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002746 if (mService != null) {
2747 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002748 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002749 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002750 throw e.rethrowFromSystemServer();
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002751 }
2752 }
2753 return false;
2754 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002755
Dianne Hackbornd6847842010-01-12 18:14:19 -08002756 /**
Rubin Xuaab7a412016-12-30 21:13:29 +00002757 * Called by a profile or device owner to provision a token which can later be used to reset the
2758 * device lockscreen password (if called by device owner), or work challenge (if called by
2759 * profile owner), via {@link #resetPasswordWithToken}.
2760 * <p>
2761 * If the user currently has a lockscreen password, the provisioned token will not be
2762 * immediately usable; it only becomes active after the user performs a confirm credential
2763 * operation, which can be triggered by {@link KeyguardManager#createConfirmDeviceCredentialIntent}.
2764 * If the user has no lockscreen password, the token is activated immediately. In all cases,
2765 * the active state of the current token can be checked by {@link #isResetPasswordTokenActive}.
2766 * For security reasons, un-activated tokens are only stored in memory and will be lost once
2767 * the device reboots. In this case a new token needs to be provisioned again.
2768 * <p>
2769 * Once provisioned and activated, the token will remain effective even if the user changes
2770 * or clears the lockscreen password.
2771 * <p>
2772 * <em>This token is highly sensitive and should be treated at the same level as user
Rubin Xuf7b036d2017-04-05 18:37:07 +01002773 * credentials. In particular, NEVER store this token on device in plaintext. Do not store
2774 * the plaintext token in device-encrypted storage if it will be needed to reset password on
2775 * file-based encryption devices before user unlocks. Consider carefully how any password token
2776 * will be stored on your server and who will need access to them. Tokens may be the subject of
2777 * legal access requests.
Rubin Xuaab7a412016-12-30 21:13:29 +00002778 * </em>
2779 *
2780 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2781 * @param token a secure token a least 32-byte long, which must be generated by a
2782 * cryptographically strong random number generator.
2783 * @return true if the operation is successful, false otherwise.
2784 * @throws IllegalArgumentException if the supplied token is invalid.
2785 * @throws SecurityException
2786 */
2787 public boolean setResetPasswordToken(ComponentName admin, byte[] token) {
2788 throwIfParentInstance("setResetPasswordToken");
2789 if (mService != null) {
2790 try {
2791 return mService.setResetPasswordToken(admin, token);
2792 } catch (RemoteException e) {
2793 throw e.rethrowFromSystemServer();
2794 }
2795 }
2796 return false;
2797 }
2798
2799 /**
2800 * Called by a profile or device owner to revoke the current password reset token.
2801 *
2802 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2803 * @return true if the operation is successful, false otherwise.
2804 */
2805 public boolean clearResetPasswordToken(ComponentName admin) {
2806 throwIfParentInstance("clearResetPasswordToken");
2807 if (mService != null) {
2808 try {
2809 return mService.clearResetPasswordToken(admin);
2810 } catch (RemoteException e) {
2811 throw e.rethrowFromSystemServer();
2812 }
2813 }
2814 return false;
2815 }
2816
2817 /**
2818 * Called by a profile or device owner to check if the current reset password token is active.
2819 *
2820 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2821 * @return true if the token is active, false otherwise.
2822 * @throws IllegalStateException if no token has been set.
2823 */
2824 public boolean isResetPasswordTokenActive(ComponentName admin) {
2825 throwIfParentInstance("isResetPasswordTokenActive");
2826 if (mService != null) {
2827 try {
2828 return mService.isResetPasswordTokenActive(admin);
2829 } catch (RemoteException e) {
2830 throw e.rethrowFromSystemServer();
2831 }
2832 }
2833 return false;
2834 }
2835
2836 /**
2837 * Called by device or profile owner to force set a new device unlock password or a work profile
2838 * challenge on current user. This takes effect immediately.
2839 * <p>
2840 * Unlike {@link #resetPassword}, this API can change the password even before the user or
2841 * device is unlocked or decrypted. The supplied token must have been previously provisioned via
2842 * {@link #setResetPasswordToken}, and in active state {@link #isResetPasswordTokenActive}.
2843 * <p>
2844 * The given password must be sufficient for the current password quality and length constraints
2845 * as returned by {@link #getPasswordQuality(ComponentName)} and
2846 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then
2847 * it will be rejected and false returned. Note that the password may be a stronger quality
2848 * (containing alphanumeric characters when the requested quality is only numeric), in which
2849 * case the currently active quality will be increased to match.
2850 * <p>
2851 * Calling with a null or empty password will clear any existing PIN, pattern or password if the
2852 * current password constraints allow it.
2853 *
2854 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2855 * @param password The new password for the user. Null or empty clears the password.
2856 * @param token the password reset token previously provisioned by #setResetPasswordToken.
2857 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
2858 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
2859 * @return Returns true if the password was applied, or false if it is not acceptable for the
2860 * current constraints.
2861 * @throws SecurityException if the calling application does not own an active administrator
2862 * that uses {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD}
2863 * @throws IllegalStateException if the provided token is not valid.
2864 * @throws IllegalArgumentException if the password does not meet system requirements.
2865 */
2866 public boolean resetPasswordWithToken(@NonNull ComponentName admin, String password,
2867 byte[] token, int flags) {
2868 throwIfParentInstance("resetPassword");
2869 if (mService != null) {
2870 try {
2871 return mService.resetPasswordWithToken(admin, password, token, flags);
2872 } catch (RemoteException e) {
2873 throw e.rethrowFromSystemServer();
2874 }
2875 }
2876 return false;
2877 }
2878
2879 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002880 * Called by an application that is administering the device to set the maximum time for user
2881 * activity until the device will lock. This limits the length that the user can set. It takes
2882 * effect immediately.
2883 * <p>
2884 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
2885 * to be able to call this method; if it has not, a security exception will be thrown.
2886 * <p>
2887 * This method can be called on the {@link DevicePolicyManager} instance returned by
2888 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2889 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002890 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002891 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002892 * @param timeMs The new desired maximum time to lock in milliseconds. A value of 0 means there
2893 * is no restriction.
2894 * @throws SecurityException if {@code admin} is not an active administrator or it does not use
2895 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002896 */
Robin Lee25e26452015-06-02 09:56:29 -07002897 public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002898 if (mService != null) {
2899 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002900 mService.setMaximumTimeToLock(admin, timeMs, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002901 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002902 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002903 }
2904 }
2905 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002906
Dianne Hackbornd6847842010-01-12 18:14:19 -08002907 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002908 * Retrieve the current maximum time to unlock for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01002909 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00002910 * a separate challenge are not taken into account.
2911 *
2912 * <p>This method can be called on the {@link DevicePolicyManager} instance
2913 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2914 * restrictions on the parent profile.
2915 *
Robin Lee25e26452015-06-02 09:56:29 -07002916 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002917 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07002918 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07002919 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002920 */
Robin Lee25e26452015-06-02 09:56:29 -07002921 public long getMaximumTimeToLock(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002922 return getMaximumTimeToLock(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002923 }
2924
2925 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002926 public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002927 if (mService != null) {
2928 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002929 return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002930 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002931 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002932 }
2933 }
2934 return 0;
2935 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002936
Dianne Hackbornd6847842010-01-12 18:14:19 -08002937 /**
Ricky Wai035e9242016-03-18 16:43:31 +00002938 * Returns maximum time to lock that applied by all profiles in this user. We do this because we
2939 * do not have a separate timeout to lock for work challenge only.
2940 *
2941 * @hide
2942 */
2943 public long getMaximumTimeToLockForUserAndProfiles(int userHandle) {
2944 if (mService != null) {
2945 try {
2946 return mService.getMaximumTimeToLockForUserAndProfiles(userHandle);
2947 } catch (RemoteException e) {
2948 throw e.rethrowFromSystemServer();
2949 }
2950 }
2951 return 0;
2952 }
2953
2954 /**
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002955 * Called by a device/profile owner to set the timeout after which unlocking with secondary, non
2956 * strong auth (e.g. fingerprint, trust agents) times out, i.e. the user has to use a strong
2957 * authentication method like password, pin or pattern.
2958 *
2959 * <p>This timeout is used internally to reset the timer to require strong auth again after
2960 * specified timeout each time it has been successfully used.
2961 *
2962 * <p>Fingerprint can also be disabled altogether using {@link #KEYGUARD_DISABLE_FINGERPRINT}.
2963 *
2964 * <p>Trust agents can also be disabled altogether using {@link #KEYGUARD_DISABLE_TRUST_AGENTS}.
2965 *
2966 * <p>The calling device admin must be a device or profile owner. If it is not,
2967 * a {@link SecurityException} will be thrown.
2968 *
Michal Karpinski943aabd2016-10-06 11:09:25 +01002969 * <p>The calling device admin can verify the value it has set by calling
2970 * {@link #getRequiredStrongAuthTimeout(ComponentName)} and passing in its instance.
2971 *
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002972 * <p>This method can be called on the {@link DevicePolicyManager} instance returned by
2973 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2974 * profile.
2975 *
2976 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2977 * @param timeoutMs The new timeout, after which the user will have to unlock with strong
Michal Karpinski943aabd2016-10-06 11:09:25 +01002978 * authentication method. A value of 0 means the admin is not participating in
2979 * controlling the timeout.
2980 * The minimum and maximum timeouts are platform-defined and are typically 1 hour and
2981 * 72 hours, respectively. Though discouraged, the admin may choose to require strong
2982 * auth at all times using {@link #KEYGUARD_DISABLE_FINGERPRINT} and/or
2983 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002984 *
2985 * @throws SecurityException if {@code admin} is not a device or profile owner.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002986 */
2987 public void setRequiredStrongAuthTimeout(@NonNull ComponentName admin,
2988 long timeoutMs) {
2989 if (mService != null) {
2990 try {
2991 mService.setRequiredStrongAuthTimeout(admin, timeoutMs, mParentInstance);
2992 } catch (RemoteException e) {
2993 throw e.rethrowFromSystemServer();
2994 }
2995 }
2996 }
2997
2998 /**
2999 * Determine for how long the user will be able to use secondary, non strong auth for
3000 * authentication, since last strong method authentication (password, pin or pattern) was used.
3001 * After the returned timeout the user is required to use strong authentication method.
3002 *
3003 * <p>This method can be called on the {@link DevicePolicyManager} instance
3004 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
3005 * restrictions on the parent profile.
3006 *
3007 * @param admin The name of the admin component to check, or {@code null} to aggregate
3008 * accross all participating admins.
Michal Karpinski943aabd2016-10-06 11:09:25 +01003009 * @return The timeout or 0 if not configured for the provided admin.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01003010 */
3011 public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin) {
3012 return getRequiredStrongAuthTimeout(admin, myUserId());
3013 }
3014
3015 /** @hide per-user version */
3016 public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin, @UserIdInt int userId) {
3017 if (mService != null) {
3018 try {
3019 return mService.getRequiredStrongAuthTimeout(admin, userId, mParentInstance);
3020 } catch (RemoteException e) {
3021 throw e.rethrowFromSystemServer();
3022 }
3023 }
3024 return DEFAULT_STRONG_AUTH_TIMEOUT_MS;
3025 }
3026
3027 /**
Andrew Scull85a63bc2016-10-24 13:47:47 +01003028 * Flag for {@link #lockNow(int)}: also evict the user's credential encryption key from the
3029 * keyring. The user's credential will need to be entered again in order to derive the
3030 * credential encryption key that will be stored back in the keyring for future use.
3031 * <p>
3032 * This flag can only be used by a profile owner when locking a managed profile on an FBE
3033 * device.
3034 * <p>
3035 * In order to secure user data, the user will be stopped and restarted so apps should wait
3036 * until they are next run to perform further actions.
3037 */
3038 public static final int FLAG_EVICT_CE_KEY = 1;
3039
3040 /** @hide */
3041 @Retention(RetentionPolicy.SOURCE)
3042 @IntDef(flag=true, value={FLAG_EVICT_CE_KEY})
3043 public @interface LockNowFlag {}
3044
3045 /**
3046 * Make the device lock immediately, as if the lock screen timeout has expired at the point of
3047 * this call.
3048 * <p>
3049 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
3050 * to be able to call this method; if it has not, a security exception will be thrown.
3051 * <p>
3052 * This method can be called on the {@link DevicePolicyManager} instance returned by
3053 * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile.
3054 * <p>
3055 * Equivalent to calling {@link #lockNow(int)} with no flags.
3056 *
3057 * @throws SecurityException if the calling application does not own an active administrator
3058 * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
3059 */
3060 public void lockNow() {
3061 lockNow(0);
3062 }
3063
3064 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003065 * Make the device lock immediately, as if the lock screen timeout has expired at the point of
3066 * this call.
3067 * <p>
3068 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
3069 * to be able to call this method; if it has not, a security exception will be thrown.
3070 * <p>
3071 * This method can be called on the {@link DevicePolicyManager} instance returned by
3072 * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003073 *
Andrew Scull85a63bc2016-10-24 13:47:47 +01003074 * @param flags May be 0 or {@link #FLAG_EVICT_CE_KEY}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003075 * @throws SecurityException if the calling application does not own an active administrator
Andrew Scull85a63bc2016-10-24 13:47:47 +01003076 * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} or the
3077 * {@link #FLAG_EVICT_CE_KEY} flag is passed by an application that is not a profile
3078 * owner of a managed profile.
3079 * @throws IllegalArgumentException if the {@link #FLAG_EVICT_CE_KEY} flag is passed when
3080 * locking the parent profile.
3081 * @throws UnsupportedOperationException if the {@link #FLAG_EVICT_CE_KEY} flag is passed on a
3082 * non-FBE device.
Dianne Hackbornd6847842010-01-12 18:14:19 -08003083 */
Andrew Scull85a63bc2016-10-24 13:47:47 +01003084 public void lockNow(@LockNowFlag int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -08003085 if (mService != null) {
3086 try {
Andrew Scull85a63bc2016-10-24 13:47:47 +01003087 mService.lockNow(flags, mParentInstance);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08003088 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003089 throw e.rethrowFromSystemServer();
Dianne Hackborndf83afa2010-01-20 13:37:26 -08003090 }
3091 }
3092 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003093
Dianne Hackbornd6847842010-01-12 18:14:19 -08003094 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07003095 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00003096 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07003097 */
3098 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
3099
3100 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00003101 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
3102 * data.
3103 *
Paul Crowley2934b262014-12-02 11:21:13 +00003104 * <p>This flag may only be set by device owner admins; if it is set by
3105 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00003106 */
3107 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
3108
3109 /**
Suprabh Shukla556b05a2016-08-10 15:49:24 -07003110 * Ask that all user data be wiped. If called as a secondary user, the user will be removed and
3111 * other users will remain unaffected. Calling from the primary user will cause the device to
3112 * reboot, erasing all device data - including all the secondary users and their data - while
3113 * booting up.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003114 * <p>
3115 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to
3116 * be able to call this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003117 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003118 * @param flags Bit mask of additional options: currently supported flags are
3119 * {@link #WIPE_EXTERNAL_STORAGE} and {@link #WIPE_RESET_PROTECTION_DATA}.
3120 * @throws SecurityException if the calling application does not own an active administrator
3121 * that uses {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}
Dianne Hackbornd6847842010-01-12 18:14:19 -08003122 */
3123 public void wipeData(int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003124 throwIfParentInstance("wipeData");
Dianne Hackbornd6847842010-01-12 18:14:19 -08003125 if (mService != null) {
3126 try {
Makoto Onuki70f929e2015-11-11 12:40:15 -08003127 mService.wipeData(flags);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003128 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003129 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003130 }
3131 }
3132 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003133
Dianne Hackbornd6847842010-01-12 18:14:19 -08003134 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07003135 * Called by an application that is administering the device to set the
3136 * global proxy and exclusion list.
3137 * <p>
3138 * The calling device admin must have requested
3139 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
3140 * this method; if it has not, a security exception will be thrown.
3141 * Only the first device admin can set the proxy. If a second admin attempts
3142 * to set the proxy, the {@link ComponentName} of the admin originally setting the
Robin Lee25e26452015-06-02 09:56:29 -07003143 * proxy will be returned. If successful in setting the proxy, {@code null} will
Oscar Montemayor69238c62010-08-03 10:51:06 -07003144 * be returned.
3145 * The method can be called repeatedly by the device admin alrady setting the
3146 * proxy to update the proxy and exclusion list.
3147 *
Robin Lee25e26452015-06-02 09:56:29 -07003148 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Oscar Montemayor69238c62010-08-03 10:51:06 -07003149 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
3150 * Pass Proxy.NO_PROXY to reset the proxy.
3151 * @param exclusionList a list of domains to be excluded from the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07003152 * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName}
3153 * of the device admin that sets the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08003154 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07003155 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003156 public @Nullable ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec,
Oscar Montemayor69238c62010-08-03 10:51:06 -07003157 List<String> exclusionList ) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003158 throwIfParentInstance("setGlobalProxy");
Oscar Montemayor69238c62010-08-03 10:51:06 -07003159 if (proxySpec == null) {
3160 throw new NullPointerException();
3161 }
3162 if (mService != null) {
3163 try {
3164 String hostSpec;
3165 String exclSpec;
3166 if (proxySpec.equals(Proxy.NO_PROXY)) {
3167 hostSpec = null;
3168 exclSpec = null;
3169 } else {
3170 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
3171 throw new IllegalArgumentException();
3172 }
3173 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
3174 String hostName = sa.getHostName();
3175 int port = sa.getPort();
3176 StringBuilder hostBuilder = new StringBuilder();
3177 hostSpec = hostBuilder.append(hostName)
3178 .append(":").append(Integer.toString(port)).toString();
3179 if (exclusionList == null) {
3180 exclSpec = "";
3181 } else {
3182 StringBuilder listBuilder = new StringBuilder();
3183 boolean firstDomain = true;
3184 for (String exclDomain : exclusionList) {
3185 if (!firstDomain) {
3186 listBuilder = listBuilder.append(",");
3187 } else {
3188 firstDomain = false;
3189 }
3190 listBuilder = listBuilder.append(exclDomain.trim());
3191 }
3192 exclSpec = listBuilder.toString();
3193 }
Yuhao Zheng90704842014-02-28 17:22:45 -08003194 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
3195 != android.net.Proxy.PROXY_VALID)
3196 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07003197 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003198 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07003199 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003200 throw e.rethrowFromSystemServer();
Oscar Montemayor69238c62010-08-03 10:51:06 -07003201 }
3202 }
3203 return null;
3204 }
3205
3206 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003207 * Set a network-independent global HTTP proxy. This is not normally what you want for typical
3208 * HTTP proxies - they are generally network dependent. However if you're doing something
3209 * unusual like general internal filtering this may be useful. On a private network where the
3210 * proxy is not accessible, you may break HTTP using this.
3211 * <p>
3212 * This method requires the caller to be the device owner.
3213 * <p>
3214 * This proxy is only a recommendation and it is possible that some apps will ignore it.
Jason Monk03bc9912014-05-13 09:44:57 -04003215 *
Jason Monk03bc9912014-05-13 09:44:57 -04003216 * @see ProxyInfo
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003217 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3218 * @param proxyInfo The a {@link ProxyInfo} object defining the new global HTTP proxy. A
3219 * {@code null} value will clear the global HTTP proxy.
3220 * @throws SecurityException if {@code admin} is not the device owner.
Jason Monk03bc9912014-05-13 09:44:57 -04003221 */
Robin Lee25e26452015-06-02 09:56:29 -07003222 public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo
3223 proxyInfo) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003224 throwIfParentInstance("setRecommendedGlobalProxy");
Jason Monk03bc9912014-05-13 09:44:57 -04003225 if (mService != null) {
3226 try {
3227 mService.setRecommendedGlobalProxy(admin, proxyInfo);
3228 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003229 throw e.rethrowFromSystemServer();
Jason Monk03bc9912014-05-13 09:44:57 -04003230 }
3231 }
3232 }
3233
3234 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07003235 * Returns the component name setting the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07003236 * @return ComponentName object of the device admin that set the global proxy, or {@code null}
3237 * if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08003238 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07003239 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003240 public @Nullable ComponentName getGlobalProxyAdmin() {
Oscar Montemayor69238c62010-08-03 10:51:06 -07003241 if (mService != null) {
3242 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003243 return mService.getGlobalProxyAdmin(myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07003244 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003245 throw e.rethrowFromSystemServer();
Oscar Montemayor69238c62010-08-03 10:51:06 -07003246 }
3247 }
3248 return null;
3249 }
3250
3251 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08003252 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003253 * indicating that encryption is not supported.
3254 */
3255 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
3256
3257 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08003258 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003259 * indicating that encryption is supported, but is not currently active.
3260 */
3261 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
3262
3263 /**
Robin Lee3795fb02015-02-16 14:17:23 +00003264 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003265 * indicating that encryption is not currently active, but is currently
3266 * being activated. This is only reported by devices that support
3267 * encryption of data and only when the storage is currently
3268 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
3269 * to become encrypted will never return this value.
3270 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08003271 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003272
3273 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08003274 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003275 * indicating that encryption is active.
Amith Yamasani75db1252016-07-11 14:41:01 -07003276 * <p>
3277 * Also see {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003278 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08003279 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003280
3281 /**
Robin Lee3795fb02015-02-16 14:17:23 +00003282 * Result code for {@link #getStorageEncryptionStatus}:
3283 * indicating that encryption is active, but an encryption key has not
3284 * been set by the user.
3285 */
3286 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
3287
3288 /**
Makoto Onukid4c9e542016-02-25 18:17:30 -08003289 * Result code for {@link #getStorageEncryptionStatus}:
Amith Yamasani75db1252016-07-11 14:41:01 -07003290 * indicating that encryption is active and the encryption key is tied to the user or profile.
3291 * <p>
3292 * This value is only returned to apps targeting API level 24 and above. For apps targeting
3293 * earlier API levels, {@link #ENCRYPTION_STATUS_ACTIVE} is returned, even if the
3294 * encryption key is specific to the user or profile.
Makoto Onukid4c9e542016-02-25 18:17:30 -08003295 */
3296 public static final int ENCRYPTION_STATUS_ACTIVE_PER_USER = 5;
3297
3298 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003299 * Activity action: begin the process of encrypting data on the device. This activity should
3300 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
3301 * After resuming from this activity, use {@link #getStorageEncryption}
3302 * to check encryption status. However, on some devices this activity may never return, as
3303 * it may trigger a reboot and in some cases a complete data wipe of the device.
3304 */
3305 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
3306 public static final String ACTION_START_ENCRYPTION
3307 = "android.app.action.START_ENCRYPTION";
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003308 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07003309 * Widgets are enabled in keyguard
3310 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07003311 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07003312
3313 /**
Jim Miller50e62182014-04-23 17:25:00 -07003314 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07003315 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07003316 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
3317
3318 /**
3319 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
3320 */
3321 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
3322
3323 /**
Jim Miller50e62182014-04-23 17:25:00 -07003324 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
3325 */
3326 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
3327
3328 /**
3329 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
3330 */
3331 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
3332
3333 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02003334 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07003335 * (e.g. PIN/Pattern/Password).
3336 */
3337 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
3338
3339 /**
Jim Miller06e34502014-07-17 14:46:05 -07003340 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
3341 */
3342 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
3343
3344 /**
Adrian Roos7f06eed2016-02-05 15:21:02 -08003345 * Disable text entry into notifications on secure keyguard screens (e.g. PIN/Pattern/Password).
3346 */
3347 public static final int KEYGUARD_DISABLE_REMOTE_INPUT = 1 << 6;
3348
3349 /**
Jim Miller35207742012-11-02 15:33:20 -07003350 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07003351 */
3352 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07003353
3354 /**
Robin Leeacdeac62017-02-21 22:13:38 +00003355 * Keyguard features that when set on a managed profile that doesn't have its own challenge will
3356 * affect the profile's parent user. These can also be set on the managed profile's parent
3357 * {@link DevicePolicyManager} instance.
3358 *
3359 * @hide
3360 */
3361 public static final int PROFILE_KEYGUARD_FEATURES_AFFECT_OWNER =
3362 DevicePolicyManager.KEYGUARD_DISABLE_TRUST_AGENTS
3363 | DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT;
3364
3365 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003366 * Called by an application that is administering the device to request that the storage system
3367 * be encrypted.
3368 * <p>
3369 * When multiple device administrators attempt to control device encryption, the most secure,
3370 * supported setting will always be used. If any device administrator requests device
3371 * encryption, it will be enabled; Conversely, if a device administrator attempts to disable
3372 * device encryption while another device administrator has enabled it, the call to disable will
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003373 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003374 * <p>
3375 * This policy controls encryption of the secure (application data) storage area. Data written
3376 * to other storage areas may or may not be encrypted, and this policy does not require or
3377 * control the encryption of any other storage areas. There is one exception: If
3378 * {@link android.os.Environment#isExternalStorageEmulated()} is {@code true}, then the
3379 * directory returned by {@link android.os.Environment#getExternalStorageDirectory()} must be
3380 * written to disk within the encrypted storage area.
3381 * <p>
3382 * Important Note: On some devices, it is possible to encrypt storage without requiring the user
3383 * to create a device PIN or Password. In this case, the storage is encrypted, but the
3384 * encryption key may not be fully secured. For maximum security, the administrator should also
3385 * require (and check for) a pattern, PIN, or password.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003386 *
3387 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3388 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08003389 * @return the new request status (for all active admins) - will be one of
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003390 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
3391 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
3392 * {@link #getStorageEncryptionStatus()} to query the actual device state.
3393 * @throws SecurityException if {@code admin} is not an active administrator or does not use
3394 * {@link DeviceAdminInfo#USES_ENCRYPTED_STORAGE}
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003395 */
Robin Lee25e26452015-06-02 09:56:29 -07003396 public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003397 throwIfParentInstance("setStorageEncryption");
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003398 if (mService != null) {
3399 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003400 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003401 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003402 throw e.rethrowFromSystemServer();
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003403 }
3404 }
3405 return ENCRYPTION_STATUS_UNSUPPORTED;
3406 }
3407
3408 /**
3409 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08003410 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003411 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08003412 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
3413 * this will return the requested encryption setting as an aggregate of all active
3414 * administrators.
3415 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003416 */
Robin Lee25e26452015-06-02 09:56:29 -07003417 public boolean getStorageEncryption(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003418 throwIfParentInstance("getStorageEncryption");
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003419 if (mService != null) {
3420 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003421 return mService.getStorageEncryption(admin, myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003422 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003423 throw e.rethrowFromSystemServer();
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003424 }
3425 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08003426 return false;
3427 }
3428
3429 /**
3430 * Called by an application that is administering the device to
3431 * determine the current encryption status of the device.
Amith Yamasani75db1252016-07-11 14:41:01 -07003432 * <p>
Andy Stadler22dbfda2011-01-17 12:47:31 -08003433 * Depending on the returned status code, the caller may proceed in different
3434 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
3435 * storage system does not support encryption. If the
3436 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
3437 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00003438 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
3439 * storage system has enabled encryption but no password is set so further action
Amith Yamasani75db1252016-07-11 14:41:01 -07003440 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING},
3441 * {@link #ENCRYPTION_STATUS_ACTIVE} or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER},
3442 * no further action is required.
Andy Stadler22dbfda2011-01-17 12:47:31 -08003443 *
Robin Lee7e678712014-07-24 16:41:31 +01003444 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08003445 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00003446 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
Amith Yamasani75db1252016-07-11 14:41:01 -07003447 * {@link #ENCRYPTION_STATUS_ACTIVE}, or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08003448 */
3449 public int getStorageEncryptionStatus() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003450 throwIfParentInstance("getStorageEncryptionStatus");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003451 return getStorageEncryptionStatus(myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003452 }
3453
3454 /** @hide per-user version */
3455 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08003456 if (mService != null) {
3457 try {
Makoto Onukid4c9e542016-02-25 18:17:30 -08003458 return mService.getStorageEncryptionStatus(mContext.getPackageName(), userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08003459 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003460 throw e.rethrowFromSystemServer();
Andy Stadler22dbfda2011-01-17 12:47:31 -08003461 }
3462 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003463 return ENCRYPTION_STATUS_UNSUPPORTED;
3464 }
3465
3466 /**
Robin Lee2f7e1e42016-03-21 10:50:01 +00003467 * Mark a CA certificate as approved by the device user. This means that they have been notified
3468 * of the installation, were made aware of the risks, viewed the certificate and still wanted to
3469 * keep the certificate on the device.
3470 *
3471 * Calling with {@param approval} as {@code true} will cancel any ongoing warnings related to
3472 * this certificate.
3473 *
3474 * @hide
3475 */
3476 public boolean approveCaCert(String alias, int userHandle, boolean approval) {
3477 if (mService != null) {
3478 try {
3479 return mService.approveCaCert(alias, userHandle, approval);
3480 } catch (RemoteException e) {
3481 throw e.rethrowFromSystemServer();
3482 }
3483 }
3484 return false;
3485 }
3486
3487 /**
3488 * Check whether a CA certificate has been approved by the device user.
3489 *
3490 * @hide
3491 */
3492 public boolean isCaCertApproved(String alias, int userHandle) {
3493 if (mService != null) {
3494 try {
3495 return mService.isCaCertApproved(alias, userHandle);
3496 } catch (RemoteException e) {
3497 throw e.rethrowFromSystemServer();
3498 }
3499 }
3500 return false;
3501 }
3502
3503 /**
Robin Lee7e678712014-07-24 16:41:31 +01003504 * Installs the given certificate as a user CA.
3505 *
Edman Anjosf9946772016-11-28 16:35:15 +01003506 * The caller must be a profile or device owner on that user, or a delegate package given the
3507 * {@link #DELEGATION_CERT_INSTALL} scope via {@link #setDelegatedScopes}; otherwise a
3508 * security exception will be thrown.
3509 *
Robin Lee25e26452015-06-02 09:56:29 -07003510 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3511 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003512 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04003513 *
3514 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01003515 * interrupted, true otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003516 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3517 * owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003518 * @see #setDelegatedScopes
3519 * @see #DELEGATION_CERT_INSTALL
Maggie Benthallda51e682013-08-08 22:35:44 -04003520 */
Robin Lee25e26452015-06-02 09:56:29 -07003521 public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003522 throwIfParentInstance("installCaCert");
Maggie Benthallda51e682013-08-08 22:35:44 -04003523 if (mService != null) {
3524 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003525 return mService.installCaCert(admin, mContext.getPackageName(), certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04003526 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003527 throw e.rethrowFromSystemServer();
Maggie Benthallda51e682013-08-08 22:35:44 -04003528 }
3529 }
3530 return false;
3531 }
3532
3533 /**
Robin Lee7e678712014-07-24 16:41:31 +01003534 * Uninstalls the given certificate from trusted user CAs, if present.
3535 *
Edman Anjosf9946772016-11-28 16:35:15 +01003536 * The caller must be a profile or device owner on that user, or a delegate package given the
3537 * {@link #DELEGATION_CERT_INSTALL} scope via {@link #setDelegatedScopes}; otherwise a
3538 * security exception will be thrown.
3539 *
Robin Lee25e26452015-06-02 09:56:29 -07003540 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3541 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003542 * @param certBuffer encoded form of the certificate to remove.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003543 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3544 * owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003545 * @see #setDelegatedScopes
3546 * @see #DELEGATION_CERT_INSTALL
Maggie Benthallda51e682013-08-08 22:35:44 -04003547 */
Robin Lee25e26452015-06-02 09:56:29 -07003548 public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003549 throwIfParentInstance("uninstallCaCert");
Maggie Benthallda51e682013-08-08 22:35:44 -04003550 if (mService != null) {
3551 try {
Robin Lee306fe082014-06-19 14:04:24 +00003552 final String alias = getCaCertAlias(certBuffer);
Edman Anjosf9946772016-11-28 16:35:15 +01003553 mService.uninstallCaCerts(admin, mContext.getPackageName(), new String[] {alias});
Robin Lee306fe082014-06-19 14:04:24 +00003554 } catch (CertificateException e) {
3555 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04003556 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003557 throw e.rethrowFromSystemServer();
Maggie Benthallda51e682013-08-08 22:35:44 -04003558 }
3559 }
3560 }
3561
3562 /**
Robin Lee7e678712014-07-24 16:41:31 +01003563 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
3564 * If a user has installed any certificates by other means than device policy these will be
3565 * included too.
3566 *
Robin Lee25e26452015-06-02 09:56:29 -07003567 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3568 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003569 * @return a List of byte[] arrays, each encoding one user CA certificate.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003570 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3571 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04003572 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003573 public @NonNull List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) {
3574 final List<byte[]> certs = new ArrayList<byte[]>();
Benjamin Franzbc33c822016-04-15 08:57:52 +01003575 throwIfParentInstance("getInstalledCaCerts");
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003576 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01003577 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003578 mService.enforceCanManageCaCerts(admin, mContext.getPackageName());
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003579 final TrustedCertificateStore certStore = new TrustedCertificateStore();
3580 for (String alias : certStore.userAliases()) {
3581 try {
3582 certs.add(certStore.getCertificate(alias).getEncoded());
3583 } catch (CertificateException ce) {
3584 Log.w(TAG, "Could not encode certificate: " + alias, ce);
3585 }
3586 }
3587 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003588 throw re.rethrowFromSystemServer();
Robin Lee7e678712014-07-24 16:41:31 +01003589 }
3590 }
3591 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04003592 }
3593
3594 /**
Robin Lee7e678712014-07-24 16:41:31 +01003595 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
3596 * means other than device policy will also be removed, except for system CA certificates.
3597 *
Robin Lee25e26452015-06-02 09:56:29 -07003598 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3599 * {@code null} if calling from a delegated certificate installer.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003600 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3601 * owner.
Robin Lee7e678712014-07-24 16:41:31 +01003602 */
Robin Lee25e26452015-06-02 09:56:29 -07003603 public void uninstallAllUserCaCerts(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003604 throwIfParentInstance("uninstallAllUserCaCerts");
Robin Lee7e678712014-07-24 16:41:31 +01003605 if (mService != null) {
Robin Lee83881bd2015-06-09 16:04:38 -07003606 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003607 mService.uninstallCaCerts(admin, mContext.getPackageName(),
3608 new TrustedCertificateStore().userAliases() .toArray(new String[0]));
Robin Lee83881bd2015-06-09 16:04:38 -07003609 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003610 throw re.rethrowFromSystemServer();
Robin Lee7e678712014-07-24 16:41:31 +01003611 }
3612 }
3613 }
3614
3615 /**
3616 * Returns whether this certificate is installed as a trusted CA.
3617 *
Robin Lee25e26452015-06-02 09:56:29 -07003618 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3619 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003620 * @param certBuffer encoded form of the certificate to look up.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003621 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3622 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04003623 */
Robin Lee25e26452015-06-02 09:56:29 -07003624 public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003625 throwIfParentInstance("hasCaCertInstalled");
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003626 if (mService != null) {
3627 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003628 mService.enforceCanManageCaCerts(admin, mContext.getPackageName());
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003629 return getCaCertAlias(certBuffer) != null;
3630 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003631 throw re.rethrowFromSystemServer();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003632 } catch (CertificateException ce) {
3633 Log.w(TAG, "Could not parse certificate", ce);
3634 }
Maggie Benthallda51e682013-08-08 22:35:44 -04003635 }
3636 return false;
3637 }
3638
3639 /**
Robin Leece3399f2016-02-24 12:08:32 +00003640 * Called by a device or profile owner, or delegated certificate installer, to install a
3641 * certificate and corresponding private key. All apps within the profile will be able to access
3642 * the certificate and use the private key, given direct user approval.
3643 *
3644 * <p>Access to the installed credentials will not be granted to the caller of this API without
3645 * direct user approval. This is for security - should a certificate installer become
3646 * compromised, certificates it had already installed will be protected.
3647 *
3648 * <p>If the installer must have access to the credentials, call
Rubin Xub4365912016-03-23 12:13:22 +00003649 * {@link #installKeyPair(ComponentName, PrivateKey, Certificate[], String, boolean)} instead.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003650 *
Robin Lee25e26452015-06-02 09:56:29 -07003651 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3652 * {@code null} if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003653 * @param privKey The private key to install.
3654 * @param cert The certificate to install.
3655 * @param alias The private key alias under which to install the certificate. If a certificate
3656 * with that alias already exists, it will be overwritten.
3657 * @return {@code true} if the keys were installed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003658 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3659 * owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003660 * @see #setDelegatedScopes
3661 * @see #DELEGATION_CERT_INSTALL
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003662 */
Robin Leefbc65642015-08-03 16:21:22 +01003663 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
3664 @NonNull Certificate cert, @NonNull String alias) {
Rubin Xub4365912016-03-23 12:13:22 +00003665 return installKeyPair(admin, privKey, new Certificate[] {cert}, alias, false);
Robin Leece3399f2016-02-24 12:08:32 +00003666 }
3667
3668 /**
3669 * Called by a device or profile owner, or delegated certificate installer, to install a
Rubin Xub4365912016-03-23 12:13:22 +00003670 * certificate chain and corresponding private key for the leaf certificate. All apps within the
3671 * profile will be able to access the certificate chain and use the private key, given direct
3672 * user approval.
Robin Leece3399f2016-02-24 12:08:32 +00003673 *
Robin Leea1b290e2016-03-09 14:38:36 +00003674 * <p>The caller of this API may grant itself access to the certificate and private key
3675 * immediately, without user approval. It is a best practice not to request this unless strictly
3676 * necessary since it opens up additional security vulnerabilities.
Robin Leece3399f2016-02-24 12:08:32 +00003677 *
3678 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Robin Leea1b290e2016-03-09 14:38:36 +00003679 * {@code null} if calling from a delegated certificate installer.
Robin Leece3399f2016-02-24 12:08:32 +00003680 * @param privKey The private key to install.
Rubin Xub4365912016-03-23 12:13:22 +00003681 * @param certs The certificate chain to install. The chain should start with the leaf
3682 * certificate and include the chain of trust in order. This will be returned by
3683 * {@link android.security.KeyChain#getCertificateChain}.
Robin Leece3399f2016-02-24 12:08:32 +00003684 * @param alias The private key alias under which to install the certificate. If a certificate
Robin Leea1b290e2016-03-09 14:38:36 +00003685 * with that alias already exists, it will be overwritten.
Robin Leece3399f2016-02-24 12:08:32 +00003686 * @param requestAccess {@code true} to request that the calling app be granted access to the
Robin Leea1b290e2016-03-09 14:38:36 +00003687 * credentials immediately. Otherwise, access to the credentials will be gated by user
3688 * approval.
Robin Leece3399f2016-02-24 12:08:32 +00003689 * @return {@code true} if the keys were installed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003690 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3691 * owner.
Rubin Xub4365912016-03-23 12:13:22 +00003692 * @see android.security.KeyChain#getCertificateChain
Edman Anjosf9946772016-11-28 16:35:15 +01003693 * @see #setDelegatedScopes
3694 * @see #DELEGATION_CERT_INSTALL
Robin Leece3399f2016-02-24 12:08:32 +00003695 */
3696 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
Rubin Xub4365912016-03-23 12:13:22 +00003697 @NonNull Certificate[] certs, @NonNull String alias, boolean requestAccess) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003698 throwIfParentInstance("installKeyPair");
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003699 try {
Rubin Xub4365912016-03-23 12:13:22 +00003700 final byte[] pemCert = Credentials.convertToPem(certs[0]);
3701 byte[] pemChain = null;
3702 if (certs.length > 1) {
3703 pemChain = Credentials.convertToPem(Arrays.copyOfRange(certs, 1, certs.length));
3704 }
Robin Lee0d5ccb72014-09-12 17:41:44 +01003705 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
3706 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
Edman Anjosf9946772016-11-28 16:35:15 +01003707 return mService.installKeyPair(admin, mContext.getPackageName(), pkcs8Key, pemCert,
3708 pemChain, alias, requestAccess);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003709 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003710 throw e.rethrowFromSystemServer();
Robin Lee0d5ccb72014-09-12 17:41:44 +01003711 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
3712 Log.w(TAG, "Failed to obtain private key material", e);
3713 } catch (CertificateException | IOException e) {
3714 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003715 }
3716 return false;
3717 }
3718
3719 /**
Robin Leea1b290e2016-03-09 14:38:36 +00003720 * Called by a device or profile owner, or delegated certificate installer, to remove a
3721 * certificate and private key pair installed under a given alias.
Robin Leefbc65642015-08-03 16:21:22 +01003722 *
3723 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Robin Leea1b290e2016-03-09 14:38:36 +00003724 * {@code null} if calling from a delegated certificate installer.
Robin Leefbc65642015-08-03 16:21:22 +01003725 * @param alias The private key alias under which the certificate is installed.
Robin Leea1b290e2016-03-09 14:38:36 +00003726 * @return {@code true} if the private key alias no longer exists, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003727 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3728 * owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003729 * @see #setDelegatedScopes
3730 * @see #DELEGATION_CERT_INSTALL
Robin Leefbc65642015-08-03 16:21:22 +01003731 */
3732 public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003733 throwIfParentInstance("removeKeyPair");
Robin Leefbc65642015-08-03 16:21:22 +01003734 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003735 return mService.removeKeyPair(admin, mContext.getPackageName(), alias);
Robin Leefbc65642015-08-03 16:21:22 +01003736 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003737 throw e.rethrowFromSystemServer();
Robin Leefbc65642015-08-03 16:21:22 +01003738 }
Robin Leefbc65642015-08-03 16:21:22 +01003739 }
3740
3741 /**
Robin Lee25e26452015-06-02 09:56:29 -07003742 * @return the alias of a given CA certificate in the certificate store, or {@code null} if it
Robin Lee306fe082014-06-19 14:04:24 +00003743 * doesn't exist.
3744 */
3745 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
3746 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
3747 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
3748 new ByteArrayInputStream(certBuffer));
3749 return new TrustedCertificateStore().getCertificateAlias(cert);
3750 }
3751
3752 /**
Rubin Xuec32b562015-03-03 17:34:05 +00003753 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01003754 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00003755 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01003756 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00003757 * <p>
3758 * Delegated certificate installer is a per-user state. The delegated access is persistent until
3759 * it is later cleared by calling this method with a null value or uninstallling the certificate
3760 * installer.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003761 * <p>
Rubin Xuf03d0a62016-02-10 14:54:15 +00003762 * <b>Note:</b>Starting from {@link android.os.Build.VERSION_CODES#N}, if the caller
3763 * application's target SDK version is {@link android.os.Build.VERSION_CODES#N} or newer, the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003764 * supplied certificate installer package must be installed when calling this API, otherwise an
3765 * {@link IllegalArgumentException} will be thrown.
Rubin Xuec32b562015-03-03 17:34:05 +00003766 *
Robin Lee25e26452015-06-02 09:56:29 -07003767 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xuec32b562015-03-03 17:34:05 +00003768 * @param installerPackage The package name of the certificate installer which will be given
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003769 * access. If {@code null} is given the current package will be cleared.
3770 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003771 *
3772 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #setDelegatedScopes}
3773 * with the {@link #DELEGATION_CERT_INSTALL} scope instead.
Rubin Xuec32b562015-03-03 17:34:05 +00003774 */
Edman Anjosf9946772016-11-28 16:35:15 +01003775 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07003776 public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String
3777 installerPackage) throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003778 throwIfParentInstance("setCertInstallerPackage");
Rubin Xuec32b562015-03-03 17:34:05 +00003779 if (mService != null) {
3780 try {
Robin Lee25e26452015-06-02 09:56:29 -07003781 mService.setCertInstallerPackage(admin, installerPackage);
Rubin Xuec32b562015-03-03 17:34:05 +00003782 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003783 throw e.rethrowFromSystemServer();
Rubin Xuec32b562015-03-03 17:34:05 +00003784 }
3785 }
3786 }
3787
3788 /**
Edman Anjosf9946772016-11-28 16:35:15 +01003789 * Called by a profile owner or device owner to retrieve the certificate installer for the user,
3790 * or {@code null} if none is set. If there are multiple delegates this function will return one
3791 * of them.
Rubin Xuec32b562015-03-03 17:34:05 +00003792 *
Robin Lee25e26452015-06-02 09:56:29 -07003793 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003794 * @return The package name of the current delegated certificate installer, or {@code null} if
3795 * none is set.
3796 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003797 *
3798 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatePackages}
3799 * with the {@link #DELEGATION_CERT_INSTALL} scope instead.
Rubin Xuec32b562015-03-03 17:34:05 +00003800 */
Edman Anjosf9946772016-11-28 16:35:15 +01003801 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07003802 public @Nullable String getCertInstallerPackage(@NonNull ComponentName admin)
3803 throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003804 throwIfParentInstance("getCertInstallerPackage");
Rubin Xuec32b562015-03-03 17:34:05 +00003805 if (mService != null) {
3806 try {
Robin Lee25e26452015-06-02 09:56:29 -07003807 return mService.getCertInstallerPackage(admin);
Rubin Xuec32b562015-03-03 17:34:05 +00003808 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003809 throw e.rethrowFromSystemServer();
Rubin Xuec32b562015-03-03 17:34:05 +00003810 }
3811 }
3812 return null;
3813 }
3814
3815 /**
Edman Anjosf9946772016-11-28 16:35:15 +01003816 * Called by a profile owner or device owner to grant access to privileged APIs to another app.
3817 * Granted APIs are determined by {@code scopes}, which is a list of the {@code DELEGATION_*}
3818 * constants.
3819 * <p>
Edman Anjos9e62c312017-01-26 22:22:58 +01003820 * A broadcast with the {@link #ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED} action will be
3821 * sent to the {@code delegatePackage} with its new scopes in an {@code ArrayList<String>} extra
3822 * under the {@link #EXTRA_DELEGATION_SCOPES} key. The broadcast is sent with the
3823 * {@link Intent#FLAG_RECEIVER_REGISTERED_ONLY} flag.
3824 * <p>
Edman Anjosf9946772016-11-28 16:35:15 +01003825 * Delegated scopes are a per-user state. The delegated access is persistent until it is later
3826 * cleared by calling this method with an empty {@code scopes} list or uninstalling the
3827 * {@code delegatePackage}.
3828 *
3829 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3830 * @param delegatePackage The package name of the app which will be given access.
3831 * @param scopes The groups of privileged APIs whose access should be granted to
3832 * {@code delegatedPackage}.
3833 * @throws SecurityException if {@code admin} is not a device or a profile owner.
3834 */
3835 public void setDelegatedScopes(@NonNull ComponentName admin, @NonNull String delegatePackage,
3836 @NonNull List<String> scopes) {
3837 throwIfParentInstance("setDelegatedScopes");
3838 if (mService != null) {
3839 try {
3840 mService.setDelegatedScopes(admin, delegatePackage, scopes);
3841 } catch (RemoteException e) {
3842 throw e.rethrowFromSystemServer();
3843 }
3844 }
3845 }
3846
3847 /**
3848 * Called by a profile owner or device owner to retrieve a list of the scopes given to a
3849 * delegate package. Other apps can use this method to retrieve their own delegated scopes by
3850 * passing {@code null} for {@code admin} and their own package name as
3851 * {@code delegatedPackage}.
3852 *
3853 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3854 * {@code null} if the caller is {@code delegatedPackage}.
3855 * @param delegatedPackage The package name of the app whose scopes should be retrieved.
3856 * @return A list containing the scopes given to {@code delegatedPackage}.
3857 * @throws SecurityException if {@code admin} is not a device or a profile owner.
3858 */
3859 @NonNull
Edman Anjos9e62c312017-01-26 22:22:58 +01003860 public List<String> getDelegatedScopes(@Nullable ComponentName admin,
Edman Anjosf9946772016-11-28 16:35:15 +01003861 @NonNull String delegatedPackage) {
3862 throwIfParentInstance("getDelegatedScopes");
3863 if (mService != null) {
3864 try {
3865 return mService.getDelegatedScopes(admin, delegatedPackage);
3866 } catch (RemoteException e) {
3867 throw e.rethrowFromSystemServer();
3868 }
3869 }
3870 return null;
3871 }
3872
3873 /**
3874 * Called by a profile owner or device owner to retrieve a list of delegate packages that were
3875 * granted a delegation scope.
3876 *
3877 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3878 * @param delegationScope The scope whose delegates should be retrieved.
3879 * @return A list of package names of the current delegated packages for
3880 {@code delegationScope}.
3881 * @throws SecurityException if {@code admin} is not a device or a profile owner.
3882 */
3883 @Nullable
3884 public List<String> getDelegatePackages(@NonNull ComponentName admin,
3885 @NonNull String delegationScope) {
3886 throwIfParentInstance("getDelegatePackages");
3887 if (mService != null) {
3888 try {
3889 return mService.getDelegatePackages(admin, delegationScope);
3890 } catch (RemoteException e) {
3891 throw e.rethrowFromSystemServer();
3892 }
3893 }
3894 return null;
3895 }
3896
3897 /**
Robin Lee244ce8e2016-01-05 18:03:46 +00003898 * Called by a device or profile owner to configure an always-on VPN connection through a
Robin Leedc679712016-05-03 13:23:03 +01003899 * specific application for the current user.
3900 *
3901 * @deprecated this version only exists for compability with previous developer preview builds.
3902 * TODO: delete once there are no longer any live references.
3903 * @hide
3904 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07003905 @Deprecated
Robin Leedc679712016-05-03 13:23:03 +01003906 public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage)
3907 throws NameNotFoundException, UnsupportedOperationException {
3908 setAlwaysOnVpnPackage(admin, vpnPackage, /* lockdownEnabled */ true);
3909 }
3910
3911 /**
3912 * Called by a device or profile owner to configure an always-on VPN connection through a
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003913 * specific application for the current user. This connection is automatically granted and
3914 * persisted after a reboot.
3915 * <p>
3916 * The designated package should declare a {@link android.net.VpnService} in its manifest
3917 * guarded by {@link android.Manifest.permission#BIND_VPN_SERVICE}, otherwise the call will
3918 * fail.
Robin Lee244ce8e2016-01-05 18:03:46 +00003919 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003920 * @param vpnPackage The package name for an installed VPN app on the device, or {@code null} to
Robin Leedc679712016-05-03 13:23:03 +01003921 * remove an existing always-on VPN configuration.
3922 * @param lockdownEnabled {@code true} to disallow networking when the VPN is not connected or
3923 * {@code false} otherwise. This carries the risk that any failure of the VPN provider
3924 * could break networking for all apps. This has no effect when clearing.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003925 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Robin Leeee5eb932016-04-05 16:27:15 +01003926 * @throws NameNotFoundException if {@code vpnPackage} is not installed.
3927 * @throws UnsupportedOperationException if {@code vpnPackage} exists but does not support being
3928 * set as always-on, or if always-on VPN is not available.
Robin Lee244ce8e2016-01-05 18:03:46 +00003929 */
Robin Leedc679712016-05-03 13:23:03 +01003930 public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage,
3931 boolean lockdownEnabled)
Robin Leeee5eb932016-04-05 16:27:15 +01003932 throws NameNotFoundException, UnsupportedOperationException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003933 throwIfParentInstance("setAlwaysOnVpnPackage");
Robin Lee244ce8e2016-01-05 18:03:46 +00003934 if (mService != null) {
3935 try {
Robin Leedc679712016-05-03 13:23:03 +01003936 if (!mService.setAlwaysOnVpnPackage(admin, vpnPackage, lockdownEnabled)) {
Robin Leeee5eb932016-04-05 16:27:15 +01003937 throw new NameNotFoundException(vpnPackage);
3938 }
Robin Lee244ce8e2016-01-05 18:03:46 +00003939 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003940 throw e.rethrowFromSystemServer();
Robin Lee244ce8e2016-01-05 18:03:46 +00003941 }
3942 }
Robin Lee244ce8e2016-01-05 18:03:46 +00003943 }
3944
3945 /**
3946 * Called by a device or profile owner to read the name of the package administering an
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003947 * always-on VPN connection for the current user. If there is no such package, or the always-on
3948 * VPN is provided by the system instead of by an application, {@code null} will be returned.
Robin Lee244ce8e2016-01-05 18:03:46 +00003949 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003950 * @return Package name of VPN controller responsible for always-on VPN, or {@code null} if none
3951 * is set.
3952 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Robin Lee244ce8e2016-01-05 18:03:46 +00003953 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003954 public @Nullable String getAlwaysOnVpnPackage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003955 throwIfParentInstance("getAlwaysOnVpnPackage");
Robin Lee244ce8e2016-01-05 18:03:46 +00003956 if (mService != null) {
3957 try {
3958 return mService.getAlwaysOnVpnPackage(admin);
3959 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003960 throw e.rethrowFromSystemServer();
Robin Lee244ce8e2016-01-05 18:03:46 +00003961 }
3962 }
3963 return null;
3964 }
3965
3966 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003967 * Called by an application that is administering the device to disable all cameras on the
3968 * device, for this user. After setting this, no applications running as this user will be able
3969 * to access any cameras on the device.
3970 * <p>
3971 * If the caller is device owner, then the restriction will be applied to all users.
3972 * <p>
3973 * The calling device admin must have requested
3974 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call this method; if it has
3975 * not, a security exception will be thrown.
Ben Komalo2447edd2011-05-09 16:05:33 -07003976 *
3977 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3978 * @param disabled Whether or not the camera should be disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003979 * @throws SecurityException if {@code admin} is not an active administrator or does not use
3980 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA}.
Ben Komalo2447edd2011-05-09 16:05:33 -07003981 */
Robin Lee25e26452015-06-02 09:56:29 -07003982 public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003983 throwIfParentInstance("setCameraDisabled");
Ben Komalo2447edd2011-05-09 16:05:33 -07003984 if (mService != null) {
3985 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003986 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07003987 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003988 throw e.rethrowFromSystemServer();
Ben Komalo2447edd2011-05-09 16:05:33 -07003989 }
3990 }
3991 }
3992
3993 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07003994 * Determine whether or not the device's cameras have been disabled for this user,
Makoto Onuki32b30572015-12-11 14:29:51 -08003995 * either by the calling admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07003996 * @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 -07003997 * have disabled the camera
3998 */
Robin Lee25e26452015-06-02 09:56:29 -07003999 public boolean getCameraDisabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004000 throwIfParentInstance("getCameraDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004001 return getCameraDisabled(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004002 }
4003
4004 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07004005 public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07004006 if (mService != null) {
4007 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004008 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07004009 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004010 throw e.rethrowFromSystemServer();
Ben Komalo2447edd2011-05-09 16:05:33 -07004011 }
4012 }
4013 return false;
4014 }
4015
4016 /**
Michal Karpinski3fc437e2015-12-15 10:09:00 +00004017 * Called by a device owner to request a bugreport.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004018 * <p>
Esteban Talaverad36dd152016-12-15 08:51:45 +00004019 * If the device contains secondary users or profiles, they must be affiliated with the device
4020 * owner user. Otherwise a {@link SecurityException} will be thrown. See
4021 * {@link #setAffiliationIds}.
Michal Karpinski3fc437e2015-12-15 10:09:00 +00004022 *
4023 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004024 * @return {@code true} if the bugreport collection started successfully, or {@code false} if it
4025 * wasn't triggered because a previous bugreport operation is still active (either the
4026 * bugreport is still running or waiting for the user to share or decline)
Esteban Talaverad36dd152016-12-15 08:51:45 +00004027 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
4028 * profile or secondary user that is not affiliated with the device owner user.
Michal Karpinski3fc437e2015-12-15 10:09:00 +00004029 */
4030 public boolean requestBugreport(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004031 throwIfParentInstance("requestBugreport");
Michal Karpinski3fc437e2015-12-15 10:09:00 +00004032 if (mService != null) {
4033 try {
4034 return mService.requestBugreport(admin);
4035 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004036 throw e.rethrowFromSystemServer();
Michal Karpinski3fc437e2015-12-15 10:09:00 +00004037 }
4038 }
4039 return false;
4040 }
4041
4042 /**
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07004043 * Determine whether or not creating a guest user has been disabled for the device
4044 *
4045 * @hide
4046 */
4047 public boolean getGuestUserDisabled(@Nullable ComponentName admin) {
4048 // Currently guest users can always be created if multi-user is enabled
4049 // TODO introduce a policy for guest user creation
4050 return false;
4051 }
4052
4053 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01004054 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
4055 * screen capture also prevents the content from being shown on display devices that do not have
4056 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
4057 * secure surfaces and secure displays.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004058 * <p>
4059 * The calling device admin must be a device or profile owner. If it is not, a security
4060 * exception will be thrown.
4061 * <p>
4062 * From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also blocks
4063 * assist requests for all activities of the relevant user.
Benjamin Franzc200f442015-06-25 18:20:04 +01004064 *
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004065 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004066 * @param disabled Whether screen capture is disabled or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004067 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004068 */
Robin Lee25e26452015-06-02 09:56:29 -07004069 public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004070 throwIfParentInstance("setScreenCaptureDisabled");
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004071 if (mService != null) {
4072 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08004073 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004074 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004075 throw e.rethrowFromSystemServer();
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004076 }
4077 }
4078 }
4079
4080 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004081 * Determine whether or not screen capture has been disabled by the calling
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004082 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07004083 * @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 +01004084 * have disabled screen capture.
4085 */
Robin Lee25e26452015-06-02 09:56:29 -07004086 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004087 throwIfParentInstance("getScreenCaptureDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004088 return getScreenCaptureDisabled(admin, myUserId());
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004089 }
4090
4091 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07004092 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004093 if (mService != null) {
4094 try {
4095 return mService.getScreenCaptureDisabled(admin, userHandle);
4096 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004097 throw e.rethrowFromSystemServer();
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004098 }
4099 }
4100 return false;
4101 }
4102
4103 /**
Jason Parks841cb0a2017-01-17 15:25:17 -06004104 * Called by a device or profile owner to set whether auto time is required. If auto time is
4105 * 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 -07004106 * <p>
4107 * Note: if auto time is required the user can still manually set the time zone.
4108 * <p>
Jason Parks841cb0a2017-01-17 15:25:17 -06004109 * The calling device admin must be a device or profile owner. If it is not, a security
4110 * exception will be thrown.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004111 *
4112 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4113 * @param required Whether auto time is set required or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004114 * @throws SecurityException if {@code admin} is not a device owner.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004115 */
Robin Lee25e26452015-06-02 09:56:29 -07004116 public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004117 throwIfParentInstance("setAutoTimeRequired");
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004118 if (mService != null) {
4119 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08004120 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004121 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004122 throw e.rethrowFromSystemServer();
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004123 }
4124 }
4125 }
4126
4127 /**
4128 * @return true if auto time is required.
4129 */
4130 public boolean getAutoTimeRequired() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004131 throwIfParentInstance("getAutoTimeRequired");
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004132 if (mService != null) {
4133 try {
4134 return mService.getAutoTimeRequired();
4135 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004136 throw e.rethrowFromSystemServer();
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004137 }
4138 }
4139 return false;
4140 }
4141
4142 /**
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004143 * Called by a device owner to set whether all users created on the device should be ephemeral.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004144 * <p>
4145 * The system user is exempt from this policy - it is never ephemeral.
4146 * <p>
4147 * The calling device admin must be the device owner. If it is not, a security exception will be
4148 * thrown.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004149 *
4150 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4151 * @param forceEphemeralUsers If true, all the existing users will be deleted and all
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004152 * subsequently created users will be ephemeral.
4153 * @throws SecurityException if {@code admin} is not a device owner.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004154 * @hide
4155 */
4156 public void setForceEphemeralUsers(
4157 @NonNull ComponentName admin, boolean forceEphemeralUsers) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004158 throwIfParentInstance("setForceEphemeralUsers");
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004159 if (mService != null) {
4160 try {
4161 mService.setForceEphemeralUsers(admin, forceEphemeralUsers);
4162 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004163 throw e.rethrowFromSystemServer();
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004164 }
4165 }
4166 }
4167
4168 /**
4169 * @return true if all users are created ephemeral.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004170 * @throws SecurityException if {@code admin} is not a device owner.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004171 * @hide
4172 */
4173 public boolean getForceEphemeralUsers(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004174 throwIfParentInstance("getForceEphemeralUsers");
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004175 if (mService != null) {
4176 try {
4177 return mService.getForceEphemeralUsers(admin);
4178 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004179 throw e.rethrowFromSystemServer();
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004180 }
4181 }
4182 return false;
4183 }
4184
4185 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07004186 * Called by an application that is administering the device to disable keyguard customizations,
4187 * such as widgets. After setting this, keyguard features will be disabled according to the
4188 * provided feature list.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004189 * <p>
4190 * The calling device admin must have requested
4191 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method;
4192 * if it has not, a security exception will be thrown.
4193 * <p>
4194 * Calling this from a managed profile before version {@link android.os.Build.VERSION_CODES#M}
4195 * will throw a security exception. From version {@link android.os.Build.VERSION_CODES#M} the
4196 * profile owner of a managed profile can set:
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00004197 * <ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00004198 * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which affects the parent user, but only if there
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004199 * is no separate challenge set on the managed profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00004200 * <li>{@link #KEYGUARD_DISABLE_FINGERPRINT} which affects the managed profile challenge if
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004201 * there is one, or the parent user otherwise.
4202 * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} which affects notifications generated
4203 * by applications in the managed profile.
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00004204 * </ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00004205 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} and {@link #KEYGUARD_DISABLE_FINGERPRINT} can also be
4206 * set on the {@link DevicePolicyManager} instance returned by
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004207 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
4208 * profile.
4209 * <p>
4210 * Requests to disable other features on a managed profile will be ignored.
4211 * <p>
4212 * The admin can check which features have been disabled by calling
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00004213 * {@link #getKeyguardDisabledFeatures(ComponentName)}
Amith Yamasani242f4b12014-10-14 16:06:13 -07004214 *
Jim Millerb8ec4702012-08-31 17:19:10 -07004215 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07004216 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004217 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
4218 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS},
4219 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
4220 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS},
4221 * {@link #KEYGUARD_DISABLE_FINGERPRINT}, {@link #KEYGUARD_DISABLE_FEATURES_ALL}
4222 * @throws SecurityException if {@code admin} is not an active administrator or does not user
4223 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES}
Jim Millerb8ec4702012-08-31 17:19:10 -07004224 */
Robin Lee25e26452015-06-02 09:56:29 -07004225 public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07004226 if (mService != null) {
4227 try {
Esteban Talavera62399912016-01-11 15:37:55 +00004228 mService.setKeyguardDisabledFeatures(admin, which, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07004229 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004230 throw e.rethrowFromSystemServer();
Jim Millerb8ec4702012-08-31 17:19:10 -07004231 }
4232 }
4233 }
4234
4235 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004236 * Determine whether or not features have been disabled in keyguard either by the calling
Rubin Xud3609d42016-07-13 18:32:57 +01004237 * admin, if specified, or all admins that set restrictions on this user and its participating
Esteban Talaverac1c83592016-02-17 17:56:15 +00004238 * profiles. Restrictions on profiles that have a separate challenge are not taken into account.
4239 *
4240 * <p>This method can be called on the {@link DevicePolicyManager} instance
4241 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
4242 * restrictions on the parent profile.
4243 *
Esteban Talavera62399912016-01-11 15:37:55 +00004244 * @param admin The name of the admin component to check, or {@code null} to check whether any
4245 * admins have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07004246 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
4247 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07004248 */
Robin Lee25e26452015-06-02 09:56:29 -07004249 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004250 return getKeyguardDisabledFeatures(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004251 }
4252
4253 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07004254 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07004255 if (mService != null) {
4256 try {
Esteban Talavera62399912016-01-11 15:37:55 +00004257 return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07004258 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004259 throw e.rethrowFromSystemServer();
Jim Millerb8ec4702012-08-31 17:19:10 -07004260 }
4261 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07004262 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07004263 }
4264
4265 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08004266 * @hide
4267 */
Robin Lee25e26452015-06-02 09:56:29 -07004268 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
4269 int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08004270 if (mService != null) {
4271 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01004272 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08004273 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004274 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08004275 }
4276 }
4277 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07004278
Dianne Hackbornd6847842010-01-12 18:14:19 -08004279 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01004280 * @hide
4281 */
Robin Lee25e26452015-06-02 09:56:29 -07004282 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004283 setActiveAdmin(policyReceiver, refreshing, myUserId());
Jessica Hummel6d36b602014-04-04 12:42:17 +01004284 }
4285
4286 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08004287 * @hide
4288 */
Robin Lee25e26452015-06-02 09:56:29 -07004289 public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08004290 if (mService != null) {
4291 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004292 mService.getRemoveWarning(admin, result, myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08004293 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004294 throw e.rethrowFromSystemServer();
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08004295 }
4296 }
4297 }
4298
4299 /**
4300 * @hide
4301 */
Andrew Scull5f9e6f32016-08-02 14:22:17 +01004302 public void setActivePasswordState(PasswordMetrics metrics, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08004303 if (mService != null) {
4304 try {
Andrew Scull5f9e6f32016-08-02 14:22:17 +01004305 mService.setActivePasswordState(metrics, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08004306 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004307 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08004308 }
4309 }
4310 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07004311
Dianne Hackbornd6847842010-01-12 18:14:19 -08004312 /**
4313 * @hide
4314 */
Andrew Scull5daf2732016-11-14 15:02:45 +00004315 public void reportPasswordChanged(@UserIdInt int userId) {
4316 if (mService != null) {
4317 try {
4318 mService.reportPasswordChanged(userId);
4319 } catch (RemoteException e) {
4320 throw e.rethrowFromSystemServer();
4321 }
4322 }
4323 }
4324
4325 /**
4326 * @hide
4327 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004328 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08004329 if (mService != null) {
4330 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004331 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08004332 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004333 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08004334 }
4335 }
4336 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07004337
Dianne Hackbornd6847842010-01-12 18:14:19 -08004338 /**
4339 * @hide
4340 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004341 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08004342 if (mService != null) {
4343 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004344 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08004345 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004346 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08004347 }
4348 }
4349 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07004350
4351 /**
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004352 * @hide
4353 */
4354 public void reportFailedFingerprintAttempt(int userHandle) {
4355 if (mService != null) {
4356 try {
4357 mService.reportFailedFingerprintAttempt(userHandle);
4358 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004359 throw e.rethrowFromSystemServer();
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004360 }
4361 }
4362 }
4363
4364 /**
4365 * @hide
4366 */
4367 public void reportSuccessfulFingerprintAttempt(int userHandle) {
4368 if (mService != null) {
4369 try {
4370 mService.reportSuccessfulFingerprintAttempt(userHandle);
4371 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004372 throw e.rethrowFromSystemServer();
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004373 }
4374 }
4375 }
4376
4377 /**
Michal Karpinski31502d32016-01-25 16:43:07 +00004378 * Should be called when keyguard has been dismissed.
4379 * @hide
4380 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004381 public void reportKeyguardDismissed(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00004382 if (mService != null) {
4383 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004384 mService.reportKeyguardDismissed(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00004385 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004386 throw e.rethrowFromSystemServer();
Michal Karpinski31502d32016-01-25 16:43:07 +00004387 }
4388 }
4389 }
4390
4391 /**
4392 * Should be called when keyguard view has been shown to the user.
4393 * @hide
4394 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004395 public void reportKeyguardSecured(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00004396 if (mService != null) {
4397 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004398 mService.reportKeyguardSecured(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00004399 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004400 throw e.rethrowFromSystemServer();
Michal Karpinski31502d32016-01-25 16:43:07 +00004401 }
4402 }
4403 }
4404
4405 /**
Amith Yamasani71e6c692013-03-24 17:39:28 -07004406 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00004407 * Sets the given package as the device owner.
Makoto Onukia52562c2015-10-01 16:12:31 -07004408 * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name.
4409 * @param who the component name to be registered as device owner.
Amith Yamasani71e6c692013-03-24 17:39:28 -07004410 * @return whether the package was successfully registered as the device owner.
4411 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00004412 * @throws IllegalStateException If the preconditions mentioned are not met.
Amith Yamasani71e6c692013-03-24 17:39:28 -07004413 */
Makoto Onukia52562c2015-10-01 16:12:31 -07004414 public boolean setDeviceOwner(ComponentName who) {
4415 return setDeviceOwner(who, null);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004416 }
4417
4418 /**
4419 * @hide
Makoto Onuki58b684f2015-09-04 10:48:16 -07004420 */
Makoto Onukia52562c2015-10-01 16:12:31 -07004421 public boolean setDeviceOwner(ComponentName who, int userId) {
4422 return setDeviceOwner(who, null, userId);
Makoto Onuki58b684f2015-09-04 10:48:16 -07004423 }
4424
4425 /**
4426 * @hide
4427 */
Makoto Onukia52562c2015-10-01 16:12:31 -07004428 public boolean setDeviceOwner(ComponentName who, String ownerName) {
4429 return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM);
Makoto Onuki58b684f2015-09-04 10:48:16 -07004430 }
4431
4432 /**
4433 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00004434 * Sets the given package as the device owner. The package must already be installed. There
4435 * must not already be a device owner.
4436 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
4437 * this method.
4438 * Calling this after the setup phase of the primary user has completed is allowed only if
4439 * the caller is the shell uid, and there are no additional users and no accounts.
Makoto Onukia52562c2015-10-01 16:12:31 -07004440 * @param who the component name to be registered as device owner.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004441 * @param ownerName the human readable name of the institution that owns this device.
Makoto Onuki58b684f2015-09-04 10:48:16 -07004442 * @param userId ID of the user on which the device owner runs.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004443 * @return whether the package was successfully registered as the device owner.
4444 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00004445 * @throws IllegalStateException If the preconditions mentioned are not met.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004446 */
Makoto Onukia52562c2015-10-01 16:12:31 -07004447 public boolean setDeviceOwner(ComponentName who, String ownerName, int userId)
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004448 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07004449 if (mService != null) {
4450 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07004451 return mService.setDeviceOwner(who, ownerName, userId);
Amith Yamasani71e6c692013-03-24 17:39:28 -07004452 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004453 throw re.rethrowFromSystemServer();
Amith Yamasani71e6c692013-03-24 17:39:28 -07004454 }
4455 }
4456 return false;
4457 }
4458
4459 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004460 * Used to determine if a particular package has been registered as a Device Owner app.
4461 * A device owner app is a special device admin that cannot be deactivated by the user, once
Robin Lee25e26452015-06-02 09:56:29 -07004462 * activated as a device admin. It also cannot be uninstalled. To check whether a particular
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004463 * package is currently registered as the device owner app, pass in the package name from
4464 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
Robin Lee25e26452015-06-02 09:56:29 -07004465 * admin apps that want to check whether they are also registered as the device owner app. The
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004466 * exact mechanism by which a device admin app is registered as a device owner app is defined by
4467 * the setup process.
4468 * @param packageName the package name of the app, to compare with the registered device owner
4469 * app, if any.
Makoto Onukic8a5a552015-11-19 14:29:12 -08004470 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07004471 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004472 public boolean isDeviceOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004473 throwIfParentInstance("isDeviceOwnerApp");
Makoto Onukic8a5a552015-11-19 14:29:12 -08004474 return isDeviceOwnerAppOnCallingUser(packageName);
4475 }
4476
4477 /**
4478 * @return true if a package is registered as device owner, only when it's running on the
4479 * calling user.
4480 *
4481 * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity.
4482 * @hide
4483 */
4484 public boolean isDeviceOwnerAppOnCallingUser(String packageName) {
4485 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true);
4486 }
4487
4488 /**
4489 * @return true if a package is registered as device owner, even if it's running on a different
4490 * user.
4491 *
4492 * <p>Requires the MANAGE_USERS permission.
4493 *
4494 * @hide
4495 */
4496 public boolean isDeviceOwnerAppOnAnyUser(String packageName) {
4497 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false);
4498 }
4499
4500 /**
4501 * @return device owner component name, only when it's running on the calling user.
4502 *
4503 * @hide
4504 */
4505 public ComponentName getDeviceOwnerComponentOnCallingUser() {
4506 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true);
4507 }
4508
4509 /**
4510 * @return device owner component name, even if it's running on a different user.
4511 *
4512 * <p>Requires the MANAGE_USERS permission.
4513 *
4514 * @hide
4515 */
Polina Bondarenko23561db2016-12-16 11:47:28 +01004516 @SystemApi
Makoto Onukic8a5a552015-11-19 14:29:12 -08004517 public ComponentName getDeviceOwnerComponentOnAnyUser() {
4518 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false);
4519 }
4520
4521 private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) {
Makoto Onuki70f929e2015-11-11 12:40:15 -08004522 if (packageName == null) {
4523 return false;
Amith Yamasani71e6c692013-03-24 17:39:28 -07004524 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08004525 final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly);
Makoto Onuki70f929e2015-11-11 12:40:15 -08004526 if (deviceOwner == null) {
4527 return false;
4528 }
4529 return packageName.equals(deviceOwner.getPackageName());
Amith Yamasani71e6c692013-03-24 17:39:28 -07004530 }
4531
Makoto Onukic8a5a552015-11-19 14:29:12 -08004532 private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) {
4533 if (mService != null) {
4534 try {
4535 return mService.getDeviceOwnerComponent(callingUserOnly);
4536 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004537 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08004538 }
4539 }
4540 return null;
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004541 }
4542
Jason Monkb0dced82014-06-06 14:36:20 -04004543 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08004544 * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's
4545 * no device owner.
4546 *
4547 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07004548 *
4549 * @hide
4550 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08004551 public int getDeviceOwnerUserId() {
4552 if (mService != null) {
4553 try {
4554 return mService.getDeviceOwnerUserId();
4555 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004556 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08004557 }
4558 }
4559 return UserHandle.USER_NULL;
Makoto Onukia52562c2015-10-01 16:12:31 -07004560 }
4561
4562 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004563 * Clears the current device owner. The caller must be the device owner. This function should be
4564 * used cautiously as once it is called it cannot be undone. The device owner can only be set as
Esteban Talaveraa5b09632017-02-10 16:15:24 +00004565 * a part of device setup, before it completes.
4566 * <p>
4567 * While some policies previously set by the device owner will be cleared by this method, it is
4568 * a best-effort process and some other policies will still remain in place after the device
4569 * owner is cleared.
Jason Monk94d2cf92014-06-18 09:53:34 -04004570 *
4571 * @param packageName The package name of the device owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004572 * @throws SecurityException if the caller is not in {@code packageName} or {@code packageName}
4573 * does not own the current device owner component.
Esteban Talaveraa5b09632017-02-10 16:15:24 +00004574 *
4575 * @deprecated This method is expected to be used for testing purposes only. The device owner
4576 * will lose control of the device and its data after calling it. In order to protect any
4577 * sensitive data that remains on the device, it is advised that the device owner factory resets
4578 * the device instead of calling this method. See {@link #wipeData(int)}.
Jason Monkb0dced82014-06-06 14:36:20 -04004579 */
Esteban Talaveraa5b09632017-02-10 16:15:24 +00004580 @Deprecated
Jason Monk94d2cf92014-06-18 09:53:34 -04004581 public void clearDeviceOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004582 throwIfParentInstance("clearDeviceOwnerApp");
Jason Monkb0dced82014-06-06 14:36:20 -04004583 if (mService != null) {
4584 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04004585 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04004586 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004587 throw re.rethrowFromSystemServer();
Jason Monkb0dced82014-06-06 14:36:20 -04004588 }
4589 }
4590 }
4591
Makoto Onukia52562c2015-10-01 16:12:31 -07004592 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08004593 * Returns the device owner package name, only if it's running on the calling user.
4594 *
4595 * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity.
Makoto Onukia52562c2015-10-01 16:12:31 -07004596 *
4597 * @hide
4598 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01004599 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004600 public @Nullable String getDeviceOwner() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004601 throwIfParentInstance("getDeviceOwner");
Makoto Onukic8a5a552015-11-19 14:29:12 -08004602 final ComponentName name = getDeviceOwnerComponentOnCallingUser();
4603 return name != null ? name.getPackageName() : null;
Makoto Onukia52562c2015-10-01 16:12:31 -07004604 }
4605
4606 /**
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004607 * Called by the system to find out whether the device is managed by a Device Owner.
Makoto Onukic8a5a552015-11-19 14:29:12 -08004608 *
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004609 * @return whether the device is managed by a Device Owner.
4610 * @throws SecurityException if the caller is not the device owner, does not hold the
4611 * MANAGE_USERS permission and is not the system.
Makoto Onukia52562c2015-10-01 16:12:31 -07004612 *
4613 * @hide
4614 */
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004615 @SystemApi
4616 @TestApi
Makoto Onukic8a5a552015-11-19 14:29:12 -08004617 public boolean isDeviceManaged() {
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004618 try {
4619 return mService.hasDeviceOwner();
4620 } catch (RemoteException re) {
4621 throw re.rethrowFromSystemServer();
4622 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08004623 }
4624
4625 /**
4626 * Returns the device owner name. Note this method *will* return the device owner
4627 * name when it's running on a different user.
4628 *
4629 * <p>Requires the MANAGE_USERS permission.
4630 *
4631 * @hide
4632 */
Makoto Onukia2b274b2016-01-19 13:26:02 -08004633 @SystemApi
Makoto Onukic8a5a552015-11-19 14:29:12 -08004634 public String getDeviceOwnerNameOnAnyUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004635 throwIfParentInstance("getDeviceOwnerNameOnAnyUser");
Amith Yamasani71e6c692013-03-24 17:39:28 -07004636 if (mService != null) {
4637 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07004638 return mService.getDeviceOwnerName();
Amith Yamasani71e6c692013-03-24 17:39:28 -07004639 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004640 throw re.rethrowFromSystemServer();
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004641 }
4642 }
4643 return null;
4644 }
Adam Connors776c5552014-01-09 10:42:56 +00004645
4646 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04004647 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004648 * @deprecated Do not use
4649 * @removed
Julia Reynolds20118f12015-02-11 12:34:08 -05004650 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004651 @Deprecated
Julia Reynolds20118f12015-02-11 12:34:08 -05004652 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004653 public @Nullable String getDeviceInitializerApp() {
Julia Reynolds20118f12015-02-11 12:34:08 -05004654 return null;
4655 }
4656
4657 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004658 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004659 * @deprecated Do not use
4660 * @removed
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004661 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004662 @Deprecated
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004663 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004664 public @Nullable ComponentName getDeviceInitializerComponent() {
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004665 return null;
4666 }
4667
Julia Reynolds20118f12015-02-11 12:34:08 -05004668 /**
Adam Connors776c5552014-01-09 10:42:56 +00004669 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004670 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304671 * Sets the given component as an active admin and registers the package as the profile
4672 * owner for this user. The package must already be installed and there shouldn't be
4673 * an existing profile owner registered for this user. Also, this method must be called
4674 * before the user setup has been completed.
4675 * <p>
4676 * This method can only be called by system apps that hold MANAGE_USERS permission and
4677 * MANAGE_DEVICE_ADMINS permission.
4678 * @param admin The component to register as an active admin and profile owner.
4679 * @param ownerName The user-visible name of the entity that is managing this user.
4680 * @return whether the admin was successfully registered as the profile owner.
4681 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
4682 * the user has already been set up.
4683 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07004684 @Deprecated
Justin Morey80440cc2014-07-24 09:16:35 -05004685 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07004686 public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304687 throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004688 throwIfParentInstance("setActiveProfileOwner");
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304689 if (mService != null) {
4690 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004691 final int myUserId = myUserId();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304692 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004693 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304694 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004695 throw re.rethrowFromSystemServer();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304696 }
4697 }
4698 return false;
4699 }
4700
4701 /**
Esteban Talaveraa5b09632017-02-10 16:15:24 +00004702 * Clears the active profile owner. The caller must be the profile owner of this user, otherwise
4703 * a SecurityException will be thrown. This method is not available to managed profile owners.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004704 * <p>
Esteban Talaveraa5b09632017-02-10 16:15:24 +00004705 * While some policies previously set by the profile owner will be cleared by this method, it is
4706 * a best-effort process and some other policies will still remain in place after the profile
4707 * owner is cleared.
Makoto Onuki5bf68022016-01-27 13:49:19 -08004708 *
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004709 * @param admin The component to remove as the profile owner.
Esteban Talaveraa5b09632017-02-10 16:15:24 +00004710 * @throws SecurityException if {@code admin} is not an active profile owner, or the method is
4711 * being called from a managed profile.
4712 *
4713 * @deprecated This method is expected to be used for testing purposes only. The profile owner
4714 * will lose control of the user and its data after calling it. In order to protect any
4715 * sensitive data that remains on this user, it is advised that the profile owner deletes it
4716 * instead of calling this method. See {@link #wipeData(int)}.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004717 */
Esteban Talaveraa5b09632017-02-10 16:15:24 +00004718 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07004719 public void clearProfileOwner(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004720 throwIfParentInstance("clearProfileOwner");
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004721 if (mService != null) {
4722 try {
4723 mService.clearProfileOwner(admin);
4724 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004725 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004726 }
4727 }
4728 }
4729
4730 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05004731 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07004732 * Checks whether the user was already setup.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004733 */
4734 public boolean hasUserSetupCompleted() {
4735 if (mService != null) {
4736 try {
4737 return mService.hasUserSetupCompleted();
4738 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004739 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004740 }
4741 }
4742 return true;
4743 }
4744
4745 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004746 * @hide
4747 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00004748 * already be installed. There must not already be a profile owner for this user.
4749 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
4750 * this method.
4751 * Calling this after the setup phase of the specified user has completed is allowed only if:
4752 * - the caller is SYSTEM_UID.
4753 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004754 * @param admin the component name to be registered as profile owner.
4755 * @param ownerName the human readable name of the organisation associated with this DPM.
4756 * @param userHandle the userId to set the profile owner for.
4757 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00004758 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
4759 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004760 */
Robin Lee25e26452015-06-02 09:56:29 -07004761 public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName,
Robin Leeddd553f2015-04-30 14:18:22 +01004762 int userHandle) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00004763 if (mService != null) {
4764 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004765 if (ownerName == null) {
4766 ownerName = "";
4767 }
4768 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00004769 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004770 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004771 }
4772 }
4773 return false;
4774 }
4775
4776 /**
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004777 * Sets the device owner information to be shown on the lock screen.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004778 * <p>
4779 * If the device owner information is {@code null} or empty then the device owner info is
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004780 * cleared and the user owner info is shown on the lock screen if it is set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004781 * <p>
4782 * If the device owner information contains only whitespaces then the message on the lock screen
4783 * will be blank and the user will not be allowed to change it.
4784 * <p>
4785 * If the device owner information needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00004786 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
4787 * and set a new version of this string accordingly.
4788 *
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004789 * @param admin The name of the admin component to check.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004790 * @param info Device owner information which will be displayed instead of the user owner info.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004791 * @throws SecurityException if {@code admin} is not a device owner.
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004792 */
Andrei Stingaceanu16187902016-03-21 15:44:45 +00004793 public void setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, CharSequence info) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004794 throwIfParentInstance("setDeviceOwnerLockScreenInfo");
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004795 if (mService != null) {
4796 try {
Andrei Stingaceanu16187902016-03-21 15:44:45 +00004797 mService.setDeviceOwnerLockScreenInfo(admin, info);
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004798 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004799 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004800 }
4801 }
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004802 }
4803
4804 /**
4805 * @return The device owner information. If it is not set returns {@code null}.
4806 */
Andrei Stingaceanu16187902016-03-21 15:44:45 +00004807 public CharSequence getDeviceOwnerLockScreenInfo() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004808 throwIfParentInstance("getDeviceOwnerLockScreenInfo");
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004809 if (mService != null) {
4810 try {
4811 return mService.getDeviceOwnerLockScreenInfo();
4812 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004813 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004814 }
4815 }
4816 return null;
4817 }
4818
4819 /**
Edman Anjos52088e42017-01-13 22:26:17 +01004820 * Called by device or profile owners to suspend packages for this user. This function can be
4821 * called by a device owner, profile owner, or by a delegate given the
4822 * {@link #DELEGATION_PACKAGE_ACCESS} scope via {@link #setDelegatedScopes}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004823 * <p>
4824 * A suspended package will not be able to start activities. Its notifications will be hidden,
4825 * it will not show up in recents, will not be able to show toasts or dialogs or ring the
4826 * device.
4827 * <p>
4828 * The package must already be installed. If the package is uninstalled while suspended the
4829 * package will no longer be suspended. The admin can block this by using
Kenny Guy871f3eb2016-03-09 20:06:16 +00004830 * {@link #setUninstallBlocked}.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004831 *
Edman Anjos52088e42017-01-13 22:26:17 +01004832 * @param admin The name of the admin component to check, or {@code null} if the caller is a
4833 * package access delegate.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004834 * @param packageNames The package names to suspend or unsuspend.
4835 * @param suspended If set to {@code true} than the packages will be suspended, if set to
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004836 * {@code false} the packages will be unsuspended.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004837 * @return an array of package names for which the suspended status is not set as requested in
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004838 * this method.
4839 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01004840 * @see #setDelegatedScopes
4841 * @see #DELEGATION_PACKAGE_ACCESS
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004842 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004843 public @NonNull String[] setPackagesSuspended(@NonNull ComponentName admin,
4844 @NonNull String[] packageNames, boolean suspended) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004845 throwIfParentInstance("setPackagesSuspended");
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004846 if (mService != null) {
4847 try {
Edman Anjos52088e42017-01-13 22:26:17 +01004848 return mService.setPackagesSuspended(admin, mContext.getPackageName(), packageNames,
4849 suspended);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004850 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004851 throw re.rethrowFromSystemServer();
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004852 }
4853 }
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004854 return packageNames;
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004855 }
4856
4857 /**
Edman Anjos52088e42017-01-13 22:26:17 +01004858 * Determine if a package is suspended. This function can be called by a device owner, profile
4859 * owner, or by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via
4860 * {@link #setDelegatedScopes}.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004861 *
Edman Anjos52088e42017-01-13 22:26:17 +01004862 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
4863 * {@code null} if the caller is a package access delegate.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004864 * @param packageName The name of the package to retrieve the suspended status of.
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00004865 * @return {@code true} if the package is suspended or {@code false} if the package is not
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004866 * suspended, could not be found or an error occurred.
4867 * @throws SecurityException if {@code admin} is not a device or profile owner.
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004868 * @throws NameNotFoundException if the package could not be found.
Edman Anjos52088e42017-01-13 22:26:17 +01004869 * @see #setDelegatedScopes
4870 * @see #DELEGATION_PACKAGE_ACCESS
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004871 */
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004872 public boolean isPackageSuspended(@NonNull ComponentName admin, String packageName)
4873 throws NameNotFoundException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004874 throwIfParentInstance("isPackageSuspended");
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004875 if (mService != null) {
4876 try {
Edman Anjos52088e42017-01-13 22:26:17 +01004877 return mService.isPackageSuspended(admin, mContext.getPackageName(), packageName);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004878 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004879 throw e.rethrowFromSystemServer();
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004880 } catch (IllegalArgumentException ex) {
4881 throw new NameNotFoundException(packageName);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004882 }
4883 }
4884 return false;
4885 }
4886
4887 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004888 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
4889 * be used. Only the profile owner can call this.
4890 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01004891 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004892 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004893 * @throws SecurityException if {@code admin} is not a profile owner.
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004894 */
Robin Lee25e26452015-06-02 09:56:29 -07004895 public void setProfileEnabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004896 throwIfParentInstance("setProfileEnabled");
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004897 if (mService != null) {
4898 try {
4899 mService.setProfileEnabled(admin);
4900 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004901 throw e.rethrowFromSystemServer();
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004902 }
4903 }
4904 }
4905
4906 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004907 * Sets the name of the profile. In the device owner case it sets the name of the user which it
4908 * is called from. Only a profile owner or device owner can call this. If this is never called
4909 * by the profile or device owner, the name will be set to default values.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004910 *
4911 * @see #isProfileOwnerApp
4912 * @see #isDeviceOwnerApp
Robin Lee25e26452015-06-02 09:56:29 -07004913 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004914 * @param profileName The name of the profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004915 * @throws SecurityException if {@code admin} is not a device or profile owner.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004916 */
Robin Lee25e26452015-06-02 09:56:29 -07004917 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004918 throwIfParentInstance("setProfileName");
Jessica Hummel1333ea12014-06-23 11:20:10 +01004919 if (mService != null) {
4920 try {
Robin Lee25e26452015-06-02 09:56:29 -07004921 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07004922 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004923 throw e.rethrowFromSystemServer();
Fyodor Kupolov78f13142015-05-27 16:52:45 -07004924 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01004925 }
4926 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01004927
4928 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004929 * Used to determine if a particular package is registered as the profile owner for the
Makoto Onuki32b30572015-12-11 14:29:51 -08004930 * user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004931 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00004932 *
4933 * @param packageName The package name of the app to compare with the registered profile owner.
4934 * @return Whether or not the package is registered as the profile owner.
4935 */
4936 public boolean isProfileOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004937 throwIfParentInstance("isProfileOwnerApp");
Adam Connors776c5552014-01-09 10:42:56 +00004938 if (mService != null) {
4939 try {
Makoto Onuki90b89652016-01-28 14:44:18 -08004940 ComponentName profileOwner = mService.getProfileOwner(myUserId());
Nicolas Prevot90af6d72014-07-30 14:19:12 +01004941 return profileOwner != null
4942 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00004943 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004944 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004945 }
4946 }
4947 return false;
4948 }
4949
4950 /**
4951 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07004952 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00004953 * owner has been set for that user.
4954 * @throws IllegalArgumentException if the userId is invalid.
4955 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01004956 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004957 public @Nullable ComponentName getProfileOwner() throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004958 throwIfParentInstance("getProfileOwner");
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01004959 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
4960 }
4961
4962 /**
4963 * @see #getProfileOwner()
4964 * @hide
4965 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004966 public @Nullable ComponentName getProfileOwnerAsUser(final int userId)
4967 throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00004968 if (mService != null) {
4969 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01004970 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00004971 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004972 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004973 }
4974 }
4975 return null;
4976 }
4977
4978 /**
4979 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07004980 * @return the human readable name of the organisation associated with this DPM or {@code null}
4981 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00004982 * @throws IllegalArgumentException if the userId is invalid.
4983 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004984 public @Nullable String getProfileOwnerName() throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00004985 if (mService != null) {
4986 try {
4987 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
4988 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004989 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004990 }
4991 }
4992 return null;
4993 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004994
4995 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07004996 * @hide
Makoto Onukic8a5a552015-11-19 14:29:12 -08004997 * @param userId The user for whom to fetch the profile owner name, if any.
Amith Yamasani38f836b2014-08-20 14:51:15 -07004998 * @return the human readable name of the organisation associated with this profile owner or
4999 * null if one is not set.
5000 * @throws IllegalArgumentException if the userId is invalid.
5001 */
5002 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07005003 public @Nullable String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005004 throwIfParentInstance("getProfileOwnerNameAsUser");
Amith Yamasani38f836b2014-08-20 14:51:15 -07005005 if (mService != null) {
5006 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02005007 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07005008 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005009 throw re.rethrowFromSystemServer();
Amith Yamasani38f836b2014-08-20 14:51:15 -07005010 }
5011 }
5012 return null;
5013 }
5014
5015 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005016 * Called by a profile owner or device owner to add a default intent handler activity for
5017 * intents that match a certain intent filter. This activity will remain the default intent
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005018 * handler even if the set of potential event handlers for the intent filter changes and if the
5019 * intent preferences are reset.
5020 * <p>
5021 * The default disambiguation mechanism takes over if the activity is not installed (anymore).
5022 * When the activity is (re)installed, it is automatically reset as default intent handler for
5023 * the filter.
5024 * <p>
5025 * The calling device admin must be a profile owner or device owner. If it is not, a security
5026 * exception will be thrown.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005027 *
5028 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5029 * @param filter The IntentFilter for which a default handler is added.
5030 * @param activity The Activity that is added as default intent handler.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005031 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005032 */
Robin Lee25e26452015-06-02 09:56:29 -07005033 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
5034 @NonNull ComponentName activity) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005035 throwIfParentInstance("addPersistentPreferredActivity");
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005036 if (mService != null) {
5037 try {
5038 mService.addPersistentPreferredActivity(admin, filter, activity);
5039 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005040 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005041 }
5042 }
5043 }
5044
5045 /**
5046 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00005047 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005048 * <p>
5049 * The calling device admin must be a profile owner. If it is not, a security exception will be
5050 * thrown.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005051 *
5052 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5053 * @param packageName The name of the package for which preferences are removed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005054 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005055 */
Robin Lee25e26452015-06-02 09:56:29 -07005056 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005057 String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005058 throwIfParentInstance("clearPackagePersistentPreferredActivities");
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005059 if (mService != null) {
5060 try {
5061 mService.clearPackagePersistentPreferredActivities(admin, packageName);
5062 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005063 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005064 }
5065 }
5066 }
Robin Lee66e5d962014-04-09 16:44:21 +01005067
5068 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00005069 * Called by a profile owner or device owner to grant permission to a package to manage
5070 * application restrictions for the calling user via {@link #setApplicationRestrictions} and
5071 * {@link #getApplicationRestrictions}.
5072 * <p>
5073 * This permission is persistent until it is later cleared by calling this method with a
5074 * {@code null} value or uninstalling the managing package.
Rubin Xuf03d0a62016-02-10 14:54:15 +00005075 * <p>
5076 * The supplied application restriction managing package must be installed when calling this
Victor Changcd14c0a2016-03-16 19:10:15 +00005077 * API, otherwise an {@link NameNotFoundException} will be thrown.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005078 *
5079 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5080 * @param packageName The package name which will be given access to application restrictions
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005081 * APIs. If {@code null} is given the current package will be cleared.
5082 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Changcd14c0a2016-03-16 19:10:15 +00005083 * @throws NameNotFoundException if {@code packageName} is not found
Edman Anjosf9946772016-11-28 16:35:15 +01005084 *
5085 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #setDelegatedScopes}
5086 * with the {@link #DELEGATION_APP_RESTRICTIONS} scope instead.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005087 */
Edman Anjosf9946772016-11-28 16:35:15 +01005088 @Deprecated
Esteban Talaverabf60f722015-12-10 16:26:44 +00005089 public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin,
Victor Changcd14c0a2016-03-16 19:10:15 +00005090 @Nullable String packageName) throws NameNotFoundException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005091 throwIfParentInstance("setApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00005092 if (mService != null) {
5093 try {
Victor Changcd14c0a2016-03-16 19:10:15 +00005094 if (!mService.setApplicationRestrictionsManagingPackage(admin, packageName)) {
5095 throw new NameNotFoundException(packageName);
5096 }
Esteban Talaverabf60f722015-12-10 16:26:44 +00005097 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005098 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00005099 }
5100 }
5101 }
5102
5103 /**
5104 * Called by a profile owner or device owner to retrieve the application restrictions managing
Edman Anjosf9946772016-11-28 16:35:15 +01005105 * package for the current user, or {@code null} if none is set. If there are multiple
5106 * delegates this function will return one of them.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005107 *
5108 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5109 * @return The package name allowed to manage application restrictions on the current user, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005110 * {@code null} if none is set.
5111 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01005112 *
5113 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatePackages}
5114 * with the {@link #DELEGATION_APP_RESTRICTIONS} scope instead.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005115 */
Edman Anjosf9946772016-11-28 16:35:15 +01005116 @Deprecated
5117 @Nullable
5118 public String getApplicationRestrictionsManagingPackage(
Makoto Onuki408e8e42016-10-25 12:10:27 -07005119 @NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005120 throwIfParentInstance("getApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00005121 if (mService != null) {
5122 try {
5123 return mService.getApplicationRestrictionsManagingPackage(admin);
5124 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005125 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00005126 }
5127 }
5128 return null;
5129 }
5130
5131 /**
Esteban Talavera96895ca2016-03-16 12:00:40 +00005132 * Called by any application to find out whether it has been granted permission via
5133 * {@link #setApplicationRestrictionsManagingPackage} to manage application restrictions
5134 * for the calling user.
5135 *
5136 * <p>This is done by comparing the calling Linux uid with the uid of the package specified by
5137 * that method.
Edman Anjosf9946772016-11-28 16:35:15 +01005138 *
5139 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatedScopes}
5140 * instead.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005141 */
Edman Anjosf9946772016-11-28 16:35:15 +01005142 @Deprecated
Esteban Talaverabf60f722015-12-10 16:26:44 +00005143 public boolean isCallerApplicationRestrictionsManagingPackage() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005144 throwIfParentInstance("isCallerApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00005145 if (mService != null) {
5146 try {
Edman Anjosf9946772016-11-28 16:35:15 +01005147 return mService.isCallerApplicationRestrictionsManagingPackage(
5148 mContext.getPackageName());
Esteban Talaverabf60f722015-12-10 16:26:44 +00005149 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005150 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00005151 }
5152 }
5153 return false;
5154 }
5155
5156 /**
5157 * Sets the application restrictions for a given target application running in the calling user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005158 * <p>
5159 * 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 +01005160 * application restrictions via {@link #setDelegatedScopes} with the
5161 * {@link #DELEGATION_APP_RESTRICTIONS} scope; otherwise a security exception will be thrown.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005162 * <p>
5163 * The provided {@link Bundle} consists of key-value pairs, where the types of values may be:
Esteban Talavera6b8e0642015-08-10 17:26:04 +01005164 * <ul>
5165 * <li>{@code boolean}
5166 * <li>{@code int}
5167 * <li>{@code String} or {@code String[]}
5168 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
5169 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005170 * <p>
5171 * If the restrictions are not available yet, but may be applied in the near future, the caller
5172 * can notify the target application of that by adding
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00005173 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005174 * <p>
5175 * The application restrictions are only made visible to the target application via
5176 * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or device
5177 * owner, and the application restrictions managing package via
Esteban Talaverabf60f722015-12-10 16:26:44 +00005178 * {@link #getApplicationRestrictions}.
Robin Lee66e5d962014-04-09 16:44:21 +01005179 *
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005180 * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
5181 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00005182 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005183 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01005184 * @param packageName The name of the package to update restricted settings for.
5185 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005186 * set of active restrictions.
5187 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01005188 * @see #setDelegatedScopes
5189 * @see #DELEGATION_APP_RESTRICTIONS
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00005190 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01005191 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005192 @WorkerThread
Esteban Talaverabf60f722015-12-10 16:26:44 +00005193 public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01005194 Bundle settings) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005195 throwIfParentInstance("setApplicationRestrictions");
Robin Lee66e5d962014-04-09 16:44:21 +01005196 if (mService != null) {
5197 try {
Edman Anjosf9946772016-11-28 16:35:15 +01005198 mService.setApplicationRestrictions(admin, mContext.getPackageName(), packageName,
5199 settings);
Robin Lee66e5d962014-04-09 16:44:21 +01005200 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005201 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01005202 }
5203 }
5204 }
5205
5206 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005207 * Sets a list of configuration features to enable for a TrustAgent component. This is meant to
5208 * be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all trust
5209 * agents but those enabled by this function call. If flag
Jim Millere303bf42014-08-26 17:12:29 -07005210 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005211 * <p>
5212 * The calling device admin must have requested
5213 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method;
5214 * if not, a security exception will be thrown.
Tony Mak089d8402016-04-05 17:42:55 +01005215 * <p>
5216 * This method can be called on the {@link DevicePolicyManager} instance returned by
5217 * {@link #getParentProfileInstance(ComponentName)} in order to set the configuration for
5218 * the parent profile.
Jim Miller604e7552014-07-18 19:00:02 -07005219 *
5220 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07005221 * @param target Component name of the agent to be enabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005222 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent will be
5223 * strictly disabled according to the state of the
5224 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
5225 * <p>
5226 * If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all
5227 * admins, then it's up to the TrustAgent itself to aggregate the values from all
5228 * device admins.
5229 * <p>
5230 * Consult documentation for the specific TrustAgent to determine legal options
5231 * parameters.
5232 * @throws SecurityException if {@code admin} is not an active administrator or does not use
5233 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES}
Jim Miller604e7552014-07-18 19:00:02 -07005234 */
Robin Lee25e26452015-06-02 09:56:29 -07005235 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
5236 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07005237 if (mService != null) {
5238 try {
Tony Mak089d8402016-04-05 17:42:55 +01005239 mService.setTrustAgentConfiguration(admin, target, configuration, mParentInstance);
Jim Miller604e7552014-07-18 19:00:02 -07005240 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005241 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07005242 }
5243 }
5244 }
5245
5246 /**
Jim Millere303bf42014-08-26 17:12:29 -07005247 * Gets configuration for the given trust agent based on aggregating all calls to
5248 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
5249 * all device admins.
Tony Mak089d8402016-04-05 17:42:55 +01005250 * <p>
5251 * This method can be called on the {@link DevicePolicyManager} instance returned by
5252 * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the configuration set
5253 * on the parent profile.
Jim Miller604e7552014-07-18 19:00:02 -07005254 *
Jim Millerb5db57a2015-01-14 18:17:19 -08005255 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
5256 * this function returns a list of configurations for all admins that declare
5257 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
5258 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
5259 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
5260 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07005261 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07005262 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07005263 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005264 public @Nullable List<PersistableBundle> getTrustAgentConfiguration(
5265 @Nullable ComponentName admin, @NonNull ComponentName agent) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07005266 return getTrustAgentConfiguration(admin, agent, myUserId());
Jim Millere303bf42014-08-26 17:12:29 -07005267 }
5268
5269 /** @hide per-user version */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005270 public @Nullable List<PersistableBundle> getTrustAgentConfiguration(
5271 @Nullable ComponentName admin, @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07005272 if (mService != null) {
5273 try {
Tony Mak089d8402016-04-05 17:42:55 +01005274 return mService.getTrustAgentConfiguration(admin, agent, userHandle,
5275 mParentInstance);
Jim Miller604e7552014-07-18 19:00:02 -07005276 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005277 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07005278 }
5279 }
Jim Millere303bf42014-08-26 17:12:29 -07005280 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07005281 }
5282
5283 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005284 * Called by a profile owner of a managed profile to set whether caller-Id information from the
5285 * managed profile will be shown in the parent profile, for incoming calls.
5286 * <p>
5287 * The calling device admin must be a profile owner. If it is not, a security exception will be
5288 * thrown.
Adam Connors210fe212014-07-17 15:41:43 +01005289 *
Robin Lee25e26452015-06-02 09:56:29 -07005290 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01005291 * @param disabled If true caller-Id information in the managed profile is not displayed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005292 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors210fe212014-07-17 15:41:43 +01005293 */
Robin Lee25e26452015-06-02 09:56:29 -07005294 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005295 throwIfParentInstance("setCrossProfileCallerIdDisabled");
Adam Connors210fe212014-07-17 15:41:43 +01005296 if (mService != null) {
5297 try {
Robin Lee25e26452015-06-02 09:56:29 -07005298 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01005299 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005300 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01005301 }
5302 }
5303 }
5304
5305 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005306 * Called by a profile owner of a managed profile to determine whether or not caller-Id
5307 * information has been disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005308 * <p>
5309 * The calling device admin must be a profile owner. If it is not, a security exception will be
5310 * thrown.
Adam Connors210fe212014-07-17 15:41:43 +01005311 *
Robin Lee25e26452015-06-02 09:56:29 -07005312 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005313 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors210fe212014-07-17 15:41:43 +01005314 */
Robin Lee25e26452015-06-02 09:56:29 -07005315 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005316 throwIfParentInstance("getCrossProfileCallerIdDisabled");
Adam Connors210fe212014-07-17 15:41:43 +01005317 if (mService != null) {
5318 try {
Robin Lee25e26452015-06-02 09:56:29 -07005319 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01005320 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005321 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01005322 }
5323 }
5324 return false;
5325 }
5326
5327 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07005328 * Determine whether or not caller-Id information has been disabled.
5329 *
5330 * @param userHandle The user for whom to check the caller-id permission
5331 * @hide
5332 */
5333 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
5334 if (mService != null) {
5335 try {
5336 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
5337 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005338 throw e.rethrowFromSystemServer();
Amith Yamasani570002f2014-07-18 15:48:54 -07005339 }
5340 }
5341 return false;
5342 }
5343
5344 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005345 * Called by a profile owner of a managed profile to set whether contacts search from the
5346 * managed profile will be shown in the parent profile, for incoming calls.
5347 * <p>
5348 * The calling device admin must be a profile owner. If it is not, a security exception will be
5349 * thrown.
Victor Chang1060c6182016-01-04 20:16:23 +00005350 *
5351 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5352 * @param disabled If true contacts search in the managed profile is not displayed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005353 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Chang1060c6182016-01-04 20:16:23 +00005354 */
5355 public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin,
5356 boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005357 throwIfParentInstance("setCrossProfileContactsSearchDisabled");
Victor Chang1060c6182016-01-04 20:16:23 +00005358 if (mService != null) {
5359 try {
5360 mService.setCrossProfileContactsSearchDisabled(admin, disabled);
5361 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005362 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00005363 }
5364 }
5365 }
5366
5367 /**
5368 * Called by a profile owner of a managed profile to determine whether or not contacts search
5369 * has been disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005370 * <p>
5371 * The calling device admin must be a profile owner. If it is not, a security exception will be
5372 * thrown.
Victor Chang1060c6182016-01-04 20:16:23 +00005373 *
5374 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005375 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Chang1060c6182016-01-04 20:16:23 +00005376 */
5377 public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005378 throwIfParentInstance("getCrossProfileContactsSearchDisabled");
Victor Chang1060c6182016-01-04 20:16:23 +00005379 if (mService != null) {
5380 try {
5381 return mService.getCrossProfileContactsSearchDisabled(admin);
5382 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005383 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00005384 }
5385 }
5386 return false;
5387 }
5388
5389
5390 /**
5391 * Determine whether or not contacts search has been disabled.
5392 *
5393 * @param userHandle The user for whom to check the contacts search permission
5394 * @hide
5395 */
5396 public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) {
5397 if (mService != null) {
5398 try {
5399 return mService
5400 .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier());
5401 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005402 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00005403 }
5404 }
5405 return false;
5406 }
5407
5408 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005409 * Start Quick Contact on the managed profile for the user, if the policy allows.
Victor Chang97bdacc2016-01-21 22:24:11 +00005410 *
Makoto Onuki1040da12015-03-19 11:24:00 -07005411 * @hide
5412 */
5413 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
Victor Chang97bdacc2016-01-21 22:24:11 +00005414 boolean isContactIdIgnored, long directoryId, Intent originalIntent) {
Makoto Onuki1040da12015-03-19 11:24:00 -07005415 if (mService != null) {
5416 try {
Victor Chang97bdacc2016-01-21 22:24:11 +00005417 mService.startManagedQuickContact(actualLookupKey, actualContactId,
5418 isContactIdIgnored, directoryId, originalIntent);
Makoto Onuki1040da12015-03-19 11:24:00 -07005419 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005420 throw e.rethrowFromSystemServer();
Makoto Onuki1040da12015-03-19 11:24:00 -07005421 }
5422 }
5423 }
5424
5425 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005426 * Start Quick Contact on the managed profile for the user, if the policy allows.
Ricky Wai494b95d2015-11-20 16:07:15 +00005427 * @hide
5428 */
5429 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
5430 Intent originalIntent) {
Victor Chang97bdacc2016-01-21 22:24:11 +00005431 startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT,
Ricky Wai494b95d2015-11-20 16:07:15 +00005432 originalIntent);
5433 }
5434
5435 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005436 * Called by a profile owner of a managed profile to set whether bluetooth devices can access
5437 * enterprise contacts.
Ricky Wai778ba132015-03-31 14:21:22 +01005438 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005439 * The calling device admin must be a profile owner. If it is not, a security exception will be
5440 * thrown.
Ricky Wai778ba132015-03-31 14:21:22 +01005441 * <p>
5442 * This API works on managed profile only.
5443 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005444 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5445 * @param disabled If true, bluetooth devices cannot access enterprise contacts.
5446 * @throws SecurityException if {@code admin} is not a device or profile owner.
Ricky Wai778ba132015-03-31 14:21:22 +01005447 */
Robin Lee25e26452015-06-02 09:56:29 -07005448 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005449 throwIfParentInstance("setBluetoothContactSharingDisabled");
Ricky Wai778ba132015-03-31 14:21:22 +01005450 if (mService != null) {
5451 try {
Robin Lee25e26452015-06-02 09:56:29 -07005452 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01005453 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005454 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01005455 }
5456 }
5457 }
5458
5459 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005460 * Called by a profile owner of a managed profile to determine whether or not Bluetooth devices
5461 * cannot access enterprise contacts.
Ricky Wai778ba132015-03-31 14:21:22 +01005462 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005463 * The calling device admin must be a profile owner. If it is not, a security exception will be
5464 * thrown.
Ricky Wai778ba132015-03-31 14:21:22 +01005465 * <p>
5466 * This API works on managed profile only.
5467 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005468 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5469 * @throws SecurityException if {@code admin} is not a device or profile owner.
Ricky Wai778ba132015-03-31 14:21:22 +01005470 */
Robin Lee25e26452015-06-02 09:56:29 -07005471 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005472 throwIfParentInstance("getBluetoothContactSharingDisabled");
Ricky Wai778ba132015-03-31 14:21:22 +01005473 if (mService != null) {
5474 try {
Robin Lee25e26452015-06-02 09:56:29 -07005475 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01005476 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005477 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01005478 }
5479 }
5480 return true;
5481 }
5482
5483 /**
5484 * Determine whether or not Bluetooth devices cannot access contacts.
5485 * <p>
5486 * This API works on managed profile UserHandle only.
5487 *
5488 * @param userHandle The user for whom to check the caller-id permission
5489 * @hide
5490 */
5491 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
5492 if (mService != null) {
5493 try {
5494 return mService.getBluetoothContactSharingDisabledForUser(userHandle
5495 .getIdentifier());
5496 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005497 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01005498 }
5499 }
5500 return true;
5501 }
5502
5503 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005504 * Called by the profile owner of a managed profile so that some intents sent in the managed
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005505 * profile can also be resolved in the parent, or vice versa. Only activity intents are
5506 * supported.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00005507 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005508 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01005509 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005510 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01005511 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005512 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
5513 * @throws SecurityException if {@code admin} is not a device or profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005514 */
Robin Lee25e26452015-06-02 09:56:29 -07005515 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005516 throwIfParentInstance("addCrossProfileIntentFilter");
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005517 if (mService != null) {
5518 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01005519 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005520 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005521 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005522 }
5523 }
5524 }
5525
5526 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005527 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
5528 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01005529 * Only removes those that have been set by the profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005530 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005531 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005532 * @throws SecurityException if {@code admin} is not a device or profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005533 */
Robin Lee25e26452015-06-02 09:56:29 -07005534 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005535 throwIfParentInstance("clearCrossProfileIntentFilters");
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005536 if (mService != null) {
5537 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01005538 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005539 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005540 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005541 }
5542 }
5543 }
5544
5545 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005546 * Called by a profile or device owner to set the permitted accessibility services. When set by
5547 * a device owner or profile owner the restriction applies to all profiles of the user the
5548 * device owner or profile owner is an admin for. By default the user can use any accessiblity
5549 * service. When zero or more packages have been added, accessiblity services that are not in
5550 * the list and not part of the system can not be enabled by the user.
5551 * <p>
5552 * Calling with a null value for the list disables the restriction so that all services can be
5553 * used, calling with an empty list only allows the builtin system's services.
5554 * <p>
5555 * System accesibility services are always available to the user the list can't modify this.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005556 *
5557 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5558 * @param packageNames List of accessibility service package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005559 * @return true if setting the restriction succeeded. It fail if there is one or more non-system
5560 * accessibility services enabled, that are not in the list.
5561 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005562 */
Robin Lee25e26452015-06-02 09:56:29 -07005563 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005564 List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005565 throwIfParentInstance("setPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005566 if (mService != null) {
5567 try {
5568 return mService.setPermittedAccessibilityServices(admin, packageNames);
5569 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005570 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005571 }
5572 }
5573 return false;
5574 }
5575
5576 /**
5577 * Returns the list of permitted accessibility services set by this device or profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005578 * <p>
5579 * An empty list means no accessibility services except system services are allowed. Null means
5580 * all accessibility services are allowed.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005581 *
5582 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5583 * @return List of accessiblity service package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005584 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005585 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005586 public @Nullable List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005587 throwIfParentInstance("getPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005588 if (mService != null) {
5589 try {
5590 return mService.getPermittedAccessibilityServices(admin);
5591 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005592 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005593 }
5594 }
5595 return null;
5596 }
5597
5598 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00005599 * Called by the system to check if a specific accessibility service is disabled by admin.
5600 *
5601 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5602 * @param packageName Accessibility service package name that needs to be checked.
5603 * @param userHandle user id the admin is running as.
5604 * @return true if the accessibility service is permitted, otherwise false.
5605 *
5606 * @hide
5607 */
5608 public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin,
5609 @NonNull String packageName, int userHandle) {
5610 if (mService != null) {
5611 try {
5612 return mService.isAccessibilityServicePermittedByAdmin(admin, packageName,
5613 userHandle);
5614 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005615 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00005616 }
5617 }
5618 return false;
5619 }
5620
5621 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005622 * Returns the list of accessibility services permitted by the device or profiles
5623 * owners of this user.
5624 *
5625 * <p>Null means all accessibility services are allowed, if a non-null list is returned
5626 * it will contain the intersection of the permitted lists for any device or profile
5627 * owners that apply to this user. It will also include any system accessibility services.
5628 *
5629 * @param userId which user to check for.
5630 * @return List of accessiblity service package names.
5631 * @hide
5632 */
5633 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07005634 public @Nullable List<String> getPermittedAccessibilityServices(int userId) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005635 throwIfParentInstance("getPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005636 if (mService != null) {
5637 try {
5638 return mService.getPermittedAccessibilityServicesForUser(userId);
5639 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005640 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005641 }
5642 }
5643 return null;
5644 }
5645
5646 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005647 * Called by a profile or device owner to set the permitted input methods services. When set by
5648 * a device owner or profile owner the restriction applies to all profiles of the user the
5649 * device owner or profile owner is an admin for. By default the user can use any input method.
5650 * When zero or more packages have been added, input method that are not in the list and not
5651 * part of the system can not be enabled by the user. This method will fail if it is called for
5652 * a admin that is not for the foreground user or a profile of the foreground user.
5653 * <p>
5654 * Calling with a null value for the list disables the restriction so that all input methods can
5655 * be used, calling with an empty list disables all but the system's own input methods.
5656 * <p>
5657 * System input methods are always available to the user this method can't modify this.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005658 *
5659 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5660 * @param packageNames List of input method package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005661 * @return true if setting the restriction succeeded. It will fail if there are one or more
5662 * non-system input methods currently enabled that are not in the packageNames list.
5663 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005664 */
Robin Lee25e26452015-06-02 09:56:29 -07005665 public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005666 throwIfParentInstance("setPermittedInputMethods");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005667 if (mService != null) {
5668 try {
5669 return mService.setPermittedInputMethods(admin, packageNames);
5670 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005671 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005672 }
5673 }
5674 return false;
5675 }
5676
5677
5678 /**
5679 * Returns the list of permitted input methods set by this device or profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005680 * <p>
5681 * An empty list means no input methods except system input methods are allowed. Null means all
5682 * input methods are allowed.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005683 *
5684 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5685 * @return List of input method package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005686 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005687 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005688 public @Nullable List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005689 throwIfParentInstance("getPermittedInputMethods");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005690 if (mService != null) {
5691 try {
5692 return mService.getPermittedInputMethods(admin);
5693 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005694 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005695 }
5696 }
5697 return null;
5698 }
5699
5700 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00005701 * Called by the system to check if a specific input method is disabled by admin.
5702 *
5703 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5704 * @param packageName Input method package name that needs to be checked.
5705 * @param userHandle user id the admin is running as.
5706 * @return true if the input method is permitted, otherwise false.
5707 *
5708 * @hide
5709 */
5710 public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin,
5711 @NonNull String packageName, int userHandle) {
5712 if (mService != null) {
5713 try {
5714 return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle);
5715 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005716 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00005717 }
5718 }
5719 return false;
5720 }
5721
5722 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005723 * Returns the list of input methods permitted by the device or profiles
Makoto Onuki32b30572015-12-11 14:29:51 -08005724 * owners of the current user. (*Not* calling user, due to a limitation in InputMethodManager.)
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005725 *
5726 * <p>Null means all input methods are allowed, if a non-null list is returned
5727 * it will contain the intersection of the permitted lists for any device or profile
5728 * owners that apply to this user. It will also include any system input methods.
5729 *
5730 * @return List of input method package names.
5731 * @hide
5732 */
5733 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07005734 public @Nullable List<String> getPermittedInputMethodsForCurrentUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005735 throwIfParentInstance("getPermittedInputMethodsForCurrentUser");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005736 if (mService != null) {
5737 try {
5738 return mService.getPermittedInputMethodsForCurrentUser();
5739 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005740 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005741 }
5742 }
5743 return null;
5744 }
5745
5746 /**
Edman Anjos52088e42017-01-13 22:26:17 +01005747 * Get the list of apps to keep around as APKs even if no user has currently installed it. This
5748 * function can be called by a device owner or by a delegate given the
5749 * {@link #DELEGATION_KEEP_UNINSTALLED_PACKAGES} scope via {@link #setDelegatedScopes}.
5750 * <p>
5751 * Please note that packages returned in this method are not automatically pre-cached.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005752 *
Edman Anjos52088e42017-01-13 22:26:17 +01005753 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
5754 * {@code null} if the caller is a keep uninstalled packages delegate.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005755 * @return List of package names to keep cached.
Edman Anjos52088e42017-01-13 22:26:17 +01005756 * @see #setDelegatedScopes
5757 * @see #DELEGATION_KEEP_UNINSTALLED_PACKAGES
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005758 * @hide
5759 */
Edman Anjos52088e42017-01-13 22:26:17 +01005760 public @Nullable List<String> getKeepUninstalledPackages(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005761 throwIfParentInstance("getKeepUninstalledPackages");
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005762 if (mService != null) {
5763 try {
Edman Anjos52088e42017-01-13 22:26:17 +01005764 return mService.getKeepUninstalledPackages(admin, mContext.getPackageName());
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005765 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005766 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005767 }
5768 }
5769 return null;
5770 }
5771
5772 /**
Edman Anjos52088e42017-01-13 22:26:17 +01005773 * Set a list of apps to keep around as APKs even if no user has currently installed it. This
5774 * function can be called by a device owner or by a delegate given the
5775 * {@link #DELEGATION_KEEP_UNINSTALLED_PACKAGES} scope via {@link #setDelegatedScopes}.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005776 *
5777 * <p>Please note that setting this policy does not imply that specified apps will be
5778 * automatically pre-cached.</p>
5779 *
Edman Anjos52088e42017-01-13 22:26:17 +01005780 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
5781 * {@code null} if the caller is a keep uninstalled packages delegate.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005782 * @param packageNames List of package names to keep cached.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005783 * @throws SecurityException if {@code admin} is not a device owner.
Edman Anjos52088e42017-01-13 22:26:17 +01005784 * @see #setDelegatedScopes
5785 * @see #DELEGATION_KEEP_UNINSTALLED_PACKAGES
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005786 * @hide
5787 */
Edman Anjos52088e42017-01-13 22:26:17 +01005788 public void setKeepUninstalledPackages(@Nullable ComponentName admin,
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005789 @NonNull List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005790 throwIfParentInstance("setKeepUninstalledPackages");
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005791 if (mService != null) {
5792 try {
Edman Anjos52088e42017-01-13 22:26:17 +01005793 mService.setKeepUninstalledPackages(admin, mContext.getPackageName(), packageNames);
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005794 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005795 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005796 }
5797 }
5798 }
5799
5800 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04005801 * Called by a device owner to create a user with the specified name. The UserHandle returned
5802 * by this method should not be persisted as user handles are recycled as users are removed and
5803 * created. If you need to persist an identifier for this user, use
5804 * {@link UserManager#getSerialNumberForUser}.
5805 *
5806 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5807 * @param name the user's name
5808 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07005809 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
5810 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01005811 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005812 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01005813 * @removed From {@link android.os.Build.VERSION_CODES#N}
Julia Reynolds1e958392014-05-16 14:25:21 -04005814 */
Kenny Guy14f48e52015-06-29 15:12:36 +01005815 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07005816 public @Nullable UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04005817 return null;
5818 }
5819
5820 /**
Jason Monk03978a42014-06-10 15:05:30 -04005821 * Called by a device owner to create a user with the specified name. The UserHandle returned
5822 * by this method should not be persisted as user handles are recycled as users are removed and
5823 * created. If you need to persist an identifier for this user, use
5824 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
5825 * immediately.
5826 *
5827 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
5828 * as registered as an active admin on the new user. The profile owner package will be
5829 * installed on the new user if it already is installed on the device.
5830 *
5831 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
5832 * profileOwnerComponent when onEnable is called.
5833 *
5834 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5835 * @param name the user's name
5836 * @param ownerName the human readable name of the organisation associated with this DPM.
5837 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
5838 * the user.
5839 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
5840 * on the new user.
5841 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07005842 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
5843 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01005844 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005845 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01005846 * @removed From {@link android.os.Build.VERSION_CODES#N}
Jason Monk03978a42014-06-10 15:05:30 -04005847 */
Kenny Guy14f48e52015-06-29 15:12:36 +01005848 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07005849 public @Nullable UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
Robin Lee25e26452015-06-02 09:56:29 -07005850 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04005851 return null;
5852 }
5853
5854 /**
phweissa92e1212016-01-25 17:14:10 +01005855 * Flag used by {@link #createAndManageUser} to skip setup wizard after creating a new user.
phweiss343fb332016-01-25 14:48:59 +01005856 */
5857 public static final int SKIP_SETUP_WIZARD = 0x0001;
5858
5859 /**
Lenka Trochtovac8202c82016-01-26 15:11:09 +01005860 * Flag used by {@link #createAndManageUser} to specify that the user should be created
5861 * ephemeral.
5862 * @hide
5863 */
5864 public static final int MAKE_USER_EPHEMERAL = 0x0002;
5865
5866 /**
phweissa92e1212016-01-25 17:14:10 +01005867 * Called by a device owner to create a user with the specified name and a given component of
5868 * the calling package as profile owner. The UserHandle returned by this method should not be
5869 * persisted as user handles are recycled as users are removed and created. If you need to
5870 * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new
5871 * user will not be started in the background.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005872 * <p>
5873 * admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also a
5874 * DeviceAdminReceiver in the same package as admin, and will become the profile owner and will
5875 * be registered as an active admin on the new user. The profile owner package will be installed
5876 * on the new user.
5877 * <p>
5878 * If the adminExtras are not null, they will be stored on the device until the user is started
5879 * for the first time. Then the extras will be passed to the admin when onEnable is called.
phweiss343fb332016-01-25 14:48:59 +01005880 *
5881 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5882 * @param name The user's name.
phweissa92e1212016-01-25 17:14:10 +01005883 * @param profileOwner Which {@link DeviceAdminReceiver} will be profile owner. Has to be in the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005884 * same package as admin, otherwise no user is created and an
5885 * IllegalArgumentException is thrown.
phweiss343fb332016-01-25 14:48:59 +01005886 * @param adminExtras Extras that will be passed to onEnable of the admin receiver on the new
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005887 * user.
phweissa92e1212016-01-25 17:14:10 +01005888 * @param flags {@link #SKIP_SETUP_WIZARD} is supported.
phweiss343fb332016-01-25 14:48:59 +01005889 * @see UserHandle
5890 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
5891 * user could not be created.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005892 * @throws SecurityException if {@code admin} is not a device owner.
phweiss343fb332016-01-25 14:48:59 +01005893 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005894 public @Nullable UserHandle createAndManageUser(@NonNull ComponentName admin,
5895 @NonNull String name,
phweissa92e1212016-01-25 17:14:10 +01005896 @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras,
5897 int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005898 throwIfParentInstance("createAndManageUser");
phweiss343fb332016-01-25 14:48:59 +01005899 try {
phweissa92e1212016-01-25 17:14:10 +01005900 return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags);
phweiss343fb332016-01-25 14:48:59 +01005901 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005902 throw re.rethrowFromSystemServer();
phweiss343fb332016-01-25 14:48:59 +01005903 }
phweiss343fb332016-01-25 14:48:59 +01005904 }
5905
5906 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005907 * Called by a device owner to remove a user and all associated data. The primary user can not
5908 * be removed.
Julia Reynolds1e958392014-05-16 14:25:21 -04005909 *
5910 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5911 * @param userHandle the user to remove.
5912 * @return {@code true} if the user was removed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005913 * @throws SecurityException if {@code admin} is not a device owner.
Julia Reynolds1e958392014-05-16 14:25:21 -04005914 */
Robin Lee25e26452015-06-02 09:56:29 -07005915 public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005916 throwIfParentInstance("removeUser");
Julia Reynolds1e958392014-05-16 14:25:21 -04005917 try {
5918 return mService.removeUser(admin, userHandle);
5919 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005920 throw re.rethrowFromSystemServer();
Julia Reynolds1e958392014-05-16 14:25:21 -04005921 }
5922 }
5923
5924 /**
Jason Monk582d9112014-07-09 19:57:08 -04005925 * Called by a device owner to switch the specified user to the foreground.
5926 *
5927 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5928 * @param userHandle the user to switch to; null will switch to primary.
5929 * @return {@code true} if the switch was successful, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005930 * @throws SecurityException if {@code admin} is not a device owner.
Jason Monk582d9112014-07-09 19:57:08 -04005931 * @see Intent#ACTION_USER_FOREGROUND
5932 */
Robin Lee25e26452015-06-02 09:56:29 -07005933 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005934 throwIfParentInstance("switchUser");
Jason Monk582d9112014-07-09 19:57:08 -04005935 try {
5936 return mService.switchUser(admin, userHandle);
5937 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005938 throw re.rethrowFromSystemServer();
Jason Monk582d9112014-07-09 19:57:08 -04005939 }
5940 }
5941
5942 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00005943 * Retrieves the application restrictions for a given target application running in the calling
5944 * user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005945 * <p>
5946 * 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 +01005947 * application restrictions via {@link #setDelegatedScopes} with the
5948 * {@link #DELEGATION_APP_RESTRICTIONS} scope; otherwise a security exception will be thrown.
Robin Lee66e5d962014-04-09 16:44:21 +01005949 *
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005950 * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
5951 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00005952 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005953 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01005954 * @param packageName The name of the package to fetch restricted settings of.
5955 * @return {@link Bundle} of settings corresponding to what was set last time
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005956 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty
5957 * {@link Bundle} if no restrictions have been set.
5958 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01005959 * @see #setDelegatedScopes
5960 * @see #DELEGATION_APP_RESTRICTIONS
Robin Lee66e5d962014-04-09 16:44:21 +01005961 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005962 @WorkerThread
Makoto Onuki408e8e42016-10-25 12:10:27 -07005963 public @NonNull Bundle getApplicationRestrictions(
5964 @Nullable ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005965 throwIfParentInstance("getApplicationRestrictions");
Robin Lee66e5d962014-04-09 16:44:21 +01005966 if (mService != null) {
5967 try {
Edman Anjosf9946772016-11-28 16:35:15 +01005968 return mService.getApplicationRestrictions(admin, mContext.getPackageName(),
5969 packageName);
Robin Lee66e5d962014-04-09 16:44:21 +01005970 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005971 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01005972 }
5973 }
5974 return null;
5975 }
Amith Yamasanibe465322014-04-24 13:45:17 -07005976
5977 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05005978 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07005979 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005980 * The calling device admin must be a profile or device owner; if it is not, a security
5981 * exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07005982 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005983 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5984 * @param key The key of the restriction. See the constants in {@link android.os.UserManager}
5985 * for the list of keys.
5986 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanibe465322014-04-24 13:45:17 -07005987 */
Robin Lee25e26452015-06-02 09:56:29 -07005988 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005989 throwIfParentInstance("addUserRestriction");
Amith Yamasanibe465322014-04-24 13:45:17 -07005990 if (mService != null) {
5991 try {
5992 mService.setUserRestriction(admin, key, true);
5993 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005994 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07005995 }
5996 }
5997 }
5998
5999 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05006000 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07006001 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006002 * The calling device admin must be a profile or device owner; if it is not, a security
6003 * exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07006004 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006005 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6006 * @param key The key of the restriction. See the constants in {@link android.os.UserManager}
6007 * for the list of keys.
6008 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanibe465322014-04-24 13:45:17 -07006009 */
Robin Lee25e26452015-06-02 09:56:29 -07006010 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006011 throwIfParentInstance("clearUserRestriction");
Amith Yamasanibe465322014-04-24 13:45:17 -07006012 if (mService != null) {
6013 try {
6014 mService.setUserRestriction(admin, key, false);
6015 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006016 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07006017 }
6018 }
6019 }
Adam Connors010cfd42014-04-16 12:48:13 +01006020
6021 /**
Makoto Onuki3a3092f2015-10-30 11:07:51 -07006022 * Called by a profile or device owner to get user restrictions set with
6023 * {@link #addUserRestriction(ComponentName, String)}.
6024 * <p>
6025 * The target user may have more restrictions set by the system or other device owner / profile
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006026 * owner. To get all the user restrictions currently set, use
Makoto Onuki3a3092f2015-10-30 11:07:51 -07006027 * {@link UserManager#getUserRestrictions()}.
6028 *
6029 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006030 * @throws SecurityException if {@code admin} is not a device or profile owner.
Makoto Onuki3a3092f2015-10-30 11:07:51 -07006031 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006032 public @NonNull Bundle getUserRestrictions(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006033 throwIfParentInstance("getUserRestrictions");
Makoto Onuki3a3092f2015-10-30 11:07:51 -07006034 Bundle ret = null;
6035 if (mService != null) {
6036 try {
Sudheer Shanka549b9692016-03-30 17:12:07 -07006037 ret = mService.getUserRestrictions(admin);
6038 } catch (RemoteException e) {
6039 throw e.rethrowFromSystemServer();
6040 }
6041 }
6042 return ret == null ? new Bundle() : ret;
6043 }
6044
6045 /**
phweiss73145f42017-01-17 19:06:38 +01006046 * Called by any app to display a support dialog when a feature was disabled by an admin.
6047 * This returns an intent that can be used with {@link Context#startActivity(Intent)} to
6048 * display the dialog. It will tell the user that the feature indicated by {@code restriction}
6049 * was disabled by an admin, and include a link for more information. The default content of
6050 * the dialog can be changed by the restricting admin via
6051 * {@link #setShortSupportMessage(ComponentName, CharSequence)}. If the restriction is not
6052 * set (i.e. the feature is available), then the return value will be {@code null}.
6053 * @param restriction Indicates for which feature the dialog should be displayed. Can be a
6054 * user restriction from {@link UserManager}, e.g.
6055 * {@link UserManager#DISALLOW_ADJUST_VOLUME}, or one of the constants
6056 * {@link #POLICY_DISABLE_CAMERA} or {@link #POLICY_DISABLE_SCREEN_CAPTURE}.
6057 * @return Intent An intent to be used to start the dialog-activity if the restriction is
6058 * set by an admin, or null if the restriction does not exist or no admin set it.
6059 */
6060 public Intent createAdminSupportIntent(@NonNull String restriction) {
6061 throwIfParentInstance("createAdminSupportIntent");
6062 if (mService != null) {
6063 try {
6064 return mService.createAdminSupportIntent(restriction);
6065 } catch (RemoteException e) {
6066 throw e.rethrowFromSystemServer();
6067 }
6068 }
6069 return null;
6070 }
6071
6072 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006073 * Hide or unhide packages. When a package is hidden it is unavailable for use, but the data and
6074 * actual package file remain. This function can be called by a device owner, profile owner, or
6075 * by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via
6076 * {@link #setDelegatedScopes}.
Julia Reynolds966881e2014-05-14 12:23:08 -04006077 *
Edman Anjos52088e42017-01-13 22:26:17 +01006078 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
6079 * {@code null} if the caller is a package access delegate.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07006080 * @param packageName The name of the package to hide or unhide.
6081 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006082 * unhidden.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07006083 * @return boolean Whether the hidden setting of the package was successfully updated.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006084 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01006085 * @see #setDelegatedScopes
6086 * @see #DELEGATION_PACKAGE_ACCESS
Julia Reynolds966881e2014-05-14 12:23:08 -04006087 */
Robin Lee25e26452015-06-02 09:56:29 -07006088 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07006089 boolean hidden) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006090 throwIfParentInstance("setApplicationHidden");
Julia Reynolds966881e2014-05-14 12:23:08 -04006091 if (mService != null) {
6092 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006093 return mService.setApplicationHidden(admin, mContext.getPackageName(), packageName,
6094 hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04006095 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006096 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04006097 }
6098 }
6099 return false;
6100 }
6101
6102 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006103 * Determine if a package is hidden. This function can be called by a device owner, profile
6104 * owner, or by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via
6105 * {@link #setDelegatedScopes}.
Julia Reynolds966881e2014-05-14 12:23:08 -04006106 *
Edman Anjos52088e42017-01-13 22:26:17 +01006107 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
6108 * {@code null} if the caller is a package access delegate.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07006109 * @param packageName The name of the package to retrieve the hidden status of.
6110 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006111 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01006112 * @see #setDelegatedScopes
6113 * @see #DELEGATION_PACKAGE_ACCESS
Julia Reynolds966881e2014-05-14 12:23:08 -04006114 */
Robin Lee25e26452015-06-02 09:56:29 -07006115 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006116 throwIfParentInstance("isApplicationHidden");
Julia Reynolds966881e2014-05-14 12:23:08 -04006117 if (mService != null) {
6118 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006119 return mService.isApplicationHidden(admin, mContext.getPackageName(), packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04006120 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006121 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04006122 }
6123 }
6124 return false;
6125 }
6126
6127 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006128 * Re-enable a system app that was disabled by default when the user was initialized. This
6129 * function can be called by a device owner, profile owner, or by a delegate given the
6130 * {@link #DELEGATION_ENABLE_SYSTEM_APP} scope via {@link #setDelegatedScopes}.
Adam Connors655be2a2014-07-14 09:01:25 +00006131 *
Edman Anjos52088e42017-01-13 22:26:17 +01006132 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
6133 * {@code null} if the caller is an enable system app delegate.
Makoto Onuki32b30572015-12-11 14:29:51 -08006134 * @param packageName The package to be re-enabled in the calling profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006135 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01006136 * @see #setDelegatedScopes
6137 * @see #DELEGATION_PACKAGE_ACCESS
Adam Connors655be2a2014-07-14 09:01:25 +00006138 */
Robin Lee25e26452015-06-02 09:56:29 -07006139 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006140 throwIfParentInstance("enableSystemApp");
Adam Connors655be2a2014-07-14 09:01:25 +00006141 if (mService != null) {
6142 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006143 mService.enableSystemApp(admin, mContext.getPackageName(), packageName);
Adam Connors655be2a2014-07-14 09:01:25 +00006144 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006145 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00006146 }
6147 }
6148 }
6149
6150 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006151 * Re-enable system apps by intent that were disabled by default when the user was initialized.
6152 * This function can be called by a device owner, profile owner, or by a delegate given the
6153 * {@link #DELEGATION_ENABLE_SYSTEM_APP} scope via {@link #setDelegatedScopes}.
Adam Connors655be2a2014-07-14 09:01:25 +00006154 *
Edman Anjos52088e42017-01-13 22:26:17 +01006155 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
6156 * {@code null} if the caller is an enable system app delegate.
Adam Connors655be2a2014-07-14 09:01:25 +00006157 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006158 * intent will be re-enabled in the calling profile.
Adam Connors655be2a2014-07-14 09:01:25 +00006159 * @return int The number of activities that matched the intent and were installed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006160 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01006161 * @see #setDelegatedScopes
6162 * @see #DELEGATION_PACKAGE_ACCESS
Adam Connors655be2a2014-07-14 09:01:25 +00006163 */
Robin Lee25e26452015-06-02 09:56:29 -07006164 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006165 throwIfParentInstance("enableSystemApp");
Adam Connors655be2a2014-07-14 09:01:25 +00006166 if (mService != null) {
6167 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006168 return mService.enableSystemAppWithIntent(admin, mContext.getPackageName(), intent);
Adam Connors655be2a2014-07-14 09:01:25 +00006169 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006170 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00006171 }
6172 }
6173 return 0;
6174 }
6175
6176 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00006177 * Called by a device owner or profile owner to disable account management for a specific type
6178 * of account.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006179 * <p>
6180 * The calling device admin must be a device owner or profile owner. If it is not, a security
6181 * exception will be thrown.
6182 * <p>
6183 * When account management is disabled for an account type, adding or removing an account of
6184 * that type will not be possible.
6185 * <p>
6186 * From {@link android.os.Build.VERSION_CODES#N} the profile or device owner can still use
Benjamin Franzb6c0ce42015-11-05 10:06:51 +00006187 * {@link android.accounts.AccountManager} APIs to add or remove accounts when account
6188 * management for a specific type is disabled.
6189 *
Sander Alewijnse650c3342014-05-08 18:00:50 +01006190 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6191 * @param accountType For which account management is disabled or enabled.
6192 * @param disabled The boolean indicating that account management will be disabled (true) or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006193 * enabled (false).
6194 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnse650c3342014-05-08 18:00:50 +01006195 */
Robin Lee25e26452015-06-02 09:56:29 -07006196 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01006197 boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006198 throwIfParentInstance("setAccountManagementDisabled");
Sander Alewijnse650c3342014-05-08 18:00:50 +01006199 if (mService != null) {
6200 try {
6201 mService.setAccountManagementDisabled(admin, accountType, disabled);
6202 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006203 throw e.rethrowFromSystemServer();
Sander Alewijnse650c3342014-05-08 18:00:50 +01006204 }
6205 }
6206 }
6207
6208 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01006209 * Gets the array of accounts for which account management is disabled by the profile owner.
6210 *
6211 * <p> Account management can be disabled/enabled by calling
6212 * {@link #setAccountManagementDisabled}.
6213 *
6214 * @return a list of account types for which account management has been disabled.
6215 *
6216 * @see #setAccountManagementDisabled
6217 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006218 public @Nullable String[] getAccountTypesWithManagementDisabled() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006219 throwIfParentInstance("getAccountTypesWithManagementDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07006220 return getAccountTypesWithManagementDisabledAsUser(myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01006221 }
6222
6223 /**
6224 * @see #getAccountTypesWithManagementDisabled()
6225 * @hide
6226 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006227 public @Nullable String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01006228 if (mService != null) {
6229 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01006230 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01006231 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006232 throw e.rethrowFromSystemServer();
Sander Alewijnse5c02db62014-05-07 10:46:57 +01006233 }
6234 }
6235
6236 return null;
6237 }
justinzhang511e0d82014-03-24 16:09:24 -04006238
6239 /**
Jason Monkd7b86212014-06-16 13:15:38 -04006240 * Sets which packages may enter lock task mode.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006241 * <p>
Esteban Talaverabdcada92017-02-01 14:20:06 +00006242 * Any packages that share uid with an allowed package will also be allowed to activate lock
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006243 * task. From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task
Esteban Talaverabdcada92017-02-01 14:20:06 +00006244 * package list results in locked tasks belonging to those packages to be finished.
6245 * <p>
6246 * This function can only be called by the device owner or by a profile owner of a user/profile
6247 * that is affiliated with the device owner user. See {@link #setAffiliationIds}. Any packages
6248 * set via this method will be cleared if the user becomes unaffiliated.
Jason Monkd7b86212014-06-16 13:15:38 -04006249 *
Jason Monkd7b86212014-06-16 13:15:38 -04006250 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04006251 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Esteban Talaverabdcada92017-02-01 14:20:06 +00006252 * @throws SecurityException if {@code admin} is not the device owner, or the profile owner of
6253 * an affiliated user or profile.
Jason Monkd7b86212014-06-16 13:15:38 -04006254 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00006255 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
6256 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04006257 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04006258 */
Esteban Talaverabdcada92017-02-01 14:20:06 +00006259 public void setLockTaskPackages(@NonNull ComponentName admin, @NonNull String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04006260 throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006261 throwIfParentInstance("setLockTaskPackages");
justinzhang511e0d82014-03-24 16:09:24 -04006262 if (mService != null) {
6263 try {
Jason Monk48aacba2014-08-13 16:29:08 -04006264 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04006265 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006266 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04006267 }
6268 }
6269 }
6270
6271 /**
Esteban Talaverabdcada92017-02-01 14:20:06 +00006272 * Returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04006273 *
Esteban Talaverabdcada92017-02-01 14:20:06 +00006274 * @throws SecurityException if {@code admin} is not the device owner, or the profile owner of
6275 * an affiliated user or profile.
6276 * @see #setLockTaskPackages
justinzhang511e0d82014-03-24 16:09:24 -04006277 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006278 public @NonNull String[] getLockTaskPackages(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006279 throwIfParentInstance("getLockTaskPackages");
justinzhang511e0d82014-03-24 16:09:24 -04006280 if (mService != null) {
6281 try {
Jason Monk48aacba2014-08-13 16:29:08 -04006282 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04006283 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006284 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04006285 }
6286 }
Esteban Talaverabdcada92017-02-01 14:20:06 +00006287 return new String[0];
justinzhang511e0d82014-03-24 16:09:24 -04006288 }
6289
6290 /**
6291 * This function lets the caller know whether the given component is allowed to start the
6292 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04006293 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04006294 */
Jason Monkd7b86212014-06-16 13:15:38 -04006295 public boolean isLockTaskPermitted(String pkg) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006296 throwIfParentInstance("isLockTaskPermitted");
justinzhang511e0d82014-03-24 16:09:24 -04006297 if (mService != null) {
6298 try {
Jason Monkd7b86212014-06-16 13:15:38 -04006299 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04006300 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006301 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04006302 }
6303 }
6304 return false;
6305 }
Julia Reynoldsda551652014-05-14 17:15:16 -04006306
6307 /**
6308 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
6309 * 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 -07006310 * <p>
6311 * The settings that can be updated with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04006312 * <ul>
6313 * <li>{@link Settings.Global#ADB_ENABLED}</li>
6314 * <li>{@link Settings.Global#AUTO_TIME}</li>
6315 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04006316 * <li>{@link Settings.Global#DATA_ROAMING}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04006317 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04006318 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006319 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN} This setting is only available from
6320 * {@link android.os.Build.VERSION_CODES#M} onwards and can only be set if
6321 * {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
6322 * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li> This setting is only
6323 * available from {@link android.os.Build.VERSION_CODES#M} onwards.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04006324 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006325 * <p>
6326 * Changing the following settings has no effect as of {@link android.os.Build.VERSION_CODES#M}:
Esteban Talavera656fa7f2015-06-29 17:41:39 +01006327 * <ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006328 * <li>{@link Settings.Global#BLUETOOTH_ON}. Use
6329 * {@link android.bluetooth.BluetoothAdapter#enable()} and
6330 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01006331 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006332 * <li>{@link Settings.Global#MODE_RINGER}. Use
6333 * {@link android.media.AudioManager#setRingerMode(int)} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01006334 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006335 * <li>{@link Settings.Global#WIFI_ON}. Use
6336 * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01006337 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04006338 *
6339 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6340 * @param setting The name of the setting to update.
6341 * @param value The value to update the setting to.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006342 * @throws SecurityException if {@code admin} is not a device owner.
Julia Reynoldsda551652014-05-14 17:15:16 -04006343 */
Robin Lee25e26452015-06-02 09:56:29 -07006344 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006345 throwIfParentInstance("setGlobalSetting");
Julia Reynoldsda551652014-05-14 17:15:16 -04006346 if (mService != null) {
6347 try {
6348 mService.setGlobalSetting(admin, setting, value);
6349 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006350 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04006351 }
6352 }
6353 }
6354
6355 /**
6356 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
6357 * that the value of the setting is in the correct form for the setting type should be performed
6358 * by the caller.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006359 * <p>
6360 * The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04006361 * <ul>
6362 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
6363 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
6364 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006365 * <p>
6366 * A device owner can additionally update the following settings:
Julia Reynolds82735bc2014-09-04 16:43:30 -04006367 * <ul>
6368 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
6369 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006370 *
Suprabh Shukla0b1356f2017-02-21 14:33:50 -08006371 * <strong>Note: Starting from Android O, apps should no longer call this method with the
6372 * setting {@link android.provider.Settings.Secure#INSTALL_NON_MARKET_APPS}, which is
6373 * deprecated. Instead, device owners or profile owners should use the restriction
6374 * {@link UserManager#DISALLOW_INSTALL_UNKNOWN_SOURCES}.
6375 * If any app targeting {@link android.os.Build.VERSION_CODES#O} or higher calls this method
6376 * with {@link android.provider.Settings.Secure#INSTALL_NON_MARKET_APPS},
6377 * an {@link UnsupportedOperationException} is thrown.
6378 * </strong>
6379 *
Julia Reynoldsda551652014-05-14 17:15:16 -04006380 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6381 * @param setting The name of the setting to update.
6382 * @param value The value to update the setting to.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006383 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynoldsda551652014-05-14 17:15:16 -04006384 */
Robin Lee25e26452015-06-02 09:56:29 -07006385 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006386 throwIfParentInstance("setSecureSetting");
Julia Reynoldsda551652014-05-14 17:15:16 -04006387 if (mService != null) {
6388 try {
6389 mService.setSecureSetting(admin, setting, value);
6390 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006391 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04006392 }
6393 }
6394 }
6395
Amith Yamasanif20d6402014-05-24 15:34:37 -07006396 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006397 * Designates a specific service component as the provider for making permission requests of a
6398 * local or remote administrator of the user.
Amith Yamasanif20d6402014-05-24 15:34:37 -07006399 * <p/>
6400 * Only a profile owner can designate the restrictions provider.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006401 *
Amith Yamasanif20d6402014-05-24 15:34:37 -07006402 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07006403 * @param provider The component name of the service that implements
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006404 * {@link RestrictionsReceiver}. If this param is null, it removes the restrictions
6405 * provider previously assigned.
6406 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanif20d6402014-05-24 15:34:37 -07006407 */
Robin Lee25e26452015-06-02 09:56:29 -07006408 public void setRestrictionsProvider(@NonNull ComponentName admin,
6409 @Nullable ComponentName provider) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006410 throwIfParentInstance("setRestrictionsProvider");
Amith Yamasanif20d6402014-05-24 15:34:37 -07006411 if (mService != null) {
6412 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07006413 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07006414 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006415 throw re.rethrowFromSystemServer();
Amith Yamasanif20d6402014-05-24 15:34:37 -07006416 }
6417 }
6418 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04006419
6420 /**
6421 * Called by profile or device owners to set the master volume mute on or off.
Nicolas Prevotaef3ce22016-09-22 12:00:25 +01006422 * This has no effect when set on a managed profile.
Julia Reynolds4a21b252014-06-04 11:11:43 -04006423 *
6424 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6425 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006426 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds4a21b252014-06-04 11:11:43 -04006427 */
Robin Lee25e26452015-06-02 09:56:29 -07006428 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006429 throwIfParentInstance("setMasterVolumeMuted");
Julia Reynolds4a21b252014-06-04 11:11:43 -04006430 if (mService != null) {
6431 try {
6432 mService.setMasterVolumeMuted(admin, on);
6433 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006434 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04006435 }
6436 }
6437 }
6438
6439 /**
6440 * Called by profile or device owners to check whether the master volume mute is on or off.
6441 *
6442 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6443 * @return {@code true} if master volume is muted, {@code false} if it's not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006444 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds4a21b252014-06-04 11:11:43 -04006445 */
Robin Lee25e26452015-06-02 09:56:29 -07006446 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006447 throwIfParentInstance("isMasterVolumeMuted");
Julia Reynolds4a21b252014-06-04 11:11:43 -04006448 if (mService != null) {
6449 try {
6450 return mService.isMasterVolumeMuted(admin);
6451 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006452 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04006453 }
6454 }
6455 return false;
6456 }
Kenny Guyc13053b2014-05-29 14:17:17 +01006457
6458 /**
Edman Anjosa5f2fb12016-12-19 11:25:54 -08006459 * Change whether a user can uninstall a package. This function can be called by a device owner,
6460 * profile owner, or by a delegate given the {@link #DELEGATION_BLOCK_UNINSTALL} scope via
6461 * {@link #setDelegatedScopes}.
Kenny Guyc13053b2014-05-29 14:17:17 +01006462 *
Edman Anjosa5f2fb12016-12-19 11:25:54 -08006463 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
6464 * {@code null} if the caller is a block uninstall delegate.
Kenny Guyc13053b2014-05-29 14:17:17 +01006465 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01006466 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006467 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjosa5f2fb12016-12-19 11:25:54 -08006468 * @see #setDelegatedScopes
6469 * @see #DELEGATION_BLOCK_UNINSTALL
Kenny Guyc13053b2014-05-29 14:17:17 +01006470 */
Edman Anjosa5f2fb12016-12-19 11:25:54 -08006471 public void setUninstallBlocked(@Nullable ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01006472 boolean uninstallBlocked) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006473 throwIfParentInstance("setUninstallBlocked");
Kenny Guyc13053b2014-05-29 14:17:17 +01006474 if (mService != null) {
6475 try {
Edman Anjosa5f2fb12016-12-19 11:25:54 -08006476 mService.setUninstallBlocked(admin, mContext.getPackageName(), packageName,
6477 uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01006478 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006479 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01006480 }
6481 }
6482 }
6483
6484 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08006485 * Check whether the user has been blocked by device policy from uninstalling a package.
Rubin Xua97855b2014-11-07 05:41:00 +00006486 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00006487 * <p>
6488 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006489 * behavior of this API is changed such that passing {@code null} as the {@code admin} parameter
6490 * will return if any admin has blocked the uninstallation. Before L MR1, passing {@code null}
6491 * will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01006492 *
Robin Lee25e26452015-06-02 09:56:29 -07006493 * @param admin The name of the admin component whose blocking policy will be checked, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006494 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01006495 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00006496 * @return true if uninstallation is blocked.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006497 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyc13053b2014-05-29 14:17:17 +01006498 */
Robin Lee25e26452015-06-02 09:56:29 -07006499 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006500 throwIfParentInstance("isUninstallBlocked");
Kenny Guyc13053b2014-05-29 14:17:17 +01006501 if (mService != null) {
6502 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01006503 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01006504 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006505 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01006506 }
6507 }
6508 return false;
6509 }
Svetoslav976e8bd2014-07-16 15:12:03 -07006510
6511 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006512 * Called by the profile owner of a managed profile to enable widget providers from a given
6513 * package to be available in the parent profile. As a result the user will be able to add
6514 * widgets from the white-listed package running under the profile to a widget host which runs
6515 * under the parent profile, for example the home screen. Note that a package may have zero or
6516 * more provider components, where each component provides a different widget type.
Svetoslav976e8bd2014-07-16 15:12:03 -07006517 * <p>
6518 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07006519 *
6520 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6521 * @param packageName The package from which widget providers are white-listed.
6522 * @return Whether the package was added.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006523 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07006524 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
6525 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
6526 */
Robin Lee25e26452015-06-02 09:56:29 -07006527 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006528 throwIfParentInstance("addCrossProfileWidgetProvider");
Svetoslav976e8bd2014-07-16 15:12:03 -07006529 if (mService != null) {
6530 try {
6531 return mService.addCrossProfileWidgetProvider(admin, packageName);
6532 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006533 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07006534 }
6535 }
6536 return false;
6537 }
6538
6539 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07006540 * Called by the profile owner of a managed profile to disable widget providers from a given
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006541 * package to be available in the parent profile. For this method to take effect the package
6542 * should have been added via
6543 * {@link #addCrossProfileWidgetProvider( android.content.ComponentName, String)}.
Svetoslav976e8bd2014-07-16 15:12:03 -07006544 * <p>
6545 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07006546 *
6547 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006548 * @param packageName The package from which widget providers are no longer white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07006549 * @return Whether the package was removed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006550 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07006551 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
6552 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
6553 */
Esteban Talavera62399912016-01-11 15:37:55 +00006554 public boolean removeCrossProfileWidgetProvider(
6555 @NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006556 throwIfParentInstance("removeCrossProfileWidgetProvider");
Svetoslav976e8bd2014-07-16 15:12:03 -07006557 if (mService != null) {
6558 try {
6559 return mService.removeCrossProfileWidgetProvider(admin, packageName);
6560 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006561 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07006562 }
6563 }
6564 return false;
6565 }
6566
6567 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07006568 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07006569 * available in the parent profile.
6570 *
6571 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6572 * @return The white-listed package list.
Svetoslav976e8bd2014-07-16 15:12:03 -07006573 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
6574 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006575 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07006576 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006577 public @NonNull List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006578 throwIfParentInstance("getCrossProfileWidgetProviders");
Svetoslav976e8bd2014-07-16 15:12:03 -07006579 if (mService != null) {
6580 try {
6581 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
6582 if (providers != null) {
6583 return providers;
6584 }
6585 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006586 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07006587 }
6588 }
6589 return Collections.emptyList();
6590 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006591
6592 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08006593 * Called by profile or device owners to set the user's photo.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006594 *
6595 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6596 * @param icon the bitmap to set as the photo.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006597 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006598 */
Robin Lee25e26452015-06-02 09:56:29 -07006599 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006600 throwIfParentInstance("setUserIcon");
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006601 try {
6602 mService.setUserIcon(admin, icon);
6603 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006604 throw re.rethrowFromSystemServer();
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006605 }
6606 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04006607
6608 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01006609 * Called by device owners to set a local system update policy. When a new policy is set,
6610 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00006611 *
Robin Lee25e26452015-06-02 09:56:29 -07006612 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006613 * components in the device owner package can set system update policies and the most
6614 * recent policy takes effect.
Robin Lee25e26452015-06-02 09:56:29 -07006615 * @param policy the new policy, or {@code null} to clear the current policy.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006616 * @throws SecurityException if {@code admin} is not a device owner.
Rubin Xu5faad8e2015-04-20 17:43:48 +01006617 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00006618 */
Robin Lee25e26452015-06-02 09:56:29 -07006619 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006620 throwIfParentInstance("setSystemUpdatePolicy");
Rubin Xu8027a4f2015-03-10 17:52:37 +00006621 if (mService != null) {
6622 try {
Robin Lee25e26452015-06-02 09:56:29 -07006623 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00006624 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006625 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00006626 }
6627 }
6628 }
6629
6630 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01006631 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00006632 *
Robin Lee25e26452015-06-02 09:56:29 -07006633 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00006634 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006635 public @Nullable SystemUpdatePolicy getSystemUpdatePolicy() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006636 throwIfParentInstance("getSystemUpdatePolicy");
Rubin Xu8027a4f2015-03-10 17:52:37 +00006637 if (mService != null) {
6638 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01006639 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00006640 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006641 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00006642 }
6643 }
6644 return null;
6645 }
Benjamin Franze36087e2015-04-07 16:40:34 +01006646
6647 /**
6648 * Called by a device owner to disable the keyguard altogether.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006649 * <p>
6650 * Setting the keyguard to disabled has the same effect as choosing "None" as the screen lock
6651 * type. However, this call has no effect if a password, pin or pattern is currently set. If a
6652 * password, pin or pattern is set after the keyguard was disabled, the keyguard stops being
6653 * disabled.
Benjamin Franze36087e2015-04-07 16:40:34 +01006654 *
6655 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01006656 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01006657 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006658 * place. {@code true} otherwise.
6659 * @throws SecurityException if {@code admin} is not a device owner.
Benjamin Franze36087e2015-04-07 16:40:34 +01006660 */
Robin Lee25e26452015-06-02 09:56:29 -07006661 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006662 throwIfParentInstance("setKeyguardDisabled");
Benjamin Franze36087e2015-04-07 16:40:34 +01006663 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01006664 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01006665 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006666 throw re.rethrowFromSystemServer();
Benjamin Franze36087e2015-04-07 16:40:34 +01006667 }
6668 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00006669
6670 /**
Benjamin Franzbece8062015-05-06 12:14:31 +01006671 * Called by device owner to disable the status bar. Disabling the status bar blocks
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006672 * notifications, quick settings and other screen overlays that allow escaping from a single use
6673 * device.
Benjamin Franzea2ec972015-03-16 17:18:09 +00006674 *
6675 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01006676 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006677 * @return {@code false} if attempting to disable the status bar failed. {@code true} otherwise.
6678 * @throws SecurityException if {@code admin} is not a device owner.
Benjamin Franzea2ec972015-03-16 17:18:09 +00006679 */
Robin Lee25e26452015-06-02 09:56:29 -07006680 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006681 throwIfParentInstance("setStatusBarDisabled");
Benjamin Franzea2ec972015-03-16 17:18:09 +00006682 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01006683 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00006684 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006685 throw re.rethrowFromSystemServer();
Benjamin Franzea2ec972015-03-16 17:18:09 +00006686 }
6687 }
Rubin Xudc105cc2015-04-14 23:38:01 +01006688
6689 /**
Charles Hedea0c3b2017-01-13 10:04:12 +00006690 * Called by the system update service to notify device and profile owners of pending system
6691 * updates.
Rubin Xudc105cc2015-04-14 23:38:01 +01006692 *
Charles Hedea0c3b2017-01-13 10:04:12 +00006693 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
6694 * permission. This method should only be used when it is unknown whether the pending system
6695 * update is a security patch. Otherwise, use
6696 * {@link #notifyPendingSystemUpdate(long, boolean)}.
6697 *
6698 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()}
6699 * indicating when the current pending update was first available. {@code -1} if no
6700 * update is available.
6701 * @see #notifyPendingSystemUpdate(long, boolean)
Rubin Xudc105cc2015-04-14 23:38:01 +01006702 * @hide
6703 */
6704 @SystemApi
6705 public void notifyPendingSystemUpdate(long updateReceivedTime) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006706 throwIfParentInstance("notifyPendingSystemUpdate");
Rubin Xudc105cc2015-04-14 23:38:01 +01006707 if (mService != null) {
6708 try {
Charles Hedea0c3b2017-01-13 10:04:12 +00006709 mService.notifyPendingSystemUpdate(SystemUpdateInfo.of(updateReceivedTime));
6710 } catch (RemoteException re) {
6711 throw re.rethrowFromSystemServer();
6712 }
6713 }
6714 }
6715
6716 /**
6717 * Called by the system update service to notify device and profile owners of pending system
6718 * updates.
6719 *
6720 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
6721 * permission. This method should be used instead of {@link #notifyPendingSystemUpdate(long)}
6722 * when it is known whether the pending system update is a security patch.
6723 *
6724 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()}
6725 * indicating when the current pending update was first available. {@code -1} if no
6726 * update is available.
6727 * @param isSecurityPatch {@code true} if this system update is purely a security patch;
6728 * {@code false} if not.
6729 * @see #notifyPendingSystemUpdate(long)
6730 * @hide
6731 */
6732 @SystemApi
6733 public void notifyPendingSystemUpdate(long updateReceivedTime, boolean isSecurityPatch) {
6734 throwIfParentInstance("notifyPendingSystemUpdate");
6735 if (mService != null) {
6736 try {
6737 mService.notifyPendingSystemUpdate(SystemUpdateInfo.of(updateReceivedTime,
6738 isSecurityPatch));
Rubin Xudc105cc2015-04-14 23:38:01 +01006739 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006740 throw re.rethrowFromSystemServer();
Rubin Xudc105cc2015-04-14 23:38:01 +01006741 }
6742 }
6743 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04006744
6745 /**
Pavel Grafovd65799e2016-12-02 11:21:45 +00006746 * Called by device or profile owners to get information about a pending system update.
6747 *
6748 * @param admin Which profile or device owner this request is associated with.
6749 * @return Information about a pending system update or {@code null} if no update pending.
6750 * @throws SecurityException if {@code admin} is not a device or profile owner.
6751 * @see DeviceAdminReceiver#onSystemUpdatePending(Context, Intent, long)
6752 */
6753 public @Nullable SystemUpdateInfo getPendingSystemUpdate(@NonNull ComponentName admin) {
6754 throwIfParentInstance("getPendingSystemUpdate");
6755 try {
6756 return mService.getPendingSystemUpdate(admin);
6757 } catch (RemoteException re) {
6758 throw re.rethrowFromSystemServer();
6759 }
6760 }
6761
6762 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006763 * Set the default response for future runtime permission requests by applications. This
6764 * function can be called by a device owner, profile owner, or by a delegate given the
6765 * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}.
6766 * The policy can allow for normal operation which prompts the user to grant a permission, or
6767 * can allow automatic granting or denying of runtime permission requests by an application.
6768 * This also applies to new permissions declared by app updates. When a permission is denied or
6769 * granted this way, the effect is equivalent to setting the permission * grant state via
6770 * {@link #setPermissionGrantState}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006771 * <p/>
6772 * As this policy only acts on runtime permission requests, it only applies to applications
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07006773 * built with a {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Benjamin Franz45dd6662015-07-08 14:24:14 +01006774 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07006775 * @param admin Which profile or device owner this request is associated with.
6776 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006777 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
6778 * @throws SecurityException if {@code admin} is not a device or profile owner.
Benjamin Franz45dd6662015-07-08 14:24:14 +01006779 * @see #setPermissionGrantState
Edman Anjos52088e42017-01-13 22:26:17 +01006780 * @see #setDelegatedScopes
6781 * @see #DELEGATION_PERMISSION_GRANT
Amith Yamasanid49489b2015-04-28 14:00:26 -07006782 */
Robin Lee25e26452015-06-02 09:56:29 -07006783 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006784 throwIfParentInstance("setPermissionPolicy");
Amith Yamasanid49489b2015-04-28 14:00:26 -07006785 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006786 mService.setPermissionPolicy(admin, mContext.getPackageName(), policy);
Amith Yamasanid49489b2015-04-28 14:00:26 -07006787 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006788 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07006789 }
6790 }
6791
6792 /**
6793 * Returns the current runtime permission policy set by the device or profile owner. The
6794 * default is {@link #PERMISSION_POLICY_PROMPT}.
Edman Anjos52088e42017-01-13 22:26:17 +01006795 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07006796 * @param admin Which profile or device owner this request is associated with.
6797 * @return the current policy for future permission requests.
6798 */
Esteban Talavera28b95702015-06-24 15:23:42 +01006799 public int getPermissionPolicy(ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006800 throwIfParentInstance("getPermissionPolicy");
Amith Yamasanid49489b2015-04-28 14:00:26 -07006801 try {
6802 return mService.getPermissionPolicy(admin);
6803 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006804 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07006805 }
6806 }
6807
6808 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006809 * Sets the grant state of a runtime permission for a specific application. The state can be
6810 * {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it through the UI,
6811 * {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission is denied and the user
6812 * cannot manage it through the UI, and {@link #PERMISSION_GRANT_STATE_GRANTED granted} in which
6813 * the permission is granted and the user cannot manage it through the UI. This might affect all
6814 * permissions in a group that the runtime permission belongs to. This method can only be called
Edman Anjos52088e42017-01-13 22:26:17 +01006815 * by a profile owner, device owner, or a delegate given the
6816 * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006817 * <p/>
6818 * Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not revoke
6819 * the permission. It retains the previous grant, if any.
6820 * <p/>
6821 * Permissions can be granted or revoked only for applications built with a
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07006822 * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07006823 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07006824 * @param admin Which profile or device owner this request is associated with.
6825 * @param packageName The application to grant or revoke a permission to.
6826 * @param permission The permission to grant or revoke.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006827 * @param grantState The permission grant state which is one of
6828 * {@link #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
6829 * {@link #PERMISSION_GRANT_STATE_GRANTED},
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006830 * @return whether the permission was successfully granted or revoked.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006831 * @throws SecurityException if {@code admin} is not a device or profile owner.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006832 * @see #PERMISSION_GRANT_STATE_DENIED
6833 * @see #PERMISSION_GRANT_STATE_DEFAULT
6834 * @see #PERMISSION_GRANT_STATE_GRANTED
Edman Anjos52088e42017-01-13 22:26:17 +01006835 * @see #setDelegatedScopes
6836 * @see #DELEGATION_PERMISSION_GRANT
Amith Yamasanid49489b2015-04-28 14:00:26 -07006837 */
Robin Lee25e26452015-06-02 09:56:29 -07006838 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006839 String permission, int grantState) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006840 throwIfParentInstance("setPermissionGrantState");
Amith Yamasanid49489b2015-04-28 14:00:26 -07006841 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006842 return mService.setPermissionGrantState(admin, mContext.getPackageName(), packageName,
6843 permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07006844 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006845 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07006846 }
6847 }
Amith Yamasani184b3752015-05-22 13:00:51 -07006848
6849 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006850 * Returns the current grant state of a runtime permission for a specific application. This
6851 * function can be called by a device owner, profile owner, or by a delegate given the
6852 * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}.
Amith Yamasani184b3752015-05-22 13:00:51 -07006853 *
Edman Anjos52088e42017-01-13 22:26:17 +01006854 * @param admin Which profile or device owner this request is associated with, or {@code null}
6855 * if the caller is a permission grant delegate.
Amith Yamasani184b3752015-05-22 13:00:51 -07006856 * @param packageName The application to check the grant state for.
6857 * @param permission The permission to check for.
6858 * @return the current grant state specified by device policy. If the profile or device owner
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006859 * has not set a grant state, the return value is
6860 * {@link #PERMISSION_GRANT_STATE_DEFAULT}. This does not indicate whether or not the
6861 * permission is currently granted for the package.
6862 * <p/>
6863 * If a grant state was set by the profile or device owner, then the return value will
6864 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or
6865 * {@link #PERMISSION_GRANT_STATE_GRANTED}, which indicates if the permission is
6866 * currently denied or granted.
6867 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasani184b3752015-05-22 13:00:51 -07006868 * @see #setPermissionGrantState(ComponentName, String, String, int)
6869 * @see PackageManager#checkPermission(String, String)
Edman Anjos52088e42017-01-13 22:26:17 +01006870 * @see #setDelegatedScopes
6871 * @see #DELEGATION_PERMISSION_GRANT
Amith Yamasani184b3752015-05-22 13:00:51 -07006872 */
Bartosz Fabianowski4b0624f2017-01-16 11:47:28 +01006873 public int getPermissionGrantState(@Nullable ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07006874 String permission) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006875 throwIfParentInstance("getPermissionGrantState");
Amith Yamasani184b3752015-05-22 13:00:51 -07006876 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006877 return mService.getPermissionGrantState(admin, mContext.getPackageName(), packageName,
6878 permission);
Amith Yamasani184b3752015-05-22 13:00:51 -07006879 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006880 throw re.rethrowFromSystemServer();
Amith Yamasani184b3752015-05-22 13:00:51 -07006881 }
6882 }
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006883
6884 /**
Esteban Talavera01576862016-12-15 11:16:44 +00006885 * Returns whether it is possible for the caller to initiate provisioning of a managed profile
6886 * or device, setting itself as the device or profile owner.
6887 *
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006888 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
6889 * {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Esteban Talavera01576862016-12-15 11:16:44 +00006890 * @return whether provisioning a managed profile or device is possible.
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006891 * @throws IllegalArgumentException if the supplied action is not valid.
6892 */
Esteban Talavera01576862016-12-15 11:16:44 +00006893 public boolean isProvisioningAllowed(@NonNull String action) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006894 throwIfParentInstance("isProvisioningAllowed");
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006895 try {
Esteban Talavera01576862016-12-15 11:16:44 +00006896 return mService.isProvisioningAllowed(action, mContext.getPackageName());
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006897 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006898 throw re.rethrowFromSystemServer();
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006899 }
6900 }
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006901
6902 /**
Esteban Talavera01576862016-12-15 11:16:44 +00006903 * Checks whether it is possible to initiate provisioning a managed device,
6904 * profile or user, setting the given package as owner.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00006905 *
6906 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
6907 * {@link #ACTION_PROVISION_MANAGED_PROFILE},
6908 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE},
6909 * {@link #ACTION_PROVISION_MANAGED_USER}
Esteban Talavera01576862016-12-15 11:16:44 +00006910 * @param packageName The package of the component that would be set as device, user, or profile
6911 * owner.
6912 * @return A {@link ProvisioningPreCondition} value indicating whether provisioning is allowed.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00006913 * @hide
6914 */
Esteban Talavera01576862016-12-15 11:16:44 +00006915 public @ProvisioningPreCondition int checkProvisioningPreCondition(
6916 String action, @NonNull String packageName) {
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00006917 try {
Esteban Talavera01576862016-12-15 11:16:44 +00006918 return mService.checkProvisioningPreCondition(action, packageName);
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00006919 } catch (RemoteException re) {
6920 throw re.rethrowFromSystemServer();
6921 }
6922 }
6923
6924 /**
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006925 * Return if this user is a managed profile of another user. An admin can become the profile
6926 * owner of a managed profile with {@link #ACTION_PROVISION_MANAGED_PROFILE} and of a managed
Kenny Guyffa38402016-03-31 16:40:57 +01006927 * user with {@link #createAndManageUser}
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006928 * @param admin Which profile owner this request is associated with.
6929 * @return if this user is a managed profile of another user.
6930 */
6931 public boolean isManagedProfile(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006932 throwIfParentInstance("isManagedProfile");
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006933 try {
6934 return mService.isManagedProfile(admin);
6935 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006936 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006937 }
6938 }
6939
6940 /**
6941 * @hide
6942 * Return if this user is a system-only user. An admin can manage a device from a system only
6943 * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}.
6944 * @param admin Which device owner this request is associated with.
6945 * @return if this user is a system-only user.
6946 */
6947 public boolean isSystemOnlyUser(@NonNull ComponentName admin) {
6948 try {
6949 return mService.isSystemOnlyUser(admin);
6950 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006951 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006952 }
6953 }
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006954
6955 /**
6956 * Called by device owner to get the MAC address of the Wi-Fi device.
6957 *
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08006958 * @param admin Which device owner this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006959 * @return the MAC address of the Wi-Fi device, or null when the information is not available.
6960 * (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.)
6961 * <p>
6962 * The address will be in the {@code XX:XX:XX:XX:XX:XX} format.
6963 * @throws SecurityException if {@code admin} is not a device owner.
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006964 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006965 public @Nullable String getWifiMacAddress(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006966 throwIfParentInstance("getWifiMacAddress");
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006967 try {
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08006968 return mService.getWifiMacAddress(admin);
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006969 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006970 throw re.rethrowFromSystemServer();
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006971 }
6972 }
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00006973
6974 /**
Mahaver Chopra1216ae52016-03-11 15:39:48 +00006975 * Called by device owner to reboot the device. If there is an ongoing call on the device,
6976 * throws an {@link IllegalStateException}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006977 * @param admin Which device owner the request is associated with.
Mahaver Chopra1216ae52016-03-11 15:39:48 +00006978 * @throws IllegalStateException if device has an ongoing call.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006979 * @throws SecurityException if {@code admin} is not a device owner.
Mahaver Chopra1216ae52016-03-11 15:39:48 +00006980 * @see TelephonyManager#CALL_STATE_IDLE
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00006981 */
6982 public void reboot(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006983 throwIfParentInstance("reboot");
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00006984 try {
6985 mService.reboot(admin);
6986 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006987 throw re.rethrowFromSystemServer();
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00006988 }
6989 }
Kenny Guy06de4e72015-12-22 12:07:39 +00006990
6991 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006992 * Called by a device admin to set the short support message. This will be displayed to the user
6993 * in settings screens where funtionality has been disabled by the admin. The message should be
6994 * limited to a short statement such as "This setting is disabled by your administrator. Contact
6995 * someone@example.com for support." If the message is longer than 200 characters it may be
6996 * truncated.
6997 * <p>
6998 * If the short support message needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006999 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
7000 * and set a new version of this string accordingly.
7001 *
Kenny Guy06de4e72015-12-22 12:07:39 +00007002 * @see #setLongSupportMessage
Kenny Guy06de4e72015-12-22 12:07:39 +00007003 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007004 * @param message Short message to be displayed to the user in settings or null to clear the
7005 * existing message.
7006 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00007007 */
7008 public void setShortSupportMessage(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007009 @Nullable CharSequence message) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007010 throwIfParentInstance("setShortSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00007011 if (mService != null) {
7012 try {
7013 mService.setShortSupportMessage(admin, message);
7014 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007015 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00007016 }
7017 }
7018 }
7019
7020 /**
7021 * Called by a device admin to get the short support message.
7022 *
7023 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007024 * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)} or
7025 * null if no message has been set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007026 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00007027 */
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007028 public CharSequence getShortSupportMessage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007029 throwIfParentInstance("getShortSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00007030 if (mService != null) {
7031 try {
7032 return mService.getShortSupportMessage(admin);
7033 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007034 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00007035 }
7036 }
7037 return null;
7038 }
7039
7040 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007041 * Called by a device admin to set the long support message. This will be displayed to the user
7042 * in the device administators settings screen.
7043 * <p>
7044 * If the long support message needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007045 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
7046 * and set a new version of this string accordingly.
7047 *
Kenny Guy06de4e72015-12-22 12:07:39 +00007048 * @see #setShortSupportMessage
Kenny Guy06de4e72015-12-22 12:07:39 +00007049 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007050 * @param message Long message to be displayed to the user in settings or null to clear the
7051 * existing message.
7052 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00007053 */
7054 public void setLongSupportMessage(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007055 @Nullable CharSequence message) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007056 throwIfParentInstance("setLongSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00007057 if (mService != null) {
7058 try {
7059 mService.setLongSupportMessage(admin, message);
7060 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007061 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00007062 }
7063 }
7064 }
7065
7066 /**
7067 * Called by a device admin to get the long support message.
7068 *
7069 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007070 * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)} or
7071 * null if no message has been set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007072 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00007073 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007074 public @Nullable CharSequence getLongSupportMessage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007075 throwIfParentInstance("getLongSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00007076 if (mService != null) {
7077 try {
7078 return mService.getLongSupportMessage(admin);
7079 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007080 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00007081 }
7082 }
7083 return null;
7084 }
7085
7086 /**
7087 * Called by the system to get the short support message.
7088 *
7089 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7090 * @param userHandle user id the admin is running as.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007091 * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)}
Kenny Guy06de4e72015-12-22 12:07:39 +00007092 *
7093 * @hide
7094 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007095 public @Nullable CharSequence getShortSupportMessageForUser(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007096 int userHandle) {
Kenny Guy06de4e72015-12-22 12:07:39 +00007097 if (mService != null) {
7098 try {
7099 return mService.getShortSupportMessageForUser(admin, userHandle);
7100 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007101 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00007102 }
7103 }
7104 return null;
7105 }
7106
7107
7108 /**
7109 * Called by the system to get the long support message.
7110 *
7111 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7112 * @param userHandle user id the admin is running as.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007113 * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)}
Kenny Guy06de4e72015-12-22 12:07:39 +00007114 *
7115 * @hide
7116 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007117 public @Nullable CharSequence getLongSupportMessageForUser(
7118 @NonNull ComponentName admin, int userHandle) {
Kenny Guy06de4e72015-12-22 12:07:39 +00007119 if (mService != null) {
7120 try {
7121 return mService.getLongSupportMessageForUser(admin, userHandle);
7122 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007123 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00007124 }
7125 }
7126 return null;
7127 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00007128
7129 /**
Esteban Talavera62399912016-01-11 15:37:55 +00007130 * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager}
7131 * whose calls act on the parent profile.
Benjamin Franz66b45f02016-04-05 19:12:39 +01007132 *
7133 * <p>The following methods are supported for the parent instance, all other methods will
7134 * throw a SecurityException when called on the parent instance:
7135 * <ul>
7136 * <li>{@link #getPasswordQuality}</li>
7137 * <li>{@link #setPasswordQuality}</li>
7138 * <li>{@link #getPasswordMinimumLength}</li>
7139 * <li>{@link #setPasswordMinimumLength}</li>
7140 * <li>{@link #getPasswordMinimumUpperCase}</li>
7141 * <li>{@link #setPasswordMinimumUpperCase}</li>
7142 * <li>{@link #getPasswordMinimumLowerCase}</li>
7143 * <li>{@link #setPasswordMinimumLowerCase}</li>
7144 * <li>{@link #getPasswordMinimumLetters}</li>
7145 * <li>{@link #setPasswordMinimumLetters}</li>
7146 * <li>{@link #getPasswordMinimumNumeric}</li>
7147 * <li>{@link #setPasswordMinimumNumeric}</li>
7148 * <li>{@link #getPasswordMinimumSymbols}</li>
7149 * <li>{@link #setPasswordMinimumSymbols}</li>
7150 * <li>{@link #getPasswordMinimumNonLetter}</li>
7151 * <li>{@link #setPasswordMinimumNonLetter}</li>
7152 * <li>{@link #getPasswordHistoryLength}</li>
7153 * <li>{@link #setPasswordHistoryLength}</li>
7154 * <li>{@link #getPasswordExpirationTimeout}</li>
7155 * <li>{@link #setPasswordExpirationTimeout}</li>
7156 * <li>{@link #getPasswordExpiration}</li>
Charles He8c760562016-10-25 16:36:53 +01007157 * <li>{@link #getPasswordMaximumLength}</li>
Benjamin Franz66b45f02016-04-05 19:12:39 +01007158 * <li>{@link #isActivePasswordSufficient}</li>
7159 * <li>{@link #getCurrentFailedPasswordAttempts}</li>
7160 * <li>{@link #getMaximumFailedPasswordsForWipe}</li>
7161 * <li>{@link #setMaximumFailedPasswordsForWipe}</li>
7162 * <li>{@link #getMaximumTimeToLock}</li>
7163 * <li>{@link #setMaximumTimeToLock}</li>
7164 * <li>{@link #lockNow}</li>
7165 * <li>{@link #getKeyguardDisabledFeatures}</li>
7166 * <li>{@link #setKeyguardDisabledFeatures}</li>
7167 * <li>{@link #getTrustAgentConfiguration}</li>
7168 * <li>{@link #setTrustAgentConfiguration}</li>
Michal Karpinskia20d8bb2016-11-23 12:09:08 +00007169 * <li>{@link #getRequiredStrongAuthTimeout}</li>
7170 * <li>{@link #setRequiredStrongAuthTimeout}</li>
Benjamin Franz66b45f02016-04-05 19:12:39 +01007171 * </ul>
Clara Bayarri3e826ef2015-12-14 17:51:22 +00007172 *
7173 * @return a new instance of {@link DevicePolicyManager} that acts on the parent profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007174 * @throws SecurityException if {@code admin} is not a profile owner.
Clara Bayarri3e826ef2015-12-14 17:51:22 +00007175 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007176 public @NonNull DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007177 throwIfParentInstance("getParentProfileInstance");
Clara Bayarri3e826ef2015-12-14 17:51:22 +00007178 try {
7179 if (!mService.isManagedProfile(admin)) {
7180 throw new SecurityException("The current user does not have a parent profile.");
7181 }
Jeff Sharkey49ca5292016-05-10 12:54:45 -06007182 return new DevicePolicyManager(mContext, mService, true);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007183 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007184 throw e.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007185 }
7186 }
7187
7188 /**
Esteban Talaverad36dd152016-12-15 08:51:45 +00007189 * Called by device owner to control the security logging feature.
Michal Karpinski6235a942016-03-15 12:07:23 +00007190 *
7191 * <p> Security logs contain various information intended for security auditing purposes.
7192 * See {@link SecurityEvent} for details.
7193 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00007194 * <p><strong>Note:</strong> The device owner won't be able to retrieve security logs if there
7195 * are unaffiliated secondary users or profiles on the device, regardless of whether the
7196 * feature is enabled. Logs will be discarded if the internal buffer fills up while waiting for
7197 * all users to become affiliated. Therefore it's recommended that affiliation ids are set for
7198 * new users as soon as possible after provisioning via {@link #setAffiliationIds}.
Michal Karpinskib58e4962016-03-01 14:55:10 +00007199 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007200 * @param admin Which device owner this request is associated with.
Michal Karpinski6235a942016-03-15 12:07:23 +00007201 * @param enabled whether security logging should be enabled or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007202 * @throws SecurityException if {@code admin} is not a device owner.
Michal Karpinski6235a942016-03-15 12:07:23 +00007203 * @see #retrieveSecurityLogs
7204 */
7205 public void setSecurityLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007206 throwIfParentInstance("setSecurityLoggingEnabled");
Michal Karpinski6235a942016-03-15 12:07:23 +00007207 try {
7208 mService.setSecurityLoggingEnabled(admin, enabled);
7209 } catch (RemoteException re) {
7210 throw re.rethrowFromSystemServer();
7211 }
7212 }
7213
7214 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00007215 * Return whether security logging is enabled or not by the device owner.
7216 *
7217 * <p>Can only be called by the device owner, otherwise a {@link SecurityException} will be
7218 * thrown.
7219 *
7220 * @param admin Which device owner this request is associated with.
7221 * @return {@code true} if security logging is enabled by device owner, {@code false} otherwise.
7222 * @throws SecurityException if {@code admin} is not a device owner.
7223 */
Bartosz Fabianowski0ec00002017-03-24 14:22:24 +01007224 public boolean isSecurityLoggingEnabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007225 throwIfParentInstance("isSecurityLoggingEnabled");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007226 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00007227 return mService.isSecurityLoggingEnabled(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007228 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007229 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007230 }
7231 }
7232
7233 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00007234 * Called by device owner to retrieve all new security logging entries since the last call to
7235 * this API after device boots.
7236 *
7237 * <p> Access to the logs is rate limited and it will only return new logs after the device
7238 * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}.
7239 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00007240 * <p>If there is any other user or profile on the device, it must be affiliated with the
7241 * device owner. Otherwise a {@link SecurityException} will be thrown. See
7242 * {@link #setAffiliationIds}
Michal Karpinskib58e4962016-03-01 14:55:10 +00007243 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007244 * @param admin Which device owner this request is associated with.
Michal Karpinski6235a942016-03-15 12:07:23 +00007245 * @return the new batch of security logs which is a list of {@link SecurityEvent},
7246 * or {@code null} if rate limitation is exceeded or if logging is currently disabled.
Esteban Talaverad36dd152016-12-15 08:51:45 +00007247 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
7248 * profile or secondary user that is not affiliated with the device owner user.
7249 * @see DeviceAdminReceiver#onSecurityLogsAvailable
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007250 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007251 public @Nullable List<SecurityEvent> retrieveSecurityLogs(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007252 throwIfParentInstance("retrieveSecurityLogs");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007253 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00007254 ParceledListSlice<SecurityEvent> list = mService.retrieveSecurityLogs(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007255 if (list != null) {
7256 return list.getList();
7257 } else {
7258 // Rate limit exceeded.
7259 return null;
7260 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00007261 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007262 throw re.rethrowFromSystemServer();
Clara Bayarri3e826ef2015-12-14 17:51:22 +00007263 }
7264 }
Benjamin Franz59720bb2016-01-18 15:26:11 +00007265
7266 /**
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00007267 * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent
7268 * profile.
7269 *
7270 * @hide
7271 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007272 public @NonNull DevicePolicyManager getParentProfileInstance(UserInfo uInfo) {
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00007273 mContext.checkSelfPermission(
7274 android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS);
7275 if (!uInfo.isManagedProfile()) {
7276 throw new SecurityException("The user " + uInfo.id
7277 + " does not have a parent profile.");
7278 }
Jeff Sharkey49ca5292016-05-10 12:54:45 -06007279 return new DevicePolicyManager(mContext, mService, true);
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00007280 }
7281
7282 /**
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007283 * Called by device owners to retrieve device logs from before the device's last reboot.
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007284 * <p>
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01007285 * <strong> This API is not supported on all devices. Calling this API on unsupported devices
7286 * will result in {@code null} being returned. The device logs are retrieved from a RAM region
7287 * which is not guaranteed to be corruption-free during power cycles, as a result be cautious
7288 * about data corruption when parsing. </strong>
Esteban Talaverad36dd152016-12-15 08:51:45 +00007289 *
7290 * <p>If there is any other user or profile on the device, it must be affiliated with the
7291 * device owner. Otherwise a {@link SecurityException} will be thrown. See
7292 * {@link #setAffiliationIds}
Michal Karpinskib58e4962016-03-01 14:55:10 +00007293 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007294 * @param admin Which device owner this request is associated with.
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01007295 * @return Device logs from before the latest reboot of the system, or {@code null} if this API
7296 * is not supported on the device.
Esteban Talaverad36dd152016-12-15 08:51:45 +00007297 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
7298 * profile or secondary user that is not affiliated with the device owner user.
7299 * @see #retrieveSecurityLogs
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007300 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007301 public @Nullable List<SecurityEvent> retrievePreRebootSecurityLogs(
7302 @NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007303 throwIfParentInstance("retrievePreRebootSecurityLogs");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007304 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00007305 ParceledListSlice<SecurityEvent> list = mService.retrievePreRebootSecurityLogs(admin);
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01007306 if (list != null) {
7307 return list.getList();
7308 } else {
7309 return null;
7310 }
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007311 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007312 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007313 }
7314 }
7315
7316 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007317 * Called by a profile owner of a managed profile to set the color used for customization. This
7318 * color is used as background color of the confirm credentials screen for that user. The
Clara Bayarri8d0bd7fa2016-03-30 14:59:58 +01007319 * default color is teal (#00796B).
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007320 * <p>
7321 * The confirm credentials screen can be created using
Benjamin Franz59720bb2016-01-18 15:26:11 +00007322 * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}.
7323 *
7324 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinski74cd7302016-04-12 15:17:36 +01007325 * @param color The 24bit (0xRRGGBB) representation of the color to be used.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007326 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz59720bb2016-01-18 15:26:11 +00007327 */
7328 public void setOrganizationColor(@NonNull ComponentName admin, int color) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007329 throwIfParentInstance("setOrganizationColor");
Benjamin Franz59720bb2016-01-18 15:26:11 +00007330 try {
Michal Karpinski74cd7302016-04-12 15:17:36 +01007331 // always enforce alpha channel to have 100% opacity
7332 color |= 0xFF000000;
Benjamin Franz59720bb2016-01-18 15:26:11 +00007333 mService.setOrganizationColor(admin, color);
7334 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007335 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00007336 }
7337 }
7338
7339 /**
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00007340 * @hide
7341 *
7342 * Sets the color used for customization.
7343 *
Michal Karpinski74cd7302016-04-12 15:17:36 +01007344 * @param color The 24bit (0xRRGGBB) representation of the color to be used.
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00007345 * @param userId which user to set the color to.
7346 * @RequiresPermission(allOf = {
7347 * Manifest.permission.MANAGE_USERS,
7348 * Manifest.permission.INTERACT_ACROSS_USERS_FULL})
7349 */
7350 public void setOrganizationColorForUser(@ColorInt int color, @UserIdInt int userId) {
7351 try {
Michal Karpinski74cd7302016-04-12 15:17:36 +01007352 // always enforce alpha channel to have 100% opacity
7353 color |= 0xFF000000;
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00007354 mService.setOrganizationColorForUser(color, userId);
7355 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007356 throw re.rethrowFromSystemServer();
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00007357 }
7358 }
7359
7360 /**
Benjamin Franz59720bb2016-01-18 15:26:11 +00007361 * Called by a profile owner of a managed profile to retrieve the color used for customization.
7362 * This color is used as background color of the confirm credentials screen for that user.
7363 *
7364 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinski74cd7302016-04-12 15:17:36 +01007365 * @return The 24bit (0xRRGGBB) representation of the color to be used.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007366 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz59720bb2016-01-18 15:26:11 +00007367 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01007368 public @ColorInt int getOrganizationColor(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007369 throwIfParentInstance("getOrganizationColor");
Benjamin Franz59720bb2016-01-18 15:26:11 +00007370 try {
7371 return mService.getOrganizationColor(admin);
7372 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007373 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00007374 }
7375 }
7376
7377 /**
7378 * @hide
7379 * Retrieve the customization color for a given user.
7380 *
7381 * @param userHandle The user id of the user we're interested in.
Michal Karpinski74cd7302016-04-12 15:17:36 +01007382 * @return The 24bit (0xRRGGBB) representation of the color to be used.
Benjamin Franz59720bb2016-01-18 15:26:11 +00007383 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01007384 public @ColorInt int getOrganizationColorForUser(int userHandle) {
Benjamin Franz59720bb2016-01-18 15:26:11 +00007385 try {
7386 return mService.getOrganizationColorForUser(userHandle);
7387 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007388 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00007389 }
7390 }
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007391
7392 /**
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01007393 * Called by the device owner or profile owner to set the name of the organization under
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007394 * management.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007395 * <p>
7396 * If the organization name needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007397 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
7398 * and set a new version of this string accordingly.
7399 *
7400 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7401 * @param title The organization name or {@code null} to clear a previously set name.
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01007402 * @throws SecurityException if {@code admin} is not a device or profile owner.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007403 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01007404 public void setOrganizationName(@NonNull ComponentName admin, @Nullable CharSequence title) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007405 throwIfParentInstance("setOrganizationName");
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007406 try {
7407 mService.setOrganizationName(admin, title);
7408 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007409 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007410 }
7411 }
7412
7413 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007414 * Called by a profile owner of a managed profile to retrieve the name of the organization under
7415 * management.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007416 *
7417 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7418 * @return The organization name or {@code null} if none is set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007419 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007420 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007421 public @Nullable CharSequence getOrganizationName(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007422 throwIfParentInstance("getOrganizationName");
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007423 try {
7424 return mService.getOrganizationName(admin);
7425 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007426 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007427 }
7428 }
7429
7430 /**
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01007431 * Called by the system to retrieve the name of the organization managing the device.
7432 *
7433 * @return The organization name or {@code null} if none is set.
7434 * @throws SecurityException if the caller is not the device owner, does not hold the
7435 * MANAGE_USERS permission and is not the system.
7436 *
7437 * @hide
7438 */
7439 @SystemApi
7440 @TestApi
7441 public @Nullable CharSequence getDeviceOwnerOrganizationName() {
7442 try {
7443 return mService.getDeviceOwnerOrganizationName();
7444 } catch (RemoteException re) {
7445 throw re.rethrowFromSystemServer();
7446 }
7447 }
7448
7449 /**
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007450 * Retrieve the default title message used in the confirm credentials screen for a given user.
7451 *
7452 * @param userHandle The user id of the user we're interested in.
7453 * @return The organization name or {@code null} if none is set.
7454 *
7455 * @hide
7456 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007457 public @Nullable CharSequence getOrganizationNameForUser(int userHandle) {
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007458 try {
7459 return mService.getOrganizationNameForUser(userHandle);
7460 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007461 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007462 }
7463 }
7464
7465 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00007466 * @return the {@link UserProvisioningState} for the current user - for unmanaged users will
7467 * return {@link #STATE_USER_UNMANAGED}
7468 * @hide
7469 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00007470 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00007471 @UserProvisioningState
7472 public int getUserProvisioningState() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007473 throwIfParentInstance("getUserProvisioningState");
Alan Treadwayafad8782016-01-19 15:15:08 +00007474 if (mService != null) {
7475 try {
7476 return mService.getUserProvisioningState();
7477 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007478 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00007479 }
7480 }
7481 return STATE_USER_UNMANAGED;
7482 }
7483
7484 /**
7485 * Set the {@link UserProvisioningState} for the supplied user, if they are managed.
7486 *
7487 * @param state to store
7488 * @param userHandle for user
7489 * @hide
7490 */
7491 public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) {
7492 if (mService != null) {
7493 try {
7494 mService.setUserProvisioningState(state, userHandle);
7495 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007496 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00007497 }
7498 }
7499 }
7500
7501 /**
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007502 * Indicates the entity that controls the device or profile owner. Two users/profiles are
7503 * affiliated if the set of ids set by their device or profile owners intersect.
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007504 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00007505 * <p><strong>Note:</strong> Features that depend on user affiliation (such as security logging
7506 * or {@link #bindDeviceAdminServiceAsUser}) won't be available when a secondary user or profile
7507 * is created, until it becomes affiliated. Therefore it is recommended that the appropriate
7508 * affiliation ids are set by its profile owner as soon as possible after the user/profile is
7509 * created.
7510 *
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007511 * @param admin Which profile or device owner this request is associated with.
Tony Mak31657432017-04-25 09:29:55 +01007512 * @param ids A set of opaque non-empty affiliation ids.
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007513 *
Tony Mak31657432017-04-25 09:29:55 +01007514 * @throws IllegalArgumentException if {@code ids} is null or contains an empty string.
7515 */
7516 public void setAffiliationIds(@NonNull ComponentName admin, @NonNull Set<String> ids) {
7517 throwIfParentInstance("setAffiliationIds");
7518 if (ids == null) {
7519 throw new IllegalArgumentException("ids must not be null");
7520 }
7521 try {
7522 mService.setAffiliationIds(admin, new ArrayList<>(ids));
7523 } catch (RemoteException e) {
7524 throw e.rethrowFromSystemServer();
7525 }
7526 }
7527
7528 /**
7529 * STOPSHIP (b/37622682) Remove it before release.
7530 * @removed
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007531 */
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007532 public void setAffiliationIds(@NonNull ComponentName admin, @NonNull List<String> ids) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007533 throwIfParentInstance("setAffiliationIds");
Tony Mak31657432017-04-25 09:29:55 +01007534 if (ids == null) {
7535 throw new IllegalArgumentException("ids must not be null");
7536 }
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007537 try {
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007538 mService.setAffiliationIds(admin, ids);
7539 } catch (RemoteException e) {
7540 throw e.rethrowFromSystemServer();
7541 }
7542 }
7543
7544 /**
Tony Mak31657432017-04-25 09:29:55 +01007545 * Returns the set of affiliation ids previously set via {@link #setAffiliationIds}, or an
7546 * empty set if none have been set.
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007547 */
Tony Mak31657432017-04-25 09:29:55 +01007548 public @NonNull Set<String> getAffiliationIds(@NonNull ComponentName admin) {
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007549 try {
Tony Mak31657432017-04-25 09:29:55 +01007550 return new ArraySet<>(mService.getAffiliationIds(admin));
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007551 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007552 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007553 }
7554 }
7555
7556 /**
7557 * @hide
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007558 * Returns whether this user/profile is affiliated with the device.
7559 * <p>
7560 * By definition, the user that the device owner runs on is always affiliated with the device.
7561 * Any other user/profile is considered affiliated with the device if the set specified by its
7562 * profile owner via {@link #setAffiliationIds} intersects with the device owner's.
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007563 *
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007564 */
7565 public boolean isAffiliatedUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007566 throwIfParentInstance("isAffiliatedUser");
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007567 try {
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007568 return mService.isAffiliatedUser();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007569 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007570 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007571 }
7572 }
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08007573
7574 /**
7575 * @hide
7576 * Returns whether the uninstall for {@code packageName} for the current user is in queue
7577 * to be started
7578 * @param packageName the package to check for
7579 * @return whether the uninstall intent for {@code packageName} is pending
7580 */
7581 public boolean isUninstallInQueue(String packageName) {
7582 try {
7583 return mService.isUninstallInQueue(packageName);
7584 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007585 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08007586 }
7587 }
7588
7589 /**
7590 * @hide
7591 * @param packageName the package containing active DAs to be uninstalled
7592 */
7593 public void uninstallPackageWithActiveAdmins(String packageName) {
7594 try {
7595 mService.uninstallPackageWithActiveAdmins(packageName);
7596 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007597 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08007598 }
7599 }
Benjamin Franzbc33c822016-04-15 08:57:52 +01007600
Kenny Guy38dcca52016-04-19 13:09:18 +01007601 /**
7602 * @hide
7603 * Remove a test admin synchronously without sending it a broadcast about being removed.
7604 * If the admin is a profile owner or device owner it will still be removed.
7605 *
7606 * @param userHandle user id to remove the admin for.
7607 * @param admin The administration compononent to remove.
7608 * @throws SecurityException if the caller is not shell / root or the admin package
7609 * isn't a test application see {@link ApplicationInfo#FLAG_TEST_APP}.
7610 */
7611 public void forceRemoveActiveAdmin(ComponentName adminReceiver, int userHandle) {
7612 try {
7613 mService.forceRemoveActiveAdmin(adminReceiver, userHandle);
7614 } catch (RemoteException re) {
7615 throw re.rethrowFromSystemServer();
7616 }
7617 }
7618
Mahaver Chopra790d1982016-07-07 16:06:49 +01007619 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007620 * Returns whether the device has been provisioned.
7621 *
7622 * <p>Not for use by third-party applications.
7623 *
Mahaver Chopra790d1982016-07-07 16:06:49 +01007624 * @hide
Mahaver Chopra790d1982016-07-07 16:06:49 +01007625 */
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007626 @SystemApi
Mahaver Chopra790d1982016-07-07 16:06:49 +01007627 public boolean isDeviceProvisioned() {
7628 try {
7629 return mService.isDeviceProvisioned();
7630 } catch (RemoteException re) {
7631 throw re.rethrowFromSystemServer();
7632 }
7633 }
7634
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007635 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007636 * Writes that the provisioning configuration has been applied.
7637 *
7638 * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS}
7639 * permission.
7640 *
7641 * <p>Not for use by third-party applications.
7642 *
7643 * @hide
7644 */
7645 @SystemApi
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007646 public void setDeviceProvisioningConfigApplied() {
7647 try {
7648 mService.setDeviceProvisioningConfigApplied();
7649 } catch (RemoteException re) {
7650 throw re.rethrowFromSystemServer();
7651 }
7652 }
7653
7654 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007655 * Returns whether the provisioning configuration has been applied.
7656 *
7657 * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS} permission.
7658 *
7659 * <p>Not for use by third-party applications.
7660 *
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007661 * @return whether the provisioning configuration has been applied.
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007662 *
7663 * @hide
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007664 */
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007665 @SystemApi
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007666 public boolean isDeviceProvisioningConfigApplied() {
7667 try {
7668 return mService.isDeviceProvisioningConfigApplied();
7669 } catch (RemoteException re) {
7670 throw re.rethrowFromSystemServer();
7671 }
7672 }
7673
Victor Chang9bfc65f2016-08-15 12:27:09 +01007674 /**
7675 * @hide
Victor Chang3577ed22016-08-25 18:49:26 +01007676 * Force update user setup completed status. This API has no effect on user build.
7677 * @throws {@link SecurityException} if the caller has no
Esteban Talavera01576862016-12-15 11:16:44 +00007678 * {@code android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS} or the caller is
7679 * not {@link UserHandle#SYSTEM_USER}
Victor Chang9bfc65f2016-08-15 12:27:09 +01007680 */
7681 public void forceUpdateUserSetupComplete() {
7682 try {
7683 mService.forceUpdateUserSetupComplete();
7684 } catch (RemoteException re) {
7685 throw re.rethrowFromSystemServer();
7686 }
7687 }
7688
Benjamin Franzbc33c822016-04-15 08:57:52 +01007689 private void throwIfParentInstance(String functionName) {
7690 if (mParentInstance) {
7691 throw new SecurityException(functionName + " cannot be called on the parent instance");
7692 }
7693 }
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007694
7695 /**
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007696 * Allows the device owner to enable or disable the backup service.
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007697 *
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007698 * <p> Backup service manages all backup and restore mechanisms on the device. Setting this to
7699 * false will prevent data from being backed up or restored.
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007700 *
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007701 * <p> Backup service is off by default when device owner is present.
7702 *
7703 * @throws SecurityException if {@code admin} is not a device owner.
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007704 */
7705 public void setBackupServiceEnabled(@NonNull ComponentName admin, boolean enabled) {
Esteban Talavera5b7f2d02017-02-17 09:45:24 +00007706 throwIfParentInstance("setBackupServiceEnabled");
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007707 try {
7708 mService.setBackupServiceEnabled(admin, enabled);
7709 } catch (RemoteException re) {
7710 throw re.rethrowFromSystemServer();
7711 }
7712 }
7713
7714 /**
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007715 * Return whether the backup service is enabled by the device owner.
7716 *
7717 * <p> Backup service manages all backup and restore mechanisms on the device.
7718 *
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007719 * @return {@code true} if backup service is enabled, {@code false} otherwise.
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007720 * @see #setBackupServiceEnabled
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007721 */
7722 public boolean isBackupServiceEnabled(@NonNull ComponentName admin) {
Esteban Talavera5b7f2d02017-02-17 09:45:24 +00007723 throwIfParentInstance("isBackupServiceEnabled");
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007724 try {
7725 return mService.isBackupServiceEnabled(admin);
7726 } catch (RemoteException re) {
7727 throw re.rethrowFromSystemServer();
7728 }
7729 }
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007730
7731 /**
Esteban Talaverad36dd152016-12-15 08:51:45 +00007732 * Called by a device owner to control the network logging feature.
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007733 *
Robin Leea40a2fb2017-02-08 17:07:06 +00007734 * <p> Network logs contain DNS lookup and connect() library call events. The following library
7735 * functions are recorded while network logging is active:
7736 * <ul>
7737 * <li>{@code getaddrinfo()}</li>
7738 * <li>{@code gethostbyname()}</li>
7739 * <li>{@code connect()}</li>
7740 * </ul>
7741 *
7742 * <p> Network logging is a low-overhead tool for forensics but it is not guaranteed to use
7743 * full system call logging; event reporting is enabled by default for all processes but not
7744 * strongly enforced.
7745 * Events from applications using alternative implementations of libc, making direct kernel
7746 * calls, or deliberately obfuscating traffic may not be recorded.
7747 *
7748 * <p> Some common network events may not be reported. For example:
7749 * <ul>
7750 * <li>Applications may hardcode IP addresses to reduce the number of DNS lookups, or use
7751 * an alternative system for name resolution, and so avoid calling
7752 * {@code getaddrinfo()} or {@code gethostbyname}.</li>
7753 * <li>Applications may use datagram sockets for performance reasons, for example
7754 * for a game client. Calling {@code connect()} is unnecessary for this kind of
7755 * socket, so it will not trigger a network event.</li>
7756 * </ul>
7757 *
7758 * <p> It is possible to directly intercept layer 3 traffic leaving the device using an
7759 * always-on VPN service.
7760 * See {@link #setAlwaysOnVpnPackage(ComponentName, String, boolean)}
7761 * and {@link android.net.VpnService} for details.
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007762 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00007763 * <p><strong>Note:</strong> The device owner won't be able to retrieve network logs if there
7764 * are unaffiliated secondary users or profiles on the device, regardless of whether the
7765 * feature is enabled. Logs will be discarded if the internal buffer fills up while waiting for
7766 * all users to become affiliated. Therefore it's recommended that affiliation ids are set for
7767 * new users as soon as possible after provisioning via {@link #setAffiliationIds}.
7768 *
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007769 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7770 * @param enabled whether network logging should be enabled or not.
Esteban Talaverad36dd152016-12-15 08:51:45 +00007771 * @throws SecurityException if {@code admin} is not a device owner.
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007772 * @see #retrieveNetworkLogs
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007773 */
7774 public void setNetworkLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
7775 throwIfParentInstance("setNetworkLoggingEnabled");
7776 try {
7777 mService.setNetworkLoggingEnabled(admin, enabled);
7778 } catch (RemoteException re) {
7779 throw re.rethrowFromSystemServer();
7780 }
7781 }
7782
7783 /**
7784 * Return whether network logging is enabled by a device owner.
7785 *
phweissa4e169e2016-11-24 16:20:57 +01007786 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Can only
7787 * be {@code null} if the caller has MANAGE_USERS permission.
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007788 * @return {@code true} if network logging is enabled by device owner, {@code false} otherwise.
Esteban Talaverad36dd152016-12-15 08:51:45 +00007789 * @throws SecurityException if {@code admin} is not a device owner and caller has
phweissa4e169e2016-11-24 16:20:57 +01007790 * no MANAGE_USERS permission
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007791 */
phweissa4e169e2016-11-24 16:20:57 +01007792 public boolean isNetworkLoggingEnabled(@Nullable ComponentName admin) {
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007793 throwIfParentInstance("isNetworkLoggingEnabled");
7794 try {
7795 return mService.isNetworkLoggingEnabled(admin);
7796 } catch (RemoteException re) {
7797 throw re.rethrowFromSystemServer();
7798 }
7799 }
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007800
7801 /**
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007802 * Called by device owner to retrieve the most recent batch of network logging events.
7803 * A device owner has to provide a batchToken provided as part of
7804 * {@link DeviceAdminReceiver#onNetworkLogsAvailable} callback. If the token doesn't match the
7805 * token of the most recent available batch of logs, {@code null} will be returned.
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007806 *
7807 * <p> {@link NetworkEvent} can be one of {@link DnsEvent} or {@link ConnectEvent}.
7808 *
7809 * <p> The list of network events is sorted chronologically, and contains at most 1200 events.
7810 *
7811 * <p> Access to the logs is rate limited and this method will only return a new batch of logs
7812 * after the device device owner has been notified via
7813 * {@link DeviceAdminReceiver#onNetworkLogsAvailable}.
7814 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00007815 * <p>If a secondary user or profile is created, calling this method will throw a
7816 * {@link SecurityException} until all users become affiliated again. It will also no longer be
7817 * possible to retrieve the network logs batch with the most recent batchToken provided
7818 * by {@link DeviceAdminReceiver#onNetworkLogsAvailable}. See
7819 * {@link DevicePolicyManager#setAffiliationIds}.
7820 *
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007821 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007822 * @param batchToken A token of the batch to retrieve
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007823 * @return A new batch of network logs which is a list of {@link NetworkEvent}. Returns
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007824 * {@code null} if the batch represented by batchToken is no longer available or if
7825 * logging is disabled.
Esteban Talaverad36dd152016-12-15 08:51:45 +00007826 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
7827 * profile or secondary user that is not affiliated with the device owner user.
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007828 * @see DeviceAdminReceiver#onNetworkLogsAvailable
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007829 */
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007830 public @Nullable List<NetworkEvent> retrieveNetworkLogs(@NonNull ComponentName admin,
7831 long batchToken) {
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007832 throwIfParentInstance("retrieveNetworkLogs");
7833 try {
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007834 return mService.retrieveNetworkLogs(admin, batchToken);
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007835 } catch (RemoteException re) {
7836 throw re.rethrowFromSystemServer();
7837 }
7838 }
Tony Mak46aabe52016-11-14 12:53:06 +00007839
7840 /**
Esteban Talavera2f897912017-01-26 10:30:48 +00007841 * Called by a device owner to bind to a service from a profile owner or vice versa.
7842 * See {@link #getBindDeviceAdminTargetUsers} for a definition of which
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007843 * device/profile owners are allowed to bind to services of another profile/device owner.
7844 * <p>
Tony Mak46aabe52016-11-14 12:53:06 +00007845 * The service must be unexported. Note that the {@link Context} used to obtain this
7846 * {@link DevicePolicyManager} instance via {@link Context#getSystemService(Class)} will be used
7847 * to bind to the {@link android.app.Service}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007848 *
Tony Mak46aabe52016-11-14 12:53:06 +00007849 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7850 * @param serviceIntent Identifies the service to connect to. The Intent must specify either an
7851 * explicit component name or a package name to match an
7852 * {@link IntentFilter} published by a service.
Tony Makbf9928d2016-12-22 11:02:45 +00007853 * @param conn Receives information as the service is started and stopped in main thread. This
7854 * must be a valid {@link ServiceConnection} object; it must not be {@code null}.
Tony Mak46aabe52016-11-14 12:53:06 +00007855 * @param flags Operation options for the binding operation. See
7856 * {@link Context#bindService(Intent, ServiceConnection, int)}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007857 * @param targetUser Which user to bind to. Must be one of the users returned by
7858 * {@link #getBindDeviceAdminTargetUsers}, otherwise a {@link SecurityException} will
7859 * be thrown.
Tony Mak46aabe52016-11-14 12:53:06 +00007860 * @return If you have successfully bound to the service, {@code true} is returned;
7861 * {@code false} is returned if the connection is not made and you will not
7862 * receive the service object.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007863 *
Tony Mak46aabe52016-11-14 12:53:06 +00007864 * @see Context#bindService(Intent, ServiceConnection, int)
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007865 * @see #getBindDeviceAdminTargetUsers(ComponentName)
Tony Mak46aabe52016-11-14 12:53:06 +00007866 */
7867 public boolean bindDeviceAdminServiceAsUser(
7868 @NonNull ComponentName admin, Intent serviceIntent, @NonNull ServiceConnection conn,
7869 @Context.BindServiceFlags int flags, @NonNull UserHandle targetUser) {
7870 throwIfParentInstance("bindDeviceAdminServiceAsUser");
7871 // Keep this in sync with ContextImpl.bindServiceCommon.
7872 try {
Tony Makbf9928d2016-12-22 11:02:45 +00007873 final IServiceConnection sd = mContext.getServiceDispatcher(
7874 conn, mContext.getMainThreadHandler(), flags);
Tony Mak46aabe52016-11-14 12:53:06 +00007875 serviceIntent.prepareToLeaveProcess(mContext);
7876 return mService.bindDeviceAdminServiceAsUser(admin,
7877 mContext.getIApplicationThread(), mContext.getActivityToken(), serviceIntent,
7878 sd, flags, targetUser.getIdentifier());
7879 } catch (RemoteException re) {
7880 throw re.rethrowFromSystemServer();
7881 }
7882 }
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007883
7884 /**
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007885 * Returns the list of target users that the calling device or profile owner can use when
7886 * calling {@link #bindDeviceAdminServiceAsUser}.
7887 * <p>
Esteban Talavera2f897912017-01-26 10:30:48 +00007888 * A device owner can bind to a service from a profile owner and vice versa, provided that:
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007889 * <ul>
7890 * <li>Both belong to the same package name.
Esteban Talavera2f897912017-01-26 10:30:48 +00007891 * <li>Both users are affiliated. See {@link #setAffiliationIds}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007892 * </ul>
7893 */
7894 public @NonNull List<UserHandle> getBindDeviceAdminTargetUsers(@NonNull ComponentName admin) {
7895 throwIfParentInstance("getBindDeviceAdminTargetUsers");
7896 try {
7897 return mService.getBindDeviceAdminTargetUsers(admin);
7898 } catch (RemoteException re) {
7899 throw re.rethrowFromSystemServer();
7900 }
7901 }
7902
7903 /**
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007904 * Called by the system to get the time at which the device owner last retrieved security
7905 * logging entries.
7906 *
7907 * @return the time at which the device owner most recently retrieved security logging entries,
7908 * in milliseconds since epoch; -1 if security logging entries were never retrieved.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007909 * @throws SecurityException if the caller is not the device owner, does not hold the
7910 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007911 *
7912 * @hide
7913 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007914 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007915 public long getLastSecurityLogRetrievalTime() {
7916 try {
7917 return mService.getLastSecurityLogRetrievalTime();
7918 } catch (RemoteException re) {
7919 throw re.rethrowFromSystemServer();
7920 }
7921 }
7922
7923 /**
7924 * Called by the system to get the time at which the device owner last requested a bug report.
7925 *
7926 * @return the time at which the device owner most recently requested a bug report, in
7927 * milliseconds since epoch; -1 if a bug report was never requested.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007928 * @throws SecurityException if the caller is not the device owner, does not hold the
7929 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007930 *
7931 * @hide
7932 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007933 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007934 public long getLastBugReportRequestTime() {
7935 try {
7936 return mService.getLastBugReportRequestTime();
7937 } catch (RemoteException re) {
7938 throw re.rethrowFromSystemServer();
7939 }
7940 }
7941
7942 /**
7943 * Called by the system to get the time at which the device owner last retrieved network logging
7944 * events.
7945 *
7946 * @return the time at which the device owner most recently retrieved network logging events, in
7947 * milliseconds since epoch; -1 if network logging events were never retrieved.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007948 * @throws SecurityException if the caller is not the device owner, does not hold the
7949 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007950 *
7951 * @hide
7952 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007953 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007954 public long getLastNetworkLogRetrievalTime() {
7955 try {
7956 return mService.getLastNetworkLogRetrievalTime();
7957 } catch (RemoteException re) {
7958 throw re.rethrowFromSystemServer();
7959 }
7960 }
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01007961
7962 /**
Bartosz Fabianowski172f7802017-03-06 12:07:57 +01007963 * Called by the system to find out whether the current user's IME was set by the device/profile
7964 * owner or the user.
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01007965 *
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01007966 * @return {@code true} if the user's IME was set by the device or profile owner, {@code false}
7967 * otherwise.
Bartosz Fabianowski172f7802017-03-06 12:07:57 +01007968 * @throws SecurityException if the caller is not the device owner/profile owner.
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01007969 *
7970 * @hide
7971 */
7972 @TestApi
Bartosz Fabianowski172f7802017-03-06 12:07:57 +01007973 public boolean isCurrentInputMethodSetByOwner() {
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01007974 try {
Bartosz Fabianowski172f7802017-03-06 12:07:57 +01007975 return mService.isCurrentInputMethodSetByOwner();
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01007976 } catch (RemoteException re) {
7977 throw re.rethrowFromSystemServer();
7978 }
7979 }
Bartosz Fabianowski05dc9f72017-02-22 23:41:14 +01007980
Bartosz Fabianowski05dc9f72017-02-22 23:41:14 +01007981 /**
7982 * Called by the system to get a list of CA certificates that were installed by the device or
7983 * profile owner.
7984 *
Bartosz Fabianowski172f7802017-03-06 12:07:57 +01007985 * <p> The caller must be the target user's device owner/profile Owner or hold the
Bartosz Fabianowski05dc9f72017-02-22 23:41:14 +01007986 * {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} permission.
7987 *
7988 * @param user The user for whom to retrieve information.
7989 * @return list of aliases identifying CA certificates installed by the device or profile owner
7990 * @throws SecurityException if the caller does not have permission to retrieve information
7991 * about the given user's CA certificates.
7992 *
7993 * @hide
7994 */
7995 @TestApi
7996 public List<String> getOwnerInstalledCaCerts(@NonNull UserHandle user) {
7997 try {
7998 return mService.getOwnerInstalledCaCerts(user).getList();
7999 } catch (RemoteException re) {
8000 throw re.rethrowFromSystemServer();
8001 }
8002 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08008003}