blob: c95e0113e8012169e4e2ba681dc6a3804f066ab9 [file] [log] [blame]
Dianne Hackbornd6847842010-01-12 18:14:19 -08001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Dianne Hackborn87bba1e2010-02-26 17:25:54 -080017package android.app.admin;
Dianne Hackbornd6847842010-01-12 18:14:19 -080018
Nicolas Prevot8f7698a2016-02-11 16:05:33 +000019import android.annotation.ColorInt;
Alan Treadwayafad8782016-01-19 15:15:08 +000020import android.annotation.IntDef;
Robin Lee25e26452015-06-02 09:56:29 -070021import android.annotation.NonNull;
22import android.annotation.Nullable;
Tony Mak46aabe52016-11-14 12:53:06 +000023import android.annotation.RequiresPermission;
Dianne Hackbornd6847842010-01-12 18:14:19 -080024import android.annotation.SdkConstant;
25import android.annotation.SdkConstant.SdkConstantType;
Justin Moreyb5deda72014-07-24 10:53:40 -050026import android.annotation.SystemApi;
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +010027import android.annotation.TestApi;
Nicolas Prevot8f7698a2016-02-11 16:05:33 +000028import android.annotation.UserIdInt;
Fyodor Kupolov4e9af062016-07-18 16:59:11 -070029import android.annotation.WorkerThread;
Jason Monkd7b86212014-06-16 13:15:38 -040030import android.app.Activity;
Andrew Scull5f9e6f32016-08-02 14:22:17 +010031import android.app.admin.PasswordMetrics;
Tony Mak46aabe52016-11-14 12:53:06 +000032import android.app.IServiceConnection;
Michal Karpinski6235a942016-03-15 12:07:23 +000033import android.app.admin.SecurityLog.SecurityEvent;
Dianne Hackbornd6847842010-01-12 18:14:19 -080034import android.content.ComponentName;
35import android.content.Context;
Adam Connors010cfd42014-04-16 12:48:13 +010036import android.content.Intent;
Sander Alewijnsef475ca32014-02-17 15:13:58 +000037import android.content.IntentFilter;
Tony Mak46aabe52016-11-14 12:53:06 +000038import android.content.ServiceConnection;
Dianne Hackbornd6847842010-01-12 18:14:19 -080039import android.content.pm.PackageManager;
Victor Changcd14c0a2016-03-16 19:10:15 +000040import android.content.pm.PackageManager.NameNotFoundException;
Rubin Xuc3cd05f2016-01-11 12:11:35 +000041import android.content.pm.ParceledListSlice;
Sudheer Shanka978fc0d2016-01-28 13:51:10 +000042import android.content.pm.UserInfo;
Julia Reynoldsfca04ca2015-02-17 13:39:12 -050043import android.graphics.Bitmap;
Jason Monk03bc9912014-05-13 09:44:57 -040044import android.net.ProxyInfo;
Nicolas Prevot8b7991c2015-11-12 17:40:12 +000045import android.net.Uri;
Robin Lee66e5d962014-04-09 16:44:21 +010046import android.os.Bundle;
Victor Changc10f6692016-12-09 15:24:00 +000047import android.os.Parcelable;
Jim Millere303bf42014-08-26 17:12:29 -070048import android.os.PersistableBundle;
Adam Connors776c5552014-01-09 10:42:56 +000049import android.os.Process;
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080050import android.os.RemoteCallback;
Dianne Hackbornd6847842010-01-12 18:14:19 -080051import android.os.RemoteException;
Amith Yamasani599dd7c2012-09-14 23:20:08 -070052import android.os.UserHandle;
Julia Reynolds1e958392014-05-16 14:25:21 -040053import android.os.UserManager;
Ricky Wai494b95d2015-11-20 16:07:15 +000054import android.provider.ContactsContract.Directory;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000055import android.provider.Settings;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010056import android.security.Credentials;
Amith Yamasanid1d7c022014-08-19 17:03:41 -070057import android.service.restrictions.RestrictionsReceiver;
Mahaver Chopra1216ae52016-03-11 15:39:48 +000058import android.telephony.TelephonyManager;
Dianne Hackbornd6847842010-01-12 18:14:19 -080059import android.util.Log;
60
Makoto Onukicc4bbeb2015-09-17 10:28:24 -070061import com.android.internal.annotations.VisibleForTesting;
Maggie Benthallda51e682013-08-08 22:35:44 -040062import com.android.org.conscrypt.TrustedCertificateStore;
63
64import java.io.ByteArrayInputStream;
Dianne Hackbornd6847842010-01-12 18:14:19 -080065import java.io.IOException;
Alan Treadwayafad8782016-01-19 15:15:08 +000066import java.lang.annotation.Retention;
67import java.lang.annotation.RetentionPolicy;
Oscar Montemayor69238c62010-08-03 10:51:06 -070068import java.net.InetSocketAddress;
69import java.net.Proxy;
Robin Lee0d5ccb72014-09-12 17:41:44 +010070import java.security.KeyFactory;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000071import java.security.NoSuchAlgorithmException;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010072import java.security.PrivateKey;
73import java.security.cert.Certificate;
Maggie Benthallda51e682013-08-08 22:35:44 -040074import java.security.cert.CertificateException;
75import java.security.cert.CertificateFactory;
76import java.security.cert.X509Certificate;
Robin Lee0d5ccb72014-09-12 17:41:44 +010077import java.security.spec.InvalidKeySpecException;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000078import java.security.spec.PKCS8EncodedKeySpec;
Jim Miller604e7552014-07-18 19:00:02 -070079import java.util.ArrayList;
Rubin Xub4365912016-03-23 12:13:22 +000080import java.util.Arrays;
Svetoslav976e8bd2014-07-16 15:12:03 -070081import java.util.Collections;
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -080082import java.util.List;
Dianne Hackbornd6847842010-01-12 18:14:19 -080083
84/**
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000085 * Public interface for managing policies enforced on a device. Most clients of this class must be
Suprabh Shukla34d92ef2016-03-14 13:49:37 -070086 * registered with the system as a <a href="{@docRoot}guide/topics/admin/device-admin.html">device
87 * administrator</a>. Additionally, a device administrator may be registered as either a profile or
88 * device owner. A given method is accessible to all device administrators unless the documentation
89 * for that method specifies that it is restricted to either device or profile owners. Any
90 * application calling an api may only pass as an argument a device administrator component it
91 * owns. Otherwise, a {@link SecurityException} will be thrown.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080092 * <div class="special reference">
93 * <h3>Developer Guides</h3>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -070094 * <p>
95 * For more information about managing policies for device administration, read the <a href=
96 * "{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a> developer
97 * guide. </div>
Dianne Hackbornd6847842010-01-12 18:14:19 -080098 */
99public class DevicePolicyManager {
100 private static String TAG = "DevicePolicyManager";
Dianne Hackbornd6847842010-01-12 18:14:19 -0800101
102 private final Context mContext;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800103 private final IDevicePolicyManager mService;
Esteban Talavera62399912016-01-11 15:37:55 +0000104 private final boolean mParentInstance;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700105
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600106 /** @hide */
107 public DevicePolicyManager(Context context, IDevicePolicyManager service) {
108 this(context, service, false);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800109 }
110
Dianne Hackborn87bba1e2010-02-26 17:25:54 -0800111 /** @hide */
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700112 @VisibleForTesting
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600113 protected DevicePolicyManager(Context context, IDevicePolicyManager service,
114 boolean parentInstance) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700115 mContext = context;
116 mService = service;
Esteban Talavera62399912016-01-11 15:37:55 +0000117 mParentInstance = parentInstance;
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700118 }
119
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700120 /** @hide test will override it. */
121 @VisibleForTesting
122 protected int myUserId() {
123 return UserHandle.myUserId();
124 }
125
Dianne Hackbornd6847842010-01-12 18:14:19 -0800126 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +0000127 * Activity action: Starts the provisioning flow which sets up a managed profile.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000128 *
Jessica Hummel9da60392014-05-21 12:32:57 +0100129 * <p>A managed profile allows data separation for example for the usage of a
130 * device as a personal and corporate device. The user which provisioning is started from and
131 * the managed profile share a launcher.
132 *
Andrew Solovay27f53372015-03-02 16:37:59 -0800133 * <p>This intent will typically be sent by a mobile device management application (MDM).
134 * Provisioning adds a managed profile and sets the MDM as the profile owner who has full
135 * control over the profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100136 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000137 * <p>It is possible to check if provisioning is allowed or not by querying the method
138 * {@link #isProvisioningAllowed(String)}.
139 *
140 * <p>In version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this intent must contain the
Nicolas Prevot18440252015-03-09 14:07:17 +0000141 * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700142 * As of {@link android.os.Build.VERSION_CODES#M}, it should contain the extra
Nicolas Prevot18440252015-03-09 14:07:17 +0000143 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only
144 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000145 *
Benjamin Franzea956242016-03-21 15:45:56 +0000146 * <p>The intent may also contain the following extras:
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000147 * <ul>
Benjamin Franzea956242016-03-21 15:45:56 +0000148 * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, optional </li>
149 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional, supported from
150 * {@link android.os.Build.VERSION_CODES#N}</li>
151 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
152 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
153 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Victor Chang51d84f92016-11-16 12:22:56 +0000154 * <li>{@link #EXTRA_PROVISIONING_SKIP_USER_CONSENT}, optional</li>
Victor Chang89ee2792016-11-23 12:10:55 +0000155 * <li>{@link #EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION}, optional</li>
Victor Changc10f6692016-12-09 15:24:00 +0000156 * <li>{@link #EXTRA_PROVISIONING_DISCLAIMERS}, optional</li>
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000157 * </ul>
Jessica Hummelf72078b2014-03-06 16:13:12 +0000158 *
Benjamin Franzea956242016-03-21 15:45:56 +0000159 * <p>When managed provisioning has completed, broadcasts are sent to the application specified
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000160 * in the provisioning intent. The
161 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the
162 * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in
163 * the primary profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100164 *
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000165 * <p>From version {@link android.os.Build.VERSION_CODES#O}, when managed provisioning has
166 * completed, along with the above broadcast, activity intent
167 * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the application specified in
168 * the provisioning intent.
169 *
Benjamin Franzea956242016-03-21 15:45:56 +0000170 * <p>If provisioning fails, the managedProfile is removed so the device returns to its
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100171 * previous state.
Alan Treadway4582f812015-07-28 11:49:35 +0100172 *
173 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
174 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
175 * the provisioning flow was successful, although this doesn't guarantee the full flow will
176 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
177 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000178 */
179 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
180 public static final String ACTION_PROVISION_MANAGED_PROFILE
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100181 = "android.app.action.PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000182
183 /**
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000184 * Activity action: Starts the provisioning flow which sets up a managed user.
185 *
186 * <p>This intent will typically be sent by a mobile device management application (MDM).
Makoto Onuki32b30572015-12-11 14:29:51 -0800187 * Provisioning configures the user as managed user and sets the MDM as the profile
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000188 * owner who has full control over the user. Provisioning can only happen before user setup has
189 * been completed. Use {@link #isProvisioningAllowed(String)} to check if provisioning is
190 * allowed.
191 *
Benjamin Franzea956242016-03-21 15:45:56 +0000192 * <p>The intent contains the following extras:
193 * <ul>
194 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
195 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
196 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
197 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
198 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
199 * </ul>
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000200 *
Benjamin Franzea956242016-03-21 15:45:56 +0000201 * <p>If provisioning fails, the device returns to its previous state.
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000202 *
203 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
204 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
205 * the provisioning flow was successful, although this doesn't guarantee the full flow will
206 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
207 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Benjamin Franzea956242016-03-21 15:45:56 +0000208 *
209 * @hide
Mahaver Chopra5e732562015-11-05 11:55:12 +0000210 */
211 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
212 public static final String ACTION_PROVISION_MANAGED_USER
213 = "android.app.action.PROVISION_MANAGED_USER";
214
215 /**
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100216 * Activity action: Starts the provisioning flow which sets up a managed device.
217 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
218 *
219 * <p> During device owner provisioning a device admin app is set as the owner of the device.
220 * A device owner has full control over the device. The device owner can not be modified by the
221 * user.
222 *
223 * <p> A typical use case would be a device that is owned by a company, but used by either an
224 * employee or client.
225 *
226 * <p> An intent with this action can be sent only on an unprovisioned device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000227 * It is possible to check if provisioning is allowed or not by querying the method
228 * {@link #isProvisioningAllowed(String)}.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100229 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000230 * <p>The intent contains the following extras:
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100231 * <ul>
232 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
233 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
234 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
Rubin Xua4f9dc12015-06-12 13:27:59 +0100235 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000236 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000237 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Victor Changc10f6692016-12-09 15:24:00 +0000238 * <li>{@link #EXTRA_PROVISIONING_DISCLAIMERS}, optional</li>
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100239 * </ul>
240 *
Benjamin Franzea956242016-03-21 15:45:56 +0000241 * <p>When device owner provisioning has completed, an intent of the type
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100242 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
243 * device owner.
244 *
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000245 * <p>From version {@link android.os.Build.VERSION_CODES#O}, when device owner provisioning has
246 * completed, along with the above broadcast, activity intent
247 * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the device owner.
248 *
Benjamin Franzea956242016-03-21 15:45:56 +0000249 * <p>If provisioning fails, the device is factory reset.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100250 *
Alan Treadway4582f812015-07-28 11:49:35 +0100251 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
252 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
253 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
254 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100255 */
256 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
257 public static final String ACTION_PROVISION_MANAGED_DEVICE
258 = "android.app.action.PROVISION_MANAGED_DEVICE";
259
260 /**
Alan Treadway46dd4492015-11-09 13:57:19 +0000261 * Activity action: Starts the provisioning flow which sets up a managed device.
Steven Ng980a1b62016-02-02 17:43:18 +0000262 *
263 * <p>During device owner provisioning, a device admin app is downloaded and set as the owner of
264 * the device. A device owner has full control over the device. The device owner can not be
265 * modified by the user and the only way of resetting the device is via factory reset.
266 *
267 * <p>A typical use case would be a device that is owned by a company, but used by either an
268 * employee or client.
269 *
270 * <p>The provisioning message should be sent to an unprovisioned device.
271 *
272 * <p>Unlike {@link #ACTION_PROVISION_MANAGED_DEVICE}, the provisioning message can only be sent
273 * by a privileged app with the permission
274 * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE}.
275 *
276 * <p>The provisioning intent contains the following properties:
277 * <ul>
278 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
279 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
280 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
281 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Victor Chang38cfd9c2017-01-04 17:41:11 +0000282 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL}, optional</li>
283 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI}, optional</li>
Steven Ng980a1b62016-02-02 17:43:18 +0000284 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
285 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
286 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
287 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
288 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
289 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
290 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
291 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
292 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
293 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
294 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
Victor Chang38cfd9c2017-01-04 17:41:11 +0000295 * <li>{@link #EXTRA_PROVISIONING_SUPPORT_URL}, optional</li>
296 * <li>{@link #EXTRA_PROVISIONING_ORGANIZATION_NAME}, optional</li>
Steven Ng980a1b62016-02-02 17:43:18 +0000297 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li></ul>
298 *
299 * @hide
300 */
301 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
302 @SystemApi
303 public static final String ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE =
304 "android.app.action.PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE";
305
306 /**
307 * Activity action: Starts the provisioning flow which sets up a managed device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000308 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
309 *
310 * <p>NOTE: This is only supported on split system user devices, and puts the device into a
311 * management state that is distinct from that reached by
312 * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system
313 * user, and only has control over device-wide policies, not individual users and their data.
314 * The primary benefit is that multiple non-system users are supported when provisioning using
315 * this form of device management.
316 *
Benjamin Franzea956242016-03-21 15:45:56 +0000317 * <p>During device owner provisioning a device admin app is set as the owner of the device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000318 * A device owner has full control over the device. The device owner can not be modified by the
319 * user.
320 *
Benjamin Franzea956242016-03-21 15:45:56 +0000321 * <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 +0000322 * employee or client.
323 *
Benjamin Franzea956242016-03-21 15:45:56 +0000324 * <p>An intent with this action can be sent only on an unprovisioned device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000325 * It is possible to check if provisioning is allowed or not by querying the method
326 * {@link #isProvisioningAllowed(String)}.
327 *
328 * <p>The intent contains the following extras:
329 * <ul>
330 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
331 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
332 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
333 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Benjamin Franzea956242016-03-21 15:45:56 +0000334 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
335 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Alan Treadway46dd4492015-11-09 13:57:19 +0000336 * </ul>
337 *
Benjamin Franzea956242016-03-21 15:45:56 +0000338 * <p>When device owner provisioning has completed, an intent of the type
Alan Treadway46dd4492015-11-09 13:57:19 +0000339 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
340 * device owner.
341 *
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000342 * <p>From version {@link android.os.Build.VERSION_CODES#O}, when device owner provisioning has
343 * completed, along with the above broadcast, activity intent
344 * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the device owner.
345 *
Benjamin Franzea956242016-03-21 15:45:56 +0000346 * <p>If provisioning fails, the device is factory reset.
Alan Treadway46dd4492015-11-09 13:57:19 +0000347 *
348 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
349 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
350 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
351 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
352 *
353 * @hide
354 */
355 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
356 public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE
357 = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE";
358
359 /**
Alan Treadwayafad8782016-01-19 15:15:08 +0000360 * Activity action: Finalizes management provisioning, should be used after user-setup
361 * has been completed and {@link #getUserProvisioningState()} returns one of:
362 * <ul>
363 * <li>{@link #STATE_USER_SETUP_INCOMPLETE}</li>
364 * <li>{@link #STATE_USER_SETUP_COMPLETE}</li>
365 * <li>{@link #STATE_USER_PROFILE_COMPLETE}</li>
366 * </ul>
367 *
368 * @hide
369 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +0000370 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +0000371 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
372 public static final String ACTION_PROVISION_FINALIZATION
373 = "android.app.action.PROVISION_FINALIZATION";
374
375 /**
Michal Karpinskiba244092016-02-25 17:28:24 +0000376 * Action: Bugreport sharing with device owner has been accepted by the user.
377 *
378 * @hide
379 */
380 public static final String ACTION_BUGREPORT_SHARING_ACCEPTED =
381 "com.android.server.action.BUGREPORT_SHARING_ACCEPTED";
382
383 /**
384 * Action: Bugreport sharing with device owner has been declined by the user.
385 *
386 * @hide
387 */
388 public static final String ACTION_BUGREPORT_SHARING_DECLINED =
389 "com.android.server.action.BUGREPORT_SHARING_DECLINED";
390
391 /**
Esteban Talavera01576862016-12-15 11:16:44 +0000392 * Action: Bugreport has been collected and is dispatched to {@code DevicePolicyManagerService}.
Michal Karpinskiba244092016-02-25 17:28:24 +0000393 *
394 * @hide
395 */
396 public static final String ACTION_REMOTE_BUGREPORT_DISPATCH =
397 "android.intent.action.REMOTE_BUGREPORT_DISPATCH";
398
399 /**
400 * Extra for shared bugreport's SHA-256 hash.
401 *
402 * @hide
403 */
404 public static final String EXTRA_REMOTE_BUGREPORT_HASH =
405 "android.intent.extra.REMOTE_BUGREPORT_HASH";
406
407 /**
408 * Extra for remote bugreport notification shown type.
409 *
410 * @hide
411 */
412 public static final String EXTRA_BUGREPORT_NOTIFICATION_TYPE =
413 "android.app.extra.bugreport_notification_type";
414
415 /**
416 * Notification type for a started remote bugreport flow.
417 *
418 * @hide
419 */
420 public static final int NOTIFICATION_BUGREPORT_STARTED = 1;
421
422 /**
423 * Notification type for a bugreport that has already been accepted to be shared, but is still
424 * being taken.
425 *
426 * @hide
427 */
428 public static final int NOTIFICATION_BUGREPORT_ACCEPTED_NOT_FINISHED = 2;
429
430 /**
431 * Notification type for a bugreport that has been taken and can be shared or declined.
432 *
433 * @hide
434 */
435 public static final int NOTIFICATION_BUGREPORT_FINISHED_NOT_ACCEPTED = 3;
436
437 /**
Michal Karpinski8f010dd2016-06-21 15:05:53 +0100438 * Default and maximum timeout in milliseconds after which unlocking with weak auth times out,
439 * i.e. the user has to use a strong authentication method like password, PIN or pattern.
440 *
441 * @hide
442 */
443 public static final long DEFAULT_STRONG_AUTH_TIMEOUT_MS = 72 * 60 * 60 * 1000; // 72h
444
445 /**
Rubin Xua4f9dc12015-06-12 13:27:59 +0100446 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100447 * allows a mobile device management application or NFC programmer application which starts
448 * managed provisioning to pass data to the management application instance after provisioning.
Rubin Xua4f9dc12015-06-12 13:27:59 +0100449 * <p>
450 * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that
451 * sends the intent to pass data to itself on the newly created profile.
452 * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same
453 * instance of the app on the primary user.
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100454 * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with
455 * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC
456 * message should contain a stringified {@link java.util.Properties} instance, whose string
457 * properties will be converted into a {@link android.os.PersistableBundle} and passed to the
458 * management application after provisioning.
459 *
Rubin Xua4f9dc12015-06-12 13:27:59 +0100460 * <p>
461 * In both cases the application receives the data in
Brian Carlstromf1fe51b2014-09-03 08:55:05 -0700462 * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action
463 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed
Rubin Xua4f9dc12015-06-12 13:27:59 +0100464 * during the managed provisioning.
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100465 */
466 public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE =
Esteban Talavera37f01842014-09-05 10:50:57 +0100467 "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE";
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100468
469 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100470 * A String extra holding the package name of the mobile device management application that
471 * will be set as the profile owner or device owner.
472 *
473 * <p>If an application starts provisioning directly via an intent with action
474 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
475 * application that started provisioning. The package will be set as profile owner in that case.
476 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000477 * <p>This package is set as device owner when device owner provisioning is started by an NFC
478 * message containing an NFC record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000479 *
480 * <p> When this extra is set, the application must have exactly one device admin receiver.
Robin Lee25e26452015-06-02 09:56:29 -0700481 * This receiver will be set as the profile or device owner and active admin.
Benjamin Franzea956242016-03-21 15:45:56 +0000482 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000483 * @see DeviceAdminReceiver
484 * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still
Nicolas Prevot8f78d6a2015-08-21 11:06:31 +0100485 * supported, but only if there is only one device admin receiver in the package that requires
486 * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000487 */
Nicolas Prevot18440252015-03-09 14:07:17 +0000488 @Deprecated
Jessica Hummelf72078b2014-03-06 16:13:12 +0000489 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100490 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000491
492 /**
Nicolas Prevot18440252015-03-09 14:07:17 +0000493 * A ComponentName extra indicating the device admin receiver of the mobile device management
494 * application that will be set as the profile owner or device owner and active admin.
495 *
496 * <p>If an application starts provisioning directly via an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100497 * {@link #ACTION_PROVISION_MANAGED_PROFILE} or
498 * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this
499 * component has to match the package name of the application that started provisioning.
Nicolas Prevot18440252015-03-09 14:07:17 +0000500 *
501 * <p>This component is set as device owner and active admin when device owner provisioning is
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100502 * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC
503 * message containing an NFC record with MIME type
Benjamin Franzea956242016-03-21 15:45:56 +0000504 * {@link #MIME_TYPE_PROVISIONING_NFC}. For the NFC record, the component name must be
Rubin Xu44ef750b2015-03-23 16:51:33 +0000505 * flattened to a string, via {@link ComponentName#flattenToShortString()}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000506 *
507 * @see DeviceAdminReceiver
508 */
509 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME
510 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME";
511
512 /**
Alexandra Gherghinaaaf2f3e2014-11-13 12:46:15 +0000513 * An {@link android.accounts.Account} extra holding the account to migrate during managed
514 * profile provisioning. If the account supplied is present in the primary user, it will be
515 * copied, along with its credentials to the managed profile and removed from the primary user.
516 *
517 * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}.
518 */
519
520 public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE
521 = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE";
522
523 /**
Victor Changaa9cbc02016-12-05 20:50:57 +0000524 * Boolean extra to indicate that the migrated account should be kept. This is used in
525 * conjunction with {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}. If it's set to {@code true},
526 * the account will not be removed from the primary user after it is migrated to the newly
527 * created user or profile.
Victor Chang89ee2792016-11-23 12:10:55 +0000528 *
529 * <p> Defaults to {@code false}
530 *
Victor Changaa9cbc02016-12-05 20:50:57 +0000531 * <p> Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
532 * {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}
Victor Chang89ee2792016-11-23 12:10:55 +0000533 */
534 public static final String EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION
535 = "android.app.extra.PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION";
536
537 /**
Jessica Hummele3da7902014-08-20 15:20:11 +0100538 * A String extra that, holds the email address of the account which a managed profile is
539 * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
540 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100541 *
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100542 * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}.
543 *
Jessica Hummele3da7902014-08-20 15:20:11 +0100544 * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning
545 * contains this extra, it is forwarded in the
546 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile
547 * device management application that was set as the profile owner during provisioning.
548 * It is usually used to avoid that the user has to enter their email address twice.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100549 */
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100550 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
551 = "android.app.extra.PROVISIONING_EMAIL_ADDRESS";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100552
553 /**
Nicolas Prevotcd2d8592015-11-23 13:27:21 +0000554 * A integer extra indicating the predominant color to show during the provisioning.
555 * Refer to {@link android.graphics.Color} for how the color is represented.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000556 *
557 * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or
558 * {@link #ACTION_PROVISION_MANAGED_DEVICE}.
559 */
560 public static final String EXTRA_PROVISIONING_MAIN_COLOR =
561 "android.app.extra.PROVISIONING_MAIN_COLOR";
562
563 /**
Sander Alewijnse8c411562014-11-12 18:03:11 +0000564 * A Boolean extra that can be used by the mobile device management application to skip the
Robin Lee25e26452015-06-02 09:56:29 -0700565 * disabling of system apps during provisioning when set to {@code true}.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000566 *
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100567 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
568 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000569 */
Sander Alewijnse5a144252014-11-18 13:25:04 +0000570 public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED =
571 "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED";
Sander Alewijnse8c411562014-11-12 18:03:11 +0000572
573 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100574 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
575 * will be set to.
576 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000577 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
578 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100579 */
580 public static final String EXTRA_PROVISIONING_TIME_ZONE
Esteban Talavera37f01842014-09-05 10:50:57 +0100581 = "android.app.extra.PROVISIONING_TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100582
583 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100584 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
585 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100586 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000587 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
588 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100589 */
590 public static final String EXTRA_PROVISIONING_LOCAL_TIME
Esteban Talavera37f01842014-09-05 10:50:57 +0100591 = "android.app.extra.PROVISIONING_LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100592
593 /**
594 * A String extra holding the {@link java.util.Locale} that the device will be set to.
595 * Format: xx_yy, where xx is the language code, and yy the country code.
596 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000597 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
598 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100599 */
600 public static final String EXTRA_PROVISIONING_LOCALE
Esteban Talavera37f01842014-09-05 10:50:57 +0100601 = "android.app.extra.PROVISIONING_LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100602
603 /**
604 * A String extra holding the ssid of the wifi network that should be used during nfc device
605 * owner provisioning for downloading the mobile device management application.
606 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000607 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
608 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100609 */
610 public static final String EXTRA_PROVISIONING_WIFI_SSID
Esteban Talavera37f01842014-09-05 10:50:57 +0100611 = "android.app.extra.PROVISIONING_WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100612
613 /**
614 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
615 * is hidden or not.
616 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000617 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
618 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100619 */
620 public static final String EXTRA_PROVISIONING_WIFI_HIDDEN
Esteban Talavera37f01842014-09-05 10:50:57 +0100621 = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100622
623 /**
624 * A String extra indicating the security type of the wifi network in
Mahaver Chopra76b08a92015-10-08 17:58:45 +0100625 * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or
626 * {@code WEP}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100627 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000628 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
629 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100630 */
631 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
Esteban Talavera37f01842014-09-05 10:50:57 +0100632 = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100633
634 /**
635 * A String extra holding the password of the wifi network in
636 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
637 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000638 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
639 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100640 */
641 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talavera37f01842014-09-05 10:50:57 +0100642 = "android.app.extra.PROVISIONING_WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100643
644 /**
645 * A String extra holding the proxy host for the wifi network in
646 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
647 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000648 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
649 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100650 */
651 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
Esteban Talavera37f01842014-09-05 10:50:57 +0100652 = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100653
654 /**
655 * An int extra holding the proxy port for the wifi network in
656 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
657 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000658 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
659 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100660 */
661 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
Esteban Talavera37f01842014-09-05 10:50:57 +0100662 = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100663
664 /**
665 * A String extra holding the proxy bypass for the wifi network in
666 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
667 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000668 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
669 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100670 */
671 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
Esteban Talavera37f01842014-09-05 10:50:57 +0100672 = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100673
674 /**
675 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
676 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
677 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000678 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
679 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100680 */
681 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
Esteban Talavera37f01842014-09-05 10:50:57 +0100682 = "android.app.extra.PROVISIONING_WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100683
684 /**
685 * A String extra holding a url that specifies the download location of the device admin
686 * package. When not provided it is assumed that the device admin package is already installed.
687 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000688 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
689 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100690 */
691 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talavera37f01842014-09-05 10:50:57 +0100692 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100693
694 /**
Victor Chang38cfd9c2017-01-04 17:41:11 +0000695 * A String extra holding the localized name of the organization under management.
696 *
697 * The name is displayed only during provisioning.
698 *
699 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE}
700 *
701 * @hide
702 */
703 @SystemApi
704 public static final String EXTRA_PROVISIONING_ORGANIZATION_NAME =
705 "android.app.extra.PROVISIONING_ORGANIZATION_NAME";
706
707 /**
708 * A String extra holding a url to the website of the device's provider. The website can be
709 * opened in a browser during provisioning.
710 *
711 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE}
712 *
713 * @hide
714 */
715 @SystemApi
716 public static final String EXTRA_PROVISIONING_SUPPORT_URL =
717 "android.app.extra.PROVISIONING_SUPPORT_URL";
718
719 /**
720 * A String extra holding the localized name of the device admin package. It should be the same
721 * as the app label of the package.
722 *
723 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE}
724 *
725 * @hide
726 */
727 @SystemApi
728 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL =
729 "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL";
730
731 /**
732 * A {@link Uri} extra pointing to the app icon of device admin package. This image will be
733 * shown during the provisioning.
734 * <h5>The following URI schemes are accepted:</h5>
735 * <ul>
736 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
737 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
738 * </ul>
739 *
740 * <p> It is the responsibility of the caller to provide an image with a reasonable
741 * pixel density for the device.
742 *
743 * <p> If a content: URI is passed, the intent should have the flag
744 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
745 * {@link android.content.ClipData} of the intent too.
746 *
747 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE}
748 *
749 * @hide
750 */
751 @SystemApi
752 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI =
753 "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI";
754
755 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400756 * An int extra holding a minimum required version code for the device admin package. If the
757 * device admin is already installed on the device, it will only be re-downloaded from
758 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the
759 * installed package is less than this version code.
760 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400761 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400762 * provisioning via an NFC bump.
763 */
764 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE
765 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE";
766
767 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100768 * A String extra holding a http cookie header which should be used in the http request to the
769 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
770 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000771 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
772 * provisioning via an NFC bump.
Sander Alewijnse681bce92014-07-24 16:46:26 +0100773 */
774 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talavera37f01842014-09-05 10:50:57 +0100775 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100776
777 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100778 * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of
779 * the file at download location specified in
780 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100781 *
Benjamin Franzea956242016-03-21 15:45:56 +0000782 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} must be
783 * present. The provided checksum must match the checksum of the file at the download
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100784 * location. If the checksum doesn't match an error will be shown to the user and the user will
785 * be asked to factory reset the device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100786 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000787 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
788 * provisioning via an NFC bump.
Rubin Xud92e7572015-05-18 17:01:13 +0100789 *
790 * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP}
791 * and {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1} only SHA-1 hash is supported.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700792 * Starting from {@link android.os.Build.VERSION_CODES#M}, this parameter accepts SHA-256 in
Rubin Xud92e7572015-05-18 17:01:13 +0100793 * addition to SHA-1. Support for SHA-1 is likely to be removed in future OS releases.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100794 */
795 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100796 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100797
798 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100799 * A String extra holding the URL-safe base64 encoded SHA-256 checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100800 * android package archive at the download location specified in {@link
801 * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
802 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100803 * <p>The signatures of an android package archive can be obtained using
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100804 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
805 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
806 *
Benjamin Franzea956242016-03-21 15:45:56 +0000807 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} must be
808 * present. The provided checksum must match the checksum of any signature of the file at
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100809 * the download location. If the checksum does not match an error will be shown to the user and
810 * the user will be asked to factory reset the device.
811 *
812 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
813 * provisioning via an NFC bump.
814 */
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100815 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM
816 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM";
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100817
818 /**
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000819 * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile
820 * has completed successfully.
821 *
822 * <p>The broadcast is limited to the primary profile, to the app specified in the provisioning
Nicolas Prevotebe2d992015-05-12 18:14:53 -0700823 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000824 *
Mahaver7074caf2016-11-29 20:52:18 +0000825 * <p>This intent will contain the following extras
826 * <ul>
827 * <li>{@link Intent#EXTRA_USER}, corresponds to the {@link UserHandle} of the managed
828 * profile.</li>
829 * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, corresponds to the account requested to
830 * be migrated at provisioning time, if any.</li>
831 * </ul>
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000832 */
833 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
834 public static final String ACTION_MANAGED_PROFILE_PROVISIONED
835 = "android.app.action.MANAGED_PROFILE_PROVISIONED";
836
837 /**
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000838 * Activity action: This activity action is sent to indicate that provisioning of a managed
839 * profile or managed device has completed successfully. It'll be sent at the same time as
840 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast but this will be
841 * delivered faster as it's an activity intent.
842 *
843 * <p>The intent is only sent to the application on the profile that requested provisioning. In
844 * the device owner case the profile is the primary user.
845 *
846 * @see #ACTION_PROVISION_MANAGED_PROFILE
847 * @see #ACTION_PROVISION_MANAGED_DEVICE
848 */
849 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
850 public static final String ACTION_PROVISIONING_SUCCESSFUL =
851 "android.app.action.PROVISIONING_SUCCESSFUL";
852
853 /**
Benjamin Franzea956242016-03-21 15:45:56 +0000854 * A boolean extra indicating whether device encryption can be skipped as part of device owner
855 * or managed profile provisioning.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500856 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400857 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100858 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Benjamin Franzea956242016-03-21 15:45:56 +0000859 *
860 * <p>From {@link android.os.Build.VERSION_CODES#N} onwards, this is also supported for an
861 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500862 */
863 public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION =
864 "android.app.extra.PROVISIONING_SKIP_ENCRYPTION";
865
866 /**
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000867 * A {@link Uri} extra pointing to a logo image. This image will be shown during the
868 * provisioning. If this extra is not passed, a default image will be shown.
869 * <h5>The following URI schemes are accepted:</h5>
870 * <ul>
871 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
872 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
873 * </ul>
874 *
Victor Changc10f6692016-12-09 15:24:00 +0000875 * <p> It is the responsibility of the caller to provide an image with a reasonable
Victor Chang38cfd9c2017-01-04 17:41:11 +0000876 * pixel density for the device.
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000877 *
878 * <p> If a content: URI is passed, the intent should have the flag
879 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
880 * {@link android.content.ClipData} of the intent too.
881 *
882 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or
883 * {@link #ACTION_PROVISION_MANAGED_DEVICE}
884 */
885 public static final String EXTRA_PROVISIONING_LOGO_URI =
886 "android.app.extra.PROVISIONING_LOGO_URI";
887
888 /**
Victor Changc10f6692016-12-09 15:24:00 +0000889 * A {@link Bundle}[] extra consisting of list of disclaimer headers and disclaimer contents.
890 * Each {@link Bundle} must have both {@link #EXTRA_PROVISIONING_DISCLAIMER_HEADER}
891 * as disclaimer header, and {@link #EXTRA_PROVISIONING_DISCLAIMER_CONTENT} as disclaimer
892 * content.
893 *
894 * <p> The extra typically contains one disclaimer from the company of mobile device
895 * management application (MDM), and one disclaimer from the organization.
896 *
897 * <p> Call {@link Bundle#putParcelableArray(String, Parcelable[])} to put the {@link Bundle}[]
898 *
899 * <p> Maximum 3 key-value pairs can be specified. The rest will be ignored.
900 *
901 * <p> Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or
902 * {@link #ACTION_PROVISION_MANAGED_DEVICE}
903 */
904 public static final String EXTRA_PROVISIONING_DISCLAIMERS =
905 "android.app.extra.PROVISIONING_DISCLAIMERS";
906
907 /**
908 * A String extra of localized disclaimer header.
909 *
910 * <p> The extra is typically the company name of mobile device management application (MDM)
911 * or the organization name.
912 *
913 * <p> Use in Bundle {@link #EXTRA_PROVISIONING_DISCLAIMERS}
914 */
915 public static final String EXTRA_PROVISIONING_DISCLAIMER_HEADER =
916 "android.app.extra.PROVISIONING_DISCLAIMER_HEADER";
917
918 /**
919 * A {@link Uri} extra pointing to disclaimer content.
920 *
921 * <h5>The following URI schemes are accepted:</h5>
922 * <ul>
923 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
924 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
925 * </ul>
926 *
927 * <p> Styled text is supported in the disclaimer content. The content is parsed by
928 * {@link android.text.Html#fromHtml(String)} and displayed in a
929 * {@link android.widget.TextView}.
930 *
931 * <p> If a <code>content:</code> URI is passed, URI is passed, the intent should have the flag
932 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
933 * {@link android.content.ClipData} of the intent too.
934 *
935 * <p> Use in Bundle {@link #EXTRA_PROVISIONING_DISCLAIMERS}
936 */
937 public static final String EXTRA_PROVISIONING_DISCLAIMER_CONTENT =
938 "android.app.extra.PROVISIONING_DISCLAIMER_CONTENT";
939
940 /**
Alan Treadway94de8c82016-01-11 10:25:23 +0000941 * A boolean extra indicating if user setup should be skipped, for when provisioning is started
942 * during setup-wizard.
943 *
944 * <p>If unspecified, defaults to {@code true} to match the behavior in
945 * {@link android.os.Build.VERSION_CODES#M} and earlier.
946 *
Alan Treadway1a538d02016-01-18 16:42:30 +0000947 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or
948 * {@link #ACTION_PROVISION_MANAGED_USER}.
Alan Treadway94de8c82016-01-11 10:25:23 +0000949 *
950 * @hide
951 */
952 public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP =
953 "android.app.extra.PROVISIONING_SKIP_USER_SETUP";
954
955 /**
Victor Chang51d84f92016-11-16 12:22:56 +0000956 * A boolean extra indicating if the user consent steps from the provisioning flow should be
957 * skipped. If unspecified, defaults to {@code false}.
958 *
959 * It can only be used by an existing device owner trying to create a managed profile via
960 * {@link #ACTION_PROVISION_MANAGED_PROFILE}. Otherwise it is ignored.
961 */
962 public static final String EXTRA_PROVISIONING_SKIP_USER_CONSENT =
963 "android.app.extra.PROVISIONING_SKIP_USER_CONSENT";
964
965 /**
Benjamin Franzea956242016-03-21 15:45:56 +0000966 * This MIME type is used for starting the device owner provisioning.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100967 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400968 * <p>During device owner provisioning a device admin app is set as the owner of the device.
969 * A device owner has full control over the device. The device owner can not be modified by the
970 * user and the only way of resetting the device is if the device owner app calls a factory
971 * reset.
972 *
973 * <p> A typical use case would be a device that is owned by a company, but used by either an
974 * employee or client.
975 *
Benjamin Franzea956242016-03-21 15:45:56 +0000976 * <p> The NFC message must be sent to an unprovisioned device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100977 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000978 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100979 * contains the following properties:
980 * <ul>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400981 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
982 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100983 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400984 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100985 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
986 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
987 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
988 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
989 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
990 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
991 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
992 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
993 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
994 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100995 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
996 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from
997 * {@link android.os.Build.VERSION_CODES#M} </li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100998 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000999 * <p>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07001000 * As of {@link android.os.Build.VERSION_CODES#M}, the properties should contain
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -04001001 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of
1002 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only
1003 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -04001004 */
1005 public static final String MIME_TYPE_PROVISIONING_NFC
1006 = "application/com.android.managedprovisioning";
1007
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +01001008 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001009 * Activity action: ask the user to add a new device administrator to the system.
1010 * The desired policy is the ComponentName of the policy in the
1011 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
1012 * bring the user through adding the device administrator to the system (or
1013 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001014 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001015 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
1016 * field to provide the user with additional explanation (in addition
1017 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001018 *
1019 * <p>If your administrator is already active, this will ordinarily return immediately (without
1020 * user intervention). However, if your administrator has been updated and is requesting
1021 * additional uses-policy flags, the user will be presented with the new list. New policies
1022 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001023 */
1024 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1025 public static final String ACTION_ADD_DEVICE_ADMIN
1026 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001027
Dianne Hackbornd6847842010-01-12 18:14:19 -08001028 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001029 * @hide
1030 * Activity action: ask the user to add a new device administrator as the profile owner
Amith Yamasani814e9872015-03-23 14:04:53 -07001031 * for this user. Only system apps can launch this intent.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001032 *
Amith Yamasani814e9872015-03-23 14:04:53 -07001033 * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN}
1034 * extra field. This will invoke a UI to bring the user through adding the profile owner admin
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001035 * to remotely control restrictions on the user.
1036 *
Makoto Onukic8a5a552015-11-19 14:29:12 -08001037 * <p>The intent must be invoked via {@link Activity#startActivityForResult} to receive the
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001038 * result of whether or not the user approved the action. If approved, the result will
1039 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
1040 * as a profile owner.
1041 *
1042 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
1043 * field to provide the user with additional explanation (in addition
1044 * to your component's description) about what is being added.
1045 *
Amith Yamasani814e9872015-03-23 14:04:53 -07001046 * <p>If there is already a profile owner active or the caller is not a system app, the
1047 * operation will return a failure result.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001048 */
1049 @SystemApi
1050 public static final String ACTION_SET_PROFILE_OWNER
1051 = "android.app.action.SET_PROFILE_OWNER";
1052
1053 /**
1054 * @hide
1055 * Name of the profile owner admin that controls the user.
1056 */
1057 @SystemApi
1058 public static final String EXTRA_PROFILE_OWNER_NAME
1059 = "android.app.extra.PROFILE_OWNER_NAME";
1060
1061 /**
Nicolas Prevot00799002015-07-27 18:15:20 +01001062 * Broadcast action: send when any policy admin changes a policy.
Jim Miller284b62e2010-06-08 14:27:42 -07001063 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -07001064 *
Jim Miller284b62e2010-06-08 14:27:42 -07001065 * @hide
1066 */
1067 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
1068 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
1069
1070 /**
Tony Mak1970f972016-08-30 17:41:48 +01001071 * Broadcast action: sent when the device owner is set, changed or cleared.
Nicolas Prevot00799002015-07-27 18:15:20 +01001072 *
1073 * This broadcast is sent only to the primary user.
1074 * @see #ACTION_PROVISION_MANAGED_DEVICE
1075 */
1076 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1077 public static final String ACTION_DEVICE_OWNER_CHANGED
1078 = "android.app.action.DEVICE_OWNER_CHANGED";
1079
1080 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001081 * The ComponentName of the administrator component.
1082 *
1083 * @see #ACTION_ADD_DEVICE_ADMIN
1084 */
1085 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001086
Dianne Hackbornd6847842010-01-12 18:14:19 -08001087 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001088 * An optional CharSequence providing additional explanation for why the
1089 * admin is being added.
1090 *
1091 * @see #ACTION_ADD_DEVICE_ADMIN
1092 */
1093 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001094
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001095 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001096 * Activity action: have the user enter a new password. This activity should
1097 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
1098 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
1099 * enter a new password that meets the current requirements. You can use
1100 * {@link #isActivePasswordSufficient()} to determine whether you need to
1101 * have the user select a new password in order to meet the current
1102 * constraints. Upon being resumed from this activity, you can check the new
1103 * password characteristics to see if they are sufficient.
Benjamin Franzc9921092016-01-08 17:17:44 +00001104 *
1105 * If the intent is launched from within a managed profile with a profile
1106 * owner built against {@link android.os.Build.VERSION_CODES#M} or before,
1107 * this will trigger entering a new password for the parent of the profile.
1108 * For all other cases it will trigger entering a new password for the user
1109 * or profile it is launched from.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001110 *
1111 * @see #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
Dianne Hackbornd6847842010-01-12 18:14:19 -08001112 */
1113 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1114 public static final String ACTION_SET_NEW_PASSWORD
1115 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001116
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001117 /**
Benjamin Franzc9921092016-01-08 17:17:44 +00001118 * Activity action: have the user enter a new password for the parent profile.
1119 * If the intent is launched from within a managed profile, this will trigger
1120 * entering a new password for the parent of the profile. In all other cases
1121 * the behaviour is identical to {@link #ACTION_SET_NEW_PASSWORD}.
1122 */
1123 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1124 public static final String ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
1125 = "android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD";
1126
1127 /**
phweissa0cb2512016-12-14 21:37:48 +01001128 * Broadcast action: Tell the status bar to open the device monitoring dialog, e.g. when
1129 * Network logging was enabled and the user tapped the notification.
1130 * <p class="note">This is a protected intent that can only be sent by the system.</p>
1131 * @hide
1132 */
1133 public static final String ACTION_SHOW_DEVICE_MONITORING_DIALOG
1134 = "android.app.action.SHOW_DEVICE_MONITORING_DIALOG";
1135
1136 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +00001137 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
1138 * the parent profile to access intents sent from the managed profile.
1139 * That is, when an app in the managed profile calls
1140 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
1141 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001142 */
Nicolas Prevot86a96732014-09-08 12:13:05 +01001143 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001144
1145 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +00001146 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
1147 * the managed profile to access intents sent from the parent profile.
1148 * That is, when an app in the parent profile calls
1149 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
1150 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001151 */
Nicolas Prevot86a96732014-09-08 12:13:05 +01001152 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001153
Dianne Hackbornd6847842010-01-12 18:14:19 -08001154 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01001155 * Broadcast action: notify that a new local system update policy has been set by the device
1156 * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00001157 */
1158 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Rubin Xu5faad8e2015-04-20 17:43:48 +01001159 public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED
1160 = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED";
Rubin Xu8027a4f2015-03-10 17:52:37 +00001161
Amith Yamasanid49489b2015-04-28 14:00:26 -07001162 /**
1163 * Permission policy to prompt user for new permission requests for runtime permissions.
1164 * Already granted or denied permissions are not affected by this.
1165 */
1166 public static final int PERMISSION_POLICY_PROMPT = 0;
1167
1168 /**
1169 * Permission policy to always grant new permission requests for runtime permissions.
1170 * Already granted or denied permissions are not affected by this.
1171 */
1172 public static final int PERMISSION_POLICY_AUTO_GRANT = 1;
1173
1174 /**
1175 * Permission policy to always deny new permission requests for runtime permissions.
1176 * Already granted or denied permissions are not affected by this.
1177 */
1178 public static final int PERMISSION_POLICY_AUTO_DENY = 2;
1179
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07001180 /**
1181 * Runtime permission state: The user can manage the permission
1182 * through the UI.
1183 */
1184 public static final int PERMISSION_GRANT_STATE_DEFAULT = 0;
1185
1186 /**
1187 * Runtime permission state: The permission is granted to the app
1188 * and the user cannot manage the permission through the UI.
1189 */
1190 public static final int PERMISSION_GRANT_STATE_GRANTED = 1;
1191
1192 /**
1193 * Runtime permission state: The permission is denied to the app
1194 * and the user cannot manage the permission through the UI.
1195 */
1196 public static final int PERMISSION_GRANT_STATE_DENIED = 2;
Rubin Xu8027a4f2015-03-10 17:52:37 +00001197
1198 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00001199 * No management for current user in-effect. This is the default.
1200 * @hide
1201 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001202 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001203 public static final int STATE_USER_UNMANAGED = 0;
1204
1205 /**
1206 * Management partially setup, user setup needs to be completed.
1207 * @hide
1208 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001209 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001210 public static final int STATE_USER_SETUP_INCOMPLETE = 1;
1211
1212 /**
1213 * Management partially setup, user setup completed.
1214 * @hide
1215 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001216 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001217 public static final int STATE_USER_SETUP_COMPLETE = 2;
1218
1219 /**
1220 * Management setup and active on current user.
1221 * @hide
1222 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001223 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001224 public static final int STATE_USER_SETUP_FINALIZED = 3;
1225
1226 /**
1227 * Management partially setup on a managed profile.
1228 * @hide
1229 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001230 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001231 public static final int STATE_USER_PROFILE_COMPLETE = 4;
1232
1233 /**
1234 * @hide
1235 */
1236 @IntDef({STATE_USER_UNMANAGED, STATE_USER_SETUP_INCOMPLETE, STATE_USER_SETUP_COMPLETE,
1237 STATE_USER_SETUP_FINALIZED, STATE_USER_PROFILE_COMPLETE})
1238 @Retention(RetentionPolicy.SOURCE)
1239 public @interface UserProvisioningState {}
1240
1241 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001242 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001243 *
1244 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1245 * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and
1246 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when provisioning is allowed.
1247 *
1248 * @hide
1249 */
1250 public static final int CODE_OK = 0;
1251
1252 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001253 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001254 *
1255 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and
1256 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the device already has a device
1257 * owner.
1258 *
1259 * @hide
1260 */
1261 public static final int CODE_HAS_DEVICE_OWNER = 1;
1262
1263 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001264 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001265 *
1266 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1267 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user has a profile owner and for
1268 * {@link #ACTION_PROVISION_MANAGED_PROFILE} when the profile owner is already set.
1269 *
1270 * @hide
1271 */
1272 public static final int CODE_USER_HAS_PROFILE_OWNER = 2;
1273
1274 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001275 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001276 *
1277 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and
1278 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user isn't running.
1279 *
1280 * @hide
1281 */
1282 public static final int CODE_USER_NOT_RUNNING = 3;
1283
1284 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001285 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001286 *
1287 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1288 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the device has already been setup and
1289 * for {@link #ACTION_PROVISION_MANAGED_USER} if the user has already been setup.
1290 *
1291 * @hide
1292 */
1293 public static final int CODE_USER_SETUP_COMPLETED = 4;
1294
1295 /**
1296 * Code used to indicate that the device also has a user other than the system user.
1297 *
1298 * @hide
1299 */
1300 public static final int CODE_NONSYSTEM_USER_EXISTS = 5;
1301
1302 /**
1303 * Code used to indicate that device has an account that prevents provisioning.
1304 *
1305 * @hide
1306 */
1307 public static final int CODE_ACCOUNTS_NOT_EMPTY = 6;
1308
1309 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001310 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001311 *
1312 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and
1313 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the user is not a system user.
1314 *
1315 * @hide
1316 */
1317 public static final int CODE_NOT_SYSTEM_USER = 7;
1318
1319 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001320 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001321 *
1322 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1323 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} and {@link #ACTION_PROVISION_MANAGED_USER}
1324 * when the device is a watch and is already paired.
1325 *
1326 * @hide
1327 */
1328 public static final int CODE_HAS_PAIRED = 8;
1329
1330 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001331 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001332 *
1333 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} and
1334 * {@link #ACTION_PROVISION_MANAGED_USER} on devices which do not support managed users.
1335 *
1336 * @see {@link PackageManager#FEATURE_MANAGED_USERS}
1337 * @hide
1338 */
1339 public static final int CODE_MANAGED_USERS_NOT_SUPPORTED = 9;
1340
1341 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001342 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001343 *
1344 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} if the user is a system user.
1345 *
1346 * @hide
1347 */
1348 public static final int CODE_SYSTEM_USER = 10;
1349
1350 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001351 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001352 *
1353 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when the user cannot have more
1354 * managed profiles.
1355 *
1356 * @hide
1357 */
1358 public static final int CODE_CANNOT_ADD_MANAGED_PROFILE = 11;
1359
1360 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001361 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001362 *
1363 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} and
1364 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices not running with split system
1365 * user.
1366 *
1367 * @hide
1368 */
1369 public static final int CODE_NOT_SYSTEM_USER_SPLIT = 12;
1370
1371 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001372 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001373 *
1374 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1375 * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and
1376 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices which do no support device
1377 * admins.
1378 *
1379 * @hide
1380 */
1381 public static final int CODE_DEVICE_ADMIN_NOT_SUPPORTED = 13;
1382
1383 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001384 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001385 *
Esteban Talavera6c9116a2016-11-24 16:12:44 +00001386 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when the device the user is a
1387 * system user on a split system user device.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001388 *
1389 * @hide
1390 */
1391 public static final int CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER = 14;
1392
1393 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001394 * Result code for {@link #checkProvisioningPreCondition}.
1395 *
1396 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when adding a managed profile is
1397 * disallowed by {@link UserManager#DISALLOW_ADD_MANAGED_PROFILE}.
1398 *
1399 * @hide
1400 */
1401 public static final int CODE_ADD_MANAGED_PROFILE_DISALLOWED = 15;
1402
1403 /**
1404 * Result codes for {@link #checkProvisioningPreCondition} indicating all the provisioning pre
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001405 * conditions.
1406 *
1407 * @hide
1408 */
1409 @Retention(RetentionPolicy.SOURCE)
1410 @IntDef({CODE_OK, CODE_HAS_DEVICE_OWNER, CODE_USER_HAS_PROFILE_OWNER, CODE_USER_NOT_RUNNING,
1411 CODE_USER_SETUP_COMPLETED, CODE_NOT_SYSTEM_USER, CODE_HAS_PAIRED,
1412 CODE_MANAGED_USERS_NOT_SUPPORTED, CODE_SYSTEM_USER, CODE_CANNOT_ADD_MANAGED_PROFILE,
1413 CODE_NOT_SYSTEM_USER_SPLIT, CODE_DEVICE_ADMIN_NOT_SUPPORTED,
Esteban Talavera01576862016-12-15 11:16:44 +00001414 CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER, CODE_ADD_MANAGED_PROFILE_DISALLOWED})
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001415 public @interface ProvisioningPreCondition {}
1416
1417 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001418 * Return true if the given administrator component is currently active (enabled) in the system.
1419 *
1420 * @param admin The administrator component to check for.
1421 * @return {@code true} if {@code admin} is currently enabled in the system, {@code false}
1422 * otherwise
Dianne Hackbornd6847842010-01-12 18:14:19 -08001423 */
Robin Lee25e26452015-06-02 09:56:29 -07001424 public boolean isAdminActive(@NonNull ComponentName admin) {
Charles He8c760562016-10-25 16:36:53 +01001425 throwIfParentInstance("isAdminActive");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001426 return isAdminActiveAsUser(admin, myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001427 }
1428
1429 /**
1430 * @see #isAdminActive(ComponentName)
1431 * @hide
1432 */
Robin Lee25e26452015-06-02 09:56:29 -07001433 public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001434 if (mService != null) {
1435 try {
Robin Lee25e26452015-06-02 09:56:29 -07001436 return mService.isAdminActive(admin, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001437 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001438 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001439 }
1440 }
1441 return false;
1442 }
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001443 /**
1444 * Return true if the given administrator component is currently being removed
1445 * for the user.
1446 * @hide
1447 */
Robin Lee25e26452015-06-02 09:56:29 -07001448 public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) {
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001449 if (mService != null) {
1450 try {
Robin Lee25e26452015-06-02 09:56:29 -07001451 return mService.isRemovingAdmin(admin, userId);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001452 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001453 throw e.rethrowFromSystemServer();
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001454 }
1455 }
1456 return false;
1457 }
1458
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001459
Dianne Hackbornd6847842010-01-12 18:14:19 -08001460 /**
Robin Lee25e26452015-06-02 09:56:29 -07001461 * Return a list of all currently active device administrators' component
1462 * names. If there are no administrators {@code null} may be
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001463 * returned.
1464 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07001465 public @Nullable List<ComponentName> getActiveAdmins() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001466 throwIfParentInstance("getActiveAdmins");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001467 return getActiveAdminsAsUser(myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001468 }
1469
1470 /**
1471 * @see #getActiveAdmins()
1472 * @hide
1473 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07001474 public @Nullable List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001475 if (mService != null) {
1476 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001477 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001478 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001479 throw e.rethrowFromSystemServer();
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001480 }
1481 }
1482 return null;
1483 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001484
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001485 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001486 * Used by package administration code to determine if a package can be stopped
1487 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001488 * @hide
1489 */
1490 public boolean packageHasActiveAdmins(String packageName) {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001491 return packageHasActiveAdmins(packageName, myUserId());
1492 }
1493
1494 /**
1495 * Used by package administration code to determine if a package can be stopped
1496 * or uninstalled.
1497 * @hide
1498 */
1499 public boolean packageHasActiveAdmins(String packageName, int userId) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001500 if (mService != null) {
1501 try {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001502 return mService.packageHasActiveAdmins(packageName, userId);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001503 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001504 throw e.rethrowFromSystemServer();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001505 }
1506 }
1507 return false;
1508 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001509
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001510 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001511 * Remove a current administration component. This can only be called
1512 * by the application that owns the administration component; if you
1513 * try to remove someone else's component, a security exception will be
1514 * thrown.
Esteban Talavera552a5612016-02-19 17:02:24 +00001515 *
1516 * <p>Note that the operation is not synchronous and the admin might still be active (as
1517 * indicated by {@link #getActiveAdmins()}) by the time this method returns.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001518 *
1519 * @param admin The administration compononent to remove.
1520 * @throws SecurityException if the caller is not in the owner application of {@code admin}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001521 */
Robin Lee25e26452015-06-02 09:56:29 -07001522 public void removeActiveAdmin(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001523 throwIfParentInstance("removeActiveAdmin");
Dianne Hackbornd6847842010-01-12 18:14:19 -08001524 if (mService != null) {
1525 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001526 mService.removeActiveAdmin(admin, myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001527 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001528 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001529 }
1530 }
1531 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001532
Dianne Hackbornd6847842010-01-12 18:14:19 -08001533 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001534 * Returns true if an administrator has been granted a particular device policy. This can be
1535 * used to check whether the administrator was activated under an earlier set of policies, but
1536 * requires additional policies after an upgrade.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001537 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001538 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be an
1539 * active administrator, or an exception will be thrown.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001540 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001541 * @throws SecurityException if {@code admin} is not an active administrator.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001542 */
Robin Lee25e26452015-06-02 09:56:29 -07001543 public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001544 throwIfParentInstance("hasGrantedPolicy");
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001545 if (mService != null) {
1546 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001547 return mService.hasGrantedPolicy(admin, usesPolicy, myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001548 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001549 throw e.rethrowFromSystemServer();
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001550 }
1551 }
1552 return false;
1553 }
1554
1555 /**
Clara Bayarria1771112015-12-18 16:29:18 +00001556 * Returns true if the Profile Challenge is available to use for the given profile user.
1557 *
1558 * @hide
1559 */
1560 public boolean isSeparateProfileChallengeAllowed(int userHandle) {
1561 if (mService != null) {
1562 try {
1563 return mService.isSeparateProfileChallengeAllowed(userHandle);
1564 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001565 throw e.rethrowFromSystemServer();
Clara Bayarria1771112015-12-18 16:29:18 +00001566 }
1567 }
1568 return false;
1569 }
1570
1571 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001572 * Constant for {@link #setPasswordQuality}: the policy has no requirements
1573 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001574 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001575 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001576 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001577
Dianne Hackbornd6847842010-01-12 18:14:19 -08001578 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -07001579 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
1580 * recognition technology. This implies technologies that can recognize the identity of
1581 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
1582 * Note that quality constants are ordered so that higher values are more restrictive.
1583 */
1584 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
1585
1586 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001587 * Constant for {@link #setPasswordQuality}: the policy requires some kind
Benjamin Franzc6a96532015-06-16 11:23:38 +01001588 * of password or pattern, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001589 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001590 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001591 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001592
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001593 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001594 * Constant for {@link #setPasswordQuality}: the user must have entered a
1595 * password containing at least numeric characters. Note that quality
1596 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001597 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001598 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001599
Dianne Hackbornd6847842010-01-12 18:14:19 -08001600 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001601 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -08001602 * password containing at least numeric characters with no repeating (4444)
1603 * or ordered (1234, 4321, 2468) sequences. Note that quality
1604 * constants are ordered so that higher values are more restrictive.
1605 */
1606 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
1607
1608 /**
1609 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001610 * password containing at least alphabetic (or other symbol) characters.
1611 * Note that quality constants are ordered so that higher values are more
1612 * restrictive.
1613 */
1614 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001615
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001616 /**
1617 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001618 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001619 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001620 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001621 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001622 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001623
Dianne Hackbornd6847842010-01-12 18:14:19 -08001624 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001625 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001626 * password containing at least a letter, a numerical digit and a special
1627 * symbol, by default. With this password quality, passwords can be
1628 * restricted to contain various sets of characters, like at least an
1629 * uppercase letter, etc. These are specified using various methods,
1630 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
1631 * that quality constants are ordered so that higher values are more
1632 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001633 */
1634 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
1635
1636 /**
Oleksandr Peletskyi0fdcd3d2016-01-13 16:49:56 +01001637 * Constant for {@link #setPasswordQuality}: the user is not allowed to
1638 * modify password. In case this password quality is set, the password is
1639 * managed by a profile owner. The profile owner can set any password,
1640 * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note
1641 * that quality constants are ordered so that higher values are more
1642 * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is
1643 * the highest.
1644 * @hide
1645 */
1646 public static final int PASSWORD_QUALITY_MANAGED = 0x80000;
1647
1648 /**
Makoto Onuki5e7e06702016-09-01 18:02:01 -07001649 * @hide
1650 *
1651 * adb shell dpm set-{device,profile}-owner will normally not allow installing an owner to
1652 * a user with accounts. {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED}
1653 * and {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} are the account features
1654 * used by authenticator to exempt their accounts from this:
1655 *
1656 * <ul>
1657 * <li>Non-test-only DO/PO still can't be installed when there are accounts.
1658 * <p>In order to make an apk test-only, add android:testOnly="true" to the
1659 * &lt;application&gt; tag in the manifest.
1660 *
1661 * <li>Test-only DO/PO can be installed even when there are accounts, as long as all the
1662 * accounts have the {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} feature.
1663 * Some authenticators claim to have any features, so to detect it, we also check
1664 * {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} and disallow installing
1665 * if any of the accounts have it.
1666 * </ul>
1667 */
1668 public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED =
1669 "android.account.DEVICE_OR_PROFILE_OWNER_ALLOWED";
1670
1671 /** @hide See {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} */
1672 public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED =
1673 "android.account.DEVICE_OR_PROFILE_OWNER_DISALLOWED";
1674
1675 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001676 * Called by an application that is administering the device to set the password restrictions it
1677 * is imposing. After setting this, the user will not be able to enter a new password that is
1678 * not at least as restrictive as what has been set. Note that the current password will remain
1679 * until the user has set a new one, so the change does not take place immediately. To prompt
1680 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
Esteban Talaverac1c83592016-02-17 17:56:15 +00001681 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after calling this method.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001682 * <p>
1683 * Quality constants are ordered so that higher values are more restrictive; thus the highest
1684 * requested quality constant (between the policy set here, the user's preference, and any other
1685 * considerations) is the one that is in effect.
1686 * <p>
1687 * The calling device admin must have requested
1688 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1689 * not, a security exception will be thrown.
1690 * <p>
1691 * This method can be called on the {@link DevicePolicyManager} instance returned by
1692 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1693 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001694 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001695 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001696 * @param quality The new desired quality. One of {@link #PASSWORD_QUALITY_UNSPECIFIED},
1697 * {@link #PASSWORD_QUALITY_SOMETHING}, {@link #PASSWORD_QUALITY_NUMERIC},
1698 * {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC},
1699 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} or {@link #PASSWORD_QUALITY_COMPLEX}.
1700 * @throws SecurityException if {@code admin} is not an active administrator or if {@code admin}
1701 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Dianne Hackbornd6847842010-01-12 18:14:19 -08001702 */
Robin Lee25e26452015-06-02 09:56:29 -07001703 public void setPasswordQuality(@NonNull ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001704 if (mService != null) {
1705 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001706 mService.setPasswordQuality(admin, quality, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001707 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001708 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001709 }
1710 }
1711 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001712
Dianne Hackbornd6847842010-01-12 18:14:19 -08001713 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001714 * Retrieve the current minimum password quality for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01001715 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00001716 * a separate challenge are not taken into account.
1717 *
1718 * <p>This method can be called on the {@link DevicePolicyManager} instance
1719 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1720 * restrictions on the parent profile.
1721 *
Robin Lee25e26452015-06-02 09:56:29 -07001722 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001723 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001724 */
Robin Lee25e26452015-06-02 09:56:29 -07001725 public int getPasswordQuality(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001726 return getPasswordQuality(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001727 }
1728
1729 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001730 public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001731 if (mService != null) {
1732 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001733 return mService.getPasswordQuality(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001734 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001735 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001736 }
1737 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001738 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001739 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001740
Dianne Hackbornd6847842010-01-12 18:14:19 -08001741 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001742 * Called by an application that is administering the device to set the minimum allowed password
1743 * length. After setting this, the user will not be able to enter a new password that is not at
1744 * least as restrictive as what has been set. Note that the current password will remain until
1745 * the user has set a new one, so the change does not take place immediately. To prompt the user
1746 * for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
1747 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
1748 * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC}
1749 * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC},
1750 * {@link #PASSWORD_QUALITY_ALPHANUMERIC}, or {@link #PASSWORD_QUALITY_COMPLEX} with
1751 * {@link #setPasswordQuality}.
1752 * <p>
1753 * The calling device admin must have requested
1754 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1755 * not, a security exception will be thrown.
1756 * <p>
1757 * This method can be called on the {@link DevicePolicyManager} instance returned by
1758 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1759 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001760 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001761 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001762 * @param length The new desired minimum password length. A value of 0 means there is no
1763 * restriction.
1764 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1765 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Dianne Hackbornd6847842010-01-12 18:14:19 -08001766 */
Robin Lee25e26452015-06-02 09:56:29 -07001767 public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001768 if (mService != null) {
1769 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001770 mService.setPasswordMinimumLength(admin, length, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001771 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001772 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001773 }
1774 }
1775 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001776
Dianne Hackbornd6847842010-01-12 18:14:19 -08001777 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001778 * Retrieve the current minimum password length for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01001779 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00001780 * a separate challenge are not taken into account.
1781 *
1782 * <p>This method can be called on the {@link DevicePolicyManager} instance
1783 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1784 * restrictions on the parent profile.
1785 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001786 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001787 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001788 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001789 */
Robin Lee25e26452015-06-02 09:56:29 -07001790 public int getPasswordMinimumLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001791 return getPasswordMinimumLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001792 }
1793
1794 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001795 public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001796 if (mService != null) {
1797 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001798 return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001799 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001800 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001801 }
1802 }
1803 return 0;
1804 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001805
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001806 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001807 * Called by an application that is administering the device to set the minimum number of upper
1808 * case letters required in the password. After setting this, the user will not be able to enter
1809 * a new password that is not at least as restrictive as what has been set. Note that the
1810 * current password will remain until the user has set a new one, so the change does not take
1811 * place immediately. To prompt the user for a new password, use
1812 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
1813 * setting this value. This constraint is only imposed if the administrator has also requested
1814 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001815 * <p>
1816 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001817 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1818 * not, a security exception will be thrown.
1819 * <p>
1820 * This method can be called on the {@link DevicePolicyManager} instance returned by
1821 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1822 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001823 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001824 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1825 * @param length The new desired minimum number of upper case letters required in the password.
1826 * A value of 0 means there is no restriction.
1827 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1828 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001829 */
Robin Lee25e26452015-06-02 09:56:29 -07001830 public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001831 if (mService != null) {
1832 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001833 mService.setPasswordMinimumUpperCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001834 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001835 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001836 }
1837 }
1838 }
1839
1840 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001841 * Retrieve the current number of upper case letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01001842 * for a particular admin or all admins that set restrictions on this user and
Esteban Talaverac1c83592016-02-17 17:56:15 +00001843 * its participating profiles. Restrictions on profiles that have a separate challenge
1844 * are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001845 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001846 * {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001847 * and only applies when the password quality is
1848 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001849 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001850 * <p>This method can be called on the {@link DevicePolicyManager} instance
1851 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1852 * restrictions on the parent profile.
1853 *
Robin Lee25e26452015-06-02 09:56:29 -07001854 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001855 * aggregate all admins.
1856 * @return The minimum number of upper case letters required in the
1857 * password.
1858 */
Robin Lee25e26452015-06-02 09:56:29 -07001859 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001860 return getPasswordMinimumUpperCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001861 }
1862
1863 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001864 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001865 if (mService != null) {
1866 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001867 return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001868 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001869 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001870 }
1871 }
1872 return 0;
1873 }
1874
1875 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001876 * Called by an application that is administering the device to set the minimum number of lower
1877 * case letters required in the password. After setting this, the user will not be able to enter
1878 * a new password that is not at least as restrictive as what has been set. Note that the
1879 * current password will remain until the user has set a new one, so the change does not take
1880 * place immediately. To prompt the user for a new password, use
1881 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
1882 * setting this value. This constraint is only imposed if the administrator has also requested
1883 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001884 * <p>
1885 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001886 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1887 * not, a security exception will be thrown.
1888 * <p>
1889 * This method can be called on the {@link DevicePolicyManager} instance returned by
1890 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1891 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001892 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001893 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1894 * @param length The new desired minimum number of lower case letters required in the password.
1895 * A value of 0 means there is no restriction.
1896 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1897 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001898 */
Robin Lee25e26452015-06-02 09:56:29 -07001899 public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001900 if (mService != null) {
1901 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001902 mService.setPasswordMinimumLowerCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001903 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001904 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001905 }
1906 }
1907 }
1908
1909 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001910 * Retrieve the current number of lower case letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01001911 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00001912 * and its participating profiles. Restrictions on profiles that have
1913 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001914 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001915 * {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001916 * and only applies when the password quality is
1917 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001918 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001919 * <p>This method can be called on the {@link DevicePolicyManager} instance
1920 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1921 * restrictions on the parent profile.
1922 *
Robin Lee25e26452015-06-02 09:56:29 -07001923 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001924 * aggregate all admins.
1925 * @return The minimum number of lower case letters required in the
1926 * password.
1927 */
Robin Lee25e26452015-06-02 09:56:29 -07001928 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001929 return getPasswordMinimumLowerCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001930 }
1931
1932 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001933 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001934 if (mService != null) {
1935 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001936 return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001937 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001938 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001939 }
1940 }
1941 return 0;
1942 }
1943
1944 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001945 * Called by an application that is administering the device to set the minimum number of
1946 * letters required in the password. After setting this, the user will not be able to enter a
1947 * new password that is not at least as restrictive as what has been set. Note that the current
1948 * password will remain until the user has set a new one, so the change does not take place
1949 * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
1950 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
1951 * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1952 * {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001953 * <p>
1954 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001955 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1956 * not, a security exception will be thrown.
1957 * <p>
1958 * This method can be called on the {@link DevicePolicyManager} instance returned by
1959 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1960 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001961 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001962 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1963 * @param length The new desired minimum number of letters required in the password. A value of
1964 * 0 means there is no restriction.
1965 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1966 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001967 */
Robin Lee25e26452015-06-02 09:56:29 -07001968 public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001969 if (mService != null) {
1970 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001971 mService.setPasswordMinimumLetters(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001972 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001973 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001974 }
1975 }
1976 }
1977
1978 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001979 * Retrieve the current number of letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01001980 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00001981 * and its participating profiles. Restrictions on profiles that have
1982 * a separate challenge are not taken into account.
1983 * This is the same value as set by
1984 * {@link #setPasswordMinimumLetters(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001985 * and only applies when the password quality is
1986 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001987 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001988 * <p>This method can be called on the {@link DevicePolicyManager} instance
1989 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1990 * restrictions on the parent profile.
1991 *
Robin Lee25e26452015-06-02 09:56:29 -07001992 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001993 * aggregate all admins.
1994 * @return The minimum number of letters required in the password.
1995 */
Robin Lee25e26452015-06-02 09:56:29 -07001996 public int getPasswordMinimumLetters(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001997 return getPasswordMinimumLetters(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001998 }
1999
2000 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002001 public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002002 if (mService != null) {
2003 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002004 return mService.getPasswordMinimumLetters(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002005 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002006 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002007 }
2008 }
2009 return 0;
2010 }
2011
2012 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002013 * Called by an application that is administering the device to set the minimum number of
2014 * numerical digits required in the password. After setting this, the user will not be able to
2015 * enter a new password that is not at least as restrictive as what has been set. Note that the
2016 * current password will remain until the user has set a new one, so the change does not take
2017 * place immediately. To prompt the user for a new password, use
2018 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
2019 * setting this value. This constraint is only imposed if the administrator has also requested
2020 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002021 * <p>
2022 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002023 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2024 * not, a security exception will be thrown.
2025 * <p>
2026 * This method can be called on the {@link DevicePolicyManager} instance returned by
2027 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2028 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002029 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002030 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2031 * @param length The new desired minimum number of numerical digits required in the password. A
2032 * value of 0 means there is no restriction.
2033 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2034 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002035 */
Robin Lee25e26452015-06-02 09:56:29 -07002036 public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002037 if (mService != null) {
2038 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002039 mService.setPasswordMinimumNumeric(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002040 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002041 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002042 }
2043 }
2044 }
2045
2046 /**
2047 * Retrieve the current number of numerical digits required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002048 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002049 * and its participating profiles. Restrictions on profiles that have
2050 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01002051 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00002052 * {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002053 * and only applies when the password quality is
2054 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002055 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002056 * <p>This method can be called on the {@link DevicePolicyManager} instance
2057 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2058 * restrictions on the parent profile.
2059 *
Robin Lee25e26452015-06-02 09:56:29 -07002060 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002061 * aggregate all admins.
2062 * @return The minimum number of numerical digits required in the password.
2063 */
Robin Lee25e26452015-06-02 09:56:29 -07002064 public int getPasswordMinimumNumeric(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002065 return getPasswordMinimumNumeric(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002066 }
2067
2068 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002069 public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002070 if (mService != null) {
2071 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002072 return mService.getPasswordMinimumNumeric(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002073 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002074 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002075 }
2076 }
2077 return 0;
2078 }
2079
2080 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002081 * Called by an application that is administering the device to set the minimum number of
2082 * symbols required in the password. After setting this, the user will not be able to enter a
2083 * new password that is not at least as restrictive as what has been set. Note that the current
2084 * password will remain until the user has set a new one, so the change does not take place
2085 * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
2086 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
2087 * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
2088 * {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002089 * <p>
2090 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002091 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2092 * not, a security exception will be thrown.
2093 * <p>
2094 * This method can be called on the {@link DevicePolicyManager} instance returned by
2095 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2096 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002097 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002098 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2099 * @param length The new desired minimum number of symbols required in the password. A value of
2100 * 0 means there is no restriction.
2101 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2102 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002103 */
Robin Lee25e26452015-06-02 09:56:29 -07002104 public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002105 if (mService != null) {
2106 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002107 mService.setPasswordMinimumSymbols(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002108 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002109 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002110 }
2111 }
2112 }
2113
2114 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002115 * Retrieve the current number of symbols required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002116 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002117 * and its participating profiles. Restrictions on profiles that have
2118 * a separate challenge are not taken into account. This is the same value as
2119 * set by {@link #setPasswordMinimumSymbols(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002120 * and only applies when the password quality is
2121 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002122 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002123 * <p>This method can be called on the {@link DevicePolicyManager} instance
2124 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2125 * restrictions on the parent profile.
2126 *
Robin Lee25e26452015-06-02 09:56:29 -07002127 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002128 * aggregate all admins.
2129 * @return The minimum number of symbols required in the password.
2130 */
Robin Lee25e26452015-06-02 09:56:29 -07002131 public int getPasswordMinimumSymbols(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002132 return getPasswordMinimumSymbols(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002133 }
2134
2135 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002136 public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002137 if (mService != null) {
2138 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002139 return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002140 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002141 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002142 }
2143 }
2144 return 0;
2145 }
2146
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002147 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002148 * Called by an application that is administering the device to set the minimum number of
2149 * non-letter characters (numerical digits or symbols) required in the password. After setting
2150 * this, the user will not be able to enter a new password that is not at least as restrictive
2151 * as what has been set. Note that the current password will remain until the user has set a new
2152 * one, so the change does not take place immediately. To prompt the user for a new password,
2153 * use {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
2154 * setting this value. This constraint is only imposed if the administrator has also requested
2155 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002156 * <p>
2157 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002158 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2159 * not, a security exception will be thrown.
2160 * <p>
2161 * This method can be called on the {@link DevicePolicyManager} instance returned by
2162 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2163 * profile.
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002164 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002165 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2166 * @param length The new desired minimum number of letters required in the password. A value of
2167 * 0 means there is no restriction.
2168 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2169 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002170 */
Robin Lee25e26452015-06-02 09:56:29 -07002171 public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002172 if (mService != null) {
2173 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002174 mService.setPasswordMinimumNonLetter(admin, length, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002175 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002176 throw e.rethrowFromSystemServer();
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002177 }
2178 }
2179 }
2180
2181 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002182 * Retrieve the current number of non-letter characters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002183 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002184 * and its participating profiles. Restrictions on profiles that have
2185 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01002186 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00002187 * {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002188 * and only applies when the password quality is
2189 * {@link #PASSWORD_QUALITY_COMPLEX}.
2190 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002191 * <p>This method can be called on the {@link DevicePolicyManager} instance
2192 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2193 * restrictions on the parent profile.
2194 *
Robin Lee25e26452015-06-02 09:56:29 -07002195 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002196 * aggregate all admins.
2197 * @return The minimum number of letters required in the password.
2198 */
Robin Lee25e26452015-06-02 09:56:29 -07002199 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002200 return getPasswordMinimumNonLetter(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002201 }
2202
2203 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002204 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002205 if (mService != null) {
2206 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002207 return mService.getPasswordMinimumNonLetter(admin, userHandle, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002208 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002209 throw e.rethrowFromSystemServer();
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002210 }
2211 }
2212 return 0;
2213 }
2214
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002215 /**
2216 * Called by an application that is administering the device to set the length of the password
2217 * history. After setting this, the user will not be able to enter a new password that is the
2218 * same as any password in the history. Note that the current password will remain until the
2219 * user has set a new one, so the change does not take place immediately. To prompt the user for
2220 * a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
2221 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
2222 * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC}
2223 * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX} {@link #PASSWORD_QUALITY_ALPHABETIC}, or
2224 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} with {@link #setPasswordQuality}.
2225 * <p>
2226 * The calling device admin must have requested
2227 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2228 * not, a security exception will be thrown.
2229 * <p>
2230 * This method can be called on the {@link DevicePolicyManager} instance returned by
2231 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2232 * profile.
2233 *
2234 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2235 * @param length The new desired length of password history. A value of 0 means there is no
2236 * restriction.
2237 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2238 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
2239 */
Robin Lee25e26452015-06-02 09:56:29 -07002240 public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002241 if (mService != null) {
2242 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002243 mService.setPasswordHistoryLength(admin, length, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002244 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002245 throw e.rethrowFromSystemServer();
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002246 }
2247 }
2248 }
2249
2250 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002251 * Called by a device admin to set the password expiration timeout. Calling this method will
2252 * restart the countdown for password expiration for the given admin, as will changing the
2253 * device password (for all admins).
2254 * <p>
2255 * The provided timeout is the time delta in ms and will be added to the current time. For
2256 * example, to have the password expire 5 days from now, timeout would be 5 * 86400 * 1000 =
2257 * 432000000 ms for timeout.
2258 * <p>
2259 * To disable password expiration, a value of 0 may be used for timeout.
2260 * <p>
2261 * The calling device admin must have requested
2262 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this method; if it has
2263 * not, a security exception will be thrown.
2264 * <p>
2265 * Note that setting the password will automatically reset the expiration time for all active
2266 * admins. Active admins do not need to explicitly call this method in that case.
2267 * <p>
2268 * This method can be called on the {@link DevicePolicyManager} instance returned by
2269 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2270 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002271 *
Jim Millera4e28d12010-11-08 16:15:47 -08002272 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002273 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0 means
2274 * there is no restriction (unlimited).
2275 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2276 * does not use {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD}
Jim Millera4e28d12010-11-08 16:15:47 -08002277 */
Robin Lee25e26452015-06-02 09:56:29 -07002278 public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) {
Jim Millera4e28d12010-11-08 16:15:47 -08002279 if (mService != null) {
2280 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002281 mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08002282 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002283 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08002284 }
2285 }
2286 }
2287
2288 /**
Jim Miller6b857682011-02-16 16:27:41 -08002289 * Get the password expiration timeout for the given admin. The expiration timeout is the
2290 * recurring expiration timeout provided in the call to
2291 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
Esteban Talaverac1c83592016-02-17 17:56:15 +00002292 * aggregate of all participating policy administrators if {@code admin} is null. Admins that
2293 * have set restrictions on profiles that have a separate challenge are not taken into account.
2294 *
2295 * <p>This method can be called on the {@link DevicePolicyManager} instance
2296 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2297 * restrictions on the parent profile.
Jim Millera4e28d12010-11-08 16:15:47 -08002298 *
Robin Lee25e26452015-06-02 09:56:29 -07002299 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08002300 * @return The timeout for the given admin or the minimum of all timeouts
2301 */
Robin Lee25e26452015-06-02 09:56:29 -07002302 public long getPasswordExpirationTimeout(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08002303 if (mService != null) {
2304 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002305 return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08002306 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002307 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08002308 }
2309 }
2310 return 0;
2311 }
2312
2313 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002314 * Get the current password expiration time for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01002315 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00002316 * a separate challenge are not taken into account. If admin is {@code null}, then a composite
2317 * of all expiration times is returned - which will be the minimum of all of them.
2318 *
2319 * <p>This method can be called on the {@link DevicePolicyManager} instance
2320 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2321 * the password expiration for the parent profile.
Jim Millera4e28d12010-11-08 16:15:47 -08002322 *
Robin Lee25e26452015-06-02 09:56:29 -07002323 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002324 * @return The password expiration time, in milliseconds since epoch.
Jim Millera4e28d12010-11-08 16:15:47 -08002325 */
Robin Lee25e26452015-06-02 09:56:29 -07002326 public long getPasswordExpiration(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08002327 if (mService != null) {
2328 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002329 return mService.getPasswordExpiration(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08002330 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002331 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08002332 }
2333 }
2334 return 0;
2335 }
2336
2337 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002338 * Retrieve the current password history length for a particular admin or all admins that
Rubin Xud3609d42016-07-13 18:32:57 +01002339 * set restrictions on this user and its participating profiles. Restrictions on profiles that
Esteban Talaverac1c83592016-02-17 17:56:15 +00002340 * have a separate challenge are not taken into account.
2341 *
2342 * <p>This method can be called on the {@link DevicePolicyManager} instance
2343 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2344 * restrictions on the parent profile.
2345 *
Robin Lee25e26452015-06-02 09:56:29 -07002346 * @param admin The name of the admin component to check, or {@code null} to aggregate
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002347 * all admins.
2348 * @return The length of the password history
2349 */
Robin Lee25e26452015-06-02 09:56:29 -07002350 public int getPasswordHistoryLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002351 return getPasswordHistoryLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002352 }
2353
2354 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002355 public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002356 if (mService != null) {
2357 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002358 return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002359 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002360 throw e.rethrowFromSystemServer();
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002361 }
2362 }
2363 return 0;
2364 }
2365
Dianne Hackbornd6847842010-01-12 18:14:19 -08002366 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08002367 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08002368 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08002369 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08002370 * @return Returns the maximum length that the user can enter.
2371 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08002372 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08002373 // Kind-of arbitrary.
2374 return 16;
2375 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002376
Dianne Hackborn254cb442010-01-27 19:23:59 -08002377 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002378 * Determine whether the current password the user has set is sufficient to meet the policy
2379 * requirements (e.g. quality, minimum length) that have been requested by the admins of this
2380 * user and its participating profiles. Restrictions on profiles that have a separate challenge
Andrew Scull5daf2732016-11-14 15:02:45 +00002381 * are not taken into account. The user must be unlocked in order to perform the check.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002382 * <p>
2383 * The calling device admin must have requested
2384 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2385 * not, a security exception will be thrown.
2386 * <p>
2387 * This method can be called on the {@link DevicePolicyManager} instance returned by
2388 * {@link #getParentProfileInstance(ComponentName)} in order to determine if the password set on
2389 * the parent profile is sufficient.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002390 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01002391 * @return Returns true if the password meets the current requirements, else false.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002392 * @throws SecurityException if the calling application does not own an active administrator
2393 * that uses {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Andrew Scull5daf2732016-11-14 15:02:45 +00002394 * @throws InvalidStateException if the user is not unlocked.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002395 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002396 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002397 if (mService != null) {
2398 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00002399 return mService.isActivePasswordSufficient(myUserId(), mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002400 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002401 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002402 }
2403 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002404 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08002405 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002406
Dianne Hackbornd6847842010-01-12 18:14:19 -08002407 /**
Clara Bayarrid7693912016-01-22 17:26:31 +00002408 * Determine whether the current profile password the user has set is sufficient
Esteban Talaverac1c83592016-02-17 17:56:15 +00002409 * to meet the policy requirements (e.g. quality, minimum length) that have been
Clara Bayarrid7693912016-01-22 17:26:31 +00002410 * requested by the admins of the parent user and its profiles.
2411 *
2412 * @param userHandle the userId of the profile to check the password for.
2413 * @return Returns true if the password would meet the current requirements, else false.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002414 * @throws SecurityException if {@code userHandle} is not a managed profile.
Clara Bayarrid7693912016-01-22 17:26:31 +00002415 * @hide
2416 */
2417 public boolean isProfileActivePasswordSufficientForParent(int userHandle) {
2418 if (mService != null) {
2419 try {
2420 return mService.isProfileActivePasswordSufficientForParent(userHandle);
2421 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002422 throw e.rethrowFromSystemServer();
Clara Bayarrid7693912016-01-22 17:26:31 +00002423 }
2424 }
2425 return false;
2426 }
2427
2428 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002429 * Retrieve the number of times the user has failed at entering a password since that last
2430 * successful password entry.
2431 * <p>
2432 * This method can be called on the {@link DevicePolicyManager} instance returned by
2433 * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the number of failed
2434 * password attemts for the parent user.
2435 * <p>
2436 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN}
2437 * to be able to call this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002438 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002439 * @return The number of times user has entered an incorrect password since the last correct
2440 * password entry.
2441 * @throws SecurityException if the calling application does not own an active administrator
2442 * that uses {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002443 */
2444 public int getCurrentFailedPasswordAttempts() {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00002445 return getCurrentFailedPasswordAttempts(myUserId());
2446 }
2447
2448 /**
2449 * Retrieve the number of times the given user has failed at entering a
2450 * password since that last successful password entry.
2451 *
2452 * <p>The calling device admin must have requested
2453 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call this method; if it has
2454 * not and it is not the system uid, a security exception will be thrown.
2455 *
2456 * @hide
2457 */
2458 public int getCurrentFailedPasswordAttempts(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002459 if (mService != null) {
2460 try {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00002461 return mService.getCurrentFailedPasswordAttempts(userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002462 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002463 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002464 }
2465 }
2466 return -1;
2467 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002468
2469 /**
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002470 * Queries whether {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002471 *
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002472 * @return true if RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002473 * @hide
2474 */
2475 public boolean getDoNotAskCredentialsOnBoot() {
2476 if (mService != null) {
2477 try {
2478 return mService.getDoNotAskCredentialsOnBoot();
2479 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002480 throw e.rethrowFromSystemServer();
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002481 }
2482 }
2483 return false;
2484 }
2485
2486 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002487 * Setting this to a value greater than zero enables a built-in policy that will perform a
2488 * device or profile wipe after too many incorrect device-unlock passwords have been entered.
2489 * This built-in policy combines watching for failed passwords and wiping the device, and
2490 * requires that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002491 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002492 * <p>
2493 * To implement any other policy (e.g. wiping data for a particular application only, erasing or
2494 * revoking credentials, or reporting the failure to a server), you should implement
2495 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} instead. Do not
2496 * use this API, because if the maximum count is reached, the device or profile will be wiped
2497 * immediately, and your callback will not be invoked.
2498 * <p>
2499 * This method can be called on the {@link DevicePolicyManager} instance returned by
2500 * {@link #getParentProfileInstance(ComponentName)} in order to set a value on the parent
2501 * profile.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002502 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002503 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002504 * @param num The number of failed password attempts at which point the device or profile will
2505 * be wiped.
2506 * @throws SecurityException if {@code admin} is not an active administrator or does not use
2507 * both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
2508 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002509 */
Robin Lee25e26452015-06-02 09:56:29 -07002510 public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002511 if (mService != null) {
2512 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002513 mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002514 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002515 throw e.rethrowFromSystemServer();
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002516 }
2517 }
2518 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002519
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002520 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002521 * Retrieve the current maximum number of login attempts that are allowed before the device
Rubin Xud3609d42016-07-13 18:32:57 +01002522 * or profile is wiped, for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002523 * and its participating profiles. Restrictions on profiles that have a separate challenge are
2524 * not taken into account.
2525 *
2526 * <p>This method can be called on the {@link DevicePolicyManager} instance
2527 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2528 * the value for the parent profile.
2529 *
Robin Lee25e26452015-06-02 09:56:29 -07002530 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002531 * all admins.
2532 */
Robin Lee25e26452015-06-02 09:56:29 -07002533 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002534 return getMaximumFailedPasswordsForWipe(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002535 }
2536
2537 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002538 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08002539 if (mService != null) {
2540 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002541 return mService.getMaximumFailedPasswordsForWipe(
2542 admin, userHandle, mParentInstance);
Dianne Hackborn254cb442010-01-27 19:23:59 -08002543 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002544 throw e.rethrowFromSystemServer();
Dianne Hackborn254cb442010-01-27 19:23:59 -08002545 }
2546 }
2547 return 0;
2548 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002549
Dianne Hackborn254cb442010-01-27 19:23:59 -08002550 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002551 * Returns the profile with the smallest maximum failed passwords for wipe,
2552 * for the given user. So for primary user, it might return the primary or
2553 * a managed profile. For a secondary user, it would be the same as the
2554 * user passed in.
2555 * @hide Used only by Keyguard
2556 */
2557 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
2558 if (mService != null) {
2559 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002560 return mService.getProfileWithMinimumFailedPasswordsForWipe(
2561 userHandle, mParentInstance);
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002562 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002563 throw e.rethrowFromSystemServer();
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002564 }
2565 }
2566 return UserHandle.USER_NULL;
2567 }
2568
2569 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002570 * Flag for {@link #resetPassword}: don't allow other admins to change
2571 * the password again until the user has entered it.
2572 */
2573 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002574
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002575 /**
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002576 * Flag for {@link #resetPassword}: don't ask for user credentials on device boot.
2577 * If the flag is set, the device can be booted without asking for user password.
2578 * The absence of this flag does not change the current boot requirements. This flag
2579 * can be set by the device owner only. If the app is not the device owner, the flag
2580 * is ignored. Once the flag is set, it cannot be reverted back without resetting the
2581 * device to factory defaults.
2582 */
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002583 public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002;
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002584
2585 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002586 * Force a new device unlock password (the password needed to access the entire device, not for
2587 * individual accounts) on the user. This takes effect immediately.
2588 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002589 * <em>Note: This API has been limited as of {@link android.os.Build.VERSION_CODES#N} for
Makoto Onuki70f929e2015-11-11 12:40:15 -08002590 * device admins that are not device owner and not profile owner.
2591 * The password can now only be changed if there is currently no password set. Device owner
Ricky Wai977ade22016-05-24 15:02:41 +01002592 * and profile owner can still do this when user is unlocked and does not have a managed
2593 * profile.</em>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002594 * <p>
2595 * The given password must be sufficient for the current password quality and length constraints
2596 * as returned by {@link #getPasswordQuality(ComponentName)} and
2597 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then
2598 * it will be rejected and false returned. Note that the password may be a stronger quality
2599 * (containing alphanumeric characters when the requested quality is only numeric), in which
2600 * case the currently active quality will be increased to match.
2601 * <p>
2602 * Calling with a null or empty password will clear any existing PIN, pattern or password if the
Robin Leece5c4002016-03-23 17:05:03 +00002603 * current password constraints allow it. <em>Note: This will not work in
2604 * {@link android.os.Build.VERSION_CODES#N} and later for managed profiles, or for device admins
2605 * that are not device owner or profile owner. Once set, the password cannot be changed to null
2606 * or empty except by these admins.</em>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002607 * <p>
2608 * The calling device admin must have requested
2609 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call this method; if it has
2610 * not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002611 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01002612 * @param password The new password for the user. Null or empty clears the password.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002613 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002614 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
2615 * @return Returns true if the password was applied, or false if it is not acceptable for the
2616 * current constraints or if the user has not been decrypted yet.
2617 * @throws SecurityException if the calling application does not own an active administrator
2618 * that uses {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD}
Ricky Wai977ade22016-05-24 15:02:41 +01002619 * @throws IllegalStateException if the calling user is locked or has a managed profile.
Andrew Scull3f81f4e2016-07-29 16:29:58 +01002620 * @throws IllegalArgumentException if the password does not meet system requirements.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002621 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002622 public boolean resetPassword(String password, int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002623 throwIfParentInstance("resetPassword");
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002624 if (mService != null) {
2625 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002626 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002627 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002628 throw e.rethrowFromSystemServer();
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002629 }
2630 }
2631 return false;
2632 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002633
Dianne Hackbornd6847842010-01-12 18:14:19 -08002634 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002635 * Called by an application that is administering the device to set the maximum time for user
2636 * activity until the device will lock. This limits the length that the user can set. It takes
2637 * effect immediately.
2638 * <p>
2639 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
2640 * to be able to call this method; if it has not, a security exception will be thrown.
2641 * <p>
2642 * This method can be called on the {@link DevicePolicyManager} instance returned by
2643 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2644 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002645 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002646 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002647 * @param timeMs The new desired maximum time to lock in milliseconds. A value of 0 means there
2648 * is no restriction.
2649 * @throws SecurityException if {@code admin} is not an active administrator or it does not use
2650 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002651 */
Robin Lee25e26452015-06-02 09:56:29 -07002652 public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002653 if (mService != null) {
2654 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002655 mService.setMaximumTimeToLock(admin, timeMs, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002656 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002657 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002658 }
2659 }
2660 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002661
Dianne Hackbornd6847842010-01-12 18:14:19 -08002662 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002663 * Retrieve the current maximum time to unlock for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01002664 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00002665 * a separate challenge are not taken into account.
2666 *
2667 * <p>This method can be called on the {@link DevicePolicyManager} instance
2668 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2669 * restrictions on the parent profile.
2670 *
Robin Lee25e26452015-06-02 09:56:29 -07002671 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002672 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07002673 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07002674 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002675 */
Robin Lee25e26452015-06-02 09:56:29 -07002676 public long getMaximumTimeToLock(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002677 return getMaximumTimeToLock(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002678 }
2679
2680 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002681 public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002682 if (mService != null) {
2683 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002684 return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002685 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002686 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002687 }
2688 }
2689 return 0;
2690 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002691
Dianne Hackbornd6847842010-01-12 18:14:19 -08002692 /**
Ricky Wai035e9242016-03-18 16:43:31 +00002693 * Returns maximum time to lock that applied by all profiles in this user. We do this because we
2694 * do not have a separate timeout to lock for work challenge only.
2695 *
2696 * @hide
2697 */
2698 public long getMaximumTimeToLockForUserAndProfiles(int userHandle) {
2699 if (mService != null) {
2700 try {
2701 return mService.getMaximumTimeToLockForUserAndProfiles(userHandle);
2702 } catch (RemoteException e) {
2703 throw e.rethrowFromSystemServer();
2704 }
2705 }
2706 return 0;
2707 }
2708
2709 /**
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002710 * Called by a device/profile owner to set the timeout after which unlocking with secondary, non
2711 * strong auth (e.g. fingerprint, trust agents) times out, i.e. the user has to use a strong
2712 * authentication method like password, pin or pattern.
2713 *
2714 * <p>This timeout is used internally to reset the timer to require strong auth again after
2715 * specified timeout each time it has been successfully used.
2716 *
2717 * <p>Fingerprint can also be disabled altogether using {@link #KEYGUARD_DISABLE_FINGERPRINT}.
2718 *
2719 * <p>Trust agents can also be disabled altogether using {@link #KEYGUARD_DISABLE_TRUST_AGENTS}.
2720 *
2721 * <p>The calling device admin must be a device or profile owner. If it is not,
2722 * a {@link SecurityException} will be thrown.
2723 *
Michal Karpinski943aabd2016-10-06 11:09:25 +01002724 * <p>The calling device admin can verify the value it has set by calling
2725 * {@link #getRequiredStrongAuthTimeout(ComponentName)} and passing in its instance.
2726 *
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002727 * <p>This method can be called on the {@link DevicePolicyManager} instance returned by
2728 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2729 * profile.
2730 *
2731 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2732 * @param timeoutMs The new timeout, after which the user will have to unlock with strong
Michal Karpinski943aabd2016-10-06 11:09:25 +01002733 * authentication method. A value of 0 means the admin is not participating in
2734 * controlling the timeout.
2735 * The minimum and maximum timeouts are platform-defined and are typically 1 hour and
2736 * 72 hours, respectively. Though discouraged, the admin may choose to require strong
2737 * auth at all times using {@link #KEYGUARD_DISABLE_FINGERPRINT} and/or
2738 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002739 *
2740 * @throws SecurityException if {@code admin} is not a device or profile owner.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002741 */
2742 public void setRequiredStrongAuthTimeout(@NonNull ComponentName admin,
2743 long timeoutMs) {
2744 if (mService != null) {
2745 try {
2746 mService.setRequiredStrongAuthTimeout(admin, timeoutMs, mParentInstance);
2747 } catch (RemoteException e) {
2748 throw e.rethrowFromSystemServer();
2749 }
2750 }
2751 }
2752
2753 /**
2754 * Determine for how long the user will be able to use secondary, non strong auth for
2755 * authentication, since last strong method authentication (password, pin or pattern) was used.
2756 * After the returned timeout the user is required to use strong authentication method.
2757 *
2758 * <p>This method can be called on the {@link DevicePolicyManager} instance
2759 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2760 * restrictions on the parent profile.
2761 *
2762 * @param admin The name of the admin component to check, or {@code null} to aggregate
2763 * accross all participating admins.
Michal Karpinski943aabd2016-10-06 11:09:25 +01002764 * @return The timeout or 0 if not configured for the provided admin.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002765 */
2766 public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin) {
2767 return getRequiredStrongAuthTimeout(admin, myUserId());
2768 }
2769
2770 /** @hide per-user version */
2771 public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin, @UserIdInt int userId) {
2772 if (mService != null) {
2773 try {
2774 return mService.getRequiredStrongAuthTimeout(admin, userId, mParentInstance);
2775 } catch (RemoteException e) {
2776 throw e.rethrowFromSystemServer();
2777 }
2778 }
2779 return DEFAULT_STRONG_AUTH_TIMEOUT_MS;
2780 }
2781
2782 /**
Andrew Scull85a63bc2016-10-24 13:47:47 +01002783 * Flag for {@link #lockNow(int)}: also evict the user's credential encryption key from the
2784 * keyring. The user's credential will need to be entered again in order to derive the
2785 * credential encryption key that will be stored back in the keyring for future use.
2786 * <p>
2787 * This flag can only be used by a profile owner when locking a managed profile on an FBE
2788 * device.
2789 * <p>
2790 * In order to secure user data, the user will be stopped and restarted so apps should wait
2791 * until they are next run to perform further actions.
2792 */
2793 public static final int FLAG_EVICT_CE_KEY = 1;
2794
2795 /** @hide */
2796 @Retention(RetentionPolicy.SOURCE)
2797 @IntDef(flag=true, value={FLAG_EVICT_CE_KEY})
2798 public @interface LockNowFlag {}
2799
2800 /**
2801 * Make the device lock immediately, as if the lock screen timeout has expired at the point of
2802 * this call.
2803 * <p>
2804 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
2805 * to be able to call this method; if it has not, a security exception will be thrown.
2806 * <p>
2807 * This method can be called on the {@link DevicePolicyManager} instance returned by
2808 * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile.
2809 * <p>
2810 * Equivalent to calling {@link #lockNow(int)} with no flags.
2811 *
2812 * @throws SecurityException if the calling application does not own an active administrator
2813 * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
2814 */
2815 public void lockNow() {
2816 lockNow(0);
2817 }
2818
2819 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002820 * Make the device lock immediately, as if the lock screen timeout has expired at the point of
2821 * this call.
2822 * <p>
2823 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
2824 * to be able to call this method; if it has not, a security exception will be thrown.
2825 * <p>
2826 * This method can be called on the {@link DevicePolicyManager} instance returned by
2827 * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002828 *
Andrew Scull85a63bc2016-10-24 13:47:47 +01002829 * @param flags May be 0 or {@link #FLAG_EVICT_CE_KEY}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002830 * @throws SecurityException if the calling application does not own an active administrator
Andrew Scull85a63bc2016-10-24 13:47:47 +01002831 * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} or the
2832 * {@link #FLAG_EVICT_CE_KEY} flag is passed by an application that is not a profile
2833 * owner of a managed profile.
2834 * @throws IllegalArgumentException if the {@link #FLAG_EVICT_CE_KEY} flag is passed when
2835 * locking the parent profile.
2836 * @throws UnsupportedOperationException if the {@link #FLAG_EVICT_CE_KEY} flag is passed on a
2837 * non-FBE device.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002838 */
Andrew Scull85a63bc2016-10-24 13:47:47 +01002839 public void lockNow(@LockNowFlag int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002840 if (mService != null) {
2841 try {
Andrew Scull85a63bc2016-10-24 13:47:47 +01002842 mService.lockNow(flags, mParentInstance);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002843 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002844 throw e.rethrowFromSystemServer();
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002845 }
2846 }
2847 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002848
Dianne Hackbornd6847842010-01-12 18:14:19 -08002849 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07002850 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002851 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07002852 */
2853 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
2854
2855 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002856 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
2857 * data.
2858 *
Paul Crowley2934b262014-12-02 11:21:13 +00002859 * <p>This flag may only be set by device owner admins; if it is set by
2860 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002861 */
2862 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
2863
2864 /**
Suprabh Shukla556b05a2016-08-10 15:49:24 -07002865 * Ask that all user data be wiped. If called as a secondary user, the user will be removed and
2866 * other users will remain unaffected. Calling from the primary user will cause the device to
2867 * reboot, erasing all device data - including all the secondary users and their data - while
2868 * booting up.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002869 * <p>
2870 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to
2871 * be able to call this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002872 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002873 * @param flags Bit mask of additional options: currently supported flags are
2874 * {@link #WIPE_EXTERNAL_STORAGE} and {@link #WIPE_RESET_PROTECTION_DATA}.
2875 * @throws SecurityException if the calling application does not own an active administrator
2876 * that uses {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002877 */
2878 public void wipeData(int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002879 throwIfParentInstance("wipeData");
Dianne Hackbornd6847842010-01-12 18:14:19 -08002880 if (mService != null) {
2881 try {
Makoto Onuki70f929e2015-11-11 12:40:15 -08002882 mService.wipeData(flags);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002883 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002884 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002885 }
2886 }
2887 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002888
Dianne Hackbornd6847842010-01-12 18:14:19 -08002889 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07002890 * Called by an application that is administering the device to set the
2891 * global proxy and exclusion list.
2892 * <p>
2893 * The calling device admin must have requested
2894 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
2895 * this method; if it has not, a security exception will be thrown.
2896 * Only the first device admin can set the proxy. If a second admin attempts
2897 * to set the proxy, the {@link ComponentName} of the admin originally setting the
Robin Lee25e26452015-06-02 09:56:29 -07002898 * proxy will be returned. If successful in setting the proxy, {@code null} will
Oscar Montemayor69238c62010-08-03 10:51:06 -07002899 * be returned.
2900 * The method can be called repeatedly by the device admin alrady setting the
2901 * proxy to update the proxy and exclusion list.
2902 *
Robin Lee25e26452015-06-02 09:56:29 -07002903 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Oscar Montemayor69238c62010-08-03 10:51:06 -07002904 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
2905 * Pass Proxy.NO_PROXY to reset the proxy.
2906 * @param exclusionList a list of domains to be excluded from the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07002907 * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName}
2908 * of the device admin that sets the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08002909 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07002910 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07002911 public @Nullable ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec,
Oscar Montemayor69238c62010-08-03 10:51:06 -07002912 List<String> exclusionList ) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002913 throwIfParentInstance("setGlobalProxy");
Oscar Montemayor69238c62010-08-03 10:51:06 -07002914 if (proxySpec == null) {
2915 throw new NullPointerException();
2916 }
2917 if (mService != null) {
2918 try {
2919 String hostSpec;
2920 String exclSpec;
2921 if (proxySpec.equals(Proxy.NO_PROXY)) {
2922 hostSpec = null;
2923 exclSpec = null;
2924 } else {
2925 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
2926 throw new IllegalArgumentException();
2927 }
2928 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
2929 String hostName = sa.getHostName();
2930 int port = sa.getPort();
2931 StringBuilder hostBuilder = new StringBuilder();
2932 hostSpec = hostBuilder.append(hostName)
2933 .append(":").append(Integer.toString(port)).toString();
2934 if (exclusionList == null) {
2935 exclSpec = "";
2936 } else {
2937 StringBuilder listBuilder = new StringBuilder();
2938 boolean firstDomain = true;
2939 for (String exclDomain : exclusionList) {
2940 if (!firstDomain) {
2941 listBuilder = listBuilder.append(",");
2942 } else {
2943 firstDomain = false;
2944 }
2945 listBuilder = listBuilder.append(exclDomain.trim());
2946 }
2947 exclSpec = listBuilder.toString();
2948 }
Yuhao Zheng90704842014-02-28 17:22:45 -08002949 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
2950 != android.net.Proxy.PROXY_VALID)
2951 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07002952 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002953 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07002954 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002955 throw e.rethrowFromSystemServer();
Oscar Montemayor69238c62010-08-03 10:51:06 -07002956 }
2957 }
2958 return null;
2959 }
2960
2961 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002962 * Set a network-independent global HTTP proxy. This is not normally what you want for typical
2963 * HTTP proxies - they are generally network dependent. However if you're doing something
2964 * unusual like general internal filtering this may be useful. On a private network where the
2965 * proxy is not accessible, you may break HTTP using this.
2966 * <p>
2967 * This method requires the caller to be the device owner.
2968 * <p>
2969 * This proxy is only a recommendation and it is possible that some apps will ignore it.
Jason Monk03bc9912014-05-13 09:44:57 -04002970 *
Jason Monk03bc9912014-05-13 09:44:57 -04002971 * @see ProxyInfo
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002972 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2973 * @param proxyInfo The a {@link ProxyInfo} object defining the new global HTTP proxy. A
2974 * {@code null} value will clear the global HTTP proxy.
2975 * @throws SecurityException if {@code admin} is not the device owner.
Jason Monk03bc9912014-05-13 09:44:57 -04002976 */
Robin Lee25e26452015-06-02 09:56:29 -07002977 public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo
2978 proxyInfo) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002979 throwIfParentInstance("setRecommendedGlobalProxy");
Jason Monk03bc9912014-05-13 09:44:57 -04002980 if (mService != null) {
2981 try {
2982 mService.setRecommendedGlobalProxy(admin, proxyInfo);
2983 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002984 throw e.rethrowFromSystemServer();
Jason Monk03bc9912014-05-13 09:44:57 -04002985 }
2986 }
2987 }
2988
2989 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07002990 * Returns the component name setting the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07002991 * @return ComponentName object of the device admin that set the global proxy, or {@code null}
2992 * if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08002993 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07002994 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07002995 public @Nullable ComponentName getGlobalProxyAdmin() {
Oscar Montemayor69238c62010-08-03 10:51:06 -07002996 if (mService != null) {
2997 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002998 return mService.getGlobalProxyAdmin(myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07002999 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003000 throw e.rethrowFromSystemServer();
Oscar Montemayor69238c62010-08-03 10:51:06 -07003001 }
3002 }
3003 return null;
3004 }
3005
3006 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08003007 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003008 * indicating that encryption is not supported.
3009 */
3010 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
3011
3012 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08003013 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003014 * indicating that encryption is supported, but is not currently active.
3015 */
3016 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
3017
3018 /**
Robin Lee3795fb02015-02-16 14:17:23 +00003019 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003020 * indicating that encryption is not currently active, but is currently
3021 * being activated. This is only reported by devices that support
3022 * encryption of data and only when the storage is currently
3023 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
3024 * to become encrypted will never return this value.
3025 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08003026 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003027
3028 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08003029 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003030 * indicating that encryption is active.
Amith Yamasani75db1252016-07-11 14:41:01 -07003031 * <p>
3032 * Also see {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003033 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08003034 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003035
3036 /**
Robin Lee3795fb02015-02-16 14:17:23 +00003037 * Result code for {@link #getStorageEncryptionStatus}:
3038 * indicating that encryption is active, but an encryption key has not
3039 * been set by the user.
3040 */
3041 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
3042
3043 /**
Makoto Onukid4c9e542016-02-25 18:17:30 -08003044 * Result code for {@link #getStorageEncryptionStatus}:
Amith Yamasani75db1252016-07-11 14:41:01 -07003045 * indicating that encryption is active and the encryption key is tied to the user or profile.
3046 * <p>
3047 * This value is only returned to apps targeting API level 24 and above. For apps targeting
3048 * earlier API levels, {@link #ENCRYPTION_STATUS_ACTIVE} is returned, even if the
3049 * encryption key is specific to the user or profile.
Makoto Onukid4c9e542016-02-25 18:17:30 -08003050 */
3051 public static final int ENCRYPTION_STATUS_ACTIVE_PER_USER = 5;
3052
3053 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003054 * Activity action: begin the process of encrypting data on the device. This activity should
3055 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
3056 * After resuming from this activity, use {@link #getStorageEncryption}
3057 * to check encryption status. However, on some devices this activity may never return, as
3058 * it may trigger a reboot and in some cases a complete data wipe of the device.
3059 */
3060 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
3061 public static final String ACTION_START_ENCRYPTION
3062 = "android.app.action.START_ENCRYPTION";
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003063 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07003064 * Widgets are enabled in keyguard
3065 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07003066 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07003067
3068 /**
Jim Miller50e62182014-04-23 17:25:00 -07003069 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07003070 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07003071 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
3072
3073 /**
3074 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
3075 */
3076 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
3077
3078 /**
Jim Miller50e62182014-04-23 17:25:00 -07003079 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
3080 */
3081 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
3082
3083 /**
3084 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
3085 */
3086 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
3087
3088 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02003089 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07003090 * (e.g. PIN/Pattern/Password).
3091 */
3092 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
3093
3094 /**
Jim Miller06e34502014-07-17 14:46:05 -07003095 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
3096 */
3097 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
3098
3099 /**
Adrian Roos7f06eed2016-02-05 15:21:02 -08003100 * Disable text entry into notifications on secure keyguard screens (e.g. PIN/Pattern/Password).
3101 */
3102 public static final int KEYGUARD_DISABLE_REMOTE_INPUT = 1 << 6;
3103
3104 /**
Jim Miller35207742012-11-02 15:33:20 -07003105 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07003106 */
3107 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07003108
3109 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003110 * Called by an application that is administering the device to request that the storage system
3111 * be encrypted.
3112 * <p>
3113 * When multiple device administrators attempt to control device encryption, the most secure,
3114 * supported setting will always be used. If any device administrator requests device
3115 * encryption, it will be enabled; Conversely, if a device administrator attempts to disable
3116 * device encryption while another device administrator has enabled it, the call to disable will
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003117 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003118 * <p>
3119 * This policy controls encryption of the secure (application data) storage area. Data written
3120 * to other storage areas may or may not be encrypted, and this policy does not require or
3121 * control the encryption of any other storage areas. There is one exception: If
3122 * {@link android.os.Environment#isExternalStorageEmulated()} is {@code true}, then the
3123 * directory returned by {@link android.os.Environment#getExternalStorageDirectory()} must be
3124 * written to disk within the encrypted storage area.
3125 * <p>
3126 * Important Note: On some devices, it is possible to encrypt storage without requiring the user
3127 * to create a device PIN or Password. In this case, the storage is encrypted, but the
3128 * encryption key may not be fully secured. For maximum security, the administrator should also
3129 * require (and check for) a pattern, PIN, or password.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003130 *
3131 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3132 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08003133 * @return the new request status (for all active admins) - will be one of
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003134 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
3135 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
3136 * {@link #getStorageEncryptionStatus()} to query the actual device state.
3137 * @throws SecurityException if {@code admin} is not an active administrator or does not use
3138 * {@link DeviceAdminInfo#USES_ENCRYPTED_STORAGE}
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003139 */
Robin Lee25e26452015-06-02 09:56:29 -07003140 public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003141 throwIfParentInstance("setStorageEncryption");
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003142 if (mService != null) {
3143 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003144 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003145 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003146 throw e.rethrowFromSystemServer();
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003147 }
3148 }
3149 return ENCRYPTION_STATUS_UNSUPPORTED;
3150 }
3151
3152 /**
3153 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08003154 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003155 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08003156 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
3157 * this will return the requested encryption setting as an aggregate of all active
3158 * administrators.
3159 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003160 */
Robin Lee25e26452015-06-02 09:56:29 -07003161 public boolean getStorageEncryption(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003162 throwIfParentInstance("getStorageEncryption");
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003163 if (mService != null) {
3164 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003165 return mService.getStorageEncryption(admin, myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003166 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003167 throw e.rethrowFromSystemServer();
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003168 }
3169 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08003170 return false;
3171 }
3172
3173 /**
3174 * Called by an application that is administering the device to
3175 * determine the current encryption status of the device.
Amith Yamasani75db1252016-07-11 14:41:01 -07003176 * <p>
Andy Stadler22dbfda2011-01-17 12:47:31 -08003177 * Depending on the returned status code, the caller may proceed in different
3178 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
3179 * storage system does not support encryption. If the
3180 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
3181 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00003182 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
3183 * storage system has enabled encryption but no password is set so further action
Amith Yamasani75db1252016-07-11 14:41:01 -07003184 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING},
3185 * {@link #ENCRYPTION_STATUS_ACTIVE} or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER},
3186 * no further action is required.
Andy Stadler22dbfda2011-01-17 12:47:31 -08003187 *
Robin Lee7e678712014-07-24 16:41:31 +01003188 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08003189 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00003190 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
Amith Yamasani75db1252016-07-11 14:41:01 -07003191 * {@link #ENCRYPTION_STATUS_ACTIVE}, or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08003192 */
3193 public int getStorageEncryptionStatus() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003194 throwIfParentInstance("getStorageEncryptionStatus");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003195 return getStorageEncryptionStatus(myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003196 }
3197
3198 /** @hide per-user version */
3199 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08003200 if (mService != null) {
3201 try {
Makoto Onukid4c9e542016-02-25 18:17:30 -08003202 return mService.getStorageEncryptionStatus(mContext.getPackageName(), userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08003203 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003204 throw e.rethrowFromSystemServer();
Andy Stadler22dbfda2011-01-17 12:47:31 -08003205 }
3206 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003207 return ENCRYPTION_STATUS_UNSUPPORTED;
3208 }
3209
3210 /**
Robin Lee2f7e1e42016-03-21 10:50:01 +00003211 * Mark a CA certificate as approved by the device user. This means that they have been notified
3212 * of the installation, were made aware of the risks, viewed the certificate and still wanted to
3213 * keep the certificate on the device.
3214 *
3215 * Calling with {@param approval} as {@code true} will cancel any ongoing warnings related to
3216 * this certificate.
3217 *
3218 * @hide
3219 */
3220 public boolean approveCaCert(String alias, int userHandle, boolean approval) {
3221 if (mService != null) {
3222 try {
3223 return mService.approveCaCert(alias, userHandle, approval);
3224 } catch (RemoteException e) {
3225 throw e.rethrowFromSystemServer();
3226 }
3227 }
3228 return false;
3229 }
3230
3231 /**
3232 * Check whether a CA certificate has been approved by the device user.
3233 *
3234 * @hide
3235 */
3236 public boolean isCaCertApproved(String alias, int userHandle) {
3237 if (mService != null) {
3238 try {
3239 return mService.isCaCertApproved(alias, userHandle);
3240 } catch (RemoteException e) {
3241 throw e.rethrowFromSystemServer();
3242 }
3243 }
3244 return false;
3245 }
3246
3247 /**
Robin Lee7e678712014-07-24 16:41:31 +01003248 * Installs the given certificate as a user CA.
3249 *
Robin Lee25e26452015-06-02 09:56:29 -07003250 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3251 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003252 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04003253 *
3254 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01003255 * interrupted, true otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003256 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3257 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04003258 */
Robin Lee25e26452015-06-02 09:56:29 -07003259 public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003260 throwIfParentInstance("installCaCert");
Maggie Benthallda51e682013-08-08 22:35:44 -04003261 if (mService != null) {
3262 try {
Robin Lee7e678712014-07-24 16:41:31 +01003263 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04003264 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003265 throw e.rethrowFromSystemServer();
Maggie Benthallda51e682013-08-08 22:35:44 -04003266 }
3267 }
3268 return false;
3269 }
3270
3271 /**
Robin Lee7e678712014-07-24 16:41:31 +01003272 * Uninstalls the given certificate from trusted user CAs, if present.
3273 *
Robin Lee25e26452015-06-02 09:56:29 -07003274 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3275 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003276 * @param certBuffer encoded form of the certificate to remove.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003277 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3278 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04003279 */
Robin Lee25e26452015-06-02 09:56:29 -07003280 public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003281 throwIfParentInstance("uninstallCaCert");
Maggie Benthallda51e682013-08-08 22:35:44 -04003282 if (mService != null) {
3283 try {
Robin Lee306fe082014-06-19 14:04:24 +00003284 final String alias = getCaCertAlias(certBuffer);
Robin Lee83881bd2015-06-09 16:04:38 -07003285 mService.uninstallCaCerts(admin, new String[] {alias});
Robin Lee306fe082014-06-19 14:04:24 +00003286 } catch (CertificateException e) {
3287 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04003288 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003289 throw e.rethrowFromSystemServer();
Maggie Benthallda51e682013-08-08 22:35:44 -04003290 }
3291 }
3292 }
3293
3294 /**
Robin Lee7e678712014-07-24 16:41:31 +01003295 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
3296 * If a user has installed any certificates by other means than device policy these will be
3297 * included too.
3298 *
Robin Lee25e26452015-06-02 09:56:29 -07003299 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3300 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003301 * @return a List of byte[] arrays, each encoding one user CA certificate.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003302 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3303 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04003304 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003305 public @NonNull List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) {
3306 final List<byte[]> certs = new ArrayList<byte[]>();
Benjamin Franzbc33c822016-04-15 08:57:52 +01003307 throwIfParentInstance("getInstalledCaCerts");
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003308 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01003309 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003310 mService.enforceCanManageCaCerts(admin);
3311 final TrustedCertificateStore certStore = new TrustedCertificateStore();
3312 for (String alias : certStore.userAliases()) {
3313 try {
3314 certs.add(certStore.getCertificate(alias).getEncoded());
3315 } catch (CertificateException ce) {
3316 Log.w(TAG, "Could not encode certificate: " + alias, ce);
3317 }
3318 }
3319 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003320 throw re.rethrowFromSystemServer();
Robin Lee7e678712014-07-24 16:41:31 +01003321 }
3322 }
3323 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04003324 }
3325
3326 /**
Robin Lee7e678712014-07-24 16:41:31 +01003327 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
3328 * means other than device policy will also be removed, except for system CA certificates.
3329 *
Robin Lee25e26452015-06-02 09:56:29 -07003330 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3331 * {@code null} if calling from a delegated certificate installer.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003332 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3333 * owner.
Robin Lee7e678712014-07-24 16:41:31 +01003334 */
Robin Lee25e26452015-06-02 09:56:29 -07003335 public void uninstallAllUserCaCerts(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003336 throwIfParentInstance("uninstallAllUserCaCerts");
Robin Lee7e678712014-07-24 16:41:31 +01003337 if (mService != null) {
Robin Lee83881bd2015-06-09 16:04:38 -07003338 try {
3339 mService.uninstallCaCerts(admin, new TrustedCertificateStore().userAliases()
3340 .toArray(new String[0]));
3341 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003342 throw re.rethrowFromSystemServer();
Robin Lee7e678712014-07-24 16:41:31 +01003343 }
3344 }
3345 }
3346
3347 /**
3348 * Returns whether this certificate is installed as a trusted CA.
3349 *
Robin Lee25e26452015-06-02 09:56:29 -07003350 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3351 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003352 * @param certBuffer encoded form of the certificate to look up.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003353 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3354 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04003355 */
Robin Lee25e26452015-06-02 09:56:29 -07003356 public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003357 throwIfParentInstance("hasCaCertInstalled");
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003358 if (mService != null) {
3359 try {
3360 mService.enforceCanManageCaCerts(admin);
3361 return getCaCertAlias(certBuffer) != null;
3362 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003363 throw re.rethrowFromSystemServer();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003364 } catch (CertificateException ce) {
3365 Log.w(TAG, "Could not parse certificate", ce);
3366 }
Maggie Benthallda51e682013-08-08 22:35:44 -04003367 }
3368 return false;
3369 }
3370
3371 /**
Robin Leece3399f2016-02-24 12:08:32 +00003372 * Called by a device or profile owner, or delegated certificate installer, to install a
3373 * certificate and corresponding private key. All apps within the profile will be able to access
3374 * the certificate and use the private key, given direct user approval.
3375 *
3376 * <p>Access to the installed credentials will not be granted to the caller of this API without
3377 * direct user approval. This is for security - should a certificate installer become
3378 * compromised, certificates it had already installed will be protected.
3379 *
3380 * <p>If the installer must have access to the credentials, call
Rubin Xub4365912016-03-23 12:13:22 +00003381 * {@link #installKeyPair(ComponentName, PrivateKey, Certificate[], String, boolean)} instead.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003382 *
Robin Lee25e26452015-06-02 09:56:29 -07003383 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3384 * {@code null} if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003385 * @param privKey The private key to install.
3386 * @param cert The certificate to install.
3387 * @param alias The private key alias under which to install the certificate. If a certificate
3388 * with that alias already exists, it will be overwritten.
3389 * @return {@code true} if the keys were installed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003390 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3391 * owner.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003392 */
Robin Leefbc65642015-08-03 16:21:22 +01003393 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
3394 @NonNull Certificate cert, @NonNull String alias) {
Rubin Xub4365912016-03-23 12:13:22 +00003395 return installKeyPair(admin, privKey, new Certificate[] {cert}, alias, false);
Robin Leece3399f2016-02-24 12:08:32 +00003396 }
3397
3398 /**
3399 * Called by a device or profile owner, or delegated certificate installer, to install a
Rubin Xub4365912016-03-23 12:13:22 +00003400 * certificate chain and corresponding private key for the leaf certificate. All apps within the
3401 * profile will be able to access the certificate chain and use the private key, given direct
3402 * user approval.
Robin Leece3399f2016-02-24 12:08:32 +00003403 *
Robin Leea1b290e2016-03-09 14:38:36 +00003404 * <p>The caller of this API may grant itself access to the certificate and private key
3405 * immediately, without user approval. It is a best practice not to request this unless strictly
3406 * necessary since it opens up additional security vulnerabilities.
Robin Leece3399f2016-02-24 12:08:32 +00003407 *
3408 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Robin Leea1b290e2016-03-09 14:38:36 +00003409 * {@code null} if calling from a delegated certificate installer.
Robin Leece3399f2016-02-24 12:08:32 +00003410 * @param privKey The private key to install.
Rubin Xub4365912016-03-23 12:13:22 +00003411 * @param certs The certificate chain to install. The chain should start with the leaf
3412 * certificate and include the chain of trust in order. This will be returned by
3413 * {@link android.security.KeyChain#getCertificateChain}.
Robin Leece3399f2016-02-24 12:08:32 +00003414 * @param alias The private key alias under which to install the certificate. If a certificate
Robin Leea1b290e2016-03-09 14:38:36 +00003415 * with that alias already exists, it will be overwritten.
Robin Leece3399f2016-02-24 12:08:32 +00003416 * @param requestAccess {@code true} to request that the calling app be granted access to the
Robin Leea1b290e2016-03-09 14:38:36 +00003417 * credentials immediately. Otherwise, access to the credentials will be gated by user
3418 * approval.
Robin Leece3399f2016-02-24 12:08:32 +00003419 * @return {@code true} if the keys were installed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003420 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3421 * owner.
Rubin Xub4365912016-03-23 12:13:22 +00003422 * @see android.security.KeyChain#getCertificateChain
Robin Leece3399f2016-02-24 12:08:32 +00003423 */
3424 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
Rubin Xub4365912016-03-23 12:13:22 +00003425 @NonNull Certificate[] certs, @NonNull String alias, boolean requestAccess) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003426 throwIfParentInstance("installKeyPair");
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003427 try {
Rubin Xub4365912016-03-23 12:13:22 +00003428 final byte[] pemCert = Credentials.convertToPem(certs[0]);
3429 byte[] pemChain = null;
3430 if (certs.length > 1) {
3431 pemChain = Credentials.convertToPem(Arrays.copyOfRange(certs, 1, certs.length));
3432 }
Robin Lee0d5ccb72014-09-12 17:41:44 +01003433 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
3434 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
Rubin Xub4365912016-03-23 12:13:22 +00003435 return mService.installKeyPair(admin, pkcs8Key, pemCert, pemChain, alias,
3436 requestAccess);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003437 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003438 throw e.rethrowFromSystemServer();
Robin Lee0d5ccb72014-09-12 17:41:44 +01003439 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
3440 Log.w(TAG, "Failed to obtain private key material", e);
3441 } catch (CertificateException | IOException e) {
3442 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003443 }
3444 return false;
3445 }
3446
3447 /**
Robin Leea1b290e2016-03-09 14:38:36 +00003448 * Called by a device or profile owner, or delegated certificate installer, to remove a
3449 * certificate and private key pair installed under a given alias.
Robin Leefbc65642015-08-03 16:21:22 +01003450 *
3451 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Robin Leea1b290e2016-03-09 14:38:36 +00003452 * {@code null} if calling from a delegated certificate installer.
Robin Leefbc65642015-08-03 16:21:22 +01003453 * @param alias The private key alias under which the certificate is installed.
Robin Leea1b290e2016-03-09 14:38:36 +00003454 * @return {@code true} if the private key alias no longer exists, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003455 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3456 * owner.
Robin Leefbc65642015-08-03 16:21:22 +01003457 */
3458 public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003459 throwIfParentInstance("removeKeyPair");
Robin Leefbc65642015-08-03 16:21:22 +01003460 try {
3461 return mService.removeKeyPair(admin, alias);
3462 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003463 throw e.rethrowFromSystemServer();
Robin Leefbc65642015-08-03 16:21:22 +01003464 }
Robin Leefbc65642015-08-03 16:21:22 +01003465 }
3466
3467 /**
Robin Lee25e26452015-06-02 09:56:29 -07003468 * @return the alias of a given CA certificate in the certificate store, or {@code null} if it
Robin Lee306fe082014-06-19 14:04:24 +00003469 * doesn't exist.
3470 */
3471 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
3472 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
3473 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
3474 new ByteArrayInputStream(certBuffer));
3475 return new TrustedCertificateStore().getCertificateAlias(cert);
3476 }
3477
3478 /**
Rubin Xuec32b562015-03-03 17:34:05 +00003479 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01003480 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00003481 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01003482 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00003483 * <p>
3484 * Delegated certificate installer is a per-user state. The delegated access is persistent until
3485 * it is later cleared by calling this method with a null value or uninstallling the certificate
3486 * installer.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003487 * <p>
Rubin Xuf03d0a62016-02-10 14:54:15 +00003488 * <b>Note:</b>Starting from {@link android.os.Build.VERSION_CODES#N}, if the caller
3489 * application's target SDK version is {@link android.os.Build.VERSION_CODES#N} or newer, the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003490 * supplied certificate installer package must be installed when calling this API, otherwise an
3491 * {@link IllegalArgumentException} will be thrown.
Rubin Xuec32b562015-03-03 17:34:05 +00003492 *
Robin Lee25e26452015-06-02 09:56:29 -07003493 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xuec32b562015-03-03 17:34:05 +00003494 * @param installerPackage The package name of the certificate installer which will be given
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003495 * access. If {@code null} is given the current package will be cleared.
3496 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Rubin Xuec32b562015-03-03 17:34:05 +00003497 */
Robin Lee25e26452015-06-02 09:56:29 -07003498 public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String
3499 installerPackage) throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003500 throwIfParentInstance("setCertInstallerPackage");
Rubin Xuec32b562015-03-03 17:34:05 +00003501 if (mService != null) {
3502 try {
Robin Lee25e26452015-06-02 09:56:29 -07003503 mService.setCertInstallerPackage(admin, installerPackage);
Rubin Xuec32b562015-03-03 17:34:05 +00003504 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003505 throw e.rethrowFromSystemServer();
Rubin Xuec32b562015-03-03 17:34:05 +00003506 }
3507 }
3508 }
3509
3510 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003511 * Called by a profile owner or device owner to retrieve the certificate installer for the user.
3512 * null if none is set.
Rubin Xuec32b562015-03-03 17:34:05 +00003513 *
Robin Lee25e26452015-06-02 09:56:29 -07003514 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003515 * @return The package name of the current delegated certificate installer, or {@code null} if
3516 * none is set.
3517 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Rubin Xuec32b562015-03-03 17:34:05 +00003518 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003519 public @Nullable String getCertInstallerPackage(@NonNull ComponentName admin)
3520 throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003521 throwIfParentInstance("getCertInstallerPackage");
Rubin Xuec32b562015-03-03 17:34:05 +00003522 if (mService != null) {
3523 try {
Robin Lee25e26452015-06-02 09:56:29 -07003524 return mService.getCertInstallerPackage(admin);
Rubin Xuec32b562015-03-03 17:34:05 +00003525 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003526 throw e.rethrowFromSystemServer();
Rubin Xuec32b562015-03-03 17:34:05 +00003527 }
3528 }
3529 return null;
3530 }
3531
3532 /**
Robin Lee244ce8e2016-01-05 18:03:46 +00003533 * Called by a device or profile owner to configure an always-on VPN connection through a
Robin Leedc679712016-05-03 13:23:03 +01003534 * specific application for the current user.
3535 *
3536 * @deprecated this version only exists for compability with previous developer preview builds.
3537 * TODO: delete once there are no longer any live references.
3538 * @hide
3539 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07003540 @Deprecated
Robin Leedc679712016-05-03 13:23:03 +01003541 public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage)
3542 throws NameNotFoundException, UnsupportedOperationException {
3543 setAlwaysOnVpnPackage(admin, vpnPackage, /* lockdownEnabled */ true);
3544 }
3545
3546 /**
3547 * Called by a device or profile owner to configure an always-on VPN connection through a
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003548 * specific application for the current user. This connection is automatically granted and
3549 * persisted after a reboot.
3550 * <p>
3551 * The designated package should declare a {@link android.net.VpnService} in its manifest
3552 * guarded by {@link android.Manifest.permission#BIND_VPN_SERVICE}, otherwise the call will
3553 * fail.
Robin Lee244ce8e2016-01-05 18:03:46 +00003554 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003555 * @param vpnPackage The package name for an installed VPN app on the device, or {@code null} to
Robin Leedc679712016-05-03 13:23:03 +01003556 * remove an existing always-on VPN configuration.
3557 * @param lockdownEnabled {@code true} to disallow networking when the VPN is not connected or
3558 * {@code false} otherwise. This carries the risk that any failure of the VPN provider
3559 * could break networking for all apps. This has no effect when clearing.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003560 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Robin Leeee5eb932016-04-05 16:27:15 +01003561 * @throws NameNotFoundException if {@code vpnPackage} is not installed.
3562 * @throws UnsupportedOperationException if {@code vpnPackage} exists but does not support being
3563 * set as always-on, or if always-on VPN is not available.
Robin Lee244ce8e2016-01-05 18:03:46 +00003564 */
Robin Leedc679712016-05-03 13:23:03 +01003565 public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage,
3566 boolean lockdownEnabled)
Robin Leeee5eb932016-04-05 16:27:15 +01003567 throws NameNotFoundException, UnsupportedOperationException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003568 throwIfParentInstance("setAlwaysOnVpnPackage");
Robin Lee244ce8e2016-01-05 18:03:46 +00003569 if (mService != null) {
3570 try {
Robin Leedc679712016-05-03 13:23:03 +01003571 if (!mService.setAlwaysOnVpnPackage(admin, vpnPackage, lockdownEnabled)) {
Robin Leeee5eb932016-04-05 16:27:15 +01003572 throw new NameNotFoundException(vpnPackage);
3573 }
Robin Lee244ce8e2016-01-05 18:03:46 +00003574 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003575 throw e.rethrowFromSystemServer();
Robin Lee244ce8e2016-01-05 18:03:46 +00003576 }
3577 }
Robin Lee244ce8e2016-01-05 18:03:46 +00003578 }
3579
3580 /**
3581 * Called by a device or profile owner to read the name of the package administering an
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003582 * always-on VPN connection for the current user. If there is no such package, or the always-on
3583 * VPN is provided by the system instead of by an application, {@code null} will be returned.
Robin Lee244ce8e2016-01-05 18:03:46 +00003584 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003585 * @return Package name of VPN controller responsible for always-on VPN, or {@code null} if none
3586 * is set.
3587 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Robin Lee244ce8e2016-01-05 18:03:46 +00003588 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003589 public @Nullable String getAlwaysOnVpnPackage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003590 throwIfParentInstance("getAlwaysOnVpnPackage");
Robin Lee244ce8e2016-01-05 18:03:46 +00003591 if (mService != null) {
3592 try {
3593 return mService.getAlwaysOnVpnPackage(admin);
3594 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003595 throw e.rethrowFromSystemServer();
Robin Lee244ce8e2016-01-05 18:03:46 +00003596 }
3597 }
3598 return null;
3599 }
3600
3601 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003602 * Called by an application that is administering the device to disable all cameras on the
3603 * device, for this user. After setting this, no applications running as this user will be able
3604 * to access any cameras on the device.
3605 * <p>
3606 * If the caller is device owner, then the restriction will be applied to all users.
3607 * <p>
3608 * The calling device admin must have requested
3609 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call this method; if it has
3610 * not, a security exception will be thrown.
Ben Komalo2447edd2011-05-09 16:05:33 -07003611 *
3612 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3613 * @param disabled Whether or not the camera should be disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003614 * @throws SecurityException if {@code admin} is not an active administrator or does not use
3615 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA}.
Ben Komalo2447edd2011-05-09 16:05:33 -07003616 */
Robin Lee25e26452015-06-02 09:56:29 -07003617 public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003618 throwIfParentInstance("setCameraDisabled");
Ben Komalo2447edd2011-05-09 16:05:33 -07003619 if (mService != null) {
3620 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003621 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07003622 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003623 throw e.rethrowFromSystemServer();
Ben Komalo2447edd2011-05-09 16:05:33 -07003624 }
3625 }
3626 }
3627
3628 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07003629 * Determine whether or not the device's cameras have been disabled for this user,
Makoto Onuki32b30572015-12-11 14:29:51 -08003630 * either by the calling admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07003631 * @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 -07003632 * have disabled the camera
3633 */
Robin Lee25e26452015-06-02 09:56:29 -07003634 public boolean getCameraDisabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003635 throwIfParentInstance("getCameraDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003636 return getCameraDisabled(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003637 }
3638
3639 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003640 public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07003641 if (mService != null) {
3642 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003643 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07003644 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003645 throw e.rethrowFromSystemServer();
Ben Komalo2447edd2011-05-09 16:05:33 -07003646 }
3647 }
3648 return false;
3649 }
3650
3651 /**
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003652 * Called by a device owner to request a bugreport.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003653 * <p>
Esteban Talaverad36dd152016-12-15 08:51:45 +00003654 * If the device contains secondary users or profiles, they must be affiliated with the device
3655 * owner user. Otherwise a {@link SecurityException} will be thrown. See
3656 * {@link #setAffiliationIds}.
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003657 *
3658 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003659 * @return {@code true} if the bugreport collection started successfully, or {@code false} if it
3660 * wasn't triggered because a previous bugreport operation is still active (either the
3661 * bugreport is still running or waiting for the user to share or decline)
Esteban Talaverad36dd152016-12-15 08:51:45 +00003662 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
3663 * profile or secondary user that is not affiliated with the device owner user.
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003664 */
3665 public boolean requestBugreport(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003666 throwIfParentInstance("requestBugreport");
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003667 if (mService != null) {
3668 try {
3669 return mService.requestBugreport(admin);
3670 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003671 throw e.rethrowFromSystemServer();
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003672 }
3673 }
3674 return false;
3675 }
3676
3677 /**
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07003678 * Determine whether or not creating a guest user has been disabled for the device
3679 *
3680 * @hide
3681 */
3682 public boolean getGuestUserDisabled(@Nullable ComponentName admin) {
3683 // Currently guest users can always be created if multi-user is enabled
3684 // TODO introduce a policy for guest user creation
3685 return false;
3686 }
3687
3688 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01003689 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
3690 * screen capture also prevents the content from being shown on display devices that do not have
3691 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
3692 * secure surfaces and secure displays.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003693 * <p>
3694 * The calling device admin must be a device or profile owner. If it is not, a security
3695 * exception will be thrown.
3696 * <p>
3697 * From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also blocks
3698 * assist requests for all activities of the relevant user.
Benjamin Franzc200f442015-06-25 18:20:04 +01003699 *
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003700 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003701 * @param disabled Whether screen capture is disabled or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003702 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003703 */
Robin Lee25e26452015-06-02 09:56:29 -07003704 public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003705 throwIfParentInstance("setScreenCaptureDisabled");
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003706 if (mService != null) {
3707 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003708 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003709 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003710 throw e.rethrowFromSystemServer();
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003711 }
3712 }
3713 }
3714
3715 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08003716 * Determine whether or not screen capture has been disabled by the calling
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003717 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07003718 * @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 +01003719 * have disabled screen capture.
3720 */
Robin Lee25e26452015-06-02 09:56:29 -07003721 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003722 throwIfParentInstance("getScreenCaptureDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003723 return getScreenCaptureDisabled(admin, myUserId());
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003724 }
3725
3726 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003727 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003728 if (mService != null) {
3729 try {
3730 return mService.getScreenCaptureDisabled(admin, userHandle);
3731 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003732 throw e.rethrowFromSystemServer();
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003733 }
3734 }
3735 return false;
3736 }
3737
3738 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003739 * Called by a device owner to set whether auto time is required. If auto time is required the
3740 * user cannot set the date and time, but has to use network date and time.
3741 * <p>
3742 * Note: if auto time is required the user can still manually set the time zone.
3743 * <p>
3744 * The calling device admin must be a device owner. If it is not, a security exception will be
3745 * thrown.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003746 *
3747 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3748 * @param required Whether auto time is set required or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003749 * @throws SecurityException if {@code admin} is not a device owner.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003750 */
Robin Lee25e26452015-06-02 09:56:29 -07003751 public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003752 throwIfParentInstance("setAutoTimeRequired");
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003753 if (mService != null) {
3754 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003755 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003756 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003757 throw e.rethrowFromSystemServer();
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003758 }
3759 }
3760 }
3761
3762 /**
3763 * @return true if auto time is required.
3764 */
3765 public boolean getAutoTimeRequired() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003766 throwIfParentInstance("getAutoTimeRequired");
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003767 if (mService != null) {
3768 try {
3769 return mService.getAutoTimeRequired();
3770 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003771 throw e.rethrowFromSystemServer();
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003772 }
3773 }
3774 return false;
3775 }
3776
3777 /**
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003778 * Called by a device owner to set whether all users created on the device should be ephemeral.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003779 * <p>
3780 * The system user is exempt from this policy - it is never ephemeral.
3781 * <p>
3782 * The calling device admin must be the device owner. If it is not, a security exception will be
3783 * thrown.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003784 *
3785 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3786 * @param forceEphemeralUsers If true, all the existing users will be deleted and all
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003787 * subsequently created users will be ephemeral.
3788 * @throws SecurityException if {@code admin} is not a device owner.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003789 * @hide
3790 */
3791 public void setForceEphemeralUsers(
3792 @NonNull ComponentName admin, boolean forceEphemeralUsers) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003793 throwIfParentInstance("setForceEphemeralUsers");
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003794 if (mService != null) {
3795 try {
3796 mService.setForceEphemeralUsers(admin, forceEphemeralUsers);
3797 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003798 throw e.rethrowFromSystemServer();
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003799 }
3800 }
3801 }
3802
3803 /**
3804 * @return true if all users are created ephemeral.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003805 * @throws SecurityException if {@code admin} is not a device owner.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003806 * @hide
3807 */
3808 public boolean getForceEphemeralUsers(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003809 throwIfParentInstance("getForceEphemeralUsers");
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003810 if (mService != null) {
3811 try {
3812 return mService.getForceEphemeralUsers(admin);
3813 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003814 throw e.rethrowFromSystemServer();
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003815 }
3816 }
3817 return false;
3818 }
3819
3820 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07003821 * Called by an application that is administering the device to disable keyguard customizations,
3822 * such as widgets. After setting this, keyguard features will be disabled according to the
3823 * provided feature list.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003824 * <p>
3825 * The calling device admin must have requested
3826 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method;
3827 * if it has not, a security exception will be thrown.
3828 * <p>
3829 * Calling this from a managed profile before version {@link android.os.Build.VERSION_CODES#M}
3830 * will throw a security exception. From version {@link android.os.Build.VERSION_CODES#M} the
3831 * profile owner of a managed profile can set:
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003832 * <ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00003833 * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which affects the parent user, but only if there
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003834 * is no separate challenge set on the managed profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00003835 * <li>{@link #KEYGUARD_DISABLE_FINGERPRINT} which affects the managed profile challenge if
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003836 * there is one, or the parent user otherwise.
3837 * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} which affects notifications generated
3838 * by applications in the managed profile.
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003839 * </ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00003840 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} and {@link #KEYGUARD_DISABLE_FINGERPRINT} can also be
3841 * set on the {@link DevicePolicyManager} instance returned by
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003842 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
3843 * profile.
3844 * <p>
3845 * Requests to disable other features on a managed profile will be ignored.
3846 * <p>
3847 * The admin can check which features have been disabled by calling
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003848 * {@link #getKeyguardDisabledFeatures(ComponentName)}
Amith Yamasani242f4b12014-10-14 16:06:13 -07003849 *
Jim Millerb8ec4702012-08-31 17:19:10 -07003850 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07003851 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003852 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
3853 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS},
3854 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
3855 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS},
3856 * {@link #KEYGUARD_DISABLE_FINGERPRINT}, {@link #KEYGUARD_DISABLE_FEATURES_ALL}
3857 * @throws SecurityException if {@code admin} is not an active administrator or does not user
3858 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES}
Jim Millerb8ec4702012-08-31 17:19:10 -07003859 */
Robin Lee25e26452015-06-02 09:56:29 -07003860 public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07003861 if (mService != null) {
3862 try {
Esteban Talavera62399912016-01-11 15:37:55 +00003863 mService.setKeyguardDisabledFeatures(admin, which, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07003864 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003865 throw e.rethrowFromSystemServer();
Jim Millerb8ec4702012-08-31 17:19:10 -07003866 }
3867 }
3868 }
3869
3870 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08003871 * Determine whether or not features have been disabled in keyguard either by the calling
Rubin Xud3609d42016-07-13 18:32:57 +01003872 * admin, if specified, or all admins that set restrictions on this user and its participating
Esteban Talaverac1c83592016-02-17 17:56:15 +00003873 * profiles. Restrictions on profiles that have a separate challenge are not taken into account.
3874 *
3875 * <p>This method can be called on the {@link DevicePolicyManager} instance
3876 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
3877 * restrictions on the parent profile.
3878 *
Esteban Talavera62399912016-01-11 15:37:55 +00003879 * @param admin The name of the admin component to check, or {@code null} to check whether any
3880 * admins have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07003881 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
3882 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07003883 */
Robin Lee25e26452015-06-02 09:56:29 -07003884 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003885 return getKeyguardDisabledFeatures(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003886 }
3887
3888 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003889 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07003890 if (mService != null) {
3891 try {
Esteban Talavera62399912016-01-11 15:37:55 +00003892 return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07003893 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003894 throw e.rethrowFromSystemServer();
Jim Millerb8ec4702012-08-31 17:19:10 -07003895 }
3896 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07003897 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07003898 }
3899
3900 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08003901 * @hide
3902 */
Robin Lee25e26452015-06-02 09:56:29 -07003903 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
3904 int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003905 if (mService != null) {
3906 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01003907 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003908 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003909 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003910 }
3911 }
3912 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003913
Dianne Hackbornd6847842010-01-12 18:14:19 -08003914 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01003915 * @hide
3916 */
Robin Lee25e26452015-06-02 09:56:29 -07003917 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003918 setActiveAdmin(policyReceiver, refreshing, myUserId());
Jessica Hummel6d36b602014-04-04 12:42:17 +01003919 }
3920
3921 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08003922 * @hide
3923 */
Robin Lee25e26452015-06-02 09:56:29 -07003924 public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08003925 if (mService != null) {
3926 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003927 mService.getRemoveWarning(admin, result, myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08003928 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003929 throw e.rethrowFromSystemServer();
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08003930 }
3931 }
3932 }
3933
3934 /**
3935 * @hide
3936 */
Andrew Scull5f9e6f32016-08-02 14:22:17 +01003937 public void setActivePasswordState(PasswordMetrics metrics, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003938 if (mService != null) {
3939 try {
Andrew Scull5f9e6f32016-08-02 14:22:17 +01003940 mService.setActivePasswordState(metrics, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003941 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003942 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003943 }
3944 }
3945 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003946
Dianne Hackbornd6847842010-01-12 18:14:19 -08003947 /**
3948 * @hide
3949 */
Andrew Scull5daf2732016-11-14 15:02:45 +00003950 public void reportPasswordChanged(@UserIdInt int userId) {
3951 if (mService != null) {
3952 try {
3953 mService.reportPasswordChanged(userId);
3954 } catch (RemoteException e) {
3955 throw e.rethrowFromSystemServer();
3956 }
3957 }
3958 }
3959
3960 /**
3961 * @hide
3962 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003963 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003964 if (mService != null) {
3965 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003966 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003967 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003968 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003969 }
3970 }
3971 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003972
Dianne Hackbornd6847842010-01-12 18:14:19 -08003973 /**
3974 * @hide
3975 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003976 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003977 if (mService != null) {
3978 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003979 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003980 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003981 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003982 }
3983 }
3984 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07003985
3986 /**
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003987 * @hide
3988 */
3989 public void reportFailedFingerprintAttempt(int userHandle) {
3990 if (mService != null) {
3991 try {
3992 mService.reportFailedFingerprintAttempt(userHandle);
3993 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003994 throw e.rethrowFromSystemServer();
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003995 }
3996 }
3997 }
3998
3999 /**
4000 * @hide
4001 */
4002 public void reportSuccessfulFingerprintAttempt(int userHandle) {
4003 if (mService != null) {
4004 try {
4005 mService.reportSuccessfulFingerprintAttempt(userHandle);
4006 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004007 throw e.rethrowFromSystemServer();
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004008 }
4009 }
4010 }
4011
4012 /**
Michal Karpinski31502d32016-01-25 16:43:07 +00004013 * Should be called when keyguard has been dismissed.
4014 * @hide
4015 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004016 public void reportKeyguardDismissed(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00004017 if (mService != null) {
4018 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004019 mService.reportKeyguardDismissed(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00004020 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004021 throw e.rethrowFromSystemServer();
Michal Karpinski31502d32016-01-25 16:43:07 +00004022 }
4023 }
4024 }
4025
4026 /**
4027 * Should be called when keyguard view has been shown to the user.
4028 * @hide
4029 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004030 public void reportKeyguardSecured(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00004031 if (mService != null) {
4032 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004033 mService.reportKeyguardSecured(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00004034 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004035 throw e.rethrowFromSystemServer();
Michal Karpinski31502d32016-01-25 16:43:07 +00004036 }
4037 }
4038 }
4039
4040 /**
Amith Yamasani71e6c692013-03-24 17:39:28 -07004041 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00004042 * Sets the given package as the device owner.
Makoto Onukia52562c2015-10-01 16:12:31 -07004043 * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name.
4044 * @param who the component name to be registered as device owner.
Amith Yamasani71e6c692013-03-24 17:39:28 -07004045 * @return whether the package was successfully registered as the device owner.
4046 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00004047 * @throws IllegalStateException If the preconditions mentioned are not met.
Amith Yamasani71e6c692013-03-24 17:39:28 -07004048 */
Makoto Onukia52562c2015-10-01 16:12:31 -07004049 public boolean setDeviceOwner(ComponentName who) {
4050 return setDeviceOwner(who, null);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004051 }
4052
4053 /**
4054 * @hide
Makoto Onuki58b684f2015-09-04 10:48:16 -07004055 */
Makoto Onukia52562c2015-10-01 16:12:31 -07004056 public boolean setDeviceOwner(ComponentName who, int userId) {
4057 return setDeviceOwner(who, null, userId);
Makoto Onuki58b684f2015-09-04 10:48:16 -07004058 }
4059
4060 /**
4061 * @hide
4062 */
Makoto Onukia52562c2015-10-01 16:12:31 -07004063 public boolean setDeviceOwner(ComponentName who, String ownerName) {
4064 return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM);
Makoto Onuki58b684f2015-09-04 10:48:16 -07004065 }
4066
4067 /**
4068 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00004069 * Sets the given package as the device owner. The package must already be installed. There
4070 * must not already be a device owner.
4071 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
4072 * this method.
4073 * Calling this after the setup phase of the primary user has completed is allowed only if
4074 * the caller is the shell uid, and there are no additional users and no accounts.
Makoto Onukia52562c2015-10-01 16:12:31 -07004075 * @param who the component name to be registered as device owner.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004076 * @param ownerName the human readable name of the institution that owns this device.
Makoto Onuki58b684f2015-09-04 10:48:16 -07004077 * @param userId ID of the user on which the device owner runs.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004078 * @return whether the package was successfully registered as the device owner.
4079 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00004080 * @throws IllegalStateException If the preconditions mentioned are not met.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004081 */
Makoto Onukia52562c2015-10-01 16:12:31 -07004082 public boolean setDeviceOwner(ComponentName who, String ownerName, int userId)
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004083 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07004084 if (mService != null) {
4085 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07004086 return mService.setDeviceOwner(who, ownerName, userId);
Amith Yamasani71e6c692013-03-24 17:39:28 -07004087 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004088 throw re.rethrowFromSystemServer();
Amith Yamasani71e6c692013-03-24 17:39:28 -07004089 }
4090 }
4091 return false;
4092 }
4093
4094 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004095 * Used to determine if a particular package has been registered as a Device Owner app.
4096 * A device owner app is a special device admin that cannot be deactivated by the user, once
Robin Lee25e26452015-06-02 09:56:29 -07004097 * activated as a device admin. It also cannot be uninstalled. To check whether a particular
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004098 * package is currently registered as the device owner app, pass in the package name from
4099 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
Robin Lee25e26452015-06-02 09:56:29 -07004100 * admin apps that want to check whether they are also registered as the device owner app. The
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004101 * exact mechanism by which a device admin app is registered as a device owner app is defined by
4102 * the setup process.
4103 * @param packageName the package name of the app, to compare with the registered device owner
4104 * app, if any.
Makoto Onukic8a5a552015-11-19 14:29:12 -08004105 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07004106 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004107 public boolean isDeviceOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004108 throwIfParentInstance("isDeviceOwnerApp");
Makoto Onukic8a5a552015-11-19 14:29:12 -08004109 return isDeviceOwnerAppOnCallingUser(packageName);
4110 }
4111
4112 /**
4113 * @return true if a package is registered as device owner, only when it's running on the
4114 * calling user.
4115 *
4116 * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity.
4117 * @hide
4118 */
4119 public boolean isDeviceOwnerAppOnCallingUser(String packageName) {
4120 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true);
4121 }
4122
4123 /**
4124 * @return true if a package is registered as device owner, even if it's running on a different
4125 * user.
4126 *
4127 * <p>Requires the MANAGE_USERS permission.
4128 *
4129 * @hide
4130 */
4131 public boolean isDeviceOwnerAppOnAnyUser(String packageName) {
4132 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false);
4133 }
4134
4135 /**
4136 * @return device owner component name, only when it's running on the calling user.
4137 *
4138 * @hide
4139 */
4140 public ComponentName getDeviceOwnerComponentOnCallingUser() {
4141 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true);
4142 }
4143
4144 /**
4145 * @return device owner component name, even if it's running on a different user.
4146 *
4147 * <p>Requires the MANAGE_USERS permission.
4148 *
4149 * @hide
4150 */
Polina Bondarenko23561db2016-12-16 11:47:28 +01004151 @SystemApi
Makoto Onukic8a5a552015-11-19 14:29:12 -08004152 public ComponentName getDeviceOwnerComponentOnAnyUser() {
4153 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false);
4154 }
4155
4156 private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) {
Makoto Onuki70f929e2015-11-11 12:40:15 -08004157 if (packageName == null) {
4158 return false;
Amith Yamasani71e6c692013-03-24 17:39:28 -07004159 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08004160 final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly);
Makoto Onuki70f929e2015-11-11 12:40:15 -08004161 if (deviceOwner == null) {
4162 return false;
4163 }
4164 return packageName.equals(deviceOwner.getPackageName());
Amith Yamasani71e6c692013-03-24 17:39:28 -07004165 }
4166
Makoto Onukic8a5a552015-11-19 14:29:12 -08004167 private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) {
4168 if (mService != null) {
4169 try {
4170 return mService.getDeviceOwnerComponent(callingUserOnly);
4171 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004172 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08004173 }
4174 }
4175 return null;
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004176 }
4177
Jason Monkb0dced82014-06-06 14:36:20 -04004178 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08004179 * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's
4180 * no device owner.
4181 *
4182 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07004183 *
4184 * @hide
4185 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08004186 public int getDeviceOwnerUserId() {
4187 if (mService != null) {
4188 try {
4189 return mService.getDeviceOwnerUserId();
4190 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004191 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08004192 }
4193 }
4194 return UserHandle.USER_NULL;
Makoto Onukia52562c2015-10-01 16:12:31 -07004195 }
4196
4197 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004198 * Clears the current device owner. The caller must be the device owner. This function should be
4199 * used cautiously as once it is called it cannot be undone. The device owner can only be set as
4200 * a part of device setup before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04004201 *
4202 * @param packageName The package name of the device owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004203 * @throws SecurityException if the caller is not in {@code packageName} or {@code packageName}
4204 * does not own the current device owner component.
Jason Monkb0dced82014-06-06 14:36:20 -04004205 */
Jason Monk94d2cf92014-06-18 09:53:34 -04004206 public void clearDeviceOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004207 throwIfParentInstance("clearDeviceOwnerApp");
Jason Monkb0dced82014-06-06 14:36:20 -04004208 if (mService != null) {
4209 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04004210 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04004211 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004212 throw re.rethrowFromSystemServer();
Jason Monkb0dced82014-06-06 14:36:20 -04004213 }
4214 }
4215 }
4216
Makoto Onukia52562c2015-10-01 16:12:31 -07004217 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08004218 * Returns the device owner package name, only if it's running on the calling user.
4219 *
4220 * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity.
Makoto Onukia52562c2015-10-01 16:12:31 -07004221 *
4222 * @hide
4223 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01004224 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004225 public @Nullable String getDeviceOwner() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004226 throwIfParentInstance("getDeviceOwner");
Makoto Onukic8a5a552015-11-19 14:29:12 -08004227 final ComponentName name = getDeviceOwnerComponentOnCallingUser();
4228 return name != null ? name.getPackageName() : null;
Makoto Onukia52562c2015-10-01 16:12:31 -07004229 }
4230
4231 /**
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004232 * Called by the system to find out whether the device is managed by a Device Owner.
Makoto Onukic8a5a552015-11-19 14:29:12 -08004233 *
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004234 * @return whether the device is managed by a Device Owner.
4235 * @throws SecurityException if the caller is not the device owner, does not hold the
4236 * MANAGE_USERS permission and is not the system.
Makoto Onukia52562c2015-10-01 16:12:31 -07004237 *
4238 * @hide
4239 */
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004240 @SystemApi
4241 @TestApi
Makoto Onukic8a5a552015-11-19 14:29:12 -08004242 public boolean isDeviceManaged() {
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004243 try {
4244 return mService.hasDeviceOwner();
4245 } catch (RemoteException re) {
4246 throw re.rethrowFromSystemServer();
4247 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08004248 }
4249
4250 /**
4251 * Returns the device owner name. Note this method *will* return the device owner
4252 * name when it's running on a different user.
4253 *
4254 * <p>Requires the MANAGE_USERS permission.
4255 *
4256 * @hide
4257 */
Makoto Onukia2b274b2016-01-19 13:26:02 -08004258 @SystemApi
Makoto Onukic8a5a552015-11-19 14:29:12 -08004259 public String getDeviceOwnerNameOnAnyUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004260 throwIfParentInstance("getDeviceOwnerNameOnAnyUser");
Amith Yamasani71e6c692013-03-24 17:39:28 -07004261 if (mService != null) {
4262 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07004263 return mService.getDeviceOwnerName();
Amith Yamasani71e6c692013-03-24 17:39:28 -07004264 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004265 throw re.rethrowFromSystemServer();
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004266 }
4267 }
4268 return null;
4269 }
Adam Connors776c5552014-01-09 10:42:56 +00004270
4271 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04004272 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004273 * @deprecated Do not use
4274 * @removed
Julia Reynolds20118f12015-02-11 12:34:08 -05004275 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004276 @Deprecated
Julia Reynolds20118f12015-02-11 12:34:08 -05004277 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004278 public @Nullable String getDeviceInitializerApp() {
Julia Reynolds20118f12015-02-11 12:34:08 -05004279 return null;
4280 }
4281
4282 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004283 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004284 * @deprecated Do not use
4285 * @removed
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004286 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004287 @Deprecated
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004288 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004289 public @Nullable ComponentName getDeviceInitializerComponent() {
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004290 return null;
4291 }
4292
Julia Reynolds20118f12015-02-11 12:34:08 -05004293 /**
Adam Connors776c5552014-01-09 10:42:56 +00004294 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004295 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304296 * Sets the given component as an active admin and registers the package as the profile
4297 * owner for this user. The package must already be installed and there shouldn't be
4298 * an existing profile owner registered for this user. Also, this method must be called
4299 * before the user setup has been completed.
4300 * <p>
4301 * This method can only be called by system apps that hold MANAGE_USERS permission and
4302 * MANAGE_DEVICE_ADMINS permission.
4303 * @param admin The component to register as an active admin and profile owner.
4304 * @param ownerName The user-visible name of the entity that is managing this user.
4305 * @return whether the admin was successfully registered as the profile owner.
4306 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
4307 * the user has already been set up.
4308 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07004309 @Deprecated
Justin Morey80440cc2014-07-24 09:16:35 -05004310 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07004311 public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304312 throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004313 throwIfParentInstance("setActiveProfileOwner");
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304314 if (mService != null) {
4315 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004316 final int myUserId = myUserId();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304317 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004318 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304319 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004320 throw re.rethrowFromSystemServer();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304321 }
4322 }
4323 return false;
4324 }
4325
4326 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004327 * Clears the active profile owner and removes all user restrictions. The caller must be from
4328 * the same package as the active profile owner for this user, otherwise a SecurityException
4329 * will be thrown.
4330 * <p>
4331 * This doesn't work for managed profile owners.
Makoto Onuki5bf68022016-01-27 13:49:19 -08004332 *
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004333 * @param admin The component to remove as the profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004334 * @throws SecurityException if {@code admin} is not an active profile owner.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004335 */
Robin Lee25e26452015-06-02 09:56:29 -07004336 public void clearProfileOwner(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004337 throwIfParentInstance("clearProfileOwner");
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004338 if (mService != null) {
4339 try {
4340 mService.clearProfileOwner(admin);
4341 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004342 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004343 }
4344 }
4345 }
4346
4347 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05004348 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07004349 * Checks whether the user was already setup.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004350 */
4351 public boolean hasUserSetupCompleted() {
4352 if (mService != null) {
4353 try {
4354 return mService.hasUserSetupCompleted();
4355 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004356 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004357 }
4358 }
4359 return true;
4360 }
4361
4362 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004363 * @hide
4364 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00004365 * already be installed. There must not already be a profile owner for this user.
4366 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
4367 * this method.
4368 * Calling this after the setup phase of the specified user has completed is allowed only if:
4369 * - the caller is SYSTEM_UID.
4370 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004371 * @param admin the component name to be registered as profile owner.
4372 * @param ownerName the human readable name of the organisation associated with this DPM.
4373 * @param userHandle the userId to set the profile owner for.
4374 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00004375 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
4376 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004377 */
Robin Lee25e26452015-06-02 09:56:29 -07004378 public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName,
Robin Leeddd553f2015-04-30 14:18:22 +01004379 int userHandle) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00004380 if (mService != null) {
4381 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004382 if (ownerName == null) {
4383 ownerName = "";
4384 }
4385 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00004386 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004387 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004388 }
4389 }
4390 return false;
4391 }
4392
4393 /**
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004394 * Sets the device owner information to be shown on the lock screen.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004395 * <p>
4396 * If the device owner information is {@code null} or empty then the device owner info is
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004397 * cleared and the user owner info is shown on the lock screen if it is set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004398 * <p>
4399 * If the device owner information contains only whitespaces then the message on the lock screen
4400 * will be blank and the user will not be allowed to change it.
4401 * <p>
4402 * If the device owner information needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00004403 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
4404 * and set a new version of this string accordingly.
4405 *
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004406 * @param admin The name of the admin component to check.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004407 * @param info Device owner information which will be displayed instead of the user owner info.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004408 * @throws SecurityException if {@code admin} is not a device owner.
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004409 */
Andrei Stingaceanu16187902016-03-21 15:44:45 +00004410 public void setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, CharSequence info) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004411 throwIfParentInstance("setDeviceOwnerLockScreenInfo");
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004412 if (mService != null) {
4413 try {
Andrei Stingaceanu16187902016-03-21 15:44:45 +00004414 mService.setDeviceOwnerLockScreenInfo(admin, info);
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004415 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004416 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004417 }
4418 }
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004419 }
4420
4421 /**
4422 * @return The device owner information. If it is not set returns {@code null}.
4423 */
Andrei Stingaceanu16187902016-03-21 15:44:45 +00004424 public CharSequence getDeviceOwnerLockScreenInfo() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004425 throwIfParentInstance("getDeviceOwnerLockScreenInfo");
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004426 if (mService != null) {
4427 try {
4428 return mService.getDeviceOwnerLockScreenInfo();
4429 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004430 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004431 }
4432 }
4433 return null;
4434 }
4435
4436 /**
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004437 * Called by device or profile owners to suspend packages for this user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004438 * <p>
4439 * A suspended package will not be able to start activities. Its notifications will be hidden,
4440 * it will not show up in recents, will not be able to show toasts or dialogs or ring the
4441 * device.
4442 * <p>
4443 * The package must already be installed. If the package is uninstalled while suspended the
4444 * package will no longer be suspended. The admin can block this by using
Kenny Guy871f3eb2016-03-09 20:06:16 +00004445 * {@link #setUninstallBlocked}.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004446 *
4447 * @param admin The name of the admin component to check.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004448 * @param packageNames The package names to suspend or unsuspend.
4449 * @param suspended If set to {@code true} than the packages will be suspended, if set to
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004450 * {@code false} the packages will be unsuspended.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004451 * @return an array of package names for which the suspended status is not set as requested in
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004452 * this method.
4453 * @throws SecurityException if {@code admin} is not a device or profile owner.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004454 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004455 public @NonNull String[] setPackagesSuspended(@NonNull ComponentName admin,
4456 @NonNull String[] packageNames, boolean suspended) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004457 throwIfParentInstance("setPackagesSuspended");
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004458 if (mService != null) {
4459 try {
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004460 return mService.setPackagesSuspended(admin, packageNames, suspended);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004461 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004462 throw re.rethrowFromSystemServer();
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004463 }
4464 }
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004465 return packageNames;
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004466 }
4467
4468 /**
4469 * Called by device or profile owners to determine if a package is suspended.
4470 *
4471 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4472 * @param packageName The name of the package to retrieve the suspended status of.
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00004473 * @return {@code true} if the package is suspended or {@code false} if the package is not
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004474 * suspended, could not be found or an error occurred.
4475 * @throws SecurityException if {@code admin} is not a device or profile owner.
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004476 * @throws NameNotFoundException if the package could not be found.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004477 */
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004478 public boolean isPackageSuspended(@NonNull ComponentName admin, String packageName)
4479 throws NameNotFoundException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004480 throwIfParentInstance("isPackageSuspended");
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004481 if (mService != null) {
4482 try {
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004483 return mService.isPackageSuspended(admin, packageName);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004484 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004485 throw e.rethrowFromSystemServer();
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004486 } catch (IllegalArgumentException ex) {
4487 throw new NameNotFoundException(packageName);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004488 }
4489 }
4490 return false;
4491 }
4492
4493 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004494 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
4495 * be used. Only the profile owner can call this.
4496 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01004497 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004498 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004499 * @throws SecurityException if {@code admin} is not a profile owner.
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004500 */
Robin Lee25e26452015-06-02 09:56:29 -07004501 public void setProfileEnabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004502 throwIfParentInstance("setProfileEnabled");
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004503 if (mService != null) {
4504 try {
4505 mService.setProfileEnabled(admin);
4506 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004507 throw e.rethrowFromSystemServer();
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004508 }
4509 }
4510 }
4511
4512 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004513 * Sets the name of the profile. In the device owner case it sets the name of the user which it
4514 * is called from. Only a profile owner or device owner can call this. If this is never called
4515 * by the profile or device owner, the name will be set to default values.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004516 *
4517 * @see #isProfileOwnerApp
4518 * @see #isDeviceOwnerApp
Robin Lee25e26452015-06-02 09:56:29 -07004519 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004520 * @param profileName The name of the profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004521 * @throws SecurityException if {@code admin} is not a device or profile owner.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004522 */
Robin Lee25e26452015-06-02 09:56:29 -07004523 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004524 throwIfParentInstance("setProfileName");
Jessica Hummel1333ea12014-06-23 11:20:10 +01004525 if (mService != null) {
4526 try {
Robin Lee25e26452015-06-02 09:56:29 -07004527 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07004528 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004529 throw e.rethrowFromSystemServer();
Fyodor Kupolov78f13142015-05-27 16:52:45 -07004530 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01004531 }
4532 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01004533
4534 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004535 * Used to determine if a particular package is registered as the profile owner for the
Makoto Onuki32b30572015-12-11 14:29:51 -08004536 * user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004537 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00004538 *
4539 * @param packageName The package name of the app to compare with the registered profile owner.
4540 * @return Whether or not the package is registered as the profile owner.
4541 */
4542 public boolean isProfileOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004543 throwIfParentInstance("isProfileOwnerApp");
Adam Connors776c5552014-01-09 10:42:56 +00004544 if (mService != null) {
4545 try {
Makoto Onuki90b89652016-01-28 14:44:18 -08004546 ComponentName profileOwner = mService.getProfileOwner(myUserId());
Nicolas Prevot90af6d72014-07-30 14:19:12 +01004547 return profileOwner != null
4548 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00004549 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004550 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004551 }
4552 }
4553 return false;
4554 }
4555
4556 /**
4557 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07004558 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00004559 * owner has been set for that user.
4560 * @throws IllegalArgumentException if the userId is invalid.
4561 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01004562 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004563 public @Nullable ComponentName getProfileOwner() throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004564 throwIfParentInstance("getProfileOwner");
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01004565 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
4566 }
4567
4568 /**
4569 * @see #getProfileOwner()
4570 * @hide
4571 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004572 public @Nullable ComponentName getProfileOwnerAsUser(final int userId)
4573 throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00004574 if (mService != null) {
4575 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01004576 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00004577 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004578 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004579 }
4580 }
4581 return null;
4582 }
4583
4584 /**
4585 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07004586 * @return the human readable name of the organisation associated with this DPM or {@code null}
4587 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00004588 * @throws IllegalArgumentException if the userId is invalid.
4589 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004590 public @Nullable String getProfileOwnerName() throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00004591 if (mService != null) {
4592 try {
4593 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
4594 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004595 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004596 }
4597 }
4598 return null;
4599 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004600
4601 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07004602 * @hide
Makoto Onukic8a5a552015-11-19 14:29:12 -08004603 * @param userId The user for whom to fetch the profile owner name, if any.
Amith Yamasani38f836b2014-08-20 14:51:15 -07004604 * @return the human readable name of the organisation associated with this profile owner or
4605 * null if one is not set.
4606 * @throws IllegalArgumentException if the userId is invalid.
4607 */
4608 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004609 public @Nullable String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004610 throwIfParentInstance("getProfileOwnerNameAsUser");
Amith Yamasani38f836b2014-08-20 14:51:15 -07004611 if (mService != null) {
4612 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02004613 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07004614 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004615 throw re.rethrowFromSystemServer();
Amith Yamasani38f836b2014-08-20 14:51:15 -07004616 }
4617 }
4618 return null;
4619 }
4620
4621 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004622 * Called by a profile owner or device owner to add a default intent handler activity for
4623 * intents that match a certain intent filter. This activity will remain the default intent
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004624 * handler even if the set of potential event handlers for the intent filter changes and if the
4625 * intent preferences are reset.
4626 * <p>
4627 * The default disambiguation mechanism takes over if the activity is not installed (anymore).
4628 * When the activity is (re)installed, it is automatically reset as default intent handler for
4629 * the filter.
4630 * <p>
4631 * The calling device admin must be a profile owner or device owner. If it is not, a security
4632 * exception will be thrown.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004633 *
4634 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4635 * @param filter The IntentFilter for which a default handler is added.
4636 * @param activity The Activity that is added as default intent handler.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004637 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004638 */
Robin Lee25e26452015-06-02 09:56:29 -07004639 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
4640 @NonNull ComponentName activity) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004641 throwIfParentInstance("addPersistentPreferredActivity");
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004642 if (mService != null) {
4643 try {
4644 mService.addPersistentPreferredActivity(admin, filter, activity);
4645 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004646 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004647 }
4648 }
4649 }
4650
4651 /**
4652 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00004653 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004654 * <p>
4655 * The calling device admin must be a profile owner. If it is not, a security exception will be
4656 * thrown.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004657 *
4658 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4659 * @param packageName The name of the package for which preferences are removed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004660 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004661 */
Robin Lee25e26452015-06-02 09:56:29 -07004662 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004663 String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004664 throwIfParentInstance("clearPackagePersistentPreferredActivities");
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004665 if (mService != null) {
4666 try {
4667 mService.clearPackagePersistentPreferredActivities(admin, packageName);
4668 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004669 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004670 }
4671 }
4672 }
Robin Lee66e5d962014-04-09 16:44:21 +01004673
4674 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00004675 * Called by a profile owner or device owner to grant permission to a package to manage
4676 * application restrictions for the calling user via {@link #setApplicationRestrictions} and
4677 * {@link #getApplicationRestrictions}.
4678 * <p>
4679 * This permission is persistent until it is later cleared by calling this method with a
4680 * {@code null} value or uninstalling the managing package.
Rubin Xuf03d0a62016-02-10 14:54:15 +00004681 * <p>
4682 * The supplied application restriction managing package must be installed when calling this
Victor Changcd14c0a2016-03-16 19:10:15 +00004683 * API, otherwise an {@link NameNotFoundException} will be thrown.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004684 *
4685 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4686 * @param packageName The package name which will be given access to application restrictions
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004687 * APIs. If {@code null} is given the current package will be cleared.
4688 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Changcd14c0a2016-03-16 19:10:15 +00004689 * @throws NameNotFoundException if {@code packageName} is not found
Esteban Talaverabf60f722015-12-10 16:26:44 +00004690 */
4691 public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin,
Victor Changcd14c0a2016-03-16 19:10:15 +00004692 @Nullable String packageName) throws NameNotFoundException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004693 throwIfParentInstance("setApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00004694 if (mService != null) {
4695 try {
Victor Changcd14c0a2016-03-16 19:10:15 +00004696 if (!mService.setApplicationRestrictionsManagingPackage(admin, packageName)) {
4697 throw new NameNotFoundException(packageName);
4698 }
Esteban Talaverabf60f722015-12-10 16:26:44 +00004699 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004700 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00004701 }
4702 }
4703 }
4704
4705 /**
4706 * Called by a profile owner or device owner to retrieve the application restrictions managing
4707 * package for the current user, or {@code null} if none is set.
4708 *
4709 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4710 * @return The package name allowed to manage application restrictions on the current user, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004711 * {@code null} if none is set.
4712 * @throws SecurityException if {@code admin} is not a device or profile owner.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004713 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004714 public @Nullable String getApplicationRestrictionsManagingPackage(
4715 @NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004716 throwIfParentInstance("getApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00004717 if (mService != null) {
4718 try {
4719 return mService.getApplicationRestrictionsManagingPackage(admin);
4720 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004721 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00004722 }
4723 }
4724 return null;
4725 }
4726
4727 /**
Esteban Talavera96895ca2016-03-16 12:00:40 +00004728 * Called by any application to find out whether it has been granted permission via
4729 * {@link #setApplicationRestrictionsManagingPackage} to manage application restrictions
4730 * for the calling user.
4731 *
4732 * <p>This is done by comparing the calling Linux uid with the uid of the package specified by
4733 * that method.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004734 */
4735 public boolean isCallerApplicationRestrictionsManagingPackage() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004736 throwIfParentInstance("isCallerApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00004737 if (mService != null) {
4738 try {
4739 return mService.isCallerApplicationRestrictionsManagingPackage();
4740 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004741 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00004742 }
4743 }
4744 return false;
4745 }
4746
4747 /**
4748 * Sets the application restrictions for a given target application running in the calling user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004749 * <p>
4750 * The caller must be a profile or device owner on that user, or the package allowed to manage
4751 * application restrictions via {@link #setApplicationRestrictionsManagingPackage}; otherwise a
4752 * security exception will be thrown.
4753 * <p>
4754 * The provided {@link Bundle} consists of key-value pairs, where the types of values may be:
Esteban Talavera6b8e0642015-08-10 17:26:04 +01004755 * <ul>
4756 * <li>{@code boolean}
4757 * <li>{@code int}
4758 * <li>{@code String} or {@code String[]}
4759 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
4760 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004761 * <p>
4762 * If the restrictions are not available yet, but may be applied in the near future, the caller
4763 * can notify the target application of that by adding
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00004764 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004765 * <p>
4766 * The application restrictions are only made visible to the target application via
4767 * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or device
4768 * owner, and the application restrictions managing package via
Esteban Talaverabf60f722015-12-10 16:26:44 +00004769 * {@link #getApplicationRestrictions}.
Robin Lee66e5d962014-04-09 16:44:21 +01004770 *
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07004771 * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
4772 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00004773 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004774 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01004775 * @param packageName The name of the package to update restricted settings for.
4776 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004777 * set of active restrictions.
4778 * @throws SecurityException if {@code admin} is not a device or profile owner.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004779 * @see #setApplicationRestrictionsManagingPackage
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00004780 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01004781 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07004782 @WorkerThread
Esteban Talaverabf60f722015-12-10 16:26:44 +00004783 public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01004784 Bundle settings) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004785 throwIfParentInstance("setApplicationRestrictions");
Robin Lee66e5d962014-04-09 16:44:21 +01004786 if (mService != null) {
4787 try {
4788 mService.setApplicationRestrictions(admin, packageName, settings);
4789 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004790 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01004791 }
4792 }
4793 }
4794
4795 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004796 * Sets a list of configuration features to enable for a TrustAgent component. This is meant to
4797 * be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all trust
4798 * agents but those enabled by this function call. If flag
Jim Millere303bf42014-08-26 17:12:29 -07004799 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004800 * <p>
4801 * The calling device admin must have requested
4802 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method;
4803 * if not, a security exception will be thrown.
Tony Mak089d8402016-04-05 17:42:55 +01004804 * <p>
4805 * This method can be called on the {@link DevicePolicyManager} instance returned by
4806 * {@link #getParentProfileInstance(ComponentName)} in order to set the configuration for
4807 * the parent profile.
Jim Miller604e7552014-07-18 19:00:02 -07004808 *
4809 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07004810 * @param target Component name of the agent to be enabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004811 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent will be
4812 * strictly disabled according to the state of the
4813 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
4814 * <p>
4815 * If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all
4816 * admins, then it's up to the TrustAgent itself to aggregate the values from all
4817 * device admins.
4818 * <p>
4819 * Consult documentation for the specific TrustAgent to determine legal options
4820 * parameters.
4821 * @throws SecurityException if {@code admin} is not an active administrator or does not use
4822 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES}
Jim Miller604e7552014-07-18 19:00:02 -07004823 */
Robin Lee25e26452015-06-02 09:56:29 -07004824 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
4825 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07004826 if (mService != null) {
4827 try {
Tony Mak089d8402016-04-05 17:42:55 +01004828 mService.setTrustAgentConfiguration(admin, target, configuration, mParentInstance);
Jim Miller604e7552014-07-18 19:00:02 -07004829 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004830 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07004831 }
4832 }
4833 }
4834
4835 /**
Jim Millere303bf42014-08-26 17:12:29 -07004836 * Gets configuration for the given trust agent based on aggregating all calls to
4837 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
4838 * all device admins.
Tony Mak089d8402016-04-05 17:42:55 +01004839 * <p>
4840 * This method can be called on the {@link DevicePolicyManager} instance returned by
4841 * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the configuration set
4842 * on the parent profile.
Jim Miller604e7552014-07-18 19:00:02 -07004843 *
Jim Millerb5db57a2015-01-14 18:17:19 -08004844 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
4845 * this function returns a list of configurations for all admins that declare
4846 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
4847 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
4848 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
4849 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07004850 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07004851 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07004852 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004853 public @Nullable List<PersistableBundle> getTrustAgentConfiguration(
4854 @Nullable ComponentName admin, @NonNull ComponentName agent) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004855 return getTrustAgentConfiguration(admin, agent, myUserId());
Jim Millere303bf42014-08-26 17:12:29 -07004856 }
4857
4858 /** @hide per-user version */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004859 public @Nullable List<PersistableBundle> getTrustAgentConfiguration(
4860 @Nullable ComponentName admin, @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07004861 if (mService != null) {
4862 try {
Tony Mak089d8402016-04-05 17:42:55 +01004863 return mService.getTrustAgentConfiguration(admin, agent, userHandle,
4864 mParentInstance);
Jim Miller604e7552014-07-18 19:00:02 -07004865 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004866 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07004867 }
4868 }
Jim Millere303bf42014-08-26 17:12:29 -07004869 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07004870 }
4871
4872 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004873 * Called by a profile owner of a managed profile to set whether caller-Id information from the
4874 * managed profile will be shown in the parent profile, for incoming calls.
4875 * <p>
4876 * The calling device admin must be a profile owner. If it is not, a security exception will be
4877 * thrown.
Adam Connors210fe212014-07-17 15:41:43 +01004878 *
Robin Lee25e26452015-06-02 09:56:29 -07004879 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01004880 * @param disabled If true caller-Id information in the managed profile is not displayed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004881 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors210fe212014-07-17 15:41:43 +01004882 */
Robin Lee25e26452015-06-02 09:56:29 -07004883 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004884 throwIfParentInstance("setCrossProfileCallerIdDisabled");
Adam Connors210fe212014-07-17 15:41:43 +01004885 if (mService != null) {
4886 try {
Robin Lee25e26452015-06-02 09:56:29 -07004887 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01004888 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004889 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01004890 }
4891 }
4892 }
4893
4894 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004895 * Called by a profile owner of a managed profile to determine whether or not caller-Id
4896 * information has been disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004897 * <p>
4898 * The calling device admin must be a profile owner. If it is not, a security exception will be
4899 * thrown.
Adam Connors210fe212014-07-17 15:41:43 +01004900 *
Robin Lee25e26452015-06-02 09:56:29 -07004901 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004902 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors210fe212014-07-17 15:41:43 +01004903 */
Robin Lee25e26452015-06-02 09:56:29 -07004904 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004905 throwIfParentInstance("getCrossProfileCallerIdDisabled");
Adam Connors210fe212014-07-17 15:41:43 +01004906 if (mService != null) {
4907 try {
Robin Lee25e26452015-06-02 09:56:29 -07004908 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01004909 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004910 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01004911 }
4912 }
4913 return false;
4914 }
4915
4916 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07004917 * Determine whether or not caller-Id information has been disabled.
4918 *
4919 * @param userHandle The user for whom to check the caller-id permission
4920 * @hide
4921 */
4922 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
4923 if (mService != null) {
4924 try {
4925 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
4926 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004927 throw e.rethrowFromSystemServer();
Amith Yamasani570002f2014-07-18 15:48:54 -07004928 }
4929 }
4930 return false;
4931 }
4932
4933 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004934 * Called by a profile owner of a managed profile to set whether contacts search from the
4935 * managed profile will be shown in the parent profile, for incoming calls.
4936 * <p>
4937 * The calling device admin must be a profile owner. If it is not, a security exception will be
4938 * thrown.
Victor Chang1060c6182016-01-04 20:16:23 +00004939 *
4940 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4941 * @param disabled If true contacts search in the managed profile is not displayed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004942 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Chang1060c6182016-01-04 20:16:23 +00004943 */
4944 public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin,
4945 boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004946 throwIfParentInstance("setCrossProfileContactsSearchDisabled");
Victor Chang1060c6182016-01-04 20:16:23 +00004947 if (mService != null) {
4948 try {
4949 mService.setCrossProfileContactsSearchDisabled(admin, disabled);
4950 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004951 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00004952 }
4953 }
4954 }
4955
4956 /**
4957 * Called by a profile owner of a managed profile to determine whether or not contacts search
4958 * has been disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004959 * <p>
4960 * The calling device admin must be a profile owner. If it is not, a security exception will be
4961 * thrown.
Victor Chang1060c6182016-01-04 20:16:23 +00004962 *
4963 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004964 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Chang1060c6182016-01-04 20:16:23 +00004965 */
4966 public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004967 throwIfParentInstance("getCrossProfileContactsSearchDisabled");
Victor Chang1060c6182016-01-04 20:16:23 +00004968 if (mService != null) {
4969 try {
4970 return mService.getCrossProfileContactsSearchDisabled(admin);
4971 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004972 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00004973 }
4974 }
4975 return false;
4976 }
4977
4978
4979 /**
4980 * Determine whether or not contacts search has been disabled.
4981 *
4982 * @param userHandle The user for whom to check the contacts search permission
4983 * @hide
4984 */
4985 public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) {
4986 if (mService != null) {
4987 try {
4988 return mService
4989 .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier());
4990 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004991 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00004992 }
4993 }
4994 return false;
4995 }
4996
4997 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004998 * Start Quick Contact on the managed profile for the user, if the policy allows.
Victor Chang97bdacc2016-01-21 22:24:11 +00004999 *
Makoto Onuki1040da12015-03-19 11:24:00 -07005000 * @hide
5001 */
5002 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
Victor Chang97bdacc2016-01-21 22:24:11 +00005003 boolean isContactIdIgnored, long directoryId, Intent originalIntent) {
Makoto Onuki1040da12015-03-19 11:24:00 -07005004 if (mService != null) {
5005 try {
Victor Chang97bdacc2016-01-21 22:24:11 +00005006 mService.startManagedQuickContact(actualLookupKey, actualContactId,
5007 isContactIdIgnored, directoryId, originalIntent);
Makoto Onuki1040da12015-03-19 11:24:00 -07005008 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005009 throw e.rethrowFromSystemServer();
Makoto Onuki1040da12015-03-19 11:24:00 -07005010 }
5011 }
5012 }
5013
5014 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005015 * Start Quick Contact on the managed profile for the user, if the policy allows.
Ricky Wai494b95d2015-11-20 16:07:15 +00005016 * @hide
5017 */
5018 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
5019 Intent originalIntent) {
Victor Chang97bdacc2016-01-21 22:24:11 +00005020 startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT,
Ricky Wai494b95d2015-11-20 16:07:15 +00005021 originalIntent);
5022 }
5023
5024 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005025 * Called by a profile owner of a managed profile to set whether bluetooth devices can access
5026 * enterprise contacts.
Ricky Wai778ba132015-03-31 14:21:22 +01005027 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005028 * The calling device admin must be a profile owner. If it is not, a security exception will be
5029 * thrown.
Ricky Wai778ba132015-03-31 14:21:22 +01005030 * <p>
5031 * This API works on managed profile only.
5032 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005033 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5034 * @param disabled If true, bluetooth devices cannot access enterprise contacts.
5035 * @throws SecurityException if {@code admin} is not a device or profile owner.
Ricky Wai778ba132015-03-31 14:21:22 +01005036 */
Robin Lee25e26452015-06-02 09:56:29 -07005037 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005038 throwIfParentInstance("setBluetoothContactSharingDisabled");
Ricky Wai778ba132015-03-31 14:21:22 +01005039 if (mService != null) {
5040 try {
Robin Lee25e26452015-06-02 09:56:29 -07005041 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01005042 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005043 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01005044 }
5045 }
5046 }
5047
5048 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005049 * Called by a profile owner of a managed profile to determine whether or not Bluetooth devices
5050 * cannot access enterprise contacts.
Ricky Wai778ba132015-03-31 14:21:22 +01005051 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005052 * The calling device admin must be a profile owner. If it is not, a security exception will be
5053 * thrown.
Ricky Wai778ba132015-03-31 14:21:22 +01005054 * <p>
5055 * This API works on managed profile only.
5056 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005057 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5058 * @throws SecurityException if {@code admin} is not a device or profile owner.
Ricky Wai778ba132015-03-31 14:21:22 +01005059 */
Robin Lee25e26452015-06-02 09:56:29 -07005060 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005061 throwIfParentInstance("getBluetoothContactSharingDisabled");
Ricky Wai778ba132015-03-31 14:21:22 +01005062 if (mService != null) {
5063 try {
Robin Lee25e26452015-06-02 09:56:29 -07005064 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01005065 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005066 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01005067 }
5068 }
5069 return true;
5070 }
5071
5072 /**
5073 * Determine whether or not Bluetooth devices cannot access contacts.
5074 * <p>
5075 * This API works on managed profile UserHandle only.
5076 *
5077 * @param userHandle The user for whom to check the caller-id permission
5078 * @hide
5079 */
5080 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
5081 if (mService != null) {
5082 try {
5083 return mService.getBluetoothContactSharingDisabledForUser(userHandle
5084 .getIdentifier());
5085 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005086 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01005087 }
5088 }
5089 return true;
5090 }
5091
5092 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005093 * Called by the profile owner of a managed profile so that some intents sent in the managed
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005094 * profile can also be resolved in the parent, or vice versa. Only activity intents are
5095 * supported.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00005096 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005097 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01005098 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005099 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01005100 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005101 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
5102 * @throws SecurityException if {@code admin} is not a device or profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005103 */
Robin Lee25e26452015-06-02 09:56:29 -07005104 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005105 throwIfParentInstance("addCrossProfileIntentFilter");
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005106 if (mService != null) {
5107 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01005108 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005109 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005110 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005111 }
5112 }
5113 }
5114
5115 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005116 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
5117 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01005118 * Only removes those that have been set by the profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005119 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005120 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005121 * @throws SecurityException if {@code admin} is not a device or profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005122 */
Robin Lee25e26452015-06-02 09:56:29 -07005123 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005124 throwIfParentInstance("clearCrossProfileIntentFilters");
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005125 if (mService != null) {
5126 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01005127 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005128 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005129 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005130 }
5131 }
5132 }
5133
5134 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005135 * Called by a profile or device owner to set the permitted accessibility services. When set by
5136 * a device owner or profile owner the restriction applies to all profiles of the user the
5137 * device owner or profile owner is an admin for. By default the user can use any accessiblity
5138 * service. When zero or more packages have been added, accessiblity services that are not in
5139 * the list and not part of the system can not be enabled by the user.
5140 * <p>
5141 * Calling with a null value for the list disables the restriction so that all services can be
5142 * used, calling with an empty list only allows the builtin system's services.
5143 * <p>
5144 * System accesibility services are always available to the user the list can't modify this.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005145 *
5146 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5147 * @param packageNames List of accessibility service package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005148 * @return true if setting the restriction succeeded. It fail if there is one or more non-system
5149 * accessibility services enabled, that are not in the list.
5150 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005151 */
Robin Lee25e26452015-06-02 09:56:29 -07005152 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005153 List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005154 throwIfParentInstance("setPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005155 if (mService != null) {
5156 try {
5157 return mService.setPermittedAccessibilityServices(admin, packageNames);
5158 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005159 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005160 }
5161 }
5162 return false;
5163 }
5164
5165 /**
5166 * Returns the list of permitted accessibility services set by this device or profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005167 * <p>
5168 * An empty list means no accessibility services except system services are allowed. Null means
5169 * all accessibility services are allowed.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005170 *
5171 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5172 * @return List of accessiblity service package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005173 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005174 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005175 public @Nullable List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005176 throwIfParentInstance("getPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005177 if (mService != null) {
5178 try {
5179 return mService.getPermittedAccessibilityServices(admin);
5180 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005181 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005182 }
5183 }
5184 return null;
5185 }
5186
5187 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00005188 * Called by the system to check if a specific accessibility service is disabled by admin.
5189 *
5190 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5191 * @param packageName Accessibility service package name that needs to be checked.
5192 * @param userHandle user id the admin is running as.
5193 * @return true if the accessibility service is permitted, otherwise false.
5194 *
5195 * @hide
5196 */
5197 public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin,
5198 @NonNull String packageName, int userHandle) {
5199 if (mService != null) {
5200 try {
5201 return mService.isAccessibilityServicePermittedByAdmin(admin, packageName,
5202 userHandle);
5203 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005204 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00005205 }
5206 }
5207 return false;
5208 }
5209
5210 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005211 * Returns the list of accessibility services permitted by the device or profiles
5212 * owners of this user.
5213 *
5214 * <p>Null means all accessibility services are allowed, if a non-null list is returned
5215 * it will contain the intersection of the permitted lists for any device or profile
5216 * owners that apply to this user. It will also include any system accessibility services.
5217 *
5218 * @param userId which user to check for.
5219 * @return List of accessiblity service package names.
5220 * @hide
5221 */
5222 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07005223 public @Nullable List<String> getPermittedAccessibilityServices(int userId) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005224 throwIfParentInstance("getPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005225 if (mService != null) {
5226 try {
5227 return mService.getPermittedAccessibilityServicesForUser(userId);
5228 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005229 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005230 }
5231 }
5232 return null;
5233 }
5234
5235 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005236 * Called by a profile or device owner to set the permitted input methods services. When set by
5237 * a device owner or profile owner the restriction applies to all profiles of the user the
5238 * device owner or profile owner is an admin for. By default the user can use any input method.
5239 * When zero or more packages have been added, input method that are not in the list and not
5240 * part of the system can not be enabled by the user. This method will fail if it is called for
5241 * a admin that is not for the foreground user or a profile of the foreground user.
5242 * <p>
5243 * Calling with a null value for the list disables the restriction so that all input methods can
5244 * be used, calling with an empty list disables all but the system's own input methods.
5245 * <p>
5246 * System input methods are always available to the user this method can't modify this.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005247 *
5248 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5249 * @param packageNames List of input method package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005250 * @return true if setting the restriction succeeded. It will fail if there are one or more
5251 * non-system input methods currently enabled that are not in the packageNames list.
5252 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005253 */
Robin Lee25e26452015-06-02 09:56:29 -07005254 public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005255 throwIfParentInstance("setPermittedInputMethods");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005256 if (mService != null) {
5257 try {
5258 return mService.setPermittedInputMethods(admin, packageNames);
5259 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005260 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005261 }
5262 }
5263 return false;
5264 }
5265
5266
5267 /**
5268 * Returns the list of permitted input methods set by this device or profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005269 * <p>
5270 * An empty list means no input methods except system input methods are allowed. Null means all
5271 * input methods are allowed.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005272 *
5273 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5274 * @return List of input method package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005275 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005276 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005277 public @Nullable List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005278 throwIfParentInstance("getPermittedInputMethods");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005279 if (mService != null) {
5280 try {
5281 return mService.getPermittedInputMethods(admin);
5282 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005283 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005284 }
5285 }
5286 return null;
5287 }
5288
5289 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00005290 * Called by the system to check if a specific input method is disabled by admin.
5291 *
5292 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5293 * @param packageName Input method package name that needs to be checked.
5294 * @param userHandle user id the admin is running as.
5295 * @return true if the input method is permitted, otherwise false.
5296 *
5297 * @hide
5298 */
5299 public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin,
5300 @NonNull String packageName, int userHandle) {
5301 if (mService != null) {
5302 try {
5303 return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle);
5304 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005305 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00005306 }
5307 }
5308 return false;
5309 }
5310
5311 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005312 * Returns the list of input methods permitted by the device or profiles
Makoto Onuki32b30572015-12-11 14:29:51 -08005313 * owners of the current user. (*Not* calling user, due to a limitation in InputMethodManager.)
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005314 *
5315 * <p>Null means all input methods are allowed, if a non-null list is returned
5316 * it will contain the intersection of the permitted lists for any device or profile
5317 * owners that apply to this user. It will also include any system input methods.
5318 *
5319 * @return List of input method package names.
5320 * @hide
5321 */
5322 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07005323 public @Nullable List<String> getPermittedInputMethodsForCurrentUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005324 throwIfParentInstance("getPermittedInputMethodsForCurrentUser");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005325 if (mService != null) {
5326 try {
5327 return mService.getPermittedInputMethodsForCurrentUser();
5328 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005329 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005330 }
5331 }
5332 return null;
5333 }
5334
5335 /**
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005336 * Called by a device owner to get the list of apps to keep around as APKs even if no user has
5337 * currently installed it.
5338 *
5339 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5340 *
5341 * @return List of package names to keep cached.
5342 * @hide
5343 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005344 public @Nullable List<String> getKeepUninstalledPackages(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005345 throwIfParentInstance("getKeepUninstalledPackages");
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005346 if (mService != null) {
5347 try {
5348 return mService.getKeepUninstalledPackages(admin);
5349 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005350 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005351 }
5352 }
5353 return null;
5354 }
5355
5356 /**
5357 * Called by a device owner to set a list of apps to keep around as APKs even if no user has
5358 * currently installed it.
5359 *
5360 * <p>Please note that setting this policy does not imply that specified apps will be
5361 * automatically pre-cached.</p>
5362 *
5363 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5364 * @param packageNames List of package names to keep cached.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005365 * @throws SecurityException if {@code admin} is not a device owner.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005366 * @hide
5367 */
5368 public void setKeepUninstalledPackages(@NonNull ComponentName admin,
5369 @NonNull List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005370 throwIfParentInstance("setKeepUninstalledPackages");
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005371 if (mService != null) {
5372 try {
5373 mService.setKeepUninstalledPackages(admin, packageNames);
5374 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005375 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005376 }
5377 }
5378 }
5379
5380 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04005381 * Called by a device owner to create a user with the specified name. The UserHandle returned
5382 * by this method should not be persisted as user handles are recycled as users are removed and
5383 * created. If you need to persist an identifier for this user, use
5384 * {@link UserManager#getSerialNumberForUser}.
5385 *
5386 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5387 * @param name the user's name
5388 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07005389 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
5390 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01005391 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005392 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01005393 * @removed From {@link android.os.Build.VERSION_CODES#N}
Julia Reynolds1e958392014-05-16 14:25:21 -04005394 */
Kenny Guy14f48e52015-06-29 15:12:36 +01005395 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07005396 public @Nullable UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04005397 return null;
5398 }
5399
5400 /**
Jason Monk03978a42014-06-10 15:05:30 -04005401 * Called by a device owner to create a user with the specified name. The UserHandle returned
5402 * by this method should not be persisted as user handles are recycled as users are removed and
5403 * created. If you need to persist an identifier for this user, use
5404 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
5405 * immediately.
5406 *
5407 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
5408 * as registered as an active admin on the new user. The profile owner package will be
5409 * installed on the new user if it already is installed on the device.
5410 *
5411 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
5412 * profileOwnerComponent when onEnable is called.
5413 *
5414 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5415 * @param name the user's name
5416 * @param ownerName the human readable name of the organisation associated with this DPM.
5417 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
5418 * the user.
5419 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
5420 * on the new user.
5421 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07005422 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
5423 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01005424 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005425 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01005426 * @removed From {@link android.os.Build.VERSION_CODES#N}
Jason Monk03978a42014-06-10 15:05:30 -04005427 */
Kenny Guy14f48e52015-06-29 15:12:36 +01005428 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07005429 public @Nullable UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
Robin Lee25e26452015-06-02 09:56:29 -07005430 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04005431 return null;
5432 }
5433
5434 /**
phweissa92e1212016-01-25 17:14:10 +01005435 * Flag used by {@link #createAndManageUser} to skip setup wizard after creating a new user.
phweiss343fb332016-01-25 14:48:59 +01005436 */
5437 public static final int SKIP_SETUP_WIZARD = 0x0001;
5438
5439 /**
Lenka Trochtovac8202c82016-01-26 15:11:09 +01005440 * Flag used by {@link #createAndManageUser} to specify that the user should be created
5441 * ephemeral.
5442 * @hide
5443 */
5444 public static final int MAKE_USER_EPHEMERAL = 0x0002;
5445
5446 /**
phweissa92e1212016-01-25 17:14:10 +01005447 * Called by a device owner to create a user with the specified name and a given component of
5448 * the calling package as profile owner. The UserHandle returned by this method should not be
5449 * persisted as user handles are recycled as users are removed and created. If you need to
5450 * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new
5451 * user will not be started in the background.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005452 * <p>
5453 * admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also a
5454 * DeviceAdminReceiver in the same package as admin, and will become the profile owner and will
5455 * be registered as an active admin on the new user. The profile owner package will be installed
5456 * on the new user.
5457 * <p>
5458 * If the adminExtras are not null, they will be stored on the device until the user is started
5459 * for the first time. Then the extras will be passed to the admin when onEnable is called.
phweiss343fb332016-01-25 14:48:59 +01005460 *
5461 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5462 * @param name The user's name.
phweissa92e1212016-01-25 17:14:10 +01005463 * @param profileOwner Which {@link DeviceAdminReceiver} will be profile owner. Has to be in the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005464 * same package as admin, otherwise no user is created and an
5465 * IllegalArgumentException is thrown.
phweiss343fb332016-01-25 14:48:59 +01005466 * @param adminExtras Extras that will be passed to onEnable of the admin receiver on the new
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005467 * user.
phweissa92e1212016-01-25 17:14:10 +01005468 * @param flags {@link #SKIP_SETUP_WIZARD} is supported.
phweiss343fb332016-01-25 14:48:59 +01005469 * @see UserHandle
5470 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
5471 * user could not be created.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005472 * @throws SecurityException if {@code admin} is not a device owner.
phweiss343fb332016-01-25 14:48:59 +01005473 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005474 public @Nullable UserHandle createAndManageUser(@NonNull ComponentName admin,
5475 @NonNull String name,
phweissa92e1212016-01-25 17:14:10 +01005476 @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras,
5477 int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005478 throwIfParentInstance("createAndManageUser");
phweiss343fb332016-01-25 14:48:59 +01005479 try {
phweissa92e1212016-01-25 17:14:10 +01005480 return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags);
phweiss343fb332016-01-25 14:48:59 +01005481 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005482 throw re.rethrowFromSystemServer();
phweiss343fb332016-01-25 14:48:59 +01005483 }
phweiss343fb332016-01-25 14:48:59 +01005484 }
5485
5486 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005487 * Called by a device owner to remove a user and all associated data. The primary user can not
5488 * be removed.
Julia Reynolds1e958392014-05-16 14:25:21 -04005489 *
5490 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5491 * @param userHandle the user to remove.
5492 * @return {@code true} if the user was removed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005493 * @throws SecurityException if {@code admin} is not a device owner.
Julia Reynolds1e958392014-05-16 14:25:21 -04005494 */
Robin Lee25e26452015-06-02 09:56:29 -07005495 public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005496 throwIfParentInstance("removeUser");
Julia Reynolds1e958392014-05-16 14:25:21 -04005497 try {
5498 return mService.removeUser(admin, userHandle);
5499 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005500 throw re.rethrowFromSystemServer();
Julia Reynolds1e958392014-05-16 14:25:21 -04005501 }
5502 }
5503
5504 /**
Jason Monk582d9112014-07-09 19:57:08 -04005505 * Called by a device owner to switch the specified user to the foreground.
5506 *
5507 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5508 * @param userHandle the user to switch to; null will switch to primary.
5509 * @return {@code true} if the switch was successful, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005510 * @throws SecurityException if {@code admin} is not a device owner.
Jason Monk582d9112014-07-09 19:57:08 -04005511 * @see Intent#ACTION_USER_FOREGROUND
5512 */
Robin Lee25e26452015-06-02 09:56:29 -07005513 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005514 throwIfParentInstance("switchUser");
Jason Monk582d9112014-07-09 19:57:08 -04005515 try {
5516 return mService.switchUser(admin, userHandle);
5517 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005518 throw re.rethrowFromSystemServer();
Jason Monk582d9112014-07-09 19:57:08 -04005519 }
5520 }
5521
5522 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00005523 * Retrieves the application restrictions for a given target application running in the calling
5524 * user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005525 * <p>
5526 * The caller must be a profile or device owner on that user, or the package allowed to manage
5527 * application restrictions via {@link #setApplicationRestrictionsManagingPackage}; otherwise a
5528 * security exception will be thrown.
Robin Lee66e5d962014-04-09 16:44:21 +01005529 *
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005530 * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
5531 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00005532 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005533 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01005534 * @param packageName The name of the package to fetch restricted settings of.
5535 * @return {@link Bundle} of settings corresponding to what was set last time
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005536 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty
5537 * {@link Bundle} if no restrictions have been set.
5538 * @throws SecurityException if {@code admin} is not a device or profile owner.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005539 * @see {@link #setApplicationRestrictionsManagingPackage}
Robin Lee66e5d962014-04-09 16:44:21 +01005540 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005541 @WorkerThread
Makoto Onuki408e8e42016-10-25 12:10:27 -07005542 public @NonNull Bundle getApplicationRestrictions(
5543 @Nullable ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005544 throwIfParentInstance("getApplicationRestrictions");
Robin Lee66e5d962014-04-09 16:44:21 +01005545 if (mService != null) {
5546 try {
5547 return mService.getApplicationRestrictions(admin, packageName);
5548 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005549 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01005550 }
5551 }
5552 return null;
5553 }
Amith Yamasanibe465322014-04-24 13:45:17 -07005554
5555 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05005556 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07005557 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005558 * The calling device admin must be a profile or device owner; if it is not, a security
5559 * exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07005560 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005561 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5562 * @param key The key of the restriction. See the constants in {@link android.os.UserManager}
5563 * for the list of keys.
5564 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanibe465322014-04-24 13:45:17 -07005565 */
Robin Lee25e26452015-06-02 09:56:29 -07005566 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005567 throwIfParentInstance("addUserRestriction");
Amith Yamasanibe465322014-04-24 13:45:17 -07005568 if (mService != null) {
5569 try {
5570 mService.setUserRestriction(admin, key, true);
5571 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005572 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07005573 }
5574 }
5575 }
5576
5577 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05005578 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07005579 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005580 * The calling device admin must be a profile or device owner; if it is not, a security
5581 * exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07005582 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005583 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5584 * @param key The key of the restriction. See the constants in {@link android.os.UserManager}
5585 * for the list of keys.
5586 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanibe465322014-04-24 13:45:17 -07005587 */
Robin Lee25e26452015-06-02 09:56:29 -07005588 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005589 throwIfParentInstance("clearUserRestriction");
Amith Yamasanibe465322014-04-24 13:45:17 -07005590 if (mService != null) {
5591 try {
5592 mService.setUserRestriction(admin, key, false);
5593 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005594 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07005595 }
5596 }
5597 }
Adam Connors010cfd42014-04-16 12:48:13 +01005598
5599 /**
Makoto Onuki3a3092f2015-10-30 11:07:51 -07005600 * Called by a profile or device owner to get user restrictions set with
5601 * {@link #addUserRestriction(ComponentName, String)}.
5602 * <p>
5603 * The target user may have more restrictions set by the system or other device owner / profile
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005604 * owner. To get all the user restrictions currently set, use
Makoto Onuki3a3092f2015-10-30 11:07:51 -07005605 * {@link UserManager#getUserRestrictions()}.
5606 *
5607 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005608 * @throws SecurityException if {@code admin} is not a device or profile owner.
Makoto Onuki3a3092f2015-10-30 11:07:51 -07005609 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005610 public @NonNull Bundle getUserRestrictions(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005611 throwIfParentInstance("getUserRestrictions");
Makoto Onuki3a3092f2015-10-30 11:07:51 -07005612 Bundle ret = null;
5613 if (mService != null) {
5614 try {
Sudheer Shanka549b9692016-03-30 17:12:07 -07005615 ret = mService.getUserRestrictions(admin);
5616 } catch (RemoteException e) {
5617 throw e.rethrowFromSystemServer();
5618 }
5619 }
5620 return ret == null ? new Bundle() : ret;
5621 }
5622
5623 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005624 * Called by profile or device owners to hide or unhide packages. When a package is hidden it is
5625 * unavailable for use, but the data and actual package file remain.
Julia Reynolds966881e2014-05-14 12:23:08 -04005626 *
5627 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005628 * @param packageName The name of the package to hide or unhide.
5629 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005630 * unhidden.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005631 * @return boolean Whether the hidden setting of the package was successfully updated.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005632 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds966881e2014-05-14 12:23:08 -04005633 */
Robin Lee25e26452015-06-02 09:56:29 -07005634 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005635 boolean hidden) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005636 throwIfParentInstance("setApplicationHidden");
Julia Reynolds966881e2014-05-14 12:23:08 -04005637 if (mService != null) {
5638 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005639 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04005640 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005641 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04005642 }
5643 }
5644 return false;
5645 }
5646
5647 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05005648 * Called by profile or device owners to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04005649 *
5650 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005651 * @param packageName The name of the package to retrieve the hidden status of.
5652 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005653 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds966881e2014-05-14 12:23:08 -04005654 */
Robin Lee25e26452015-06-02 09:56:29 -07005655 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005656 throwIfParentInstance("isApplicationHidden");
Julia Reynolds966881e2014-05-14 12:23:08 -04005657 if (mService != null) {
5658 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005659 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04005660 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005661 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04005662 }
5663 }
5664 return false;
5665 }
5666
5667 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05005668 * Called by profile or device owners to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005669 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00005670 *
5671 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Makoto Onuki32b30572015-12-11 14:29:51 -08005672 * @param packageName The package to be re-enabled in the calling profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005673 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors655be2a2014-07-14 09:01:25 +00005674 */
Robin Lee25e26452015-06-02 09:56:29 -07005675 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005676 throwIfParentInstance("enableSystemApp");
Adam Connors655be2a2014-07-14 09:01:25 +00005677 if (mService != null) {
5678 try {
5679 mService.enableSystemApp(admin, packageName);
5680 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005681 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00005682 }
5683 }
5684 }
5685
5686 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005687 * Called by profile or device owners to re-enable system apps by intent that were disabled by
5688 * default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00005689 *
5690 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5691 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005692 * intent will be re-enabled in the calling profile.
Adam Connors655be2a2014-07-14 09:01:25 +00005693 * @return int The number of activities that matched the intent and were installed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005694 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors655be2a2014-07-14 09:01:25 +00005695 */
Robin Lee25e26452015-06-02 09:56:29 -07005696 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005697 throwIfParentInstance("enableSystemApp");
Adam Connors655be2a2014-07-14 09:01:25 +00005698 if (mService != null) {
5699 try {
5700 return mService.enableSystemAppWithIntent(admin, intent);
5701 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005702 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00005703 }
5704 }
5705 return 0;
5706 }
5707
5708 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00005709 * Called by a device owner or profile owner to disable account management for a specific type
5710 * of account.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005711 * <p>
5712 * The calling device admin must be a device owner or profile owner. If it is not, a security
5713 * exception will be thrown.
5714 * <p>
5715 * When account management is disabled for an account type, adding or removing an account of
5716 * that type will not be possible.
5717 * <p>
5718 * From {@link android.os.Build.VERSION_CODES#N} the profile or device owner can still use
Benjamin Franzb6c0ce42015-11-05 10:06:51 +00005719 * {@link android.accounts.AccountManager} APIs to add or remove accounts when account
5720 * management for a specific type is disabled.
5721 *
Sander Alewijnse650c3342014-05-08 18:00:50 +01005722 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5723 * @param accountType For which account management is disabled or enabled.
5724 * @param disabled The boolean indicating that account management will be disabled (true) or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005725 * enabled (false).
5726 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnse650c3342014-05-08 18:00:50 +01005727 */
Robin Lee25e26452015-06-02 09:56:29 -07005728 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01005729 boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005730 throwIfParentInstance("setAccountManagementDisabled");
Sander Alewijnse650c3342014-05-08 18:00:50 +01005731 if (mService != null) {
5732 try {
5733 mService.setAccountManagementDisabled(admin, accountType, disabled);
5734 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005735 throw e.rethrowFromSystemServer();
Sander Alewijnse650c3342014-05-08 18:00:50 +01005736 }
5737 }
5738 }
5739
5740 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01005741 * Gets the array of accounts for which account management is disabled by the profile owner.
5742 *
5743 * <p> Account management can be disabled/enabled by calling
5744 * {@link #setAccountManagementDisabled}.
5745 *
5746 * @return a list of account types for which account management has been disabled.
5747 *
5748 * @see #setAccountManagementDisabled
5749 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005750 public @Nullable String[] getAccountTypesWithManagementDisabled() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005751 throwIfParentInstance("getAccountTypesWithManagementDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07005752 return getAccountTypesWithManagementDisabledAsUser(myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01005753 }
5754
5755 /**
5756 * @see #getAccountTypesWithManagementDisabled()
5757 * @hide
5758 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005759 public @Nullable String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01005760 if (mService != null) {
5761 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01005762 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01005763 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005764 throw e.rethrowFromSystemServer();
Sander Alewijnse5c02db62014-05-07 10:46:57 +01005765 }
5766 }
5767
5768 return null;
5769 }
justinzhang511e0d82014-03-24 16:09:24 -04005770
5771 /**
Jason Monkd7b86212014-06-16 13:15:38 -04005772 * Sets which packages may enter lock task mode.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005773 * <p>
5774 * Any packages that shares uid with an allowed package will also be allowed to activate lock
5775 * task. From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task
5776 * package list results in locked tasks belonging to those packages to be finished. This
5777 * function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04005778 *
Jason Monkd7b86212014-06-16 13:15:38 -04005779 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04005780 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005781 * @throws SecurityException if {@code admin} is not a device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04005782 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00005783 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
5784 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04005785 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04005786 */
Robin Lee25e26452015-06-02 09:56:29 -07005787 public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04005788 throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005789 throwIfParentInstance("setLockTaskPackages");
justinzhang511e0d82014-03-24 16:09:24 -04005790 if (mService != null) {
5791 try {
Jason Monk48aacba2014-08-13 16:29:08 -04005792 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04005793 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005794 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04005795 }
5796 }
5797 }
5798
5799 /**
Jason Monkd7b86212014-06-16 13:15:38 -04005800 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04005801 *
5802 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04005803 * @hide
5804 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005805 public @NonNull String[] getLockTaskPackages(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005806 throwIfParentInstance("getLockTaskPackages");
justinzhang511e0d82014-03-24 16:09:24 -04005807 if (mService != null) {
5808 try {
Jason Monk48aacba2014-08-13 16:29:08 -04005809 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04005810 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005811 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04005812 }
5813 }
5814 return null;
5815 }
5816
5817 /**
5818 * This function lets the caller know whether the given component is allowed to start the
5819 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04005820 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04005821 */
Jason Monkd7b86212014-06-16 13:15:38 -04005822 public boolean isLockTaskPermitted(String pkg) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005823 throwIfParentInstance("isLockTaskPermitted");
justinzhang511e0d82014-03-24 16:09:24 -04005824 if (mService != null) {
5825 try {
Jason Monkd7b86212014-06-16 13:15:38 -04005826 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04005827 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005828 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04005829 }
5830 }
5831 return false;
5832 }
Julia Reynoldsda551652014-05-14 17:15:16 -04005833
5834 /**
5835 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
5836 * 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 -07005837 * <p>
5838 * The settings that can be updated with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005839 * <ul>
5840 * <li>{@link Settings.Global#ADB_ENABLED}</li>
5841 * <li>{@link Settings.Global#AUTO_TIME}</li>
5842 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005843 * <li>{@link Settings.Global#DATA_ROAMING}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005844 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005845 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005846 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN} This setting is only available from
5847 * {@link android.os.Build.VERSION_CODES#M} onwards and can only be set if
5848 * {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
5849 * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li> This setting is only
5850 * available from {@link android.os.Build.VERSION_CODES#M} onwards.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005851 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005852 * <p>
5853 * Changing the following settings has no effect as of {@link android.os.Build.VERSION_CODES#M}:
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005854 * <ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005855 * <li>{@link Settings.Global#BLUETOOTH_ON}. Use
5856 * {@link android.bluetooth.BluetoothAdapter#enable()} and
5857 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005858 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005859 * <li>{@link Settings.Global#MODE_RINGER}. Use
5860 * {@link android.media.AudioManager#setRingerMode(int)} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005861 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005862 * <li>{@link Settings.Global#WIFI_ON}. Use
5863 * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005864 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04005865 *
5866 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5867 * @param setting The name of the setting to update.
5868 * @param value The value to update the setting to.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005869 * @throws SecurityException if {@code admin} is not a device owner.
Julia Reynoldsda551652014-05-14 17:15:16 -04005870 */
Robin Lee25e26452015-06-02 09:56:29 -07005871 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005872 throwIfParentInstance("setGlobalSetting");
Julia Reynoldsda551652014-05-14 17:15:16 -04005873 if (mService != null) {
5874 try {
5875 mService.setGlobalSetting(admin, setting, value);
5876 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005877 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04005878 }
5879 }
5880 }
5881
5882 /**
5883 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
5884 * that the value of the setting is in the correct form for the setting type should be performed
5885 * by the caller.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005886 * <p>
5887 * The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005888 * <ul>
5889 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07005890 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005891 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
5892 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005893 * <p>
5894 * A device owner can additionally update the following settings:
Julia Reynolds82735bc2014-09-04 16:43:30 -04005895 * <ul>
5896 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
5897 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005898 *
Julia Reynoldsda551652014-05-14 17:15:16 -04005899 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5900 * @param setting The name of the setting to update.
5901 * @param value The value to update the setting to.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005902 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynoldsda551652014-05-14 17:15:16 -04005903 */
Robin Lee25e26452015-06-02 09:56:29 -07005904 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005905 throwIfParentInstance("setSecureSetting");
Julia Reynoldsda551652014-05-14 17:15:16 -04005906 if (mService != null) {
5907 try {
5908 mService.setSecureSetting(admin, setting, value);
5909 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005910 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04005911 }
5912 }
5913 }
5914
Amith Yamasanif20d6402014-05-24 15:34:37 -07005915 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005916 * Designates a specific service component as the provider for making permission requests of a
5917 * local or remote administrator of the user.
Amith Yamasanif20d6402014-05-24 15:34:37 -07005918 * <p/>
5919 * Only a profile owner can designate the restrictions provider.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005920 *
Amith Yamasanif20d6402014-05-24 15:34:37 -07005921 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07005922 * @param provider The component name of the service that implements
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005923 * {@link RestrictionsReceiver}. If this param is null, it removes the restrictions
5924 * provider previously assigned.
5925 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanif20d6402014-05-24 15:34:37 -07005926 */
Robin Lee25e26452015-06-02 09:56:29 -07005927 public void setRestrictionsProvider(@NonNull ComponentName admin,
5928 @Nullable ComponentName provider) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005929 throwIfParentInstance("setRestrictionsProvider");
Amith Yamasanif20d6402014-05-24 15:34:37 -07005930 if (mService != null) {
5931 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07005932 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07005933 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005934 throw re.rethrowFromSystemServer();
Amith Yamasanif20d6402014-05-24 15:34:37 -07005935 }
5936 }
5937 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04005938
5939 /**
5940 * Called by profile or device owners to set the master volume mute on or off.
Nicolas Prevotaef3ce22016-09-22 12:00:25 +01005941 * This has no effect when set on a managed profile.
Julia Reynolds4a21b252014-06-04 11:11:43 -04005942 *
5943 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5944 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005945 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds4a21b252014-06-04 11:11:43 -04005946 */
Robin Lee25e26452015-06-02 09:56:29 -07005947 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005948 throwIfParentInstance("setMasterVolumeMuted");
Julia Reynolds4a21b252014-06-04 11:11:43 -04005949 if (mService != null) {
5950 try {
5951 mService.setMasterVolumeMuted(admin, on);
5952 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005953 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04005954 }
5955 }
5956 }
5957
5958 /**
5959 * Called by profile or device owners to check whether the master volume mute is on or off.
5960 *
5961 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5962 * @return {@code true} if master volume is muted, {@code false} if it's not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005963 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds4a21b252014-06-04 11:11:43 -04005964 */
Robin Lee25e26452015-06-02 09:56:29 -07005965 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005966 throwIfParentInstance("isMasterVolumeMuted");
Julia Reynolds4a21b252014-06-04 11:11:43 -04005967 if (mService != null) {
5968 try {
5969 return mService.isMasterVolumeMuted(admin);
5970 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005971 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04005972 }
5973 }
5974 return false;
5975 }
Kenny Guyc13053b2014-05-29 14:17:17 +01005976
5977 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005978 * Called by profile or device owners to change whether a user can uninstall a package.
Kenny Guyc13053b2014-05-29 14:17:17 +01005979 *
5980 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5981 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01005982 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005983 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyc13053b2014-05-29 14:17:17 +01005984 */
Robin Lee25e26452015-06-02 09:56:29 -07005985 public void setUninstallBlocked(@NonNull ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01005986 boolean uninstallBlocked) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005987 throwIfParentInstance("setUninstallBlocked");
Kenny Guyc13053b2014-05-29 14:17:17 +01005988 if (mService != null) {
5989 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01005990 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01005991 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005992 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01005993 }
5994 }
5995 }
5996
5997 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005998 * Check whether the user has been blocked by device policy from uninstalling a package.
Rubin Xua97855b2014-11-07 05:41:00 +00005999 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00006000 * <p>
6001 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006002 * behavior of this API is changed such that passing {@code null} as the {@code admin} parameter
6003 * will return if any admin has blocked the uninstallation. Before L MR1, passing {@code null}
6004 * will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01006005 *
Robin Lee25e26452015-06-02 09:56:29 -07006006 * @param admin The name of the admin component whose blocking policy will be checked, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006007 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01006008 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00006009 * @return true if uninstallation is blocked.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006010 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyc13053b2014-05-29 14:17:17 +01006011 */
Robin Lee25e26452015-06-02 09:56:29 -07006012 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006013 throwIfParentInstance("isUninstallBlocked");
Kenny Guyc13053b2014-05-29 14:17:17 +01006014 if (mService != null) {
6015 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01006016 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01006017 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006018 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01006019 }
6020 }
6021 return false;
6022 }
Svetoslav976e8bd2014-07-16 15:12:03 -07006023
6024 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006025 * Called by the profile owner of a managed profile to enable widget providers from a given
6026 * package to be available in the parent profile. As a result the user will be able to add
6027 * widgets from the white-listed package running under the profile to a widget host which runs
6028 * under the parent profile, for example the home screen. Note that a package may have zero or
6029 * more provider components, where each component provides a different widget type.
Svetoslav976e8bd2014-07-16 15:12:03 -07006030 * <p>
6031 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07006032 *
6033 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6034 * @param packageName The package from which widget providers are white-listed.
6035 * @return Whether the package was added.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006036 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07006037 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
6038 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
6039 */
Robin Lee25e26452015-06-02 09:56:29 -07006040 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006041 throwIfParentInstance("addCrossProfileWidgetProvider");
Svetoslav976e8bd2014-07-16 15:12:03 -07006042 if (mService != null) {
6043 try {
6044 return mService.addCrossProfileWidgetProvider(admin, packageName);
6045 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006046 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07006047 }
6048 }
6049 return false;
6050 }
6051
6052 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07006053 * Called by the profile owner of a managed profile to disable widget providers from a given
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006054 * package to be available in the parent profile. For this method to take effect the package
6055 * should have been added via
6056 * {@link #addCrossProfileWidgetProvider( android.content.ComponentName, String)}.
Svetoslav976e8bd2014-07-16 15:12:03 -07006057 * <p>
6058 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07006059 *
6060 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006061 * @param packageName The package from which widget providers are no longer white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07006062 * @return Whether the package was removed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006063 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07006064 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
6065 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
6066 */
Esteban Talavera62399912016-01-11 15:37:55 +00006067 public boolean removeCrossProfileWidgetProvider(
6068 @NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006069 throwIfParentInstance("removeCrossProfileWidgetProvider");
Svetoslav976e8bd2014-07-16 15:12:03 -07006070 if (mService != null) {
6071 try {
6072 return mService.removeCrossProfileWidgetProvider(admin, packageName);
6073 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006074 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07006075 }
6076 }
6077 return false;
6078 }
6079
6080 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07006081 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07006082 * available in the parent profile.
6083 *
6084 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6085 * @return The white-listed package list.
Svetoslav976e8bd2014-07-16 15:12:03 -07006086 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
6087 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006088 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07006089 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006090 public @NonNull List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006091 throwIfParentInstance("getCrossProfileWidgetProviders");
Svetoslav976e8bd2014-07-16 15:12:03 -07006092 if (mService != null) {
6093 try {
6094 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
6095 if (providers != null) {
6096 return providers;
6097 }
6098 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006099 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07006100 }
6101 }
6102 return Collections.emptyList();
6103 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006104
6105 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08006106 * Called by profile or device owners to set the user's photo.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006107 *
6108 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6109 * @param icon the bitmap to set as the photo.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006110 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006111 */
Robin Lee25e26452015-06-02 09:56:29 -07006112 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006113 throwIfParentInstance("setUserIcon");
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006114 try {
6115 mService.setUserIcon(admin, icon);
6116 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006117 throw re.rethrowFromSystemServer();
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006118 }
6119 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04006120
6121 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01006122 * Called by device owners to set a local system update policy. When a new policy is set,
6123 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00006124 *
Robin Lee25e26452015-06-02 09:56:29 -07006125 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006126 * components in the device owner package can set system update policies and the most
6127 * recent policy takes effect.
Robin Lee25e26452015-06-02 09:56:29 -07006128 * @param policy the new policy, or {@code null} to clear the current policy.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006129 * @throws SecurityException if {@code admin} is not a device owner.
Rubin Xu5faad8e2015-04-20 17:43:48 +01006130 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00006131 */
Robin Lee25e26452015-06-02 09:56:29 -07006132 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006133 throwIfParentInstance("setSystemUpdatePolicy");
Rubin Xu8027a4f2015-03-10 17:52:37 +00006134 if (mService != null) {
6135 try {
Robin Lee25e26452015-06-02 09:56:29 -07006136 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00006137 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006138 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00006139 }
6140 }
6141 }
6142
6143 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01006144 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00006145 *
Robin Lee25e26452015-06-02 09:56:29 -07006146 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00006147 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006148 public @Nullable SystemUpdatePolicy getSystemUpdatePolicy() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006149 throwIfParentInstance("getSystemUpdatePolicy");
Rubin Xu8027a4f2015-03-10 17:52:37 +00006150 if (mService != null) {
6151 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01006152 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00006153 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006154 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00006155 }
6156 }
6157 return null;
6158 }
Benjamin Franze36087e2015-04-07 16:40:34 +01006159
6160 /**
6161 * Called by a device owner to disable the keyguard altogether.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006162 * <p>
6163 * Setting the keyguard to disabled has the same effect as choosing "None" as the screen lock
6164 * type. However, this call has no effect if a password, pin or pattern is currently set. If a
6165 * password, pin or pattern is set after the keyguard was disabled, the keyguard stops being
6166 * disabled.
Benjamin Franze36087e2015-04-07 16:40:34 +01006167 *
6168 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01006169 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01006170 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006171 * place. {@code true} otherwise.
6172 * @throws SecurityException if {@code admin} is not a device owner.
Benjamin Franze36087e2015-04-07 16:40:34 +01006173 */
Robin Lee25e26452015-06-02 09:56:29 -07006174 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006175 throwIfParentInstance("setKeyguardDisabled");
Benjamin Franze36087e2015-04-07 16:40:34 +01006176 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01006177 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01006178 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006179 throw re.rethrowFromSystemServer();
Benjamin Franze36087e2015-04-07 16:40:34 +01006180 }
6181 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00006182
6183 /**
Benjamin Franzbece8062015-05-06 12:14:31 +01006184 * Called by device owner to disable the status bar. Disabling the status bar blocks
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006185 * notifications, quick settings and other screen overlays that allow escaping from a single use
6186 * device.
Benjamin Franzea2ec972015-03-16 17:18:09 +00006187 *
6188 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01006189 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006190 * @return {@code false} if attempting to disable the status bar failed. {@code true} otherwise.
6191 * @throws SecurityException if {@code admin} is not a device owner.
Benjamin Franzea2ec972015-03-16 17:18:09 +00006192 */
Robin Lee25e26452015-06-02 09:56:29 -07006193 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006194 throwIfParentInstance("setStatusBarDisabled");
Benjamin Franzea2ec972015-03-16 17:18:09 +00006195 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01006196 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00006197 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006198 throw re.rethrowFromSystemServer();
Benjamin Franzea2ec972015-03-16 17:18:09 +00006199 }
6200 }
Rubin Xudc105cc2015-04-14 23:38:01 +01006201
6202 /**
6203 * Callable by the system update service to notify device owners about pending updates.
6204 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
6205 * permission.
6206 *
6207 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating
6208 * when the current pending update was first available. -1 if no update is available.
6209 * @hide
6210 */
6211 @SystemApi
6212 public void notifyPendingSystemUpdate(long updateReceivedTime) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006213 throwIfParentInstance("notifyPendingSystemUpdate");
Rubin Xudc105cc2015-04-14 23:38:01 +01006214 if (mService != null) {
6215 try {
6216 mService.notifyPendingSystemUpdate(updateReceivedTime);
6217 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006218 throw re.rethrowFromSystemServer();
Rubin Xudc105cc2015-04-14 23:38:01 +01006219 }
6220 }
6221 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04006222
6223 /**
Amith Yamasanid49489b2015-04-28 14:00:26 -07006224 * Called by profile or device owners to set the default response for future runtime permission
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006225 * requests by applications. The policy can allow for normal operation which prompts the user to
6226 * grant a permission, or can allow automatic granting or denying of runtime permission requests
6227 * by an application. This also applies to new permissions declared by app updates. When a
6228 * permission is denied or granted this way, the effect is equivalent to setting the permission
6229 * grant state via {@link #setPermissionGrantState}.
6230 * <p/>
6231 * As this policy only acts on runtime permission requests, it only applies to applications
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07006232 * built with a {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Benjamin Franz45dd6662015-07-08 14:24:14 +01006233 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07006234 * @param admin Which profile or device owner this request is associated with.
6235 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006236 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
6237 * @throws SecurityException if {@code admin} is not a device or profile owner.
Benjamin Franz45dd6662015-07-08 14:24:14 +01006238 * @see #setPermissionGrantState
Amith Yamasanid49489b2015-04-28 14:00:26 -07006239 */
Robin Lee25e26452015-06-02 09:56:29 -07006240 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006241 throwIfParentInstance("setPermissionPolicy");
Amith Yamasanid49489b2015-04-28 14:00:26 -07006242 try {
6243 mService.setPermissionPolicy(admin, policy);
6244 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006245 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07006246 }
6247 }
6248
6249 /**
6250 * Returns the current runtime permission policy set by the device or profile owner. The
6251 * default is {@link #PERMISSION_POLICY_PROMPT}.
6252 * @param admin Which profile or device owner this request is associated with.
6253 * @return the current policy for future permission requests.
6254 */
Esteban Talavera28b95702015-06-24 15:23:42 +01006255 public int getPermissionPolicy(ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006256 throwIfParentInstance("getPermissionPolicy");
Amith Yamasanid49489b2015-04-28 14:00:26 -07006257 try {
6258 return mService.getPermissionPolicy(admin);
6259 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006260 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07006261 }
6262 }
6263
6264 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006265 * Sets the grant state of a runtime permission for a specific application. The state can be
6266 * {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it through the UI,
6267 * {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission is denied and the user
6268 * cannot manage it through the UI, and {@link #PERMISSION_GRANT_STATE_GRANTED granted} in which
6269 * the permission is granted and the user cannot manage it through the UI. This might affect all
6270 * permissions in a group that the runtime permission belongs to. This method can only be called
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006271 * by a profile or device owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006272 * <p/>
6273 * Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not revoke
6274 * the permission. It retains the previous grant, if any.
6275 * <p/>
6276 * Permissions can be granted or revoked only for applications built with a
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07006277 * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07006278 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07006279 * @param admin Which profile or device owner this request is associated with.
6280 * @param packageName The application to grant or revoke a permission to.
6281 * @param permission The permission to grant or revoke.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006282 * @param grantState The permission grant state which is one of
6283 * {@link #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
6284 * {@link #PERMISSION_GRANT_STATE_GRANTED},
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006285 * @return whether the permission was successfully granted or revoked.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006286 * @throws SecurityException if {@code admin} is not a device or profile owner.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006287 * @see #PERMISSION_GRANT_STATE_DENIED
6288 * @see #PERMISSION_GRANT_STATE_DEFAULT
6289 * @see #PERMISSION_GRANT_STATE_GRANTED
Amith Yamasanid49489b2015-04-28 14:00:26 -07006290 */
Robin Lee25e26452015-06-02 09:56:29 -07006291 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006292 String permission, int grantState) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006293 throwIfParentInstance("setPermissionGrantState");
Amith Yamasanid49489b2015-04-28 14:00:26 -07006294 try {
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006295 return mService.setPermissionGrantState(admin, packageName, permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07006296 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006297 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07006298 }
6299 }
Amith Yamasani184b3752015-05-22 13:00:51 -07006300
6301 /**
6302 * Returns the current grant state of a runtime permission for a specific application.
6303 *
6304 * @param admin Which profile or device owner this request is associated with.
6305 * @param packageName The application to check the grant state for.
6306 * @param permission The permission to check for.
6307 * @return the current grant state specified by device policy. If the profile or device owner
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006308 * has not set a grant state, the return value is
6309 * {@link #PERMISSION_GRANT_STATE_DEFAULT}. This does not indicate whether or not the
6310 * permission is currently granted for the package.
6311 * <p/>
6312 * If a grant state was set by the profile or device owner, then the return value will
6313 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or
6314 * {@link #PERMISSION_GRANT_STATE_GRANTED}, which indicates if the permission is
6315 * currently denied or granted.
6316 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasani184b3752015-05-22 13:00:51 -07006317 * @see #setPermissionGrantState(ComponentName, String, String, int)
6318 * @see PackageManager#checkPermission(String, String)
6319 */
Robin Lee25e26452015-06-02 09:56:29 -07006320 public int getPermissionGrantState(@NonNull ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07006321 String permission) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006322 throwIfParentInstance("getPermissionGrantState");
Amith Yamasani184b3752015-05-22 13:00:51 -07006323 try {
6324 return mService.getPermissionGrantState(admin, packageName, permission);
6325 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006326 throw re.rethrowFromSystemServer();
Amith Yamasani184b3752015-05-22 13:00:51 -07006327 }
6328 }
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006329
6330 /**
Esteban Talavera01576862016-12-15 11:16:44 +00006331 * Returns whether it is possible for the caller to initiate provisioning of a managed profile
6332 * or device, setting itself as the device or profile owner.
6333 *
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006334 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
6335 * {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Esteban Talavera01576862016-12-15 11:16:44 +00006336 * @return whether provisioning a managed profile or device is possible.
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006337 * @throws IllegalArgumentException if the supplied action is not valid.
6338 */
Esteban Talavera01576862016-12-15 11:16:44 +00006339 public boolean isProvisioningAllowed(@NonNull String action) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006340 throwIfParentInstance("isProvisioningAllowed");
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006341 try {
Esteban Talavera01576862016-12-15 11:16:44 +00006342 return mService.isProvisioningAllowed(action, mContext.getPackageName());
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006343 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006344 throw re.rethrowFromSystemServer();
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006345 }
6346 }
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006347
6348 /**
Esteban Talavera01576862016-12-15 11:16:44 +00006349 * Checks whether it is possible to initiate provisioning a managed device,
6350 * profile or user, setting the given package as owner.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00006351 *
6352 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
6353 * {@link #ACTION_PROVISION_MANAGED_PROFILE},
6354 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE},
6355 * {@link #ACTION_PROVISION_MANAGED_USER}
Esteban Talavera01576862016-12-15 11:16:44 +00006356 * @param packageName The package of the component that would be set as device, user, or profile
6357 * owner.
6358 * @return A {@link ProvisioningPreCondition} value indicating whether provisioning is allowed.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00006359 * @hide
6360 */
Esteban Talavera01576862016-12-15 11:16:44 +00006361 public @ProvisioningPreCondition int checkProvisioningPreCondition(
6362 String action, @NonNull String packageName) {
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00006363 try {
Esteban Talavera01576862016-12-15 11:16:44 +00006364 return mService.checkProvisioningPreCondition(action, packageName);
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00006365 } catch (RemoteException re) {
6366 throw re.rethrowFromSystemServer();
6367 }
6368 }
6369
6370 /**
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006371 * Return if this user is a managed profile of another user. An admin can become the profile
6372 * owner of a managed profile with {@link #ACTION_PROVISION_MANAGED_PROFILE} and of a managed
Kenny Guyffa38402016-03-31 16:40:57 +01006373 * user with {@link #createAndManageUser}
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006374 * @param admin Which profile owner this request is associated with.
6375 * @return if this user is a managed profile of another user.
6376 */
6377 public boolean isManagedProfile(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006378 throwIfParentInstance("isManagedProfile");
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006379 try {
6380 return mService.isManagedProfile(admin);
6381 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006382 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006383 }
6384 }
6385
6386 /**
6387 * @hide
6388 * Return if this user is a system-only user. An admin can manage a device from a system only
6389 * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}.
6390 * @param admin Which device owner this request is associated with.
6391 * @return if this user is a system-only user.
6392 */
6393 public boolean isSystemOnlyUser(@NonNull ComponentName admin) {
6394 try {
6395 return mService.isSystemOnlyUser(admin);
6396 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006397 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006398 }
6399 }
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006400
6401 /**
6402 * Called by device owner to get the MAC address of the Wi-Fi device.
6403 *
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08006404 * @param admin Which device owner this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006405 * @return the MAC address of the Wi-Fi device, or null when the information is not available.
6406 * (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.)
6407 * <p>
6408 * The address will be in the {@code XX:XX:XX:XX:XX:XX} format.
6409 * @throws SecurityException if {@code admin} is not a device owner.
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006410 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006411 public @Nullable String getWifiMacAddress(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006412 throwIfParentInstance("getWifiMacAddress");
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006413 try {
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08006414 return mService.getWifiMacAddress(admin);
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006415 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006416 throw re.rethrowFromSystemServer();
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006417 }
6418 }
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00006419
6420 /**
Mahaver Chopra1216ae52016-03-11 15:39:48 +00006421 * Called by device owner to reboot the device. If there is an ongoing call on the device,
6422 * throws an {@link IllegalStateException}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006423 * @param admin Which device owner the request is associated with.
Mahaver Chopra1216ae52016-03-11 15:39:48 +00006424 * @throws IllegalStateException if device has an ongoing call.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006425 * @throws SecurityException if {@code admin} is not a device owner.
Mahaver Chopra1216ae52016-03-11 15:39:48 +00006426 * @see TelephonyManager#CALL_STATE_IDLE
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00006427 */
6428 public void reboot(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006429 throwIfParentInstance("reboot");
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00006430 try {
6431 mService.reboot(admin);
6432 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006433 throw re.rethrowFromSystemServer();
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00006434 }
6435 }
Kenny Guy06de4e72015-12-22 12:07:39 +00006436
6437 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006438 * Called by a device admin to set the short support message. This will be displayed to the user
6439 * in settings screens where funtionality has been disabled by the admin. The message should be
6440 * limited to a short statement such as "This setting is disabled by your administrator. Contact
6441 * someone@example.com for support." If the message is longer than 200 characters it may be
6442 * truncated.
6443 * <p>
6444 * If the short support message needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006445 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
6446 * and set a new version of this string accordingly.
6447 *
Kenny Guy06de4e72015-12-22 12:07:39 +00006448 * @see #setLongSupportMessage
Kenny Guy06de4e72015-12-22 12:07:39 +00006449 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006450 * @param message Short message to be displayed to the user in settings or null to clear the
6451 * existing message.
6452 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00006453 */
6454 public void setShortSupportMessage(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006455 @Nullable CharSequence message) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006456 throwIfParentInstance("setShortSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00006457 if (mService != null) {
6458 try {
6459 mService.setShortSupportMessage(admin, message);
6460 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006461 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006462 }
6463 }
6464 }
6465
6466 /**
6467 * Called by a device admin to get the short support message.
6468 *
6469 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006470 * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)} or
6471 * null if no message has been set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006472 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00006473 */
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006474 public CharSequence getShortSupportMessage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006475 throwIfParentInstance("getShortSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00006476 if (mService != null) {
6477 try {
6478 return mService.getShortSupportMessage(admin);
6479 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006480 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006481 }
6482 }
6483 return null;
6484 }
6485
6486 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006487 * Called by a device admin to set the long support message. This will be displayed to the user
6488 * in the device administators settings screen.
6489 * <p>
6490 * If the long support message needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006491 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
6492 * and set a new version of this string accordingly.
6493 *
Kenny Guy06de4e72015-12-22 12:07:39 +00006494 * @see #setShortSupportMessage
Kenny Guy06de4e72015-12-22 12:07:39 +00006495 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006496 * @param message Long message to be displayed to the user in settings or null to clear the
6497 * existing message.
6498 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00006499 */
6500 public void setLongSupportMessage(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006501 @Nullable CharSequence message) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006502 throwIfParentInstance("setLongSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00006503 if (mService != null) {
6504 try {
6505 mService.setLongSupportMessage(admin, message);
6506 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006507 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006508 }
6509 }
6510 }
6511
6512 /**
6513 * Called by a device admin to get the long support message.
6514 *
6515 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006516 * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)} or
6517 * null if no message has been set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006518 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00006519 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006520 public @Nullable CharSequence getLongSupportMessage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006521 throwIfParentInstance("getLongSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00006522 if (mService != null) {
6523 try {
6524 return mService.getLongSupportMessage(admin);
6525 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006526 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006527 }
6528 }
6529 return null;
6530 }
6531
6532 /**
6533 * Called by the system to get the short support message.
6534 *
6535 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6536 * @param userHandle user id the admin is running as.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006537 * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)}
Kenny Guy06de4e72015-12-22 12:07:39 +00006538 *
6539 * @hide
6540 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006541 public @Nullable CharSequence getShortSupportMessageForUser(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006542 int userHandle) {
Kenny Guy06de4e72015-12-22 12:07:39 +00006543 if (mService != null) {
6544 try {
6545 return mService.getShortSupportMessageForUser(admin, userHandle);
6546 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006547 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006548 }
6549 }
6550 return null;
6551 }
6552
6553
6554 /**
6555 * Called by the system to get the long support message.
6556 *
6557 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6558 * @param userHandle user id the admin is running as.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006559 * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)}
Kenny Guy06de4e72015-12-22 12:07:39 +00006560 *
6561 * @hide
6562 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006563 public @Nullable CharSequence getLongSupportMessageForUser(
6564 @NonNull ComponentName admin, int userHandle) {
Kenny Guy06de4e72015-12-22 12:07:39 +00006565 if (mService != null) {
6566 try {
6567 return mService.getLongSupportMessageForUser(admin, userHandle);
6568 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006569 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006570 }
6571 }
6572 return null;
6573 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006574
6575 /**
Esteban Talavera62399912016-01-11 15:37:55 +00006576 * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager}
6577 * whose calls act on the parent profile.
Benjamin Franz66b45f02016-04-05 19:12:39 +01006578 *
6579 * <p>The following methods are supported for the parent instance, all other methods will
6580 * throw a SecurityException when called on the parent instance:
6581 * <ul>
6582 * <li>{@link #getPasswordQuality}</li>
6583 * <li>{@link #setPasswordQuality}</li>
6584 * <li>{@link #getPasswordMinimumLength}</li>
6585 * <li>{@link #setPasswordMinimumLength}</li>
6586 * <li>{@link #getPasswordMinimumUpperCase}</li>
6587 * <li>{@link #setPasswordMinimumUpperCase}</li>
6588 * <li>{@link #getPasswordMinimumLowerCase}</li>
6589 * <li>{@link #setPasswordMinimumLowerCase}</li>
6590 * <li>{@link #getPasswordMinimumLetters}</li>
6591 * <li>{@link #setPasswordMinimumLetters}</li>
6592 * <li>{@link #getPasswordMinimumNumeric}</li>
6593 * <li>{@link #setPasswordMinimumNumeric}</li>
6594 * <li>{@link #getPasswordMinimumSymbols}</li>
6595 * <li>{@link #setPasswordMinimumSymbols}</li>
6596 * <li>{@link #getPasswordMinimumNonLetter}</li>
6597 * <li>{@link #setPasswordMinimumNonLetter}</li>
6598 * <li>{@link #getPasswordHistoryLength}</li>
6599 * <li>{@link #setPasswordHistoryLength}</li>
6600 * <li>{@link #getPasswordExpirationTimeout}</li>
6601 * <li>{@link #setPasswordExpirationTimeout}</li>
6602 * <li>{@link #getPasswordExpiration}</li>
Charles He8c760562016-10-25 16:36:53 +01006603 * <li>{@link #getPasswordMaximumLength}</li>
Benjamin Franz66b45f02016-04-05 19:12:39 +01006604 * <li>{@link #isActivePasswordSufficient}</li>
6605 * <li>{@link #getCurrentFailedPasswordAttempts}</li>
6606 * <li>{@link #getMaximumFailedPasswordsForWipe}</li>
6607 * <li>{@link #setMaximumFailedPasswordsForWipe}</li>
6608 * <li>{@link #getMaximumTimeToLock}</li>
6609 * <li>{@link #setMaximumTimeToLock}</li>
6610 * <li>{@link #lockNow}</li>
6611 * <li>{@link #getKeyguardDisabledFeatures}</li>
6612 * <li>{@link #setKeyguardDisabledFeatures}</li>
6613 * <li>{@link #getTrustAgentConfiguration}</li>
6614 * <li>{@link #setTrustAgentConfiguration}</li>
Michal Karpinskia20d8bb2016-11-23 12:09:08 +00006615 * <li>{@link #getRequiredStrongAuthTimeout}</li>
6616 * <li>{@link #setRequiredStrongAuthTimeout}</li>
Benjamin Franz66b45f02016-04-05 19:12:39 +01006617 * </ul>
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006618 *
6619 * @return a new instance of {@link DevicePolicyManager} that acts on the parent profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006620 * @throws SecurityException if {@code admin} is not a profile owner.
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006621 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006622 public @NonNull DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006623 throwIfParentInstance("getParentProfileInstance");
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006624 try {
6625 if (!mService.isManagedProfile(admin)) {
6626 throw new SecurityException("The current user does not have a parent profile.");
6627 }
Jeff Sharkey49ca5292016-05-10 12:54:45 -06006628 return new DevicePolicyManager(mContext, mService, true);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006629 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006630 throw e.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006631 }
6632 }
6633
6634 /**
Esteban Talaverad36dd152016-12-15 08:51:45 +00006635 * Called by device owner to control the security logging feature.
Michal Karpinski6235a942016-03-15 12:07:23 +00006636 *
6637 * <p> Security logs contain various information intended for security auditing purposes.
6638 * See {@link SecurityEvent} for details.
6639 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00006640 * <p><strong>Note:</strong> The device owner won't be able to retrieve security logs if there
6641 * are unaffiliated secondary users or profiles on the device, regardless of whether the
6642 * feature is enabled. Logs will be discarded if the internal buffer fills up while waiting for
6643 * all users to become affiliated. Therefore it's recommended that affiliation ids are set for
6644 * new users as soon as possible after provisioning via {@link #setAffiliationIds}.
Michal Karpinskib58e4962016-03-01 14:55:10 +00006645 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006646 * @param admin Which device owner this request is associated with.
Michal Karpinski6235a942016-03-15 12:07:23 +00006647 * @param enabled whether security logging should be enabled or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006648 * @throws SecurityException if {@code admin} is not a device owner.
Michal Karpinski6235a942016-03-15 12:07:23 +00006649 * @see #retrieveSecurityLogs
6650 */
6651 public void setSecurityLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006652 throwIfParentInstance("setSecurityLoggingEnabled");
Michal Karpinski6235a942016-03-15 12:07:23 +00006653 try {
6654 mService.setSecurityLoggingEnabled(admin, enabled);
6655 } catch (RemoteException re) {
6656 throw re.rethrowFromSystemServer();
6657 }
6658 }
6659
6660 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00006661 * Return whether security logging is enabled or not by the device owner.
6662 *
6663 * <p>Can only be called by the device owner, otherwise a {@link SecurityException} will be
6664 * thrown.
6665 *
6666 * @param admin Which device owner this request is associated with.
6667 * @return {@code true} if security logging is enabled by device owner, {@code false} otherwise.
6668 * @throws SecurityException if {@code admin} is not a device owner.
6669 */
6670 public boolean isSecurityLoggingEnabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006671 throwIfParentInstance("isSecurityLoggingEnabled");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006672 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00006673 return mService.isSecurityLoggingEnabled(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006674 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006675 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006676 }
6677 }
6678
6679 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00006680 * Called by device owner to retrieve all new security logging entries since the last call to
6681 * this API after device boots.
6682 *
6683 * <p> Access to the logs is rate limited and it will only return new logs after the device
6684 * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}.
6685 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00006686 * <p>If there is any other user or profile on the device, it must be affiliated with the
6687 * device owner. Otherwise a {@link SecurityException} will be thrown. See
6688 * {@link #setAffiliationIds}
Michal Karpinskib58e4962016-03-01 14:55:10 +00006689 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006690 * @param admin Which device owner this request is associated with.
Michal Karpinski6235a942016-03-15 12:07:23 +00006691 * @return the new batch of security logs which is a list of {@link SecurityEvent},
6692 * or {@code null} if rate limitation is exceeded or if logging is currently disabled.
Esteban Talaverad36dd152016-12-15 08:51:45 +00006693 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
6694 * profile or secondary user that is not affiliated with the device owner user.
6695 * @see DeviceAdminReceiver#onSecurityLogsAvailable
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006696 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006697 public @Nullable List<SecurityEvent> retrieveSecurityLogs(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006698 throwIfParentInstance("retrieveSecurityLogs");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006699 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00006700 ParceledListSlice<SecurityEvent> list = mService.retrieveSecurityLogs(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006701 if (list != null) {
6702 return list.getList();
6703 } else {
6704 // Rate limit exceeded.
6705 return null;
6706 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006707 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006708 throw re.rethrowFromSystemServer();
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006709 }
6710 }
Benjamin Franz59720bb2016-01-18 15:26:11 +00006711
6712 /**
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00006713 * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent
6714 * profile.
6715 *
6716 * @hide
6717 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006718 public @NonNull DevicePolicyManager getParentProfileInstance(UserInfo uInfo) {
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00006719 mContext.checkSelfPermission(
6720 android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS);
6721 if (!uInfo.isManagedProfile()) {
6722 throw new SecurityException("The user " + uInfo.id
6723 + " does not have a parent profile.");
6724 }
Jeff Sharkey49ca5292016-05-10 12:54:45 -06006725 return new DevicePolicyManager(mContext, mService, true);
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00006726 }
6727
6728 /**
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006729 * Called by device owners to retrieve device logs from before the device's last reboot.
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006730 * <p>
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01006731 * <strong> This API is not supported on all devices. Calling this API on unsupported devices
6732 * will result in {@code null} being returned. The device logs are retrieved from a RAM region
6733 * which is not guaranteed to be corruption-free during power cycles, as a result be cautious
6734 * about data corruption when parsing. </strong>
Esteban Talaverad36dd152016-12-15 08:51:45 +00006735 *
6736 * <p>If there is any other user or profile on the device, it must be affiliated with the
6737 * device owner. Otherwise a {@link SecurityException} will be thrown. See
6738 * {@link #setAffiliationIds}
Michal Karpinskib58e4962016-03-01 14:55:10 +00006739 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006740 * @param admin Which device owner this request is associated with.
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01006741 * @return Device logs from before the latest reboot of the system, or {@code null} if this API
6742 * is not supported on the device.
Esteban Talaverad36dd152016-12-15 08:51:45 +00006743 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
6744 * profile or secondary user that is not affiliated with the device owner user.
6745 * @see #retrieveSecurityLogs
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006746 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006747 public @Nullable List<SecurityEvent> retrievePreRebootSecurityLogs(
6748 @NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006749 throwIfParentInstance("retrievePreRebootSecurityLogs");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006750 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00006751 ParceledListSlice<SecurityEvent> list = mService.retrievePreRebootSecurityLogs(admin);
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01006752 if (list != null) {
6753 return list.getList();
6754 } else {
6755 return null;
6756 }
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006757 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006758 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006759 }
6760 }
6761
6762 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006763 * Called by a profile owner of a managed profile to set the color used for customization. This
6764 * color is used as background color of the confirm credentials screen for that user. The
Clara Bayarri8d0bd7fa2016-03-30 14:59:58 +01006765 * default color is teal (#00796B).
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006766 * <p>
6767 * The confirm credentials screen can be created using
Benjamin Franz59720bb2016-01-18 15:26:11 +00006768 * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}.
6769 *
6770 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinski74cd7302016-04-12 15:17:36 +01006771 * @param color The 24bit (0xRRGGBB) representation of the color to be used.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006772 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz59720bb2016-01-18 15:26:11 +00006773 */
6774 public void setOrganizationColor(@NonNull ComponentName admin, int color) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006775 throwIfParentInstance("setOrganizationColor");
Benjamin Franz59720bb2016-01-18 15:26:11 +00006776 try {
Michal Karpinski74cd7302016-04-12 15:17:36 +01006777 // always enforce alpha channel to have 100% opacity
6778 color |= 0xFF000000;
Benjamin Franz59720bb2016-01-18 15:26:11 +00006779 mService.setOrganizationColor(admin, color);
6780 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006781 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00006782 }
6783 }
6784
6785 /**
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00006786 * @hide
6787 *
6788 * Sets the color used for customization.
6789 *
Michal Karpinski74cd7302016-04-12 15:17:36 +01006790 * @param color The 24bit (0xRRGGBB) representation of the color to be used.
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00006791 * @param userId which user to set the color to.
6792 * @RequiresPermission(allOf = {
6793 * Manifest.permission.MANAGE_USERS,
6794 * Manifest.permission.INTERACT_ACROSS_USERS_FULL})
6795 */
6796 public void setOrganizationColorForUser(@ColorInt int color, @UserIdInt int userId) {
6797 try {
Michal Karpinski74cd7302016-04-12 15:17:36 +01006798 // always enforce alpha channel to have 100% opacity
6799 color |= 0xFF000000;
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00006800 mService.setOrganizationColorForUser(color, userId);
6801 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006802 throw re.rethrowFromSystemServer();
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00006803 }
6804 }
6805
6806 /**
Benjamin Franz59720bb2016-01-18 15:26:11 +00006807 * Called by a profile owner of a managed profile to retrieve the color used for customization.
6808 * This color is used as background color of the confirm credentials screen for that user.
6809 *
6810 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinski74cd7302016-04-12 15:17:36 +01006811 * @return The 24bit (0xRRGGBB) representation of the color to be used.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006812 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz59720bb2016-01-18 15:26:11 +00006813 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01006814 public @ColorInt int getOrganizationColor(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006815 throwIfParentInstance("getOrganizationColor");
Benjamin Franz59720bb2016-01-18 15:26:11 +00006816 try {
6817 return mService.getOrganizationColor(admin);
6818 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006819 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00006820 }
6821 }
6822
6823 /**
6824 * @hide
6825 * Retrieve the customization color for a given user.
6826 *
6827 * @param userHandle The user id of the user we're interested in.
Michal Karpinski74cd7302016-04-12 15:17:36 +01006828 * @return The 24bit (0xRRGGBB) representation of the color to be used.
Benjamin Franz59720bb2016-01-18 15:26:11 +00006829 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01006830 public @ColorInt int getOrganizationColorForUser(int userHandle) {
Benjamin Franz59720bb2016-01-18 15:26:11 +00006831 try {
6832 return mService.getOrganizationColorForUser(userHandle);
6833 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006834 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00006835 }
6836 }
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006837
6838 /**
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01006839 * Called by the device owner or profile owner to set the name of the organization under
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006840 * management.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006841 * <p>
6842 * If the organization name needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006843 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
6844 * and set a new version of this string accordingly.
6845 *
6846 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6847 * @param title The organization name or {@code null} to clear a previously set name.
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01006848 * @throws SecurityException if {@code admin} is not a device or profile owner.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006849 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01006850 public void setOrganizationName(@NonNull ComponentName admin, @Nullable CharSequence title) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006851 throwIfParentInstance("setOrganizationName");
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006852 try {
6853 mService.setOrganizationName(admin, title);
6854 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006855 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006856 }
6857 }
6858
6859 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006860 * Called by a profile owner of a managed profile to retrieve the name of the organization under
6861 * management.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006862 *
6863 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6864 * @return The organization name or {@code null} if none is set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006865 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006866 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006867 public @Nullable CharSequence getOrganizationName(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006868 throwIfParentInstance("getOrganizationName");
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006869 try {
6870 return mService.getOrganizationName(admin);
6871 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006872 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006873 }
6874 }
6875
6876 /**
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01006877 * Called by the system to retrieve the name of the organization managing the device.
6878 *
6879 * @return The organization name or {@code null} if none is set.
6880 * @throws SecurityException if the caller is not the device owner, does not hold the
6881 * MANAGE_USERS permission and is not the system.
6882 *
6883 * @hide
6884 */
6885 @SystemApi
6886 @TestApi
6887 public @Nullable CharSequence getDeviceOwnerOrganizationName() {
6888 try {
6889 return mService.getDeviceOwnerOrganizationName();
6890 } catch (RemoteException re) {
6891 throw re.rethrowFromSystemServer();
6892 }
6893 }
6894
6895 /**
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006896 * Retrieve the default title message used in the confirm credentials screen for a given user.
6897 *
6898 * @param userHandle The user id of the user we're interested in.
6899 * @return The organization name or {@code null} if none is set.
6900 *
6901 * @hide
6902 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006903 public @Nullable CharSequence getOrganizationNameForUser(int userHandle) {
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006904 try {
6905 return mService.getOrganizationNameForUser(userHandle);
6906 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006907 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006908 }
6909 }
6910
6911 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00006912 * @return the {@link UserProvisioningState} for the current user - for unmanaged users will
6913 * return {@link #STATE_USER_UNMANAGED}
6914 * @hide
6915 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00006916 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00006917 @UserProvisioningState
6918 public int getUserProvisioningState() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006919 throwIfParentInstance("getUserProvisioningState");
Alan Treadwayafad8782016-01-19 15:15:08 +00006920 if (mService != null) {
6921 try {
6922 return mService.getUserProvisioningState();
6923 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006924 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00006925 }
6926 }
6927 return STATE_USER_UNMANAGED;
6928 }
6929
6930 /**
6931 * Set the {@link UserProvisioningState} for the supplied user, if they are managed.
6932 *
6933 * @param state to store
6934 * @param userHandle for user
6935 * @hide
6936 */
6937 public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) {
6938 if (mService != null) {
6939 try {
6940 mService.setUserProvisioningState(state, userHandle);
6941 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006942 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00006943 }
6944 }
6945 }
6946
6947 /**
Esteban Talaverac9bb3782016-11-11 15:41:14 +00006948 * Indicates the entity that controls the device or profile owner. Two users/profiles are
6949 * affiliated if the set of ids set by their device or profile owners intersect.
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006950 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00006951 * <p><strong>Note:</strong> Features that depend on user affiliation (such as security logging
6952 * or {@link #bindDeviceAdminServiceAsUser}) won't be available when a secondary user or profile
6953 * is created, until it becomes affiliated. Therefore it is recommended that the appropriate
6954 * affiliation ids are set by its profile owner as soon as possible after the user/profile is
6955 * created.
6956 *
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006957 * @param admin Which profile or device owner this request is associated with.
Esteban Talaverac9bb3782016-11-11 15:41:14 +00006958 * @param ids A list of opaque non-empty affiliation ids. Duplicate elements will be ignored.
6959 *
6960 * @throws NullPointerException if {@code ids} is null or contains null elements.
6961 * @throws IllegalArgumentException if {@code ids} contains an empty string.
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006962 */
Esteban Talaverac9bb3782016-11-11 15:41:14 +00006963 public void setAffiliationIds(@NonNull ComponentName admin, @NonNull List<String> ids) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006964 throwIfParentInstance("setAffiliationIds");
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006965 try {
Esteban Talaverac9bb3782016-11-11 15:41:14 +00006966 mService.setAffiliationIds(admin, ids);
6967 } catch (RemoteException e) {
6968 throw e.rethrowFromSystemServer();
6969 }
6970 }
6971
6972 /**
6973 * Returns the list of affiliation ids previously set via {@link #setAffiliationIds}, or an
6974 * empty list if none have been set.
6975 */
6976 public @NonNull List<String> getAffiliationIds(@NonNull ComponentName admin) {
6977 throwIfParentInstance("getAffiliationIds");
6978 try {
6979 return mService.getAffiliationIds(admin);
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006980 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006981 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006982 }
6983 }
6984
6985 /**
6986 * @hide
Esteban Talaverac9bb3782016-11-11 15:41:14 +00006987 * Returns whether this user/profile is affiliated with the device.
6988 * <p>
6989 * By definition, the user that the device owner runs on is always affiliated with the device.
6990 * Any other user/profile is considered affiliated with the device if the set specified by its
6991 * profile owner via {@link #setAffiliationIds} intersects with the device owner's.
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006992 *
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006993 */
6994 public boolean isAffiliatedUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006995 throwIfParentInstance("isAffiliatedUser");
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006996 try {
Esteban Talaverac9bb3782016-11-11 15:41:14 +00006997 return mService.isAffiliatedUser();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006998 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006999 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007000 }
7001 }
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08007002
7003 /**
7004 * @hide
7005 * Returns whether the uninstall for {@code packageName} for the current user is in queue
7006 * to be started
7007 * @param packageName the package to check for
7008 * @return whether the uninstall intent for {@code packageName} is pending
7009 */
7010 public boolean isUninstallInQueue(String packageName) {
7011 try {
7012 return mService.isUninstallInQueue(packageName);
7013 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007014 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08007015 }
7016 }
7017
7018 /**
7019 * @hide
7020 * @param packageName the package containing active DAs to be uninstalled
7021 */
7022 public void uninstallPackageWithActiveAdmins(String packageName) {
7023 try {
7024 mService.uninstallPackageWithActiveAdmins(packageName);
7025 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007026 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08007027 }
7028 }
Benjamin Franzbc33c822016-04-15 08:57:52 +01007029
Kenny Guy38dcca52016-04-19 13:09:18 +01007030 /**
7031 * @hide
7032 * Remove a test admin synchronously without sending it a broadcast about being removed.
7033 * If the admin is a profile owner or device owner it will still be removed.
7034 *
7035 * @param userHandle user id to remove the admin for.
7036 * @param admin The administration compononent to remove.
7037 * @throws SecurityException if the caller is not shell / root or the admin package
7038 * isn't a test application see {@link ApplicationInfo#FLAG_TEST_APP}.
7039 */
7040 public void forceRemoveActiveAdmin(ComponentName adminReceiver, int userHandle) {
7041 try {
7042 mService.forceRemoveActiveAdmin(adminReceiver, userHandle);
7043 } catch (RemoteException re) {
7044 throw re.rethrowFromSystemServer();
7045 }
7046 }
7047
Mahaver Chopra790d1982016-07-07 16:06:49 +01007048 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007049 * Returns whether the device has been provisioned.
7050 *
7051 * <p>Not for use by third-party applications.
7052 *
Mahaver Chopra790d1982016-07-07 16:06:49 +01007053 * @hide
Mahaver Chopra790d1982016-07-07 16:06:49 +01007054 */
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007055 @SystemApi
Mahaver Chopra790d1982016-07-07 16:06:49 +01007056 public boolean isDeviceProvisioned() {
7057 try {
7058 return mService.isDeviceProvisioned();
7059 } catch (RemoteException re) {
7060 throw re.rethrowFromSystemServer();
7061 }
7062 }
7063
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007064 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007065 * Writes that the provisioning configuration has been applied.
7066 *
7067 * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS}
7068 * permission.
7069 *
7070 * <p>Not for use by third-party applications.
7071 *
7072 * @hide
7073 */
7074 @SystemApi
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007075 public void setDeviceProvisioningConfigApplied() {
7076 try {
7077 mService.setDeviceProvisioningConfigApplied();
7078 } catch (RemoteException re) {
7079 throw re.rethrowFromSystemServer();
7080 }
7081 }
7082
7083 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007084 * Returns whether the provisioning configuration has been applied.
7085 *
7086 * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS} permission.
7087 *
7088 * <p>Not for use by third-party applications.
7089 *
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007090 * @return whether the provisioning configuration has been applied.
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007091 *
7092 * @hide
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007093 */
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007094 @SystemApi
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007095 public boolean isDeviceProvisioningConfigApplied() {
7096 try {
7097 return mService.isDeviceProvisioningConfigApplied();
7098 } catch (RemoteException re) {
7099 throw re.rethrowFromSystemServer();
7100 }
7101 }
7102
Victor Chang9bfc65f2016-08-15 12:27:09 +01007103 /**
7104 * @hide
Victor Chang3577ed22016-08-25 18:49:26 +01007105 * Force update user setup completed status. This API has no effect on user build.
7106 * @throws {@link SecurityException} if the caller has no
Esteban Talavera01576862016-12-15 11:16:44 +00007107 * {@code android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS} or the caller is
7108 * not {@link UserHandle#SYSTEM_USER}
Victor Chang9bfc65f2016-08-15 12:27:09 +01007109 */
7110 public void forceUpdateUserSetupComplete() {
7111 try {
7112 mService.forceUpdateUserSetupComplete();
7113 } catch (RemoteException re) {
7114 throw re.rethrowFromSystemServer();
7115 }
7116 }
7117
Benjamin Franzbc33c822016-04-15 08:57:52 +01007118 private void throwIfParentInstance(String functionName) {
7119 if (mParentInstance) {
7120 throw new SecurityException(functionName + " cannot be called on the parent instance");
7121 }
7122 }
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007123
7124 /**
7125 * @hide
7126 * Enable backup service.
7127 * <p>This includes all backup and restore mechanisms.
7128 * Setting this to {@code false} will make backup service no-op or return empty results.
7129 *
7130 * <p>There must be only one user on the device, managed by the device owner.
7131 * Otherwise a {@link SecurityException} will be thrown.
7132 *
7133 * <p>Backup service is off by default when device owner is present.
7134 */
7135 public void setBackupServiceEnabled(@NonNull ComponentName admin, boolean enabled) {
7136 try {
7137 mService.setBackupServiceEnabled(admin, enabled);
7138 } catch (RemoteException re) {
7139 throw re.rethrowFromSystemServer();
7140 }
7141 }
7142
7143 /**
7144 * @hide
7145 * @return {@code true} if backup service is enabled, {@code false} otherwise.
7146 */
7147 public boolean isBackupServiceEnabled(@NonNull ComponentName admin) {
7148 try {
7149 return mService.isBackupServiceEnabled(admin);
7150 } catch (RemoteException re) {
7151 throw re.rethrowFromSystemServer();
7152 }
7153 }
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007154
7155 /**
Esteban Talaverad36dd152016-12-15 08:51:45 +00007156 * Called by a device owner to control the network logging feature.
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007157 *
7158 * <p> Network logs contain DNS lookup and connect() library call events.
7159 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00007160 * <p><strong>Note:</strong> The device owner won't be able to retrieve network logs if there
7161 * are unaffiliated secondary users or profiles on the device, regardless of whether the
7162 * feature is enabled. Logs will be discarded if the internal buffer fills up while waiting for
7163 * all users to become affiliated. Therefore it's recommended that affiliation ids are set for
7164 * new users as soon as possible after provisioning via {@link #setAffiliationIds}.
7165 *
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007166 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7167 * @param enabled whether network logging should be enabled or not.
Esteban Talaverad36dd152016-12-15 08:51:45 +00007168 * @throws SecurityException if {@code admin} is not a device owner.
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007169 * @see #retrieveNetworkLogs
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007170 */
7171 public void setNetworkLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
7172 throwIfParentInstance("setNetworkLoggingEnabled");
7173 try {
7174 mService.setNetworkLoggingEnabled(admin, enabled);
7175 } catch (RemoteException re) {
7176 throw re.rethrowFromSystemServer();
7177 }
7178 }
7179
7180 /**
7181 * Return whether network logging is enabled by a device owner.
7182 *
phweissa4e169e2016-11-24 16:20:57 +01007183 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Can only
7184 * be {@code null} if the caller has MANAGE_USERS permission.
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007185 * @return {@code true} if network logging is enabled by device owner, {@code false} otherwise.
Esteban Talaverad36dd152016-12-15 08:51:45 +00007186 * @throws SecurityException if {@code admin} is not a device owner and caller has
phweissa4e169e2016-11-24 16:20:57 +01007187 * no MANAGE_USERS permission
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007188 */
phweissa4e169e2016-11-24 16:20:57 +01007189 public boolean isNetworkLoggingEnabled(@Nullable ComponentName admin) {
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007190 throwIfParentInstance("isNetworkLoggingEnabled");
7191 try {
7192 return mService.isNetworkLoggingEnabled(admin);
7193 } catch (RemoteException re) {
7194 throw re.rethrowFromSystemServer();
7195 }
7196 }
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007197
7198 /**
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007199 * Called by device owner to retrieve the most recent batch of network logging events.
7200 * A device owner has to provide a batchToken provided as part of
7201 * {@link DeviceAdminReceiver#onNetworkLogsAvailable} callback. If the token doesn't match the
7202 * token of the most recent available batch of logs, {@code null} will be returned.
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007203 *
7204 * <p> {@link NetworkEvent} can be one of {@link DnsEvent} or {@link ConnectEvent}.
7205 *
7206 * <p> The list of network events is sorted chronologically, and contains at most 1200 events.
7207 *
7208 * <p> Access to the logs is rate limited and this method will only return a new batch of logs
7209 * after the device device owner has been notified via
7210 * {@link DeviceAdminReceiver#onNetworkLogsAvailable}.
7211 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00007212 * <p>If a secondary user or profile is created, calling this method will throw a
7213 * {@link SecurityException} until all users become affiliated again. It will also no longer be
7214 * possible to retrieve the network logs batch with the most recent batchToken provided
7215 * by {@link DeviceAdminReceiver#onNetworkLogsAvailable}. See
7216 * {@link DevicePolicyManager#setAffiliationIds}.
7217 *
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007218 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007219 * @param batchToken A token of the batch to retrieve
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007220 * @return A new batch of network logs which is a list of {@link NetworkEvent}. Returns
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007221 * {@code null} if the batch represented by batchToken is no longer available or if
7222 * logging is disabled.
Esteban Talaverad36dd152016-12-15 08:51:45 +00007223 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
7224 * profile or secondary user that is not affiliated with the device owner user.
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007225 * @see DeviceAdminReceiver#onNetworkLogsAvailable
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007226 */
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007227 public @Nullable List<NetworkEvent> retrieveNetworkLogs(@NonNull ComponentName admin,
7228 long batchToken) {
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007229 throwIfParentInstance("retrieveNetworkLogs");
7230 try {
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007231 return mService.retrieveNetworkLogs(admin, batchToken);
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007232 } catch (RemoteException re) {
7233 throw re.rethrowFromSystemServer();
7234 }
7235 }
Tony Mak46aabe52016-11-14 12:53:06 +00007236
7237 /**
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007238 * Called by a device owner to bind to a service from a profile owner of a managed profile or
7239 * vice versa. See {@link #getBindDeviceAdminTargetUsers} for a definition of which
7240 * device/profile owners are allowed to bind to services of another profile/device owner.
7241 * <p>
Tony Mak46aabe52016-11-14 12:53:06 +00007242 * The service must be unexported. Note that the {@link Context} used to obtain this
7243 * {@link DevicePolicyManager} instance via {@link Context#getSystemService(Class)} will be used
7244 * to bind to the {@link android.app.Service}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007245 *
Tony Mak46aabe52016-11-14 12:53:06 +00007246 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7247 * @param serviceIntent Identifies the service to connect to. The Intent must specify either an
7248 * explicit component name or a package name to match an
7249 * {@link IntentFilter} published by a service.
Tony Makbf9928d2016-12-22 11:02:45 +00007250 * @param conn Receives information as the service is started and stopped in main thread. This
7251 * must be a valid {@link ServiceConnection} object; it must not be {@code null}.
Tony Mak46aabe52016-11-14 12:53:06 +00007252 * @param flags Operation options for the binding operation. See
7253 * {@link Context#bindService(Intent, ServiceConnection, int)}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007254 * @param targetUser Which user to bind to. Must be one of the users returned by
7255 * {@link #getBindDeviceAdminTargetUsers}, otherwise a {@link SecurityException} will
7256 * be thrown.
Tony Mak46aabe52016-11-14 12:53:06 +00007257 * @return If you have successfully bound to the service, {@code true} is returned;
7258 * {@code false} is returned if the connection is not made and you will not
7259 * receive the service object.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007260 *
Tony Mak46aabe52016-11-14 12:53:06 +00007261 * @see Context#bindService(Intent, ServiceConnection, int)
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007262 * @see #getBindDeviceAdminTargetUsers(ComponentName)
Tony Mak46aabe52016-11-14 12:53:06 +00007263 */
7264 public boolean bindDeviceAdminServiceAsUser(
7265 @NonNull ComponentName admin, Intent serviceIntent, @NonNull ServiceConnection conn,
7266 @Context.BindServiceFlags int flags, @NonNull UserHandle targetUser) {
7267 throwIfParentInstance("bindDeviceAdminServiceAsUser");
7268 // Keep this in sync with ContextImpl.bindServiceCommon.
7269 try {
Tony Makbf9928d2016-12-22 11:02:45 +00007270 final IServiceConnection sd = mContext.getServiceDispatcher(
7271 conn, mContext.getMainThreadHandler(), flags);
Tony Mak46aabe52016-11-14 12:53:06 +00007272 serviceIntent.prepareToLeaveProcess(mContext);
7273 return mService.bindDeviceAdminServiceAsUser(admin,
7274 mContext.getIApplicationThread(), mContext.getActivityToken(), serviceIntent,
7275 sd, flags, targetUser.getIdentifier());
7276 } catch (RemoteException re) {
7277 throw re.rethrowFromSystemServer();
7278 }
7279 }
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007280
7281 /**
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007282 * Returns the list of target users that the calling device or profile owner can use when
7283 * calling {@link #bindDeviceAdminServiceAsUser}.
7284 * <p>
7285 * A device owner can bind to a service from a profile owner of a managed profile and
7286 * vice versa, provided that:
7287 * <ul>
7288 * <li>Both belong to the same package name.
7289 * <li>The managed profile is a profile of the user where the device owner is set.
7290 * See {@link UserManager#getUserProfiles()}
7291 * <li>Both users are affiliated.
Nicolas Prevotd5b03602016-12-06 13:32:22 +00007292 * See {@link #setAffiliationIds}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007293 * </ul>
7294 */
7295 public @NonNull List<UserHandle> getBindDeviceAdminTargetUsers(@NonNull ComponentName admin) {
7296 throwIfParentInstance("getBindDeviceAdminTargetUsers");
7297 try {
7298 return mService.getBindDeviceAdminTargetUsers(admin);
7299 } catch (RemoteException re) {
7300 throw re.rethrowFromSystemServer();
7301 }
7302 }
7303
7304 /**
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007305 * Called by the system to get the time at which the device owner last retrieved security
7306 * logging entries.
7307 *
7308 * @return the time at which the device owner most recently retrieved security logging entries,
7309 * in milliseconds since epoch; -1 if security logging entries were never retrieved.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007310 * @throws SecurityException if the caller is not the device owner, does not hold the
7311 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007312 *
7313 * @hide
7314 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007315 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007316 public long getLastSecurityLogRetrievalTime() {
7317 try {
7318 return mService.getLastSecurityLogRetrievalTime();
7319 } catch (RemoteException re) {
7320 throw re.rethrowFromSystemServer();
7321 }
7322 }
7323
7324 /**
7325 * Called by the system to get the time at which the device owner last requested a bug report.
7326 *
7327 * @return the time at which the device owner most recently requested a bug report, in
7328 * milliseconds since epoch; -1 if a bug report was never requested.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007329 * @throws SecurityException if the caller is not the device owner, does not hold the
7330 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007331 *
7332 * @hide
7333 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007334 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007335 public long getLastBugReportRequestTime() {
7336 try {
7337 return mService.getLastBugReportRequestTime();
7338 } catch (RemoteException re) {
7339 throw re.rethrowFromSystemServer();
7340 }
7341 }
7342
7343 /**
7344 * Called by the system to get the time at which the device owner last retrieved network logging
7345 * events.
7346 *
7347 * @return the time at which the device owner most recently retrieved network logging events, in
7348 * milliseconds since epoch; -1 if network logging events were never retrieved.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007349 * @throws SecurityException if the caller is not the device owner, does not hold the
7350 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007351 *
7352 * @hide
7353 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007354 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007355 public long getLastNetworkLogRetrievalTime() {
7356 try {
7357 return mService.getLastNetworkLogRetrievalTime();
7358 } catch (RemoteException re) {
7359 throw re.rethrowFromSystemServer();
7360 }
7361 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08007362}