blob: e0b631ed85f19f18fe8143f1523d5b39e9d283eb [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;
Tony Mak46aabe52016-11-14 12:53:06 +000023import android.annotation.RequiresPermission;
Dianne Hackbornd6847842010-01-12 18:14:19 -080024import android.annotation.SdkConstant;
25import android.annotation.SdkConstant.SdkConstantType;
Justin Moreyb5deda72014-07-24 10:53:40 -050026import android.annotation.SystemApi;
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +010027import android.annotation.TestApi;
Nicolas Prevot8f7698a2016-02-11 16:05:33 +000028import android.annotation.UserIdInt;
Fyodor Kupolov4e9af062016-07-18 16:59:11 -070029import android.annotation.WorkerThread;
Jason Monkd7b86212014-06-16 13:15:38 -040030import android.app.Activity;
Andrew Scull5f9e6f32016-08-02 14:22:17 +010031import android.app.admin.PasswordMetrics;
Tony Mak46aabe52016-11-14 12:53:06 +000032import android.app.IServiceConnection;
Michal Karpinski6235a942016-03-15 12:07:23 +000033import android.app.admin.SecurityLog.SecurityEvent;
Dianne Hackbornd6847842010-01-12 18:14:19 -080034import android.content.ComponentName;
35import android.content.Context;
Adam Connors010cfd42014-04-16 12:48:13 +010036import android.content.Intent;
Sander Alewijnsef475ca32014-02-17 15:13:58 +000037import android.content.IntentFilter;
Tony Mak46aabe52016-11-14 12:53:06 +000038import android.content.ServiceConnection;
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;
Dianne Hackbornd6847842010-01-12 18:14:19 -080059import android.util.Log;
60
Makoto Onukicc4bbeb2015-09-17 10:28:24 -070061import com.android.internal.annotations.VisibleForTesting;
Maggie Benthallda51e682013-08-08 22:35:44 -040062import com.android.org.conscrypt.TrustedCertificateStore;
63
64import java.io.ByteArrayInputStream;
Dianne Hackbornd6847842010-01-12 18:14:19 -080065import java.io.IOException;
Alan Treadwayafad8782016-01-19 15:15:08 +000066import java.lang.annotation.Retention;
67import java.lang.annotation.RetentionPolicy;
Oscar Montemayor69238c62010-08-03 10:51:06 -070068import java.net.InetSocketAddress;
69import java.net.Proxy;
Robin Lee0d5ccb72014-09-12 17:41:44 +010070import java.security.KeyFactory;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000071import java.security.NoSuchAlgorithmException;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010072import java.security.PrivateKey;
73import java.security.cert.Certificate;
Maggie Benthallda51e682013-08-08 22:35:44 -040074import java.security.cert.CertificateException;
75import java.security.cert.CertificateFactory;
76import java.security.cert.X509Certificate;
Robin Lee0d5ccb72014-09-12 17:41:44 +010077import java.security.spec.InvalidKeySpecException;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000078import java.security.spec.PKCS8EncodedKeySpec;
Jim Miller604e7552014-07-18 19:00:02 -070079import java.util.ArrayList;
Rubin Xub4365912016-03-23 12:13:22 +000080import java.util.Arrays;
Svetoslav976e8bd2014-07-16 15:12:03 -070081import java.util.Collections;
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -080082import java.util.List;
Dianne Hackbornd6847842010-01-12 18:14:19 -080083
84/**
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000085 * Public interface for managing policies enforced on a device. Most clients of this class must be
Suprabh Shukla34d92ef2016-03-14 13:49:37 -070086 * registered with the system as a <a href="{@docRoot}guide/topics/admin/device-admin.html">device
87 * administrator</a>. Additionally, a device administrator may be registered as either a profile or
88 * device owner. A given method is accessible to all device administrators unless the documentation
89 * for that method specifies that it is restricted to either device or profile owners. Any
90 * application calling an api may only pass as an argument a device administrator component it
91 * owns. Otherwise, a {@link SecurityException} will be thrown.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080092 * <div class="special reference">
93 * <h3>Developer Guides</h3>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -070094 * <p>
95 * For more information about managing policies for device administration, read the <a href=
96 * "{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a> developer
97 * guide. </div>
Dianne Hackbornd6847842010-01-12 18:14:19 -080098 */
99public class DevicePolicyManager {
100 private static String TAG = "DevicePolicyManager";
Dianne Hackbornd6847842010-01-12 18:14:19 -0800101
102 private final Context mContext;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800103 private final IDevicePolicyManager mService;
Esteban Talavera62399912016-01-11 15:37:55 +0000104 private final boolean mParentInstance;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700105
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600106 /** @hide */
107 public DevicePolicyManager(Context context, IDevicePolicyManager service) {
108 this(context, service, false);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800109 }
110
Dianne Hackborn87bba1e2010-02-26 17:25:54 -0800111 /** @hide */
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700112 @VisibleForTesting
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600113 protected DevicePolicyManager(Context context, IDevicePolicyManager service,
114 boolean parentInstance) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700115 mContext = context;
116 mService = service;
Esteban Talavera62399912016-01-11 15:37:55 +0000117 mParentInstance = parentInstance;
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700118 }
119
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700120 /** @hide test will override it. */
121 @VisibleForTesting
122 protected int myUserId() {
123 return UserHandle.myUserId();
124 }
125
Dianne Hackbornd6847842010-01-12 18:14:19 -0800126 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +0000127 * Activity action: Starts the provisioning flow which sets up a managed profile.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000128 *
Jessica Hummel9da60392014-05-21 12:32:57 +0100129 * <p>A managed profile allows data separation for example for the usage of a
130 * device as a personal and corporate device. The user which provisioning is started from and
131 * the managed profile share a launcher.
132 *
Andrew Solovay27f53372015-03-02 16:37:59 -0800133 * <p>This intent will typically be sent by a mobile device management application (MDM).
134 * Provisioning adds a managed profile and sets the MDM as the profile owner who has full
135 * control over the profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100136 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000137 * <p>It is possible to check if provisioning is allowed or not by querying the method
138 * {@link #isProvisioningAllowed(String)}.
139 *
140 * <p>In version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this intent must contain the
Nicolas Prevot18440252015-03-09 14:07:17 +0000141 * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700142 * As of {@link android.os.Build.VERSION_CODES#M}, it should contain the extra
Nicolas Prevot18440252015-03-09 14:07:17 +0000143 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only
144 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000145 *
Benjamin Franzea956242016-03-21 15:45:56 +0000146 * <p>The intent may also contain the following extras:
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000147 * <ul>
Benjamin Franzea956242016-03-21 15:45:56 +0000148 * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, optional </li>
149 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional, supported from
150 * {@link android.os.Build.VERSION_CODES#N}</li>
151 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
152 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
153 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Victor Chang51d84f92016-11-16 12:22:56 +0000154 * <li>{@link #EXTRA_PROVISIONING_SKIP_USER_CONSENT}, optional</li>
Victor Chang89ee2792016-11-23 12:10:55 +0000155 * <li>{@link #EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION}, optional</li>
Victor Changc10f6692016-12-09 15:24:00 +0000156 * <li>{@link #EXTRA_PROVISIONING_DISCLAIMERS}, optional</li>
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000157 * </ul>
Jessica Hummelf72078b2014-03-06 16:13:12 +0000158 *
Benjamin Franzea956242016-03-21 15:45:56 +0000159 * <p>When managed provisioning has completed, broadcasts are sent to the application specified
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000160 * in the provisioning intent. The
161 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the
162 * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in
163 * the primary profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100164 *
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000165 * <p>From version {@link android.os.Build.VERSION_CODES#O}, when managed provisioning has
166 * completed, along with the above broadcast, activity intent
167 * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the application specified in
168 * the provisioning intent.
169 *
Benjamin Franzea956242016-03-21 15:45:56 +0000170 * <p>If provisioning fails, the managedProfile is removed so the device returns to its
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100171 * previous state.
Alan Treadway4582f812015-07-28 11:49:35 +0100172 *
173 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
174 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
175 * the provisioning flow was successful, although this doesn't guarantee the full flow will
176 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
177 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000178 */
179 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
180 public static final String ACTION_PROVISION_MANAGED_PROFILE
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100181 = "android.app.action.PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000182
183 /**
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000184 * Activity action: Starts the provisioning flow which sets up a managed user.
185 *
186 * <p>This intent will typically be sent by a mobile device management application (MDM).
Makoto Onuki32b30572015-12-11 14:29:51 -0800187 * Provisioning configures the user as managed user and sets the MDM as the profile
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000188 * owner who has full control over the user. Provisioning can only happen before user setup has
189 * been completed. Use {@link #isProvisioningAllowed(String)} to check if provisioning is
190 * allowed.
191 *
Benjamin Franzea956242016-03-21 15:45:56 +0000192 * <p>The intent contains the following extras:
193 * <ul>
194 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
195 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
196 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
197 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
198 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
199 * </ul>
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000200 *
Benjamin Franzea956242016-03-21 15:45:56 +0000201 * <p>If provisioning fails, the device returns to its previous state.
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000202 *
203 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
204 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
205 * the provisioning flow was successful, although this doesn't guarantee the full flow will
206 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
207 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Benjamin Franzea956242016-03-21 15:45:56 +0000208 *
209 * @hide
Mahaver Chopra5e732562015-11-05 11:55:12 +0000210 */
211 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
212 public static final String ACTION_PROVISION_MANAGED_USER
213 = "android.app.action.PROVISION_MANAGED_USER";
214
215 /**
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100216 * Activity action: Starts the provisioning flow which sets up a managed device.
217 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
218 *
219 * <p> During device owner provisioning a device admin app is set as the owner of the device.
220 * A device owner has full control over the device. The device owner can not be modified by the
221 * user.
222 *
223 * <p> A typical use case would be a device that is owned by a company, but used by either an
224 * employee or client.
225 *
226 * <p> An intent with this action can be sent only on an unprovisioned device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000227 * It is possible to check if provisioning is allowed or not by querying the method
228 * {@link #isProvisioningAllowed(String)}.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100229 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000230 * <p>The intent contains the following extras:
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100231 * <ul>
232 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
233 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
234 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
Rubin Xua4f9dc12015-06-12 13:27:59 +0100235 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000236 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000237 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Victor Changc10f6692016-12-09 15:24:00 +0000238 * <li>{@link #EXTRA_PROVISIONING_DISCLAIMERS}, optional</li>
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100239 * </ul>
240 *
Benjamin Franzea956242016-03-21 15:45:56 +0000241 * <p>When device owner provisioning has completed, an intent of the type
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100242 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
243 * device owner.
244 *
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000245 * <p>From version {@link android.os.Build.VERSION_CODES#O}, when device owner provisioning has
246 * completed, along with the above broadcast, activity intent
247 * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the device owner.
248 *
Benjamin Franzea956242016-03-21 15:45:56 +0000249 * <p>If provisioning fails, the device is factory reset.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100250 *
Alan Treadway4582f812015-07-28 11:49:35 +0100251 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
252 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
253 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
254 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100255 */
256 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
257 public static final String ACTION_PROVISION_MANAGED_DEVICE
258 = "android.app.action.PROVISION_MANAGED_DEVICE";
259
260 /**
Alan Treadway46dd4492015-11-09 13:57:19 +0000261 * Activity action: Starts the provisioning flow which sets up a managed device.
Steven Ng980a1b62016-02-02 17:43:18 +0000262 *
263 * <p>During device owner provisioning, a device admin app is downloaded and set as the owner of
264 * the device. A device owner has full control over the device. The device owner can not be
265 * modified by the user and the only way of resetting the device is via factory reset.
266 *
267 * <p>A typical use case would be a device that is owned by a company, but used by either an
268 * employee or client.
269 *
270 * <p>The provisioning message should be sent to an unprovisioned device.
271 *
272 * <p>Unlike {@link #ACTION_PROVISION_MANAGED_DEVICE}, the provisioning message can only be sent
273 * by a privileged app with the permission
274 * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE}.
275 *
276 * <p>The provisioning intent contains the following properties:
277 * <ul>
278 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
279 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
280 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
281 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
282 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
283 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
284 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
285 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
286 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
287 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
288 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
289 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
290 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
291 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
292 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
293 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li></ul>
294 *
295 * @hide
296 */
297 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
298 @SystemApi
299 public static final String ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE =
300 "android.app.action.PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE";
301
302 /**
303 * Activity action: Starts the provisioning flow which sets up a managed device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000304 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
305 *
306 * <p>NOTE: This is only supported on split system user devices, and puts the device into a
307 * management state that is distinct from that reached by
308 * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system
309 * user, and only has control over device-wide policies, not individual users and their data.
310 * The primary benefit is that multiple non-system users are supported when provisioning using
311 * this form of device management.
312 *
Benjamin Franzea956242016-03-21 15:45:56 +0000313 * <p>During device owner provisioning a device admin app is set as the owner of the device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000314 * A device owner has full control over the device. The device owner can not be modified by the
315 * user.
316 *
Benjamin Franzea956242016-03-21 15:45:56 +0000317 * <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 +0000318 * employee or client.
319 *
Benjamin Franzea956242016-03-21 15:45:56 +0000320 * <p>An intent with this action can be sent only on an unprovisioned device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000321 * It is possible to check if provisioning is allowed or not by querying the method
322 * {@link #isProvisioningAllowed(String)}.
323 *
324 * <p>The intent contains the following extras:
325 * <ul>
326 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
327 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
328 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
329 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Benjamin Franzea956242016-03-21 15:45:56 +0000330 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
331 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Alan Treadway46dd4492015-11-09 13:57:19 +0000332 * </ul>
333 *
Benjamin Franzea956242016-03-21 15:45:56 +0000334 * <p>When device owner provisioning has completed, an intent of the type
Alan Treadway46dd4492015-11-09 13:57:19 +0000335 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
336 * device owner.
337 *
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000338 * <p>From version {@link android.os.Build.VERSION_CODES#O}, when device owner provisioning has
339 * completed, along with the above broadcast, activity intent
340 * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the device owner.
341 *
Benjamin Franzea956242016-03-21 15:45:56 +0000342 * <p>If provisioning fails, the device is factory reset.
Alan Treadway46dd4492015-11-09 13:57:19 +0000343 *
344 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
345 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
346 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
347 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
348 *
349 * @hide
350 */
351 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
352 public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE
353 = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE";
354
355 /**
Alan Treadwayafad8782016-01-19 15:15:08 +0000356 * Activity action: Finalizes management provisioning, should be used after user-setup
357 * has been completed and {@link #getUserProvisioningState()} returns one of:
358 * <ul>
359 * <li>{@link #STATE_USER_SETUP_INCOMPLETE}</li>
360 * <li>{@link #STATE_USER_SETUP_COMPLETE}</li>
361 * <li>{@link #STATE_USER_PROFILE_COMPLETE}</li>
362 * </ul>
363 *
364 * @hide
365 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +0000366 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +0000367 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
368 public static final String ACTION_PROVISION_FINALIZATION
369 = "android.app.action.PROVISION_FINALIZATION";
370
371 /**
Michal Karpinskiba244092016-02-25 17:28:24 +0000372 * Action: Bugreport sharing with device owner has been accepted by the user.
373 *
374 * @hide
375 */
376 public static final String ACTION_BUGREPORT_SHARING_ACCEPTED =
377 "com.android.server.action.BUGREPORT_SHARING_ACCEPTED";
378
379 /**
380 * Action: Bugreport sharing with device owner has been declined by the user.
381 *
382 * @hide
383 */
384 public static final String ACTION_BUGREPORT_SHARING_DECLINED =
385 "com.android.server.action.BUGREPORT_SHARING_DECLINED";
386
387 /**
Esteban Talavera01576862016-12-15 11:16:44 +0000388 * Action: Bugreport has been collected and is dispatched to {@code DevicePolicyManagerService}.
Michal Karpinskiba244092016-02-25 17:28:24 +0000389 *
390 * @hide
391 */
392 public static final String ACTION_REMOTE_BUGREPORT_DISPATCH =
393 "android.intent.action.REMOTE_BUGREPORT_DISPATCH";
394
395 /**
396 * Extra for shared bugreport's SHA-256 hash.
397 *
398 * @hide
399 */
400 public static final String EXTRA_REMOTE_BUGREPORT_HASH =
401 "android.intent.extra.REMOTE_BUGREPORT_HASH";
402
403 /**
404 * Extra for remote bugreport notification shown type.
405 *
406 * @hide
407 */
408 public static final String EXTRA_BUGREPORT_NOTIFICATION_TYPE =
409 "android.app.extra.bugreport_notification_type";
410
411 /**
412 * Notification type for a started remote bugreport flow.
413 *
414 * @hide
415 */
416 public static final int NOTIFICATION_BUGREPORT_STARTED = 1;
417
418 /**
419 * Notification type for a bugreport that has already been accepted to be shared, but is still
420 * being taken.
421 *
422 * @hide
423 */
424 public static final int NOTIFICATION_BUGREPORT_ACCEPTED_NOT_FINISHED = 2;
425
426 /**
427 * Notification type for a bugreport that has been taken and can be shared or declined.
428 *
429 * @hide
430 */
431 public static final int NOTIFICATION_BUGREPORT_FINISHED_NOT_ACCEPTED = 3;
432
433 /**
Michal Karpinski8f010dd2016-06-21 15:05:53 +0100434 * Default and maximum timeout in milliseconds after which unlocking with weak auth times out,
435 * i.e. the user has to use a strong authentication method like password, PIN or pattern.
436 *
437 * @hide
438 */
439 public static final long DEFAULT_STRONG_AUTH_TIMEOUT_MS = 72 * 60 * 60 * 1000; // 72h
440
441 /**
Rubin Xua4f9dc12015-06-12 13:27:59 +0100442 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100443 * allows a mobile device management application or NFC programmer application which starts
444 * managed provisioning to pass data to the management application instance after provisioning.
Rubin Xua4f9dc12015-06-12 13:27:59 +0100445 * <p>
446 * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that
447 * sends the intent to pass data to itself on the newly created profile.
448 * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same
449 * instance of the app on the primary user.
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100450 * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with
451 * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC
452 * message should contain a stringified {@link java.util.Properties} instance, whose string
453 * properties will be converted into a {@link android.os.PersistableBundle} and passed to the
454 * management application after provisioning.
455 *
Rubin Xua4f9dc12015-06-12 13:27:59 +0100456 * <p>
457 * In both cases the application receives the data in
Brian Carlstromf1fe51b2014-09-03 08:55:05 -0700458 * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action
459 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed
Rubin Xua4f9dc12015-06-12 13:27:59 +0100460 * during the managed provisioning.
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100461 */
462 public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE =
Esteban Talavera37f01842014-09-05 10:50:57 +0100463 "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE";
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100464
465 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100466 * A String extra holding the package name of the mobile device management application that
467 * will be set as the profile owner or device owner.
468 *
469 * <p>If an application starts provisioning directly via an intent with action
470 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
471 * application that started provisioning. The package will be set as profile owner in that case.
472 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000473 * <p>This package is set as device owner when device owner provisioning is started by an NFC
474 * message containing an NFC record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000475 *
476 * <p> When this extra is set, the application must have exactly one device admin receiver.
Robin Lee25e26452015-06-02 09:56:29 -0700477 * This receiver will be set as the profile or device owner and active admin.
Benjamin Franzea956242016-03-21 15:45:56 +0000478 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000479 * @see DeviceAdminReceiver
480 * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still
Nicolas Prevot8f78d6a2015-08-21 11:06:31 +0100481 * supported, but only if there is only one device admin receiver in the package that requires
482 * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000483 */
Nicolas Prevot18440252015-03-09 14:07:17 +0000484 @Deprecated
Jessica Hummelf72078b2014-03-06 16:13:12 +0000485 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100486 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000487
488 /**
Nicolas Prevot18440252015-03-09 14:07:17 +0000489 * A ComponentName extra indicating the device admin receiver of the mobile device management
490 * application that will be set as the profile owner or device owner and active admin.
491 *
492 * <p>If an application starts provisioning directly via an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100493 * {@link #ACTION_PROVISION_MANAGED_PROFILE} or
494 * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this
495 * component has to match the package name of the application that started provisioning.
Nicolas Prevot18440252015-03-09 14:07:17 +0000496 *
497 * <p>This component is set as device owner and active admin when device owner provisioning is
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100498 * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC
499 * message containing an NFC record with MIME type
Benjamin Franzea956242016-03-21 15:45:56 +0000500 * {@link #MIME_TYPE_PROVISIONING_NFC}. For the NFC record, the component name must be
Rubin Xu44ef750b2015-03-23 16:51:33 +0000501 * flattened to a string, via {@link ComponentName#flattenToShortString()}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000502 *
503 * @see DeviceAdminReceiver
504 */
505 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME
506 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME";
507
508 /**
Alexandra Gherghinaaaf2f3e2014-11-13 12:46:15 +0000509 * An {@link android.accounts.Account} extra holding the account to migrate during managed
510 * profile provisioning. If the account supplied is present in the primary user, it will be
511 * copied, along with its credentials to the managed profile and removed from the primary user.
512 *
513 * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}.
514 */
515
516 public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE
517 = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE";
518
519 /**
Victor Changaa9cbc02016-12-05 20:50:57 +0000520 * Boolean extra to indicate that the migrated account should be kept. This is used in
521 * conjunction with {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}. If it's set to {@code true},
522 * the account will not be removed from the primary user after it is migrated to the newly
523 * created user or profile.
Victor Chang89ee2792016-11-23 12:10:55 +0000524 *
525 * <p> Defaults to {@code false}
526 *
Victor Changaa9cbc02016-12-05 20:50:57 +0000527 * <p> Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
528 * {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}
Victor Chang89ee2792016-11-23 12:10:55 +0000529 */
530 public static final String EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION
531 = "android.app.extra.PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION";
532
533 /**
Jessica Hummele3da7902014-08-20 15:20:11 +0100534 * A String extra that, holds the email address of the account which a managed profile is
535 * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
536 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100537 *
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100538 * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}.
539 *
Jessica Hummele3da7902014-08-20 15:20:11 +0100540 * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning
541 * contains this extra, it is forwarded in the
542 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile
543 * device management application that was set as the profile owner during provisioning.
544 * It is usually used to avoid that the user has to enter their email address twice.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100545 */
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100546 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
547 = "android.app.extra.PROVISIONING_EMAIL_ADDRESS";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100548
549 /**
Nicolas Prevotcd2d8592015-11-23 13:27:21 +0000550 * A integer extra indicating the predominant color to show during the provisioning.
551 * Refer to {@link android.graphics.Color} for how the color is represented.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000552 *
553 * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or
554 * {@link #ACTION_PROVISION_MANAGED_DEVICE}.
555 */
556 public static final String EXTRA_PROVISIONING_MAIN_COLOR =
557 "android.app.extra.PROVISIONING_MAIN_COLOR";
558
559 /**
Sander Alewijnse8c411562014-11-12 18:03:11 +0000560 * A Boolean extra that can be used by the mobile device management application to skip the
Robin Lee25e26452015-06-02 09:56:29 -0700561 * disabling of system apps during provisioning when set to {@code true}.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000562 *
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100563 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
564 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000565 */
Sander Alewijnse5a144252014-11-18 13:25:04 +0000566 public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED =
567 "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED";
Sander Alewijnse8c411562014-11-12 18:03:11 +0000568
569 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100570 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
571 * will be set to.
572 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000573 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
574 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100575 */
576 public static final String EXTRA_PROVISIONING_TIME_ZONE
Esteban Talavera37f01842014-09-05 10:50:57 +0100577 = "android.app.extra.PROVISIONING_TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100578
579 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100580 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
581 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100582 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000583 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
584 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100585 */
586 public static final String EXTRA_PROVISIONING_LOCAL_TIME
Esteban Talavera37f01842014-09-05 10:50:57 +0100587 = "android.app.extra.PROVISIONING_LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100588
589 /**
590 * A String extra holding the {@link java.util.Locale} that the device will be set to.
591 * Format: xx_yy, where xx is the language code, and yy the country code.
592 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000593 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
594 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100595 */
596 public static final String EXTRA_PROVISIONING_LOCALE
Esteban Talavera37f01842014-09-05 10:50:57 +0100597 = "android.app.extra.PROVISIONING_LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100598
599 /**
600 * A String extra holding the ssid of the wifi network that should be used during nfc device
601 * owner provisioning for downloading the mobile device management application.
602 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000603 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
604 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100605 */
606 public static final String EXTRA_PROVISIONING_WIFI_SSID
Esteban Talavera37f01842014-09-05 10:50:57 +0100607 = "android.app.extra.PROVISIONING_WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100608
609 /**
610 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
611 * is hidden or not.
612 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000613 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
614 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100615 */
616 public static final String EXTRA_PROVISIONING_WIFI_HIDDEN
Esteban Talavera37f01842014-09-05 10:50:57 +0100617 = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100618
619 /**
620 * A String extra indicating the security type of the wifi network in
Mahaver Chopra76b08a92015-10-08 17:58:45 +0100621 * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or
622 * {@code WEP}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100623 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000624 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
625 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100626 */
627 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
Esteban Talavera37f01842014-09-05 10:50:57 +0100628 = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100629
630 /**
631 * A String extra holding the password of the wifi network in
632 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
633 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000634 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
635 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100636 */
637 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talavera37f01842014-09-05 10:50:57 +0100638 = "android.app.extra.PROVISIONING_WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100639
640 /**
641 * A String extra holding the proxy host for the wifi network in
642 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
643 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000644 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
645 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100646 */
647 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
Esteban Talavera37f01842014-09-05 10:50:57 +0100648 = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100649
650 /**
651 * An int extra holding the proxy port for the wifi network in
652 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
653 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000654 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
655 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100656 */
657 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
Esteban Talavera37f01842014-09-05 10:50:57 +0100658 = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100659
660 /**
661 * A String extra holding the proxy bypass for the wifi network in
662 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
663 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000664 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
665 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100666 */
667 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
Esteban Talavera37f01842014-09-05 10:50:57 +0100668 = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100669
670 /**
671 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
672 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
673 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000674 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
675 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100676 */
677 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
Esteban Talavera37f01842014-09-05 10:50:57 +0100678 = "android.app.extra.PROVISIONING_WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100679
680 /**
681 * A String extra holding a url that specifies the download location of the device admin
682 * package. When not provided it is assumed that the device admin package is already installed.
683 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000684 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
685 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100686 */
687 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talavera37f01842014-09-05 10:50:57 +0100688 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100689
690 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400691 * An int extra holding a minimum required version code for the device admin package. If the
692 * device admin is already installed on the device, it will only be re-downloaded from
693 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the
694 * installed package is less than this version code.
695 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400696 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400697 * provisioning via an NFC bump.
698 */
699 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE
700 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE";
701
702 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100703 * A String extra holding a http cookie header which should be used in the http request to the
704 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
705 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000706 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
707 * provisioning via an NFC bump.
Sander Alewijnse681bce92014-07-24 16:46:26 +0100708 */
709 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talavera37f01842014-09-05 10:50:57 +0100710 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100711
712 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100713 * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of
714 * the file at download location specified in
715 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100716 *
Benjamin Franzea956242016-03-21 15:45:56 +0000717 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} must be
718 * present. The provided checksum must match the checksum of the file at the download
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100719 * location. If the checksum doesn't match an error will be shown to the user and the user will
720 * be asked to factory reset the device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100721 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000722 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
723 * provisioning via an NFC bump.
Rubin Xud92e7572015-05-18 17:01:13 +0100724 *
725 * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP}
726 * and {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1} only SHA-1 hash is supported.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700727 * Starting from {@link android.os.Build.VERSION_CODES#M}, this parameter accepts SHA-256 in
Rubin Xud92e7572015-05-18 17:01:13 +0100728 * addition to SHA-1. Support for SHA-1 is likely to be removed in future OS releases.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100729 */
730 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100731 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100732
733 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100734 * A String extra holding the URL-safe base64 encoded SHA-256 checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100735 * android package archive at the download location specified in {@link
736 * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
737 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100738 * <p>The signatures of an android package archive can be obtained using
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100739 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
740 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
741 *
Benjamin Franzea956242016-03-21 15:45:56 +0000742 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} must be
743 * present. The provided checksum must match the checksum of any signature of the file at
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100744 * the download location. If the checksum does not match an error will be shown to the user and
745 * the user will be asked to factory reset the device.
746 *
747 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
748 * provisioning via an NFC bump.
749 */
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100750 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM
751 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM";
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100752
753 /**
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000754 * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile
755 * has completed successfully.
756 *
757 * <p>The broadcast is limited to the primary profile, to the app specified in the provisioning
Nicolas Prevotebe2d992015-05-12 18:14:53 -0700758 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000759 *
Mahaver7074caf2016-11-29 20:52:18 +0000760 * <p>This intent will contain the following extras
761 * <ul>
762 * <li>{@link Intent#EXTRA_USER}, corresponds to the {@link UserHandle} of the managed
763 * profile.</li>
764 * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, corresponds to the account requested to
765 * be migrated at provisioning time, if any.</li>
766 * </ul>
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000767 */
768 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
769 public static final String ACTION_MANAGED_PROFILE_PROVISIONED
770 = "android.app.action.MANAGED_PROFILE_PROVISIONED";
771
772 /**
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000773 * Activity action: This activity action is sent to indicate that provisioning of a managed
774 * profile or managed device has completed successfully. It'll be sent at the same time as
775 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast but this will be
776 * delivered faster as it's an activity intent.
777 *
778 * <p>The intent is only sent to the application on the profile that requested provisioning. In
779 * the device owner case the profile is the primary user.
780 *
781 * @see #ACTION_PROVISION_MANAGED_PROFILE
782 * @see #ACTION_PROVISION_MANAGED_DEVICE
783 */
784 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
785 public static final String ACTION_PROVISIONING_SUCCESSFUL =
786 "android.app.action.PROVISIONING_SUCCESSFUL";
787
788 /**
Benjamin Franzea956242016-03-21 15:45:56 +0000789 * A boolean extra indicating whether device encryption can be skipped as part of device owner
790 * or managed profile provisioning.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500791 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400792 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100793 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Benjamin Franzea956242016-03-21 15:45:56 +0000794 *
795 * <p>From {@link android.os.Build.VERSION_CODES#N} onwards, this is also supported for an
796 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500797 */
798 public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION =
799 "android.app.extra.PROVISIONING_SKIP_ENCRYPTION";
800
801 /**
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000802 * A {@link Uri} extra pointing to a logo image. This image will be shown during the
803 * provisioning. If this extra is not passed, a default image will be shown.
804 * <h5>The following URI schemes are accepted:</h5>
805 * <ul>
806 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
807 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
808 * </ul>
809 *
Victor Changc10f6692016-12-09 15:24:00 +0000810 * <p> It is the responsibility of the caller to provide an image with a reasonable
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000811 * pixed density for the device.
812 *
813 * <p> If a content: URI is passed, the intent should have the flag
814 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
815 * {@link android.content.ClipData} of the intent too.
816 *
817 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or
818 * {@link #ACTION_PROVISION_MANAGED_DEVICE}
819 */
820 public static final String EXTRA_PROVISIONING_LOGO_URI =
821 "android.app.extra.PROVISIONING_LOGO_URI";
822
823 /**
Victor Changc10f6692016-12-09 15:24:00 +0000824 * A {@link Bundle}[] extra consisting of list of disclaimer headers and disclaimer contents.
825 * Each {@link Bundle} must have both {@link #EXTRA_PROVISIONING_DISCLAIMER_HEADER}
826 * as disclaimer header, and {@link #EXTRA_PROVISIONING_DISCLAIMER_CONTENT} as disclaimer
827 * content.
828 *
829 * <p> The extra typically contains one disclaimer from the company of mobile device
830 * management application (MDM), and one disclaimer from the organization.
831 *
832 * <p> Call {@link Bundle#putParcelableArray(String, Parcelable[])} to put the {@link Bundle}[]
833 *
834 * <p> Maximum 3 key-value pairs can be specified. The rest will be ignored.
835 *
836 * <p> Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or
837 * {@link #ACTION_PROVISION_MANAGED_DEVICE}
838 */
839 public static final String EXTRA_PROVISIONING_DISCLAIMERS =
840 "android.app.extra.PROVISIONING_DISCLAIMERS";
841
842 /**
843 * A String extra of localized disclaimer header.
844 *
845 * <p> The extra is typically the company name of mobile device management application (MDM)
846 * or the organization name.
847 *
848 * <p> Use in Bundle {@link #EXTRA_PROVISIONING_DISCLAIMERS}
849 */
850 public static final String EXTRA_PROVISIONING_DISCLAIMER_HEADER =
851 "android.app.extra.PROVISIONING_DISCLAIMER_HEADER";
852
853 /**
854 * A {@link Uri} extra pointing to disclaimer content.
855 *
856 * <h5>The following URI schemes are accepted:</h5>
857 * <ul>
858 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
859 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
860 * </ul>
861 *
862 * <p> Styled text is supported in the disclaimer content. The content is parsed by
863 * {@link android.text.Html#fromHtml(String)} and displayed in a
864 * {@link android.widget.TextView}.
865 *
866 * <p> If a <code>content:</code> URI is passed, URI is passed, the intent should have the flag
867 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
868 * {@link android.content.ClipData} of the intent too.
869 *
870 * <p> Use in Bundle {@link #EXTRA_PROVISIONING_DISCLAIMERS}
871 */
872 public static final String EXTRA_PROVISIONING_DISCLAIMER_CONTENT =
873 "android.app.extra.PROVISIONING_DISCLAIMER_CONTENT";
874
875 /**
Alan Treadway94de8c82016-01-11 10:25:23 +0000876 * A boolean extra indicating if user setup should be skipped, for when provisioning is started
877 * during setup-wizard.
878 *
879 * <p>If unspecified, defaults to {@code true} to match the behavior in
880 * {@link android.os.Build.VERSION_CODES#M} and earlier.
881 *
Alan Treadway1a538d02016-01-18 16:42:30 +0000882 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or
883 * {@link #ACTION_PROVISION_MANAGED_USER}.
Alan Treadway94de8c82016-01-11 10:25:23 +0000884 *
885 * @hide
886 */
887 public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP =
888 "android.app.extra.PROVISIONING_SKIP_USER_SETUP";
889
890 /**
Victor Chang51d84f92016-11-16 12:22:56 +0000891 * A boolean extra indicating if the user consent steps from the provisioning flow should be
892 * skipped. If unspecified, defaults to {@code false}.
893 *
894 * It can only be used by an existing device owner trying to create a managed profile via
895 * {@link #ACTION_PROVISION_MANAGED_PROFILE}. Otherwise it is ignored.
896 */
897 public static final String EXTRA_PROVISIONING_SKIP_USER_CONSENT =
898 "android.app.extra.PROVISIONING_SKIP_USER_CONSENT";
899
900 /**
Benjamin Franzea956242016-03-21 15:45:56 +0000901 * This MIME type is used for starting the device owner provisioning.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100902 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400903 * <p>During device owner provisioning a device admin app is set as the owner of the device.
904 * A device owner has full control over the device. The device owner can not be modified by the
905 * user and the only way of resetting the device is if the device owner app calls a factory
906 * reset.
907 *
908 * <p> A typical use case would be a device that is owned by a company, but used by either an
909 * employee or client.
910 *
Benjamin Franzea956242016-03-21 15:45:56 +0000911 * <p> The NFC message must be sent to an unprovisioned device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100912 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000913 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100914 * contains the following properties:
915 * <ul>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400916 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
917 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100918 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400919 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100920 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
921 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
922 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
923 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
924 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
925 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
926 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
927 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
928 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
929 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100930 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
931 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from
932 * {@link android.os.Build.VERSION_CODES#M} </li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100933 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000934 * <p>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700935 * As of {@link android.os.Build.VERSION_CODES#M}, the properties should contain
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400936 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of
937 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only
938 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400939 */
940 public static final String MIME_TYPE_PROVISIONING_NFC
941 = "application/com.android.managedprovisioning";
942
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100943 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800944 * Activity action: ask the user to add a new device administrator to the system.
945 * The desired policy is the ComponentName of the policy in the
946 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
947 * bring the user through adding the device administrator to the system (or
948 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700949 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800950 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
951 * field to provide the user with additional explanation (in addition
952 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800953 *
954 * <p>If your administrator is already active, this will ordinarily return immediately (without
955 * user intervention). However, if your administrator has been updated and is requesting
956 * additional uses-policy flags, the user will be presented with the new list. New policies
957 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800958 */
959 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
960 public static final String ACTION_ADD_DEVICE_ADMIN
961 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700962
Dianne Hackbornd6847842010-01-12 18:14:19 -0800963 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700964 * @hide
965 * Activity action: ask the user to add a new device administrator as the profile owner
Amith Yamasani814e9872015-03-23 14:04:53 -0700966 * for this user. Only system apps can launch this intent.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700967 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700968 * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN}
969 * extra field. This will invoke a UI to bring the user through adding the profile owner admin
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700970 * to remotely control restrictions on the user.
971 *
Makoto Onukic8a5a552015-11-19 14:29:12 -0800972 * <p>The intent must be invoked via {@link Activity#startActivityForResult} to receive the
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700973 * result of whether or not the user approved the action. If approved, the result will
974 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
975 * as a profile owner.
976 *
977 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
978 * field to provide the user with additional explanation (in addition
979 * to your component's description) about what is being added.
980 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700981 * <p>If there is already a profile owner active or the caller is not a system app, the
982 * operation will return a failure result.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700983 */
984 @SystemApi
985 public static final String ACTION_SET_PROFILE_OWNER
986 = "android.app.action.SET_PROFILE_OWNER";
987
988 /**
989 * @hide
990 * Name of the profile owner admin that controls the user.
991 */
992 @SystemApi
993 public static final String EXTRA_PROFILE_OWNER_NAME
994 = "android.app.extra.PROFILE_OWNER_NAME";
995
996 /**
Nicolas Prevot00799002015-07-27 18:15:20 +0100997 * Broadcast action: send when any policy admin changes a policy.
Jim Miller284b62e2010-06-08 14:27:42 -0700998 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700999 *
Jim Miller284b62e2010-06-08 14:27:42 -07001000 * @hide
1001 */
1002 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
1003 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
1004
1005 /**
Tony Mak1970f972016-08-30 17:41:48 +01001006 * Broadcast action: sent when the device owner is set, changed or cleared.
Nicolas Prevot00799002015-07-27 18:15:20 +01001007 *
1008 * This broadcast is sent only to the primary user.
1009 * @see #ACTION_PROVISION_MANAGED_DEVICE
1010 */
1011 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1012 public static final String ACTION_DEVICE_OWNER_CHANGED
1013 = "android.app.action.DEVICE_OWNER_CHANGED";
1014
1015 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001016 * The ComponentName of the administrator component.
1017 *
1018 * @see #ACTION_ADD_DEVICE_ADMIN
1019 */
1020 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001021
Dianne Hackbornd6847842010-01-12 18:14:19 -08001022 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001023 * An optional CharSequence providing additional explanation for why the
1024 * admin is being added.
1025 *
1026 * @see #ACTION_ADD_DEVICE_ADMIN
1027 */
1028 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001029
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001030 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001031 * Activity action: have the user enter a new password. This activity should
1032 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
1033 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
1034 * enter a new password that meets the current requirements. You can use
1035 * {@link #isActivePasswordSufficient()} to determine whether you need to
1036 * have the user select a new password in order to meet the current
1037 * constraints. Upon being resumed from this activity, you can check the new
1038 * password characteristics to see if they are sufficient.
Benjamin Franzc9921092016-01-08 17:17:44 +00001039 *
1040 * If the intent is launched from within a managed profile with a profile
1041 * owner built against {@link android.os.Build.VERSION_CODES#M} or before,
1042 * this will trigger entering a new password for the parent of the profile.
1043 * For all other cases it will trigger entering a new password for the user
1044 * or profile it is launched from.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001045 *
1046 * @see #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
Dianne Hackbornd6847842010-01-12 18:14:19 -08001047 */
1048 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1049 public static final String ACTION_SET_NEW_PASSWORD
1050 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001051
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001052 /**
Benjamin Franzc9921092016-01-08 17:17:44 +00001053 * Activity action: have the user enter a new password for the parent profile.
1054 * If the intent is launched from within a managed profile, this will trigger
1055 * entering a new password for the parent of the profile. In all other cases
1056 * the behaviour is identical to {@link #ACTION_SET_NEW_PASSWORD}.
1057 */
1058 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1059 public static final String ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
1060 = "android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD";
1061
1062 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +00001063 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
1064 * the parent profile to access intents sent from the managed profile.
1065 * That is, when an app in the managed profile calls
1066 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
1067 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001068 */
Nicolas Prevot86a96732014-09-08 12:13:05 +01001069 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001070
1071 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +00001072 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
1073 * the managed profile to access intents sent from the parent profile.
1074 * That is, when an app in the parent profile calls
1075 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
1076 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001077 */
Nicolas Prevot86a96732014-09-08 12:13:05 +01001078 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001079
Dianne Hackbornd6847842010-01-12 18:14:19 -08001080 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01001081 * Broadcast action: notify that a new local system update policy has been set by the device
1082 * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00001083 */
1084 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Rubin Xu5faad8e2015-04-20 17:43:48 +01001085 public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED
1086 = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED";
Rubin Xu8027a4f2015-03-10 17:52:37 +00001087
Amith Yamasanid49489b2015-04-28 14:00:26 -07001088 /**
1089 * Permission policy to prompt user for new permission requests for runtime permissions.
1090 * Already granted or denied permissions are not affected by this.
1091 */
1092 public static final int PERMISSION_POLICY_PROMPT = 0;
1093
1094 /**
1095 * Permission policy to always grant new permission requests for runtime permissions.
1096 * Already granted or denied permissions are not affected by this.
1097 */
1098 public static final int PERMISSION_POLICY_AUTO_GRANT = 1;
1099
1100 /**
1101 * Permission policy to always deny new permission requests for runtime permissions.
1102 * Already granted or denied permissions are not affected by this.
1103 */
1104 public static final int PERMISSION_POLICY_AUTO_DENY = 2;
1105
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07001106 /**
1107 * Runtime permission state: The user can manage the permission
1108 * through the UI.
1109 */
1110 public static final int PERMISSION_GRANT_STATE_DEFAULT = 0;
1111
1112 /**
1113 * Runtime permission state: The permission is granted to the app
1114 * and the user cannot manage the permission through the UI.
1115 */
1116 public static final int PERMISSION_GRANT_STATE_GRANTED = 1;
1117
1118 /**
1119 * Runtime permission state: The permission is denied to the app
1120 * and the user cannot manage the permission through the UI.
1121 */
1122 public static final int PERMISSION_GRANT_STATE_DENIED = 2;
Rubin Xu8027a4f2015-03-10 17:52:37 +00001123
1124 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00001125 * No management for current user in-effect. This is the default.
1126 * @hide
1127 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001128 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001129 public static final int STATE_USER_UNMANAGED = 0;
1130
1131 /**
1132 * Management partially setup, user setup needs to be completed.
1133 * @hide
1134 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001135 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001136 public static final int STATE_USER_SETUP_INCOMPLETE = 1;
1137
1138 /**
1139 * Management partially setup, user setup completed.
1140 * @hide
1141 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001142 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001143 public static final int STATE_USER_SETUP_COMPLETE = 2;
1144
1145 /**
1146 * Management setup and active on current user.
1147 * @hide
1148 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001149 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001150 public static final int STATE_USER_SETUP_FINALIZED = 3;
1151
1152 /**
1153 * Management partially setup on a managed profile.
1154 * @hide
1155 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001156 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001157 public static final int STATE_USER_PROFILE_COMPLETE = 4;
1158
1159 /**
1160 * @hide
1161 */
1162 @IntDef({STATE_USER_UNMANAGED, STATE_USER_SETUP_INCOMPLETE, STATE_USER_SETUP_COMPLETE,
1163 STATE_USER_SETUP_FINALIZED, STATE_USER_PROFILE_COMPLETE})
1164 @Retention(RetentionPolicy.SOURCE)
1165 public @interface UserProvisioningState {}
1166
1167 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001168 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001169 *
1170 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1171 * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and
1172 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when provisioning is allowed.
1173 *
1174 * @hide
1175 */
1176 public static final int CODE_OK = 0;
1177
1178 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001179 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001180 *
1181 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and
1182 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the device already has a device
1183 * owner.
1184 *
1185 * @hide
1186 */
1187 public static final int CODE_HAS_DEVICE_OWNER = 1;
1188
1189 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001190 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001191 *
1192 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1193 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user has a profile owner and for
1194 * {@link #ACTION_PROVISION_MANAGED_PROFILE} when the profile owner is already set.
1195 *
1196 * @hide
1197 */
1198 public static final int CODE_USER_HAS_PROFILE_OWNER = 2;
1199
1200 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001201 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001202 *
1203 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and
1204 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user isn't running.
1205 *
1206 * @hide
1207 */
1208 public static final int CODE_USER_NOT_RUNNING = 3;
1209
1210 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001211 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001212 *
1213 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1214 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the device has already been setup and
1215 * for {@link #ACTION_PROVISION_MANAGED_USER} if the user has already been setup.
1216 *
1217 * @hide
1218 */
1219 public static final int CODE_USER_SETUP_COMPLETED = 4;
1220
1221 /**
1222 * Code used to indicate that the device also has a user other than the system user.
1223 *
1224 * @hide
1225 */
1226 public static final int CODE_NONSYSTEM_USER_EXISTS = 5;
1227
1228 /**
1229 * Code used to indicate that device has an account that prevents provisioning.
1230 *
1231 * @hide
1232 */
1233 public static final int CODE_ACCOUNTS_NOT_EMPTY = 6;
1234
1235 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001236 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001237 *
1238 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and
1239 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the user is not a system user.
1240 *
1241 * @hide
1242 */
1243 public static final int CODE_NOT_SYSTEM_USER = 7;
1244
1245 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001246 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001247 *
1248 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1249 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} and {@link #ACTION_PROVISION_MANAGED_USER}
1250 * when the device is a watch and is already paired.
1251 *
1252 * @hide
1253 */
1254 public static final int CODE_HAS_PAIRED = 8;
1255
1256 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001257 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001258 *
1259 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} and
1260 * {@link #ACTION_PROVISION_MANAGED_USER} on devices which do not support managed users.
1261 *
1262 * @see {@link PackageManager#FEATURE_MANAGED_USERS}
1263 * @hide
1264 */
1265 public static final int CODE_MANAGED_USERS_NOT_SUPPORTED = 9;
1266
1267 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001268 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001269 *
1270 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} if the user is a system user.
1271 *
1272 * @hide
1273 */
1274 public static final int CODE_SYSTEM_USER = 10;
1275
1276 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001277 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001278 *
1279 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when the user cannot have more
1280 * managed profiles.
1281 *
1282 * @hide
1283 */
1284 public static final int CODE_CANNOT_ADD_MANAGED_PROFILE = 11;
1285
1286 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001287 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001288 *
1289 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} and
1290 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices not running with split system
1291 * user.
1292 *
1293 * @hide
1294 */
1295 public static final int CODE_NOT_SYSTEM_USER_SPLIT = 12;
1296
1297 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001298 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001299 *
1300 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1301 * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and
1302 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices which do no support device
1303 * admins.
1304 *
1305 * @hide
1306 */
1307 public static final int CODE_DEVICE_ADMIN_NOT_SUPPORTED = 13;
1308
1309 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001310 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001311 *
Esteban Talavera6c9116a2016-11-24 16:12:44 +00001312 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when the device the user is a
1313 * system user on a split system user device.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001314 *
1315 * @hide
1316 */
1317 public static final int CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER = 14;
1318
1319 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001320 * Result code for {@link #checkProvisioningPreCondition}.
1321 *
1322 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when adding a managed profile is
1323 * disallowed by {@link UserManager#DISALLOW_ADD_MANAGED_PROFILE}.
1324 *
1325 * @hide
1326 */
1327 public static final int CODE_ADD_MANAGED_PROFILE_DISALLOWED = 15;
1328
1329 /**
1330 * Result codes for {@link #checkProvisioningPreCondition} indicating all the provisioning pre
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001331 * conditions.
1332 *
1333 * @hide
1334 */
1335 @Retention(RetentionPolicy.SOURCE)
1336 @IntDef({CODE_OK, CODE_HAS_DEVICE_OWNER, CODE_USER_HAS_PROFILE_OWNER, CODE_USER_NOT_RUNNING,
1337 CODE_USER_SETUP_COMPLETED, CODE_NOT_SYSTEM_USER, CODE_HAS_PAIRED,
1338 CODE_MANAGED_USERS_NOT_SUPPORTED, CODE_SYSTEM_USER, CODE_CANNOT_ADD_MANAGED_PROFILE,
1339 CODE_NOT_SYSTEM_USER_SPLIT, CODE_DEVICE_ADMIN_NOT_SUPPORTED,
Esteban Talavera01576862016-12-15 11:16:44 +00001340 CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER, CODE_ADD_MANAGED_PROFILE_DISALLOWED})
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001341 public @interface ProvisioningPreCondition {}
1342
1343 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001344 * Return true if the given administrator component is currently active (enabled) in the system.
1345 *
1346 * @param admin The administrator component to check for.
1347 * @return {@code true} if {@code admin} is currently enabled in the system, {@code false}
1348 * otherwise
Dianne Hackbornd6847842010-01-12 18:14:19 -08001349 */
Robin Lee25e26452015-06-02 09:56:29 -07001350 public boolean isAdminActive(@NonNull ComponentName admin) {
Charles He8c760562016-10-25 16:36:53 +01001351 throwIfParentInstance("isAdminActive");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001352 return isAdminActiveAsUser(admin, myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001353 }
1354
1355 /**
1356 * @see #isAdminActive(ComponentName)
1357 * @hide
1358 */
Robin Lee25e26452015-06-02 09:56:29 -07001359 public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001360 if (mService != null) {
1361 try {
Robin Lee25e26452015-06-02 09:56:29 -07001362 return mService.isAdminActive(admin, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001363 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001364 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001365 }
1366 }
1367 return false;
1368 }
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001369 /**
1370 * Return true if the given administrator component is currently being removed
1371 * for the user.
1372 * @hide
1373 */
Robin Lee25e26452015-06-02 09:56:29 -07001374 public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) {
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001375 if (mService != null) {
1376 try {
Robin Lee25e26452015-06-02 09:56:29 -07001377 return mService.isRemovingAdmin(admin, userId);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001378 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001379 throw e.rethrowFromSystemServer();
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001380 }
1381 }
1382 return false;
1383 }
1384
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001385
Dianne Hackbornd6847842010-01-12 18:14:19 -08001386 /**
Robin Lee25e26452015-06-02 09:56:29 -07001387 * Return a list of all currently active device administrators' component
1388 * names. If there are no administrators {@code null} may be
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001389 * returned.
1390 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07001391 public @Nullable List<ComponentName> getActiveAdmins() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001392 throwIfParentInstance("getActiveAdmins");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001393 return getActiveAdminsAsUser(myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001394 }
1395
1396 /**
1397 * @see #getActiveAdmins()
1398 * @hide
1399 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07001400 public @Nullable List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001401 if (mService != null) {
1402 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001403 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001404 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001405 throw e.rethrowFromSystemServer();
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001406 }
1407 }
1408 return null;
1409 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001410
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001411 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001412 * Used by package administration code to determine if a package can be stopped
1413 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001414 * @hide
1415 */
1416 public boolean packageHasActiveAdmins(String packageName) {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001417 return packageHasActiveAdmins(packageName, myUserId());
1418 }
1419
1420 /**
1421 * Used by package administration code to determine if a package can be stopped
1422 * or uninstalled.
1423 * @hide
1424 */
1425 public boolean packageHasActiveAdmins(String packageName, int userId) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001426 if (mService != null) {
1427 try {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001428 return mService.packageHasActiveAdmins(packageName, userId);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001429 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001430 throw e.rethrowFromSystemServer();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001431 }
1432 }
1433 return false;
1434 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001435
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001436 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001437 * Remove a current administration component. This can only be called
1438 * by the application that owns the administration component; if you
1439 * try to remove someone else's component, a security exception will be
1440 * thrown.
Esteban Talavera552a5612016-02-19 17:02:24 +00001441 *
1442 * <p>Note that the operation is not synchronous and the admin might still be active (as
1443 * indicated by {@link #getActiveAdmins()}) by the time this method returns.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001444 *
1445 * @param admin The administration compononent to remove.
1446 * @throws SecurityException if the caller is not in the owner application of {@code admin}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001447 */
Robin Lee25e26452015-06-02 09:56:29 -07001448 public void removeActiveAdmin(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001449 throwIfParentInstance("removeActiveAdmin");
Dianne Hackbornd6847842010-01-12 18:14:19 -08001450 if (mService != null) {
1451 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001452 mService.removeActiveAdmin(admin, myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001453 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001454 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001455 }
1456 }
1457 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001458
Dianne Hackbornd6847842010-01-12 18:14:19 -08001459 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001460 * Returns true if an administrator has been granted a particular device policy. This can be
1461 * used to check whether the administrator was activated under an earlier set of policies, but
1462 * requires additional policies after an upgrade.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001463 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001464 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be an
1465 * active administrator, or an exception will be thrown.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001466 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001467 * @throws SecurityException if {@code admin} is not an active administrator.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001468 */
Robin Lee25e26452015-06-02 09:56:29 -07001469 public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001470 throwIfParentInstance("hasGrantedPolicy");
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001471 if (mService != null) {
1472 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001473 return mService.hasGrantedPolicy(admin, usesPolicy, myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001474 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001475 throw e.rethrowFromSystemServer();
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001476 }
1477 }
1478 return false;
1479 }
1480
1481 /**
Clara Bayarria1771112015-12-18 16:29:18 +00001482 * Returns true if the Profile Challenge is available to use for the given profile user.
1483 *
1484 * @hide
1485 */
1486 public boolean isSeparateProfileChallengeAllowed(int userHandle) {
1487 if (mService != null) {
1488 try {
1489 return mService.isSeparateProfileChallengeAllowed(userHandle);
1490 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001491 throw e.rethrowFromSystemServer();
Clara Bayarria1771112015-12-18 16:29:18 +00001492 }
1493 }
1494 return false;
1495 }
1496
1497 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001498 * Constant for {@link #setPasswordQuality}: the policy has no requirements
1499 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001500 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001501 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001502 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001503
Dianne Hackbornd6847842010-01-12 18:14:19 -08001504 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -07001505 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
1506 * recognition technology. This implies technologies that can recognize the identity of
1507 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
1508 * Note that quality constants are ordered so that higher values are more restrictive.
1509 */
1510 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
1511
1512 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001513 * Constant for {@link #setPasswordQuality}: the policy requires some kind
Benjamin Franzc6a96532015-06-16 11:23:38 +01001514 * of password or pattern, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001515 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001516 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001517 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001518
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001519 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001520 * Constant for {@link #setPasswordQuality}: the user must have entered a
1521 * password containing at least numeric characters. Note that quality
1522 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001523 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001524 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001525
Dianne Hackbornd6847842010-01-12 18:14:19 -08001526 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001527 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -08001528 * password containing at least numeric characters with no repeating (4444)
1529 * or ordered (1234, 4321, 2468) sequences. Note that quality
1530 * constants are ordered so that higher values are more restrictive.
1531 */
1532 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
1533
1534 /**
1535 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001536 * password containing at least alphabetic (or other symbol) characters.
1537 * Note that quality constants are ordered so that higher values are more
1538 * restrictive.
1539 */
1540 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001541
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001542 /**
1543 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001544 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001545 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001546 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001547 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001548 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001549
Dianne Hackbornd6847842010-01-12 18:14:19 -08001550 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001551 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001552 * password containing at least a letter, a numerical digit and a special
1553 * symbol, by default. With this password quality, passwords can be
1554 * restricted to contain various sets of characters, like at least an
1555 * uppercase letter, etc. These are specified using various methods,
1556 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
1557 * that quality constants are ordered so that higher values are more
1558 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001559 */
1560 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
1561
1562 /**
Oleksandr Peletskyi0fdcd3d2016-01-13 16:49:56 +01001563 * Constant for {@link #setPasswordQuality}: the user is not allowed to
1564 * modify password. In case this password quality is set, the password is
1565 * managed by a profile owner. The profile owner can set any password,
1566 * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note
1567 * that quality constants are ordered so that higher values are more
1568 * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is
1569 * the highest.
1570 * @hide
1571 */
1572 public static final int PASSWORD_QUALITY_MANAGED = 0x80000;
1573
1574 /**
Makoto Onuki5e7e06702016-09-01 18:02:01 -07001575 * @hide
1576 *
1577 * adb shell dpm set-{device,profile}-owner will normally not allow installing an owner to
1578 * a user with accounts. {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED}
1579 * and {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} are the account features
1580 * used by authenticator to exempt their accounts from this:
1581 *
1582 * <ul>
1583 * <li>Non-test-only DO/PO still can't be installed when there are accounts.
1584 * <p>In order to make an apk test-only, add android:testOnly="true" to the
1585 * &lt;application&gt; tag in the manifest.
1586 *
1587 * <li>Test-only DO/PO can be installed even when there are accounts, as long as all the
1588 * accounts have the {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} feature.
1589 * Some authenticators claim to have any features, so to detect it, we also check
1590 * {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} and disallow installing
1591 * if any of the accounts have it.
1592 * </ul>
1593 */
1594 public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED =
1595 "android.account.DEVICE_OR_PROFILE_OWNER_ALLOWED";
1596
1597 /** @hide See {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} */
1598 public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED =
1599 "android.account.DEVICE_OR_PROFILE_OWNER_DISALLOWED";
1600
1601 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001602 * Called by an application that is administering the device to set the password restrictions it
1603 * is imposing. After setting this, the user will not be able to enter a new password that is
1604 * not at least as restrictive as what has been set. Note that the current password will remain
1605 * until the user has set a new one, so the change does not take place immediately. To prompt
1606 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
Esteban Talaverac1c83592016-02-17 17:56:15 +00001607 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after calling this method.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001608 * <p>
1609 * Quality constants are ordered so that higher values are more restrictive; thus the highest
1610 * requested quality constant (between the policy set here, the user's preference, and any other
1611 * considerations) is the one that is in effect.
1612 * <p>
1613 * The calling device admin must have requested
1614 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1615 * not, a security exception will be thrown.
1616 * <p>
1617 * This method can be called on the {@link DevicePolicyManager} instance returned by
1618 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1619 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001620 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001621 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001622 * @param quality The new desired quality. One of {@link #PASSWORD_QUALITY_UNSPECIFIED},
1623 * {@link #PASSWORD_QUALITY_SOMETHING}, {@link #PASSWORD_QUALITY_NUMERIC},
1624 * {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC},
1625 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} or {@link #PASSWORD_QUALITY_COMPLEX}.
1626 * @throws SecurityException if {@code admin} is not an active administrator or if {@code admin}
1627 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Dianne Hackbornd6847842010-01-12 18:14:19 -08001628 */
Robin Lee25e26452015-06-02 09:56:29 -07001629 public void setPasswordQuality(@NonNull ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001630 if (mService != null) {
1631 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001632 mService.setPasswordQuality(admin, quality, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001633 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001634 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001635 }
1636 }
1637 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001638
Dianne Hackbornd6847842010-01-12 18:14:19 -08001639 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001640 * Retrieve the current minimum password quality for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01001641 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00001642 * a separate challenge are not taken into account.
1643 *
1644 * <p>This method can be called on the {@link DevicePolicyManager} instance
1645 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1646 * restrictions on the parent profile.
1647 *
Robin Lee25e26452015-06-02 09:56:29 -07001648 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001649 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001650 */
Robin Lee25e26452015-06-02 09:56:29 -07001651 public int getPasswordQuality(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001652 return getPasswordQuality(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001653 }
1654
1655 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001656 public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001657 if (mService != null) {
1658 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001659 return mService.getPasswordQuality(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001660 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001661 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001662 }
1663 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001664 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001665 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001666
Dianne Hackbornd6847842010-01-12 18:14:19 -08001667 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001668 * Called by an application that is administering the device to set the minimum allowed password
1669 * length. After setting this, the user will not be able to enter a new password that is not at
1670 * least as restrictive as what has been set. Note that the current password will remain until
1671 * the user has set a new one, so the change does not take place immediately. To prompt the user
1672 * for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
1673 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
1674 * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC}
1675 * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC},
1676 * {@link #PASSWORD_QUALITY_ALPHANUMERIC}, or {@link #PASSWORD_QUALITY_COMPLEX} with
1677 * {@link #setPasswordQuality}.
1678 * <p>
1679 * The calling device admin must have requested
1680 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1681 * not, a security exception will be thrown.
1682 * <p>
1683 * This method can be called on the {@link DevicePolicyManager} instance returned by
1684 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1685 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001686 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001687 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001688 * @param length The new desired minimum password length. A value of 0 means there is no
1689 * restriction.
1690 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1691 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Dianne Hackbornd6847842010-01-12 18:14:19 -08001692 */
Robin Lee25e26452015-06-02 09:56:29 -07001693 public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001694 if (mService != null) {
1695 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001696 mService.setPasswordMinimumLength(admin, length, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001697 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001698 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001699 }
1700 }
1701 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001702
Dianne Hackbornd6847842010-01-12 18:14:19 -08001703 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001704 * Retrieve the current minimum password length for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01001705 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00001706 * a separate challenge are not taken into account.
1707 *
1708 * <p>This method can be called on the {@link DevicePolicyManager} instance
1709 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1710 * restrictions on the parent profile.
1711 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001712 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001713 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001714 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001715 */
Robin Lee25e26452015-06-02 09:56:29 -07001716 public int getPasswordMinimumLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001717 return getPasswordMinimumLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001718 }
1719
1720 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001721 public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001722 if (mService != null) {
1723 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001724 return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001725 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001726 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001727 }
1728 }
1729 return 0;
1730 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001731
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001732 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001733 * Called by an application that is administering the device to set the minimum number of upper
1734 * case letters required in the password. After setting this, the user will not be able to enter
1735 * a new password that is not at least as restrictive as what has been set. Note that the
1736 * current password will remain until the user has set a new one, so the change does not take
1737 * place immediately. To prompt the user for a new password, use
1738 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
1739 * setting this value. This constraint is only imposed if the administrator has also requested
1740 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001741 * <p>
1742 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001743 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1744 * not, a security exception will be thrown.
1745 * <p>
1746 * This method can be called on the {@link DevicePolicyManager} instance returned by
1747 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1748 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001749 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001750 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1751 * @param length The new desired minimum number of upper case letters required in the password.
1752 * A value of 0 means there is no restriction.
1753 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1754 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001755 */
Robin Lee25e26452015-06-02 09:56:29 -07001756 public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001757 if (mService != null) {
1758 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001759 mService.setPasswordMinimumUpperCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001760 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001761 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001762 }
1763 }
1764 }
1765
1766 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001767 * Retrieve the current number of upper case letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01001768 * for a particular admin or all admins that set restrictions on this user and
Esteban Talaverac1c83592016-02-17 17:56:15 +00001769 * its participating profiles. Restrictions on profiles that have a separate challenge
1770 * are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001771 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001772 * {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001773 * and only applies when the password quality is
1774 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001775 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001776 * <p>This method can be called on the {@link DevicePolicyManager} instance
1777 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1778 * restrictions on the parent profile.
1779 *
Robin Lee25e26452015-06-02 09:56:29 -07001780 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001781 * aggregate all admins.
1782 * @return The minimum number of upper case letters required in the
1783 * password.
1784 */
Robin Lee25e26452015-06-02 09:56:29 -07001785 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001786 return getPasswordMinimumUpperCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001787 }
1788
1789 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001790 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001791 if (mService != null) {
1792 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001793 return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001794 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001795 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001796 }
1797 }
1798 return 0;
1799 }
1800
1801 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001802 * Called by an application that is administering the device to set the minimum number of lower
1803 * case letters required in the password. After setting this, the user will not be able to enter
1804 * a new password that is not at least as restrictive as what has been set. Note that the
1805 * current password will remain until the user has set a new one, so the change does not take
1806 * place immediately. To prompt the user for a new password, use
1807 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
1808 * setting this value. This constraint is only imposed if the administrator has also requested
1809 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001810 * <p>
1811 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001812 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1813 * not, a security exception will be thrown.
1814 * <p>
1815 * This method can be called on the {@link DevicePolicyManager} instance returned by
1816 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1817 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001818 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001819 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1820 * @param length The new desired minimum number of lower case letters required in the password.
1821 * A value of 0 means there is no restriction.
1822 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1823 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001824 */
Robin Lee25e26452015-06-02 09:56:29 -07001825 public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001826 if (mService != null) {
1827 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001828 mService.setPasswordMinimumLowerCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001829 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001830 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001831 }
1832 }
1833 }
1834
1835 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001836 * Retrieve the current number of lower case letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01001837 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00001838 * and its participating profiles. Restrictions on profiles that have
1839 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001840 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001841 * {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001842 * and only applies when the password quality is
1843 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001844 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001845 * <p>This method can be called on the {@link DevicePolicyManager} instance
1846 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1847 * restrictions on the parent profile.
1848 *
Robin Lee25e26452015-06-02 09:56:29 -07001849 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001850 * aggregate all admins.
1851 * @return The minimum number of lower case letters required in the
1852 * password.
1853 */
Robin Lee25e26452015-06-02 09:56:29 -07001854 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001855 return getPasswordMinimumLowerCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001856 }
1857
1858 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001859 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001860 if (mService != null) {
1861 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001862 return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001863 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001864 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001865 }
1866 }
1867 return 0;
1868 }
1869
1870 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001871 * Called by an application that is administering the device to set the minimum number of
1872 * letters required in the password. After setting this, the user will not be able to enter a
1873 * new password that is not at least as restrictive as what has been set. Note that the current
1874 * password will remain until the user has set a new one, so the change does not take place
1875 * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
1876 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
1877 * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1878 * {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001879 * <p>
1880 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001881 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1882 * not, a security exception will be thrown.
1883 * <p>
1884 * This method can be called on the {@link DevicePolicyManager} instance returned by
1885 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1886 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001887 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001888 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1889 * @param length The new desired minimum number of letters required in the password. A value of
1890 * 0 means there is no restriction.
1891 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1892 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001893 */
Robin Lee25e26452015-06-02 09:56:29 -07001894 public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001895 if (mService != null) {
1896 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001897 mService.setPasswordMinimumLetters(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001898 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001899 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001900 }
1901 }
1902 }
1903
1904 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001905 * Retrieve the current number of letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01001906 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00001907 * and its participating profiles. Restrictions on profiles that have
1908 * a separate challenge are not taken into account.
1909 * This is the same value as set by
1910 * {@link #setPasswordMinimumLetters(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001911 * and only applies when the password quality is
1912 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001913 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001914 * <p>This method can be called on the {@link DevicePolicyManager} instance
1915 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1916 * restrictions on the parent profile.
1917 *
Robin Lee25e26452015-06-02 09:56:29 -07001918 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001919 * aggregate all admins.
1920 * @return The minimum number of letters required in the password.
1921 */
Robin Lee25e26452015-06-02 09:56:29 -07001922 public int getPasswordMinimumLetters(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001923 return getPasswordMinimumLetters(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001924 }
1925
1926 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001927 public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001928 if (mService != null) {
1929 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001930 return mService.getPasswordMinimumLetters(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001931 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001932 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001933 }
1934 }
1935 return 0;
1936 }
1937
1938 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001939 * Called by an application that is administering the device to set the minimum number of
1940 * numerical digits required in the password. After setting this, the user will not be able to
1941 * enter a new password that is not at least as restrictive as what has been set. Note that the
1942 * current password will remain until the user has set a new one, so the change does not take
1943 * place immediately. To prompt the user for a new password, use
1944 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
1945 * setting this value. This constraint is only imposed if the administrator has also requested
1946 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001947 * <p>
1948 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001949 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1950 * not, a security exception will be thrown.
1951 * <p>
1952 * This method can be called on the {@link DevicePolicyManager} instance returned by
1953 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1954 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001955 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001956 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1957 * @param length The new desired minimum number of numerical digits required in the password. A
1958 * value of 0 means there is no restriction.
1959 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1960 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001961 */
Robin Lee25e26452015-06-02 09:56:29 -07001962 public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001963 if (mService != null) {
1964 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001965 mService.setPasswordMinimumNumeric(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001966 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001967 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001968 }
1969 }
1970 }
1971
1972 /**
1973 * Retrieve the current number of numerical digits required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01001974 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00001975 * and its participating profiles. Restrictions on profiles that have
1976 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001977 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001978 * {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001979 * and only applies when the password quality is
1980 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001981 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001982 * <p>This method can be called on the {@link DevicePolicyManager} instance
1983 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1984 * restrictions on the parent profile.
1985 *
Robin Lee25e26452015-06-02 09:56:29 -07001986 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001987 * aggregate all admins.
1988 * @return The minimum number of numerical digits required in the password.
1989 */
Robin Lee25e26452015-06-02 09:56:29 -07001990 public int getPasswordMinimumNumeric(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001991 return getPasswordMinimumNumeric(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001992 }
1993
1994 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001995 public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001996 if (mService != null) {
1997 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001998 return mService.getPasswordMinimumNumeric(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001999 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002000 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002001 }
2002 }
2003 return 0;
2004 }
2005
2006 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002007 * Called by an application that is administering the device to set the minimum number of
2008 * symbols required in the password. After setting this, the user will not be able to enter a
2009 * new password that is not at least as restrictive as what has been set. Note that the current
2010 * password will remain until the user has set a new one, so the change does not take place
2011 * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
2012 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
2013 * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
2014 * {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002015 * <p>
2016 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002017 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2018 * not, a security exception will be thrown.
2019 * <p>
2020 * This method can be called on the {@link DevicePolicyManager} instance returned by
2021 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2022 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002023 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002024 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2025 * @param length The new desired minimum number of symbols required in the password. A value of
2026 * 0 means there is no restriction.
2027 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2028 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002029 */
Robin Lee25e26452015-06-02 09:56:29 -07002030 public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002031 if (mService != null) {
2032 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002033 mService.setPasswordMinimumSymbols(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002034 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002035 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002036 }
2037 }
2038 }
2039
2040 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002041 * Retrieve the current number of symbols required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002042 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002043 * and its participating profiles. Restrictions on profiles that have
2044 * a separate challenge are not taken into account. This is the same value as
2045 * set by {@link #setPasswordMinimumSymbols(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002046 * and only applies when the password quality is
2047 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002048 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002049 * <p>This method can be called on the {@link DevicePolicyManager} instance
2050 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2051 * restrictions on the parent profile.
2052 *
Robin Lee25e26452015-06-02 09:56:29 -07002053 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002054 * aggregate all admins.
2055 * @return The minimum number of symbols required in the password.
2056 */
Robin Lee25e26452015-06-02 09:56:29 -07002057 public int getPasswordMinimumSymbols(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002058 return getPasswordMinimumSymbols(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002059 }
2060
2061 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002062 public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002063 if (mService != null) {
2064 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002065 return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002066 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002067 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002068 }
2069 }
2070 return 0;
2071 }
2072
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002073 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002074 * Called by an application that is administering the device to set the minimum number of
2075 * non-letter characters (numerical digits or symbols) required in the password. After setting
2076 * this, the user will not be able to enter a new password that is not at least as restrictive
2077 * as what has been set. Note that the current password will remain until the user has set a new
2078 * one, so the change does not take place immediately. To prompt the user for a new password,
2079 * use {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
2080 * setting this value. This constraint is only imposed if the administrator has also requested
2081 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002082 * <p>
2083 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002084 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2085 * not, a security exception will be thrown.
2086 * <p>
2087 * This method can be called on the {@link DevicePolicyManager} instance returned by
2088 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2089 * profile.
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002090 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002091 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2092 * @param length The new desired minimum number of letters required in the password. A value of
2093 * 0 means there is no restriction.
2094 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2095 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002096 */
Robin Lee25e26452015-06-02 09:56:29 -07002097 public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002098 if (mService != null) {
2099 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002100 mService.setPasswordMinimumNonLetter(admin, length, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002101 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002102 throw e.rethrowFromSystemServer();
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002103 }
2104 }
2105 }
2106
2107 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002108 * Retrieve the current number of non-letter characters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002109 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002110 * and its participating profiles. Restrictions on profiles that have
2111 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01002112 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00002113 * {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002114 * and only applies when the password quality is
2115 * {@link #PASSWORD_QUALITY_COMPLEX}.
2116 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002117 * <p>This method can be called on the {@link DevicePolicyManager} instance
2118 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2119 * restrictions on the parent profile.
2120 *
Robin Lee25e26452015-06-02 09:56:29 -07002121 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002122 * aggregate all admins.
2123 * @return The minimum number of letters required in the password.
2124 */
Robin Lee25e26452015-06-02 09:56:29 -07002125 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002126 return getPasswordMinimumNonLetter(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002127 }
2128
2129 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002130 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002131 if (mService != null) {
2132 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002133 return mService.getPasswordMinimumNonLetter(admin, userHandle, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002134 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002135 throw e.rethrowFromSystemServer();
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002136 }
2137 }
2138 return 0;
2139 }
2140
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002141 /**
2142 * Called by an application that is administering the device to set the length of the password
2143 * history. After setting this, the user will not be able to enter a new password that is the
2144 * same as any password in the history. Note that the current password will remain until the
2145 * user has set a new one, so the change does not take place immediately. To prompt the user for
2146 * a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
2147 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
2148 * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC}
2149 * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX} {@link #PASSWORD_QUALITY_ALPHABETIC}, or
2150 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} with {@link #setPasswordQuality}.
2151 * <p>
2152 * The calling device admin must have requested
2153 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2154 * not, a security exception will be thrown.
2155 * <p>
2156 * This method can be called on the {@link DevicePolicyManager} instance returned by
2157 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2158 * profile.
2159 *
2160 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2161 * @param length The new desired length of password history. A value of 0 means there is no
2162 * restriction.
2163 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2164 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
2165 */
Robin Lee25e26452015-06-02 09:56:29 -07002166 public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002167 if (mService != null) {
2168 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002169 mService.setPasswordHistoryLength(admin, length, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002170 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002171 throw e.rethrowFromSystemServer();
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002172 }
2173 }
2174 }
2175
2176 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002177 * Called by a device admin to set the password expiration timeout. Calling this method will
2178 * restart the countdown for password expiration for the given admin, as will changing the
2179 * device password (for all admins).
2180 * <p>
2181 * The provided timeout is the time delta in ms and will be added to the current time. For
2182 * example, to have the password expire 5 days from now, timeout would be 5 * 86400 * 1000 =
2183 * 432000000 ms for timeout.
2184 * <p>
2185 * To disable password expiration, a value of 0 may be used for timeout.
2186 * <p>
2187 * The calling device admin must have requested
2188 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this method; if it has
2189 * not, a security exception will be thrown.
2190 * <p>
2191 * Note that setting the password will automatically reset the expiration time for all active
2192 * admins. Active admins do not need to explicitly call this method in that case.
2193 * <p>
2194 * This method can be called on the {@link DevicePolicyManager} instance returned by
2195 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2196 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002197 *
Jim Millera4e28d12010-11-08 16:15:47 -08002198 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002199 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0 means
2200 * there is no restriction (unlimited).
2201 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2202 * does not use {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD}
Jim Millera4e28d12010-11-08 16:15:47 -08002203 */
Robin Lee25e26452015-06-02 09:56:29 -07002204 public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) {
Jim Millera4e28d12010-11-08 16:15:47 -08002205 if (mService != null) {
2206 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002207 mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08002208 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002209 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08002210 }
2211 }
2212 }
2213
2214 /**
Jim Miller6b857682011-02-16 16:27:41 -08002215 * Get the password expiration timeout for the given admin. The expiration timeout is the
2216 * recurring expiration timeout provided in the call to
2217 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
Esteban Talaverac1c83592016-02-17 17:56:15 +00002218 * aggregate of all participating policy administrators if {@code admin} is null. Admins that
2219 * have set restrictions on profiles that have a separate challenge are not taken into account.
2220 *
2221 * <p>This method can be called on the {@link DevicePolicyManager} instance
2222 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2223 * restrictions on the parent profile.
Jim Millera4e28d12010-11-08 16:15:47 -08002224 *
Robin Lee25e26452015-06-02 09:56:29 -07002225 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08002226 * @return The timeout for the given admin or the minimum of all timeouts
2227 */
Robin Lee25e26452015-06-02 09:56:29 -07002228 public long getPasswordExpirationTimeout(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08002229 if (mService != null) {
2230 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002231 return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08002232 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002233 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08002234 }
2235 }
2236 return 0;
2237 }
2238
2239 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002240 * Get the current password expiration time for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01002241 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00002242 * a separate challenge are not taken into account. If admin is {@code null}, then a composite
2243 * of all expiration times is returned - which will be the minimum of all of them.
2244 *
2245 * <p>This method can be called on the {@link DevicePolicyManager} instance
2246 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2247 * the password expiration for the parent profile.
Jim Millera4e28d12010-11-08 16:15:47 -08002248 *
Robin Lee25e26452015-06-02 09:56:29 -07002249 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002250 * @return The password expiration time, in milliseconds since epoch.
Jim Millera4e28d12010-11-08 16:15:47 -08002251 */
Robin Lee25e26452015-06-02 09:56:29 -07002252 public long getPasswordExpiration(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08002253 if (mService != null) {
2254 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002255 return mService.getPasswordExpiration(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08002256 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002257 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08002258 }
2259 }
2260 return 0;
2261 }
2262
2263 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002264 * Retrieve the current password history length for a particular admin or all admins that
Rubin Xud3609d42016-07-13 18:32:57 +01002265 * set restrictions on this user and its participating profiles. Restrictions on profiles that
Esteban Talaverac1c83592016-02-17 17:56:15 +00002266 * have a separate challenge are not taken into account.
2267 *
2268 * <p>This method can be called on the {@link DevicePolicyManager} instance
2269 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2270 * restrictions on the parent profile.
2271 *
Robin Lee25e26452015-06-02 09:56:29 -07002272 * @param admin The name of the admin component to check, or {@code null} to aggregate
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002273 * all admins.
2274 * @return The length of the password history
2275 */
Robin Lee25e26452015-06-02 09:56:29 -07002276 public int getPasswordHistoryLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002277 return getPasswordHistoryLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002278 }
2279
2280 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002281 public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002282 if (mService != null) {
2283 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002284 return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002285 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002286 throw e.rethrowFromSystemServer();
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002287 }
2288 }
2289 return 0;
2290 }
2291
Dianne Hackbornd6847842010-01-12 18:14:19 -08002292 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08002293 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08002294 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08002295 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08002296 * @return Returns the maximum length that the user can enter.
2297 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08002298 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08002299 // Kind-of arbitrary.
2300 return 16;
2301 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002302
Dianne Hackborn254cb442010-01-27 19:23:59 -08002303 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002304 * Determine whether the current password the user has set is sufficient to meet the policy
2305 * requirements (e.g. quality, minimum length) that have been requested by the admins of this
2306 * user and its participating profiles. Restrictions on profiles that have a separate challenge
2307 * are not taken into account.
2308 * <p>
2309 * The calling device admin must have requested
2310 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2311 * not, a security exception will be thrown.
2312 * <p>
2313 * This method can be called on the {@link DevicePolicyManager} instance returned by
2314 * {@link #getParentProfileInstance(ComponentName)} in order to determine if the password set on
2315 * the parent profile is sufficient.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002316 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01002317 * @return Returns true if the password meets the current requirements, else false.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002318 * @throws SecurityException if the calling application does not own an active administrator
2319 * that uses {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002320 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002321 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002322 if (mService != null) {
2323 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00002324 return mService.isActivePasswordSufficient(myUserId(), mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002325 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002326 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002327 }
2328 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002329 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08002330 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002331
Dianne Hackbornd6847842010-01-12 18:14:19 -08002332 /**
Clara Bayarrid7693912016-01-22 17:26:31 +00002333 * Determine whether the current profile password the user has set is sufficient
Esteban Talaverac1c83592016-02-17 17:56:15 +00002334 * to meet the policy requirements (e.g. quality, minimum length) that have been
Clara Bayarrid7693912016-01-22 17:26:31 +00002335 * requested by the admins of the parent user and its profiles.
2336 *
2337 * @param userHandle the userId of the profile to check the password for.
2338 * @return Returns true if the password would meet the current requirements, else false.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002339 * @throws SecurityException if {@code userHandle} is not a managed profile.
Clara Bayarrid7693912016-01-22 17:26:31 +00002340 * @hide
2341 */
2342 public boolean isProfileActivePasswordSufficientForParent(int userHandle) {
2343 if (mService != null) {
2344 try {
2345 return mService.isProfileActivePasswordSufficientForParent(userHandle);
2346 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002347 throw e.rethrowFromSystemServer();
Clara Bayarrid7693912016-01-22 17:26:31 +00002348 }
2349 }
2350 return false;
2351 }
2352
2353 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002354 * Retrieve the number of times the user has failed at entering a password since that last
2355 * successful password entry.
2356 * <p>
2357 * This method can be called on the {@link DevicePolicyManager} instance returned by
2358 * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the number of failed
2359 * password attemts for the parent user.
2360 * <p>
2361 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN}
2362 * to be able to call this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002363 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002364 * @return The number of times user has entered an incorrect password since the last correct
2365 * password entry.
2366 * @throws SecurityException if the calling application does not own an active administrator
2367 * that uses {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002368 */
2369 public int getCurrentFailedPasswordAttempts() {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00002370 return getCurrentFailedPasswordAttempts(myUserId());
2371 }
2372
2373 /**
2374 * Retrieve the number of times the given user has failed at entering a
2375 * password since that last successful password entry.
2376 *
2377 * <p>The calling device admin must have requested
2378 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call this method; if it has
2379 * not and it is not the system uid, a security exception will be thrown.
2380 *
2381 * @hide
2382 */
2383 public int getCurrentFailedPasswordAttempts(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002384 if (mService != null) {
2385 try {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00002386 return mService.getCurrentFailedPasswordAttempts(userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002387 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002388 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002389 }
2390 }
2391 return -1;
2392 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002393
2394 /**
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002395 * Queries whether {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002396 *
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002397 * @return true if RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002398 * @hide
2399 */
2400 public boolean getDoNotAskCredentialsOnBoot() {
2401 if (mService != null) {
2402 try {
2403 return mService.getDoNotAskCredentialsOnBoot();
2404 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002405 throw e.rethrowFromSystemServer();
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002406 }
2407 }
2408 return false;
2409 }
2410
2411 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002412 * Setting this to a value greater than zero enables a built-in policy that will perform a
2413 * device or profile wipe after too many incorrect device-unlock passwords have been entered.
2414 * This built-in policy combines watching for failed passwords and wiping the device, and
2415 * requires that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002416 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002417 * <p>
2418 * To implement any other policy (e.g. wiping data for a particular application only, erasing or
2419 * revoking credentials, or reporting the failure to a server), you should implement
2420 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} instead. Do not
2421 * use this API, because if the maximum count is reached, the device or profile will be wiped
2422 * immediately, and your callback will not be invoked.
2423 * <p>
2424 * This method can be called on the {@link DevicePolicyManager} instance returned by
2425 * {@link #getParentProfileInstance(ComponentName)} in order to set a value on the parent
2426 * profile.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002427 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002428 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002429 * @param num The number of failed password attempts at which point the device or profile will
2430 * be wiped.
2431 * @throws SecurityException if {@code admin} is not an active administrator or does not use
2432 * both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
2433 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002434 */
Robin Lee25e26452015-06-02 09:56:29 -07002435 public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002436 if (mService != null) {
2437 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002438 mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002439 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002440 throw e.rethrowFromSystemServer();
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002441 }
2442 }
2443 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002444
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002445 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002446 * Retrieve the current maximum number of login attempts that are allowed before the device
Rubin Xud3609d42016-07-13 18:32:57 +01002447 * or profile is wiped, for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002448 * and its participating profiles. Restrictions on profiles that have a separate challenge are
2449 * not taken into account.
2450 *
2451 * <p>This method can be called on the {@link DevicePolicyManager} instance
2452 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2453 * the value for the parent profile.
2454 *
Robin Lee25e26452015-06-02 09:56:29 -07002455 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002456 * all admins.
2457 */
Robin Lee25e26452015-06-02 09:56:29 -07002458 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002459 return getMaximumFailedPasswordsForWipe(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002460 }
2461
2462 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002463 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08002464 if (mService != null) {
2465 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002466 return mService.getMaximumFailedPasswordsForWipe(
2467 admin, userHandle, mParentInstance);
Dianne Hackborn254cb442010-01-27 19:23:59 -08002468 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002469 throw e.rethrowFromSystemServer();
Dianne Hackborn254cb442010-01-27 19:23:59 -08002470 }
2471 }
2472 return 0;
2473 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002474
Dianne Hackborn254cb442010-01-27 19:23:59 -08002475 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002476 * Returns the profile with the smallest maximum failed passwords for wipe,
2477 * for the given user. So for primary user, it might return the primary or
2478 * a managed profile. For a secondary user, it would be the same as the
2479 * user passed in.
2480 * @hide Used only by Keyguard
2481 */
2482 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
2483 if (mService != null) {
2484 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002485 return mService.getProfileWithMinimumFailedPasswordsForWipe(
2486 userHandle, mParentInstance);
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002487 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002488 throw e.rethrowFromSystemServer();
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002489 }
2490 }
2491 return UserHandle.USER_NULL;
2492 }
2493
2494 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002495 * Flag for {@link #resetPassword}: don't allow other admins to change
2496 * the password again until the user has entered it.
2497 */
2498 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002499
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002500 /**
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002501 * Flag for {@link #resetPassword}: don't ask for user credentials on device boot.
2502 * If the flag is set, the device can be booted without asking for user password.
2503 * The absence of this flag does not change the current boot requirements. This flag
2504 * can be set by the device owner only. If the app is not the device owner, the flag
2505 * is ignored. Once the flag is set, it cannot be reverted back without resetting the
2506 * device to factory defaults.
2507 */
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002508 public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002;
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002509
2510 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002511 * Force a new device unlock password (the password needed to access the entire device, not for
2512 * individual accounts) on the user. This takes effect immediately.
2513 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002514 * <em>Note: This API has been limited as of {@link android.os.Build.VERSION_CODES#N} for
Makoto Onuki70f929e2015-11-11 12:40:15 -08002515 * device admins that are not device owner and not profile owner.
2516 * The password can now only be changed if there is currently no password set. Device owner
Ricky Wai977ade22016-05-24 15:02:41 +01002517 * and profile owner can still do this when user is unlocked and does not have a managed
2518 * profile.</em>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002519 * <p>
2520 * The given password must be sufficient for the current password quality and length constraints
2521 * as returned by {@link #getPasswordQuality(ComponentName)} and
2522 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then
2523 * it will be rejected and false returned. Note that the password may be a stronger quality
2524 * (containing alphanumeric characters when the requested quality is only numeric), in which
2525 * case the currently active quality will be increased to match.
2526 * <p>
2527 * Calling with a null or empty password will clear any existing PIN, pattern or password if the
Robin Leece5c4002016-03-23 17:05:03 +00002528 * current password constraints allow it. <em>Note: This will not work in
2529 * {@link android.os.Build.VERSION_CODES#N} and later for managed profiles, or for device admins
2530 * that are not device owner or profile owner. Once set, the password cannot be changed to null
2531 * or empty except by these admins.</em>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002532 * <p>
2533 * The calling device admin must have requested
2534 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call this method; if it has
2535 * not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002536 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01002537 * @param password The new password for the user. Null or empty clears the password.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002538 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002539 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
2540 * @return Returns true if the password was applied, or false if it is not acceptable for the
2541 * current constraints or if the user has not been decrypted yet.
2542 * @throws SecurityException if the calling application does not own an active administrator
2543 * that uses {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD}
Ricky Wai977ade22016-05-24 15:02:41 +01002544 * @throws IllegalStateException if the calling user is locked or has a managed profile.
Andrew Scull3f81f4e2016-07-29 16:29:58 +01002545 * @throws IllegalArgumentException if the password does not meet system requirements.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002546 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002547 public boolean resetPassword(String password, int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002548 throwIfParentInstance("resetPassword");
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002549 if (mService != null) {
2550 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002551 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002552 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002553 throw e.rethrowFromSystemServer();
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002554 }
2555 }
2556 return false;
2557 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002558
Dianne Hackbornd6847842010-01-12 18:14:19 -08002559 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002560 * Called by an application that is administering the device to set the maximum time for user
2561 * activity until the device will lock. This limits the length that the user can set. It takes
2562 * effect immediately.
2563 * <p>
2564 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
2565 * to be able to call this method; if it has not, a security exception will be thrown.
2566 * <p>
2567 * This method can be called on the {@link DevicePolicyManager} instance returned by
2568 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2569 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002570 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002571 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002572 * @param timeMs The new desired maximum time to lock in milliseconds. A value of 0 means there
2573 * is no restriction.
2574 * @throws SecurityException if {@code admin} is not an active administrator or it does not use
2575 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002576 */
Robin Lee25e26452015-06-02 09:56:29 -07002577 public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002578 if (mService != null) {
2579 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002580 mService.setMaximumTimeToLock(admin, timeMs, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002581 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002582 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002583 }
2584 }
2585 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002586
Dianne Hackbornd6847842010-01-12 18:14:19 -08002587 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002588 * Retrieve the current maximum time to unlock for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01002589 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00002590 * a separate challenge are not taken into account.
2591 *
2592 * <p>This method can be called on the {@link DevicePolicyManager} instance
2593 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2594 * restrictions on the parent profile.
2595 *
Robin Lee25e26452015-06-02 09:56:29 -07002596 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002597 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07002598 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07002599 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002600 */
Robin Lee25e26452015-06-02 09:56:29 -07002601 public long getMaximumTimeToLock(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002602 return getMaximumTimeToLock(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002603 }
2604
2605 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002606 public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002607 if (mService != null) {
2608 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002609 return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002610 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002611 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002612 }
2613 }
2614 return 0;
2615 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002616
Dianne Hackbornd6847842010-01-12 18:14:19 -08002617 /**
Ricky Wai035e9242016-03-18 16:43:31 +00002618 * Returns maximum time to lock that applied by all profiles in this user. We do this because we
2619 * do not have a separate timeout to lock for work challenge only.
2620 *
2621 * @hide
2622 */
2623 public long getMaximumTimeToLockForUserAndProfiles(int userHandle) {
2624 if (mService != null) {
2625 try {
2626 return mService.getMaximumTimeToLockForUserAndProfiles(userHandle);
2627 } catch (RemoteException e) {
2628 throw e.rethrowFromSystemServer();
2629 }
2630 }
2631 return 0;
2632 }
2633
2634 /**
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002635 * Called by a device/profile owner to set the timeout after which unlocking with secondary, non
2636 * strong auth (e.g. fingerprint, trust agents) times out, i.e. the user has to use a strong
2637 * authentication method like password, pin or pattern.
2638 *
2639 * <p>This timeout is used internally to reset the timer to require strong auth again after
2640 * specified timeout each time it has been successfully used.
2641 *
2642 * <p>Fingerprint can also be disabled altogether using {@link #KEYGUARD_DISABLE_FINGERPRINT}.
2643 *
2644 * <p>Trust agents can also be disabled altogether using {@link #KEYGUARD_DISABLE_TRUST_AGENTS}.
2645 *
2646 * <p>The calling device admin must be a device or profile owner. If it is not,
2647 * a {@link SecurityException} will be thrown.
2648 *
Michal Karpinski943aabd2016-10-06 11:09:25 +01002649 * <p>The calling device admin can verify the value it has set by calling
2650 * {@link #getRequiredStrongAuthTimeout(ComponentName)} and passing in its instance.
2651 *
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002652 * <p>This method can be called on the {@link DevicePolicyManager} instance returned by
2653 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2654 * profile.
2655 *
2656 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2657 * @param timeoutMs The new timeout, after which the user will have to unlock with strong
Michal Karpinski943aabd2016-10-06 11:09:25 +01002658 * authentication method. A value of 0 means the admin is not participating in
2659 * controlling the timeout.
2660 * The minimum and maximum timeouts are platform-defined and are typically 1 hour and
2661 * 72 hours, respectively. Though discouraged, the admin may choose to require strong
2662 * auth at all times using {@link #KEYGUARD_DISABLE_FINGERPRINT} and/or
2663 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002664 *
2665 * @throws SecurityException if {@code admin} is not a device or profile owner.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002666 */
2667 public void setRequiredStrongAuthTimeout(@NonNull ComponentName admin,
2668 long timeoutMs) {
2669 if (mService != null) {
2670 try {
2671 mService.setRequiredStrongAuthTimeout(admin, timeoutMs, mParentInstance);
2672 } catch (RemoteException e) {
2673 throw e.rethrowFromSystemServer();
2674 }
2675 }
2676 }
2677
2678 /**
2679 * Determine for how long the user will be able to use secondary, non strong auth for
2680 * authentication, since last strong method authentication (password, pin or pattern) was used.
2681 * After the returned timeout the user is required to use strong authentication method.
2682 *
2683 * <p>This method can be called on the {@link DevicePolicyManager} instance
2684 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2685 * restrictions on the parent profile.
2686 *
2687 * @param admin The name of the admin component to check, or {@code null} to aggregate
2688 * accross all participating admins.
Michal Karpinski943aabd2016-10-06 11:09:25 +01002689 * @return The timeout or 0 if not configured for the provided admin.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002690 */
2691 public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin) {
2692 return getRequiredStrongAuthTimeout(admin, myUserId());
2693 }
2694
2695 /** @hide per-user version */
2696 public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin, @UserIdInt int userId) {
2697 if (mService != null) {
2698 try {
2699 return mService.getRequiredStrongAuthTimeout(admin, userId, mParentInstance);
2700 } catch (RemoteException e) {
2701 throw e.rethrowFromSystemServer();
2702 }
2703 }
2704 return DEFAULT_STRONG_AUTH_TIMEOUT_MS;
2705 }
2706
2707 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002708 * Make the device lock immediately, as if the lock screen timeout has expired at the point of
2709 * this call.
2710 * <p>
2711 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
2712 * to be able to call this method; if it has not, a security exception will be thrown.
2713 * <p>
2714 * This method can be called on the {@link DevicePolicyManager} instance returned by
2715 * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002716 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002717 * @throws SecurityException if the calling application does not own an active administrator
2718 * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002719 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002720 public void lockNow() {
2721 if (mService != null) {
2722 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002723 mService.lockNow(mParentInstance);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002724 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002725 throw e.rethrowFromSystemServer();
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002726 }
2727 }
2728 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002729
Dianne Hackbornd6847842010-01-12 18:14:19 -08002730 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07002731 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002732 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07002733 */
2734 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
2735
2736 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002737 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
2738 * data.
2739 *
Paul Crowley2934b262014-12-02 11:21:13 +00002740 * <p>This flag may only be set by device owner admins; if it is set by
2741 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002742 */
2743 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
2744
2745 /**
Suprabh Shukla556b05a2016-08-10 15:49:24 -07002746 * Ask that all user data be wiped. If called as a secondary user, the user will be removed and
2747 * other users will remain unaffected. Calling from the primary user will cause the device to
2748 * reboot, erasing all device data - including all the secondary users and their data - while
2749 * booting up.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002750 * <p>
2751 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to
2752 * be able to call this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002753 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002754 * @param flags Bit mask of additional options: currently supported flags are
2755 * {@link #WIPE_EXTERNAL_STORAGE} and {@link #WIPE_RESET_PROTECTION_DATA}.
2756 * @throws SecurityException if the calling application does not own an active administrator
2757 * that uses {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002758 */
2759 public void wipeData(int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002760 throwIfParentInstance("wipeData");
Dianne Hackbornd6847842010-01-12 18:14:19 -08002761 if (mService != null) {
2762 try {
Makoto Onuki70f929e2015-11-11 12:40:15 -08002763 mService.wipeData(flags);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002764 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002765 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002766 }
2767 }
2768 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002769
Dianne Hackbornd6847842010-01-12 18:14:19 -08002770 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07002771 * Called by an application that is administering the device to set the
2772 * global proxy and exclusion list.
2773 * <p>
2774 * The calling device admin must have requested
2775 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
2776 * this method; if it has not, a security exception will be thrown.
2777 * Only the first device admin can set the proxy. If a second admin attempts
2778 * to set the proxy, the {@link ComponentName} of the admin originally setting the
Robin Lee25e26452015-06-02 09:56:29 -07002779 * proxy will be returned. If successful in setting the proxy, {@code null} will
Oscar Montemayor69238c62010-08-03 10:51:06 -07002780 * be returned.
2781 * The method can be called repeatedly by the device admin alrady setting the
2782 * proxy to update the proxy and exclusion list.
2783 *
Robin Lee25e26452015-06-02 09:56:29 -07002784 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Oscar Montemayor69238c62010-08-03 10:51:06 -07002785 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
2786 * Pass Proxy.NO_PROXY to reset the proxy.
2787 * @param exclusionList a list of domains to be excluded from the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07002788 * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName}
2789 * of the device admin that sets the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08002790 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07002791 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07002792 public @Nullable ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec,
Oscar Montemayor69238c62010-08-03 10:51:06 -07002793 List<String> exclusionList ) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002794 throwIfParentInstance("setGlobalProxy");
Oscar Montemayor69238c62010-08-03 10:51:06 -07002795 if (proxySpec == null) {
2796 throw new NullPointerException();
2797 }
2798 if (mService != null) {
2799 try {
2800 String hostSpec;
2801 String exclSpec;
2802 if (proxySpec.equals(Proxy.NO_PROXY)) {
2803 hostSpec = null;
2804 exclSpec = null;
2805 } else {
2806 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
2807 throw new IllegalArgumentException();
2808 }
2809 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
2810 String hostName = sa.getHostName();
2811 int port = sa.getPort();
2812 StringBuilder hostBuilder = new StringBuilder();
2813 hostSpec = hostBuilder.append(hostName)
2814 .append(":").append(Integer.toString(port)).toString();
2815 if (exclusionList == null) {
2816 exclSpec = "";
2817 } else {
2818 StringBuilder listBuilder = new StringBuilder();
2819 boolean firstDomain = true;
2820 for (String exclDomain : exclusionList) {
2821 if (!firstDomain) {
2822 listBuilder = listBuilder.append(",");
2823 } else {
2824 firstDomain = false;
2825 }
2826 listBuilder = listBuilder.append(exclDomain.trim());
2827 }
2828 exclSpec = listBuilder.toString();
2829 }
Yuhao Zheng90704842014-02-28 17:22:45 -08002830 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
2831 != android.net.Proxy.PROXY_VALID)
2832 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07002833 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002834 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07002835 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002836 throw e.rethrowFromSystemServer();
Oscar Montemayor69238c62010-08-03 10:51:06 -07002837 }
2838 }
2839 return null;
2840 }
2841
2842 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002843 * Set a network-independent global HTTP proxy. This is not normally what you want for typical
2844 * HTTP proxies - they are generally network dependent. However if you're doing something
2845 * unusual like general internal filtering this may be useful. On a private network where the
2846 * proxy is not accessible, you may break HTTP using this.
2847 * <p>
2848 * This method requires the caller to be the device owner.
2849 * <p>
2850 * This proxy is only a recommendation and it is possible that some apps will ignore it.
Jason Monk03bc9912014-05-13 09:44:57 -04002851 *
Jason Monk03bc9912014-05-13 09:44:57 -04002852 * @see ProxyInfo
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002853 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2854 * @param proxyInfo The a {@link ProxyInfo} object defining the new global HTTP proxy. A
2855 * {@code null} value will clear the global HTTP proxy.
2856 * @throws SecurityException if {@code admin} is not the device owner.
Jason Monk03bc9912014-05-13 09:44:57 -04002857 */
Robin Lee25e26452015-06-02 09:56:29 -07002858 public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo
2859 proxyInfo) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002860 throwIfParentInstance("setRecommendedGlobalProxy");
Jason Monk03bc9912014-05-13 09:44:57 -04002861 if (mService != null) {
2862 try {
2863 mService.setRecommendedGlobalProxy(admin, proxyInfo);
2864 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002865 throw e.rethrowFromSystemServer();
Jason Monk03bc9912014-05-13 09:44:57 -04002866 }
2867 }
2868 }
2869
2870 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07002871 * Returns the component name setting the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07002872 * @return ComponentName object of the device admin that set the global proxy, or {@code null}
2873 * if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08002874 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07002875 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07002876 public @Nullable ComponentName getGlobalProxyAdmin() {
Oscar Montemayor69238c62010-08-03 10:51:06 -07002877 if (mService != null) {
2878 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002879 return mService.getGlobalProxyAdmin(myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07002880 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002881 throw e.rethrowFromSystemServer();
Oscar Montemayor69238c62010-08-03 10:51:06 -07002882 }
2883 }
2884 return null;
2885 }
2886
2887 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002888 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002889 * indicating that encryption is not supported.
2890 */
2891 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
2892
2893 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002894 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002895 * indicating that encryption is supported, but is not currently active.
2896 */
2897 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
2898
2899 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002900 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002901 * indicating that encryption is not currently active, but is currently
2902 * being activated. This is only reported by devices that support
2903 * encryption of data and only when the storage is currently
2904 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
2905 * to become encrypted will never return this value.
2906 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002907 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002908
2909 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002910 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002911 * indicating that encryption is active.
Amith Yamasani75db1252016-07-11 14:41:01 -07002912 * <p>
2913 * Also see {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002914 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002915 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002916
2917 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002918 * Result code for {@link #getStorageEncryptionStatus}:
2919 * indicating that encryption is active, but an encryption key has not
2920 * been set by the user.
2921 */
2922 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
2923
2924 /**
Makoto Onukid4c9e542016-02-25 18:17:30 -08002925 * Result code for {@link #getStorageEncryptionStatus}:
Amith Yamasani75db1252016-07-11 14:41:01 -07002926 * indicating that encryption is active and the encryption key is tied to the user or profile.
2927 * <p>
2928 * This value is only returned to apps targeting API level 24 and above. For apps targeting
2929 * earlier API levels, {@link #ENCRYPTION_STATUS_ACTIVE} is returned, even if the
2930 * encryption key is specific to the user or profile.
Makoto Onukid4c9e542016-02-25 18:17:30 -08002931 */
2932 public static final int ENCRYPTION_STATUS_ACTIVE_PER_USER = 5;
2933
2934 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002935 * Activity action: begin the process of encrypting data on the device. This activity should
2936 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
2937 * After resuming from this activity, use {@link #getStorageEncryption}
2938 * to check encryption status. However, on some devices this activity may never return, as
2939 * it may trigger a reboot and in some cases a complete data wipe of the device.
2940 */
2941 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
2942 public static final String ACTION_START_ENCRYPTION
2943 = "android.app.action.START_ENCRYPTION";
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002944 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07002945 * Widgets are enabled in keyguard
2946 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002947 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07002948
2949 /**
Jim Miller50e62182014-04-23 17:25:00 -07002950 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07002951 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002952 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
2953
2954 /**
2955 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
2956 */
2957 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
2958
2959 /**
Jim Miller50e62182014-04-23 17:25:00 -07002960 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2961 */
2962 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
2963
2964 /**
2965 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2966 */
2967 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
2968
2969 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02002970 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07002971 * (e.g. PIN/Pattern/Password).
2972 */
2973 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
2974
2975 /**
Jim Miller06e34502014-07-17 14:46:05 -07002976 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
2977 */
2978 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
2979
2980 /**
Adrian Roos7f06eed2016-02-05 15:21:02 -08002981 * Disable text entry into notifications on secure keyguard screens (e.g. PIN/Pattern/Password).
2982 */
2983 public static final int KEYGUARD_DISABLE_REMOTE_INPUT = 1 << 6;
2984
2985 /**
Jim Miller35207742012-11-02 15:33:20 -07002986 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07002987 */
2988 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07002989
2990 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002991 * Called by an application that is administering the device to request that the storage system
2992 * be encrypted.
2993 * <p>
2994 * When multiple device administrators attempt to control device encryption, the most secure,
2995 * supported setting will always be used. If any device administrator requests device
2996 * encryption, it will be enabled; Conversely, if a device administrator attempts to disable
2997 * device encryption while another device administrator has enabled it, the call to disable will
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002998 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002999 * <p>
3000 * This policy controls encryption of the secure (application data) storage area. Data written
3001 * to other storage areas may or may not be encrypted, and this policy does not require or
3002 * control the encryption of any other storage areas. There is one exception: If
3003 * {@link android.os.Environment#isExternalStorageEmulated()} is {@code true}, then the
3004 * directory returned by {@link android.os.Environment#getExternalStorageDirectory()} must be
3005 * written to disk within the encrypted storage area.
3006 * <p>
3007 * Important Note: On some devices, it is possible to encrypt storage without requiring the user
3008 * to create a device PIN or Password. In this case, the storage is encrypted, but the
3009 * encryption key may not be fully secured. For maximum security, the administrator should also
3010 * require (and check for) a pattern, PIN, or password.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003011 *
3012 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3013 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08003014 * @return the new request status (for all active admins) - will be one of
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003015 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
3016 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
3017 * {@link #getStorageEncryptionStatus()} to query the actual device state.
3018 * @throws SecurityException if {@code admin} is not an active administrator or does not use
3019 * {@link DeviceAdminInfo#USES_ENCRYPTED_STORAGE}
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003020 */
Robin Lee25e26452015-06-02 09:56:29 -07003021 public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003022 throwIfParentInstance("setStorageEncryption");
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003023 if (mService != null) {
3024 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003025 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003026 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003027 throw e.rethrowFromSystemServer();
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003028 }
3029 }
3030 return ENCRYPTION_STATUS_UNSUPPORTED;
3031 }
3032
3033 /**
3034 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08003035 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003036 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08003037 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
3038 * this will return the requested encryption setting as an aggregate of all active
3039 * administrators.
3040 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003041 */
Robin Lee25e26452015-06-02 09:56:29 -07003042 public boolean getStorageEncryption(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003043 throwIfParentInstance("getStorageEncryption");
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003044 if (mService != null) {
3045 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003046 return mService.getStorageEncryption(admin, myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003047 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003048 throw e.rethrowFromSystemServer();
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003049 }
3050 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08003051 return false;
3052 }
3053
3054 /**
3055 * Called by an application that is administering the device to
3056 * determine the current encryption status of the device.
Amith Yamasani75db1252016-07-11 14:41:01 -07003057 * <p>
Andy Stadler22dbfda2011-01-17 12:47:31 -08003058 * Depending on the returned status code, the caller may proceed in different
3059 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
3060 * storage system does not support encryption. If the
3061 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
3062 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00003063 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
3064 * storage system has enabled encryption but no password is set so further action
Amith Yamasani75db1252016-07-11 14:41:01 -07003065 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING},
3066 * {@link #ENCRYPTION_STATUS_ACTIVE} or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER},
3067 * no further action is required.
Andy Stadler22dbfda2011-01-17 12:47:31 -08003068 *
Robin Lee7e678712014-07-24 16:41:31 +01003069 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08003070 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00003071 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
Amith Yamasani75db1252016-07-11 14:41:01 -07003072 * {@link #ENCRYPTION_STATUS_ACTIVE}, or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08003073 */
3074 public int getStorageEncryptionStatus() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003075 throwIfParentInstance("getStorageEncryptionStatus");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003076 return getStorageEncryptionStatus(myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003077 }
3078
3079 /** @hide per-user version */
3080 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08003081 if (mService != null) {
3082 try {
Makoto Onukid4c9e542016-02-25 18:17:30 -08003083 return mService.getStorageEncryptionStatus(mContext.getPackageName(), userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08003084 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003085 throw e.rethrowFromSystemServer();
Andy Stadler22dbfda2011-01-17 12:47:31 -08003086 }
3087 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003088 return ENCRYPTION_STATUS_UNSUPPORTED;
3089 }
3090
3091 /**
Robin Lee2f7e1e42016-03-21 10:50:01 +00003092 * Mark a CA certificate as approved by the device user. This means that they have been notified
3093 * of the installation, were made aware of the risks, viewed the certificate and still wanted to
3094 * keep the certificate on the device.
3095 *
3096 * Calling with {@param approval} as {@code true} will cancel any ongoing warnings related to
3097 * this certificate.
3098 *
3099 * @hide
3100 */
3101 public boolean approveCaCert(String alias, int userHandle, boolean approval) {
3102 if (mService != null) {
3103 try {
3104 return mService.approveCaCert(alias, userHandle, approval);
3105 } catch (RemoteException e) {
3106 throw e.rethrowFromSystemServer();
3107 }
3108 }
3109 return false;
3110 }
3111
3112 /**
3113 * Check whether a CA certificate has been approved by the device user.
3114 *
3115 * @hide
3116 */
3117 public boolean isCaCertApproved(String alias, int userHandle) {
3118 if (mService != null) {
3119 try {
3120 return mService.isCaCertApproved(alias, userHandle);
3121 } catch (RemoteException e) {
3122 throw e.rethrowFromSystemServer();
3123 }
3124 }
3125 return false;
3126 }
3127
3128 /**
Robin Lee7e678712014-07-24 16:41:31 +01003129 * Installs the given certificate as a user CA.
3130 *
Robin Lee25e26452015-06-02 09:56:29 -07003131 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3132 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003133 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04003134 *
3135 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01003136 * interrupted, true otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003137 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3138 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04003139 */
Robin Lee25e26452015-06-02 09:56:29 -07003140 public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003141 throwIfParentInstance("installCaCert");
Maggie Benthallda51e682013-08-08 22:35:44 -04003142 if (mService != null) {
3143 try {
Robin Lee7e678712014-07-24 16:41:31 +01003144 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04003145 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003146 throw e.rethrowFromSystemServer();
Maggie Benthallda51e682013-08-08 22:35:44 -04003147 }
3148 }
3149 return false;
3150 }
3151
3152 /**
Robin Lee7e678712014-07-24 16:41:31 +01003153 * Uninstalls the given certificate from trusted user CAs, if present.
3154 *
Robin Lee25e26452015-06-02 09:56:29 -07003155 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3156 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003157 * @param certBuffer encoded form of the certificate to remove.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003158 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3159 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04003160 */
Robin Lee25e26452015-06-02 09:56:29 -07003161 public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003162 throwIfParentInstance("uninstallCaCert");
Maggie Benthallda51e682013-08-08 22:35:44 -04003163 if (mService != null) {
3164 try {
Robin Lee306fe082014-06-19 14:04:24 +00003165 final String alias = getCaCertAlias(certBuffer);
Robin Lee83881bd2015-06-09 16:04:38 -07003166 mService.uninstallCaCerts(admin, new String[] {alias});
Robin Lee306fe082014-06-19 14:04:24 +00003167 } catch (CertificateException e) {
3168 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04003169 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003170 throw e.rethrowFromSystemServer();
Maggie Benthallda51e682013-08-08 22:35:44 -04003171 }
3172 }
3173 }
3174
3175 /**
Robin Lee7e678712014-07-24 16:41:31 +01003176 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
3177 * If a user has installed any certificates by other means than device policy these will be
3178 * included too.
3179 *
Robin Lee25e26452015-06-02 09:56:29 -07003180 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3181 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003182 * @return a List of byte[] arrays, each encoding one user CA certificate.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003183 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3184 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04003185 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003186 public @NonNull List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) {
3187 final List<byte[]> certs = new ArrayList<byte[]>();
Benjamin Franzbc33c822016-04-15 08:57:52 +01003188 throwIfParentInstance("getInstalledCaCerts");
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003189 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01003190 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003191 mService.enforceCanManageCaCerts(admin);
3192 final TrustedCertificateStore certStore = new TrustedCertificateStore();
3193 for (String alias : certStore.userAliases()) {
3194 try {
3195 certs.add(certStore.getCertificate(alias).getEncoded());
3196 } catch (CertificateException ce) {
3197 Log.w(TAG, "Could not encode certificate: " + alias, ce);
3198 }
3199 }
3200 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003201 throw re.rethrowFromSystemServer();
Robin Lee7e678712014-07-24 16:41:31 +01003202 }
3203 }
3204 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04003205 }
3206
3207 /**
Robin Lee7e678712014-07-24 16:41:31 +01003208 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
3209 * means other than device policy will also be removed, except for system CA certificates.
3210 *
Robin Lee25e26452015-06-02 09:56:29 -07003211 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3212 * {@code null} if calling from a delegated certificate installer.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003213 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3214 * owner.
Robin Lee7e678712014-07-24 16:41:31 +01003215 */
Robin Lee25e26452015-06-02 09:56:29 -07003216 public void uninstallAllUserCaCerts(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003217 throwIfParentInstance("uninstallAllUserCaCerts");
Robin Lee7e678712014-07-24 16:41:31 +01003218 if (mService != null) {
Robin Lee83881bd2015-06-09 16:04:38 -07003219 try {
3220 mService.uninstallCaCerts(admin, new TrustedCertificateStore().userAliases()
3221 .toArray(new String[0]));
3222 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003223 throw re.rethrowFromSystemServer();
Robin Lee7e678712014-07-24 16:41:31 +01003224 }
3225 }
3226 }
3227
3228 /**
3229 * Returns whether this certificate is installed as a trusted CA.
3230 *
Robin Lee25e26452015-06-02 09:56:29 -07003231 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3232 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003233 * @param certBuffer encoded form of the certificate to look up.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003234 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3235 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04003236 */
Robin Lee25e26452015-06-02 09:56:29 -07003237 public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003238 throwIfParentInstance("hasCaCertInstalled");
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003239 if (mService != null) {
3240 try {
3241 mService.enforceCanManageCaCerts(admin);
3242 return getCaCertAlias(certBuffer) != null;
3243 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003244 throw re.rethrowFromSystemServer();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003245 } catch (CertificateException ce) {
3246 Log.w(TAG, "Could not parse certificate", ce);
3247 }
Maggie Benthallda51e682013-08-08 22:35:44 -04003248 }
3249 return false;
3250 }
3251
3252 /**
Robin Leece3399f2016-02-24 12:08:32 +00003253 * Called by a device or profile owner, or delegated certificate installer, to install a
3254 * certificate and corresponding private key. All apps within the profile will be able to access
3255 * the certificate and use the private key, given direct user approval.
3256 *
3257 * <p>Access to the installed credentials will not be granted to the caller of this API without
3258 * direct user approval. This is for security - should a certificate installer become
3259 * compromised, certificates it had already installed will be protected.
3260 *
3261 * <p>If the installer must have access to the credentials, call
Rubin Xub4365912016-03-23 12:13:22 +00003262 * {@link #installKeyPair(ComponentName, PrivateKey, Certificate[], String, boolean)} instead.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003263 *
Robin Lee25e26452015-06-02 09:56:29 -07003264 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3265 * {@code null} if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003266 * @param privKey The private key to install.
3267 * @param cert The certificate to install.
3268 * @param alias The private key alias under which to install the certificate. If a certificate
3269 * with that alias already exists, it will be overwritten.
3270 * @return {@code true} if the keys were installed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003271 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3272 * owner.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003273 */
Robin Leefbc65642015-08-03 16:21:22 +01003274 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
3275 @NonNull Certificate cert, @NonNull String alias) {
Rubin Xub4365912016-03-23 12:13:22 +00003276 return installKeyPair(admin, privKey, new Certificate[] {cert}, alias, false);
Robin Leece3399f2016-02-24 12:08:32 +00003277 }
3278
3279 /**
3280 * Called by a device or profile owner, or delegated certificate installer, to install a
Rubin Xub4365912016-03-23 12:13:22 +00003281 * certificate chain and corresponding private key for the leaf certificate. All apps within the
3282 * profile will be able to access the certificate chain and use the private key, given direct
3283 * user approval.
Robin Leece3399f2016-02-24 12:08:32 +00003284 *
Robin Leea1b290e2016-03-09 14:38:36 +00003285 * <p>The caller of this API may grant itself access to the certificate and private key
3286 * immediately, without user approval. It is a best practice not to request this unless strictly
3287 * necessary since it opens up additional security vulnerabilities.
Robin Leece3399f2016-02-24 12:08:32 +00003288 *
3289 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Robin Leea1b290e2016-03-09 14:38:36 +00003290 * {@code null} if calling from a delegated certificate installer.
Robin Leece3399f2016-02-24 12:08:32 +00003291 * @param privKey The private key to install.
Rubin Xub4365912016-03-23 12:13:22 +00003292 * @param certs The certificate chain to install. The chain should start with the leaf
3293 * certificate and include the chain of trust in order. This will be returned by
3294 * {@link android.security.KeyChain#getCertificateChain}.
Robin Leece3399f2016-02-24 12:08:32 +00003295 * @param alias The private key alias under which to install the certificate. If a certificate
Robin Leea1b290e2016-03-09 14:38:36 +00003296 * with that alias already exists, it will be overwritten.
Robin Leece3399f2016-02-24 12:08:32 +00003297 * @param requestAccess {@code true} to request that the calling app be granted access to the
Robin Leea1b290e2016-03-09 14:38:36 +00003298 * credentials immediately. Otherwise, access to the credentials will be gated by user
3299 * approval.
Robin Leece3399f2016-02-24 12:08:32 +00003300 * @return {@code true} if the keys were installed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003301 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3302 * owner.
Rubin Xub4365912016-03-23 12:13:22 +00003303 * @see android.security.KeyChain#getCertificateChain
Robin Leece3399f2016-02-24 12:08:32 +00003304 */
3305 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
Rubin Xub4365912016-03-23 12:13:22 +00003306 @NonNull Certificate[] certs, @NonNull String alias, boolean requestAccess) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003307 throwIfParentInstance("installKeyPair");
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003308 try {
Rubin Xub4365912016-03-23 12:13:22 +00003309 final byte[] pemCert = Credentials.convertToPem(certs[0]);
3310 byte[] pemChain = null;
3311 if (certs.length > 1) {
3312 pemChain = Credentials.convertToPem(Arrays.copyOfRange(certs, 1, certs.length));
3313 }
Robin Lee0d5ccb72014-09-12 17:41:44 +01003314 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
3315 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
Rubin Xub4365912016-03-23 12:13:22 +00003316 return mService.installKeyPair(admin, pkcs8Key, pemCert, pemChain, alias,
3317 requestAccess);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003318 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003319 throw e.rethrowFromSystemServer();
Robin Lee0d5ccb72014-09-12 17:41:44 +01003320 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
3321 Log.w(TAG, "Failed to obtain private key material", e);
3322 } catch (CertificateException | IOException e) {
3323 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003324 }
3325 return false;
3326 }
3327
3328 /**
Robin Leea1b290e2016-03-09 14:38:36 +00003329 * Called by a device or profile owner, or delegated certificate installer, to remove a
3330 * certificate and private key pair installed under a given alias.
Robin Leefbc65642015-08-03 16:21:22 +01003331 *
3332 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Robin Leea1b290e2016-03-09 14:38:36 +00003333 * {@code null} if calling from a delegated certificate installer.
Robin Leefbc65642015-08-03 16:21:22 +01003334 * @param alias The private key alias under which the certificate is installed.
Robin Leea1b290e2016-03-09 14:38:36 +00003335 * @return {@code true} if the private key alias no longer exists, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003336 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3337 * owner.
Robin Leefbc65642015-08-03 16:21:22 +01003338 */
3339 public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003340 throwIfParentInstance("removeKeyPair");
Robin Leefbc65642015-08-03 16:21:22 +01003341 try {
3342 return mService.removeKeyPair(admin, alias);
3343 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003344 throw e.rethrowFromSystemServer();
Robin Leefbc65642015-08-03 16:21:22 +01003345 }
Robin Leefbc65642015-08-03 16:21:22 +01003346 }
3347
3348 /**
Robin Lee25e26452015-06-02 09:56:29 -07003349 * @return the alias of a given CA certificate in the certificate store, or {@code null} if it
Robin Lee306fe082014-06-19 14:04:24 +00003350 * doesn't exist.
3351 */
3352 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
3353 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
3354 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
3355 new ByteArrayInputStream(certBuffer));
3356 return new TrustedCertificateStore().getCertificateAlias(cert);
3357 }
3358
3359 /**
Rubin Xuec32b562015-03-03 17:34:05 +00003360 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01003361 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00003362 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01003363 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00003364 * <p>
3365 * Delegated certificate installer is a per-user state. The delegated access is persistent until
3366 * it is later cleared by calling this method with a null value or uninstallling the certificate
3367 * installer.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003368 * <p>
Rubin Xuf03d0a62016-02-10 14:54:15 +00003369 * <b>Note:</b>Starting from {@link android.os.Build.VERSION_CODES#N}, if the caller
3370 * application's target SDK version is {@link android.os.Build.VERSION_CODES#N} or newer, the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003371 * supplied certificate installer package must be installed when calling this API, otherwise an
3372 * {@link IllegalArgumentException} will be thrown.
Rubin Xuec32b562015-03-03 17:34:05 +00003373 *
Robin Lee25e26452015-06-02 09:56:29 -07003374 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xuec32b562015-03-03 17:34:05 +00003375 * @param installerPackage The package name of the certificate installer which will be given
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003376 * access. If {@code null} is given the current package will be cleared.
3377 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Rubin Xuec32b562015-03-03 17:34:05 +00003378 */
Robin Lee25e26452015-06-02 09:56:29 -07003379 public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String
3380 installerPackage) throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003381 throwIfParentInstance("setCertInstallerPackage");
Rubin Xuec32b562015-03-03 17:34:05 +00003382 if (mService != null) {
3383 try {
Robin Lee25e26452015-06-02 09:56:29 -07003384 mService.setCertInstallerPackage(admin, installerPackage);
Rubin Xuec32b562015-03-03 17:34:05 +00003385 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003386 throw e.rethrowFromSystemServer();
Rubin Xuec32b562015-03-03 17:34:05 +00003387 }
3388 }
3389 }
3390
3391 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003392 * Called by a profile owner or device owner to retrieve the certificate installer for the user.
3393 * null if none is set.
Rubin Xuec32b562015-03-03 17:34:05 +00003394 *
Robin Lee25e26452015-06-02 09:56:29 -07003395 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003396 * @return The package name of the current delegated certificate installer, or {@code null} if
3397 * none is set.
3398 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Rubin Xuec32b562015-03-03 17:34:05 +00003399 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003400 public @Nullable String getCertInstallerPackage(@NonNull ComponentName admin)
3401 throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003402 throwIfParentInstance("getCertInstallerPackage");
Rubin Xuec32b562015-03-03 17:34:05 +00003403 if (mService != null) {
3404 try {
Robin Lee25e26452015-06-02 09:56:29 -07003405 return mService.getCertInstallerPackage(admin);
Rubin Xuec32b562015-03-03 17:34:05 +00003406 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003407 throw e.rethrowFromSystemServer();
Rubin Xuec32b562015-03-03 17:34:05 +00003408 }
3409 }
3410 return null;
3411 }
3412
3413 /**
Robin Lee244ce8e2016-01-05 18:03:46 +00003414 * Called by a device or profile owner to configure an always-on VPN connection through a
Robin Leedc679712016-05-03 13:23:03 +01003415 * specific application for the current user.
3416 *
3417 * @deprecated this version only exists for compability with previous developer preview builds.
3418 * TODO: delete once there are no longer any live references.
3419 * @hide
3420 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07003421 @Deprecated
Robin Leedc679712016-05-03 13:23:03 +01003422 public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage)
3423 throws NameNotFoundException, UnsupportedOperationException {
3424 setAlwaysOnVpnPackage(admin, vpnPackage, /* lockdownEnabled */ true);
3425 }
3426
3427 /**
3428 * Called by a device or profile owner to configure an always-on VPN connection through a
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003429 * specific application for the current user. This connection is automatically granted and
3430 * persisted after a reboot.
3431 * <p>
3432 * The designated package should declare a {@link android.net.VpnService} in its manifest
3433 * guarded by {@link android.Manifest.permission#BIND_VPN_SERVICE}, otherwise the call will
3434 * fail.
Robin Lee244ce8e2016-01-05 18:03:46 +00003435 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003436 * @param vpnPackage The package name for an installed VPN app on the device, or {@code null} to
Robin Leedc679712016-05-03 13:23:03 +01003437 * remove an existing always-on VPN configuration.
3438 * @param lockdownEnabled {@code true} to disallow networking when the VPN is not connected or
3439 * {@code false} otherwise. This carries the risk that any failure of the VPN provider
3440 * could break networking for all apps. This has no effect when clearing.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003441 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Robin Leeee5eb932016-04-05 16:27:15 +01003442 * @throws NameNotFoundException if {@code vpnPackage} is not installed.
3443 * @throws UnsupportedOperationException if {@code vpnPackage} exists but does not support being
3444 * set as always-on, or if always-on VPN is not available.
Robin Lee244ce8e2016-01-05 18:03:46 +00003445 */
Robin Leedc679712016-05-03 13:23:03 +01003446 public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage,
3447 boolean lockdownEnabled)
Robin Leeee5eb932016-04-05 16:27:15 +01003448 throws NameNotFoundException, UnsupportedOperationException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003449 throwIfParentInstance("setAlwaysOnVpnPackage");
Robin Lee244ce8e2016-01-05 18:03:46 +00003450 if (mService != null) {
3451 try {
Robin Leedc679712016-05-03 13:23:03 +01003452 if (!mService.setAlwaysOnVpnPackage(admin, vpnPackage, lockdownEnabled)) {
Robin Leeee5eb932016-04-05 16:27:15 +01003453 throw new NameNotFoundException(vpnPackage);
3454 }
Robin Lee244ce8e2016-01-05 18:03:46 +00003455 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003456 throw e.rethrowFromSystemServer();
Robin Lee244ce8e2016-01-05 18:03:46 +00003457 }
3458 }
Robin Lee244ce8e2016-01-05 18:03:46 +00003459 }
3460
3461 /**
3462 * Called by a device or profile owner to read the name of the package administering an
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003463 * always-on VPN connection for the current user. If there is no such package, or the always-on
3464 * VPN is provided by the system instead of by an application, {@code null} will be returned.
Robin Lee244ce8e2016-01-05 18:03:46 +00003465 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003466 * @return Package name of VPN controller responsible for always-on VPN, or {@code null} if none
3467 * is set.
3468 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Robin Lee244ce8e2016-01-05 18:03:46 +00003469 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003470 public @Nullable String getAlwaysOnVpnPackage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003471 throwIfParentInstance("getAlwaysOnVpnPackage");
Robin Lee244ce8e2016-01-05 18:03:46 +00003472 if (mService != null) {
3473 try {
3474 return mService.getAlwaysOnVpnPackage(admin);
3475 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003476 throw e.rethrowFromSystemServer();
Robin Lee244ce8e2016-01-05 18:03:46 +00003477 }
3478 }
3479 return null;
3480 }
3481
3482 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003483 * Called by an application that is administering the device to disable all cameras on the
3484 * device, for this user. After setting this, no applications running as this user will be able
3485 * to access any cameras on the device.
3486 * <p>
3487 * If the caller is device owner, then the restriction will be applied to all users.
3488 * <p>
3489 * The calling device admin must have requested
3490 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call this method; if it has
3491 * not, a security exception will be thrown.
Ben Komalo2447edd2011-05-09 16:05:33 -07003492 *
3493 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3494 * @param disabled Whether or not the camera should be disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003495 * @throws SecurityException if {@code admin} is not an active administrator or does not use
3496 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA}.
Ben Komalo2447edd2011-05-09 16:05:33 -07003497 */
Robin Lee25e26452015-06-02 09:56:29 -07003498 public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003499 throwIfParentInstance("setCameraDisabled");
Ben Komalo2447edd2011-05-09 16:05:33 -07003500 if (mService != null) {
3501 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003502 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07003503 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003504 throw e.rethrowFromSystemServer();
Ben Komalo2447edd2011-05-09 16:05:33 -07003505 }
3506 }
3507 }
3508
3509 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07003510 * Determine whether or not the device's cameras have been disabled for this user,
Makoto Onuki32b30572015-12-11 14:29:51 -08003511 * either by the calling admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07003512 * @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 -07003513 * have disabled the camera
3514 */
Robin Lee25e26452015-06-02 09:56:29 -07003515 public boolean getCameraDisabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003516 throwIfParentInstance("getCameraDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003517 return getCameraDisabled(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003518 }
3519
3520 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003521 public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07003522 if (mService != null) {
3523 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003524 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07003525 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003526 throw e.rethrowFromSystemServer();
Ben Komalo2447edd2011-05-09 16:05:33 -07003527 }
3528 }
3529 return false;
3530 }
3531
3532 /**
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003533 * Called by a device owner to request a bugreport.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003534 * <p>
3535 * There must be only one user on the device, managed by the device owner. Otherwise a
3536 * {@link SecurityException} will be thrown.
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003537 *
3538 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003539 * @return {@code true} if the bugreport collection started successfully, or {@code false} if it
3540 * wasn't triggered because a previous bugreport operation is still active (either the
3541 * bugreport is still running or waiting for the user to share or decline)
3542 * @throws SecurityException if {@code admin} is not a device owner, or if there are users other
3543 * than the one managed by the device owner.
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003544 */
3545 public boolean requestBugreport(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003546 throwIfParentInstance("requestBugreport");
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003547 if (mService != null) {
3548 try {
3549 return mService.requestBugreport(admin);
3550 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003551 throw e.rethrowFromSystemServer();
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003552 }
3553 }
3554 return false;
3555 }
3556
3557 /**
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07003558 * Determine whether or not creating a guest user has been disabled for the device
3559 *
3560 * @hide
3561 */
3562 public boolean getGuestUserDisabled(@Nullable ComponentName admin) {
3563 // Currently guest users can always be created if multi-user is enabled
3564 // TODO introduce a policy for guest user creation
3565 return false;
3566 }
3567
3568 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01003569 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
3570 * screen capture also prevents the content from being shown on display devices that do not have
3571 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
3572 * secure surfaces and secure displays.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003573 * <p>
3574 * The calling device admin must be a device or profile owner. If it is not, a security
3575 * exception will be thrown.
3576 * <p>
3577 * From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also blocks
3578 * assist requests for all activities of the relevant user.
Benjamin Franzc200f442015-06-25 18:20:04 +01003579 *
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003580 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003581 * @param disabled Whether screen capture is disabled or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003582 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003583 */
Robin Lee25e26452015-06-02 09:56:29 -07003584 public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003585 throwIfParentInstance("setScreenCaptureDisabled");
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003586 if (mService != null) {
3587 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003588 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003589 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003590 throw e.rethrowFromSystemServer();
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003591 }
3592 }
3593 }
3594
3595 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08003596 * Determine whether or not screen capture has been disabled by the calling
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003597 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07003598 * @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 +01003599 * have disabled screen capture.
3600 */
Robin Lee25e26452015-06-02 09:56:29 -07003601 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003602 throwIfParentInstance("getScreenCaptureDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003603 return getScreenCaptureDisabled(admin, myUserId());
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003604 }
3605
3606 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003607 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003608 if (mService != null) {
3609 try {
3610 return mService.getScreenCaptureDisabled(admin, userHandle);
3611 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003612 throw e.rethrowFromSystemServer();
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003613 }
3614 }
3615 return false;
3616 }
3617
3618 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003619 * Called by a device owner to set whether auto time is required. If auto time is required the
3620 * user cannot set the date and time, but has to use network date and time.
3621 * <p>
3622 * Note: if auto time is required the user can still manually set the time zone.
3623 * <p>
3624 * The calling device admin must be a device owner. If it is not, a security exception will be
3625 * thrown.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003626 *
3627 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3628 * @param required Whether auto time is set required or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003629 * @throws SecurityException if {@code admin} is not a device owner.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003630 */
Robin Lee25e26452015-06-02 09:56:29 -07003631 public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003632 throwIfParentInstance("setAutoTimeRequired");
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003633 if (mService != null) {
3634 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003635 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003636 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003637 throw e.rethrowFromSystemServer();
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003638 }
3639 }
3640 }
3641
3642 /**
3643 * @return true if auto time is required.
3644 */
3645 public boolean getAutoTimeRequired() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003646 throwIfParentInstance("getAutoTimeRequired");
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003647 if (mService != null) {
3648 try {
3649 return mService.getAutoTimeRequired();
3650 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003651 throw e.rethrowFromSystemServer();
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003652 }
3653 }
3654 return false;
3655 }
3656
3657 /**
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003658 * Called by a device owner to set whether all users created on the device should be ephemeral.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003659 * <p>
3660 * The system user is exempt from this policy - it is never ephemeral.
3661 * <p>
3662 * The calling device admin must be the device owner. If it is not, a security exception will be
3663 * thrown.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003664 *
3665 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3666 * @param forceEphemeralUsers If true, all the existing users will be deleted and all
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003667 * subsequently created users will be ephemeral.
3668 * @throws SecurityException if {@code admin} is not a device owner.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003669 * @hide
3670 */
3671 public void setForceEphemeralUsers(
3672 @NonNull ComponentName admin, boolean forceEphemeralUsers) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003673 throwIfParentInstance("setForceEphemeralUsers");
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003674 if (mService != null) {
3675 try {
3676 mService.setForceEphemeralUsers(admin, forceEphemeralUsers);
3677 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003678 throw e.rethrowFromSystemServer();
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003679 }
3680 }
3681 }
3682
3683 /**
3684 * @return true if all users are created ephemeral.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003685 * @throws SecurityException if {@code admin} is not a device owner.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003686 * @hide
3687 */
3688 public boolean getForceEphemeralUsers(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003689 throwIfParentInstance("getForceEphemeralUsers");
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003690 if (mService != null) {
3691 try {
3692 return mService.getForceEphemeralUsers(admin);
3693 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003694 throw e.rethrowFromSystemServer();
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003695 }
3696 }
3697 return false;
3698 }
3699
3700 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07003701 * Called by an application that is administering the device to disable keyguard customizations,
3702 * such as widgets. After setting this, keyguard features will be disabled according to the
3703 * provided feature list.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003704 * <p>
3705 * The calling device admin must have requested
3706 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method;
3707 * if it has not, a security exception will be thrown.
3708 * <p>
3709 * Calling this from a managed profile before version {@link android.os.Build.VERSION_CODES#M}
3710 * will throw a security exception. From version {@link android.os.Build.VERSION_CODES#M} the
3711 * profile owner of a managed profile can set:
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003712 * <ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00003713 * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which affects the parent user, but only if there
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003714 * is no separate challenge set on the managed profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00003715 * <li>{@link #KEYGUARD_DISABLE_FINGERPRINT} which affects the managed profile challenge if
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003716 * there is one, or the parent user otherwise.
3717 * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} which affects notifications generated
3718 * by applications in the managed profile.
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003719 * </ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00003720 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} and {@link #KEYGUARD_DISABLE_FINGERPRINT} can also be
3721 * set on the {@link DevicePolicyManager} instance returned by
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003722 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
3723 * profile.
3724 * <p>
3725 * Requests to disable other features on a managed profile will be ignored.
3726 * <p>
3727 * The admin can check which features have been disabled by calling
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003728 * {@link #getKeyguardDisabledFeatures(ComponentName)}
Amith Yamasani242f4b12014-10-14 16:06:13 -07003729 *
Jim Millerb8ec4702012-08-31 17:19:10 -07003730 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07003731 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003732 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
3733 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS},
3734 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
3735 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS},
3736 * {@link #KEYGUARD_DISABLE_FINGERPRINT}, {@link #KEYGUARD_DISABLE_FEATURES_ALL}
3737 * @throws SecurityException if {@code admin} is not an active administrator or does not user
3738 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES}
Jim Millerb8ec4702012-08-31 17:19:10 -07003739 */
Robin Lee25e26452015-06-02 09:56:29 -07003740 public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07003741 if (mService != null) {
3742 try {
Esteban Talavera62399912016-01-11 15:37:55 +00003743 mService.setKeyguardDisabledFeatures(admin, which, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07003744 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003745 throw e.rethrowFromSystemServer();
Jim Millerb8ec4702012-08-31 17:19:10 -07003746 }
3747 }
3748 }
3749
3750 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08003751 * Determine whether or not features have been disabled in keyguard either by the calling
Rubin Xud3609d42016-07-13 18:32:57 +01003752 * admin, if specified, or all admins that set restrictions on this user and its participating
Esteban Talaverac1c83592016-02-17 17:56:15 +00003753 * profiles. Restrictions on profiles that have a separate challenge are not taken into account.
3754 *
3755 * <p>This method can be called on the {@link DevicePolicyManager} instance
3756 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
3757 * restrictions on the parent profile.
3758 *
Esteban Talavera62399912016-01-11 15:37:55 +00003759 * @param admin The name of the admin component to check, or {@code null} to check whether any
3760 * admins have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07003761 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
3762 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07003763 */
Robin Lee25e26452015-06-02 09:56:29 -07003764 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003765 return getKeyguardDisabledFeatures(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003766 }
3767
3768 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003769 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07003770 if (mService != null) {
3771 try {
Esteban Talavera62399912016-01-11 15:37:55 +00003772 return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07003773 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003774 throw e.rethrowFromSystemServer();
Jim Millerb8ec4702012-08-31 17:19:10 -07003775 }
3776 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07003777 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07003778 }
3779
3780 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08003781 * @hide
3782 */
Robin Lee25e26452015-06-02 09:56:29 -07003783 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
3784 int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003785 if (mService != null) {
3786 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01003787 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003788 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003789 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003790 }
3791 }
3792 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003793
Dianne Hackbornd6847842010-01-12 18:14:19 -08003794 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01003795 * @hide
3796 */
Robin Lee25e26452015-06-02 09:56:29 -07003797 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003798 setActiveAdmin(policyReceiver, refreshing, myUserId());
Jessica Hummel6d36b602014-04-04 12:42:17 +01003799 }
3800
3801 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08003802 * @hide
3803 */
Robin Lee25e26452015-06-02 09:56:29 -07003804 public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08003805 if (mService != null) {
3806 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003807 mService.getRemoveWarning(admin, result, myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08003808 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003809 throw e.rethrowFromSystemServer();
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08003810 }
3811 }
3812 }
3813
3814 /**
3815 * @hide
3816 */
Andrew Scull5f9e6f32016-08-02 14:22:17 +01003817 public void setActivePasswordState(PasswordMetrics metrics, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003818 if (mService != null) {
3819 try {
Andrew Scull5f9e6f32016-08-02 14:22:17 +01003820 mService.setActivePasswordState(metrics, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003821 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003822 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003823 }
3824 }
3825 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003826
Dianne Hackbornd6847842010-01-12 18:14:19 -08003827 /**
3828 * @hide
3829 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003830 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003831 if (mService != null) {
3832 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003833 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003834 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003835 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003836 }
3837 }
3838 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003839
Dianne Hackbornd6847842010-01-12 18:14:19 -08003840 /**
3841 * @hide
3842 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003843 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003844 if (mService != null) {
3845 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003846 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003847 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003848 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003849 }
3850 }
3851 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07003852
3853 /**
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003854 * @hide
3855 */
3856 public void reportFailedFingerprintAttempt(int userHandle) {
3857 if (mService != null) {
3858 try {
3859 mService.reportFailedFingerprintAttempt(userHandle);
3860 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003861 throw e.rethrowFromSystemServer();
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003862 }
3863 }
3864 }
3865
3866 /**
3867 * @hide
3868 */
3869 public void reportSuccessfulFingerprintAttempt(int userHandle) {
3870 if (mService != null) {
3871 try {
3872 mService.reportSuccessfulFingerprintAttempt(userHandle);
3873 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003874 throw e.rethrowFromSystemServer();
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003875 }
3876 }
3877 }
3878
3879 /**
Michal Karpinski31502d32016-01-25 16:43:07 +00003880 * Should be called when keyguard has been dismissed.
3881 * @hide
3882 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003883 public void reportKeyguardDismissed(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00003884 if (mService != null) {
3885 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003886 mService.reportKeyguardDismissed(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00003887 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003888 throw e.rethrowFromSystemServer();
Michal Karpinski31502d32016-01-25 16:43:07 +00003889 }
3890 }
3891 }
3892
3893 /**
3894 * Should be called when keyguard view has been shown to the user.
3895 * @hide
3896 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003897 public void reportKeyguardSecured(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00003898 if (mService != null) {
3899 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003900 mService.reportKeyguardSecured(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00003901 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003902 throw e.rethrowFromSystemServer();
Michal Karpinski31502d32016-01-25 16:43:07 +00003903 }
3904 }
3905 }
3906
3907 /**
Amith Yamasani71e6c692013-03-24 17:39:28 -07003908 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00003909 * Sets the given package as the device owner.
Makoto Onukia52562c2015-10-01 16:12:31 -07003910 * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name.
3911 * @param who the component name to be registered as device owner.
Amith Yamasani71e6c692013-03-24 17:39:28 -07003912 * @return whether the package was successfully registered as the device owner.
3913 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00003914 * @throws IllegalStateException If the preconditions mentioned are not met.
Amith Yamasani71e6c692013-03-24 17:39:28 -07003915 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003916 public boolean setDeviceOwner(ComponentName who) {
3917 return setDeviceOwner(who, null);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003918 }
3919
3920 /**
3921 * @hide
Makoto Onuki58b684f2015-09-04 10:48:16 -07003922 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003923 public boolean setDeviceOwner(ComponentName who, int userId) {
3924 return setDeviceOwner(who, null, userId);
Makoto Onuki58b684f2015-09-04 10:48:16 -07003925 }
3926
3927 /**
3928 * @hide
3929 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003930 public boolean setDeviceOwner(ComponentName who, String ownerName) {
3931 return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM);
Makoto Onuki58b684f2015-09-04 10:48:16 -07003932 }
3933
3934 /**
3935 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00003936 * Sets the given package as the device owner. The package must already be installed. There
3937 * must not already be a device owner.
3938 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
3939 * this method.
3940 * Calling this after the setup phase of the primary user has completed is allowed only if
3941 * the caller is the shell uid, and there are no additional users and no accounts.
Makoto Onukia52562c2015-10-01 16:12:31 -07003942 * @param who the component name to be registered as device owner.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003943 * @param ownerName the human readable name of the institution that owns this device.
Makoto Onuki58b684f2015-09-04 10:48:16 -07003944 * @param userId ID of the user on which the device owner runs.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003945 * @return whether the package was successfully registered as the device owner.
3946 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00003947 * @throws IllegalStateException If the preconditions mentioned are not met.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003948 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003949 public boolean setDeviceOwner(ComponentName who, String ownerName, int userId)
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003950 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07003951 if (mService != null) {
3952 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07003953 return mService.setDeviceOwner(who, ownerName, userId);
Amith Yamasani71e6c692013-03-24 17:39:28 -07003954 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003955 throw re.rethrowFromSystemServer();
Amith Yamasani71e6c692013-03-24 17:39:28 -07003956 }
3957 }
3958 return false;
3959 }
3960
3961 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003962 * Used to determine if a particular package has been registered as a Device Owner app.
3963 * A device owner app is a special device admin that cannot be deactivated by the user, once
Robin Lee25e26452015-06-02 09:56:29 -07003964 * activated as a device admin. It also cannot be uninstalled. To check whether a particular
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003965 * package is currently registered as the device owner app, pass in the package name from
3966 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
Robin Lee25e26452015-06-02 09:56:29 -07003967 * admin apps that want to check whether they are also registered as the device owner app. The
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003968 * exact mechanism by which a device admin app is registered as a device owner app is defined by
3969 * the setup process.
3970 * @param packageName the package name of the app, to compare with the registered device owner
3971 * app, if any.
Makoto Onukic8a5a552015-11-19 14:29:12 -08003972 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07003973 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003974 public boolean isDeviceOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003975 throwIfParentInstance("isDeviceOwnerApp");
Makoto Onukic8a5a552015-11-19 14:29:12 -08003976 return isDeviceOwnerAppOnCallingUser(packageName);
3977 }
3978
3979 /**
3980 * @return true if a package is registered as device owner, only when it's running on the
3981 * calling user.
3982 *
3983 * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity.
3984 * @hide
3985 */
3986 public boolean isDeviceOwnerAppOnCallingUser(String packageName) {
3987 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true);
3988 }
3989
3990 /**
3991 * @return true if a package is registered as device owner, even if it's running on a different
3992 * user.
3993 *
3994 * <p>Requires the MANAGE_USERS permission.
3995 *
3996 * @hide
3997 */
3998 public boolean isDeviceOwnerAppOnAnyUser(String packageName) {
3999 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false);
4000 }
4001
4002 /**
4003 * @return device owner component name, only when it's running on the calling user.
4004 *
4005 * @hide
4006 */
4007 public ComponentName getDeviceOwnerComponentOnCallingUser() {
4008 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true);
4009 }
4010
4011 /**
4012 * @return device owner component name, even if it's running on a different user.
4013 *
4014 * <p>Requires the MANAGE_USERS permission.
4015 *
4016 * @hide
4017 */
4018 public ComponentName getDeviceOwnerComponentOnAnyUser() {
4019 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false);
4020 }
4021
4022 private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) {
Makoto Onuki70f929e2015-11-11 12:40:15 -08004023 if (packageName == null) {
4024 return false;
Amith Yamasani71e6c692013-03-24 17:39:28 -07004025 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08004026 final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly);
Makoto Onuki70f929e2015-11-11 12:40:15 -08004027 if (deviceOwner == null) {
4028 return false;
4029 }
4030 return packageName.equals(deviceOwner.getPackageName());
Amith Yamasani71e6c692013-03-24 17:39:28 -07004031 }
4032
Makoto Onukic8a5a552015-11-19 14:29:12 -08004033 private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) {
4034 if (mService != null) {
4035 try {
4036 return mService.getDeviceOwnerComponent(callingUserOnly);
4037 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004038 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08004039 }
4040 }
4041 return null;
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004042 }
4043
Jason Monkb0dced82014-06-06 14:36:20 -04004044 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08004045 * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's
4046 * no device owner.
4047 *
4048 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07004049 *
4050 * @hide
4051 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08004052 public int getDeviceOwnerUserId() {
4053 if (mService != null) {
4054 try {
4055 return mService.getDeviceOwnerUserId();
4056 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004057 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08004058 }
4059 }
4060 return UserHandle.USER_NULL;
Makoto Onukia52562c2015-10-01 16:12:31 -07004061 }
4062
4063 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004064 * Clears the current device owner. The caller must be the device owner. This function should be
4065 * used cautiously as once it is called it cannot be undone. The device owner can only be set as
4066 * a part of device setup before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04004067 *
4068 * @param packageName The package name of the device owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004069 * @throws SecurityException if the caller is not in {@code packageName} or {@code packageName}
4070 * does not own the current device owner component.
Jason Monkb0dced82014-06-06 14:36:20 -04004071 */
Jason Monk94d2cf92014-06-18 09:53:34 -04004072 public void clearDeviceOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004073 throwIfParentInstance("clearDeviceOwnerApp");
Jason Monkb0dced82014-06-06 14:36:20 -04004074 if (mService != null) {
4075 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04004076 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04004077 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004078 throw re.rethrowFromSystemServer();
Jason Monkb0dced82014-06-06 14:36:20 -04004079 }
4080 }
4081 }
4082
Makoto Onukia52562c2015-10-01 16:12:31 -07004083 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08004084 * Returns the device owner package name, only if it's running on the calling user.
4085 *
4086 * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity.
Makoto Onukia52562c2015-10-01 16:12:31 -07004087 *
4088 * @hide
4089 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01004090 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004091 public @Nullable String getDeviceOwner() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004092 throwIfParentInstance("getDeviceOwner");
Makoto Onukic8a5a552015-11-19 14:29:12 -08004093 final ComponentName name = getDeviceOwnerComponentOnCallingUser();
4094 return name != null ? name.getPackageName() : null;
Makoto Onukia52562c2015-10-01 16:12:31 -07004095 }
4096
4097 /**
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004098 * Called by the system to find out whether the device is managed by a Device Owner.
Makoto Onukic8a5a552015-11-19 14:29:12 -08004099 *
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004100 * @return whether the device is managed by a Device Owner.
4101 * @throws SecurityException if the caller is not the device owner, does not hold the
4102 * MANAGE_USERS permission and is not the system.
Makoto Onukia52562c2015-10-01 16:12:31 -07004103 *
4104 * @hide
4105 */
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004106 @SystemApi
4107 @TestApi
Makoto Onukic8a5a552015-11-19 14:29:12 -08004108 public boolean isDeviceManaged() {
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004109 try {
4110 return mService.hasDeviceOwner();
4111 } catch (RemoteException re) {
4112 throw re.rethrowFromSystemServer();
4113 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08004114 }
4115
4116 /**
4117 * Returns the device owner name. Note this method *will* return the device owner
4118 * name when it's running on a different user.
4119 *
4120 * <p>Requires the MANAGE_USERS permission.
4121 *
4122 * @hide
4123 */
Makoto Onukia2b274b2016-01-19 13:26:02 -08004124 @SystemApi
Makoto Onukic8a5a552015-11-19 14:29:12 -08004125 public String getDeviceOwnerNameOnAnyUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004126 throwIfParentInstance("getDeviceOwnerNameOnAnyUser");
Amith Yamasani71e6c692013-03-24 17:39:28 -07004127 if (mService != null) {
4128 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07004129 return mService.getDeviceOwnerName();
Amith Yamasani71e6c692013-03-24 17:39:28 -07004130 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004131 throw re.rethrowFromSystemServer();
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004132 }
4133 }
4134 return null;
4135 }
Adam Connors776c5552014-01-09 10:42:56 +00004136
4137 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04004138 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004139 * @deprecated Do not use
4140 * @removed
Julia Reynolds20118f12015-02-11 12:34:08 -05004141 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004142 @Deprecated
Julia Reynolds20118f12015-02-11 12:34:08 -05004143 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004144 public @Nullable String getDeviceInitializerApp() {
Julia Reynolds20118f12015-02-11 12:34:08 -05004145 return null;
4146 }
4147
4148 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004149 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004150 * @deprecated Do not use
4151 * @removed
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004152 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004153 @Deprecated
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004154 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004155 public @Nullable ComponentName getDeviceInitializerComponent() {
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004156 return null;
4157 }
4158
Julia Reynolds20118f12015-02-11 12:34:08 -05004159 /**
Adam Connors776c5552014-01-09 10:42:56 +00004160 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004161 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304162 * Sets the given component as an active admin and registers the package as the profile
4163 * owner for this user. The package must already be installed and there shouldn't be
4164 * an existing profile owner registered for this user. Also, this method must be called
4165 * before the user setup has been completed.
4166 * <p>
4167 * This method can only be called by system apps that hold MANAGE_USERS permission and
4168 * MANAGE_DEVICE_ADMINS permission.
4169 * @param admin The component to register as an active admin and profile owner.
4170 * @param ownerName The user-visible name of the entity that is managing this user.
4171 * @return whether the admin was successfully registered as the profile owner.
4172 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
4173 * the user has already been set up.
4174 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07004175 @Deprecated
Justin Morey80440cc2014-07-24 09:16:35 -05004176 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07004177 public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304178 throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004179 throwIfParentInstance("setActiveProfileOwner");
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304180 if (mService != null) {
4181 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004182 final int myUserId = myUserId();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304183 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004184 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304185 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004186 throw re.rethrowFromSystemServer();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304187 }
4188 }
4189 return false;
4190 }
4191
4192 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004193 * Clears the active profile owner and removes all user restrictions. The caller must be from
4194 * the same package as the active profile owner for this user, otherwise a SecurityException
4195 * will be thrown.
4196 * <p>
4197 * This doesn't work for managed profile owners.
Makoto Onuki5bf68022016-01-27 13:49:19 -08004198 *
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004199 * @param admin The component to remove as the profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004200 * @throws SecurityException if {@code admin} is not an active profile owner.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004201 */
Robin Lee25e26452015-06-02 09:56:29 -07004202 public void clearProfileOwner(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004203 throwIfParentInstance("clearProfileOwner");
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004204 if (mService != null) {
4205 try {
4206 mService.clearProfileOwner(admin);
4207 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004208 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004209 }
4210 }
4211 }
4212
4213 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05004214 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07004215 * Checks whether the user was already setup.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004216 */
4217 public boolean hasUserSetupCompleted() {
4218 if (mService != null) {
4219 try {
4220 return mService.hasUserSetupCompleted();
4221 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004222 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004223 }
4224 }
4225 return true;
4226 }
4227
4228 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004229 * @hide
4230 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00004231 * already be installed. There must not already be a profile owner for this user.
4232 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
4233 * this method.
4234 * Calling this after the setup phase of the specified user has completed is allowed only if:
4235 * - the caller is SYSTEM_UID.
4236 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004237 * @param admin the component name to be registered as profile owner.
4238 * @param ownerName the human readable name of the organisation associated with this DPM.
4239 * @param userHandle the userId to set the profile owner for.
4240 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00004241 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
4242 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004243 */
Robin Lee25e26452015-06-02 09:56:29 -07004244 public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName,
Robin Leeddd553f2015-04-30 14:18:22 +01004245 int userHandle) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00004246 if (mService != null) {
4247 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004248 if (ownerName == null) {
4249 ownerName = "";
4250 }
4251 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00004252 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004253 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004254 }
4255 }
4256 return false;
4257 }
4258
4259 /**
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004260 * Sets the device owner information to be shown on the lock screen.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004261 * <p>
4262 * If the device owner information is {@code null} or empty then the device owner info is
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004263 * cleared and the user owner info is shown on the lock screen if it is set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004264 * <p>
4265 * If the device owner information contains only whitespaces then the message on the lock screen
4266 * will be blank and the user will not be allowed to change it.
4267 * <p>
4268 * If the device owner information needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00004269 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
4270 * and set a new version of this string accordingly.
4271 *
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004272 * @param admin The name of the admin component to check.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004273 * @param info Device owner information which will be displayed instead of the user owner info.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004274 * @throws SecurityException if {@code admin} is not a device owner.
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004275 */
Andrei Stingaceanu16187902016-03-21 15:44:45 +00004276 public void setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, CharSequence info) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004277 throwIfParentInstance("setDeviceOwnerLockScreenInfo");
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004278 if (mService != null) {
4279 try {
Andrei Stingaceanu16187902016-03-21 15:44:45 +00004280 mService.setDeviceOwnerLockScreenInfo(admin, info);
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004281 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004282 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004283 }
4284 }
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004285 }
4286
4287 /**
4288 * @return The device owner information. If it is not set returns {@code null}.
4289 */
Andrei Stingaceanu16187902016-03-21 15:44:45 +00004290 public CharSequence getDeviceOwnerLockScreenInfo() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004291 throwIfParentInstance("getDeviceOwnerLockScreenInfo");
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004292 if (mService != null) {
4293 try {
4294 return mService.getDeviceOwnerLockScreenInfo();
4295 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004296 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004297 }
4298 }
4299 return null;
4300 }
4301
4302 /**
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004303 * Called by device or profile owners to suspend packages for this user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004304 * <p>
4305 * A suspended package will not be able to start activities. Its notifications will be hidden,
4306 * it will not show up in recents, will not be able to show toasts or dialogs or ring the
4307 * device.
4308 * <p>
4309 * The package must already be installed. If the package is uninstalled while suspended the
4310 * package will no longer be suspended. The admin can block this by using
Kenny Guy871f3eb2016-03-09 20:06:16 +00004311 * {@link #setUninstallBlocked}.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004312 *
4313 * @param admin The name of the admin component to check.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004314 * @param packageNames The package names to suspend or unsuspend.
4315 * @param suspended If set to {@code true} than the packages will be suspended, if set to
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004316 * {@code false} the packages will be unsuspended.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004317 * @return an array of package names for which the suspended status is not set as requested in
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004318 * this method.
4319 * @throws SecurityException if {@code admin} is not a device or profile owner.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004320 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004321 public @NonNull String[] setPackagesSuspended(@NonNull ComponentName admin,
4322 @NonNull String[] packageNames, boolean suspended) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004323 throwIfParentInstance("setPackagesSuspended");
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004324 if (mService != null) {
4325 try {
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004326 return mService.setPackagesSuspended(admin, packageNames, suspended);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004327 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004328 throw re.rethrowFromSystemServer();
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004329 }
4330 }
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004331 return packageNames;
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004332 }
4333
4334 /**
4335 * Called by device or profile owners to determine if a package is suspended.
4336 *
4337 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4338 * @param packageName The name of the package to retrieve the suspended status of.
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00004339 * @return {@code true} if the package is suspended or {@code false} if the package is not
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004340 * suspended, could not be found or an error occurred.
4341 * @throws SecurityException if {@code admin} is not a device or profile owner.
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004342 * @throws NameNotFoundException if the package could not be found.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004343 */
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004344 public boolean isPackageSuspended(@NonNull ComponentName admin, String packageName)
4345 throws NameNotFoundException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004346 throwIfParentInstance("isPackageSuspended");
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004347 if (mService != null) {
4348 try {
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004349 return mService.isPackageSuspended(admin, packageName);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004350 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004351 throw e.rethrowFromSystemServer();
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004352 } catch (IllegalArgumentException ex) {
4353 throw new NameNotFoundException(packageName);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004354 }
4355 }
4356 return false;
4357 }
4358
4359 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004360 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
4361 * be used. Only the profile owner can call this.
4362 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01004363 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004364 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004365 * @throws SecurityException if {@code admin} is not a profile owner.
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004366 */
Robin Lee25e26452015-06-02 09:56:29 -07004367 public void setProfileEnabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004368 throwIfParentInstance("setProfileEnabled");
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004369 if (mService != null) {
4370 try {
4371 mService.setProfileEnabled(admin);
4372 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004373 throw e.rethrowFromSystemServer();
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004374 }
4375 }
4376 }
4377
4378 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004379 * Sets the name of the profile. In the device owner case it sets the name of the user which it
4380 * is called from. Only a profile owner or device owner can call this. If this is never called
4381 * by the profile or device owner, the name will be set to default values.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004382 *
4383 * @see #isProfileOwnerApp
4384 * @see #isDeviceOwnerApp
Robin Lee25e26452015-06-02 09:56:29 -07004385 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004386 * @param profileName The name of the profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004387 * @throws SecurityException if {@code admin} is not a device or profile owner.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004388 */
Robin Lee25e26452015-06-02 09:56:29 -07004389 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004390 throwIfParentInstance("setProfileName");
Jessica Hummel1333ea12014-06-23 11:20:10 +01004391 if (mService != null) {
4392 try {
Robin Lee25e26452015-06-02 09:56:29 -07004393 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07004394 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004395 throw e.rethrowFromSystemServer();
Fyodor Kupolov78f13142015-05-27 16:52:45 -07004396 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01004397 }
4398 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01004399
4400 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004401 * Used to determine if a particular package is registered as the profile owner for the
Makoto Onuki32b30572015-12-11 14:29:51 -08004402 * user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004403 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00004404 *
4405 * @param packageName The package name of the app to compare with the registered profile owner.
4406 * @return Whether or not the package is registered as the profile owner.
4407 */
4408 public boolean isProfileOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004409 throwIfParentInstance("isProfileOwnerApp");
Adam Connors776c5552014-01-09 10:42:56 +00004410 if (mService != null) {
4411 try {
Makoto Onuki90b89652016-01-28 14:44:18 -08004412 ComponentName profileOwner = mService.getProfileOwner(myUserId());
Nicolas Prevot90af6d72014-07-30 14:19:12 +01004413 return profileOwner != null
4414 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00004415 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004416 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004417 }
4418 }
4419 return false;
4420 }
4421
4422 /**
4423 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07004424 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00004425 * owner has been set for that user.
4426 * @throws IllegalArgumentException if the userId is invalid.
4427 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01004428 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004429 public @Nullable ComponentName getProfileOwner() throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004430 throwIfParentInstance("getProfileOwner");
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01004431 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
4432 }
4433
4434 /**
4435 * @see #getProfileOwner()
4436 * @hide
4437 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004438 public @Nullable ComponentName getProfileOwnerAsUser(final int userId)
4439 throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00004440 if (mService != null) {
4441 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01004442 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00004443 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004444 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004445 }
4446 }
4447 return null;
4448 }
4449
4450 /**
4451 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07004452 * @return the human readable name of the organisation associated with this DPM or {@code null}
4453 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00004454 * @throws IllegalArgumentException if the userId is invalid.
4455 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004456 public @Nullable String getProfileOwnerName() throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00004457 if (mService != null) {
4458 try {
4459 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
4460 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004461 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004462 }
4463 }
4464 return null;
4465 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004466
4467 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07004468 * @hide
Makoto Onukic8a5a552015-11-19 14:29:12 -08004469 * @param userId The user for whom to fetch the profile owner name, if any.
Amith Yamasani38f836b2014-08-20 14:51:15 -07004470 * @return the human readable name of the organisation associated with this profile owner or
4471 * null if one is not set.
4472 * @throws IllegalArgumentException if the userId is invalid.
4473 */
4474 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004475 public @Nullable String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004476 throwIfParentInstance("getProfileOwnerNameAsUser");
Amith Yamasani38f836b2014-08-20 14:51:15 -07004477 if (mService != null) {
4478 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02004479 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07004480 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004481 throw re.rethrowFromSystemServer();
Amith Yamasani38f836b2014-08-20 14:51:15 -07004482 }
4483 }
4484 return null;
4485 }
4486
4487 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004488 * Called by a profile owner or device owner to add a default intent handler activity for
4489 * intents that match a certain intent filter. This activity will remain the default intent
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004490 * handler even if the set of potential event handlers for the intent filter changes and if the
4491 * intent preferences are reset.
4492 * <p>
4493 * The default disambiguation mechanism takes over if the activity is not installed (anymore).
4494 * When the activity is (re)installed, it is automatically reset as default intent handler for
4495 * the filter.
4496 * <p>
4497 * The calling device admin must be a profile owner or device owner. If it is not, a security
4498 * exception will be thrown.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004499 *
4500 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4501 * @param filter The IntentFilter for which a default handler is added.
4502 * @param activity The Activity that is added as default intent handler.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004503 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004504 */
Robin Lee25e26452015-06-02 09:56:29 -07004505 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
4506 @NonNull ComponentName activity) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004507 throwIfParentInstance("addPersistentPreferredActivity");
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004508 if (mService != null) {
4509 try {
4510 mService.addPersistentPreferredActivity(admin, filter, activity);
4511 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004512 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004513 }
4514 }
4515 }
4516
4517 /**
4518 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00004519 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004520 * <p>
4521 * The calling device admin must be a profile owner. If it is not, a security exception will be
4522 * thrown.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004523 *
4524 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4525 * @param packageName The name of the package for which preferences are removed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004526 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004527 */
Robin Lee25e26452015-06-02 09:56:29 -07004528 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004529 String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004530 throwIfParentInstance("clearPackagePersistentPreferredActivities");
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004531 if (mService != null) {
4532 try {
4533 mService.clearPackagePersistentPreferredActivities(admin, packageName);
4534 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004535 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004536 }
4537 }
4538 }
Robin Lee66e5d962014-04-09 16:44:21 +01004539
4540 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00004541 * Called by a profile owner or device owner to grant permission to a package to manage
4542 * application restrictions for the calling user via {@link #setApplicationRestrictions} and
4543 * {@link #getApplicationRestrictions}.
4544 * <p>
4545 * This permission is persistent until it is later cleared by calling this method with a
4546 * {@code null} value or uninstalling the managing package.
Rubin Xuf03d0a62016-02-10 14:54:15 +00004547 * <p>
4548 * The supplied application restriction managing package must be installed when calling this
Victor Changcd14c0a2016-03-16 19:10:15 +00004549 * API, otherwise an {@link NameNotFoundException} will be thrown.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004550 *
4551 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4552 * @param packageName The package name which will be given access to application restrictions
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004553 * APIs. If {@code null} is given the current package will be cleared.
4554 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Changcd14c0a2016-03-16 19:10:15 +00004555 * @throws NameNotFoundException if {@code packageName} is not found
Esteban Talaverabf60f722015-12-10 16:26:44 +00004556 */
4557 public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin,
Victor Changcd14c0a2016-03-16 19:10:15 +00004558 @Nullable String packageName) throws NameNotFoundException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004559 throwIfParentInstance("setApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00004560 if (mService != null) {
4561 try {
Victor Changcd14c0a2016-03-16 19:10:15 +00004562 if (!mService.setApplicationRestrictionsManagingPackage(admin, packageName)) {
4563 throw new NameNotFoundException(packageName);
4564 }
Esteban Talaverabf60f722015-12-10 16:26:44 +00004565 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004566 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00004567 }
4568 }
4569 }
4570
4571 /**
4572 * Called by a profile owner or device owner to retrieve the application restrictions managing
4573 * package for the current user, or {@code null} if none is set.
4574 *
4575 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4576 * @return The package name allowed to manage application restrictions on the current user, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004577 * {@code null} if none is set.
4578 * @throws SecurityException if {@code admin} is not a device or profile owner.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004579 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004580 public @Nullable String getApplicationRestrictionsManagingPackage(
4581 @NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004582 throwIfParentInstance("getApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00004583 if (mService != null) {
4584 try {
4585 return mService.getApplicationRestrictionsManagingPackage(admin);
4586 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004587 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00004588 }
4589 }
4590 return null;
4591 }
4592
4593 /**
Esteban Talavera96895ca2016-03-16 12:00:40 +00004594 * Called by any application to find out whether it has been granted permission via
4595 * {@link #setApplicationRestrictionsManagingPackage} to manage application restrictions
4596 * for the calling user.
4597 *
4598 * <p>This is done by comparing the calling Linux uid with the uid of the package specified by
4599 * that method.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004600 */
4601 public boolean isCallerApplicationRestrictionsManagingPackage() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004602 throwIfParentInstance("isCallerApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00004603 if (mService != null) {
4604 try {
4605 return mService.isCallerApplicationRestrictionsManagingPackage();
4606 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004607 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00004608 }
4609 }
4610 return false;
4611 }
4612
4613 /**
4614 * Sets the application restrictions for a given target application running in the calling user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004615 * <p>
4616 * The caller must be a profile or device owner on that user, or the package allowed to manage
4617 * application restrictions via {@link #setApplicationRestrictionsManagingPackage}; otherwise a
4618 * security exception will be thrown.
4619 * <p>
4620 * The provided {@link Bundle} consists of key-value pairs, where the types of values may be:
Esteban Talavera6b8e0642015-08-10 17:26:04 +01004621 * <ul>
4622 * <li>{@code boolean}
4623 * <li>{@code int}
4624 * <li>{@code String} or {@code String[]}
4625 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
4626 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004627 * <p>
4628 * If the restrictions are not available yet, but may be applied in the near future, the caller
4629 * can notify the target application of that by adding
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00004630 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004631 * <p>
4632 * The application restrictions are only made visible to the target application via
4633 * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or device
4634 * owner, and the application restrictions managing package via
Esteban Talaverabf60f722015-12-10 16:26:44 +00004635 * {@link #getApplicationRestrictions}.
Robin Lee66e5d962014-04-09 16:44:21 +01004636 *
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07004637 * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
4638 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00004639 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004640 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01004641 * @param packageName The name of the package to update restricted settings for.
4642 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004643 * set of active restrictions.
4644 * @throws SecurityException if {@code admin} is not a device or profile owner.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004645 * @see #setApplicationRestrictionsManagingPackage
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00004646 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01004647 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07004648 @WorkerThread
Esteban Talaverabf60f722015-12-10 16:26:44 +00004649 public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01004650 Bundle settings) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004651 throwIfParentInstance("setApplicationRestrictions");
Robin Lee66e5d962014-04-09 16:44:21 +01004652 if (mService != null) {
4653 try {
4654 mService.setApplicationRestrictions(admin, packageName, settings);
4655 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004656 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01004657 }
4658 }
4659 }
4660
4661 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004662 * Sets a list of configuration features to enable for a TrustAgent component. This is meant to
4663 * be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all trust
4664 * agents but those enabled by this function call. If flag
Jim Millere303bf42014-08-26 17:12:29 -07004665 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004666 * <p>
4667 * The calling device admin must have requested
4668 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method;
4669 * if not, a security exception will be thrown.
Tony Mak089d8402016-04-05 17:42:55 +01004670 * <p>
4671 * This method can be called on the {@link DevicePolicyManager} instance returned by
4672 * {@link #getParentProfileInstance(ComponentName)} in order to set the configuration for
4673 * the parent profile.
Jim Miller604e7552014-07-18 19:00:02 -07004674 *
4675 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07004676 * @param target Component name of the agent to be enabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004677 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent will be
4678 * strictly disabled according to the state of the
4679 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
4680 * <p>
4681 * If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all
4682 * admins, then it's up to the TrustAgent itself to aggregate the values from all
4683 * device admins.
4684 * <p>
4685 * Consult documentation for the specific TrustAgent to determine legal options
4686 * parameters.
4687 * @throws SecurityException if {@code admin} is not an active administrator or does not use
4688 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES}
Jim Miller604e7552014-07-18 19:00:02 -07004689 */
Robin Lee25e26452015-06-02 09:56:29 -07004690 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
4691 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07004692 if (mService != null) {
4693 try {
Tony Mak089d8402016-04-05 17:42:55 +01004694 mService.setTrustAgentConfiguration(admin, target, configuration, mParentInstance);
Jim Miller604e7552014-07-18 19:00:02 -07004695 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004696 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07004697 }
4698 }
4699 }
4700
4701 /**
Jim Millere303bf42014-08-26 17:12:29 -07004702 * Gets configuration for the given trust agent based on aggregating all calls to
4703 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
4704 * all device admins.
Tony Mak089d8402016-04-05 17:42:55 +01004705 * <p>
4706 * This method can be called on the {@link DevicePolicyManager} instance returned by
4707 * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the configuration set
4708 * on the parent profile.
Jim Miller604e7552014-07-18 19:00:02 -07004709 *
Jim Millerb5db57a2015-01-14 18:17:19 -08004710 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
4711 * this function returns a list of configurations for all admins that declare
4712 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
4713 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
4714 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
4715 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07004716 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07004717 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07004718 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004719 public @Nullable List<PersistableBundle> getTrustAgentConfiguration(
4720 @Nullable ComponentName admin, @NonNull ComponentName agent) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004721 return getTrustAgentConfiguration(admin, agent, myUserId());
Jim Millere303bf42014-08-26 17:12:29 -07004722 }
4723
4724 /** @hide per-user version */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004725 public @Nullable List<PersistableBundle> getTrustAgentConfiguration(
4726 @Nullable ComponentName admin, @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07004727 if (mService != null) {
4728 try {
Tony Mak089d8402016-04-05 17:42:55 +01004729 return mService.getTrustAgentConfiguration(admin, agent, userHandle,
4730 mParentInstance);
Jim Miller604e7552014-07-18 19:00:02 -07004731 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004732 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07004733 }
4734 }
Jim Millere303bf42014-08-26 17:12:29 -07004735 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07004736 }
4737
4738 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004739 * Called by a profile owner of a managed profile to set whether caller-Id information from the
4740 * managed profile will be shown in the parent profile, for incoming calls.
4741 * <p>
4742 * The calling device admin must be a profile owner. If it is not, a security exception will be
4743 * thrown.
Adam Connors210fe212014-07-17 15:41:43 +01004744 *
Robin Lee25e26452015-06-02 09:56:29 -07004745 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01004746 * @param disabled If true caller-Id information in the managed profile is not displayed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004747 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors210fe212014-07-17 15:41:43 +01004748 */
Robin Lee25e26452015-06-02 09:56:29 -07004749 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004750 throwIfParentInstance("setCrossProfileCallerIdDisabled");
Adam Connors210fe212014-07-17 15:41:43 +01004751 if (mService != null) {
4752 try {
Robin Lee25e26452015-06-02 09:56:29 -07004753 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01004754 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004755 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01004756 }
4757 }
4758 }
4759
4760 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004761 * Called by a profile owner of a managed profile to determine whether or not caller-Id
4762 * information has been disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004763 * <p>
4764 * The calling device admin must be a profile owner. If it is not, a security exception will be
4765 * thrown.
Adam Connors210fe212014-07-17 15:41:43 +01004766 *
Robin Lee25e26452015-06-02 09:56:29 -07004767 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004768 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors210fe212014-07-17 15:41:43 +01004769 */
Robin Lee25e26452015-06-02 09:56:29 -07004770 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004771 throwIfParentInstance("getCrossProfileCallerIdDisabled");
Adam Connors210fe212014-07-17 15:41:43 +01004772 if (mService != null) {
4773 try {
Robin Lee25e26452015-06-02 09:56:29 -07004774 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01004775 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004776 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01004777 }
4778 }
4779 return false;
4780 }
4781
4782 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07004783 * Determine whether or not caller-Id information has been disabled.
4784 *
4785 * @param userHandle The user for whom to check the caller-id permission
4786 * @hide
4787 */
4788 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
4789 if (mService != null) {
4790 try {
4791 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
4792 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004793 throw e.rethrowFromSystemServer();
Amith Yamasani570002f2014-07-18 15:48:54 -07004794 }
4795 }
4796 return false;
4797 }
4798
4799 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004800 * Called by a profile owner of a managed profile to set whether contacts search from the
4801 * managed profile will be shown in the parent profile, for incoming calls.
4802 * <p>
4803 * The calling device admin must be a profile owner. If it is not, a security exception will be
4804 * thrown.
Victor Chang1060c6182016-01-04 20:16:23 +00004805 *
4806 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4807 * @param disabled If true contacts search in the managed profile is not displayed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004808 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Chang1060c6182016-01-04 20:16:23 +00004809 */
4810 public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin,
4811 boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004812 throwIfParentInstance("setCrossProfileContactsSearchDisabled");
Victor Chang1060c6182016-01-04 20:16:23 +00004813 if (mService != null) {
4814 try {
4815 mService.setCrossProfileContactsSearchDisabled(admin, disabled);
4816 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004817 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00004818 }
4819 }
4820 }
4821
4822 /**
4823 * Called by a profile owner of a managed profile to determine whether or not contacts search
4824 * has been disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004825 * <p>
4826 * The calling device admin must be a profile owner. If it is not, a security exception will be
4827 * thrown.
Victor Chang1060c6182016-01-04 20:16:23 +00004828 *
4829 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004830 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Chang1060c6182016-01-04 20:16:23 +00004831 */
4832 public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004833 throwIfParentInstance("getCrossProfileContactsSearchDisabled");
Victor Chang1060c6182016-01-04 20:16:23 +00004834 if (mService != null) {
4835 try {
4836 return mService.getCrossProfileContactsSearchDisabled(admin);
4837 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004838 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00004839 }
4840 }
4841 return false;
4842 }
4843
4844
4845 /**
4846 * Determine whether or not contacts search has been disabled.
4847 *
4848 * @param userHandle The user for whom to check the contacts search permission
4849 * @hide
4850 */
4851 public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) {
4852 if (mService != null) {
4853 try {
4854 return mService
4855 .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier());
4856 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004857 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00004858 }
4859 }
4860 return false;
4861 }
4862
4863 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004864 * Start Quick Contact on the managed profile for the user, if the policy allows.
Victor Chang97bdacc2016-01-21 22:24:11 +00004865 *
Makoto Onuki1040da12015-03-19 11:24:00 -07004866 * @hide
4867 */
4868 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
Victor Chang97bdacc2016-01-21 22:24:11 +00004869 boolean isContactIdIgnored, long directoryId, Intent originalIntent) {
Makoto Onuki1040da12015-03-19 11:24:00 -07004870 if (mService != null) {
4871 try {
Victor Chang97bdacc2016-01-21 22:24:11 +00004872 mService.startManagedQuickContact(actualLookupKey, actualContactId,
4873 isContactIdIgnored, directoryId, originalIntent);
Makoto Onuki1040da12015-03-19 11:24:00 -07004874 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004875 throw e.rethrowFromSystemServer();
Makoto Onuki1040da12015-03-19 11:24:00 -07004876 }
4877 }
4878 }
4879
4880 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004881 * Start Quick Contact on the managed profile for the user, if the policy allows.
Ricky Wai494b95d2015-11-20 16:07:15 +00004882 * @hide
4883 */
4884 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
4885 Intent originalIntent) {
Victor Chang97bdacc2016-01-21 22:24:11 +00004886 startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT,
Ricky Wai494b95d2015-11-20 16:07:15 +00004887 originalIntent);
4888 }
4889
4890 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004891 * Called by a profile owner of a managed profile to set whether bluetooth devices can access
4892 * enterprise contacts.
Ricky Wai778ba132015-03-31 14:21:22 +01004893 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004894 * The calling device admin must be a profile owner. If it is not, a security exception will be
4895 * thrown.
Ricky Wai778ba132015-03-31 14:21:22 +01004896 * <p>
4897 * This API works on managed profile only.
4898 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004899 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4900 * @param disabled If true, bluetooth devices cannot access enterprise contacts.
4901 * @throws SecurityException if {@code admin} is not a device or profile owner.
Ricky Wai778ba132015-03-31 14:21:22 +01004902 */
Robin Lee25e26452015-06-02 09:56:29 -07004903 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004904 throwIfParentInstance("setBluetoothContactSharingDisabled");
Ricky Wai778ba132015-03-31 14:21:22 +01004905 if (mService != null) {
4906 try {
Robin Lee25e26452015-06-02 09:56:29 -07004907 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01004908 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004909 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01004910 }
4911 }
4912 }
4913
4914 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004915 * Called by a profile owner of a managed profile to determine whether or not Bluetooth devices
4916 * cannot access enterprise contacts.
Ricky Wai778ba132015-03-31 14:21:22 +01004917 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004918 * The calling device admin must be a profile owner. If it is not, a security exception will be
4919 * thrown.
Ricky Wai778ba132015-03-31 14:21:22 +01004920 * <p>
4921 * This API works on managed profile only.
4922 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004923 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4924 * @throws SecurityException if {@code admin} is not a device or profile owner.
Ricky Wai778ba132015-03-31 14:21:22 +01004925 */
Robin Lee25e26452015-06-02 09:56:29 -07004926 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004927 throwIfParentInstance("getBluetoothContactSharingDisabled");
Ricky Wai778ba132015-03-31 14:21:22 +01004928 if (mService != null) {
4929 try {
Robin Lee25e26452015-06-02 09:56:29 -07004930 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01004931 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004932 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01004933 }
4934 }
4935 return true;
4936 }
4937
4938 /**
4939 * Determine whether or not Bluetooth devices cannot access contacts.
4940 * <p>
4941 * This API works on managed profile UserHandle only.
4942 *
4943 * @param userHandle The user for whom to check the caller-id permission
4944 * @hide
4945 */
4946 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
4947 if (mService != null) {
4948 try {
4949 return mService.getBluetoothContactSharingDisabledForUser(userHandle
4950 .getIdentifier());
4951 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004952 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01004953 }
4954 }
4955 return true;
4956 }
4957
4958 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004959 * Called by the profile owner of a managed profile so that some intents sent in the managed
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004960 * profile can also be resolved in the parent, or vice versa. Only activity intents are
4961 * supported.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00004962 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004963 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01004964 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004965 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01004966 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004967 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
4968 * @throws SecurityException if {@code admin} is not a device or profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004969 */
Robin Lee25e26452015-06-02 09:56:29 -07004970 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004971 throwIfParentInstance("addCrossProfileIntentFilter");
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004972 if (mService != null) {
4973 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01004974 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004975 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004976 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004977 }
4978 }
4979 }
4980
4981 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004982 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
4983 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01004984 * Only removes those that have been set by the profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004985 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004986 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004987 * @throws SecurityException if {@code admin} is not a device or profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004988 */
Robin Lee25e26452015-06-02 09:56:29 -07004989 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004990 throwIfParentInstance("clearCrossProfileIntentFilters");
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004991 if (mService != null) {
4992 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01004993 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004994 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004995 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004996 }
4997 }
4998 }
4999
5000 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005001 * Called by a profile or device owner to set the permitted accessibility services. When set by
5002 * a device owner or profile owner the restriction applies to all profiles of the user the
5003 * device owner or profile owner is an admin for. By default the user can use any accessiblity
5004 * service. When zero or more packages have been added, accessiblity services that are not in
5005 * the list and not part of the system can not be enabled by the user.
5006 * <p>
5007 * Calling with a null value for the list disables the restriction so that all services can be
5008 * used, calling with an empty list only allows the builtin system's services.
5009 * <p>
5010 * System accesibility services are always available to the user the list can't modify this.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005011 *
5012 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5013 * @param packageNames List of accessibility service package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005014 * @return true if setting the restriction succeeded. It fail if there is one or more non-system
5015 * accessibility services enabled, that are not in the list.
5016 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005017 */
Robin Lee25e26452015-06-02 09:56:29 -07005018 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005019 List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005020 throwIfParentInstance("setPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005021 if (mService != null) {
5022 try {
5023 return mService.setPermittedAccessibilityServices(admin, packageNames);
5024 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005025 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005026 }
5027 }
5028 return false;
5029 }
5030
5031 /**
5032 * Returns the list of permitted accessibility services set by this device or profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005033 * <p>
5034 * An empty list means no accessibility services except system services are allowed. Null means
5035 * all accessibility services are allowed.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005036 *
5037 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5038 * @return List of accessiblity service package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005039 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005040 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005041 public @Nullable List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005042 throwIfParentInstance("getPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005043 if (mService != null) {
5044 try {
5045 return mService.getPermittedAccessibilityServices(admin);
5046 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005047 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005048 }
5049 }
5050 return null;
5051 }
5052
5053 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00005054 * Called by the system to check if a specific accessibility service is disabled by admin.
5055 *
5056 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5057 * @param packageName Accessibility service package name that needs to be checked.
5058 * @param userHandle user id the admin is running as.
5059 * @return true if the accessibility service is permitted, otherwise false.
5060 *
5061 * @hide
5062 */
5063 public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin,
5064 @NonNull String packageName, int userHandle) {
5065 if (mService != null) {
5066 try {
5067 return mService.isAccessibilityServicePermittedByAdmin(admin, packageName,
5068 userHandle);
5069 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005070 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00005071 }
5072 }
5073 return false;
5074 }
5075
5076 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005077 * Returns the list of accessibility services permitted by the device or profiles
5078 * owners of this user.
5079 *
5080 * <p>Null means all accessibility services are allowed, if a non-null list is returned
5081 * it will contain the intersection of the permitted lists for any device or profile
5082 * owners that apply to this user. It will also include any system accessibility services.
5083 *
5084 * @param userId which user to check for.
5085 * @return List of accessiblity service package names.
5086 * @hide
5087 */
5088 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07005089 public @Nullable List<String> getPermittedAccessibilityServices(int userId) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005090 throwIfParentInstance("getPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005091 if (mService != null) {
5092 try {
5093 return mService.getPermittedAccessibilityServicesForUser(userId);
5094 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005095 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005096 }
5097 }
5098 return null;
5099 }
5100
5101 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005102 * Called by a profile or device owner to set the permitted input methods services. When set by
5103 * a device owner or profile owner the restriction applies to all profiles of the user the
5104 * device owner or profile owner is an admin for. By default the user can use any input method.
5105 * When zero or more packages have been added, input method that are not in the list and not
5106 * part of the system can not be enabled by the user. This method will fail if it is called for
5107 * a admin that is not for the foreground user or a profile of the foreground user.
5108 * <p>
5109 * Calling with a null value for the list disables the restriction so that all input methods can
5110 * be used, calling with an empty list disables all but the system's own input methods.
5111 * <p>
5112 * System input methods are always available to the user this method can't modify this.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005113 *
5114 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5115 * @param packageNames List of input method package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005116 * @return true if setting the restriction succeeded. It will fail if there are one or more
5117 * non-system input methods currently enabled that are not in the packageNames list.
5118 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005119 */
Robin Lee25e26452015-06-02 09:56:29 -07005120 public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005121 throwIfParentInstance("setPermittedInputMethods");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005122 if (mService != null) {
5123 try {
5124 return mService.setPermittedInputMethods(admin, packageNames);
5125 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005126 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005127 }
5128 }
5129 return false;
5130 }
5131
5132
5133 /**
5134 * Returns the list of permitted input methods set by this device or profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005135 * <p>
5136 * An empty list means no input methods except system input methods are allowed. Null means all
5137 * input methods are allowed.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005138 *
5139 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5140 * @return List of input method package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005141 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005142 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005143 public @Nullable List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005144 throwIfParentInstance("getPermittedInputMethods");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005145 if (mService != null) {
5146 try {
5147 return mService.getPermittedInputMethods(admin);
5148 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005149 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005150 }
5151 }
5152 return null;
5153 }
5154
5155 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00005156 * Called by the system to check if a specific input method is disabled by admin.
5157 *
5158 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5159 * @param packageName Input method package name that needs to be checked.
5160 * @param userHandle user id the admin is running as.
5161 * @return true if the input method is permitted, otherwise false.
5162 *
5163 * @hide
5164 */
5165 public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin,
5166 @NonNull String packageName, int userHandle) {
5167 if (mService != null) {
5168 try {
5169 return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle);
5170 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005171 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00005172 }
5173 }
5174 return false;
5175 }
5176
5177 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005178 * Returns the list of input methods permitted by the device or profiles
Makoto Onuki32b30572015-12-11 14:29:51 -08005179 * owners of the current user. (*Not* calling user, due to a limitation in InputMethodManager.)
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005180 *
5181 * <p>Null means all input methods are allowed, if a non-null list is returned
5182 * it will contain the intersection of the permitted lists for any device or profile
5183 * owners that apply to this user. It will also include any system input methods.
5184 *
5185 * @return List of input method package names.
5186 * @hide
5187 */
5188 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07005189 public @Nullable List<String> getPermittedInputMethodsForCurrentUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005190 throwIfParentInstance("getPermittedInputMethodsForCurrentUser");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005191 if (mService != null) {
5192 try {
5193 return mService.getPermittedInputMethodsForCurrentUser();
5194 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005195 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005196 }
5197 }
5198 return null;
5199 }
5200
5201 /**
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005202 * Called by a device owner to get the list of apps to keep around as APKs even if no user has
5203 * currently installed it.
5204 *
5205 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5206 *
5207 * @return List of package names to keep cached.
5208 * @hide
5209 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005210 public @Nullable List<String> getKeepUninstalledPackages(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005211 throwIfParentInstance("getKeepUninstalledPackages");
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005212 if (mService != null) {
5213 try {
5214 return mService.getKeepUninstalledPackages(admin);
5215 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005216 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005217 }
5218 }
5219 return null;
5220 }
5221
5222 /**
5223 * Called by a device owner to set a list of apps to keep around as APKs even if no user has
5224 * currently installed it.
5225 *
5226 * <p>Please note that setting this policy does not imply that specified apps will be
5227 * automatically pre-cached.</p>
5228 *
5229 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5230 * @param packageNames List of package names to keep cached.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005231 * @throws SecurityException if {@code admin} is not a device owner.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005232 * @hide
5233 */
5234 public void setKeepUninstalledPackages(@NonNull ComponentName admin,
5235 @NonNull List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005236 throwIfParentInstance("setKeepUninstalledPackages");
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005237 if (mService != null) {
5238 try {
5239 mService.setKeepUninstalledPackages(admin, packageNames);
5240 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005241 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005242 }
5243 }
5244 }
5245
5246 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04005247 * Called by a device owner to create a user with the specified name. The UserHandle returned
5248 * by this method should not be persisted as user handles are recycled as users are removed and
5249 * created. If you need to persist an identifier for this user, use
5250 * {@link UserManager#getSerialNumberForUser}.
5251 *
5252 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5253 * @param name the user's name
5254 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07005255 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
5256 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01005257 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005258 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01005259 * @removed From {@link android.os.Build.VERSION_CODES#N}
Julia Reynolds1e958392014-05-16 14:25:21 -04005260 */
Kenny Guy14f48e52015-06-29 15:12:36 +01005261 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07005262 public @Nullable UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04005263 return null;
5264 }
5265
5266 /**
Jason Monk03978a42014-06-10 15:05:30 -04005267 * Called by a device owner to create a user with the specified name. The UserHandle returned
5268 * by this method should not be persisted as user handles are recycled as users are removed and
5269 * created. If you need to persist an identifier for this user, use
5270 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
5271 * immediately.
5272 *
5273 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
5274 * as registered as an active admin on the new user. The profile owner package will be
5275 * installed on the new user if it already is installed on the device.
5276 *
5277 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
5278 * profileOwnerComponent when onEnable is called.
5279 *
5280 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5281 * @param name the user's name
5282 * @param ownerName the human readable name of the organisation associated with this DPM.
5283 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
5284 * the user.
5285 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
5286 * on the new user.
5287 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07005288 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
5289 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01005290 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005291 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01005292 * @removed From {@link android.os.Build.VERSION_CODES#N}
Jason Monk03978a42014-06-10 15:05:30 -04005293 */
Kenny Guy14f48e52015-06-29 15:12:36 +01005294 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07005295 public @Nullable UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
Robin Lee25e26452015-06-02 09:56:29 -07005296 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04005297 return null;
5298 }
5299
5300 /**
phweissa92e1212016-01-25 17:14:10 +01005301 * Flag used by {@link #createAndManageUser} to skip setup wizard after creating a new user.
phweiss343fb332016-01-25 14:48:59 +01005302 */
5303 public static final int SKIP_SETUP_WIZARD = 0x0001;
5304
5305 /**
Lenka Trochtovac8202c82016-01-26 15:11:09 +01005306 * Flag used by {@link #createAndManageUser} to specify that the user should be created
5307 * ephemeral.
5308 * @hide
5309 */
5310 public static final int MAKE_USER_EPHEMERAL = 0x0002;
5311
5312 /**
phweissa92e1212016-01-25 17:14:10 +01005313 * Called by a device owner to create a user with the specified name and a given component of
5314 * the calling package as profile owner. The UserHandle returned by this method should not be
5315 * persisted as user handles are recycled as users are removed and created. If you need to
5316 * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new
5317 * user will not be started in the background.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005318 * <p>
5319 * admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also a
5320 * DeviceAdminReceiver in the same package as admin, and will become the profile owner and will
5321 * be registered as an active admin on the new user. The profile owner package will be installed
5322 * on the new user.
5323 * <p>
5324 * If the adminExtras are not null, they will be stored on the device until the user is started
5325 * for the first time. Then the extras will be passed to the admin when onEnable is called.
phweiss343fb332016-01-25 14:48:59 +01005326 *
5327 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5328 * @param name The user's name.
phweissa92e1212016-01-25 17:14:10 +01005329 * @param profileOwner Which {@link DeviceAdminReceiver} will be profile owner. Has to be in the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005330 * same package as admin, otherwise no user is created and an
5331 * IllegalArgumentException is thrown.
phweiss343fb332016-01-25 14:48:59 +01005332 * @param adminExtras Extras that will be passed to onEnable of the admin receiver on the new
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005333 * user.
phweissa92e1212016-01-25 17:14:10 +01005334 * @param flags {@link #SKIP_SETUP_WIZARD} is supported.
phweiss343fb332016-01-25 14:48:59 +01005335 * @see UserHandle
5336 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
5337 * user could not be created.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005338 * @throws SecurityException if {@code admin} is not a device owner.
phweiss343fb332016-01-25 14:48:59 +01005339 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005340 public @Nullable UserHandle createAndManageUser(@NonNull ComponentName admin,
5341 @NonNull String name,
phweissa92e1212016-01-25 17:14:10 +01005342 @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras,
5343 int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005344 throwIfParentInstance("createAndManageUser");
phweiss343fb332016-01-25 14:48:59 +01005345 try {
phweissa92e1212016-01-25 17:14:10 +01005346 return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags);
phweiss343fb332016-01-25 14:48:59 +01005347 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005348 throw re.rethrowFromSystemServer();
phweiss343fb332016-01-25 14:48:59 +01005349 }
phweiss343fb332016-01-25 14:48:59 +01005350 }
5351
5352 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005353 * Called by a device owner to remove a user and all associated data. The primary user can not
5354 * be removed.
Julia Reynolds1e958392014-05-16 14:25:21 -04005355 *
5356 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5357 * @param userHandle the user to remove.
5358 * @return {@code true} if the user was removed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005359 * @throws SecurityException if {@code admin} is not a device owner.
Julia Reynolds1e958392014-05-16 14:25:21 -04005360 */
Robin Lee25e26452015-06-02 09:56:29 -07005361 public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005362 throwIfParentInstance("removeUser");
Julia Reynolds1e958392014-05-16 14:25:21 -04005363 try {
5364 return mService.removeUser(admin, userHandle);
5365 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005366 throw re.rethrowFromSystemServer();
Julia Reynolds1e958392014-05-16 14:25:21 -04005367 }
5368 }
5369
5370 /**
Jason Monk582d9112014-07-09 19:57:08 -04005371 * Called by a device owner to switch the specified user to the foreground.
5372 *
5373 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5374 * @param userHandle the user to switch to; null will switch to primary.
5375 * @return {@code true} if the switch was successful, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005376 * @throws SecurityException if {@code admin} is not a device owner.
Jason Monk582d9112014-07-09 19:57:08 -04005377 * @see Intent#ACTION_USER_FOREGROUND
5378 */
Robin Lee25e26452015-06-02 09:56:29 -07005379 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005380 throwIfParentInstance("switchUser");
Jason Monk582d9112014-07-09 19:57:08 -04005381 try {
5382 return mService.switchUser(admin, userHandle);
5383 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005384 throw re.rethrowFromSystemServer();
Jason Monk582d9112014-07-09 19:57:08 -04005385 }
5386 }
5387
5388 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00005389 * Retrieves the application restrictions for a given target application running in the calling
5390 * user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005391 * <p>
5392 * The caller must be a profile or device owner on that user, or the package allowed to manage
5393 * application restrictions via {@link #setApplicationRestrictionsManagingPackage}; otherwise a
5394 * security exception will be thrown.
Robin Lee66e5d962014-04-09 16:44:21 +01005395 *
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005396 * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
5397 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00005398 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005399 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01005400 * @param packageName The name of the package to fetch restricted settings of.
5401 * @return {@link Bundle} of settings corresponding to what was set last time
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005402 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty
5403 * {@link Bundle} if no restrictions have been set.
5404 * @throws SecurityException if {@code admin} is not a device or profile owner.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005405 * @see {@link #setApplicationRestrictionsManagingPackage}
Robin Lee66e5d962014-04-09 16:44:21 +01005406 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005407 @WorkerThread
Makoto Onuki408e8e42016-10-25 12:10:27 -07005408 public @NonNull Bundle getApplicationRestrictions(
5409 @Nullable ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005410 throwIfParentInstance("getApplicationRestrictions");
Robin Lee66e5d962014-04-09 16:44:21 +01005411 if (mService != null) {
5412 try {
5413 return mService.getApplicationRestrictions(admin, packageName);
5414 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005415 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01005416 }
5417 }
5418 return null;
5419 }
Amith Yamasanibe465322014-04-24 13:45:17 -07005420
5421 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05005422 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07005423 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005424 * The calling device admin must be a profile or device owner; if it is not, a security
5425 * exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07005426 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005427 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5428 * @param key The key of the restriction. See the constants in {@link android.os.UserManager}
5429 * for the list of keys.
5430 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanibe465322014-04-24 13:45:17 -07005431 */
Robin Lee25e26452015-06-02 09:56:29 -07005432 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005433 throwIfParentInstance("addUserRestriction");
Amith Yamasanibe465322014-04-24 13:45:17 -07005434 if (mService != null) {
5435 try {
5436 mService.setUserRestriction(admin, key, true);
5437 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005438 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07005439 }
5440 }
5441 }
5442
5443 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05005444 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07005445 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005446 * The calling device admin must be a profile or device owner; if it is not, a security
5447 * exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07005448 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005449 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5450 * @param key The key of the restriction. See the constants in {@link android.os.UserManager}
5451 * for the list of keys.
5452 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanibe465322014-04-24 13:45:17 -07005453 */
Robin Lee25e26452015-06-02 09:56:29 -07005454 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005455 throwIfParentInstance("clearUserRestriction");
Amith Yamasanibe465322014-04-24 13:45:17 -07005456 if (mService != null) {
5457 try {
5458 mService.setUserRestriction(admin, key, false);
5459 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005460 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07005461 }
5462 }
5463 }
Adam Connors010cfd42014-04-16 12:48:13 +01005464
5465 /**
Makoto Onuki3a3092f2015-10-30 11:07:51 -07005466 * Called by a profile or device owner to get user restrictions set with
5467 * {@link #addUserRestriction(ComponentName, String)}.
5468 * <p>
5469 * The target user may have more restrictions set by the system or other device owner / profile
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005470 * owner. To get all the user restrictions currently set, use
Makoto Onuki3a3092f2015-10-30 11:07:51 -07005471 * {@link UserManager#getUserRestrictions()}.
5472 *
5473 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005474 * @throws SecurityException if {@code admin} is not a device or profile owner.
Makoto Onuki3a3092f2015-10-30 11:07:51 -07005475 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005476 public @NonNull Bundle getUserRestrictions(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005477 throwIfParentInstance("getUserRestrictions");
Makoto Onuki3a3092f2015-10-30 11:07:51 -07005478 Bundle ret = null;
5479 if (mService != null) {
5480 try {
Sudheer Shanka549b9692016-03-30 17:12:07 -07005481 ret = mService.getUserRestrictions(admin);
5482 } catch (RemoteException e) {
5483 throw e.rethrowFromSystemServer();
5484 }
5485 }
5486 return ret == null ? new Bundle() : ret;
5487 }
5488
5489 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005490 * Called by profile or device owners to hide or unhide packages. When a package is hidden it is
5491 * unavailable for use, but the data and actual package file remain.
Julia Reynolds966881e2014-05-14 12:23:08 -04005492 *
5493 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005494 * @param packageName The name of the package to hide or unhide.
5495 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005496 * unhidden.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005497 * @return boolean Whether the hidden setting of the package was successfully updated.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005498 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds966881e2014-05-14 12:23:08 -04005499 */
Robin Lee25e26452015-06-02 09:56:29 -07005500 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005501 boolean hidden) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005502 throwIfParentInstance("setApplicationHidden");
Julia Reynolds966881e2014-05-14 12:23:08 -04005503 if (mService != null) {
5504 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005505 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04005506 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005507 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04005508 }
5509 }
5510 return false;
5511 }
5512
5513 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05005514 * Called by profile or device owners to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04005515 *
5516 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005517 * @param packageName The name of the package to retrieve the hidden status of.
5518 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005519 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds966881e2014-05-14 12:23:08 -04005520 */
Robin Lee25e26452015-06-02 09:56:29 -07005521 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005522 throwIfParentInstance("isApplicationHidden");
Julia Reynolds966881e2014-05-14 12:23:08 -04005523 if (mService != null) {
5524 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005525 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04005526 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005527 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04005528 }
5529 }
5530 return false;
5531 }
5532
5533 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05005534 * Called by profile or device owners to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005535 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00005536 *
5537 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Makoto Onuki32b30572015-12-11 14:29:51 -08005538 * @param packageName The package to be re-enabled in the calling profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005539 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors655be2a2014-07-14 09:01:25 +00005540 */
Robin Lee25e26452015-06-02 09:56:29 -07005541 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005542 throwIfParentInstance("enableSystemApp");
Adam Connors655be2a2014-07-14 09:01:25 +00005543 if (mService != null) {
5544 try {
5545 mService.enableSystemApp(admin, packageName);
5546 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005547 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00005548 }
5549 }
5550 }
5551
5552 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005553 * Called by profile or device owners to re-enable system apps by intent that were disabled by
5554 * default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00005555 *
5556 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5557 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005558 * intent will be re-enabled in the calling profile.
Adam Connors655be2a2014-07-14 09:01:25 +00005559 * @return int The number of activities that matched the intent and were installed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005560 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors655be2a2014-07-14 09:01:25 +00005561 */
Robin Lee25e26452015-06-02 09:56:29 -07005562 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005563 throwIfParentInstance("enableSystemApp");
Adam Connors655be2a2014-07-14 09:01:25 +00005564 if (mService != null) {
5565 try {
5566 return mService.enableSystemAppWithIntent(admin, intent);
5567 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005568 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00005569 }
5570 }
5571 return 0;
5572 }
5573
5574 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00005575 * Called by a device owner or profile owner to disable account management for a specific type
5576 * of account.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005577 * <p>
5578 * The calling device admin must be a device owner or profile owner. If it is not, a security
5579 * exception will be thrown.
5580 * <p>
5581 * When account management is disabled for an account type, adding or removing an account of
5582 * that type will not be possible.
5583 * <p>
5584 * From {@link android.os.Build.VERSION_CODES#N} the profile or device owner can still use
Benjamin Franzb6c0ce42015-11-05 10:06:51 +00005585 * {@link android.accounts.AccountManager} APIs to add or remove accounts when account
5586 * management for a specific type is disabled.
5587 *
Sander Alewijnse650c3342014-05-08 18:00:50 +01005588 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5589 * @param accountType For which account management is disabled or enabled.
5590 * @param disabled The boolean indicating that account management will be disabled (true) or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005591 * enabled (false).
5592 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnse650c3342014-05-08 18:00:50 +01005593 */
Robin Lee25e26452015-06-02 09:56:29 -07005594 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01005595 boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005596 throwIfParentInstance("setAccountManagementDisabled");
Sander Alewijnse650c3342014-05-08 18:00:50 +01005597 if (mService != null) {
5598 try {
5599 mService.setAccountManagementDisabled(admin, accountType, disabled);
5600 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005601 throw e.rethrowFromSystemServer();
Sander Alewijnse650c3342014-05-08 18:00:50 +01005602 }
5603 }
5604 }
5605
5606 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01005607 * Gets the array of accounts for which account management is disabled by the profile owner.
5608 *
5609 * <p> Account management can be disabled/enabled by calling
5610 * {@link #setAccountManagementDisabled}.
5611 *
5612 * @return a list of account types for which account management has been disabled.
5613 *
5614 * @see #setAccountManagementDisabled
5615 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005616 public @Nullable String[] getAccountTypesWithManagementDisabled() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005617 throwIfParentInstance("getAccountTypesWithManagementDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07005618 return getAccountTypesWithManagementDisabledAsUser(myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01005619 }
5620
5621 /**
5622 * @see #getAccountTypesWithManagementDisabled()
5623 * @hide
5624 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005625 public @Nullable String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01005626 if (mService != null) {
5627 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01005628 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01005629 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005630 throw e.rethrowFromSystemServer();
Sander Alewijnse5c02db62014-05-07 10:46:57 +01005631 }
5632 }
5633
5634 return null;
5635 }
justinzhang511e0d82014-03-24 16:09:24 -04005636
5637 /**
Jason Monkd7b86212014-06-16 13:15:38 -04005638 * Sets which packages may enter lock task mode.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005639 * <p>
5640 * Any packages that shares uid with an allowed package will also be allowed to activate lock
5641 * task. From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task
5642 * package list results in locked tasks belonging to those packages to be finished. This
5643 * function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04005644 *
Jason Monkd7b86212014-06-16 13:15:38 -04005645 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04005646 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005647 * @throws SecurityException if {@code admin} is not a device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04005648 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00005649 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
5650 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04005651 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04005652 */
Robin Lee25e26452015-06-02 09:56:29 -07005653 public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04005654 throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005655 throwIfParentInstance("setLockTaskPackages");
justinzhang511e0d82014-03-24 16:09:24 -04005656 if (mService != null) {
5657 try {
Jason Monk48aacba2014-08-13 16:29:08 -04005658 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04005659 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005660 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04005661 }
5662 }
5663 }
5664
5665 /**
Jason Monkd7b86212014-06-16 13:15:38 -04005666 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04005667 *
5668 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04005669 * @hide
5670 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005671 public @NonNull String[] getLockTaskPackages(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005672 throwIfParentInstance("getLockTaskPackages");
justinzhang511e0d82014-03-24 16:09:24 -04005673 if (mService != null) {
5674 try {
Jason Monk48aacba2014-08-13 16:29:08 -04005675 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04005676 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005677 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04005678 }
5679 }
5680 return null;
5681 }
5682
5683 /**
5684 * This function lets the caller know whether the given component is allowed to start the
5685 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04005686 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04005687 */
Jason Monkd7b86212014-06-16 13:15:38 -04005688 public boolean isLockTaskPermitted(String pkg) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005689 throwIfParentInstance("isLockTaskPermitted");
justinzhang511e0d82014-03-24 16:09:24 -04005690 if (mService != null) {
5691 try {
Jason Monkd7b86212014-06-16 13:15:38 -04005692 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04005693 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005694 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04005695 }
5696 }
5697 return false;
5698 }
Julia Reynoldsda551652014-05-14 17:15:16 -04005699
5700 /**
5701 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
5702 * 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 -07005703 * <p>
5704 * The settings that can be updated with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005705 * <ul>
5706 * <li>{@link Settings.Global#ADB_ENABLED}</li>
5707 * <li>{@link Settings.Global#AUTO_TIME}</li>
5708 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005709 * <li>{@link Settings.Global#DATA_ROAMING}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005710 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005711 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005712 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN} This setting is only available from
5713 * {@link android.os.Build.VERSION_CODES#M} onwards and can only be set if
5714 * {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
5715 * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li> This setting is only
5716 * available from {@link android.os.Build.VERSION_CODES#M} onwards.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005717 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005718 * <p>
5719 * Changing the following settings has no effect as of {@link android.os.Build.VERSION_CODES#M}:
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005720 * <ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005721 * <li>{@link Settings.Global#BLUETOOTH_ON}. Use
5722 * {@link android.bluetooth.BluetoothAdapter#enable()} and
5723 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005724 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005725 * <li>{@link Settings.Global#MODE_RINGER}. Use
5726 * {@link android.media.AudioManager#setRingerMode(int)} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005727 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005728 * <li>{@link Settings.Global#WIFI_ON}. Use
5729 * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005730 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04005731 *
5732 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5733 * @param setting The name of the setting to update.
5734 * @param value The value to update the setting to.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005735 * @throws SecurityException if {@code admin} is not a device owner.
Julia Reynoldsda551652014-05-14 17:15:16 -04005736 */
Robin Lee25e26452015-06-02 09:56:29 -07005737 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005738 throwIfParentInstance("setGlobalSetting");
Julia Reynoldsda551652014-05-14 17:15:16 -04005739 if (mService != null) {
5740 try {
5741 mService.setGlobalSetting(admin, setting, value);
5742 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005743 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04005744 }
5745 }
5746 }
5747
5748 /**
5749 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
5750 * that the value of the setting is in the correct form for the setting type should be performed
5751 * by the caller.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005752 * <p>
5753 * The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005754 * <ul>
5755 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07005756 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005757 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
5758 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005759 * <p>
5760 * A device owner can additionally update the following settings:
Julia Reynolds82735bc2014-09-04 16:43:30 -04005761 * <ul>
5762 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
5763 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005764 *
Julia Reynoldsda551652014-05-14 17:15:16 -04005765 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5766 * @param setting The name of the setting to update.
5767 * @param value The value to update the setting to.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005768 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynoldsda551652014-05-14 17:15:16 -04005769 */
Robin Lee25e26452015-06-02 09:56:29 -07005770 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005771 throwIfParentInstance("setSecureSetting");
Julia Reynoldsda551652014-05-14 17:15:16 -04005772 if (mService != null) {
5773 try {
5774 mService.setSecureSetting(admin, setting, value);
5775 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005776 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04005777 }
5778 }
5779 }
5780
Amith Yamasanif20d6402014-05-24 15:34:37 -07005781 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005782 * Designates a specific service component as the provider for making permission requests of a
5783 * local or remote administrator of the user.
Amith Yamasanif20d6402014-05-24 15:34:37 -07005784 * <p/>
5785 * Only a profile owner can designate the restrictions provider.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005786 *
Amith Yamasanif20d6402014-05-24 15:34:37 -07005787 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07005788 * @param provider The component name of the service that implements
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005789 * {@link RestrictionsReceiver}. If this param is null, it removes the restrictions
5790 * provider previously assigned.
5791 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanif20d6402014-05-24 15:34:37 -07005792 */
Robin Lee25e26452015-06-02 09:56:29 -07005793 public void setRestrictionsProvider(@NonNull ComponentName admin,
5794 @Nullable ComponentName provider) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005795 throwIfParentInstance("setRestrictionsProvider");
Amith Yamasanif20d6402014-05-24 15:34:37 -07005796 if (mService != null) {
5797 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07005798 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07005799 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005800 throw re.rethrowFromSystemServer();
Amith Yamasanif20d6402014-05-24 15:34:37 -07005801 }
5802 }
5803 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04005804
5805 /**
5806 * Called by profile or device owners to set the master volume mute on or off.
Nicolas Prevotaef3ce22016-09-22 12:00:25 +01005807 * This has no effect when set on a managed profile.
Julia Reynolds4a21b252014-06-04 11:11:43 -04005808 *
5809 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5810 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005811 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds4a21b252014-06-04 11:11:43 -04005812 */
Robin Lee25e26452015-06-02 09:56:29 -07005813 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005814 throwIfParentInstance("setMasterVolumeMuted");
Julia Reynolds4a21b252014-06-04 11:11:43 -04005815 if (mService != null) {
5816 try {
5817 mService.setMasterVolumeMuted(admin, on);
5818 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005819 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04005820 }
5821 }
5822 }
5823
5824 /**
5825 * Called by profile or device owners to check whether the master volume mute is on or off.
5826 *
5827 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5828 * @return {@code true} if master volume is muted, {@code false} if it's not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005829 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds4a21b252014-06-04 11:11:43 -04005830 */
Robin Lee25e26452015-06-02 09:56:29 -07005831 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005832 throwIfParentInstance("isMasterVolumeMuted");
Julia Reynolds4a21b252014-06-04 11:11:43 -04005833 if (mService != null) {
5834 try {
5835 return mService.isMasterVolumeMuted(admin);
5836 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005837 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04005838 }
5839 }
5840 return false;
5841 }
Kenny Guyc13053b2014-05-29 14:17:17 +01005842
5843 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005844 * Called by profile or device owners to change whether a user can uninstall a package.
Kenny Guyc13053b2014-05-29 14:17:17 +01005845 *
5846 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5847 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01005848 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005849 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyc13053b2014-05-29 14:17:17 +01005850 */
Robin Lee25e26452015-06-02 09:56:29 -07005851 public void setUninstallBlocked(@NonNull ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01005852 boolean uninstallBlocked) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005853 throwIfParentInstance("setUninstallBlocked");
Kenny Guyc13053b2014-05-29 14:17:17 +01005854 if (mService != null) {
5855 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01005856 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01005857 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005858 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01005859 }
5860 }
5861 }
5862
5863 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005864 * Check whether the user has been blocked by device policy from uninstalling a package.
Rubin Xua97855b2014-11-07 05:41:00 +00005865 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00005866 * <p>
5867 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005868 * behavior of this API is changed such that passing {@code null} as the {@code admin} parameter
5869 * will return if any admin has blocked the uninstallation. Before L MR1, passing {@code null}
5870 * will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01005871 *
Robin Lee25e26452015-06-02 09:56:29 -07005872 * @param admin The name of the admin component whose blocking policy will be checked, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005873 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01005874 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00005875 * @return true if uninstallation is blocked.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005876 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyc13053b2014-05-29 14:17:17 +01005877 */
Robin Lee25e26452015-06-02 09:56:29 -07005878 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005879 throwIfParentInstance("isUninstallBlocked");
Kenny Guyc13053b2014-05-29 14:17:17 +01005880 if (mService != null) {
5881 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01005882 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01005883 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005884 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01005885 }
5886 }
5887 return false;
5888 }
Svetoslav976e8bd2014-07-16 15:12:03 -07005889
5890 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005891 * Called by the profile owner of a managed profile to enable widget providers from a given
5892 * package to be available in the parent profile. As a result the user will be able to add
5893 * widgets from the white-listed package running under the profile to a widget host which runs
5894 * under the parent profile, for example the home screen. Note that a package may have zero or
5895 * more provider components, where each component provides a different widget type.
Svetoslav976e8bd2014-07-16 15:12:03 -07005896 * <p>
5897 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07005898 *
5899 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5900 * @param packageName The package from which widget providers are white-listed.
5901 * @return Whether the package was added.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005902 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07005903 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
5904 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
5905 */
Robin Lee25e26452015-06-02 09:56:29 -07005906 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005907 throwIfParentInstance("addCrossProfileWidgetProvider");
Svetoslav976e8bd2014-07-16 15:12:03 -07005908 if (mService != null) {
5909 try {
5910 return mService.addCrossProfileWidgetProvider(admin, packageName);
5911 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005912 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07005913 }
5914 }
5915 return false;
5916 }
5917
5918 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005919 * Called by the profile owner of a managed profile to disable widget providers from a given
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005920 * package to be available in the parent profile. For this method to take effect the package
5921 * should have been added via
5922 * {@link #addCrossProfileWidgetProvider( android.content.ComponentName, String)}.
Svetoslav976e8bd2014-07-16 15:12:03 -07005923 * <p>
5924 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07005925 *
5926 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005927 * @param packageName The package from which widget providers are no longer white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07005928 * @return Whether the package was removed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005929 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07005930 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
5931 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
5932 */
Esteban Talavera62399912016-01-11 15:37:55 +00005933 public boolean removeCrossProfileWidgetProvider(
5934 @NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005935 throwIfParentInstance("removeCrossProfileWidgetProvider");
Svetoslav976e8bd2014-07-16 15:12:03 -07005936 if (mService != null) {
5937 try {
5938 return mService.removeCrossProfileWidgetProvider(admin, packageName);
5939 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005940 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07005941 }
5942 }
5943 return false;
5944 }
5945
5946 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005947 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07005948 * available in the parent profile.
5949 *
5950 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5951 * @return The white-listed package list.
Svetoslav976e8bd2014-07-16 15:12:03 -07005952 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
5953 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005954 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07005955 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005956 public @NonNull List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005957 throwIfParentInstance("getCrossProfileWidgetProviders");
Svetoslav976e8bd2014-07-16 15:12:03 -07005958 if (mService != null) {
5959 try {
5960 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
5961 if (providers != null) {
5962 return providers;
5963 }
5964 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005965 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07005966 }
5967 }
5968 return Collections.emptyList();
5969 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005970
5971 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005972 * Called by profile or device owners to set the user's photo.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005973 *
5974 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5975 * @param icon the bitmap to set as the photo.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005976 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005977 */
Robin Lee25e26452015-06-02 09:56:29 -07005978 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005979 throwIfParentInstance("setUserIcon");
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005980 try {
5981 mService.setUserIcon(admin, icon);
5982 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005983 throw re.rethrowFromSystemServer();
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005984 }
5985 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04005986
5987 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01005988 * Called by device owners to set a local system update policy. When a new policy is set,
5989 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00005990 *
Robin Lee25e26452015-06-02 09:56:29 -07005991 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005992 * components in the device owner package can set system update policies and the most
5993 * recent policy takes effect.
Robin Lee25e26452015-06-02 09:56:29 -07005994 * @param policy the new policy, or {@code null} to clear the current policy.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005995 * @throws SecurityException if {@code admin} is not a device owner.
Rubin Xu5faad8e2015-04-20 17:43:48 +01005996 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00005997 */
Robin Lee25e26452015-06-02 09:56:29 -07005998 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005999 throwIfParentInstance("setSystemUpdatePolicy");
Rubin Xu8027a4f2015-03-10 17:52:37 +00006000 if (mService != null) {
6001 try {
Robin Lee25e26452015-06-02 09:56:29 -07006002 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00006003 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006004 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00006005 }
6006 }
6007 }
6008
6009 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01006010 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00006011 *
Robin Lee25e26452015-06-02 09:56:29 -07006012 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00006013 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006014 public @Nullable SystemUpdatePolicy getSystemUpdatePolicy() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006015 throwIfParentInstance("getSystemUpdatePolicy");
Rubin Xu8027a4f2015-03-10 17:52:37 +00006016 if (mService != null) {
6017 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01006018 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00006019 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006020 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00006021 }
6022 }
6023 return null;
6024 }
Benjamin Franze36087e2015-04-07 16:40:34 +01006025
6026 /**
6027 * Called by a device owner to disable the keyguard altogether.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006028 * <p>
6029 * Setting the keyguard to disabled has the same effect as choosing "None" as the screen lock
6030 * type. However, this call has no effect if a password, pin or pattern is currently set. If a
6031 * password, pin or pattern is set after the keyguard was disabled, the keyguard stops being
6032 * disabled.
Benjamin Franze36087e2015-04-07 16:40:34 +01006033 *
6034 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01006035 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01006036 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006037 * place. {@code true} otherwise.
6038 * @throws SecurityException if {@code admin} is not a device owner.
Benjamin Franze36087e2015-04-07 16:40:34 +01006039 */
Robin Lee25e26452015-06-02 09:56:29 -07006040 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006041 throwIfParentInstance("setKeyguardDisabled");
Benjamin Franze36087e2015-04-07 16:40:34 +01006042 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01006043 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01006044 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006045 throw re.rethrowFromSystemServer();
Benjamin Franze36087e2015-04-07 16:40:34 +01006046 }
6047 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00006048
6049 /**
Benjamin Franzbece8062015-05-06 12:14:31 +01006050 * Called by device owner to disable the status bar. Disabling the status bar blocks
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006051 * notifications, quick settings and other screen overlays that allow escaping from a single use
6052 * device.
Benjamin Franzea2ec972015-03-16 17:18:09 +00006053 *
6054 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01006055 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006056 * @return {@code false} if attempting to disable the status bar failed. {@code true} otherwise.
6057 * @throws SecurityException if {@code admin} is not a device owner.
Benjamin Franzea2ec972015-03-16 17:18:09 +00006058 */
Robin Lee25e26452015-06-02 09:56:29 -07006059 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006060 throwIfParentInstance("setStatusBarDisabled");
Benjamin Franzea2ec972015-03-16 17:18:09 +00006061 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01006062 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00006063 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006064 throw re.rethrowFromSystemServer();
Benjamin Franzea2ec972015-03-16 17:18:09 +00006065 }
6066 }
Rubin Xudc105cc2015-04-14 23:38:01 +01006067
6068 /**
6069 * Callable by the system update service to notify device owners about pending updates.
6070 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
6071 * permission.
6072 *
6073 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating
6074 * when the current pending update was first available. -1 if no update is available.
6075 * @hide
6076 */
6077 @SystemApi
6078 public void notifyPendingSystemUpdate(long updateReceivedTime) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006079 throwIfParentInstance("notifyPendingSystemUpdate");
Rubin Xudc105cc2015-04-14 23:38:01 +01006080 if (mService != null) {
6081 try {
6082 mService.notifyPendingSystemUpdate(updateReceivedTime);
6083 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006084 throw re.rethrowFromSystemServer();
Rubin Xudc105cc2015-04-14 23:38:01 +01006085 }
6086 }
6087 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04006088
6089 /**
Amith Yamasanid49489b2015-04-28 14:00:26 -07006090 * Called by profile or device owners to set the default response for future runtime permission
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006091 * requests by applications. The policy can allow for normal operation which prompts the user to
6092 * grant a permission, or can allow automatic granting or denying of runtime permission requests
6093 * by an application. This also applies to new permissions declared by app updates. When a
6094 * permission is denied or granted this way, the effect is equivalent to setting the permission
6095 * grant state via {@link #setPermissionGrantState}.
6096 * <p/>
6097 * As this policy only acts on runtime permission requests, it only applies to applications
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07006098 * built with a {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Benjamin Franz45dd6662015-07-08 14:24:14 +01006099 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07006100 * @param admin Which profile or device owner this request is associated with.
6101 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006102 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
6103 * @throws SecurityException if {@code admin} is not a device or profile owner.
Benjamin Franz45dd6662015-07-08 14:24:14 +01006104 * @see #setPermissionGrantState
Amith Yamasanid49489b2015-04-28 14:00:26 -07006105 */
Robin Lee25e26452015-06-02 09:56:29 -07006106 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006107 throwIfParentInstance("setPermissionPolicy");
Amith Yamasanid49489b2015-04-28 14:00:26 -07006108 try {
6109 mService.setPermissionPolicy(admin, policy);
6110 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006111 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07006112 }
6113 }
6114
6115 /**
6116 * Returns the current runtime permission policy set by the device or profile owner. The
6117 * default is {@link #PERMISSION_POLICY_PROMPT}.
6118 * @param admin Which profile or device owner this request is associated with.
6119 * @return the current policy for future permission requests.
6120 */
Esteban Talavera28b95702015-06-24 15:23:42 +01006121 public int getPermissionPolicy(ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006122 throwIfParentInstance("getPermissionPolicy");
Amith Yamasanid49489b2015-04-28 14:00:26 -07006123 try {
6124 return mService.getPermissionPolicy(admin);
6125 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006126 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07006127 }
6128 }
6129
6130 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006131 * Sets the grant state of a runtime permission for a specific application. The state can be
6132 * {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it through the UI,
6133 * {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission is denied and the user
6134 * cannot manage it through the UI, and {@link #PERMISSION_GRANT_STATE_GRANTED granted} in which
6135 * the permission is granted and the user cannot manage it through the UI. This might affect all
6136 * permissions in a group that the runtime permission belongs to. This method can only be called
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006137 * by a profile or device owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006138 * <p/>
6139 * Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not revoke
6140 * the permission. It retains the previous grant, if any.
6141 * <p/>
6142 * Permissions can be granted or revoked only for applications built with a
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07006143 * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07006144 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07006145 * @param admin Which profile or device owner this request is associated with.
6146 * @param packageName The application to grant or revoke a permission to.
6147 * @param permission The permission to grant or revoke.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006148 * @param grantState The permission grant state which is one of
6149 * {@link #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
6150 * {@link #PERMISSION_GRANT_STATE_GRANTED},
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006151 * @return whether the permission was successfully granted or revoked.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006152 * @throws SecurityException if {@code admin} is not a device or profile owner.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006153 * @see #PERMISSION_GRANT_STATE_DENIED
6154 * @see #PERMISSION_GRANT_STATE_DEFAULT
6155 * @see #PERMISSION_GRANT_STATE_GRANTED
Amith Yamasanid49489b2015-04-28 14:00:26 -07006156 */
Robin Lee25e26452015-06-02 09:56:29 -07006157 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006158 String permission, int grantState) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006159 throwIfParentInstance("setPermissionGrantState");
Amith Yamasanid49489b2015-04-28 14:00:26 -07006160 try {
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006161 return mService.setPermissionGrantState(admin, packageName, permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07006162 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006163 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07006164 }
6165 }
Amith Yamasani184b3752015-05-22 13:00:51 -07006166
6167 /**
6168 * Returns the current grant state of a runtime permission for a specific application.
6169 *
6170 * @param admin Which profile or device owner this request is associated with.
6171 * @param packageName The application to check the grant state for.
6172 * @param permission The permission to check for.
6173 * @return the current grant state specified by device policy. If the profile or device owner
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006174 * has not set a grant state, the return value is
6175 * {@link #PERMISSION_GRANT_STATE_DEFAULT}. This does not indicate whether or not the
6176 * permission is currently granted for the package.
6177 * <p/>
6178 * If a grant state was set by the profile or device owner, then the return value will
6179 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or
6180 * {@link #PERMISSION_GRANT_STATE_GRANTED}, which indicates if the permission is
6181 * currently denied or granted.
6182 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasani184b3752015-05-22 13:00:51 -07006183 * @see #setPermissionGrantState(ComponentName, String, String, int)
6184 * @see PackageManager#checkPermission(String, String)
6185 */
Robin Lee25e26452015-06-02 09:56:29 -07006186 public int getPermissionGrantState(@NonNull ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07006187 String permission) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006188 throwIfParentInstance("getPermissionGrantState");
Amith Yamasani184b3752015-05-22 13:00:51 -07006189 try {
6190 return mService.getPermissionGrantState(admin, packageName, permission);
6191 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006192 throw re.rethrowFromSystemServer();
Amith Yamasani184b3752015-05-22 13:00:51 -07006193 }
6194 }
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006195
6196 /**
Esteban Talavera01576862016-12-15 11:16:44 +00006197 * Returns whether it is possible for the caller to initiate provisioning of a managed profile
6198 * or device, setting itself as the device or profile owner.
6199 *
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006200 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
6201 * {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Esteban Talavera01576862016-12-15 11:16:44 +00006202 * @return whether provisioning a managed profile or device is possible.
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006203 * @throws IllegalArgumentException if the supplied action is not valid.
6204 */
Esteban Talavera01576862016-12-15 11:16:44 +00006205 public boolean isProvisioningAllowed(@NonNull String action) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006206 throwIfParentInstance("isProvisioningAllowed");
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006207 try {
Esteban Talavera01576862016-12-15 11:16:44 +00006208 return mService.isProvisioningAllowed(action, mContext.getPackageName());
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006209 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006210 throw re.rethrowFromSystemServer();
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006211 }
6212 }
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006213
6214 /**
Esteban Talavera01576862016-12-15 11:16:44 +00006215 * Checks whether it is possible to initiate provisioning a managed device,
6216 * profile or user, setting the given package as owner.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00006217 *
6218 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
6219 * {@link #ACTION_PROVISION_MANAGED_PROFILE},
6220 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE},
6221 * {@link #ACTION_PROVISION_MANAGED_USER}
Esteban Talavera01576862016-12-15 11:16:44 +00006222 * @param packageName The package of the component that would be set as device, user, or profile
6223 * owner.
6224 * @return A {@link ProvisioningPreCondition} value indicating whether provisioning is allowed.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00006225 * @hide
6226 */
Esteban Talavera01576862016-12-15 11:16:44 +00006227 public @ProvisioningPreCondition int checkProvisioningPreCondition(
6228 String action, @NonNull String packageName) {
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00006229 try {
Esteban Talavera01576862016-12-15 11:16:44 +00006230 return mService.checkProvisioningPreCondition(action, packageName);
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00006231 } catch (RemoteException re) {
6232 throw re.rethrowFromSystemServer();
6233 }
6234 }
6235
6236 /**
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006237 * Return if this user is a managed profile of another user. An admin can become the profile
6238 * owner of a managed profile with {@link #ACTION_PROVISION_MANAGED_PROFILE} and of a managed
Kenny Guyffa38402016-03-31 16:40:57 +01006239 * user with {@link #createAndManageUser}
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006240 * @param admin Which profile owner this request is associated with.
6241 * @return if this user is a managed profile of another user.
6242 */
6243 public boolean isManagedProfile(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006244 throwIfParentInstance("isManagedProfile");
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006245 try {
6246 return mService.isManagedProfile(admin);
6247 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006248 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006249 }
6250 }
6251
6252 /**
6253 * @hide
6254 * Return if this user is a system-only user. An admin can manage a device from a system only
6255 * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}.
6256 * @param admin Which device owner this request is associated with.
6257 * @return if this user is a system-only user.
6258 */
6259 public boolean isSystemOnlyUser(@NonNull ComponentName admin) {
6260 try {
6261 return mService.isSystemOnlyUser(admin);
6262 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006263 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006264 }
6265 }
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006266
6267 /**
6268 * Called by device owner to get the MAC address of the Wi-Fi device.
6269 *
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08006270 * @param admin Which device owner this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006271 * @return the MAC address of the Wi-Fi device, or null when the information is not available.
6272 * (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.)
6273 * <p>
6274 * The address will be in the {@code XX:XX:XX:XX:XX:XX} format.
6275 * @throws SecurityException if {@code admin} is not a device owner.
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006276 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006277 public @Nullable String getWifiMacAddress(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006278 throwIfParentInstance("getWifiMacAddress");
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006279 try {
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08006280 return mService.getWifiMacAddress(admin);
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006281 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006282 throw re.rethrowFromSystemServer();
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006283 }
6284 }
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00006285
6286 /**
Mahaver Chopra1216ae52016-03-11 15:39:48 +00006287 * Called by device owner to reboot the device. If there is an ongoing call on the device,
6288 * throws an {@link IllegalStateException}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006289 * @param admin Which device owner the request is associated with.
Mahaver Chopra1216ae52016-03-11 15:39:48 +00006290 * @throws IllegalStateException if device has an ongoing call.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006291 * @throws SecurityException if {@code admin} is not a device owner.
Mahaver Chopra1216ae52016-03-11 15:39:48 +00006292 * @see TelephonyManager#CALL_STATE_IDLE
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00006293 */
6294 public void reboot(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006295 throwIfParentInstance("reboot");
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00006296 try {
6297 mService.reboot(admin);
6298 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006299 throw re.rethrowFromSystemServer();
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00006300 }
6301 }
Kenny Guy06de4e72015-12-22 12:07:39 +00006302
6303 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006304 * Called by a device admin to set the short support message. This will be displayed to the user
6305 * in settings screens where funtionality has been disabled by the admin. The message should be
6306 * limited to a short statement such as "This setting is disabled by your administrator. Contact
6307 * someone@example.com for support." If the message is longer than 200 characters it may be
6308 * truncated.
6309 * <p>
6310 * If the short support message needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006311 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
6312 * and set a new version of this string accordingly.
6313 *
Kenny Guy06de4e72015-12-22 12:07:39 +00006314 * @see #setLongSupportMessage
Kenny Guy06de4e72015-12-22 12:07:39 +00006315 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006316 * @param message Short message to be displayed to the user in settings or null to clear the
6317 * existing message.
6318 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00006319 */
6320 public void setShortSupportMessage(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006321 @Nullable CharSequence message) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006322 throwIfParentInstance("setShortSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00006323 if (mService != null) {
6324 try {
6325 mService.setShortSupportMessage(admin, message);
6326 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006327 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006328 }
6329 }
6330 }
6331
6332 /**
6333 * Called by a device admin to get the short support message.
6334 *
6335 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006336 * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)} or
6337 * null if no message has been set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006338 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00006339 */
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006340 public CharSequence getShortSupportMessage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006341 throwIfParentInstance("getShortSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00006342 if (mService != null) {
6343 try {
6344 return mService.getShortSupportMessage(admin);
6345 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006346 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006347 }
6348 }
6349 return null;
6350 }
6351
6352 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006353 * Called by a device admin to set the long support message. This will be displayed to the user
6354 * in the device administators settings screen.
6355 * <p>
6356 * If the long support message needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006357 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
6358 * and set a new version of this string accordingly.
6359 *
Kenny Guy06de4e72015-12-22 12:07:39 +00006360 * @see #setShortSupportMessage
Kenny Guy06de4e72015-12-22 12:07:39 +00006361 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006362 * @param message Long message to be displayed to the user in settings or null to clear the
6363 * existing message.
6364 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00006365 */
6366 public void setLongSupportMessage(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006367 @Nullable CharSequence message) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006368 throwIfParentInstance("setLongSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00006369 if (mService != null) {
6370 try {
6371 mService.setLongSupportMessage(admin, message);
6372 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006373 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006374 }
6375 }
6376 }
6377
6378 /**
6379 * Called by a device admin to get the long support message.
6380 *
6381 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006382 * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)} or
6383 * null if no message has been set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006384 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00006385 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006386 public @Nullable CharSequence getLongSupportMessage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006387 throwIfParentInstance("getLongSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00006388 if (mService != null) {
6389 try {
6390 return mService.getLongSupportMessage(admin);
6391 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006392 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006393 }
6394 }
6395 return null;
6396 }
6397
6398 /**
6399 * Called by the system to get the short support message.
6400 *
6401 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6402 * @param userHandle user id the admin is running as.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006403 * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)}
Kenny Guy06de4e72015-12-22 12:07:39 +00006404 *
6405 * @hide
6406 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006407 public @Nullable CharSequence getShortSupportMessageForUser(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006408 int userHandle) {
Kenny Guy06de4e72015-12-22 12:07:39 +00006409 if (mService != null) {
6410 try {
6411 return mService.getShortSupportMessageForUser(admin, userHandle);
6412 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006413 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006414 }
6415 }
6416 return null;
6417 }
6418
6419
6420 /**
6421 * Called by the system to get the long support message.
6422 *
6423 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6424 * @param userHandle user id the admin is running as.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006425 * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)}
Kenny Guy06de4e72015-12-22 12:07:39 +00006426 *
6427 * @hide
6428 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006429 public @Nullable CharSequence getLongSupportMessageForUser(
6430 @NonNull ComponentName admin, int userHandle) {
Kenny Guy06de4e72015-12-22 12:07:39 +00006431 if (mService != null) {
6432 try {
6433 return mService.getLongSupportMessageForUser(admin, userHandle);
6434 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006435 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006436 }
6437 }
6438 return null;
6439 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006440
6441 /**
Esteban Talavera62399912016-01-11 15:37:55 +00006442 * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager}
6443 * whose calls act on the parent profile.
Benjamin Franz66b45f02016-04-05 19:12:39 +01006444 *
6445 * <p>The following methods are supported for the parent instance, all other methods will
6446 * throw a SecurityException when called on the parent instance:
6447 * <ul>
6448 * <li>{@link #getPasswordQuality}</li>
6449 * <li>{@link #setPasswordQuality}</li>
6450 * <li>{@link #getPasswordMinimumLength}</li>
6451 * <li>{@link #setPasswordMinimumLength}</li>
6452 * <li>{@link #getPasswordMinimumUpperCase}</li>
6453 * <li>{@link #setPasswordMinimumUpperCase}</li>
6454 * <li>{@link #getPasswordMinimumLowerCase}</li>
6455 * <li>{@link #setPasswordMinimumLowerCase}</li>
6456 * <li>{@link #getPasswordMinimumLetters}</li>
6457 * <li>{@link #setPasswordMinimumLetters}</li>
6458 * <li>{@link #getPasswordMinimumNumeric}</li>
6459 * <li>{@link #setPasswordMinimumNumeric}</li>
6460 * <li>{@link #getPasswordMinimumSymbols}</li>
6461 * <li>{@link #setPasswordMinimumSymbols}</li>
6462 * <li>{@link #getPasswordMinimumNonLetter}</li>
6463 * <li>{@link #setPasswordMinimumNonLetter}</li>
6464 * <li>{@link #getPasswordHistoryLength}</li>
6465 * <li>{@link #setPasswordHistoryLength}</li>
6466 * <li>{@link #getPasswordExpirationTimeout}</li>
6467 * <li>{@link #setPasswordExpirationTimeout}</li>
6468 * <li>{@link #getPasswordExpiration}</li>
Charles He8c760562016-10-25 16:36:53 +01006469 * <li>{@link #getPasswordMaximumLength}</li>
Benjamin Franz66b45f02016-04-05 19:12:39 +01006470 * <li>{@link #isActivePasswordSufficient}</li>
6471 * <li>{@link #getCurrentFailedPasswordAttempts}</li>
6472 * <li>{@link #getMaximumFailedPasswordsForWipe}</li>
6473 * <li>{@link #setMaximumFailedPasswordsForWipe}</li>
6474 * <li>{@link #getMaximumTimeToLock}</li>
6475 * <li>{@link #setMaximumTimeToLock}</li>
6476 * <li>{@link #lockNow}</li>
6477 * <li>{@link #getKeyguardDisabledFeatures}</li>
6478 * <li>{@link #setKeyguardDisabledFeatures}</li>
6479 * <li>{@link #getTrustAgentConfiguration}</li>
6480 * <li>{@link #setTrustAgentConfiguration}</li>
Michal Karpinskia20d8bb2016-11-23 12:09:08 +00006481 * <li>{@link #getRequiredStrongAuthTimeout}</li>
6482 * <li>{@link #setRequiredStrongAuthTimeout}</li>
Benjamin Franz66b45f02016-04-05 19:12:39 +01006483 * </ul>
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006484 *
6485 * @return a new instance of {@link DevicePolicyManager} that acts on the parent profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006486 * @throws SecurityException if {@code admin} is not a profile owner.
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006487 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006488 public @NonNull DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006489 throwIfParentInstance("getParentProfileInstance");
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006490 try {
6491 if (!mService.isManagedProfile(admin)) {
6492 throw new SecurityException("The current user does not have a parent profile.");
6493 }
Jeff Sharkey49ca5292016-05-10 12:54:45 -06006494 return new DevicePolicyManager(mContext, mService, true);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006495 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006496 throw e.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006497 }
6498 }
6499
6500 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00006501 * Called by device owner to control the security logging feature. Logging can only be
6502 * enabled on single user devices where the sole user is managed by the device owner.
6503 *
6504 * <p> Security logs contain various information intended for security auditing purposes.
6505 * See {@link SecurityEvent} for details.
6506 *
6507 * <p>There must be only one user on the device, managed by the device owner.
6508 * Otherwise a {@link SecurityException} will be thrown.
Michal Karpinskib58e4962016-03-01 14:55:10 +00006509 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006510 * @param admin Which device owner this request is associated with.
Michal Karpinski6235a942016-03-15 12:07:23 +00006511 * @param enabled whether security logging should be enabled or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006512 * @throws SecurityException if {@code admin} is not a device owner.
Michal Karpinski6235a942016-03-15 12:07:23 +00006513 * @see #retrieveSecurityLogs
6514 */
6515 public void setSecurityLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006516 throwIfParentInstance("setSecurityLoggingEnabled");
Michal Karpinski6235a942016-03-15 12:07:23 +00006517 try {
6518 mService.setSecurityLoggingEnabled(admin, enabled);
6519 } catch (RemoteException re) {
6520 throw re.rethrowFromSystemServer();
6521 }
6522 }
6523
6524 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00006525 * Return whether security logging is enabled or not by the device owner.
6526 *
6527 * <p>Can only be called by the device owner, otherwise a {@link SecurityException} will be
6528 * thrown.
6529 *
6530 * @param admin Which device owner this request is associated with.
6531 * @return {@code true} if security logging is enabled by device owner, {@code false} otherwise.
6532 * @throws SecurityException if {@code admin} is not a device owner.
6533 */
6534 public boolean isSecurityLoggingEnabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006535 throwIfParentInstance("isSecurityLoggingEnabled");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006536 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00006537 return mService.isSecurityLoggingEnabled(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006538 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006539 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006540 }
6541 }
6542
6543 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00006544 * Called by device owner to retrieve all new security logging entries since the last call to
6545 * this API after device boots.
6546 *
6547 * <p> Access to the logs is rate limited and it will only return new logs after the device
6548 * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}.
6549 *
6550 * <p>There must be only one user on the device, managed by the device owner.
6551 * Otherwise a {@link SecurityException} will be thrown.
Michal Karpinskib58e4962016-03-01 14:55:10 +00006552 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006553 * @param admin Which device owner this request is associated with.
Michal Karpinski6235a942016-03-15 12:07:23 +00006554 * @return the new batch of security logs which is a list of {@link SecurityEvent},
6555 * or {@code null} if rate limitation is exceeded or if logging is currently disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006556 * @throws SecurityException if {@code admin} is not a device owner.
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006557 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006558 public @Nullable List<SecurityEvent> retrieveSecurityLogs(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006559 throwIfParentInstance("retrieveSecurityLogs");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006560 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00006561 ParceledListSlice<SecurityEvent> list = mService.retrieveSecurityLogs(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006562 if (list != null) {
6563 return list.getList();
6564 } else {
6565 // Rate limit exceeded.
6566 return null;
6567 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006568 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006569 throw re.rethrowFromSystemServer();
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006570 }
6571 }
Benjamin Franz59720bb2016-01-18 15:26:11 +00006572
6573 /**
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00006574 * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent
6575 * profile.
6576 *
6577 * @hide
6578 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006579 public @NonNull DevicePolicyManager getParentProfileInstance(UserInfo uInfo) {
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00006580 mContext.checkSelfPermission(
6581 android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS);
6582 if (!uInfo.isManagedProfile()) {
6583 throw new SecurityException("The user " + uInfo.id
6584 + " does not have a parent profile.");
6585 }
Jeff Sharkey49ca5292016-05-10 12:54:45 -06006586 return new DevicePolicyManager(mContext, mService, true);
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00006587 }
6588
6589 /**
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006590 * Called by device owners to retrieve device logs from before the device's last reboot.
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006591 * <p>
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01006592 * <strong> This API is not supported on all devices. Calling this API on unsupported devices
6593 * will result in {@code null} being returned. The device logs are retrieved from a RAM region
6594 * which is not guaranteed to be corruption-free during power cycles, as a result be cautious
6595 * about data corruption when parsing. </strong>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006596 * <p>
6597 * There must be only one user on the device, managed by the device owner. Otherwise a
6598 * {@link SecurityException} will be thrown.
Michal Karpinskib58e4962016-03-01 14:55:10 +00006599 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006600 * @param admin Which device owner this request is associated with.
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01006601 * @return Device logs from before the latest reboot of the system, or {@code null} if this API
6602 * is not supported on the device.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006603 * @throws SecurityException if {@code admin} is not a device owner.
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006604 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006605 public @Nullable List<SecurityEvent> retrievePreRebootSecurityLogs(
6606 @NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006607 throwIfParentInstance("retrievePreRebootSecurityLogs");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006608 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00006609 ParceledListSlice<SecurityEvent> list = mService.retrievePreRebootSecurityLogs(admin);
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01006610 if (list != null) {
6611 return list.getList();
6612 } else {
6613 return null;
6614 }
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006615 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006616 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006617 }
6618 }
6619
6620 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006621 * Called by a profile owner of a managed profile to set the color used for customization. This
6622 * color is used as background color of the confirm credentials screen for that user. The
Clara Bayarri8d0bd7fa2016-03-30 14:59:58 +01006623 * default color is teal (#00796B).
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006624 * <p>
6625 * The confirm credentials screen can be created using
Benjamin Franz59720bb2016-01-18 15:26:11 +00006626 * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}.
6627 *
6628 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinski74cd7302016-04-12 15:17:36 +01006629 * @param color The 24bit (0xRRGGBB) representation of the color to be used.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006630 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz59720bb2016-01-18 15:26:11 +00006631 */
6632 public void setOrganizationColor(@NonNull ComponentName admin, int color) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006633 throwIfParentInstance("setOrganizationColor");
Benjamin Franz59720bb2016-01-18 15:26:11 +00006634 try {
Michal Karpinski74cd7302016-04-12 15:17:36 +01006635 // always enforce alpha channel to have 100% opacity
6636 color |= 0xFF000000;
Benjamin Franz59720bb2016-01-18 15:26:11 +00006637 mService.setOrganizationColor(admin, color);
6638 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006639 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00006640 }
6641 }
6642
6643 /**
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00006644 * @hide
6645 *
6646 * Sets the color used for customization.
6647 *
Michal Karpinski74cd7302016-04-12 15:17:36 +01006648 * @param color The 24bit (0xRRGGBB) representation of the color to be used.
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00006649 * @param userId which user to set the color to.
6650 * @RequiresPermission(allOf = {
6651 * Manifest.permission.MANAGE_USERS,
6652 * Manifest.permission.INTERACT_ACROSS_USERS_FULL})
6653 */
6654 public void setOrganizationColorForUser(@ColorInt int color, @UserIdInt int userId) {
6655 try {
Michal Karpinski74cd7302016-04-12 15:17:36 +01006656 // always enforce alpha channel to have 100% opacity
6657 color |= 0xFF000000;
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00006658 mService.setOrganizationColorForUser(color, userId);
6659 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006660 throw re.rethrowFromSystemServer();
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00006661 }
6662 }
6663
6664 /**
Benjamin Franz59720bb2016-01-18 15:26:11 +00006665 * Called by a profile owner of a managed profile to retrieve the color used for customization.
6666 * This color is used as background color of the confirm credentials screen for that user.
6667 *
6668 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinski74cd7302016-04-12 15:17:36 +01006669 * @return The 24bit (0xRRGGBB) representation of the color to be used.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006670 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz59720bb2016-01-18 15:26:11 +00006671 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01006672 public @ColorInt int getOrganizationColor(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006673 throwIfParentInstance("getOrganizationColor");
Benjamin Franz59720bb2016-01-18 15:26:11 +00006674 try {
6675 return mService.getOrganizationColor(admin);
6676 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006677 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00006678 }
6679 }
6680
6681 /**
6682 * @hide
6683 * Retrieve the customization color for a given user.
6684 *
6685 * @param userHandle The user id of the user we're interested in.
Michal Karpinski74cd7302016-04-12 15:17:36 +01006686 * @return The 24bit (0xRRGGBB) representation of the color to be used.
Benjamin Franz59720bb2016-01-18 15:26:11 +00006687 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01006688 public @ColorInt int getOrganizationColorForUser(int userHandle) {
Benjamin Franz59720bb2016-01-18 15:26:11 +00006689 try {
6690 return mService.getOrganizationColorForUser(userHandle);
6691 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006692 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00006693 }
6694 }
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006695
6696 /**
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01006697 * Called by the device owner or profile owner to set the name of the organization under
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006698 * management.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006699 * <p>
6700 * If the organization name needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006701 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
6702 * and set a new version of this string accordingly.
6703 *
6704 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6705 * @param title The organization name or {@code null} to clear a previously set name.
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01006706 * @throws SecurityException if {@code admin} is not a device or profile owner.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006707 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01006708 public void setOrganizationName(@NonNull ComponentName admin, @Nullable CharSequence title) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006709 throwIfParentInstance("setOrganizationName");
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006710 try {
6711 mService.setOrganizationName(admin, title);
6712 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006713 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006714 }
6715 }
6716
6717 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006718 * Called by a profile owner of a managed profile to retrieve the name of the organization under
6719 * management.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006720 *
6721 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6722 * @return The organization name or {@code null} if none is set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006723 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006724 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006725 public @Nullable CharSequence getOrganizationName(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006726 throwIfParentInstance("getOrganizationName");
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006727 try {
6728 return mService.getOrganizationName(admin);
6729 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006730 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006731 }
6732 }
6733
6734 /**
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01006735 * Called by the system to retrieve the name of the organization managing the device.
6736 *
6737 * @return The organization name or {@code null} if none is set.
6738 * @throws SecurityException if the caller is not the device owner, does not hold the
6739 * MANAGE_USERS permission and is not the system.
6740 *
6741 * @hide
6742 */
6743 @SystemApi
6744 @TestApi
6745 public @Nullable CharSequence getDeviceOwnerOrganizationName() {
6746 try {
6747 return mService.getDeviceOwnerOrganizationName();
6748 } catch (RemoteException re) {
6749 throw re.rethrowFromSystemServer();
6750 }
6751 }
6752
6753 /**
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006754 * Retrieve the default title message used in the confirm credentials screen for a given user.
6755 *
6756 * @param userHandle The user id of the user we're interested in.
6757 * @return The organization name or {@code null} if none is set.
6758 *
6759 * @hide
6760 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006761 public @Nullable CharSequence getOrganizationNameForUser(int userHandle) {
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006762 try {
6763 return mService.getOrganizationNameForUser(userHandle);
6764 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006765 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006766 }
6767 }
6768
6769 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00006770 * @return the {@link UserProvisioningState} for the current user - for unmanaged users will
6771 * return {@link #STATE_USER_UNMANAGED}
6772 * @hide
6773 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00006774 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00006775 @UserProvisioningState
6776 public int getUserProvisioningState() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006777 throwIfParentInstance("getUserProvisioningState");
Alan Treadwayafad8782016-01-19 15:15:08 +00006778 if (mService != null) {
6779 try {
6780 return mService.getUserProvisioningState();
6781 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006782 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00006783 }
6784 }
6785 return STATE_USER_UNMANAGED;
6786 }
6787
6788 /**
6789 * Set the {@link UserProvisioningState} for the supplied user, if they are managed.
6790 *
6791 * @param state to store
6792 * @param userHandle for user
6793 * @hide
6794 */
6795 public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) {
6796 if (mService != null) {
6797 try {
6798 mService.setUserProvisioningState(state, userHandle);
6799 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006800 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00006801 }
6802 }
6803 }
6804
6805 /**
Esteban Talaverac9bb3782016-11-11 15:41:14 +00006806 * Indicates the entity that controls the device or profile owner. Two users/profiles are
6807 * affiliated if the set of ids set by their device or profile owners intersect.
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006808 *
6809 * @param admin Which profile or device owner this request is associated with.
Esteban Talaverac9bb3782016-11-11 15:41:14 +00006810 * @param ids A list of opaque non-empty affiliation ids. Duplicate elements will be ignored.
6811 *
6812 * @throws NullPointerException if {@code ids} is null or contains null elements.
6813 * @throws IllegalArgumentException if {@code ids} contains an empty string.
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006814 */
Esteban Talaverac9bb3782016-11-11 15:41:14 +00006815 public void setAffiliationIds(@NonNull ComponentName admin, @NonNull List<String> ids) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006816 throwIfParentInstance("setAffiliationIds");
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006817 try {
Esteban Talaverac9bb3782016-11-11 15:41:14 +00006818 mService.setAffiliationIds(admin, ids);
6819 } catch (RemoteException e) {
6820 throw e.rethrowFromSystemServer();
6821 }
6822 }
6823
6824 /**
6825 * Returns the list of affiliation ids previously set via {@link #setAffiliationIds}, or an
6826 * empty list if none have been set.
6827 */
6828 public @NonNull List<String> getAffiliationIds(@NonNull ComponentName admin) {
6829 throwIfParentInstance("getAffiliationIds");
6830 try {
6831 return mService.getAffiliationIds(admin);
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006832 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006833 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006834 }
6835 }
6836
6837 /**
6838 * @hide
Esteban Talaverac9bb3782016-11-11 15:41:14 +00006839 * Returns whether this user/profile is affiliated with the device.
6840 * <p>
6841 * By definition, the user that the device owner runs on is always affiliated with the device.
6842 * Any other user/profile is considered affiliated with the device if the set specified by its
6843 * profile owner via {@link #setAffiliationIds} intersects with the device owner's.
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006844 *
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006845 */
6846 public boolean isAffiliatedUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006847 throwIfParentInstance("isAffiliatedUser");
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006848 try {
Esteban Talaverac9bb3782016-11-11 15:41:14 +00006849 return mService.isAffiliatedUser();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006850 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006851 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006852 }
6853 }
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08006854
6855 /**
6856 * @hide
6857 * Returns whether the uninstall for {@code packageName} for the current user is in queue
6858 * to be started
6859 * @param packageName the package to check for
6860 * @return whether the uninstall intent for {@code packageName} is pending
6861 */
6862 public boolean isUninstallInQueue(String packageName) {
6863 try {
6864 return mService.isUninstallInQueue(packageName);
6865 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006866 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08006867 }
6868 }
6869
6870 /**
6871 * @hide
6872 * @param packageName the package containing active DAs to be uninstalled
6873 */
6874 public void uninstallPackageWithActiveAdmins(String packageName) {
6875 try {
6876 mService.uninstallPackageWithActiveAdmins(packageName);
6877 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006878 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08006879 }
6880 }
Benjamin Franzbc33c822016-04-15 08:57:52 +01006881
Kenny Guy38dcca52016-04-19 13:09:18 +01006882 /**
6883 * @hide
6884 * Remove a test admin synchronously without sending it a broadcast about being removed.
6885 * If the admin is a profile owner or device owner it will still be removed.
6886 *
6887 * @param userHandle user id to remove the admin for.
6888 * @param admin The administration compononent to remove.
6889 * @throws SecurityException if the caller is not shell / root or the admin package
6890 * isn't a test application see {@link ApplicationInfo#FLAG_TEST_APP}.
6891 */
6892 public void forceRemoveActiveAdmin(ComponentName adminReceiver, int userHandle) {
6893 try {
6894 mService.forceRemoveActiveAdmin(adminReceiver, userHandle);
6895 } catch (RemoteException re) {
6896 throw re.rethrowFromSystemServer();
6897 }
6898 }
6899
Mahaver Chopra790d1982016-07-07 16:06:49 +01006900 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01006901 * Returns whether the device has been provisioned.
6902 *
6903 * <p>Not for use by third-party applications.
6904 *
Mahaver Chopra790d1982016-07-07 16:06:49 +01006905 * @hide
Mahaver Chopra790d1982016-07-07 16:06:49 +01006906 */
Lenka Trochtova5291ee72016-11-28 16:38:23 +01006907 @SystemApi
Mahaver Chopra790d1982016-07-07 16:06:49 +01006908 public boolean isDeviceProvisioned() {
6909 try {
6910 return mService.isDeviceProvisioned();
6911 } catch (RemoteException re) {
6912 throw re.rethrowFromSystemServer();
6913 }
6914 }
6915
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01006916 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01006917 * Writes that the provisioning configuration has been applied.
6918 *
6919 * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS}
6920 * permission.
6921 *
6922 * <p>Not for use by third-party applications.
6923 *
6924 * @hide
6925 */
6926 @SystemApi
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01006927 public void setDeviceProvisioningConfigApplied() {
6928 try {
6929 mService.setDeviceProvisioningConfigApplied();
6930 } catch (RemoteException re) {
6931 throw re.rethrowFromSystemServer();
6932 }
6933 }
6934
6935 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01006936 * Returns whether the provisioning configuration has been applied.
6937 *
6938 * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS} permission.
6939 *
6940 * <p>Not for use by third-party applications.
6941 *
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01006942 * @return whether the provisioning configuration has been applied.
Lenka Trochtova5291ee72016-11-28 16:38:23 +01006943 *
6944 * @hide
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01006945 */
Lenka Trochtova5291ee72016-11-28 16:38:23 +01006946 @SystemApi
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01006947 public boolean isDeviceProvisioningConfigApplied() {
6948 try {
6949 return mService.isDeviceProvisioningConfigApplied();
6950 } catch (RemoteException re) {
6951 throw re.rethrowFromSystemServer();
6952 }
6953 }
6954
Victor Chang9bfc65f2016-08-15 12:27:09 +01006955 /**
6956 * @hide
Victor Chang3577ed22016-08-25 18:49:26 +01006957 * Force update user setup completed status. This API has no effect on user build.
6958 * @throws {@link SecurityException} if the caller has no
Esteban Talavera01576862016-12-15 11:16:44 +00006959 * {@code android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS} or the caller is
6960 * not {@link UserHandle#SYSTEM_USER}
Victor Chang9bfc65f2016-08-15 12:27:09 +01006961 */
6962 public void forceUpdateUserSetupComplete() {
6963 try {
6964 mService.forceUpdateUserSetupComplete();
6965 } catch (RemoteException re) {
6966 throw re.rethrowFromSystemServer();
6967 }
6968 }
6969
Benjamin Franzbc33c822016-04-15 08:57:52 +01006970 private void throwIfParentInstance(String functionName) {
6971 if (mParentInstance) {
6972 throw new SecurityException(functionName + " cannot be called on the parent instance");
6973 }
6974 }
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02006975
6976 /**
6977 * @hide
6978 * Enable backup service.
6979 * <p>This includes all backup and restore mechanisms.
6980 * Setting this to {@code false} will make backup service no-op or return empty results.
6981 *
6982 * <p>There must be only one user on the device, managed by the device owner.
6983 * Otherwise a {@link SecurityException} will be thrown.
6984 *
6985 * <p>Backup service is off by default when device owner is present.
6986 */
6987 public void setBackupServiceEnabled(@NonNull ComponentName admin, boolean enabled) {
6988 try {
6989 mService.setBackupServiceEnabled(admin, enabled);
6990 } catch (RemoteException re) {
6991 throw re.rethrowFromSystemServer();
6992 }
6993 }
6994
6995 /**
6996 * @hide
6997 * @return {@code true} if backup service is enabled, {@code false} otherwise.
6998 */
6999 public boolean isBackupServiceEnabled(@NonNull ComponentName admin) {
7000 try {
7001 return mService.isBackupServiceEnabled(admin);
7002 } catch (RemoteException re) {
7003 throw re.rethrowFromSystemServer();
7004 }
7005 }
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007006
7007 /**
7008 * Called by a device owner to control the network logging feature. Logging can only be
7009 * enabled on single user devices where the sole user is managed by the device owner. If a new
7010 * user is added on the device, logging is disabled.
7011 *
7012 * <p> Network logs contain DNS lookup and connect() library call events.
7013 *
7014 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7015 * @param enabled whether network logging should be enabled or not.
7016 * @throws {@link SecurityException} if {@code admin} is not a device owner.
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007017 * @see #retrieveNetworkLogs
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007018 */
7019 public void setNetworkLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
7020 throwIfParentInstance("setNetworkLoggingEnabled");
7021 try {
7022 mService.setNetworkLoggingEnabled(admin, enabled);
7023 } catch (RemoteException re) {
7024 throw re.rethrowFromSystemServer();
7025 }
7026 }
7027
7028 /**
7029 * Return whether network logging is enabled by a device owner.
7030 *
phweissa4e169e2016-11-24 16:20:57 +01007031 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Can only
7032 * be {@code null} if the caller has MANAGE_USERS permission.
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007033 * @return {@code true} if network logging is enabled by device owner, {@code false} otherwise.
phweissa4e169e2016-11-24 16:20:57 +01007034 * @throws {@link SecurityException} if {@code admin} is not a device owner and caller has
7035 * no MANAGE_USERS permission
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007036 */
phweissa4e169e2016-11-24 16:20:57 +01007037 public boolean isNetworkLoggingEnabled(@Nullable ComponentName admin) {
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007038 throwIfParentInstance("isNetworkLoggingEnabled");
7039 try {
7040 return mService.isNetworkLoggingEnabled(admin);
7041 } catch (RemoteException re) {
7042 throw re.rethrowFromSystemServer();
7043 }
7044 }
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007045
7046 /**
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007047 * Called by device owner to retrieve the most recent batch of network logging events.
7048 * A device owner has to provide a batchToken provided as part of
7049 * {@link DeviceAdminReceiver#onNetworkLogsAvailable} callback. If the token doesn't match the
7050 * token of the most recent available batch of logs, {@code null} will be returned.
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007051 *
7052 * <p> {@link NetworkEvent} can be one of {@link DnsEvent} or {@link ConnectEvent}.
7053 *
7054 * <p> The list of network events is sorted chronologically, and contains at most 1200 events.
7055 *
7056 * <p> Access to the logs is rate limited and this method will only return a new batch of logs
7057 * after the device device owner has been notified via
7058 * {@link DeviceAdminReceiver#onNetworkLogsAvailable}.
7059 *
7060 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007061 * @param batchToken A token of the batch to retrieve
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007062 * @return A new batch of network logs which is a list of {@link NetworkEvent}. Returns
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007063 * {@code null} if the batch represented by batchToken is no longer available or if
7064 * logging is disabled.
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007065 * @throws {@link SecurityException} if {@code admin} is not a device owner.
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007066 * @see DeviceAdminReceiver#onNetworkLogsAvailable
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007067 */
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007068 public @Nullable List<NetworkEvent> retrieveNetworkLogs(@NonNull ComponentName admin,
7069 long batchToken) {
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007070 throwIfParentInstance("retrieveNetworkLogs");
7071 try {
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007072 return mService.retrieveNetworkLogs(admin, batchToken);
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007073 } catch (RemoteException re) {
7074 throw re.rethrowFromSystemServer();
7075 }
7076 }
Tony Mak46aabe52016-11-14 12:53:06 +00007077
7078 /**
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007079 * Called by a device owner to bind to a service from a profile owner of a managed profile or
7080 * vice versa. See {@link #getBindDeviceAdminTargetUsers} for a definition of which
7081 * device/profile owners are allowed to bind to services of another profile/device owner.
7082 * <p>
Tony Mak46aabe52016-11-14 12:53:06 +00007083 * The service must be unexported. Note that the {@link Context} used to obtain this
7084 * {@link DevicePolicyManager} instance via {@link Context#getSystemService(Class)} will be used
7085 * to bind to the {@link android.app.Service}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007086 *
Tony Mak46aabe52016-11-14 12:53:06 +00007087 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7088 * @param serviceIntent Identifies the service to connect to. The Intent must specify either an
7089 * explicit component name or a package name to match an
7090 * {@link IntentFilter} published by a service.
7091 * @param conn Receives information as the service is started and stopped. This must be a
7092 * valid {@link ServiceConnection} object; it must not be {@code null}.
7093 * @param flags Operation options for the binding operation. See
7094 * {@link Context#bindService(Intent, ServiceConnection, int)}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007095 * @param targetUser Which user to bind to. Must be one of the users returned by
7096 * {@link #getBindDeviceAdminTargetUsers}, otherwise a {@link SecurityException} will
7097 * be thrown.
Tony Mak46aabe52016-11-14 12:53:06 +00007098 * @return If you have successfully bound to the service, {@code true} is returned;
7099 * {@code false} is returned if the connection is not made and you will not
7100 * receive the service object.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007101 *
Tony Mak46aabe52016-11-14 12:53:06 +00007102 * @see Context#bindService(Intent, ServiceConnection, int)
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007103 * @see #getBindDeviceAdminTargetUsers(ComponentName)
Tony Mak46aabe52016-11-14 12:53:06 +00007104 */
7105 public boolean bindDeviceAdminServiceAsUser(
7106 @NonNull ComponentName admin, Intent serviceIntent, @NonNull ServiceConnection conn,
7107 @Context.BindServiceFlags int flags, @NonNull UserHandle targetUser) {
7108 throwIfParentInstance("bindDeviceAdminServiceAsUser");
7109 // Keep this in sync with ContextImpl.bindServiceCommon.
7110 try {
7111 final IServiceConnection sd = mContext.getServiceDispatcher(conn, null, flags);
7112 serviceIntent.prepareToLeaveProcess(mContext);
7113 return mService.bindDeviceAdminServiceAsUser(admin,
7114 mContext.getIApplicationThread(), mContext.getActivityToken(), serviceIntent,
7115 sd, flags, targetUser.getIdentifier());
7116 } catch (RemoteException re) {
7117 throw re.rethrowFromSystemServer();
7118 }
7119 }
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007120
7121 /**
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007122 * Returns the list of target users that the calling device or profile owner can use when
7123 * calling {@link #bindDeviceAdminServiceAsUser}.
7124 * <p>
7125 * A device owner can bind to a service from a profile owner of a managed profile and
7126 * vice versa, provided that:
7127 * <ul>
7128 * <li>Both belong to the same package name.
7129 * <li>The managed profile is a profile of the user where the device owner is set.
7130 * See {@link UserManager#getUserProfiles()}
7131 * <li>Both users are affiliated.
Nicolas Prevotd5b03602016-12-06 13:32:22 +00007132 * See {@link #setAffiliationIds}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007133 * </ul>
7134 */
7135 public @NonNull List<UserHandle> getBindDeviceAdminTargetUsers(@NonNull ComponentName admin) {
7136 throwIfParentInstance("getBindDeviceAdminTargetUsers");
7137 try {
7138 return mService.getBindDeviceAdminTargetUsers(admin);
7139 } catch (RemoteException re) {
7140 throw re.rethrowFromSystemServer();
7141 }
7142 }
7143
7144 /**
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007145 * Called by the system to get the time at which the device owner last retrieved security
7146 * logging entries.
7147 *
7148 * @return the time at which the device owner most recently retrieved security logging entries,
7149 * in milliseconds since epoch; -1 if security logging entries were never retrieved.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007150 * @throws SecurityException if the caller is not the device owner, does not hold the
7151 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007152 *
7153 * @hide
7154 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007155 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007156 public long getLastSecurityLogRetrievalTime() {
7157 try {
7158 return mService.getLastSecurityLogRetrievalTime();
7159 } catch (RemoteException re) {
7160 throw re.rethrowFromSystemServer();
7161 }
7162 }
7163
7164 /**
7165 * Called by the system to get the time at which the device owner last requested a bug report.
7166 *
7167 * @return the time at which the device owner most recently requested a bug report, in
7168 * milliseconds since epoch; -1 if a bug report was never requested.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007169 * @throws SecurityException if the caller is not the device owner, does not hold the
7170 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007171 *
7172 * @hide
7173 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007174 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007175 public long getLastBugReportRequestTime() {
7176 try {
7177 return mService.getLastBugReportRequestTime();
7178 } catch (RemoteException re) {
7179 throw re.rethrowFromSystemServer();
7180 }
7181 }
7182
7183 /**
7184 * Called by the system to get the time at which the device owner last retrieved network logging
7185 * events.
7186 *
7187 * @return the time at which the device owner most recently retrieved network logging events, in
7188 * milliseconds since epoch; -1 if network logging events were never retrieved.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007189 * @throws SecurityException if the caller is not the device owner, does not hold the
7190 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007191 *
7192 * @hide
7193 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007194 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007195 public long getLastNetworkLogRetrievalTime() {
7196 try {
7197 return mService.getLastNetworkLogRetrievalTime();
7198 } catch (RemoteException re) {
7199 throw re.rethrowFromSystemServer();
7200 }
7201 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08007202}