blob: 9cb3dd6e4c0aff7d32246dd27f465ed513e89763 [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 /**
Jessica Hummele3da7902014-08-20 15:20:11 +0100538 * A String extra that, holds the email address of the account which a managed profile is
539 * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
540 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100541 *
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100542 * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}.
543 *
Jessica Hummele3da7902014-08-20 15:20:11 +0100544 * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning
545 * contains this extra, it is forwarded in the
546 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile
547 * device management application that was set as the profile owner during provisioning.
548 * It is usually used to avoid that the user has to enter their email address twice.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100549 */
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100550 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
551 = "android.app.extra.PROVISIONING_EMAIL_ADDRESS";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100552
553 /**
Nicolas Prevotcd2d8592015-11-23 13:27:21 +0000554 * A integer extra indicating the predominant color to show during the provisioning.
555 * Refer to {@link android.graphics.Color} for how the color is represented.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000556 *
557 * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or
558 * {@link #ACTION_PROVISION_MANAGED_DEVICE}.
559 */
560 public static final String EXTRA_PROVISIONING_MAIN_COLOR =
561 "android.app.extra.PROVISIONING_MAIN_COLOR";
562
563 /**
Sander Alewijnse8c411562014-11-12 18:03:11 +0000564 * A Boolean extra that can be used by the mobile device management application to skip the
Robin Lee25e26452015-06-02 09:56:29 -0700565 * disabling of system apps during provisioning when set to {@code true}.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000566 *
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100567 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
568 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000569 */
Sander Alewijnse5a144252014-11-18 13:25:04 +0000570 public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED =
571 "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED";
Sander Alewijnse8c411562014-11-12 18:03:11 +0000572
573 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100574 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
575 * will be set to.
576 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000577 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
578 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100579 */
580 public static final String EXTRA_PROVISIONING_TIME_ZONE
Esteban Talavera37f01842014-09-05 10:50:57 +0100581 = "android.app.extra.PROVISIONING_TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100582
583 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100584 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
585 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100586 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000587 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
588 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100589 */
590 public static final String EXTRA_PROVISIONING_LOCAL_TIME
Esteban Talavera37f01842014-09-05 10:50:57 +0100591 = "android.app.extra.PROVISIONING_LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100592
593 /**
594 * A String extra holding the {@link java.util.Locale} that the device will be set to.
595 * Format: xx_yy, where xx is the language code, and yy the country code.
596 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000597 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
598 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100599 */
600 public static final String EXTRA_PROVISIONING_LOCALE
Esteban Talavera37f01842014-09-05 10:50:57 +0100601 = "android.app.extra.PROVISIONING_LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100602
603 /**
604 * A String extra holding the ssid of the wifi network that should be used during nfc device
605 * owner provisioning for downloading the mobile device management application.
606 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000607 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
608 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100609 */
610 public static final String EXTRA_PROVISIONING_WIFI_SSID
Esteban Talavera37f01842014-09-05 10:50:57 +0100611 = "android.app.extra.PROVISIONING_WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100612
613 /**
614 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
615 * is hidden or not.
616 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000617 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
618 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100619 */
620 public static final String EXTRA_PROVISIONING_WIFI_HIDDEN
Esteban Talavera37f01842014-09-05 10:50:57 +0100621 = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100622
623 /**
624 * A String extra indicating the security type of the wifi network in
Mahaver Chopra76b08a92015-10-08 17:58:45 +0100625 * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or
626 * {@code WEP}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100627 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000628 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
629 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100630 */
631 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
Esteban Talavera37f01842014-09-05 10:50:57 +0100632 = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100633
634 /**
635 * A String extra holding the password of the wifi network in
636 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
637 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000638 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
639 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100640 */
641 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talavera37f01842014-09-05 10:50:57 +0100642 = "android.app.extra.PROVISIONING_WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100643
644 /**
645 * A String extra holding the proxy host for the wifi network in
646 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
647 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000648 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
649 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100650 */
651 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
Esteban Talavera37f01842014-09-05 10:50:57 +0100652 = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100653
654 /**
655 * An int extra holding the proxy port for the wifi network in
656 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
657 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000658 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
659 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100660 */
661 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
Esteban Talavera37f01842014-09-05 10:50:57 +0100662 = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100663
664 /**
665 * A String extra holding the proxy bypass for the wifi network in
666 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
667 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000668 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
669 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100670 */
671 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
Esteban Talavera37f01842014-09-05 10:50:57 +0100672 = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100673
674 /**
675 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
676 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
677 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000678 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
679 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100680 */
681 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
Esteban Talavera37f01842014-09-05 10:50:57 +0100682 = "android.app.extra.PROVISIONING_WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100683
684 /**
685 * A String extra holding a url that specifies the download location of the device admin
686 * package. When not provided it is assumed that the device admin package is already installed.
687 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000688 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
689 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100690 */
691 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talavera37f01842014-09-05 10:50:57 +0100692 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100693
694 /**
Victor Chang38cfd9c2017-01-04 17:41:11 +0000695 * A String extra holding the localized name of the organization under management.
696 *
697 * The name is displayed only during provisioning.
698 *
699 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE}
700 *
701 * @hide
702 */
703 @SystemApi
704 public static final String EXTRA_PROVISIONING_ORGANIZATION_NAME =
705 "android.app.extra.PROVISIONING_ORGANIZATION_NAME";
706
707 /**
708 * A String extra holding a url to the website of the device's provider. The website can be
709 * opened in a browser during provisioning.
710 *
711 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE}
712 *
713 * @hide
714 */
715 @SystemApi
716 public static final String EXTRA_PROVISIONING_SUPPORT_URL =
717 "android.app.extra.PROVISIONING_SUPPORT_URL";
718
719 /**
720 * A String extra holding the localized name of the device admin package. It should be the same
721 * as the app label of the package.
722 *
723 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE}
724 *
725 * @hide
726 */
727 @SystemApi
728 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL =
729 "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL";
730
731 /**
732 * A {@link Uri} extra pointing to the app icon of device admin package. This image will be
733 * shown during the provisioning.
734 * <h5>The following URI schemes are accepted:</h5>
735 * <ul>
736 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
737 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
738 * </ul>
739 *
740 * <p> It is the responsibility of the caller to provide an image with a reasonable
741 * pixel density for the device.
742 *
743 * <p> If a content: URI is passed, the intent should have the flag
744 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
745 * {@link android.content.ClipData} of the intent too.
746 *
747 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE}
748 *
749 * @hide
750 */
751 @SystemApi
752 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI =
753 "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI";
754
755 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400756 * An int extra holding a minimum required version code for the device admin package. If the
757 * device admin is already installed on the device, it will only be re-downloaded from
758 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the
759 * installed package is less than this version code.
760 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400761 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400762 * provisioning via an NFC bump.
763 */
764 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE
765 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE";
766
767 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100768 * A String extra holding a http cookie header which should be used in the http request to the
769 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
770 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000771 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
772 * provisioning via an NFC bump.
Sander Alewijnse681bce92014-07-24 16:46:26 +0100773 */
774 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talavera37f01842014-09-05 10:50:57 +0100775 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100776
777 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100778 * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of
779 * the file at download location specified in
780 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100781 *
Benjamin Franzea956242016-03-21 15:45:56 +0000782 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} must be
783 * present. The provided checksum must match the checksum of the file at the download
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100784 * location. If the checksum doesn't match an error will be shown to the user and the user will
785 * be asked to factory reset the device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100786 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000787 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
788 * provisioning via an NFC bump.
Rubin Xud92e7572015-05-18 17:01:13 +0100789 *
790 * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP}
791 * and {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1} only SHA-1 hash is supported.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700792 * Starting from {@link android.os.Build.VERSION_CODES#M}, this parameter accepts SHA-256 in
Rubin Xud92e7572015-05-18 17:01:13 +0100793 * addition to SHA-1. Support for SHA-1 is likely to be removed in future OS releases.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100794 */
795 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100796 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100797
798 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100799 * A String extra holding the URL-safe base64 encoded SHA-256 checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100800 * android package archive at the download location specified in {@link
801 * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
802 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100803 * <p>The signatures of an android package archive can be obtained using
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100804 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
805 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
806 *
Benjamin Franzea956242016-03-21 15:45:56 +0000807 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} must be
808 * present. The provided checksum must match the checksum of any signature of the file at
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100809 * the download location. If the checksum does not match an error will be shown to the user and
810 * the user will be asked to factory reset the device.
811 *
812 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
813 * provisioning via an NFC bump.
814 */
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100815 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM
816 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM";
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100817
818 /**
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000819 * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile
820 * has completed successfully.
821 *
822 * <p>The broadcast is limited to the primary profile, to the app specified in the provisioning
Nicolas Prevotebe2d992015-05-12 18:14:53 -0700823 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000824 *
Mahaver7074caf2016-11-29 20:52:18 +0000825 * <p>This intent will contain the following extras
826 * <ul>
827 * <li>{@link Intent#EXTRA_USER}, corresponds to the {@link UserHandle} of the managed
828 * profile.</li>
829 * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, corresponds to the account requested to
830 * be migrated at provisioning time, if any.</li>
831 * </ul>
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000832 */
833 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
834 public static final String ACTION_MANAGED_PROFILE_PROVISIONED
835 = "android.app.action.MANAGED_PROFILE_PROVISIONED";
836
837 /**
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000838 * Activity action: This activity action is sent to indicate that provisioning of a managed
839 * profile or managed device has completed successfully. It'll be sent at the same time as
840 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast but this will be
841 * delivered faster as it's an activity intent.
842 *
843 * <p>The intent is only sent to the application on the profile that requested provisioning. In
844 * the device owner case the profile is the primary user.
845 *
846 * @see #ACTION_PROVISION_MANAGED_PROFILE
847 * @see #ACTION_PROVISION_MANAGED_DEVICE
848 */
849 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
850 public static final String ACTION_PROVISIONING_SUCCESSFUL =
851 "android.app.action.PROVISIONING_SUCCESSFUL";
852
853 /**
Benjamin Franzea956242016-03-21 15:45:56 +0000854 * A boolean extra indicating whether device encryption can be skipped as part of device owner
855 * or managed profile provisioning.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500856 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400857 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100858 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Benjamin Franzea956242016-03-21 15:45:56 +0000859 *
860 * <p>From {@link android.os.Build.VERSION_CODES#N} onwards, this is also supported for an
861 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500862 */
863 public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION =
864 "android.app.extra.PROVISIONING_SKIP_ENCRYPTION";
865
866 /**
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000867 * A {@link Uri} extra pointing to a logo image. This image will be shown during the
868 * provisioning. If this extra is not passed, a default image will be shown.
869 * <h5>The following URI schemes are accepted:</h5>
870 * <ul>
871 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
872 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
873 * </ul>
874 *
Victor Changc10f6692016-12-09 15:24:00 +0000875 * <p> It is the responsibility of the caller to provide an image with a reasonable
Victor Chang38cfd9c2017-01-04 17:41:11 +0000876 * pixel density for the device.
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000877 *
878 * <p> If a content: URI is passed, the intent should have the flag
879 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
880 * {@link android.content.ClipData} of the intent too.
881 *
882 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or
883 * {@link #ACTION_PROVISION_MANAGED_DEVICE}
884 */
885 public static final String EXTRA_PROVISIONING_LOGO_URI =
886 "android.app.extra.PROVISIONING_LOGO_URI";
887
888 /**
Victor Changc10f6692016-12-09 15:24:00 +0000889 * A {@link Bundle}[] extra consisting of list of disclaimer headers and disclaimer contents.
890 * Each {@link Bundle} must have both {@link #EXTRA_PROVISIONING_DISCLAIMER_HEADER}
891 * as disclaimer header, and {@link #EXTRA_PROVISIONING_DISCLAIMER_CONTENT} as disclaimer
892 * content.
893 *
894 * <p> The extra typically contains one disclaimer from the company of mobile device
895 * management application (MDM), and one disclaimer from the organization.
896 *
897 * <p> Call {@link Bundle#putParcelableArray(String, Parcelable[])} to put the {@link Bundle}[]
898 *
899 * <p> Maximum 3 key-value pairs can be specified. The rest will be ignored.
900 *
901 * <p> Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or
902 * {@link #ACTION_PROVISION_MANAGED_DEVICE}
903 */
904 public static final String EXTRA_PROVISIONING_DISCLAIMERS =
905 "android.app.extra.PROVISIONING_DISCLAIMERS";
906
907 /**
908 * A String extra of localized disclaimer header.
909 *
910 * <p> The extra is typically the company name of mobile device management application (MDM)
911 * or the organization name.
912 *
913 * <p> Use in Bundle {@link #EXTRA_PROVISIONING_DISCLAIMERS}
Victor Chang98607132017-01-27 11:51:56 +0000914 *
915 * <p> System app, i.e. application with {@link ApplicationInfo#FLAG_SYSTEM}, can also insert a
916 * disclaimer by declaring an application-level meta-data in {@code AndroidManifest.xml}.
917 * Must use it with {@link #EXTRA_PROVISIONING_DISCLAIMER_CONTENT}. Here is the example:
918 *
919 * <pre>
920 * &lt;meta-data
921 * android:name="android.app.extra.PROVISIONING_DISCLAIMER_HEADER"
922 * android:resource="@string/disclaimer_header"
923 * /&gt;</pre>
Victor Changc10f6692016-12-09 15:24:00 +0000924 */
925 public static final String EXTRA_PROVISIONING_DISCLAIMER_HEADER =
926 "android.app.extra.PROVISIONING_DISCLAIMER_HEADER";
927
928 /**
929 * A {@link Uri} extra pointing to disclaimer content.
930 *
931 * <h5>The following URI schemes are accepted:</h5>
932 * <ul>
933 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
934 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
935 * </ul>
936 *
937 * <p> Styled text is supported in the disclaimer content. The content is parsed by
938 * {@link android.text.Html#fromHtml(String)} and displayed in a
939 * {@link android.widget.TextView}.
940 *
941 * <p> If a <code>content:</code> URI is passed, URI is passed, the intent should have the flag
942 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
943 * {@link android.content.ClipData} of the intent too.
944 *
945 * <p> Use in Bundle {@link #EXTRA_PROVISIONING_DISCLAIMERS}
Victor Chang98607132017-01-27 11:51:56 +0000946 *
947 * <p> System app, i.e. application with {@link ApplicationInfo#FLAG_SYSTEM}, can also insert a
948 * disclaimer by declaring an application-level meta-data in {@code AndroidManifest.xml}.
949 * Must use it with {@link #EXTRA_PROVISIONING_DISCLAIMER_HEADER}. Here is the example:
950 *
951 * <pre>
952 * &lt;meta-data
953 * android:name="android.app.extra.PROVISIONING_DISCLAIMER_CONTENT"
954 * android:resource="@string/disclaimer_content"
955 * /&gt;</pre>
Victor Changc10f6692016-12-09 15:24:00 +0000956 */
957 public static final String EXTRA_PROVISIONING_DISCLAIMER_CONTENT =
958 "android.app.extra.PROVISIONING_DISCLAIMER_CONTENT";
959
960 /**
Alan Treadway94de8c82016-01-11 10:25:23 +0000961 * A boolean extra indicating if user setup should be skipped, for when provisioning is started
962 * during setup-wizard.
963 *
964 * <p>If unspecified, defaults to {@code true} to match the behavior in
965 * {@link android.os.Build.VERSION_CODES#M} and earlier.
966 *
Alan Treadway1a538d02016-01-18 16:42:30 +0000967 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or
968 * {@link #ACTION_PROVISION_MANAGED_USER}.
Alan Treadway94de8c82016-01-11 10:25:23 +0000969 *
970 * @hide
971 */
972 public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP =
973 "android.app.extra.PROVISIONING_SKIP_USER_SETUP";
974
975 /**
Victor Chang51d84f92016-11-16 12:22:56 +0000976 * A boolean extra indicating if the user consent steps from the provisioning flow should be
977 * skipped. If unspecified, defaults to {@code false}.
978 *
979 * It can only be used by an existing device owner trying to create a managed profile via
980 * {@link #ACTION_PROVISION_MANAGED_PROFILE}. Otherwise it is ignored.
981 */
982 public static final String EXTRA_PROVISIONING_SKIP_USER_CONSENT =
983 "android.app.extra.PROVISIONING_SKIP_USER_CONSENT";
984
985 /**
Benjamin Franzea956242016-03-21 15:45:56 +0000986 * This MIME type is used for starting the device owner provisioning.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100987 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400988 * <p>During device owner provisioning a device admin app is set as the owner of the device.
989 * A device owner has full control over the device. The device owner can not be modified by the
990 * user and the only way of resetting the device is if the device owner app calls a factory
991 * reset.
992 *
993 * <p> A typical use case would be a device that is owned by a company, but used by either an
994 * employee or client.
995 *
Benjamin Franzea956242016-03-21 15:45:56 +0000996 * <p> The NFC message must be sent to an unprovisioned device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100997 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000998 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100999 * contains the following properties:
1000 * <ul>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -04001001 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
1002 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +01001003 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -04001004 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +01001005 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
1006 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
1007 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
1008 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
1009 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
1010 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
1011 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
1012 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
1013 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
1014 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Rubin Xu41f2ccb92015-08-05 16:29:13 +01001015 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
1016 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from
1017 * {@link android.os.Build.VERSION_CODES#M} </li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +01001018 *
Nicolas Prevot18440252015-03-09 14:07:17 +00001019 * <p>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07001020 * As of {@link android.os.Build.VERSION_CODES#M}, the properties should contain
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -04001021 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of
1022 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only
1023 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -04001024 */
1025 public static final String MIME_TYPE_PROVISIONING_NFC
1026 = "application/com.android.managedprovisioning";
1027
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +01001028 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001029 * Activity action: ask the user to add a new device administrator to the system.
1030 * The desired policy is the ComponentName of the policy in the
1031 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
1032 * bring the user through adding the device administrator to the system (or
1033 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001034 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001035 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
1036 * field to provide the user with additional explanation (in addition
1037 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001038 *
1039 * <p>If your administrator is already active, this will ordinarily return immediately (without
1040 * user intervention). However, if your administrator has been updated and is requesting
1041 * additional uses-policy flags, the user will be presented with the new list. New policies
1042 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001043 */
1044 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1045 public static final String ACTION_ADD_DEVICE_ADMIN
1046 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001047
Dianne Hackbornd6847842010-01-12 18:14:19 -08001048 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001049 * @hide
1050 * Activity action: ask the user to add a new device administrator as the profile owner
Amith Yamasani814e9872015-03-23 14:04:53 -07001051 * for this user. Only system apps can launch this intent.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001052 *
Amith Yamasani814e9872015-03-23 14:04:53 -07001053 * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN}
1054 * extra field. This will invoke a UI to bring the user through adding the profile owner admin
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001055 * to remotely control restrictions on the user.
1056 *
Makoto Onukic8a5a552015-11-19 14:29:12 -08001057 * <p>The intent must be invoked via {@link Activity#startActivityForResult} to receive the
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001058 * result of whether or not the user approved the action. If approved, the result will
1059 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
1060 * as a profile owner.
1061 *
1062 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
1063 * field to provide the user with additional explanation (in addition
1064 * to your component's description) about what is being added.
1065 *
Amith Yamasani814e9872015-03-23 14:04:53 -07001066 * <p>If there is already a profile owner active or the caller is not a system app, the
1067 * operation will return a failure result.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001068 */
1069 @SystemApi
1070 public static final String ACTION_SET_PROFILE_OWNER
1071 = "android.app.action.SET_PROFILE_OWNER";
1072
1073 /**
1074 * @hide
1075 * Name of the profile owner admin that controls the user.
1076 */
1077 @SystemApi
1078 public static final String EXTRA_PROFILE_OWNER_NAME
1079 = "android.app.extra.PROFILE_OWNER_NAME";
1080
1081 /**
Nicolas Prevot00799002015-07-27 18:15:20 +01001082 * Broadcast action: send when any policy admin changes a policy.
Jim Miller284b62e2010-06-08 14:27:42 -07001083 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -07001084 *
Jim Miller284b62e2010-06-08 14:27:42 -07001085 * @hide
1086 */
1087 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
1088 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
1089
1090 /**
Tony Mak1970f972016-08-30 17:41:48 +01001091 * Broadcast action: sent when the device owner is set, changed or cleared.
Nicolas Prevot00799002015-07-27 18:15:20 +01001092 *
1093 * This broadcast is sent only to the primary user.
1094 * @see #ACTION_PROVISION_MANAGED_DEVICE
1095 */
1096 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1097 public static final String ACTION_DEVICE_OWNER_CHANGED
1098 = "android.app.action.DEVICE_OWNER_CHANGED";
1099
1100 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001101 * The ComponentName of the administrator component.
1102 *
1103 * @see #ACTION_ADD_DEVICE_ADMIN
1104 */
1105 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001106
Dianne Hackbornd6847842010-01-12 18:14:19 -08001107 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001108 * An optional CharSequence providing additional explanation for why the
1109 * admin is being added.
1110 *
1111 * @see #ACTION_ADD_DEVICE_ADMIN
1112 */
1113 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001114
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001115 /**
phweiss73145f42017-01-17 19:06:38 +01001116 * Constant to indicate the feature of disabling the camera. Used as argument to
1117 * {@link #createAdminSupportIntent(String)}.
1118 * @see #setCameraDisabled(ComponentName, boolean)
1119 */
1120 public static final String POLICY_DISABLE_CAMERA = "policy_disable_camera";
1121
1122 /**
1123 * Constant to indicate the feature of disabling screen captures. Used as argument to
1124 * {@link #createAdminSupportIntent(String)}.
1125 * @see #setScreenCaptureDisabled(ComponentName, boolean)
1126 */
1127 public static final String POLICY_DISABLE_SCREEN_CAPTURE = "policy_disable_screen_capture";
1128
1129 /**
1130 * A String indicating a specific restricted feature. Can be a user restriction from the
1131 * {@link UserManager}, e.g. {@link UserManager#DISALLOW_ADJUST_VOLUME}, or one of the values
1132 * {@link #POLICY_DISABLE_CAMERA} or {@link #POLICY_DISABLE_SCREEN_CAPTURE}.
1133 * @see #createAdminSupportIntent(String)
1134 * @hide
1135 */
1136 @TestApi
1137 public static final String EXTRA_RESTRICTION = "android.app.extra.RESTRICTION";
1138
1139 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001140 * Activity action: have the user enter a new password. This activity should
1141 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
1142 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
1143 * enter a new password that meets the current requirements. You can use
1144 * {@link #isActivePasswordSufficient()} to determine whether you need to
1145 * have the user select a new password in order to meet the current
1146 * constraints. Upon being resumed from this activity, you can check the new
1147 * password characteristics to see if they are sufficient.
Benjamin Franzc9921092016-01-08 17:17:44 +00001148 *
1149 * If the intent is launched from within a managed profile with a profile
1150 * owner built against {@link android.os.Build.VERSION_CODES#M} or before,
1151 * this will trigger entering a new password for the parent of the profile.
1152 * For all other cases it will trigger entering a new password for the user
1153 * or profile it is launched from.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001154 *
1155 * @see #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
Dianne Hackbornd6847842010-01-12 18:14:19 -08001156 */
1157 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1158 public static final String ACTION_SET_NEW_PASSWORD
1159 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001160
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001161 /**
Benjamin Franzc9921092016-01-08 17:17:44 +00001162 * Activity action: have the user enter a new password for the parent profile.
1163 * If the intent is launched from within a managed profile, this will trigger
1164 * entering a new password for the parent of the profile. In all other cases
1165 * the behaviour is identical to {@link #ACTION_SET_NEW_PASSWORD}.
1166 */
1167 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1168 public static final String ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
1169 = "android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD";
1170
1171 /**
phweissa0cb2512016-12-14 21:37:48 +01001172 * Broadcast action: Tell the status bar to open the device monitoring dialog, e.g. when
1173 * Network logging was enabled and the user tapped the notification.
1174 * <p class="note">This is a protected intent that can only be sent by the system.</p>
1175 * @hide
1176 */
1177 public static final String ACTION_SHOW_DEVICE_MONITORING_DIALOG
1178 = "android.app.action.SHOW_DEVICE_MONITORING_DIALOG";
1179
1180 /**
Edman Anjos9e62c312017-01-26 22:22:58 +01001181 * Broadcast Action: Sent after application delegation scopes are changed. The new delegation
1182 * scopes will be sent in an {@code ArrayList<String>} extra identified by the
1183 * {@link #EXTRA_DELEGATION_SCOPES} key.
Edman Anjosf9946772016-11-28 16:35:15 +01001184 *
1185 * <p class=”note”> Note: This is a protected intent that can only be sent by the system.</p>
1186 */
1187 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1188 public static final String ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED =
1189 "android.app.action.APPLICATION_DELEGATION_SCOPES_CHANGED";
1190
1191 /**
Edman Anjos9e62c312017-01-26 22:22:58 +01001192 * An {@code ArrayList<String>} corresponding to the delegation scopes given to an app in the
Edman Anjosf9946772016-11-28 16:35:15 +01001193 * {@link #ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED} broadcast.
1194 */
1195 public static final String EXTRA_DELEGATION_SCOPES = "android.app.extra.DELEGATION_SCOPES";
1196
1197 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +00001198 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
1199 * the parent profile to access intents sent from the managed profile.
1200 * That is, when an app in the managed profile calls
1201 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
1202 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001203 */
Nicolas Prevot86a96732014-09-08 12:13:05 +01001204 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001205
1206 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +00001207 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
1208 * the managed profile to access intents sent from the parent profile.
1209 * That is, when an app in the parent profile calls
1210 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
1211 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001212 */
Nicolas Prevot86a96732014-09-08 12:13:05 +01001213 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001214
Dianne Hackbornd6847842010-01-12 18:14:19 -08001215 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01001216 * Broadcast action: notify that a new local system update policy has been set by the device
1217 * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00001218 */
1219 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Rubin Xu5faad8e2015-04-20 17:43:48 +01001220 public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED
1221 = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED";
Rubin Xu8027a4f2015-03-10 17:52:37 +00001222
Amith Yamasanid49489b2015-04-28 14:00:26 -07001223 /**
1224 * Permission policy to prompt user for new permission requests for runtime permissions.
1225 * Already granted or denied permissions are not affected by this.
1226 */
1227 public static final int PERMISSION_POLICY_PROMPT = 0;
1228
1229 /**
1230 * Permission policy to always grant new permission requests for runtime permissions.
1231 * Already granted or denied permissions are not affected by this.
1232 */
1233 public static final int PERMISSION_POLICY_AUTO_GRANT = 1;
1234
1235 /**
1236 * Permission policy to always deny new permission requests for runtime permissions.
1237 * Already granted or denied permissions are not affected by this.
1238 */
1239 public static final int PERMISSION_POLICY_AUTO_DENY = 2;
1240
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07001241 /**
1242 * Runtime permission state: The user can manage the permission
1243 * through the UI.
1244 */
1245 public static final int PERMISSION_GRANT_STATE_DEFAULT = 0;
1246
1247 /**
1248 * Runtime permission state: The permission is granted to the app
1249 * and the user cannot manage the permission through the UI.
1250 */
1251 public static final int PERMISSION_GRANT_STATE_GRANTED = 1;
1252
1253 /**
1254 * Runtime permission state: The permission is denied to the app
1255 * and the user cannot manage the permission through the UI.
1256 */
1257 public static final int PERMISSION_GRANT_STATE_DENIED = 2;
Rubin Xu8027a4f2015-03-10 17:52:37 +00001258
1259 /**
Edman Anjosf9946772016-11-28 16:35:15 +01001260 * Delegation of certificate installation and management. This scope grants access to the
1261 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
1262 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair} APIs.
1263 */
1264 public static final String DELEGATION_CERT_INSTALL = "delegation-cert-install";
1265
1266 /**
1267 * Delegation of application restrictions management. This scope grants access to the
1268 * {@link #setApplicationRestrictions} and {@link #getApplicationRestrictions} APIs.
1269 */
1270 public static final String DELEGATION_APP_RESTRICTIONS = "delegation-app-restrictions";
1271
1272 /**
Edman Anjosa5f2fb12016-12-19 11:25:54 -08001273 * Delegation of application uninstall block. This scope grants access to the
1274 * {@link #setUninstallBlocked} API.
1275 */
1276 public static final String DELEGATION_BLOCK_UNINSTALL = "delegation-block-uninstall";
1277
1278 /**
Edman Anjos52088e42017-01-13 22:26:17 +01001279 * Delegation of permission policy and permission grant state. This scope grants access to the
1280 * {@link #setPermissionPolicy}, {@link #getPermissionGrantState},
1281 * and {@link #setPermissionGrantState} APIs.
1282 */
1283 public static final String DELEGATION_PERMISSION_GRANT = "delegation-permission-grant";
1284
1285 /**
1286 * Delegation of package access state. This scope grants access to the
1287 * {@link #isApplicationHidden}, {@link #setApplicationHidden}, {@link #isPackageSuspended}, and
1288 * {@link #setPackagesSuspended} APIs.
1289 */
1290 public static final String DELEGATION_PACKAGE_ACCESS = "delegation-package-access";
1291
1292 /**
1293 * Delegation for enabling system apps. This scope grants access to the {@link #enableSystemApp}
1294 * API.
1295 */
1296 public static final String DELEGATION_ENABLE_SYSTEM_APP = "delegation-enable-system-app";
1297
1298 /**
1299 * Delegation of management of uninstalled packages. This scope grants access to the
1300 * {@code #setKeepUninstalledPackages} and {@code #getKeepUninstalledPackages} APIs.
1301 * @hide
1302 */
1303 public static final String DELEGATION_KEEP_UNINSTALLED_PACKAGES =
1304 "delegation-keep-uninstalled-packages";
1305
1306 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00001307 * No management for current user in-effect. This is the default.
1308 * @hide
1309 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001310 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001311 public static final int STATE_USER_UNMANAGED = 0;
1312
1313 /**
1314 * Management partially setup, user setup needs to be completed.
1315 * @hide
1316 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001317 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001318 public static final int STATE_USER_SETUP_INCOMPLETE = 1;
1319
1320 /**
1321 * Management partially setup, user setup completed.
1322 * @hide
1323 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001324 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001325 public static final int STATE_USER_SETUP_COMPLETE = 2;
1326
1327 /**
1328 * Management setup and active on current user.
1329 * @hide
1330 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001331 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001332 public static final int STATE_USER_SETUP_FINALIZED = 3;
1333
1334 /**
1335 * Management partially setup on a managed profile.
1336 * @hide
1337 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001338 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001339 public static final int STATE_USER_PROFILE_COMPLETE = 4;
1340
1341 /**
1342 * @hide
1343 */
1344 @IntDef({STATE_USER_UNMANAGED, STATE_USER_SETUP_INCOMPLETE, STATE_USER_SETUP_COMPLETE,
1345 STATE_USER_SETUP_FINALIZED, STATE_USER_PROFILE_COMPLETE})
1346 @Retention(RetentionPolicy.SOURCE)
1347 public @interface UserProvisioningState {}
1348
1349 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001350 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001351 *
1352 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1353 * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and
1354 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when provisioning is allowed.
1355 *
1356 * @hide
1357 */
1358 public static final int CODE_OK = 0;
1359
1360 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001361 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001362 *
1363 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and
1364 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the device already has a device
1365 * owner.
1366 *
1367 * @hide
1368 */
1369 public static final int CODE_HAS_DEVICE_OWNER = 1;
1370
1371 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001372 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001373 *
1374 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1375 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user has a profile owner and for
1376 * {@link #ACTION_PROVISION_MANAGED_PROFILE} when the profile owner is already set.
1377 *
1378 * @hide
1379 */
1380 public static final int CODE_USER_HAS_PROFILE_OWNER = 2;
1381
1382 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001383 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001384 *
1385 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and
1386 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user isn't running.
1387 *
1388 * @hide
1389 */
1390 public static final int CODE_USER_NOT_RUNNING = 3;
1391
1392 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001393 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001394 *
1395 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1396 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the device has already been setup and
1397 * for {@link #ACTION_PROVISION_MANAGED_USER} if the user has already been setup.
1398 *
1399 * @hide
1400 */
1401 public static final int CODE_USER_SETUP_COMPLETED = 4;
1402
1403 /**
1404 * Code used to indicate that the device also has a user other than the system user.
1405 *
1406 * @hide
1407 */
1408 public static final int CODE_NONSYSTEM_USER_EXISTS = 5;
1409
1410 /**
1411 * Code used to indicate that device has an account that prevents provisioning.
1412 *
1413 * @hide
1414 */
1415 public static final int CODE_ACCOUNTS_NOT_EMPTY = 6;
1416
1417 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001418 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001419 *
1420 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and
1421 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the user is not a system user.
1422 *
1423 * @hide
1424 */
1425 public static final int CODE_NOT_SYSTEM_USER = 7;
1426
1427 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001428 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001429 *
1430 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1431 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} and {@link #ACTION_PROVISION_MANAGED_USER}
1432 * when the device is a watch and is already paired.
1433 *
1434 * @hide
1435 */
1436 public static final int CODE_HAS_PAIRED = 8;
1437
1438 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001439 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001440 *
1441 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} and
1442 * {@link #ACTION_PROVISION_MANAGED_USER} on devices which do not support managed users.
1443 *
1444 * @see {@link PackageManager#FEATURE_MANAGED_USERS}
1445 * @hide
1446 */
1447 public static final int CODE_MANAGED_USERS_NOT_SUPPORTED = 9;
1448
1449 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001450 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001451 *
1452 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} if the user is a system user.
1453 *
1454 * @hide
1455 */
1456 public static final int CODE_SYSTEM_USER = 10;
1457
1458 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001459 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001460 *
1461 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when the user cannot have more
1462 * managed profiles.
1463 *
1464 * @hide
1465 */
1466 public static final int CODE_CANNOT_ADD_MANAGED_PROFILE = 11;
1467
1468 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001469 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001470 *
1471 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} and
1472 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices not running with split system
1473 * user.
1474 *
1475 * @hide
1476 */
1477 public static final int CODE_NOT_SYSTEM_USER_SPLIT = 12;
1478
1479 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001480 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001481 *
1482 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1483 * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and
1484 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices which do no support device
1485 * admins.
1486 *
1487 * @hide
1488 */
1489 public static final int CODE_DEVICE_ADMIN_NOT_SUPPORTED = 13;
1490
1491 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001492 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001493 *
Esteban Talavera6c9116a2016-11-24 16:12:44 +00001494 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when the device the user is a
1495 * system user on a split system user device.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001496 *
1497 * @hide
1498 */
1499 public static final int CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER = 14;
1500
1501 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001502 * Result code for {@link #checkProvisioningPreCondition}.
1503 *
1504 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when adding a managed profile is
1505 * disallowed by {@link UserManager#DISALLOW_ADD_MANAGED_PROFILE}.
1506 *
1507 * @hide
1508 */
1509 public static final int CODE_ADD_MANAGED_PROFILE_DISALLOWED = 15;
1510
1511 /**
1512 * Result codes for {@link #checkProvisioningPreCondition} indicating all the provisioning pre
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001513 * conditions.
1514 *
1515 * @hide
1516 */
1517 @Retention(RetentionPolicy.SOURCE)
1518 @IntDef({CODE_OK, CODE_HAS_DEVICE_OWNER, CODE_USER_HAS_PROFILE_OWNER, CODE_USER_NOT_RUNNING,
1519 CODE_USER_SETUP_COMPLETED, CODE_NOT_SYSTEM_USER, CODE_HAS_PAIRED,
1520 CODE_MANAGED_USERS_NOT_SUPPORTED, CODE_SYSTEM_USER, CODE_CANNOT_ADD_MANAGED_PROFILE,
1521 CODE_NOT_SYSTEM_USER_SPLIT, CODE_DEVICE_ADMIN_NOT_SUPPORTED,
Esteban Talavera01576862016-12-15 11:16:44 +00001522 CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER, CODE_ADD_MANAGED_PROFILE_DISALLOWED})
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001523 public @interface ProvisioningPreCondition {}
1524
1525 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001526 * Return true if the given administrator component is currently active (enabled) in the system.
1527 *
1528 * @param admin The administrator component to check for.
1529 * @return {@code true} if {@code admin} is currently enabled in the system, {@code false}
1530 * otherwise
Dianne Hackbornd6847842010-01-12 18:14:19 -08001531 */
Robin Lee25e26452015-06-02 09:56:29 -07001532 public boolean isAdminActive(@NonNull ComponentName admin) {
Charles He8c760562016-10-25 16:36:53 +01001533 throwIfParentInstance("isAdminActive");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001534 return isAdminActiveAsUser(admin, myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001535 }
1536
1537 /**
1538 * @see #isAdminActive(ComponentName)
1539 * @hide
1540 */
Robin Lee25e26452015-06-02 09:56:29 -07001541 public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001542 if (mService != null) {
1543 try {
Robin Lee25e26452015-06-02 09:56:29 -07001544 return mService.isAdminActive(admin, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001545 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001546 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001547 }
1548 }
1549 return false;
1550 }
Charles Hedea0c3b2017-01-13 10:04:12 +00001551
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001552 /**
1553 * Return true if the given administrator component is currently being removed
1554 * for the user.
1555 * @hide
1556 */
Robin Lee25e26452015-06-02 09:56:29 -07001557 public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) {
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001558 if (mService != null) {
1559 try {
Robin Lee25e26452015-06-02 09:56:29 -07001560 return mService.isRemovingAdmin(admin, userId);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001561 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001562 throw e.rethrowFromSystemServer();
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001563 }
1564 }
1565 return false;
1566 }
1567
Dianne Hackbornd6847842010-01-12 18:14:19 -08001568 /**
Robin Lee25e26452015-06-02 09:56:29 -07001569 * Return a list of all currently active device administrators' component
1570 * names. If there are no administrators {@code null} may be
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001571 * returned.
1572 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07001573 public @Nullable List<ComponentName> getActiveAdmins() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001574 throwIfParentInstance("getActiveAdmins");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001575 return getActiveAdminsAsUser(myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001576 }
1577
1578 /**
1579 * @see #getActiveAdmins()
1580 * @hide
1581 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07001582 public @Nullable List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001583 if (mService != null) {
1584 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001585 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001586 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001587 throw e.rethrowFromSystemServer();
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001588 }
1589 }
1590 return null;
1591 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001592
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001593 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001594 * Used by package administration code to determine if a package can be stopped
1595 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001596 * @hide
1597 */
David Ouyang3a83a332017-01-11 16:36:40 -08001598 @SystemApi
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001599 public boolean packageHasActiveAdmins(String packageName) {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001600 return packageHasActiveAdmins(packageName, myUserId());
1601 }
1602
1603 /**
1604 * Used by package administration code to determine if a package can be stopped
1605 * or uninstalled.
1606 * @hide
1607 */
1608 public boolean packageHasActiveAdmins(String packageName, int userId) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001609 if (mService != null) {
1610 try {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001611 return mService.packageHasActiveAdmins(packageName, userId);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001612 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001613 throw e.rethrowFromSystemServer();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001614 }
1615 }
1616 return false;
1617 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001618
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001619 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001620 * Remove a current administration component. This can only be called
1621 * by the application that owns the administration component; if you
1622 * try to remove someone else's component, a security exception will be
1623 * thrown.
Esteban Talavera552a5612016-02-19 17:02:24 +00001624 *
1625 * <p>Note that the operation is not synchronous and the admin might still be active (as
1626 * indicated by {@link #getActiveAdmins()}) by the time this method returns.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001627 *
1628 * @param admin The administration compononent to remove.
1629 * @throws SecurityException if the caller is not in the owner application of {@code admin}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001630 */
Robin Lee25e26452015-06-02 09:56:29 -07001631 public void removeActiveAdmin(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001632 throwIfParentInstance("removeActiveAdmin");
Dianne Hackbornd6847842010-01-12 18:14:19 -08001633 if (mService != null) {
1634 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001635 mService.removeActiveAdmin(admin, myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001636 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001637 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001638 }
1639 }
1640 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001641
Dianne Hackbornd6847842010-01-12 18:14:19 -08001642 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001643 * Returns true if an administrator has been granted a particular device policy. This can be
1644 * used to check whether the administrator was activated under an earlier set of policies, but
1645 * requires additional policies after an upgrade.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001646 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001647 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be an
1648 * active administrator, or an exception will be thrown.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001649 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001650 * @throws SecurityException if {@code admin} is not an active administrator.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001651 */
Robin Lee25e26452015-06-02 09:56:29 -07001652 public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001653 throwIfParentInstance("hasGrantedPolicy");
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001654 if (mService != null) {
1655 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001656 return mService.hasGrantedPolicy(admin, usesPolicy, myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001657 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001658 throw e.rethrowFromSystemServer();
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001659 }
1660 }
1661 return false;
1662 }
1663
1664 /**
Clara Bayarria1771112015-12-18 16:29:18 +00001665 * Returns true if the Profile Challenge is available to use for the given profile user.
1666 *
1667 * @hide
1668 */
1669 public boolean isSeparateProfileChallengeAllowed(int userHandle) {
1670 if (mService != null) {
1671 try {
1672 return mService.isSeparateProfileChallengeAllowed(userHandle);
1673 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001674 throw e.rethrowFromSystemServer();
Clara Bayarria1771112015-12-18 16:29:18 +00001675 }
1676 }
1677 return false;
1678 }
1679
1680 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001681 * Constant for {@link #setPasswordQuality}: the policy has no requirements
1682 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001683 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001684 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001685 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001686
Dianne Hackbornd6847842010-01-12 18:14:19 -08001687 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -07001688 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
1689 * recognition technology. This implies technologies that can recognize the identity of
1690 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
1691 * Note that quality constants are ordered so that higher values are more restrictive.
1692 */
1693 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
1694
1695 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001696 * Constant for {@link #setPasswordQuality}: the policy requires some kind
Benjamin Franzc6a96532015-06-16 11:23:38 +01001697 * of password or pattern, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001698 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001699 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001700 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001701
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001702 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001703 * Constant for {@link #setPasswordQuality}: the user must have entered a
1704 * password containing at least numeric characters. Note that quality
1705 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001706 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001707 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001708
Dianne Hackbornd6847842010-01-12 18:14:19 -08001709 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001710 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -08001711 * password containing at least numeric characters with no repeating (4444)
1712 * or ordered (1234, 4321, 2468) sequences. Note that quality
1713 * constants are ordered so that higher values are more restrictive.
1714 */
1715 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
1716
1717 /**
1718 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001719 * password containing at least alphabetic (or other symbol) characters.
1720 * Note that quality constants are ordered so that higher values are more
1721 * restrictive.
1722 */
1723 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001724
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001725 /**
1726 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001727 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001728 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001729 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001730 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001731 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001732
Dianne Hackbornd6847842010-01-12 18:14:19 -08001733 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001734 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001735 * password containing at least a letter, a numerical digit and a special
1736 * symbol, by default. With this password quality, passwords can be
1737 * restricted to contain various sets of characters, like at least an
1738 * uppercase letter, etc. These are specified using various methods,
1739 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
1740 * that quality constants are ordered so that higher values are more
1741 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001742 */
1743 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
1744
1745 /**
Oleksandr Peletskyi0fdcd3d2016-01-13 16:49:56 +01001746 * Constant for {@link #setPasswordQuality}: the user is not allowed to
1747 * modify password. In case this password quality is set, the password is
1748 * managed by a profile owner. The profile owner can set any password,
1749 * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note
1750 * that quality constants are ordered so that higher values are more
1751 * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is
1752 * the highest.
1753 * @hide
1754 */
1755 public static final int PASSWORD_QUALITY_MANAGED = 0x80000;
1756
1757 /**
Makoto Onuki5e7e06702016-09-01 18:02:01 -07001758 * @hide
1759 *
1760 * adb shell dpm set-{device,profile}-owner will normally not allow installing an owner to
1761 * a user with accounts. {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED}
1762 * and {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} are the account features
1763 * used by authenticator to exempt their accounts from this:
1764 *
1765 * <ul>
1766 * <li>Non-test-only DO/PO still can't be installed when there are accounts.
1767 * <p>In order to make an apk test-only, add android:testOnly="true" to the
1768 * &lt;application&gt; tag in the manifest.
1769 *
1770 * <li>Test-only DO/PO can be installed even when there are accounts, as long as all the
1771 * accounts have the {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} feature.
1772 * Some authenticators claim to have any features, so to detect it, we also check
1773 * {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} and disallow installing
1774 * if any of the accounts have it.
1775 * </ul>
1776 */
Makoto Onuki47c203d2017-02-13 16:21:19 -08001777 @SystemApi
1778 @TestApi
Makoto Onuki5e7e06702016-09-01 18:02:01 -07001779 public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED =
1780 "android.account.DEVICE_OR_PROFILE_OWNER_ALLOWED";
1781
1782 /** @hide See {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} */
Makoto Onuki47c203d2017-02-13 16:21:19 -08001783 @SystemApi
1784 @TestApi
Makoto Onuki5e7e06702016-09-01 18:02:01 -07001785 public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED =
1786 "android.account.DEVICE_OR_PROFILE_OWNER_DISALLOWED";
1787
1788 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001789 * Called by an application that is administering the device to set the password restrictions it
1790 * is imposing. After setting this, the user will not be able to enter a new password that is
1791 * not at least as restrictive as what has been set. Note that the current password will remain
1792 * until the user has set a new one, so the change does not take place immediately. To prompt
1793 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
Esteban Talaverac1c83592016-02-17 17:56:15 +00001794 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after calling this method.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001795 * <p>
1796 * Quality constants are ordered so that higher values are more restrictive; thus the highest
1797 * requested quality constant (between the policy set here, the user's preference, and any other
1798 * considerations) is the one that is in effect.
1799 * <p>
1800 * The calling device admin must have requested
1801 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1802 * not, a security exception will be thrown.
1803 * <p>
1804 * This method can be called on the {@link DevicePolicyManager} instance returned by
1805 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1806 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001807 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001808 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001809 * @param quality The new desired quality. One of {@link #PASSWORD_QUALITY_UNSPECIFIED},
1810 * {@link #PASSWORD_QUALITY_SOMETHING}, {@link #PASSWORD_QUALITY_NUMERIC},
1811 * {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC},
1812 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} or {@link #PASSWORD_QUALITY_COMPLEX}.
1813 * @throws SecurityException if {@code admin} is not an active administrator or if {@code admin}
1814 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Dianne Hackbornd6847842010-01-12 18:14:19 -08001815 */
Robin Lee25e26452015-06-02 09:56:29 -07001816 public void setPasswordQuality(@NonNull ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001817 if (mService != null) {
1818 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001819 mService.setPasswordQuality(admin, quality, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001820 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001821 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001822 }
1823 }
1824 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001825
Dianne Hackbornd6847842010-01-12 18:14:19 -08001826 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001827 * Retrieve the current minimum password quality for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01001828 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00001829 * a separate challenge are not taken into account.
1830 *
1831 * <p>This method can be called on the {@link DevicePolicyManager} instance
1832 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1833 * restrictions on the parent profile.
1834 *
Robin Lee25e26452015-06-02 09:56:29 -07001835 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001836 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001837 */
Robin Lee25e26452015-06-02 09:56:29 -07001838 public int getPasswordQuality(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001839 return getPasswordQuality(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001840 }
1841
1842 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001843 public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001844 if (mService != null) {
1845 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001846 return mService.getPasswordQuality(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001847 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001848 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001849 }
1850 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001851 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001852 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001853
Dianne Hackbornd6847842010-01-12 18:14:19 -08001854 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001855 * Called by an application that is administering the device to set the minimum allowed password
1856 * length. After setting this, the user will not be able to enter a new password that is not at
1857 * least as restrictive as what has been set. Note that the current password will remain until
1858 * the user has set a new one, so the change does not take place immediately. To prompt the user
1859 * for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
1860 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
1861 * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC}
1862 * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC},
1863 * {@link #PASSWORD_QUALITY_ALPHANUMERIC}, or {@link #PASSWORD_QUALITY_COMPLEX} with
1864 * {@link #setPasswordQuality}.
1865 * <p>
1866 * The calling device admin must have requested
1867 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1868 * not, a security exception will be thrown.
1869 * <p>
1870 * This method can be called on the {@link DevicePolicyManager} instance returned by
1871 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1872 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001873 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001874 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001875 * @param length The new desired minimum password length. A value of 0 means there is no
1876 * restriction.
1877 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1878 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Dianne Hackbornd6847842010-01-12 18:14:19 -08001879 */
Robin Lee25e26452015-06-02 09:56:29 -07001880 public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001881 if (mService != null) {
1882 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001883 mService.setPasswordMinimumLength(admin, length, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001884 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001885 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001886 }
1887 }
1888 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001889
Dianne Hackbornd6847842010-01-12 18:14:19 -08001890 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001891 * Retrieve the current minimum password length for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01001892 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00001893 * a separate challenge are not taken into account.
1894 *
1895 * <p>This method can be called on the {@link DevicePolicyManager} instance
1896 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1897 * restrictions on the parent profile.
1898 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001899 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001900 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001901 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001902 */
Robin Lee25e26452015-06-02 09:56:29 -07001903 public int getPasswordMinimumLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001904 return getPasswordMinimumLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001905 }
1906
1907 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001908 public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001909 if (mService != null) {
1910 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001911 return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001912 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001913 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001914 }
1915 }
1916 return 0;
1917 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001918
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001919 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001920 * Called by an application that is administering the device to set the minimum number of upper
1921 * case letters required in the password. After setting this, the user will not be able to enter
1922 * a new password that is not at least as restrictive as what has been set. Note that the
1923 * current password will remain until the user has set a new one, so the change does not take
1924 * place immediately. To prompt the user for a new password, use
1925 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
1926 * setting this value. This constraint is only imposed if the administrator has also requested
1927 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001928 * <p>
1929 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001930 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1931 * not, a security exception will be thrown.
1932 * <p>
1933 * This method can be called on the {@link DevicePolicyManager} instance returned by
1934 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1935 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001936 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001937 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1938 * @param length The new desired minimum number of upper case letters required in the password.
1939 * A value of 0 means there is no restriction.
1940 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1941 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001942 */
Robin Lee25e26452015-06-02 09:56:29 -07001943 public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001944 if (mService != null) {
1945 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001946 mService.setPasswordMinimumUpperCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001947 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001948 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001949 }
1950 }
1951 }
1952
1953 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001954 * Retrieve the current number of upper case letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01001955 * for a particular admin or all admins that set restrictions on this user and
Esteban Talaverac1c83592016-02-17 17:56:15 +00001956 * its participating profiles. Restrictions on profiles that have a separate challenge
1957 * are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001958 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001959 * {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001960 * and only applies when the password quality is
1961 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001962 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001963 * <p>This method can be called on the {@link DevicePolicyManager} instance
1964 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1965 * restrictions on the parent profile.
1966 *
Robin Lee25e26452015-06-02 09:56:29 -07001967 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001968 * aggregate all admins.
1969 * @return The minimum number of upper case letters required in the
1970 * password.
1971 */
Robin Lee25e26452015-06-02 09:56:29 -07001972 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001973 return getPasswordMinimumUpperCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001974 }
1975
1976 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001977 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001978 if (mService != null) {
1979 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001980 return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001981 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001982 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001983 }
1984 }
1985 return 0;
1986 }
1987
1988 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001989 * Called by an application that is administering the device to set the minimum number of lower
1990 * case letters required in the password. After setting this, the user will not be able to enter
1991 * a new password that is not at least as restrictive as what has been set. Note that the
1992 * current password will remain until the user has set a new one, so the change does not take
1993 * place immediately. To prompt the user for a new password, use
1994 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
1995 * setting this value. This constraint is only imposed if the administrator has also requested
1996 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001997 * <p>
1998 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001999 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2000 * not, a security exception will be thrown.
2001 * <p>
2002 * This method can be called on the {@link DevicePolicyManager} instance returned by
2003 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2004 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002005 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002006 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2007 * @param length The new desired minimum number of lower case letters required in the password.
2008 * A value of 0 means there is no restriction.
2009 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2010 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002011 */
Robin Lee25e26452015-06-02 09:56:29 -07002012 public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002013 if (mService != null) {
2014 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002015 mService.setPasswordMinimumLowerCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002016 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002017 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002018 }
2019 }
2020 }
2021
2022 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002023 * Retrieve the current number of lower case letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002024 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002025 * and its participating profiles. Restrictions on profiles that have
2026 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01002027 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00002028 * {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002029 * and only applies when the password quality is
2030 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002031 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002032 * <p>This method can be called on the {@link DevicePolicyManager} instance
2033 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2034 * restrictions on the parent profile.
2035 *
Robin Lee25e26452015-06-02 09:56:29 -07002036 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002037 * aggregate all admins.
2038 * @return The minimum number of lower case letters required in the
2039 * password.
2040 */
Robin Lee25e26452015-06-02 09:56:29 -07002041 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002042 return getPasswordMinimumLowerCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002043 }
2044
2045 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002046 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002047 if (mService != null) {
2048 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002049 return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002050 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002051 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002052 }
2053 }
2054 return 0;
2055 }
2056
2057 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002058 * Called by an application that is administering the device to set the minimum number of
2059 * letters required in the password. After setting this, the user will not be able to enter a
2060 * new password that is not at least as restrictive as what has been set. Note that the current
2061 * password will remain until the user has set a new one, so the change does not take place
2062 * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
2063 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
2064 * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
2065 * {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002066 * <p>
2067 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002068 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2069 * not, a security exception will be thrown.
2070 * <p>
2071 * This method can be called on the {@link DevicePolicyManager} instance returned by
2072 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2073 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002074 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002075 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2076 * @param length The new desired minimum number of letters required in the password. A value of
2077 * 0 means there is no restriction.
2078 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2079 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002080 */
Robin Lee25e26452015-06-02 09:56:29 -07002081 public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002082 if (mService != null) {
2083 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002084 mService.setPasswordMinimumLetters(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002085 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002086 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002087 }
2088 }
2089 }
2090
2091 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002092 * Retrieve the current number of letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002093 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002094 * and its participating profiles. Restrictions on profiles that have
2095 * a separate challenge are not taken into account.
2096 * This is the same value as set by
2097 * {@link #setPasswordMinimumLetters(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002098 * and only applies when the password quality is
2099 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002100 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002101 * <p>This method can be called on the {@link DevicePolicyManager} instance
2102 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2103 * restrictions on the parent profile.
2104 *
Robin Lee25e26452015-06-02 09:56:29 -07002105 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002106 * aggregate all admins.
2107 * @return The minimum number of letters required in the password.
2108 */
Robin Lee25e26452015-06-02 09:56:29 -07002109 public int getPasswordMinimumLetters(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002110 return getPasswordMinimumLetters(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002111 }
2112
2113 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002114 public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002115 if (mService != null) {
2116 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002117 return mService.getPasswordMinimumLetters(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002118 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002119 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002120 }
2121 }
2122 return 0;
2123 }
2124
2125 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002126 * Called by an application that is administering the device to set the minimum number of
2127 * numerical digits required in the password. After setting this, the user will not be able to
2128 * enter a new password that is not at least as restrictive as what has been set. Note that the
2129 * current password will remain until the user has set a new one, so the change does not take
2130 * place immediately. To prompt the user for a new password, use
2131 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
2132 * setting this value. This constraint is only imposed if the administrator has also requested
2133 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002134 * <p>
2135 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002136 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2137 * not, a security exception will be thrown.
2138 * <p>
2139 * This method can be called on the {@link DevicePolicyManager} instance returned by
2140 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2141 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002142 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002143 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2144 * @param length The new desired minimum number of numerical digits required in the password. A
2145 * value of 0 means there is no restriction.
2146 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2147 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002148 */
Robin Lee25e26452015-06-02 09:56:29 -07002149 public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002150 if (mService != null) {
2151 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002152 mService.setPasswordMinimumNumeric(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002153 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002154 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002155 }
2156 }
2157 }
2158
2159 /**
2160 * Retrieve the current number of numerical digits required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002161 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002162 * and its participating profiles. Restrictions on profiles that have
2163 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01002164 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00002165 * {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002166 * and only applies when the password quality is
2167 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002168 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002169 * <p>This method can be called on the {@link DevicePolicyManager} instance
2170 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2171 * restrictions on the parent profile.
2172 *
Robin Lee25e26452015-06-02 09:56:29 -07002173 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002174 * aggregate all admins.
2175 * @return The minimum number of numerical digits required in the password.
2176 */
Robin Lee25e26452015-06-02 09:56:29 -07002177 public int getPasswordMinimumNumeric(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002178 return getPasswordMinimumNumeric(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002179 }
2180
2181 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002182 public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002183 if (mService != null) {
2184 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002185 return mService.getPasswordMinimumNumeric(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002186 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002187 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002188 }
2189 }
2190 return 0;
2191 }
2192
2193 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002194 * Called by an application that is administering the device to set the minimum number of
2195 * symbols required in the password. After setting this, the user will not be able to enter a
2196 * new password that is not at least as restrictive as what has been set. Note that the current
2197 * password will remain until the user has set a new one, so the change does not take place
2198 * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
2199 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
2200 * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
2201 * {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002202 * <p>
2203 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002204 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2205 * not, a security exception will be thrown.
2206 * <p>
2207 * This method can be called on the {@link DevicePolicyManager} instance returned by
2208 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2209 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002210 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002211 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2212 * @param length The new desired minimum number of symbols required in the password. A value of
2213 * 0 means there is no restriction.
2214 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2215 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002216 */
Robin Lee25e26452015-06-02 09:56:29 -07002217 public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002218 if (mService != null) {
2219 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002220 mService.setPasswordMinimumSymbols(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002221 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002222 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002223 }
2224 }
2225 }
2226
2227 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002228 * Retrieve the current number of symbols required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002229 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002230 * and its participating profiles. Restrictions on profiles that have
2231 * a separate challenge are not taken into account. This is the same value as
2232 * set by {@link #setPasswordMinimumSymbols(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002233 * and only applies when the password quality is
2234 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002235 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002236 * <p>This method can be called on the {@link DevicePolicyManager} instance
2237 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2238 * restrictions on the parent profile.
2239 *
Robin Lee25e26452015-06-02 09:56:29 -07002240 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002241 * aggregate all admins.
2242 * @return The minimum number of symbols required in the password.
2243 */
Robin Lee25e26452015-06-02 09:56:29 -07002244 public int getPasswordMinimumSymbols(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002245 return getPasswordMinimumSymbols(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002246 }
2247
2248 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002249 public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002250 if (mService != null) {
2251 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002252 return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002253 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002254 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002255 }
2256 }
2257 return 0;
2258 }
2259
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002260 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002261 * Called by an application that is administering the device to set the minimum number of
2262 * non-letter characters (numerical digits or symbols) required in the password. After setting
2263 * this, the user will not be able to enter a new password that is not at least as restrictive
2264 * as what has been set. Note that the current password will remain until the user has set a new
2265 * one, so the change does not take place immediately. To prompt the user for a new password,
2266 * use {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
2267 * setting this value. This constraint is only imposed if the administrator has also requested
2268 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002269 * <p>
2270 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002271 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2272 * not, a security exception will be thrown.
2273 * <p>
2274 * This method can be called on the {@link DevicePolicyManager} instance returned by
2275 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2276 * profile.
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002277 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002278 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2279 * @param length The new desired minimum number of letters required in the password. A value of
2280 * 0 means there is no restriction.
2281 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2282 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002283 */
Robin Lee25e26452015-06-02 09:56:29 -07002284 public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002285 if (mService != null) {
2286 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002287 mService.setPasswordMinimumNonLetter(admin, length, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002288 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002289 throw e.rethrowFromSystemServer();
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002290 }
2291 }
2292 }
2293
2294 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002295 * Retrieve the current number of non-letter characters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002296 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002297 * and its participating profiles. Restrictions on profiles that have
2298 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01002299 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00002300 * {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002301 * and only applies when the password quality is
2302 * {@link #PASSWORD_QUALITY_COMPLEX}.
2303 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002304 * <p>This method can be called on the {@link DevicePolicyManager} instance
2305 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2306 * restrictions on the parent profile.
2307 *
Robin Lee25e26452015-06-02 09:56:29 -07002308 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002309 * aggregate all admins.
2310 * @return The minimum number of letters required in the password.
2311 */
Robin Lee25e26452015-06-02 09:56:29 -07002312 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002313 return getPasswordMinimumNonLetter(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002314 }
2315
2316 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002317 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002318 if (mService != null) {
2319 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002320 return mService.getPasswordMinimumNonLetter(admin, userHandle, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002321 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002322 throw e.rethrowFromSystemServer();
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002323 }
2324 }
2325 return 0;
2326 }
2327
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002328 /**
2329 * Called by an application that is administering the device to set the length of the password
2330 * history. After setting this, the user will not be able to enter a new password that is the
2331 * same as any password in the history. Note that the current password will remain until the
2332 * user has set a new one, so the change does not take place immediately. To prompt the user for
2333 * a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
2334 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
2335 * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC}
2336 * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX} {@link #PASSWORD_QUALITY_ALPHABETIC}, or
2337 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} with {@link #setPasswordQuality}.
2338 * <p>
2339 * The calling device admin must have requested
2340 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2341 * not, a security exception will be thrown.
2342 * <p>
2343 * This method can be called on the {@link DevicePolicyManager} instance returned by
2344 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2345 * profile.
2346 *
2347 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2348 * @param length The new desired length of password history. A value of 0 means there is no
2349 * restriction.
2350 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2351 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
2352 */
Robin Lee25e26452015-06-02 09:56:29 -07002353 public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002354 if (mService != null) {
2355 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002356 mService.setPasswordHistoryLength(admin, length, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002357 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002358 throw e.rethrowFromSystemServer();
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002359 }
2360 }
2361 }
2362
2363 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002364 * Called by a device admin to set the password expiration timeout. Calling this method will
2365 * restart the countdown for password expiration for the given admin, as will changing the
2366 * device password (for all admins).
2367 * <p>
2368 * The provided timeout is the time delta in ms and will be added to the current time. For
2369 * example, to have the password expire 5 days from now, timeout would be 5 * 86400 * 1000 =
2370 * 432000000 ms for timeout.
2371 * <p>
2372 * To disable password expiration, a value of 0 may be used for timeout.
2373 * <p>
2374 * The calling device admin must have requested
2375 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this method; if it has
2376 * not, a security exception will be thrown.
2377 * <p>
2378 * Note that setting the password will automatically reset the expiration time for all active
2379 * admins. Active admins do not need to explicitly call this method in that case.
2380 * <p>
2381 * This method can be called on the {@link DevicePolicyManager} instance returned by
2382 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2383 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002384 *
Jim Millera4e28d12010-11-08 16:15:47 -08002385 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002386 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0 means
2387 * there is no restriction (unlimited).
2388 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2389 * does not use {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD}
Jim Millera4e28d12010-11-08 16:15:47 -08002390 */
Robin Lee25e26452015-06-02 09:56:29 -07002391 public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) {
Jim Millera4e28d12010-11-08 16:15:47 -08002392 if (mService != null) {
2393 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002394 mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08002395 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002396 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08002397 }
2398 }
2399 }
2400
2401 /**
Jim Miller6b857682011-02-16 16:27:41 -08002402 * Get the password expiration timeout for the given admin. The expiration timeout is the
2403 * recurring expiration timeout provided in the call to
2404 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
Esteban Talaverac1c83592016-02-17 17:56:15 +00002405 * aggregate of all participating policy administrators if {@code admin} is null. Admins that
2406 * have set restrictions on profiles that have a separate challenge are not taken into account.
2407 *
2408 * <p>This method can be called on the {@link DevicePolicyManager} instance
2409 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2410 * restrictions on the parent profile.
Jim Millera4e28d12010-11-08 16:15:47 -08002411 *
Robin Lee25e26452015-06-02 09:56:29 -07002412 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08002413 * @return The timeout for the given admin or the minimum of all timeouts
2414 */
Robin Lee25e26452015-06-02 09:56:29 -07002415 public long getPasswordExpirationTimeout(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08002416 if (mService != null) {
2417 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002418 return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08002419 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002420 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08002421 }
2422 }
2423 return 0;
2424 }
2425
2426 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002427 * Get the current password expiration time for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01002428 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00002429 * a separate challenge are not taken into account. If admin is {@code null}, then a composite
2430 * of all expiration times is returned - which will be the minimum of all of them.
2431 *
2432 * <p>This method can be called on the {@link DevicePolicyManager} instance
2433 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2434 * the password expiration for the parent profile.
Jim Millera4e28d12010-11-08 16:15:47 -08002435 *
Robin Lee25e26452015-06-02 09:56:29 -07002436 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002437 * @return The password expiration time, in milliseconds since epoch.
Jim Millera4e28d12010-11-08 16:15:47 -08002438 */
Robin Lee25e26452015-06-02 09:56:29 -07002439 public long getPasswordExpiration(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08002440 if (mService != null) {
2441 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002442 return mService.getPasswordExpiration(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08002443 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002444 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08002445 }
2446 }
2447 return 0;
2448 }
2449
2450 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002451 * Retrieve the current password history length for a particular admin or all admins that
Rubin Xud3609d42016-07-13 18:32:57 +01002452 * set restrictions on this user and its participating profiles. Restrictions on profiles that
Esteban Talaverac1c83592016-02-17 17:56:15 +00002453 * have a separate challenge are not taken into account.
2454 *
2455 * <p>This method can be called on the {@link DevicePolicyManager} instance
2456 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2457 * restrictions on the parent profile.
2458 *
Robin Lee25e26452015-06-02 09:56:29 -07002459 * @param admin The name of the admin component to check, or {@code null} to aggregate
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002460 * all admins.
2461 * @return The length of the password history
2462 */
Robin Lee25e26452015-06-02 09:56:29 -07002463 public int getPasswordHistoryLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002464 return getPasswordHistoryLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002465 }
2466
2467 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002468 public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002469 if (mService != null) {
2470 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002471 return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002472 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002473 throw e.rethrowFromSystemServer();
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002474 }
2475 }
2476 return 0;
2477 }
2478
Dianne Hackbornd6847842010-01-12 18:14:19 -08002479 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08002480 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08002481 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08002482 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08002483 * @return Returns the maximum length that the user can enter.
2484 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08002485 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08002486 // Kind-of arbitrary.
2487 return 16;
2488 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002489
Dianne Hackborn254cb442010-01-27 19:23:59 -08002490 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002491 * Determine whether the current password the user has set is sufficient to meet the policy
2492 * requirements (e.g. quality, minimum length) that have been requested by the admins of this
2493 * user and its participating profiles. Restrictions on profiles that have a separate challenge
Andrew Scull5daf2732016-11-14 15:02:45 +00002494 * are not taken into account. The user must be unlocked in order to perform the check.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002495 * <p>
2496 * The calling device admin must have requested
2497 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2498 * not, a security exception will be thrown.
2499 * <p>
2500 * This method can be called on the {@link DevicePolicyManager} instance returned by
2501 * {@link #getParentProfileInstance(ComponentName)} in order to determine if the password set on
2502 * the parent profile is sufficient.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002503 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01002504 * @return Returns true if the password meets the current requirements, else false.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002505 * @throws SecurityException if the calling application does not own an active administrator
2506 * that uses {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Andrew Scull5daf2732016-11-14 15:02:45 +00002507 * @throws InvalidStateException if the user is not unlocked.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002508 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002509 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002510 if (mService != null) {
2511 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00002512 return mService.isActivePasswordSufficient(myUserId(), mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002513 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002514 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002515 }
2516 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002517 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08002518 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002519
Dianne Hackbornd6847842010-01-12 18:14:19 -08002520 /**
Clara Bayarrid7693912016-01-22 17:26:31 +00002521 * Determine whether the current profile password the user has set is sufficient
Esteban Talaverac1c83592016-02-17 17:56:15 +00002522 * to meet the policy requirements (e.g. quality, minimum length) that have been
Clara Bayarrid7693912016-01-22 17:26:31 +00002523 * requested by the admins of the parent user and its profiles.
2524 *
2525 * @param userHandle the userId of the profile to check the password for.
2526 * @return Returns true if the password would meet the current requirements, else false.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002527 * @throws SecurityException if {@code userHandle} is not a managed profile.
Clara Bayarrid7693912016-01-22 17:26:31 +00002528 * @hide
2529 */
2530 public boolean isProfileActivePasswordSufficientForParent(int userHandle) {
2531 if (mService != null) {
2532 try {
2533 return mService.isProfileActivePasswordSufficientForParent(userHandle);
2534 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002535 throw e.rethrowFromSystemServer();
Clara Bayarrid7693912016-01-22 17:26:31 +00002536 }
2537 }
2538 return false;
2539 }
2540
2541 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002542 * Retrieve the number of times the user has failed at entering a password since that last
2543 * successful password entry.
2544 * <p>
2545 * This method can be called on the {@link DevicePolicyManager} instance returned by
2546 * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the number of failed
2547 * password attemts for the parent user.
2548 * <p>
2549 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN}
2550 * to be able to call this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002551 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002552 * @return The number of times user has entered an incorrect password since the last correct
2553 * password entry.
2554 * @throws SecurityException if the calling application does not own an active administrator
2555 * that uses {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002556 */
2557 public int getCurrentFailedPasswordAttempts() {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00002558 return getCurrentFailedPasswordAttempts(myUserId());
2559 }
2560
2561 /**
2562 * Retrieve the number of times the given user has failed at entering a
2563 * password since that last successful password entry.
2564 *
2565 * <p>The calling device admin must have requested
2566 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call this method; if it has
2567 * not and it is not the system uid, a security exception will be thrown.
2568 *
2569 * @hide
2570 */
2571 public int getCurrentFailedPasswordAttempts(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002572 if (mService != null) {
2573 try {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00002574 return mService.getCurrentFailedPasswordAttempts(userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002575 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002576 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002577 }
2578 }
2579 return -1;
2580 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002581
2582 /**
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002583 * Queries whether {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002584 *
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002585 * @return true if RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002586 * @hide
2587 */
2588 public boolean getDoNotAskCredentialsOnBoot() {
2589 if (mService != null) {
2590 try {
2591 return mService.getDoNotAskCredentialsOnBoot();
2592 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002593 throw e.rethrowFromSystemServer();
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002594 }
2595 }
2596 return false;
2597 }
2598
2599 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002600 * Setting this to a value greater than zero enables a built-in policy that will perform a
2601 * device or profile wipe after too many incorrect device-unlock passwords have been entered.
2602 * This built-in policy combines watching for failed passwords and wiping the device, and
2603 * requires that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002604 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002605 * <p>
2606 * To implement any other policy (e.g. wiping data for a particular application only, erasing or
2607 * revoking credentials, or reporting the failure to a server), you should implement
2608 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} instead. Do not
2609 * use this API, because if the maximum count is reached, the device or profile will be wiped
2610 * immediately, and your callback will not be invoked.
2611 * <p>
2612 * This method can be called on the {@link DevicePolicyManager} instance returned by
2613 * {@link #getParentProfileInstance(ComponentName)} in order to set a value on the parent
2614 * profile.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002615 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002616 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002617 * @param num The number of failed password attempts at which point the device or profile will
2618 * be wiped.
2619 * @throws SecurityException if {@code admin} is not an active administrator or does not use
2620 * both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
2621 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002622 */
Robin Lee25e26452015-06-02 09:56:29 -07002623 public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002624 if (mService != null) {
2625 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002626 mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002627 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002628 throw e.rethrowFromSystemServer();
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002629 }
2630 }
2631 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002632
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002633 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002634 * Retrieve the current maximum number of login attempts that are allowed before the device
Rubin Xud3609d42016-07-13 18:32:57 +01002635 * or profile is wiped, for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002636 * and its participating profiles. Restrictions on profiles that have a separate challenge are
2637 * not taken into account.
2638 *
2639 * <p>This method can be called on the {@link DevicePolicyManager} instance
2640 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2641 * the value for the parent profile.
2642 *
Robin Lee25e26452015-06-02 09:56:29 -07002643 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002644 * all admins.
2645 */
Robin Lee25e26452015-06-02 09:56:29 -07002646 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002647 return getMaximumFailedPasswordsForWipe(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002648 }
2649
2650 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002651 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08002652 if (mService != null) {
2653 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002654 return mService.getMaximumFailedPasswordsForWipe(
2655 admin, userHandle, mParentInstance);
Dianne Hackborn254cb442010-01-27 19:23:59 -08002656 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002657 throw e.rethrowFromSystemServer();
Dianne Hackborn254cb442010-01-27 19:23:59 -08002658 }
2659 }
2660 return 0;
2661 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002662
Dianne Hackborn254cb442010-01-27 19:23:59 -08002663 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002664 * Returns the profile with the smallest maximum failed passwords for wipe,
2665 * for the given user. So for primary user, it might return the primary or
2666 * a managed profile. For a secondary user, it would be the same as the
2667 * user passed in.
2668 * @hide Used only by Keyguard
2669 */
2670 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
2671 if (mService != null) {
2672 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002673 return mService.getProfileWithMinimumFailedPasswordsForWipe(
2674 userHandle, mParentInstance);
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002675 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002676 throw e.rethrowFromSystemServer();
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002677 }
2678 }
2679 return UserHandle.USER_NULL;
2680 }
2681
2682 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002683 * Flag for {@link #resetPassword}: don't allow other admins to change
2684 * the password again until the user has entered it.
2685 */
2686 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002687
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002688 /**
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002689 * Flag for {@link #resetPassword}: don't ask for user credentials on device boot.
2690 * If the flag is set, the device can be booted without asking for user password.
2691 * The absence of this flag does not change the current boot requirements. This flag
2692 * can be set by the device owner only. If the app is not the device owner, the flag
2693 * is ignored. Once the flag is set, it cannot be reverted back without resetting the
2694 * device to factory defaults.
2695 */
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002696 public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002;
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002697
2698 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002699 * Force a new device unlock password (the password needed to access the entire device, not for
2700 * individual accounts) on the user. This takes effect immediately.
2701 * <p>
Rubin Xuaab7a412016-12-30 21:13:29 +00002702 * <em>For device owner and profile owners targeting SDK level
2703 * {@link android.os.Build.VERSION_CODES#O} or above, this API is no longer available and will
2704 * throw {@link SecurityException}. Please use the new API {@link #resetPasswordWithToken}
2705 * instead. </em>
2706 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002707 * <em>Note: This API has been limited as of {@link android.os.Build.VERSION_CODES#N} for
Makoto Onuki70f929e2015-11-11 12:40:15 -08002708 * device admins that are not device owner and not profile owner.
2709 * The password can now only be changed if there is currently no password set. Device owner
Ricky Wai977ade22016-05-24 15:02:41 +01002710 * and profile owner can still do this when user is unlocked and does not have a managed
2711 * profile.</em>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002712 * <p>
2713 * The given password must be sufficient for the current password quality and length constraints
2714 * as returned by {@link #getPasswordQuality(ComponentName)} and
2715 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then
2716 * it will be rejected and false returned. Note that the password may be a stronger quality
2717 * (containing alphanumeric characters when the requested quality is only numeric), in which
2718 * case the currently active quality will be increased to match.
2719 * <p>
2720 * Calling with a null or empty password will clear any existing PIN, pattern or password if the
Robin Leece5c4002016-03-23 17:05:03 +00002721 * current password constraints allow it. <em>Note: This will not work in
2722 * {@link android.os.Build.VERSION_CODES#N} and later for managed profiles, or for device admins
2723 * that are not device owner or profile owner. Once set, the password cannot be changed to null
2724 * or empty except by these admins.</em>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002725 * <p>
2726 * The calling device admin must have requested
2727 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call this method; if it has
2728 * not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002729 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01002730 * @param password The new password for the user. Null or empty clears the password.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002731 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002732 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
2733 * @return Returns true if the password was applied, or false if it is not acceptable for the
2734 * current constraints or if the user has not been decrypted yet.
2735 * @throws SecurityException if the calling application does not own an active administrator
2736 * that uses {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD}
Ricky Wai977ade22016-05-24 15:02:41 +01002737 * @throws IllegalStateException if the calling user is locked or has a managed profile.
Andrew Scull3f81f4e2016-07-29 16:29:58 +01002738 * @throws IllegalArgumentException if the password does not meet system requirements.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002739 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002740 public boolean resetPassword(String password, int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002741 throwIfParentInstance("resetPassword");
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002742 if (mService != null) {
2743 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002744 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002745 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002746 throw e.rethrowFromSystemServer();
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002747 }
2748 }
2749 return false;
2750 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002751
Dianne Hackbornd6847842010-01-12 18:14:19 -08002752 /**
Rubin Xuaab7a412016-12-30 21:13:29 +00002753 * Called by a profile or device owner to provision a token which can later be used to reset the
2754 * device lockscreen password (if called by device owner), or work challenge (if called by
2755 * profile owner), via {@link #resetPasswordWithToken}.
2756 * <p>
2757 * If the user currently has a lockscreen password, the provisioned token will not be
2758 * immediately usable; it only becomes active after the user performs a confirm credential
2759 * operation, which can be triggered by {@link KeyguardManager#createConfirmDeviceCredentialIntent}.
2760 * If the user has no lockscreen password, the token is activated immediately. In all cases,
2761 * the active state of the current token can be checked by {@link #isResetPasswordTokenActive}.
2762 * For security reasons, un-activated tokens are only stored in memory and will be lost once
2763 * the device reboots. In this case a new token needs to be provisioned again.
2764 * <p>
2765 * Once provisioned and activated, the token will remain effective even if the user changes
2766 * or clears the lockscreen password.
2767 * <p>
2768 * <em>This token is highly sensitive and should be treated at the same level as user
2769 * credentials. In particular, NEVER store this token on device in plaintext, especially in
2770 * Device-Encrypted storage if the token will be used to reset password on FBE devices before
2771 * user unlocks.
2772 * </em>
2773 *
2774 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2775 * @param token a secure token a least 32-byte long, which must be generated by a
2776 * cryptographically strong random number generator.
2777 * @return true if the operation is successful, false otherwise.
2778 * @throws IllegalArgumentException if the supplied token is invalid.
2779 * @throws SecurityException
2780 */
2781 public boolean setResetPasswordToken(ComponentName admin, byte[] token) {
2782 throwIfParentInstance("setResetPasswordToken");
2783 if (mService != null) {
2784 try {
2785 return mService.setResetPasswordToken(admin, token);
2786 } catch (RemoteException e) {
2787 throw e.rethrowFromSystemServer();
2788 }
2789 }
2790 return false;
2791 }
2792
2793 /**
2794 * Called by a profile or device owner to revoke the current password reset token.
2795 *
2796 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2797 * @return true if the operation is successful, false otherwise.
2798 */
2799 public boolean clearResetPasswordToken(ComponentName admin) {
2800 throwIfParentInstance("clearResetPasswordToken");
2801 if (mService != null) {
2802 try {
2803 return mService.clearResetPasswordToken(admin);
2804 } catch (RemoteException e) {
2805 throw e.rethrowFromSystemServer();
2806 }
2807 }
2808 return false;
2809 }
2810
2811 /**
2812 * Called by a profile or device owner to check if the current reset password token is active.
2813 *
2814 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2815 * @return true if the token is active, false otherwise.
2816 * @throws IllegalStateException if no token has been set.
2817 */
2818 public boolean isResetPasswordTokenActive(ComponentName admin) {
2819 throwIfParentInstance("isResetPasswordTokenActive");
2820 if (mService != null) {
2821 try {
2822 return mService.isResetPasswordTokenActive(admin);
2823 } catch (RemoteException e) {
2824 throw e.rethrowFromSystemServer();
2825 }
2826 }
2827 return false;
2828 }
2829
2830 /**
2831 * Called by device or profile owner to force set a new device unlock password or a work profile
2832 * challenge on current user. This takes effect immediately.
2833 * <p>
2834 * Unlike {@link #resetPassword}, this API can change the password even before the user or
2835 * device is unlocked or decrypted. The supplied token must have been previously provisioned via
2836 * {@link #setResetPasswordToken}, and in active state {@link #isResetPasswordTokenActive}.
2837 * <p>
2838 * The given password must be sufficient for the current password quality and length constraints
2839 * as returned by {@link #getPasswordQuality(ComponentName)} and
2840 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then
2841 * it will be rejected and false returned. Note that the password may be a stronger quality
2842 * (containing alphanumeric characters when the requested quality is only numeric), in which
2843 * case the currently active quality will be increased to match.
2844 * <p>
2845 * Calling with a null or empty password will clear any existing PIN, pattern or password if the
2846 * current password constraints allow it.
2847 *
2848 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2849 * @param password The new password for the user. Null or empty clears the password.
2850 * @param token the password reset token previously provisioned by #setResetPasswordToken.
2851 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
2852 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
2853 * @return Returns true if the password was applied, or false if it is not acceptable for the
2854 * current constraints.
2855 * @throws SecurityException if the calling application does not own an active administrator
2856 * that uses {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD}
2857 * @throws IllegalStateException if the provided token is not valid.
2858 * @throws IllegalArgumentException if the password does not meet system requirements.
2859 */
2860 public boolean resetPasswordWithToken(@NonNull ComponentName admin, String password,
2861 byte[] token, int flags) {
2862 throwIfParentInstance("resetPassword");
2863 if (mService != null) {
2864 try {
2865 return mService.resetPasswordWithToken(admin, password, token, flags);
2866 } catch (RemoteException e) {
2867 throw e.rethrowFromSystemServer();
2868 }
2869 }
2870 return false;
2871 }
2872
2873 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002874 * Called by an application that is administering the device to set the maximum time for user
2875 * activity until the device will lock. This limits the length that the user can set. It takes
2876 * effect immediately.
2877 * <p>
2878 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
2879 * to be able to call this method; if it has not, a security exception will be thrown.
2880 * <p>
2881 * This method can be called on the {@link DevicePolicyManager} instance returned by
2882 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2883 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002884 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002885 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002886 * @param timeMs The new desired maximum time to lock in milliseconds. A value of 0 means there
2887 * is no restriction.
2888 * @throws SecurityException if {@code admin} is not an active administrator or it does not use
2889 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002890 */
Robin Lee25e26452015-06-02 09:56:29 -07002891 public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002892 if (mService != null) {
2893 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002894 mService.setMaximumTimeToLock(admin, timeMs, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002895 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002896 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002897 }
2898 }
2899 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002900
Dianne Hackbornd6847842010-01-12 18:14:19 -08002901 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002902 * Retrieve the current maximum time to unlock for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01002903 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00002904 * a separate challenge are not taken into account.
2905 *
2906 * <p>This method can be called on the {@link DevicePolicyManager} instance
2907 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2908 * restrictions on the parent profile.
2909 *
Robin Lee25e26452015-06-02 09:56:29 -07002910 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002911 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07002912 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07002913 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002914 */
Robin Lee25e26452015-06-02 09:56:29 -07002915 public long getMaximumTimeToLock(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002916 return getMaximumTimeToLock(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002917 }
2918
2919 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002920 public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002921 if (mService != null) {
2922 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002923 return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002924 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002925 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002926 }
2927 }
2928 return 0;
2929 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002930
Dianne Hackbornd6847842010-01-12 18:14:19 -08002931 /**
Ricky Wai035e9242016-03-18 16:43:31 +00002932 * Returns maximum time to lock that applied by all profiles in this user. We do this because we
2933 * do not have a separate timeout to lock for work challenge only.
2934 *
2935 * @hide
2936 */
2937 public long getMaximumTimeToLockForUserAndProfiles(int userHandle) {
2938 if (mService != null) {
2939 try {
2940 return mService.getMaximumTimeToLockForUserAndProfiles(userHandle);
2941 } catch (RemoteException e) {
2942 throw e.rethrowFromSystemServer();
2943 }
2944 }
2945 return 0;
2946 }
2947
2948 /**
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002949 * Called by a device/profile owner to set the timeout after which unlocking with secondary, non
2950 * strong auth (e.g. fingerprint, trust agents) times out, i.e. the user has to use a strong
2951 * authentication method like password, pin or pattern.
2952 *
2953 * <p>This timeout is used internally to reset the timer to require strong auth again after
2954 * specified timeout each time it has been successfully used.
2955 *
2956 * <p>Fingerprint can also be disabled altogether using {@link #KEYGUARD_DISABLE_FINGERPRINT}.
2957 *
2958 * <p>Trust agents can also be disabled altogether using {@link #KEYGUARD_DISABLE_TRUST_AGENTS}.
2959 *
2960 * <p>The calling device admin must be a device or profile owner. If it is not,
2961 * a {@link SecurityException} will be thrown.
2962 *
Michal Karpinski943aabd2016-10-06 11:09:25 +01002963 * <p>The calling device admin can verify the value it has set by calling
2964 * {@link #getRequiredStrongAuthTimeout(ComponentName)} and passing in its instance.
2965 *
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002966 * <p>This method can be called on the {@link DevicePolicyManager} instance returned by
2967 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2968 * profile.
2969 *
2970 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2971 * @param timeoutMs The new timeout, after which the user will have to unlock with strong
Michal Karpinski943aabd2016-10-06 11:09:25 +01002972 * authentication method. A value of 0 means the admin is not participating in
2973 * controlling the timeout.
2974 * The minimum and maximum timeouts are platform-defined and are typically 1 hour and
2975 * 72 hours, respectively. Though discouraged, the admin may choose to require strong
2976 * auth at all times using {@link #KEYGUARD_DISABLE_FINGERPRINT} and/or
2977 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002978 *
2979 * @throws SecurityException if {@code admin} is not a device or profile owner.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002980 */
2981 public void setRequiredStrongAuthTimeout(@NonNull ComponentName admin,
2982 long timeoutMs) {
2983 if (mService != null) {
2984 try {
2985 mService.setRequiredStrongAuthTimeout(admin, timeoutMs, mParentInstance);
2986 } catch (RemoteException e) {
2987 throw e.rethrowFromSystemServer();
2988 }
2989 }
2990 }
2991
2992 /**
2993 * Determine for how long the user will be able to use secondary, non strong auth for
2994 * authentication, since last strong method authentication (password, pin or pattern) was used.
2995 * After the returned timeout the user is required to use strong authentication method.
2996 *
2997 * <p>This method can be called on the {@link DevicePolicyManager} instance
2998 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2999 * restrictions on the parent profile.
3000 *
3001 * @param admin The name of the admin component to check, or {@code null} to aggregate
3002 * accross all participating admins.
Michal Karpinski943aabd2016-10-06 11:09:25 +01003003 * @return The timeout or 0 if not configured for the provided admin.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01003004 */
3005 public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin) {
3006 return getRequiredStrongAuthTimeout(admin, myUserId());
3007 }
3008
3009 /** @hide per-user version */
3010 public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin, @UserIdInt int userId) {
3011 if (mService != null) {
3012 try {
3013 return mService.getRequiredStrongAuthTimeout(admin, userId, mParentInstance);
3014 } catch (RemoteException e) {
3015 throw e.rethrowFromSystemServer();
3016 }
3017 }
3018 return DEFAULT_STRONG_AUTH_TIMEOUT_MS;
3019 }
3020
3021 /**
Andrew Scull85a63bc2016-10-24 13:47:47 +01003022 * Flag for {@link #lockNow(int)}: also evict the user's credential encryption key from the
3023 * keyring. The user's credential will need to be entered again in order to derive the
3024 * credential encryption key that will be stored back in the keyring for future use.
3025 * <p>
3026 * This flag can only be used by a profile owner when locking a managed profile on an FBE
3027 * device.
3028 * <p>
3029 * In order to secure user data, the user will be stopped and restarted so apps should wait
3030 * until they are next run to perform further actions.
3031 */
3032 public static final int FLAG_EVICT_CE_KEY = 1;
3033
3034 /** @hide */
3035 @Retention(RetentionPolicy.SOURCE)
3036 @IntDef(flag=true, value={FLAG_EVICT_CE_KEY})
3037 public @interface LockNowFlag {}
3038
3039 /**
3040 * Make the device lock immediately, as if the lock screen timeout has expired at the point of
3041 * this call.
3042 * <p>
3043 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
3044 * to be able to call this method; if it has not, a security exception will be thrown.
3045 * <p>
3046 * This method can be called on the {@link DevicePolicyManager} instance returned by
3047 * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile.
3048 * <p>
3049 * Equivalent to calling {@link #lockNow(int)} with no flags.
3050 *
3051 * @throws SecurityException if the calling application does not own an active administrator
3052 * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
3053 */
3054 public void lockNow() {
3055 lockNow(0);
3056 }
3057
3058 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003059 * Make the device lock immediately, as if the lock screen timeout has expired at the point of
3060 * this call.
3061 * <p>
3062 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
3063 * to be able to call this method; if it has not, a security exception will be thrown.
3064 * <p>
3065 * This method can be called on the {@link DevicePolicyManager} instance returned by
3066 * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003067 *
Andrew Scull85a63bc2016-10-24 13:47:47 +01003068 * @param flags May be 0 or {@link #FLAG_EVICT_CE_KEY}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003069 * @throws SecurityException if the calling application does not own an active administrator
Andrew Scull85a63bc2016-10-24 13:47:47 +01003070 * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} or the
3071 * {@link #FLAG_EVICT_CE_KEY} flag is passed by an application that is not a profile
3072 * owner of a managed profile.
3073 * @throws IllegalArgumentException if the {@link #FLAG_EVICT_CE_KEY} flag is passed when
3074 * locking the parent profile.
3075 * @throws UnsupportedOperationException if the {@link #FLAG_EVICT_CE_KEY} flag is passed on a
3076 * non-FBE device.
Dianne Hackbornd6847842010-01-12 18:14:19 -08003077 */
Andrew Scull85a63bc2016-10-24 13:47:47 +01003078 public void lockNow(@LockNowFlag int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -08003079 if (mService != null) {
3080 try {
Andrew Scull85a63bc2016-10-24 13:47:47 +01003081 mService.lockNow(flags, mParentInstance);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08003082 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003083 throw e.rethrowFromSystemServer();
Dianne Hackborndf83afa2010-01-20 13:37:26 -08003084 }
3085 }
3086 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003087
Dianne Hackbornd6847842010-01-12 18:14:19 -08003088 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07003089 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00003090 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07003091 */
3092 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
3093
3094 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00003095 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
3096 * data.
3097 *
Paul Crowley2934b262014-12-02 11:21:13 +00003098 * <p>This flag may only be set by device owner admins; if it is set by
3099 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00003100 */
3101 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
3102
3103 /**
Suprabh Shukla556b05a2016-08-10 15:49:24 -07003104 * Ask that all user data be wiped. If called as a secondary user, the user will be removed and
3105 * other users will remain unaffected. Calling from the primary user will cause the device to
3106 * reboot, erasing all device data - including all the secondary users and their data - while
3107 * booting up.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003108 * <p>
3109 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to
3110 * be able to call this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003111 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003112 * @param flags Bit mask of additional options: currently supported flags are
3113 * {@link #WIPE_EXTERNAL_STORAGE} and {@link #WIPE_RESET_PROTECTION_DATA}.
3114 * @throws SecurityException if the calling application does not own an active administrator
3115 * that uses {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}
Dianne Hackbornd6847842010-01-12 18:14:19 -08003116 */
3117 public void wipeData(int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003118 throwIfParentInstance("wipeData");
Dianne Hackbornd6847842010-01-12 18:14:19 -08003119 if (mService != null) {
3120 try {
Makoto Onuki70f929e2015-11-11 12:40:15 -08003121 mService.wipeData(flags);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003122 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003123 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003124 }
3125 }
3126 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003127
Dianne Hackbornd6847842010-01-12 18:14:19 -08003128 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07003129 * Called by an application that is administering the device to set the
3130 * global proxy and exclusion list.
3131 * <p>
3132 * The calling device admin must have requested
3133 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
3134 * this method; if it has not, a security exception will be thrown.
3135 * Only the first device admin can set the proxy. If a second admin attempts
3136 * to set the proxy, the {@link ComponentName} of the admin originally setting the
Robin Lee25e26452015-06-02 09:56:29 -07003137 * proxy will be returned. If successful in setting the proxy, {@code null} will
Oscar Montemayor69238c62010-08-03 10:51:06 -07003138 * be returned.
3139 * The method can be called repeatedly by the device admin alrady setting the
3140 * proxy to update the proxy and exclusion list.
3141 *
Robin Lee25e26452015-06-02 09:56:29 -07003142 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Oscar Montemayor69238c62010-08-03 10:51:06 -07003143 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
3144 * Pass Proxy.NO_PROXY to reset the proxy.
3145 * @param exclusionList a list of domains to be excluded from the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07003146 * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName}
3147 * of the device admin that sets the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08003148 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07003149 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003150 public @Nullable ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec,
Oscar Montemayor69238c62010-08-03 10:51:06 -07003151 List<String> exclusionList ) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003152 throwIfParentInstance("setGlobalProxy");
Oscar Montemayor69238c62010-08-03 10:51:06 -07003153 if (proxySpec == null) {
3154 throw new NullPointerException();
3155 }
3156 if (mService != null) {
3157 try {
3158 String hostSpec;
3159 String exclSpec;
3160 if (proxySpec.equals(Proxy.NO_PROXY)) {
3161 hostSpec = null;
3162 exclSpec = null;
3163 } else {
3164 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
3165 throw new IllegalArgumentException();
3166 }
3167 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
3168 String hostName = sa.getHostName();
3169 int port = sa.getPort();
3170 StringBuilder hostBuilder = new StringBuilder();
3171 hostSpec = hostBuilder.append(hostName)
3172 .append(":").append(Integer.toString(port)).toString();
3173 if (exclusionList == null) {
3174 exclSpec = "";
3175 } else {
3176 StringBuilder listBuilder = new StringBuilder();
3177 boolean firstDomain = true;
3178 for (String exclDomain : exclusionList) {
3179 if (!firstDomain) {
3180 listBuilder = listBuilder.append(",");
3181 } else {
3182 firstDomain = false;
3183 }
3184 listBuilder = listBuilder.append(exclDomain.trim());
3185 }
3186 exclSpec = listBuilder.toString();
3187 }
Yuhao Zheng90704842014-02-28 17:22:45 -08003188 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
3189 != android.net.Proxy.PROXY_VALID)
3190 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07003191 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003192 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07003193 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003194 throw e.rethrowFromSystemServer();
Oscar Montemayor69238c62010-08-03 10:51:06 -07003195 }
3196 }
3197 return null;
3198 }
3199
3200 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003201 * Set a network-independent global HTTP proxy. This is not normally what you want for typical
3202 * HTTP proxies - they are generally network dependent. However if you're doing something
3203 * unusual like general internal filtering this may be useful. On a private network where the
3204 * proxy is not accessible, you may break HTTP using this.
3205 * <p>
3206 * This method requires the caller to be the device owner.
3207 * <p>
3208 * This proxy is only a recommendation and it is possible that some apps will ignore it.
Jason Monk03bc9912014-05-13 09:44:57 -04003209 *
Jason Monk03bc9912014-05-13 09:44:57 -04003210 * @see ProxyInfo
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003211 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3212 * @param proxyInfo The a {@link ProxyInfo} object defining the new global HTTP proxy. A
3213 * {@code null} value will clear the global HTTP proxy.
3214 * @throws SecurityException if {@code admin} is not the device owner.
Jason Monk03bc9912014-05-13 09:44:57 -04003215 */
Robin Lee25e26452015-06-02 09:56:29 -07003216 public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo
3217 proxyInfo) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003218 throwIfParentInstance("setRecommendedGlobalProxy");
Jason Monk03bc9912014-05-13 09:44:57 -04003219 if (mService != null) {
3220 try {
3221 mService.setRecommendedGlobalProxy(admin, proxyInfo);
3222 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003223 throw e.rethrowFromSystemServer();
Jason Monk03bc9912014-05-13 09:44:57 -04003224 }
3225 }
3226 }
3227
3228 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07003229 * Returns the component name setting the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07003230 * @return ComponentName object of the device admin that set the global proxy, or {@code null}
3231 * if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08003232 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07003233 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003234 public @Nullable ComponentName getGlobalProxyAdmin() {
Oscar Montemayor69238c62010-08-03 10:51:06 -07003235 if (mService != null) {
3236 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003237 return mService.getGlobalProxyAdmin(myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07003238 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003239 throw e.rethrowFromSystemServer();
Oscar Montemayor69238c62010-08-03 10:51:06 -07003240 }
3241 }
3242 return null;
3243 }
3244
3245 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08003246 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003247 * indicating that encryption is not supported.
3248 */
3249 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
3250
3251 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08003252 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003253 * indicating that encryption is supported, but is not currently active.
3254 */
3255 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
3256
3257 /**
Robin Lee3795fb02015-02-16 14:17:23 +00003258 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003259 * indicating that encryption is not currently active, but is currently
3260 * being activated. This is only reported by devices that support
3261 * encryption of data and only when the storage is currently
3262 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
3263 * to become encrypted will never return this value.
3264 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08003265 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003266
3267 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08003268 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003269 * indicating that encryption is active.
Amith Yamasani75db1252016-07-11 14:41:01 -07003270 * <p>
3271 * Also see {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003272 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08003273 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003274
3275 /**
Robin Lee3795fb02015-02-16 14:17:23 +00003276 * Result code for {@link #getStorageEncryptionStatus}:
3277 * indicating that encryption is active, but an encryption key has not
3278 * been set by the user.
3279 */
3280 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
3281
3282 /**
Makoto Onukid4c9e542016-02-25 18:17:30 -08003283 * Result code for {@link #getStorageEncryptionStatus}:
Amith Yamasani75db1252016-07-11 14:41:01 -07003284 * indicating that encryption is active and the encryption key is tied to the user or profile.
3285 * <p>
3286 * This value is only returned to apps targeting API level 24 and above. For apps targeting
3287 * earlier API levels, {@link #ENCRYPTION_STATUS_ACTIVE} is returned, even if the
3288 * encryption key is specific to the user or profile.
Makoto Onukid4c9e542016-02-25 18:17:30 -08003289 */
3290 public static final int ENCRYPTION_STATUS_ACTIVE_PER_USER = 5;
3291
3292 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003293 * Activity action: begin the process of encrypting data on the device. This activity should
3294 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
3295 * After resuming from this activity, use {@link #getStorageEncryption}
3296 * to check encryption status. However, on some devices this activity may never return, as
3297 * it may trigger a reboot and in some cases a complete data wipe of the device.
3298 */
3299 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
3300 public static final String ACTION_START_ENCRYPTION
3301 = "android.app.action.START_ENCRYPTION";
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003302 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07003303 * Widgets are enabled in keyguard
3304 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07003305 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07003306
3307 /**
Jim Miller50e62182014-04-23 17:25:00 -07003308 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07003309 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07003310 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
3311
3312 /**
3313 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
3314 */
3315 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
3316
3317 /**
Jim Miller50e62182014-04-23 17:25:00 -07003318 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
3319 */
3320 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
3321
3322 /**
3323 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
3324 */
3325 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
3326
3327 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02003328 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07003329 * (e.g. PIN/Pattern/Password).
3330 */
3331 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
3332
3333 /**
Jim Miller06e34502014-07-17 14:46:05 -07003334 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
3335 */
3336 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
3337
3338 /**
Adrian Roos7f06eed2016-02-05 15:21:02 -08003339 * Disable text entry into notifications on secure keyguard screens (e.g. PIN/Pattern/Password).
3340 */
3341 public static final int KEYGUARD_DISABLE_REMOTE_INPUT = 1 << 6;
3342
3343 /**
Jim Miller35207742012-11-02 15:33:20 -07003344 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07003345 */
3346 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07003347
3348 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003349 * Called by an application that is administering the device to request that the storage system
3350 * be encrypted.
3351 * <p>
3352 * When multiple device administrators attempt to control device encryption, the most secure,
3353 * supported setting will always be used. If any device administrator requests device
3354 * encryption, it will be enabled; Conversely, if a device administrator attempts to disable
3355 * device encryption while another device administrator has enabled it, the call to disable will
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003356 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003357 * <p>
3358 * This policy controls encryption of the secure (application data) storage area. Data written
3359 * to other storage areas may or may not be encrypted, and this policy does not require or
3360 * control the encryption of any other storage areas. There is one exception: If
3361 * {@link android.os.Environment#isExternalStorageEmulated()} is {@code true}, then the
3362 * directory returned by {@link android.os.Environment#getExternalStorageDirectory()} must be
3363 * written to disk within the encrypted storage area.
3364 * <p>
3365 * Important Note: On some devices, it is possible to encrypt storage without requiring the user
3366 * to create a device PIN or Password. In this case, the storage is encrypted, but the
3367 * encryption key may not be fully secured. For maximum security, the administrator should also
3368 * require (and check for) a pattern, PIN, or password.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003369 *
3370 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3371 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08003372 * @return the new request status (for all active admins) - will be one of
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003373 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
3374 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
3375 * {@link #getStorageEncryptionStatus()} to query the actual device state.
3376 * @throws SecurityException if {@code admin} is not an active administrator or does not use
3377 * {@link DeviceAdminInfo#USES_ENCRYPTED_STORAGE}
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003378 */
Robin Lee25e26452015-06-02 09:56:29 -07003379 public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003380 throwIfParentInstance("setStorageEncryption");
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003381 if (mService != null) {
3382 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003383 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003384 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003385 throw e.rethrowFromSystemServer();
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003386 }
3387 }
3388 return ENCRYPTION_STATUS_UNSUPPORTED;
3389 }
3390
3391 /**
3392 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08003393 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003394 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08003395 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
3396 * this will return the requested encryption setting as an aggregate of all active
3397 * administrators.
3398 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003399 */
Robin Lee25e26452015-06-02 09:56:29 -07003400 public boolean getStorageEncryption(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003401 throwIfParentInstance("getStorageEncryption");
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003402 if (mService != null) {
3403 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003404 return mService.getStorageEncryption(admin, myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003405 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003406 throw e.rethrowFromSystemServer();
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003407 }
3408 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08003409 return false;
3410 }
3411
3412 /**
3413 * Called by an application that is administering the device to
3414 * determine the current encryption status of the device.
Amith Yamasani75db1252016-07-11 14:41:01 -07003415 * <p>
Andy Stadler22dbfda2011-01-17 12:47:31 -08003416 * Depending on the returned status code, the caller may proceed in different
3417 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
3418 * storage system does not support encryption. If the
3419 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
3420 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00003421 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
3422 * storage system has enabled encryption but no password is set so further action
Amith Yamasani75db1252016-07-11 14:41:01 -07003423 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING},
3424 * {@link #ENCRYPTION_STATUS_ACTIVE} or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER},
3425 * no further action is required.
Andy Stadler22dbfda2011-01-17 12:47:31 -08003426 *
Robin Lee7e678712014-07-24 16:41:31 +01003427 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08003428 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00003429 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
Amith Yamasani75db1252016-07-11 14:41:01 -07003430 * {@link #ENCRYPTION_STATUS_ACTIVE}, or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08003431 */
3432 public int getStorageEncryptionStatus() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003433 throwIfParentInstance("getStorageEncryptionStatus");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003434 return getStorageEncryptionStatus(myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003435 }
3436
3437 /** @hide per-user version */
3438 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08003439 if (mService != null) {
3440 try {
Makoto Onukid4c9e542016-02-25 18:17:30 -08003441 return mService.getStorageEncryptionStatus(mContext.getPackageName(), userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08003442 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003443 throw e.rethrowFromSystemServer();
Andy Stadler22dbfda2011-01-17 12:47:31 -08003444 }
3445 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003446 return ENCRYPTION_STATUS_UNSUPPORTED;
3447 }
3448
3449 /**
Robin Lee2f7e1e42016-03-21 10:50:01 +00003450 * Mark a CA certificate as approved by the device user. This means that they have been notified
3451 * of the installation, were made aware of the risks, viewed the certificate and still wanted to
3452 * keep the certificate on the device.
3453 *
3454 * Calling with {@param approval} as {@code true} will cancel any ongoing warnings related to
3455 * this certificate.
3456 *
3457 * @hide
3458 */
3459 public boolean approveCaCert(String alias, int userHandle, boolean approval) {
3460 if (mService != null) {
3461 try {
3462 return mService.approveCaCert(alias, userHandle, approval);
3463 } catch (RemoteException e) {
3464 throw e.rethrowFromSystemServer();
3465 }
3466 }
3467 return false;
3468 }
3469
3470 /**
3471 * Check whether a CA certificate has been approved by the device user.
3472 *
3473 * @hide
3474 */
3475 public boolean isCaCertApproved(String alias, int userHandle) {
3476 if (mService != null) {
3477 try {
3478 return mService.isCaCertApproved(alias, userHandle);
3479 } catch (RemoteException e) {
3480 throw e.rethrowFromSystemServer();
3481 }
3482 }
3483 return false;
3484 }
3485
3486 /**
Robin Lee7e678712014-07-24 16:41:31 +01003487 * Installs the given certificate as a user CA.
3488 *
Edman Anjosf9946772016-11-28 16:35:15 +01003489 * The caller must be a profile or device owner on that user, or a delegate package given the
3490 * {@link #DELEGATION_CERT_INSTALL} scope via {@link #setDelegatedScopes}; otherwise a
3491 * security exception will be thrown.
3492 *
Robin Lee25e26452015-06-02 09:56:29 -07003493 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3494 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003495 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04003496 *
3497 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01003498 * interrupted, true otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003499 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3500 * owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003501 * @see #setDelegatedScopes
3502 * @see #DELEGATION_CERT_INSTALL
Maggie Benthallda51e682013-08-08 22:35:44 -04003503 */
Robin Lee25e26452015-06-02 09:56:29 -07003504 public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003505 throwIfParentInstance("installCaCert");
Maggie Benthallda51e682013-08-08 22:35:44 -04003506 if (mService != null) {
3507 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003508 return mService.installCaCert(admin, mContext.getPackageName(), certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04003509 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003510 throw e.rethrowFromSystemServer();
Maggie Benthallda51e682013-08-08 22:35:44 -04003511 }
3512 }
3513 return false;
3514 }
3515
3516 /**
Robin Lee7e678712014-07-24 16:41:31 +01003517 * Uninstalls the given certificate from trusted user CAs, if present.
3518 *
Edman Anjosf9946772016-11-28 16:35:15 +01003519 * The caller must be a profile or device owner on that user, or a delegate package given the
3520 * {@link #DELEGATION_CERT_INSTALL} scope via {@link #setDelegatedScopes}; otherwise a
3521 * security exception will be thrown.
3522 *
Robin Lee25e26452015-06-02 09:56:29 -07003523 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3524 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003525 * @param certBuffer encoded form of the certificate to remove.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003526 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3527 * owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003528 * @see #setDelegatedScopes
3529 * @see #DELEGATION_CERT_INSTALL
Maggie Benthallda51e682013-08-08 22:35:44 -04003530 */
Robin Lee25e26452015-06-02 09:56:29 -07003531 public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003532 throwIfParentInstance("uninstallCaCert");
Maggie Benthallda51e682013-08-08 22:35:44 -04003533 if (mService != null) {
3534 try {
Robin Lee306fe082014-06-19 14:04:24 +00003535 final String alias = getCaCertAlias(certBuffer);
Edman Anjosf9946772016-11-28 16:35:15 +01003536 mService.uninstallCaCerts(admin, mContext.getPackageName(), new String[] {alias});
Robin Lee306fe082014-06-19 14:04:24 +00003537 } catch (CertificateException e) {
3538 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04003539 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003540 throw e.rethrowFromSystemServer();
Maggie Benthallda51e682013-08-08 22:35:44 -04003541 }
3542 }
3543 }
3544
3545 /**
Robin Lee7e678712014-07-24 16:41:31 +01003546 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
3547 * If a user has installed any certificates by other means than device policy these will be
3548 * included too.
3549 *
Robin Lee25e26452015-06-02 09:56:29 -07003550 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3551 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003552 * @return a List of byte[] arrays, each encoding one user CA certificate.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003553 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3554 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04003555 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003556 public @NonNull List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) {
3557 final List<byte[]> certs = new ArrayList<byte[]>();
Benjamin Franzbc33c822016-04-15 08:57:52 +01003558 throwIfParentInstance("getInstalledCaCerts");
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003559 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01003560 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003561 mService.enforceCanManageCaCerts(admin, mContext.getPackageName());
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003562 final TrustedCertificateStore certStore = new TrustedCertificateStore();
3563 for (String alias : certStore.userAliases()) {
3564 try {
3565 certs.add(certStore.getCertificate(alias).getEncoded());
3566 } catch (CertificateException ce) {
3567 Log.w(TAG, "Could not encode certificate: " + alias, ce);
3568 }
3569 }
3570 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003571 throw re.rethrowFromSystemServer();
Robin Lee7e678712014-07-24 16:41:31 +01003572 }
3573 }
3574 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04003575 }
3576
3577 /**
Robin Lee7e678712014-07-24 16:41:31 +01003578 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
3579 * means other than device policy will also be removed, except for system CA certificates.
3580 *
Robin Lee25e26452015-06-02 09:56:29 -07003581 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3582 * {@code null} if calling from a delegated certificate installer.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003583 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3584 * owner.
Robin Lee7e678712014-07-24 16:41:31 +01003585 */
Robin Lee25e26452015-06-02 09:56:29 -07003586 public void uninstallAllUserCaCerts(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003587 throwIfParentInstance("uninstallAllUserCaCerts");
Robin Lee7e678712014-07-24 16:41:31 +01003588 if (mService != null) {
Robin Lee83881bd2015-06-09 16:04:38 -07003589 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003590 mService.uninstallCaCerts(admin, mContext.getPackageName(),
3591 new TrustedCertificateStore().userAliases() .toArray(new String[0]));
Robin Lee83881bd2015-06-09 16:04:38 -07003592 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003593 throw re.rethrowFromSystemServer();
Robin Lee7e678712014-07-24 16:41:31 +01003594 }
3595 }
3596 }
3597
3598 /**
3599 * Returns whether this certificate is installed as a trusted CA.
3600 *
Robin Lee25e26452015-06-02 09:56:29 -07003601 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3602 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003603 * @param certBuffer encoded form of the certificate to look up.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003604 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3605 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04003606 */
Robin Lee25e26452015-06-02 09:56:29 -07003607 public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003608 throwIfParentInstance("hasCaCertInstalled");
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003609 if (mService != null) {
3610 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003611 mService.enforceCanManageCaCerts(admin, mContext.getPackageName());
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003612 return getCaCertAlias(certBuffer) != null;
3613 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003614 throw re.rethrowFromSystemServer();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003615 } catch (CertificateException ce) {
3616 Log.w(TAG, "Could not parse certificate", ce);
3617 }
Maggie Benthallda51e682013-08-08 22:35:44 -04003618 }
3619 return false;
3620 }
3621
3622 /**
Robin Leece3399f2016-02-24 12:08:32 +00003623 * Called by a device or profile owner, or delegated certificate installer, to install a
3624 * certificate and corresponding private key. All apps within the profile will be able to access
3625 * the certificate and use the private key, given direct user approval.
3626 *
3627 * <p>Access to the installed credentials will not be granted to the caller of this API without
3628 * direct user approval. This is for security - should a certificate installer become
3629 * compromised, certificates it had already installed will be protected.
3630 *
3631 * <p>If the installer must have access to the credentials, call
Rubin Xub4365912016-03-23 12:13:22 +00003632 * {@link #installKeyPair(ComponentName, PrivateKey, Certificate[], String, boolean)} instead.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003633 *
Robin Lee25e26452015-06-02 09:56:29 -07003634 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3635 * {@code null} if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003636 * @param privKey The private key to install.
3637 * @param cert The certificate to install.
3638 * @param alias The private key alias under which to install the certificate. If a certificate
3639 * with that alias already exists, it will be overwritten.
3640 * @return {@code true} if the keys were installed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003641 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3642 * owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003643 * @see #setDelegatedScopes
3644 * @see #DELEGATION_CERT_INSTALL
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003645 */
Robin Leefbc65642015-08-03 16:21:22 +01003646 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
3647 @NonNull Certificate cert, @NonNull String alias) {
Rubin Xub4365912016-03-23 12:13:22 +00003648 return installKeyPair(admin, privKey, new Certificate[] {cert}, alias, false);
Robin Leece3399f2016-02-24 12:08:32 +00003649 }
3650
3651 /**
3652 * Called by a device or profile owner, or delegated certificate installer, to install a
Rubin Xub4365912016-03-23 12:13:22 +00003653 * certificate chain and corresponding private key for the leaf certificate. All apps within the
3654 * profile will be able to access the certificate chain and use the private key, given direct
3655 * user approval.
Robin Leece3399f2016-02-24 12:08:32 +00003656 *
Robin Leea1b290e2016-03-09 14:38:36 +00003657 * <p>The caller of this API may grant itself access to the certificate and private key
3658 * immediately, without user approval. It is a best practice not to request this unless strictly
3659 * necessary since it opens up additional security vulnerabilities.
Robin Leece3399f2016-02-24 12:08:32 +00003660 *
3661 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Robin Leea1b290e2016-03-09 14:38:36 +00003662 * {@code null} if calling from a delegated certificate installer.
Robin Leece3399f2016-02-24 12:08:32 +00003663 * @param privKey The private key to install.
Rubin Xub4365912016-03-23 12:13:22 +00003664 * @param certs The certificate chain to install. The chain should start with the leaf
3665 * certificate and include the chain of trust in order. This will be returned by
3666 * {@link android.security.KeyChain#getCertificateChain}.
Robin Leece3399f2016-02-24 12:08:32 +00003667 * @param alias The private key alias under which to install the certificate. If a certificate
Robin Leea1b290e2016-03-09 14:38:36 +00003668 * with that alias already exists, it will be overwritten.
Robin Leece3399f2016-02-24 12:08:32 +00003669 * @param requestAccess {@code true} to request that the calling app be granted access to the
Robin Leea1b290e2016-03-09 14:38:36 +00003670 * credentials immediately. Otherwise, access to the credentials will be gated by user
3671 * approval.
Robin Leece3399f2016-02-24 12:08:32 +00003672 * @return {@code true} if the keys were installed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003673 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3674 * owner.
Rubin Xub4365912016-03-23 12:13:22 +00003675 * @see android.security.KeyChain#getCertificateChain
Edman Anjosf9946772016-11-28 16:35:15 +01003676 * @see #setDelegatedScopes
3677 * @see #DELEGATION_CERT_INSTALL
Robin Leece3399f2016-02-24 12:08:32 +00003678 */
3679 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
Rubin Xub4365912016-03-23 12:13:22 +00003680 @NonNull Certificate[] certs, @NonNull String alias, boolean requestAccess) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003681 throwIfParentInstance("installKeyPair");
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003682 try {
Rubin Xub4365912016-03-23 12:13:22 +00003683 final byte[] pemCert = Credentials.convertToPem(certs[0]);
3684 byte[] pemChain = null;
3685 if (certs.length > 1) {
3686 pemChain = Credentials.convertToPem(Arrays.copyOfRange(certs, 1, certs.length));
3687 }
Robin Lee0d5ccb72014-09-12 17:41:44 +01003688 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
3689 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
Edman Anjosf9946772016-11-28 16:35:15 +01003690 return mService.installKeyPair(admin, mContext.getPackageName(), pkcs8Key, pemCert,
3691 pemChain, alias, requestAccess);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003692 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003693 throw e.rethrowFromSystemServer();
Robin Lee0d5ccb72014-09-12 17:41:44 +01003694 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
3695 Log.w(TAG, "Failed to obtain private key material", e);
3696 } catch (CertificateException | IOException e) {
3697 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003698 }
3699 return false;
3700 }
3701
3702 /**
Robin Leea1b290e2016-03-09 14:38:36 +00003703 * Called by a device or profile owner, or delegated certificate installer, to remove a
3704 * certificate and private key pair installed under a given alias.
Robin Leefbc65642015-08-03 16:21:22 +01003705 *
3706 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Robin Leea1b290e2016-03-09 14:38:36 +00003707 * {@code null} if calling from a delegated certificate installer.
Robin Leefbc65642015-08-03 16:21:22 +01003708 * @param alias The private key alias under which the certificate is installed.
Robin Leea1b290e2016-03-09 14:38:36 +00003709 * @return {@code true} if the private key alias no longer exists, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003710 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3711 * owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003712 * @see #setDelegatedScopes
3713 * @see #DELEGATION_CERT_INSTALL
Robin Leefbc65642015-08-03 16:21:22 +01003714 */
3715 public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003716 throwIfParentInstance("removeKeyPair");
Robin Leefbc65642015-08-03 16:21:22 +01003717 try {
Edman Anjosf9946772016-11-28 16:35:15 +01003718 return mService.removeKeyPair(admin, mContext.getPackageName(), alias);
Robin Leefbc65642015-08-03 16:21:22 +01003719 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003720 throw e.rethrowFromSystemServer();
Robin Leefbc65642015-08-03 16:21:22 +01003721 }
Robin Leefbc65642015-08-03 16:21:22 +01003722 }
3723
3724 /**
Robin Lee25e26452015-06-02 09:56:29 -07003725 * @return the alias of a given CA certificate in the certificate store, or {@code null} if it
Robin Lee306fe082014-06-19 14:04:24 +00003726 * doesn't exist.
3727 */
3728 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
3729 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
3730 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
3731 new ByteArrayInputStream(certBuffer));
3732 return new TrustedCertificateStore().getCertificateAlias(cert);
3733 }
3734
3735 /**
Rubin Xuec32b562015-03-03 17:34:05 +00003736 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01003737 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00003738 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01003739 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00003740 * <p>
3741 * Delegated certificate installer is a per-user state. The delegated access is persistent until
3742 * it is later cleared by calling this method with a null value or uninstallling the certificate
3743 * installer.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003744 * <p>
Rubin Xuf03d0a62016-02-10 14:54:15 +00003745 * <b>Note:</b>Starting from {@link android.os.Build.VERSION_CODES#N}, if the caller
3746 * application's target SDK version is {@link android.os.Build.VERSION_CODES#N} or newer, the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003747 * supplied certificate installer package must be installed when calling this API, otherwise an
3748 * {@link IllegalArgumentException} will be thrown.
Rubin Xuec32b562015-03-03 17:34:05 +00003749 *
Robin Lee25e26452015-06-02 09:56:29 -07003750 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xuec32b562015-03-03 17:34:05 +00003751 * @param installerPackage The package name of the certificate installer which will be given
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003752 * access. If {@code null} is given the current package will be cleared.
3753 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003754 *
3755 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #setDelegatedScopes}
3756 * with the {@link #DELEGATION_CERT_INSTALL} scope instead.
Rubin Xuec32b562015-03-03 17:34:05 +00003757 */
Edman Anjosf9946772016-11-28 16:35:15 +01003758 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07003759 public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String
3760 installerPackage) throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003761 throwIfParentInstance("setCertInstallerPackage");
Rubin Xuec32b562015-03-03 17:34:05 +00003762 if (mService != null) {
3763 try {
Robin Lee25e26452015-06-02 09:56:29 -07003764 mService.setCertInstallerPackage(admin, installerPackage);
Rubin Xuec32b562015-03-03 17:34:05 +00003765 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003766 throw e.rethrowFromSystemServer();
Rubin Xuec32b562015-03-03 17:34:05 +00003767 }
3768 }
3769 }
3770
3771 /**
Edman Anjosf9946772016-11-28 16:35:15 +01003772 * Called by a profile owner or device owner to retrieve the certificate installer for the user,
3773 * or {@code null} if none is set. If there are multiple delegates this function will return one
3774 * of them.
Rubin Xuec32b562015-03-03 17:34:05 +00003775 *
Robin Lee25e26452015-06-02 09:56:29 -07003776 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003777 * @return The package name of the current delegated certificate installer, or {@code null} if
3778 * none is set.
3779 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01003780 *
3781 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatePackages}
3782 * with the {@link #DELEGATION_CERT_INSTALL} scope instead.
Rubin Xuec32b562015-03-03 17:34:05 +00003783 */
Edman Anjosf9946772016-11-28 16:35:15 +01003784 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07003785 public @Nullable String getCertInstallerPackage(@NonNull ComponentName admin)
3786 throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003787 throwIfParentInstance("getCertInstallerPackage");
Rubin Xuec32b562015-03-03 17:34:05 +00003788 if (mService != null) {
3789 try {
Robin Lee25e26452015-06-02 09:56:29 -07003790 return mService.getCertInstallerPackage(admin);
Rubin Xuec32b562015-03-03 17:34:05 +00003791 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003792 throw e.rethrowFromSystemServer();
Rubin Xuec32b562015-03-03 17:34:05 +00003793 }
3794 }
3795 return null;
3796 }
3797
3798 /**
Edman Anjosf9946772016-11-28 16:35:15 +01003799 * Called by a profile owner or device owner to grant access to privileged APIs to another app.
3800 * Granted APIs are determined by {@code scopes}, which is a list of the {@code DELEGATION_*}
3801 * constants.
3802 * <p>
Edman Anjos9e62c312017-01-26 22:22:58 +01003803 * A broadcast with the {@link #ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED} action will be
3804 * sent to the {@code delegatePackage} with its new scopes in an {@code ArrayList<String>} extra
3805 * under the {@link #EXTRA_DELEGATION_SCOPES} key. The broadcast is sent with the
3806 * {@link Intent#FLAG_RECEIVER_REGISTERED_ONLY} flag.
3807 * <p>
Edman Anjosf9946772016-11-28 16:35:15 +01003808 * Delegated scopes are a per-user state. The delegated access is persistent until it is later
3809 * cleared by calling this method with an empty {@code scopes} list or uninstalling the
3810 * {@code delegatePackage}.
3811 *
3812 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3813 * @param delegatePackage The package name of the app which will be given access.
3814 * @param scopes The groups of privileged APIs whose access should be granted to
3815 * {@code delegatedPackage}.
3816 * @throws SecurityException if {@code admin} is not a device or a profile owner.
3817 */
3818 public void setDelegatedScopes(@NonNull ComponentName admin, @NonNull String delegatePackage,
3819 @NonNull List<String> scopes) {
3820 throwIfParentInstance("setDelegatedScopes");
3821 if (mService != null) {
3822 try {
3823 mService.setDelegatedScopes(admin, delegatePackage, scopes);
3824 } catch (RemoteException e) {
3825 throw e.rethrowFromSystemServer();
3826 }
3827 }
3828 }
3829
3830 /**
3831 * Called by a profile owner or device owner to retrieve a list of the scopes given to a
3832 * delegate package. Other apps can use this method to retrieve their own delegated scopes by
3833 * passing {@code null} for {@code admin} and their own package name as
3834 * {@code delegatedPackage}.
3835 *
3836 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3837 * {@code null} if the caller is {@code delegatedPackage}.
3838 * @param delegatedPackage The package name of the app whose scopes should be retrieved.
3839 * @return A list containing the scopes given to {@code delegatedPackage}.
3840 * @throws SecurityException if {@code admin} is not a device or a profile owner.
3841 */
3842 @NonNull
Edman Anjos9e62c312017-01-26 22:22:58 +01003843 public List<String> getDelegatedScopes(@Nullable ComponentName admin,
Edman Anjosf9946772016-11-28 16:35:15 +01003844 @NonNull String delegatedPackage) {
3845 throwIfParentInstance("getDelegatedScopes");
3846 if (mService != null) {
3847 try {
3848 return mService.getDelegatedScopes(admin, delegatedPackage);
3849 } catch (RemoteException e) {
3850 throw e.rethrowFromSystemServer();
3851 }
3852 }
3853 return null;
3854 }
3855
3856 /**
3857 * Called by a profile owner or device owner to retrieve a list of delegate packages that were
3858 * granted a delegation scope.
3859 *
3860 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3861 * @param delegationScope The scope whose delegates should be retrieved.
3862 * @return A list of package names of the current delegated packages for
3863 {@code delegationScope}.
3864 * @throws SecurityException if {@code admin} is not a device or a profile owner.
3865 */
3866 @Nullable
3867 public List<String> getDelegatePackages(@NonNull ComponentName admin,
3868 @NonNull String delegationScope) {
3869 throwIfParentInstance("getDelegatePackages");
3870 if (mService != null) {
3871 try {
3872 return mService.getDelegatePackages(admin, delegationScope);
3873 } catch (RemoteException e) {
3874 throw e.rethrowFromSystemServer();
3875 }
3876 }
3877 return null;
3878 }
3879
3880 /**
Robin Lee244ce8e2016-01-05 18:03:46 +00003881 * Called by a device or profile owner to configure an always-on VPN connection through a
Robin Leedc679712016-05-03 13:23:03 +01003882 * specific application for the current user.
3883 *
3884 * @deprecated this version only exists for compability with previous developer preview builds.
3885 * TODO: delete once there are no longer any live references.
3886 * @hide
3887 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07003888 @Deprecated
Robin Leedc679712016-05-03 13:23:03 +01003889 public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage)
3890 throws NameNotFoundException, UnsupportedOperationException {
3891 setAlwaysOnVpnPackage(admin, vpnPackage, /* lockdownEnabled */ true);
3892 }
3893
3894 /**
3895 * Called by a device or profile owner to configure an always-on VPN connection through a
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003896 * specific application for the current user. This connection is automatically granted and
3897 * persisted after a reboot.
3898 * <p>
3899 * The designated package should declare a {@link android.net.VpnService} in its manifest
3900 * guarded by {@link android.Manifest.permission#BIND_VPN_SERVICE}, otherwise the call will
3901 * fail.
Robin Lee244ce8e2016-01-05 18:03:46 +00003902 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003903 * @param vpnPackage The package name for an installed VPN app on the device, or {@code null} to
Robin Leedc679712016-05-03 13:23:03 +01003904 * remove an existing always-on VPN configuration.
3905 * @param lockdownEnabled {@code true} to disallow networking when the VPN is not connected or
3906 * {@code false} otherwise. This carries the risk that any failure of the VPN provider
3907 * could break networking for all apps. This has no effect when clearing.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003908 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Robin Leeee5eb932016-04-05 16:27:15 +01003909 * @throws NameNotFoundException if {@code vpnPackage} is not installed.
3910 * @throws UnsupportedOperationException if {@code vpnPackage} exists but does not support being
3911 * set as always-on, or if always-on VPN is not available.
Robin Lee244ce8e2016-01-05 18:03:46 +00003912 */
Robin Leedc679712016-05-03 13:23:03 +01003913 public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage,
3914 boolean lockdownEnabled)
Robin Leeee5eb932016-04-05 16:27:15 +01003915 throws NameNotFoundException, UnsupportedOperationException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003916 throwIfParentInstance("setAlwaysOnVpnPackage");
Robin Lee244ce8e2016-01-05 18:03:46 +00003917 if (mService != null) {
3918 try {
Robin Leedc679712016-05-03 13:23:03 +01003919 if (!mService.setAlwaysOnVpnPackage(admin, vpnPackage, lockdownEnabled)) {
Robin Leeee5eb932016-04-05 16:27:15 +01003920 throw new NameNotFoundException(vpnPackage);
3921 }
Robin Lee244ce8e2016-01-05 18:03:46 +00003922 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003923 throw e.rethrowFromSystemServer();
Robin Lee244ce8e2016-01-05 18:03:46 +00003924 }
3925 }
Robin Lee244ce8e2016-01-05 18:03:46 +00003926 }
3927
3928 /**
3929 * Called by a device or profile owner to read the name of the package administering an
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003930 * always-on VPN connection for the current user. If there is no such package, or the always-on
3931 * VPN is provided by the system instead of by an application, {@code null} will be returned.
Robin Lee244ce8e2016-01-05 18:03:46 +00003932 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003933 * @return Package name of VPN controller responsible for always-on VPN, or {@code null} if none
3934 * is set.
3935 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Robin Lee244ce8e2016-01-05 18:03:46 +00003936 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003937 public @Nullable String getAlwaysOnVpnPackage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003938 throwIfParentInstance("getAlwaysOnVpnPackage");
Robin Lee244ce8e2016-01-05 18:03:46 +00003939 if (mService != null) {
3940 try {
3941 return mService.getAlwaysOnVpnPackage(admin);
3942 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003943 throw e.rethrowFromSystemServer();
Robin Lee244ce8e2016-01-05 18:03:46 +00003944 }
3945 }
3946 return null;
3947 }
3948
3949 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003950 * Called by an application that is administering the device to disable all cameras on the
3951 * device, for this user. After setting this, no applications running as this user will be able
3952 * to access any cameras on the device.
3953 * <p>
3954 * If the caller is device owner, then the restriction will be applied to all users.
3955 * <p>
3956 * The calling device admin must have requested
3957 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call this method; if it has
3958 * not, a security exception will be thrown.
Ben Komalo2447edd2011-05-09 16:05:33 -07003959 *
3960 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3961 * @param disabled Whether or not the camera should be disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003962 * @throws SecurityException if {@code admin} is not an active administrator or does not use
3963 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA}.
Ben Komalo2447edd2011-05-09 16:05:33 -07003964 */
Robin Lee25e26452015-06-02 09:56:29 -07003965 public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003966 throwIfParentInstance("setCameraDisabled");
Ben Komalo2447edd2011-05-09 16:05:33 -07003967 if (mService != null) {
3968 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003969 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07003970 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003971 throw e.rethrowFromSystemServer();
Ben Komalo2447edd2011-05-09 16:05:33 -07003972 }
3973 }
3974 }
3975
3976 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07003977 * Determine whether or not the device's cameras have been disabled for this user,
Makoto Onuki32b30572015-12-11 14:29:51 -08003978 * either by the calling admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07003979 * @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 -07003980 * have disabled the camera
3981 */
Robin Lee25e26452015-06-02 09:56:29 -07003982 public boolean getCameraDisabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003983 throwIfParentInstance("getCameraDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003984 return getCameraDisabled(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003985 }
3986
3987 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003988 public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07003989 if (mService != null) {
3990 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003991 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07003992 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003993 throw e.rethrowFromSystemServer();
Ben Komalo2447edd2011-05-09 16:05:33 -07003994 }
3995 }
3996 return false;
3997 }
3998
3999 /**
Michal Karpinski3fc437e2015-12-15 10:09:00 +00004000 * Called by a device owner to request a bugreport.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004001 * <p>
Esteban Talaverad36dd152016-12-15 08:51:45 +00004002 * If the device contains secondary users or profiles, they must be affiliated with the device
4003 * owner user. Otherwise a {@link SecurityException} will be thrown. See
4004 * {@link #setAffiliationIds}.
Michal Karpinski3fc437e2015-12-15 10:09:00 +00004005 *
4006 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004007 * @return {@code true} if the bugreport collection started successfully, or {@code false} if it
4008 * wasn't triggered because a previous bugreport operation is still active (either the
4009 * bugreport is still running or waiting for the user to share or decline)
Esteban Talaverad36dd152016-12-15 08:51:45 +00004010 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
4011 * profile or secondary user that is not affiliated with the device owner user.
Michal Karpinski3fc437e2015-12-15 10:09:00 +00004012 */
4013 public boolean requestBugreport(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004014 throwIfParentInstance("requestBugreport");
Michal Karpinski3fc437e2015-12-15 10:09:00 +00004015 if (mService != null) {
4016 try {
4017 return mService.requestBugreport(admin);
4018 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004019 throw e.rethrowFromSystemServer();
Michal Karpinski3fc437e2015-12-15 10:09:00 +00004020 }
4021 }
4022 return false;
4023 }
4024
4025 /**
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07004026 * Determine whether or not creating a guest user has been disabled for the device
4027 *
4028 * @hide
4029 */
4030 public boolean getGuestUserDisabled(@Nullable ComponentName admin) {
4031 // Currently guest users can always be created if multi-user is enabled
4032 // TODO introduce a policy for guest user creation
4033 return false;
4034 }
4035
4036 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01004037 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
4038 * screen capture also prevents the content from being shown on display devices that do not have
4039 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
4040 * secure surfaces and secure displays.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004041 * <p>
4042 * The calling device admin must be a device or profile owner. If it is not, a security
4043 * exception will be thrown.
4044 * <p>
4045 * From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also blocks
4046 * assist requests for all activities of the relevant user.
Benjamin Franzc200f442015-06-25 18:20:04 +01004047 *
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004048 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004049 * @param disabled Whether screen capture is disabled or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004050 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004051 */
Robin Lee25e26452015-06-02 09:56:29 -07004052 public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004053 throwIfParentInstance("setScreenCaptureDisabled");
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004054 if (mService != null) {
4055 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08004056 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004057 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004058 throw e.rethrowFromSystemServer();
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004059 }
4060 }
4061 }
4062
4063 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004064 * Determine whether or not screen capture has been disabled by the calling
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004065 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07004066 * @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 +01004067 * have disabled screen capture.
4068 */
Robin Lee25e26452015-06-02 09:56:29 -07004069 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004070 throwIfParentInstance("getScreenCaptureDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004071 return getScreenCaptureDisabled(admin, myUserId());
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004072 }
4073
4074 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07004075 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004076 if (mService != null) {
4077 try {
4078 return mService.getScreenCaptureDisabled(admin, userHandle);
4079 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004080 throw e.rethrowFromSystemServer();
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01004081 }
4082 }
4083 return false;
4084 }
4085
4086 /**
Jason Parks841cb0a2017-01-17 15:25:17 -06004087 * Called by a device or profile owner to set whether auto time is required. If auto time is
4088 * 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 -07004089 * <p>
4090 * Note: if auto time is required the user can still manually set the time zone.
4091 * <p>
Jason Parks841cb0a2017-01-17 15:25:17 -06004092 * The calling device admin must be a device or profile owner. If it is not, a security
4093 * exception will be thrown.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004094 *
4095 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4096 * @param required Whether auto time is set required or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004097 * @throws SecurityException if {@code admin} is not a device owner.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004098 */
Robin Lee25e26452015-06-02 09:56:29 -07004099 public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004100 throwIfParentInstance("setAutoTimeRequired");
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004101 if (mService != null) {
4102 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08004103 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004104 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004105 throw e.rethrowFromSystemServer();
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004106 }
4107 }
4108 }
4109
4110 /**
4111 * @return true if auto time is required.
4112 */
4113 public boolean getAutoTimeRequired() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004114 throwIfParentInstance("getAutoTimeRequired");
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004115 if (mService != null) {
4116 try {
4117 return mService.getAutoTimeRequired();
4118 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004119 throw e.rethrowFromSystemServer();
Sander Alewijnse0ced6272014-08-26 11:18:26 +01004120 }
4121 }
4122 return false;
4123 }
4124
4125 /**
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004126 * Called by a device owner to set whether all users created on the device should be ephemeral.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004127 * <p>
4128 * The system user is exempt from this policy - it is never ephemeral.
4129 * <p>
4130 * The calling device admin must be the device owner. If it is not, a security exception will be
4131 * thrown.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004132 *
4133 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4134 * @param forceEphemeralUsers If true, all the existing users will be deleted and all
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004135 * subsequently created users will be ephemeral.
4136 * @throws SecurityException if {@code admin} is not a device owner.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004137 * @hide
4138 */
4139 public void setForceEphemeralUsers(
4140 @NonNull ComponentName admin, boolean forceEphemeralUsers) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004141 throwIfParentInstance("setForceEphemeralUsers");
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004142 if (mService != null) {
4143 try {
4144 mService.setForceEphemeralUsers(admin, forceEphemeralUsers);
4145 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004146 throw e.rethrowFromSystemServer();
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004147 }
4148 }
4149 }
4150
4151 /**
4152 * @return true if all users are created ephemeral.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004153 * @throws SecurityException if {@code admin} is not a device owner.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004154 * @hide
4155 */
4156 public boolean getForceEphemeralUsers(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004157 throwIfParentInstance("getForceEphemeralUsers");
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01004158 if (mService != null) {
4159 try {
4160 return mService.getForceEphemeralUsers(admin);
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 return false;
4166 }
4167
4168 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07004169 * Called by an application that is administering the device to disable keyguard customizations,
4170 * such as widgets. After setting this, keyguard features will be disabled according to the
4171 * provided feature list.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004172 * <p>
4173 * The calling device admin must have requested
4174 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method;
4175 * if it has not, a security exception will be thrown.
4176 * <p>
4177 * Calling this from a managed profile before version {@link android.os.Build.VERSION_CODES#M}
4178 * will throw a security exception. From version {@link android.os.Build.VERSION_CODES#M} the
4179 * profile owner of a managed profile can set:
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00004180 * <ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00004181 * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which affects the parent user, but only if there
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004182 * is no separate challenge set on the managed profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00004183 * <li>{@link #KEYGUARD_DISABLE_FINGERPRINT} which affects the managed profile challenge if
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004184 * there is one, or the parent user otherwise.
4185 * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} which affects notifications generated
4186 * by applications in the managed profile.
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00004187 * </ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00004188 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} and {@link #KEYGUARD_DISABLE_FINGERPRINT} can also be
4189 * set on the {@link DevicePolicyManager} instance returned by
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004190 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
4191 * profile.
4192 * <p>
4193 * Requests to disable other features on a managed profile will be ignored.
4194 * <p>
4195 * The admin can check which features have been disabled by calling
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00004196 * {@link #getKeyguardDisabledFeatures(ComponentName)}
Amith Yamasani242f4b12014-10-14 16:06:13 -07004197 *
Jim Millerb8ec4702012-08-31 17:19:10 -07004198 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07004199 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004200 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
4201 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS},
4202 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
4203 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS},
4204 * {@link #KEYGUARD_DISABLE_FINGERPRINT}, {@link #KEYGUARD_DISABLE_FEATURES_ALL}
4205 * @throws SecurityException if {@code admin} is not an active administrator or does not user
4206 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES}
Jim Millerb8ec4702012-08-31 17:19:10 -07004207 */
Robin Lee25e26452015-06-02 09:56:29 -07004208 public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07004209 if (mService != null) {
4210 try {
Esteban Talavera62399912016-01-11 15:37:55 +00004211 mService.setKeyguardDisabledFeatures(admin, which, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07004212 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004213 throw e.rethrowFromSystemServer();
Jim Millerb8ec4702012-08-31 17:19:10 -07004214 }
4215 }
4216 }
4217
4218 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004219 * Determine whether or not features have been disabled in keyguard either by the calling
Rubin Xud3609d42016-07-13 18:32:57 +01004220 * admin, if specified, or all admins that set restrictions on this user and its participating
Esteban Talaverac1c83592016-02-17 17:56:15 +00004221 * profiles. Restrictions on profiles that have a separate challenge are not taken into account.
4222 *
4223 * <p>This method can be called on the {@link DevicePolicyManager} instance
4224 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
4225 * restrictions on the parent profile.
4226 *
Esteban Talavera62399912016-01-11 15:37:55 +00004227 * @param admin The name of the admin component to check, or {@code null} to check whether any
4228 * admins have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07004229 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
4230 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07004231 */
Robin Lee25e26452015-06-02 09:56:29 -07004232 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004233 return getKeyguardDisabledFeatures(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004234 }
4235
4236 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07004237 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07004238 if (mService != null) {
4239 try {
Esteban Talavera62399912016-01-11 15:37:55 +00004240 return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07004241 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004242 throw e.rethrowFromSystemServer();
Jim Millerb8ec4702012-08-31 17:19:10 -07004243 }
4244 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07004245 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07004246 }
4247
4248 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08004249 * @hide
4250 */
Robin Lee25e26452015-06-02 09:56:29 -07004251 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
4252 int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08004253 if (mService != null) {
4254 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01004255 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08004256 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004257 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08004258 }
4259 }
4260 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07004261
Dianne Hackbornd6847842010-01-12 18:14:19 -08004262 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01004263 * @hide
4264 */
Robin Lee25e26452015-06-02 09:56:29 -07004265 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004266 setActiveAdmin(policyReceiver, refreshing, myUserId());
Jessica Hummel6d36b602014-04-04 12:42:17 +01004267 }
4268
4269 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08004270 * @hide
4271 */
Robin Lee25e26452015-06-02 09:56:29 -07004272 public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08004273 if (mService != null) {
4274 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004275 mService.getRemoveWarning(admin, result, myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08004276 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004277 throw e.rethrowFromSystemServer();
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08004278 }
4279 }
4280 }
4281
4282 /**
4283 * @hide
4284 */
Andrew Scull5f9e6f32016-08-02 14:22:17 +01004285 public void setActivePasswordState(PasswordMetrics metrics, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08004286 if (mService != null) {
4287 try {
Andrew Scull5f9e6f32016-08-02 14:22:17 +01004288 mService.setActivePasswordState(metrics, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08004289 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004290 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08004291 }
4292 }
4293 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07004294
Dianne Hackbornd6847842010-01-12 18:14:19 -08004295 /**
4296 * @hide
4297 */
Andrew Scull5daf2732016-11-14 15:02:45 +00004298 public void reportPasswordChanged(@UserIdInt int userId) {
4299 if (mService != null) {
4300 try {
4301 mService.reportPasswordChanged(userId);
4302 } catch (RemoteException e) {
4303 throw e.rethrowFromSystemServer();
4304 }
4305 }
4306 }
4307
4308 /**
4309 * @hide
4310 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004311 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08004312 if (mService != null) {
4313 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004314 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08004315 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004316 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08004317 }
4318 }
4319 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07004320
Dianne Hackbornd6847842010-01-12 18:14:19 -08004321 /**
4322 * @hide
4323 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004324 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08004325 if (mService != null) {
4326 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07004327 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08004328 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004329 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08004330 }
4331 }
4332 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07004333
4334 /**
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004335 * @hide
4336 */
4337 public void reportFailedFingerprintAttempt(int userHandle) {
4338 if (mService != null) {
4339 try {
4340 mService.reportFailedFingerprintAttempt(userHandle);
4341 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004342 throw e.rethrowFromSystemServer();
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004343 }
4344 }
4345 }
4346
4347 /**
4348 * @hide
4349 */
4350 public void reportSuccessfulFingerprintAttempt(int userHandle) {
4351 if (mService != null) {
4352 try {
4353 mService.reportSuccessfulFingerprintAttempt(userHandle);
4354 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004355 throw e.rethrowFromSystemServer();
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004356 }
4357 }
4358 }
4359
4360 /**
Michal Karpinski31502d32016-01-25 16:43:07 +00004361 * Should be called when keyguard has been dismissed.
4362 * @hide
4363 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004364 public void reportKeyguardDismissed(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00004365 if (mService != null) {
4366 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004367 mService.reportKeyguardDismissed(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00004368 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004369 throw e.rethrowFromSystemServer();
Michal Karpinski31502d32016-01-25 16:43:07 +00004370 }
4371 }
4372 }
4373
4374 /**
4375 * Should be called when keyguard view has been shown to the user.
4376 * @hide
4377 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004378 public void reportKeyguardSecured(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00004379 if (mService != null) {
4380 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004381 mService.reportKeyguardSecured(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00004382 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004383 throw e.rethrowFromSystemServer();
Michal Karpinski31502d32016-01-25 16:43:07 +00004384 }
4385 }
4386 }
4387
4388 /**
Amith Yamasani71e6c692013-03-24 17:39:28 -07004389 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00004390 * Sets the given package as the device owner.
Makoto Onukia52562c2015-10-01 16:12:31 -07004391 * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name.
4392 * @param who the component name to be registered as device owner.
Amith Yamasani71e6c692013-03-24 17:39:28 -07004393 * @return whether the package was successfully registered as the device owner.
4394 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00004395 * @throws IllegalStateException If the preconditions mentioned are not met.
Amith Yamasani71e6c692013-03-24 17:39:28 -07004396 */
Makoto Onukia52562c2015-10-01 16:12:31 -07004397 public boolean setDeviceOwner(ComponentName who) {
4398 return setDeviceOwner(who, null);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004399 }
4400
4401 /**
4402 * @hide
Makoto Onuki58b684f2015-09-04 10:48:16 -07004403 */
Makoto Onukia52562c2015-10-01 16:12:31 -07004404 public boolean setDeviceOwner(ComponentName who, int userId) {
4405 return setDeviceOwner(who, null, userId);
Makoto Onuki58b684f2015-09-04 10:48:16 -07004406 }
4407
4408 /**
4409 * @hide
4410 */
Makoto Onukia52562c2015-10-01 16:12:31 -07004411 public boolean setDeviceOwner(ComponentName who, String ownerName) {
4412 return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM);
Makoto Onuki58b684f2015-09-04 10:48:16 -07004413 }
4414
4415 /**
4416 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00004417 * Sets the given package as the device owner. The package must already be installed. There
4418 * must not already be a device owner.
4419 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
4420 * this method.
4421 * Calling this after the setup phase of the primary user has completed is allowed only if
4422 * the caller is the shell uid, and there are no additional users and no accounts.
Makoto Onukia52562c2015-10-01 16:12:31 -07004423 * @param who the component name to be registered as device owner.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004424 * @param ownerName the human readable name of the institution that owns this device.
Makoto Onuki58b684f2015-09-04 10:48:16 -07004425 * @param userId ID of the user on which the device owner runs.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004426 * @return whether the package was successfully registered as the device owner.
4427 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00004428 * @throws IllegalStateException If the preconditions mentioned are not met.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004429 */
Makoto Onukia52562c2015-10-01 16:12:31 -07004430 public boolean setDeviceOwner(ComponentName who, String ownerName, int userId)
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004431 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07004432 if (mService != null) {
4433 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07004434 return mService.setDeviceOwner(who, ownerName, userId);
Amith Yamasani71e6c692013-03-24 17:39:28 -07004435 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004436 throw re.rethrowFromSystemServer();
Amith Yamasani71e6c692013-03-24 17:39:28 -07004437 }
4438 }
4439 return false;
4440 }
4441
4442 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004443 * Used to determine if a particular package has been registered as a Device Owner app.
4444 * A device owner app is a special device admin that cannot be deactivated by the user, once
Robin Lee25e26452015-06-02 09:56:29 -07004445 * activated as a device admin. It also cannot be uninstalled. To check whether a particular
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004446 * package is currently registered as the device owner app, pass in the package name from
4447 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
Robin Lee25e26452015-06-02 09:56:29 -07004448 * admin apps that want to check whether they are also registered as the device owner app. The
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004449 * exact mechanism by which a device admin app is registered as a device owner app is defined by
4450 * the setup process.
4451 * @param packageName the package name of the app, to compare with the registered device owner
4452 * app, if any.
Makoto Onukic8a5a552015-11-19 14:29:12 -08004453 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07004454 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004455 public boolean isDeviceOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004456 throwIfParentInstance("isDeviceOwnerApp");
Makoto Onukic8a5a552015-11-19 14:29:12 -08004457 return isDeviceOwnerAppOnCallingUser(packageName);
4458 }
4459
4460 /**
4461 * @return true if a package is registered as device owner, only when it's running on the
4462 * calling user.
4463 *
4464 * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity.
4465 * @hide
4466 */
4467 public boolean isDeviceOwnerAppOnCallingUser(String packageName) {
4468 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true);
4469 }
4470
4471 /**
4472 * @return true if a package is registered as device owner, even if it's running on a different
4473 * user.
4474 *
4475 * <p>Requires the MANAGE_USERS permission.
4476 *
4477 * @hide
4478 */
4479 public boolean isDeviceOwnerAppOnAnyUser(String packageName) {
4480 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false);
4481 }
4482
4483 /**
4484 * @return device owner component name, only when it's running on the calling user.
4485 *
4486 * @hide
4487 */
4488 public ComponentName getDeviceOwnerComponentOnCallingUser() {
4489 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true);
4490 }
4491
4492 /**
4493 * @return device owner component name, even if it's running on a different user.
4494 *
4495 * <p>Requires the MANAGE_USERS permission.
4496 *
4497 * @hide
4498 */
Polina Bondarenko23561db2016-12-16 11:47:28 +01004499 @SystemApi
Makoto Onukic8a5a552015-11-19 14:29:12 -08004500 public ComponentName getDeviceOwnerComponentOnAnyUser() {
4501 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false);
4502 }
4503
4504 private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) {
Makoto Onuki70f929e2015-11-11 12:40:15 -08004505 if (packageName == null) {
4506 return false;
Amith Yamasani71e6c692013-03-24 17:39:28 -07004507 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08004508 final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly);
Makoto Onuki70f929e2015-11-11 12:40:15 -08004509 if (deviceOwner == null) {
4510 return false;
4511 }
4512 return packageName.equals(deviceOwner.getPackageName());
Amith Yamasani71e6c692013-03-24 17:39:28 -07004513 }
4514
Makoto Onukic8a5a552015-11-19 14:29:12 -08004515 private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) {
4516 if (mService != null) {
4517 try {
4518 return mService.getDeviceOwnerComponent(callingUserOnly);
4519 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004520 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08004521 }
4522 }
4523 return null;
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004524 }
4525
Jason Monkb0dced82014-06-06 14:36:20 -04004526 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08004527 * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's
4528 * no device owner.
4529 *
4530 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07004531 *
4532 * @hide
4533 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08004534 public int getDeviceOwnerUserId() {
4535 if (mService != null) {
4536 try {
4537 return mService.getDeviceOwnerUserId();
4538 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004539 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08004540 }
4541 }
4542 return UserHandle.USER_NULL;
Makoto Onukia52562c2015-10-01 16:12:31 -07004543 }
4544
4545 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004546 * Clears the current device owner. The caller must be the device owner. This function should be
4547 * 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 +00004548 * a part of device setup, before it completes.
4549 * <p>
4550 * While some policies previously set by the device owner will be cleared by this method, it is
4551 * a best-effort process and some other policies will still remain in place after the device
4552 * owner is cleared.
Jason Monk94d2cf92014-06-18 09:53:34 -04004553 *
4554 * @param packageName The package name of the device owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004555 * @throws SecurityException if the caller is not in {@code packageName} or {@code packageName}
4556 * does not own the current device owner component.
Esteban Talaveraa5b09632017-02-10 16:15:24 +00004557 *
4558 * @deprecated This method is expected to be used for testing purposes only. The device owner
4559 * will lose control of the device and its data after calling it. In order to protect any
4560 * sensitive data that remains on the device, it is advised that the device owner factory resets
4561 * the device instead of calling this method. See {@link #wipeData(int)}.
Jason Monkb0dced82014-06-06 14:36:20 -04004562 */
Esteban Talaveraa5b09632017-02-10 16:15:24 +00004563 @Deprecated
Jason Monk94d2cf92014-06-18 09:53:34 -04004564 public void clearDeviceOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004565 throwIfParentInstance("clearDeviceOwnerApp");
Jason Monkb0dced82014-06-06 14:36:20 -04004566 if (mService != null) {
4567 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04004568 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04004569 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004570 throw re.rethrowFromSystemServer();
Jason Monkb0dced82014-06-06 14:36:20 -04004571 }
4572 }
4573 }
4574
Makoto Onukia52562c2015-10-01 16:12:31 -07004575 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08004576 * Returns the device owner package name, only if it's running on the calling user.
4577 *
4578 * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity.
Makoto Onukia52562c2015-10-01 16:12:31 -07004579 *
4580 * @hide
4581 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01004582 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004583 public @Nullable String getDeviceOwner() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004584 throwIfParentInstance("getDeviceOwner");
Makoto Onukic8a5a552015-11-19 14:29:12 -08004585 final ComponentName name = getDeviceOwnerComponentOnCallingUser();
4586 return name != null ? name.getPackageName() : null;
Makoto Onukia52562c2015-10-01 16:12:31 -07004587 }
4588
4589 /**
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004590 * Called by the system to find out whether the device is managed by a Device Owner.
Makoto Onukic8a5a552015-11-19 14:29:12 -08004591 *
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004592 * @return whether the device is managed by a Device Owner.
4593 * @throws SecurityException if the caller is not the device owner, does not hold the
4594 * MANAGE_USERS permission and is not the system.
Makoto Onukia52562c2015-10-01 16:12:31 -07004595 *
4596 * @hide
4597 */
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004598 @SystemApi
4599 @TestApi
Makoto Onukic8a5a552015-11-19 14:29:12 -08004600 public boolean isDeviceManaged() {
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004601 try {
4602 return mService.hasDeviceOwner();
4603 } catch (RemoteException re) {
4604 throw re.rethrowFromSystemServer();
4605 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08004606 }
4607
4608 /**
4609 * Returns the device owner name. Note this method *will* return the device owner
4610 * name when it's running on a different user.
4611 *
4612 * <p>Requires the MANAGE_USERS permission.
4613 *
4614 * @hide
4615 */
Makoto Onukia2b274b2016-01-19 13:26:02 -08004616 @SystemApi
Makoto Onukic8a5a552015-11-19 14:29:12 -08004617 public String getDeviceOwnerNameOnAnyUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004618 throwIfParentInstance("getDeviceOwnerNameOnAnyUser");
Amith Yamasani71e6c692013-03-24 17:39:28 -07004619 if (mService != null) {
4620 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07004621 return mService.getDeviceOwnerName();
Amith Yamasani71e6c692013-03-24 17:39:28 -07004622 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004623 throw re.rethrowFromSystemServer();
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004624 }
4625 }
4626 return null;
4627 }
Adam Connors776c5552014-01-09 10:42:56 +00004628
4629 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04004630 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004631 * @deprecated Do not use
4632 * @removed
Julia Reynolds20118f12015-02-11 12:34:08 -05004633 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004634 @Deprecated
Julia Reynolds20118f12015-02-11 12:34:08 -05004635 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004636 public @Nullable String getDeviceInitializerApp() {
Julia Reynolds20118f12015-02-11 12:34:08 -05004637 return null;
4638 }
4639
4640 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004641 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004642 * @deprecated Do not use
4643 * @removed
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004644 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004645 @Deprecated
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004646 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004647 public @Nullable ComponentName getDeviceInitializerComponent() {
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004648 return null;
4649 }
4650
Julia Reynolds20118f12015-02-11 12:34:08 -05004651 /**
Adam Connors776c5552014-01-09 10:42:56 +00004652 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004653 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304654 * Sets the given component as an active admin and registers the package as the profile
4655 * owner for this user. The package must already be installed and there shouldn't be
4656 * an existing profile owner registered for this user. Also, this method must be called
4657 * before the user setup has been completed.
4658 * <p>
4659 * This method can only be called by system apps that hold MANAGE_USERS permission and
4660 * MANAGE_DEVICE_ADMINS permission.
4661 * @param admin The component to register as an active admin and profile owner.
4662 * @param ownerName The user-visible name of the entity that is managing this user.
4663 * @return whether the admin was successfully registered as the profile owner.
4664 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
4665 * the user has already been set up.
4666 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07004667 @Deprecated
Justin Morey80440cc2014-07-24 09:16:35 -05004668 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07004669 public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304670 throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004671 throwIfParentInstance("setActiveProfileOwner");
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304672 if (mService != null) {
4673 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004674 final int myUserId = myUserId();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304675 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004676 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304677 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004678 throw re.rethrowFromSystemServer();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304679 }
4680 }
4681 return false;
4682 }
4683
4684 /**
Esteban Talaveraa5b09632017-02-10 16:15:24 +00004685 * Clears the active profile owner. The caller must be the profile owner of this user, otherwise
4686 * a SecurityException will be thrown. This method is not available to managed profile owners.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004687 * <p>
Esteban Talaveraa5b09632017-02-10 16:15:24 +00004688 * While some policies previously set by the profile owner will be cleared by this method, it is
4689 * a best-effort process and some other policies will still remain in place after the profile
4690 * owner is cleared.
Makoto Onuki5bf68022016-01-27 13:49:19 -08004691 *
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004692 * @param admin The component to remove as the profile owner.
Esteban Talaveraa5b09632017-02-10 16:15:24 +00004693 * @throws SecurityException if {@code admin} is not an active profile owner, or the method is
4694 * being called from a managed profile.
4695 *
4696 * @deprecated This method is expected to be used for testing purposes only. The profile owner
4697 * will lose control of the user and its data after calling it. In order to protect any
4698 * sensitive data that remains on this user, it is advised that the profile owner deletes it
4699 * instead of calling this method. See {@link #wipeData(int)}.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004700 */
Esteban Talaveraa5b09632017-02-10 16:15:24 +00004701 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07004702 public void clearProfileOwner(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004703 throwIfParentInstance("clearProfileOwner");
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004704 if (mService != null) {
4705 try {
4706 mService.clearProfileOwner(admin);
4707 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004708 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004709 }
4710 }
4711 }
4712
4713 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05004714 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07004715 * Checks whether the user was already setup.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004716 */
4717 public boolean hasUserSetupCompleted() {
4718 if (mService != null) {
4719 try {
4720 return mService.hasUserSetupCompleted();
4721 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004722 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004723 }
4724 }
4725 return true;
4726 }
4727
4728 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004729 * @hide
4730 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00004731 * already be installed. There must not already be a profile owner for this user.
4732 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
4733 * this method.
4734 * Calling this after the setup phase of the specified user has completed is allowed only if:
4735 * - the caller is SYSTEM_UID.
4736 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004737 * @param admin the component name to be registered as profile owner.
4738 * @param ownerName the human readable name of the organisation associated with this DPM.
4739 * @param userHandle the userId to set the profile owner for.
4740 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00004741 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
4742 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004743 */
Robin Lee25e26452015-06-02 09:56:29 -07004744 public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName,
Robin Leeddd553f2015-04-30 14:18:22 +01004745 int userHandle) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00004746 if (mService != null) {
4747 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004748 if (ownerName == null) {
4749 ownerName = "";
4750 }
4751 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00004752 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004753 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004754 }
4755 }
4756 return false;
4757 }
4758
4759 /**
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004760 * Sets the device owner information to be shown on the lock screen.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004761 * <p>
4762 * If the device owner information is {@code null} or empty then the device owner info is
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004763 * cleared and the user owner info is shown on the lock screen if it is set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004764 * <p>
4765 * If the device owner information contains only whitespaces then the message on the lock screen
4766 * will be blank and the user will not be allowed to change it.
4767 * <p>
4768 * If the device owner information needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00004769 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
4770 * and set a new version of this string accordingly.
4771 *
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004772 * @param admin The name of the admin component to check.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004773 * @param info Device owner information which will be displayed instead of the user owner info.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004774 * @throws SecurityException if {@code admin} is not a device owner.
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004775 */
Andrei Stingaceanu16187902016-03-21 15:44:45 +00004776 public void setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, CharSequence info) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004777 throwIfParentInstance("setDeviceOwnerLockScreenInfo");
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004778 if (mService != null) {
4779 try {
Andrei Stingaceanu16187902016-03-21 15:44:45 +00004780 mService.setDeviceOwnerLockScreenInfo(admin, info);
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004781 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004782 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004783 }
4784 }
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004785 }
4786
4787 /**
4788 * @return The device owner information. If it is not set returns {@code null}.
4789 */
Andrei Stingaceanu16187902016-03-21 15:44:45 +00004790 public CharSequence getDeviceOwnerLockScreenInfo() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004791 throwIfParentInstance("getDeviceOwnerLockScreenInfo");
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004792 if (mService != null) {
4793 try {
4794 return mService.getDeviceOwnerLockScreenInfo();
4795 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004796 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004797 }
4798 }
4799 return null;
4800 }
4801
4802 /**
Edman Anjos52088e42017-01-13 22:26:17 +01004803 * Called by device or profile owners to suspend packages for this user. This function can be
4804 * called by a device owner, profile owner, or by a delegate given the
4805 * {@link #DELEGATION_PACKAGE_ACCESS} scope via {@link #setDelegatedScopes}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004806 * <p>
4807 * A suspended package will not be able to start activities. Its notifications will be hidden,
4808 * it will not show up in recents, will not be able to show toasts or dialogs or ring the
4809 * device.
4810 * <p>
4811 * The package must already be installed. If the package is uninstalled while suspended the
4812 * package will no longer be suspended. The admin can block this by using
Kenny Guy871f3eb2016-03-09 20:06:16 +00004813 * {@link #setUninstallBlocked}.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004814 *
Edman Anjos52088e42017-01-13 22:26:17 +01004815 * @param admin The name of the admin component to check, or {@code null} if the caller is a
4816 * package access delegate.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004817 * @param packageNames The package names to suspend or unsuspend.
4818 * @param suspended If set to {@code true} than the packages will be suspended, if set to
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004819 * {@code false} the packages will be unsuspended.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004820 * @return an array of package names for which the suspended status is not set as requested in
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004821 * this method.
4822 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01004823 * @see #setDelegatedScopes
4824 * @see #DELEGATION_PACKAGE_ACCESS
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004825 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004826 public @NonNull String[] setPackagesSuspended(@NonNull ComponentName admin,
4827 @NonNull String[] packageNames, boolean suspended) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004828 throwIfParentInstance("setPackagesSuspended");
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004829 if (mService != null) {
4830 try {
Edman Anjos52088e42017-01-13 22:26:17 +01004831 return mService.setPackagesSuspended(admin, mContext.getPackageName(), packageNames,
4832 suspended);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004833 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004834 throw re.rethrowFromSystemServer();
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004835 }
4836 }
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004837 return packageNames;
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004838 }
4839
4840 /**
Edman Anjos52088e42017-01-13 22:26:17 +01004841 * Determine if a package is suspended. This function can be called by a device owner, profile
4842 * owner, or by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via
4843 * {@link #setDelegatedScopes}.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004844 *
Edman Anjos52088e42017-01-13 22:26:17 +01004845 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
4846 * {@code null} if the caller is a package access delegate.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004847 * @param packageName The name of the package to retrieve the suspended status of.
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00004848 * @return {@code true} if the package is suspended or {@code false} if the package is not
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004849 * suspended, could not be found or an error occurred.
4850 * @throws SecurityException if {@code admin} is not a device or profile owner.
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004851 * @throws NameNotFoundException if the package could not be found.
Edman Anjos52088e42017-01-13 22:26:17 +01004852 * @see #setDelegatedScopes
4853 * @see #DELEGATION_PACKAGE_ACCESS
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004854 */
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004855 public boolean isPackageSuspended(@NonNull ComponentName admin, String packageName)
4856 throws NameNotFoundException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004857 throwIfParentInstance("isPackageSuspended");
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004858 if (mService != null) {
4859 try {
Edman Anjos52088e42017-01-13 22:26:17 +01004860 return mService.isPackageSuspended(admin, mContext.getPackageName(), packageName);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004861 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004862 throw e.rethrowFromSystemServer();
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004863 } catch (IllegalArgumentException ex) {
4864 throw new NameNotFoundException(packageName);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004865 }
4866 }
4867 return false;
4868 }
4869
4870 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004871 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
4872 * be used. Only the profile owner can call this.
4873 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01004874 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004875 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004876 * @throws SecurityException if {@code admin} is not a profile owner.
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004877 */
Robin Lee25e26452015-06-02 09:56:29 -07004878 public void setProfileEnabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004879 throwIfParentInstance("setProfileEnabled");
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004880 if (mService != null) {
4881 try {
4882 mService.setProfileEnabled(admin);
4883 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004884 throw e.rethrowFromSystemServer();
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004885 }
4886 }
4887 }
4888
4889 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004890 * Sets the name of the profile. In the device owner case it sets the name of the user which it
4891 * is called from. Only a profile owner or device owner can call this. If this is never called
4892 * by the profile or device owner, the name will be set to default values.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004893 *
4894 * @see #isProfileOwnerApp
4895 * @see #isDeviceOwnerApp
Robin Lee25e26452015-06-02 09:56:29 -07004896 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004897 * @param profileName The name of the profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004898 * @throws SecurityException if {@code admin} is not a device or profile owner.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004899 */
Robin Lee25e26452015-06-02 09:56:29 -07004900 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004901 throwIfParentInstance("setProfileName");
Jessica Hummel1333ea12014-06-23 11:20:10 +01004902 if (mService != null) {
4903 try {
Robin Lee25e26452015-06-02 09:56:29 -07004904 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07004905 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004906 throw e.rethrowFromSystemServer();
Fyodor Kupolov78f13142015-05-27 16:52:45 -07004907 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01004908 }
4909 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01004910
4911 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004912 * Used to determine if a particular package is registered as the profile owner for the
Makoto Onuki32b30572015-12-11 14:29:51 -08004913 * user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004914 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00004915 *
4916 * @param packageName The package name of the app to compare with the registered profile owner.
4917 * @return Whether or not the package is registered as the profile owner.
4918 */
4919 public boolean isProfileOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004920 throwIfParentInstance("isProfileOwnerApp");
Adam Connors776c5552014-01-09 10:42:56 +00004921 if (mService != null) {
4922 try {
Makoto Onuki90b89652016-01-28 14:44:18 -08004923 ComponentName profileOwner = mService.getProfileOwner(myUserId());
Nicolas Prevot90af6d72014-07-30 14:19:12 +01004924 return profileOwner != null
4925 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00004926 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004927 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004928 }
4929 }
4930 return false;
4931 }
4932
4933 /**
4934 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07004935 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00004936 * owner has been set for that user.
4937 * @throws IllegalArgumentException if the userId is invalid.
4938 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01004939 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004940 public @Nullable ComponentName getProfileOwner() throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004941 throwIfParentInstance("getProfileOwner");
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01004942 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
4943 }
4944
4945 /**
4946 * @see #getProfileOwner()
4947 * @hide
4948 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004949 public @Nullable ComponentName getProfileOwnerAsUser(final int userId)
4950 throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00004951 if (mService != null) {
4952 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01004953 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00004954 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004955 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004956 }
4957 }
4958 return null;
4959 }
4960
4961 /**
4962 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07004963 * @return the human readable name of the organisation associated with this DPM or {@code null}
4964 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00004965 * @throws IllegalArgumentException if the userId is invalid.
4966 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004967 public @Nullable String getProfileOwnerName() throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00004968 if (mService != null) {
4969 try {
4970 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
4971 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004972 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004973 }
4974 }
4975 return null;
4976 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004977
4978 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07004979 * @hide
Makoto Onukic8a5a552015-11-19 14:29:12 -08004980 * @param userId The user for whom to fetch the profile owner name, if any.
Amith Yamasani38f836b2014-08-20 14:51:15 -07004981 * @return the human readable name of the organisation associated with this profile owner or
4982 * null if one is not set.
4983 * @throws IllegalArgumentException if the userId is invalid.
4984 */
4985 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004986 public @Nullable String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004987 throwIfParentInstance("getProfileOwnerNameAsUser");
Amith Yamasani38f836b2014-08-20 14:51:15 -07004988 if (mService != null) {
4989 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02004990 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07004991 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004992 throw re.rethrowFromSystemServer();
Amith Yamasani38f836b2014-08-20 14:51:15 -07004993 }
4994 }
4995 return null;
4996 }
4997
4998 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004999 * Called by a profile owner or device owner to add a default intent handler activity for
5000 * intents that match a certain intent filter. This activity will remain the default intent
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005001 * handler even if the set of potential event handlers for the intent filter changes and if the
5002 * intent preferences are reset.
5003 * <p>
5004 * The default disambiguation mechanism takes over if the activity is not installed (anymore).
5005 * When the activity is (re)installed, it is automatically reset as default intent handler for
5006 * the filter.
5007 * <p>
5008 * The calling device admin must be a profile owner or device owner. If it is not, a security
5009 * exception will be thrown.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005010 *
5011 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5012 * @param filter The IntentFilter for which a default handler is added.
5013 * @param activity The Activity that is added as default intent handler.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005014 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005015 */
Robin Lee25e26452015-06-02 09:56:29 -07005016 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
5017 @NonNull ComponentName activity) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005018 throwIfParentInstance("addPersistentPreferredActivity");
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005019 if (mService != null) {
5020 try {
5021 mService.addPersistentPreferredActivity(admin, filter, activity);
5022 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005023 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005024 }
5025 }
5026 }
5027
5028 /**
5029 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00005030 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005031 * <p>
5032 * The calling device admin must be a profile owner. If it is not, a security exception will be
5033 * thrown.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005034 *
5035 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5036 * @param packageName The name of the package for which preferences are removed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005037 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005038 */
Robin Lee25e26452015-06-02 09:56:29 -07005039 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005040 String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005041 throwIfParentInstance("clearPackagePersistentPreferredActivities");
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005042 if (mService != null) {
5043 try {
5044 mService.clearPackagePersistentPreferredActivities(admin, packageName);
5045 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005046 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00005047 }
5048 }
5049 }
Robin Lee66e5d962014-04-09 16:44:21 +01005050
5051 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00005052 * Called by a profile owner or device owner to grant permission to a package to manage
5053 * application restrictions for the calling user via {@link #setApplicationRestrictions} and
5054 * {@link #getApplicationRestrictions}.
5055 * <p>
5056 * This permission is persistent until it is later cleared by calling this method with a
5057 * {@code null} value or uninstalling the managing package.
Rubin Xuf03d0a62016-02-10 14:54:15 +00005058 * <p>
5059 * The supplied application restriction managing package must be installed when calling this
Victor Changcd14c0a2016-03-16 19:10:15 +00005060 * API, otherwise an {@link NameNotFoundException} will be thrown.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005061 *
5062 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5063 * @param packageName The package name which will be given access to application restrictions
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005064 * APIs. If {@code null} is given the current package will be cleared.
5065 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Changcd14c0a2016-03-16 19:10:15 +00005066 * @throws NameNotFoundException if {@code packageName} is not found
Edman Anjosf9946772016-11-28 16:35:15 +01005067 *
5068 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #setDelegatedScopes}
5069 * with the {@link #DELEGATION_APP_RESTRICTIONS} scope instead.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005070 */
Edman Anjosf9946772016-11-28 16:35:15 +01005071 @Deprecated
Esteban Talaverabf60f722015-12-10 16:26:44 +00005072 public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin,
Victor Changcd14c0a2016-03-16 19:10:15 +00005073 @Nullable String packageName) throws NameNotFoundException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005074 throwIfParentInstance("setApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00005075 if (mService != null) {
5076 try {
Victor Changcd14c0a2016-03-16 19:10:15 +00005077 if (!mService.setApplicationRestrictionsManagingPackage(admin, packageName)) {
5078 throw new NameNotFoundException(packageName);
5079 }
Esteban Talaverabf60f722015-12-10 16:26:44 +00005080 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005081 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00005082 }
5083 }
5084 }
5085
5086 /**
5087 * Called by a profile owner or device owner to retrieve the application restrictions managing
Edman Anjosf9946772016-11-28 16:35:15 +01005088 * package for the current user, or {@code null} if none is set. If there are multiple
5089 * delegates this function will return one of them.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005090 *
5091 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5092 * @return The package name allowed to manage application restrictions on the current user, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005093 * {@code null} if none is set.
5094 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01005095 *
5096 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatePackages}
5097 * with the {@link #DELEGATION_APP_RESTRICTIONS} scope instead.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005098 */
Edman Anjosf9946772016-11-28 16:35:15 +01005099 @Deprecated
5100 @Nullable
5101 public String getApplicationRestrictionsManagingPackage(
Makoto Onuki408e8e42016-10-25 12:10:27 -07005102 @NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005103 throwIfParentInstance("getApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00005104 if (mService != null) {
5105 try {
5106 return mService.getApplicationRestrictionsManagingPackage(admin);
5107 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005108 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00005109 }
5110 }
5111 return null;
5112 }
5113
5114 /**
Esteban Talavera96895ca2016-03-16 12:00:40 +00005115 * Called by any application to find out whether it has been granted permission via
5116 * {@link #setApplicationRestrictionsManagingPackage} to manage application restrictions
5117 * for the calling user.
5118 *
5119 * <p>This is done by comparing the calling Linux uid with the uid of the package specified by
5120 * that method.
Edman Anjosf9946772016-11-28 16:35:15 +01005121 *
5122 * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatedScopes}
5123 * instead.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005124 */
Edman Anjosf9946772016-11-28 16:35:15 +01005125 @Deprecated
Esteban Talaverabf60f722015-12-10 16:26:44 +00005126 public boolean isCallerApplicationRestrictionsManagingPackage() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005127 throwIfParentInstance("isCallerApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00005128 if (mService != null) {
5129 try {
Edman Anjosf9946772016-11-28 16:35:15 +01005130 return mService.isCallerApplicationRestrictionsManagingPackage(
5131 mContext.getPackageName());
Esteban Talaverabf60f722015-12-10 16:26:44 +00005132 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005133 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00005134 }
5135 }
5136 return false;
5137 }
5138
5139 /**
5140 * Sets the application restrictions for a given target application running in the calling user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005141 * <p>
5142 * 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 +01005143 * application restrictions via {@link #setDelegatedScopes} with the
5144 * {@link #DELEGATION_APP_RESTRICTIONS} scope; otherwise a security exception will be thrown.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005145 * <p>
5146 * The provided {@link Bundle} consists of key-value pairs, where the types of values may be:
Esteban Talavera6b8e0642015-08-10 17:26:04 +01005147 * <ul>
5148 * <li>{@code boolean}
5149 * <li>{@code int}
5150 * <li>{@code String} or {@code String[]}
5151 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
5152 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005153 * <p>
5154 * If the restrictions are not available yet, but may be applied in the near future, the caller
5155 * can notify the target application of that by adding
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00005156 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005157 * <p>
5158 * The application restrictions are only made visible to the target application via
5159 * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or device
5160 * owner, and the application restrictions managing package via
Esteban Talaverabf60f722015-12-10 16:26:44 +00005161 * {@link #getApplicationRestrictions}.
Robin Lee66e5d962014-04-09 16:44:21 +01005162 *
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005163 * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
5164 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00005165 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005166 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01005167 * @param packageName The name of the package to update restricted settings for.
5168 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005169 * set of active restrictions.
5170 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01005171 * @see #setDelegatedScopes
5172 * @see #DELEGATION_APP_RESTRICTIONS
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00005173 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01005174 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005175 @WorkerThread
Esteban Talaverabf60f722015-12-10 16:26:44 +00005176 public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01005177 Bundle settings) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005178 throwIfParentInstance("setApplicationRestrictions");
Robin Lee66e5d962014-04-09 16:44:21 +01005179 if (mService != null) {
5180 try {
Edman Anjosf9946772016-11-28 16:35:15 +01005181 mService.setApplicationRestrictions(admin, mContext.getPackageName(), packageName,
5182 settings);
Robin Lee66e5d962014-04-09 16:44:21 +01005183 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005184 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01005185 }
5186 }
5187 }
5188
5189 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005190 * Sets a list of configuration features to enable for a TrustAgent component. This is meant to
5191 * be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all trust
5192 * agents but those enabled by this function call. If flag
Jim Millere303bf42014-08-26 17:12:29 -07005193 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005194 * <p>
5195 * The calling device admin must have requested
5196 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method;
5197 * if not, a security exception will be thrown.
Tony Mak089d8402016-04-05 17:42:55 +01005198 * <p>
5199 * This method can be called on the {@link DevicePolicyManager} instance returned by
5200 * {@link #getParentProfileInstance(ComponentName)} in order to set the configuration for
5201 * the parent profile.
Jim Miller604e7552014-07-18 19:00:02 -07005202 *
5203 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07005204 * @param target Component name of the agent to be enabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005205 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent will be
5206 * strictly disabled according to the state of the
5207 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
5208 * <p>
5209 * If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all
5210 * admins, then it's up to the TrustAgent itself to aggregate the values from all
5211 * device admins.
5212 * <p>
5213 * Consult documentation for the specific TrustAgent to determine legal options
5214 * parameters.
5215 * @throws SecurityException if {@code admin} is not an active administrator or does not use
5216 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES}
Jim Miller604e7552014-07-18 19:00:02 -07005217 */
Robin Lee25e26452015-06-02 09:56:29 -07005218 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
5219 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07005220 if (mService != null) {
5221 try {
Tony Mak089d8402016-04-05 17:42:55 +01005222 mService.setTrustAgentConfiguration(admin, target, configuration, mParentInstance);
Jim Miller604e7552014-07-18 19:00:02 -07005223 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005224 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07005225 }
5226 }
5227 }
5228
5229 /**
Jim Millere303bf42014-08-26 17:12:29 -07005230 * Gets configuration for the given trust agent based on aggregating all calls to
5231 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
5232 * all device admins.
Tony Mak089d8402016-04-05 17:42:55 +01005233 * <p>
5234 * This method can be called on the {@link DevicePolicyManager} instance returned by
5235 * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the configuration set
5236 * on the parent profile.
Jim Miller604e7552014-07-18 19:00:02 -07005237 *
Jim Millerb5db57a2015-01-14 18:17:19 -08005238 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
5239 * this function returns a list of configurations for all admins that declare
5240 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
5241 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
5242 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
5243 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07005244 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07005245 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07005246 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005247 public @Nullable List<PersistableBundle> getTrustAgentConfiguration(
5248 @Nullable ComponentName admin, @NonNull ComponentName agent) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07005249 return getTrustAgentConfiguration(admin, agent, myUserId());
Jim Millere303bf42014-08-26 17:12:29 -07005250 }
5251
5252 /** @hide per-user version */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005253 public @Nullable List<PersistableBundle> getTrustAgentConfiguration(
5254 @Nullable ComponentName admin, @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07005255 if (mService != null) {
5256 try {
Tony Mak089d8402016-04-05 17:42:55 +01005257 return mService.getTrustAgentConfiguration(admin, agent, userHandle,
5258 mParentInstance);
Jim Miller604e7552014-07-18 19:00:02 -07005259 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005260 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07005261 }
5262 }
Jim Millere303bf42014-08-26 17:12:29 -07005263 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07005264 }
5265
5266 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005267 * Called by a profile owner of a managed profile to set whether caller-Id information from the
5268 * managed profile will be shown in the parent profile, for incoming calls.
5269 * <p>
5270 * The calling device admin must be a profile owner. If it is not, a security exception will be
5271 * thrown.
Adam Connors210fe212014-07-17 15:41:43 +01005272 *
Robin Lee25e26452015-06-02 09:56:29 -07005273 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01005274 * @param disabled If true caller-Id information in the managed profile is not displayed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005275 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors210fe212014-07-17 15:41:43 +01005276 */
Robin Lee25e26452015-06-02 09:56:29 -07005277 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005278 throwIfParentInstance("setCrossProfileCallerIdDisabled");
Adam Connors210fe212014-07-17 15:41:43 +01005279 if (mService != null) {
5280 try {
Robin Lee25e26452015-06-02 09:56:29 -07005281 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01005282 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005283 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01005284 }
5285 }
5286 }
5287
5288 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005289 * Called by a profile owner of a managed profile to determine whether or not caller-Id
5290 * information has been disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005291 * <p>
5292 * The calling device admin must be a profile owner. If it is not, a security exception will be
5293 * thrown.
Adam Connors210fe212014-07-17 15:41:43 +01005294 *
Robin Lee25e26452015-06-02 09:56:29 -07005295 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005296 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors210fe212014-07-17 15:41:43 +01005297 */
Robin Lee25e26452015-06-02 09:56:29 -07005298 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005299 throwIfParentInstance("getCrossProfileCallerIdDisabled");
Adam Connors210fe212014-07-17 15:41:43 +01005300 if (mService != null) {
5301 try {
Robin Lee25e26452015-06-02 09:56:29 -07005302 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01005303 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005304 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01005305 }
5306 }
5307 return false;
5308 }
5309
5310 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07005311 * Determine whether or not caller-Id information has been disabled.
5312 *
5313 * @param userHandle The user for whom to check the caller-id permission
5314 * @hide
5315 */
5316 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
5317 if (mService != null) {
5318 try {
5319 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
5320 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005321 throw e.rethrowFromSystemServer();
Amith Yamasani570002f2014-07-18 15:48:54 -07005322 }
5323 }
5324 return false;
5325 }
5326
5327 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005328 * Called by a profile owner of a managed profile to set whether contacts search from the
5329 * managed profile will be shown in the parent profile, for incoming calls.
5330 * <p>
5331 * The calling device admin must be a profile owner. If it is not, a security exception will be
5332 * thrown.
Victor Chang1060c6182016-01-04 20:16:23 +00005333 *
5334 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5335 * @param disabled If true contacts search in the managed profile is not displayed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005336 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Chang1060c6182016-01-04 20:16:23 +00005337 */
5338 public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin,
5339 boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005340 throwIfParentInstance("setCrossProfileContactsSearchDisabled");
Victor Chang1060c6182016-01-04 20:16:23 +00005341 if (mService != null) {
5342 try {
5343 mService.setCrossProfileContactsSearchDisabled(admin, disabled);
5344 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005345 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00005346 }
5347 }
5348 }
5349
5350 /**
5351 * Called by a profile owner of a managed profile to determine whether or not contacts search
5352 * has been disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005353 * <p>
5354 * The calling device admin must be a profile owner. If it is not, a security exception will be
5355 * thrown.
Victor Chang1060c6182016-01-04 20:16:23 +00005356 *
5357 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005358 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Chang1060c6182016-01-04 20:16:23 +00005359 */
5360 public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005361 throwIfParentInstance("getCrossProfileContactsSearchDisabled");
Victor Chang1060c6182016-01-04 20:16:23 +00005362 if (mService != null) {
5363 try {
5364 return mService.getCrossProfileContactsSearchDisabled(admin);
5365 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005366 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00005367 }
5368 }
5369 return false;
5370 }
5371
5372
5373 /**
5374 * Determine whether or not contacts search has been disabled.
5375 *
5376 * @param userHandle The user for whom to check the contacts search permission
5377 * @hide
5378 */
5379 public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) {
5380 if (mService != null) {
5381 try {
5382 return mService
5383 .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier());
5384 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005385 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00005386 }
5387 }
5388 return false;
5389 }
5390
5391 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005392 * Start Quick Contact on the managed profile for the user, if the policy allows.
Victor Chang97bdacc2016-01-21 22:24:11 +00005393 *
Makoto Onuki1040da12015-03-19 11:24:00 -07005394 * @hide
5395 */
5396 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
Victor Chang97bdacc2016-01-21 22:24:11 +00005397 boolean isContactIdIgnored, long directoryId, Intent originalIntent) {
Makoto Onuki1040da12015-03-19 11:24:00 -07005398 if (mService != null) {
5399 try {
Victor Chang97bdacc2016-01-21 22:24:11 +00005400 mService.startManagedQuickContact(actualLookupKey, actualContactId,
5401 isContactIdIgnored, directoryId, originalIntent);
Makoto Onuki1040da12015-03-19 11:24:00 -07005402 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005403 throw e.rethrowFromSystemServer();
Makoto Onuki1040da12015-03-19 11:24:00 -07005404 }
5405 }
5406 }
5407
5408 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005409 * Start Quick Contact on the managed profile for the user, if the policy allows.
Ricky Wai494b95d2015-11-20 16:07:15 +00005410 * @hide
5411 */
5412 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
5413 Intent originalIntent) {
Victor Chang97bdacc2016-01-21 22:24:11 +00005414 startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT,
Ricky Wai494b95d2015-11-20 16:07:15 +00005415 originalIntent);
5416 }
5417
5418 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005419 * Called by a profile owner of a managed profile to set whether bluetooth devices can access
5420 * enterprise contacts.
Ricky Wai778ba132015-03-31 14:21:22 +01005421 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005422 * The calling device admin must be a profile owner. If it is not, a security exception will be
5423 * thrown.
Ricky Wai778ba132015-03-31 14:21:22 +01005424 * <p>
5425 * This API works on managed profile only.
5426 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005427 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5428 * @param disabled If true, bluetooth devices cannot access enterprise contacts.
5429 * @throws SecurityException if {@code admin} is not a device or profile owner.
Ricky Wai778ba132015-03-31 14:21:22 +01005430 */
Robin Lee25e26452015-06-02 09:56:29 -07005431 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005432 throwIfParentInstance("setBluetoothContactSharingDisabled");
Ricky Wai778ba132015-03-31 14:21:22 +01005433 if (mService != null) {
5434 try {
Robin Lee25e26452015-06-02 09:56:29 -07005435 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01005436 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005437 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01005438 }
5439 }
5440 }
5441
5442 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005443 * Called by a profile owner of a managed profile to determine whether or not Bluetooth devices
5444 * cannot access enterprise contacts.
Ricky Wai778ba132015-03-31 14:21:22 +01005445 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005446 * The calling device admin must be a profile owner. If it is not, a security exception will be
5447 * thrown.
Ricky Wai778ba132015-03-31 14:21:22 +01005448 * <p>
5449 * This API works on managed profile only.
5450 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005451 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5452 * @throws SecurityException if {@code admin} is not a device or profile owner.
Ricky Wai778ba132015-03-31 14:21:22 +01005453 */
Robin Lee25e26452015-06-02 09:56:29 -07005454 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005455 throwIfParentInstance("getBluetoothContactSharingDisabled");
Ricky Wai778ba132015-03-31 14:21:22 +01005456 if (mService != null) {
5457 try {
Robin Lee25e26452015-06-02 09:56:29 -07005458 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01005459 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005460 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01005461 }
5462 }
5463 return true;
5464 }
5465
5466 /**
5467 * Determine whether or not Bluetooth devices cannot access contacts.
5468 * <p>
5469 * This API works on managed profile UserHandle only.
5470 *
5471 * @param userHandle The user for whom to check the caller-id permission
5472 * @hide
5473 */
5474 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
5475 if (mService != null) {
5476 try {
5477 return mService.getBluetoothContactSharingDisabledForUser(userHandle
5478 .getIdentifier());
5479 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005480 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01005481 }
5482 }
5483 return true;
5484 }
5485
5486 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005487 * Called by the profile owner of a managed profile so that some intents sent in the managed
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005488 * profile can also be resolved in the parent, or vice versa. Only activity intents are
5489 * supported.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00005490 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005491 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01005492 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005493 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01005494 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005495 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
5496 * @throws SecurityException if {@code admin} is not a device or profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005497 */
Robin Lee25e26452015-06-02 09:56:29 -07005498 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005499 throwIfParentInstance("addCrossProfileIntentFilter");
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005500 if (mService != null) {
5501 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01005502 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005503 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005504 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005505 }
5506 }
5507 }
5508
5509 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005510 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
5511 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01005512 * Only removes those that have been set by the profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005513 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005514 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005515 * @throws SecurityException if {@code admin} is not a device or profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005516 */
Robin Lee25e26452015-06-02 09:56:29 -07005517 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005518 throwIfParentInstance("clearCrossProfileIntentFilters");
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005519 if (mService != null) {
5520 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01005521 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005522 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005523 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005524 }
5525 }
5526 }
5527
5528 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005529 * Called by a profile or device owner to set the permitted accessibility services. When set by
5530 * a device owner or profile owner the restriction applies to all profiles of the user the
5531 * device owner or profile owner is an admin for. By default the user can use any accessiblity
5532 * service. When zero or more packages have been added, accessiblity services that are not in
5533 * the list and not part of the system can not be enabled by the user.
5534 * <p>
5535 * Calling with a null value for the list disables the restriction so that all services can be
5536 * used, calling with an empty list only allows the builtin system's services.
5537 * <p>
5538 * System accesibility services are always available to the user the list can't modify this.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005539 *
5540 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5541 * @param packageNames List of accessibility service package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005542 * @return true if setting the restriction succeeded. It fail if there is one or more non-system
5543 * accessibility services enabled, that are not in the list.
5544 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005545 */
Robin Lee25e26452015-06-02 09:56:29 -07005546 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005547 List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005548 throwIfParentInstance("setPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005549 if (mService != null) {
5550 try {
5551 return mService.setPermittedAccessibilityServices(admin, packageNames);
5552 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005553 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005554 }
5555 }
5556 return false;
5557 }
5558
5559 /**
5560 * Returns the list of permitted accessibility services set by this device or profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005561 * <p>
5562 * An empty list means no accessibility services except system services are allowed. Null means
5563 * all accessibility services are allowed.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005564 *
5565 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5566 * @return List of accessiblity service package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005567 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005568 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005569 public @Nullable List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005570 throwIfParentInstance("getPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005571 if (mService != null) {
5572 try {
5573 return mService.getPermittedAccessibilityServices(admin);
5574 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005575 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005576 }
5577 }
5578 return null;
5579 }
5580
5581 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00005582 * Called by the system to check if a specific accessibility service is disabled by admin.
5583 *
5584 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5585 * @param packageName Accessibility service package name that needs to be checked.
5586 * @param userHandle user id the admin is running as.
5587 * @return true if the accessibility service is permitted, otherwise false.
5588 *
5589 * @hide
5590 */
5591 public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin,
5592 @NonNull String packageName, int userHandle) {
5593 if (mService != null) {
5594 try {
5595 return mService.isAccessibilityServicePermittedByAdmin(admin, packageName,
5596 userHandle);
5597 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005598 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00005599 }
5600 }
5601 return false;
5602 }
5603
5604 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005605 * Returns the list of accessibility services permitted by the device or profiles
5606 * owners of this user.
5607 *
5608 * <p>Null means all accessibility services are allowed, if a non-null list is returned
5609 * it will contain the intersection of the permitted lists for any device or profile
5610 * owners that apply to this user. It will also include any system accessibility services.
5611 *
5612 * @param userId which user to check for.
5613 * @return List of accessiblity service package names.
5614 * @hide
5615 */
5616 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07005617 public @Nullable List<String> getPermittedAccessibilityServices(int userId) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005618 throwIfParentInstance("getPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005619 if (mService != null) {
5620 try {
5621 return mService.getPermittedAccessibilityServicesForUser(userId);
5622 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005623 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005624 }
5625 }
5626 return null;
5627 }
5628
5629 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005630 * Called by a profile or device owner to set the permitted input methods services. When set by
5631 * a device owner or profile owner the restriction applies to all profiles of the user the
5632 * device owner or profile owner is an admin for. By default the user can use any input method.
5633 * When zero or more packages have been added, input method that are not in the list and not
5634 * part of the system can not be enabled by the user. This method will fail if it is called for
5635 * a admin that is not for the foreground user or a profile of the foreground user.
5636 * <p>
5637 * Calling with a null value for the list disables the restriction so that all input methods can
5638 * be used, calling with an empty list disables all but the system's own input methods.
5639 * <p>
5640 * System input methods are always available to the user this method can't modify this.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005641 *
5642 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5643 * @param packageNames List of input method package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005644 * @return true if setting the restriction succeeded. It will fail if there are one or more
5645 * non-system input methods currently enabled that are not in the packageNames list.
5646 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005647 */
Robin Lee25e26452015-06-02 09:56:29 -07005648 public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005649 throwIfParentInstance("setPermittedInputMethods");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005650 if (mService != null) {
5651 try {
5652 return mService.setPermittedInputMethods(admin, packageNames);
5653 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005654 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005655 }
5656 }
5657 return false;
5658 }
5659
5660
5661 /**
5662 * Returns the list of permitted input methods set by this device or profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005663 * <p>
5664 * An empty list means no input methods except system input methods are allowed. Null means all
5665 * input methods are allowed.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005666 *
5667 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5668 * @return List of input method package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005669 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005670 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005671 public @Nullable List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005672 throwIfParentInstance("getPermittedInputMethods");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005673 if (mService != null) {
5674 try {
5675 return mService.getPermittedInputMethods(admin);
5676 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005677 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005678 }
5679 }
5680 return null;
5681 }
5682
5683 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00005684 * Called by the system to check if a specific input method is disabled by admin.
5685 *
5686 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5687 * @param packageName Input method package name that needs to be checked.
5688 * @param userHandle user id the admin is running as.
5689 * @return true if the input method is permitted, otherwise false.
5690 *
5691 * @hide
5692 */
5693 public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin,
5694 @NonNull String packageName, int userHandle) {
5695 if (mService != null) {
5696 try {
5697 return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle);
5698 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005699 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00005700 }
5701 }
5702 return false;
5703 }
5704
5705 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005706 * Returns the list of input methods permitted by the device or profiles
Makoto Onuki32b30572015-12-11 14:29:51 -08005707 * owners of the current user. (*Not* calling user, due to a limitation in InputMethodManager.)
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005708 *
5709 * <p>Null means all input methods are allowed, if a non-null list is returned
5710 * it will contain the intersection of the permitted lists for any device or profile
5711 * owners that apply to this user. It will also include any system input methods.
5712 *
5713 * @return List of input method package names.
5714 * @hide
5715 */
5716 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07005717 public @Nullable List<String> getPermittedInputMethodsForCurrentUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005718 throwIfParentInstance("getPermittedInputMethodsForCurrentUser");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005719 if (mService != null) {
5720 try {
5721 return mService.getPermittedInputMethodsForCurrentUser();
5722 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005723 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005724 }
5725 }
5726 return null;
5727 }
5728
5729 /**
Edman Anjos52088e42017-01-13 22:26:17 +01005730 * Get the list of apps to keep around as APKs even if no user has currently installed it. This
5731 * function can be called by a device owner or by a delegate given the
5732 * {@link #DELEGATION_KEEP_UNINSTALLED_PACKAGES} scope via {@link #setDelegatedScopes}.
5733 * <p>
5734 * Please note that packages returned in this method are not automatically pre-cached.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005735 *
Edman Anjos52088e42017-01-13 22:26:17 +01005736 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
5737 * {@code null} if the caller is a keep uninstalled packages delegate.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005738 * @return List of package names to keep cached.
Edman Anjos52088e42017-01-13 22:26:17 +01005739 * @see #setDelegatedScopes
5740 * @see #DELEGATION_KEEP_UNINSTALLED_PACKAGES
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005741 * @hide
5742 */
Edman Anjos52088e42017-01-13 22:26:17 +01005743 public @Nullable List<String> getKeepUninstalledPackages(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005744 throwIfParentInstance("getKeepUninstalledPackages");
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005745 if (mService != null) {
5746 try {
Edman Anjos52088e42017-01-13 22:26:17 +01005747 return mService.getKeepUninstalledPackages(admin, mContext.getPackageName());
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005748 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005749 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005750 }
5751 }
5752 return null;
5753 }
5754
5755 /**
Edman Anjos52088e42017-01-13 22:26:17 +01005756 * Set a list of apps to keep around as APKs even if no user has currently installed it. This
5757 * function can be called by a device owner or by a delegate given the
5758 * {@link #DELEGATION_KEEP_UNINSTALLED_PACKAGES} scope via {@link #setDelegatedScopes}.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005759 *
5760 * <p>Please note that setting this policy does not imply that specified apps will be
5761 * automatically pre-cached.</p>
5762 *
Edman Anjos52088e42017-01-13 22:26:17 +01005763 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
5764 * {@code null} if the caller is a keep uninstalled packages delegate.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005765 * @param packageNames List of package names to keep cached.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005766 * @throws SecurityException if {@code admin} is not a device owner.
Edman Anjos52088e42017-01-13 22:26:17 +01005767 * @see #setDelegatedScopes
5768 * @see #DELEGATION_KEEP_UNINSTALLED_PACKAGES
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005769 * @hide
5770 */
Edman Anjos52088e42017-01-13 22:26:17 +01005771 public void setKeepUninstalledPackages(@Nullable ComponentName admin,
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005772 @NonNull List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005773 throwIfParentInstance("setKeepUninstalledPackages");
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005774 if (mService != null) {
5775 try {
Edman Anjos52088e42017-01-13 22:26:17 +01005776 mService.setKeepUninstalledPackages(admin, mContext.getPackageName(), packageNames);
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005777 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005778 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005779 }
5780 }
5781 }
5782
5783 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04005784 * Called by a device owner to create a user with the specified name. The UserHandle returned
5785 * by this method should not be persisted as user handles are recycled as users are removed and
5786 * created. If you need to persist an identifier for this user, use
5787 * {@link UserManager#getSerialNumberForUser}.
5788 *
5789 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5790 * @param name the user's name
5791 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07005792 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
5793 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01005794 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005795 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01005796 * @removed From {@link android.os.Build.VERSION_CODES#N}
Julia Reynolds1e958392014-05-16 14:25:21 -04005797 */
Kenny Guy14f48e52015-06-29 15:12:36 +01005798 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07005799 public @Nullable UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04005800 return null;
5801 }
5802
5803 /**
Jason Monk03978a42014-06-10 15:05:30 -04005804 * Called by a device owner to create a user with the specified name. The UserHandle returned
5805 * by this method should not be persisted as user handles are recycled as users are removed and
5806 * created. If you need to persist an identifier for this user, use
5807 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
5808 * immediately.
5809 *
5810 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
5811 * as registered as an active admin on the new user. The profile owner package will be
5812 * installed on the new user if it already is installed on the device.
5813 *
5814 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
5815 * profileOwnerComponent when onEnable is called.
5816 *
5817 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5818 * @param name the user's name
5819 * @param ownerName the human readable name of the organisation associated with this DPM.
5820 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
5821 * the user.
5822 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
5823 * on the new user.
5824 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07005825 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
5826 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01005827 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005828 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01005829 * @removed From {@link android.os.Build.VERSION_CODES#N}
Jason Monk03978a42014-06-10 15:05:30 -04005830 */
Kenny Guy14f48e52015-06-29 15:12:36 +01005831 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07005832 public @Nullable UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
Robin Lee25e26452015-06-02 09:56:29 -07005833 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04005834 return null;
5835 }
5836
5837 /**
phweissa92e1212016-01-25 17:14:10 +01005838 * Flag used by {@link #createAndManageUser} to skip setup wizard after creating a new user.
phweiss343fb332016-01-25 14:48:59 +01005839 */
5840 public static final int SKIP_SETUP_WIZARD = 0x0001;
5841
5842 /**
Lenka Trochtovac8202c82016-01-26 15:11:09 +01005843 * Flag used by {@link #createAndManageUser} to specify that the user should be created
5844 * ephemeral.
5845 * @hide
5846 */
5847 public static final int MAKE_USER_EPHEMERAL = 0x0002;
5848
5849 /**
phweissa92e1212016-01-25 17:14:10 +01005850 * Called by a device owner to create a user with the specified name and a given component of
5851 * the calling package as profile owner. The UserHandle returned by this method should not be
5852 * persisted as user handles are recycled as users are removed and created. If you need to
5853 * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new
5854 * user will not be started in the background.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005855 * <p>
5856 * admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also a
5857 * DeviceAdminReceiver in the same package as admin, and will become the profile owner and will
5858 * be registered as an active admin on the new user. The profile owner package will be installed
5859 * on the new user.
5860 * <p>
5861 * If the adminExtras are not null, they will be stored on the device until the user is started
5862 * for the first time. Then the extras will be passed to the admin when onEnable is called.
phweiss343fb332016-01-25 14:48:59 +01005863 *
5864 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5865 * @param name The user's name.
phweissa92e1212016-01-25 17:14:10 +01005866 * @param profileOwner Which {@link DeviceAdminReceiver} will be profile owner. Has to be in the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005867 * same package as admin, otherwise no user is created and an
5868 * IllegalArgumentException is thrown.
phweiss343fb332016-01-25 14:48:59 +01005869 * @param adminExtras Extras that will be passed to onEnable of the admin receiver on the new
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005870 * user.
phweissa92e1212016-01-25 17:14:10 +01005871 * @param flags {@link #SKIP_SETUP_WIZARD} is supported.
phweiss343fb332016-01-25 14:48:59 +01005872 * @see UserHandle
5873 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
5874 * user could not be created.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005875 * @throws SecurityException if {@code admin} is not a device owner.
phweiss343fb332016-01-25 14:48:59 +01005876 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005877 public @Nullable UserHandle createAndManageUser(@NonNull ComponentName admin,
5878 @NonNull String name,
phweissa92e1212016-01-25 17:14:10 +01005879 @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras,
5880 int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005881 throwIfParentInstance("createAndManageUser");
phweiss343fb332016-01-25 14:48:59 +01005882 try {
phweissa92e1212016-01-25 17:14:10 +01005883 return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags);
phweiss343fb332016-01-25 14:48:59 +01005884 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005885 throw re.rethrowFromSystemServer();
phweiss343fb332016-01-25 14:48:59 +01005886 }
phweiss343fb332016-01-25 14:48:59 +01005887 }
5888
5889 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005890 * Called by a device owner to remove a user and all associated data. The primary user can not
5891 * be removed.
Julia Reynolds1e958392014-05-16 14:25:21 -04005892 *
5893 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5894 * @param userHandle the user to remove.
5895 * @return {@code true} if the user was removed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005896 * @throws SecurityException if {@code admin} is not a device owner.
Julia Reynolds1e958392014-05-16 14:25:21 -04005897 */
Robin Lee25e26452015-06-02 09:56:29 -07005898 public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005899 throwIfParentInstance("removeUser");
Julia Reynolds1e958392014-05-16 14:25:21 -04005900 try {
5901 return mService.removeUser(admin, userHandle);
5902 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005903 throw re.rethrowFromSystemServer();
Julia Reynolds1e958392014-05-16 14:25:21 -04005904 }
5905 }
5906
5907 /**
Jason Monk582d9112014-07-09 19:57:08 -04005908 * Called by a device owner to switch the specified user to the foreground.
5909 *
5910 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5911 * @param userHandle the user to switch to; null will switch to primary.
5912 * @return {@code true} if the switch was successful, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005913 * @throws SecurityException if {@code admin} is not a device owner.
Jason Monk582d9112014-07-09 19:57:08 -04005914 * @see Intent#ACTION_USER_FOREGROUND
5915 */
Robin Lee25e26452015-06-02 09:56:29 -07005916 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005917 throwIfParentInstance("switchUser");
Jason Monk582d9112014-07-09 19:57:08 -04005918 try {
5919 return mService.switchUser(admin, userHandle);
5920 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005921 throw re.rethrowFromSystemServer();
Jason Monk582d9112014-07-09 19:57:08 -04005922 }
5923 }
5924
5925 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00005926 * Retrieves the application restrictions for a given target application running in the calling
5927 * user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005928 * <p>
5929 * 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 +01005930 * application restrictions via {@link #setDelegatedScopes} with the
5931 * {@link #DELEGATION_APP_RESTRICTIONS} scope; otherwise a security exception will be thrown.
Robin Lee66e5d962014-04-09 16:44:21 +01005932 *
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005933 * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
5934 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00005935 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005936 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01005937 * @param packageName The name of the package to fetch restricted settings of.
5938 * @return {@link Bundle} of settings corresponding to what was set last time
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005939 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty
5940 * {@link Bundle} if no restrictions have been set.
5941 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjosf9946772016-11-28 16:35:15 +01005942 * @see #setDelegatedScopes
5943 * @see #DELEGATION_APP_RESTRICTIONS
Robin Lee66e5d962014-04-09 16:44:21 +01005944 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005945 @WorkerThread
Makoto Onuki408e8e42016-10-25 12:10:27 -07005946 public @NonNull Bundle getApplicationRestrictions(
5947 @Nullable ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005948 throwIfParentInstance("getApplicationRestrictions");
Robin Lee66e5d962014-04-09 16:44:21 +01005949 if (mService != null) {
5950 try {
Edman Anjosf9946772016-11-28 16:35:15 +01005951 return mService.getApplicationRestrictions(admin, mContext.getPackageName(),
5952 packageName);
Robin Lee66e5d962014-04-09 16:44:21 +01005953 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005954 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01005955 }
5956 }
5957 return null;
5958 }
Amith Yamasanibe465322014-04-24 13:45:17 -07005959
5960 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05005961 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07005962 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005963 * The calling device admin must be a profile or device owner; if it is not, a security
5964 * exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07005965 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005966 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5967 * @param key The key of the restriction. See the constants in {@link android.os.UserManager}
5968 * for the list of keys.
5969 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanibe465322014-04-24 13:45:17 -07005970 */
Robin Lee25e26452015-06-02 09:56:29 -07005971 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005972 throwIfParentInstance("addUserRestriction");
Amith Yamasanibe465322014-04-24 13:45:17 -07005973 if (mService != null) {
5974 try {
5975 mService.setUserRestriction(admin, key, true);
5976 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005977 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07005978 }
5979 }
5980 }
5981
5982 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05005983 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07005984 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005985 * The calling device admin must be a profile or device owner; if it is not, a security
5986 * exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07005987 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005988 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5989 * @param key The key of the restriction. See the constants in {@link android.os.UserManager}
5990 * for the list of keys.
5991 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanibe465322014-04-24 13:45:17 -07005992 */
Robin Lee25e26452015-06-02 09:56:29 -07005993 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005994 throwIfParentInstance("clearUserRestriction");
Amith Yamasanibe465322014-04-24 13:45:17 -07005995 if (mService != null) {
5996 try {
5997 mService.setUserRestriction(admin, key, false);
5998 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005999 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07006000 }
6001 }
6002 }
Adam Connors010cfd42014-04-16 12:48:13 +01006003
6004 /**
Makoto Onuki3a3092f2015-10-30 11:07:51 -07006005 * Called by a profile or device owner to get user restrictions set with
6006 * {@link #addUserRestriction(ComponentName, String)}.
6007 * <p>
6008 * The target user may have more restrictions set by the system or other device owner / profile
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006009 * owner. To get all the user restrictions currently set, use
Makoto Onuki3a3092f2015-10-30 11:07:51 -07006010 * {@link UserManager#getUserRestrictions()}.
6011 *
6012 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006013 * @throws SecurityException if {@code admin} is not a device or profile owner.
Makoto Onuki3a3092f2015-10-30 11:07:51 -07006014 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006015 public @NonNull Bundle getUserRestrictions(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006016 throwIfParentInstance("getUserRestrictions");
Makoto Onuki3a3092f2015-10-30 11:07:51 -07006017 Bundle ret = null;
6018 if (mService != null) {
6019 try {
Sudheer Shanka549b9692016-03-30 17:12:07 -07006020 ret = mService.getUserRestrictions(admin);
6021 } catch (RemoteException e) {
6022 throw e.rethrowFromSystemServer();
6023 }
6024 }
6025 return ret == null ? new Bundle() : ret;
6026 }
6027
6028 /**
phweiss73145f42017-01-17 19:06:38 +01006029 * Called by any app to display a support dialog when a feature was disabled by an admin.
6030 * This returns an intent that can be used with {@link Context#startActivity(Intent)} to
6031 * display the dialog. It will tell the user that the feature indicated by {@code restriction}
6032 * was disabled by an admin, and include a link for more information. The default content of
6033 * the dialog can be changed by the restricting admin via
6034 * {@link #setShortSupportMessage(ComponentName, CharSequence)}. If the restriction is not
6035 * set (i.e. the feature is available), then the return value will be {@code null}.
6036 * @param restriction Indicates for which feature the dialog should be displayed. Can be a
6037 * user restriction from {@link UserManager}, e.g.
6038 * {@link UserManager#DISALLOW_ADJUST_VOLUME}, or one of the constants
6039 * {@link #POLICY_DISABLE_CAMERA} or {@link #POLICY_DISABLE_SCREEN_CAPTURE}.
6040 * @return Intent An intent to be used to start the dialog-activity if the restriction is
6041 * set by an admin, or null if the restriction does not exist or no admin set it.
6042 */
6043 public Intent createAdminSupportIntent(@NonNull String restriction) {
6044 throwIfParentInstance("createAdminSupportIntent");
6045 if (mService != null) {
6046 try {
6047 return mService.createAdminSupportIntent(restriction);
6048 } catch (RemoteException e) {
6049 throw e.rethrowFromSystemServer();
6050 }
6051 }
6052 return null;
6053 }
6054
6055 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006056 * Hide or unhide packages. When a package is hidden it is unavailable for use, but the data and
6057 * actual package file remain. This function can be called by a device owner, profile owner, or
6058 * by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via
6059 * {@link #setDelegatedScopes}.
Julia Reynolds966881e2014-05-14 12:23:08 -04006060 *
Edman Anjos52088e42017-01-13 22:26:17 +01006061 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
6062 * {@code null} if the caller is a package access delegate.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07006063 * @param packageName The name of the package to hide or unhide.
6064 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006065 * unhidden.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07006066 * @return boolean Whether the hidden setting of the package was successfully updated.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006067 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01006068 * @see #setDelegatedScopes
6069 * @see #DELEGATION_PACKAGE_ACCESS
Julia Reynolds966881e2014-05-14 12:23:08 -04006070 */
Robin Lee25e26452015-06-02 09:56:29 -07006071 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07006072 boolean hidden) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006073 throwIfParentInstance("setApplicationHidden");
Julia Reynolds966881e2014-05-14 12:23:08 -04006074 if (mService != null) {
6075 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006076 return mService.setApplicationHidden(admin, mContext.getPackageName(), packageName,
6077 hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04006078 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006079 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04006080 }
6081 }
6082 return false;
6083 }
6084
6085 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006086 * Determine if a package is hidden. This function can be called by a device owner, profile
6087 * owner, or by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via
6088 * {@link #setDelegatedScopes}.
Julia Reynolds966881e2014-05-14 12:23:08 -04006089 *
Edman Anjos52088e42017-01-13 22:26:17 +01006090 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
6091 * {@code null} if the caller is a package access delegate.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07006092 * @param packageName The name of the package to retrieve the hidden status of.
6093 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006094 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01006095 * @see #setDelegatedScopes
6096 * @see #DELEGATION_PACKAGE_ACCESS
Julia Reynolds966881e2014-05-14 12:23:08 -04006097 */
Robin Lee25e26452015-06-02 09:56:29 -07006098 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006099 throwIfParentInstance("isApplicationHidden");
Julia Reynolds966881e2014-05-14 12:23:08 -04006100 if (mService != null) {
6101 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006102 return mService.isApplicationHidden(admin, mContext.getPackageName(), packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04006103 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006104 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04006105 }
6106 }
6107 return false;
6108 }
6109
6110 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006111 * Re-enable a system app that was disabled by default when the user was initialized. This
6112 * function can be called by a device owner, profile owner, or by a delegate given the
6113 * {@link #DELEGATION_ENABLE_SYSTEM_APP} scope via {@link #setDelegatedScopes}.
Adam Connors655be2a2014-07-14 09:01:25 +00006114 *
Edman Anjos52088e42017-01-13 22:26:17 +01006115 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
6116 * {@code null} if the caller is an enable system app delegate.
Makoto Onuki32b30572015-12-11 14:29:51 -08006117 * @param packageName The package to be re-enabled in the calling profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006118 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01006119 * @see #setDelegatedScopes
6120 * @see #DELEGATION_PACKAGE_ACCESS
Adam Connors655be2a2014-07-14 09:01:25 +00006121 */
Robin Lee25e26452015-06-02 09:56:29 -07006122 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006123 throwIfParentInstance("enableSystemApp");
Adam Connors655be2a2014-07-14 09:01:25 +00006124 if (mService != null) {
6125 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006126 mService.enableSystemApp(admin, mContext.getPackageName(), packageName);
Adam Connors655be2a2014-07-14 09:01:25 +00006127 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006128 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00006129 }
6130 }
6131 }
6132
6133 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006134 * Re-enable system apps by intent that were disabled by default when the user was initialized.
6135 * This function can be called by a device owner, profile owner, or by a delegate given the
6136 * {@link #DELEGATION_ENABLE_SYSTEM_APP} scope via {@link #setDelegatedScopes}.
Adam Connors655be2a2014-07-14 09:01:25 +00006137 *
Edman Anjos52088e42017-01-13 22:26:17 +01006138 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
6139 * {@code null} if the caller is an enable system app delegate.
Adam Connors655be2a2014-07-14 09:01:25 +00006140 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006141 * intent will be re-enabled in the calling profile.
Adam Connors655be2a2014-07-14 09:01:25 +00006142 * @return int The number of activities that matched the intent and were installed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006143 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjos52088e42017-01-13 22:26:17 +01006144 * @see #setDelegatedScopes
6145 * @see #DELEGATION_PACKAGE_ACCESS
Adam Connors655be2a2014-07-14 09:01:25 +00006146 */
Robin Lee25e26452015-06-02 09:56:29 -07006147 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006148 throwIfParentInstance("enableSystemApp");
Adam Connors655be2a2014-07-14 09:01:25 +00006149 if (mService != null) {
6150 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006151 return mService.enableSystemAppWithIntent(admin, mContext.getPackageName(), intent);
Adam Connors655be2a2014-07-14 09:01:25 +00006152 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006153 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00006154 }
6155 }
6156 return 0;
6157 }
6158
6159 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00006160 * Called by a device owner or profile owner to disable account management for a specific type
6161 * of account.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006162 * <p>
6163 * The calling device admin must be a device owner or profile owner. If it is not, a security
6164 * exception will be thrown.
6165 * <p>
6166 * When account management is disabled for an account type, adding or removing an account of
6167 * that type will not be possible.
6168 * <p>
6169 * From {@link android.os.Build.VERSION_CODES#N} the profile or device owner can still use
Benjamin Franzb6c0ce42015-11-05 10:06:51 +00006170 * {@link android.accounts.AccountManager} APIs to add or remove accounts when account
6171 * management for a specific type is disabled.
6172 *
Sander Alewijnse650c3342014-05-08 18:00:50 +01006173 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6174 * @param accountType For which account management is disabled or enabled.
6175 * @param disabled The boolean indicating that account management will be disabled (true) or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006176 * enabled (false).
6177 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnse650c3342014-05-08 18:00:50 +01006178 */
Robin Lee25e26452015-06-02 09:56:29 -07006179 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01006180 boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006181 throwIfParentInstance("setAccountManagementDisabled");
Sander Alewijnse650c3342014-05-08 18:00:50 +01006182 if (mService != null) {
6183 try {
6184 mService.setAccountManagementDisabled(admin, accountType, disabled);
6185 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006186 throw e.rethrowFromSystemServer();
Sander Alewijnse650c3342014-05-08 18:00:50 +01006187 }
6188 }
6189 }
6190
6191 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01006192 * Gets the array of accounts for which account management is disabled by the profile owner.
6193 *
6194 * <p> Account management can be disabled/enabled by calling
6195 * {@link #setAccountManagementDisabled}.
6196 *
6197 * @return a list of account types for which account management has been disabled.
6198 *
6199 * @see #setAccountManagementDisabled
6200 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006201 public @Nullable String[] getAccountTypesWithManagementDisabled() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006202 throwIfParentInstance("getAccountTypesWithManagementDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07006203 return getAccountTypesWithManagementDisabledAsUser(myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01006204 }
6205
6206 /**
6207 * @see #getAccountTypesWithManagementDisabled()
6208 * @hide
6209 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006210 public @Nullable String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01006211 if (mService != null) {
6212 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01006213 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01006214 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006215 throw e.rethrowFromSystemServer();
Sander Alewijnse5c02db62014-05-07 10:46:57 +01006216 }
6217 }
6218
6219 return null;
6220 }
justinzhang511e0d82014-03-24 16:09:24 -04006221
6222 /**
Jason Monkd7b86212014-06-16 13:15:38 -04006223 * Sets which packages may enter lock task mode.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006224 * <p>
Esteban Talaverabdcada92017-02-01 14:20:06 +00006225 * Any packages that share uid with an allowed package will also be allowed to activate lock
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006226 * task. From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task
Esteban Talaverabdcada92017-02-01 14:20:06 +00006227 * package list results in locked tasks belonging to those packages to be finished.
6228 * <p>
6229 * This function can only be called by the device owner or by a profile owner of a user/profile
6230 * that is affiliated with the device owner user. See {@link #setAffiliationIds}. Any packages
6231 * set via this method will be cleared if the user becomes unaffiliated.
Jason Monkd7b86212014-06-16 13:15:38 -04006232 *
Jason Monkd7b86212014-06-16 13:15:38 -04006233 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04006234 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Esteban Talaverabdcada92017-02-01 14:20:06 +00006235 * @throws SecurityException if {@code admin} is not the device owner, or the profile owner of
6236 * an affiliated user or profile.
Jason Monkd7b86212014-06-16 13:15:38 -04006237 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00006238 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
6239 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04006240 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04006241 */
Esteban Talaverabdcada92017-02-01 14:20:06 +00006242 public void setLockTaskPackages(@NonNull ComponentName admin, @NonNull String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04006243 throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006244 throwIfParentInstance("setLockTaskPackages");
justinzhang511e0d82014-03-24 16:09:24 -04006245 if (mService != null) {
6246 try {
Jason Monk48aacba2014-08-13 16:29:08 -04006247 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04006248 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006249 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04006250 }
6251 }
6252 }
6253
6254 /**
Esteban Talaverabdcada92017-02-01 14:20:06 +00006255 * Returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04006256 *
Esteban Talaverabdcada92017-02-01 14:20:06 +00006257 * @throws SecurityException if {@code admin} is not the device owner, or the profile owner of
6258 * an affiliated user or profile.
6259 * @see #setLockTaskPackages
justinzhang511e0d82014-03-24 16:09:24 -04006260 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006261 public @NonNull String[] getLockTaskPackages(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006262 throwIfParentInstance("getLockTaskPackages");
justinzhang511e0d82014-03-24 16:09:24 -04006263 if (mService != null) {
6264 try {
Jason Monk48aacba2014-08-13 16:29:08 -04006265 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04006266 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006267 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04006268 }
6269 }
Esteban Talaverabdcada92017-02-01 14:20:06 +00006270 return new String[0];
justinzhang511e0d82014-03-24 16:09:24 -04006271 }
6272
6273 /**
6274 * This function lets the caller know whether the given component is allowed to start the
6275 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04006276 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04006277 */
Jason Monkd7b86212014-06-16 13:15:38 -04006278 public boolean isLockTaskPermitted(String pkg) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006279 throwIfParentInstance("isLockTaskPermitted");
justinzhang511e0d82014-03-24 16:09:24 -04006280 if (mService != null) {
6281 try {
Jason Monkd7b86212014-06-16 13:15:38 -04006282 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04006283 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006284 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04006285 }
6286 }
6287 return false;
6288 }
Julia Reynoldsda551652014-05-14 17:15:16 -04006289
6290 /**
6291 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
6292 * 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 -07006293 * <p>
6294 * The settings that can be updated with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04006295 * <ul>
6296 * <li>{@link Settings.Global#ADB_ENABLED}</li>
6297 * <li>{@link Settings.Global#AUTO_TIME}</li>
6298 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04006299 * <li>{@link Settings.Global#DATA_ROAMING}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04006300 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04006301 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006302 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN} This setting is only available from
6303 * {@link android.os.Build.VERSION_CODES#M} onwards and can only be set if
6304 * {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
6305 * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li> This setting is only
6306 * available from {@link android.os.Build.VERSION_CODES#M} onwards.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04006307 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006308 * <p>
6309 * Changing the following settings has no effect as of {@link android.os.Build.VERSION_CODES#M}:
Esteban Talavera656fa7f2015-06-29 17:41:39 +01006310 * <ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006311 * <li>{@link Settings.Global#BLUETOOTH_ON}. Use
6312 * {@link android.bluetooth.BluetoothAdapter#enable()} and
6313 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01006314 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006315 * <li>{@link Settings.Global#MODE_RINGER}. Use
6316 * {@link android.media.AudioManager#setRingerMode(int)} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01006317 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006318 * <li>{@link Settings.Global#WIFI_ON}. Use
6319 * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01006320 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04006321 *
6322 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6323 * @param setting The name of the setting to update.
6324 * @param value The value to update the setting to.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006325 * @throws SecurityException if {@code admin} is not a device owner.
Julia Reynoldsda551652014-05-14 17:15:16 -04006326 */
Robin Lee25e26452015-06-02 09:56:29 -07006327 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006328 throwIfParentInstance("setGlobalSetting");
Julia Reynoldsda551652014-05-14 17:15:16 -04006329 if (mService != null) {
6330 try {
6331 mService.setGlobalSetting(admin, setting, value);
6332 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006333 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04006334 }
6335 }
6336 }
6337
6338 /**
6339 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
6340 * that the value of the setting is in the correct form for the setting type should be performed
6341 * by the caller.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006342 * <p>
6343 * The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04006344 * <ul>
6345 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
6346 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
6347 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006348 * <p>
6349 * A device owner can additionally update the following settings:
Julia Reynolds82735bc2014-09-04 16:43:30 -04006350 * <ul>
6351 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
6352 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006353 *
Suprabh Shukla0b1356f2017-02-21 14:33:50 -08006354 * <strong>Note: Starting from Android O, apps should no longer call this method with the
6355 * setting {@link android.provider.Settings.Secure#INSTALL_NON_MARKET_APPS}, which is
6356 * deprecated. Instead, device owners or profile owners should use the restriction
6357 * {@link UserManager#DISALLOW_INSTALL_UNKNOWN_SOURCES}.
6358 * If any app targeting {@link android.os.Build.VERSION_CODES#O} or higher calls this method
6359 * with {@link android.provider.Settings.Secure#INSTALL_NON_MARKET_APPS},
6360 * an {@link UnsupportedOperationException} is thrown.
6361 * </strong>
6362 *
Julia Reynoldsda551652014-05-14 17:15:16 -04006363 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6364 * @param setting The name of the setting to update.
6365 * @param value The value to update the setting to.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006366 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynoldsda551652014-05-14 17:15:16 -04006367 */
Robin Lee25e26452015-06-02 09:56:29 -07006368 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006369 throwIfParentInstance("setSecureSetting");
Julia Reynoldsda551652014-05-14 17:15:16 -04006370 if (mService != null) {
6371 try {
6372 mService.setSecureSetting(admin, setting, value);
6373 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006374 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04006375 }
6376 }
6377 }
6378
Amith Yamasanif20d6402014-05-24 15:34:37 -07006379 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006380 * Designates a specific service component as the provider for making permission requests of a
6381 * local or remote administrator of the user.
Amith Yamasanif20d6402014-05-24 15:34:37 -07006382 * <p/>
6383 * Only a profile owner can designate the restrictions provider.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006384 *
Amith Yamasanif20d6402014-05-24 15:34:37 -07006385 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07006386 * @param provider The component name of the service that implements
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006387 * {@link RestrictionsReceiver}. If this param is null, it removes the restrictions
6388 * provider previously assigned.
6389 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanif20d6402014-05-24 15:34:37 -07006390 */
Robin Lee25e26452015-06-02 09:56:29 -07006391 public void setRestrictionsProvider(@NonNull ComponentName admin,
6392 @Nullable ComponentName provider) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006393 throwIfParentInstance("setRestrictionsProvider");
Amith Yamasanif20d6402014-05-24 15:34:37 -07006394 if (mService != null) {
6395 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07006396 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07006397 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006398 throw re.rethrowFromSystemServer();
Amith Yamasanif20d6402014-05-24 15:34:37 -07006399 }
6400 }
6401 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04006402
6403 /**
6404 * Called by profile or device owners to set the master volume mute on or off.
Nicolas Prevotaef3ce22016-09-22 12:00:25 +01006405 * This has no effect when set on a managed profile.
Julia Reynolds4a21b252014-06-04 11:11:43 -04006406 *
6407 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6408 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006409 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds4a21b252014-06-04 11:11:43 -04006410 */
Robin Lee25e26452015-06-02 09:56:29 -07006411 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006412 throwIfParentInstance("setMasterVolumeMuted");
Julia Reynolds4a21b252014-06-04 11:11:43 -04006413 if (mService != null) {
6414 try {
6415 mService.setMasterVolumeMuted(admin, on);
6416 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006417 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04006418 }
6419 }
6420 }
6421
6422 /**
6423 * Called by profile or device owners to check whether the master volume mute is on or off.
6424 *
6425 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6426 * @return {@code true} if master volume is muted, {@code false} if it's not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006427 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds4a21b252014-06-04 11:11:43 -04006428 */
Robin Lee25e26452015-06-02 09:56:29 -07006429 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006430 throwIfParentInstance("isMasterVolumeMuted");
Julia Reynolds4a21b252014-06-04 11:11:43 -04006431 if (mService != null) {
6432 try {
6433 return mService.isMasterVolumeMuted(admin);
6434 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006435 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04006436 }
6437 }
6438 return false;
6439 }
Kenny Guyc13053b2014-05-29 14:17:17 +01006440
6441 /**
Edman Anjosa5f2fb12016-12-19 11:25:54 -08006442 * Change whether a user can uninstall a package. This function can be called by a device owner,
6443 * profile owner, or by a delegate given the {@link #DELEGATION_BLOCK_UNINSTALL} scope via
6444 * {@link #setDelegatedScopes}.
Kenny Guyc13053b2014-05-29 14:17:17 +01006445 *
Edman Anjosa5f2fb12016-12-19 11:25:54 -08006446 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
6447 * {@code null} if the caller is a block uninstall delegate.
Kenny Guyc13053b2014-05-29 14:17:17 +01006448 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01006449 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006450 * @throws SecurityException if {@code admin} is not a device or profile owner.
Edman Anjosa5f2fb12016-12-19 11:25:54 -08006451 * @see #setDelegatedScopes
6452 * @see #DELEGATION_BLOCK_UNINSTALL
Kenny Guyc13053b2014-05-29 14:17:17 +01006453 */
Edman Anjosa5f2fb12016-12-19 11:25:54 -08006454 public void setUninstallBlocked(@Nullable ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01006455 boolean uninstallBlocked) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006456 throwIfParentInstance("setUninstallBlocked");
Kenny Guyc13053b2014-05-29 14:17:17 +01006457 if (mService != null) {
6458 try {
Edman Anjosa5f2fb12016-12-19 11:25:54 -08006459 mService.setUninstallBlocked(admin, mContext.getPackageName(), packageName,
6460 uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01006461 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006462 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01006463 }
6464 }
6465 }
6466
6467 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08006468 * Check whether the user has been blocked by device policy from uninstalling a package.
Rubin Xua97855b2014-11-07 05:41:00 +00006469 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00006470 * <p>
6471 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006472 * behavior of this API is changed such that passing {@code null} as the {@code admin} parameter
6473 * will return if any admin has blocked the uninstallation. Before L MR1, passing {@code null}
6474 * will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01006475 *
Robin Lee25e26452015-06-02 09:56:29 -07006476 * @param admin The name of the admin component whose blocking policy will be checked, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006477 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01006478 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00006479 * @return true if uninstallation is blocked.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006480 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyc13053b2014-05-29 14:17:17 +01006481 */
Robin Lee25e26452015-06-02 09:56:29 -07006482 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006483 throwIfParentInstance("isUninstallBlocked");
Kenny Guyc13053b2014-05-29 14:17:17 +01006484 if (mService != null) {
6485 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01006486 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01006487 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006488 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01006489 }
6490 }
6491 return false;
6492 }
Svetoslav976e8bd2014-07-16 15:12:03 -07006493
6494 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006495 * Called by the profile owner of a managed profile to enable widget providers from a given
6496 * package to be available in the parent profile. As a result the user will be able to add
6497 * widgets from the white-listed package running under the profile to a widget host which runs
6498 * under the parent profile, for example the home screen. Note that a package may have zero or
6499 * more provider components, where each component provides a different widget type.
Svetoslav976e8bd2014-07-16 15:12:03 -07006500 * <p>
6501 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07006502 *
6503 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6504 * @param packageName The package from which widget providers are white-listed.
6505 * @return Whether the package was added.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006506 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07006507 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
6508 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
6509 */
Robin Lee25e26452015-06-02 09:56:29 -07006510 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006511 throwIfParentInstance("addCrossProfileWidgetProvider");
Svetoslav976e8bd2014-07-16 15:12:03 -07006512 if (mService != null) {
6513 try {
6514 return mService.addCrossProfileWidgetProvider(admin, packageName);
6515 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006516 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07006517 }
6518 }
6519 return false;
6520 }
6521
6522 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07006523 * Called by the profile owner of a managed profile to disable widget providers from a given
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006524 * package to be available in the parent profile. For this method to take effect the package
6525 * should have been added via
6526 * {@link #addCrossProfileWidgetProvider( android.content.ComponentName, String)}.
Svetoslav976e8bd2014-07-16 15:12:03 -07006527 * <p>
6528 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07006529 *
6530 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006531 * @param packageName The package from which widget providers are no longer white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07006532 * @return Whether the package was removed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006533 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07006534 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
6535 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
6536 */
Esteban Talavera62399912016-01-11 15:37:55 +00006537 public boolean removeCrossProfileWidgetProvider(
6538 @NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006539 throwIfParentInstance("removeCrossProfileWidgetProvider");
Svetoslav976e8bd2014-07-16 15:12:03 -07006540 if (mService != null) {
6541 try {
6542 return mService.removeCrossProfileWidgetProvider(admin, packageName);
6543 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006544 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07006545 }
6546 }
6547 return false;
6548 }
6549
6550 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07006551 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07006552 * available in the parent profile.
6553 *
6554 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6555 * @return The white-listed package list.
Svetoslav976e8bd2014-07-16 15:12:03 -07006556 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
6557 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006558 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07006559 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006560 public @NonNull List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006561 throwIfParentInstance("getCrossProfileWidgetProviders");
Svetoslav976e8bd2014-07-16 15:12:03 -07006562 if (mService != null) {
6563 try {
6564 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
6565 if (providers != null) {
6566 return providers;
6567 }
6568 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006569 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07006570 }
6571 }
6572 return Collections.emptyList();
6573 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006574
6575 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08006576 * Called by profile or device owners to set the user's photo.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006577 *
6578 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6579 * @param icon the bitmap to set as the photo.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006580 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006581 */
Robin Lee25e26452015-06-02 09:56:29 -07006582 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006583 throwIfParentInstance("setUserIcon");
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006584 try {
6585 mService.setUserIcon(admin, icon);
6586 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006587 throw re.rethrowFromSystemServer();
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006588 }
6589 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04006590
6591 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01006592 * Called by device owners to set a local system update policy. When a new policy is set,
6593 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00006594 *
Robin Lee25e26452015-06-02 09:56:29 -07006595 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006596 * components in the device owner package can set system update policies and the most
6597 * recent policy takes effect.
Robin Lee25e26452015-06-02 09:56:29 -07006598 * @param policy the new policy, or {@code null} to clear the current policy.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006599 * @throws SecurityException if {@code admin} is not a device owner.
Rubin Xu5faad8e2015-04-20 17:43:48 +01006600 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00006601 */
Robin Lee25e26452015-06-02 09:56:29 -07006602 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006603 throwIfParentInstance("setSystemUpdatePolicy");
Rubin Xu8027a4f2015-03-10 17:52:37 +00006604 if (mService != null) {
6605 try {
Robin Lee25e26452015-06-02 09:56:29 -07006606 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00006607 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006608 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00006609 }
6610 }
6611 }
6612
6613 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01006614 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00006615 *
Robin Lee25e26452015-06-02 09:56:29 -07006616 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00006617 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006618 public @Nullable SystemUpdatePolicy getSystemUpdatePolicy() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006619 throwIfParentInstance("getSystemUpdatePolicy");
Rubin Xu8027a4f2015-03-10 17:52:37 +00006620 if (mService != null) {
6621 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01006622 return mService.getSystemUpdatePolicy();
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 return null;
6628 }
Benjamin Franze36087e2015-04-07 16:40:34 +01006629
6630 /**
6631 * Called by a device owner to disable the keyguard altogether.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006632 * <p>
6633 * Setting the keyguard to disabled has the same effect as choosing "None" as the screen lock
6634 * type. However, this call has no effect if a password, pin or pattern is currently set. If a
6635 * password, pin or pattern is set after the keyguard was disabled, the keyguard stops being
6636 * disabled.
Benjamin Franze36087e2015-04-07 16:40:34 +01006637 *
6638 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01006639 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01006640 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006641 * place. {@code true} otherwise.
6642 * @throws SecurityException if {@code admin} is not a device owner.
Benjamin Franze36087e2015-04-07 16:40:34 +01006643 */
Robin Lee25e26452015-06-02 09:56:29 -07006644 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006645 throwIfParentInstance("setKeyguardDisabled");
Benjamin Franze36087e2015-04-07 16:40:34 +01006646 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01006647 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01006648 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006649 throw re.rethrowFromSystemServer();
Benjamin Franze36087e2015-04-07 16:40:34 +01006650 }
6651 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00006652
6653 /**
Benjamin Franzbece8062015-05-06 12:14:31 +01006654 * Called by device owner to disable the status bar. Disabling the status bar blocks
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006655 * notifications, quick settings and other screen overlays that allow escaping from a single use
6656 * device.
Benjamin Franzea2ec972015-03-16 17:18:09 +00006657 *
6658 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01006659 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006660 * @return {@code false} if attempting to disable the status bar failed. {@code true} otherwise.
6661 * @throws SecurityException if {@code admin} is not a device owner.
Benjamin Franzea2ec972015-03-16 17:18:09 +00006662 */
Robin Lee25e26452015-06-02 09:56:29 -07006663 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006664 throwIfParentInstance("setStatusBarDisabled");
Benjamin Franzea2ec972015-03-16 17:18:09 +00006665 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01006666 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00006667 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006668 throw re.rethrowFromSystemServer();
Benjamin Franzea2ec972015-03-16 17:18:09 +00006669 }
6670 }
Rubin Xudc105cc2015-04-14 23:38:01 +01006671
6672 /**
Charles Hedea0c3b2017-01-13 10:04:12 +00006673 * Called by the system update service to notify device and profile owners of pending system
6674 * updates.
Rubin Xudc105cc2015-04-14 23:38:01 +01006675 *
Charles Hedea0c3b2017-01-13 10:04:12 +00006676 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
6677 * permission. This method should only be used when it is unknown whether the pending system
6678 * update is a security patch. Otherwise, use
6679 * {@link #notifyPendingSystemUpdate(long, boolean)}.
6680 *
6681 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()}
6682 * indicating when the current pending update was first available. {@code -1} if no
6683 * update is available.
6684 * @see #notifyPendingSystemUpdate(long, boolean)
Rubin Xudc105cc2015-04-14 23:38:01 +01006685 * @hide
6686 */
6687 @SystemApi
6688 public void notifyPendingSystemUpdate(long updateReceivedTime) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006689 throwIfParentInstance("notifyPendingSystemUpdate");
Rubin Xudc105cc2015-04-14 23:38:01 +01006690 if (mService != null) {
6691 try {
Charles Hedea0c3b2017-01-13 10:04:12 +00006692 mService.notifyPendingSystemUpdate(SystemUpdateInfo.of(updateReceivedTime));
6693 } catch (RemoteException re) {
6694 throw re.rethrowFromSystemServer();
6695 }
6696 }
6697 }
6698
6699 /**
6700 * Called by the system update service to notify device and profile owners of pending system
6701 * updates.
6702 *
6703 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
6704 * permission. This method should be used instead of {@link #notifyPendingSystemUpdate(long)}
6705 * when it is known whether the pending system update is a security patch.
6706 *
6707 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()}
6708 * indicating when the current pending update was first available. {@code -1} if no
6709 * update is available.
6710 * @param isSecurityPatch {@code true} if this system update is purely a security patch;
6711 * {@code false} if not.
6712 * @see #notifyPendingSystemUpdate(long)
6713 * @hide
6714 */
6715 @SystemApi
6716 public void notifyPendingSystemUpdate(long updateReceivedTime, boolean isSecurityPatch) {
6717 throwIfParentInstance("notifyPendingSystemUpdate");
6718 if (mService != null) {
6719 try {
6720 mService.notifyPendingSystemUpdate(SystemUpdateInfo.of(updateReceivedTime,
6721 isSecurityPatch));
Rubin Xudc105cc2015-04-14 23:38:01 +01006722 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006723 throw re.rethrowFromSystemServer();
Rubin Xudc105cc2015-04-14 23:38:01 +01006724 }
6725 }
6726 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04006727
6728 /**
Pavel Grafovd65799e2016-12-02 11:21:45 +00006729 * Called by device or profile owners to get information about a pending system update.
6730 *
6731 * @param admin Which profile or device owner this request is associated with.
6732 * @return Information about a pending system update or {@code null} if no update pending.
6733 * @throws SecurityException if {@code admin} is not a device or profile owner.
6734 * @see DeviceAdminReceiver#onSystemUpdatePending(Context, Intent, long)
6735 */
6736 public @Nullable SystemUpdateInfo getPendingSystemUpdate(@NonNull ComponentName admin) {
6737 throwIfParentInstance("getPendingSystemUpdate");
6738 try {
6739 return mService.getPendingSystemUpdate(admin);
6740 } catch (RemoteException re) {
6741 throw re.rethrowFromSystemServer();
6742 }
6743 }
6744
6745 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006746 * Set the default response for future runtime permission requests by applications. This
6747 * function can be called by a device owner, profile owner, or by a delegate given the
6748 * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}.
6749 * The policy can allow for normal operation which prompts the user to grant a permission, or
6750 * can allow automatic granting or denying of runtime permission requests by an application.
6751 * This also applies to new permissions declared by app updates. When a permission is denied or
6752 * granted this way, the effect is equivalent to setting the permission * grant state via
6753 * {@link #setPermissionGrantState}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006754 * <p/>
6755 * As this policy only acts on runtime permission requests, it only applies to applications
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07006756 * built with a {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Benjamin Franz45dd6662015-07-08 14:24:14 +01006757 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07006758 * @param admin Which profile or device owner this request is associated with.
6759 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006760 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
6761 * @throws SecurityException if {@code admin} is not a device or profile owner.
Benjamin Franz45dd6662015-07-08 14:24:14 +01006762 * @see #setPermissionGrantState
Edman Anjos52088e42017-01-13 22:26:17 +01006763 * @see #setDelegatedScopes
6764 * @see #DELEGATION_PERMISSION_GRANT
Amith Yamasanid49489b2015-04-28 14:00:26 -07006765 */
Robin Lee25e26452015-06-02 09:56:29 -07006766 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006767 throwIfParentInstance("setPermissionPolicy");
Amith Yamasanid49489b2015-04-28 14:00:26 -07006768 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006769 mService.setPermissionPolicy(admin, mContext.getPackageName(), policy);
Amith Yamasanid49489b2015-04-28 14:00:26 -07006770 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006771 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07006772 }
6773 }
6774
6775 /**
6776 * Returns the current runtime permission policy set by the device or profile owner. The
6777 * default is {@link #PERMISSION_POLICY_PROMPT}.
Edman Anjos52088e42017-01-13 22:26:17 +01006778 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07006779 * @param admin Which profile or device owner this request is associated with.
6780 * @return the current policy for future permission requests.
6781 */
Esteban Talavera28b95702015-06-24 15:23:42 +01006782 public int getPermissionPolicy(ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006783 throwIfParentInstance("getPermissionPolicy");
Amith Yamasanid49489b2015-04-28 14:00:26 -07006784 try {
6785 return mService.getPermissionPolicy(admin);
6786 } 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 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006792 * Sets the grant state of a runtime permission for a specific application. The state can be
6793 * {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it through the UI,
6794 * {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission is denied and the user
6795 * cannot manage it through the UI, and {@link #PERMISSION_GRANT_STATE_GRANTED granted} in which
6796 * the permission is granted and the user cannot manage it through the UI. This might affect all
6797 * permissions in a group that the runtime permission belongs to. This method can only be called
Edman Anjos52088e42017-01-13 22:26:17 +01006798 * by a profile owner, device owner, or a delegate given the
6799 * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006800 * <p/>
6801 * Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not revoke
6802 * the permission. It retains the previous grant, if any.
6803 * <p/>
6804 * Permissions can be granted or revoked only for applications built with a
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07006805 * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07006806 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07006807 * @param admin Which profile or device owner this request is associated with.
6808 * @param packageName The application to grant or revoke a permission to.
6809 * @param permission The permission to grant or revoke.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006810 * @param grantState The permission grant state which is one of
6811 * {@link #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
6812 * {@link #PERMISSION_GRANT_STATE_GRANTED},
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006813 * @return whether the permission was successfully granted or revoked.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006814 * @throws SecurityException if {@code admin} is not a device or profile owner.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006815 * @see #PERMISSION_GRANT_STATE_DENIED
6816 * @see #PERMISSION_GRANT_STATE_DEFAULT
6817 * @see #PERMISSION_GRANT_STATE_GRANTED
Edman Anjos52088e42017-01-13 22:26:17 +01006818 * @see #setDelegatedScopes
6819 * @see #DELEGATION_PERMISSION_GRANT
Amith Yamasanid49489b2015-04-28 14:00:26 -07006820 */
Robin Lee25e26452015-06-02 09:56:29 -07006821 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006822 String permission, int grantState) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006823 throwIfParentInstance("setPermissionGrantState");
Amith Yamasanid49489b2015-04-28 14:00:26 -07006824 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006825 return mService.setPermissionGrantState(admin, mContext.getPackageName(), packageName,
6826 permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07006827 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006828 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07006829 }
6830 }
Amith Yamasani184b3752015-05-22 13:00:51 -07006831
6832 /**
Edman Anjos52088e42017-01-13 22:26:17 +01006833 * Returns the current grant state of a runtime permission for a specific application. This
6834 * function can be called by a device owner, profile owner, or by a delegate given the
6835 * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}.
Amith Yamasani184b3752015-05-22 13:00:51 -07006836 *
Edman Anjos52088e42017-01-13 22:26:17 +01006837 * @param admin Which profile or device owner this request is associated with, or {@code null}
6838 * if the caller is a permission grant delegate.
Amith Yamasani184b3752015-05-22 13:00:51 -07006839 * @param packageName The application to check the grant state for.
6840 * @param permission The permission to check for.
6841 * @return the current grant state specified by device policy. If the profile or device owner
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006842 * has not set a grant state, the return value is
6843 * {@link #PERMISSION_GRANT_STATE_DEFAULT}. This does not indicate whether or not the
6844 * permission is currently granted for the package.
6845 * <p/>
6846 * If a grant state was set by the profile or device owner, then the return value will
6847 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or
6848 * {@link #PERMISSION_GRANT_STATE_GRANTED}, which indicates if the permission is
6849 * currently denied or granted.
6850 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasani184b3752015-05-22 13:00:51 -07006851 * @see #setPermissionGrantState(ComponentName, String, String, int)
6852 * @see PackageManager#checkPermission(String, String)
Edman Anjos52088e42017-01-13 22:26:17 +01006853 * @see #setDelegatedScopes
6854 * @see #DELEGATION_PERMISSION_GRANT
Amith Yamasani184b3752015-05-22 13:00:51 -07006855 */
Bartosz Fabianowski4b0624f2017-01-16 11:47:28 +01006856 public int getPermissionGrantState(@Nullable ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07006857 String permission) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006858 throwIfParentInstance("getPermissionGrantState");
Amith Yamasani184b3752015-05-22 13:00:51 -07006859 try {
Edman Anjos52088e42017-01-13 22:26:17 +01006860 return mService.getPermissionGrantState(admin, mContext.getPackageName(), packageName,
6861 permission);
Amith Yamasani184b3752015-05-22 13:00:51 -07006862 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006863 throw re.rethrowFromSystemServer();
Amith Yamasani184b3752015-05-22 13:00:51 -07006864 }
6865 }
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006866
6867 /**
Esteban Talavera01576862016-12-15 11:16:44 +00006868 * Returns whether it is possible for the caller to initiate provisioning of a managed profile
6869 * or device, setting itself as the device or profile owner.
6870 *
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006871 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
6872 * {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Esteban Talavera01576862016-12-15 11:16:44 +00006873 * @return whether provisioning a managed profile or device is possible.
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006874 * @throws IllegalArgumentException if the supplied action is not valid.
6875 */
Esteban Talavera01576862016-12-15 11:16:44 +00006876 public boolean isProvisioningAllowed(@NonNull String action) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006877 throwIfParentInstance("isProvisioningAllowed");
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006878 try {
Esteban Talavera01576862016-12-15 11:16:44 +00006879 return mService.isProvisioningAllowed(action, mContext.getPackageName());
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006880 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006881 throw re.rethrowFromSystemServer();
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006882 }
6883 }
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006884
6885 /**
Esteban Talavera01576862016-12-15 11:16:44 +00006886 * Checks whether it is possible to initiate provisioning a managed device,
6887 * profile or user, setting the given package as owner.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00006888 *
6889 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
6890 * {@link #ACTION_PROVISION_MANAGED_PROFILE},
6891 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE},
6892 * {@link #ACTION_PROVISION_MANAGED_USER}
Esteban Talavera01576862016-12-15 11:16:44 +00006893 * @param packageName The package of the component that would be set as device, user, or profile
6894 * owner.
6895 * @return A {@link ProvisioningPreCondition} value indicating whether provisioning is allowed.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00006896 * @hide
6897 */
Esteban Talavera01576862016-12-15 11:16:44 +00006898 public @ProvisioningPreCondition int checkProvisioningPreCondition(
6899 String action, @NonNull String packageName) {
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00006900 try {
Esteban Talavera01576862016-12-15 11:16:44 +00006901 return mService.checkProvisioningPreCondition(action, packageName);
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00006902 } catch (RemoteException re) {
6903 throw re.rethrowFromSystemServer();
6904 }
6905 }
6906
6907 /**
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006908 * Return if this user is a managed profile of another user. An admin can become the profile
6909 * owner of a managed profile with {@link #ACTION_PROVISION_MANAGED_PROFILE} and of a managed
Kenny Guyffa38402016-03-31 16:40:57 +01006910 * user with {@link #createAndManageUser}
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006911 * @param admin Which profile owner this request is associated with.
6912 * @return if this user is a managed profile of another user.
6913 */
6914 public boolean isManagedProfile(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006915 throwIfParentInstance("isManagedProfile");
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006916 try {
6917 return mService.isManagedProfile(admin);
6918 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006919 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006920 }
6921 }
6922
6923 /**
6924 * @hide
6925 * Return if this user is a system-only user. An admin can manage a device from a system only
6926 * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}.
6927 * @param admin Which device owner this request is associated with.
6928 * @return if this user is a system-only user.
6929 */
6930 public boolean isSystemOnlyUser(@NonNull ComponentName admin) {
6931 try {
6932 return mService.isSystemOnlyUser(admin);
6933 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006934 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006935 }
6936 }
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006937
6938 /**
6939 * Called by device owner to get the MAC address of the Wi-Fi device.
6940 *
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08006941 * @param admin Which device owner this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006942 * @return the MAC address of the Wi-Fi device, or null when the information is not available.
6943 * (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.)
6944 * <p>
6945 * The address will be in the {@code XX:XX:XX:XX:XX:XX} format.
6946 * @throws SecurityException if {@code admin} is not a device owner.
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006947 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006948 public @Nullable String getWifiMacAddress(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006949 throwIfParentInstance("getWifiMacAddress");
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006950 try {
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08006951 return mService.getWifiMacAddress(admin);
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006952 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006953 throw re.rethrowFromSystemServer();
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006954 }
6955 }
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00006956
6957 /**
Mahaver Chopra1216ae52016-03-11 15:39:48 +00006958 * Called by device owner to reboot the device. If there is an ongoing call on the device,
6959 * throws an {@link IllegalStateException}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006960 * @param admin Which device owner the request is associated with.
Mahaver Chopra1216ae52016-03-11 15:39:48 +00006961 * @throws IllegalStateException if device has an ongoing call.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006962 * @throws SecurityException if {@code admin} is not a device owner.
Mahaver Chopra1216ae52016-03-11 15:39:48 +00006963 * @see TelephonyManager#CALL_STATE_IDLE
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00006964 */
6965 public void reboot(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006966 throwIfParentInstance("reboot");
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00006967 try {
6968 mService.reboot(admin);
6969 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006970 throw re.rethrowFromSystemServer();
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00006971 }
6972 }
Kenny Guy06de4e72015-12-22 12:07:39 +00006973
6974 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006975 * Called by a device admin to set the short support message. This will be displayed to the user
6976 * in settings screens where funtionality has been disabled by the admin. The message should be
6977 * limited to a short statement such as "This setting is disabled by your administrator. Contact
6978 * someone@example.com for support." If the message is longer than 200 characters it may be
6979 * truncated.
6980 * <p>
6981 * If the short support message needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006982 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
6983 * and set a new version of this string accordingly.
6984 *
Kenny Guy06de4e72015-12-22 12:07:39 +00006985 * @see #setLongSupportMessage
Kenny Guy06de4e72015-12-22 12:07:39 +00006986 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006987 * @param message Short message to be displayed to the user in settings or null to clear the
6988 * existing message.
6989 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00006990 */
6991 public void setShortSupportMessage(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006992 @Nullable CharSequence message) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006993 throwIfParentInstance("setShortSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00006994 if (mService != null) {
6995 try {
6996 mService.setShortSupportMessage(admin, message);
6997 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006998 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006999 }
7000 }
7001 }
7002
7003 /**
7004 * Called by a device admin to get the short support message.
7005 *
7006 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007007 * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)} or
7008 * null if no message has been set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007009 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00007010 */
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007011 public CharSequence getShortSupportMessage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007012 throwIfParentInstance("getShortSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00007013 if (mService != null) {
7014 try {
7015 return mService.getShortSupportMessage(admin);
7016 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007017 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00007018 }
7019 }
7020 return null;
7021 }
7022
7023 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007024 * Called by a device admin to set the long support message. This will be displayed to the user
7025 * in the device administators settings screen.
7026 * <p>
7027 * If the long support message needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007028 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
7029 * and set a new version of this string accordingly.
7030 *
Kenny Guy06de4e72015-12-22 12:07:39 +00007031 * @see #setShortSupportMessage
Kenny Guy06de4e72015-12-22 12:07:39 +00007032 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007033 * @param message Long message to be displayed to the user in settings or null to clear the
7034 * existing message.
7035 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00007036 */
7037 public void setLongSupportMessage(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007038 @Nullable CharSequence message) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007039 throwIfParentInstance("setLongSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00007040 if (mService != null) {
7041 try {
7042 mService.setLongSupportMessage(admin, message);
7043 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007044 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00007045 }
7046 }
7047 }
7048
7049 /**
7050 * Called by a device admin to get the long support message.
7051 *
7052 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007053 * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)} or
7054 * null if no message has been set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007055 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00007056 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007057 public @Nullable CharSequence getLongSupportMessage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007058 throwIfParentInstance("getLongSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00007059 if (mService != null) {
7060 try {
7061 return mService.getLongSupportMessage(admin);
7062 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007063 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00007064 }
7065 }
7066 return null;
7067 }
7068
7069 /**
7070 * Called by the system to get the short support message.
7071 *
7072 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7073 * @param userHandle user id the admin is running as.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007074 * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)}
Kenny Guy06de4e72015-12-22 12:07:39 +00007075 *
7076 * @hide
7077 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007078 public @Nullable CharSequence getShortSupportMessageForUser(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007079 int userHandle) {
Kenny Guy06de4e72015-12-22 12:07:39 +00007080 if (mService != null) {
7081 try {
7082 return mService.getShortSupportMessageForUser(admin, userHandle);
7083 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007084 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00007085 }
7086 }
7087 return null;
7088 }
7089
7090
7091 /**
7092 * Called by the system to get the long support message.
7093 *
7094 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7095 * @param userHandle user id the admin is running as.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07007096 * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)}
Kenny Guy06de4e72015-12-22 12:07:39 +00007097 *
7098 * @hide
7099 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007100 public @Nullable CharSequence getLongSupportMessageForUser(
7101 @NonNull ComponentName admin, int userHandle) {
Kenny Guy06de4e72015-12-22 12:07:39 +00007102 if (mService != null) {
7103 try {
7104 return mService.getLongSupportMessageForUser(admin, userHandle);
7105 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007106 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00007107 }
7108 }
7109 return null;
7110 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00007111
7112 /**
Esteban Talavera62399912016-01-11 15:37:55 +00007113 * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager}
7114 * whose calls act on the parent profile.
Benjamin Franz66b45f02016-04-05 19:12:39 +01007115 *
7116 * <p>The following methods are supported for the parent instance, all other methods will
7117 * throw a SecurityException when called on the parent instance:
7118 * <ul>
7119 * <li>{@link #getPasswordQuality}</li>
7120 * <li>{@link #setPasswordQuality}</li>
7121 * <li>{@link #getPasswordMinimumLength}</li>
7122 * <li>{@link #setPasswordMinimumLength}</li>
7123 * <li>{@link #getPasswordMinimumUpperCase}</li>
7124 * <li>{@link #setPasswordMinimumUpperCase}</li>
7125 * <li>{@link #getPasswordMinimumLowerCase}</li>
7126 * <li>{@link #setPasswordMinimumLowerCase}</li>
7127 * <li>{@link #getPasswordMinimumLetters}</li>
7128 * <li>{@link #setPasswordMinimumLetters}</li>
7129 * <li>{@link #getPasswordMinimumNumeric}</li>
7130 * <li>{@link #setPasswordMinimumNumeric}</li>
7131 * <li>{@link #getPasswordMinimumSymbols}</li>
7132 * <li>{@link #setPasswordMinimumSymbols}</li>
7133 * <li>{@link #getPasswordMinimumNonLetter}</li>
7134 * <li>{@link #setPasswordMinimumNonLetter}</li>
7135 * <li>{@link #getPasswordHistoryLength}</li>
7136 * <li>{@link #setPasswordHistoryLength}</li>
7137 * <li>{@link #getPasswordExpirationTimeout}</li>
7138 * <li>{@link #setPasswordExpirationTimeout}</li>
7139 * <li>{@link #getPasswordExpiration}</li>
Charles He8c760562016-10-25 16:36:53 +01007140 * <li>{@link #getPasswordMaximumLength}</li>
Benjamin Franz66b45f02016-04-05 19:12:39 +01007141 * <li>{@link #isActivePasswordSufficient}</li>
7142 * <li>{@link #getCurrentFailedPasswordAttempts}</li>
7143 * <li>{@link #getMaximumFailedPasswordsForWipe}</li>
7144 * <li>{@link #setMaximumFailedPasswordsForWipe}</li>
7145 * <li>{@link #getMaximumTimeToLock}</li>
7146 * <li>{@link #setMaximumTimeToLock}</li>
7147 * <li>{@link #lockNow}</li>
7148 * <li>{@link #getKeyguardDisabledFeatures}</li>
7149 * <li>{@link #setKeyguardDisabledFeatures}</li>
7150 * <li>{@link #getTrustAgentConfiguration}</li>
7151 * <li>{@link #setTrustAgentConfiguration}</li>
Michal Karpinskia20d8bb2016-11-23 12:09:08 +00007152 * <li>{@link #getRequiredStrongAuthTimeout}</li>
7153 * <li>{@link #setRequiredStrongAuthTimeout}</li>
Benjamin Franz66b45f02016-04-05 19:12:39 +01007154 * </ul>
Clara Bayarri3e826ef2015-12-14 17:51:22 +00007155 *
7156 * @return a new instance of {@link DevicePolicyManager} that acts on the parent profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007157 * @throws SecurityException if {@code admin} is not a profile owner.
Clara Bayarri3e826ef2015-12-14 17:51:22 +00007158 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007159 public @NonNull DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007160 throwIfParentInstance("getParentProfileInstance");
Clara Bayarri3e826ef2015-12-14 17:51:22 +00007161 try {
7162 if (!mService.isManagedProfile(admin)) {
7163 throw new SecurityException("The current user does not have a parent profile.");
7164 }
Jeff Sharkey49ca5292016-05-10 12:54:45 -06007165 return new DevicePolicyManager(mContext, mService, true);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007166 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007167 throw e.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007168 }
7169 }
7170
7171 /**
Esteban Talaverad36dd152016-12-15 08:51:45 +00007172 * Called by device owner to control the security logging feature.
Michal Karpinski6235a942016-03-15 12:07:23 +00007173 *
7174 * <p> Security logs contain various information intended for security auditing purposes.
7175 * See {@link SecurityEvent} for details.
7176 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00007177 * <p><strong>Note:</strong> The device owner won't be able to retrieve security logs if there
7178 * are unaffiliated secondary users or profiles on the device, regardless of whether the
7179 * feature is enabled. Logs will be discarded if the internal buffer fills up while waiting for
7180 * all users to become affiliated. Therefore it's recommended that affiliation ids are set for
7181 * new users as soon as possible after provisioning via {@link #setAffiliationIds}.
Michal Karpinskib58e4962016-03-01 14:55:10 +00007182 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007183 * @param admin Which device owner this request is associated with.
Michal Karpinski6235a942016-03-15 12:07:23 +00007184 * @param enabled whether security logging should be enabled or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007185 * @throws SecurityException if {@code admin} is not a device owner.
Michal Karpinski6235a942016-03-15 12:07:23 +00007186 * @see #retrieveSecurityLogs
7187 */
7188 public void setSecurityLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007189 throwIfParentInstance("setSecurityLoggingEnabled");
Michal Karpinski6235a942016-03-15 12:07:23 +00007190 try {
7191 mService.setSecurityLoggingEnabled(admin, enabled);
7192 } catch (RemoteException re) {
7193 throw re.rethrowFromSystemServer();
7194 }
7195 }
7196
7197 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00007198 * Return whether security logging is enabled or not by the device owner.
7199 *
7200 * <p>Can only be called by the device owner, otherwise a {@link SecurityException} will be
7201 * thrown.
7202 *
7203 * @param admin Which device owner this request is associated with.
7204 * @return {@code true} if security logging is enabled by device owner, {@code false} otherwise.
7205 * @throws SecurityException if {@code admin} is not a device owner.
7206 */
7207 public boolean isSecurityLoggingEnabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007208 throwIfParentInstance("isSecurityLoggingEnabled");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007209 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00007210 return mService.isSecurityLoggingEnabled(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007211 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007212 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007213 }
7214 }
7215
7216 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00007217 * Called by device owner to retrieve all new security logging entries since the last call to
7218 * this API after device boots.
7219 *
7220 * <p> Access to the logs is rate limited and it will only return new logs after the device
7221 * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}.
7222 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00007223 * <p>If there is any other user or profile on the device, it must be affiliated with the
7224 * device owner. Otherwise a {@link SecurityException} will be thrown. See
7225 * {@link #setAffiliationIds}
Michal Karpinskib58e4962016-03-01 14:55:10 +00007226 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007227 * @param admin Which device owner this request is associated with.
Michal Karpinski6235a942016-03-15 12:07:23 +00007228 * @return the new batch of security logs which is a list of {@link SecurityEvent},
7229 * or {@code null} if rate limitation is exceeded or if logging is currently disabled.
Esteban Talaverad36dd152016-12-15 08:51:45 +00007230 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
7231 * profile or secondary user that is not affiliated with the device owner user.
7232 * @see DeviceAdminReceiver#onSecurityLogsAvailable
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007233 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007234 public @Nullable List<SecurityEvent> retrieveSecurityLogs(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007235 throwIfParentInstance("retrieveSecurityLogs");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007236 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00007237 ParceledListSlice<SecurityEvent> list = mService.retrieveSecurityLogs(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007238 if (list != null) {
7239 return list.getList();
7240 } else {
7241 // Rate limit exceeded.
7242 return null;
7243 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00007244 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007245 throw re.rethrowFromSystemServer();
Clara Bayarri3e826ef2015-12-14 17:51:22 +00007246 }
7247 }
Benjamin Franz59720bb2016-01-18 15:26:11 +00007248
7249 /**
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00007250 * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent
7251 * profile.
7252 *
7253 * @hide
7254 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007255 public @NonNull DevicePolicyManager getParentProfileInstance(UserInfo uInfo) {
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00007256 mContext.checkSelfPermission(
7257 android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS);
7258 if (!uInfo.isManagedProfile()) {
7259 throw new SecurityException("The user " + uInfo.id
7260 + " does not have a parent profile.");
7261 }
Jeff Sharkey49ca5292016-05-10 12:54:45 -06007262 return new DevicePolicyManager(mContext, mService, true);
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00007263 }
7264
7265 /**
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007266 * Called by device owners to retrieve device logs from before the device's last reboot.
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007267 * <p>
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01007268 * <strong> This API is not supported on all devices. Calling this API on unsupported devices
7269 * will result in {@code null} being returned. The device logs are retrieved from a RAM region
7270 * which is not guaranteed to be corruption-free during power cycles, as a result be cautious
7271 * about data corruption when parsing. </strong>
Esteban Talaverad36dd152016-12-15 08:51:45 +00007272 *
7273 * <p>If there is any other user or profile on the device, it must be affiliated with the
7274 * device owner. Otherwise a {@link SecurityException} will be thrown. See
7275 * {@link #setAffiliationIds}
Michal Karpinskib58e4962016-03-01 14:55:10 +00007276 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007277 * @param admin Which device owner this request is associated with.
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01007278 * @return Device logs from before the latest reboot of the system, or {@code null} if this API
7279 * is not supported on the device.
Esteban Talaverad36dd152016-12-15 08:51:45 +00007280 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
7281 * profile or secondary user that is not affiliated with the device owner user.
7282 * @see #retrieveSecurityLogs
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007283 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007284 public @Nullable List<SecurityEvent> retrievePreRebootSecurityLogs(
7285 @NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007286 throwIfParentInstance("retrievePreRebootSecurityLogs");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007287 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00007288 ParceledListSlice<SecurityEvent> list = mService.retrievePreRebootSecurityLogs(admin);
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01007289 if (list != null) {
7290 return list.getList();
7291 } else {
7292 return null;
7293 }
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007294 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007295 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00007296 }
7297 }
7298
7299 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007300 * Called by a profile owner of a managed profile to set the color used for customization. This
7301 * color is used as background color of the confirm credentials screen for that user. The
Clara Bayarri8d0bd7fa2016-03-30 14:59:58 +01007302 * default color is teal (#00796B).
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007303 * <p>
7304 * The confirm credentials screen can be created using
Benjamin Franz59720bb2016-01-18 15:26:11 +00007305 * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}.
7306 *
7307 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinski74cd7302016-04-12 15:17:36 +01007308 * @param color The 24bit (0xRRGGBB) representation of the color to be used.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007309 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz59720bb2016-01-18 15:26:11 +00007310 */
7311 public void setOrganizationColor(@NonNull ComponentName admin, int color) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007312 throwIfParentInstance("setOrganizationColor");
Benjamin Franz59720bb2016-01-18 15:26:11 +00007313 try {
Michal Karpinski74cd7302016-04-12 15:17:36 +01007314 // always enforce alpha channel to have 100% opacity
7315 color |= 0xFF000000;
Benjamin Franz59720bb2016-01-18 15:26:11 +00007316 mService.setOrganizationColor(admin, color);
7317 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007318 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00007319 }
7320 }
7321
7322 /**
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00007323 * @hide
7324 *
7325 * Sets the color used for customization.
7326 *
Michal Karpinski74cd7302016-04-12 15:17:36 +01007327 * @param color The 24bit (0xRRGGBB) representation of the color to be used.
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00007328 * @param userId which user to set the color to.
7329 * @RequiresPermission(allOf = {
7330 * Manifest.permission.MANAGE_USERS,
7331 * Manifest.permission.INTERACT_ACROSS_USERS_FULL})
7332 */
7333 public void setOrganizationColorForUser(@ColorInt int color, @UserIdInt int userId) {
7334 try {
Michal Karpinski74cd7302016-04-12 15:17:36 +01007335 // always enforce alpha channel to have 100% opacity
7336 color |= 0xFF000000;
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00007337 mService.setOrganizationColorForUser(color, userId);
7338 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007339 throw re.rethrowFromSystemServer();
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00007340 }
7341 }
7342
7343 /**
Benjamin Franz59720bb2016-01-18 15:26:11 +00007344 * Called by a profile owner of a managed profile to retrieve the color used for customization.
7345 * This color is used as background color of the confirm credentials screen for that user.
7346 *
7347 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinski74cd7302016-04-12 15:17:36 +01007348 * @return The 24bit (0xRRGGBB) representation of the color to be used.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007349 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz59720bb2016-01-18 15:26:11 +00007350 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01007351 public @ColorInt int getOrganizationColor(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007352 throwIfParentInstance("getOrganizationColor");
Benjamin Franz59720bb2016-01-18 15:26:11 +00007353 try {
7354 return mService.getOrganizationColor(admin);
7355 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007356 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00007357 }
7358 }
7359
7360 /**
7361 * @hide
7362 * Retrieve the customization color for a given user.
7363 *
7364 * @param userHandle The user id of the user we're interested in.
Michal Karpinski74cd7302016-04-12 15:17:36 +01007365 * @return The 24bit (0xRRGGBB) representation of the color to be used.
Benjamin Franz59720bb2016-01-18 15:26:11 +00007366 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01007367 public @ColorInt int getOrganizationColorForUser(int userHandle) {
Benjamin Franz59720bb2016-01-18 15:26:11 +00007368 try {
7369 return mService.getOrganizationColorForUser(userHandle);
7370 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007371 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00007372 }
7373 }
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007374
7375 /**
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01007376 * Called by the device owner or profile owner to set the name of the organization under
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007377 * management.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007378 * <p>
7379 * If the organization name needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007380 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
7381 * and set a new version of this string accordingly.
7382 *
7383 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7384 * @param title The organization name or {@code null} to clear a previously set name.
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01007385 * @throws SecurityException if {@code admin} is not a device or profile owner.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007386 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01007387 public void setOrganizationName(@NonNull ComponentName admin, @Nullable CharSequence title) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007388 throwIfParentInstance("setOrganizationName");
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007389 try {
7390 mService.setOrganizationName(admin, title);
7391 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007392 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007393 }
7394 }
7395
7396 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007397 * Called by a profile owner of a managed profile to retrieve the name of the organization under
7398 * management.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007399 *
7400 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7401 * @return The organization name or {@code null} if none is set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07007402 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007403 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007404 public @Nullable CharSequence getOrganizationName(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007405 throwIfParentInstance("getOrganizationName");
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007406 try {
7407 return mService.getOrganizationName(admin);
7408 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007409 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007410 }
7411 }
7412
7413 /**
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01007414 * Called by the system to retrieve the name of the organization managing the device.
7415 *
7416 * @return The organization name or {@code null} if none is set.
7417 * @throws SecurityException if the caller is not the device owner, does not hold the
7418 * MANAGE_USERS permission and is not the system.
7419 *
7420 * @hide
7421 */
7422 @SystemApi
7423 @TestApi
7424 public @Nullable CharSequence getDeviceOwnerOrganizationName() {
7425 try {
7426 return mService.getDeviceOwnerOrganizationName();
7427 } catch (RemoteException re) {
7428 throw re.rethrowFromSystemServer();
7429 }
7430 }
7431
7432 /**
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007433 * Retrieve the default title message used in the confirm credentials screen for a given user.
7434 *
7435 * @param userHandle The user id of the user we're interested in.
7436 * @return The organization name or {@code null} if none is set.
7437 *
7438 * @hide
7439 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07007440 public @Nullable CharSequence getOrganizationNameForUser(int userHandle) {
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007441 try {
7442 return mService.getOrganizationNameForUser(userHandle);
7443 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007444 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00007445 }
7446 }
7447
7448 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00007449 * @return the {@link UserProvisioningState} for the current user - for unmanaged users will
7450 * return {@link #STATE_USER_UNMANAGED}
7451 * @hide
7452 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00007453 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00007454 @UserProvisioningState
7455 public int getUserProvisioningState() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007456 throwIfParentInstance("getUserProvisioningState");
Alan Treadwayafad8782016-01-19 15:15:08 +00007457 if (mService != null) {
7458 try {
7459 return mService.getUserProvisioningState();
7460 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007461 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00007462 }
7463 }
7464 return STATE_USER_UNMANAGED;
7465 }
7466
7467 /**
7468 * Set the {@link UserProvisioningState} for the supplied user, if they are managed.
7469 *
7470 * @param state to store
7471 * @param userHandle for user
7472 * @hide
7473 */
7474 public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) {
7475 if (mService != null) {
7476 try {
7477 mService.setUserProvisioningState(state, userHandle);
7478 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007479 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00007480 }
7481 }
7482 }
7483
7484 /**
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007485 * Indicates the entity that controls the device or profile owner. Two users/profiles are
7486 * affiliated if the set of ids set by their device or profile owners intersect.
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007487 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00007488 * <p><strong>Note:</strong> Features that depend on user affiliation (such as security logging
7489 * or {@link #bindDeviceAdminServiceAsUser}) won't be available when a secondary user or profile
7490 * is created, until it becomes affiliated. Therefore it is recommended that the appropriate
7491 * affiliation ids are set by its profile owner as soon as possible after the user/profile is
7492 * created.
7493 *
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007494 * @param admin Which profile or device owner this request is associated with.
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007495 * @param ids A list of opaque non-empty affiliation ids. Duplicate elements will be ignored.
7496 *
7497 * @throws NullPointerException if {@code ids} is null or contains null elements.
7498 * @throws IllegalArgumentException if {@code ids} contains an empty string.
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007499 */
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007500 public void setAffiliationIds(@NonNull ComponentName admin, @NonNull List<String> ids) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007501 throwIfParentInstance("setAffiliationIds");
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007502 try {
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007503 mService.setAffiliationIds(admin, ids);
7504 } catch (RemoteException e) {
7505 throw e.rethrowFromSystemServer();
7506 }
7507 }
7508
7509 /**
7510 * Returns the list of affiliation ids previously set via {@link #setAffiliationIds}, or an
7511 * empty list if none have been set.
7512 */
7513 public @NonNull List<String> getAffiliationIds(@NonNull ComponentName admin) {
7514 throwIfParentInstance("getAffiliationIds");
7515 try {
7516 return mService.getAffiliationIds(admin);
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007517 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007518 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007519 }
7520 }
7521
7522 /**
7523 * @hide
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007524 * Returns whether this user/profile is affiliated with the device.
7525 * <p>
7526 * By definition, the user that the device owner runs on is always affiliated with the device.
7527 * Any other user/profile is considered affiliated with the device if the set specified by its
7528 * profile owner via {@link #setAffiliationIds} intersects with the device owner's.
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007529 *
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007530 */
7531 public boolean isAffiliatedUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007532 throwIfParentInstance("isAffiliatedUser");
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007533 try {
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007534 return mService.isAffiliatedUser();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007535 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007536 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007537 }
7538 }
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08007539
7540 /**
7541 * @hide
7542 * Returns whether the uninstall for {@code packageName} for the current user is in queue
7543 * to be started
7544 * @param packageName the package to check for
7545 * @return whether the uninstall intent for {@code packageName} is pending
7546 */
7547 public boolean isUninstallInQueue(String packageName) {
7548 try {
7549 return mService.isUninstallInQueue(packageName);
7550 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007551 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08007552 }
7553 }
7554
7555 /**
7556 * @hide
7557 * @param packageName the package containing active DAs to be uninstalled
7558 */
7559 public void uninstallPackageWithActiveAdmins(String packageName) {
7560 try {
7561 mService.uninstallPackageWithActiveAdmins(packageName);
7562 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007563 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08007564 }
7565 }
Benjamin Franzbc33c822016-04-15 08:57:52 +01007566
Kenny Guy38dcca52016-04-19 13:09:18 +01007567 /**
7568 * @hide
7569 * Remove a test admin synchronously without sending it a broadcast about being removed.
7570 * If the admin is a profile owner or device owner it will still be removed.
7571 *
7572 * @param userHandle user id to remove the admin for.
7573 * @param admin The administration compononent to remove.
7574 * @throws SecurityException if the caller is not shell / root or the admin package
7575 * isn't a test application see {@link ApplicationInfo#FLAG_TEST_APP}.
7576 */
7577 public void forceRemoveActiveAdmin(ComponentName adminReceiver, int userHandle) {
7578 try {
7579 mService.forceRemoveActiveAdmin(adminReceiver, userHandle);
7580 } catch (RemoteException re) {
7581 throw re.rethrowFromSystemServer();
7582 }
7583 }
7584
Mahaver Chopra790d1982016-07-07 16:06:49 +01007585 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007586 * Returns whether the device has been provisioned.
7587 *
7588 * <p>Not for use by third-party applications.
7589 *
Mahaver Chopra790d1982016-07-07 16:06:49 +01007590 * @hide
Mahaver Chopra790d1982016-07-07 16:06:49 +01007591 */
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007592 @SystemApi
Mahaver Chopra790d1982016-07-07 16:06:49 +01007593 public boolean isDeviceProvisioned() {
7594 try {
7595 return mService.isDeviceProvisioned();
7596 } catch (RemoteException re) {
7597 throw re.rethrowFromSystemServer();
7598 }
7599 }
7600
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007601 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007602 * Writes that the provisioning configuration has been applied.
7603 *
7604 * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS}
7605 * permission.
7606 *
7607 * <p>Not for use by third-party applications.
7608 *
7609 * @hide
7610 */
7611 @SystemApi
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007612 public void setDeviceProvisioningConfigApplied() {
7613 try {
7614 mService.setDeviceProvisioningConfigApplied();
7615 } catch (RemoteException re) {
7616 throw re.rethrowFromSystemServer();
7617 }
7618 }
7619
7620 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007621 * Returns whether the provisioning configuration has been applied.
7622 *
7623 * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS} permission.
7624 *
7625 * <p>Not for use by third-party applications.
7626 *
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007627 * @return whether the provisioning configuration has been applied.
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007628 *
7629 * @hide
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007630 */
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007631 @SystemApi
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007632 public boolean isDeviceProvisioningConfigApplied() {
7633 try {
7634 return mService.isDeviceProvisioningConfigApplied();
7635 } catch (RemoteException re) {
7636 throw re.rethrowFromSystemServer();
7637 }
7638 }
7639
Victor Chang9bfc65f2016-08-15 12:27:09 +01007640 /**
7641 * @hide
Victor Chang3577ed22016-08-25 18:49:26 +01007642 * Force update user setup completed status. This API has no effect on user build.
7643 * @throws {@link SecurityException} if the caller has no
Esteban Talavera01576862016-12-15 11:16:44 +00007644 * {@code android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS} or the caller is
7645 * not {@link UserHandle#SYSTEM_USER}
Victor Chang9bfc65f2016-08-15 12:27:09 +01007646 */
7647 public void forceUpdateUserSetupComplete() {
7648 try {
7649 mService.forceUpdateUserSetupComplete();
7650 } catch (RemoteException re) {
7651 throw re.rethrowFromSystemServer();
7652 }
7653 }
7654
Benjamin Franzbc33c822016-04-15 08:57:52 +01007655 private void throwIfParentInstance(String functionName) {
7656 if (mParentInstance) {
7657 throw new SecurityException(functionName + " cannot be called on the parent instance");
7658 }
7659 }
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007660
7661 /**
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007662 * Allows the device owner to enable or disable the backup service.
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007663 *
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007664 * <p> Backup service manages all backup and restore mechanisms on the device. Setting this to
7665 * false will prevent data from being backed up or restored.
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007666 *
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007667 * <p> Backup service is off by default when device owner is present.
7668 *
7669 * @throws SecurityException if {@code admin} is not a device owner.
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007670 */
7671 public void setBackupServiceEnabled(@NonNull ComponentName admin, boolean enabled) {
Esteban Talavera5b7f2d02017-02-17 09:45:24 +00007672 throwIfParentInstance("setBackupServiceEnabled");
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007673 try {
7674 mService.setBackupServiceEnabled(admin, enabled);
7675 } catch (RemoteException re) {
7676 throw re.rethrowFromSystemServer();
7677 }
7678 }
7679
7680 /**
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007681 * Return whether the backup service is enabled by the device owner.
7682 *
7683 * <p> Backup service manages all backup and restore mechanisms on the device.
7684 *
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007685 * @return {@code true} if backup service is enabled, {@code false} otherwise.
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007686 * @see #setBackupServiceEnabled
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007687 */
7688 public boolean isBackupServiceEnabled(@NonNull ComponentName admin) {
Esteban Talavera5b7f2d02017-02-17 09:45:24 +00007689 throwIfParentInstance("isBackupServiceEnabled");
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007690 try {
7691 return mService.isBackupServiceEnabled(admin);
7692 } catch (RemoteException re) {
7693 throw re.rethrowFromSystemServer();
7694 }
7695 }
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007696
7697 /**
Esteban Talaverad36dd152016-12-15 08:51:45 +00007698 * Called by a device owner to control the network logging feature.
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007699 *
7700 * <p> Network logs contain DNS lookup and connect() library call events.
7701 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00007702 * <p><strong>Note:</strong> The device owner won't be able to retrieve network logs if there
7703 * are unaffiliated secondary users or profiles on the device, regardless of whether the
7704 * feature is enabled. Logs will be discarded if the internal buffer fills up while waiting for
7705 * all users to become affiliated. Therefore it's recommended that affiliation ids are set for
7706 * new users as soon as possible after provisioning via {@link #setAffiliationIds}.
7707 *
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007708 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7709 * @param enabled whether network logging should be enabled or not.
Esteban Talaverad36dd152016-12-15 08:51:45 +00007710 * @throws SecurityException if {@code admin} is not a device owner.
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007711 * @see #retrieveNetworkLogs
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007712 */
7713 public void setNetworkLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
7714 throwIfParentInstance("setNetworkLoggingEnabled");
7715 try {
7716 mService.setNetworkLoggingEnabled(admin, enabled);
7717 } catch (RemoteException re) {
7718 throw re.rethrowFromSystemServer();
7719 }
7720 }
7721
7722 /**
7723 * Return whether network logging is enabled by a device owner.
7724 *
phweissa4e169e2016-11-24 16:20:57 +01007725 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Can only
7726 * be {@code null} if the caller has MANAGE_USERS permission.
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007727 * @return {@code true} if network logging is enabled by device owner, {@code false} otherwise.
Esteban Talaverad36dd152016-12-15 08:51:45 +00007728 * @throws SecurityException if {@code admin} is not a device owner and caller has
phweissa4e169e2016-11-24 16:20:57 +01007729 * no MANAGE_USERS permission
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007730 */
phweissa4e169e2016-11-24 16:20:57 +01007731 public boolean isNetworkLoggingEnabled(@Nullable ComponentName admin) {
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007732 throwIfParentInstance("isNetworkLoggingEnabled");
7733 try {
7734 return mService.isNetworkLoggingEnabled(admin);
7735 } catch (RemoteException re) {
7736 throw re.rethrowFromSystemServer();
7737 }
7738 }
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007739
7740 /**
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007741 * Called by device owner to retrieve the most recent batch of network logging events.
7742 * A device owner has to provide a batchToken provided as part of
7743 * {@link DeviceAdminReceiver#onNetworkLogsAvailable} callback. If the token doesn't match the
7744 * token of the most recent available batch of logs, {@code null} will be returned.
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007745 *
7746 * <p> {@link NetworkEvent} can be one of {@link DnsEvent} or {@link ConnectEvent}.
7747 *
7748 * <p> The list of network events is sorted chronologically, and contains at most 1200 events.
7749 *
7750 * <p> Access to the logs is rate limited and this method will only return a new batch of logs
7751 * after the device device owner has been notified via
7752 * {@link DeviceAdminReceiver#onNetworkLogsAvailable}.
7753 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00007754 * <p>If a secondary user or profile is created, calling this method will throw a
7755 * {@link SecurityException} until all users become affiliated again. It will also no longer be
7756 * possible to retrieve the network logs batch with the most recent batchToken provided
7757 * by {@link DeviceAdminReceiver#onNetworkLogsAvailable}. See
7758 * {@link DevicePolicyManager#setAffiliationIds}.
7759 *
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007760 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007761 * @param batchToken A token of the batch to retrieve
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007762 * @return A new batch of network logs which is a list of {@link NetworkEvent}. Returns
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007763 * {@code null} if the batch represented by batchToken is no longer available or if
7764 * logging is disabled.
Esteban Talaverad36dd152016-12-15 08:51:45 +00007765 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
7766 * profile or secondary user that is not affiliated with the device owner user.
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007767 * @see DeviceAdminReceiver#onNetworkLogsAvailable
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007768 */
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007769 public @Nullable List<NetworkEvent> retrieveNetworkLogs(@NonNull ComponentName admin,
7770 long batchToken) {
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007771 throwIfParentInstance("retrieveNetworkLogs");
7772 try {
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007773 return mService.retrieveNetworkLogs(admin, batchToken);
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007774 } catch (RemoteException re) {
7775 throw re.rethrowFromSystemServer();
7776 }
7777 }
Tony Mak46aabe52016-11-14 12:53:06 +00007778
7779 /**
Esteban Talavera2f897912017-01-26 10:30:48 +00007780 * Called by a device owner to bind to a service from a profile owner or vice versa.
7781 * See {@link #getBindDeviceAdminTargetUsers} for a definition of which
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007782 * device/profile owners are allowed to bind to services of another profile/device owner.
7783 * <p>
Tony Mak46aabe52016-11-14 12:53:06 +00007784 * The service must be unexported. Note that the {@link Context} used to obtain this
7785 * {@link DevicePolicyManager} instance via {@link Context#getSystemService(Class)} will be used
7786 * to bind to the {@link android.app.Service}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007787 *
Tony Mak46aabe52016-11-14 12:53:06 +00007788 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7789 * @param serviceIntent Identifies the service to connect to. The Intent must specify either an
7790 * explicit component name or a package name to match an
7791 * {@link IntentFilter} published by a service.
Tony Makbf9928d2016-12-22 11:02:45 +00007792 * @param conn Receives information as the service is started and stopped in main thread. This
7793 * must be a valid {@link ServiceConnection} object; it must not be {@code null}.
Tony Mak46aabe52016-11-14 12:53:06 +00007794 * @param flags Operation options for the binding operation. See
7795 * {@link Context#bindService(Intent, ServiceConnection, int)}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007796 * @param targetUser Which user to bind to. Must be one of the users returned by
7797 * {@link #getBindDeviceAdminTargetUsers}, otherwise a {@link SecurityException} will
7798 * be thrown.
Tony Mak46aabe52016-11-14 12:53:06 +00007799 * @return If you have successfully bound to the service, {@code true} is returned;
7800 * {@code false} is returned if the connection is not made and you will not
7801 * receive the service object.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007802 *
Tony Mak46aabe52016-11-14 12:53:06 +00007803 * @see Context#bindService(Intent, ServiceConnection, int)
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007804 * @see #getBindDeviceAdminTargetUsers(ComponentName)
Tony Mak46aabe52016-11-14 12:53:06 +00007805 */
7806 public boolean bindDeviceAdminServiceAsUser(
7807 @NonNull ComponentName admin, Intent serviceIntent, @NonNull ServiceConnection conn,
7808 @Context.BindServiceFlags int flags, @NonNull UserHandle targetUser) {
7809 throwIfParentInstance("bindDeviceAdminServiceAsUser");
7810 // Keep this in sync with ContextImpl.bindServiceCommon.
7811 try {
Tony Makbf9928d2016-12-22 11:02:45 +00007812 final IServiceConnection sd = mContext.getServiceDispatcher(
7813 conn, mContext.getMainThreadHandler(), flags);
Tony Mak46aabe52016-11-14 12:53:06 +00007814 serviceIntent.prepareToLeaveProcess(mContext);
7815 return mService.bindDeviceAdminServiceAsUser(admin,
7816 mContext.getIApplicationThread(), mContext.getActivityToken(), serviceIntent,
7817 sd, flags, targetUser.getIdentifier());
7818 } catch (RemoteException re) {
7819 throw re.rethrowFromSystemServer();
7820 }
7821 }
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007822
7823 /**
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007824 * Returns the list of target users that the calling device or profile owner can use when
7825 * calling {@link #bindDeviceAdminServiceAsUser}.
7826 * <p>
Esteban Talavera2f897912017-01-26 10:30:48 +00007827 * A device owner can bind to a service from a profile owner and vice versa, provided that:
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007828 * <ul>
7829 * <li>Both belong to the same package name.
Esteban Talavera2f897912017-01-26 10:30:48 +00007830 * <li>Both users are affiliated. See {@link #setAffiliationIds}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007831 * </ul>
7832 */
7833 public @NonNull List<UserHandle> getBindDeviceAdminTargetUsers(@NonNull ComponentName admin) {
7834 throwIfParentInstance("getBindDeviceAdminTargetUsers");
7835 try {
7836 return mService.getBindDeviceAdminTargetUsers(admin);
7837 } catch (RemoteException re) {
7838 throw re.rethrowFromSystemServer();
7839 }
7840 }
7841
7842 /**
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007843 * Called by the system to get the time at which the device owner last retrieved security
7844 * logging entries.
7845 *
7846 * @return the time at which the device owner most recently retrieved security logging entries,
7847 * in milliseconds since epoch; -1 if security logging entries were never retrieved.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007848 * @throws SecurityException if the caller is not the device owner, does not hold the
7849 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007850 *
7851 * @hide
7852 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007853 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007854 public long getLastSecurityLogRetrievalTime() {
7855 try {
7856 return mService.getLastSecurityLogRetrievalTime();
7857 } catch (RemoteException re) {
7858 throw re.rethrowFromSystemServer();
7859 }
7860 }
7861
7862 /**
7863 * Called by the system to get the time at which the device owner last requested a bug report.
7864 *
7865 * @return the time at which the device owner most recently requested a bug report, in
7866 * milliseconds since epoch; -1 if a bug report was never requested.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007867 * @throws SecurityException if the caller is not the device owner, does not hold the
7868 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007869 *
7870 * @hide
7871 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007872 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007873 public long getLastBugReportRequestTime() {
7874 try {
7875 return mService.getLastBugReportRequestTime();
7876 } catch (RemoteException re) {
7877 throw re.rethrowFromSystemServer();
7878 }
7879 }
7880
7881 /**
7882 * Called by the system to get the time at which the device owner last retrieved network logging
7883 * events.
7884 *
7885 * @return the time at which the device owner most recently retrieved network logging events, in
7886 * milliseconds since epoch; -1 if network logging events were never retrieved.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007887 * @throws SecurityException if the caller is not the device owner, does not hold the
7888 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007889 *
7890 * @hide
7891 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007892 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007893 public long getLastNetworkLogRetrievalTime() {
7894 try {
7895 return mService.getLastNetworkLogRetrievalTime();
7896 } catch (RemoteException re) {
7897 throw re.rethrowFromSystemServer();
7898 }
7899 }
Bartosz Fabianowskiaff5e9c2017-01-25 06:09:13 +01007900
7901 /**
7902 * Called by the system to find out whether the user's IME was set by the device/profile owner
7903 * or the user.
7904 *
7905 * @param user The user for whom to retrieve information.
7906 * @return {@code true} if the user's IME was set by the device or profile owner, {@code false}
7907 * otherwise.
7908 * @throws SecurityException if the caller does not have permission to retrieve information
7909 * about the given user's default IME. Device Owner and Profile Owner can retrieve
7910 * information about the user they run on; the System can retrieve information about any
7911 * user.
7912 *
7913 * @hide
7914 */
7915 @TestApi
7916 public boolean isDefaultInputMethodSetByOwner(@NonNull UserHandle user) {
7917 try {
7918 return mService.isDefaultInputMethodSetByOwner(user);
7919 } catch (RemoteException re) {
7920 throw re.rethrowFromSystemServer();
7921 }
7922 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08007923}