blob: 6adca01f0fdddcc45e7c03d189353986ea547a7e [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;
Nicolas Prevot8f7698a2016-02-11 16:05:33 +000027import android.annotation.UserIdInt;
Fyodor Kupolov4e9af062016-07-18 16:59:11 -070028import android.annotation.WorkerThread;
Jason Monkd7b86212014-06-16 13:15:38 -040029import android.app.Activity;
Andrew Scull5f9e6f32016-08-02 14:22:17 +010030import android.app.admin.PasswordMetrics;
Tony Mak46aabe52016-11-14 12:53:06 +000031import android.app.IServiceConnection;
Michal Karpinski6235a942016-03-15 12:07:23 +000032import android.app.admin.SecurityLog.SecurityEvent;
Dianne Hackbornd6847842010-01-12 18:14:19 -080033import android.content.ComponentName;
34import android.content.Context;
Adam Connors010cfd42014-04-16 12:48:13 +010035import android.content.Intent;
Sander Alewijnsef475ca32014-02-17 15:13:58 +000036import android.content.IntentFilter;
Tony Mak46aabe52016-11-14 12:53:06 +000037import android.content.ServiceConnection;
Dianne Hackbornd6847842010-01-12 18:14:19 -080038import android.content.pm.PackageManager;
Victor Changcd14c0a2016-03-16 19:10:15 +000039import android.content.pm.PackageManager.NameNotFoundException;
Rubin Xuc3cd05f2016-01-11 12:11:35 +000040import android.content.pm.ParceledListSlice;
Sudheer Shanka978fc0d2016-01-28 13:51:10 +000041import android.content.pm.UserInfo;
Julia Reynoldsfca04ca2015-02-17 13:39:12 -050042import android.graphics.Bitmap;
Jason Monk03bc9912014-05-13 09:44:57 -040043import android.net.ProxyInfo;
Nicolas Prevot8b7991c2015-11-12 17:40:12 +000044import android.net.Uri;
Robin Lee66e5d962014-04-09 16:44:21 +010045import android.os.Bundle;
Jim Millere303bf42014-08-26 17:12:29 -070046import android.os.PersistableBundle;
Adam Connors776c5552014-01-09 10:42:56 +000047import android.os.Process;
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080048import android.os.RemoteCallback;
Dianne Hackbornd6847842010-01-12 18:14:19 -080049import android.os.RemoteException;
Amith Yamasani599dd7c2012-09-14 23:20:08 -070050import android.os.UserHandle;
Julia Reynolds1e958392014-05-16 14:25:21 -040051import android.os.UserManager;
Ricky Wai494b95d2015-11-20 16:07:15 +000052import android.provider.ContactsContract.Directory;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000053import android.provider.Settings;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010054import android.security.Credentials;
Amith Yamasanid1d7c022014-08-19 17:03:41 -070055import android.service.restrictions.RestrictionsReceiver;
Mahaver Chopra1216ae52016-03-11 15:39:48 +000056import android.telephony.TelephonyManager;
Dianne Hackbornd6847842010-01-12 18:14:19 -080057import android.util.Log;
58
Makoto Onukicc4bbeb2015-09-17 10:28:24 -070059import com.android.internal.annotations.VisibleForTesting;
Maggie Benthallda51e682013-08-08 22:35:44 -040060import com.android.org.conscrypt.TrustedCertificateStore;
61
62import java.io.ByteArrayInputStream;
Dianne Hackbornd6847842010-01-12 18:14:19 -080063import java.io.IOException;
Alan Treadwayafad8782016-01-19 15:15:08 +000064import java.lang.annotation.Retention;
65import java.lang.annotation.RetentionPolicy;
Oscar Montemayor69238c62010-08-03 10:51:06 -070066import java.net.InetSocketAddress;
67import java.net.Proxy;
Robin Lee0d5ccb72014-09-12 17:41:44 +010068import java.security.KeyFactory;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000069import java.security.NoSuchAlgorithmException;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010070import java.security.PrivateKey;
71import java.security.cert.Certificate;
Maggie Benthallda51e682013-08-08 22:35:44 -040072import java.security.cert.CertificateException;
73import java.security.cert.CertificateFactory;
74import java.security.cert.X509Certificate;
Robin Lee0d5ccb72014-09-12 17:41:44 +010075import java.security.spec.InvalidKeySpecException;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000076import java.security.spec.PKCS8EncodedKeySpec;
Jim Miller604e7552014-07-18 19:00:02 -070077import java.util.ArrayList;
Rubin Xub4365912016-03-23 12:13:22 +000078import java.util.Arrays;
Svetoslav976e8bd2014-07-16 15:12:03 -070079import java.util.Collections;
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -080080import java.util.List;
Dianne Hackbornd6847842010-01-12 18:14:19 -080081
82/**
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000083 * Public interface for managing policies enforced on a device. Most clients of this class must be
Suprabh Shukla34d92ef2016-03-14 13:49:37 -070084 * registered with the system as a <a href="{@docRoot}guide/topics/admin/device-admin.html">device
85 * administrator</a>. Additionally, a device administrator may be registered as either a profile or
86 * device owner. A given method is accessible to all device administrators unless the documentation
87 * for that method specifies that it is restricted to either device or profile owners. Any
88 * application calling an api may only pass as an argument a device administrator component it
89 * owns. Otherwise, a {@link SecurityException} will be thrown.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080090 * <div class="special reference">
91 * <h3>Developer Guides</h3>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -070092 * <p>
93 * For more information about managing policies for device administration, read the <a href=
94 * "{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a> developer
95 * guide. </div>
Dianne Hackbornd6847842010-01-12 18:14:19 -080096 */
97public class DevicePolicyManager {
98 private static String TAG = "DevicePolicyManager";
Dianne Hackbornd6847842010-01-12 18:14:19 -080099
100 private final Context mContext;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800101 private final IDevicePolicyManager mService;
Esteban Talavera62399912016-01-11 15:37:55 +0000102 private final boolean mParentInstance;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700103
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600104 /** @hide */
105 public DevicePolicyManager(Context context, IDevicePolicyManager service) {
106 this(context, service, false);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800107 }
108
Dianne Hackborn87bba1e2010-02-26 17:25:54 -0800109 /** @hide */
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700110 @VisibleForTesting
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600111 protected DevicePolicyManager(Context context, IDevicePolicyManager service,
112 boolean parentInstance) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700113 mContext = context;
114 mService = service;
Esteban Talavera62399912016-01-11 15:37:55 +0000115 mParentInstance = parentInstance;
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700116 }
117
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700118 /** @hide test will override it. */
119 @VisibleForTesting
120 protected int myUserId() {
121 return UserHandle.myUserId();
122 }
123
Dianne Hackbornd6847842010-01-12 18:14:19 -0800124 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +0000125 * Activity action: Starts the provisioning flow which sets up a managed profile.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000126 *
Jessica Hummel9da60392014-05-21 12:32:57 +0100127 * <p>A managed profile allows data separation for example for the usage of a
128 * device as a personal and corporate device. The user which provisioning is started from and
129 * the managed profile share a launcher.
130 *
Andrew Solovay27f53372015-03-02 16:37:59 -0800131 * <p>This intent will typically be sent by a mobile device management application (MDM).
132 * Provisioning adds a managed profile and sets the MDM as the profile owner who has full
133 * control over the profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100134 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000135 * <p>It is possible to check if provisioning is allowed or not by querying the method
136 * {@link #isProvisioningAllowed(String)}.
137 *
138 * <p>In version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this intent must contain the
Nicolas Prevot18440252015-03-09 14:07:17 +0000139 * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700140 * As of {@link android.os.Build.VERSION_CODES#M}, it should contain the extra
Nicolas Prevot18440252015-03-09 14:07:17 +0000141 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only
142 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000143 *
Benjamin Franzea956242016-03-21 15:45:56 +0000144 * <p>The intent may also contain the following extras:
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000145 * <ul>
Benjamin Franzea956242016-03-21 15:45:56 +0000146 * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, optional </li>
147 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional, supported from
148 * {@link android.os.Build.VERSION_CODES#N}</li>
149 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
150 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
151 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000152 * </ul>
Jessica Hummelf72078b2014-03-06 16:13:12 +0000153 *
Benjamin Franzea956242016-03-21 15:45:56 +0000154 * <p>When managed provisioning has completed, broadcasts are sent to the application specified
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000155 * in the provisioning intent. The
156 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the
157 * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in
158 * the primary profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100159 *
Benjamin Franzea956242016-03-21 15:45:56 +0000160 * <p>If provisioning fails, the managedProfile is removed so the device returns to its
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100161 * previous state.
Alan Treadway4582f812015-07-28 11:49:35 +0100162 *
163 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
164 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
165 * the provisioning flow was successful, although this doesn't guarantee the full flow will
166 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
167 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000168 */
169 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
170 public static final String ACTION_PROVISION_MANAGED_PROFILE
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100171 = "android.app.action.PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000172
173 /**
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000174 * Activity action: Starts the provisioning flow which sets up a managed user.
175 *
176 * <p>This intent will typically be sent by a mobile device management application (MDM).
Makoto Onuki32b30572015-12-11 14:29:51 -0800177 * Provisioning configures the user as managed user and sets the MDM as the profile
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000178 * owner who has full control over the user. Provisioning can only happen before user setup has
179 * been completed. Use {@link #isProvisioningAllowed(String)} to check if provisioning is
180 * allowed.
181 *
Benjamin Franzea956242016-03-21 15:45:56 +0000182 * <p>The intent contains the following extras:
183 * <ul>
184 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
185 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
186 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
187 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
188 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
189 * </ul>
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000190 *
Benjamin Franzea956242016-03-21 15:45:56 +0000191 * <p>If provisioning fails, the device returns to its previous state.
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000192 *
193 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
194 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
195 * the provisioning flow was successful, although this doesn't guarantee the full flow will
196 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
197 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Benjamin Franzea956242016-03-21 15:45:56 +0000198 *
199 * @hide
Mahaver Chopra5e732562015-11-05 11:55:12 +0000200 */
201 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
202 public static final String ACTION_PROVISION_MANAGED_USER
203 = "android.app.action.PROVISION_MANAGED_USER";
204
205 /**
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100206 * Activity action: Starts the provisioning flow which sets up a managed device.
207 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
208 *
209 * <p> During device owner provisioning a device admin app is set as the owner of the device.
210 * A device owner has full control over the device. The device owner can not be modified by the
211 * user.
212 *
213 * <p> A typical use case would be a device that is owned by a company, but used by either an
214 * employee or client.
215 *
216 * <p> An intent with this action can be sent only on an unprovisioned device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000217 * It is possible to check if provisioning is allowed or not by querying the method
218 * {@link #isProvisioningAllowed(String)}.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100219 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000220 * <p>The intent contains the following extras:
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100221 * <ul>
222 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
223 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
224 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
Rubin Xua4f9dc12015-06-12 13:27:59 +0100225 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000226 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000227 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100228 * </ul>
229 *
Benjamin Franzea956242016-03-21 15:45:56 +0000230 * <p>When device owner provisioning has completed, an intent of the type
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100231 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
232 * device owner.
233 *
Benjamin Franzea956242016-03-21 15:45:56 +0000234 * <p>If provisioning fails, the device is factory reset.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100235 *
Alan Treadway4582f812015-07-28 11:49:35 +0100236 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
237 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
238 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
239 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100240 */
241 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
242 public static final String ACTION_PROVISION_MANAGED_DEVICE
243 = "android.app.action.PROVISION_MANAGED_DEVICE";
244
245 /**
Alan Treadway46dd4492015-11-09 13:57:19 +0000246 * Activity action: Starts the provisioning flow which sets up a managed device.
Steven Ng980a1b62016-02-02 17:43:18 +0000247 *
248 * <p>During device owner provisioning, a device admin app is downloaded and set as the owner of
249 * the device. A device owner has full control over the device. The device owner can not be
250 * modified by the user and the only way of resetting the device is via factory reset.
251 *
252 * <p>A typical use case would be a device that is owned by a company, but used by either an
253 * employee or client.
254 *
255 * <p>The provisioning message should be sent to an unprovisioned device.
256 *
257 * <p>Unlike {@link #ACTION_PROVISION_MANAGED_DEVICE}, the provisioning message can only be sent
258 * by a privileged app with the permission
259 * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE}.
260 *
261 * <p>The provisioning intent contains the following properties:
262 * <ul>
263 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
264 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
265 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
266 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
267 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
268 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
269 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
270 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
271 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
272 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
273 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
274 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
275 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
276 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
277 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
278 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li></ul>
279 *
280 * @hide
281 */
282 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
283 @SystemApi
284 public static final String ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE =
285 "android.app.action.PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE";
286
287 /**
288 * Activity action: Starts the provisioning flow which sets up a managed device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000289 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
290 *
291 * <p>NOTE: This is only supported on split system user devices, and puts the device into a
292 * management state that is distinct from that reached by
293 * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system
294 * user, and only has control over device-wide policies, not individual users and their data.
295 * The primary benefit is that multiple non-system users are supported when provisioning using
296 * this form of device management.
297 *
Benjamin Franzea956242016-03-21 15:45:56 +0000298 * <p>During device owner provisioning a device admin app is set as the owner of the device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000299 * A device owner has full control over the device. The device owner can not be modified by the
300 * user.
301 *
Benjamin Franzea956242016-03-21 15:45:56 +0000302 * <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 +0000303 * employee or client.
304 *
Benjamin Franzea956242016-03-21 15:45:56 +0000305 * <p>An intent with this action can be sent only on an unprovisioned device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000306 * It is possible to check if provisioning is allowed or not by querying the method
307 * {@link #isProvisioningAllowed(String)}.
308 *
309 * <p>The intent contains the following extras:
310 * <ul>
311 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
312 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
313 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
314 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Benjamin Franzea956242016-03-21 15:45:56 +0000315 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
316 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Alan Treadway46dd4492015-11-09 13:57:19 +0000317 * </ul>
318 *
Benjamin Franzea956242016-03-21 15:45:56 +0000319 * <p>When device owner provisioning has completed, an intent of the type
Alan Treadway46dd4492015-11-09 13:57:19 +0000320 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
321 * device owner.
322 *
Benjamin Franzea956242016-03-21 15:45:56 +0000323 * <p>If provisioning fails, the device is factory reset.
Alan Treadway46dd4492015-11-09 13:57:19 +0000324 *
325 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
326 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
327 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
328 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
329 *
330 * @hide
331 */
332 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
333 public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE
334 = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE";
335
336 /**
Alan Treadwayafad8782016-01-19 15:15:08 +0000337 * Activity action: Finalizes management provisioning, should be used after user-setup
338 * has been completed and {@link #getUserProvisioningState()} returns one of:
339 * <ul>
340 * <li>{@link #STATE_USER_SETUP_INCOMPLETE}</li>
341 * <li>{@link #STATE_USER_SETUP_COMPLETE}</li>
342 * <li>{@link #STATE_USER_PROFILE_COMPLETE}</li>
343 * </ul>
344 *
345 * @hide
346 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +0000347 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +0000348 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
349 public static final String ACTION_PROVISION_FINALIZATION
350 = "android.app.action.PROVISION_FINALIZATION";
351
352 /**
Michal Karpinskiba244092016-02-25 17:28:24 +0000353 * Action: Bugreport sharing with device owner has been accepted by the user.
354 *
355 * @hide
356 */
357 public static final String ACTION_BUGREPORT_SHARING_ACCEPTED =
358 "com.android.server.action.BUGREPORT_SHARING_ACCEPTED";
359
360 /**
361 * Action: Bugreport sharing with device owner has been declined by the user.
362 *
363 * @hide
364 */
365 public static final String ACTION_BUGREPORT_SHARING_DECLINED =
366 "com.android.server.action.BUGREPORT_SHARING_DECLINED";
367
368 /**
369 * Action: Bugreport has been collected and is dispatched to {@link DevicePolicyManagerService}.
370 *
371 * @hide
372 */
373 public static final String ACTION_REMOTE_BUGREPORT_DISPATCH =
374 "android.intent.action.REMOTE_BUGREPORT_DISPATCH";
375
376 /**
377 * Extra for shared bugreport's SHA-256 hash.
378 *
379 * @hide
380 */
381 public static final String EXTRA_REMOTE_BUGREPORT_HASH =
382 "android.intent.extra.REMOTE_BUGREPORT_HASH";
383
384 /**
385 * Extra for remote bugreport notification shown type.
386 *
387 * @hide
388 */
389 public static final String EXTRA_BUGREPORT_NOTIFICATION_TYPE =
390 "android.app.extra.bugreport_notification_type";
391
392 /**
393 * Notification type for a started remote bugreport flow.
394 *
395 * @hide
396 */
397 public static final int NOTIFICATION_BUGREPORT_STARTED = 1;
398
399 /**
400 * Notification type for a bugreport that has already been accepted to be shared, but is still
401 * being taken.
402 *
403 * @hide
404 */
405 public static final int NOTIFICATION_BUGREPORT_ACCEPTED_NOT_FINISHED = 2;
406
407 /**
408 * Notification type for a bugreport that has been taken and can be shared or declined.
409 *
410 * @hide
411 */
412 public static final int NOTIFICATION_BUGREPORT_FINISHED_NOT_ACCEPTED = 3;
413
414 /**
Michal Karpinski8f010dd2016-06-21 15:05:53 +0100415 * Default and maximum timeout in milliseconds after which unlocking with weak auth times out,
416 * i.e. the user has to use a strong authentication method like password, PIN or pattern.
417 *
418 * @hide
419 */
420 public static final long DEFAULT_STRONG_AUTH_TIMEOUT_MS = 72 * 60 * 60 * 1000; // 72h
421
422 /**
Rubin Xua4f9dc12015-06-12 13:27:59 +0100423 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100424 * allows a mobile device management application or NFC programmer application which starts
425 * managed provisioning to pass data to the management application instance after provisioning.
Rubin Xua4f9dc12015-06-12 13:27:59 +0100426 * <p>
427 * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that
428 * sends the intent to pass data to itself on the newly created profile.
429 * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same
430 * instance of the app on the primary user.
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100431 * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with
432 * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC
433 * message should contain a stringified {@link java.util.Properties} instance, whose string
434 * properties will be converted into a {@link android.os.PersistableBundle} and passed to the
435 * management application after provisioning.
436 *
Rubin Xua4f9dc12015-06-12 13:27:59 +0100437 * <p>
438 * In both cases the application receives the data in
Brian Carlstromf1fe51b2014-09-03 08:55:05 -0700439 * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action
440 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed
Rubin Xua4f9dc12015-06-12 13:27:59 +0100441 * during the managed provisioning.
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100442 */
443 public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE =
Esteban Talavera37f01842014-09-05 10:50:57 +0100444 "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE";
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100445
446 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100447 * A String extra holding the package name of the mobile device management application that
448 * will be set as the profile owner or device owner.
449 *
450 * <p>If an application starts provisioning directly via an intent with action
451 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
452 * application that started provisioning. The package will be set as profile owner in that case.
453 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000454 * <p>This package is set as device owner when device owner provisioning is started by an NFC
455 * message containing an NFC record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000456 *
457 * <p> When this extra is set, the application must have exactly one device admin receiver.
Robin Lee25e26452015-06-02 09:56:29 -0700458 * This receiver will be set as the profile or device owner and active admin.
Benjamin Franzea956242016-03-21 15:45:56 +0000459 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000460 * @see DeviceAdminReceiver
461 * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still
Nicolas Prevot8f78d6a2015-08-21 11:06:31 +0100462 * supported, but only if there is only one device admin receiver in the package that requires
463 * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000464 */
Nicolas Prevot18440252015-03-09 14:07:17 +0000465 @Deprecated
Jessica Hummelf72078b2014-03-06 16:13:12 +0000466 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100467 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000468
469 /**
Nicolas Prevot18440252015-03-09 14:07:17 +0000470 * A ComponentName extra indicating the device admin receiver of the mobile device management
471 * application that will be set as the profile owner or device owner and active admin.
472 *
473 * <p>If an application starts provisioning directly via an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100474 * {@link #ACTION_PROVISION_MANAGED_PROFILE} or
475 * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this
476 * component has to match the package name of the application that started provisioning.
Nicolas Prevot18440252015-03-09 14:07:17 +0000477 *
478 * <p>This component is set as device owner and active admin when device owner provisioning is
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100479 * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC
480 * message containing an NFC record with MIME type
Benjamin Franzea956242016-03-21 15:45:56 +0000481 * {@link #MIME_TYPE_PROVISIONING_NFC}. For the NFC record, the component name must be
Rubin Xu44ef750b2015-03-23 16:51:33 +0000482 * flattened to a string, via {@link ComponentName#flattenToShortString()}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000483 *
484 * @see DeviceAdminReceiver
485 */
486 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME
487 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME";
488
489 /**
Alexandra Gherghinaaaf2f3e2014-11-13 12:46:15 +0000490 * An {@link android.accounts.Account} extra holding the account to migrate during managed
491 * profile provisioning. If the account supplied is present in the primary user, it will be
492 * copied, along with its credentials to the managed profile and removed from the primary user.
493 *
494 * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}.
495 */
496
497 public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE
498 = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE";
499
500 /**
Jessica Hummele3da7902014-08-20 15:20:11 +0100501 * A String extra that, holds the email address of the account which a managed profile is
502 * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
503 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100504 *
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100505 * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}.
506 *
Jessica Hummele3da7902014-08-20 15:20:11 +0100507 * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning
508 * contains this extra, it is forwarded in the
509 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile
510 * device management application that was set as the profile owner during provisioning.
511 * It is usually used to avoid that the user has to enter their email address twice.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100512 */
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100513 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
514 = "android.app.extra.PROVISIONING_EMAIL_ADDRESS";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100515
516 /**
Nicolas Prevotcd2d8592015-11-23 13:27:21 +0000517 * A integer extra indicating the predominant color to show during the provisioning.
518 * Refer to {@link android.graphics.Color} for how the color is represented.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000519 *
520 * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or
521 * {@link #ACTION_PROVISION_MANAGED_DEVICE}.
522 */
523 public static final String EXTRA_PROVISIONING_MAIN_COLOR =
524 "android.app.extra.PROVISIONING_MAIN_COLOR";
525
526 /**
Sander Alewijnse8c411562014-11-12 18:03:11 +0000527 * A Boolean extra that can be used by the mobile device management application to skip the
Robin Lee25e26452015-06-02 09:56:29 -0700528 * disabling of system apps during provisioning when set to {@code true}.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000529 *
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100530 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
531 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000532 */
Sander Alewijnse5a144252014-11-18 13:25:04 +0000533 public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED =
534 "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED";
Sander Alewijnse8c411562014-11-12 18:03:11 +0000535
536 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100537 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
538 * will be set to.
539 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000540 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
541 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100542 */
543 public static final String EXTRA_PROVISIONING_TIME_ZONE
Esteban Talavera37f01842014-09-05 10:50:57 +0100544 = "android.app.extra.PROVISIONING_TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100545
546 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100547 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
548 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100549 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000550 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
551 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100552 */
553 public static final String EXTRA_PROVISIONING_LOCAL_TIME
Esteban Talavera37f01842014-09-05 10:50:57 +0100554 = "android.app.extra.PROVISIONING_LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100555
556 /**
557 * A String extra holding the {@link java.util.Locale} that the device will be set to.
558 * Format: xx_yy, where xx is the language code, and yy the country code.
559 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000560 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
561 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100562 */
563 public static final String EXTRA_PROVISIONING_LOCALE
Esteban Talavera37f01842014-09-05 10:50:57 +0100564 = "android.app.extra.PROVISIONING_LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100565
566 /**
567 * A String extra holding the ssid of the wifi network that should be used during nfc device
568 * owner provisioning for downloading the mobile device management application.
569 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000570 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
571 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100572 */
573 public static final String EXTRA_PROVISIONING_WIFI_SSID
Esteban Talavera37f01842014-09-05 10:50:57 +0100574 = "android.app.extra.PROVISIONING_WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100575
576 /**
577 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
578 * is hidden or not.
579 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000580 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
581 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100582 */
583 public static final String EXTRA_PROVISIONING_WIFI_HIDDEN
Esteban Talavera37f01842014-09-05 10:50:57 +0100584 = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100585
586 /**
587 * A String extra indicating the security type of the wifi network in
Mahaver Chopra76b08a92015-10-08 17:58:45 +0100588 * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or
589 * {@code WEP}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100590 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000591 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
592 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100593 */
594 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
Esteban Talavera37f01842014-09-05 10:50:57 +0100595 = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100596
597 /**
598 * A String extra holding the password of the wifi network in
599 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
600 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000601 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
602 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100603 */
604 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talavera37f01842014-09-05 10:50:57 +0100605 = "android.app.extra.PROVISIONING_WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100606
607 /**
608 * A String extra holding the proxy host for the wifi network in
609 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
610 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000611 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
612 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100613 */
614 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
Esteban Talavera37f01842014-09-05 10:50:57 +0100615 = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100616
617 /**
618 * An int extra holding the proxy port for the wifi network in
619 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
620 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000621 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
622 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100623 */
624 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
Esteban Talavera37f01842014-09-05 10:50:57 +0100625 = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100626
627 /**
628 * A String extra holding the proxy bypass for the wifi network in
629 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
630 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000631 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
632 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100633 */
634 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
Esteban Talavera37f01842014-09-05 10:50:57 +0100635 = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100636
637 /**
638 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
639 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
640 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000641 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
642 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100643 */
644 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
Esteban Talavera37f01842014-09-05 10:50:57 +0100645 = "android.app.extra.PROVISIONING_WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100646
647 /**
648 * A String extra holding a url that specifies the download location of the device admin
649 * package. When not provided it is assumed that the device admin package is already installed.
650 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000651 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
652 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100653 */
654 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talavera37f01842014-09-05 10:50:57 +0100655 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100656
657 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400658 * An int extra holding a minimum required version code for the device admin package. If the
659 * device admin is already installed on the device, it will only be re-downloaded from
660 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the
661 * installed package is less than this version code.
662 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400663 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400664 * provisioning via an NFC bump.
665 */
666 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE
667 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE";
668
669 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100670 * A String extra holding a http cookie header which should be used in the http request to the
671 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
672 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000673 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
674 * provisioning via an NFC bump.
Sander Alewijnse681bce92014-07-24 16:46:26 +0100675 */
676 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talavera37f01842014-09-05 10:50:57 +0100677 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100678
679 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100680 * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of
681 * the file at download location specified in
682 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100683 *
Benjamin Franzea956242016-03-21 15:45:56 +0000684 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} must be
685 * present. The provided checksum must match the checksum of the file at the download
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100686 * location. If the checksum doesn't match an error will be shown to the user and the user will
687 * be asked to factory reset the device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100688 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000689 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
690 * provisioning via an NFC bump.
Rubin Xud92e7572015-05-18 17:01:13 +0100691 *
692 * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP}
693 * and {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1} only SHA-1 hash is supported.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700694 * Starting from {@link android.os.Build.VERSION_CODES#M}, this parameter accepts SHA-256 in
Rubin Xud92e7572015-05-18 17:01:13 +0100695 * addition to SHA-1. Support for SHA-1 is likely to be removed in future OS releases.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100696 */
697 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100698 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100699
700 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100701 * A String extra holding the URL-safe base64 encoded SHA-256 checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100702 * android package archive at the download location specified in {@link
703 * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
704 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100705 * <p>The signatures of an android package archive can be obtained using
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100706 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
707 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
708 *
Benjamin Franzea956242016-03-21 15:45:56 +0000709 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} must be
710 * present. The provided checksum must match the checksum of any signature of the file at
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100711 * the download location. If the checksum does not match an error will be shown to the user and
712 * the user will be asked to factory reset the device.
713 *
714 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
715 * provisioning via an NFC bump.
716 */
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100717 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM
718 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM";
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100719
720 /**
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000721 * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile
722 * has completed successfully.
723 *
724 * <p>The broadcast is limited to the primary profile, to the app specified in the provisioning
Nicolas Prevotebe2d992015-05-12 18:14:53 -0700725 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000726 *
Ying Wang7f38aab2015-02-20 11:50:09 -0800727 * <p>This intent will contain the extra {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE} which
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000728 * corresponds to the account requested to be migrated at provisioning time, if any.
729 */
730 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
731 public static final String ACTION_MANAGED_PROFILE_PROVISIONED
732 = "android.app.action.MANAGED_PROFILE_PROVISIONED";
733
734 /**
Benjamin Franzea956242016-03-21 15:45:56 +0000735 * A boolean extra indicating whether device encryption can be skipped as part of device owner
736 * or managed profile provisioning.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500737 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400738 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100739 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Benjamin Franzea956242016-03-21 15:45:56 +0000740 *
741 * <p>From {@link android.os.Build.VERSION_CODES#N} onwards, this is also supported for an
742 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500743 */
744 public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION =
745 "android.app.extra.PROVISIONING_SKIP_ENCRYPTION";
746
747 /**
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000748 * A {@link Uri} extra pointing to a logo image. This image will be shown during the
749 * provisioning. If this extra is not passed, a default image will be shown.
750 * <h5>The following URI schemes are accepted:</h5>
751 * <ul>
752 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
753 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
754 * </ul>
755 *
756 * <p> It is the responsability of the caller to provide an image with a reasonable
757 * pixed density for the device.
758 *
759 * <p> If a content: URI is passed, the intent should have the flag
760 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
761 * {@link android.content.ClipData} of the intent too.
762 *
763 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or
764 * {@link #ACTION_PROVISION_MANAGED_DEVICE}
765 */
766 public static final String EXTRA_PROVISIONING_LOGO_URI =
767 "android.app.extra.PROVISIONING_LOGO_URI";
768
769 /**
Alan Treadway94de8c82016-01-11 10:25:23 +0000770 * A boolean extra indicating if user setup should be skipped, for when provisioning is started
771 * during setup-wizard.
772 *
773 * <p>If unspecified, defaults to {@code true} to match the behavior in
774 * {@link android.os.Build.VERSION_CODES#M} and earlier.
775 *
Alan Treadway1a538d02016-01-18 16:42:30 +0000776 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or
777 * {@link #ACTION_PROVISION_MANAGED_USER}.
Alan Treadway94de8c82016-01-11 10:25:23 +0000778 *
779 * @hide
780 */
781 public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP =
782 "android.app.extra.PROVISIONING_SKIP_USER_SETUP";
783
784 /**
Benjamin Franzea956242016-03-21 15:45:56 +0000785 * This MIME type is used for starting the device owner provisioning.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100786 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400787 * <p>During device owner provisioning a device admin app is set as the owner of the device.
788 * A device owner has full control over the device. The device owner can not be modified by the
789 * user and the only way of resetting the device is if the device owner app calls a factory
790 * reset.
791 *
792 * <p> A typical use case would be a device that is owned by a company, but used by either an
793 * employee or client.
794 *
Benjamin Franzea956242016-03-21 15:45:56 +0000795 * <p> The NFC message must be sent to an unprovisioned device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100796 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000797 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100798 * contains the following properties:
799 * <ul>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400800 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
801 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100802 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400803 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100804 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
805 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
806 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
807 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
808 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
809 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
810 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
811 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
812 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
813 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100814 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
815 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from
816 * {@link android.os.Build.VERSION_CODES#M} </li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100817 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000818 * <p>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700819 * As of {@link android.os.Build.VERSION_CODES#M}, the properties should contain
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400820 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of
821 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only
822 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400823 */
824 public static final String MIME_TYPE_PROVISIONING_NFC
825 = "application/com.android.managedprovisioning";
826
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100827 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800828 * Activity action: ask the user to add a new device administrator to the system.
829 * The desired policy is the ComponentName of the policy in the
830 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
831 * bring the user through adding the device administrator to the system (or
832 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700833 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800834 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
835 * field to provide the user with additional explanation (in addition
836 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800837 *
838 * <p>If your administrator is already active, this will ordinarily return immediately (without
839 * user intervention). However, if your administrator has been updated and is requesting
840 * additional uses-policy flags, the user will be presented with the new list. New policies
841 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800842 */
843 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
844 public static final String ACTION_ADD_DEVICE_ADMIN
845 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700846
Dianne Hackbornd6847842010-01-12 18:14:19 -0800847 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700848 * @hide
849 * Activity action: ask the user to add a new device administrator as the profile owner
Amith Yamasani814e9872015-03-23 14:04:53 -0700850 * for this user. Only system apps can launch this intent.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700851 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700852 * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN}
853 * extra field. This will invoke a UI to bring the user through adding the profile owner admin
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700854 * to remotely control restrictions on the user.
855 *
Makoto Onukic8a5a552015-11-19 14:29:12 -0800856 * <p>The intent must be invoked via {@link Activity#startActivityForResult} to receive the
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700857 * result of whether or not the user approved the action. If approved, the result will
858 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
859 * as a profile owner.
860 *
861 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
862 * field to provide the user with additional explanation (in addition
863 * to your component's description) about what is being added.
864 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700865 * <p>If there is already a profile owner active or the caller is not a system app, the
866 * operation will return a failure result.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700867 */
868 @SystemApi
869 public static final String ACTION_SET_PROFILE_OWNER
870 = "android.app.action.SET_PROFILE_OWNER";
871
872 /**
873 * @hide
874 * Name of the profile owner admin that controls the user.
875 */
876 @SystemApi
877 public static final String EXTRA_PROFILE_OWNER_NAME
878 = "android.app.extra.PROFILE_OWNER_NAME";
879
880 /**
Nicolas Prevot00799002015-07-27 18:15:20 +0100881 * Broadcast action: send when any policy admin changes a policy.
Jim Miller284b62e2010-06-08 14:27:42 -0700882 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700883 *
Jim Miller284b62e2010-06-08 14:27:42 -0700884 * @hide
885 */
886 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
887 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
888
889 /**
Tony Mak1970f972016-08-30 17:41:48 +0100890 * Broadcast action: sent when the device owner is set, changed or cleared.
Nicolas Prevot00799002015-07-27 18:15:20 +0100891 *
892 * This broadcast is sent only to the primary user.
893 * @see #ACTION_PROVISION_MANAGED_DEVICE
894 */
895 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
896 public static final String ACTION_DEVICE_OWNER_CHANGED
897 = "android.app.action.DEVICE_OWNER_CHANGED";
898
899 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800900 * The ComponentName of the administrator component.
901 *
902 * @see #ACTION_ADD_DEVICE_ADMIN
903 */
904 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700905
Dianne Hackbornd6847842010-01-12 18:14:19 -0800906 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800907 * An optional CharSequence providing additional explanation for why the
908 * admin is being added.
909 *
910 * @see #ACTION_ADD_DEVICE_ADMIN
911 */
912 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700913
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800914 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700915 * Activity action: have the user enter a new password. This activity should
916 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
917 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
918 * enter a new password that meets the current requirements. You can use
919 * {@link #isActivePasswordSufficient()} to determine whether you need to
920 * have the user select a new password in order to meet the current
921 * constraints. Upon being resumed from this activity, you can check the new
922 * password characteristics to see if they are sufficient.
Benjamin Franzc9921092016-01-08 17:17:44 +0000923 *
924 * If the intent is launched from within a managed profile with a profile
925 * owner built against {@link android.os.Build.VERSION_CODES#M} or before,
926 * this will trigger entering a new password for the parent of the profile.
927 * For all other cases it will trigger entering a new password for the user
928 * or profile it is launched from.
Esteban Talaverac1c83592016-02-17 17:56:15 +0000929 *
930 * @see #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
Dianne Hackbornd6847842010-01-12 18:14:19 -0800931 */
932 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
933 public static final String ACTION_SET_NEW_PASSWORD
934 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700935
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000936 /**
Benjamin Franzc9921092016-01-08 17:17:44 +0000937 * Activity action: have the user enter a new password for the parent profile.
938 * If the intent is launched from within a managed profile, this will trigger
939 * entering a new password for the parent of the profile. In all other cases
940 * the behaviour is identical to {@link #ACTION_SET_NEW_PASSWORD}.
941 */
942 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
943 public static final String ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
944 = "android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD";
945
946 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000947 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
948 * the parent profile to access intents sent from the managed profile.
949 * That is, when an app in the managed profile calls
950 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
951 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000952 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100953 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000954
955 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000956 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
957 * the managed profile to access intents sent from the parent profile.
958 * That is, when an app in the parent profile calls
959 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
960 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000961 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100962 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700963
Dianne Hackbornd6847842010-01-12 18:14:19 -0800964 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +0100965 * Broadcast action: notify that a new local system update policy has been set by the device
966 * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}.
Rubin Xu8027a4f2015-03-10 17:52:37 +0000967 */
968 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Rubin Xu5faad8e2015-04-20 17:43:48 +0100969 public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED
970 = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED";
Rubin Xu8027a4f2015-03-10 17:52:37 +0000971
Amith Yamasanid49489b2015-04-28 14:00:26 -0700972 /**
973 * Permission policy to prompt user for new permission requests for runtime permissions.
974 * Already granted or denied permissions are not affected by this.
975 */
976 public static final int PERMISSION_POLICY_PROMPT = 0;
977
978 /**
979 * Permission policy to always grant new permission requests for runtime permissions.
980 * Already granted or denied permissions are not affected by this.
981 */
982 public static final int PERMISSION_POLICY_AUTO_GRANT = 1;
983
984 /**
985 * Permission policy to always deny new permission requests for runtime permissions.
986 * Already granted or denied permissions are not affected by this.
987 */
988 public static final int PERMISSION_POLICY_AUTO_DENY = 2;
989
Svet Ganovd8ecc5a2015-05-20 10:45:43 -0700990 /**
991 * Runtime permission state: The user can manage the permission
992 * through the UI.
993 */
994 public static final int PERMISSION_GRANT_STATE_DEFAULT = 0;
995
996 /**
997 * Runtime permission state: The permission is granted to the app
998 * and the user cannot manage the permission through the UI.
999 */
1000 public static final int PERMISSION_GRANT_STATE_GRANTED = 1;
1001
1002 /**
1003 * Runtime permission state: The permission is denied to the app
1004 * and the user cannot manage the permission through the UI.
1005 */
1006 public static final int PERMISSION_GRANT_STATE_DENIED = 2;
Rubin Xu8027a4f2015-03-10 17:52:37 +00001007
1008 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00001009 * No management for current user in-effect. This is the default.
1010 * @hide
1011 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001012 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001013 public static final int STATE_USER_UNMANAGED = 0;
1014
1015 /**
1016 * Management partially setup, user setup needs to be completed.
1017 * @hide
1018 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001019 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001020 public static final int STATE_USER_SETUP_INCOMPLETE = 1;
1021
1022 /**
1023 * Management partially setup, user setup completed.
1024 * @hide
1025 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001026 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001027 public static final int STATE_USER_SETUP_COMPLETE = 2;
1028
1029 /**
1030 * Management setup and active on current user.
1031 * @hide
1032 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001033 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001034 public static final int STATE_USER_SETUP_FINALIZED = 3;
1035
1036 /**
1037 * Management partially setup on a managed profile.
1038 * @hide
1039 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001040 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001041 public static final int STATE_USER_PROFILE_COMPLETE = 4;
1042
1043 /**
1044 * @hide
1045 */
1046 @IntDef({STATE_USER_UNMANAGED, STATE_USER_SETUP_INCOMPLETE, STATE_USER_SETUP_COMPLETE,
1047 STATE_USER_SETUP_FINALIZED, STATE_USER_PROFILE_COMPLETE})
1048 @Retention(RetentionPolicy.SOURCE)
1049 public @interface UserProvisioningState {}
1050
1051 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001052 * Return true if the given administrator component is currently active (enabled) in the system.
1053 *
1054 * @param admin The administrator component to check for.
1055 * @return {@code true} if {@code admin} is currently enabled in the system, {@code false}
1056 * otherwise
Dianne Hackbornd6847842010-01-12 18:14:19 -08001057 */
Robin Lee25e26452015-06-02 09:56:29 -07001058 public boolean isAdminActive(@NonNull ComponentName admin) {
Charles He8c760562016-10-25 16:36:53 +01001059 throwIfParentInstance("isAdminActive");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001060 return isAdminActiveAsUser(admin, myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001061 }
1062
1063 /**
1064 * @see #isAdminActive(ComponentName)
1065 * @hide
1066 */
Robin Lee25e26452015-06-02 09:56:29 -07001067 public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001068 if (mService != null) {
1069 try {
Robin Lee25e26452015-06-02 09:56:29 -07001070 return mService.isAdminActive(admin, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001071 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001072 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001073 }
1074 }
1075 return false;
1076 }
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001077 /**
1078 * Return true if the given administrator component is currently being removed
1079 * for the user.
1080 * @hide
1081 */
Robin Lee25e26452015-06-02 09:56:29 -07001082 public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) {
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001083 if (mService != null) {
1084 try {
Robin Lee25e26452015-06-02 09:56:29 -07001085 return mService.isRemovingAdmin(admin, userId);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001086 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001087 throw e.rethrowFromSystemServer();
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001088 }
1089 }
1090 return false;
1091 }
1092
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001093
Dianne Hackbornd6847842010-01-12 18:14:19 -08001094 /**
Robin Lee25e26452015-06-02 09:56:29 -07001095 * Return a list of all currently active device administrators' component
1096 * names. If there are no administrators {@code null} may be
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001097 * returned.
1098 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07001099 public @Nullable List<ComponentName> getActiveAdmins() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001100 throwIfParentInstance("getActiveAdmins");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001101 return getActiveAdminsAsUser(myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001102 }
1103
1104 /**
1105 * @see #getActiveAdmins()
1106 * @hide
1107 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07001108 public @Nullable List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001109 if (mService != null) {
1110 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001111 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001112 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001113 throw e.rethrowFromSystemServer();
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001114 }
1115 }
1116 return null;
1117 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001118
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001119 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001120 * Used by package administration code to determine if a package can be stopped
1121 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001122 * @hide
1123 */
1124 public boolean packageHasActiveAdmins(String packageName) {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001125 return packageHasActiveAdmins(packageName, myUserId());
1126 }
1127
1128 /**
1129 * Used by package administration code to determine if a package can be stopped
1130 * or uninstalled.
1131 * @hide
1132 */
1133 public boolean packageHasActiveAdmins(String packageName, int userId) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001134 if (mService != null) {
1135 try {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001136 return mService.packageHasActiveAdmins(packageName, userId);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001137 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001138 throw e.rethrowFromSystemServer();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001139 }
1140 }
1141 return false;
1142 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001143
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001144 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001145 * Remove a current administration component. This can only be called
1146 * by the application that owns the administration component; if you
1147 * try to remove someone else's component, a security exception will be
1148 * thrown.
Esteban Talavera552a5612016-02-19 17:02:24 +00001149 *
1150 * <p>Note that the operation is not synchronous and the admin might still be active (as
1151 * indicated by {@link #getActiveAdmins()}) by the time this method returns.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001152 *
1153 * @param admin The administration compononent to remove.
1154 * @throws SecurityException if the caller is not in the owner application of {@code admin}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001155 */
Robin Lee25e26452015-06-02 09:56:29 -07001156 public void removeActiveAdmin(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001157 throwIfParentInstance("removeActiveAdmin");
Dianne Hackbornd6847842010-01-12 18:14:19 -08001158 if (mService != null) {
1159 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001160 mService.removeActiveAdmin(admin, myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001161 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001162 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001163 }
1164 }
1165 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001166
Dianne Hackbornd6847842010-01-12 18:14:19 -08001167 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001168 * Returns true if an administrator has been granted a particular device policy. This can be
1169 * used to check whether the administrator was activated under an earlier set of policies, but
1170 * requires additional policies after an upgrade.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001171 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001172 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be an
1173 * active administrator, or an exception will be thrown.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001174 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001175 * @throws SecurityException if {@code admin} is not an active administrator.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001176 */
Robin Lee25e26452015-06-02 09:56:29 -07001177 public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001178 throwIfParentInstance("hasGrantedPolicy");
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001179 if (mService != null) {
1180 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001181 return mService.hasGrantedPolicy(admin, usesPolicy, myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001182 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001183 throw e.rethrowFromSystemServer();
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001184 }
1185 }
1186 return false;
1187 }
1188
1189 /**
Clara Bayarria1771112015-12-18 16:29:18 +00001190 * Returns true if the Profile Challenge is available to use for the given profile user.
1191 *
1192 * @hide
1193 */
1194 public boolean isSeparateProfileChallengeAllowed(int userHandle) {
1195 if (mService != null) {
1196 try {
1197 return mService.isSeparateProfileChallengeAllowed(userHandle);
1198 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001199 throw e.rethrowFromSystemServer();
Clara Bayarria1771112015-12-18 16:29:18 +00001200 }
1201 }
1202 return false;
1203 }
1204
1205 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001206 * Constant for {@link #setPasswordQuality}: the policy has no requirements
1207 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001208 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001209 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001210 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001211
Dianne Hackbornd6847842010-01-12 18:14:19 -08001212 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -07001213 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
1214 * recognition technology. This implies technologies that can recognize the identity of
1215 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
1216 * Note that quality constants are ordered so that higher values are more restrictive.
1217 */
1218 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
1219
1220 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001221 * Constant for {@link #setPasswordQuality}: the policy requires some kind
Benjamin Franzc6a96532015-06-16 11:23:38 +01001222 * of password or pattern, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001223 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001224 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001225 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001226
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001227 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001228 * Constant for {@link #setPasswordQuality}: the user must have entered a
1229 * password containing at least numeric characters. Note that quality
1230 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001231 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001232 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001233
Dianne Hackbornd6847842010-01-12 18:14:19 -08001234 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001235 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -08001236 * password containing at least numeric characters with no repeating (4444)
1237 * or ordered (1234, 4321, 2468) sequences. Note that quality
1238 * constants are ordered so that higher values are more restrictive.
1239 */
1240 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
1241
1242 /**
1243 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001244 * password containing at least alphabetic (or other symbol) characters.
1245 * Note that quality constants are ordered so that higher values are more
1246 * restrictive.
1247 */
1248 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001249
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001250 /**
1251 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001252 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001253 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001254 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001255 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001256 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001257
Dianne Hackbornd6847842010-01-12 18:14:19 -08001258 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001259 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001260 * password containing at least a letter, a numerical digit and a special
1261 * symbol, by default. With this password quality, passwords can be
1262 * restricted to contain various sets of characters, like at least an
1263 * uppercase letter, etc. These are specified using various methods,
1264 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
1265 * that quality constants are ordered so that higher values are more
1266 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001267 */
1268 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
1269
1270 /**
Oleksandr Peletskyi0fdcd3d2016-01-13 16:49:56 +01001271 * Constant for {@link #setPasswordQuality}: the user is not allowed to
1272 * modify password. In case this password quality is set, the password is
1273 * managed by a profile owner. The profile owner can set any password,
1274 * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note
1275 * that quality constants are ordered so that higher values are more
1276 * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is
1277 * the highest.
1278 * @hide
1279 */
1280 public static final int PASSWORD_QUALITY_MANAGED = 0x80000;
1281
1282 /**
Makoto Onuki5e7e06702016-09-01 18:02:01 -07001283 * @hide
1284 *
1285 * adb shell dpm set-{device,profile}-owner will normally not allow installing an owner to
1286 * a user with accounts. {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED}
1287 * and {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} are the account features
1288 * used by authenticator to exempt their accounts from this:
1289 *
1290 * <ul>
1291 * <li>Non-test-only DO/PO still can't be installed when there are accounts.
1292 * <p>In order to make an apk test-only, add android:testOnly="true" to the
1293 * &lt;application&gt; tag in the manifest.
1294 *
1295 * <li>Test-only DO/PO can be installed even when there are accounts, as long as all the
1296 * accounts have the {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} feature.
1297 * Some authenticators claim to have any features, so to detect it, we also check
1298 * {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} and disallow installing
1299 * if any of the accounts have it.
1300 * </ul>
1301 */
1302 public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED =
1303 "android.account.DEVICE_OR_PROFILE_OWNER_ALLOWED";
1304
1305 /** @hide See {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} */
1306 public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED =
1307 "android.account.DEVICE_OR_PROFILE_OWNER_DISALLOWED";
1308
1309 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001310 * Called by an application that is administering the device to set the password restrictions it
1311 * is imposing. After setting this, the user will not be able to enter a new password that is
1312 * not at least as restrictive as what has been set. Note that the current password will remain
1313 * until the user has set a new one, so the change does not take place immediately. To prompt
1314 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
Esteban Talaverac1c83592016-02-17 17:56:15 +00001315 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after calling this method.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001316 * <p>
1317 * Quality constants are ordered so that higher values are more restrictive; thus the highest
1318 * requested quality constant (between the policy set here, the user's preference, and any other
1319 * considerations) is the one that is in effect.
1320 * <p>
1321 * The calling device admin must have requested
1322 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1323 * not, a security exception will be thrown.
1324 * <p>
1325 * This method can be called on the {@link DevicePolicyManager} instance returned by
1326 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1327 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001328 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001329 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001330 * @param quality The new desired quality. One of {@link #PASSWORD_QUALITY_UNSPECIFIED},
1331 * {@link #PASSWORD_QUALITY_SOMETHING}, {@link #PASSWORD_QUALITY_NUMERIC},
1332 * {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC},
1333 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} or {@link #PASSWORD_QUALITY_COMPLEX}.
1334 * @throws SecurityException if {@code admin} is not an active administrator or if {@code admin}
1335 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Dianne Hackbornd6847842010-01-12 18:14:19 -08001336 */
Robin Lee25e26452015-06-02 09:56:29 -07001337 public void setPasswordQuality(@NonNull ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001338 if (mService != null) {
1339 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001340 mService.setPasswordQuality(admin, quality, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001341 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001342 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001343 }
1344 }
1345 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001346
Dianne Hackbornd6847842010-01-12 18:14:19 -08001347 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001348 * Retrieve the current minimum password quality for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01001349 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00001350 * a separate challenge are not taken into account.
1351 *
1352 * <p>This method can be called on the {@link DevicePolicyManager} instance
1353 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1354 * restrictions on the parent profile.
1355 *
Robin Lee25e26452015-06-02 09:56:29 -07001356 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001357 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001358 */
Robin Lee25e26452015-06-02 09:56:29 -07001359 public int getPasswordQuality(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001360 return getPasswordQuality(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001361 }
1362
1363 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001364 public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001365 if (mService != null) {
1366 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001367 return mService.getPasswordQuality(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001368 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001369 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001370 }
1371 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001372 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001373 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001374
Dianne Hackbornd6847842010-01-12 18:14:19 -08001375 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001376 * Called by an application that is administering the device to set the minimum allowed password
1377 * length. After setting this, the user will not be able to enter a new password that is not at
1378 * least as restrictive as what has been set. Note that the current password will remain until
1379 * the user has set a new one, so the change does not take place immediately. To prompt the user
1380 * for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
1381 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
1382 * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC}
1383 * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC},
1384 * {@link #PASSWORD_QUALITY_ALPHANUMERIC}, or {@link #PASSWORD_QUALITY_COMPLEX} with
1385 * {@link #setPasswordQuality}.
1386 * <p>
1387 * The calling device admin must have requested
1388 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1389 * not, a security exception will be thrown.
1390 * <p>
1391 * This method can be called on the {@link DevicePolicyManager} instance returned by
1392 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1393 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001394 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001395 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001396 * @param length The new desired minimum password length. A value of 0 means there is no
1397 * restriction.
1398 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1399 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Dianne Hackbornd6847842010-01-12 18:14:19 -08001400 */
Robin Lee25e26452015-06-02 09:56:29 -07001401 public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001402 if (mService != null) {
1403 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001404 mService.setPasswordMinimumLength(admin, length, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001405 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001406 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001407 }
1408 }
1409 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001410
Dianne Hackbornd6847842010-01-12 18:14:19 -08001411 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001412 * Retrieve the current minimum password length for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01001413 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00001414 * a separate challenge are not taken into account.
1415 *
1416 * <p>This method can be called on the {@link DevicePolicyManager} instance
1417 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1418 * restrictions on the parent profile.
1419 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001420 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001421 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001422 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001423 */
Robin Lee25e26452015-06-02 09:56:29 -07001424 public int getPasswordMinimumLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001425 return getPasswordMinimumLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001426 }
1427
1428 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001429 public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001430 if (mService != null) {
1431 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001432 return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001433 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001434 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001435 }
1436 }
1437 return 0;
1438 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001439
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001440 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001441 * Called by an application that is administering the device to set the minimum number of upper
1442 * case letters required in the password. After setting this, the user will not be able to enter
1443 * a new password that is not at least as restrictive as what has been set. Note that the
1444 * current password will remain until the user has set a new one, so the change does not take
1445 * place immediately. To prompt the user for a new password, use
1446 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
1447 * setting this value. This constraint is only imposed if the administrator has also requested
1448 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001449 * <p>
1450 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001451 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1452 * not, a security exception will be thrown.
1453 * <p>
1454 * This method can be called on the {@link DevicePolicyManager} instance returned by
1455 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1456 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001457 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001458 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1459 * @param length The new desired minimum number of upper case letters required in the password.
1460 * A value of 0 means there is no restriction.
1461 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1462 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001463 */
Robin Lee25e26452015-06-02 09:56:29 -07001464 public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001465 if (mService != null) {
1466 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001467 mService.setPasswordMinimumUpperCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001468 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001469 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001470 }
1471 }
1472 }
1473
1474 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001475 * Retrieve the current number of upper case letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01001476 * for a particular admin or all admins that set restrictions on this user and
Esteban Talaverac1c83592016-02-17 17:56:15 +00001477 * its participating profiles. Restrictions on profiles that have a separate challenge
1478 * are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001479 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001480 * {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001481 * and only applies when the password quality is
1482 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001483 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001484 * <p>This method can be called on the {@link DevicePolicyManager} instance
1485 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1486 * restrictions on the parent profile.
1487 *
Robin Lee25e26452015-06-02 09:56:29 -07001488 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001489 * aggregate all admins.
1490 * @return The minimum number of upper case letters required in the
1491 * password.
1492 */
Robin Lee25e26452015-06-02 09:56:29 -07001493 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001494 return getPasswordMinimumUpperCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001495 }
1496
1497 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001498 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001499 if (mService != null) {
1500 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001501 return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001502 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001503 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001504 }
1505 }
1506 return 0;
1507 }
1508
1509 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001510 * Called by an application that is administering the device to set the minimum number of lower
1511 * case letters required in the password. After setting this, the user will not be able to enter
1512 * a new password that is not at least as restrictive as what has been set. Note that the
1513 * current password will remain until the user has set a new one, so the change does not take
1514 * place immediately. To prompt the user for a new password, use
1515 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
1516 * setting this value. This constraint is only imposed if the administrator has also requested
1517 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001518 * <p>
1519 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001520 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1521 * not, a security exception will be thrown.
1522 * <p>
1523 * This method can be called on the {@link DevicePolicyManager} instance returned by
1524 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1525 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001526 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001527 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1528 * @param length The new desired minimum number of lower case letters required in the password.
1529 * A value of 0 means there is no restriction.
1530 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1531 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001532 */
Robin Lee25e26452015-06-02 09:56:29 -07001533 public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001534 if (mService != null) {
1535 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001536 mService.setPasswordMinimumLowerCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001537 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001538 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001539 }
1540 }
1541 }
1542
1543 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001544 * Retrieve the current number of lower case letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01001545 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00001546 * and its participating profiles. Restrictions on profiles that have
1547 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001548 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001549 * {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001550 * and only applies when the password quality is
1551 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001552 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001553 * <p>This method can be called on the {@link DevicePolicyManager} instance
1554 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1555 * restrictions on the parent profile.
1556 *
Robin Lee25e26452015-06-02 09:56:29 -07001557 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001558 * aggregate all admins.
1559 * @return The minimum number of lower case letters required in the
1560 * password.
1561 */
Robin Lee25e26452015-06-02 09:56:29 -07001562 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001563 return getPasswordMinimumLowerCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001564 }
1565
1566 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001567 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001568 if (mService != null) {
1569 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001570 return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001571 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001572 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001573 }
1574 }
1575 return 0;
1576 }
1577
1578 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001579 * Called by an application that is administering the device to set the minimum number of
1580 * letters required in the password. After setting this, the user will not be able to enter a
1581 * new password that is not at least as restrictive as what has been set. Note that the current
1582 * password will remain until the user has set a new one, so the change does not take place
1583 * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
1584 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
1585 * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1586 * {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001587 * <p>
1588 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001589 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1590 * not, a security exception will be thrown.
1591 * <p>
1592 * This method can be called on the {@link DevicePolicyManager} instance returned by
1593 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1594 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001595 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001596 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1597 * @param length The new desired minimum number of letters required in the password. A value of
1598 * 0 means there is no restriction.
1599 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1600 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001601 */
Robin Lee25e26452015-06-02 09:56:29 -07001602 public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001603 if (mService != null) {
1604 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001605 mService.setPasswordMinimumLetters(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001606 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001607 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001608 }
1609 }
1610 }
1611
1612 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001613 * Retrieve the current number of letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01001614 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00001615 * and its participating profiles. Restrictions on profiles that have
1616 * a separate challenge are not taken into account.
1617 * This is the same value as set by
1618 * {@link #setPasswordMinimumLetters(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001619 * and only applies when the password quality is
1620 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001621 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001622 * <p>This method can be called on the {@link DevicePolicyManager} instance
1623 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1624 * restrictions on the parent profile.
1625 *
Robin Lee25e26452015-06-02 09:56:29 -07001626 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001627 * aggregate all admins.
1628 * @return The minimum number of letters required in the password.
1629 */
Robin Lee25e26452015-06-02 09:56:29 -07001630 public int getPasswordMinimumLetters(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001631 return getPasswordMinimumLetters(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001632 }
1633
1634 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001635 public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001636 if (mService != null) {
1637 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001638 return mService.getPasswordMinimumLetters(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001639 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001640 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001641 }
1642 }
1643 return 0;
1644 }
1645
1646 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001647 * Called by an application that is administering the device to set the minimum number of
1648 * numerical digits required in the password. After setting this, the user will not be able to
1649 * enter a new password that is not at least as restrictive as what has been set. Note that the
1650 * current password will remain until the user has set a new one, so the change does not take
1651 * place immediately. To prompt the user for a new password, use
1652 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
1653 * setting this value. This constraint is only imposed if the administrator has also requested
1654 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001655 * <p>
1656 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001657 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1658 * not, a security exception will be thrown.
1659 * <p>
1660 * This method can be called on the {@link DevicePolicyManager} instance returned by
1661 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1662 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001663 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001664 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1665 * @param length The new desired minimum number of numerical digits required in the password. A
1666 * value of 0 means there is no restriction.
1667 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1668 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001669 */
Robin Lee25e26452015-06-02 09:56:29 -07001670 public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001671 if (mService != null) {
1672 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001673 mService.setPasswordMinimumNumeric(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001674 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001675 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001676 }
1677 }
1678 }
1679
1680 /**
1681 * Retrieve the current number of numerical digits required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01001682 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00001683 * and its participating profiles. Restrictions on profiles that have
1684 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001685 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001686 * {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001687 * and only applies when the password quality is
1688 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001689 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001690 * <p>This method can be called on the {@link DevicePolicyManager} instance
1691 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1692 * restrictions on the parent profile.
1693 *
Robin Lee25e26452015-06-02 09:56:29 -07001694 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001695 * aggregate all admins.
1696 * @return The minimum number of numerical digits required in the password.
1697 */
Robin Lee25e26452015-06-02 09:56:29 -07001698 public int getPasswordMinimumNumeric(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001699 return getPasswordMinimumNumeric(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001700 }
1701
1702 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001703 public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001704 if (mService != null) {
1705 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001706 return mService.getPasswordMinimumNumeric(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001707 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001708 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001709 }
1710 }
1711 return 0;
1712 }
1713
1714 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001715 * Called by an application that is administering the device to set the minimum number of
1716 * symbols required in the password. After setting this, the user will not be able to enter a
1717 * new password that is not at least as restrictive as what has been set. Note that the current
1718 * password will remain until the user has set a new one, so the change does not take place
1719 * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
1720 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
1721 * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1722 * {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001723 * <p>
1724 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001725 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1726 * not, a security exception will be thrown.
1727 * <p>
1728 * This method can be called on the {@link DevicePolicyManager} instance returned by
1729 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1730 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001731 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001732 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1733 * @param length The new desired minimum number of symbols required in the password. A value of
1734 * 0 means there is no restriction.
1735 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1736 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001737 */
Robin Lee25e26452015-06-02 09:56:29 -07001738 public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001739 if (mService != null) {
1740 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001741 mService.setPasswordMinimumSymbols(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001742 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001743 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001744 }
1745 }
1746 }
1747
1748 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001749 * Retrieve the current number of symbols required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01001750 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00001751 * and its participating profiles. Restrictions on profiles that have
1752 * a separate challenge are not taken into account. This is the same value as
1753 * set by {@link #setPasswordMinimumSymbols(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001754 * and only applies when the password quality is
1755 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001756 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001757 * <p>This method can be called on the {@link DevicePolicyManager} instance
1758 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1759 * restrictions on the parent profile.
1760 *
Robin Lee25e26452015-06-02 09:56:29 -07001761 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001762 * aggregate all admins.
1763 * @return The minimum number of symbols required in the password.
1764 */
Robin Lee25e26452015-06-02 09:56:29 -07001765 public int getPasswordMinimumSymbols(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001766 return getPasswordMinimumSymbols(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001767 }
1768
1769 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001770 public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001771 if (mService != null) {
1772 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001773 return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001774 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001775 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001776 }
1777 }
1778 return 0;
1779 }
1780
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001781 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001782 * Called by an application that is administering the device to set the minimum number of
1783 * non-letter characters (numerical digits or symbols) required in the password. After setting
1784 * this, the user will not be able to enter a new password that is not at least as restrictive
1785 * as what has been set. Note that the current password will remain until the user has set a new
1786 * one, so the change does not take place immediately. To prompt the user for a new password,
1787 * use {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
1788 * setting this value. This constraint is only imposed if the administrator has also requested
1789 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001790 * <p>
1791 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001792 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1793 * not, a security exception will be thrown.
1794 * <p>
1795 * This method can be called on the {@link DevicePolicyManager} instance returned by
1796 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1797 * profile.
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001798 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001799 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1800 * @param length The new desired minimum number of letters required in the password. A value of
1801 * 0 means there is no restriction.
1802 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1803 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001804 */
Robin Lee25e26452015-06-02 09:56:29 -07001805 public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001806 if (mService != null) {
1807 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001808 mService.setPasswordMinimumNonLetter(admin, length, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001809 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001810 throw e.rethrowFromSystemServer();
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001811 }
1812 }
1813 }
1814
1815 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001816 * Retrieve the current number of non-letter characters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01001817 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00001818 * and its participating profiles. Restrictions on profiles that have
1819 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001820 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001821 * {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001822 * and only applies when the password quality is
1823 * {@link #PASSWORD_QUALITY_COMPLEX}.
1824 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001825 * <p>This method can be called on the {@link DevicePolicyManager} instance
1826 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1827 * restrictions on the parent profile.
1828 *
Robin Lee25e26452015-06-02 09:56:29 -07001829 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001830 * aggregate all admins.
1831 * @return The minimum number of letters required in the password.
1832 */
Robin Lee25e26452015-06-02 09:56:29 -07001833 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001834 return getPasswordMinimumNonLetter(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001835 }
1836
1837 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001838 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001839 if (mService != null) {
1840 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001841 return mService.getPasswordMinimumNonLetter(admin, userHandle, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001842 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001843 throw e.rethrowFromSystemServer();
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001844 }
1845 }
1846 return 0;
1847 }
1848
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001849 /**
1850 * Called by an application that is administering the device to set the length of the password
1851 * history. After setting this, the user will not be able to enter a new password that is the
1852 * same as any password in the history. Note that the current password will remain until the
1853 * user has set a new one, so the change does not take place immediately. To prompt the user for
1854 * a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
1855 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
1856 * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC}
1857 * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX} {@link #PASSWORD_QUALITY_ALPHABETIC}, or
1858 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} with {@link #setPasswordQuality}.
1859 * <p>
1860 * The calling device admin must have requested
1861 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1862 * not, a security exception will be thrown.
1863 * <p>
1864 * This method can be called on the {@link DevicePolicyManager} instance returned by
1865 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1866 * profile.
1867 *
1868 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1869 * @param length The new desired length of password history. A value of 0 means there is no
1870 * restriction.
1871 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1872 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
1873 */
Robin Lee25e26452015-06-02 09:56:29 -07001874 public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001875 if (mService != null) {
1876 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001877 mService.setPasswordHistoryLength(admin, length, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001878 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001879 throw e.rethrowFromSystemServer();
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001880 }
1881 }
1882 }
1883
1884 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001885 * Called by a device admin to set the password expiration timeout. Calling this method will
1886 * restart the countdown for password expiration for the given admin, as will changing the
1887 * device password (for all admins).
1888 * <p>
1889 * The provided timeout is the time delta in ms and will be added to the current time. For
1890 * example, to have the password expire 5 days from now, timeout would be 5 * 86400 * 1000 =
1891 * 432000000 ms for timeout.
1892 * <p>
1893 * To disable password expiration, a value of 0 may be used for timeout.
1894 * <p>
1895 * The calling device admin must have requested
1896 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this method; if it has
1897 * not, a security exception will be thrown.
1898 * <p>
1899 * Note that setting the password will automatically reset the expiration time for all active
1900 * admins. Active admins do not need to explicitly call this method in that case.
1901 * <p>
1902 * This method can be called on the {@link DevicePolicyManager} instance returned by
1903 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1904 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001905 *
Jim Millera4e28d12010-11-08 16:15:47 -08001906 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001907 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0 means
1908 * there is no restriction (unlimited).
1909 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1910 * does not use {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD}
Jim Millera4e28d12010-11-08 16:15:47 -08001911 */
Robin Lee25e26452015-06-02 09:56:29 -07001912 public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) {
Jim Millera4e28d12010-11-08 16:15:47 -08001913 if (mService != null) {
1914 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001915 mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08001916 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001917 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08001918 }
1919 }
1920 }
1921
1922 /**
Jim Miller6b857682011-02-16 16:27:41 -08001923 * Get the password expiration timeout for the given admin. The expiration timeout is the
1924 * recurring expiration timeout provided in the call to
1925 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
Esteban Talaverac1c83592016-02-17 17:56:15 +00001926 * aggregate of all participating policy administrators if {@code admin} is null. Admins that
1927 * have set restrictions on profiles that have a separate challenge are not taken into account.
1928 *
1929 * <p>This method can be called on the {@link DevicePolicyManager} instance
1930 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1931 * restrictions on the parent profile.
Jim Millera4e28d12010-11-08 16:15:47 -08001932 *
Robin Lee25e26452015-06-02 09:56:29 -07001933 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001934 * @return The timeout for the given admin or the minimum of all timeouts
1935 */
Robin Lee25e26452015-06-02 09:56:29 -07001936 public long getPasswordExpirationTimeout(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001937 if (mService != null) {
1938 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001939 return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08001940 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001941 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08001942 }
1943 }
1944 return 0;
1945 }
1946
1947 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001948 * Get the current password expiration time for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01001949 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00001950 * a separate challenge are not taken into account. If admin is {@code null}, then a composite
1951 * of all expiration times is returned - which will be the minimum of all of them.
1952 *
1953 * <p>This method can be called on the {@link DevicePolicyManager} instance
1954 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1955 * the password expiration for the parent profile.
Jim Millera4e28d12010-11-08 16:15:47 -08001956 *
Robin Lee25e26452015-06-02 09:56:29 -07001957 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001958 * @return The password expiration time, in milliseconds since epoch.
Jim Millera4e28d12010-11-08 16:15:47 -08001959 */
Robin Lee25e26452015-06-02 09:56:29 -07001960 public long getPasswordExpiration(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001961 if (mService != null) {
1962 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001963 return mService.getPasswordExpiration(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08001964 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001965 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08001966 }
1967 }
1968 return 0;
1969 }
1970
1971 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001972 * Retrieve the current password history length for a particular admin or all admins that
Rubin Xud3609d42016-07-13 18:32:57 +01001973 * set restrictions on this user and its participating profiles. Restrictions on profiles that
Esteban Talaverac1c83592016-02-17 17:56:15 +00001974 * have a separate challenge are not taken into account.
1975 *
1976 * <p>This method can be called on the {@link DevicePolicyManager} instance
1977 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1978 * restrictions on the parent profile.
1979 *
Robin Lee25e26452015-06-02 09:56:29 -07001980 * @param admin The name of the admin component to check, or {@code null} to aggregate
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001981 * all admins.
1982 * @return The length of the password history
1983 */
Robin Lee25e26452015-06-02 09:56:29 -07001984 public int getPasswordHistoryLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001985 return getPasswordHistoryLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001986 }
1987
1988 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001989 public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001990 if (mService != null) {
1991 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001992 return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001993 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001994 throw e.rethrowFromSystemServer();
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001995 }
1996 }
1997 return 0;
1998 }
1999
Dianne Hackbornd6847842010-01-12 18:14:19 -08002000 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08002001 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08002002 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08002003 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08002004 * @return Returns the maximum length that the user can enter.
2005 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08002006 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08002007 // Kind-of arbitrary.
2008 return 16;
2009 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002010
Dianne Hackborn254cb442010-01-27 19:23:59 -08002011 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002012 * Determine whether the current password the user has set is sufficient to meet the policy
2013 * requirements (e.g. quality, minimum length) that have been requested by the admins of this
2014 * user and its participating profiles. Restrictions on profiles that have a separate challenge
2015 * are not taken into account.
2016 * <p>
2017 * The calling device admin must have requested
2018 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2019 * not, a security exception will be thrown.
2020 * <p>
2021 * This method can be called on the {@link DevicePolicyManager} instance returned by
2022 * {@link #getParentProfileInstance(ComponentName)} in order to determine if the password set on
2023 * the parent profile is sufficient.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002024 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01002025 * @return Returns true if the password meets the current requirements, else false.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002026 * @throws SecurityException if the calling application does not own an active administrator
2027 * that uses {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002028 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002029 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002030 if (mService != null) {
2031 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00002032 return mService.isActivePasswordSufficient(myUserId(), mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002033 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002034 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002035 }
2036 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002037 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08002038 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002039
Dianne Hackbornd6847842010-01-12 18:14:19 -08002040 /**
Clara Bayarrid7693912016-01-22 17:26:31 +00002041 * Determine whether the current profile password the user has set is sufficient
Esteban Talaverac1c83592016-02-17 17:56:15 +00002042 * to meet the policy requirements (e.g. quality, minimum length) that have been
Clara Bayarrid7693912016-01-22 17:26:31 +00002043 * requested by the admins of the parent user and its profiles.
2044 *
2045 * @param userHandle the userId of the profile to check the password for.
2046 * @return Returns true if the password would meet the current requirements, else false.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002047 * @throws SecurityException if {@code userHandle} is not a managed profile.
Clara Bayarrid7693912016-01-22 17:26:31 +00002048 * @hide
2049 */
2050 public boolean isProfileActivePasswordSufficientForParent(int userHandle) {
2051 if (mService != null) {
2052 try {
2053 return mService.isProfileActivePasswordSufficientForParent(userHandle);
2054 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002055 throw e.rethrowFromSystemServer();
Clara Bayarrid7693912016-01-22 17:26:31 +00002056 }
2057 }
2058 return false;
2059 }
2060
2061 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002062 * Retrieve the number of times the user has failed at entering a password since that last
2063 * successful password entry.
2064 * <p>
2065 * This method can be called on the {@link DevicePolicyManager} instance returned by
2066 * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the number of failed
2067 * password attemts for the parent user.
2068 * <p>
2069 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN}
2070 * to be able to call this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002071 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002072 * @return The number of times user has entered an incorrect password since the last correct
2073 * password entry.
2074 * @throws SecurityException if the calling application does not own an active administrator
2075 * that uses {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002076 */
2077 public int getCurrentFailedPasswordAttempts() {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00002078 return getCurrentFailedPasswordAttempts(myUserId());
2079 }
2080
2081 /**
2082 * Retrieve the number of times the given user has failed at entering a
2083 * password since that last successful password entry.
2084 *
2085 * <p>The calling device admin must have requested
2086 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call this method; if it has
2087 * not and it is not the system uid, a security exception will be thrown.
2088 *
2089 * @hide
2090 */
2091 public int getCurrentFailedPasswordAttempts(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002092 if (mService != null) {
2093 try {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00002094 return mService.getCurrentFailedPasswordAttempts(userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002095 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002096 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002097 }
2098 }
2099 return -1;
2100 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002101
2102 /**
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002103 * Queries whether {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002104 *
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002105 * @return true if RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002106 * @hide
2107 */
2108 public boolean getDoNotAskCredentialsOnBoot() {
2109 if (mService != null) {
2110 try {
2111 return mService.getDoNotAskCredentialsOnBoot();
2112 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002113 throw e.rethrowFromSystemServer();
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002114 }
2115 }
2116 return false;
2117 }
2118
2119 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002120 * Setting this to a value greater than zero enables a built-in policy that will perform a
2121 * device or profile wipe after too many incorrect device-unlock passwords have been entered.
2122 * This built-in policy combines watching for failed passwords and wiping the device, and
2123 * requires that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002124 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002125 * <p>
2126 * To implement any other policy (e.g. wiping data for a particular application only, erasing or
2127 * revoking credentials, or reporting the failure to a server), you should implement
2128 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} instead. Do not
2129 * use this API, because if the maximum count is reached, the device or profile will be wiped
2130 * immediately, and your callback will not be invoked.
2131 * <p>
2132 * This method can be called on the {@link DevicePolicyManager} instance returned by
2133 * {@link #getParentProfileInstance(ComponentName)} in order to set a value on the parent
2134 * profile.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002135 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002136 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002137 * @param num The number of failed password attempts at which point the device or profile will
2138 * be wiped.
2139 * @throws SecurityException if {@code admin} is not an active administrator or does not use
2140 * both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
2141 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002142 */
Robin Lee25e26452015-06-02 09:56:29 -07002143 public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002144 if (mService != null) {
2145 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002146 mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002147 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002148 throw e.rethrowFromSystemServer();
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002149 }
2150 }
2151 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002152
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002153 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002154 * Retrieve the current maximum number of login attempts that are allowed before the device
Rubin Xud3609d42016-07-13 18:32:57 +01002155 * or profile is wiped, for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002156 * and its participating profiles. Restrictions on profiles that have a separate challenge are
2157 * not taken into account.
2158 *
2159 * <p>This method can be called on the {@link DevicePolicyManager} instance
2160 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2161 * the value for the parent profile.
2162 *
Robin Lee25e26452015-06-02 09:56:29 -07002163 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002164 * all admins.
2165 */
Robin Lee25e26452015-06-02 09:56:29 -07002166 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002167 return getMaximumFailedPasswordsForWipe(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002168 }
2169
2170 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002171 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08002172 if (mService != null) {
2173 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002174 return mService.getMaximumFailedPasswordsForWipe(
2175 admin, userHandle, mParentInstance);
Dianne Hackborn254cb442010-01-27 19:23:59 -08002176 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002177 throw e.rethrowFromSystemServer();
Dianne Hackborn254cb442010-01-27 19:23:59 -08002178 }
2179 }
2180 return 0;
2181 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002182
Dianne Hackborn254cb442010-01-27 19:23:59 -08002183 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002184 * Returns the profile with the smallest maximum failed passwords for wipe,
2185 * for the given user. So for primary user, it might return the primary or
2186 * a managed profile. For a secondary user, it would be the same as the
2187 * user passed in.
2188 * @hide Used only by Keyguard
2189 */
2190 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
2191 if (mService != null) {
2192 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002193 return mService.getProfileWithMinimumFailedPasswordsForWipe(
2194 userHandle, mParentInstance);
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002195 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002196 throw e.rethrowFromSystemServer();
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002197 }
2198 }
2199 return UserHandle.USER_NULL;
2200 }
2201
2202 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002203 * Flag for {@link #resetPassword}: don't allow other admins to change
2204 * the password again until the user has entered it.
2205 */
2206 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002207
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002208 /**
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002209 * Flag for {@link #resetPassword}: don't ask for user credentials on device boot.
2210 * If the flag is set, the device can be booted without asking for user password.
2211 * The absence of this flag does not change the current boot requirements. This flag
2212 * can be set by the device owner only. If the app is not the device owner, the flag
2213 * is ignored. Once the flag is set, it cannot be reverted back without resetting the
2214 * device to factory defaults.
2215 */
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002216 public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002;
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002217
2218 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002219 * Force a new device unlock password (the password needed to access the entire device, not for
2220 * individual accounts) on the user. This takes effect immediately.
2221 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002222 * <em>Note: This API has been limited as of {@link android.os.Build.VERSION_CODES#N} for
Makoto Onuki70f929e2015-11-11 12:40:15 -08002223 * device admins that are not device owner and not profile owner.
2224 * The password can now only be changed if there is currently no password set. Device owner
Ricky Wai977ade22016-05-24 15:02:41 +01002225 * and profile owner can still do this when user is unlocked and does not have a managed
2226 * profile.</em>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002227 * <p>
2228 * The given password must be sufficient for the current password quality and length constraints
2229 * as returned by {@link #getPasswordQuality(ComponentName)} and
2230 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then
2231 * it will be rejected and false returned. Note that the password may be a stronger quality
2232 * (containing alphanumeric characters when the requested quality is only numeric), in which
2233 * case the currently active quality will be increased to match.
2234 * <p>
2235 * Calling with a null or empty password will clear any existing PIN, pattern or password if the
Robin Leece5c4002016-03-23 17:05:03 +00002236 * current password constraints allow it. <em>Note: This will not work in
2237 * {@link android.os.Build.VERSION_CODES#N} and later for managed profiles, or for device admins
2238 * that are not device owner or profile owner. Once set, the password cannot be changed to null
2239 * or empty except by these admins.</em>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002240 * <p>
2241 * The calling device admin must have requested
2242 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call this method; if it has
2243 * not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002244 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01002245 * @param password The new password for the user. Null or empty clears the password.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002246 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002247 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
2248 * @return Returns true if the password was applied, or false if it is not acceptable for the
2249 * current constraints or if the user has not been decrypted yet.
2250 * @throws SecurityException if the calling application does not own an active administrator
2251 * that uses {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD}
Ricky Wai977ade22016-05-24 15:02:41 +01002252 * @throws IllegalStateException if the calling user is locked or has a managed profile.
Andrew Scull3f81f4e2016-07-29 16:29:58 +01002253 * @throws IllegalArgumentException if the password does not meet system requirements.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002254 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002255 public boolean resetPassword(String password, int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002256 throwIfParentInstance("resetPassword");
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002257 if (mService != null) {
2258 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002259 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002260 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002261 throw e.rethrowFromSystemServer();
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002262 }
2263 }
2264 return false;
2265 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002266
Dianne Hackbornd6847842010-01-12 18:14:19 -08002267 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002268 * Called by an application that is administering the device to set the maximum time for user
2269 * activity until the device will lock. This limits the length that the user can set. It takes
2270 * effect immediately.
2271 * <p>
2272 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
2273 * to be able to call this method; if it has not, a security exception will be thrown.
2274 * <p>
2275 * This method can be called on the {@link DevicePolicyManager} instance returned by
2276 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2277 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002278 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002279 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002280 * @param timeMs The new desired maximum time to lock in milliseconds. A value of 0 means there
2281 * is no restriction.
2282 * @throws SecurityException if {@code admin} is not an active administrator or it does not use
2283 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002284 */
Robin Lee25e26452015-06-02 09:56:29 -07002285 public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002286 if (mService != null) {
2287 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002288 mService.setMaximumTimeToLock(admin, timeMs, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002289 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002290 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002291 }
2292 }
2293 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002294
Dianne Hackbornd6847842010-01-12 18:14:19 -08002295 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002296 * Retrieve the current maximum time to unlock for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01002297 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00002298 * a separate challenge are not taken into account.
2299 *
2300 * <p>This method can be called on the {@link DevicePolicyManager} instance
2301 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2302 * restrictions on the parent profile.
2303 *
Robin Lee25e26452015-06-02 09:56:29 -07002304 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002305 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07002306 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07002307 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002308 */
Robin Lee25e26452015-06-02 09:56:29 -07002309 public long getMaximumTimeToLock(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002310 return getMaximumTimeToLock(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002311 }
2312
2313 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002314 public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002315 if (mService != null) {
2316 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002317 return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002318 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002319 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002320 }
2321 }
2322 return 0;
2323 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002324
Dianne Hackbornd6847842010-01-12 18:14:19 -08002325 /**
Ricky Wai035e9242016-03-18 16:43:31 +00002326 * Returns maximum time to lock that applied by all profiles in this user. We do this because we
2327 * do not have a separate timeout to lock for work challenge only.
2328 *
2329 * @hide
2330 */
2331 public long getMaximumTimeToLockForUserAndProfiles(int userHandle) {
2332 if (mService != null) {
2333 try {
2334 return mService.getMaximumTimeToLockForUserAndProfiles(userHandle);
2335 } catch (RemoteException e) {
2336 throw e.rethrowFromSystemServer();
2337 }
2338 }
2339 return 0;
2340 }
2341
2342 /**
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002343 * Called by a device/profile owner to set the timeout after which unlocking with secondary, non
2344 * strong auth (e.g. fingerprint, trust agents) times out, i.e. the user has to use a strong
2345 * authentication method like password, pin or pattern.
2346 *
2347 * <p>This timeout is used internally to reset the timer to require strong auth again after
2348 * specified timeout each time it has been successfully used.
2349 *
2350 * <p>Fingerprint can also be disabled altogether using {@link #KEYGUARD_DISABLE_FINGERPRINT}.
2351 *
2352 * <p>Trust agents can also be disabled altogether using {@link #KEYGUARD_DISABLE_TRUST_AGENTS}.
2353 *
2354 * <p>The calling device admin must be a device or profile owner. If it is not,
2355 * a {@link SecurityException} will be thrown.
2356 *
Michal Karpinski943aabd2016-10-06 11:09:25 +01002357 * <p>The calling device admin can verify the value it has set by calling
2358 * {@link #getRequiredStrongAuthTimeout(ComponentName)} and passing in its instance.
2359 *
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002360 * <p>This method can be called on the {@link DevicePolicyManager} instance returned by
2361 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2362 * profile.
2363 *
2364 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2365 * @param timeoutMs The new timeout, after which the user will have to unlock with strong
Michal Karpinski943aabd2016-10-06 11:09:25 +01002366 * authentication method. A value of 0 means the admin is not participating in
2367 * controlling the timeout.
2368 * The minimum and maximum timeouts are platform-defined and are typically 1 hour and
2369 * 72 hours, respectively. Though discouraged, the admin may choose to require strong
2370 * auth at all times using {@link #KEYGUARD_DISABLE_FINGERPRINT} and/or
2371 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002372 *
2373 * @throws SecurityException if {@code admin} is not a device or profile owner.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002374 *
2375 * @hide
2376 */
2377 public void setRequiredStrongAuthTimeout(@NonNull ComponentName admin,
2378 long timeoutMs) {
2379 if (mService != null) {
2380 try {
2381 mService.setRequiredStrongAuthTimeout(admin, timeoutMs, mParentInstance);
2382 } catch (RemoteException e) {
2383 throw e.rethrowFromSystemServer();
2384 }
2385 }
2386 }
2387
2388 /**
2389 * Determine for how long the user will be able to use secondary, non strong auth for
2390 * authentication, since last strong method authentication (password, pin or pattern) was used.
2391 * After the returned timeout the user is required to use strong authentication method.
2392 *
2393 * <p>This method can be called on the {@link DevicePolicyManager} instance
2394 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2395 * restrictions on the parent profile.
2396 *
2397 * @param admin The name of the admin component to check, or {@code null} to aggregate
2398 * accross all participating admins.
Michal Karpinski943aabd2016-10-06 11:09:25 +01002399 * @return The timeout or 0 if not configured for the provided admin.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002400 *
2401 * @hide
2402 */
2403 public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin) {
2404 return getRequiredStrongAuthTimeout(admin, myUserId());
2405 }
2406
2407 /** @hide per-user version */
2408 public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin, @UserIdInt int userId) {
2409 if (mService != null) {
2410 try {
2411 return mService.getRequiredStrongAuthTimeout(admin, userId, mParentInstance);
2412 } catch (RemoteException e) {
2413 throw e.rethrowFromSystemServer();
2414 }
2415 }
2416 return DEFAULT_STRONG_AUTH_TIMEOUT_MS;
2417 }
2418
2419 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002420 * Make the device lock immediately, as if the lock screen timeout has expired at the point of
2421 * this call.
2422 * <p>
2423 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
2424 * to be able to call this method; if it has not, a security exception will be thrown.
2425 * <p>
2426 * This method can be called on the {@link DevicePolicyManager} instance returned by
2427 * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002428 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002429 * @throws SecurityException if the calling application does not own an active administrator
2430 * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002431 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002432 public void lockNow() {
2433 if (mService != null) {
2434 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002435 mService.lockNow(mParentInstance);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002436 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002437 throw e.rethrowFromSystemServer();
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002438 }
2439 }
2440 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002441
Dianne Hackbornd6847842010-01-12 18:14:19 -08002442 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07002443 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002444 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07002445 */
2446 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
2447
2448 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002449 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
2450 * data.
2451 *
Paul Crowley2934b262014-12-02 11:21:13 +00002452 * <p>This flag may only be set by device owner admins; if it is set by
2453 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002454 */
2455 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
2456
2457 /**
Suprabh Shukla556b05a2016-08-10 15:49:24 -07002458 * Ask that all user data be wiped. If called as a secondary user, the user will be removed and
2459 * other users will remain unaffected. Calling from the primary user will cause the device to
2460 * reboot, erasing all device data - including all the secondary users and their data - while
2461 * booting up.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002462 * <p>
2463 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to
2464 * be able to call this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002465 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002466 * @param flags Bit mask of additional options: currently supported flags are
2467 * {@link #WIPE_EXTERNAL_STORAGE} and {@link #WIPE_RESET_PROTECTION_DATA}.
2468 * @throws SecurityException if the calling application does not own an active administrator
2469 * that uses {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002470 */
2471 public void wipeData(int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002472 throwIfParentInstance("wipeData");
Dianne Hackbornd6847842010-01-12 18:14:19 -08002473 if (mService != null) {
2474 try {
Makoto Onuki70f929e2015-11-11 12:40:15 -08002475 mService.wipeData(flags);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002476 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002477 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002478 }
2479 }
2480 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002481
Dianne Hackbornd6847842010-01-12 18:14:19 -08002482 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07002483 * Called by an application that is administering the device to set the
2484 * global proxy and exclusion list.
2485 * <p>
2486 * The calling device admin must have requested
2487 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
2488 * this method; if it has not, a security exception will be thrown.
2489 * Only the first device admin can set the proxy. If a second admin attempts
2490 * to set the proxy, the {@link ComponentName} of the admin originally setting the
Robin Lee25e26452015-06-02 09:56:29 -07002491 * proxy will be returned. If successful in setting the proxy, {@code null} will
Oscar Montemayor69238c62010-08-03 10:51:06 -07002492 * be returned.
2493 * The method can be called repeatedly by the device admin alrady setting the
2494 * proxy to update the proxy and exclusion list.
2495 *
Robin Lee25e26452015-06-02 09:56:29 -07002496 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Oscar Montemayor69238c62010-08-03 10:51:06 -07002497 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
2498 * Pass Proxy.NO_PROXY to reset the proxy.
2499 * @param exclusionList a list of domains to be excluded from the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07002500 * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName}
2501 * of the device admin that sets the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08002502 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07002503 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07002504 public @Nullable ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec,
Oscar Montemayor69238c62010-08-03 10:51:06 -07002505 List<String> exclusionList ) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002506 throwIfParentInstance("setGlobalProxy");
Oscar Montemayor69238c62010-08-03 10:51:06 -07002507 if (proxySpec == null) {
2508 throw new NullPointerException();
2509 }
2510 if (mService != null) {
2511 try {
2512 String hostSpec;
2513 String exclSpec;
2514 if (proxySpec.equals(Proxy.NO_PROXY)) {
2515 hostSpec = null;
2516 exclSpec = null;
2517 } else {
2518 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
2519 throw new IllegalArgumentException();
2520 }
2521 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
2522 String hostName = sa.getHostName();
2523 int port = sa.getPort();
2524 StringBuilder hostBuilder = new StringBuilder();
2525 hostSpec = hostBuilder.append(hostName)
2526 .append(":").append(Integer.toString(port)).toString();
2527 if (exclusionList == null) {
2528 exclSpec = "";
2529 } else {
2530 StringBuilder listBuilder = new StringBuilder();
2531 boolean firstDomain = true;
2532 for (String exclDomain : exclusionList) {
2533 if (!firstDomain) {
2534 listBuilder = listBuilder.append(",");
2535 } else {
2536 firstDomain = false;
2537 }
2538 listBuilder = listBuilder.append(exclDomain.trim());
2539 }
2540 exclSpec = listBuilder.toString();
2541 }
Yuhao Zheng90704842014-02-28 17:22:45 -08002542 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
2543 != android.net.Proxy.PROXY_VALID)
2544 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07002545 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002546 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07002547 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002548 throw e.rethrowFromSystemServer();
Oscar Montemayor69238c62010-08-03 10:51:06 -07002549 }
2550 }
2551 return null;
2552 }
2553
2554 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002555 * Set a network-independent global HTTP proxy. This is not normally what you want for typical
2556 * HTTP proxies - they are generally network dependent. However if you're doing something
2557 * unusual like general internal filtering this may be useful. On a private network where the
2558 * proxy is not accessible, you may break HTTP using this.
2559 * <p>
2560 * This method requires the caller to be the device owner.
2561 * <p>
2562 * This proxy is only a recommendation and it is possible that some apps will ignore it.
Jason Monk03bc9912014-05-13 09:44:57 -04002563 *
Jason Monk03bc9912014-05-13 09:44:57 -04002564 * @see ProxyInfo
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002565 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2566 * @param proxyInfo The a {@link ProxyInfo} object defining the new global HTTP proxy. A
2567 * {@code null} value will clear the global HTTP proxy.
2568 * @throws SecurityException if {@code admin} is not the device owner.
Jason Monk03bc9912014-05-13 09:44:57 -04002569 */
Robin Lee25e26452015-06-02 09:56:29 -07002570 public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo
2571 proxyInfo) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002572 throwIfParentInstance("setRecommendedGlobalProxy");
Jason Monk03bc9912014-05-13 09:44:57 -04002573 if (mService != null) {
2574 try {
2575 mService.setRecommendedGlobalProxy(admin, proxyInfo);
2576 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002577 throw e.rethrowFromSystemServer();
Jason Monk03bc9912014-05-13 09:44:57 -04002578 }
2579 }
2580 }
2581
2582 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07002583 * Returns the component name setting the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07002584 * @return ComponentName object of the device admin that set the global proxy, or {@code null}
2585 * if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08002586 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07002587 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07002588 public @Nullable ComponentName getGlobalProxyAdmin() {
Oscar Montemayor69238c62010-08-03 10:51:06 -07002589 if (mService != null) {
2590 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002591 return mService.getGlobalProxyAdmin(myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07002592 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002593 throw e.rethrowFromSystemServer();
Oscar Montemayor69238c62010-08-03 10:51:06 -07002594 }
2595 }
2596 return null;
2597 }
2598
2599 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002600 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002601 * indicating that encryption is not supported.
2602 */
2603 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
2604
2605 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002606 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002607 * indicating that encryption is supported, but is not currently active.
2608 */
2609 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
2610
2611 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002612 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002613 * indicating that encryption is not currently active, but is currently
2614 * being activated. This is only reported by devices that support
2615 * encryption of data and only when the storage is currently
2616 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
2617 * to become encrypted will never return this value.
2618 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002619 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002620
2621 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002622 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002623 * indicating that encryption is active.
Amith Yamasani75db1252016-07-11 14:41:01 -07002624 * <p>
2625 * Also see {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002626 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002627 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002628
2629 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002630 * Result code for {@link #getStorageEncryptionStatus}:
2631 * indicating that encryption is active, but an encryption key has not
2632 * been set by the user.
2633 */
2634 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
2635
2636 /**
Makoto Onukid4c9e542016-02-25 18:17:30 -08002637 * Result code for {@link #getStorageEncryptionStatus}:
Amith Yamasani75db1252016-07-11 14:41:01 -07002638 * indicating that encryption is active and the encryption key is tied to the user or profile.
2639 * <p>
2640 * This value is only returned to apps targeting API level 24 and above. For apps targeting
2641 * earlier API levels, {@link #ENCRYPTION_STATUS_ACTIVE} is returned, even if the
2642 * encryption key is specific to the user or profile.
Makoto Onukid4c9e542016-02-25 18:17:30 -08002643 */
2644 public static final int ENCRYPTION_STATUS_ACTIVE_PER_USER = 5;
2645
2646 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002647 * Activity action: begin the process of encrypting data on the device. This activity should
2648 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
2649 * After resuming from this activity, use {@link #getStorageEncryption}
2650 * to check encryption status. However, on some devices this activity may never return, as
2651 * it may trigger a reboot and in some cases a complete data wipe of the device.
2652 */
2653 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
2654 public static final String ACTION_START_ENCRYPTION
2655 = "android.app.action.START_ENCRYPTION";
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002656 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07002657 * Widgets are enabled in keyguard
2658 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002659 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07002660
2661 /**
Jim Miller50e62182014-04-23 17:25:00 -07002662 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07002663 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002664 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
2665
2666 /**
2667 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
2668 */
2669 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
2670
2671 /**
Jim Miller50e62182014-04-23 17:25:00 -07002672 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2673 */
2674 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
2675
2676 /**
2677 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2678 */
2679 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
2680
2681 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02002682 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07002683 * (e.g. PIN/Pattern/Password).
2684 */
2685 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
2686
2687 /**
Jim Miller06e34502014-07-17 14:46:05 -07002688 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
2689 */
2690 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
2691
2692 /**
Adrian Roos7f06eed2016-02-05 15:21:02 -08002693 * Disable text entry into notifications on secure keyguard screens (e.g. PIN/Pattern/Password).
2694 */
2695 public static final int KEYGUARD_DISABLE_REMOTE_INPUT = 1 << 6;
2696
2697 /**
Jim Miller35207742012-11-02 15:33:20 -07002698 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07002699 */
2700 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07002701
2702 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002703 * Called by an application that is administering the device to request that the storage system
2704 * be encrypted.
2705 * <p>
2706 * When multiple device administrators attempt to control device encryption, the most secure,
2707 * supported setting will always be used. If any device administrator requests device
2708 * encryption, it will be enabled; Conversely, if a device administrator attempts to disable
2709 * device encryption while another device administrator has enabled it, the call to disable will
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002710 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002711 * <p>
2712 * This policy controls encryption of the secure (application data) storage area. Data written
2713 * to other storage areas may or may not be encrypted, and this policy does not require or
2714 * control the encryption of any other storage areas. There is one exception: If
2715 * {@link android.os.Environment#isExternalStorageEmulated()} is {@code true}, then the
2716 * directory returned by {@link android.os.Environment#getExternalStorageDirectory()} must be
2717 * written to disk within the encrypted storage area.
2718 * <p>
2719 * Important Note: On some devices, it is possible to encrypt storage without requiring the user
2720 * to create a device PIN or Password. In this case, the storage is encrypted, but the
2721 * encryption key may not be fully secured. For maximum security, the administrator should also
2722 * require (and check for) a pattern, PIN, or password.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002723 *
2724 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2725 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08002726 * @return the new request status (for all active admins) - will be one of
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002727 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
2728 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
2729 * {@link #getStorageEncryptionStatus()} to query the actual device state.
2730 * @throws SecurityException if {@code admin} is not an active administrator or does not use
2731 * {@link DeviceAdminInfo#USES_ENCRYPTED_STORAGE}
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002732 */
Robin Lee25e26452015-06-02 09:56:29 -07002733 public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002734 throwIfParentInstance("setStorageEncryption");
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002735 if (mService != null) {
2736 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002737 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002738 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002739 throw e.rethrowFromSystemServer();
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002740 }
2741 }
2742 return ENCRYPTION_STATUS_UNSUPPORTED;
2743 }
2744
2745 /**
2746 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002747 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002748 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08002749 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
2750 * this will return the requested encryption setting as an aggregate of all active
2751 * administrators.
2752 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002753 */
Robin Lee25e26452015-06-02 09:56:29 -07002754 public boolean getStorageEncryption(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002755 throwIfParentInstance("getStorageEncryption");
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002756 if (mService != null) {
2757 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002758 return mService.getStorageEncryption(admin, myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002759 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002760 throw e.rethrowFromSystemServer();
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002761 }
2762 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08002763 return false;
2764 }
2765
2766 /**
2767 * Called by an application that is administering the device to
2768 * determine the current encryption status of the device.
Amith Yamasani75db1252016-07-11 14:41:01 -07002769 * <p>
Andy Stadler22dbfda2011-01-17 12:47:31 -08002770 * Depending on the returned status code, the caller may proceed in different
2771 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
2772 * storage system does not support encryption. If the
2773 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
2774 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00002775 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
2776 * storage system has enabled encryption but no password is set so further action
Amith Yamasani75db1252016-07-11 14:41:01 -07002777 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING},
2778 * {@link #ENCRYPTION_STATUS_ACTIVE} or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER},
2779 * no further action is required.
Andy Stadler22dbfda2011-01-17 12:47:31 -08002780 *
Robin Lee7e678712014-07-24 16:41:31 +01002781 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08002782 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00002783 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
Amith Yamasani75db1252016-07-11 14:41:01 -07002784 * {@link #ENCRYPTION_STATUS_ACTIVE}, or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08002785 */
2786 public int getStorageEncryptionStatus() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002787 throwIfParentInstance("getStorageEncryptionStatus");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002788 return getStorageEncryptionStatus(myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002789 }
2790
2791 /** @hide per-user version */
2792 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08002793 if (mService != null) {
2794 try {
Makoto Onukid4c9e542016-02-25 18:17:30 -08002795 return mService.getStorageEncryptionStatus(mContext.getPackageName(), userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08002796 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002797 throw e.rethrowFromSystemServer();
Andy Stadler22dbfda2011-01-17 12:47:31 -08002798 }
2799 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002800 return ENCRYPTION_STATUS_UNSUPPORTED;
2801 }
2802
2803 /**
Robin Lee2f7e1e42016-03-21 10:50:01 +00002804 * Mark a CA certificate as approved by the device user. This means that they have been notified
2805 * of the installation, were made aware of the risks, viewed the certificate and still wanted to
2806 * keep the certificate on the device.
2807 *
2808 * Calling with {@param approval} as {@code true} will cancel any ongoing warnings related to
2809 * this certificate.
2810 *
2811 * @hide
2812 */
2813 public boolean approveCaCert(String alias, int userHandle, boolean approval) {
2814 if (mService != null) {
2815 try {
2816 return mService.approveCaCert(alias, userHandle, approval);
2817 } catch (RemoteException e) {
2818 throw e.rethrowFromSystemServer();
2819 }
2820 }
2821 return false;
2822 }
2823
2824 /**
2825 * Check whether a CA certificate has been approved by the device user.
2826 *
2827 * @hide
2828 */
2829 public boolean isCaCertApproved(String alias, int userHandle) {
2830 if (mService != null) {
2831 try {
2832 return mService.isCaCertApproved(alias, userHandle);
2833 } catch (RemoteException e) {
2834 throw e.rethrowFromSystemServer();
2835 }
2836 }
2837 return false;
2838 }
2839
2840 /**
Robin Lee7e678712014-07-24 16:41:31 +01002841 * Installs the given certificate as a user CA.
2842 *
Robin Lee25e26452015-06-02 09:56:29 -07002843 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2844 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002845 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04002846 *
2847 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01002848 * interrupted, true otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002849 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
2850 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04002851 */
Robin Lee25e26452015-06-02 09:56:29 -07002852 public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002853 throwIfParentInstance("installCaCert");
Maggie Benthallda51e682013-08-08 22:35:44 -04002854 if (mService != null) {
2855 try {
Robin Lee7e678712014-07-24 16:41:31 +01002856 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04002857 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002858 throw e.rethrowFromSystemServer();
Maggie Benthallda51e682013-08-08 22:35:44 -04002859 }
2860 }
2861 return false;
2862 }
2863
2864 /**
Robin Lee7e678712014-07-24 16:41:31 +01002865 * Uninstalls the given certificate from trusted user CAs, if present.
2866 *
Robin Lee25e26452015-06-02 09:56:29 -07002867 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2868 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002869 * @param certBuffer encoded form of the certificate to remove.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002870 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
2871 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04002872 */
Robin Lee25e26452015-06-02 09:56:29 -07002873 public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002874 throwIfParentInstance("uninstallCaCert");
Maggie Benthallda51e682013-08-08 22:35:44 -04002875 if (mService != null) {
2876 try {
Robin Lee306fe082014-06-19 14:04:24 +00002877 final String alias = getCaCertAlias(certBuffer);
Robin Lee83881bd2015-06-09 16:04:38 -07002878 mService.uninstallCaCerts(admin, new String[] {alias});
Robin Lee306fe082014-06-19 14:04:24 +00002879 } catch (CertificateException e) {
2880 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002881 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002882 throw e.rethrowFromSystemServer();
Maggie Benthallda51e682013-08-08 22:35:44 -04002883 }
2884 }
2885 }
2886
2887 /**
Robin Lee7e678712014-07-24 16:41:31 +01002888 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
2889 * If a user has installed any certificates by other means than device policy these will be
2890 * included too.
2891 *
Robin Lee25e26452015-06-02 09:56:29 -07002892 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2893 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002894 * @return a List of byte[] arrays, each encoding one user CA certificate.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002895 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
2896 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04002897 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07002898 public @NonNull List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) {
2899 final List<byte[]> certs = new ArrayList<byte[]>();
Benjamin Franzbc33c822016-04-15 08:57:52 +01002900 throwIfParentInstance("getInstalledCaCerts");
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002901 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01002902 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002903 mService.enforceCanManageCaCerts(admin);
2904 final TrustedCertificateStore certStore = new TrustedCertificateStore();
2905 for (String alias : certStore.userAliases()) {
2906 try {
2907 certs.add(certStore.getCertificate(alias).getEncoded());
2908 } catch (CertificateException ce) {
2909 Log.w(TAG, "Could not encode certificate: " + alias, ce);
2910 }
2911 }
2912 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002913 throw re.rethrowFromSystemServer();
Robin Lee7e678712014-07-24 16:41:31 +01002914 }
2915 }
2916 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04002917 }
2918
2919 /**
Robin Lee7e678712014-07-24 16:41:31 +01002920 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
2921 * means other than device policy will also be removed, except for system CA certificates.
2922 *
Robin Lee25e26452015-06-02 09:56:29 -07002923 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2924 * {@code null} if calling from a delegated certificate installer.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002925 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
2926 * owner.
Robin Lee7e678712014-07-24 16:41:31 +01002927 */
Robin Lee25e26452015-06-02 09:56:29 -07002928 public void uninstallAllUserCaCerts(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002929 throwIfParentInstance("uninstallAllUserCaCerts");
Robin Lee7e678712014-07-24 16:41:31 +01002930 if (mService != null) {
Robin Lee83881bd2015-06-09 16:04:38 -07002931 try {
2932 mService.uninstallCaCerts(admin, new TrustedCertificateStore().userAliases()
2933 .toArray(new String[0]));
2934 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002935 throw re.rethrowFromSystemServer();
Robin Lee7e678712014-07-24 16:41:31 +01002936 }
2937 }
2938 }
2939
2940 /**
2941 * Returns whether this certificate is installed as a trusted CA.
2942 *
Robin Lee25e26452015-06-02 09:56:29 -07002943 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2944 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002945 * @param certBuffer encoded form of the certificate to look up.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002946 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
2947 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04002948 */
Robin Lee25e26452015-06-02 09:56:29 -07002949 public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002950 throwIfParentInstance("hasCaCertInstalled");
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002951 if (mService != null) {
2952 try {
2953 mService.enforceCanManageCaCerts(admin);
2954 return getCaCertAlias(certBuffer) != null;
2955 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002956 throw re.rethrowFromSystemServer();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002957 } catch (CertificateException ce) {
2958 Log.w(TAG, "Could not parse certificate", ce);
2959 }
Maggie Benthallda51e682013-08-08 22:35:44 -04002960 }
2961 return false;
2962 }
2963
2964 /**
Robin Leece3399f2016-02-24 12:08:32 +00002965 * Called by a device or profile owner, or delegated certificate installer, to install a
2966 * certificate and corresponding private key. All apps within the profile will be able to access
2967 * the certificate and use the private key, given direct user approval.
2968 *
2969 * <p>Access to the installed credentials will not be granted to the caller of this API without
2970 * direct user approval. This is for security - should a certificate installer become
2971 * compromised, certificates it had already installed will be protected.
2972 *
2973 * <p>If the installer must have access to the credentials, call
Rubin Xub4365912016-03-23 12:13:22 +00002974 * {@link #installKeyPair(ComponentName, PrivateKey, Certificate[], String, boolean)} instead.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002975 *
Robin Lee25e26452015-06-02 09:56:29 -07002976 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2977 * {@code null} if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002978 * @param privKey The private key to install.
2979 * @param cert The certificate to install.
2980 * @param alias The private key alias under which to install the certificate. If a certificate
2981 * with that alias already exists, it will be overwritten.
2982 * @return {@code true} if the keys were installed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002983 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
2984 * owner.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002985 */
Robin Leefbc65642015-08-03 16:21:22 +01002986 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
2987 @NonNull Certificate cert, @NonNull String alias) {
Rubin Xub4365912016-03-23 12:13:22 +00002988 return installKeyPair(admin, privKey, new Certificate[] {cert}, alias, false);
Robin Leece3399f2016-02-24 12:08:32 +00002989 }
2990
2991 /**
2992 * Called by a device or profile owner, or delegated certificate installer, to install a
Rubin Xub4365912016-03-23 12:13:22 +00002993 * certificate chain and corresponding private key for the leaf certificate. All apps within the
2994 * profile will be able to access the certificate chain and use the private key, given direct
2995 * user approval.
Robin Leece3399f2016-02-24 12:08:32 +00002996 *
Robin Leea1b290e2016-03-09 14:38:36 +00002997 * <p>The caller of this API may grant itself access to the certificate and private key
2998 * immediately, without user approval. It is a best practice not to request this unless strictly
2999 * necessary since it opens up additional security vulnerabilities.
Robin Leece3399f2016-02-24 12:08:32 +00003000 *
3001 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Robin Leea1b290e2016-03-09 14:38:36 +00003002 * {@code null} if calling from a delegated certificate installer.
Robin Leece3399f2016-02-24 12:08:32 +00003003 * @param privKey The private key to install.
Rubin Xub4365912016-03-23 12:13:22 +00003004 * @param certs The certificate chain to install. The chain should start with the leaf
3005 * certificate and include the chain of trust in order. This will be returned by
3006 * {@link android.security.KeyChain#getCertificateChain}.
Robin Leece3399f2016-02-24 12:08:32 +00003007 * @param alias The private key alias under which to install the certificate. If a certificate
Robin Leea1b290e2016-03-09 14:38:36 +00003008 * with that alias already exists, it will be overwritten.
Robin Leece3399f2016-02-24 12:08:32 +00003009 * @param requestAccess {@code true} to request that the calling app be granted access to the
Robin Leea1b290e2016-03-09 14:38:36 +00003010 * credentials immediately. Otherwise, access to the credentials will be gated by user
3011 * approval.
Robin Leece3399f2016-02-24 12:08:32 +00003012 * @return {@code true} if the keys were installed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003013 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3014 * owner.
Rubin Xub4365912016-03-23 12:13:22 +00003015 * @see android.security.KeyChain#getCertificateChain
Robin Leece3399f2016-02-24 12:08:32 +00003016 */
3017 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
Rubin Xub4365912016-03-23 12:13:22 +00003018 @NonNull Certificate[] certs, @NonNull String alias, boolean requestAccess) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003019 throwIfParentInstance("installKeyPair");
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003020 try {
Rubin Xub4365912016-03-23 12:13:22 +00003021 final byte[] pemCert = Credentials.convertToPem(certs[0]);
3022 byte[] pemChain = null;
3023 if (certs.length > 1) {
3024 pemChain = Credentials.convertToPem(Arrays.copyOfRange(certs, 1, certs.length));
3025 }
Robin Lee0d5ccb72014-09-12 17:41:44 +01003026 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
3027 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
Rubin Xub4365912016-03-23 12:13:22 +00003028 return mService.installKeyPair(admin, pkcs8Key, pemCert, pemChain, alias,
3029 requestAccess);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003030 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003031 throw e.rethrowFromSystemServer();
Robin Lee0d5ccb72014-09-12 17:41:44 +01003032 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
3033 Log.w(TAG, "Failed to obtain private key material", e);
3034 } catch (CertificateException | IOException e) {
3035 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003036 }
3037 return false;
3038 }
3039
3040 /**
Robin Leea1b290e2016-03-09 14:38:36 +00003041 * Called by a device or profile owner, or delegated certificate installer, to remove a
3042 * certificate and private key pair installed under a given alias.
Robin Leefbc65642015-08-03 16:21:22 +01003043 *
3044 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Robin Leea1b290e2016-03-09 14:38:36 +00003045 * {@code null} if calling from a delegated certificate installer.
Robin Leefbc65642015-08-03 16:21:22 +01003046 * @param alias The private key alias under which the certificate is installed.
Robin Leea1b290e2016-03-09 14:38:36 +00003047 * @return {@code true} if the private key alias no longer exists, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003048 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3049 * owner.
Robin Leefbc65642015-08-03 16:21:22 +01003050 */
3051 public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003052 throwIfParentInstance("removeKeyPair");
Robin Leefbc65642015-08-03 16:21:22 +01003053 try {
3054 return mService.removeKeyPair(admin, alias);
3055 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003056 throw e.rethrowFromSystemServer();
Robin Leefbc65642015-08-03 16:21:22 +01003057 }
Robin Leefbc65642015-08-03 16:21:22 +01003058 }
3059
3060 /**
Robin Lee25e26452015-06-02 09:56:29 -07003061 * @return the alias of a given CA certificate in the certificate store, or {@code null} if it
Robin Lee306fe082014-06-19 14:04:24 +00003062 * doesn't exist.
3063 */
3064 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
3065 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
3066 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
3067 new ByteArrayInputStream(certBuffer));
3068 return new TrustedCertificateStore().getCertificateAlias(cert);
3069 }
3070
3071 /**
Rubin Xuec32b562015-03-03 17:34:05 +00003072 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01003073 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00003074 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01003075 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00003076 * <p>
3077 * Delegated certificate installer is a per-user state. The delegated access is persistent until
3078 * it is later cleared by calling this method with a null value or uninstallling the certificate
3079 * installer.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003080 * <p>
Rubin Xuf03d0a62016-02-10 14:54:15 +00003081 * <b>Note:</b>Starting from {@link android.os.Build.VERSION_CODES#N}, if the caller
3082 * application's target SDK version is {@link android.os.Build.VERSION_CODES#N} or newer, the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003083 * supplied certificate installer package must be installed when calling this API, otherwise an
3084 * {@link IllegalArgumentException} will be thrown.
Rubin Xuec32b562015-03-03 17:34:05 +00003085 *
Robin Lee25e26452015-06-02 09:56:29 -07003086 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xuec32b562015-03-03 17:34:05 +00003087 * @param installerPackage The package name of the certificate installer which will be given
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003088 * access. If {@code null} is given the current package will be cleared.
3089 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Rubin Xuec32b562015-03-03 17:34:05 +00003090 */
Robin Lee25e26452015-06-02 09:56:29 -07003091 public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String
3092 installerPackage) throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003093 throwIfParentInstance("setCertInstallerPackage");
Rubin Xuec32b562015-03-03 17:34:05 +00003094 if (mService != null) {
3095 try {
Robin Lee25e26452015-06-02 09:56:29 -07003096 mService.setCertInstallerPackage(admin, installerPackage);
Rubin Xuec32b562015-03-03 17:34:05 +00003097 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003098 throw e.rethrowFromSystemServer();
Rubin Xuec32b562015-03-03 17:34:05 +00003099 }
3100 }
3101 }
3102
3103 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003104 * Called by a profile owner or device owner to retrieve the certificate installer for the user.
3105 * null if none is set.
Rubin Xuec32b562015-03-03 17:34:05 +00003106 *
Robin Lee25e26452015-06-02 09:56:29 -07003107 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003108 * @return The package name of the current delegated certificate installer, or {@code null} if
3109 * none is set.
3110 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Rubin Xuec32b562015-03-03 17:34:05 +00003111 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003112 public @Nullable String getCertInstallerPackage(@NonNull ComponentName admin)
3113 throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003114 throwIfParentInstance("getCertInstallerPackage");
Rubin Xuec32b562015-03-03 17:34:05 +00003115 if (mService != null) {
3116 try {
Robin Lee25e26452015-06-02 09:56:29 -07003117 return mService.getCertInstallerPackage(admin);
Rubin Xuec32b562015-03-03 17:34:05 +00003118 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003119 throw e.rethrowFromSystemServer();
Rubin Xuec32b562015-03-03 17:34:05 +00003120 }
3121 }
3122 return null;
3123 }
3124
3125 /**
Robin Lee244ce8e2016-01-05 18:03:46 +00003126 * Called by a device or profile owner to configure an always-on VPN connection through a
Robin Leedc679712016-05-03 13:23:03 +01003127 * specific application for the current user.
3128 *
3129 * @deprecated this version only exists for compability with previous developer preview builds.
3130 * TODO: delete once there are no longer any live references.
3131 * @hide
3132 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07003133 @Deprecated
Robin Leedc679712016-05-03 13:23:03 +01003134 public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage)
3135 throws NameNotFoundException, UnsupportedOperationException {
3136 setAlwaysOnVpnPackage(admin, vpnPackage, /* lockdownEnabled */ true);
3137 }
3138
3139 /**
3140 * Called by a device or profile owner to configure an always-on VPN connection through a
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003141 * specific application for the current user. This connection is automatically granted and
3142 * persisted after a reboot.
3143 * <p>
3144 * The designated package should declare a {@link android.net.VpnService} in its manifest
3145 * guarded by {@link android.Manifest.permission#BIND_VPN_SERVICE}, otherwise the call will
3146 * fail.
Robin Lee244ce8e2016-01-05 18:03:46 +00003147 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003148 * @param vpnPackage The package name for an installed VPN app on the device, or {@code null} to
Robin Leedc679712016-05-03 13:23:03 +01003149 * remove an existing always-on VPN configuration.
3150 * @param lockdownEnabled {@code true} to disallow networking when the VPN is not connected or
3151 * {@code false} otherwise. This carries the risk that any failure of the VPN provider
3152 * could break networking for all apps. This has no effect when clearing.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003153 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Robin Leeee5eb932016-04-05 16:27:15 +01003154 * @throws NameNotFoundException if {@code vpnPackage} is not installed.
3155 * @throws UnsupportedOperationException if {@code vpnPackage} exists but does not support being
3156 * set as always-on, or if always-on VPN is not available.
Robin Lee244ce8e2016-01-05 18:03:46 +00003157 */
Robin Leedc679712016-05-03 13:23:03 +01003158 public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage,
3159 boolean lockdownEnabled)
Robin Leeee5eb932016-04-05 16:27:15 +01003160 throws NameNotFoundException, UnsupportedOperationException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003161 throwIfParentInstance("setAlwaysOnVpnPackage");
Robin Lee244ce8e2016-01-05 18:03:46 +00003162 if (mService != null) {
3163 try {
Robin Leedc679712016-05-03 13:23:03 +01003164 if (!mService.setAlwaysOnVpnPackage(admin, vpnPackage, lockdownEnabled)) {
Robin Leeee5eb932016-04-05 16:27:15 +01003165 throw new NameNotFoundException(vpnPackage);
3166 }
Robin Lee244ce8e2016-01-05 18:03:46 +00003167 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003168 throw e.rethrowFromSystemServer();
Robin Lee244ce8e2016-01-05 18:03:46 +00003169 }
3170 }
Robin Lee244ce8e2016-01-05 18:03:46 +00003171 }
3172
3173 /**
3174 * Called by a device or profile owner to read the name of the package administering an
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003175 * always-on VPN connection for the current user. If there is no such package, or the always-on
3176 * VPN is provided by the system instead of by an application, {@code null} will be returned.
Robin Lee244ce8e2016-01-05 18:03:46 +00003177 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003178 * @return Package name of VPN controller responsible for always-on VPN, or {@code null} if none
3179 * is set.
3180 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Robin Lee244ce8e2016-01-05 18:03:46 +00003181 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003182 public @Nullable String getAlwaysOnVpnPackage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003183 throwIfParentInstance("getAlwaysOnVpnPackage");
Robin Lee244ce8e2016-01-05 18:03:46 +00003184 if (mService != null) {
3185 try {
3186 return mService.getAlwaysOnVpnPackage(admin);
3187 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003188 throw e.rethrowFromSystemServer();
Robin Lee244ce8e2016-01-05 18:03:46 +00003189 }
3190 }
3191 return null;
3192 }
3193
3194 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003195 * Called by an application that is administering the device to disable all cameras on the
3196 * device, for this user. After setting this, no applications running as this user will be able
3197 * to access any cameras on the device.
3198 * <p>
3199 * If the caller is device owner, then the restriction will be applied to all users.
3200 * <p>
3201 * The calling device admin must have requested
3202 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call this method; if it has
3203 * not, a security exception will be thrown.
Ben Komalo2447edd2011-05-09 16:05:33 -07003204 *
3205 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3206 * @param disabled Whether or not the camera should be disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003207 * @throws SecurityException if {@code admin} is not an active administrator or does not use
3208 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA}.
Ben Komalo2447edd2011-05-09 16:05:33 -07003209 */
Robin Lee25e26452015-06-02 09:56:29 -07003210 public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003211 throwIfParentInstance("setCameraDisabled");
Ben Komalo2447edd2011-05-09 16:05:33 -07003212 if (mService != null) {
3213 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003214 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07003215 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003216 throw e.rethrowFromSystemServer();
Ben Komalo2447edd2011-05-09 16:05:33 -07003217 }
3218 }
3219 }
3220
3221 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07003222 * Determine whether or not the device's cameras have been disabled for this user,
Makoto Onuki32b30572015-12-11 14:29:51 -08003223 * either by the calling admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07003224 * @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 -07003225 * have disabled the camera
3226 */
Robin Lee25e26452015-06-02 09:56:29 -07003227 public boolean getCameraDisabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003228 throwIfParentInstance("getCameraDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003229 return getCameraDisabled(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003230 }
3231
3232 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003233 public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07003234 if (mService != null) {
3235 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003236 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07003237 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003238 throw e.rethrowFromSystemServer();
Ben Komalo2447edd2011-05-09 16:05:33 -07003239 }
3240 }
3241 return false;
3242 }
3243
3244 /**
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003245 * Called by a device owner to request a bugreport.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003246 * <p>
3247 * There must be only one user on the device, managed by the device owner. Otherwise a
3248 * {@link SecurityException} will be thrown.
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003249 *
3250 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003251 * @return {@code true} if the bugreport collection started successfully, or {@code false} if it
3252 * wasn't triggered because a previous bugreport operation is still active (either the
3253 * bugreport is still running or waiting for the user to share or decline)
3254 * @throws SecurityException if {@code admin} is not a device owner, or if there are users other
3255 * than the one managed by the device owner.
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003256 */
3257 public boolean requestBugreport(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003258 throwIfParentInstance("requestBugreport");
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003259 if (mService != null) {
3260 try {
3261 return mService.requestBugreport(admin);
3262 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003263 throw e.rethrowFromSystemServer();
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003264 }
3265 }
3266 return false;
3267 }
3268
3269 /**
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07003270 * Determine whether or not creating a guest user has been disabled for the device
3271 *
3272 * @hide
3273 */
3274 public boolean getGuestUserDisabled(@Nullable ComponentName admin) {
3275 // Currently guest users can always be created if multi-user is enabled
3276 // TODO introduce a policy for guest user creation
3277 return false;
3278 }
3279
3280 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01003281 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
3282 * screen capture also prevents the content from being shown on display devices that do not have
3283 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
3284 * secure surfaces and secure displays.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003285 * <p>
3286 * The calling device admin must be a device or profile owner. If it is not, a security
3287 * exception will be thrown.
3288 * <p>
3289 * From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also blocks
3290 * assist requests for all activities of the relevant user.
Benjamin Franzc200f442015-06-25 18:20:04 +01003291 *
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003292 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003293 * @param disabled Whether screen capture is disabled or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003294 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003295 */
Robin Lee25e26452015-06-02 09:56:29 -07003296 public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003297 throwIfParentInstance("setScreenCaptureDisabled");
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003298 if (mService != null) {
3299 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003300 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003301 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003302 throw e.rethrowFromSystemServer();
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003303 }
3304 }
3305 }
3306
3307 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08003308 * Determine whether or not screen capture has been disabled by the calling
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003309 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07003310 * @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 +01003311 * have disabled screen capture.
3312 */
Robin Lee25e26452015-06-02 09:56:29 -07003313 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003314 throwIfParentInstance("getScreenCaptureDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003315 return getScreenCaptureDisabled(admin, myUserId());
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003316 }
3317
3318 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003319 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003320 if (mService != null) {
3321 try {
3322 return mService.getScreenCaptureDisabled(admin, userHandle);
3323 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003324 throw e.rethrowFromSystemServer();
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003325 }
3326 }
3327 return false;
3328 }
3329
3330 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003331 * Called by a device owner to set whether auto time is required. If auto time is required the
3332 * user cannot set the date and time, but has to use network date and time.
3333 * <p>
3334 * Note: if auto time is required the user can still manually set the time zone.
3335 * <p>
3336 * The calling device admin must be a device owner. If it is not, a security exception will be
3337 * thrown.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003338 *
3339 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3340 * @param required Whether auto time is set required or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003341 * @throws SecurityException if {@code admin} is not a device owner.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003342 */
Robin Lee25e26452015-06-02 09:56:29 -07003343 public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003344 throwIfParentInstance("setAutoTimeRequired");
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003345 if (mService != null) {
3346 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003347 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003348 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003349 throw e.rethrowFromSystemServer();
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003350 }
3351 }
3352 }
3353
3354 /**
3355 * @return true if auto time is required.
3356 */
3357 public boolean getAutoTimeRequired() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003358 throwIfParentInstance("getAutoTimeRequired");
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003359 if (mService != null) {
3360 try {
3361 return mService.getAutoTimeRequired();
3362 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003363 throw e.rethrowFromSystemServer();
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003364 }
3365 }
3366 return false;
3367 }
3368
3369 /**
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003370 * Called by a device owner to set whether all users created on the device should be ephemeral.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003371 * <p>
3372 * The system user is exempt from this policy - it is never ephemeral.
3373 * <p>
3374 * The calling device admin must be the device owner. If it is not, a security exception will be
3375 * thrown.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003376 *
3377 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3378 * @param forceEphemeralUsers If true, all the existing users will be deleted and all
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003379 * subsequently created users will be ephemeral.
3380 * @throws SecurityException if {@code admin} is not a device owner.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003381 * @hide
3382 */
3383 public void setForceEphemeralUsers(
3384 @NonNull ComponentName admin, boolean forceEphemeralUsers) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003385 throwIfParentInstance("setForceEphemeralUsers");
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003386 if (mService != null) {
3387 try {
3388 mService.setForceEphemeralUsers(admin, forceEphemeralUsers);
3389 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003390 throw e.rethrowFromSystemServer();
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003391 }
3392 }
3393 }
3394
3395 /**
3396 * @return true if all users are created ephemeral.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003397 * @throws SecurityException if {@code admin} is not a device owner.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003398 * @hide
3399 */
3400 public boolean getForceEphemeralUsers(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003401 throwIfParentInstance("getForceEphemeralUsers");
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003402 if (mService != null) {
3403 try {
3404 return mService.getForceEphemeralUsers(admin);
3405 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003406 throw e.rethrowFromSystemServer();
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003407 }
3408 }
3409 return false;
3410 }
3411
3412 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07003413 * Called by an application that is administering the device to disable keyguard customizations,
3414 * such as widgets. After setting this, keyguard features will be disabled according to the
3415 * provided feature list.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003416 * <p>
3417 * The calling device admin must have requested
3418 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method;
3419 * if it has not, a security exception will be thrown.
3420 * <p>
3421 * Calling this from a managed profile before version {@link android.os.Build.VERSION_CODES#M}
3422 * will throw a security exception. From version {@link android.os.Build.VERSION_CODES#M} the
3423 * profile owner of a managed profile can set:
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003424 * <ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00003425 * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which affects the parent user, but only if there
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003426 * is no separate challenge set on the managed profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00003427 * <li>{@link #KEYGUARD_DISABLE_FINGERPRINT} which affects the managed profile challenge if
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003428 * there is one, or the parent user otherwise.
3429 * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} which affects notifications generated
3430 * by applications in the managed profile.
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003431 * </ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00003432 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} and {@link #KEYGUARD_DISABLE_FINGERPRINT} can also be
3433 * set on the {@link DevicePolicyManager} instance returned by
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003434 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
3435 * profile.
3436 * <p>
3437 * Requests to disable other features on a managed profile will be ignored.
3438 * <p>
3439 * The admin can check which features have been disabled by calling
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003440 * {@link #getKeyguardDisabledFeatures(ComponentName)}
Amith Yamasani242f4b12014-10-14 16:06:13 -07003441 *
Jim Millerb8ec4702012-08-31 17:19:10 -07003442 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07003443 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003444 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
3445 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS},
3446 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
3447 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS},
3448 * {@link #KEYGUARD_DISABLE_FINGERPRINT}, {@link #KEYGUARD_DISABLE_FEATURES_ALL}
3449 * @throws SecurityException if {@code admin} is not an active administrator or does not user
3450 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES}
Jim Millerb8ec4702012-08-31 17:19:10 -07003451 */
Robin Lee25e26452015-06-02 09:56:29 -07003452 public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07003453 if (mService != null) {
3454 try {
Esteban Talavera62399912016-01-11 15:37:55 +00003455 mService.setKeyguardDisabledFeatures(admin, which, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07003456 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003457 throw e.rethrowFromSystemServer();
Jim Millerb8ec4702012-08-31 17:19:10 -07003458 }
3459 }
3460 }
3461
3462 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08003463 * Determine whether or not features have been disabled in keyguard either by the calling
Rubin Xud3609d42016-07-13 18:32:57 +01003464 * admin, if specified, or all admins that set restrictions on this user and its participating
Esteban Talaverac1c83592016-02-17 17:56:15 +00003465 * profiles. Restrictions on profiles that have a separate challenge are not taken into account.
3466 *
3467 * <p>This method can be called on the {@link DevicePolicyManager} instance
3468 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
3469 * restrictions on the parent profile.
3470 *
Esteban Talavera62399912016-01-11 15:37:55 +00003471 * @param admin The name of the admin component to check, or {@code null} to check whether any
3472 * admins have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07003473 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
3474 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07003475 */
Robin Lee25e26452015-06-02 09:56:29 -07003476 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003477 return getKeyguardDisabledFeatures(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003478 }
3479
3480 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003481 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07003482 if (mService != null) {
3483 try {
Esteban Talavera62399912016-01-11 15:37:55 +00003484 return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07003485 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003486 throw e.rethrowFromSystemServer();
Jim Millerb8ec4702012-08-31 17:19:10 -07003487 }
3488 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07003489 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07003490 }
3491
3492 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08003493 * @hide
3494 */
Robin Lee25e26452015-06-02 09:56:29 -07003495 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
3496 int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003497 if (mService != null) {
3498 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01003499 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003500 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003501 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003502 }
3503 }
3504 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003505
Dianne Hackbornd6847842010-01-12 18:14:19 -08003506 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01003507 * @hide
3508 */
Robin Lee25e26452015-06-02 09:56:29 -07003509 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003510 setActiveAdmin(policyReceiver, refreshing, myUserId());
Jessica Hummel6d36b602014-04-04 12:42:17 +01003511 }
3512
3513 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08003514 * @hide
3515 */
Robin Lee25e26452015-06-02 09:56:29 -07003516 public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08003517 if (mService != null) {
3518 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003519 mService.getRemoveWarning(admin, result, myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08003520 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003521 throw e.rethrowFromSystemServer();
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08003522 }
3523 }
3524 }
3525
3526 /**
3527 * @hide
3528 */
Andrew Scull5f9e6f32016-08-02 14:22:17 +01003529 public void setActivePasswordState(PasswordMetrics metrics, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003530 if (mService != null) {
3531 try {
Andrew Scull5f9e6f32016-08-02 14:22:17 +01003532 mService.setActivePasswordState(metrics, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003533 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003534 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003535 }
3536 }
3537 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003538
Dianne Hackbornd6847842010-01-12 18:14:19 -08003539 /**
3540 * @hide
3541 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003542 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003543 if (mService != null) {
3544 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003545 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003546 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003547 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003548 }
3549 }
3550 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003551
Dianne Hackbornd6847842010-01-12 18:14:19 -08003552 /**
3553 * @hide
3554 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003555 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003556 if (mService != null) {
3557 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003558 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003559 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003560 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003561 }
3562 }
3563 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07003564
3565 /**
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003566 * @hide
3567 */
3568 public void reportFailedFingerprintAttempt(int userHandle) {
3569 if (mService != null) {
3570 try {
3571 mService.reportFailedFingerprintAttempt(userHandle);
3572 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003573 throw e.rethrowFromSystemServer();
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003574 }
3575 }
3576 }
3577
3578 /**
3579 * @hide
3580 */
3581 public void reportSuccessfulFingerprintAttempt(int userHandle) {
3582 if (mService != null) {
3583 try {
3584 mService.reportSuccessfulFingerprintAttempt(userHandle);
3585 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003586 throw e.rethrowFromSystemServer();
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003587 }
3588 }
3589 }
3590
3591 /**
Michal Karpinski31502d32016-01-25 16:43:07 +00003592 * Should be called when keyguard has been dismissed.
3593 * @hide
3594 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003595 public void reportKeyguardDismissed(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00003596 if (mService != null) {
3597 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003598 mService.reportKeyguardDismissed(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00003599 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003600 throw e.rethrowFromSystemServer();
Michal Karpinski31502d32016-01-25 16:43:07 +00003601 }
3602 }
3603 }
3604
3605 /**
3606 * Should be called when keyguard view has been shown to the user.
3607 * @hide
3608 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003609 public void reportKeyguardSecured(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00003610 if (mService != null) {
3611 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003612 mService.reportKeyguardSecured(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00003613 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003614 throw e.rethrowFromSystemServer();
Michal Karpinski31502d32016-01-25 16:43:07 +00003615 }
3616 }
3617 }
3618
3619 /**
Amith Yamasani71e6c692013-03-24 17:39:28 -07003620 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00003621 * Sets the given package as the device owner.
Makoto Onukia52562c2015-10-01 16:12:31 -07003622 * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name.
3623 * @param who the component name to be registered as device owner.
Amith Yamasani71e6c692013-03-24 17:39:28 -07003624 * @return whether the package was successfully registered as the device owner.
3625 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00003626 * @throws IllegalStateException If the preconditions mentioned are not met.
Amith Yamasani71e6c692013-03-24 17:39:28 -07003627 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003628 public boolean setDeviceOwner(ComponentName who) {
3629 return setDeviceOwner(who, null);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003630 }
3631
3632 /**
3633 * @hide
Makoto Onuki58b684f2015-09-04 10:48:16 -07003634 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003635 public boolean setDeviceOwner(ComponentName who, int userId) {
3636 return setDeviceOwner(who, null, userId);
Makoto Onuki58b684f2015-09-04 10:48:16 -07003637 }
3638
3639 /**
3640 * @hide
3641 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003642 public boolean setDeviceOwner(ComponentName who, String ownerName) {
3643 return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM);
Makoto Onuki58b684f2015-09-04 10:48:16 -07003644 }
3645
3646 /**
3647 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00003648 * Sets the given package as the device owner. The package must already be installed. There
3649 * must not already be a device owner.
3650 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
3651 * this method.
3652 * Calling this after the setup phase of the primary user has completed is allowed only if
3653 * the caller is the shell uid, and there are no additional users and no accounts.
Makoto Onukia52562c2015-10-01 16:12:31 -07003654 * @param who the component name to be registered as device owner.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003655 * @param ownerName the human readable name of the institution that owns this device.
Makoto Onuki58b684f2015-09-04 10:48:16 -07003656 * @param userId ID of the user on which the device owner runs.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003657 * @return whether the package was successfully registered as the device owner.
3658 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00003659 * @throws IllegalStateException If the preconditions mentioned are not met.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003660 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003661 public boolean setDeviceOwner(ComponentName who, String ownerName, int userId)
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003662 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07003663 if (mService != null) {
3664 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07003665 return mService.setDeviceOwner(who, ownerName, userId);
Amith Yamasani71e6c692013-03-24 17:39:28 -07003666 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003667 throw re.rethrowFromSystemServer();
Amith Yamasani71e6c692013-03-24 17:39:28 -07003668 }
3669 }
3670 return false;
3671 }
3672
3673 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003674 * Used to determine if a particular package has been registered as a Device Owner app.
3675 * A device owner app is a special device admin that cannot be deactivated by the user, once
Robin Lee25e26452015-06-02 09:56:29 -07003676 * activated as a device admin. It also cannot be uninstalled. To check whether a particular
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003677 * package is currently registered as the device owner app, pass in the package name from
3678 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
Robin Lee25e26452015-06-02 09:56:29 -07003679 * admin apps that want to check whether they are also registered as the device owner app. The
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003680 * exact mechanism by which a device admin app is registered as a device owner app is defined by
3681 * the setup process.
3682 * @param packageName the package name of the app, to compare with the registered device owner
3683 * app, if any.
Makoto Onukic8a5a552015-11-19 14:29:12 -08003684 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07003685 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003686 public boolean isDeviceOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003687 throwIfParentInstance("isDeviceOwnerApp");
Makoto Onukic8a5a552015-11-19 14:29:12 -08003688 return isDeviceOwnerAppOnCallingUser(packageName);
3689 }
3690
3691 /**
3692 * @return true if a package is registered as device owner, only when it's running on the
3693 * calling user.
3694 *
3695 * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity.
3696 * @hide
3697 */
3698 public boolean isDeviceOwnerAppOnCallingUser(String packageName) {
3699 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true);
3700 }
3701
3702 /**
3703 * @return true if a package is registered as device owner, even if it's running on a different
3704 * user.
3705 *
3706 * <p>Requires the MANAGE_USERS permission.
3707 *
3708 * @hide
3709 */
3710 public boolean isDeviceOwnerAppOnAnyUser(String packageName) {
3711 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false);
3712 }
3713
3714 /**
3715 * @return device owner component name, only when it's running on the calling user.
3716 *
3717 * @hide
3718 */
3719 public ComponentName getDeviceOwnerComponentOnCallingUser() {
3720 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true);
3721 }
3722
3723 /**
3724 * @return device owner component name, even if it's running on a different user.
3725 *
3726 * <p>Requires the MANAGE_USERS permission.
3727 *
3728 * @hide
3729 */
3730 public ComponentName getDeviceOwnerComponentOnAnyUser() {
3731 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false);
3732 }
3733
3734 private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) {
Makoto Onuki70f929e2015-11-11 12:40:15 -08003735 if (packageName == null) {
3736 return false;
Amith Yamasani71e6c692013-03-24 17:39:28 -07003737 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08003738 final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly);
Makoto Onuki70f929e2015-11-11 12:40:15 -08003739 if (deviceOwner == null) {
3740 return false;
3741 }
3742 return packageName.equals(deviceOwner.getPackageName());
Amith Yamasani71e6c692013-03-24 17:39:28 -07003743 }
3744
Makoto Onukic8a5a552015-11-19 14:29:12 -08003745 private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) {
3746 if (mService != null) {
3747 try {
3748 return mService.getDeviceOwnerComponent(callingUserOnly);
3749 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003750 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08003751 }
3752 }
3753 return null;
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003754 }
3755
Jason Monkb0dced82014-06-06 14:36:20 -04003756 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08003757 * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's
3758 * no device owner.
3759 *
3760 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07003761 *
3762 * @hide
3763 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08003764 public int getDeviceOwnerUserId() {
3765 if (mService != null) {
3766 try {
3767 return mService.getDeviceOwnerUserId();
3768 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003769 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08003770 }
3771 }
3772 return UserHandle.USER_NULL;
Makoto Onukia52562c2015-10-01 16:12:31 -07003773 }
3774
3775 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003776 * Clears the current device owner. The caller must be the device owner. This function should be
3777 * used cautiously as once it is called it cannot be undone. The device owner can only be set as
3778 * a part of device setup before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04003779 *
3780 * @param packageName The package name of the device owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003781 * @throws SecurityException if the caller is not in {@code packageName} or {@code packageName}
3782 * does not own the current device owner component.
Jason Monkb0dced82014-06-06 14:36:20 -04003783 */
Jason Monk94d2cf92014-06-18 09:53:34 -04003784 public void clearDeviceOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003785 throwIfParentInstance("clearDeviceOwnerApp");
Jason Monkb0dced82014-06-06 14:36:20 -04003786 if (mService != null) {
3787 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04003788 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04003789 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003790 throw re.rethrowFromSystemServer();
Jason Monkb0dced82014-06-06 14:36:20 -04003791 }
3792 }
3793 }
3794
Makoto Onukia52562c2015-10-01 16:12:31 -07003795 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08003796 * Returns the device owner package name, only if it's running on the calling user.
3797 *
3798 * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity.
Makoto Onukia52562c2015-10-01 16:12:31 -07003799 *
3800 * @hide
3801 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01003802 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07003803 public @Nullable String getDeviceOwner() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003804 throwIfParentInstance("getDeviceOwner");
Makoto Onukic8a5a552015-11-19 14:29:12 -08003805 final ComponentName name = getDeviceOwnerComponentOnCallingUser();
3806 return name != null ? name.getPackageName() : null;
Makoto Onukia52562c2015-10-01 16:12:31 -07003807 }
3808
3809 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08003810 * @return true if the device is managed by any device owner.
3811 *
3812 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07003813 *
3814 * @hide
3815 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08003816 public boolean isDeviceManaged() {
3817 return getDeviceOwnerComponentOnAnyUser() != null;
3818 }
3819
3820 /**
3821 * Returns the device owner name. Note this method *will* return the device owner
3822 * name when it's running on a different user.
3823 *
3824 * <p>Requires the MANAGE_USERS permission.
3825 *
3826 * @hide
3827 */
Makoto Onukia2b274b2016-01-19 13:26:02 -08003828 @SystemApi
Makoto Onukic8a5a552015-11-19 14:29:12 -08003829 public String getDeviceOwnerNameOnAnyUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003830 throwIfParentInstance("getDeviceOwnerNameOnAnyUser");
Amith Yamasani71e6c692013-03-24 17:39:28 -07003831 if (mService != null) {
3832 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07003833 return mService.getDeviceOwnerName();
Amith Yamasani71e6c692013-03-24 17:39:28 -07003834 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003835 throw re.rethrowFromSystemServer();
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003836 }
3837 }
3838 return null;
3839 }
Adam Connors776c5552014-01-09 10:42:56 +00003840
3841 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04003842 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003843 * @deprecated Do not use
3844 * @removed
Julia Reynolds20118f12015-02-11 12:34:08 -05003845 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003846 @Deprecated
Julia Reynolds20118f12015-02-11 12:34:08 -05003847 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07003848 public @Nullable String getDeviceInitializerApp() {
Julia Reynolds20118f12015-02-11 12:34:08 -05003849 return null;
3850 }
3851
3852 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003853 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003854 * @deprecated Do not use
3855 * @removed
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003856 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003857 @Deprecated
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003858 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07003859 public @Nullable ComponentName getDeviceInitializerComponent() {
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003860 return null;
3861 }
3862
Julia Reynolds20118f12015-02-11 12:34:08 -05003863 /**
Adam Connors776c5552014-01-09 10:42:56 +00003864 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003865 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303866 * Sets the given component as an active admin and registers the package as the profile
3867 * owner for this user. The package must already be installed and there shouldn't be
3868 * an existing profile owner registered for this user. Also, this method must be called
3869 * before the user setup has been completed.
3870 * <p>
3871 * This method can only be called by system apps that hold MANAGE_USERS permission and
3872 * MANAGE_DEVICE_ADMINS permission.
3873 * @param admin The component to register as an active admin and profile owner.
3874 * @param ownerName The user-visible name of the entity that is managing this user.
3875 * @return whether the admin was successfully registered as the profile owner.
3876 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
3877 * the user has already been set up.
3878 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07003879 @Deprecated
Justin Morey80440cc2014-07-24 09:16:35 -05003880 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07003881 public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303882 throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003883 throwIfParentInstance("setActiveProfileOwner");
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303884 if (mService != null) {
3885 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003886 final int myUserId = myUserId();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303887 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003888 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303889 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003890 throw re.rethrowFromSystemServer();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303891 }
3892 }
3893 return false;
3894 }
3895
3896 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003897 * Clears the active profile owner and removes all user restrictions. The caller must be from
3898 * the same package as the active profile owner for this user, otherwise a SecurityException
3899 * will be thrown.
3900 * <p>
3901 * This doesn't work for managed profile owners.
Makoto Onuki5bf68022016-01-27 13:49:19 -08003902 *
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003903 * @param admin The component to remove as the profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003904 * @throws SecurityException if {@code admin} is not an active profile owner.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003905 */
Robin Lee25e26452015-06-02 09:56:29 -07003906 public void clearProfileOwner(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003907 throwIfParentInstance("clearProfileOwner");
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003908 if (mService != null) {
3909 try {
3910 mService.clearProfileOwner(admin);
3911 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003912 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003913 }
3914 }
3915 }
3916
3917 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05003918 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003919 * Checks whether the user was already setup.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003920 */
3921 public boolean hasUserSetupCompleted() {
3922 if (mService != null) {
3923 try {
3924 return mService.hasUserSetupCompleted();
3925 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003926 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003927 }
3928 }
3929 return true;
3930 }
3931
3932 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003933 * @hide
3934 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00003935 * already be installed. There must not already be a profile owner for this user.
3936 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
3937 * this method.
3938 * Calling this after the setup phase of the specified user has completed is allowed only if:
3939 * - the caller is SYSTEM_UID.
3940 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003941 * @param admin the component name to be registered as profile owner.
3942 * @param ownerName the human readable name of the organisation associated with this DPM.
3943 * @param userHandle the userId to set the profile owner for.
3944 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00003945 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
3946 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003947 */
Robin Lee25e26452015-06-02 09:56:29 -07003948 public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName,
Robin Leeddd553f2015-04-30 14:18:22 +01003949 int userHandle) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00003950 if (mService != null) {
3951 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003952 if (ownerName == null) {
3953 ownerName = "";
3954 }
3955 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00003956 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003957 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00003958 }
3959 }
3960 return false;
3961 }
3962
3963 /**
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003964 * Sets the device owner information to be shown on the lock screen.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003965 * <p>
3966 * If the device owner information is {@code null} or empty then the device owner info is
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003967 * cleared and the user owner info is shown on the lock screen if it is set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003968 * <p>
3969 * If the device owner information contains only whitespaces then the message on the lock screen
3970 * will be blank and the user will not be allowed to change it.
3971 * <p>
3972 * If the device owner information needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00003973 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
3974 * and set a new version of this string accordingly.
3975 *
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003976 * @param admin The name of the admin component to check.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003977 * @param info Device owner information which will be displayed instead of the user owner info.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003978 * @throws SecurityException if {@code admin} is not a device owner.
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003979 */
Andrei Stingaceanu16187902016-03-21 15:44:45 +00003980 public void setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, CharSequence info) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003981 throwIfParentInstance("setDeviceOwnerLockScreenInfo");
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003982 if (mService != null) {
3983 try {
Andrei Stingaceanu16187902016-03-21 15:44:45 +00003984 mService.setDeviceOwnerLockScreenInfo(admin, info);
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003985 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003986 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003987 }
3988 }
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003989 }
3990
3991 /**
3992 * @return The device owner information. If it is not set returns {@code null}.
3993 */
Andrei Stingaceanu16187902016-03-21 15:44:45 +00003994 public CharSequence getDeviceOwnerLockScreenInfo() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003995 throwIfParentInstance("getDeviceOwnerLockScreenInfo");
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003996 if (mService != null) {
3997 try {
3998 return mService.getDeviceOwnerLockScreenInfo();
3999 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004000 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004001 }
4002 }
4003 return null;
4004 }
4005
4006 /**
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004007 * Called by device or profile owners to suspend packages for this user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004008 * <p>
4009 * A suspended package will not be able to start activities. Its notifications will be hidden,
4010 * it will not show up in recents, will not be able to show toasts or dialogs or ring the
4011 * device.
4012 * <p>
4013 * The package must already be installed. If the package is uninstalled while suspended the
4014 * package will no longer be suspended. The admin can block this by using
Kenny Guy871f3eb2016-03-09 20:06:16 +00004015 * {@link #setUninstallBlocked}.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004016 *
4017 * @param admin The name of the admin component to check.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004018 * @param packageNames The package names to suspend or unsuspend.
4019 * @param suspended If set to {@code true} than the packages will be suspended, if set to
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004020 * {@code false} the packages will be unsuspended.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004021 * @return an array of package names for which the suspended status is not set as requested in
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004022 * this method.
4023 * @throws SecurityException if {@code admin} is not a device or profile owner.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004024 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004025 public @NonNull String[] setPackagesSuspended(@NonNull ComponentName admin,
4026 @NonNull String[] packageNames, boolean suspended) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004027 throwIfParentInstance("setPackagesSuspended");
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004028 if (mService != null) {
4029 try {
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004030 return mService.setPackagesSuspended(admin, packageNames, suspended);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004031 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004032 throw re.rethrowFromSystemServer();
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004033 }
4034 }
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004035 return packageNames;
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004036 }
4037
4038 /**
4039 * Called by device or profile owners to determine if a package is suspended.
4040 *
4041 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4042 * @param packageName The name of the package to retrieve the suspended status of.
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00004043 * @return {@code true} if the package is suspended or {@code false} if the package is not
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004044 * suspended, could not be found or an error occurred.
4045 * @throws SecurityException if {@code admin} is not a device or profile owner.
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004046 * @throws NameNotFoundException if the package could not be found.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004047 */
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004048 public boolean isPackageSuspended(@NonNull ComponentName admin, String packageName)
4049 throws NameNotFoundException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004050 throwIfParentInstance("isPackageSuspended");
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004051 if (mService != null) {
4052 try {
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004053 return mService.isPackageSuspended(admin, packageName);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004054 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004055 throw e.rethrowFromSystemServer();
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004056 } catch (IllegalArgumentException ex) {
4057 throw new NameNotFoundException(packageName);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004058 }
4059 }
4060 return false;
4061 }
4062
4063 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004064 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
4065 * be used. Only the profile owner can call this.
4066 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01004067 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004068 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004069 * @throws SecurityException if {@code admin} is not a profile owner.
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004070 */
Robin Lee25e26452015-06-02 09:56:29 -07004071 public void setProfileEnabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004072 throwIfParentInstance("setProfileEnabled");
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004073 if (mService != null) {
4074 try {
4075 mService.setProfileEnabled(admin);
4076 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004077 throw e.rethrowFromSystemServer();
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004078 }
4079 }
4080 }
4081
4082 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004083 * Sets the name of the profile. In the device owner case it sets the name of the user which it
4084 * is called from. Only a profile owner or device owner can call this. If this is never called
4085 * by the profile or device owner, the name will be set to default values.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004086 *
4087 * @see #isProfileOwnerApp
4088 * @see #isDeviceOwnerApp
Robin Lee25e26452015-06-02 09:56:29 -07004089 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004090 * @param profileName The name of the profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004091 * @throws SecurityException if {@code admin} is not a device or profile owner.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004092 */
Robin Lee25e26452015-06-02 09:56:29 -07004093 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004094 throwIfParentInstance("setProfileName");
Jessica Hummel1333ea12014-06-23 11:20:10 +01004095 if (mService != null) {
4096 try {
Robin Lee25e26452015-06-02 09:56:29 -07004097 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07004098 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004099 throw e.rethrowFromSystemServer();
Fyodor Kupolov78f13142015-05-27 16:52:45 -07004100 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01004101 }
4102 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01004103
4104 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004105 * Used to determine if a particular package is registered as the profile owner for the
Makoto Onuki32b30572015-12-11 14:29:51 -08004106 * user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004107 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00004108 *
4109 * @param packageName The package name of the app to compare with the registered profile owner.
4110 * @return Whether or not the package is registered as the profile owner.
4111 */
4112 public boolean isProfileOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004113 throwIfParentInstance("isProfileOwnerApp");
Adam Connors776c5552014-01-09 10:42:56 +00004114 if (mService != null) {
4115 try {
Makoto Onuki90b89652016-01-28 14:44:18 -08004116 ComponentName profileOwner = mService.getProfileOwner(myUserId());
Nicolas Prevot90af6d72014-07-30 14:19:12 +01004117 return profileOwner != null
4118 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00004119 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004120 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004121 }
4122 }
4123 return false;
4124 }
4125
4126 /**
4127 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07004128 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00004129 * owner has been set for that user.
4130 * @throws IllegalArgumentException if the userId is invalid.
4131 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01004132 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004133 public @Nullable ComponentName getProfileOwner() throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004134 throwIfParentInstance("getProfileOwner");
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01004135 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
4136 }
4137
4138 /**
4139 * @see #getProfileOwner()
4140 * @hide
4141 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004142 public @Nullable ComponentName getProfileOwnerAsUser(final int userId)
4143 throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00004144 if (mService != null) {
4145 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01004146 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00004147 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004148 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004149 }
4150 }
4151 return null;
4152 }
4153
4154 /**
4155 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07004156 * @return the human readable name of the organisation associated with this DPM or {@code null}
4157 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00004158 * @throws IllegalArgumentException if the userId is invalid.
4159 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004160 public @Nullable String getProfileOwnerName() throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00004161 if (mService != null) {
4162 try {
4163 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
4164 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004165 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004166 }
4167 }
4168 return null;
4169 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004170
4171 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07004172 * @hide
Makoto Onukic8a5a552015-11-19 14:29:12 -08004173 * @param userId The user for whom to fetch the profile owner name, if any.
Amith Yamasani38f836b2014-08-20 14:51:15 -07004174 * @return the human readable name of the organisation associated with this profile owner or
4175 * null if one is not set.
4176 * @throws IllegalArgumentException if the userId is invalid.
4177 */
4178 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004179 public @Nullable String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004180 throwIfParentInstance("getProfileOwnerNameAsUser");
Amith Yamasani38f836b2014-08-20 14:51:15 -07004181 if (mService != null) {
4182 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02004183 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07004184 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004185 throw re.rethrowFromSystemServer();
Amith Yamasani38f836b2014-08-20 14:51:15 -07004186 }
4187 }
4188 return null;
4189 }
4190
4191 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004192 * Called by a profile owner or device owner to add a default intent handler activity for
4193 * intents that match a certain intent filter. This activity will remain the default intent
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004194 * handler even if the set of potential event handlers for the intent filter changes and if the
4195 * intent preferences are reset.
4196 * <p>
4197 * The default disambiguation mechanism takes over if the activity is not installed (anymore).
4198 * When the activity is (re)installed, it is automatically reset as default intent handler for
4199 * the filter.
4200 * <p>
4201 * The calling device admin must be a profile owner or device owner. If it is not, a security
4202 * exception will be thrown.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004203 *
4204 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4205 * @param filter The IntentFilter for which a default handler is added.
4206 * @param activity The Activity that is added as default intent handler.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004207 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004208 */
Robin Lee25e26452015-06-02 09:56:29 -07004209 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
4210 @NonNull ComponentName activity) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004211 throwIfParentInstance("addPersistentPreferredActivity");
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004212 if (mService != null) {
4213 try {
4214 mService.addPersistentPreferredActivity(admin, filter, activity);
4215 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004216 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004217 }
4218 }
4219 }
4220
4221 /**
4222 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00004223 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004224 * <p>
4225 * The calling device admin must be a profile owner. If it is not, a security exception will be
4226 * thrown.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004227 *
4228 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4229 * @param packageName The name of the package for which preferences are removed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004230 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004231 */
Robin Lee25e26452015-06-02 09:56:29 -07004232 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004233 String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004234 throwIfParentInstance("clearPackagePersistentPreferredActivities");
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004235 if (mService != null) {
4236 try {
4237 mService.clearPackagePersistentPreferredActivities(admin, packageName);
4238 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004239 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004240 }
4241 }
4242 }
Robin Lee66e5d962014-04-09 16:44:21 +01004243
4244 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00004245 * Called by a profile owner or device owner to grant permission to a package to manage
4246 * application restrictions for the calling user via {@link #setApplicationRestrictions} and
4247 * {@link #getApplicationRestrictions}.
4248 * <p>
4249 * This permission is persistent until it is later cleared by calling this method with a
4250 * {@code null} value or uninstalling the managing package.
Rubin Xuf03d0a62016-02-10 14:54:15 +00004251 * <p>
4252 * The supplied application restriction managing package must be installed when calling this
Victor Changcd14c0a2016-03-16 19:10:15 +00004253 * API, otherwise an {@link NameNotFoundException} will be thrown.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004254 *
4255 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4256 * @param packageName The package name which will be given access to application restrictions
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004257 * APIs. If {@code null} is given the current package will be cleared.
4258 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Changcd14c0a2016-03-16 19:10:15 +00004259 * @throws NameNotFoundException if {@code packageName} is not found
Esteban Talaverabf60f722015-12-10 16:26:44 +00004260 */
4261 public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin,
Victor Changcd14c0a2016-03-16 19:10:15 +00004262 @Nullable String packageName) throws NameNotFoundException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004263 throwIfParentInstance("setApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00004264 if (mService != null) {
4265 try {
Victor Changcd14c0a2016-03-16 19:10:15 +00004266 if (!mService.setApplicationRestrictionsManagingPackage(admin, packageName)) {
4267 throw new NameNotFoundException(packageName);
4268 }
Esteban Talaverabf60f722015-12-10 16:26:44 +00004269 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004270 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00004271 }
4272 }
4273 }
4274
4275 /**
4276 * Called by a profile owner or device owner to retrieve the application restrictions managing
4277 * package for the current user, or {@code null} if none is set.
4278 *
4279 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4280 * @return The package name allowed to manage application restrictions on the current user, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004281 * {@code null} if none is set.
4282 * @throws SecurityException if {@code admin} is not a device or profile owner.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004283 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004284 public @Nullable String getApplicationRestrictionsManagingPackage(
4285 @NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004286 throwIfParentInstance("getApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00004287 if (mService != null) {
4288 try {
4289 return mService.getApplicationRestrictionsManagingPackage(admin);
4290 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004291 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00004292 }
4293 }
4294 return null;
4295 }
4296
4297 /**
Esteban Talavera96895ca2016-03-16 12:00:40 +00004298 * Called by any application to find out whether it has been granted permission via
4299 * {@link #setApplicationRestrictionsManagingPackage} to manage application restrictions
4300 * for the calling user.
4301 *
4302 * <p>This is done by comparing the calling Linux uid with the uid of the package specified by
4303 * that method.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004304 */
4305 public boolean isCallerApplicationRestrictionsManagingPackage() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004306 throwIfParentInstance("isCallerApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00004307 if (mService != null) {
4308 try {
4309 return mService.isCallerApplicationRestrictionsManagingPackage();
4310 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004311 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00004312 }
4313 }
4314 return false;
4315 }
4316
4317 /**
4318 * Sets the application restrictions for a given target application running in the calling user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004319 * <p>
4320 * The caller must be a profile or device owner on that user, or the package allowed to manage
4321 * application restrictions via {@link #setApplicationRestrictionsManagingPackage}; otherwise a
4322 * security exception will be thrown.
4323 * <p>
4324 * The provided {@link Bundle} consists of key-value pairs, where the types of values may be:
Esteban Talavera6b8e0642015-08-10 17:26:04 +01004325 * <ul>
4326 * <li>{@code boolean}
4327 * <li>{@code int}
4328 * <li>{@code String} or {@code String[]}
4329 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
4330 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004331 * <p>
4332 * If the restrictions are not available yet, but may be applied in the near future, the caller
4333 * can notify the target application of that by adding
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00004334 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004335 * <p>
4336 * The application restrictions are only made visible to the target application via
4337 * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or device
4338 * owner, and the application restrictions managing package via
Esteban Talaverabf60f722015-12-10 16:26:44 +00004339 * {@link #getApplicationRestrictions}.
Robin Lee66e5d962014-04-09 16:44:21 +01004340 *
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07004341 * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
4342 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00004343 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004344 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01004345 * @param packageName The name of the package to update restricted settings for.
4346 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004347 * set of active restrictions.
4348 * @throws SecurityException if {@code admin} is not a device or profile owner.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004349 * @see #setApplicationRestrictionsManagingPackage
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00004350 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01004351 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07004352 @WorkerThread
Esteban Talaverabf60f722015-12-10 16:26:44 +00004353 public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01004354 Bundle settings) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004355 throwIfParentInstance("setApplicationRestrictions");
Robin Lee66e5d962014-04-09 16:44:21 +01004356 if (mService != null) {
4357 try {
4358 mService.setApplicationRestrictions(admin, packageName, settings);
4359 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004360 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01004361 }
4362 }
4363 }
4364
4365 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004366 * Sets a list of configuration features to enable for a TrustAgent component. This is meant to
4367 * be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all trust
4368 * agents but those enabled by this function call. If flag
Jim Millere303bf42014-08-26 17:12:29 -07004369 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004370 * <p>
4371 * The calling device admin must have requested
4372 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method;
4373 * if not, a security exception will be thrown.
Tony Mak089d8402016-04-05 17:42:55 +01004374 * <p>
4375 * This method can be called on the {@link DevicePolicyManager} instance returned by
4376 * {@link #getParentProfileInstance(ComponentName)} in order to set the configuration for
4377 * the parent profile.
Jim Miller604e7552014-07-18 19:00:02 -07004378 *
4379 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07004380 * @param target Component name of the agent to be enabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004381 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent will be
4382 * strictly disabled according to the state of the
4383 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
4384 * <p>
4385 * If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all
4386 * admins, then it's up to the TrustAgent itself to aggregate the values from all
4387 * device admins.
4388 * <p>
4389 * Consult documentation for the specific TrustAgent to determine legal options
4390 * parameters.
4391 * @throws SecurityException if {@code admin} is not an active administrator or does not use
4392 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES}
Jim Miller604e7552014-07-18 19:00:02 -07004393 */
Robin Lee25e26452015-06-02 09:56:29 -07004394 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
4395 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07004396 if (mService != null) {
4397 try {
Tony Mak089d8402016-04-05 17:42:55 +01004398 mService.setTrustAgentConfiguration(admin, target, configuration, mParentInstance);
Jim Miller604e7552014-07-18 19:00:02 -07004399 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004400 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07004401 }
4402 }
4403 }
4404
4405 /**
Jim Millere303bf42014-08-26 17:12:29 -07004406 * Gets configuration for the given trust agent based on aggregating all calls to
4407 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
4408 * all device admins.
Tony Mak089d8402016-04-05 17:42:55 +01004409 * <p>
4410 * This method can be called on the {@link DevicePolicyManager} instance returned by
4411 * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the configuration set
4412 * on the parent profile.
Jim Miller604e7552014-07-18 19:00:02 -07004413 *
Jim Millerb5db57a2015-01-14 18:17:19 -08004414 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
4415 * this function returns a list of configurations for all admins that declare
4416 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
4417 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
4418 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
4419 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07004420 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07004421 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07004422 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004423 public @Nullable List<PersistableBundle> getTrustAgentConfiguration(
4424 @Nullable ComponentName admin, @NonNull ComponentName agent) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004425 return getTrustAgentConfiguration(admin, agent, myUserId());
Jim Millere303bf42014-08-26 17:12:29 -07004426 }
4427
4428 /** @hide per-user version */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004429 public @Nullable List<PersistableBundle> getTrustAgentConfiguration(
4430 @Nullable ComponentName admin, @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07004431 if (mService != null) {
4432 try {
Tony Mak089d8402016-04-05 17:42:55 +01004433 return mService.getTrustAgentConfiguration(admin, agent, userHandle,
4434 mParentInstance);
Jim Miller604e7552014-07-18 19:00:02 -07004435 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004436 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07004437 }
4438 }
Jim Millere303bf42014-08-26 17:12:29 -07004439 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07004440 }
4441
4442 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004443 * Called by a profile owner of a managed profile to set whether caller-Id information from the
4444 * managed profile will be shown in the parent profile, for incoming calls.
4445 * <p>
4446 * The calling device admin must be a profile owner. If it is not, a security exception will be
4447 * thrown.
Adam Connors210fe212014-07-17 15:41:43 +01004448 *
Robin Lee25e26452015-06-02 09:56:29 -07004449 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01004450 * @param disabled If true caller-Id information in the managed profile is not displayed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004451 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors210fe212014-07-17 15:41:43 +01004452 */
Robin Lee25e26452015-06-02 09:56:29 -07004453 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004454 throwIfParentInstance("setCrossProfileCallerIdDisabled");
Adam Connors210fe212014-07-17 15:41:43 +01004455 if (mService != null) {
4456 try {
Robin Lee25e26452015-06-02 09:56:29 -07004457 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01004458 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004459 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01004460 }
4461 }
4462 }
4463
4464 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004465 * Called by a profile owner of a managed profile to determine whether or not caller-Id
4466 * information has been disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004467 * <p>
4468 * The calling device admin must be a profile owner. If it is not, a security exception will be
4469 * thrown.
Adam Connors210fe212014-07-17 15:41:43 +01004470 *
Robin Lee25e26452015-06-02 09:56:29 -07004471 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004472 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors210fe212014-07-17 15:41:43 +01004473 */
Robin Lee25e26452015-06-02 09:56:29 -07004474 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004475 throwIfParentInstance("getCrossProfileCallerIdDisabled");
Adam Connors210fe212014-07-17 15:41:43 +01004476 if (mService != null) {
4477 try {
Robin Lee25e26452015-06-02 09:56:29 -07004478 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01004479 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004480 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01004481 }
4482 }
4483 return false;
4484 }
4485
4486 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07004487 * Determine whether or not caller-Id information has been disabled.
4488 *
4489 * @param userHandle The user for whom to check the caller-id permission
4490 * @hide
4491 */
4492 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
4493 if (mService != null) {
4494 try {
4495 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
4496 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004497 throw e.rethrowFromSystemServer();
Amith Yamasani570002f2014-07-18 15:48:54 -07004498 }
4499 }
4500 return false;
4501 }
4502
4503 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004504 * Called by a profile owner of a managed profile to set whether contacts search from the
4505 * managed profile will be shown in the parent profile, for incoming calls.
4506 * <p>
4507 * The calling device admin must be a profile owner. If it is not, a security exception will be
4508 * thrown.
Victor Chang1060c6182016-01-04 20:16:23 +00004509 *
4510 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4511 * @param disabled If true contacts search in the managed profile is not displayed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004512 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Chang1060c6182016-01-04 20:16:23 +00004513 */
4514 public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin,
4515 boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004516 throwIfParentInstance("setCrossProfileContactsSearchDisabled");
Victor Chang1060c6182016-01-04 20:16:23 +00004517 if (mService != null) {
4518 try {
4519 mService.setCrossProfileContactsSearchDisabled(admin, disabled);
4520 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004521 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00004522 }
4523 }
4524 }
4525
4526 /**
4527 * Called by a profile owner of a managed profile to determine whether or not contacts search
4528 * has been disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004529 * <p>
4530 * The calling device admin must be a profile owner. If it is not, a security exception will be
4531 * thrown.
Victor Chang1060c6182016-01-04 20:16:23 +00004532 *
4533 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004534 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Chang1060c6182016-01-04 20:16:23 +00004535 */
4536 public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004537 throwIfParentInstance("getCrossProfileContactsSearchDisabled");
Victor Chang1060c6182016-01-04 20:16:23 +00004538 if (mService != null) {
4539 try {
4540 return mService.getCrossProfileContactsSearchDisabled(admin);
4541 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004542 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00004543 }
4544 }
4545 return false;
4546 }
4547
4548
4549 /**
4550 * Determine whether or not contacts search has been disabled.
4551 *
4552 * @param userHandle The user for whom to check the contacts search permission
4553 * @hide
4554 */
4555 public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) {
4556 if (mService != null) {
4557 try {
4558 return mService
4559 .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier());
4560 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004561 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00004562 }
4563 }
4564 return false;
4565 }
4566
4567 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004568 * Start Quick Contact on the managed profile for the user, if the policy allows.
Victor Chang97bdacc2016-01-21 22:24:11 +00004569 *
Makoto Onuki1040da12015-03-19 11:24:00 -07004570 * @hide
4571 */
4572 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
Victor Chang97bdacc2016-01-21 22:24:11 +00004573 boolean isContactIdIgnored, long directoryId, Intent originalIntent) {
Makoto Onuki1040da12015-03-19 11:24:00 -07004574 if (mService != null) {
4575 try {
Victor Chang97bdacc2016-01-21 22:24:11 +00004576 mService.startManagedQuickContact(actualLookupKey, actualContactId,
4577 isContactIdIgnored, directoryId, originalIntent);
Makoto Onuki1040da12015-03-19 11:24:00 -07004578 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004579 throw e.rethrowFromSystemServer();
Makoto Onuki1040da12015-03-19 11:24:00 -07004580 }
4581 }
4582 }
4583
4584 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004585 * Start Quick Contact on the managed profile for the user, if the policy allows.
Ricky Wai494b95d2015-11-20 16:07:15 +00004586 * @hide
4587 */
4588 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
4589 Intent originalIntent) {
Victor Chang97bdacc2016-01-21 22:24:11 +00004590 startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT,
Ricky Wai494b95d2015-11-20 16:07:15 +00004591 originalIntent);
4592 }
4593
4594 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004595 * Called by a profile owner of a managed profile to set whether bluetooth devices can access
4596 * enterprise contacts.
Ricky Wai778ba132015-03-31 14:21:22 +01004597 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004598 * The calling device admin must be a profile owner. If it is not, a security exception will be
4599 * thrown.
Ricky Wai778ba132015-03-31 14:21:22 +01004600 * <p>
4601 * This API works on managed profile only.
4602 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004603 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4604 * @param disabled If true, bluetooth devices cannot access enterprise contacts.
4605 * @throws SecurityException if {@code admin} is not a device or profile owner.
Ricky Wai778ba132015-03-31 14:21:22 +01004606 */
Robin Lee25e26452015-06-02 09:56:29 -07004607 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004608 throwIfParentInstance("setBluetoothContactSharingDisabled");
Ricky Wai778ba132015-03-31 14:21:22 +01004609 if (mService != null) {
4610 try {
Robin Lee25e26452015-06-02 09:56:29 -07004611 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01004612 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004613 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01004614 }
4615 }
4616 }
4617
4618 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004619 * Called by a profile owner of a managed profile to determine whether or not Bluetooth devices
4620 * cannot access enterprise contacts.
Ricky Wai778ba132015-03-31 14:21:22 +01004621 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004622 * The calling device admin must be a profile owner. If it is not, a security exception will be
4623 * thrown.
Ricky Wai778ba132015-03-31 14:21:22 +01004624 * <p>
4625 * This API works on managed profile only.
4626 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004627 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4628 * @throws SecurityException if {@code admin} is not a device or profile owner.
Ricky Wai778ba132015-03-31 14:21:22 +01004629 */
Robin Lee25e26452015-06-02 09:56:29 -07004630 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004631 throwIfParentInstance("getBluetoothContactSharingDisabled");
Ricky Wai778ba132015-03-31 14:21:22 +01004632 if (mService != null) {
4633 try {
Robin Lee25e26452015-06-02 09:56:29 -07004634 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01004635 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004636 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01004637 }
4638 }
4639 return true;
4640 }
4641
4642 /**
4643 * Determine whether or not Bluetooth devices cannot access contacts.
4644 * <p>
4645 * This API works on managed profile UserHandle only.
4646 *
4647 * @param userHandle The user for whom to check the caller-id permission
4648 * @hide
4649 */
4650 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
4651 if (mService != null) {
4652 try {
4653 return mService.getBluetoothContactSharingDisabledForUser(userHandle
4654 .getIdentifier());
4655 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004656 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01004657 }
4658 }
4659 return true;
4660 }
4661
4662 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004663 * Called by the profile owner of a managed profile so that some intents sent in the managed
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004664 * profile can also be resolved in the parent, or vice versa. Only activity intents are
4665 * supported.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00004666 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004667 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01004668 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004669 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01004670 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004671 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
4672 * @throws SecurityException if {@code admin} is not a device or profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004673 */
Robin Lee25e26452015-06-02 09:56:29 -07004674 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004675 throwIfParentInstance("addCrossProfileIntentFilter");
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004676 if (mService != null) {
4677 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01004678 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004679 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004680 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004681 }
4682 }
4683 }
4684
4685 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004686 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
4687 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01004688 * Only removes those that have been set by the profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004689 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004690 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004691 * @throws SecurityException if {@code admin} is not a device or profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004692 */
Robin Lee25e26452015-06-02 09:56:29 -07004693 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004694 throwIfParentInstance("clearCrossProfileIntentFilters");
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004695 if (mService != null) {
4696 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01004697 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004698 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004699 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004700 }
4701 }
4702 }
4703
4704 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004705 * Called by a profile or device owner to set the permitted accessibility services. When set by
4706 * a device owner or profile owner the restriction applies to all profiles of the user the
4707 * device owner or profile owner is an admin for. By default the user can use any accessiblity
4708 * service. When zero or more packages have been added, accessiblity services that are not in
4709 * the list and not part of the system can not be enabled by the user.
4710 * <p>
4711 * Calling with a null value for the list disables the restriction so that all services can be
4712 * used, calling with an empty list only allows the builtin system's services.
4713 * <p>
4714 * System accesibility services are always available to the user the list can't modify this.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004715 *
4716 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4717 * @param packageNames List of accessibility service package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004718 * @return true if setting the restriction succeeded. It fail if there is one or more non-system
4719 * accessibility services enabled, that are not in the list.
4720 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004721 */
Robin Lee25e26452015-06-02 09:56:29 -07004722 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004723 List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004724 throwIfParentInstance("setPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004725 if (mService != null) {
4726 try {
4727 return mService.setPermittedAccessibilityServices(admin, packageNames);
4728 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004729 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004730 }
4731 }
4732 return false;
4733 }
4734
4735 /**
4736 * Returns the list of permitted accessibility services set by this device or profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004737 * <p>
4738 * An empty list means no accessibility services except system services are allowed. Null means
4739 * all accessibility services are allowed.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004740 *
4741 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4742 * @return List of accessiblity service package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004743 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004744 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004745 public @Nullable List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004746 throwIfParentInstance("getPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004747 if (mService != null) {
4748 try {
4749 return mService.getPermittedAccessibilityServices(admin);
4750 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004751 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004752 }
4753 }
4754 return null;
4755 }
4756
4757 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00004758 * Called by the system to check if a specific accessibility service is disabled by admin.
4759 *
4760 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4761 * @param packageName Accessibility service package name that needs to be checked.
4762 * @param userHandle user id the admin is running as.
4763 * @return true if the accessibility service is permitted, otherwise false.
4764 *
4765 * @hide
4766 */
4767 public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin,
4768 @NonNull String packageName, int userHandle) {
4769 if (mService != null) {
4770 try {
4771 return mService.isAccessibilityServicePermittedByAdmin(admin, packageName,
4772 userHandle);
4773 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004774 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00004775 }
4776 }
4777 return false;
4778 }
4779
4780 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004781 * Returns the list of accessibility services permitted by the device or profiles
4782 * owners of this user.
4783 *
4784 * <p>Null means all accessibility services are allowed, if a non-null list is returned
4785 * it will contain the intersection of the permitted lists for any device or profile
4786 * owners that apply to this user. It will also include any system accessibility services.
4787 *
4788 * @param userId which user to check for.
4789 * @return List of accessiblity service package names.
4790 * @hide
4791 */
4792 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004793 public @Nullable List<String> getPermittedAccessibilityServices(int userId) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004794 throwIfParentInstance("getPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004795 if (mService != null) {
4796 try {
4797 return mService.getPermittedAccessibilityServicesForUser(userId);
4798 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004799 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004800 }
4801 }
4802 return null;
4803 }
4804
4805 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004806 * Called by a profile or device owner to set the permitted input methods services. When set by
4807 * a device owner or profile owner the restriction applies to all profiles of the user the
4808 * device owner or profile owner is an admin for. By default the user can use any input method.
4809 * When zero or more packages have been added, input method that are not in the list and not
4810 * part of the system can not be enabled by the user. This method will fail if it is called for
4811 * a admin that is not for the foreground user or a profile of the foreground user.
4812 * <p>
4813 * Calling with a null value for the list disables the restriction so that all input methods can
4814 * be used, calling with an empty list disables all but the system's own input methods.
4815 * <p>
4816 * System input methods are always available to the user this method can't modify this.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004817 *
4818 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4819 * @param packageNames List of input method package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004820 * @return true if setting the restriction succeeded. It will fail if there are one or more
4821 * non-system input methods currently enabled that are not in the packageNames list.
4822 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004823 */
Robin Lee25e26452015-06-02 09:56:29 -07004824 public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004825 throwIfParentInstance("setPermittedInputMethods");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004826 if (mService != null) {
4827 try {
4828 return mService.setPermittedInputMethods(admin, packageNames);
4829 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004830 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004831 }
4832 }
4833 return false;
4834 }
4835
4836
4837 /**
4838 * Returns the list of permitted input methods set by this device or profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004839 * <p>
4840 * An empty list means no input methods except system input methods are allowed. Null means all
4841 * input methods are allowed.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004842 *
4843 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4844 * @return List of input method package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004845 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004846 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004847 public @Nullable List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004848 throwIfParentInstance("getPermittedInputMethods");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004849 if (mService != null) {
4850 try {
4851 return mService.getPermittedInputMethods(admin);
4852 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004853 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004854 }
4855 }
4856 return null;
4857 }
4858
4859 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00004860 * Called by the system to check if a specific input method is disabled by admin.
4861 *
4862 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4863 * @param packageName Input method package name that needs to be checked.
4864 * @param userHandle user id the admin is running as.
4865 * @return true if the input method is permitted, otherwise false.
4866 *
4867 * @hide
4868 */
4869 public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin,
4870 @NonNull String packageName, int userHandle) {
4871 if (mService != null) {
4872 try {
4873 return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle);
4874 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004875 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00004876 }
4877 }
4878 return false;
4879 }
4880
4881 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004882 * Returns the list of input methods permitted by the device or profiles
Makoto Onuki32b30572015-12-11 14:29:51 -08004883 * owners of the current user. (*Not* calling user, due to a limitation in InputMethodManager.)
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004884 *
4885 * <p>Null means all input methods are allowed, if a non-null list is returned
4886 * it will contain the intersection of the permitted lists for any device or profile
4887 * owners that apply to this user. It will also include any system input methods.
4888 *
4889 * @return List of input method package names.
4890 * @hide
4891 */
4892 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004893 public @Nullable List<String> getPermittedInputMethodsForCurrentUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004894 throwIfParentInstance("getPermittedInputMethodsForCurrentUser");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004895 if (mService != null) {
4896 try {
4897 return mService.getPermittedInputMethodsForCurrentUser();
4898 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004899 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004900 }
4901 }
4902 return null;
4903 }
4904
4905 /**
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004906 * Called by a device owner to get the list of apps to keep around as APKs even if no user has
4907 * currently installed it.
4908 *
4909 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4910 *
4911 * @return List of package names to keep cached.
4912 * @hide
4913 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004914 public @Nullable List<String> getKeepUninstalledPackages(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004915 throwIfParentInstance("getKeepUninstalledPackages");
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004916 if (mService != null) {
4917 try {
4918 return mService.getKeepUninstalledPackages(admin);
4919 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004920 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004921 }
4922 }
4923 return null;
4924 }
4925
4926 /**
4927 * Called by a device owner to set a list of apps to keep around as APKs even if no user has
4928 * currently installed it.
4929 *
4930 * <p>Please note that setting this policy does not imply that specified apps will be
4931 * automatically pre-cached.</p>
4932 *
4933 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4934 * @param packageNames List of package names to keep cached.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004935 * @throws SecurityException if {@code admin} is not a device owner.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004936 * @hide
4937 */
4938 public void setKeepUninstalledPackages(@NonNull ComponentName admin,
4939 @NonNull List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004940 throwIfParentInstance("setKeepUninstalledPackages");
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004941 if (mService != null) {
4942 try {
4943 mService.setKeepUninstalledPackages(admin, packageNames);
4944 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004945 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004946 }
4947 }
4948 }
4949
4950 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04004951 * Called by a device owner to create a user with the specified name. The UserHandle returned
4952 * by this method should not be persisted as user handles are recycled as users are removed and
4953 * created. If you need to persist an identifier for this user, use
4954 * {@link UserManager#getSerialNumberForUser}.
4955 *
4956 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4957 * @param name the user's name
4958 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07004959 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
4960 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01004961 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004962 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01004963 * @removed From {@link android.os.Build.VERSION_CODES#N}
Julia Reynolds1e958392014-05-16 14:25:21 -04004964 */
Kenny Guy14f48e52015-06-29 15:12:36 +01004965 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07004966 public @Nullable UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04004967 return null;
4968 }
4969
4970 /**
Jason Monk03978a42014-06-10 15:05:30 -04004971 * Called by a device owner to create a user with the specified name. The UserHandle returned
4972 * by this method should not be persisted as user handles are recycled as users are removed and
4973 * created. If you need to persist an identifier for this user, use
4974 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
4975 * immediately.
4976 *
4977 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
4978 * as registered as an active admin on the new user. The profile owner package will be
4979 * installed on the new user if it already is installed on the device.
4980 *
4981 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
4982 * profileOwnerComponent when onEnable is called.
4983 *
4984 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4985 * @param name the user's name
4986 * @param ownerName the human readable name of the organisation associated with this DPM.
4987 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
4988 * the user.
4989 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
4990 * on the new user.
4991 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07004992 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
4993 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01004994 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004995 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01004996 * @removed From {@link android.os.Build.VERSION_CODES#N}
Jason Monk03978a42014-06-10 15:05:30 -04004997 */
Kenny Guy14f48e52015-06-29 15:12:36 +01004998 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07004999 public @Nullable UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
Robin Lee25e26452015-06-02 09:56:29 -07005000 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04005001 return null;
5002 }
5003
5004 /**
phweissa92e1212016-01-25 17:14:10 +01005005 * Flag used by {@link #createAndManageUser} to skip setup wizard after creating a new user.
phweiss343fb332016-01-25 14:48:59 +01005006 */
5007 public static final int SKIP_SETUP_WIZARD = 0x0001;
5008
5009 /**
Lenka Trochtovac8202c82016-01-26 15:11:09 +01005010 * Flag used by {@link #createAndManageUser} to specify that the user should be created
5011 * ephemeral.
5012 * @hide
5013 */
5014 public static final int MAKE_USER_EPHEMERAL = 0x0002;
5015
5016 /**
phweissa92e1212016-01-25 17:14:10 +01005017 * Called by a device owner to create a user with the specified name and a given component of
5018 * the calling package as profile owner. The UserHandle returned by this method should not be
5019 * persisted as user handles are recycled as users are removed and created. If you need to
5020 * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new
5021 * user will not be started in the background.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005022 * <p>
5023 * admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also a
5024 * DeviceAdminReceiver in the same package as admin, and will become the profile owner and will
5025 * be registered as an active admin on the new user. The profile owner package will be installed
5026 * on the new user.
5027 * <p>
5028 * If the adminExtras are not null, they will be stored on the device until the user is started
5029 * for the first time. Then the extras will be passed to the admin when onEnable is called.
phweiss343fb332016-01-25 14:48:59 +01005030 *
5031 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5032 * @param name The user's name.
phweissa92e1212016-01-25 17:14:10 +01005033 * @param profileOwner Which {@link DeviceAdminReceiver} will be profile owner. Has to be in the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005034 * same package as admin, otherwise no user is created and an
5035 * IllegalArgumentException is thrown.
phweiss343fb332016-01-25 14:48:59 +01005036 * @param adminExtras Extras that will be passed to onEnable of the admin receiver on the new
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005037 * user.
phweissa92e1212016-01-25 17:14:10 +01005038 * @param flags {@link #SKIP_SETUP_WIZARD} is supported.
phweiss343fb332016-01-25 14:48:59 +01005039 * @see UserHandle
5040 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
5041 * user could not be created.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005042 * @throws SecurityException if {@code admin} is not a device owner.
phweiss343fb332016-01-25 14:48:59 +01005043 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005044 public @Nullable UserHandle createAndManageUser(@NonNull ComponentName admin,
5045 @NonNull String name,
phweissa92e1212016-01-25 17:14:10 +01005046 @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras,
5047 int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005048 throwIfParentInstance("createAndManageUser");
phweiss343fb332016-01-25 14:48:59 +01005049 try {
phweissa92e1212016-01-25 17:14:10 +01005050 return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags);
phweiss343fb332016-01-25 14:48:59 +01005051 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005052 throw re.rethrowFromSystemServer();
phweiss343fb332016-01-25 14:48:59 +01005053 }
phweiss343fb332016-01-25 14:48:59 +01005054 }
5055
5056 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005057 * Called by a device owner to remove a user and all associated data. The primary user can not
5058 * be removed.
Julia Reynolds1e958392014-05-16 14:25:21 -04005059 *
5060 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5061 * @param userHandle the user to remove.
5062 * @return {@code true} if the user was removed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005063 * @throws SecurityException if {@code admin} is not a device owner.
Julia Reynolds1e958392014-05-16 14:25:21 -04005064 */
Robin Lee25e26452015-06-02 09:56:29 -07005065 public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005066 throwIfParentInstance("removeUser");
Julia Reynolds1e958392014-05-16 14:25:21 -04005067 try {
5068 return mService.removeUser(admin, userHandle);
5069 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005070 throw re.rethrowFromSystemServer();
Julia Reynolds1e958392014-05-16 14:25:21 -04005071 }
5072 }
5073
5074 /**
Jason Monk582d9112014-07-09 19:57:08 -04005075 * Called by a device owner to switch the specified user to the foreground.
5076 *
5077 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5078 * @param userHandle the user to switch to; null will switch to primary.
5079 * @return {@code true} if the switch was successful, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005080 * @throws SecurityException if {@code admin} is not a device owner.
Jason Monk582d9112014-07-09 19:57:08 -04005081 * @see Intent#ACTION_USER_FOREGROUND
5082 */
Robin Lee25e26452015-06-02 09:56:29 -07005083 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005084 throwIfParentInstance("switchUser");
Jason Monk582d9112014-07-09 19:57:08 -04005085 try {
5086 return mService.switchUser(admin, userHandle);
5087 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005088 throw re.rethrowFromSystemServer();
Jason Monk582d9112014-07-09 19:57:08 -04005089 }
5090 }
5091
5092 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00005093 * Retrieves the application restrictions for a given target application running in the calling
5094 * user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005095 * <p>
5096 * The caller must be a profile or device owner on that user, or the package allowed to manage
5097 * application restrictions via {@link #setApplicationRestrictionsManagingPackage}; otherwise a
5098 * security exception will be thrown.
Robin Lee66e5d962014-04-09 16:44:21 +01005099 *
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005100 * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
5101 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00005102 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005103 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01005104 * @param packageName The name of the package to fetch restricted settings of.
5105 * @return {@link Bundle} of settings corresponding to what was set last time
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005106 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty
5107 * {@link Bundle} if no restrictions have been set.
5108 * @throws SecurityException if {@code admin} is not a device or profile owner.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005109 * @see {@link #setApplicationRestrictionsManagingPackage}
Robin Lee66e5d962014-04-09 16:44:21 +01005110 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005111 @WorkerThread
Makoto Onuki408e8e42016-10-25 12:10:27 -07005112 public @NonNull Bundle getApplicationRestrictions(
5113 @Nullable ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005114 throwIfParentInstance("getApplicationRestrictions");
Robin Lee66e5d962014-04-09 16:44:21 +01005115 if (mService != null) {
5116 try {
5117 return mService.getApplicationRestrictions(admin, packageName);
5118 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005119 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01005120 }
5121 }
5122 return null;
5123 }
Amith Yamasanibe465322014-04-24 13:45:17 -07005124
5125 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05005126 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07005127 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005128 * The calling device admin must be a profile or device owner; if it is not, a security
5129 * exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07005130 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005131 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5132 * @param key The key of the restriction. See the constants in {@link android.os.UserManager}
5133 * for the list of keys.
5134 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanibe465322014-04-24 13:45:17 -07005135 */
Robin Lee25e26452015-06-02 09:56:29 -07005136 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005137 throwIfParentInstance("addUserRestriction");
Amith Yamasanibe465322014-04-24 13:45:17 -07005138 if (mService != null) {
5139 try {
5140 mService.setUserRestriction(admin, key, true);
5141 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005142 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07005143 }
5144 }
5145 }
5146
5147 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05005148 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07005149 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005150 * The calling device admin must be a profile or device owner; if it is not, a security
5151 * exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07005152 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005153 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5154 * @param key The key of the restriction. See the constants in {@link android.os.UserManager}
5155 * for the list of keys.
5156 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanibe465322014-04-24 13:45:17 -07005157 */
Robin Lee25e26452015-06-02 09:56:29 -07005158 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005159 throwIfParentInstance("clearUserRestriction");
Amith Yamasanibe465322014-04-24 13:45:17 -07005160 if (mService != null) {
5161 try {
5162 mService.setUserRestriction(admin, key, false);
5163 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005164 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07005165 }
5166 }
5167 }
Adam Connors010cfd42014-04-16 12:48:13 +01005168
5169 /**
Makoto Onuki3a3092f2015-10-30 11:07:51 -07005170 * Called by a profile or device owner to get user restrictions set with
5171 * {@link #addUserRestriction(ComponentName, String)}.
5172 * <p>
5173 * The target user may have more restrictions set by the system or other device owner / profile
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005174 * owner. To get all the user restrictions currently set, use
Makoto Onuki3a3092f2015-10-30 11:07:51 -07005175 * {@link UserManager#getUserRestrictions()}.
5176 *
5177 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005178 * @throws SecurityException if {@code admin} is not a device or profile owner.
Makoto Onuki3a3092f2015-10-30 11:07:51 -07005179 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005180 public @NonNull Bundle getUserRestrictions(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005181 throwIfParentInstance("getUserRestrictions");
Makoto Onuki3a3092f2015-10-30 11:07:51 -07005182 Bundle ret = null;
5183 if (mService != null) {
5184 try {
Sudheer Shanka549b9692016-03-30 17:12:07 -07005185 ret = mService.getUserRestrictions(admin);
5186 } catch (RemoteException e) {
5187 throw e.rethrowFromSystemServer();
5188 }
5189 }
5190 return ret == null ? new Bundle() : ret;
5191 }
5192
5193 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005194 * Called by profile or device owners to hide or unhide packages. When a package is hidden it is
5195 * unavailable for use, but the data and actual package file remain.
Julia Reynolds966881e2014-05-14 12:23:08 -04005196 *
5197 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005198 * @param packageName The name of the package to hide or unhide.
5199 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005200 * unhidden.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005201 * @return boolean Whether the hidden setting of the package was successfully updated.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005202 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds966881e2014-05-14 12:23:08 -04005203 */
Robin Lee25e26452015-06-02 09:56:29 -07005204 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005205 boolean hidden) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005206 throwIfParentInstance("setApplicationHidden");
Julia Reynolds966881e2014-05-14 12:23:08 -04005207 if (mService != null) {
5208 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005209 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04005210 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005211 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04005212 }
5213 }
5214 return false;
5215 }
5216
5217 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05005218 * Called by profile or device owners to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04005219 *
5220 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005221 * @param packageName The name of the package to retrieve the hidden status of.
5222 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005223 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds966881e2014-05-14 12:23:08 -04005224 */
Robin Lee25e26452015-06-02 09:56:29 -07005225 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005226 throwIfParentInstance("isApplicationHidden");
Julia Reynolds966881e2014-05-14 12:23:08 -04005227 if (mService != null) {
5228 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005229 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04005230 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005231 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04005232 }
5233 }
5234 return false;
5235 }
5236
5237 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05005238 * Called by profile or device owners to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005239 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00005240 *
5241 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Makoto Onuki32b30572015-12-11 14:29:51 -08005242 * @param packageName The package to be re-enabled in the calling profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005243 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors655be2a2014-07-14 09:01:25 +00005244 */
Robin Lee25e26452015-06-02 09:56:29 -07005245 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005246 throwIfParentInstance("enableSystemApp");
Adam Connors655be2a2014-07-14 09:01:25 +00005247 if (mService != null) {
5248 try {
5249 mService.enableSystemApp(admin, packageName);
5250 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005251 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00005252 }
5253 }
5254 }
5255
5256 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005257 * Called by profile or device owners to re-enable system apps by intent that were disabled by
5258 * default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00005259 *
5260 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5261 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005262 * intent will be re-enabled in the calling profile.
Adam Connors655be2a2014-07-14 09:01:25 +00005263 * @return int The number of activities that matched the intent and were installed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005264 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors655be2a2014-07-14 09:01:25 +00005265 */
Robin Lee25e26452015-06-02 09:56:29 -07005266 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005267 throwIfParentInstance("enableSystemApp");
Adam Connors655be2a2014-07-14 09:01:25 +00005268 if (mService != null) {
5269 try {
5270 return mService.enableSystemAppWithIntent(admin, intent);
5271 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005272 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00005273 }
5274 }
5275 return 0;
5276 }
5277
5278 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00005279 * Called by a device owner or profile owner to disable account management for a specific type
5280 * of account.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005281 * <p>
5282 * The calling device admin must be a device owner or profile owner. If it is not, a security
5283 * exception will be thrown.
5284 * <p>
5285 * When account management is disabled for an account type, adding or removing an account of
5286 * that type will not be possible.
5287 * <p>
5288 * From {@link android.os.Build.VERSION_CODES#N} the profile or device owner can still use
Benjamin Franzb6c0ce42015-11-05 10:06:51 +00005289 * {@link android.accounts.AccountManager} APIs to add or remove accounts when account
5290 * management for a specific type is disabled.
5291 *
Sander Alewijnse650c3342014-05-08 18:00:50 +01005292 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5293 * @param accountType For which account management is disabled or enabled.
5294 * @param disabled The boolean indicating that account management will be disabled (true) or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005295 * enabled (false).
5296 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnse650c3342014-05-08 18:00:50 +01005297 */
Robin Lee25e26452015-06-02 09:56:29 -07005298 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01005299 boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005300 throwIfParentInstance("setAccountManagementDisabled");
Sander Alewijnse650c3342014-05-08 18:00:50 +01005301 if (mService != null) {
5302 try {
5303 mService.setAccountManagementDisabled(admin, accountType, disabled);
5304 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005305 throw e.rethrowFromSystemServer();
Sander Alewijnse650c3342014-05-08 18:00:50 +01005306 }
5307 }
5308 }
5309
5310 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01005311 * Gets the array of accounts for which account management is disabled by the profile owner.
5312 *
5313 * <p> Account management can be disabled/enabled by calling
5314 * {@link #setAccountManagementDisabled}.
5315 *
5316 * @return a list of account types for which account management has been disabled.
5317 *
5318 * @see #setAccountManagementDisabled
5319 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005320 public @Nullable String[] getAccountTypesWithManagementDisabled() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005321 throwIfParentInstance("getAccountTypesWithManagementDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07005322 return getAccountTypesWithManagementDisabledAsUser(myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01005323 }
5324
5325 /**
5326 * @see #getAccountTypesWithManagementDisabled()
5327 * @hide
5328 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005329 public @Nullable String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01005330 if (mService != null) {
5331 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01005332 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01005333 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005334 throw e.rethrowFromSystemServer();
Sander Alewijnse5c02db62014-05-07 10:46:57 +01005335 }
5336 }
5337
5338 return null;
5339 }
justinzhang511e0d82014-03-24 16:09:24 -04005340
5341 /**
Jason Monkd7b86212014-06-16 13:15:38 -04005342 * Sets which packages may enter lock task mode.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005343 * <p>
5344 * Any packages that shares uid with an allowed package will also be allowed to activate lock
5345 * task. From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task
5346 * package list results in locked tasks belonging to those packages to be finished. This
5347 * function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04005348 *
Jason Monkd7b86212014-06-16 13:15:38 -04005349 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04005350 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005351 * @throws SecurityException if {@code admin} is not a device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04005352 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00005353 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
5354 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04005355 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04005356 */
Robin Lee25e26452015-06-02 09:56:29 -07005357 public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04005358 throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005359 throwIfParentInstance("setLockTaskPackages");
justinzhang511e0d82014-03-24 16:09:24 -04005360 if (mService != null) {
5361 try {
Jason Monk48aacba2014-08-13 16:29:08 -04005362 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04005363 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005364 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04005365 }
5366 }
5367 }
5368
5369 /**
Jason Monkd7b86212014-06-16 13:15:38 -04005370 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04005371 *
5372 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04005373 * @hide
5374 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005375 public @NonNull String[] getLockTaskPackages(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005376 throwIfParentInstance("getLockTaskPackages");
justinzhang511e0d82014-03-24 16:09:24 -04005377 if (mService != null) {
5378 try {
Jason Monk48aacba2014-08-13 16:29:08 -04005379 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04005380 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005381 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04005382 }
5383 }
5384 return null;
5385 }
5386
5387 /**
5388 * This function lets the caller know whether the given component is allowed to start the
5389 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04005390 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04005391 */
Jason Monkd7b86212014-06-16 13:15:38 -04005392 public boolean isLockTaskPermitted(String pkg) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005393 throwIfParentInstance("isLockTaskPermitted");
justinzhang511e0d82014-03-24 16:09:24 -04005394 if (mService != null) {
5395 try {
Jason Monkd7b86212014-06-16 13:15:38 -04005396 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04005397 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005398 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04005399 }
5400 }
5401 return false;
5402 }
Julia Reynoldsda551652014-05-14 17:15:16 -04005403
5404 /**
5405 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
5406 * 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 -07005407 * <p>
5408 * The settings that can be updated with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005409 * <ul>
5410 * <li>{@link Settings.Global#ADB_ENABLED}</li>
5411 * <li>{@link Settings.Global#AUTO_TIME}</li>
5412 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005413 * <li>{@link Settings.Global#DATA_ROAMING}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005414 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005415 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005416 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN} This setting is only available from
5417 * {@link android.os.Build.VERSION_CODES#M} onwards and can only be set if
5418 * {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
5419 * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li> This setting is only
5420 * available from {@link android.os.Build.VERSION_CODES#M} onwards.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005421 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005422 * <p>
5423 * Changing the following settings has no effect as of {@link android.os.Build.VERSION_CODES#M}:
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005424 * <ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005425 * <li>{@link Settings.Global#BLUETOOTH_ON}. Use
5426 * {@link android.bluetooth.BluetoothAdapter#enable()} and
5427 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005428 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005429 * <li>{@link Settings.Global#MODE_RINGER}. Use
5430 * {@link android.media.AudioManager#setRingerMode(int)} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005431 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005432 * <li>{@link Settings.Global#WIFI_ON}. Use
5433 * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005434 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04005435 *
5436 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5437 * @param setting The name of the setting to update.
5438 * @param value The value to update the setting to.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005439 * @throws SecurityException if {@code admin} is not a device owner.
Julia Reynoldsda551652014-05-14 17:15:16 -04005440 */
Robin Lee25e26452015-06-02 09:56:29 -07005441 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005442 throwIfParentInstance("setGlobalSetting");
Julia Reynoldsda551652014-05-14 17:15:16 -04005443 if (mService != null) {
5444 try {
5445 mService.setGlobalSetting(admin, setting, value);
5446 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005447 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04005448 }
5449 }
5450 }
5451
5452 /**
5453 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
5454 * that the value of the setting is in the correct form for the setting type should be performed
5455 * by the caller.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005456 * <p>
5457 * The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005458 * <ul>
5459 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07005460 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005461 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
5462 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005463 * <p>
5464 * A device owner can additionally update the following settings:
Julia Reynolds82735bc2014-09-04 16:43:30 -04005465 * <ul>
5466 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
5467 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005468 *
Julia Reynoldsda551652014-05-14 17:15:16 -04005469 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5470 * @param setting The name of the setting to update.
5471 * @param value The value to update the setting to.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005472 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynoldsda551652014-05-14 17:15:16 -04005473 */
Robin Lee25e26452015-06-02 09:56:29 -07005474 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005475 throwIfParentInstance("setSecureSetting");
Julia Reynoldsda551652014-05-14 17:15:16 -04005476 if (mService != null) {
5477 try {
5478 mService.setSecureSetting(admin, setting, value);
5479 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005480 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04005481 }
5482 }
5483 }
5484
Amith Yamasanif20d6402014-05-24 15:34:37 -07005485 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005486 * Designates a specific service component as the provider for making permission requests of a
5487 * local or remote administrator of the user.
Amith Yamasanif20d6402014-05-24 15:34:37 -07005488 * <p/>
5489 * Only a profile owner can designate the restrictions provider.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005490 *
Amith Yamasanif20d6402014-05-24 15:34:37 -07005491 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07005492 * @param provider The component name of the service that implements
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005493 * {@link RestrictionsReceiver}. If this param is null, it removes the restrictions
5494 * provider previously assigned.
5495 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanif20d6402014-05-24 15:34:37 -07005496 */
Robin Lee25e26452015-06-02 09:56:29 -07005497 public void setRestrictionsProvider(@NonNull ComponentName admin,
5498 @Nullable ComponentName provider) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005499 throwIfParentInstance("setRestrictionsProvider");
Amith Yamasanif20d6402014-05-24 15:34:37 -07005500 if (mService != null) {
5501 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07005502 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07005503 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005504 throw re.rethrowFromSystemServer();
Amith Yamasanif20d6402014-05-24 15:34:37 -07005505 }
5506 }
5507 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04005508
5509 /**
5510 * Called by profile or device owners to set the master volume mute on or off.
Nicolas Prevotaef3ce22016-09-22 12:00:25 +01005511 * This has no effect when set on a managed profile.
Julia Reynolds4a21b252014-06-04 11:11:43 -04005512 *
5513 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5514 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005515 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds4a21b252014-06-04 11:11:43 -04005516 */
Robin Lee25e26452015-06-02 09:56:29 -07005517 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005518 throwIfParentInstance("setMasterVolumeMuted");
Julia Reynolds4a21b252014-06-04 11:11:43 -04005519 if (mService != null) {
5520 try {
5521 mService.setMasterVolumeMuted(admin, on);
5522 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005523 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04005524 }
5525 }
5526 }
5527
5528 /**
5529 * Called by profile or device owners to check whether the master volume mute is on or off.
5530 *
5531 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5532 * @return {@code true} if master volume is muted, {@code false} if it's not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005533 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds4a21b252014-06-04 11:11:43 -04005534 */
Robin Lee25e26452015-06-02 09:56:29 -07005535 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005536 throwIfParentInstance("isMasterVolumeMuted");
Julia Reynolds4a21b252014-06-04 11:11:43 -04005537 if (mService != null) {
5538 try {
5539 return mService.isMasterVolumeMuted(admin);
5540 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005541 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04005542 }
5543 }
5544 return false;
5545 }
Kenny Guyc13053b2014-05-29 14:17:17 +01005546
5547 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005548 * Called by profile or device owners to change whether a user can uninstall a package.
Kenny Guyc13053b2014-05-29 14:17:17 +01005549 *
5550 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5551 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01005552 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005553 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyc13053b2014-05-29 14:17:17 +01005554 */
Robin Lee25e26452015-06-02 09:56:29 -07005555 public void setUninstallBlocked(@NonNull ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01005556 boolean uninstallBlocked) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005557 throwIfParentInstance("setUninstallBlocked");
Kenny Guyc13053b2014-05-29 14:17:17 +01005558 if (mService != null) {
5559 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01005560 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01005561 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005562 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01005563 }
5564 }
5565 }
5566
5567 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005568 * Check whether the user has been blocked by device policy from uninstalling a package.
Rubin Xua97855b2014-11-07 05:41:00 +00005569 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00005570 * <p>
5571 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005572 * behavior of this API is changed such that passing {@code null} as the {@code admin} parameter
5573 * will return if any admin has blocked the uninstallation. Before L MR1, passing {@code null}
5574 * will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01005575 *
Robin Lee25e26452015-06-02 09:56:29 -07005576 * @param admin The name of the admin component whose blocking policy will be checked, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005577 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01005578 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00005579 * @return true if uninstallation is blocked.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005580 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyc13053b2014-05-29 14:17:17 +01005581 */
Robin Lee25e26452015-06-02 09:56:29 -07005582 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005583 throwIfParentInstance("isUninstallBlocked");
Kenny Guyc13053b2014-05-29 14:17:17 +01005584 if (mService != null) {
5585 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01005586 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01005587 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005588 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01005589 }
5590 }
5591 return false;
5592 }
Svetoslav976e8bd2014-07-16 15:12:03 -07005593
5594 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005595 * Called by the profile owner of a managed profile to enable widget providers from a given
5596 * package to be available in the parent profile. As a result the user will be able to add
5597 * widgets from the white-listed package running under the profile to a widget host which runs
5598 * under the parent profile, for example the home screen. Note that a package may have zero or
5599 * more provider components, where each component provides a different widget type.
Svetoslav976e8bd2014-07-16 15:12:03 -07005600 * <p>
5601 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07005602 *
5603 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5604 * @param packageName The package from which widget providers are white-listed.
5605 * @return Whether the package was added.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005606 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07005607 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
5608 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
5609 */
Robin Lee25e26452015-06-02 09:56:29 -07005610 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005611 throwIfParentInstance("addCrossProfileWidgetProvider");
Svetoslav976e8bd2014-07-16 15:12:03 -07005612 if (mService != null) {
5613 try {
5614 return mService.addCrossProfileWidgetProvider(admin, packageName);
5615 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005616 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07005617 }
5618 }
5619 return false;
5620 }
5621
5622 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005623 * Called by the profile owner of a managed profile to disable widget providers from a given
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005624 * package to be available in the parent profile. For this method to take effect the package
5625 * should have been added via
5626 * {@link #addCrossProfileWidgetProvider( android.content.ComponentName, String)}.
Svetoslav976e8bd2014-07-16 15:12:03 -07005627 * <p>
5628 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07005629 *
5630 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005631 * @param packageName The package from which widget providers are no longer white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07005632 * @return Whether the package was removed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005633 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07005634 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
5635 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
5636 */
Esteban Talavera62399912016-01-11 15:37:55 +00005637 public boolean removeCrossProfileWidgetProvider(
5638 @NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005639 throwIfParentInstance("removeCrossProfileWidgetProvider");
Svetoslav976e8bd2014-07-16 15:12:03 -07005640 if (mService != null) {
5641 try {
5642 return mService.removeCrossProfileWidgetProvider(admin, packageName);
5643 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005644 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07005645 }
5646 }
5647 return false;
5648 }
5649
5650 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005651 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07005652 * available in the parent profile.
5653 *
5654 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5655 * @return The white-listed package list.
Svetoslav976e8bd2014-07-16 15:12:03 -07005656 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
5657 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005658 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07005659 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005660 public @NonNull List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005661 throwIfParentInstance("getCrossProfileWidgetProviders");
Svetoslav976e8bd2014-07-16 15:12:03 -07005662 if (mService != null) {
5663 try {
5664 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
5665 if (providers != null) {
5666 return providers;
5667 }
5668 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005669 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07005670 }
5671 }
5672 return Collections.emptyList();
5673 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005674
5675 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005676 * Called by profile or device owners to set the user's photo.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005677 *
5678 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5679 * @param icon the bitmap to set as the photo.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005680 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005681 */
Robin Lee25e26452015-06-02 09:56:29 -07005682 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005683 throwIfParentInstance("setUserIcon");
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005684 try {
5685 mService.setUserIcon(admin, icon);
5686 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005687 throw re.rethrowFromSystemServer();
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005688 }
5689 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04005690
5691 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01005692 * Called by device owners to set a local system update policy. When a new policy is set,
5693 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00005694 *
Robin Lee25e26452015-06-02 09:56:29 -07005695 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005696 * components in the device owner package can set system update policies and the most
5697 * recent policy takes effect.
Robin Lee25e26452015-06-02 09:56:29 -07005698 * @param policy the new policy, or {@code null} to clear the current policy.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005699 * @throws SecurityException if {@code admin} is not a device owner.
Rubin Xu5faad8e2015-04-20 17:43:48 +01005700 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00005701 */
Robin Lee25e26452015-06-02 09:56:29 -07005702 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005703 throwIfParentInstance("setSystemUpdatePolicy");
Rubin Xu8027a4f2015-03-10 17:52:37 +00005704 if (mService != null) {
5705 try {
Robin Lee25e26452015-06-02 09:56:29 -07005706 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00005707 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005708 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00005709 }
5710 }
5711 }
5712
5713 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01005714 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00005715 *
Robin Lee25e26452015-06-02 09:56:29 -07005716 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00005717 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005718 public @Nullable SystemUpdatePolicy getSystemUpdatePolicy() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005719 throwIfParentInstance("getSystemUpdatePolicy");
Rubin Xu8027a4f2015-03-10 17:52:37 +00005720 if (mService != null) {
5721 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01005722 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00005723 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005724 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00005725 }
5726 }
5727 return null;
5728 }
Benjamin Franze36087e2015-04-07 16:40:34 +01005729
5730 /**
5731 * Called by a device owner to disable the keyguard altogether.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005732 * <p>
5733 * Setting the keyguard to disabled has the same effect as choosing "None" as the screen lock
5734 * type. However, this call has no effect if a password, pin or pattern is currently set. If a
5735 * password, pin or pattern is set after the keyguard was disabled, the keyguard stops being
5736 * disabled.
Benjamin Franze36087e2015-04-07 16:40:34 +01005737 *
5738 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01005739 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01005740 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005741 * place. {@code true} otherwise.
5742 * @throws SecurityException if {@code admin} is not a device owner.
Benjamin Franze36087e2015-04-07 16:40:34 +01005743 */
Robin Lee25e26452015-06-02 09:56:29 -07005744 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005745 throwIfParentInstance("setKeyguardDisabled");
Benjamin Franze36087e2015-04-07 16:40:34 +01005746 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01005747 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01005748 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005749 throw re.rethrowFromSystemServer();
Benjamin Franze36087e2015-04-07 16:40:34 +01005750 }
5751 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00005752
5753 /**
Benjamin Franzbece8062015-05-06 12:14:31 +01005754 * Called by device owner to disable the status bar. Disabling the status bar blocks
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005755 * notifications, quick settings and other screen overlays that allow escaping from a single use
5756 * device.
Benjamin Franzea2ec972015-03-16 17:18:09 +00005757 *
5758 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01005759 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005760 * @return {@code false} if attempting to disable the status bar failed. {@code true} otherwise.
5761 * @throws SecurityException if {@code admin} is not a device owner.
Benjamin Franzea2ec972015-03-16 17:18:09 +00005762 */
Robin Lee25e26452015-06-02 09:56:29 -07005763 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005764 throwIfParentInstance("setStatusBarDisabled");
Benjamin Franzea2ec972015-03-16 17:18:09 +00005765 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01005766 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00005767 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005768 throw re.rethrowFromSystemServer();
Benjamin Franzea2ec972015-03-16 17:18:09 +00005769 }
5770 }
Rubin Xudc105cc2015-04-14 23:38:01 +01005771
5772 /**
5773 * Callable by the system update service to notify device owners about pending updates.
5774 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
5775 * permission.
5776 *
5777 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating
5778 * when the current pending update was first available. -1 if no update is available.
5779 * @hide
5780 */
5781 @SystemApi
5782 public void notifyPendingSystemUpdate(long updateReceivedTime) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005783 throwIfParentInstance("notifyPendingSystemUpdate");
Rubin Xudc105cc2015-04-14 23:38:01 +01005784 if (mService != null) {
5785 try {
5786 mService.notifyPendingSystemUpdate(updateReceivedTime);
5787 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005788 throw re.rethrowFromSystemServer();
Rubin Xudc105cc2015-04-14 23:38:01 +01005789 }
5790 }
5791 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04005792
5793 /**
Amith Yamasanid49489b2015-04-28 14:00:26 -07005794 * Called by profile or device owners to set the default response for future runtime permission
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005795 * requests by applications. The policy can allow for normal operation which prompts the user to
5796 * grant a permission, or can allow automatic granting or denying of runtime permission requests
5797 * by an application. This also applies to new permissions declared by app updates. When a
5798 * permission is denied or granted this way, the effect is equivalent to setting the permission
5799 * grant state via {@link #setPermissionGrantState}.
5800 * <p/>
5801 * As this policy only acts on runtime permission requests, it only applies to applications
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005802 * built with a {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Benjamin Franz45dd6662015-07-08 14:24:14 +01005803 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07005804 * @param admin Which profile or device owner this request is associated with.
5805 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005806 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
5807 * @throws SecurityException if {@code admin} is not a device or profile owner.
Benjamin Franz45dd6662015-07-08 14:24:14 +01005808 * @see #setPermissionGrantState
Amith Yamasanid49489b2015-04-28 14:00:26 -07005809 */
Robin Lee25e26452015-06-02 09:56:29 -07005810 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005811 throwIfParentInstance("setPermissionPolicy");
Amith Yamasanid49489b2015-04-28 14:00:26 -07005812 try {
5813 mService.setPermissionPolicy(admin, policy);
5814 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005815 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07005816 }
5817 }
5818
5819 /**
5820 * Returns the current runtime permission policy set by the device or profile owner. The
5821 * default is {@link #PERMISSION_POLICY_PROMPT}.
5822 * @param admin Which profile or device owner this request is associated with.
5823 * @return the current policy for future permission requests.
5824 */
Esteban Talavera28b95702015-06-24 15:23:42 +01005825 public int getPermissionPolicy(ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005826 throwIfParentInstance("getPermissionPolicy");
Amith Yamasanid49489b2015-04-28 14:00:26 -07005827 try {
5828 return mService.getPermissionPolicy(admin);
5829 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005830 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07005831 }
5832 }
5833
5834 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005835 * Sets the grant state of a runtime permission for a specific application. The state can be
5836 * {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it through the UI,
5837 * {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission is denied and the user
5838 * cannot manage it through the UI, and {@link #PERMISSION_GRANT_STATE_GRANTED granted} in which
5839 * the permission is granted and the user cannot manage it through the UI. This might affect all
5840 * permissions in a group that the runtime permission belongs to. This method can only be called
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005841 * by a profile or device owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005842 * <p/>
5843 * Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not revoke
5844 * the permission. It retains the previous grant, if any.
5845 * <p/>
5846 * Permissions can be granted or revoked only for applications built with a
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005847 * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07005848 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07005849 * @param admin Which profile or device owner this request is associated with.
5850 * @param packageName The application to grant or revoke a permission to.
5851 * @param permission The permission to grant or revoke.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005852 * @param grantState The permission grant state which is one of
5853 * {@link #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
5854 * {@link #PERMISSION_GRANT_STATE_GRANTED},
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005855 * @return whether the permission was successfully granted or revoked.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005856 * @throws SecurityException if {@code admin} is not a device or profile owner.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005857 * @see #PERMISSION_GRANT_STATE_DENIED
5858 * @see #PERMISSION_GRANT_STATE_DEFAULT
5859 * @see #PERMISSION_GRANT_STATE_GRANTED
Amith Yamasanid49489b2015-04-28 14:00:26 -07005860 */
Robin Lee25e26452015-06-02 09:56:29 -07005861 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005862 String permission, int grantState) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005863 throwIfParentInstance("setPermissionGrantState");
Amith Yamasanid49489b2015-04-28 14:00:26 -07005864 try {
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005865 return mService.setPermissionGrantState(admin, packageName, permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07005866 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005867 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07005868 }
5869 }
Amith Yamasani184b3752015-05-22 13:00:51 -07005870
5871 /**
5872 * Returns the current grant state of a runtime permission for a specific application.
5873 *
5874 * @param admin Which profile or device owner this request is associated with.
5875 * @param packageName The application to check the grant state for.
5876 * @param permission The permission to check for.
5877 * @return the current grant state specified by device policy. If the profile or device owner
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005878 * has not set a grant state, the return value is
5879 * {@link #PERMISSION_GRANT_STATE_DEFAULT}. This does not indicate whether or not the
5880 * permission is currently granted for the package.
5881 * <p/>
5882 * If a grant state was set by the profile or device owner, then the return value will
5883 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or
5884 * {@link #PERMISSION_GRANT_STATE_GRANTED}, which indicates if the permission is
5885 * currently denied or granted.
5886 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasani184b3752015-05-22 13:00:51 -07005887 * @see #setPermissionGrantState(ComponentName, String, String, int)
5888 * @see PackageManager#checkPermission(String, String)
5889 */
Robin Lee25e26452015-06-02 09:56:29 -07005890 public int getPermissionGrantState(@NonNull ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07005891 String permission) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005892 throwIfParentInstance("getPermissionGrantState");
Amith Yamasani184b3752015-05-22 13:00:51 -07005893 try {
5894 return mService.getPermissionGrantState(admin, packageName, permission);
5895 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005896 throw re.rethrowFromSystemServer();
Amith Yamasani184b3752015-05-22 13:00:51 -07005897 }
5898 }
Nicolas Prevot07387fe2015-10-30 17:53:30 +00005899
5900 /**
5901 * Returns if provisioning a managed profile or device is possible or not.
5902 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
5903 * {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Nicolas Prevot07387fe2015-10-30 17:53:30 +00005904 * @return if provisioning a managed profile or device is possible or not.
5905 * @throws IllegalArgumentException if the supplied action is not valid.
5906 */
5907 public boolean isProvisioningAllowed(String action) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005908 throwIfParentInstance("isProvisioningAllowed");
Nicolas Prevot07387fe2015-10-30 17:53:30 +00005909 try {
5910 return mService.isProvisioningAllowed(action);
5911 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005912 throw re.rethrowFromSystemServer();
Nicolas Prevot07387fe2015-10-30 17:53:30 +00005913 }
5914 }
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005915
5916 /**
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005917 * Return if this user is a managed profile of another user. An admin can become the profile
5918 * owner of a managed profile with {@link #ACTION_PROVISION_MANAGED_PROFILE} and of a managed
Kenny Guyffa38402016-03-31 16:40:57 +01005919 * user with {@link #createAndManageUser}
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005920 * @param admin Which profile owner this request is associated with.
5921 * @return if this user is a managed profile of another user.
5922 */
5923 public boolean isManagedProfile(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005924 throwIfParentInstance("isManagedProfile");
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005925 try {
5926 return mService.isManagedProfile(admin);
5927 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005928 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005929 }
5930 }
5931
5932 /**
5933 * @hide
5934 * Return if this user is a system-only user. An admin can manage a device from a system only
5935 * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}.
5936 * @param admin Which device owner this request is associated with.
5937 * @return if this user is a system-only user.
5938 */
5939 public boolean isSystemOnlyUser(@NonNull ComponentName admin) {
5940 try {
5941 return mService.isSystemOnlyUser(admin);
5942 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005943 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005944 }
5945 }
Makoto Onukia31ebbc2015-11-23 17:15:21 -08005946
5947 /**
5948 * Called by device owner to get the MAC address of the Wi-Fi device.
5949 *
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08005950 * @param admin Which device owner this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005951 * @return the MAC address of the Wi-Fi device, or null when the information is not available.
5952 * (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.)
5953 * <p>
5954 * The address will be in the {@code XX:XX:XX:XX:XX:XX} format.
5955 * @throws SecurityException if {@code admin} is not a device owner.
Makoto Onukia31ebbc2015-11-23 17:15:21 -08005956 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005957 public @Nullable String getWifiMacAddress(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005958 throwIfParentInstance("getWifiMacAddress");
Makoto Onukia31ebbc2015-11-23 17:15:21 -08005959 try {
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08005960 return mService.getWifiMacAddress(admin);
Makoto Onukia31ebbc2015-11-23 17:15:21 -08005961 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005962 throw re.rethrowFromSystemServer();
Makoto Onukia31ebbc2015-11-23 17:15:21 -08005963 }
5964 }
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00005965
5966 /**
Mahaver Chopra1216ae52016-03-11 15:39:48 +00005967 * Called by device owner to reboot the device. If there is an ongoing call on the device,
5968 * throws an {@link IllegalStateException}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005969 * @param admin Which device owner the request is associated with.
Mahaver Chopra1216ae52016-03-11 15:39:48 +00005970 * @throws IllegalStateException if device has an ongoing call.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005971 * @throws SecurityException if {@code admin} is not a device owner.
Mahaver Chopra1216ae52016-03-11 15:39:48 +00005972 * @see TelephonyManager#CALL_STATE_IDLE
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00005973 */
5974 public void reboot(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005975 throwIfParentInstance("reboot");
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00005976 try {
5977 mService.reboot(admin);
5978 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005979 throw re.rethrowFromSystemServer();
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00005980 }
5981 }
Kenny Guy06de4e72015-12-22 12:07:39 +00005982
5983 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005984 * Called by a device admin to set the short support message. This will be displayed to the user
5985 * in settings screens where funtionality has been disabled by the admin. The message should be
5986 * limited to a short statement such as "This setting is disabled by your administrator. Contact
5987 * someone@example.com for support." If the message is longer than 200 characters it may be
5988 * truncated.
5989 * <p>
5990 * If the short support message needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00005991 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
5992 * and set a new version of this string accordingly.
5993 *
Kenny Guy06de4e72015-12-22 12:07:39 +00005994 * @see #setLongSupportMessage
Kenny Guy06de4e72015-12-22 12:07:39 +00005995 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005996 * @param message Short message to be displayed to the user in settings or null to clear the
5997 * existing message.
5998 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00005999 */
6000 public void setShortSupportMessage(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006001 @Nullable CharSequence message) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006002 throwIfParentInstance("setShortSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00006003 if (mService != null) {
6004 try {
6005 mService.setShortSupportMessage(admin, message);
6006 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006007 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006008 }
6009 }
6010 }
6011
6012 /**
6013 * Called by a device admin to get the short support message.
6014 *
6015 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006016 * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)} or
6017 * null if no message has been set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006018 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00006019 */
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006020 public CharSequence getShortSupportMessage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006021 throwIfParentInstance("getShortSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00006022 if (mService != null) {
6023 try {
6024 return mService.getShortSupportMessage(admin);
6025 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006026 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006027 }
6028 }
6029 return null;
6030 }
6031
6032 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006033 * Called by a device admin to set the long support message. This will be displayed to the user
6034 * in the device administators settings screen.
6035 * <p>
6036 * If the long support message needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006037 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
6038 * and set a new version of this string accordingly.
6039 *
Kenny Guy06de4e72015-12-22 12:07:39 +00006040 * @see #setShortSupportMessage
Kenny Guy06de4e72015-12-22 12:07:39 +00006041 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006042 * @param message Long message to be displayed to the user in settings or null to clear the
6043 * existing message.
6044 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00006045 */
6046 public void setLongSupportMessage(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006047 @Nullable CharSequence message) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006048 throwIfParentInstance("setLongSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00006049 if (mService != null) {
6050 try {
6051 mService.setLongSupportMessage(admin, message);
6052 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006053 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006054 }
6055 }
6056 }
6057
6058 /**
6059 * Called by a device admin to get the long support message.
6060 *
6061 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006062 * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)} or
6063 * null if no message has been set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006064 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00006065 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006066 public @Nullable CharSequence getLongSupportMessage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006067 throwIfParentInstance("getLongSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00006068 if (mService != null) {
6069 try {
6070 return mService.getLongSupportMessage(admin);
6071 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006072 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006073 }
6074 }
6075 return null;
6076 }
6077
6078 /**
6079 * Called by the system to get the short support message.
6080 *
6081 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6082 * @param userHandle user id the admin is running as.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006083 * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)}
Kenny Guy06de4e72015-12-22 12:07:39 +00006084 *
6085 * @hide
6086 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006087 public @Nullable CharSequence getShortSupportMessageForUser(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006088 int userHandle) {
Kenny Guy06de4e72015-12-22 12:07:39 +00006089 if (mService != null) {
6090 try {
6091 return mService.getShortSupportMessageForUser(admin, userHandle);
6092 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006093 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006094 }
6095 }
6096 return null;
6097 }
6098
6099
6100 /**
6101 * Called by the system to get the long support message.
6102 *
6103 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6104 * @param userHandle user id the admin is running as.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006105 * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)}
Kenny Guy06de4e72015-12-22 12:07:39 +00006106 *
6107 * @hide
6108 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006109 public @Nullable CharSequence getLongSupportMessageForUser(
6110 @NonNull ComponentName admin, int userHandle) {
Kenny Guy06de4e72015-12-22 12:07:39 +00006111 if (mService != null) {
6112 try {
6113 return mService.getLongSupportMessageForUser(admin, userHandle);
6114 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006115 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006116 }
6117 }
6118 return null;
6119 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006120
6121 /**
Esteban Talavera62399912016-01-11 15:37:55 +00006122 * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager}
6123 * whose calls act on the parent profile.
Benjamin Franz66b45f02016-04-05 19:12:39 +01006124 *
6125 * <p>The following methods are supported for the parent instance, all other methods will
6126 * throw a SecurityException when called on the parent instance:
6127 * <ul>
6128 * <li>{@link #getPasswordQuality}</li>
6129 * <li>{@link #setPasswordQuality}</li>
6130 * <li>{@link #getPasswordMinimumLength}</li>
6131 * <li>{@link #setPasswordMinimumLength}</li>
6132 * <li>{@link #getPasswordMinimumUpperCase}</li>
6133 * <li>{@link #setPasswordMinimumUpperCase}</li>
6134 * <li>{@link #getPasswordMinimumLowerCase}</li>
6135 * <li>{@link #setPasswordMinimumLowerCase}</li>
6136 * <li>{@link #getPasswordMinimumLetters}</li>
6137 * <li>{@link #setPasswordMinimumLetters}</li>
6138 * <li>{@link #getPasswordMinimumNumeric}</li>
6139 * <li>{@link #setPasswordMinimumNumeric}</li>
6140 * <li>{@link #getPasswordMinimumSymbols}</li>
6141 * <li>{@link #setPasswordMinimumSymbols}</li>
6142 * <li>{@link #getPasswordMinimumNonLetter}</li>
6143 * <li>{@link #setPasswordMinimumNonLetter}</li>
6144 * <li>{@link #getPasswordHistoryLength}</li>
6145 * <li>{@link #setPasswordHistoryLength}</li>
6146 * <li>{@link #getPasswordExpirationTimeout}</li>
6147 * <li>{@link #setPasswordExpirationTimeout}</li>
6148 * <li>{@link #getPasswordExpiration}</li>
Charles He8c760562016-10-25 16:36:53 +01006149 * <li>{@link #getPasswordMaximumLength}</li>
Benjamin Franz66b45f02016-04-05 19:12:39 +01006150 * <li>{@link #isActivePasswordSufficient}</li>
6151 * <li>{@link #getCurrentFailedPasswordAttempts}</li>
6152 * <li>{@link #getMaximumFailedPasswordsForWipe}</li>
6153 * <li>{@link #setMaximumFailedPasswordsForWipe}</li>
6154 * <li>{@link #getMaximumTimeToLock}</li>
6155 * <li>{@link #setMaximumTimeToLock}</li>
6156 * <li>{@link #lockNow}</li>
6157 * <li>{@link #getKeyguardDisabledFeatures}</li>
6158 * <li>{@link #setKeyguardDisabledFeatures}</li>
6159 * <li>{@link #getTrustAgentConfiguration}</li>
6160 * <li>{@link #setTrustAgentConfiguration}</li>
6161 * </ul>
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006162 *
6163 * @return a new instance of {@link DevicePolicyManager} that acts on the parent profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006164 * @throws SecurityException if {@code admin} is not a profile owner.
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006165 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006166 public @NonNull DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006167 throwIfParentInstance("getParentProfileInstance");
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006168 try {
6169 if (!mService.isManagedProfile(admin)) {
6170 throw new SecurityException("The current user does not have a parent profile.");
6171 }
Jeff Sharkey49ca5292016-05-10 12:54:45 -06006172 return new DevicePolicyManager(mContext, mService, true);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006173 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006174 throw e.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006175 }
6176 }
6177
6178 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00006179 * Called by device owner to control the security logging feature. Logging can only be
6180 * enabled on single user devices where the sole user is managed by the device owner.
6181 *
6182 * <p> Security logs contain various information intended for security auditing purposes.
6183 * See {@link SecurityEvent} for details.
6184 *
6185 * <p>There must be only one user on the device, managed by the device owner.
6186 * Otherwise a {@link SecurityException} will be thrown.
Michal Karpinskib58e4962016-03-01 14:55:10 +00006187 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006188 * @param admin Which device owner this request is associated with.
Michal Karpinski6235a942016-03-15 12:07:23 +00006189 * @param enabled whether security logging should be enabled or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006190 * @throws SecurityException if {@code admin} is not a device owner.
Michal Karpinski6235a942016-03-15 12:07:23 +00006191 * @see #retrieveSecurityLogs
6192 */
6193 public void setSecurityLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006194 throwIfParentInstance("setSecurityLoggingEnabled");
Michal Karpinski6235a942016-03-15 12:07:23 +00006195 try {
6196 mService.setSecurityLoggingEnabled(admin, enabled);
6197 } catch (RemoteException re) {
6198 throw re.rethrowFromSystemServer();
6199 }
6200 }
6201
6202 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00006203 * Return whether security logging is enabled or not by the device owner.
6204 *
6205 * <p>Can only be called by the device owner, otherwise a {@link SecurityException} will be
6206 * thrown.
6207 *
6208 * @param admin Which device owner this request is associated with.
6209 * @return {@code true} if security logging is enabled by device owner, {@code false} otherwise.
6210 * @throws SecurityException if {@code admin} is not a device owner.
6211 */
6212 public boolean isSecurityLoggingEnabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006213 throwIfParentInstance("isSecurityLoggingEnabled");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006214 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00006215 return mService.isSecurityLoggingEnabled(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006216 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006217 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006218 }
6219 }
6220
6221 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00006222 * Called by device owner to retrieve all new security logging entries since the last call to
6223 * this API after device boots.
6224 *
6225 * <p> Access to the logs is rate limited and it will only return new logs after the device
6226 * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}.
6227 *
6228 * <p>There must be only one user on the device, managed by the device owner.
6229 * Otherwise a {@link SecurityException} will be thrown.
Michal Karpinskib58e4962016-03-01 14:55:10 +00006230 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006231 * @param admin Which device owner this request is associated with.
Michal Karpinski6235a942016-03-15 12:07:23 +00006232 * @return the new batch of security logs which is a list of {@link SecurityEvent},
6233 * or {@code null} if rate limitation is exceeded or if logging is currently disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006234 * @throws SecurityException if {@code admin} is not a device owner.
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006235 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006236 public @Nullable List<SecurityEvent> retrieveSecurityLogs(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006237 throwIfParentInstance("retrieveSecurityLogs");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006238 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00006239 ParceledListSlice<SecurityEvent> list = mService.retrieveSecurityLogs(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006240 if (list != null) {
6241 return list.getList();
6242 } else {
6243 // Rate limit exceeded.
6244 return null;
6245 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006246 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006247 throw re.rethrowFromSystemServer();
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006248 }
6249 }
Benjamin Franz59720bb2016-01-18 15:26:11 +00006250
6251 /**
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00006252 * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent
6253 * profile.
6254 *
6255 * @hide
6256 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006257 public @NonNull DevicePolicyManager getParentProfileInstance(UserInfo uInfo) {
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00006258 mContext.checkSelfPermission(
6259 android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS);
6260 if (!uInfo.isManagedProfile()) {
6261 throw new SecurityException("The user " + uInfo.id
6262 + " does not have a parent profile.");
6263 }
Jeff Sharkey49ca5292016-05-10 12:54:45 -06006264 return new DevicePolicyManager(mContext, mService, true);
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00006265 }
6266
6267 /**
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006268 * Called by device owners to retrieve device logs from before the device's last reboot.
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006269 * <p>
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01006270 * <strong> This API is not supported on all devices. Calling this API on unsupported devices
6271 * will result in {@code null} being returned. The device logs are retrieved from a RAM region
6272 * which is not guaranteed to be corruption-free during power cycles, as a result be cautious
6273 * about data corruption when parsing. </strong>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006274 * <p>
6275 * There must be only one user on the device, managed by the device owner. Otherwise a
6276 * {@link SecurityException} will be thrown.
Michal Karpinskib58e4962016-03-01 14:55:10 +00006277 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006278 * @param admin Which device owner this request is associated with.
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01006279 * @return Device logs from before the latest reboot of the system, or {@code null} if this API
6280 * is not supported on the device.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006281 * @throws SecurityException if {@code admin} is not a device owner.
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006282 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006283 public @Nullable List<SecurityEvent> retrievePreRebootSecurityLogs(
6284 @NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006285 throwIfParentInstance("retrievePreRebootSecurityLogs");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006286 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00006287 ParceledListSlice<SecurityEvent> list = mService.retrievePreRebootSecurityLogs(admin);
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01006288 if (list != null) {
6289 return list.getList();
6290 } else {
6291 return null;
6292 }
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006293 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006294 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006295 }
6296 }
6297
6298 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006299 * Called by a profile owner of a managed profile to set the color used for customization. This
6300 * color is used as background color of the confirm credentials screen for that user. The
Clara Bayarri8d0bd7fa2016-03-30 14:59:58 +01006301 * default color is teal (#00796B).
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006302 * <p>
6303 * The confirm credentials screen can be created using
Benjamin Franz59720bb2016-01-18 15:26:11 +00006304 * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}.
6305 *
6306 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinski74cd7302016-04-12 15:17:36 +01006307 * @param color The 24bit (0xRRGGBB) representation of the color to be used.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006308 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz59720bb2016-01-18 15:26:11 +00006309 */
6310 public void setOrganizationColor(@NonNull ComponentName admin, int color) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006311 throwIfParentInstance("setOrganizationColor");
Benjamin Franz59720bb2016-01-18 15:26:11 +00006312 try {
Michal Karpinski74cd7302016-04-12 15:17:36 +01006313 // always enforce alpha channel to have 100% opacity
6314 color |= 0xFF000000;
Benjamin Franz59720bb2016-01-18 15:26:11 +00006315 mService.setOrganizationColor(admin, color);
6316 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006317 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00006318 }
6319 }
6320
6321 /**
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00006322 * @hide
6323 *
6324 * Sets the color used for customization.
6325 *
Michal Karpinski74cd7302016-04-12 15:17:36 +01006326 * @param color The 24bit (0xRRGGBB) representation of the color to be used.
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00006327 * @param userId which user to set the color to.
6328 * @RequiresPermission(allOf = {
6329 * Manifest.permission.MANAGE_USERS,
6330 * Manifest.permission.INTERACT_ACROSS_USERS_FULL})
6331 */
6332 public void setOrganizationColorForUser(@ColorInt int color, @UserIdInt int userId) {
6333 try {
Michal Karpinski74cd7302016-04-12 15:17:36 +01006334 // always enforce alpha channel to have 100% opacity
6335 color |= 0xFF000000;
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00006336 mService.setOrganizationColorForUser(color, userId);
6337 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006338 throw re.rethrowFromSystemServer();
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00006339 }
6340 }
6341
6342 /**
Benjamin Franz59720bb2016-01-18 15:26:11 +00006343 * Called by a profile owner of a managed profile to retrieve the color used for customization.
6344 * This color is used as background color of the confirm credentials screen for that user.
6345 *
6346 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinski74cd7302016-04-12 15:17:36 +01006347 * @return The 24bit (0xRRGGBB) representation of the color to be used.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006348 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz59720bb2016-01-18 15:26:11 +00006349 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01006350 public @ColorInt int getOrganizationColor(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006351 throwIfParentInstance("getOrganizationColor");
Benjamin Franz59720bb2016-01-18 15:26:11 +00006352 try {
6353 return mService.getOrganizationColor(admin);
6354 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006355 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00006356 }
6357 }
6358
6359 /**
6360 * @hide
6361 * Retrieve the customization color for a given user.
6362 *
6363 * @param userHandle The user id of the user we're interested in.
Michal Karpinski74cd7302016-04-12 15:17:36 +01006364 * @return The 24bit (0xRRGGBB) representation of the color to be used.
Benjamin Franz59720bb2016-01-18 15:26:11 +00006365 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01006366 public @ColorInt int getOrganizationColorForUser(int userHandle) {
Benjamin Franz59720bb2016-01-18 15:26:11 +00006367 try {
6368 return mService.getOrganizationColorForUser(userHandle);
6369 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006370 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00006371 }
6372 }
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006373
6374 /**
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006375 * Called by a profile owner of a managed profile to set the name of the organization under
6376 * management.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006377 * <p>
6378 * If the organization name needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006379 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
6380 * and set a new version of this string accordingly.
6381 *
6382 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6383 * @param title The organization name or {@code null} to clear a previously set name.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006384 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006385 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01006386 public void setOrganizationName(@NonNull ComponentName admin, @Nullable CharSequence title) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006387 throwIfParentInstance("setOrganizationName");
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006388 try {
6389 mService.setOrganizationName(admin, title);
6390 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006391 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006392 }
6393 }
6394
6395 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006396 * Called by a profile owner of a managed profile to retrieve the name of the organization under
6397 * management.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006398 *
6399 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6400 * @return The organization name or {@code null} if none is set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006401 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006402 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006403 public @Nullable CharSequence getOrganizationName(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006404 throwIfParentInstance("getOrganizationName");
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006405 try {
6406 return mService.getOrganizationName(admin);
6407 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006408 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006409 }
6410 }
6411
6412 /**
6413 * Retrieve the default title message used in the confirm credentials screen for a given user.
6414 *
6415 * @param userHandle The user id of the user we're interested in.
6416 * @return The organization name or {@code null} if none is set.
6417 *
6418 * @hide
6419 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006420 public @Nullable CharSequence getOrganizationNameForUser(int userHandle) {
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006421 try {
6422 return mService.getOrganizationNameForUser(userHandle);
6423 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006424 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006425 }
6426 }
6427
6428 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00006429 * @return the {@link UserProvisioningState} for the current user - for unmanaged users will
6430 * return {@link #STATE_USER_UNMANAGED}
6431 * @hide
6432 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00006433 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00006434 @UserProvisioningState
6435 public int getUserProvisioningState() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006436 throwIfParentInstance("getUserProvisioningState");
Alan Treadwayafad8782016-01-19 15:15:08 +00006437 if (mService != null) {
6438 try {
6439 return mService.getUserProvisioningState();
6440 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006441 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00006442 }
6443 }
6444 return STATE_USER_UNMANAGED;
6445 }
6446
6447 /**
6448 * Set the {@link UserProvisioningState} for the supplied user, if they are managed.
6449 *
6450 * @param state to store
6451 * @param userHandle for user
6452 * @hide
6453 */
6454 public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) {
6455 if (mService != null) {
6456 try {
6457 mService.setUserProvisioningState(state, userHandle);
6458 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006459 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00006460 }
6461 }
6462 }
6463
6464 /**
Esteban Talaverac9bb3782016-11-11 15:41:14 +00006465 * Indicates the entity that controls the device or profile owner. Two users/profiles are
6466 * affiliated if the set of ids set by their device or profile owners intersect.
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006467 *
6468 * @param admin Which profile or device owner this request is associated with.
Esteban Talaverac9bb3782016-11-11 15:41:14 +00006469 * @param ids A list of opaque non-empty affiliation ids. Duplicate elements will be ignored.
6470 *
6471 * @throws NullPointerException if {@code ids} is null or contains null elements.
6472 * @throws IllegalArgumentException if {@code ids} contains an empty string.
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006473 */
Esteban Talaverac9bb3782016-11-11 15:41:14 +00006474 public void setAffiliationIds(@NonNull ComponentName admin, @NonNull List<String> ids) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006475 throwIfParentInstance("setAffiliationIds");
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006476 try {
Esteban Talaverac9bb3782016-11-11 15:41:14 +00006477 mService.setAffiliationIds(admin, ids);
6478 } catch (RemoteException e) {
6479 throw e.rethrowFromSystemServer();
6480 }
6481 }
6482
6483 /**
6484 * Returns the list of affiliation ids previously set via {@link #setAffiliationIds}, or an
6485 * empty list if none have been set.
6486 */
6487 public @NonNull List<String> getAffiliationIds(@NonNull ComponentName admin) {
6488 throwIfParentInstance("getAffiliationIds");
6489 try {
6490 return mService.getAffiliationIds(admin);
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006491 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006492 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006493 }
6494 }
6495
6496 /**
6497 * @hide
Esteban Talaverac9bb3782016-11-11 15:41:14 +00006498 * Returns whether this user/profile is affiliated with the device.
6499 * <p>
6500 * By definition, the user that the device owner runs on is always affiliated with the device.
6501 * Any other user/profile is considered affiliated with the device if the set specified by its
6502 * profile owner via {@link #setAffiliationIds} intersects with the device owner's.
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006503 *
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006504 */
6505 public boolean isAffiliatedUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006506 throwIfParentInstance("isAffiliatedUser");
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006507 try {
Esteban Talaverac9bb3782016-11-11 15:41:14 +00006508 return mService.isAffiliatedUser();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006509 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006510 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006511 }
6512 }
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08006513
6514 /**
6515 * @hide
6516 * Returns whether the uninstall for {@code packageName} for the current user is in queue
6517 * to be started
6518 * @param packageName the package to check for
6519 * @return whether the uninstall intent for {@code packageName} is pending
6520 */
6521 public boolean isUninstallInQueue(String packageName) {
6522 try {
6523 return mService.isUninstallInQueue(packageName);
6524 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006525 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08006526 }
6527 }
6528
6529 /**
6530 * @hide
6531 * @param packageName the package containing active DAs to be uninstalled
6532 */
6533 public void uninstallPackageWithActiveAdmins(String packageName) {
6534 try {
6535 mService.uninstallPackageWithActiveAdmins(packageName);
6536 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006537 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08006538 }
6539 }
Benjamin Franzbc33c822016-04-15 08:57:52 +01006540
Kenny Guy38dcca52016-04-19 13:09:18 +01006541 /**
6542 * @hide
6543 * Remove a test admin synchronously without sending it a broadcast about being removed.
6544 * If the admin is a profile owner or device owner it will still be removed.
6545 *
6546 * @param userHandle user id to remove the admin for.
6547 * @param admin The administration compononent to remove.
6548 * @throws SecurityException if the caller is not shell / root or the admin package
6549 * isn't a test application see {@link ApplicationInfo#FLAG_TEST_APP}.
6550 */
6551 public void forceRemoveActiveAdmin(ComponentName adminReceiver, int userHandle) {
6552 try {
6553 mService.forceRemoveActiveAdmin(adminReceiver, userHandle);
6554 } catch (RemoteException re) {
6555 throw re.rethrowFromSystemServer();
6556 }
6557 }
6558
Mahaver Chopra790d1982016-07-07 16:06:49 +01006559 /**
6560 * @hide
6561 * @return whether {@link android.provider.Settings.Global#DEVICE_PROVISIONED} has ever been set
6562 * to 1.
6563 */
6564 public boolean isDeviceProvisioned() {
6565 try {
6566 return mService.isDeviceProvisioned();
6567 } catch (RemoteException re) {
6568 throw re.rethrowFromSystemServer();
6569 }
6570 }
6571
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01006572 /**
6573 * @hide
6574 * Writes that the provisioning configuration has been applied.
6575 */
6576 public void setDeviceProvisioningConfigApplied() {
6577 try {
6578 mService.setDeviceProvisioningConfigApplied();
6579 } catch (RemoteException re) {
6580 throw re.rethrowFromSystemServer();
6581 }
6582 }
6583
6584 /**
6585 * @hide
6586 * @return whether the provisioning configuration has been applied.
6587 */
6588 public boolean isDeviceProvisioningConfigApplied() {
6589 try {
6590 return mService.isDeviceProvisioningConfigApplied();
6591 } catch (RemoteException re) {
6592 throw re.rethrowFromSystemServer();
6593 }
6594 }
6595
Victor Chang9bfc65f2016-08-15 12:27:09 +01006596 /**
6597 * @hide
Victor Chang3577ed22016-08-25 18:49:26 +01006598 * Force update user setup completed status. This API has no effect on user build.
6599 * @throws {@link SecurityException} if the caller has no
6600 * {@link android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS} or the caller is
6601 * not {@link UserHandle.SYSTEM_USER}
Victor Chang9bfc65f2016-08-15 12:27:09 +01006602 */
6603 public void forceUpdateUserSetupComplete() {
6604 try {
6605 mService.forceUpdateUserSetupComplete();
6606 } catch (RemoteException re) {
6607 throw re.rethrowFromSystemServer();
6608 }
6609 }
6610
Benjamin Franzbc33c822016-04-15 08:57:52 +01006611 private void throwIfParentInstance(String functionName) {
6612 if (mParentInstance) {
6613 throw new SecurityException(functionName + " cannot be called on the parent instance");
6614 }
6615 }
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02006616
6617 /**
6618 * @hide
6619 * Enable backup service.
6620 * <p>This includes all backup and restore mechanisms.
6621 * Setting this to {@code false} will make backup service no-op or return empty results.
6622 *
6623 * <p>There must be only one user on the device, managed by the device owner.
6624 * Otherwise a {@link SecurityException} will be thrown.
6625 *
6626 * <p>Backup service is off by default when device owner is present.
6627 */
6628 public void setBackupServiceEnabled(@NonNull ComponentName admin, boolean enabled) {
6629 try {
6630 mService.setBackupServiceEnabled(admin, enabled);
6631 } catch (RemoteException re) {
6632 throw re.rethrowFromSystemServer();
6633 }
6634 }
6635
6636 /**
6637 * @hide
6638 * @return {@code true} if backup service is enabled, {@code false} otherwise.
6639 */
6640 public boolean isBackupServiceEnabled(@NonNull ComponentName admin) {
6641 try {
6642 return mService.isBackupServiceEnabled(admin);
6643 } catch (RemoteException re) {
6644 throw re.rethrowFromSystemServer();
6645 }
6646 }
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01006647
6648 /**
6649 * Called by a device owner to control the network logging feature. Logging can only be
6650 * enabled on single user devices where the sole user is managed by the device owner. If a new
6651 * user is added on the device, logging is disabled.
6652 *
6653 * <p> Network logs contain DNS lookup and connect() library call events.
6654 *
6655 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6656 * @param enabled whether network logging should be enabled or not.
6657 * @throws {@link SecurityException} if {@code admin} is not a device owner.
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01006658 * @see #retrieveNetworkLogs
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01006659 *
6660 * @hide
6661 */
6662 public void setNetworkLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
6663 throwIfParentInstance("setNetworkLoggingEnabled");
6664 try {
6665 mService.setNetworkLoggingEnabled(admin, enabled);
6666 } catch (RemoteException re) {
6667 throw re.rethrowFromSystemServer();
6668 }
6669 }
6670
6671 /**
6672 * Return whether network logging is enabled by a device owner.
6673 *
6674 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6675 * @return {@code true} if network logging is enabled by device owner, {@code false} otherwise.
6676 * @throws {@link SecurityException} if {@code admin} is not a device owner.
6677 *
6678 * @hide
6679 */
6680 public boolean isNetworkLoggingEnabled(@NonNull ComponentName admin) {
6681 throwIfParentInstance("isNetworkLoggingEnabled");
6682 try {
6683 return mService.isNetworkLoggingEnabled(admin);
6684 } catch (RemoteException re) {
6685 throw re.rethrowFromSystemServer();
6686 }
6687 }
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01006688
6689 /**
Michal Karpinskia9ff2062016-11-03 15:46:17 +00006690 * Called by device owner to retrieve the most recent batch of network logging events.
6691 * A device owner has to provide a batchToken provided as part of
6692 * {@link DeviceAdminReceiver#onNetworkLogsAvailable} callback. If the token doesn't match the
6693 * token of the most recent available batch of logs, {@code null} will be returned.
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01006694 *
6695 * <p> {@link NetworkEvent} can be one of {@link DnsEvent} or {@link ConnectEvent}.
6696 *
6697 * <p> The list of network events is sorted chronologically, and contains at most 1200 events.
6698 *
6699 * <p> Access to the logs is rate limited and this method will only return a new batch of logs
6700 * after the device device owner has been notified via
6701 * {@link DeviceAdminReceiver#onNetworkLogsAvailable}.
6702 *
6703 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinskia9ff2062016-11-03 15:46:17 +00006704 * @param batchToken A token of the batch to retrieve
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01006705 * @return A new batch of network logs which is a list of {@link NetworkEvent}. Returns
Michal Karpinskia9ff2062016-11-03 15:46:17 +00006706 * {@code null} if the batch represented by batchToken is no longer available or if
6707 * logging is disabled.
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01006708 * @throws {@link SecurityException} if {@code admin} is not a device owner.
Michal Karpinskia9ff2062016-11-03 15:46:17 +00006709 * @see DeviceAdminReceiver#onNetworkLogsAvailable
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01006710 *
6711 * @hide
6712 */
Michal Karpinskia9ff2062016-11-03 15:46:17 +00006713 public @Nullable List<NetworkEvent> retrieveNetworkLogs(@NonNull ComponentName admin,
6714 long batchToken) {
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01006715 throwIfParentInstance("retrieveNetworkLogs");
6716 try {
Michal Karpinskia9ff2062016-11-03 15:46:17 +00006717 return mService.retrieveNetworkLogs(admin, batchToken);
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01006718 } catch (RemoteException re) {
6719 throw re.rethrowFromSystemServer();
6720 }
6721 }
Tony Mak46aabe52016-11-14 12:53:06 +00006722
6723 /**
6724 * Called by device owner/ profile owner in managed profile to bind the service with each other.
6725 * The service must be unexported. Note that the {@link Context} used to obtain this
6726 * {@link DevicePolicyManager} instance via {@link Context#getSystemService(Class)} will be used
6727 * to bind to the {@link android.app.Service}.
6728 * STOPSHIP (b/31952368): Update the javadoc after we policy to control which packages can talk.
6729 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6730 * @param serviceIntent Identifies the service to connect to. The Intent must specify either an
6731 * explicit component name or a package name to match an
6732 * {@link IntentFilter} published by a service.
6733 * @param conn Receives information as the service is started and stopped. This must be a
6734 * valid {@link ServiceConnection} object; it must not be {@code null}.
6735 * @param flags Operation options for the binding operation. See
6736 * {@link Context#bindService(Intent, ServiceConnection, int)}.
6737 * @param targetUser Which user to bind to.
6738 * @return If you have successfully bound to the service, {@code true} is returned;
6739 * {@code false} is returned if the connection is not made and you will not
6740 * receive the service object.
6741 * @see Context#bindService(Intent, ServiceConnection, int)
6742 */
6743 public boolean bindDeviceAdminServiceAsUser(
6744 @NonNull ComponentName admin, Intent serviceIntent, @NonNull ServiceConnection conn,
6745 @Context.BindServiceFlags int flags, @NonNull UserHandle targetUser) {
6746 throwIfParentInstance("bindDeviceAdminServiceAsUser");
6747 // Keep this in sync with ContextImpl.bindServiceCommon.
6748 try {
6749 final IServiceConnection sd = mContext.getServiceDispatcher(conn, null, flags);
6750 serviceIntent.prepareToLeaveProcess(mContext);
6751 return mService.bindDeviceAdminServiceAsUser(admin,
6752 mContext.getIApplicationThread(), mContext.getActivityToken(), serviceIntent,
6753 sd, flags, targetUser.getIdentifier());
6754 } catch (RemoteException re) {
6755 throw re.rethrowFromSystemServer();
6756 }
6757 }
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01006758
6759 /**
6760 * Called by the system to get the time at which the device owner last retrieved security
6761 * logging entries.
6762 *
6763 * @return the time at which the device owner most recently retrieved security logging entries,
6764 * in milliseconds since epoch; -1 if security logging entries were never retrieved.
6765 *
6766 * @hide
6767 */
6768 public long getLastSecurityLogRetrievalTime() {
6769 try {
6770 return mService.getLastSecurityLogRetrievalTime();
6771 } catch (RemoteException re) {
6772 throw re.rethrowFromSystemServer();
6773 }
6774 }
6775
6776 /**
6777 * Called by the system to get the time at which the device owner last requested a bug report.
6778 *
6779 * @return the time at which the device owner most recently requested a bug report, in
6780 * milliseconds since epoch; -1 if a bug report was never requested.
6781 *
6782 * @hide
6783 */
6784 public long getLastBugReportRequestTime() {
6785 try {
6786 return mService.getLastBugReportRequestTime();
6787 } catch (RemoteException re) {
6788 throw re.rethrowFromSystemServer();
6789 }
6790 }
6791
6792 /**
6793 * Called by the system to get the time at which the device owner last retrieved network logging
6794 * events.
6795 *
6796 * @return the time at which the device owner most recently retrieved network logging events, in
6797 * milliseconds since epoch; -1 if network logging events were never retrieved.
6798 *
6799 * @hide
6800 */
6801 public long getLastNetworkLogRetrievalTime() {
6802 try {
6803 return mService.getLastNetworkLogRetrievalTime();
6804 } catch (RemoteException re) {
6805 throw re.rethrowFromSystemServer();
6806 }
6807 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08006808}