blob: 51deb87e1779b15faf822ee61751ca095e95a069 [file] [log] [blame]
Dianne Hackbornd6847842010-01-12 18:14:19 -08001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Dianne Hackborn87bba1e2010-02-26 17:25:54 -080017package android.app.admin;
Dianne Hackbornd6847842010-01-12 18:14:19 -080018
Nicolas Prevot8f7698a2016-02-11 16:05:33 +000019import android.annotation.ColorInt;
Alan Treadwayafad8782016-01-19 15:15:08 +000020import android.annotation.IntDef;
Robin Lee25e26452015-06-02 09:56:29 -070021import android.annotation.NonNull;
22import android.annotation.Nullable;
Dianne Hackbornd6847842010-01-12 18:14:19 -080023import android.annotation.SdkConstant;
24import android.annotation.SdkConstant.SdkConstantType;
Justin Moreyb5deda72014-07-24 10:53:40 -050025import android.annotation.SystemApi;
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +010026import android.annotation.TestApi;
Nicolas Prevot8f7698a2016-02-11 16:05:33 +000027import android.annotation.UserIdInt;
Fyodor Kupolov4e9af062016-07-18 16:59:11 -070028import android.annotation.WorkerThread;
Jason Monkd7b86212014-06-16 13:15:38 -040029import android.app.Activity;
Tony Mak46aabe52016-11-14 12:53:06 +000030import android.app.IServiceConnection;
Rubin Xuaab7a412016-12-30 21:13:29 +000031import android.app.KeyguardManager;
Michal Karpinski6235a942016-03-15 12:07:23 +000032import android.app.admin.SecurityLog.SecurityEvent;
Dianne Hackbornd6847842010-01-12 18:14:19 -080033import android.content.ComponentName;
34import android.content.Context;
Adam Connors010cfd42014-04-16 12:48:13 +010035import android.content.Intent;
Sander Alewijnsef475ca32014-02-17 15:13:58 +000036import android.content.IntentFilter;
Tony Mak46aabe52016-11-14 12:53:06 +000037import android.content.ServiceConnection;
Victor Chang98607132017-01-27 11:51:56 +000038import android.content.pm.ApplicationInfo;
Dianne Hackbornd6847842010-01-12 18:14:19 -080039import android.content.pm.PackageManager;
Victor Changcd14c0a2016-03-16 19:10:15 +000040import android.content.pm.PackageManager.NameNotFoundException;
Rubin Xuc3cd05f2016-01-11 12:11:35 +000041import android.content.pm.ParceledListSlice;
Sudheer Shanka978fc0d2016-01-28 13:51:10 +000042import android.content.pm.UserInfo;
Julia Reynoldsfca04ca2015-02-17 13:39:12 -050043import android.graphics.Bitmap;
Jason Monk03bc9912014-05-13 09:44:57 -040044import android.net.ProxyInfo;
Nicolas Prevot8b7991c2015-11-12 17:40:12 +000045import android.net.Uri;
Robin Lee66e5d962014-04-09 16:44:21 +010046import android.os.Bundle;
Victor Changc10f6692016-12-09 15:24:00 +000047import android.os.Parcelable;
Jim Millere303bf42014-08-26 17:12:29 -070048import android.os.PersistableBundle;
Adam Connors776c5552014-01-09 10:42:56 +000049import android.os.Process;
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080050import android.os.RemoteCallback;
Dianne Hackbornd6847842010-01-12 18:14:19 -080051import android.os.RemoteException;
Amith Yamasani599dd7c2012-09-14 23:20:08 -070052import android.os.UserHandle;
Julia Reynolds1e958392014-05-16 14:25:21 -040053import android.os.UserManager;
Ricky Wai494b95d2015-11-20 16:07:15 +000054import android.provider.ContactsContract.Directory;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000055import android.provider.Settings;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010056import android.security.Credentials;
Amith Yamasanid1d7c022014-08-19 17:03:41 -070057import android.service.restrictions.RestrictionsReceiver;
Mahaver Chopra1216ae52016-03-11 15:39:48 +000058import android.telephony.TelephonyManager;
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 =
Rubin Xu7226c7d2017-02-06 17:18:50 +0000381 "com.android.server.action.REMOTE_BUGREPORT_SHARING_ACCEPTED";
Michal Karpinskiba244092016-02-25 17:28:24 +0000382
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 =
Rubin Xu7226c7d2017-02-06 17:18:50 +0000389 "com.android.server.action.REMOTE_BUGREPORT_SHARING_DECLINED";
Michal Karpinskiba244092016-02-25 17:28:24 +0000390
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 /**
Mahaver761ce772017-03-13 16:40:45 +0000538 * @deprecated From {@link android.os.Build.VERSION_CODES#O}, never used while provisioning the
539 * device.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100540 */
Mahaver761ce772017-03-13 16:40:45 +0000541 @Deprecated
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100542 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
543 = "android.app.extra.PROVISIONING_EMAIL_ADDRESS";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100544
545 /**
Nicolas Prevotcd2d8592015-11-23 13:27:21 +0000546 * A integer extra indicating the predominant color to show during the provisioning.
547 * Refer to {@link android.graphics.Color} for how the color is represented.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000548 *
549 * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or
550 * {@link #ACTION_PROVISION_MANAGED_DEVICE}.
551 */
552 public static final String EXTRA_PROVISIONING_MAIN_COLOR =
553 "android.app.extra.PROVISIONING_MAIN_COLOR";
554
555 /**
Sander Alewijnse8c411562014-11-12 18:03:11 +0000556 * A Boolean extra that can be used by the mobile device management application to skip the
Robin Lee25e26452015-06-02 09:56:29 -0700557 * disabling of system apps during provisioning when set to {@code true}.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000558 *
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100559 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
560 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000561 */
Sander Alewijnse5a144252014-11-18 13:25:04 +0000562 public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED =
563 "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED";
Sander Alewijnse8c411562014-11-12 18:03:11 +0000564
565 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100566 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
567 * will be set to.
568 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000569 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
570 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100571 */
572 public static final String EXTRA_PROVISIONING_TIME_ZONE
Esteban Talavera37f01842014-09-05 10:50:57 +0100573 = "android.app.extra.PROVISIONING_TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100574
575 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100576 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
577 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100578 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000579 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
580 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100581 */
582 public static final String EXTRA_PROVISIONING_LOCAL_TIME
Esteban Talavera37f01842014-09-05 10:50:57 +0100583 = "android.app.extra.PROVISIONING_LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100584
585 /**
586 * A String extra holding the {@link java.util.Locale} that the device will be set to.
587 * Format: xx_yy, where xx is the language code, and yy the country code.
588 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000589 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
590 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100591 */
592 public static final String EXTRA_PROVISIONING_LOCALE
Esteban Talavera37f01842014-09-05 10:50:57 +0100593 = "android.app.extra.PROVISIONING_LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100594
595 /**
596 * A String extra holding the ssid of the wifi network that should be used during nfc device
597 * owner provisioning for downloading the mobile device management application.
598 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000599 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
600 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100601 */
602 public static final String EXTRA_PROVISIONING_WIFI_SSID
Esteban Talavera37f01842014-09-05 10:50:57 +0100603 = "android.app.extra.PROVISIONING_WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100604
605 /**
606 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
607 * is hidden or not.
608 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000609 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
610 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100611 */
612 public static final String EXTRA_PROVISIONING_WIFI_HIDDEN
Esteban Talavera37f01842014-09-05 10:50:57 +0100613 = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100614
615 /**
616 * A String extra indicating the security type of the wifi network in
Mahaver Chopra76b08a92015-10-08 17:58:45 +0100617 * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or
618 * {@code WEP}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100619 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000620 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
621 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100622 */
623 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
Esteban Talavera37f01842014-09-05 10:50:57 +0100624 = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100625
626 /**
627 * A String extra holding the password of the wifi network in
628 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
629 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000630 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
631 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100632 */
633 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talavera37f01842014-09-05 10:50:57 +0100634 = "android.app.extra.PROVISIONING_WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100635
636 /**
637 * A String extra holding the proxy host for the wifi network in
638 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
639 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000640 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
641 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100642 */
643 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
Esteban Talavera37f01842014-09-05 10:50:57 +0100644 = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100645
646 /**
647 * An int extra holding the proxy port for the wifi network in
648 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
649 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000650 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
651 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100652 */
653 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
Esteban Talavera37f01842014-09-05 10:50:57 +0100654 = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100655
656 /**
657 * A String extra holding the proxy bypass for the wifi network in
658 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
659 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000660 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
661 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100662 */
663 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
Esteban Talavera37f01842014-09-05 10:50:57 +0100664 = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100665
666 /**
667 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
668 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
669 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000670 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
671 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100672 */
673 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
Esteban Talavera37f01842014-09-05 10:50:57 +0100674 = "android.app.extra.PROVISIONING_WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100675
676 /**
677 * A String extra holding a url that specifies the download location of the device admin
678 * package. When not provided it is assumed that the device admin package is already installed.
679 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000680 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
681 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100682 */
683 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talavera37f01842014-09-05 10:50:57 +0100684 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100685
686 /**
Victor Chang38cfd9c2017-01-04 17:41:11 +0000687 * A String extra holding the localized name of the organization under management.
688 *
689 * The name is displayed only during provisioning.
690 *
691 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE}
692 *
693 * @hide
694 */
695 @SystemApi
696 public static final String EXTRA_PROVISIONING_ORGANIZATION_NAME =
697 "android.app.extra.PROVISIONING_ORGANIZATION_NAME";
698
699 /**
Alejandro Fernándezbfd61932017-04-04 19:33:01 +0100700 * A String extra holding a url to the website of the device provider so the user can open it
701 * during provisioning. If the url is not HTTPS, an error will be shown.
Victor Chang38cfd9c2017-01-04 17:41:11 +0000702 *
703 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE}
704 *
705 * @hide
706 */
707 @SystemApi
708 public static final String EXTRA_PROVISIONING_SUPPORT_URL =
709 "android.app.extra.PROVISIONING_SUPPORT_URL";
710
711 /**
712 * A String extra holding the localized name of the device admin package. It should be the same
713 * as the app label of the package.
714 *
715 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE}
716 *
717 * @hide
718 */
719 @SystemApi
720 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL =
721 "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL";
722
723 /**
724 * A {@link Uri} extra pointing to the app icon of device admin package. This image will be
725 * shown during the provisioning.
726 * <h5>The following URI schemes are accepted:</h5>
727 * <ul>
728 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
729 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
730 * </ul>
731 *
732 * <p> It is the responsibility of the caller to provide an image with a reasonable
733 * pixel density for the device.
734 *
735 * <p> If a content: URI is passed, the intent should have the flag
736 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
737 * {@link android.content.ClipData} of the intent too.
738 *
739 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE}
740 *
741 * @hide
742 */
743 @SystemApi
744 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI =
745 "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI";
746
747 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400748 * An int extra holding a minimum required version code for the device admin package. If the
749 * device admin is already installed on the device, it will only be re-downloaded from
750 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the
751 * installed package is less than this version code.
752 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400753 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400754 * provisioning via an NFC bump.
755 */
756 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE
757 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE";
758
759 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100760 * A String extra holding a http cookie header which should be used in the http request to the
761 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
762 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000763 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
764 * provisioning via an NFC bump.
Sander Alewijnse681bce92014-07-24 16:46:26 +0100765 */
766 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talavera37f01842014-09-05 10:50:57 +0100767 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100768
769 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100770 * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of
771 * the file at download location specified in
772 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100773 *
Benjamin Franzea956242016-03-21 15:45:56 +0000774 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} must be
775 * present. The provided checksum must match the checksum of the file at the download
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100776 * location. If the checksum doesn't match an error will be shown to the user and the user will
777 * be asked to factory reset the device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100778 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000779 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
780 * provisioning via an NFC bump.
Rubin Xud92e7572015-05-18 17:01:13 +0100781 *
782 * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP}
783 * and {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1} only SHA-1 hash is supported.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700784 * Starting from {@link android.os.Build.VERSION_CODES#M}, this parameter accepts SHA-256 in
Rubin Xud92e7572015-05-18 17:01:13 +0100785 * addition to SHA-1. Support for SHA-1 is likely to be removed in future OS releases.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100786 */
787 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100788 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100789
790 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100791 * A String extra holding the URL-safe base64 encoded SHA-256 checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100792 * android package archive at the download location specified in {@link
793 * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
794 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100795 * <p>The signatures of an android package archive can be obtained using
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100796 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
797 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
798 *
Benjamin Franzea956242016-03-21 15:45:56 +0000799 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} must be
800 * present. The provided checksum must match the checksum of any signature of the file at
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100801 * the download location. If the checksum does not match an error will be shown to the user and
802 * the user will be asked to factory reset the device.
803 *
804 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
805 * provisioning via an NFC bump.
806 */
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100807 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM
808 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM";
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100809
810 /**
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000811 * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile
812 * has completed successfully.
813 *
814 * <p>The broadcast is limited to the primary profile, to the app specified in the provisioning
Nicolas Prevotebe2d992015-05-12 18:14:53 -0700815 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000816 *
Mahaver7074caf2016-11-29 20:52:18 +0000817 * <p>This intent will contain the following extras
818 * <ul>
819 * <li>{@link Intent#EXTRA_USER}, corresponds to the {@link UserHandle} of the managed
820 * profile.</li>
821 * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, corresponds to the account requested to
822 * be migrated at provisioning time, if any.</li>
823 * </ul>
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000824 */
825 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
826 public static final String ACTION_MANAGED_PROFILE_PROVISIONED
827 = "android.app.action.MANAGED_PROFILE_PROVISIONED";
828
829 /**
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000830 * Activity action: This activity action is sent to indicate that provisioning of a managed
831 * profile or managed device has completed successfully. It'll be sent at the same time as
832 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast but this will be
833 * delivered faster as it's an activity intent.
834 *
835 * <p>The intent is only sent to the application on the profile that requested provisioning. In
836 * the device owner case the profile is the primary user.
837 *
838 * @see #ACTION_PROVISION_MANAGED_PROFILE
839 * @see #ACTION_PROVISION_MANAGED_DEVICE
840 */
841 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
842 public static final String ACTION_PROVISIONING_SUCCESSFUL =
843 "android.app.action.PROVISIONING_SUCCESSFUL";
844
845 /**
Benjamin Franzea956242016-03-21 15:45:56 +0000846 * A boolean extra indicating whether device encryption can be skipped as part of device owner
847 * or managed profile provisioning.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500848 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400849 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100850 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Benjamin Franzea956242016-03-21 15:45:56 +0000851 *
852 * <p>From {@link android.os.Build.VERSION_CODES#N} onwards, this is also supported for an
853 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500854 */
855 public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION =
856 "android.app.extra.PROVISIONING_SKIP_ENCRYPTION";
857
858 /**
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000859 * A {@link Uri} extra pointing to a logo image. This image will be shown during the
860 * provisioning. If this extra is not passed, a default image will be shown.
861 * <h5>The following URI schemes are accepted:</h5>
862 * <ul>
863 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
864 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
865 * </ul>
866 *
Victor Changc10f6692016-12-09 15:24:00 +0000867 * <p> It is the responsibility of the caller to provide an image with a reasonable
Victor Chang38cfd9c2017-01-04 17:41:11 +0000868 * pixel density for the device.
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000869 *
870 * <p> If a content: URI is passed, the intent should have the flag
871 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
872 * {@link android.content.ClipData} of the intent too.
873 *
874 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or
875 * {@link #ACTION_PROVISION_MANAGED_DEVICE}
876 */
877 public static final String EXTRA_PROVISIONING_LOGO_URI =
878 "android.app.extra.PROVISIONING_LOGO_URI";
879
880 /**
Victor Changc10f6692016-12-09 15:24:00 +0000881 * A {@link Bundle}[] extra consisting of list of disclaimer headers and disclaimer contents.
882 * Each {@link Bundle} must have both {@link #EXTRA_PROVISIONING_DISCLAIMER_HEADER}
883 * as disclaimer header, and {@link #EXTRA_PROVISIONING_DISCLAIMER_CONTENT} as disclaimer
884 * content.
885 *
886 * <p> The extra typically contains one disclaimer from the company of mobile device
887 * management application (MDM), and one disclaimer from the organization.
888 *
889 * <p> Call {@link Bundle#putParcelableArray(String, Parcelable[])} to put the {@link Bundle}[]
890 *
891 * <p> Maximum 3 key-value pairs can be specified. The rest will be ignored.
892 *
893 * <p> Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or
894 * {@link #ACTION_PROVISION_MANAGED_DEVICE}
895 */
896 public static final String EXTRA_PROVISIONING_DISCLAIMERS =
897 "android.app.extra.PROVISIONING_DISCLAIMERS";
898
899 /**
900 * A String extra of localized disclaimer header.
901 *
902 * <p> The extra is typically the company name of mobile device management application (MDM)
903 * or the organization name.
904 *
905 * <p> Use in Bundle {@link #EXTRA_PROVISIONING_DISCLAIMERS}
Victor Chang98607132017-01-27 11:51:56 +0000906 *
907 * <p> System app, i.e. application with {@link ApplicationInfo#FLAG_SYSTEM}, can also insert a
908 * disclaimer by declaring an application-level meta-data in {@code AndroidManifest.xml}.
909 * Must use it with {@link #EXTRA_PROVISIONING_DISCLAIMER_CONTENT}. Here is the example:
910 *
911 * <pre>
912 * &lt;meta-data
913 * android:name="android.app.extra.PROVISIONING_DISCLAIMER_HEADER"
914 * android:resource="@string/disclaimer_header"
915 * /&gt;</pre>
Victor Changc10f6692016-12-09 15:24:00 +0000916 */
917 public static final String EXTRA_PROVISIONING_DISCLAIMER_HEADER =
918 "android.app.extra.PROVISIONING_DISCLAIMER_HEADER";
919
920 /**
921 * A {@link Uri} extra pointing to disclaimer content.
922 *
923 * <h5>The following URI schemes are accepted:</h5>
924 * <ul>
925 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
926 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
927 * </ul>
928 *
929 * <p> Styled text is supported in the disclaimer content. The content is parsed by
930 * {@link android.text.Html#fromHtml(String)} and displayed in a
931 * {@link android.widget.TextView}.
932 *
933 * <p> If a <code>content:</code> URI is passed, URI is passed, the intent should have the flag
934 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
935 * {@link android.content.ClipData} of the intent too.
936 *
937 * <p> Use in Bundle {@link #EXTRA_PROVISIONING_DISCLAIMERS}
Victor Chang98607132017-01-27 11:51:56 +0000938 *
939 * <p> System app, i.e. application with {@link ApplicationInfo#FLAG_SYSTEM}, can also insert a
940 * disclaimer by declaring an application-level meta-data in {@code AndroidManifest.xml}.
941 * Must use it with {@link #EXTRA_PROVISIONING_DISCLAIMER_HEADER}. Here is the example:
942 *
943 * <pre>
944 * &lt;meta-data
945 * android:name="android.app.extra.PROVISIONING_DISCLAIMER_CONTENT"
946 * android:resource="@string/disclaimer_content"
947 * /&gt;</pre>
Victor Changc10f6692016-12-09 15:24:00 +0000948 */
949 public static final String EXTRA_PROVISIONING_DISCLAIMER_CONTENT =
950 "android.app.extra.PROVISIONING_DISCLAIMER_CONTENT";
951
952 /**
Alan Treadway94de8c82016-01-11 10:25:23 +0000953 * A boolean extra indicating if user setup should be skipped, for when provisioning is started
954 * during setup-wizard.
955 *
956 * <p>If unspecified, defaults to {@code true} to match the behavior in
957 * {@link android.os.Build.VERSION_CODES#M} and earlier.
958 *
Alan Treadway1a538d02016-01-18 16:42:30 +0000959 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or
960 * {@link #ACTION_PROVISION_MANAGED_USER}.
Alan Treadway94de8c82016-01-11 10:25:23 +0000961 *
962 * @hide
963 */
964 public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP =
965 "android.app.extra.PROVISIONING_SKIP_USER_SETUP";
966
967 /**
Victor Chang51d84f92016-11-16 12:22:56 +0000968 * A boolean extra indicating if the user consent steps from the provisioning flow should be
969 * skipped. If unspecified, defaults to {@code false}.
970 *
971 * It can only be used by an existing device owner trying to create a managed profile via
972 * {@link #ACTION_PROVISION_MANAGED_PROFILE}. Otherwise it is ignored.
973 */
974 public static final String EXTRA_PROVISIONING_SKIP_USER_CONSENT =
975 "android.app.extra.PROVISIONING_SKIP_USER_CONSENT";
976
977 /**
Benjamin Franzea956242016-03-21 15:45:56 +0000978 * This MIME type is used for starting the device owner provisioning.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100979 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400980 * <p>During device owner provisioning a device admin app is set as the owner of the device.
981 * A device owner has full control over the device. The device owner can not be modified by the
982 * user and the only way of resetting the device is if the device owner app calls a factory
983 * reset.
984 *
985 * <p> A typical use case would be a device that is owned by a company, but used by either an
986 * employee or client.
987 *
Benjamin Franzea956242016-03-21 15:45:56 +0000988 * <p> The NFC message must be sent to an unprovisioned device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100989 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000990 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100991 * contains the following properties:
992 * <ul>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400993 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
994 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100995 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400996 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100997 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
998 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
999 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
1000 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
1001 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
1002 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
1003 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
1004 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
1005 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
1006 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Rubin Xu41f2ccb92015-08-05 16:29:13 +01001007 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
1008 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from
1009 * {@link android.os.Build.VERSION_CODES#M} </li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +01001010 *
Nicolas Prevot18440252015-03-09 14:07:17 +00001011 * <p>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07001012 * As of {@link android.os.Build.VERSION_CODES#M}, the properties should contain
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -04001013 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of
1014 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only
1015 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -04001016 */
1017 public static final String MIME_TYPE_PROVISIONING_NFC
1018 = "application/com.android.managedprovisioning";
1019
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +01001020 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001021 * Activity action: ask the user to add a new device administrator to the system.
1022 * The desired policy is the ComponentName of the policy in the
1023 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
1024 * bring the user through adding the device administrator to the system (or
1025 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001026 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001027 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
1028 * field to provide the user with additional explanation (in addition
1029 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001030 *
1031 * <p>If your administrator is already active, this will ordinarily return immediately (without
1032 * user intervention). However, if your administrator has been updated and is requesting
1033 * additional uses-policy flags, the user will be presented with the new list. New policies
1034 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001035 */
1036 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1037 public static final String ACTION_ADD_DEVICE_ADMIN
1038 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001039
Dianne Hackbornd6847842010-01-12 18:14:19 -08001040 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001041 * @hide
1042 * Activity action: ask the user to add a new device administrator as the profile owner
Amith Yamasani814e9872015-03-23 14:04:53 -07001043 * for this user. Only system apps can launch this intent.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001044 *
Amith Yamasani814e9872015-03-23 14:04:53 -07001045 * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN}
1046 * extra field. This will invoke a UI to bring the user through adding the profile owner admin
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001047 * to remotely control restrictions on the user.
1048 *
Makoto Onukic8a5a552015-11-19 14:29:12 -08001049 * <p>The intent must be invoked via {@link Activity#startActivityForResult} to receive the
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001050 * result of whether or not the user approved the action. If approved, the result will
1051 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
1052 * as a profile owner.
1053 *
1054 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
1055 * field to provide the user with additional explanation (in addition
1056 * to your component's description) about what is being added.
1057 *
Amith Yamasani814e9872015-03-23 14:04:53 -07001058 * <p>If there is already a profile owner active or the caller is not a system app, the
1059 * operation will return a failure result.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001060 */
1061 @SystemApi
1062 public static final String ACTION_SET_PROFILE_OWNER
1063 = "android.app.action.SET_PROFILE_OWNER";
1064
1065 /**
1066 * @hide
1067 * Name of the profile owner admin that controls the user.
1068 */
1069 @SystemApi
1070 public static final String EXTRA_PROFILE_OWNER_NAME
1071 = "android.app.extra.PROFILE_OWNER_NAME";
1072
1073 /**
Nicolas Prevot00799002015-07-27 18:15:20 +01001074 * Broadcast action: send when any policy admin changes a policy.
Jim Miller284b62e2010-06-08 14:27:42 -07001075 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -07001076 *
Jim Miller284b62e2010-06-08 14:27:42 -07001077 * @hide
1078 */
1079 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
1080 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
1081
1082 /**
Tony Mak1970f972016-08-30 17:41:48 +01001083 * Broadcast action: sent when the device owner is set, changed or cleared.
Nicolas Prevot00799002015-07-27 18:15:20 +01001084 *
1085 * This broadcast is sent only to the primary user.
1086 * @see #ACTION_PROVISION_MANAGED_DEVICE
1087 */
1088 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1089 public static final String ACTION_DEVICE_OWNER_CHANGED
1090 = "android.app.action.DEVICE_OWNER_CHANGED";
1091
1092 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001093 * The ComponentName of the administrator component.
1094 *
1095 * @see #ACTION_ADD_DEVICE_ADMIN
1096 */
1097 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001098
Dianne Hackbornd6847842010-01-12 18:14:19 -08001099 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001100 * An optional CharSequence providing additional explanation for why the
1101 * admin is being added.
1102 *
1103 * @see #ACTION_ADD_DEVICE_ADMIN
1104 */
1105 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001106
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001107 /**
phweiss73145f42017-01-17 19:06:38 +01001108 * Constant to indicate the feature of disabling the camera. Used as argument to
1109 * {@link #createAdminSupportIntent(String)}.
1110 * @see #setCameraDisabled(ComponentName, boolean)
1111 */
1112 public static final String POLICY_DISABLE_CAMERA = "policy_disable_camera";
1113
1114 /**
1115 * Constant to indicate the feature of disabling screen captures. Used as argument to
1116 * {@link #createAdminSupportIntent(String)}.
1117 * @see #setScreenCaptureDisabled(ComponentName, boolean)
1118 */
1119 public static final String POLICY_DISABLE_SCREEN_CAPTURE = "policy_disable_screen_capture";
1120
1121 /**
1122 * A String indicating a specific restricted feature. Can be a user restriction from the
1123 * {@link UserManager}, e.g. {@link UserManager#DISALLOW_ADJUST_VOLUME}, or one of the values
1124 * {@link #POLICY_DISABLE_CAMERA} or {@link #POLICY_DISABLE_SCREEN_CAPTURE}.
1125 * @see #createAdminSupportIntent(String)
1126 * @hide
1127 */
1128 @TestApi
1129 public static final String EXTRA_RESTRICTION = "android.app.extra.RESTRICTION";
1130
1131 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001132 * Activity action: have the user enter a new password. This activity should
1133 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
1134 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
1135 * enter a new password that meets the current requirements. You can use
1136 * {@link #isActivePasswordSufficient()} to determine whether you need to
1137 * have the user select a new password in order to meet the current
1138 * constraints. Upon being resumed from this activity, you can check the new
1139 * password characteristics to see if they are sufficient.
Benjamin Franzc9921092016-01-08 17:17:44 +00001140 *
1141 * If the intent is launched from within a managed profile with a profile
1142 * owner built against {@link android.os.Build.VERSION_CODES#M} or before,
1143 * this will trigger entering a new password for the parent of the profile.
1144 * For all other cases it will trigger entering a new password for the user
1145 * or profile it is launched from.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001146 *
1147 * @see #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
Dianne Hackbornd6847842010-01-12 18:14:19 -08001148 */
1149 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1150 public static final String ACTION_SET_NEW_PASSWORD
1151 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001152
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001153 /**
Benjamin Franzc9921092016-01-08 17:17:44 +00001154 * Activity action: have the user enter a new password for the parent profile.
1155 * If the intent is launched from within a managed profile, this will trigger
1156 * entering a new password for the parent of the profile. In all other cases
1157 * the behaviour is identical to {@link #ACTION_SET_NEW_PASSWORD}.
1158 */
1159 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1160 public static final String ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
1161 = "android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD";
1162
1163 /**
phweissa0cb2512016-12-14 21:37:48 +01001164 * Broadcast action: Tell the status bar to open the device monitoring dialog, e.g. when
1165 * Network logging was enabled and the user tapped the notification.
1166 * <p class="note">This is a protected intent that can only be sent by the system.</p>
1167 * @hide
1168 */
1169 public static final String ACTION_SHOW_DEVICE_MONITORING_DIALOG
1170 = "android.app.action.SHOW_DEVICE_MONITORING_DIALOG";
1171
1172 /**
Edman Anjos9e62c312017-01-26 22:22:58 +01001173 * Broadcast Action: Sent after application delegation scopes are changed. The new delegation
1174 * scopes will be sent in an {@code ArrayList<String>} extra identified by the
1175 * {@link #EXTRA_DELEGATION_SCOPES} key.
Edman Anjosf9946772016-11-28 16:35:15 +01001176 *
1177 * <p class=”note”> Note: This is a protected intent that can only be sent by the system.</p>
1178 */
1179 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1180 public static final String ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED =
1181 "android.app.action.APPLICATION_DELEGATION_SCOPES_CHANGED";
1182
1183 /**
Edman Anjos9e62c312017-01-26 22:22:58 +01001184 * An {@code ArrayList<String>} corresponding to the delegation scopes given to an app in the
Edman Anjosf9946772016-11-28 16:35:15 +01001185 * {@link #ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED} broadcast.
1186 */
1187 public static final String EXTRA_DELEGATION_SCOPES = "android.app.extra.DELEGATION_SCOPES";
1188
1189 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +00001190 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
1191 * the parent profile to access intents sent from the managed profile.
1192 * That is, when an app in the managed profile calls
1193 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
1194 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001195 */
Nicolas Prevot86a96732014-09-08 12:13:05 +01001196 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001197
1198 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +00001199 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
1200 * the managed profile to access intents sent from the parent profile.
1201 * That is, when an app in the parent profile calls
1202 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
1203 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001204 */
Nicolas Prevot86a96732014-09-08 12:13:05 +01001205 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001206
Dianne Hackbornd6847842010-01-12 18:14:19 -08001207 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01001208 * Broadcast action: notify that a new local system update policy has been set by the device
1209 * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00001210 */
1211 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Rubin Xu5faad8e2015-04-20 17:43:48 +01001212 public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED
1213 = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED";
Rubin Xu8027a4f2015-03-10 17:52:37 +00001214
Amith Yamasanid49489b2015-04-28 14:00:26 -07001215 /**
1216 * Permission policy to prompt user for new permission requests for runtime permissions.
1217 * Already granted or denied permissions are not affected by this.
1218 */
1219 public static final int PERMISSION_POLICY_PROMPT = 0;
1220
1221 /**
1222 * Permission policy to always grant new permission requests for runtime permissions.
1223 * Already granted or denied permissions are not affected by this.
1224 */
1225 public static final int PERMISSION_POLICY_AUTO_GRANT = 1;
1226
1227 /**
1228 * Permission policy to always deny new permission requests for runtime permissions.
1229 * Already granted or denied permissions are not affected by this.
1230 */
1231 public static final int PERMISSION_POLICY_AUTO_DENY = 2;
1232
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07001233 /**
1234 * Runtime permission state: The user can manage the permission
1235 * through the UI.
1236 */
1237 public static final int PERMISSION_GRANT_STATE_DEFAULT = 0;
1238
1239 /**
1240 * Runtime permission state: The permission is granted to the app
1241 * and the user cannot manage the permission through the UI.
1242 */
1243 public static final int PERMISSION_GRANT_STATE_GRANTED = 1;
1244
1245 /**
1246 * Runtime permission state: The permission is denied to the app
1247 * and the user cannot manage the permission through the UI.
1248 */
1249 public static final int PERMISSION_GRANT_STATE_DENIED = 2;
Rubin Xu8027a4f2015-03-10 17:52:37 +00001250
1251 /**
Edman Anjosf9946772016-11-28 16:35:15 +01001252 * Delegation of certificate installation and management. This scope grants access to the
1253 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
1254 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair} APIs.
1255 */
1256 public static final String DELEGATION_CERT_INSTALL = "delegation-cert-install";
1257
1258 /**
1259 * Delegation of application restrictions management. This scope grants access to the
1260 * {@link #setApplicationRestrictions} and {@link #getApplicationRestrictions} APIs.
1261 */
1262 public static final String DELEGATION_APP_RESTRICTIONS = "delegation-app-restrictions";
1263
1264 /**
Edman Anjosa5f2fb12016-12-19 11:25:54 -08001265 * Delegation of application uninstall block. This scope grants access to the
1266 * {@link #setUninstallBlocked} API.
1267 */
1268 public static final String DELEGATION_BLOCK_UNINSTALL = "delegation-block-uninstall";
1269
1270 /**
Edman Anjos52088e42017-01-13 22:26:17 +01001271 * Delegation of permission policy and permission grant state. This scope grants access to the
1272 * {@link #setPermissionPolicy}, {@link #getPermissionGrantState},
1273 * and {@link #setPermissionGrantState} APIs.
1274 */
1275 public static final String DELEGATION_PERMISSION_GRANT = "delegation-permission-grant";
1276
1277 /**
1278 * Delegation of package access state. This scope grants access to the
1279 * {@link #isApplicationHidden}, {@link #setApplicationHidden}, {@link #isPackageSuspended}, and
1280 * {@link #setPackagesSuspended} APIs.
1281 */
1282 public static final String DELEGATION_PACKAGE_ACCESS = "delegation-package-access";
1283
1284 /**
1285 * Delegation for enabling system apps. This scope grants access to the {@link #enableSystemApp}
1286 * API.
1287 */
1288 public static final String DELEGATION_ENABLE_SYSTEM_APP = "delegation-enable-system-app";
1289
1290 /**
1291 * Delegation of management of uninstalled packages. This scope grants access to the
1292 * {@code #setKeepUninstalledPackages} and {@code #getKeepUninstalledPackages} APIs.
1293 * @hide
1294 */
1295 public static final String DELEGATION_KEEP_UNINSTALLED_PACKAGES =
1296 "delegation-keep-uninstalled-packages";
1297
1298 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00001299 * No management for current user in-effect. This is the default.
1300 * @hide
1301 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001302 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001303 public static final int STATE_USER_UNMANAGED = 0;
1304
1305 /**
1306 * Management partially setup, user setup needs to be completed.
1307 * @hide
1308 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001309 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001310 public static final int STATE_USER_SETUP_INCOMPLETE = 1;
1311
1312 /**
1313 * Management partially setup, user setup completed.
1314 * @hide
1315 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001316 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001317 public static final int STATE_USER_SETUP_COMPLETE = 2;
1318
1319 /**
1320 * Management setup and active on current user.
1321 * @hide
1322 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001323 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001324 public static final int STATE_USER_SETUP_FINALIZED = 3;
1325
1326 /**
1327 * Management partially setup on a managed profile.
1328 * @hide
1329 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001330 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001331 public static final int STATE_USER_PROFILE_COMPLETE = 4;
1332
1333 /**
1334 * @hide
1335 */
1336 @IntDef({STATE_USER_UNMANAGED, STATE_USER_SETUP_INCOMPLETE, STATE_USER_SETUP_COMPLETE,
1337 STATE_USER_SETUP_FINALIZED, STATE_USER_PROFILE_COMPLETE})
1338 @Retention(RetentionPolicy.SOURCE)
1339 public @interface UserProvisioningState {}
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_DEVICE},
1345 * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and
1346 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when provisioning is allowed.
1347 *
1348 * @hide
1349 */
1350 public static final int CODE_OK = 0;
1351
1352 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001353 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001354 *
1355 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and
1356 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the device already has a device
1357 * owner.
1358 *
1359 * @hide
1360 */
1361 public static final int CODE_HAS_DEVICE_OWNER = 1;
1362
1363 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001364 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001365 *
1366 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1367 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user has a profile owner and for
1368 * {@link #ACTION_PROVISION_MANAGED_PROFILE} when the profile owner is already set.
1369 *
1370 * @hide
1371 */
1372 public static final int CODE_USER_HAS_PROFILE_OWNER = 2;
1373
1374 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001375 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001376 *
1377 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and
1378 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user isn't running.
1379 *
1380 * @hide
1381 */
1382 public static final int CODE_USER_NOT_RUNNING = 3;
1383
1384 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001385 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001386 *
1387 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1388 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the device has already been setup and
1389 * for {@link #ACTION_PROVISION_MANAGED_USER} if the user has already been setup.
1390 *
1391 * @hide
1392 */
1393 public static final int CODE_USER_SETUP_COMPLETED = 4;
1394
1395 /**
1396 * Code used to indicate that the device also has a user other than the system user.
1397 *
1398 * @hide
1399 */
1400 public static final int CODE_NONSYSTEM_USER_EXISTS = 5;
1401
1402 /**
1403 * Code used to indicate that device has an account that prevents provisioning.
1404 *
1405 * @hide
1406 */
1407 public static final int CODE_ACCOUNTS_NOT_EMPTY = 6;
1408
1409 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001410 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001411 *
1412 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and
1413 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the user is not a system user.
1414 *
1415 * @hide
1416 */
1417 public static final int CODE_NOT_SYSTEM_USER = 7;
1418
1419 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001420 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001421 *
1422 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1423 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} and {@link #ACTION_PROVISION_MANAGED_USER}
1424 * when the device is a watch and is already paired.
1425 *
1426 * @hide
1427 */
1428 public static final int CODE_HAS_PAIRED = 8;
1429
1430 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001431 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001432 *
1433 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} and
1434 * {@link #ACTION_PROVISION_MANAGED_USER} on devices which do not support managed users.
1435 *
1436 * @see {@link PackageManager#FEATURE_MANAGED_USERS}
1437 * @hide
1438 */
1439 public static final int CODE_MANAGED_USERS_NOT_SUPPORTED = 9;
1440
1441 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001442 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001443 *
1444 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} if the user is a system user.
1445 *
1446 * @hide
1447 */
1448 public static final int CODE_SYSTEM_USER = 10;
1449
1450 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001451 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001452 *
1453 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when the user cannot have more
1454 * managed profiles.
1455 *
1456 * @hide
1457 */
1458 public static final int CODE_CANNOT_ADD_MANAGED_PROFILE = 11;
1459
1460 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001461 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001462 *
1463 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} and
1464 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices not running with split system
1465 * user.
1466 *
1467 * @hide
1468 */
1469 public static final int CODE_NOT_SYSTEM_USER_SPLIT = 12;
1470
1471 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001472 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001473 *
1474 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1475 * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and
1476 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices which do no support device
1477 * admins.
1478 *
1479 * @hide
1480 */
1481 public static final int CODE_DEVICE_ADMIN_NOT_SUPPORTED = 13;
1482
1483 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001484 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001485 *
Esteban Talavera6c9116a2016-11-24 16:12:44 +00001486 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when the device the user is a
1487 * system user on a split system user device.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001488 *
1489 * @hide
1490 */
1491 public static final int CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER = 14;
1492
1493 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001494 * Result code for {@link #checkProvisioningPreCondition}.
1495 *
1496 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when adding a managed profile is
1497 * disallowed by {@link UserManager#DISALLOW_ADD_MANAGED_PROFILE}.
1498 *
1499 * @hide
1500 */
1501 public static final int CODE_ADD_MANAGED_PROFILE_DISALLOWED = 15;
1502
1503 /**
1504 * Result codes for {@link #checkProvisioningPreCondition} indicating all the provisioning pre
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001505 * conditions.
1506 *
1507 * @hide
1508 */
1509 @Retention(RetentionPolicy.SOURCE)
1510 @IntDef({CODE_OK, CODE_HAS_DEVICE_OWNER, CODE_USER_HAS_PROFILE_OWNER, CODE_USER_NOT_RUNNING,
1511 CODE_USER_SETUP_COMPLETED, CODE_NOT_SYSTEM_USER, CODE_HAS_PAIRED,
1512 CODE_MANAGED_USERS_NOT_SUPPORTED, CODE_SYSTEM_USER, CODE_CANNOT_ADD_MANAGED_PROFILE,
1513 CODE_NOT_SYSTEM_USER_SPLIT, CODE_DEVICE_ADMIN_NOT_SUPPORTED,
Esteban Talavera01576862016-12-15 11:16:44 +00001514 CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER, CODE_ADD_MANAGED_PROFILE_DISALLOWED})
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001515 public @interface ProvisioningPreCondition {}
1516
1517 /**
Makoto Onukifc73d792017-03-22 14:22:35 -07001518 * Service action: Action for a service that device owner and profile owner can optionally
1519 * own. If a device owner or a profile owner has such a service, the system tries to keep
1520 * a bound connection to it, in order to keep their process always running.
Makoto Onukife739702017-04-25 13:26:21 -07001521 * The service must be protected with the {@link android.Manifest.permission#BIND_DEVICE_ADMIN}
1522 * permission.
Makoto Onukifc73d792017-03-22 14:22:35 -07001523 */
1524 @SdkConstant(SdkConstantType.SERVICE_ACTION)
1525 public static final String ACTION_DEVICE_ADMIN_SERVICE
1526 = "android.app.action.DEVICE_ADMIN_SERVICE";
1527
1528 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001529 * Return true if the given administrator component is currently active (enabled) in the system.
1530 *
1531 * @param admin The administrator component to check for.
1532 * @return {@code true} if {@code admin} is currently enabled in the system, {@code false}
1533 * otherwise
Dianne Hackbornd6847842010-01-12 18:14:19 -08001534 */
Robin Lee25e26452015-06-02 09:56:29 -07001535 public boolean isAdminActive(@NonNull ComponentName admin) {
Charles He8c760562016-10-25 16:36:53 +01001536 throwIfParentInstance("isAdminActive");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001537 return isAdminActiveAsUser(admin, myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001538 }
1539
1540 /**
1541 * @see #isAdminActive(ComponentName)
1542 * @hide
1543 */
Robin Lee25e26452015-06-02 09:56:29 -07001544 public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001545 if (mService != null) {
1546 try {
Robin Lee25e26452015-06-02 09:56:29 -07001547 return mService.isAdminActive(admin, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001548 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001549 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001550 }
1551 }
1552 return false;
1553 }
Charles Hedea0c3b2017-01-13 10:04:12 +00001554
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001555 /**
1556 * Return true if the given administrator component is currently being removed
1557 * for the user.
1558 * @hide
1559 */
Robin Lee25e26452015-06-02 09:56:29 -07001560 public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) {
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001561 if (mService != null) {
1562 try {
Robin Lee25e26452015-06-02 09:56:29 -07001563 return mService.isRemovingAdmin(admin, userId);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001564 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001565 throw e.rethrowFromSystemServer();
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001566 }
1567 }
1568 return false;
1569 }
1570
Dianne Hackbornd6847842010-01-12 18:14:19 -08001571 /**
Robin Lee25e26452015-06-02 09:56:29 -07001572 * Return a list of all currently active device administrators' component
1573 * names. If there are no administrators {@code null} may be
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001574 * returned.
1575 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07001576 public @Nullable List<ComponentName> getActiveAdmins() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001577 throwIfParentInstance("getActiveAdmins");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001578 return getActiveAdminsAsUser(myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001579 }
1580
1581 /**
1582 * @see #getActiveAdmins()
1583 * @hide
1584 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07001585 public @Nullable List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001586 if (mService != null) {
1587 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001588 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001589 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001590 throw e.rethrowFromSystemServer();
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001591 }
1592 }
1593 return null;
1594 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001595
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001596 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001597 * Used by package administration code to determine if a package can be stopped
1598 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001599 * @hide
1600 */
David Ouyang3a83a332017-01-11 16:36:40 -08001601 @SystemApi
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001602 public boolean packageHasActiveAdmins(String packageName) {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001603 return packageHasActiveAdmins(packageName, myUserId());
1604 }
1605
1606 /**
1607 * Used by package administration code to determine if a package can be stopped
1608 * or uninstalled.
1609 * @hide
1610 */
1611 public boolean packageHasActiveAdmins(String packageName, int userId) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001612 if (mService != null) {
1613 try {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001614 return mService.packageHasActiveAdmins(packageName, userId);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001615 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001616 throw e.rethrowFromSystemServer();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001617 }
1618 }
1619 return false;
1620 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001621
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001622 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001623 * Remove a current administration component. This can only be called
1624 * by the application that owns the administration component; if you
1625 * try to remove someone else's component, a security exception will be
1626 * thrown.
Esteban Talavera552a5612016-02-19 17:02:24 +00001627 *
1628 * <p>Note that the operation is not synchronous and the admin might still be active (as
1629 * indicated by {@link #getActiveAdmins()}) by the time this method returns.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001630 *
1631 * @param admin The administration compononent to remove.
1632 * @throws SecurityException if the caller is not in the owner application of {@code admin}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001633 */
Robin Lee25e26452015-06-02 09:56:29 -07001634 public void removeActiveAdmin(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001635 throwIfParentInstance("removeActiveAdmin");
Dianne Hackbornd6847842010-01-12 18:14:19 -08001636 if (mService != null) {
1637 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001638 mService.removeActiveAdmin(admin, myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001639 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001640 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001641 }
1642 }
1643 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001644
Dianne Hackbornd6847842010-01-12 18:14:19 -08001645 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001646 * Returns true if an administrator has been granted a particular device policy. This can be
1647 * used to check whether the administrator was activated under an earlier set of policies, but
1648 * requires additional policies after an upgrade.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001649 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001650 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be an
1651 * active administrator, or an exception will be thrown.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001652 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001653 * @throws SecurityException if {@code admin} is not an active administrator.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001654 */
Robin Lee25e26452015-06-02 09:56:29 -07001655 public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001656 throwIfParentInstance("hasGrantedPolicy");
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001657 if (mService != null) {
1658 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001659 return mService.hasGrantedPolicy(admin, usesPolicy, myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001660 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001661 throw e.rethrowFromSystemServer();
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001662 }
1663 }
1664 return false;
1665 }
1666
1667 /**
Clara Bayarria1771112015-12-18 16:29:18 +00001668 * Returns true if the Profile Challenge is available to use for the given profile user.
1669 *
1670 * @hide
1671 */
1672 public boolean isSeparateProfileChallengeAllowed(int userHandle) {
1673 if (mService != null) {
1674 try {
1675 return mService.isSeparateProfileChallengeAllowed(userHandle);
1676 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001677 throw e.rethrowFromSystemServer();
Clara Bayarria1771112015-12-18 16:29:18 +00001678 }
1679 }
1680 return false;
1681 }
1682
1683 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001684 * Constant for {@link #setPasswordQuality}: the policy has no requirements
1685 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001686 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001687 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001688 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001689
Dianne Hackbornd6847842010-01-12 18:14:19 -08001690 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -07001691 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
1692 * recognition technology. This implies technologies that can recognize the identity of
1693 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
1694 * Note that quality constants are ordered so that higher values are more restrictive.
1695 */
1696 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
1697
1698 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001699 * Constant for {@link #setPasswordQuality}: the policy requires some kind
Benjamin Franzc6a96532015-06-16 11:23:38 +01001700 * of password or pattern, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001701 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001702 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001703 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001704
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001705 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001706 * Constant for {@link #setPasswordQuality}: the user must have entered a
1707 * password containing at least numeric characters. Note that quality
1708 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001709 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001710 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001711
Dianne Hackbornd6847842010-01-12 18:14:19 -08001712 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001713 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -08001714 * password containing at least numeric characters with no repeating (4444)
1715 * or ordered (1234, 4321, 2468) sequences. Note that quality
1716 * constants are ordered so that higher values are more restrictive.
1717 */
1718 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
1719
1720 /**
1721 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001722 * password containing at least alphabetic (or other symbol) characters.
1723 * Note that quality constants are ordered so that higher values are more
1724 * restrictive.
1725 */
1726 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001727
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001728 /**
1729 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001730 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001731 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001732 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001733 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001734 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001735
Dianne Hackbornd6847842010-01-12 18:14:19 -08001736 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001737 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001738 * password containing at least a letter, a numerical digit and a special
1739 * symbol, by default. With this password quality, passwords can be
1740 * restricted to contain various sets of characters, like at least an
1741 * uppercase letter, etc. These are specified using various methods,
1742 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
1743 * that quality constants are ordered so that higher values are more
1744 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001745 */
1746 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
1747
1748 /**
Oleksandr Peletskyi0fdcd3d2016-01-13 16:49:56 +01001749 * Constant for {@link #setPasswordQuality}: the user is not allowed to
1750 * modify password. In case this password quality is set, the password is
1751 * managed by a profile owner. The profile owner can set any password,
1752 * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note
1753 * that quality constants are ordered so that higher values are more
1754 * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is
1755 * the highest.
1756 * @hide
1757 */
1758 public static final int PASSWORD_QUALITY_MANAGED = 0x80000;
1759
1760 /**
Makoto Onuki5e7e06702016-09-01 18:02:01 -07001761 * @hide
1762 *
1763 * adb shell dpm set-{device,profile}-owner will normally not allow installing an owner to
1764 * a user with accounts. {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED}
1765 * and {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} are the account features
1766 * used by authenticator to exempt their accounts from this:
1767 *
1768 * <ul>
1769 * <li>Non-test-only DO/PO still can't be installed when there are accounts.
1770 * <p>In order to make an apk test-only, add android:testOnly="true" to the
1771 * &lt;application&gt; tag in the manifest.
1772 *
1773 * <li>Test-only DO/PO can be installed even when there are accounts, as long as all the
1774 * accounts have the {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} feature.
1775 * Some authenticators claim to have any features, so to detect it, we also check
1776 * {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} and disallow installing
1777 * if any of the accounts have it.
1778 * </ul>
1779 */
Makoto Onuki47c203d2017-02-13 16:21:19 -08001780 @SystemApi
1781 @TestApi
Makoto Onuki5e7e06702016-09-01 18:02:01 -07001782 public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED =
1783 "android.account.DEVICE_OR_PROFILE_OWNER_ALLOWED";
1784
1785 /** @hide See {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} */
Makoto Onuki47c203d2017-02-13 16:21:19 -08001786 @SystemApi
1787 @TestApi
Makoto Onuki5e7e06702016-09-01 18:02:01 -07001788 public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED =
1789 "android.account.DEVICE_OR_PROFILE_OWNER_DISALLOWED";
1790
1791 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001792 * Called by an application that is administering the device to set the password restrictions it
1793 * is imposing. After setting this, the user will not be able to enter a new password that is
1794 * not at least as restrictive as what has been set. Note that the current password will remain
1795 * until the user has set a new one, so the change does not take place immediately. To prompt
1796 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
Esteban Talaverac1c83592016-02-17 17:56:15 +00001797 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after calling this method.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001798 * <p>
1799 * Quality constants are ordered so that higher values are more restrictive; thus the highest
1800 * requested quality constant (between the policy set here, the user's preference, and any other
1801 * considerations) is the one that is in effect.
1802 * <p>
1803 * The calling device admin must have requested
1804 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1805 * not, a security exception will be thrown.
1806 * <p>
1807 * This method can be called on the {@link DevicePolicyManager} instance returned by
1808 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1809 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001810 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001811 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001812 * @param quality The new desired quality. One of {@link #PASSWORD_QUALITY_UNSPECIFIED},
1813 * {@link #PASSWORD_QUALITY_SOMETHING}, {@link #PASSWORD_QUALITY_NUMERIC},
1814 * {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC},
1815 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} or {@link #PASSWORD_QUALITY_COMPLEX}.
1816 * @throws SecurityException if {@code admin} is not an active administrator or if {@code admin}
1817 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Dianne Hackbornd6847842010-01-12 18:14:19 -08001818 */
Robin Lee25e26452015-06-02 09:56:29 -07001819 public void setPasswordQuality(@NonNull ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001820 if (mService != null) {
1821 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001822 mService.setPasswordQuality(admin, quality, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001823 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001824 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001825 }
1826 }
1827 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001828
Dianne Hackbornd6847842010-01-12 18:14:19 -08001829 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001830 * Retrieve the current minimum password quality for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01001831 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00001832 * a separate challenge are not taken into account.
1833 *
1834 * <p>This method can be called on the {@link DevicePolicyManager} instance
1835 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1836 * restrictions on the parent profile.
1837 *
Robin Lee25e26452015-06-02 09:56:29 -07001838 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001839 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001840 */
Robin Lee25e26452015-06-02 09:56:29 -07001841 public int getPasswordQuality(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001842 return getPasswordQuality(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001843 }
1844
1845 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001846 public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001847 if (mService != null) {
1848 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001849 return mService.getPasswordQuality(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001850 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001851 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001852 }
1853 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001854 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001855 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001856
Dianne Hackbornd6847842010-01-12 18:14:19 -08001857 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001858 * Called by an application that is administering the device to set the minimum allowed password
1859 * length. After setting this, the user will not be able to enter a new password that is not at
1860 * least as restrictive as what has been set. Note that the current password will remain until
1861 * the user has set a new one, so the change does not take place immediately. To prompt the user
1862 * for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
1863 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
1864 * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC}
1865 * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC},
1866 * {@link #PASSWORD_QUALITY_ALPHANUMERIC}, or {@link #PASSWORD_QUALITY_COMPLEX} with
1867 * {@link #setPasswordQuality}.
1868 * <p>
1869 * The calling device admin must have requested
1870 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1871 * not, a security exception will be thrown.
1872 * <p>
1873 * This method can be called on the {@link DevicePolicyManager} instance returned by
1874 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1875 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001876 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001877 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001878 * @param length The new desired minimum password length. A value of 0 means there is no
1879 * restriction.
1880 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1881 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Dianne Hackbornd6847842010-01-12 18:14:19 -08001882 */
Robin Lee25e26452015-06-02 09:56:29 -07001883 public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001884 if (mService != null) {
1885 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001886 mService.setPasswordMinimumLength(admin, length, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001887 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001888 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001889 }
1890 }
1891 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001892
Dianne Hackbornd6847842010-01-12 18:14:19 -08001893 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001894 * Retrieve the current minimum password length for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01001895 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00001896 * a separate challenge are not taken into account.
1897 *
1898 * <p>This method can be called on the {@link DevicePolicyManager} instance
1899 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1900 * restrictions on the parent profile.
1901 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001902 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001903 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001904 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001905 */
Robin Lee25e26452015-06-02 09:56:29 -07001906 public int getPasswordMinimumLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001907 return getPasswordMinimumLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001908 }
1909
1910 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001911 public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001912 if (mService != null) {
1913 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001914 return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001915 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001916 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001917 }
1918 }
1919 return 0;
1920 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001921
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001922 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001923 * Called by an application that is administering the device to set the minimum number of upper
1924 * case letters required in the password. After setting this, the user will not be able to enter
1925 * a new password that is not at least as restrictive as what has been set. Note that the
1926 * current password will remain until the user has set a new one, so the change does not take
1927 * place immediately. To prompt the user for a new password, use
1928 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
1929 * setting this value. This constraint is only imposed if the administrator has also requested
1930 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001931 * <p>
1932 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001933 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1934 * not, a security exception will be thrown.
1935 * <p>
1936 * This method can be called on the {@link DevicePolicyManager} instance returned by
1937 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1938 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001939 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001940 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1941 * @param length The new desired minimum number of upper case letters required in the password.
1942 * A value of 0 means there is no restriction.
1943 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1944 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001945 */
Robin Lee25e26452015-06-02 09:56:29 -07001946 public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001947 if (mService != null) {
1948 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001949 mService.setPasswordMinimumUpperCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001950 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001951 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001952 }
1953 }
1954 }
1955
1956 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001957 * Retrieve the current number of upper case letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01001958 * for a particular admin or all admins that set restrictions on this user and
Esteban Talaverac1c83592016-02-17 17:56:15 +00001959 * its participating profiles. Restrictions on profiles that have a separate challenge
1960 * are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001961 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001962 * {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001963 * and only applies when the password quality is
1964 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001965 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001966 * <p>This method can be called on the {@link DevicePolicyManager} instance
1967 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1968 * restrictions on the parent profile.
1969 *
Robin Lee25e26452015-06-02 09:56:29 -07001970 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001971 * aggregate all admins.
1972 * @return The minimum number of upper case letters required in the
1973 * password.
1974 */
Robin Lee25e26452015-06-02 09:56:29 -07001975 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001976 return getPasswordMinimumUpperCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001977 }
1978
1979 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001980 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001981 if (mService != null) {
1982 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001983 return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001984 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001985 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001986 }
1987 }
1988 return 0;
1989 }
1990
1991 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001992 * Called by an application that is administering the device to set the minimum number of lower
1993 * case letters required in the password. After setting this, the user will not be able to enter
1994 * a new password that is not at least as restrictive as what has been set. Note that the
1995 * current password will remain until the user has set a new one, so the change does not take
1996 * place immediately. To prompt the user for a new password, use
1997 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
1998 * setting this value. This constraint is only imposed if the administrator has also requested
1999 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002000 * <p>
2001 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002002 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2003 * not, a security exception will be thrown.
2004 * <p>
2005 * This method can be called on the {@link DevicePolicyManager} instance returned by
2006 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2007 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002008 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002009 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2010 * @param length The new desired minimum number of lower case letters required in the password.
2011 * A value of 0 means there is no restriction.
2012 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2013 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002014 */
Robin Lee25e26452015-06-02 09:56:29 -07002015 public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002016 if (mService != null) {
2017 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002018 mService.setPasswordMinimumLowerCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002019 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002020 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002021 }
2022 }
2023 }
2024
2025 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002026 * Retrieve the current number of lower case letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002027 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002028 * and its participating profiles. Restrictions on profiles that have
2029 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01002030 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00002031 * {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002032 * and only applies when the password quality is
2033 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002034 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002035 * <p>This method can be called on the {@link DevicePolicyManager} instance
2036 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2037 * restrictions on the parent profile.
2038 *
Robin Lee25e26452015-06-02 09:56:29 -07002039 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002040 * aggregate all admins.
2041 * @return The minimum number of lower case letters required in the
2042 * password.
2043 */
Robin Lee25e26452015-06-02 09:56:29 -07002044 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002045 return getPasswordMinimumLowerCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002046 }
2047
2048 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002049 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002050 if (mService != null) {
2051 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002052 return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002053 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002054 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002055 }
2056 }
2057 return 0;
2058 }
2059
2060 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002061 * Called by an application that is administering the device to set the minimum number of
2062 * letters required in the password. After setting this, the user will not be able to enter a
2063 * new password that is not at least as restrictive as what has been set. Note that the current
2064 * password will remain until the user has set a new one, so the change does not take place
2065 * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
2066 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
2067 * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
2068 * {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002069 * <p>
2070 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002071 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2072 * not, a security exception will be thrown.
2073 * <p>
2074 * This method can be called on the {@link DevicePolicyManager} instance returned by
2075 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2076 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002077 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002078 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2079 * @param length The new desired minimum number of letters required in the password. A value of
2080 * 0 means there is no restriction.
2081 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2082 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002083 */
Robin Lee25e26452015-06-02 09:56:29 -07002084 public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002085 if (mService != null) {
2086 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002087 mService.setPasswordMinimumLetters(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002088 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002089 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002090 }
2091 }
2092 }
2093
2094 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002095 * Retrieve the current number of letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002096 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002097 * and its participating profiles. Restrictions on profiles that have
2098 * a separate challenge are not taken into account.
2099 * This is the same value as set by
2100 * {@link #setPasswordMinimumLetters(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002101 * and only applies when the password quality is
2102 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002103 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002104 * <p>This method can be called on the {@link DevicePolicyManager} instance
2105 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2106 * restrictions on the parent profile.
2107 *
Robin Lee25e26452015-06-02 09:56:29 -07002108 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002109 * aggregate all admins.
2110 * @return The minimum number of letters required in the password.
2111 */
Robin Lee25e26452015-06-02 09:56:29 -07002112 public int getPasswordMinimumLetters(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002113 return getPasswordMinimumLetters(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002114 }
2115
2116 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002117 public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002118 if (mService != null) {
2119 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002120 return mService.getPasswordMinimumLetters(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002121 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002122 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002123 }
2124 }
2125 return 0;
2126 }
2127
2128 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002129 * Called by an application that is administering the device to set the minimum number of
2130 * numerical digits required in the password. After setting this, the user will not be able to
2131 * enter a new password that is not at least as restrictive as what has been set. Note that the
2132 * current password will remain until the user has set a new one, so the change does not take
2133 * place immediately. To prompt the user for a new password, use
2134 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
2135 * setting this value. This constraint is only imposed if the administrator has also requested
2136 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002137 * <p>
2138 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002139 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2140 * not, a security exception will be thrown.
2141 * <p>
2142 * This method can be called on the {@link DevicePolicyManager} instance returned by
2143 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2144 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002145 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002146 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2147 * @param length The new desired minimum number of numerical digits required in the password. A
2148 * value of 0 means there is no restriction.
2149 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2150 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002151 */
Robin Lee25e26452015-06-02 09:56:29 -07002152 public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002153 if (mService != null) {
2154 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002155 mService.setPasswordMinimumNumeric(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002156 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002157 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002158 }
2159 }
2160 }
2161
2162 /**
2163 * Retrieve the current number of numerical digits required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002164 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002165 * and its participating profiles. Restrictions on profiles that have
2166 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01002167 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00002168 * {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002169 * and only applies when the password quality is
2170 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002171 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002172 * <p>This method can be called on the {@link DevicePolicyManager} instance
2173 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2174 * restrictions on the parent profile.
2175 *
Robin Lee25e26452015-06-02 09:56:29 -07002176 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002177 * aggregate all admins.
2178 * @return The minimum number of numerical digits required in the password.
2179 */
Robin Lee25e26452015-06-02 09:56:29 -07002180 public int getPasswordMinimumNumeric(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002181 return getPasswordMinimumNumeric(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002182 }
2183
2184 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002185 public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002186 if (mService != null) {
2187 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002188 return mService.getPasswordMinimumNumeric(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002189 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002190 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002191 }
2192 }
2193 return 0;
2194 }
2195
2196 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002197 * Called by an application that is administering the device to set the minimum number of
2198 * symbols required in the password. After setting this, the user will not be able to enter a
2199 * new password that is not at least as restrictive as what has been set. Note that the current
2200 * password will remain until the user has set a new one, so the change does not take place
2201 * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
2202 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
2203 * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
2204 * {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002205 * <p>
2206 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002207 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2208 * not, a security exception will be thrown.
2209 * <p>
2210 * This method can be called on the {@link DevicePolicyManager} instance returned by
2211 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2212 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002213 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002214 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2215 * @param length The new desired minimum number of symbols required in the password. A value of
2216 * 0 means there is no restriction.
2217 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2218 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002219 */
Robin Lee25e26452015-06-02 09:56:29 -07002220 public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002221 if (mService != null) {
2222 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002223 mService.setPasswordMinimumSymbols(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002224 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002225 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002226 }
2227 }
2228 }
2229
2230 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002231 * Retrieve the current number of symbols required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002232 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002233 * and its participating profiles. Restrictions on profiles that have
2234 * a separate challenge are not taken into account. This is the same value as
2235 * set by {@link #setPasswordMinimumSymbols(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002236 * and only applies when the password quality is
2237 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002238 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002239 * <p>This method can be called on the {@link DevicePolicyManager} instance
2240 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2241 * restrictions on the parent profile.
2242 *
Robin Lee25e26452015-06-02 09:56:29 -07002243 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002244 * aggregate all admins.
2245 * @return The minimum number of symbols required in the password.
2246 */
Robin Lee25e26452015-06-02 09:56:29 -07002247 public int getPasswordMinimumSymbols(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002248 return getPasswordMinimumSymbols(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002249 }
2250
2251 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002252 public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002253 if (mService != null) {
2254 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002255 return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002256 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002257 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002258 }
2259 }
2260 return 0;
2261 }
2262
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002263 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002264 * Called by an application that is administering the device to set the minimum number of
2265 * non-letter characters (numerical digits or symbols) required in the password. After setting
2266 * this, the user will not be able to enter a new password that is not at least as restrictive
2267 * as what has been set. Note that the current password will remain until the user has set a new
2268 * one, so the change does not take place immediately. To prompt the user for a new password,
2269 * use {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
2270 * setting this value. This constraint is only imposed if the administrator has also requested
2271 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002272 * <p>
2273 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002274 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2275 * not, a security exception will be thrown.
2276 * <p>
2277 * This method can be called on the {@link DevicePolicyManager} instance returned by
2278 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2279 * profile.
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002280 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002281 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2282 * @param length The new desired minimum number of letters required in the password. A value of
2283 * 0 means there is no restriction.
2284 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2285 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002286 */
Robin Lee25e26452015-06-02 09:56:29 -07002287 public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002288 if (mService != null) {
2289 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002290 mService.setPasswordMinimumNonLetter(admin, length, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002291 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002292 throw e.rethrowFromSystemServer();
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002293 }
2294 }
2295 }
2296
2297 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002298 * Retrieve the current number of non-letter characters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002299 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002300 * and its participating profiles. Restrictions on profiles that have
2301 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01002302 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00002303 * {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002304 * and only applies when the password quality is
2305 * {@link #PASSWORD_QUALITY_COMPLEX}.
2306 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002307 * <p>This method can be called on the {@link DevicePolicyManager} instance
2308 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2309 * restrictions on the parent profile.
2310 *
Robin Lee25e26452015-06-02 09:56:29 -07002311 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002312 * aggregate all admins.
2313 * @return The minimum number of letters required in the password.
2314 */
Robin Lee25e26452015-06-02 09:56:29 -07002315 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002316 return getPasswordMinimumNonLetter(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002317 }
2318
2319 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002320 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002321 if (mService != null) {
2322 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002323 return mService.getPasswordMinimumNonLetter(admin, userHandle, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002324 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002325 throw e.rethrowFromSystemServer();
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002326 }
2327 }
2328 return 0;
2329 }
2330
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002331 /**
2332 * Called by an application that is administering the device to set the length of the password
2333 * history. After setting this, the user will not be able to enter a new password that is the
2334 * same as any password in the history. Note that the current password will remain until the
2335 * user has set a new one, so the change does not take place immediately. To prompt the user for
2336 * a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
2337 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
2338 * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC}
2339 * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX} {@link #PASSWORD_QUALITY_ALPHABETIC}, or
2340 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} with {@link #setPasswordQuality}.
2341 * <p>
2342 * The calling device admin must have requested
2343 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2344 * not, a security exception will be thrown.
2345 * <p>
2346 * This method can be called on the {@link DevicePolicyManager} instance returned by
2347 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2348 * profile.
2349 *
2350 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2351 * @param length The new desired length of password history. A value of 0 means there is no
2352 * restriction.
2353 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2354 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
2355 */
Robin Lee25e26452015-06-02 09:56:29 -07002356 public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002357 if (mService != null) {
2358 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002359 mService.setPasswordHistoryLength(admin, length, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002360 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002361 throw e.rethrowFromSystemServer();
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002362 }
2363 }
2364 }
2365
2366 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002367 * Called by a device admin to set the password expiration timeout. Calling this method will
2368 * restart the countdown for password expiration for the given admin, as will changing the
2369 * device password (for all admins).
2370 * <p>
2371 * The provided timeout is the time delta in ms and will be added to the current time. For
2372 * example, to have the password expire 5 days from now, timeout would be 5 * 86400 * 1000 =
2373 * 432000000 ms for timeout.
2374 * <p>
2375 * To disable password expiration, a value of 0 may be used for timeout.
2376 * <p>
2377 * The calling device admin must have requested
2378 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this method; if it has
2379 * not, a security exception will be thrown.
2380 * <p>
2381 * Note that setting the password will automatically reset the expiration time for all active
2382 * admins. Active admins do not need to explicitly call this method in that case.
2383 * <p>
2384 * This method can be called on the {@link DevicePolicyManager} instance returned by
2385 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2386 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002387 *
Jim Millera4e28d12010-11-08 16:15:47 -08002388 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002389 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0 means
2390 * there is no restriction (unlimited).
2391 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2392 * does not use {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD}
Jim Millera4e28d12010-11-08 16:15:47 -08002393 */
Robin Lee25e26452015-06-02 09:56:29 -07002394 public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) {
Jim Millera4e28d12010-11-08 16:15:47 -08002395 if (mService != null) {
2396 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002397 mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08002398 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002399 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08002400 }
2401 }
2402 }
2403
2404 /**
Jim Miller6b857682011-02-16 16:27:41 -08002405 * Get the password expiration timeout for the given admin. The expiration timeout is the
2406 * recurring expiration timeout provided in the call to
2407 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
Esteban Talaverac1c83592016-02-17 17:56:15 +00002408 * aggregate of all participating policy administrators if {@code admin} is null. Admins that
2409 * have set restrictions on profiles that have a separate challenge are not taken into account.
2410 *
2411 * <p>This method can be called on the {@link DevicePolicyManager} instance
2412 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2413 * restrictions on the parent profile.
Jim Millera4e28d12010-11-08 16:15:47 -08002414 *
Robin Lee25e26452015-06-02 09:56:29 -07002415 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08002416 * @return The timeout for the given admin or the minimum of all timeouts
2417 */
Robin Lee25e26452015-06-02 09:56:29 -07002418 public long getPasswordExpirationTimeout(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08002419 if (mService != null) {
2420 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002421 return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08002422 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002423 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08002424 }
2425 }
2426 return 0;
2427 }
2428
2429 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002430 * Get the current password expiration time for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01002431 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00002432 * a separate challenge are not taken into account. If admin is {@code null}, then a composite
2433 * of all expiration times is returned - which will be the minimum of all of them.
2434 *
2435 * <p>This method can be called on the {@link DevicePolicyManager} instance
2436 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2437 * the password expiration for the parent profile.
Jim Millera4e28d12010-11-08 16:15:47 -08002438 *
Robin Lee25e26452015-06-02 09:56:29 -07002439 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002440 * @return The password expiration time, in milliseconds since epoch.
Jim Millera4e28d12010-11-08 16:15:47 -08002441 */
Robin Lee25e26452015-06-02 09:56:29 -07002442 public long getPasswordExpiration(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08002443 if (mService != null) {
2444 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002445 return mService.getPasswordExpiration(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08002446 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002447 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08002448 }
2449 }
2450 return 0;
2451 }
2452
2453 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002454 * Retrieve the current password history length for a particular admin or all admins that
Rubin Xud3609d42016-07-13 18:32:57 +01002455 * set restrictions on this user and its participating profiles. Restrictions on profiles that
Esteban Talaverac1c83592016-02-17 17:56:15 +00002456 * have a separate challenge are not taken into account.
2457 *
2458 * <p>This method can be called on the {@link DevicePolicyManager} instance
2459 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2460 * restrictions on the parent profile.
2461 *
Robin Lee25e26452015-06-02 09:56:29 -07002462 * @param admin The name of the admin component to check, or {@code null} to aggregate
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002463 * all admins.
2464 * @return The length of the password history
2465 */
Robin Lee25e26452015-06-02 09:56:29 -07002466 public int getPasswordHistoryLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002467 return getPasswordHistoryLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002468 }
2469
2470 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002471 public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002472 if (mService != null) {
2473 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002474 return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002475 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002476 throw e.rethrowFromSystemServer();
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002477 }
2478 }
2479 return 0;
2480 }
2481
Dianne Hackbornd6847842010-01-12 18:14:19 -08002482 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08002483 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08002484 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08002485 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08002486 * @return Returns the maximum length that the user can enter.
2487 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08002488 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08002489 // Kind-of arbitrary.
2490 return 16;
2491 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002492
Dianne Hackborn254cb442010-01-27 19:23:59 -08002493 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002494 * Determine whether the current password the user has set is sufficient to meet the policy
2495 * requirements (e.g. quality, minimum length) that have been requested by the admins of this
2496 * user and its participating profiles. Restrictions on profiles that have a separate challenge
Andrew Scull5daf2732016-11-14 15:02:45 +00002497 * are not taken into account. The user must be unlocked in order to perform the check.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002498 * <p>
2499 * The calling device admin must have requested
2500 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2501 * not, a security exception will be thrown.
2502 * <p>
2503 * This method can be called on the {@link DevicePolicyManager} instance returned by
2504 * {@link #getParentProfileInstance(ComponentName)} in order to determine if the password set on
2505 * the parent profile is sufficient.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002506 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01002507 * @return Returns true if the password meets the current requirements, else false.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002508 * @throws SecurityException if the calling application does not own an active administrator
2509 * that uses {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Andrew Scull5daf2732016-11-14 15:02:45 +00002510 * @throws InvalidStateException if the user is not unlocked.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002511 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002512 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002513 if (mService != null) {
2514 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00002515 return mService.isActivePasswordSufficient(myUserId(), mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002516 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002517 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002518 }
2519 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002520 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08002521 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002522
Dianne Hackbornd6847842010-01-12 18:14:19 -08002523 /**
Clara Bayarrid7693912016-01-22 17:26:31 +00002524 * Determine whether the current profile password the user has set is sufficient
Esteban Talaverac1c83592016-02-17 17:56:15 +00002525 * to meet the policy requirements (e.g. quality, minimum length) that have been
Clara Bayarrid7693912016-01-22 17:26:31 +00002526 * requested by the admins of the parent user and its profiles.
2527 *
2528 * @param userHandle the userId of the profile to check the password for.
2529 * @return Returns true if the password would meet the current requirements, else false.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002530 * @throws SecurityException if {@code userHandle} is not a managed profile.
Clara Bayarrid7693912016-01-22 17:26:31 +00002531 * @hide
2532 */
2533 public boolean isProfileActivePasswordSufficientForParent(int userHandle) {
2534 if (mService != null) {
2535 try {
2536 return mService.isProfileActivePasswordSufficientForParent(userHandle);
2537 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002538 throw e.rethrowFromSystemServer();
Clara Bayarrid7693912016-01-22 17:26:31 +00002539 }
2540 }
2541 return false;
2542 }
2543
2544 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002545 * Retrieve the number of times the user has failed at entering a password since that last
2546 * successful password entry.
2547 * <p>
2548 * This method can be called on the {@link DevicePolicyManager} instance returned by
2549 * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the number of failed
2550 * password attemts for the parent user.
2551 * <p>
2552 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN}
2553 * to be able to call this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002554 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002555 * @return The number of times user has entered an incorrect password since the last correct
2556 * password entry.
2557 * @throws SecurityException if the calling application does not own an active administrator
2558 * that uses {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002559 */
2560 public int getCurrentFailedPasswordAttempts() {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00002561 return getCurrentFailedPasswordAttempts(myUserId());
2562 }
2563
2564 /**
2565 * Retrieve the number of times the given user has failed at entering a
2566 * password since that last successful password entry.
2567 *
2568 * <p>The calling device admin must have requested
2569 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call this method; if it has
2570 * not and it is not the system uid, a security exception will be thrown.
2571 *
2572 * @hide
2573 */
2574 public int getCurrentFailedPasswordAttempts(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002575 if (mService != null) {
2576 try {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00002577 return mService.getCurrentFailedPasswordAttempts(userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002578 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002579 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002580 }
2581 }
2582 return -1;
2583 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002584
2585 /**
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002586 * Queries whether {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002587 *
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002588 * @return true if RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002589 * @hide
2590 */
2591 public boolean getDoNotAskCredentialsOnBoot() {
2592 if (mService != null) {
2593 try {
2594 return mService.getDoNotAskCredentialsOnBoot();
2595 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002596 throw e.rethrowFromSystemServer();
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002597 }
2598 }
2599 return false;
2600 }
2601
2602 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002603 * Setting this to a value greater than zero enables a built-in policy that will perform a
2604 * device or profile wipe after too many incorrect device-unlock passwords have been entered.
2605 * This built-in policy combines watching for failed passwords and wiping the device, and
2606 * requires that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002607 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002608 * <p>
2609 * To implement any other policy (e.g. wiping data for a particular application only, erasing or
2610 * revoking credentials, or reporting the failure to a server), you should implement
2611 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} instead. Do not
2612 * use this API, because if the maximum count is reached, the device or profile will be wiped
2613 * immediately, and your callback will not be invoked.
2614 * <p>
2615 * This method can be called on the {@link DevicePolicyManager} instance returned by
2616 * {@link #getParentProfileInstance(ComponentName)} in order to set a value on the parent
2617 * profile.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002618 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002619 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002620 * @param num The number of failed password attempts at which point the device or profile will
2621 * be wiped.
2622 * @throws SecurityException if {@code admin} is not an active administrator or does not use
2623 * both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
2624 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002625 */
Robin Lee25e26452015-06-02 09:56:29 -07002626 public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002627 if (mService != null) {
2628 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002629 mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002630 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002631 throw e.rethrowFromSystemServer();
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002632 }
2633 }
2634 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002635
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002636 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002637 * Retrieve the current maximum number of login attempts that are allowed before the device
Rubin Xud3609d42016-07-13 18:32:57 +01002638 * or profile is wiped, for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002639 * and its participating profiles. Restrictions on profiles that have a separate challenge are
2640 * not taken into account.
2641 *
2642 * <p>This method can be called on the {@link DevicePolicyManager} instance
2643 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2644 * the value for the parent profile.
2645 *
Robin Lee25e26452015-06-02 09:56:29 -07002646 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002647 * all admins.
2648 */
Robin Lee25e26452015-06-02 09:56:29 -07002649 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002650 return getMaximumFailedPasswordsForWipe(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002651 }
2652
2653 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002654 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08002655 if (mService != null) {
2656 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002657 return mService.getMaximumFailedPasswordsForWipe(
2658 admin, userHandle, mParentInstance);
Dianne Hackborn254cb442010-01-27 19:23:59 -08002659 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002660 throw e.rethrowFromSystemServer();
Dianne Hackborn254cb442010-01-27 19:23:59 -08002661 }
2662 }
2663 return 0;
2664 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002665
Dianne Hackborn254cb442010-01-27 19:23:59 -08002666 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002667 * Returns the profile with the smallest maximum failed passwords for wipe,
2668 * for the given user. So for primary user, it might return the primary or
2669 * a managed profile. For a secondary user, it would be the same as the
2670 * user passed in.
2671 * @hide Used only by Keyguard
2672 */
2673 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
2674 if (mService != null) {
2675 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002676 return mService.getProfileWithMinimumFailedPasswordsForWipe(
2677 userHandle, mParentInstance);
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002678 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002679 throw e.rethrowFromSystemServer();
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002680 }
2681 }
2682 return UserHandle.USER_NULL;
2683 }
2684
2685 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002686 * Flag for {@link #resetPassword}: don't allow other admins to change
2687 * the password again until the user has entered it.
2688 */
2689 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002690
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002691 /**
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002692 * Flag for {@link #resetPassword}: don't ask for user credentials on device boot.
2693 * If the flag is set, the device can be booted without asking for user password.
2694 * The absence of this flag does not change the current boot requirements. This flag
2695 * can be set by the device owner only. If the app is not the device owner, the flag
2696 * is ignored. Once the flag is set, it cannot be reverted back without resetting the
2697 * device to factory defaults.
2698 */
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002699 public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002;
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002700
2701 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002702 * Force a new device unlock password (the password needed to access the entire device, not for
2703 * individual accounts) on the user. This takes effect immediately.
2704 * <p>
Rubin Xuaab7a412016-12-30 21:13:29 +00002705 * <em>For device owner and profile owners targeting SDK level
2706 * {@link android.os.Build.VERSION_CODES#O} or above, this API is no longer available and will
2707 * throw {@link SecurityException}. Please use the new API {@link #resetPasswordWithToken}
2708 * instead. </em>
2709 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002710 * <em>Note: This API has been limited as of {@link android.os.Build.VERSION_CODES#N} for
Makoto Onuki70f929e2015-11-11 12:40:15 -08002711 * device admins that are not device owner and not profile owner.
2712 * The password can now only be changed if there is currently no password set. Device owner
Ricky Wai977ade22016-05-24 15:02:41 +01002713 * and profile owner can still do this when user is unlocked and does not have a managed
2714 * profile.</em>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002715 * <p>
2716 * The given password must be sufficient for the current password quality and length constraints
2717 * as returned by {@link #getPasswordQuality(ComponentName)} and
2718 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then
2719 * it will be rejected and false returned. Note that the password may be a stronger quality
2720 * (containing alphanumeric characters when the requested quality is only numeric), in which
2721 * case the currently active quality will be increased to match.
2722 * <p>
2723 * Calling with a null or empty password will clear any existing PIN, pattern or password if the
Robin Leece5c4002016-03-23 17:05:03 +00002724 * current password constraints allow it. <em>Note: This will not work in
2725 * {@link android.os.Build.VERSION_CODES#N} and later for managed profiles, or for device admins
2726 * that are not device owner or profile owner. Once set, the password cannot be changed to null
2727 * or empty except by these admins.</em>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002728 * <p>
2729 * The calling device admin must have requested
2730 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call this method; if it has
2731 * not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002732 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01002733 * @param password The new password for the user. Null or empty clears the password.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002734 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002735 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
2736 * @return Returns true if the password was applied, or false if it is not acceptable for the
2737 * current constraints or if the user has not been decrypted yet.
2738 * @throws SecurityException if the calling application does not own an active administrator
2739 * that uses {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD}
Ricky Wai977ade22016-05-24 15:02:41 +01002740 * @throws IllegalStateException if the calling user is locked or has a managed profile.
Andrew Scull3f81f4e2016-07-29 16:29:58 +01002741 * @throws IllegalArgumentException if the password does not meet system requirements.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002742 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002743 public boolean resetPassword(String password, int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002744 throwIfParentInstance("resetPassword");
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002745 if (mService != null) {
2746 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002747 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002748 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002749 throw e.rethrowFromSystemServer();
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002750 }
2751 }
2752 return false;
2753 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002754
Dianne Hackbornd6847842010-01-12 18:14:19 -08002755 /**
Rubin Xuaab7a412016-12-30 21:13:29 +00002756 * Called by a profile or device owner to provision a token which can later be used to reset the
2757 * device lockscreen password (if called by device owner), or work challenge (if called by
2758 * profile owner), via {@link #resetPasswordWithToken}.
2759 * <p>
2760 * If the user currently has a lockscreen password, the provisioned token will not be
2761 * immediately usable; it only becomes active after the user performs a confirm credential
2762 * operation, which can be triggered by {@link KeyguardManager#createConfirmDeviceCredentialIntent}.
2763 * If the user has no lockscreen password, the token is activated immediately. In all cases,
2764 * the active state of the current token can be checked by {@link #isResetPasswordTokenActive}.
2765 * For security reasons, un-activated tokens are only stored in memory and will be lost once
2766 * the device reboots. In this case a new token needs to be provisioned again.
2767 * <p>
2768 * Once provisioned and activated, the token will remain effective even if the user changes
2769 * or clears the lockscreen password.
2770 * <p>
2771 * <em>This token is highly sensitive and should be treated at the same level as user
Rubin Xuf7b036d2017-04-05 18:37:07 +01002772 * credentials. In particular, NEVER store this token on device in plaintext. Do not store
2773 * the plaintext token in device-encrypted storage if it will be needed to reset password on
2774 * file-based encryption devices before user unlocks. Consider carefully how any password token
2775 * will be stored on your server and who will need access to them. Tokens may be the subject of
2776 * legal access requests.
Rubin Xuaab7a412016-12-30 21:13:29 +00002777 * </em>
2778 *
2779 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2780 * @param token a secure token a least 32-byte long, which must be generated by a
2781 * cryptographically strong random number generator.
2782 * @return true if the operation is successful, false otherwise.
2783 * @throws IllegalArgumentException if the supplied token is invalid.
2784 * @throws SecurityException
2785 */
2786 public boolean setResetPasswordToken(ComponentName admin, byte[] token) {
2787 throwIfParentInstance("setResetPasswordToken");
2788 if (mService != null) {
2789 try {
2790 return mService.setResetPasswordToken(admin, token);
2791 } catch (RemoteException e) {
2792 throw e.rethrowFromSystemServer();
2793 }
2794 }
2795 return false;
2796 }
2797
2798 /**
2799 * Called by a profile or device owner to revoke the current password reset token.
2800 *
2801 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2802 * @return true if the operation is successful, false otherwise.
2803 */
2804 public boolean clearResetPasswordToken(ComponentName admin) {
2805 throwIfParentInstance("clearResetPasswordToken");
2806 if (mService != null) {
2807 try {
2808 return mService.clearResetPasswordToken(admin);
2809 } catch (RemoteException e) {
2810 throw e.rethrowFromSystemServer();
2811 }
2812 }
2813 return false;
2814 }
2815
2816 /**
2817 * Called by a profile or device owner to check if the current reset password token is active.
2818 *
2819 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2820 * @return true if the token is active, false otherwise.
2821 * @throws IllegalStateException if no token has been set.
2822 */
2823 public boolean isResetPasswordTokenActive(ComponentName admin) {
2824 throwIfParentInstance("isResetPasswordTokenActive");
2825 if (mService != null) {
2826 try {
2827 return mService.isResetPasswordTokenActive(admin);
2828 } catch (RemoteException e) {
2829 throw e.rethrowFromSystemServer();
2830 }
2831 }
2832 return false;
2833 }
2834
2835 /**
2836 * Called by device or profile owner to force set a new device unlock password or a work profile
2837 * challenge on current user. This takes effect immediately.
2838 * <p>
2839 * Unlike {@link #resetPassword}, this API can change the password even before the user or
2840 * device is unlocked or decrypted. The supplied token must have been previously provisioned via
2841 * {@link #setResetPasswordToken}, and in active state {@link #isResetPasswordTokenActive}.
2842 * <p>
2843 * The given password must be sufficient for the current password quality and length constraints
2844 * as returned by {@link #getPasswordQuality(ComponentName)} and
2845 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then
2846 * it will be rejected and false returned. Note that the password may be a stronger quality
2847 * (containing alphanumeric characters when the requested quality is only numeric), in which
2848 * case the currently active quality will be increased to match.
2849 * <p>
2850 * Calling with a null or empty password will clear any existing PIN, pattern or password if the
2851 * current password constraints allow it.
2852 *
2853 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2854 * @param password The new password for the user. Null or empty clears the password.
2855 * @param token the password reset token previously provisioned by #setResetPasswordToken.
2856 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
2857 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
2858 * @return Returns true if the password was applied, or false if it is not acceptable for the
2859 * current constraints.
2860 * @throws SecurityException if the calling application does not own an active administrator
2861 * that uses {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD}
2862 * @throws IllegalStateException if the provided token is not valid.
2863 * @throws IllegalArgumentException if the password does not meet system requirements.
2864 */
2865 public boolean resetPasswordWithToken(@NonNull ComponentName admin, String password,
2866 byte[] token, int flags) {
2867 throwIfParentInstance("resetPassword");
2868 if (mService != null) {
2869 try {
2870 return mService.resetPasswordWithToken(admin, password, token, flags);
2871 } catch (RemoteException e) {
2872 throw e.rethrowFromSystemServer();
2873 }
2874 }
2875 return false;
2876 }
2877
2878 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002879 * Called by an application that is administering the device to set the maximum time for user
2880 * activity until the device will lock. This limits the length that the user can set. It takes
2881 * effect immediately.
2882 * <p>
2883 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
2884 * to be able to call this method; if it has not, a security exception will be thrown.
2885 * <p>
2886 * This method can be called on the {@link DevicePolicyManager} instance returned by
2887 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2888 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002889 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002890 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002891 * @param timeMs The new desired maximum time to lock in milliseconds. A value of 0 means there
2892 * is no restriction.
2893 * @throws SecurityException if {@code admin} is not an active administrator or it does not use
2894 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002895 */
Robin Lee25e26452015-06-02 09:56:29 -07002896 public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002897 if (mService != null) {
2898 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002899 mService.setMaximumTimeToLock(admin, timeMs, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002900 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002901 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002902 }
2903 }
2904 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002905
Dianne Hackbornd6847842010-01-12 18:14:19 -08002906 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002907 * Retrieve the current maximum time to unlock for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01002908 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00002909 * a separate challenge are not taken into account.
2910 *
2911 * <p>This method can be called on the {@link DevicePolicyManager} instance
2912 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2913 * restrictions on the parent profile.
2914 *
Robin Lee25e26452015-06-02 09:56:29 -07002915 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002916 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07002917 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07002918 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002919 */
Robin Lee25e26452015-06-02 09:56:29 -07002920 public long getMaximumTimeToLock(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002921 return getMaximumTimeToLock(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002922 }
2923
2924 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002925 public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002926 if (mService != null) {
2927 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002928 return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002929 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002930 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002931 }
2932 }
2933 return 0;
2934 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002935
Dianne Hackbornd6847842010-01-12 18:14:19 -08002936 /**
Ricky Wai035e9242016-03-18 16:43:31 +00002937 * Returns maximum time to lock that applied by all profiles in this user. We do this because we
2938 * do not have a separate timeout to lock for work challenge only.
2939 *
2940 * @hide
2941 */
2942 public long getMaximumTimeToLockForUserAndProfiles(int userHandle) {
2943 if (mService != null) {
2944 try {
2945 return mService.getMaximumTimeToLockForUserAndProfiles(userHandle);
2946 } catch (RemoteException e) {
2947 throw e.rethrowFromSystemServer();
2948 }
2949 }
2950 return 0;
2951 }
2952
2953 /**
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002954 * Called by a device/profile owner to set the timeout after which unlocking with secondary, non
2955 * strong auth (e.g. fingerprint, trust agents) times out, i.e. the user has to use a strong
2956 * authentication method like password, pin or pattern.
2957 *
2958 * <p>This timeout is used internally to reset the timer to require strong auth again after
2959 * specified timeout each time it has been successfully used.
2960 *
2961 * <p>Fingerprint can also be disabled altogether using {@link #KEYGUARD_DISABLE_FINGERPRINT}.
2962 *
2963 * <p>Trust agents can also be disabled altogether using {@link #KEYGUARD_DISABLE_TRUST_AGENTS}.
2964 *
2965 * <p>The calling device admin must be a device or profile owner. If it is not,
2966 * a {@link SecurityException} will be thrown.
2967 *
Michal Karpinski943aabd2016-10-06 11:09:25 +01002968 * <p>The calling device admin can verify the value it has set by calling
2969 * {@link #getRequiredStrongAuthTimeout(ComponentName)} and passing in its instance.
2970 *
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002971 * <p>This method can be called on the {@link DevicePolicyManager} instance returned by
2972 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2973 * profile.
2974 *
2975 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xu5d39ea72017-04-24 20:26:30 +01002976 * @param timeoutMs The new timeout in milliseconds, after which the user will have to unlock
2977 * with strong authentication method. A value of 0 means the admin is not participating
2978 * in controlling the timeout.
Michal Karpinski943aabd2016-10-06 11:09:25 +01002979 * The minimum and maximum timeouts are platform-defined and are typically 1 hour and
2980 * 72 hours, respectively. Though discouraged, the admin may choose to require strong
2981 * auth at all times using {@link #KEYGUARD_DISABLE_FINGERPRINT} and/or
2982 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002983 *
2984 * @throws SecurityException if {@code admin} is not a device or profile owner.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002985 */
2986 public void setRequiredStrongAuthTimeout(@NonNull ComponentName admin,
2987 long timeoutMs) {
2988 if (mService != null) {
2989 try {
2990 mService.setRequiredStrongAuthTimeout(admin, timeoutMs, mParentInstance);
2991 } catch (RemoteException e) {
2992 throw e.rethrowFromSystemServer();
2993 }
2994 }
2995 }
2996
2997 /**
2998 * Determine for how long the user will be able to use secondary, non strong auth for
2999 * authentication, since last strong method authentication (password, pin or pattern) was used.
3000 * After the returned timeout the user is required to use strong authentication method.
3001 *
3002 * <p>This method can be called on the {@link DevicePolicyManager} instance
3003 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
3004 * restrictions on the parent profile.
3005 *
3006 * @param admin The name of the admin component to check, or {@code null} to aggregate
3007 * accross all participating admins.
Rubin Xu5d39ea72017-04-24 20:26:30 +01003008 * @return The timeout in milliseconds or 0 if not configured for the provided admin.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01003009 */
3010 public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin) {
3011 return getRequiredStrongAuthTimeout(admin, myUserId());
3012 }
3013
3014 /** @hide per-user version */
3015 public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin, @UserIdInt int userId) {
3016 if (mService != null) {
3017 try {
3018 return mService.getRequiredStrongAuthTimeout(admin, userId, mParentInstance);
3019 } catch (RemoteException e) {
3020 throw e.rethrowFromSystemServer();
3021 }
3022 }
3023 return DEFAULT_STRONG_AUTH_TIMEOUT_MS;
3024 }
3025
3026 /**
Andrew Scull85a63bc2016-10-24 13:47:47 +01003027 * Flag for {@link #lockNow(int)}: also evict the user's credential encryption key from the
3028 * keyring. The user's credential will need to be entered again in order to derive the
3029 * credential encryption key that will be stored back in the keyring for future use.
3030 * <p>
3031 * This flag can only be used by a profile owner when locking a managed profile on an FBE
3032 * device.
3033 * <p>
3034 * In order to secure user data, the user will be stopped and restarted so apps should wait
3035 * until they are next run to perform further actions.
3036 */
3037 public static final int FLAG_EVICT_CE_KEY = 1;
3038
3039 /** @hide */
3040 @Retention(RetentionPolicy.SOURCE)
3041 @IntDef(flag=true, value={FLAG_EVICT_CE_KEY})
3042 public @interface LockNowFlag {}
3043
3044 /**
3045 * Make the device lock immediately, as if the lock screen timeout has expired at the point of
3046 * this call.
3047 * <p>
3048 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
3049 * to be able to call this method; if it has not, a security exception will be thrown.
3050 * <p>
3051 * This method can be called on the {@link DevicePolicyManager} instance returned by
3052 * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile.
3053 * <p>
3054 * Equivalent to calling {@link #lockNow(int)} with no flags.
3055 *
3056 * @throws SecurityException if the calling application does not own an active administrator
3057 * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
3058 */
3059 public void lockNow() {
3060 lockNow(0);
3061 }
3062
3063 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003064 * Make the device lock immediately, as if the lock screen timeout has expired at the point of
3065 * this call.
3066 * <p>
3067 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
3068 * to be able to call this method; if it has not, a security exception will be thrown.
3069 * <p>
3070 * This method can be called on the {@link DevicePolicyManager} instance returned by
3071 * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003072 *
Andrew Scull85a63bc2016-10-24 13:47:47 +01003073 * @param flags May be 0 or {@link #FLAG_EVICT_CE_KEY}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003074 * @throws SecurityException if the calling application does not own an active administrator
Andrew Scull85a63bc2016-10-24 13:47:47 +01003075 * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} or the
3076 * {@link #FLAG_EVICT_CE_KEY} flag is passed by an application that is not a profile
3077 * owner of a managed profile.
3078 * @throws IllegalArgumentException if the {@link #FLAG_EVICT_CE_KEY} flag is passed when
3079 * locking the parent profile.
3080 * @throws UnsupportedOperationException if the {@link #FLAG_EVICT_CE_KEY} flag is passed on a
3081 * non-FBE device.
Dianne Hackbornd6847842010-01-12 18:14:19 -08003082 */
Andrew Scull85a63bc2016-10-24 13:47:47 +01003083 public void lockNow(@LockNowFlag int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -08003084 if (mService != null) {
3085 try {
Andrew Scull85a63bc2016-10-24 13:47:47 +01003086 mService.lockNow(flags, mParentInstance);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08003087 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003088 throw e.rethrowFromSystemServer();
Dianne Hackborndf83afa2010-01-20 13:37:26 -08003089 }
3090 }
3091 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003092
Dianne Hackbornd6847842010-01-12 18:14:19 -08003093 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07003094 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00003095 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07003096 */
3097 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
3098
3099 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00003100 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
3101 * data.
3102 *
Paul Crowley2934b262014-12-02 11:21:13 +00003103 * <p>This flag may only be set by device owner admins; if it is set by
3104 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00003105 */
3106 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
3107
3108 /**
Suprabh Shukla556b05a2016-08-10 15:49:24 -07003109 * Ask that all user data be wiped. If called as a secondary user, the user will be removed and
3110 * other users will remain unaffected. Calling from the primary user will cause the device to
3111 * reboot, erasing all device data - including all the secondary users and their data - while
3112 * booting up.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003113 * <p>
3114 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to
3115 * be able to call this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003116 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003117 * @param flags Bit mask of additional options: currently supported flags are
3118 * {@link #WIPE_EXTERNAL_STORAGE} and {@link #WIPE_RESET_PROTECTION_DATA}.
3119 * @throws SecurityException if the calling application does not own an active administrator
3120 * that uses {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}
Dianne Hackbornd6847842010-01-12 18:14:19 -08003121 */
3122 public void wipeData(int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003123 throwIfParentInstance("wipeData");
Dianne Hackbornd6847842010-01-12 18:14:19 -08003124 if (mService != null) {
3125 try {
Makoto Onuki70f929e2015-11-11 12:40:15 -08003126 mService.wipeData(flags);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003127 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003128 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003129 }
3130 }
3131 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003132
Dianne Hackbornd6847842010-01-12 18:14:19 -08003133 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07003134 * Called by an application that is administering the device to set the
3135 * global proxy and exclusion list.
3136 * <p>
3137 * The calling device admin must have requested
3138 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
3139 * this method; if it has not, a security exception will be thrown.
3140 * Only the first device admin can set the proxy. If a second admin attempts
3141 * to set the proxy, the {@link ComponentName} of the admin originally setting the
Robin Lee25e26452015-06-02 09:56:29 -07003142 * proxy will be returned. If successful in setting the proxy, {@code null} will
Oscar Montemayor69238c62010-08-03 10:51:06 -07003143 * be returned.
3144 * The method can be called repeatedly by the device admin alrady setting the
3145 * proxy to update the proxy and exclusion list.
3146 *
Robin Lee25e26452015-06-02 09:56:29 -07003147 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Oscar Montemayor69238c62010-08-03 10:51:06 -07003148 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
3149 * Pass Proxy.NO_PROXY to reset the proxy.
3150 * @param exclusionList a list of domains to be excluded from the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07003151 * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName}
3152 * of the device admin that sets the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08003153 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07003154 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003155 public @Nullable ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec,
Oscar Montemayor69238c62010-08-03 10:51:06 -07003156 List<String> exclusionList ) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003157 throwIfParentInstance("setGlobalProxy");
Oscar Montemayor69238c62010-08-03 10:51:06 -07003158 if (proxySpec == null) {
3159 throw new NullPointerException();
3160 }
3161 if (mService != null) {
3162 try {
3163 String hostSpec;
3164 String exclSpec;
3165 if (proxySpec.equals(Proxy.NO_PROXY)) {
3166 hostSpec = null;
3167 exclSpec = null;
3168 } else {
3169 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
3170 throw new IllegalArgumentException();
3171 }
3172 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
3173 String hostName = sa.getHostName();
3174 int port = sa.getPort();
3175 StringBuilder hostBuilder = new StringBuilder();
3176 hostSpec = hostBuilder.append(hostName)
3177 .append(":").append(Integer.toString(port)).toString();
3178 if (exclusionList == null) {
3179 exclSpec = "";
3180 } else {
3181 StringBuilder listBuilder = new StringBuilder();
3182 boolean firstDomain = true;
3183 for (String exclDomain : exclusionList) {
3184 if (!firstDomain) {
3185 listBuilder = listBuilder.append(",");
3186 } else {
3187 firstDomain = false;
3188 }
3189 listBuilder = listBuilder.append(exclDomain.trim());
3190 }
3191 exclSpec = listBuilder.toString();
3192 }
Yuhao Zheng90704842014-02-28 17:22:45 -08003193 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
3194 != android.net.Proxy.PROXY_VALID)
3195 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07003196 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003197 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07003198 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003199 throw e.rethrowFromSystemServer();
Oscar Montemayor69238c62010-08-03 10:51:06 -07003200 }
3201 }
3202 return null;
3203 }
3204
3205 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003206 * Set a network-independent global HTTP proxy. This is not normally what you want for typical
3207 * HTTP proxies - they are generally network dependent. However if you're doing something
3208 * unusual like general internal filtering this may be useful. On a private network where the
3209 * proxy is not accessible, you may break HTTP using this.
3210 * <p>
3211 * This method requires the caller to be the device owner.
3212 * <p>
3213 * This proxy is only a recommendation and it is possible that some apps will ignore it.
Jason Monk03bc9912014-05-13 09:44:57 -04003214 *
Jason Monk03bc9912014-05-13 09:44:57 -04003215 * @see ProxyInfo
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003216 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3217 * @param proxyInfo The a {@link ProxyInfo} object defining the new global HTTP proxy. A
3218 * {@code null} value will clear the global HTTP proxy.
3219 * @throws SecurityException if {@code admin} is not the device owner.
Jason Monk03bc9912014-05-13 09:44:57 -04003220 */
Robin Lee25e26452015-06-02 09:56:29 -07003221 public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo
3222 proxyInfo) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003223 throwIfParentInstance("setRecommendedGlobalProxy");
Jason Monk03bc9912014-05-13 09:44:57 -04003224 if (mService != null) {
3225 try {
3226 mService.setRecommendedGlobalProxy(admin, proxyInfo);
3227 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003228 throw e.rethrowFromSystemServer();
Jason Monk03bc9912014-05-13 09:44:57 -04003229 }
3230 }
3231 }
3232
3233 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07003234 * Returns the component name setting the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07003235 * @return ComponentName object of the device admin that set the global proxy, or {@code null}
3236 * if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08003237 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07003238 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003239 public @Nullable ComponentName getGlobalProxyAdmin() {
Oscar Montemayor69238c62010-08-03 10:51:06 -07003240 if (mService != null) {
3241 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003242 return mService.getGlobalProxyAdmin(myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07003243 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003244 throw e.rethrowFromSystemServer();
Oscar Montemayor69238c62010-08-03 10:51:06 -07003245 }
3246 }
3247 return null;
3248 }
3249
3250 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08003251 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003252 * indicating that encryption is not supported.
3253 */
3254 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
3255
3256 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08003257 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003258 * indicating that encryption is supported, but is not currently active.
3259 */
3260 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
3261
3262 /**
Robin Lee3795fb02015-02-16 14:17:23 +00003263 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003264 * indicating that encryption is not currently active, but is currently
3265 * being activated. This is only reported by devices that support
3266 * encryption of data and only when the storage is currently
3267 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
3268 * to become encrypted will never return this value.
3269 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08003270 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003271
3272 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08003273 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003274 * indicating that encryption is active.
Amith Yamasani75db1252016-07-11 14:41:01 -07003275 * <p>
3276 * Also see {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003277 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08003278 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003279
3280 /**
Robin Lee3795fb02015-02-16 14:17:23 +00003281 * Result code for {@link #getStorageEncryptionStatus}:
3282 * indicating that encryption is active, but an encryption key has not
3283 * been set by the user.
3284 */
3285 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
3286
3287 /**
Makoto Onukid4c9e542016-02-25 18:17:30 -08003288 * Result code for {@link #getStorageEncryptionStatus}:
Amith Yamasani75db1252016-07-11 14:41:01 -07003289 * indicating that encryption is active and the encryption key is tied to the user or profile.
3290 * <p>
3291 * This value is only returned to apps targeting API level 24 and above. For apps targeting
3292 * earlier API levels, {@link #ENCRYPTION_STATUS_ACTIVE} is returned, even if the
3293 * encryption key is specific to the user or profile.
Makoto Onukid4c9e542016-02-25 18:17:30 -08003294 */
3295 public static final int ENCRYPTION_STATUS_ACTIVE_PER_USER = 5;
3296
3297 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003298 * Activity action: begin the process of encrypting data on the device. This activity should
3299 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
3300 * After resuming from this activity, use {@link #getStorageEncryption}
3301 * to check encryption status. However, on some devices this activity may never return, as
3302 * it may trigger a reboot and in some cases a complete data wipe of the device.
3303 */
3304 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
3305 public static final String ACTION_START_ENCRYPTION
3306 = "android.app.action.START_ENCRYPTION";
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003307 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07003308 * Widgets are enabled in keyguard
3309 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07003310 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07003311
3312 /**
Jim Miller50e62182014-04-23 17:25:00 -07003313 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07003314 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07003315 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
3316
3317 /**
3318 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
3319 */
3320 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
3321
3322 /**
Jim Miller50e62182014-04-23 17:25:00 -07003323 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
3324 */
3325 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
3326
3327 /**
3328 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
3329 */
3330 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
3331
3332 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02003333 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07003334 * (e.g. PIN/Pattern/Password).
3335 */
3336 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
3337
3338 /**
Jim Miller06e34502014-07-17 14:46:05 -07003339 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
3340 */
3341 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
3342
3343 /**
Adrian Roos7f06eed2016-02-05 15:21:02 -08003344 * Disable text entry into notifications on secure keyguard screens (e.g. PIN/Pattern/Password).
3345 */
3346 public static final int KEYGUARD_DISABLE_REMOTE_INPUT = 1 << 6;
3347
3348 /**
Jim Miller35207742012-11-02 15:33:20 -07003349 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07003350 */
3351 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07003352
3353 /**
Robin Leeacdeac62017-02-21 22:13:38 +00003354 * Keyguard features that when set on a managed profile that doesn't have its own challenge will
3355 * affect the profile's parent user. These can also be set on the managed profile's parent
3356 * {@link DevicePolicyManager} instance.
3357 *
3358 * @hide
3359 */
3360 public static final int PROFILE_KEYGUARD_FEATURES_AFFECT_OWNER =
3361 DevicePolicyManager.KEYGUARD_DISABLE_TRUST_AGENTS
3362 | DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT;
3363
3364 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003365 * Called by an application that is administering the device to request that the storage system
3366 * be encrypted.
3367 * <p>
3368 * When multiple device administrators attempt to control device encryption, the most secure,
3369 * supported setting will always be used. If any device administrator requests device
3370 * encryption, it will be enabled; Conversely, if a device administrator attempts to disable
3371 * device encryption while another device administrator has enabled it, the call to disable will
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003372 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003373 * <p>
3374 * This policy controls encryption of the secure (application data) storage area. Data written
3375 * to other storage areas may or may not be encrypted, and this policy does not require or
3376 * control the encryption of any other storage areas. There is one exception: If
3377 * {@link android.os.Environment#isExternalStorageEmulated()} is {@code true}, then the
3378 * directory returned by {@link android.os.Environment#getExternalStorageDirectory()} must be
3379 * written to disk within the encrypted storage area.
3380 * <p>
3381 * Important Note: On some devices, it is possible to encrypt storage without requiring the user
3382 * to create a device PIN or Password. In this case, the storage is encrypted, but the
3383 * encryption key may not be fully secured. For maximum security, the administrator should also
3384 * require (and check for) a pattern, PIN, or password.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003385 *
3386 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3387 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08003388 * @return the new request status (for all active admins) - will be one of
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003389 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
3390 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
3391 * {@link #getStorageEncryptionStatus()} to query the actual device state.
3392 * @throws SecurityException if {@code admin} is not an active administrator or does not use
3393 * {@link DeviceAdminInfo#USES_ENCRYPTED_STORAGE}
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003394 */
Robin Lee25e26452015-06-02 09:56:29 -07003395 public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003396 throwIfParentInstance("setStorageEncryption");
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003397 if (mService != null) {
3398 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003399 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003400 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003401 throw e.rethrowFromSystemServer();
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003402 }
3403 }
3404 return ENCRYPTION_STATUS_UNSUPPORTED;
3405 }
3406
3407 /**
3408 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08003409 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003410 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08003411 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
3412 * this will return the requested encryption setting as an aggregate of all active
3413 * administrators.
3414 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003415 */
Robin Lee25e26452015-06-02 09:56:29 -07003416 public boolean getStorageEncryption(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003417 throwIfParentInstance("getStorageEncryption");
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003418 if (mService != null) {
3419 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003420 return mService.getStorageEncryption(admin, myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003421 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003422 throw e.rethrowFromSystemServer();
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003423 }
3424 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08003425 return false;
3426 }
3427
3428 /**
3429 * Called by an application that is administering the device to
3430 * determine the current encryption status of the device.
Amith Yamasani75db1252016-07-11 14:41:01 -07003431 * <p>
Andy Stadler22dbfda2011-01-17 12:47:31 -08003432 * Depending on the returned status code, the caller may proceed in different
3433 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
3434 * storage system does not support encryption. If the
3435 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
3436 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00003437 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
3438 * storage system has enabled encryption but no password is set so further action
Amith Yamasani75db1252016-07-11 14:41:01 -07003439 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING},
3440 * {@link #ENCRYPTION_STATUS_ACTIVE} or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER},
3441 * no further action is required.
Andy Stadler22dbfda2011-01-17 12:47:31 -08003442 *
Robin Lee7e678712014-07-24 16:41:31 +01003443 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08003444 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00003445 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
Amith Yamasani75db1252016-07-11 14:41:01 -07003446 * {@link #ENCRYPTION_STATUS_ACTIVE}, or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08003447 */
3448 public int getStorageEncryptionStatus() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003449 throwIfParentInstance("getStorageEncryptionStatus");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003450 return getStorageEncryptionStatus(myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003451 }
3452
3453 /** @hide per-user version */
3454 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08003455 if (mService != null) {
3456 try {
Makoto Onukid4c9e542016-02-25 18:17:30 -08003457 return mService.getStorageEncryptionStatus(mContext.getPackageName(), userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08003458 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003459 throw e.rethrowFromSystemServer();
Andy Stadler22dbfda2011-01-17 12:47:31 -08003460 }
3461 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003462 return ENCRYPTION_STATUS_UNSUPPORTED;
3463 }
3464
3465 /**
Robin Lee2f7e1e42016-03-21 10:50:01 +00003466 * Mark a CA certificate as approved by the device user. This means that they have been notified
3467 * of the installation, were made aware of the risks, viewed the certificate and still wanted to
3468 * keep the certificate on the device.
3469 *
3470 * Calling with {@param approval} as {@code true} will cancel any ongoing warnings related to
3471 * this certificate.
3472 *
3473 * @hide
3474 */
3475 public boolean approveCaCert(String alias, int userHandle, boolean approval) {
3476 if (mService != null) {
3477 try {
3478 return mService.approveCaCert(alias, userHandle, approval);
3479 } catch (RemoteException e) {
3480 throw e.rethrowFromSystemServer();
3481 }
3482 }
3483 return false;
3484 }
3485
3486 /**
3487 * Check whether a CA certificate has been approved by the device user.
3488 *
3489 * @hide
3490 */
3491 public boolean isCaCertApproved(String alias, int userHandle) {
3492 if (mService != null) {
3493 try {
3494 return mService.isCaCertApproved(alias, userHandle);
3495 } catch (RemoteException e) {
3496 throw e.rethrowFromSystemServer();
3497 }
3498 }
3499 return false;
3500 }
3501
3502 /**
Robin Lee7e678712014-07-24 16:41:31 +01003503 * Installs the given certificate as a user CA.
3504 *
Edman Anjosf9946772016-11-28 16:35:15 +01003505 * The caller must be a profile or device owner on that user, or a delegate package given the
3506 * {@link #DELEGATION_CERT_INSTALL} scope via {@link #setDelegatedScopes}; otherwise a
3507 * security exception will be thrown.
3508 *
Robin Lee25e26452015-06-02 09:56:29 -07003509 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3510 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003511 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04003512 *
3513 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01003514 * interrupted, true otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003515 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3516 * owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003517 * @see #setDelegatedScopes
3518 * @see #DELEGATION_CERT_INSTALL
Maggie Benthallda51e682013-08-08 22:35:44 -04003519 */
Robin Lee25e26452015-06-02 09:56:29 -07003520 public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003521 throwIfParentInstance("installCaCert");
Maggie Benthallda51e682013-08-08 22:35:44 -04003522 if (mService != null) {
3523 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003524 return mService.installCaCert(admin, mContext.getPackageName(), certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04003525 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003526 throw e.rethrowFromSystemServer();
Maggie Benthallda51e682013-08-08 22:35:44 -04003527 }
3528 }
3529 return false;
3530 }
3531
3532 /**
Robin Lee7e678712014-07-24 16:41:31 +01003533 * Uninstalls the given certificate from trusted user CAs, if present.
3534 *
Edman Anjosf9946772016-11-28 16:35:15 +01003535 * The caller must be a profile or device owner on that user, or a delegate package given the
3536 * {@link #DELEGATION_CERT_INSTALL} scope via {@link #setDelegatedScopes}; otherwise a
3537 * security exception will be thrown.
3538 *
Robin Lee25e26452015-06-02 09:56:29 -07003539 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3540 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003541 * @param certBuffer encoded form of the certificate to remove.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003542 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3543 * owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003544 * @see #setDelegatedScopes
3545 * @see #DELEGATION_CERT_INSTALL
Maggie Benthallda51e682013-08-08 22:35:44 -04003546 */
Robin Lee25e26452015-06-02 09:56:29 -07003547 public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003548 throwIfParentInstance("uninstallCaCert");
Maggie Benthallda51e682013-08-08 22:35:44 -04003549 if (mService != null) {
3550 try {
Robin Lee306fe082014-06-19 14:04:24 +00003551 final String alias = getCaCertAlias(certBuffer);
Edman Anjosf9946772016-11-28 16:35:15 +01003552 mService.uninstallCaCerts(admin, mContext.getPackageName(), new String[] {alias});
Robin Lee306fe082014-06-19 14:04:24 +00003553 } catch (CertificateException e) {
3554 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04003555 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003556 throw e.rethrowFromSystemServer();
Maggie Benthallda51e682013-08-08 22:35:44 -04003557 }
3558 }
3559 }
3560
3561 /**
Robin Lee7e678712014-07-24 16:41:31 +01003562 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
3563 * If a user has installed any certificates by other means than device policy these will be
3564 * included too.
3565 *
Robin Lee25e26452015-06-02 09:56:29 -07003566 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3567 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003568 * @return a List of byte[] arrays, each encoding one user CA certificate.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003569 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3570 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04003571 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003572 public @NonNull List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) {
3573 final List<byte[]> certs = new ArrayList<byte[]>();
Benjamin Franzbc33c822016-04-15 08:57:52 +01003574 throwIfParentInstance("getInstalledCaCerts");
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003575 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01003576 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003577 mService.enforceCanManageCaCerts(admin, mContext.getPackageName());
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003578 final TrustedCertificateStore certStore = new TrustedCertificateStore();
3579 for (String alias : certStore.userAliases()) {
3580 try {
3581 certs.add(certStore.getCertificate(alias).getEncoded());
3582 } catch (CertificateException ce) {
3583 Log.w(TAG, "Could not encode certificate: " + alias, ce);
3584 }
3585 }
3586 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003587 throw re.rethrowFromSystemServer();
Robin Lee7e678712014-07-24 16:41:31 +01003588 }
3589 }
3590 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04003591 }
3592
3593 /**
Robin Lee7e678712014-07-24 16:41:31 +01003594 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
3595 * means other than device policy will also be removed, except for system CA certificates.
3596 *
Robin Lee25e26452015-06-02 09:56:29 -07003597 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3598 * {@code null} if calling from a delegated certificate installer.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003599 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3600 * owner.
Robin Lee7e678712014-07-24 16:41:31 +01003601 */
Robin Lee25e26452015-06-02 09:56:29 -07003602 public void uninstallAllUserCaCerts(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003603 throwIfParentInstance("uninstallAllUserCaCerts");
Robin Lee7e678712014-07-24 16:41:31 +01003604 if (mService != null) {
Robin Lee83881bd2015-06-09 16:04:38 -07003605 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003606 mService.uninstallCaCerts(admin, mContext.getPackageName(),
3607 new TrustedCertificateStore().userAliases() .toArray(new String[0]));
Robin Lee83881bd2015-06-09 16:04:38 -07003608 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003609 throw re.rethrowFromSystemServer();
Robin Lee7e678712014-07-24 16:41:31 +01003610 }
3611 }
3612 }
3613
3614 /**
3615 * Returns whether this certificate is installed as a trusted CA.
3616 *
Robin Lee25e26452015-06-02 09:56:29 -07003617 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3618 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003619 * @param certBuffer encoded form of the certificate to look up.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003620 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3621 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04003622 */
Robin Lee25e26452015-06-02 09:56:29 -07003623 public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003624 throwIfParentInstance("hasCaCertInstalled");
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003625 if (mService != null) {
3626 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003627 mService.enforceCanManageCaCerts(admin, mContext.getPackageName());
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003628 return getCaCertAlias(certBuffer) != null;
3629 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003630 throw re.rethrowFromSystemServer();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003631 } catch (CertificateException ce) {
3632 Log.w(TAG, "Could not parse certificate", ce);
3633 }
Maggie Benthallda51e682013-08-08 22:35:44 -04003634 }
3635 return false;
3636 }
3637
3638 /**
Robin Leece3399f2016-02-24 12:08:32 +00003639 * Called by a device or profile owner, or delegated certificate installer, to install a
3640 * certificate and corresponding private key. All apps within the profile will be able to access
3641 * the certificate and use the private key, given direct user approval.
3642 *
3643 * <p>Access to the installed credentials will not be granted to the caller of this API without
3644 * direct user approval. This is for security - should a certificate installer become
3645 * compromised, certificates it had already installed will be protected.
3646 *
3647 * <p>If the installer must have access to the credentials, call
Rubin Xub4365912016-03-23 12:13:22 +00003648 * {@link #installKeyPair(ComponentName, PrivateKey, Certificate[], String, boolean)} instead.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003649 *
Robin Lee25e26452015-06-02 09:56:29 -07003650 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3651 * {@code null} if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003652 * @param privKey The private key to install.
3653 * @param cert The certificate to install.
3654 * @param alias The private key alias under which to install the certificate. If a certificate
3655 * with that alias already exists, it will be overwritten.
3656 * @return {@code true} if the keys were installed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003657 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3658 * owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003659 * @see #setDelegatedScopes
3660 * @see #DELEGATION_CERT_INSTALL
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003661 */
Robin Leefbc65642015-08-03 16:21:22 +01003662 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
3663 @NonNull Certificate cert, @NonNull String alias) {
Rubin Xub4365912016-03-23 12:13:22 +00003664 return installKeyPair(admin, privKey, new Certificate[] {cert}, alias, false);
Robin Leece3399f2016-02-24 12:08:32 +00003665 }
3666
3667 /**
3668 * Called by a device or profile owner, or delegated certificate installer, to install a
Rubin Xub4365912016-03-23 12:13:22 +00003669 * certificate chain and corresponding private key for the leaf certificate. All apps within the
3670 * profile will be able to access the certificate chain and use the private key, given direct
3671 * user approval.
Robin Leece3399f2016-02-24 12:08:32 +00003672 *
Robin Leea1b290e2016-03-09 14:38:36 +00003673 * <p>The caller of this API may grant itself access to the certificate and private key
3674 * immediately, without user approval. It is a best practice not to request this unless strictly
3675 * necessary since it opens up additional security vulnerabilities.
Robin Leece3399f2016-02-24 12:08:32 +00003676 *
3677 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Robin Leea1b290e2016-03-09 14:38:36 +00003678 * {@code null} if calling from a delegated certificate installer.
Robin Leece3399f2016-02-24 12:08:32 +00003679 * @param privKey The private key to install.
Rubin Xub4365912016-03-23 12:13:22 +00003680 * @param certs The certificate chain to install. The chain should start with the leaf
3681 * certificate and include the chain of trust in order. This will be returned by
3682 * {@link android.security.KeyChain#getCertificateChain}.
Robin Leece3399f2016-02-24 12:08:32 +00003683 * @param alias The private key alias under which to install the certificate. If a certificate
Robin Leea1b290e2016-03-09 14:38:36 +00003684 * with that alias already exists, it will be overwritten.
Robin Leece3399f2016-02-24 12:08:32 +00003685 * @param requestAccess {@code true} to request that the calling app be granted access to the
Robin Leea1b290e2016-03-09 14:38:36 +00003686 * credentials immediately. Otherwise, access to the credentials will be gated by user
3687 * approval.
Robin Leece3399f2016-02-24 12:08:32 +00003688 * @return {@code true} if the keys were installed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003689 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3690 * owner.
Rubin Xub4365912016-03-23 12:13:22 +00003691 * @see android.security.KeyChain#getCertificateChain
Edman Anjosf9946772016-11-28 16:35:15 +01003692 * @see #setDelegatedScopes
3693 * @see #DELEGATION_CERT_INSTALL
Robin Leece3399f2016-02-24 12:08:32 +00003694 */
3695 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
Rubin Xub4365912016-03-23 12:13:22 +00003696 @NonNull Certificate[] certs, @NonNull String alias, boolean requestAccess) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003697 throwIfParentInstance("installKeyPair");
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003698 try {
Rubin Xub4365912016-03-23 12:13:22 +00003699 final byte[] pemCert = Credentials.convertToPem(certs[0]);
3700 byte[] pemChain = null;
3701 if (certs.length > 1) {
3702 pemChain = Credentials.convertToPem(Arrays.copyOfRange(certs, 1, certs.length));
3703 }
Robin Lee0d5ccb72014-09-12 17:41:44 +01003704 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
3705 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
Edman Anjosf9946772016-11-28 16:35:15 +01003706 return mService.installKeyPair(admin, mContext.getPackageName(), pkcs8Key, pemCert,
3707 pemChain, alias, requestAccess);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003708 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003709 throw e.rethrowFromSystemServer();
Robin Lee0d5ccb72014-09-12 17:41:44 +01003710 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
3711 Log.w(TAG, "Failed to obtain private key material", e);
3712 } catch (CertificateException | IOException e) {
3713 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003714 }
3715 return false;
3716 }
3717
3718 /**
Robin Leea1b290e2016-03-09 14:38:36 +00003719 * Called by a device or profile owner, or delegated certificate installer, to remove a
3720 * certificate and private key pair installed under a given alias.
Robin Leefbc65642015-08-03 16:21:22 +01003721 *
3722 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Robin Leea1b290e2016-03-09 14:38:36 +00003723 * {@code null} if calling from a delegated certificate installer.
Robin Leefbc65642015-08-03 16:21:22 +01003724 * @param alias The private key alias under which the certificate is installed.
Robin Leea1b290e2016-03-09 14:38:36 +00003725 * @return {@code true} if the private key alias no longer exists, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003726 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3727 * owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003728 * @see #setDelegatedScopes
3729 * @see #DELEGATION_CERT_INSTALL
Robin Leefbc65642015-08-03 16:21:22 +01003730 */
3731 public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003732 throwIfParentInstance("removeKeyPair");
Robin Leefbc65642015-08-03 16:21:22 +01003733 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003734 return mService.removeKeyPair(admin, mContext.getPackageName(), alias);
Robin Leefbc65642015-08-03 16:21:22 +01003735 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003736 throw e.rethrowFromSystemServer();
Robin Leefbc65642015-08-03 16:21:22 +01003737 }
Robin Leefbc65642015-08-03 16:21:22 +01003738 }
3739
3740 /**
Robin Lee25e26452015-06-02 09:56:29 -07003741 * @return the alias of a given CA certificate in the certificate store, or {@code null} if it
Robin Lee306fe082014-06-19 14:04:24 +00003742 * doesn't exist.
3743 */
3744 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
3745 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
3746 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
3747 new ByteArrayInputStream(certBuffer));
3748 return new TrustedCertificateStore().getCertificateAlias(cert);
3749 }
3750
3751 /**
Rubin Xuec32b562015-03-03 17:34:05 +00003752 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01003753 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00003754 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01003755 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00003756 * <p>
3757 * Delegated certificate installer is a per-user state. The delegated access is persistent until
3758 * it is later cleared by calling this method with a null value or uninstallling the certificate
3759 * installer.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003760 * <p>
Rubin Xuf03d0a62016-02-10 14:54:15 +00003761 * <b>Note:</b>Starting from {@link android.os.Build.VERSION_CODES#N}, if the caller
3762 * application's target SDK version is {@link android.os.Build.VERSION_CODES#N} or newer, the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003763 * supplied certificate installer package must be installed when calling this API, otherwise an
3764 * {@link IllegalArgumentException} will be thrown.
Rubin Xuec32b562015-03-03 17:34:05 +00003765 *
Robin Lee25e26452015-06-02 09:56:29 -07003766 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xuec32b562015-03-03 17:34:05 +00003767 * @param installerPackage The package name of the certificate installer which will be given
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003768 * access. If {@code null} is given the current package will be cleared.
3769 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003770 *
3771 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #setDelegatedScopes}
3772 * with the {@link #DELEGATION_CERT_INSTALL} scope instead.
Rubin Xuec32b562015-03-03 17:34:05 +00003773 */
Edman Anjosf9946772016-11-28 16:35:15 +01003774 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07003775 public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String
3776 installerPackage) throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003777 throwIfParentInstance("setCertInstallerPackage");
Rubin Xuec32b562015-03-03 17:34:05 +00003778 if (mService != null) {
3779 try {
Robin Lee25e26452015-06-02 09:56:29 -07003780 mService.setCertInstallerPackage(admin, installerPackage);
Rubin Xuec32b562015-03-03 17:34:05 +00003781 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003782 throw e.rethrowFromSystemServer();
Rubin Xuec32b562015-03-03 17:34:05 +00003783 }
3784 }
3785 }
3786
3787 /**
Edman Anjosf9946772016-11-28 16:35:15 +01003788 * Called by a profile owner or device owner to retrieve the certificate installer for the user,
3789 * or {@code null} if none is set. If there are multiple delegates this function will return one
3790 * of them.
Rubin Xuec32b562015-03-03 17:34:05 +00003791 *
Robin Lee25e26452015-06-02 09:56:29 -07003792 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003793 * @return The package name of the current delegated certificate installer, or {@code null} if
3794 * none is set.
3795 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003796 *
3797 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatePackages}
3798 * with the {@link #DELEGATION_CERT_INSTALL} scope instead.
Rubin Xuec32b562015-03-03 17:34:05 +00003799 */
Edman Anjosf9946772016-11-28 16:35:15 +01003800 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07003801 public @Nullable String getCertInstallerPackage(@NonNull ComponentName admin)
3802 throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003803 throwIfParentInstance("getCertInstallerPackage");
Rubin Xuec32b562015-03-03 17:34:05 +00003804 if (mService != null) {
3805 try {
Robin Lee25e26452015-06-02 09:56:29 -07003806 return mService.getCertInstallerPackage(admin);
Rubin Xuec32b562015-03-03 17:34:05 +00003807 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003808 throw e.rethrowFromSystemServer();
Rubin Xuec32b562015-03-03 17:34:05 +00003809 }
3810 }
3811 return null;
3812 }
3813
3814 /**
Edman Anjosf9946772016-11-28 16:35:15 +01003815 * Called by a profile owner or device owner to grant access to privileged APIs to another app.
3816 * Granted APIs are determined by {@code scopes}, which is a list of the {@code DELEGATION_*}
3817 * constants.
3818 * <p>
Edman Anjos9e62c312017-01-26 22:22:58 +01003819 * A broadcast with the {@link #ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED} action will be
3820 * sent to the {@code delegatePackage} with its new scopes in an {@code ArrayList<String>} extra
3821 * under the {@link #EXTRA_DELEGATION_SCOPES} key. The broadcast is sent with the
3822 * {@link Intent#FLAG_RECEIVER_REGISTERED_ONLY} flag.
3823 * <p>
Edman Anjosf9946772016-11-28 16:35:15 +01003824 * Delegated scopes are a per-user state. The delegated access is persistent until it is later
3825 * cleared by calling this method with an empty {@code scopes} list or uninstalling the
3826 * {@code delegatePackage}.
3827 *
3828 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3829 * @param delegatePackage The package name of the app which will be given access.
3830 * @param scopes The groups of privileged APIs whose access should be granted to
3831 * {@code delegatedPackage}.
3832 * @throws SecurityException if {@code admin} is not a device or a profile owner.
3833 */
3834 public void setDelegatedScopes(@NonNull ComponentName admin, @NonNull String delegatePackage,
3835 @NonNull List<String> scopes) {
3836 throwIfParentInstance("setDelegatedScopes");
3837 if (mService != null) {
3838 try {
3839 mService.setDelegatedScopes(admin, delegatePackage, scopes);
3840 } catch (RemoteException e) {
3841 throw e.rethrowFromSystemServer();
3842 }
3843 }
3844 }
3845
3846 /**
3847 * Called by a profile owner or device owner to retrieve a list of the scopes given to a
3848 * delegate package. Other apps can use this method to retrieve their own delegated scopes by
3849 * passing {@code null} for {@code admin} and their own package name as
3850 * {@code delegatedPackage}.
3851 *
3852 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3853 * {@code null} if the caller is {@code delegatedPackage}.
3854 * @param delegatedPackage The package name of the app whose scopes should be retrieved.
3855 * @return A list containing the scopes given to {@code delegatedPackage}.
3856 * @throws SecurityException if {@code admin} is not a device or a profile owner.
3857 */
3858 @NonNull
Edman Anjos9e62c312017-01-26 22:22:58 +01003859 public List<String> getDelegatedScopes(@Nullable ComponentName admin,
Edman Anjosf9946772016-11-28 16:35:15 +01003860 @NonNull String delegatedPackage) {
3861 throwIfParentInstance("getDelegatedScopes");
3862 if (mService != null) {
3863 try {
3864 return mService.getDelegatedScopes(admin, delegatedPackage);
3865 } catch (RemoteException e) {
3866 throw e.rethrowFromSystemServer();
3867 }
3868 }
3869 return null;
3870 }
3871
3872 /**
3873 * Called by a profile owner or device owner to retrieve a list of delegate packages that were
3874 * granted a delegation scope.
3875 *
3876 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3877 * @param delegationScope The scope whose delegates should be retrieved.
3878 * @return A list of package names of the current delegated packages for
3879 {@code delegationScope}.
3880 * @throws SecurityException if {@code admin} is not a device or a profile owner.
3881 */
3882 @Nullable
3883 public List<String> getDelegatePackages(@NonNull ComponentName admin,
3884 @NonNull String delegationScope) {
3885 throwIfParentInstance("getDelegatePackages");
3886 if (mService != null) {
3887 try {
3888 return mService.getDelegatePackages(admin, delegationScope);
3889 } catch (RemoteException e) {
3890 throw e.rethrowFromSystemServer();
3891 }
3892 }
3893 return null;
3894 }
3895
3896 /**
Robin Lee244ce8e2016-01-05 18:03:46 +00003897 * Called by a device or profile owner to configure an always-on VPN connection through a
Robin Leedc679712016-05-03 13:23:03 +01003898 * specific application for the current user.
3899 *
3900 * @deprecated this version only exists for compability with previous developer preview builds.
3901 * TODO: delete once there are no longer any live references.
3902 * @hide
3903 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07003904 @Deprecated
Robin Leedc679712016-05-03 13:23:03 +01003905 public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage)
3906 throws NameNotFoundException, UnsupportedOperationException {
3907 setAlwaysOnVpnPackage(admin, vpnPackage, /* lockdownEnabled */ true);
3908 }
3909
3910 /**
3911 * Called by a device or profile owner to configure an always-on VPN connection through a
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003912 * specific application for the current user. This connection is automatically granted and
3913 * persisted after a reboot.
3914 * <p>
3915 * The designated package should declare a {@link android.net.VpnService} in its manifest
3916 * guarded by {@link android.Manifest.permission#BIND_VPN_SERVICE}, otherwise the call will
3917 * fail.
Robin Lee244ce8e2016-01-05 18:03:46 +00003918 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003919 * @param vpnPackage The package name for an installed VPN app on the device, or {@code null} to
Robin Leedc679712016-05-03 13:23:03 +01003920 * remove an existing always-on VPN configuration.
3921 * @param lockdownEnabled {@code true} to disallow networking when the VPN is not connected or
3922 * {@code false} otherwise. This carries the risk that any failure of the VPN provider
3923 * could break networking for all apps. This has no effect when clearing.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003924 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Robin Leeee5eb932016-04-05 16:27:15 +01003925 * @throws NameNotFoundException if {@code vpnPackage} is not installed.
3926 * @throws UnsupportedOperationException if {@code vpnPackage} exists but does not support being
3927 * set as always-on, or if always-on VPN is not available.
Robin Lee244ce8e2016-01-05 18:03:46 +00003928 */
Robin Leedc679712016-05-03 13:23:03 +01003929 public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage,
3930 boolean lockdownEnabled)
Robin Leeee5eb932016-04-05 16:27:15 +01003931 throws NameNotFoundException, UnsupportedOperationException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003932 throwIfParentInstance("setAlwaysOnVpnPackage");
Robin Lee244ce8e2016-01-05 18:03:46 +00003933 if (mService != null) {
3934 try {
Robin Leedc679712016-05-03 13:23:03 +01003935 if (!mService.setAlwaysOnVpnPackage(admin, vpnPackage, lockdownEnabled)) {
Robin Leeee5eb932016-04-05 16:27:15 +01003936 throw new NameNotFoundException(vpnPackage);
3937 }
Robin Lee244ce8e2016-01-05 18:03:46 +00003938 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003939 throw e.rethrowFromSystemServer();
Robin Lee244ce8e2016-01-05 18:03:46 +00003940 }
3941 }
Robin Lee244ce8e2016-01-05 18:03:46 +00003942 }
3943
3944 /**
3945 * Called by a device or profile owner to read the name of the package administering an
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003946 * always-on VPN connection for the current user. If there is no such package, or the always-on
3947 * VPN is provided by the system instead of by an application, {@code null} will be returned.
Robin Lee244ce8e2016-01-05 18:03:46 +00003948 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003949 * @return Package name of VPN controller responsible for always-on VPN, or {@code null} if none
3950 * is set.
3951 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Robin Lee244ce8e2016-01-05 18:03:46 +00003952 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003953 public @Nullable String getAlwaysOnVpnPackage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003954 throwIfParentInstance("getAlwaysOnVpnPackage");
Robin Lee244ce8e2016-01-05 18:03:46 +00003955 if (mService != null) {
3956 try {
3957 return mService.getAlwaysOnVpnPackage(admin);
3958 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003959 throw e.rethrowFromSystemServer();
Robin Lee244ce8e2016-01-05 18:03:46 +00003960 }
3961 }
3962 return null;
3963 }
3964
3965 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003966 * Called by an application that is administering the device to disable all cameras on the
3967 * device, for this user. After setting this, no applications running as this user will be able
3968 * to access any cameras on the device.
3969 * <p>
3970 * If the caller is device owner, then the restriction will be applied to all users.
3971 * <p>
3972 * The calling device admin must have requested
3973 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call this method; if it has
3974 * not, a security exception will be thrown.
Ben Komalo2447edd2011-05-09 16:05:33 -07003975 *
3976 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3977 * @param disabled Whether or not the camera should be disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003978 * @throws SecurityException if {@code admin} is not an active administrator or does not use
3979 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA}.
Ben Komalo2447edd2011-05-09 16:05:33 -07003980 */
Robin Lee25e26452015-06-02 09:56:29 -07003981 public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003982 throwIfParentInstance("setCameraDisabled");
Ben Komalo2447edd2011-05-09 16:05:33 -07003983 if (mService != null) {
3984 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003985 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07003986 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003987 throw e.rethrowFromSystemServer();
Ben Komalo2447edd2011-05-09 16:05:33 -07003988 }
3989 }
3990 }
3991
3992 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07003993 * Determine whether or not the device's cameras have been disabled for this user,
Makoto Onuki32b30572015-12-11 14:29:51 -08003994 * either by the calling admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07003995 * @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 -07003996 * have disabled the camera
3997 */
Robin Lee25e26452015-06-02 09:56:29 -07003998 public boolean getCameraDisabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003999 throwIfParentInstance("getCameraDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004000 return getCameraDisabled(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004001 }
4002
4003 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07004004 public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07004005 if (mService != null) {
4006 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004007 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07004008 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004009 throw e.rethrowFromSystemServer();
Ben Komalo2447edd2011-05-09 16:05:33 -07004010 }
4011 }
4012 return false;
4013 }
4014
4015 /**
Michal Karpinski3fc437e2015-12-15 10:09:00 +00004016 * Called by a device owner to request a bugreport.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004017 * <p>
Esteban Talaverad36dd152016-12-15 08:51:45 +00004018 * If the device contains secondary users or profiles, they must be affiliated with the device
4019 * owner user. Otherwise a {@link SecurityException} will be thrown. See
4020 * {@link #setAffiliationIds}.
Michal Karpinski3fc437e2015-12-15 10:09:00 +00004021 *
4022 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004023 * @return {@code true} if the bugreport collection started successfully, or {@code false} if it
4024 * wasn't triggered because a previous bugreport operation is still active (either the
4025 * bugreport is still running or waiting for the user to share or decline)
Esteban Talaverad36dd152016-12-15 08:51:45 +00004026 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
4027 * profile or secondary user that is not affiliated with the device owner user.
Michal Karpinski3fc437e2015-12-15 10:09:00 +00004028 */
4029 public boolean requestBugreport(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004030 throwIfParentInstance("requestBugreport");
Michal Karpinski3fc437e2015-12-15 10:09:00 +00004031 if (mService != null) {
4032 try {
4033 return mService.requestBugreport(admin);
4034 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004035 throw e.rethrowFromSystemServer();
Michal Karpinski3fc437e2015-12-15 10:09:00 +00004036 }
4037 }
4038 return false;
4039 }
4040
4041 /**
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07004042 * Determine whether or not creating a guest user has been disabled for the device
4043 *
4044 * @hide
4045 */
4046 public boolean getGuestUserDisabled(@Nullable ComponentName admin) {
4047 // Currently guest users can always be created if multi-user is enabled
4048 // TODO introduce a policy for guest user creation
4049 return false;
4050 }
4051
4052 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01004053 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
4054 * screen capture also prevents the content from being shown on display devices that do not have
4055 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
4056 * secure surfaces and secure displays.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004057 * <p>
4058 * The calling device admin must be a device or profile owner. If it is not, a security
4059 * exception will be thrown.
4060 * <p>
4061 * From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also blocks
4062 * assist requests for all activities of the relevant user.
Benjamin Franzc200f442015-06-25 18:20:04 +01004063 *
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004064 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004065 * @param disabled Whether screen capture is disabled or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004066 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004067 */
Robin Lee25e26452015-06-02 09:56:29 -07004068 public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004069 throwIfParentInstance("setScreenCaptureDisabled");
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004070 if (mService != null) {
4071 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08004072 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004073 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004074 throw e.rethrowFromSystemServer();
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004075 }
4076 }
4077 }
4078
4079 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004080 * Determine whether or not screen capture has been disabled by the calling
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004081 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07004082 * @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 +01004083 * have disabled screen capture.
4084 */
Robin Lee25e26452015-06-02 09:56:29 -07004085 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004086 throwIfParentInstance("getScreenCaptureDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004087 return getScreenCaptureDisabled(admin, myUserId());
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004088 }
4089
4090 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07004091 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004092 if (mService != null) {
4093 try {
4094 return mService.getScreenCaptureDisabled(admin, userHandle);
4095 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004096 throw e.rethrowFromSystemServer();
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004097 }
4098 }
4099 return false;
4100 }
4101
4102 /**
Jason Parks841cb0a2017-01-17 15:25:17 -06004103 * Called by a device or profile owner to set whether auto time is required. If auto time is
4104 * required, no user will be able set the date and time and network date and time will be used.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004105 * <p>
4106 * Note: if auto time is required the user can still manually set the time zone.
4107 * <p>
Jason Parks841cb0a2017-01-17 15:25:17 -06004108 * The calling device admin must be a device or profile owner. If it is not, a security
4109 * exception will be thrown.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004110 *
4111 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4112 * @param required Whether auto time is set required or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004113 * @throws SecurityException if {@code admin} is not a device owner.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004114 */
Robin Lee25e26452015-06-02 09:56:29 -07004115 public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004116 throwIfParentInstance("setAutoTimeRequired");
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004117 if (mService != null) {
4118 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08004119 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004120 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004121 throw e.rethrowFromSystemServer();
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004122 }
4123 }
4124 }
4125
4126 /**
4127 * @return true if auto time is required.
4128 */
4129 public boolean getAutoTimeRequired() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004130 throwIfParentInstance("getAutoTimeRequired");
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004131 if (mService != null) {
4132 try {
4133 return mService.getAutoTimeRequired();
4134 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004135 throw e.rethrowFromSystemServer();
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004136 }
4137 }
4138 return false;
4139 }
4140
4141 /**
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004142 * Called by a device owner to set whether all users created on the device should be ephemeral.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004143 * <p>
4144 * The system user is exempt from this policy - it is never ephemeral.
4145 * <p>
4146 * The calling device admin must be the device owner. If it is not, a security exception will be
4147 * thrown.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004148 *
4149 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4150 * @param forceEphemeralUsers If true, all the existing users will be deleted and all
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004151 * subsequently created users will be ephemeral.
4152 * @throws SecurityException if {@code admin} is not a device owner.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004153 * @hide
4154 */
4155 public void setForceEphemeralUsers(
4156 @NonNull ComponentName admin, boolean forceEphemeralUsers) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004157 throwIfParentInstance("setForceEphemeralUsers");
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004158 if (mService != null) {
4159 try {
4160 mService.setForceEphemeralUsers(admin, forceEphemeralUsers);
4161 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004162 throw e.rethrowFromSystemServer();
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004163 }
4164 }
4165 }
4166
4167 /**
4168 * @return true if all users are created ephemeral.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004169 * @throws SecurityException if {@code admin} is not a device owner.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004170 * @hide
4171 */
4172 public boolean getForceEphemeralUsers(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004173 throwIfParentInstance("getForceEphemeralUsers");
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004174 if (mService != null) {
4175 try {
4176 return mService.getForceEphemeralUsers(admin);
4177 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004178 throw e.rethrowFromSystemServer();
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004179 }
4180 }
4181 return false;
4182 }
4183
4184 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07004185 * Called by an application that is administering the device to disable keyguard customizations,
4186 * such as widgets. After setting this, keyguard features will be disabled according to the
4187 * provided feature list.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004188 * <p>
4189 * The calling device admin must have requested
4190 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method;
4191 * if it has not, a security exception will be thrown.
4192 * <p>
4193 * Calling this from a managed profile before version {@link android.os.Build.VERSION_CODES#M}
4194 * will throw a security exception. From version {@link android.os.Build.VERSION_CODES#M} the
4195 * profile owner of a managed profile can set:
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00004196 * <ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00004197 * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which affects the parent user, but only if there
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004198 * is no separate challenge set on the managed profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00004199 * <li>{@link #KEYGUARD_DISABLE_FINGERPRINT} which affects the managed profile challenge if
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004200 * there is one, or the parent user otherwise.
4201 * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} which affects notifications generated
4202 * by applications in the managed profile.
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00004203 * </ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00004204 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} and {@link #KEYGUARD_DISABLE_FINGERPRINT} can also be
4205 * set on the {@link DevicePolicyManager} instance returned by
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004206 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
4207 * profile.
4208 * <p>
4209 * Requests to disable other features on a managed profile will be ignored.
4210 * <p>
4211 * The admin can check which features have been disabled by calling
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00004212 * {@link #getKeyguardDisabledFeatures(ComponentName)}
Amith Yamasani242f4b12014-10-14 16:06:13 -07004213 *
Jim Millerb8ec4702012-08-31 17:19:10 -07004214 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07004215 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004216 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
4217 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS},
4218 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
4219 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS},
4220 * {@link #KEYGUARD_DISABLE_FINGERPRINT}, {@link #KEYGUARD_DISABLE_FEATURES_ALL}
4221 * @throws SecurityException if {@code admin} is not an active administrator or does not user
4222 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES}
Jim Millerb8ec4702012-08-31 17:19:10 -07004223 */
Robin Lee25e26452015-06-02 09:56:29 -07004224 public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07004225 if (mService != null) {
4226 try {
Esteban Talavera62399912016-01-11 15:37:55 +00004227 mService.setKeyguardDisabledFeatures(admin, which, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07004228 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004229 throw e.rethrowFromSystemServer();
Jim Millerb8ec4702012-08-31 17:19:10 -07004230 }
4231 }
4232 }
4233
4234 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004235 * Determine whether or not features have been disabled in keyguard either by the calling
Rubin Xud3609d42016-07-13 18:32:57 +01004236 * admin, if specified, or all admins that set restrictions on this user and its participating
Esteban Talaverac1c83592016-02-17 17:56:15 +00004237 * profiles. Restrictions on profiles that have a separate challenge are not taken into account.
4238 *
4239 * <p>This method can be called on the {@link DevicePolicyManager} instance
4240 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
4241 * restrictions on the parent profile.
4242 *
Esteban Talavera62399912016-01-11 15:37:55 +00004243 * @param admin The name of the admin component to check, or {@code null} to check whether any
4244 * admins have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07004245 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
4246 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07004247 */
Robin Lee25e26452015-06-02 09:56:29 -07004248 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004249 return getKeyguardDisabledFeatures(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004250 }
4251
4252 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07004253 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07004254 if (mService != null) {
4255 try {
Esteban Talavera62399912016-01-11 15:37:55 +00004256 return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07004257 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004258 throw e.rethrowFromSystemServer();
Jim Millerb8ec4702012-08-31 17:19:10 -07004259 }
4260 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07004261 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07004262 }
4263
4264 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08004265 * @hide
4266 */
Robin Lee25e26452015-06-02 09:56:29 -07004267 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
4268 int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08004269 if (mService != null) {
4270 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01004271 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08004272 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004273 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08004274 }
4275 }
4276 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07004277
Dianne Hackbornd6847842010-01-12 18:14:19 -08004278 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01004279 * @hide
4280 */
Robin Lee25e26452015-06-02 09:56:29 -07004281 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004282 setActiveAdmin(policyReceiver, refreshing, myUserId());
Jessica Hummel6d36b602014-04-04 12:42:17 +01004283 }
4284
4285 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08004286 * @hide
4287 */
Robin Lee25e26452015-06-02 09:56:29 -07004288 public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08004289 if (mService != null) {
4290 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004291 mService.getRemoveWarning(admin, result, myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08004292 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004293 throw e.rethrowFromSystemServer();
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08004294 }
4295 }
4296 }
4297
4298 /**
4299 * @hide
4300 */
Andrew Scull5f9e6f32016-08-02 14:22:17 +01004301 public void setActivePasswordState(PasswordMetrics metrics, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08004302 if (mService != null) {
4303 try {
Andrew Scull5f9e6f32016-08-02 14:22:17 +01004304 mService.setActivePasswordState(metrics, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08004305 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004306 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08004307 }
4308 }
4309 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07004310
Dianne Hackbornd6847842010-01-12 18:14:19 -08004311 /**
4312 * @hide
4313 */
Andrew Scull5daf2732016-11-14 15:02:45 +00004314 public void reportPasswordChanged(@UserIdInt int userId) {
4315 if (mService != null) {
4316 try {
4317 mService.reportPasswordChanged(userId);
4318 } catch (RemoteException e) {
4319 throw e.rethrowFromSystemServer();
4320 }
4321 }
4322 }
4323
4324 /**
4325 * @hide
4326 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004327 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08004328 if (mService != null) {
4329 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004330 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08004331 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004332 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08004333 }
4334 }
4335 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07004336
Dianne Hackbornd6847842010-01-12 18:14:19 -08004337 /**
4338 * @hide
4339 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004340 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08004341 if (mService != null) {
4342 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004343 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08004344 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004345 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08004346 }
4347 }
4348 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07004349
4350 /**
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004351 * @hide
4352 */
4353 public void reportFailedFingerprintAttempt(int userHandle) {
4354 if (mService != null) {
4355 try {
4356 mService.reportFailedFingerprintAttempt(userHandle);
4357 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004358 throw e.rethrowFromSystemServer();
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004359 }
4360 }
4361 }
4362
4363 /**
4364 * @hide
4365 */
4366 public void reportSuccessfulFingerprintAttempt(int userHandle) {
4367 if (mService != null) {
4368 try {
4369 mService.reportSuccessfulFingerprintAttempt(userHandle);
4370 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004371 throw e.rethrowFromSystemServer();
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004372 }
4373 }
4374 }
4375
4376 /**
Michal Karpinski31502d32016-01-25 16:43:07 +00004377 * Should be called when keyguard has been dismissed.
4378 * @hide
4379 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004380 public void reportKeyguardDismissed(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00004381 if (mService != null) {
4382 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004383 mService.reportKeyguardDismissed(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00004384 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004385 throw e.rethrowFromSystemServer();
Michal Karpinski31502d32016-01-25 16:43:07 +00004386 }
4387 }
4388 }
4389
4390 /**
4391 * Should be called when keyguard view has been shown to the user.
4392 * @hide
4393 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004394 public void reportKeyguardSecured(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00004395 if (mService != null) {
4396 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004397 mService.reportKeyguardSecured(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00004398 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004399 throw e.rethrowFromSystemServer();
Michal Karpinski31502d32016-01-25 16:43:07 +00004400 }
4401 }
4402 }
4403
4404 /**
Amith Yamasani71e6c692013-03-24 17:39:28 -07004405 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00004406 * Sets the given package as the device owner.
Makoto Onukia52562c2015-10-01 16:12:31 -07004407 * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name.
4408 * @param who the component name to be registered as device owner.
Amith Yamasani71e6c692013-03-24 17:39:28 -07004409 * @return whether the package was successfully registered as the device owner.
4410 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00004411 * @throws IllegalStateException If the preconditions mentioned are not met.
Amith Yamasani71e6c692013-03-24 17:39:28 -07004412 */
Makoto Onukia52562c2015-10-01 16:12:31 -07004413 public boolean setDeviceOwner(ComponentName who) {
4414 return setDeviceOwner(who, null);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004415 }
4416
4417 /**
4418 * @hide
Makoto Onuki58b684f2015-09-04 10:48:16 -07004419 */
Makoto Onukia52562c2015-10-01 16:12:31 -07004420 public boolean setDeviceOwner(ComponentName who, int userId) {
4421 return setDeviceOwner(who, null, userId);
Makoto Onuki58b684f2015-09-04 10:48:16 -07004422 }
4423
4424 /**
4425 * @hide
4426 */
Makoto Onukia52562c2015-10-01 16:12:31 -07004427 public boolean setDeviceOwner(ComponentName who, String ownerName) {
4428 return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM);
Makoto Onuki58b684f2015-09-04 10:48:16 -07004429 }
4430
4431 /**
4432 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00004433 * Sets the given package as the device owner. The package must already be installed. There
4434 * must not already be a device owner.
4435 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
4436 * this method.
4437 * Calling this after the setup phase of the primary user has completed is allowed only if
4438 * the caller is the shell uid, and there are no additional users and no accounts.
Makoto Onukia52562c2015-10-01 16:12:31 -07004439 * @param who the component name to be registered as device owner.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004440 * @param ownerName the human readable name of the institution that owns this device.
Makoto Onuki58b684f2015-09-04 10:48:16 -07004441 * @param userId ID of the user on which the device owner runs.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004442 * @return whether the package was successfully registered as the device owner.
4443 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00004444 * @throws IllegalStateException If the preconditions mentioned are not met.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004445 */
Makoto Onukia52562c2015-10-01 16:12:31 -07004446 public boolean setDeviceOwner(ComponentName who, String ownerName, int userId)
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004447 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07004448 if (mService != null) {
4449 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07004450 return mService.setDeviceOwner(who, ownerName, userId);
Amith Yamasani71e6c692013-03-24 17:39:28 -07004451 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004452 throw re.rethrowFromSystemServer();
Amith Yamasani71e6c692013-03-24 17:39:28 -07004453 }
4454 }
4455 return false;
4456 }
4457
4458 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004459 * Used to determine if a particular package has been registered as a Device Owner app.
4460 * A device owner app is a special device admin that cannot be deactivated by the user, once
Robin Lee25e26452015-06-02 09:56:29 -07004461 * activated as a device admin. It also cannot be uninstalled. To check whether a particular
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004462 * package is currently registered as the device owner app, pass in the package name from
4463 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
Robin Lee25e26452015-06-02 09:56:29 -07004464 * admin apps that want to check whether they are also registered as the device owner app. The
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004465 * exact mechanism by which a device admin app is registered as a device owner app is defined by
4466 * the setup process.
4467 * @param packageName the package name of the app, to compare with the registered device owner
4468 * app, if any.
Makoto Onukic8a5a552015-11-19 14:29:12 -08004469 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07004470 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004471 public boolean isDeviceOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004472 throwIfParentInstance("isDeviceOwnerApp");
Makoto Onukic8a5a552015-11-19 14:29:12 -08004473 return isDeviceOwnerAppOnCallingUser(packageName);
4474 }
4475
4476 /**
4477 * @return true if a package is registered as device owner, only when it's running on the
4478 * calling user.
4479 *
4480 * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity.
4481 * @hide
4482 */
4483 public boolean isDeviceOwnerAppOnCallingUser(String packageName) {
4484 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true);
4485 }
4486
4487 /**
4488 * @return true if a package is registered as device owner, even if it's running on a different
4489 * user.
4490 *
4491 * <p>Requires the MANAGE_USERS permission.
4492 *
4493 * @hide
4494 */
4495 public boolean isDeviceOwnerAppOnAnyUser(String packageName) {
4496 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false);
4497 }
4498
4499 /**
4500 * @return device owner component name, only when it's running on the calling user.
4501 *
4502 * @hide
4503 */
4504 public ComponentName getDeviceOwnerComponentOnCallingUser() {
4505 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true);
4506 }
4507
4508 /**
4509 * @return device owner component name, even if it's running on a different user.
4510 *
4511 * <p>Requires the MANAGE_USERS permission.
4512 *
4513 * @hide
4514 */
Polina Bondarenko23561db2016-12-16 11:47:28 +01004515 @SystemApi
Makoto Onukic8a5a552015-11-19 14:29:12 -08004516 public ComponentName getDeviceOwnerComponentOnAnyUser() {
4517 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false);
4518 }
4519
4520 private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) {
Makoto Onuki70f929e2015-11-11 12:40:15 -08004521 if (packageName == null) {
4522 return false;
Amith Yamasani71e6c692013-03-24 17:39:28 -07004523 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08004524 final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly);
Makoto Onuki70f929e2015-11-11 12:40:15 -08004525 if (deviceOwner == null) {
4526 return false;
4527 }
4528 return packageName.equals(deviceOwner.getPackageName());
Amith Yamasani71e6c692013-03-24 17:39:28 -07004529 }
4530
Makoto Onukic8a5a552015-11-19 14:29:12 -08004531 private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) {
4532 if (mService != null) {
4533 try {
4534 return mService.getDeviceOwnerComponent(callingUserOnly);
4535 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004536 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08004537 }
4538 }
4539 return null;
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004540 }
4541
Jason Monkb0dced82014-06-06 14:36:20 -04004542 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08004543 * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's
4544 * no device owner.
4545 *
4546 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07004547 *
4548 * @hide
4549 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08004550 public int getDeviceOwnerUserId() {
4551 if (mService != null) {
4552 try {
4553 return mService.getDeviceOwnerUserId();
4554 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004555 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08004556 }
4557 }
4558 return UserHandle.USER_NULL;
Makoto Onukia52562c2015-10-01 16:12:31 -07004559 }
4560
4561 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004562 * Clears the current device owner. The caller must be the device owner. This function should be
4563 * used cautiously as once it is called it cannot be undone. The device owner can only be set as
Esteban Talaveraa5b09632017-02-10 16:15:24 +00004564 * a part of device setup, before it completes.
4565 * <p>
4566 * While some policies previously set by the device owner will be cleared by this method, it is
4567 * a best-effort process and some other policies will still remain in place after the device
4568 * owner is cleared.
Jason Monk94d2cf92014-06-18 09:53:34 -04004569 *
4570 * @param packageName The package name of the device owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004571 * @throws SecurityException if the caller is not in {@code packageName} or {@code packageName}
4572 * does not own the current device owner component.
Esteban Talaveraa5b09632017-02-10 16:15:24 +00004573 *
4574 * @deprecated This method is expected to be used for testing purposes only. The device owner
4575 * will lose control of the device and its data after calling it. In order to protect any
4576 * sensitive data that remains on the device, it is advised that the device owner factory resets
4577 * the device instead of calling this method. See {@link #wipeData(int)}.
Jason Monkb0dced82014-06-06 14:36:20 -04004578 */
Esteban Talaveraa5b09632017-02-10 16:15:24 +00004579 @Deprecated
Jason Monk94d2cf92014-06-18 09:53:34 -04004580 public void clearDeviceOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004581 throwIfParentInstance("clearDeviceOwnerApp");
Jason Monkb0dced82014-06-06 14:36:20 -04004582 if (mService != null) {
4583 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04004584 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04004585 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004586 throw re.rethrowFromSystemServer();
Jason Monkb0dced82014-06-06 14:36:20 -04004587 }
4588 }
4589 }
4590
Makoto Onukia52562c2015-10-01 16:12:31 -07004591 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08004592 * Returns the device owner package name, only if it's running on the calling user.
4593 *
4594 * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity.
Makoto Onukia52562c2015-10-01 16:12:31 -07004595 *
4596 * @hide
4597 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01004598 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004599 public @Nullable String getDeviceOwner() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004600 throwIfParentInstance("getDeviceOwner");
Makoto Onukic8a5a552015-11-19 14:29:12 -08004601 final ComponentName name = getDeviceOwnerComponentOnCallingUser();
4602 return name != null ? name.getPackageName() : null;
Makoto Onukia52562c2015-10-01 16:12:31 -07004603 }
4604
4605 /**
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004606 * Called by the system to find out whether the device is managed by a Device Owner.
Makoto Onukic8a5a552015-11-19 14:29:12 -08004607 *
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004608 * @return whether the device is managed by a Device Owner.
4609 * @throws SecurityException if the caller is not the device owner, does not hold the
4610 * MANAGE_USERS permission and is not the system.
Makoto Onukia52562c2015-10-01 16:12:31 -07004611 *
4612 * @hide
4613 */
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004614 @SystemApi
4615 @TestApi
Makoto Onukic8a5a552015-11-19 14:29:12 -08004616 public boolean isDeviceManaged() {
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004617 try {
4618 return mService.hasDeviceOwner();
4619 } catch (RemoteException re) {
4620 throw re.rethrowFromSystemServer();
4621 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08004622 }
4623
4624 /**
4625 * Returns the device owner name. Note this method *will* return the device owner
4626 * name when it's running on a different user.
4627 *
4628 * <p>Requires the MANAGE_USERS permission.
4629 *
4630 * @hide
4631 */
Makoto Onukia2b274b2016-01-19 13:26:02 -08004632 @SystemApi
Makoto Onukic8a5a552015-11-19 14:29:12 -08004633 public String getDeviceOwnerNameOnAnyUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004634 throwIfParentInstance("getDeviceOwnerNameOnAnyUser");
Amith Yamasani71e6c692013-03-24 17:39:28 -07004635 if (mService != null) {
4636 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07004637 return mService.getDeviceOwnerName();
Amith Yamasani71e6c692013-03-24 17:39:28 -07004638 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004639 throw re.rethrowFromSystemServer();
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004640 }
4641 }
4642 return null;
4643 }
Adam Connors776c5552014-01-09 10:42:56 +00004644
4645 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04004646 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004647 * @deprecated Do not use
4648 * @removed
Julia Reynolds20118f12015-02-11 12:34:08 -05004649 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004650 @Deprecated
Julia Reynolds20118f12015-02-11 12:34:08 -05004651 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004652 public @Nullable String getDeviceInitializerApp() {
Julia Reynolds20118f12015-02-11 12:34:08 -05004653 return null;
4654 }
4655
4656 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004657 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004658 * @deprecated Do not use
4659 * @removed
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004660 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004661 @Deprecated
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004662 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004663 public @Nullable ComponentName getDeviceInitializerComponent() {
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004664 return null;
4665 }
4666
Julia Reynolds20118f12015-02-11 12:34:08 -05004667 /**
Adam Connors776c5552014-01-09 10:42:56 +00004668 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004669 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304670 * Sets the given component as an active admin and registers the package as the profile
4671 * owner for this user. The package must already be installed and there shouldn't be
4672 * an existing profile owner registered for this user. Also, this method must be called
4673 * before the user setup has been completed.
4674 * <p>
4675 * This method can only be called by system apps that hold MANAGE_USERS permission and
4676 * MANAGE_DEVICE_ADMINS permission.
4677 * @param admin The component to register as an active admin and profile owner.
4678 * @param ownerName The user-visible name of the entity that is managing this user.
4679 * @return whether the admin was successfully registered as the profile owner.
4680 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
4681 * the user has already been set up.
4682 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07004683 @Deprecated
Justin Morey80440cc2014-07-24 09:16:35 -05004684 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07004685 public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304686 throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004687 throwIfParentInstance("setActiveProfileOwner");
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304688 if (mService != null) {
4689 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004690 final int myUserId = myUserId();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304691 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004692 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304693 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004694 throw re.rethrowFromSystemServer();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304695 }
4696 }
4697 return false;
4698 }
4699
4700 /**
Esteban Talaveraa5b09632017-02-10 16:15:24 +00004701 * Clears the active profile owner. The caller must be the profile owner of this user, otherwise
4702 * a SecurityException will be thrown. This method is not available to managed profile owners.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004703 * <p>
Esteban Talaveraa5b09632017-02-10 16:15:24 +00004704 * While some policies previously set by the profile owner will be cleared by this method, it is
4705 * a best-effort process and some other policies will still remain in place after the profile
4706 * owner is cleared.
Makoto Onuki5bf68022016-01-27 13:49:19 -08004707 *
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004708 * @param admin The component to remove as the profile owner.
Esteban Talaveraa5b09632017-02-10 16:15:24 +00004709 * @throws SecurityException if {@code admin} is not an active profile owner, or the method is
4710 * being called from a managed profile.
4711 *
4712 * @deprecated This method is expected to be used for testing purposes only. The profile owner
4713 * will lose control of the user and its data after calling it. In order to protect any
4714 * sensitive data that remains on this user, it is advised that the profile owner deletes it
4715 * instead of calling this method. See {@link #wipeData(int)}.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004716 */
Esteban Talaveraa5b09632017-02-10 16:15:24 +00004717 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07004718 public void clearProfileOwner(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004719 throwIfParentInstance("clearProfileOwner");
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004720 if (mService != null) {
4721 try {
4722 mService.clearProfileOwner(admin);
4723 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004724 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004725 }
4726 }
4727 }
4728
4729 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05004730 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07004731 * Checks whether the user was already setup.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004732 */
4733 public boolean hasUserSetupCompleted() {
4734 if (mService != null) {
4735 try {
4736 return mService.hasUserSetupCompleted();
4737 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004738 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004739 }
4740 }
4741 return true;
4742 }
4743
4744 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004745 * @hide
4746 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00004747 * already be installed. There must not already be a profile owner for this user.
4748 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
4749 * this method.
4750 * Calling this after the setup phase of the specified user has completed is allowed only if:
4751 * - the caller is SYSTEM_UID.
4752 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004753 * @param admin the component name to be registered as profile owner.
4754 * @param ownerName the human readable name of the organisation associated with this DPM.
4755 * @param userHandle the userId to set the profile owner for.
4756 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00004757 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
4758 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004759 */
Robin Lee25e26452015-06-02 09:56:29 -07004760 public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName,
Robin Leeddd553f2015-04-30 14:18:22 +01004761 int userHandle) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00004762 if (mService != null) {
4763 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004764 if (ownerName == null) {
4765 ownerName = "";
4766 }
4767 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00004768 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004769 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004770 }
4771 }
4772 return false;
4773 }
4774
4775 /**
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004776 * Sets the device owner information to be shown on the lock screen.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004777 * <p>
4778 * If the device owner information is {@code null} or empty then the device owner info is
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004779 * cleared and the user owner info is shown on the lock screen if it is set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004780 * <p>
4781 * If the device owner information contains only whitespaces then the message on the lock screen
4782 * will be blank and the user will not be allowed to change it.
4783 * <p>
4784 * If the device owner information needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00004785 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
4786 * and set a new version of this string accordingly.
4787 *
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004788 * @param admin The name of the admin component to check.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004789 * @param info Device owner information which will be displayed instead of the user owner info.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004790 * @throws SecurityException if {@code admin} is not a device owner.
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004791 */
Andrei Stingaceanu16187902016-03-21 15:44:45 +00004792 public void setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, CharSequence info) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004793 throwIfParentInstance("setDeviceOwnerLockScreenInfo");
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004794 if (mService != null) {
4795 try {
Andrei Stingaceanu16187902016-03-21 15:44:45 +00004796 mService.setDeviceOwnerLockScreenInfo(admin, info);
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004797 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004798 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004799 }
4800 }
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004801 }
4802
4803 /**
4804 * @return The device owner information. If it is not set returns {@code null}.
4805 */
Andrei Stingaceanu16187902016-03-21 15:44:45 +00004806 public CharSequence getDeviceOwnerLockScreenInfo() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004807 throwIfParentInstance("getDeviceOwnerLockScreenInfo");
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004808 if (mService != null) {
4809 try {
4810 return mService.getDeviceOwnerLockScreenInfo();
4811 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004812 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004813 }
4814 }
4815 return null;
4816 }
4817
4818 /**
Edman Anjos52088e42017-01-13 22:26:17 +01004819 * Called by device or profile owners to suspend packages for this user. This function can be
4820 * called by a device owner, profile owner, or by a delegate given the
4821 * {@link #DELEGATION_PACKAGE_ACCESS} scope via {@link #setDelegatedScopes}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004822 * <p>
4823 * A suspended package will not be able to start activities. Its notifications will be hidden,
4824 * it will not show up in recents, will not be able to show toasts or dialogs or ring the
4825 * device.
4826 * <p>
4827 * The package must already be installed. If the package is uninstalled while suspended the
4828 * package will no longer be suspended. The admin can block this by using
Kenny Guy871f3eb2016-03-09 20:06:16 +00004829 * {@link #setUninstallBlocked}.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004830 *
Edman Anjos52088e42017-01-13 22:26:17 +01004831 * @param admin The name of the admin component to check, or {@code null} if the caller is a
4832 * package access delegate.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004833 * @param packageNames The package names to suspend or unsuspend.
4834 * @param suspended If set to {@code true} than the packages will be suspended, if set to
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004835 * {@code false} the packages will be unsuspended.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004836 * @return an array of package names for which the suspended status is not set as requested in
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004837 * this method.
4838 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01004839 * @see #setDelegatedScopes
4840 * @see #DELEGATION_PACKAGE_ACCESS
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004841 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004842 public @NonNull String[] setPackagesSuspended(@NonNull ComponentName admin,
4843 @NonNull String[] packageNames, boolean suspended) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004844 throwIfParentInstance("setPackagesSuspended");
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004845 if (mService != null) {
4846 try {
Edman Anjos52088e42017-01-13 22:26:17 +01004847 return mService.setPackagesSuspended(admin, mContext.getPackageName(), packageNames,
4848 suspended);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004849 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004850 throw re.rethrowFromSystemServer();
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004851 }
4852 }
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004853 return packageNames;
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004854 }
4855
4856 /**
Edman Anjos52088e42017-01-13 22:26:17 +01004857 * Determine if a package is suspended. This function can be called by a device owner, profile
4858 * owner, or by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via
4859 * {@link #setDelegatedScopes}.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004860 *
Edman Anjos52088e42017-01-13 22:26:17 +01004861 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
4862 * {@code null} if the caller is a package access delegate.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004863 * @param packageName The name of the package to retrieve the suspended status of.
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00004864 * @return {@code true} if the package is suspended or {@code false} if the package is not
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004865 * suspended, could not be found or an error occurred.
4866 * @throws SecurityException if {@code admin} is not a device or profile owner.
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004867 * @throws NameNotFoundException if the package could not be found.
Edman Anjos52088e42017-01-13 22:26:17 +01004868 * @see #setDelegatedScopes
4869 * @see #DELEGATION_PACKAGE_ACCESS
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004870 */
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004871 public boolean isPackageSuspended(@NonNull ComponentName admin, String packageName)
4872 throws NameNotFoundException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004873 throwIfParentInstance("isPackageSuspended");
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004874 if (mService != null) {
4875 try {
Edman Anjos52088e42017-01-13 22:26:17 +01004876 return mService.isPackageSuspended(admin, mContext.getPackageName(), packageName);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004877 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004878 throw e.rethrowFromSystemServer();
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004879 } catch (IllegalArgumentException ex) {
4880 throw new NameNotFoundException(packageName);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004881 }
4882 }
4883 return false;
4884 }
4885
4886 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004887 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
4888 * be used. Only the profile owner can call this.
4889 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01004890 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004891 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004892 * @throws SecurityException if {@code admin} is not a profile owner.
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004893 */
Robin Lee25e26452015-06-02 09:56:29 -07004894 public void setProfileEnabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004895 throwIfParentInstance("setProfileEnabled");
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004896 if (mService != null) {
4897 try {
4898 mService.setProfileEnabled(admin);
4899 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004900 throw e.rethrowFromSystemServer();
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004901 }
4902 }
4903 }
4904
4905 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004906 * Sets the name of the profile. In the device owner case it sets the name of the user which it
4907 * is called from. Only a profile owner or device owner can call this. If this is never called
4908 * by the profile or device owner, the name will be set to default values.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004909 *
4910 * @see #isProfileOwnerApp
4911 * @see #isDeviceOwnerApp
Robin Lee25e26452015-06-02 09:56:29 -07004912 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004913 * @param profileName The name of the profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004914 * @throws SecurityException if {@code admin} is not a device or profile owner.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004915 */
Robin Lee25e26452015-06-02 09:56:29 -07004916 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004917 throwIfParentInstance("setProfileName");
Jessica Hummel1333ea12014-06-23 11:20:10 +01004918 if (mService != null) {
4919 try {
Robin Lee25e26452015-06-02 09:56:29 -07004920 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07004921 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004922 throw e.rethrowFromSystemServer();
Fyodor Kupolov78f13142015-05-27 16:52:45 -07004923 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01004924 }
4925 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01004926
4927 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004928 * Used to determine if a particular package is registered as the profile owner for the
Makoto Onuki32b30572015-12-11 14:29:51 -08004929 * user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004930 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00004931 *
4932 * @param packageName The package name of the app to compare with the registered profile owner.
4933 * @return Whether or not the package is registered as the profile owner.
4934 */
4935 public boolean isProfileOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004936 throwIfParentInstance("isProfileOwnerApp");
Adam Connors776c5552014-01-09 10:42:56 +00004937 if (mService != null) {
4938 try {
Makoto Onuki90b89652016-01-28 14:44:18 -08004939 ComponentName profileOwner = mService.getProfileOwner(myUserId());
Nicolas Prevot90af6d72014-07-30 14:19:12 +01004940 return profileOwner != null
4941 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00004942 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004943 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004944 }
4945 }
4946 return false;
4947 }
4948
4949 /**
4950 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07004951 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00004952 * owner has been set for that user.
4953 * @throws IllegalArgumentException if the userId is invalid.
4954 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01004955 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004956 public @Nullable ComponentName getProfileOwner() throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004957 throwIfParentInstance("getProfileOwner");
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01004958 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
4959 }
4960
4961 /**
4962 * @see #getProfileOwner()
4963 * @hide
4964 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004965 public @Nullable ComponentName getProfileOwnerAsUser(final int userId)
4966 throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00004967 if (mService != null) {
4968 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01004969 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00004970 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004971 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004972 }
4973 }
4974 return null;
4975 }
4976
4977 /**
4978 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07004979 * @return the human readable name of the organisation associated with this DPM or {@code null}
4980 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00004981 * @throws IllegalArgumentException if the userId is invalid.
4982 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004983 public @Nullable String getProfileOwnerName() throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00004984 if (mService != null) {
4985 try {
4986 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
4987 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004988 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004989 }
4990 }
4991 return null;
4992 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004993
4994 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07004995 * @hide
Makoto Onukic8a5a552015-11-19 14:29:12 -08004996 * @param userId The user for whom to fetch the profile owner name, if any.
Amith Yamasani38f836b2014-08-20 14:51:15 -07004997 * @return the human readable name of the organisation associated with this profile owner or
4998 * null if one is not set.
4999 * @throws IllegalArgumentException if the userId is invalid.
5000 */
5001 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07005002 public @Nullable String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005003 throwIfParentInstance("getProfileOwnerNameAsUser");
Amith Yamasani38f836b2014-08-20 14:51:15 -07005004 if (mService != null) {
5005 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02005006 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07005007 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005008 throw re.rethrowFromSystemServer();
Amith Yamasani38f836b2014-08-20 14:51:15 -07005009 }
5010 }
5011 return null;
5012 }
5013
5014 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005015 * Called by a profile owner or device owner to add a default intent handler activity for
5016 * intents that match a certain intent filter. This activity will remain the default intent
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005017 * handler even if the set of potential event handlers for the intent filter changes and if the
5018 * intent preferences are reset.
5019 * <p>
5020 * The default disambiguation mechanism takes over if the activity is not installed (anymore).
5021 * When the activity is (re)installed, it is automatically reset as default intent handler for
5022 * the filter.
5023 * <p>
5024 * The calling device admin must be a profile owner or device owner. If it is not, a security
5025 * exception will be thrown.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005026 *
5027 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5028 * @param filter The IntentFilter for which a default handler is added.
5029 * @param activity The Activity that is added as default intent handler.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005030 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005031 */
Robin Lee25e26452015-06-02 09:56:29 -07005032 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
5033 @NonNull ComponentName activity) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005034 throwIfParentInstance("addPersistentPreferredActivity");
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005035 if (mService != null) {
5036 try {
5037 mService.addPersistentPreferredActivity(admin, filter, activity);
5038 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005039 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005040 }
5041 }
5042 }
5043
5044 /**
5045 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00005046 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005047 * <p>
5048 * The calling device admin must be a profile owner. If it is not, a security exception will be
5049 * thrown.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005050 *
5051 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5052 * @param packageName The name of the package for which preferences are removed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005053 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005054 */
Robin Lee25e26452015-06-02 09:56:29 -07005055 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005056 String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005057 throwIfParentInstance("clearPackagePersistentPreferredActivities");
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005058 if (mService != null) {
5059 try {
5060 mService.clearPackagePersistentPreferredActivities(admin, packageName);
5061 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005062 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005063 }
5064 }
5065 }
Robin Lee66e5d962014-04-09 16:44:21 +01005066
5067 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00005068 * Called by a profile owner or device owner to grant permission to a package to manage
5069 * application restrictions for the calling user via {@link #setApplicationRestrictions} and
5070 * {@link #getApplicationRestrictions}.
5071 * <p>
5072 * This permission is persistent until it is later cleared by calling this method with a
5073 * {@code null} value or uninstalling the managing package.
Rubin Xuf03d0a62016-02-10 14:54:15 +00005074 * <p>
5075 * The supplied application restriction managing package must be installed when calling this
Victor Changcd14c0a2016-03-16 19:10:15 +00005076 * API, otherwise an {@link NameNotFoundException} will be thrown.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005077 *
5078 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5079 * @param packageName The package name which will be given access to application restrictions
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005080 * APIs. If {@code null} is given the current package will be cleared.
5081 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Changcd14c0a2016-03-16 19:10:15 +00005082 * @throws NameNotFoundException if {@code packageName} is not found
Edman Anjosf9946772016-11-28 16:35:15 +01005083 *
5084 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #setDelegatedScopes}
5085 * with the {@link #DELEGATION_APP_RESTRICTIONS} scope instead.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005086 */
Edman Anjosf9946772016-11-28 16:35:15 +01005087 @Deprecated
Esteban Talaverabf60f722015-12-10 16:26:44 +00005088 public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin,
Victor Changcd14c0a2016-03-16 19:10:15 +00005089 @Nullable String packageName) throws NameNotFoundException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005090 throwIfParentInstance("setApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00005091 if (mService != null) {
5092 try {
Victor Changcd14c0a2016-03-16 19:10:15 +00005093 if (!mService.setApplicationRestrictionsManagingPackage(admin, packageName)) {
5094 throw new NameNotFoundException(packageName);
5095 }
Esteban Talaverabf60f722015-12-10 16:26:44 +00005096 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005097 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00005098 }
5099 }
5100 }
5101
5102 /**
5103 * Called by a profile owner or device owner to retrieve the application restrictions managing
Edman Anjosf9946772016-11-28 16:35:15 +01005104 * package for the current user, or {@code null} if none is set. If there are multiple
5105 * delegates this function will return one of them.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005106 *
5107 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5108 * @return The package name allowed to manage application restrictions on the current user, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005109 * {@code null} if none is set.
5110 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01005111 *
5112 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatePackages}
5113 * with the {@link #DELEGATION_APP_RESTRICTIONS} scope instead.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005114 */
Edman Anjosf9946772016-11-28 16:35:15 +01005115 @Deprecated
5116 @Nullable
5117 public String getApplicationRestrictionsManagingPackage(
Makoto Onuki408e8e42016-10-25 12:10:27 -07005118 @NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005119 throwIfParentInstance("getApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00005120 if (mService != null) {
5121 try {
5122 return mService.getApplicationRestrictionsManagingPackage(admin);
5123 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005124 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00005125 }
5126 }
5127 return null;
5128 }
5129
5130 /**
Esteban Talavera96895ca2016-03-16 12:00:40 +00005131 * Called by any application to find out whether it has been granted permission via
5132 * {@link #setApplicationRestrictionsManagingPackage} to manage application restrictions
5133 * for the calling user.
5134 *
5135 * <p>This is done by comparing the calling Linux uid with the uid of the package specified by
5136 * that method.
Edman Anjosf9946772016-11-28 16:35:15 +01005137 *
5138 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatedScopes}
5139 * instead.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005140 */
Edman Anjosf9946772016-11-28 16:35:15 +01005141 @Deprecated
Esteban Talaverabf60f722015-12-10 16:26:44 +00005142 public boolean isCallerApplicationRestrictionsManagingPackage() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005143 throwIfParentInstance("isCallerApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00005144 if (mService != null) {
5145 try {
Edman Anjosf9946772016-11-28 16:35:15 +01005146 return mService.isCallerApplicationRestrictionsManagingPackage(
5147 mContext.getPackageName());
Esteban Talaverabf60f722015-12-10 16:26:44 +00005148 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005149 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00005150 }
5151 }
5152 return false;
5153 }
5154
5155 /**
5156 * Sets the application restrictions for a given target application running in the calling user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005157 * <p>
5158 * The caller must be a profile or device owner on that user, or the package allowed to manage
Edman Anjosf9946772016-11-28 16:35:15 +01005159 * application restrictions via {@link #setDelegatedScopes} with the
5160 * {@link #DELEGATION_APP_RESTRICTIONS} scope; otherwise a security exception will be thrown.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005161 * <p>
5162 * The provided {@link Bundle} consists of key-value pairs, where the types of values may be:
Esteban Talavera6b8e0642015-08-10 17:26:04 +01005163 * <ul>
5164 * <li>{@code boolean}
5165 * <li>{@code int}
5166 * <li>{@code String} or {@code String[]}
5167 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
5168 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005169 * <p>
5170 * If the restrictions are not available yet, but may be applied in the near future, the caller
5171 * can notify the target application of that by adding
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00005172 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005173 * <p>
5174 * The application restrictions are only made visible to the target application via
5175 * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or device
5176 * owner, and the application restrictions managing package via
Esteban Talaverabf60f722015-12-10 16:26:44 +00005177 * {@link #getApplicationRestrictions}.
Robin Lee66e5d962014-04-09 16:44:21 +01005178 *
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005179 * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
5180 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00005181 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005182 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01005183 * @param packageName The name of the package to update restricted settings for.
5184 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005185 * set of active restrictions.
5186 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01005187 * @see #setDelegatedScopes
5188 * @see #DELEGATION_APP_RESTRICTIONS
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00005189 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01005190 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005191 @WorkerThread
Esteban Talaverabf60f722015-12-10 16:26:44 +00005192 public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01005193 Bundle settings) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005194 throwIfParentInstance("setApplicationRestrictions");
Robin Lee66e5d962014-04-09 16:44:21 +01005195 if (mService != null) {
5196 try {
Edman Anjosf9946772016-11-28 16:35:15 +01005197 mService.setApplicationRestrictions(admin, mContext.getPackageName(), packageName,
5198 settings);
Robin Lee66e5d962014-04-09 16:44:21 +01005199 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005200 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01005201 }
5202 }
5203 }
5204
5205 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005206 * Sets a list of configuration features to enable for a TrustAgent component. This is meant to
5207 * be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all trust
5208 * agents but those enabled by this function call. If flag
Jim Millere303bf42014-08-26 17:12:29 -07005209 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005210 * <p>
5211 * The calling device admin must have requested
5212 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method;
5213 * if not, a security exception will be thrown.
Tony Mak089d8402016-04-05 17:42:55 +01005214 * <p>
5215 * This method can be called on the {@link DevicePolicyManager} instance returned by
5216 * {@link #getParentProfileInstance(ComponentName)} in order to set the configuration for
5217 * the parent profile.
Jim Miller604e7552014-07-18 19:00:02 -07005218 *
5219 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07005220 * @param target Component name of the agent to be enabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005221 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent will be
5222 * strictly disabled according to the state of the
5223 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
5224 * <p>
5225 * If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all
5226 * admins, then it's up to the TrustAgent itself to aggregate the values from all
5227 * device admins.
5228 * <p>
5229 * Consult documentation for the specific TrustAgent to determine legal options
5230 * parameters.
5231 * @throws SecurityException if {@code admin} is not an active administrator or does not use
5232 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES}
Jim Miller604e7552014-07-18 19:00:02 -07005233 */
Robin Lee25e26452015-06-02 09:56:29 -07005234 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
5235 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07005236 if (mService != null) {
5237 try {
Tony Mak089d8402016-04-05 17:42:55 +01005238 mService.setTrustAgentConfiguration(admin, target, configuration, mParentInstance);
Jim Miller604e7552014-07-18 19:00:02 -07005239 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005240 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07005241 }
5242 }
5243 }
5244
5245 /**
Jim Millere303bf42014-08-26 17:12:29 -07005246 * Gets configuration for the given trust agent based on aggregating all calls to
5247 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
5248 * all device admins.
Tony Mak089d8402016-04-05 17:42:55 +01005249 * <p>
5250 * This method can be called on the {@link DevicePolicyManager} instance returned by
5251 * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the configuration set
5252 * on the parent profile.
Jim Miller604e7552014-07-18 19:00:02 -07005253 *
Jim Millerb5db57a2015-01-14 18:17:19 -08005254 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
5255 * this function returns a list of configurations for all admins that declare
5256 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
5257 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
5258 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
5259 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07005260 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07005261 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07005262 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005263 public @Nullable List<PersistableBundle> getTrustAgentConfiguration(
5264 @Nullable ComponentName admin, @NonNull ComponentName agent) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07005265 return getTrustAgentConfiguration(admin, agent, myUserId());
Jim Millere303bf42014-08-26 17:12:29 -07005266 }
5267
5268 /** @hide per-user version */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005269 public @Nullable List<PersistableBundle> getTrustAgentConfiguration(
5270 @Nullable ComponentName admin, @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07005271 if (mService != null) {
5272 try {
Tony Mak089d8402016-04-05 17:42:55 +01005273 return mService.getTrustAgentConfiguration(admin, agent, userHandle,
5274 mParentInstance);
Jim Miller604e7552014-07-18 19:00:02 -07005275 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005276 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07005277 }
5278 }
Jim Millere303bf42014-08-26 17:12:29 -07005279 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07005280 }
5281
5282 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005283 * Called by a profile owner of a managed profile to set whether caller-Id information from the
5284 * managed profile will be shown in the parent profile, for incoming calls.
5285 * <p>
5286 * The calling device admin must be a profile owner. If it is not, a security exception will be
5287 * thrown.
Adam Connors210fe212014-07-17 15:41:43 +01005288 *
Robin Lee25e26452015-06-02 09:56:29 -07005289 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01005290 * @param disabled If true caller-Id information in the managed profile is not displayed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005291 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors210fe212014-07-17 15:41:43 +01005292 */
Robin Lee25e26452015-06-02 09:56:29 -07005293 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005294 throwIfParentInstance("setCrossProfileCallerIdDisabled");
Adam Connors210fe212014-07-17 15:41:43 +01005295 if (mService != null) {
5296 try {
Robin Lee25e26452015-06-02 09:56:29 -07005297 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01005298 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005299 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01005300 }
5301 }
5302 }
5303
5304 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005305 * Called by a profile owner of a managed profile to determine whether or not caller-Id
5306 * information has been disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005307 * <p>
5308 * The calling device admin must be a profile owner. If it is not, a security exception will be
5309 * thrown.
Adam Connors210fe212014-07-17 15:41:43 +01005310 *
Robin Lee25e26452015-06-02 09:56:29 -07005311 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005312 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors210fe212014-07-17 15:41:43 +01005313 */
Robin Lee25e26452015-06-02 09:56:29 -07005314 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005315 throwIfParentInstance("getCrossProfileCallerIdDisabled");
Adam Connors210fe212014-07-17 15:41:43 +01005316 if (mService != null) {
5317 try {
Robin Lee25e26452015-06-02 09:56:29 -07005318 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01005319 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005320 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01005321 }
5322 }
5323 return false;
5324 }
5325
5326 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07005327 * Determine whether or not caller-Id information has been disabled.
5328 *
5329 * @param userHandle The user for whom to check the caller-id permission
5330 * @hide
5331 */
5332 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
5333 if (mService != null) {
5334 try {
5335 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
5336 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005337 throw e.rethrowFromSystemServer();
Amith Yamasani570002f2014-07-18 15:48:54 -07005338 }
5339 }
5340 return false;
5341 }
5342
5343 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005344 * Called by a profile owner of a managed profile to set whether contacts search from the
5345 * managed profile will be shown in the parent profile, for incoming calls.
5346 * <p>
5347 * The calling device admin must be a profile owner. If it is not, a security exception will be
5348 * thrown.
Victor Chang1060c6182016-01-04 20:16:23 +00005349 *
5350 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5351 * @param disabled If true contacts search in the managed profile is not displayed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005352 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Chang1060c6182016-01-04 20:16:23 +00005353 */
5354 public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin,
5355 boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005356 throwIfParentInstance("setCrossProfileContactsSearchDisabled");
Victor Chang1060c6182016-01-04 20:16:23 +00005357 if (mService != null) {
5358 try {
5359 mService.setCrossProfileContactsSearchDisabled(admin, disabled);
5360 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005361 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00005362 }
5363 }
5364 }
5365
5366 /**
5367 * Called by a profile owner of a managed profile to determine whether or not contacts search
5368 * has been disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005369 * <p>
5370 * The calling device admin must be a profile owner. If it is not, a security exception will be
5371 * thrown.
Victor Chang1060c6182016-01-04 20:16:23 +00005372 *
5373 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005374 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Chang1060c6182016-01-04 20:16:23 +00005375 */
5376 public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005377 throwIfParentInstance("getCrossProfileContactsSearchDisabled");
Victor Chang1060c6182016-01-04 20:16:23 +00005378 if (mService != null) {
5379 try {
5380 return mService.getCrossProfileContactsSearchDisabled(admin);
5381 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005382 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00005383 }
5384 }
5385 return false;
5386 }
5387
5388
5389 /**
5390 * Determine whether or not contacts search has been disabled.
5391 *
5392 * @param userHandle The user for whom to check the contacts search permission
5393 * @hide
5394 */
5395 public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) {
5396 if (mService != null) {
5397 try {
5398 return mService
5399 .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier());
5400 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005401 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00005402 }
5403 }
5404 return false;
5405 }
5406
5407 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005408 * Start Quick Contact on the managed profile for the user, if the policy allows.
Victor Chang97bdacc2016-01-21 22:24:11 +00005409 *
Makoto Onuki1040da12015-03-19 11:24:00 -07005410 * @hide
5411 */
5412 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
Victor Chang97bdacc2016-01-21 22:24:11 +00005413 boolean isContactIdIgnored, long directoryId, Intent originalIntent) {
Makoto Onuki1040da12015-03-19 11:24:00 -07005414 if (mService != null) {
5415 try {
Victor Chang97bdacc2016-01-21 22:24:11 +00005416 mService.startManagedQuickContact(actualLookupKey, actualContactId,
5417 isContactIdIgnored, directoryId, originalIntent);
Makoto Onuki1040da12015-03-19 11:24:00 -07005418 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005419 throw e.rethrowFromSystemServer();
Makoto Onuki1040da12015-03-19 11:24:00 -07005420 }
5421 }
5422 }
5423
5424 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005425 * Start Quick Contact on the managed profile for the user, if the policy allows.
Ricky Wai494b95d2015-11-20 16:07:15 +00005426 * @hide
5427 */
5428 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
5429 Intent originalIntent) {
Victor Chang97bdacc2016-01-21 22:24:11 +00005430 startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT,
Ricky Wai494b95d2015-11-20 16:07:15 +00005431 originalIntent);
5432 }
5433
5434 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005435 * Called by a profile owner of a managed profile to set whether bluetooth devices can access
5436 * enterprise contacts.
Ricky Wai778ba132015-03-31 14:21:22 +01005437 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005438 * The calling device admin must be a profile owner. If it is not, a security exception will be
5439 * thrown.
Ricky Wai778ba132015-03-31 14:21:22 +01005440 * <p>
5441 * This API works on managed profile only.
5442 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005443 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5444 * @param disabled If true, bluetooth devices cannot access enterprise contacts.
5445 * @throws SecurityException if {@code admin} is not a device or profile owner.
Ricky Wai778ba132015-03-31 14:21:22 +01005446 */
Robin Lee25e26452015-06-02 09:56:29 -07005447 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005448 throwIfParentInstance("setBluetoothContactSharingDisabled");
Ricky Wai778ba132015-03-31 14:21:22 +01005449 if (mService != null) {
5450 try {
Robin Lee25e26452015-06-02 09:56:29 -07005451 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01005452 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005453 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01005454 }
5455 }
5456 }
5457
5458 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005459 * Called by a profile owner of a managed profile to determine whether or not Bluetooth devices
5460 * cannot access enterprise contacts.
Ricky Wai778ba132015-03-31 14:21:22 +01005461 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005462 * The calling device admin must be a profile owner. If it is not, a security exception will be
5463 * thrown.
Ricky Wai778ba132015-03-31 14:21:22 +01005464 * <p>
5465 * This API works on managed profile only.
5466 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005467 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5468 * @throws SecurityException if {@code admin} is not a device or profile owner.
Ricky Wai778ba132015-03-31 14:21:22 +01005469 */
Robin Lee25e26452015-06-02 09:56:29 -07005470 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005471 throwIfParentInstance("getBluetoothContactSharingDisabled");
Ricky Wai778ba132015-03-31 14:21:22 +01005472 if (mService != null) {
5473 try {
Robin Lee25e26452015-06-02 09:56:29 -07005474 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01005475 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005476 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01005477 }
5478 }
5479 return true;
5480 }
5481
5482 /**
5483 * Determine whether or not Bluetooth devices cannot access contacts.
5484 * <p>
5485 * This API works on managed profile UserHandle only.
5486 *
5487 * @param userHandle The user for whom to check the caller-id permission
5488 * @hide
5489 */
5490 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
5491 if (mService != null) {
5492 try {
5493 return mService.getBluetoothContactSharingDisabledForUser(userHandle
5494 .getIdentifier());
5495 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005496 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01005497 }
5498 }
5499 return true;
5500 }
5501
5502 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005503 * Called by the profile owner of a managed profile so that some intents sent in the managed
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005504 * profile can also be resolved in the parent, or vice versa. Only activity intents are
5505 * supported.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00005506 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005507 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01005508 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005509 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01005510 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005511 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
5512 * @throws SecurityException if {@code admin} is not a device or profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005513 */
Robin Lee25e26452015-06-02 09:56:29 -07005514 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005515 throwIfParentInstance("addCrossProfileIntentFilter");
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005516 if (mService != null) {
5517 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01005518 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005519 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005520 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005521 }
5522 }
5523 }
5524
5525 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005526 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
5527 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01005528 * Only removes those that have been set by the profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005529 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005530 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005531 * @throws SecurityException if {@code admin} is not a device or profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005532 */
Robin Lee25e26452015-06-02 09:56:29 -07005533 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005534 throwIfParentInstance("clearCrossProfileIntentFilters");
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005535 if (mService != null) {
5536 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01005537 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005538 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005539 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005540 }
5541 }
5542 }
5543
5544 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005545 * Called by a profile or device owner to set the permitted accessibility services. When set by
5546 * a device owner or profile owner the restriction applies to all profiles of the user the
5547 * device owner or profile owner is an admin for. By default the user can use any accessiblity
5548 * service. When zero or more packages have been added, accessiblity services that are not in
5549 * the list and not part of the system can not be enabled by the user.
5550 * <p>
5551 * Calling with a null value for the list disables the restriction so that all services can be
5552 * used, calling with an empty list only allows the builtin system's services.
5553 * <p>
5554 * System accesibility services are always available to the user the list can't modify this.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005555 *
5556 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5557 * @param packageNames List of accessibility service package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005558 * @return true if setting the restriction succeeded. It fail if there is one or more non-system
5559 * accessibility services enabled, that are not in the list.
5560 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005561 */
Robin Lee25e26452015-06-02 09:56:29 -07005562 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005563 List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005564 throwIfParentInstance("setPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005565 if (mService != null) {
5566 try {
5567 return mService.setPermittedAccessibilityServices(admin, packageNames);
5568 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005569 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005570 }
5571 }
5572 return false;
5573 }
5574
5575 /**
5576 * Returns the list of permitted accessibility services set by this device or profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005577 * <p>
5578 * An empty list means no accessibility services except system services are allowed. Null means
5579 * all accessibility services are allowed.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005580 *
5581 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5582 * @return List of accessiblity service package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005583 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005584 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005585 public @Nullable List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005586 throwIfParentInstance("getPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005587 if (mService != null) {
5588 try {
5589 return mService.getPermittedAccessibilityServices(admin);
5590 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005591 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005592 }
5593 }
5594 return null;
5595 }
5596
5597 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00005598 * Called by the system to check if a specific accessibility service is disabled by admin.
5599 *
5600 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5601 * @param packageName Accessibility service package name that needs to be checked.
5602 * @param userHandle user id the admin is running as.
5603 * @return true if the accessibility service is permitted, otherwise false.
5604 *
5605 * @hide
5606 */
5607 public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin,
5608 @NonNull String packageName, int userHandle) {
5609 if (mService != null) {
5610 try {
5611 return mService.isAccessibilityServicePermittedByAdmin(admin, packageName,
5612 userHandle);
5613 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005614 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00005615 }
5616 }
5617 return false;
5618 }
5619
5620 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005621 * Returns the list of accessibility services permitted by the device or profiles
5622 * owners of this user.
5623 *
5624 * <p>Null means all accessibility services are allowed, if a non-null list is returned
5625 * it will contain the intersection of the permitted lists for any device or profile
5626 * owners that apply to this user. It will also include any system accessibility services.
5627 *
5628 * @param userId which user to check for.
5629 * @return List of accessiblity service package names.
5630 * @hide
5631 */
5632 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07005633 public @Nullable List<String> getPermittedAccessibilityServices(int userId) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005634 throwIfParentInstance("getPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005635 if (mService != null) {
5636 try {
5637 return mService.getPermittedAccessibilityServicesForUser(userId);
5638 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005639 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005640 }
5641 }
5642 return null;
5643 }
5644
5645 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005646 * Called by a profile or device owner to set the permitted input methods services. When set by
5647 * a device owner or profile owner the restriction applies to all profiles of the user the
5648 * device owner or profile owner is an admin for. By default the user can use any input method.
5649 * When zero or more packages have been added, input method that are not in the list and not
5650 * part of the system can not be enabled by the user. This method will fail if it is called for
5651 * a admin that is not for the foreground user or a profile of the foreground user.
5652 * <p>
5653 * Calling with a null value for the list disables the restriction so that all input methods can
5654 * be used, calling with an empty list disables all but the system's own input methods.
5655 * <p>
5656 * System input methods are always available to the user this method can't modify this.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005657 *
5658 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5659 * @param packageNames List of input method package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005660 * @return true if setting the restriction succeeded. It will fail if there are one or more
5661 * non-system input methods currently enabled that are not in the packageNames list.
5662 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005663 */
Robin Lee25e26452015-06-02 09:56:29 -07005664 public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005665 throwIfParentInstance("setPermittedInputMethods");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005666 if (mService != null) {
5667 try {
5668 return mService.setPermittedInputMethods(admin, packageNames);
5669 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005670 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005671 }
5672 }
5673 return false;
5674 }
5675
5676
5677 /**
5678 * Returns the list of permitted input methods set by this device or profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005679 * <p>
5680 * An empty list means no input methods except system input methods are allowed. Null means all
5681 * input methods are allowed.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005682 *
5683 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5684 * @return List of input method package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005685 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005686 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005687 public @Nullable List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005688 throwIfParentInstance("getPermittedInputMethods");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005689 if (mService != null) {
5690 try {
5691 return mService.getPermittedInputMethods(admin);
5692 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005693 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005694 }
5695 }
5696 return null;
5697 }
5698
5699 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00005700 * Called by the system to check if a specific input method is disabled by admin.
5701 *
5702 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5703 * @param packageName Input method package name that needs to be checked.
5704 * @param userHandle user id the admin is running as.
5705 * @return true if the input method is permitted, otherwise false.
5706 *
5707 * @hide
5708 */
5709 public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin,
5710 @NonNull String packageName, int userHandle) {
5711 if (mService != null) {
5712 try {
5713 return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle);
5714 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005715 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00005716 }
5717 }
5718 return false;
5719 }
5720
5721 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005722 * Returns the list of input methods permitted by the device or profiles
Makoto Onuki32b30572015-12-11 14:29:51 -08005723 * owners of the current user. (*Not* calling user, due to a limitation in InputMethodManager.)
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005724 *
5725 * <p>Null means all input methods are allowed, if a non-null list is returned
5726 * it will contain the intersection of the permitted lists for any device or profile
5727 * owners that apply to this user. It will also include any system input methods.
5728 *
5729 * @return List of input method package names.
5730 * @hide
5731 */
5732 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07005733 public @Nullable List<String> getPermittedInputMethodsForCurrentUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005734 throwIfParentInstance("getPermittedInputMethodsForCurrentUser");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005735 if (mService != null) {
5736 try {
5737 return mService.getPermittedInputMethodsForCurrentUser();
5738 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005739 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005740 }
5741 }
5742 return null;
5743 }
5744
5745 /**
Edman Anjos52088e42017-01-13 22:26:17 +01005746 * Get the list of apps to keep around as APKs even if no user has currently installed it. This
5747 * function can be called by a device owner or by a delegate given the
5748 * {@link #DELEGATION_KEEP_UNINSTALLED_PACKAGES} scope via {@link #setDelegatedScopes}.
5749 * <p>
5750 * Please note that packages returned in this method are not automatically pre-cached.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005751 *
Edman Anjos52088e42017-01-13 22:26:17 +01005752 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
5753 * {@code null} if the caller is a keep uninstalled packages delegate.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005754 * @return List of package names to keep cached.
Edman Anjos52088e42017-01-13 22:26:17 +01005755 * @see #setDelegatedScopes
5756 * @see #DELEGATION_KEEP_UNINSTALLED_PACKAGES
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005757 * @hide
5758 */
Edman Anjos52088e42017-01-13 22:26:17 +01005759 public @Nullable List<String> getKeepUninstalledPackages(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005760 throwIfParentInstance("getKeepUninstalledPackages");
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005761 if (mService != null) {
5762 try {
Edman Anjos52088e42017-01-13 22:26:17 +01005763 return mService.getKeepUninstalledPackages(admin, mContext.getPackageName());
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005764 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005765 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005766 }
5767 }
5768 return null;
5769 }
5770
5771 /**
Edman Anjos52088e42017-01-13 22:26:17 +01005772 * Set a list of apps to keep around as APKs even if no user has currently installed it. This
5773 * function can be called by a device owner or by a delegate given the
5774 * {@link #DELEGATION_KEEP_UNINSTALLED_PACKAGES} scope via {@link #setDelegatedScopes}.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005775 *
5776 * <p>Please note that setting this policy does not imply that specified apps will be
5777 * automatically pre-cached.</p>
5778 *
Edman Anjos52088e42017-01-13 22:26:17 +01005779 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
5780 * {@code null} if the caller is a keep uninstalled packages delegate.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005781 * @param packageNames List of package names to keep cached.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005782 * @throws SecurityException if {@code admin} is not a device owner.
Edman Anjos52088e42017-01-13 22:26:17 +01005783 * @see #setDelegatedScopes
5784 * @see #DELEGATION_KEEP_UNINSTALLED_PACKAGES
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005785 * @hide
5786 */
Edman Anjos52088e42017-01-13 22:26:17 +01005787 public void setKeepUninstalledPackages(@Nullable ComponentName admin,
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005788 @NonNull List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005789 throwIfParentInstance("setKeepUninstalledPackages");
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005790 if (mService != null) {
5791 try {
Edman Anjos52088e42017-01-13 22:26:17 +01005792 mService.setKeepUninstalledPackages(admin, mContext.getPackageName(), packageNames);
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005793 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005794 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005795 }
5796 }
5797 }
5798
5799 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04005800 * Called by a device owner to create a user with the specified name. The UserHandle returned
5801 * by this method should not be persisted as user handles are recycled as users are removed and
5802 * created. If you need to persist an identifier for this user, use
5803 * {@link UserManager#getSerialNumberForUser}.
5804 *
5805 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5806 * @param name the user's name
5807 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07005808 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
5809 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01005810 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005811 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01005812 * @removed From {@link android.os.Build.VERSION_CODES#N}
Julia Reynolds1e958392014-05-16 14:25:21 -04005813 */
Kenny Guy14f48e52015-06-29 15:12:36 +01005814 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07005815 public @Nullable UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04005816 return null;
5817 }
5818
5819 /**
Jason Monk03978a42014-06-10 15:05:30 -04005820 * Called by a device owner to create a user with the specified name. The UserHandle returned
5821 * by this method should not be persisted as user handles are recycled as users are removed and
5822 * created. If you need to persist an identifier for this user, use
5823 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
5824 * immediately.
5825 *
5826 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
5827 * as registered as an active admin on the new user. The profile owner package will be
5828 * installed on the new user if it already is installed on the device.
5829 *
5830 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
5831 * profileOwnerComponent when onEnable is called.
5832 *
5833 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5834 * @param name the user's name
5835 * @param ownerName the human readable name of the organisation associated with this DPM.
5836 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
5837 * the user.
5838 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
5839 * on the new user.
5840 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07005841 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
5842 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01005843 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005844 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01005845 * @removed From {@link android.os.Build.VERSION_CODES#N}
Jason Monk03978a42014-06-10 15:05:30 -04005846 */
Kenny Guy14f48e52015-06-29 15:12:36 +01005847 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07005848 public @Nullable UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
Robin Lee25e26452015-06-02 09:56:29 -07005849 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04005850 return null;
5851 }
5852
5853 /**
phweissa92e1212016-01-25 17:14:10 +01005854 * Flag used by {@link #createAndManageUser} to skip setup wizard after creating a new user.
phweiss343fb332016-01-25 14:48:59 +01005855 */
5856 public static final int SKIP_SETUP_WIZARD = 0x0001;
5857
5858 /**
Lenka Trochtovac8202c82016-01-26 15:11:09 +01005859 * Flag used by {@link #createAndManageUser} to specify that the user should be created
5860 * ephemeral.
5861 * @hide
5862 */
5863 public static final int MAKE_USER_EPHEMERAL = 0x0002;
5864
5865 /**
phweissa92e1212016-01-25 17:14:10 +01005866 * Called by a device owner to create a user with the specified name and a given component of
5867 * the calling package as profile owner. The UserHandle returned by this method should not be
5868 * persisted as user handles are recycled as users are removed and created. If you need to
5869 * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new
5870 * user will not be started in the background.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005871 * <p>
5872 * admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also a
5873 * DeviceAdminReceiver in the same package as admin, and will become the profile owner and will
5874 * be registered as an active admin on the new user. The profile owner package will be installed
5875 * on the new user.
5876 * <p>
5877 * If the adminExtras are not null, they will be stored on the device until the user is started
5878 * for the first time. Then the extras will be passed to the admin when onEnable is called.
phweiss343fb332016-01-25 14:48:59 +01005879 *
5880 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5881 * @param name The user's name.
phweissa92e1212016-01-25 17:14:10 +01005882 * @param profileOwner Which {@link DeviceAdminReceiver} will be profile owner. Has to be in the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005883 * same package as admin, otherwise no user is created and an
5884 * IllegalArgumentException is thrown.
phweiss343fb332016-01-25 14:48:59 +01005885 * @param adminExtras Extras that will be passed to onEnable of the admin receiver on the new
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005886 * user.
phweissa92e1212016-01-25 17:14:10 +01005887 * @param flags {@link #SKIP_SETUP_WIZARD} is supported.
phweiss343fb332016-01-25 14:48:59 +01005888 * @see UserHandle
5889 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
5890 * user could not be created.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005891 * @throws SecurityException if {@code admin} is not a device owner.
phweiss343fb332016-01-25 14:48:59 +01005892 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005893 public @Nullable UserHandle createAndManageUser(@NonNull ComponentName admin,
5894 @NonNull String name,
phweissa92e1212016-01-25 17:14:10 +01005895 @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras,
5896 int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005897 throwIfParentInstance("createAndManageUser");
phweiss343fb332016-01-25 14:48:59 +01005898 try {
phweissa92e1212016-01-25 17:14:10 +01005899 return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags);
phweiss343fb332016-01-25 14:48:59 +01005900 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005901 throw re.rethrowFromSystemServer();
phweiss343fb332016-01-25 14:48:59 +01005902 }
phweiss343fb332016-01-25 14:48:59 +01005903 }
5904
5905 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005906 * Called by a device owner to remove a user and all associated data. The primary user can not
5907 * be removed.
Julia Reynolds1e958392014-05-16 14:25:21 -04005908 *
5909 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5910 * @param userHandle the user to remove.
5911 * @return {@code true} if the user was removed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005912 * @throws SecurityException if {@code admin} is not a device owner.
Julia Reynolds1e958392014-05-16 14:25:21 -04005913 */
Robin Lee25e26452015-06-02 09:56:29 -07005914 public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005915 throwIfParentInstance("removeUser");
Julia Reynolds1e958392014-05-16 14:25:21 -04005916 try {
5917 return mService.removeUser(admin, userHandle);
5918 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005919 throw re.rethrowFromSystemServer();
Julia Reynolds1e958392014-05-16 14:25:21 -04005920 }
5921 }
5922
5923 /**
Jason Monk582d9112014-07-09 19:57:08 -04005924 * Called by a device owner to switch the specified user to the foreground.
5925 *
5926 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5927 * @param userHandle the user to switch to; null will switch to primary.
5928 * @return {@code true} if the switch was successful, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005929 * @throws SecurityException if {@code admin} is not a device owner.
Jason Monk582d9112014-07-09 19:57:08 -04005930 * @see Intent#ACTION_USER_FOREGROUND
5931 */
Robin Lee25e26452015-06-02 09:56:29 -07005932 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005933 throwIfParentInstance("switchUser");
Jason Monk582d9112014-07-09 19:57:08 -04005934 try {
5935 return mService.switchUser(admin, userHandle);
5936 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005937 throw re.rethrowFromSystemServer();
Jason Monk582d9112014-07-09 19:57:08 -04005938 }
5939 }
5940
5941 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00005942 * Retrieves the application restrictions for a given target application running in the calling
5943 * user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005944 * <p>
5945 * The caller must be a profile or device owner on that user, or the package allowed to manage
Edman Anjosf9946772016-11-28 16:35:15 +01005946 * application restrictions via {@link #setDelegatedScopes} with the
5947 * {@link #DELEGATION_APP_RESTRICTIONS} scope; otherwise a security exception will be thrown.
Robin Lee66e5d962014-04-09 16:44:21 +01005948 *
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005949 * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
5950 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00005951 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005952 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01005953 * @param packageName The name of the package to fetch restricted settings of.
5954 * @return {@link Bundle} of settings corresponding to what was set last time
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005955 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty
5956 * {@link Bundle} if no restrictions have been set.
5957 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01005958 * @see #setDelegatedScopes
5959 * @see #DELEGATION_APP_RESTRICTIONS
Robin Lee66e5d962014-04-09 16:44:21 +01005960 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005961 @WorkerThread
Makoto Onuki408e8e42016-10-25 12:10:27 -07005962 public @NonNull Bundle getApplicationRestrictions(
5963 @Nullable ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005964 throwIfParentInstance("getApplicationRestrictions");
Robin Lee66e5d962014-04-09 16:44:21 +01005965 if (mService != null) {
5966 try {
Edman Anjosf9946772016-11-28 16:35:15 +01005967 return mService.getApplicationRestrictions(admin, mContext.getPackageName(),
5968 packageName);
Robin Lee66e5d962014-04-09 16:44:21 +01005969 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005970 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01005971 }
5972 }
5973 return null;
5974 }
Amith Yamasanibe465322014-04-24 13:45:17 -07005975
5976 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05005977 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07005978 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005979 * The calling device admin must be a profile or device owner; if it is not, a security
5980 * exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07005981 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005982 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5983 * @param key The key of the restriction. See the constants in {@link android.os.UserManager}
5984 * for the list of keys.
5985 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanibe465322014-04-24 13:45:17 -07005986 */
Robin Lee25e26452015-06-02 09:56:29 -07005987 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005988 throwIfParentInstance("addUserRestriction");
Amith Yamasanibe465322014-04-24 13:45:17 -07005989 if (mService != null) {
5990 try {
5991 mService.setUserRestriction(admin, key, true);
5992 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005993 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07005994 }
5995 }
5996 }
5997
5998 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05005999 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07006000 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006001 * The calling device admin must be a profile or device owner; if it is not, a security
6002 * exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07006003 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006004 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6005 * @param key The key of the restriction. See the constants in {@link android.os.UserManager}
6006 * for the list of keys.
6007 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanibe465322014-04-24 13:45:17 -07006008 */
Robin Lee25e26452015-06-02 09:56:29 -07006009 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006010 throwIfParentInstance("clearUserRestriction");
Amith Yamasanibe465322014-04-24 13:45:17 -07006011 if (mService != null) {
6012 try {
6013 mService.setUserRestriction(admin, key, false);
6014 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006015 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07006016 }
6017 }
6018 }
Adam Connors010cfd42014-04-16 12:48:13 +01006019
6020 /**
Makoto Onuki3a3092f2015-10-30 11:07:51 -07006021 * Called by a profile or device owner to get user restrictions set with
6022 * {@link #addUserRestriction(ComponentName, String)}.
6023 * <p>
6024 * The target user may have more restrictions set by the system or other device owner / profile
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006025 * owner. To get all the user restrictions currently set, use
Makoto Onuki3a3092f2015-10-30 11:07:51 -07006026 * {@link UserManager#getUserRestrictions()}.
6027 *
6028 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006029 * @throws SecurityException if {@code admin} is not a device or profile owner.
Makoto Onuki3a3092f2015-10-30 11:07:51 -07006030 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006031 public @NonNull Bundle getUserRestrictions(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006032 throwIfParentInstance("getUserRestrictions");
Makoto Onuki3a3092f2015-10-30 11:07:51 -07006033 Bundle ret = null;
6034 if (mService != null) {
6035 try {
Sudheer Shanka549b9692016-03-30 17:12:07 -07006036 ret = mService.getUserRestrictions(admin);
6037 } catch (RemoteException e) {
6038 throw e.rethrowFromSystemServer();
6039 }
6040 }
6041 return ret == null ? new Bundle() : ret;
6042 }
6043
6044 /**
phweiss73145f42017-01-17 19:06:38 +01006045 * Called by any app to display a support dialog when a feature was disabled by an admin.
6046 * This returns an intent that can be used with {@link Context#startActivity(Intent)} to
6047 * display the dialog. It will tell the user that the feature indicated by {@code restriction}
6048 * was disabled by an admin, and include a link for more information. The default content of
6049 * the dialog can be changed by the restricting admin via
6050 * {@link #setShortSupportMessage(ComponentName, CharSequence)}. If the restriction is not
6051 * set (i.e. the feature is available), then the return value will be {@code null}.
6052 * @param restriction Indicates for which feature the dialog should be displayed. Can be a
6053 * user restriction from {@link UserManager}, e.g.
6054 * {@link UserManager#DISALLOW_ADJUST_VOLUME}, or one of the constants
6055 * {@link #POLICY_DISABLE_CAMERA} or {@link #POLICY_DISABLE_SCREEN_CAPTURE}.
6056 * @return Intent An intent to be used to start the dialog-activity if the restriction is
6057 * set by an admin, or null if the restriction does not exist or no admin set it.
6058 */
6059 public Intent createAdminSupportIntent(@NonNull String restriction) {
6060 throwIfParentInstance("createAdminSupportIntent");
6061 if (mService != null) {
6062 try {
6063 return mService.createAdminSupportIntent(restriction);
6064 } catch (RemoteException e) {
6065 throw e.rethrowFromSystemServer();
6066 }
6067 }
6068 return null;
6069 }
6070
6071 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006072 * Hide or unhide packages. When a package is hidden it is unavailable for use, but the data and
6073 * actual package file remain. This function can be called by a device owner, profile owner, or
6074 * by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via
6075 * {@link #setDelegatedScopes}.
Julia Reynolds966881e2014-05-14 12:23:08 -04006076 *
Edman Anjos52088e42017-01-13 22:26:17 +01006077 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
6078 * {@code null} if the caller is a package access delegate.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07006079 * @param packageName The name of the package to hide or unhide.
6080 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006081 * unhidden.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07006082 * @return boolean Whether the hidden setting of the package was successfully updated.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006083 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01006084 * @see #setDelegatedScopes
6085 * @see #DELEGATION_PACKAGE_ACCESS
Julia Reynolds966881e2014-05-14 12:23:08 -04006086 */
Robin Lee25e26452015-06-02 09:56:29 -07006087 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07006088 boolean hidden) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006089 throwIfParentInstance("setApplicationHidden");
Julia Reynolds966881e2014-05-14 12:23:08 -04006090 if (mService != null) {
6091 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006092 return mService.setApplicationHidden(admin, mContext.getPackageName(), packageName,
6093 hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04006094 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006095 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04006096 }
6097 }
6098 return false;
6099 }
6100
6101 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006102 * Determine if a package is hidden. This function can be called by a device owner, profile
6103 * owner, or by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via
6104 * {@link #setDelegatedScopes}.
Julia Reynolds966881e2014-05-14 12:23:08 -04006105 *
Edman Anjos52088e42017-01-13 22:26:17 +01006106 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
6107 * {@code null} if the caller is a package access delegate.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07006108 * @param packageName The name of the package to retrieve the hidden status of.
6109 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006110 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01006111 * @see #setDelegatedScopes
6112 * @see #DELEGATION_PACKAGE_ACCESS
Julia Reynolds966881e2014-05-14 12:23:08 -04006113 */
Robin Lee25e26452015-06-02 09:56:29 -07006114 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006115 throwIfParentInstance("isApplicationHidden");
Julia Reynolds966881e2014-05-14 12:23:08 -04006116 if (mService != null) {
6117 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006118 return mService.isApplicationHidden(admin, mContext.getPackageName(), packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04006119 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006120 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04006121 }
6122 }
6123 return false;
6124 }
6125
6126 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006127 * Re-enable a system app that was disabled by default when the user was initialized. This
6128 * function can be called by a device owner, profile owner, or by a delegate given the
6129 * {@link #DELEGATION_ENABLE_SYSTEM_APP} scope via {@link #setDelegatedScopes}.
Adam Connors655be2a2014-07-14 09:01:25 +00006130 *
Edman Anjos52088e42017-01-13 22:26:17 +01006131 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
6132 * {@code null} if the caller is an enable system app delegate.
Makoto Onuki32b30572015-12-11 14:29:51 -08006133 * @param packageName The package to be re-enabled in the calling profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006134 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01006135 * @see #setDelegatedScopes
6136 * @see #DELEGATION_PACKAGE_ACCESS
Adam Connors655be2a2014-07-14 09:01:25 +00006137 */
Robin Lee25e26452015-06-02 09:56:29 -07006138 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006139 throwIfParentInstance("enableSystemApp");
Adam Connors655be2a2014-07-14 09:01:25 +00006140 if (mService != null) {
6141 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006142 mService.enableSystemApp(admin, mContext.getPackageName(), packageName);
Adam Connors655be2a2014-07-14 09:01:25 +00006143 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006144 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00006145 }
6146 }
6147 }
6148
6149 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006150 * Re-enable system apps by intent that were disabled by default when the user was initialized.
6151 * This function can be called by a device owner, profile owner, or by a delegate given the
6152 * {@link #DELEGATION_ENABLE_SYSTEM_APP} scope via {@link #setDelegatedScopes}.
Adam Connors655be2a2014-07-14 09:01:25 +00006153 *
Edman Anjos52088e42017-01-13 22:26:17 +01006154 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
6155 * {@code null} if the caller is an enable system app delegate.
Adam Connors655be2a2014-07-14 09:01:25 +00006156 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006157 * intent will be re-enabled in the calling profile.
Adam Connors655be2a2014-07-14 09:01:25 +00006158 * @return int The number of activities that matched the intent and were installed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006159 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01006160 * @see #setDelegatedScopes
6161 * @see #DELEGATION_PACKAGE_ACCESS
Adam Connors655be2a2014-07-14 09:01:25 +00006162 */
Robin Lee25e26452015-06-02 09:56:29 -07006163 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006164 throwIfParentInstance("enableSystemApp");
Adam Connors655be2a2014-07-14 09:01:25 +00006165 if (mService != null) {
6166 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006167 return mService.enableSystemAppWithIntent(admin, mContext.getPackageName(), intent);
Adam Connors655be2a2014-07-14 09:01:25 +00006168 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006169 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00006170 }
6171 }
6172 return 0;
6173 }
6174
6175 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00006176 * Called by a device owner or profile owner to disable account management for a specific type
6177 * of account.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006178 * <p>
6179 * The calling device admin must be a device owner or profile owner. If it is not, a security
6180 * exception will be thrown.
6181 * <p>
6182 * When account management is disabled for an account type, adding or removing an account of
6183 * that type will not be possible.
6184 * <p>
6185 * From {@link android.os.Build.VERSION_CODES#N} the profile or device owner can still use
Benjamin Franzb6c0ce42015-11-05 10:06:51 +00006186 * {@link android.accounts.AccountManager} APIs to add or remove accounts when account
6187 * management for a specific type is disabled.
6188 *
Sander Alewijnse650c3342014-05-08 18:00:50 +01006189 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6190 * @param accountType For which account management is disabled or enabled.
6191 * @param disabled The boolean indicating that account management will be disabled (true) or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006192 * enabled (false).
6193 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnse650c3342014-05-08 18:00:50 +01006194 */
Robin Lee25e26452015-06-02 09:56:29 -07006195 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01006196 boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006197 throwIfParentInstance("setAccountManagementDisabled");
Sander Alewijnse650c3342014-05-08 18:00:50 +01006198 if (mService != null) {
6199 try {
6200 mService.setAccountManagementDisabled(admin, accountType, disabled);
6201 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006202 throw e.rethrowFromSystemServer();
Sander Alewijnse650c3342014-05-08 18:00:50 +01006203 }
6204 }
6205 }
6206
6207 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01006208 * Gets the array of accounts for which account management is disabled by the profile owner.
6209 *
6210 * <p> Account management can be disabled/enabled by calling
6211 * {@link #setAccountManagementDisabled}.
6212 *
6213 * @return a list of account types for which account management has been disabled.
6214 *
6215 * @see #setAccountManagementDisabled
6216 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006217 public @Nullable String[] getAccountTypesWithManagementDisabled() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006218 throwIfParentInstance("getAccountTypesWithManagementDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07006219 return getAccountTypesWithManagementDisabledAsUser(myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01006220 }
6221
6222 /**
6223 * @see #getAccountTypesWithManagementDisabled()
6224 * @hide
6225 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006226 public @Nullable String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01006227 if (mService != null) {
6228 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01006229 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01006230 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006231 throw e.rethrowFromSystemServer();
Sander Alewijnse5c02db62014-05-07 10:46:57 +01006232 }
6233 }
6234
6235 return null;
6236 }
justinzhang511e0d82014-03-24 16:09:24 -04006237
6238 /**
Jason Monkd7b86212014-06-16 13:15:38 -04006239 * Sets which packages may enter lock task mode.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006240 * <p>
Esteban Talaverabdcada92017-02-01 14:20:06 +00006241 * Any packages that share uid with an allowed package will also be allowed to activate lock
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006242 * task. From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task
Esteban Talaverabdcada92017-02-01 14:20:06 +00006243 * package list results in locked tasks belonging to those packages to be finished.
6244 * <p>
6245 * This function can only be called by the device owner or by a profile owner of a user/profile
6246 * that is affiliated with the device owner user. See {@link #setAffiliationIds}. Any packages
6247 * set via this method will be cleared if the user becomes unaffiliated.
Jason Monkd7b86212014-06-16 13:15:38 -04006248 *
Jason Monkd7b86212014-06-16 13:15:38 -04006249 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04006250 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Esteban Talaverabdcada92017-02-01 14:20:06 +00006251 * @throws SecurityException if {@code admin} is not the device owner, or the profile owner of
6252 * an affiliated user or profile.
Jason Monkd7b86212014-06-16 13:15:38 -04006253 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00006254 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
6255 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04006256 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04006257 */
Esteban Talaverabdcada92017-02-01 14:20:06 +00006258 public void setLockTaskPackages(@NonNull ComponentName admin, @NonNull String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04006259 throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006260 throwIfParentInstance("setLockTaskPackages");
justinzhang511e0d82014-03-24 16:09:24 -04006261 if (mService != null) {
6262 try {
Jason Monk48aacba2014-08-13 16:29:08 -04006263 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04006264 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006265 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04006266 }
6267 }
6268 }
6269
6270 /**
Esteban Talaverabdcada92017-02-01 14:20:06 +00006271 * Returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04006272 *
Esteban Talaverabdcada92017-02-01 14:20:06 +00006273 * @throws SecurityException if {@code admin} is not the device owner, or the profile owner of
6274 * an affiliated user or profile.
6275 * @see #setLockTaskPackages
justinzhang511e0d82014-03-24 16:09:24 -04006276 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006277 public @NonNull String[] getLockTaskPackages(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006278 throwIfParentInstance("getLockTaskPackages");
justinzhang511e0d82014-03-24 16:09:24 -04006279 if (mService != null) {
6280 try {
Jason Monk48aacba2014-08-13 16:29:08 -04006281 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04006282 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006283 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04006284 }
6285 }
Esteban Talaverabdcada92017-02-01 14:20:06 +00006286 return new String[0];
justinzhang511e0d82014-03-24 16:09:24 -04006287 }
6288
6289 /**
6290 * This function lets the caller know whether the given component is allowed to start the
6291 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04006292 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04006293 */
Jason Monkd7b86212014-06-16 13:15:38 -04006294 public boolean isLockTaskPermitted(String pkg) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006295 throwIfParentInstance("isLockTaskPermitted");
justinzhang511e0d82014-03-24 16:09:24 -04006296 if (mService != null) {
6297 try {
Jason Monkd7b86212014-06-16 13:15:38 -04006298 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04006299 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006300 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04006301 }
6302 }
6303 return false;
6304 }
Julia Reynoldsda551652014-05-14 17:15:16 -04006305
6306 /**
6307 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
6308 * 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 -07006309 * <p>
6310 * The settings that can be updated with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04006311 * <ul>
6312 * <li>{@link Settings.Global#ADB_ENABLED}</li>
6313 * <li>{@link Settings.Global#AUTO_TIME}</li>
6314 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04006315 * <li>{@link Settings.Global#DATA_ROAMING}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04006316 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04006317 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006318 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN} This setting is only available from
6319 * {@link android.os.Build.VERSION_CODES#M} onwards and can only be set if
6320 * {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
6321 * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li> This setting is only
6322 * available from {@link android.os.Build.VERSION_CODES#M} onwards.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04006323 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006324 * <p>
6325 * Changing the following settings has no effect as of {@link android.os.Build.VERSION_CODES#M}:
Esteban Talavera656fa7f2015-06-29 17:41:39 +01006326 * <ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006327 * <li>{@link Settings.Global#BLUETOOTH_ON}. Use
6328 * {@link android.bluetooth.BluetoothAdapter#enable()} and
6329 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01006330 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006331 * <li>{@link Settings.Global#MODE_RINGER}. Use
6332 * {@link android.media.AudioManager#setRingerMode(int)} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01006333 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006334 * <li>{@link Settings.Global#WIFI_ON}. Use
6335 * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01006336 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04006337 *
6338 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6339 * @param setting The name of the setting to update.
6340 * @param value The value to update the setting to.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006341 * @throws SecurityException if {@code admin} is not a device owner.
Julia Reynoldsda551652014-05-14 17:15:16 -04006342 */
Robin Lee25e26452015-06-02 09:56:29 -07006343 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006344 throwIfParentInstance("setGlobalSetting");
Julia Reynoldsda551652014-05-14 17:15:16 -04006345 if (mService != null) {
6346 try {
6347 mService.setGlobalSetting(admin, setting, value);
6348 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006349 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04006350 }
6351 }
6352 }
6353
6354 /**
6355 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
6356 * that the value of the setting is in the correct form for the setting type should be performed
6357 * by the caller.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006358 * <p>
6359 * The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04006360 * <ul>
6361 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
6362 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
6363 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006364 * <p>
6365 * A device owner can additionally update the following settings:
Julia Reynolds82735bc2014-09-04 16:43:30 -04006366 * <ul>
6367 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
6368 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006369 *
Suprabh Shukla0b1356f2017-02-21 14:33:50 -08006370 * <strong>Note: Starting from Android O, apps should no longer call this method with the
6371 * setting {@link android.provider.Settings.Secure#INSTALL_NON_MARKET_APPS}, which is
6372 * deprecated. Instead, device owners or profile owners should use the restriction
6373 * {@link UserManager#DISALLOW_INSTALL_UNKNOWN_SOURCES}.
6374 * If any app targeting {@link android.os.Build.VERSION_CODES#O} or higher calls this method
6375 * with {@link android.provider.Settings.Secure#INSTALL_NON_MARKET_APPS},
6376 * an {@link UnsupportedOperationException} is thrown.
6377 * </strong>
6378 *
Julia Reynoldsda551652014-05-14 17:15:16 -04006379 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6380 * @param setting The name of the setting to update.
6381 * @param value The value to update the setting to.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006382 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynoldsda551652014-05-14 17:15:16 -04006383 */
Robin Lee25e26452015-06-02 09:56:29 -07006384 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006385 throwIfParentInstance("setSecureSetting");
Julia Reynoldsda551652014-05-14 17:15:16 -04006386 if (mService != null) {
6387 try {
6388 mService.setSecureSetting(admin, setting, value);
6389 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006390 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04006391 }
6392 }
6393 }
6394
Amith Yamasanif20d6402014-05-24 15:34:37 -07006395 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006396 * Designates a specific service component as the provider for making permission requests of a
6397 * local or remote administrator of the user.
Amith Yamasanif20d6402014-05-24 15:34:37 -07006398 * <p/>
6399 * Only a profile owner can designate the restrictions provider.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006400 *
Amith Yamasanif20d6402014-05-24 15:34:37 -07006401 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07006402 * @param provider The component name of the service that implements
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006403 * {@link RestrictionsReceiver}. If this param is null, it removes the restrictions
6404 * provider previously assigned.
6405 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanif20d6402014-05-24 15:34:37 -07006406 */
Robin Lee25e26452015-06-02 09:56:29 -07006407 public void setRestrictionsProvider(@NonNull ComponentName admin,
6408 @Nullable ComponentName provider) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006409 throwIfParentInstance("setRestrictionsProvider");
Amith Yamasanif20d6402014-05-24 15:34:37 -07006410 if (mService != null) {
6411 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07006412 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07006413 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006414 throw re.rethrowFromSystemServer();
Amith Yamasanif20d6402014-05-24 15:34:37 -07006415 }
6416 }
6417 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04006418
6419 /**
6420 * Called by profile or device owners to set the master volume mute on or off.
Nicolas Prevotaef3ce22016-09-22 12:00:25 +01006421 * This has no effect when set on a managed profile.
Julia Reynolds4a21b252014-06-04 11:11:43 -04006422 *
6423 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6424 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006425 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds4a21b252014-06-04 11:11:43 -04006426 */
Robin Lee25e26452015-06-02 09:56:29 -07006427 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006428 throwIfParentInstance("setMasterVolumeMuted");
Julia Reynolds4a21b252014-06-04 11:11:43 -04006429 if (mService != null) {
6430 try {
6431 mService.setMasterVolumeMuted(admin, on);
6432 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006433 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04006434 }
6435 }
6436 }
6437
6438 /**
6439 * Called by profile or device owners to check whether the master volume mute is on or off.
6440 *
6441 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6442 * @return {@code true} if master volume is muted, {@code false} if it's not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006443 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds4a21b252014-06-04 11:11:43 -04006444 */
Robin Lee25e26452015-06-02 09:56:29 -07006445 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006446 throwIfParentInstance("isMasterVolumeMuted");
Julia Reynolds4a21b252014-06-04 11:11:43 -04006447 if (mService != null) {
6448 try {
6449 return mService.isMasterVolumeMuted(admin);
6450 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006451 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04006452 }
6453 }
6454 return false;
6455 }
Kenny Guyc13053b2014-05-29 14:17:17 +01006456
6457 /**
Edman Anjosa5f2fb12016-12-19 11:25:54 -08006458 * Change whether a user can uninstall a package. This function can be called by a device owner,
6459 * profile owner, or by a delegate given the {@link #DELEGATION_BLOCK_UNINSTALL} scope via
6460 * {@link #setDelegatedScopes}.
Kenny Guyc13053b2014-05-29 14:17:17 +01006461 *
Edman Anjosa5f2fb12016-12-19 11:25:54 -08006462 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
6463 * {@code null} if the caller is a block uninstall delegate.
Kenny Guyc13053b2014-05-29 14:17:17 +01006464 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01006465 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006466 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjosa5f2fb12016-12-19 11:25:54 -08006467 * @see #setDelegatedScopes
6468 * @see #DELEGATION_BLOCK_UNINSTALL
Kenny Guyc13053b2014-05-29 14:17:17 +01006469 */
Edman Anjosa5f2fb12016-12-19 11:25:54 -08006470 public void setUninstallBlocked(@Nullable ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01006471 boolean uninstallBlocked) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006472 throwIfParentInstance("setUninstallBlocked");
Kenny Guyc13053b2014-05-29 14:17:17 +01006473 if (mService != null) {
6474 try {
Edman Anjosa5f2fb12016-12-19 11:25:54 -08006475 mService.setUninstallBlocked(admin, mContext.getPackageName(), packageName,
6476 uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01006477 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006478 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01006479 }
6480 }
6481 }
6482
6483 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08006484 * Check whether the user has been blocked by device policy from uninstalling a package.
Rubin Xua97855b2014-11-07 05:41:00 +00006485 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00006486 * <p>
6487 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006488 * behavior of this API is changed such that passing {@code null} as the {@code admin} parameter
6489 * will return if any admin has blocked the uninstallation. Before L MR1, passing {@code null}
6490 * will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01006491 *
Robin Lee25e26452015-06-02 09:56:29 -07006492 * @param admin The name of the admin component whose blocking policy will be checked, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006493 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01006494 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00006495 * @return true if uninstallation is blocked.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006496 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyc13053b2014-05-29 14:17:17 +01006497 */
Robin Lee25e26452015-06-02 09:56:29 -07006498 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006499 throwIfParentInstance("isUninstallBlocked");
Kenny Guyc13053b2014-05-29 14:17:17 +01006500 if (mService != null) {
6501 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01006502 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01006503 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006504 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01006505 }
6506 }
6507 return false;
6508 }
Svetoslav976e8bd2014-07-16 15:12:03 -07006509
6510 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006511 * Called by the profile owner of a managed profile to enable widget providers from a given
6512 * package to be available in the parent profile. As a result the user will be able to add
6513 * widgets from the white-listed package running under the profile to a widget host which runs
6514 * under the parent profile, for example the home screen. Note that a package may have zero or
6515 * more provider components, where each component provides a different widget type.
Svetoslav976e8bd2014-07-16 15:12:03 -07006516 * <p>
6517 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07006518 *
6519 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6520 * @param packageName The package from which widget providers are white-listed.
6521 * @return Whether the package was added.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006522 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07006523 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
6524 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
6525 */
Robin Lee25e26452015-06-02 09:56:29 -07006526 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006527 throwIfParentInstance("addCrossProfileWidgetProvider");
Svetoslav976e8bd2014-07-16 15:12:03 -07006528 if (mService != null) {
6529 try {
6530 return mService.addCrossProfileWidgetProvider(admin, packageName);
6531 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006532 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07006533 }
6534 }
6535 return false;
6536 }
6537
6538 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07006539 * Called by the profile owner of a managed profile to disable widget providers from a given
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006540 * package to be available in the parent profile. For this method to take effect the package
6541 * should have been added via
6542 * {@link #addCrossProfileWidgetProvider( android.content.ComponentName, String)}.
Svetoslav976e8bd2014-07-16 15:12:03 -07006543 * <p>
6544 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07006545 *
6546 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006547 * @param packageName The package from which widget providers are no longer white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07006548 * @return Whether the package was removed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006549 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07006550 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
6551 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
6552 */
Esteban Talavera62399912016-01-11 15:37:55 +00006553 public boolean removeCrossProfileWidgetProvider(
6554 @NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006555 throwIfParentInstance("removeCrossProfileWidgetProvider");
Svetoslav976e8bd2014-07-16 15:12:03 -07006556 if (mService != null) {
6557 try {
6558 return mService.removeCrossProfileWidgetProvider(admin, packageName);
6559 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006560 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07006561 }
6562 }
6563 return false;
6564 }
6565
6566 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07006567 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07006568 * available in the parent profile.
6569 *
6570 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6571 * @return The white-listed package list.
Svetoslav976e8bd2014-07-16 15:12:03 -07006572 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
6573 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006574 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07006575 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006576 public @NonNull List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006577 throwIfParentInstance("getCrossProfileWidgetProviders");
Svetoslav976e8bd2014-07-16 15:12:03 -07006578 if (mService != null) {
6579 try {
6580 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
6581 if (providers != null) {
6582 return providers;
6583 }
6584 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006585 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07006586 }
6587 }
6588 return Collections.emptyList();
6589 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006590
6591 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08006592 * Called by profile or device owners to set the user's photo.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006593 *
6594 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6595 * @param icon the bitmap to set as the photo.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006596 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006597 */
Robin Lee25e26452015-06-02 09:56:29 -07006598 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006599 throwIfParentInstance("setUserIcon");
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006600 try {
6601 mService.setUserIcon(admin, icon);
6602 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006603 throw re.rethrowFromSystemServer();
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006604 }
6605 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04006606
6607 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01006608 * Called by device owners to set a local system update policy. When a new policy is set,
6609 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00006610 *
Robin Lee25e26452015-06-02 09:56:29 -07006611 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006612 * components in the device owner package can set system update policies and the most
6613 * recent policy takes effect.
Robin Lee25e26452015-06-02 09:56:29 -07006614 * @param policy the new policy, or {@code null} to clear the current policy.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006615 * @throws SecurityException if {@code admin} is not a device owner.
Rubin Xu5faad8e2015-04-20 17:43:48 +01006616 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00006617 */
Robin Lee25e26452015-06-02 09:56:29 -07006618 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006619 throwIfParentInstance("setSystemUpdatePolicy");
Rubin Xu8027a4f2015-03-10 17:52:37 +00006620 if (mService != null) {
6621 try {
Robin Lee25e26452015-06-02 09:56:29 -07006622 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00006623 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006624 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00006625 }
6626 }
6627 }
6628
6629 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01006630 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00006631 *
Robin Lee25e26452015-06-02 09:56:29 -07006632 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00006633 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006634 public @Nullable SystemUpdatePolicy getSystemUpdatePolicy() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006635 throwIfParentInstance("getSystemUpdatePolicy");
Rubin Xu8027a4f2015-03-10 17:52:37 +00006636 if (mService != null) {
6637 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01006638 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00006639 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006640 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00006641 }
6642 }
6643 return null;
6644 }
Benjamin Franze36087e2015-04-07 16:40:34 +01006645
6646 /**
6647 * Called by a device owner to disable the keyguard altogether.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006648 * <p>
6649 * Setting the keyguard to disabled has the same effect as choosing "None" as the screen lock
6650 * type. However, this call has no effect if a password, pin or pattern is currently set. If a
6651 * password, pin or pattern is set after the keyguard was disabled, the keyguard stops being
6652 * disabled.
Benjamin Franze36087e2015-04-07 16:40:34 +01006653 *
6654 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01006655 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01006656 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006657 * place. {@code true} otherwise.
6658 * @throws SecurityException if {@code admin} is not a device owner.
Benjamin Franze36087e2015-04-07 16:40:34 +01006659 */
Robin Lee25e26452015-06-02 09:56:29 -07006660 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006661 throwIfParentInstance("setKeyguardDisabled");
Benjamin Franze36087e2015-04-07 16:40:34 +01006662 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01006663 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01006664 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006665 throw re.rethrowFromSystemServer();
Benjamin Franze36087e2015-04-07 16:40:34 +01006666 }
6667 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00006668
6669 /**
Benjamin Franzbece8062015-05-06 12:14:31 +01006670 * Called by device owner to disable the status bar. Disabling the status bar blocks
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006671 * notifications, quick settings and other screen overlays that allow escaping from a single use
6672 * device.
Benjamin Franzea2ec972015-03-16 17:18:09 +00006673 *
6674 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01006675 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006676 * @return {@code false} if attempting to disable the status bar failed. {@code true} otherwise.
6677 * @throws SecurityException if {@code admin} is not a device owner.
Benjamin Franzea2ec972015-03-16 17:18:09 +00006678 */
Robin Lee25e26452015-06-02 09:56:29 -07006679 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006680 throwIfParentInstance("setStatusBarDisabled");
Benjamin Franzea2ec972015-03-16 17:18:09 +00006681 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01006682 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00006683 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006684 throw re.rethrowFromSystemServer();
Benjamin Franzea2ec972015-03-16 17:18:09 +00006685 }
6686 }
Rubin Xudc105cc2015-04-14 23:38:01 +01006687
6688 /**
Charles Hedea0c3b2017-01-13 10:04:12 +00006689 * Called by the system update service to notify device and profile owners of pending system
6690 * updates.
Rubin Xudc105cc2015-04-14 23:38:01 +01006691 *
Charles Hedea0c3b2017-01-13 10:04:12 +00006692 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
6693 * permission. This method should only be used when it is unknown whether the pending system
6694 * update is a security patch. Otherwise, use
6695 * {@link #notifyPendingSystemUpdate(long, boolean)}.
6696 *
6697 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()}
6698 * indicating when the current pending update was first available. {@code -1} if no
6699 * update is available.
6700 * @see #notifyPendingSystemUpdate(long, boolean)
Rubin Xudc105cc2015-04-14 23:38:01 +01006701 * @hide
6702 */
6703 @SystemApi
6704 public void notifyPendingSystemUpdate(long updateReceivedTime) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006705 throwIfParentInstance("notifyPendingSystemUpdate");
Rubin Xudc105cc2015-04-14 23:38:01 +01006706 if (mService != null) {
6707 try {
Charles Hedea0c3b2017-01-13 10:04:12 +00006708 mService.notifyPendingSystemUpdate(SystemUpdateInfo.of(updateReceivedTime));
6709 } catch (RemoteException re) {
6710 throw re.rethrowFromSystemServer();
6711 }
6712 }
6713 }
6714
6715 /**
6716 * Called by the system update service to notify device and profile owners of pending system
6717 * updates.
6718 *
6719 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
6720 * permission. This method should be used instead of {@link #notifyPendingSystemUpdate(long)}
6721 * when it is known whether the pending system update is a security patch.
6722 *
6723 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()}
6724 * indicating when the current pending update was first available. {@code -1} if no
6725 * update is available.
6726 * @param isSecurityPatch {@code true} if this system update is purely a security patch;
6727 * {@code false} if not.
6728 * @see #notifyPendingSystemUpdate(long)
6729 * @hide
6730 */
6731 @SystemApi
6732 public void notifyPendingSystemUpdate(long updateReceivedTime, boolean isSecurityPatch) {
6733 throwIfParentInstance("notifyPendingSystemUpdate");
6734 if (mService != null) {
6735 try {
6736 mService.notifyPendingSystemUpdate(SystemUpdateInfo.of(updateReceivedTime,
6737 isSecurityPatch));
Rubin Xudc105cc2015-04-14 23:38:01 +01006738 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006739 throw re.rethrowFromSystemServer();
Rubin Xudc105cc2015-04-14 23:38:01 +01006740 }
6741 }
6742 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04006743
6744 /**
Pavel Grafovd65799e2016-12-02 11:21:45 +00006745 * Called by device or profile owners to get information about a pending system update.
6746 *
6747 * @param admin Which profile or device owner this request is associated with.
6748 * @return Information about a pending system update or {@code null} if no update pending.
6749 * @throws SecurityException if {@code admin} is not a device or profile owner.
6750 * @see DeviceAdminReceiver#onSystemUpdatePending(Context, Intent, long)
6751 */
6752 public @Nullable SystemUpdateInfo getPendingSystemUpdate(@NonNull ComponentName admin) {
6753 throwIfParentInstance("getPendingSystemUpdate");
6754 try {
6755 return mService.getPendingSystemUpdate(admin);
6756 } catch (RemoteException re) {
6757 throw re.rethrowFromSystemServer();
6758 }
6759 }
6760
6761 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006762 * Set the default response for future runtime permission requests by applications. This
6763 * function can be called by a device owner, profile owner, or by a delegate given the
6764 * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}.
6765 * The policy can allow for normal operation which prompts the user to grant a permission, or
6766 * can allow automatic granting or denying of runtime permission requests by an application.
6767 * This also applies to new permissions declared by app updates. When a permission is denied or
6768 * granted this way, the effect is equivalent to setting the permission * grant state via
6769 * {@link #setPermissionGrantState}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006770 * <p/>
6771 * As this policy only acts on runtime permission requests, it only applies to applications
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07006772 * built with a {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Benjamin Franz45dd6662015-07-08 14:24:14 +01006773 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07006774 * @param admin Which profile or device owner this request is associated with.
6775 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006776 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
6777 * @throws SecurityException if {@code admin} is not a device or profile owner.
Benjamin Franz45dd6662015-07-08 14:24:14 +01006778 * @see #setPermissionGrantState
Edman Anjos52088e42017-01-13 22:26:17 +01006779 * @see #setDelegatedScopes
6780 * @see #DELEGATION_PERMISSION_GRANT
Amith Yamasanid49489b2015-04-28 14:00:26 -07006781 */
Robin Lee25e26452015-06-02 09:56:29 -07006782 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006783 throwIfParentInstance("setPermissionPolicy");
Amith Yamasanid49489b2015-04-28 14:00:26 -07006784 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006785 mService.setPermissionPolicy(admin, mContext.getPackageName(), policy);
Amith Yamasanid49489b2015-04-28 14:00:26 -07006786 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006787 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07006788 }
6789 }
6790
6791 /**
6792 * Returns the current runtime permission policy set by the device or profile owner. The
6793 * default is {@link #PERMISSION_POLICY_PROMPT}.
Edman Anjos52088e42017-01-13 22:26:17 +01006794 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07006795 * @param admin Which profile or device owner this request is associated with.
6796 * @return the current policy for future permission requests.
6797 */
Esteban Talavera28b95702015-06-24 15:23:42 +01006798 public int getPermissionPolicy(ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006799 throwIfParentInstance("getPermissionPolicy");
Amith Yamasanid49489b2015-04-28 14:00:26 -07006800 try {
6801 return mService.getPermissionPolicy(admin);
6802 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006803 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07006804 }
6805 }
6806
6807 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006808 * Sets the grant state of a runtime permission for a specific application. The state can be
6809 * {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it through the UI,
6810 * {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission is denied and the user
6811 * cannot manage it through the UI, and {@link #PERMISSION_GRANT_STATE_GRANTED granted} in which
6812 * the permission is granted and the user cannot manage it through the UI. This might affect all
6813 * permissions in a group that the runtime permission belongs to. This method can only be called
Edman Anjos52088e42017-01-13 22:26:17 +01006814 * by a profile owner, device owner, or a delegate given the
6815 * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006816 * <p/>
6817 * Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not revoke
6818 * the permission. It retains the previous grant, if any.
6819 * <p/>
6820 * Permissions can be granted or revoked only for applications built with a
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07006821 * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07006822 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07006823 * @param admin Which profile or device owner this request is associated with.
6824 * @param packageName The application to grant or revoke a permission to.
6825 * @param permission The permission to grant or revoke.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006826 * @param grantState The permission grant state which is one of
6827 * {@link #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
6828 * {@link #PERMISSION_GRANT_STATE_GRANTED},
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006829 * @return whether the permission was successfully granted or revoked.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006830 * @throws SecurityException if {@code admin} is not a device or profile owner.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006831 * @see #PERMISSION_GRANT_STATE_DENIED
6832 * @see #PERMISSION_GRANT_STATE_DEFAULT
6833 * @see #PERMISSION_GRANT_STATE_GRANTED
Edman Anjos52088e42017-01-13 22:26:17 +01006834 * @see #setDelegatedScopes
6835 * @see #DELEGATION_PERMISSION_GRANT
Amith Yamasanid49489b2015-04-28 14:00:26 -07006836 */
Robin Lee25e26452015-06-02 09:56:29 -07006837 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006838 String permission, int grantState) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006839 throwIfParentInstance("setPermissionGrantState");
Amith Yamasanid49489b2015-04-28 14:00:26 -07006840 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006841 return mService.setPermissionGrantState(admin, mContext.getPackageName(), packageName,
6842 permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07006843 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006844 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07006845 }
6846 }
Amith Yamasani184b3752015-05-22 13:00:51 -07006847
6848 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006849 * Returns the current grant state of a runtime permission for a specific application. This
6850 * function can be called by a device owner, profile owner, or by a delegate given the
6851 * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}.
Amith Yamasani184b3752015-05-22 13:00:51 -07006852 *
Edman Anjos52088e42017-01-13 22:26:17 +01006853 * @param admin Which profile or device owner this request is associated with, or {@code null}
6854 * if the caller is a permission grant delegate.
Amith Yamasani184b3752015-05-22 13:00:51 -07006855 * @param packageName The application to check the grant state for.
6856 * @param permission The permission to check for.
6857 * @return the current grant state specified by device policy. If the profile or device owner
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006858 * has not set a grant state, the return value is
6859 * {@link #PERMISSION_GRANT_STATE_DEFAULT}. This does not indicate whether or not the
6860 * permission is currently granted for the package.
6861 * <p/>
6862 * If a grant state was set by the profile or device owner, then the return value will
6863 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or
6864 * {@link #PERMISSION_GRANT_STATE_GRANTED}, which indicates if the permission is
6865 * currently denied or granted.
6866 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasani184b3752015-05-22 13:00:51 -07006867 * @see #setPermissionGrantState(ComponentName, String, String, int)
6868 * @see PackageManager#checkPermission(String, String)
Edman Anjos52088e42017-01-13 22:26:17 +01006869 * @see #setDelegatedScopes
6870 * @see #DELEGATION_PERMISSION_GRANT
Amith Yamasani184b3752015-05-22 13:00:51 -07006871 */
Bartosz Fabianowski4b0624f2017-01-16 11:47:28 +01006872 public int getPermissionGrantState(@Nullable ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07006873 String permission) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006874 throwIfParentInstance("getPermissionGrantState");
Amith Yamasani184b3752015-05-22 13:00:51 -07006875 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006876 return mService.getPermissionGrantState(admin, mContext.getPackageName(), packageName,
6877 permission);
Amith Yamasani184b3752015-05-22 13:00:51 -07006878 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006879 throw re.rethrowFromSystemServer();
Amith Yamasani184b3752015-05-22 13:00:51 -07006880 }
6881 }
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006882
6883 /**
Esteban Talavera01576862016-12-15 11:16:44 +00006884 * Returns whether it is possible for the caller to initiate provisioning of a managed profile
6885 * or device, setting itself as the device or profile owner.
6886 *
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006887 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
6888 * {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Esteban Talavera01576862016-12-15 11:16:44 +00006889 * @return whether provisioning a managed profile or device is possible.
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006890 * @throws IllegalArgumentException if the supplied action is not valid.
6891 */
Esteban Talavera01576862016-12-15 11:16:44 +00006892 public boolean isProvisioningAllowed(@NonNull String action) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006893 throwIfParentInstance("isProvisioningAllowed");
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006894 try {
Esteban Talavera01576862016-12-15 11:16:44 +00006895 return mService.isProvisioningAllowed(action, mContext.getPackageName());
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006896 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006897 throw re.rethrowFromSystemServer();
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006898 }
6899 }
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006900
6901 /**
Esteban Talavera01576862016-12-15 11:16:44 +00006902 * Checks whether it is possible to initiate provisioning a managed device,
6903 * profile or user, setting the given package as owner.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00006904 *
6905 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
6906 * {@link #ACTION_PROVISION_MANAGED_PROFILE},
6907 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE},
6908 * {@link #ACTION_PROVISION_MANAGED_USER}
Esteban Talavera01576862016-12-15 11:16:44 +00006909 * @param packageName The package of the component that would be set as device, user, or profile
6910 * owner.
6911 * @return A {@link ProvisioningPreCondition} value indicating whether provisioning is allowed.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00006912 * @hide
6913 */
Esteban Talavera01576862016-12-15 11:16:44 +00006914 public @ProvisioningPreCondition int checkProvisioningPreCondition(
6915 String action, @NonNull String packageName) {
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00006916 try {
Esteban Talavera01576862016-12-15 11:16:44 +00006917 return mService.checkProvisioningPreCondition(action, packageName);
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00006918 } catch (RemoteException re) {
6919 throw re.rethrowFromSystemServer();
6920 }
6921 }
6922
6923 /**
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006924 * Return if this user is a managed profile of another user. An admin can become the profile
6925 * owner of a managed profile with {@link #ACTION_PROVISION_MANAGED_PROFILE} and of a managed
Kenny Guyffa38402016-03-31 16:40:57 +01006926 * user with {@link #createAndManageUser}
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006927 * @param admin Which profile owner this request is associated with.
6928 * @return if this user is a managed profile of another user.
6929 */
6930 public boolean isManagedProfile(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006931 throwIfParentInstance("isManagedProfile");
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006932 try {
6933 return mService.isManagedProfile(admin);
6934 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006935 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006936 }
6937 }
6938
6939 /**
6940 * @hide
6941 * Return if this user is a system-only user. An admin can manage a device from a system only
6942 * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}.
6943 * @param admin Which device owner this request is associated with.
6944 * @return if this user is a system-only user.
6945 */
6946 public boolean isSystemOnlyUser(@NonNull ComponentName admin) {
6947 try {
6948 return mService.isSystemOnlyUser(admin);
6949 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006950 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006951 }
6952 }
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006953
6954 /**
6955 * Called by device owner to get the MAC address of the Wi-Fi device.
6956 *
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08006957 * @param admin Which device owner this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006958 * @return the MAC address of the Wi-Fi device, or null when the information is not available.
6959 * (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.)
6960 * <p>
6961 * The address will be in the {@code XX:XX:XX:XX:XX:XX} format.
6962 * @throws SecurityException if {@code admin} is not a device owner.
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006963 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006964 public @Nullable String getWifiMacAddress(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006965 throwIfParentInstance("getWifiMacAddress");
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006966 try {
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08006967 return mService.getWifiMacAddress(admin);
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006968 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006969 throw re.rethrowFromSystemServer();
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006970 }
6971 }
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00006972
6973 /**
Mahaver Chopra1216ae52016-03-11 15:39:48 +00006974 * Called by device owner to reboot the device. If there is an ongoing call on the device,
6975 * throws an {@link IllegalStateException}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006976 * @param admin Which device owner the request is associated with.
Mahaver Chopra1216ae52016-03-11 15:39:48 +00006977 * @throws IllegalStateException if device has an ongoing call.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006978 * @throws SecurityException if {@code admin} is not a device owner.
Mahaver Chopra1216ae52016-03-11 15:39:48 +00006979 * @see TelephonyManager#CALL_STATE_IDLE
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00006980 */
6981 public void reboot(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006982 throwIfParentInstance("reboot");
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00006983 try {
6984 mService.reboot(admin);
6985 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006986 throw re.rethrowFromSystemServer();
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00006987 }
6988 }
Kenny Guy06de4e72015-12-22 12:07:39 +00006989
6990 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006991 * Called by a device admin to set the short support message. This will be displayed to the user
6992 * in settings screens where funtionality has been disabled by the admin. The message should be
6993 * limited to a short statement such as "This setting is disabled by your administrator. Contact
6994 * someone@example.com for support." If the message is longer than 200 characters it may be
6995 * truncated.
6996 * <p>
6997 * If the short support message needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006998 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
6999 * and set a new version of this string accordingly.
7000 *
Kenny Guy06de4e72015-12-22 12:07:39 +00007001 * @see #setLongSupportMessage
Kenny Guy06de4e72015-12-22 12:07:39 +00007002 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007003 * @param message Short message to be displayed to the user in settings or null to clear the
7004 * existing message.
7005 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00007006 */
7007 public void setShortSupportMessage(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007008 @Nullable CharSequence message) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007009 throwIfParentInstance("setShortSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00007010 if (mService != null) {
7011 try {
7012 mService.setShortSupportMessage(admin, message);
7013 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007014 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00007015 }
7016 }
7017 }
7018
7019 /**
7020 * Called by a device admin to get the short support message.
7021 *
7022 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007023 * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)} or
7024 * null if no message has been set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007025 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00007026 */
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007027 public CharSequence getShortSupportMessage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007028 throwIfParentInstance("getShortSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00007029 if (mService != null) {
7030 try {
7031 return mService.getShortSupportMessage(admin);
7032 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007033 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00007034 }
7035 }
7036 return null;
7037 }
7038
7039 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007040 * Called by a device admin to set the long support message. This will be displayed to the user
7041 * in the device administators settings screen.
7042 * <p>
7043 * If the long support message needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007044 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
7045 * and set a new version of this string accordingly.
7046 *
Kenny Guy06de4e72015-12-22 12:07:39 +00007047 * @see #setShortSupportMessage
Kenny Guy06de4e72015-12-22 12:07:39 +00007048 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007049 * @param message Long message to be displayed to the user in settings or null to clear the
7050 * existing message.
7051 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00007052 */
7053 public void setLongSupportMessage(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007054 @Nullable CharSequence message) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007055 throwIfParentInstance("setLongSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00007056 if (mService != null) {
7057 try {
7058 mService.setLongSupportMessage(admin, message);
7059 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007060 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00007061 }
7062 }
7063 }
7064
7065 /**
7066 * Called by a device admin to get the long support message.
7067 *
7068 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007069 * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)} or
7070 * null if no message has been set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007071 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00007072 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007073 public @Nullable CharSequence getLongSupportMessage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007074 throwIfParentInstance("getLongSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00007075 if (mService != null) {
7076 try {
7077 return mService.getLongSupportMessage(admin);
7078 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007079 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00007080 }
7081 }
7082 return null;
7083 }
7084
7085 /**
7086 * Called by the system to get the short support message.
7087 *
7088 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7089 * @param userHandle user id the admin is running as.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007090 * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)}
Kenny Guy06de4e72015-12-22 12:07:39 +00007091 *
7092 * @hide
7093 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007094 public @Nullable CharSequence getShortSupportMessageForUser(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007095 int userHandle) {
Kenny Guy06de4e72015-12-22 12:07:39 +00007096 if (mService != null) {
7097 try {
7098 return mService.getShortSupportMessageForUser(admin, userHandle);
7099 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007100 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00007101 }
7102 }
7103 return null;
7104 }
7105
7106
7107 /**
7108 * Called by the system to get the long support message.
7109 *
7110 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7111 * @param userHandle user id the admin is running as.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007112 * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)}
Kenny Guy06de4e72015-12-22 12:07:39 +00007113 *
7114 * @hide
7115 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007116 public @Nullable CharSequence getLongSupportMessageForUser(
7117 @NonNull ComponentName admin, int userHandle) {
Kenny Guy06de4e72015-12-22 12:07:39 +00007118 if (mService != null) {
7119 try {
7120 return mService.getLongSupportMessageForUser(admin, userHandle);
7121 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007122 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00007123 }
7124 }
7125 return null;
7126 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00007127
7128 /**
Esteban Talavera62399912016-01-11 15:37:55 +00007129 * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager}
7130 * whose calls act on the parent profile.
Benjamin Franz66b45f02016-04-05 19:12:39 +01007131 *
7132 * <p>The following methods are supported for the parent instance, all other methods will
7133 * throw a SecurityException when called on the parent instance:
7134 * <ul>
7135 * <li>{@link #getPasswordQuality}</li>
7136 * <li>{@link #setPasswordQuality}</li>
7137 * <li>{@link #getPasswordMinimumLength}</li>
7138 * <li>{@link #setPasswordMinimumLength}</li>
7139 * <li>{@link #getPasswordMinimumUpperCase}</li>
7140 * <li>{@link #setPasswordMinimumUpperCase}</li>
7141 * <li>{@link #getPasswordMinimumLowerCase}</li>
7142 * <li>{@link #setPasswordMinimumLowerCase}</li>
7143 * <li>{@link #getPasswordMinimumLetters}</li>
7144 * <li>{@link #setPasswordMinimumLetters}</li>
7145 * <li>{@link #getPasswordMinimumNumeric}</li>
7146 * <li>{@link #setPasswordMinimumNumeric}</li>
7147 * <li>{@link #getPasswordMinimumSymbols}</li>
7148 * <li>{@link #setPasswordMinimumSymbols}</li>
7149 * <li>{@link #getPasswordMinimumNonLetter}</li>
7150 * <li>{@link #setPasswordMinimumNonLetter}</li>
7151 * <li>{@link #getPasswordHistoryLength}</li>
7152 * <li>{@link #setPasswordHistoryLength}</li>
7153 * <li>{@link #getPasswordExpirationTimeout}</li>
7154 * <li>{@link #setPasswordExpirationTimeout}</li>
7155 * <li>{@link #getPasswordExpiration}</li>
Charles He8c760562016-10-25 16:36:53 +01007156 * <li>{@link #getPasswordMaximumLength}</li>
Benjamin Franz66b45f02016-04-05 19:12:39 +01007157 * <li>{@link #isActivePasswordSufficient}</li>
7158 * <li>{@link #getCurrentFailedPasswordAttempts}</li>
7159 * <li>{@link #getMaximumFailedPasswordsForWipe}</li>
7160 * <li>{@link #setMaximumFailedPasswordsForWipe}</li>
7161 * <li>{@link #getMaximumTimeToLock}</li>
7162 * <li>{@link #setMaximumTimeToLock}</li>
7163 * <li>{@link #lockNow}</li>
7164 * <li>{@link #getKeyguardDisabledFeatures}</li>
7165 * <li>{@link #setKeyguardDisabledFeatures}</li>
7166 * <li>{@link #getTrustAgentConfiguration}</li>
7167 * <li>{@link #setTrustAgentConfiguration}</li>
Michal Karpinskia20d8bb2016-11-23 12:09:08 +00007168 * <li>{@link #getRequiredStrongAuthTimeout}</li>
7169 * <li>{@link #setRequiredStrongAuthTimeout}</li>
Benjamin Franz66b45f02016-04-05 19:12:39 +01007170 * </ul>
Clara Bayarri3e826ef2015-12-14 17:51:22 +00007171 *
7172 * @return a new instance of {@link DevicePolicyManager} that acts on the parent profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007173 * @throws SecurityException if {@code admin} is not a profile owner.
Clara Bayarri3e826ef2015-12-14 17:51:22 +00007174 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007175 public @NonNull DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007176 throwIfParentInstance("getParentProfileInstance");
Clara Bayarri3e826ef2015-12-14 17:51:22 +00007177 try {
7178 if (!mService.isManagedProfile(admin)) {
7179 throw new SecurityException("The current user does not have a parent profile.");
7180 }
Jeff Sharkey49ca5292016-05-10 12:54:45 -06007181 return new DevicePolicyManager(mContext, mService, true);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007182 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007183 throw e.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007184 }
7185 }
7186
7187 /**
Esteban Talaverad36dd152016-12-15 08:51:45 +00007188 * Called by device owner to control the security logging feature.
Michal Karpinski6235a942016-03-15 12:07:23 +00007189 *
7190 * <p> Security logs contain various information intended for security auditing purposes.
7191 * See {@link SecurityEvent} for details.
7192 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00007193 * <p><strong>Note:</strong> The device owner won't be able to retrieve security logs if there
7194 * are unaffiliated secondary users or profiles on the device, regardless of whether the
7195 * feature is enabled. Logs will be discarded if the internal buffer fills up while waiting for
7196 * all users to become affiliated. Therefore it's recommended that affiliation ids are set for
7197 * new users as soon as possible after provisioning via {@link #setAffiliationIds}.
Michal Karpinskib58e4962016-03-01 14:55:10 +00007198 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007199 * @param admin Which device owner this request is associated with.
Michal Karpinski6235a942016-03-15 12:07:23 +00007200 * @param enabled whether security logging should be enabled or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007201 * @throws SecurityException if {@code admin} is not a device owner.
Michal Karpinski6235a942016-03-15 12:07:23 +00007202 * @see #retrieveSecurityLogs
7203 */
7204 public void setSecurityLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007205 throwIfParentInstance("setSecurityLoggingEnabled");
Michal Karpinski6235a942016-03-15 12:07:23 +00007206 try {
7207 mService.setSecurityLoggingEnabled(admin, enabled);
7208 } catch (RemoteException re) {
7209 throw re.rethrowFromSystemServer();
7210 }
7211 }
7212
7213 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00007214 * Return whether security logging is enabled or not by the device owner.
7215 *
7216 * <p>Can only be called by the device owner, otherwise a {@link SecurityException} will be
7217 * thrown.
7218 *
7219 * @param admin Which device owner this request is associated with.
7220 * @return {@code true} if security logging is enabled by device owner, {@code false} otherwise.
7221 * @throws SecurityException if {@code admin} is not a device owner.
7222 */
Bartosz Fabianowski0ec00002017-03-24 14:22:24 +01007223 public boolean isSecurityLoggingEnabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007224 throwIfParentInstance("isSecurityLoggingEnabled");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007225 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00007226 return mService.isSecurityLoggingEnabled(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007227 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007228 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007229 }
7230 }
7231
7232 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00007233 * Called by device owner to retrieve all new security logging entries since the last call to
7234 * this API after device boots.
7235 *
7236 * <p> Access to the logs is rate limited and it will only return new logs after the device
7237 * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}.
7238 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00007239 * <p>If there is any other user or profile on the device, it must be affiliated with the
7240 * device owner. Otherwise a {@link SecurityException} will be thrown. See
7241 * {@link #setAffiliationIds}
Michal Karpinskib58e4962016-03-01 14:55:10 +00007242 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007243 * @param admin Which device owner this request is associated with.
Michal Karpinski6235a942016-03-15 12:07:23 +00007244 * @return the new batch of security logs which is a list of {@link SecurityEvent},
7245 * or {@code null} if rate limitation is exceeded or if logging is currently disabled.
Esteban Talaverad36dd152016-12-15 08:51:45 +00007246 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
7247 * profile or secondary user that is not affiliated with the device owner user.
7248 * @see DeviceAdminReceiver#onSecurityLogsAvailable
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007249 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007250 public @Nullable List<SecurityEvent> retrieveSecurityLogs(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007251 throwIfParentInstance("retrieveSecurityLogs");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007252 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00007253 ParceledListSlice<SecurityEvent> list = mService.retrieveSecurityLogs(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007254 if (list != null) {
7255 return list.getList();
7256 } else {
7257 // Rate limit exceeded.
7258 return null;
7259 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00007260 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007261 throw re.rethrowFromSystemServer();
Clara Bayarri3e826ef2015-12-14 17:51:22 +00007262 }
7263 }
Benjamin Franz59720bb2016-01-18 15:26:11 +00007264
7265 /**
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00007266 * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent
7267 * profile.
7268 *
7269 * @hide
7270 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007271 public @NonNull DevicePolicyManager getParentProfileInstance(UserInfo uInfo) {
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00007272 mContext.checkSelfPermission(
7273 android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS);
7274 if (!uInfo.isManagedProfile()) {
7275 throw new SecurityException("The user " + uInfo.id
7276 + " does not have a parent profile.");
7277 }
Jeff Sharkey49ca5292016-05-10 12:54:45 -06007278 return new DevicePolicyManager(mContext, mService, true);
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00007279 }
7280
7281 /**
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007282 * Called by device owners to retrieve device logs from before the device's last reboot.
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007283 * <p>
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01007284 * <strong> This API is not supported on all devices. Calling this API on unsupported devices
7285 * will result in {@code null} being returned. The device logs are retrieved from a RAM region
7286 * which is not guaranteed to be corruption-free during power cycles, as a result be cautious
7287 * about data corruption when parsing. </strong>
Esteban Talaverad36dd152016-12-15 08:51:45 +00007288 *
7289 * <p>If there is any other user or profile on the device, it must be affiliated with the
7290 * device owner. Otherwise a {@link SecurityException} will be thrown. See
7291 * {@link #setAffiliationIds}
Michal Karpinskib58e4962016-03-01 14:55:10 +00007292 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007293 * @param admin Which device owner this request is associated with.
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01007294 * @return Device logs from before the latest reboot of the system, or {@code null} if this API
7295 * is not supported on the device.
Esteban Talaverad36dd152016-12-15 08:51:45 +00007296 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
7297 * profile or secondary user that is not affiliated with the device owner user.
7298 * @see #retrieveSecurityLogs
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007299 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007300 public @Nullable List<SecurityEvent> retrievePreRebootSecurityLogs(
7301 @NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007302 throwIfParentInstance("retrievePreRebootSecurityLogs");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007303 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00007304 ParceledListSlice<SecurityEvent> list = mService.retrievePreRebootSecurityLogs(admin);
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01007305 if (list != null) {
7306 return list.getList();
7307 } else {
7308 return null;
7309 }
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007310 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007311 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007312 }
7313 }
7314
7315 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007316 * Called by a profile owner of a managed profile to set the color used for customization. This
7317 * color is used as background color of the confirm credentials screen for that user. The
Clara Bayarri8d0bd7fa2016-03-30 14:59:58 +01007318 * default color is teal (#00796B).
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007319 * <p>
7320 * The confirm credentials screen can be created using
Benjamin Franz59720bb2016-01-18 15:26:11 +00007321 * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}.
7322 *
7323 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinski74cd7302016-04-12 15:17:36 +01007324 * @param color The 24bit (0xRRGGBB) representation of the color to be used.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007325 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz59720bb2016-01-18 15:26:11 +00007326 */
7327 public void setOrganizationColor(@NonNull ComponentName admin, int color) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007328 throwIfParentInstance("setOrganizationColor");
Benjamin Franz59720bb2016-01-18 15:26:11 +00007329 try {
Michal Karpinski74cd7302016-04-12 15:17:36 +01007330 // always enforce alpha channel to have 100% opacity
7331 color |= 0xFF000000;
Benjamin Franz59720bb2016-01-18 15:26:11 +00007332 mService.setOrganizationColor(admin, color);
7333 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007334 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00007335 }
7336 }
7337
7338 /**
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00007339 * @hide
7340 *
7341 * Sets the color used for customization.
7342 *
Michal Karpinski74cd7302016-04-12 15:17:36 +01007343 * @param color The 24bit (0xRRGGBB) representation of the color to be used.
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00007344 * @param userId which user to set the color to.
7345 * @RequiresPermission(allOf = {
7346 * Manifest.permission.MANAGE_USERS,
7347 * Manifest.permission.INTERACT_ACROSS_USERS_FULL})
7348 */
7349 public void setOrganizationColorForUser(@ColorInt int color, @UserIdInt int userId) {
7350 try {
Michal Karpinski74cd7302016-04-12 15:17:36 +01007351 // always enforce alpha channel to have 100% opacity
7352 color |= 0xFF000000;
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00007353 mService.setOrganizationColorForUser(color, userId);
7354 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007355 throw re.rethrowFromSystemServer();
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00007356 }
7357 }
7358
7359 /**
Benjamin Franz59720bb2016-01-18 15:26:11 +00007360 * Called by a profile owner of a managed profile to retrieve the color used for customization.
7361 * This color is used as background color of the confirm credentials screen for that user.
7362 *
7363 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinski74cd7302016-04-12 15:17:36 +01007364 * @return The 24bit (0xRRGGBB) representation of the color to be used.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007365 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz59720bb2016-01-18 15:26:11 +00007366 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01007367 public @ColorInt int getOrganizationColor(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007368 throwIfParentInstance("getOrganizationColor");
Benjamin Franz59720bb2016-01-18 15:26:11 +00007369 try {
7370 return mService.getOrganizationColor(admin);
7371 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007372 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00007373 }
7374 }
7375
7376 /**
7377 * @hide
7378 * Retrieve the customization color for a given user.
7379 *
7380 * @param userHandle The user id of the user we're interested in.
Michal Karpinski74cd7302016-04-12 15:17:36 +01007381 * @return The 24bit (0xRRGGBB) representation of the color to be used.
Benjamin Franz59720bb2016-01-18 15:26:11 +00007382 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01007383 public @ColorInt int getOrganizationColorForUser(int userHandle) {
Benjamin Franz59720bb2016-01-18 15:26:11 +00007384 try {
7385 return mService.getOrganizationColorForUser(userHandle);
7386 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007387 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00007388 }
7389 }
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007390
7391 /**
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01007392 * Called by the device owner or profile owner to set the name of the organization under
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007393 * management.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007394 * <p>
7395 * If the organization name needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007396 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
7397 * and set a new version of this string accordingly.
7398 *
7399 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7400 * @param title The organization name or {@code null} to clear a previously set name.
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01007401 * @throws SecurityException if {@code admin} is not a device or profile owner.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007402 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01007403 public void setOrganizationName(@NonNull ComponentName admin, @Nullable CharSequence title) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007404 throwIfParentInstance("setOrganizationName");
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007405 try {
7406 mService.setOrganizationName(admin, title);
7407 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007408 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007409 }
7410 }
7411
7412 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007413 * Called by a profile owner of a managed profile to retrieve the name of the organization under
7414 * management.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007415 *
7416 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7417 * @return The organization name or {@code null} if none is set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007418 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007419 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007420 public @Nullable CharSequence getOrganizationName(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007421 throwIfParentInstance("getOrganizationName");
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007422 try {
7423 return mService.getOrganizationName(admin);
7424 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007425 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007426 }
7427 }
7428
7429 /**
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01007430 * Called by the system to retrieve the name of the organization managing the device.
7431 *
7432 * @return The organization name or {@code null} if none is set.
7433 * @throws SecurityException if the caller is not the device owner, does not hold the
7434 * MANAGE_USERS permission and is not the system.
7435 *
7436 * @hide
7437 */
7438 @SystemApi
7439 @TestApi
7440 public @Nullable CharSequence getDeviceOwnerOrganizationName() {
7441 try {
7442 return mService.getDeviceOwnerOrganizationName();
7443 } catch (RemoteException re) {
7444 throw re.rethrowFromSystemServer();
7445 }
7446 }
7447
7448 /**
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007449 * Retrieve the default title message used in the confirm credentials screen for a given user.
7450 *
7451 * @param userHandle The user id of the user we're interested in.
7452 * @return The organization name or {@code null} if none is set.
7453 *
7454 * @hide
7455 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007456 public @Nullable CharSequence getOrganizationNameForUser(int userHandle) {
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007457 try {
7458 return mService.getOrganizationNameForUser(userHandle);
7459 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007460 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007461 }
7462 }
7463
7464 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00007465 * @return the {@link UserProvisioningState} for the current user - for unmanaged users will
7466 * return {@link #STATE_USER_UNMANAGED}
7467 * @hide
7468 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00007469 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00007470 @UserProvisioningState
7471 public int getUserProvisioningState() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007472 throwIfParentInstance("getUserProvisioningState");
Alan Treadwayafad8782016-01-19 15:15:08 +00007473 if (mService != null) {
7474 try {
7475 return mService.getUserProvisioningState();
7476 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007477 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00007478 }
7479 }
7480 return STATE_USER_UNMANAGED;
7481 }
7482
7483 /**
7484 * Set the {@link UserProvisioningState} for the supplied user, if they are managed.
7485 *
7486 * @param state to store
7487 * @param userHandle for user
7488 * @hide
7489 */
7490 public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) {
7491 if (mService != null) {
7492 try {
7493 mService.setUserProvisioningState(state, userHandle);
7494 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007495 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00007496 }
7497 }
7498 }
7499
7500 /**
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007501 * Indicates the entity that controls the device or profile owner. Two users/profiles are
7502 * affiliated if the set of ids set by their device or profile owners intersect.
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007503 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00007504 * <p><strong>Note:</strong> Features that depend on user affiliation (such as security logging
7505 * or {@link #bindDeviceAdminServiceAsUser}) won't be available when a secondary user or profile
7506 * is created, until it becomes affiliated. Therefore it is recommended that the appropriate
7507 * affiliation ids are set by its profile owner as soon as possible after the user/profile is
7508 * created.
7509 *
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007510 * @param admin Which profile or device owner this request is associated with.
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007511 * @param ids A list of opaque non-empty affiliation ids. Duplicate elements will be ignored.
7512 *
7513 * @throws NullPointerException if {@code ids} is null or contains null elements.
7514 * @throws IllegalArgumentException if {@code ids} contains an empty string.
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007515 */
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007516 public void setAffiliationIds(@NonNull ComponentName admin, @NonNull List<String> ids) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007517 throwIfParentInstance("setAffiliationIds");
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007518 try {
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007519 mService.setAffiliationIds(admin, ids);
7520 } catch (RemoteException e) {
7521 throw e.rethrowFromSystemServer();
7522 }
7523 }
7524
7525 /**
7526 * Returns the list of affiliation ids previously set via {@link #setAffiliationIds}, or an
7527 * empty list if none have been set.
7528 */
7529 public @NonNull List<String> getAffiliationIds(@NonNull ComponentName admin) {
7530 throwIfParentInstance("getAffiliationIds");
7531 try {
7532 return mService.getAffiliationIds(admin);
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007533 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007534 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007535 }
7536 }
7537
7538 /**
7539 * @hide
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007540 * Returns whether this user/profile is affiliated with the device.
7541 * <p>
7542 * By definition, the user that the device owner runs on is always affiliated with the device.
7543 * Any other user/profile is considered affiliated with the device if the set specified by its
7544 * profile owner via {@link #setAffiliationIds} intersects with the device owner's.
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007545 *
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007546 */
7547 public boolean isAffiliatedUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007548 throwIfParentInstance("isAffiliatedUser");
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007549 try {
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007550 return mService.isAffiliatedUser();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007551 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007552 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007553 }
7554 }
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08007555
7556 /**
7557 * @hide
7558 * Returns whether the uninstall for {@code packageName} for the current user is in queue
7559 * to be started
7560 * @param packageName the package to check for
7561 * @return whether the uninstall intent for {@code packageName} is pending
7562 */
7563 public boolean isUninstallInQueue(String packageName) {
7564 try {
7565 return mService.isUninstallInQueue(packageName);
7566 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007567 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08007568 }
7569 }
7570
7571 /**
7572 * @hide
7573 * @param packageName the package containing active DAs to be uninstalled
7574 */
7575 public void uninstallPackageWithActiveAdmins(String packageName) {
7576 try {
7577 mService.uninstallPackageWithActiveAdmins(packageName);
7578 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007579 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08007580 }
7581 }
Benjamin Franzbc33c822016-04-15 08:57:52 +01007582
Kenny Guy38dcca52016-04-19 13:09:18 +01007583 /**
7584 * @hide
7585 * Remove a test admin synchronously without sending it a broadcast about being removed.
7586 * If the admin is a profile owner or device owner it will still be removed.
7587 *
7588 * @param userHandle user id to remove the admin for.
7589 * @param admin The administration compononent to remove.
7590 * @throws SecurityException if the caller is not shell / root or the admin package
7591 * isn't a test application see {@link ApplicationInfo#FLAG_TEST_APP}.
7592 */
7593 public void forceRemoveActiveAdmin(ComponentName adminReceiver, int userHandle) {
7594 try {
7595 mService.forceRemoveActiveAdmin(adminReceiver, userHandle);
7596 } catch (RemoteException re) {
7597 throw re.rethrowFromSystemServer();
7598 }
7599 }
7600
Mahaver Chopra790d1982016-07-07 16:06:49 +01007601 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007602 * Returns whether the device has been provisioned.
7603 *
7604 * <p>Not for use by third-party applications.
7605 *
Mahaver Chopra790d1982016-07-07 16:06:49 +01007606 * @hide
Mahaver Chopra790d1982016-07-07 16:06:49 +01007607 */
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007608 @SystemApi
Mahaver Chopra790d1982016-07-07 16:06:49 +01007609 public boolean isDeviceProvisioned() {
7610 try {
7611 return mService.isDeviceProvisioned();
7612 } catch (RemoteException re) {
7613 throw re.rethrowFromSystemServer();
7614 }
7615 }
7616
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007617 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007618 * Writes that the provisioning configuration has been applied.
7619 *
7620 * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS}
7621 * permission.
7622 *
7623 * <p>Not for use by third-party applications.
7624 *
7625 * @hide
7626 */
7627 @SystemApi
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007628 public void setDeviceProvisioningConfigApplied() {
7629 try {
7630 mService.setDeviceProvisioningConfigApplied();
7631 } catch (RemoteException re) {
7632 throw re.rethrowFromSystemServer();
7633 }
7634 }
7635
7636 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007637 * Returns whether the provisioning configuration has been applied.
7638 *
7639 * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS} permission.
7640 *
7641 * <p>Not for use by third-party applications.
7642 *
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007643 * @return whether the provisioning configuration has been applied.
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007644 *
7645 * @hide
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007646 */
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007647 @SystemApi
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007648 public boolean isDeviceProvisioningConfigApplied() {
7649 try {
7650 return mService.isDeviceProvisioningConfigApplied();
7651 } catch (RemoteException re) {
7652 throw re.rethrowFromSystemServer();
7653 }
7654 }
7655
Victor Chang9bfc65f2016-08-15 12:27:09 +01007656 /**
7657 * @hide
Victor Chang3577ed22016-08-25 18:49:26 +01007658 * Force update user setup completed status. This API has no effect on user build.
7659 * @throws {@link SecurityException} if the caller has no
Esteban Talavera01576862016-12-15 11:16:44 +00007660 * {@code android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS} or the caller is
7661 * not {@link UserHandle#SYSTEM_USER}
Victor Chang9bfc65f2016-08-15 12:27:09 +01007662 */
7663 public void forceUpdateUserSetupComplete() {
7664 try {
7665 mService.forceUpdateUserSetupComplete();
7666 } catch (RemoteException re) {
7667 throw re.rethrowFromSystemServer();
7668 }
7669 }
7670
Benjamin Franzbc33c822016-04-15 08:57:52 +01007671 private void throwIfParentInstance(String functionName) {
7672 if (mParentInstance) {
7673 throw new SecurityException(functionName + " cannot be called on the parent instance");
7674 }
7675 }
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007676
7677 /**
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007678 * Allows the device owner to enable or disable the backup service.
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007679 *
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007680 * <p> Backup service manages all backup and restore mechanisms on the device. Setting this to
7681 * false will prevent data from being backed up or restored.
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007682 *
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007683 * <p> Backup service is off by default when device owner is present.
7684 *
Rubin Xu0367f072017-04-24 20:17:16 +01007685 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7686 * @param enabled {@code true} to enable the backup service, {@code false} to disable it.
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007687 * @throws SecurityException if {@code admin} is not a device owner.
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007688 */
7689 public void setBackupServiceEnabled(@NonNull ComponentName admin, boolean enabled) {
Esteban Talavera5b7f2d02017-02-17 09:45:24 +00007690 throwIfParentInstance("setBackupServiceEnabled");
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007691 try {
7692 mService.setBackupServiceEnabled(admin, enabled);
7693 } catch (RemoteException re) {
7694 throw re.rethrowFromSystemServer();
7695 }
7696 }
7697
7698 /**
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007699 * Return whether the backup service is enabled by the device owner.
7700 *
7701 * <p> Backup service manages all backup and restore mechanisms on the device.
7702 *
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007703 * @return {@code true} if backup service is enabled, {@code false} otherwise.
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007704 * @see #setBackupServiceEnabled
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007705 */
7706 public boolean isBackupServiceEnabled(@NonNull ComponentName admin) {
Esteban Talavera5b7f2d02017-02-17 09:45:24 +00007707 throwIfParentInstance("isBackupServiceEnabled");
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007708 try {
7709 return mService.isBackupServiceEnabled(admin);
7710 } catch (RemoteException re) {
7711 throw re.rethrowFromSystemServer();
7712 }
7713 }
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007714
7715 /**
Esteban Talaverad36dd152016-12-15 08:51:45 +00007716 * Called by a device owner to control the network logging feature.
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007717 *
Robin Leea40a2fb2017-02-08 17:07:06 +00007718 * <p> Network logs contain DNS lookup and connect() library call events. The following library
7719 * functions are recorded while network logging is active:
7720 * <ul>
7721 * <li>{@code getaddrinfo()}</li>
7722 * <li>{@code gethostbyname()}</li>
7723 * <li>{@code connect()}</li>
7724 * </ul>
7725 *
7726 * <p> Network logging is a low-overhead tool for forensics but it is not guaranteed to use
7727 * full system call logging; event reporting is enabled by default for all processes but not
7728 * strongly enforced.
7729 * Events from applications using alternative implementations of libc, making direct kernel
7730 * calls, or deliberately obfuscating traffic may not be recorded.
7731 *
7732 * <p> Some common network events may not be reported. For example:
7733 * <ul>
7734 * <li>Applications may hardcode IP addresses to reduce the number of DNS lookups, or use
7735 * an alternative system for name resolution, and so avoid calling
7736 * {@code getaddrinfo()} or {@code gethostbyname}.</li>
7737 * <li>Applications may use datagram sockets for performance reasons, for example
7738 * for a game client. Calling {@code connect()} is unnecessary for this kind of
7739 * socket, so it will not trigger a network event.</li>
7740 * </ul>
7741 *
7742 * <p> It is possible to directly intercept layer 3 traffic leaving the device using an
7743 * always-on VPN service.
7744 * See {@link #setAlwaysOnVpnPackage(ComponentName, String, boolean)}
7745 * and {@link android.net.VpnService} for details.
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007746 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00007747 * <p><strong>Note:</strong> The device owner won't be able to retrieve network logs if there
7748 * are unaffiliated secondary users or profiles on the device, regardless of whether the
7749 * feature is enabled. Logs will be discarded if the internal buffer fills up while waiting for
7750 * all users to become affiliated. Therefore it's recommended that affiliation ids are set for
7751 * new users as soon as possible after provisioning via {@link #setAffiliationIds}.
7752 *
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007753 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7754 * @param enabled whether network logging should be enabled or not.
Esteban Talaverad36dd152016-12-15 08:51:45 +00007755 * @throws SecurityException if {@code admin} is not a device owner.
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007756 * @see #retrieveNetworkLogs
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007757 */
7758 public void setNetworkLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
7759 throwIfParentInstance("setNetworkLoggingEnabled");
7760 try {
7761 mService.setNetworkLoggingEnabled(admin, enabled);
7762 } catch (RemoteException re) {
7763 throw re.rethrowFromSystemServer();
7764 }
7765 }
7766
7767 /**
7768 * Return whether network logging is enabled by a device owner.
7769 *
phweissa4e169e2016-11-24 16:20:57 +01007770 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Can only
7771 * be {@code null} if the caller has MANAGE_USERS permission.
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007772 * @return {@code true} if network logging is enabled by device owner, {@code false} otherwise.
Esteban Talaverad36dd152016-12-15 08:51:45 +00007773 * @throws SecurityException if {@code admin} is not a device owner and caller has
phweissa4e169e2016-11-24 16:20:57 +01007774 * no MANAGE_USERS permission
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007775 */
phweissa4e169e2016-11-24 16:20:57 +01007776 public boolean isNetworkLoggingEnabled(@Nullable ComponentName admin) {
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007777 throwIfParentInstance("isNetworkLoggingEnabled");
7778 try {
7779 return mService.isNetworkLoggingEnabled(admin);
7780 } catch (RemoteException re) {
7781 throw re.rethrowFromSystemServer();
7782 }
7783 }
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007784
7785 /**
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007786 * Called by device owner to retrieve the most recent batch of network logging events.
7787 * A device owner has to provide a batchToken provided as part of
7788 * {@link DeviceAdminReceiver#onNetworkLogsAvailable} callback. If the token doesn't match the
7789 * token of the most recent available batch of logs, {@code null} will be returned.
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007790 *
7791 * <p> {@link NetworkEvent} can be one of {@link DnsEvent} or {@link ConnectEvent}.
7792 *
7793 * <p> The list of network events is sorted chronologically, and contains at most 1200 events.
7794 *
7795 * <p> Access to the logs is rate limited and this method will only return a new batch of logs
7796 * after the device device owner has been notified via
7797 * {@link DeviceAdminReceiver#onNetworkLogsAvailable}.
7798 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00007799 * <p>If a secondary user or profile is created, calling this method will throw a
7800 * {@link SecurityException} until all users become affiliated again. It will also no longer be
7801 * possible to retrieve the network logs batch with the most recent batchToken provided
7802 * by {@link DeviceAdminReceiver#onNetworkLogsAvailable}. See
7803 * {@link DevicePolicyManager#setAffiliationIds}.
7804 *
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007805 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007806 * @param batchToken A token of the batch to retrieve
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007807 * @return A new batch of network logs which is a list of {@link NetworkEvent}. Returns
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007808 * {@code null} if the batch represented by batchToken is no longer available or if
7809 * logging is disabled.
Esteban Talaverad36dd152016-12-15 08:51:45 +00007810 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
7811 * profile or secondary user that is not affiliated with the device owner user.
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007812 * @see DeviceAdminReceiver#onNetworkLogsAvailable
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007813 */
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007814 public @Nullable List<NetworkEvent> retrieveNetworkLogs(@NonNull ComponentName admin,
7815 long batchToken) {
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007816 throwIfParentInstance("retrieveNetworkLogs");
7817 try {
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007818 return mService.retrieveNetworkLogs(admin, batchToken);
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007819 } catch (RemoteException re) {
7820 throw re.rethrowFromSystemServer();
7821 }
7822 }
Tony Mak46aabe52016-11-14 12:53:06 +00007823
7824 /**
Esteban Talavera2f897912017-01-26 10:30:48 +00007825 * Called by a device owner to bind to a service from a profile owner or vice versa.
7826 * See {@link #getBindDeviceAdminTargetUsers} for a definition of which
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007827 * device/profile owners are allowed to bind to services of another profile/device owner.
7828 * <p>
Tony Makeda0a9a2017-04-25 12:07:14 +01007829 * The service must be protected by {@link android.Manifest.permission#BIND_DEVICE_ADMIN}.
7830 * Note that the {@link Context} used to obtain this
Tony Mak46aabe52016-11-14 12:53:06 +00007831 * {@link DevicePolicyManager} instance via {@link Context#getSystemService(Class)} will be used
7832 * to bind to the {@link android.app.Service}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007833 *
Tony Mak46aabe52016-11-14 12:53:06 +00007834 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7835 * @param serviceIntent Identifies the service to connect to. The Intent must specify either an
7836 * explicit component name or a package name to match an
7837 * {@link IntentFilter} published by a service.
Tony Makbf9928d2016-12-22 11:02:45 +00007838 * @param conn Receives information as the service is started and stopped in main thread. This
7839 * must be a valid {@link ServiceConnection} object; it must not be {@code null}.
Tony Mak46aabe52016-11-14 12:53:06 +00007840 * @param flags Operation options for the binding operation. See
7841 * {@link Context#bindService(Intent, ServiceConnection, int)}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007842 * @param targetUser Which user to bind to. Must be one of the users returned by
7843 * {@link #getBindDeviceAdminTargetUsers}, otherwise a {@link SecurityException} will
7844 * be thrown.
Tony Mak46aabe52016-11-14 12:53:06 +00007845 * @return If you have successfully bound to the service, {@code true} is returned;
7846 * {@code false} is returned if the connection is not made and you will not
7847 * receive the service object.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007848 *
Tony Mak46aabe52016-11-14 12:53:06 +00007849 * @see Context#bindService(Intent, ServiceConnection, int)
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007850 * @see #getBindDeviceAdminTargetUsers(ComponentName)
Tony Mak46aabe52016-11-14 12:53:06 +00007851 */
7852 public boolean bindDeviceAdminServiceAsUser(
7853 @NonNull ComponentName admin, Intent serviceIntent, @NonNull ServiceConnection conn,
7854 @Context.BindServiceFlags int flags, @NonNull UserHandle targetUser) {
7855 throwIfParentInstance("bindDeviceAdminServiceAsUser");
7856 // Keep this in sync with ContextImpl.bindServiceCommon.
7857 try {
Tony Makbf9928d2016-12-22 11:02:45 +00007858 final IServiceConnection sd = mContext.getServiceDispatcher(
7859 conn, mContext.getMainThreadHandler(), flags);
Tony Mak46aabe52016-11-14 12:53:06 +00007860 serviceIntent.prepareToLeaveProcess(mContext);
7861 return mService.bindDeviceAdminServiceAsUser(admin,
7862 mContext.getIApplicationThread(), mContext.getActivityToken(), serviceIntent,
7863 sd, flags, targetUser.getIdentifier());
7864 } catch (RemoteException re) {
7865 throw re.rethrowFromSystemServer();
7866 }
7867 }
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007868
7869 /**
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007870 * Returns the list of target users that the calling device or profile owner can use when
7871 * calling {@link #bindDeviceAdminServiceAsUser}.
7872 * <p>
Esteban Talavera2f897912017-01-26 10:30:48 +00007873 * A device owner can bind to a service from a profile owner and vice versa, provided that:
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007874 * <ul>
7875 * <li>Both belong to the same package name.
Esteban Talavera2f897912017-01-26 10:30:48 +00007876 * <li>Both users are affiliated. See {@link #setAffiliationIds}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007877 * </ul>
7878 */
7879 public @NonNull List<UserHandle> getBindDeviceAdminTargetUsers(@NonNull ComponentName admin) {
7880 throwIfParentInstance("getBindDeviceAdminTargetUsers");
7881 try {
7882 return mService.getBindDeviceAdminTargetUsers(admin);
7883 } catch (RemoteException re) {
7884 throw re.rethrowFromSystemServer();
7885 }
7886 }
7887
7888 /**
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007889 * Called by the system to get the time at which the device owner last retrieved security
7890 * logging entries.
7891 *
7892 * @return the time at which the device owner most recently retrieved security logging entries,
7893 * in milliseconds since epoch; -1 if security logging entries were never retrieved.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007894 * @throws SecurityException if the caller is not the device owner, does not hold the
7895 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007896 *
7897 * @hide
7898 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007899 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007900 public long getLastSecurityLogRetrievalTime() {
7901 try {
7902 return mService.getLastSecurityLogRetrievalTime();
7903 } catch (RemoteException re) {
7904 throw re.rethrowFromSystemServer();
7905 }
7906 }
7907
7908 /**
7909 * Called by the system to get the time at which the device owner last requested a bug report.
7910 *
7911 * @return the time at which the device owner most recently requested a bug report, in
7912 * milliseconds since epoch; -1 if a bug report was never requested.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007913 * @throws SecurityException if the caller is not the device owner, does not hold the
7914 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007915 *
7916 * @hide
7917 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007918 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007919 public long getLastBugReportRequestTime() {
7920 try {
7921 return mService.getLastBugReportRequestTime();
7922 } catch (RemoteException re) {
7923 throw re.rethrowFromSystemServer();
7924 }
7925 }
7926
7927 /**
7928 * Called by the system to get the time at which the device owner last retrieved network logging
7929 * events.
7930 *
7931 * @return the time at which the device owner most recently retrieved network logging events, in
7932 * milliseconds since epoch; -1 if network logging events were never retrieved.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007933 * @throws SecurityException if the caller is not the device owner, does not hold the
7934 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007935 *
7936 * @hide
7937 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007938 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007939 public long getLastNetworkLogRetrievalTime() {
7940 try {
7941 return mService.getLastNetworkLogRetrievalTime();
7942 } catch (RemoteException re) {
7943 throw re.rethrowFromSystemServer();
7944 }
7945 }
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01007946
7947 /**
Bartosz Fabianowski172f7802017-03-06 12:07:57 +01007948 * Called by the system to find out whether the current user's IME was set by the device/profile
7949 * owner or the user.
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01007950 *
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01007951 * @return {@code true} if the user's IME was set by the device or profile owner, {@code false}
7952 * otherwise.
Bartosz Fabianowski172f7802017-03-06 12:07:57 +01007953 * @throws SecurityException if the caller is not the device owner/profile owner.
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01007954 *
7955 * @hide
7956 */
7957 @TestApi
Bartosz Fabianowski172f7802017-03-06 12:07:57 +01007958 public boolean isCurrentInputMethodSetByOwner() {
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01007959 try {
Bartosz Fabianowski172f7802017-03-06 12:07:57 +01007960 return mService.isCurrentInputMethodSetByOwner();
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01007961 } catch (RemoteException re) {
7962 throw re.rethrowFromSystemServer();
7963 }
7964 }
Bartosz Fabianowski05dc9f72017-02-22 23:41:14 +01007965
Bartosz Fabianowski05dc9f72017-02-22 23:41:14 +01007966 /**
7967 * Called by the system to get a list of CA certificates that were installed by the device or
7968 * profile owner.
7969 *
Bartosz Fabianowski172f7802017-03-06 12:07:57 +01007970 * <p> The caller must be the target user's device owner/profile Owner or hold the
Bartosz Fabianowski05dc9f72017-02-22 23:41:14 +01007971 * {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} permission.
7972 *
7973 * @param user The user for whom to retrieve information.
7974 * @return list of aliases identifying CA certificates installed by the device or profile owner
7975 * @throws SecurityException if the caller does not have permission to retrieve information
7976 * about the given user's CA certificates.
7977 *
7978 * @hide
7979 */
7980 @TestApi
7981 public List<String> getOwnerInstalledCaCerts(@NonNull UserHandle user) {
7982 try {
7983 return mService.getOwnerInstalledCaCerts(user).getList();
7984 } catch (RemoteException re) {
7985 throw re.rethrowFromSystemServer();
7986 }
7987 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08007988}