blob: 42d0dcb4f4933938b46c5f4cfb667b2d08e38809 [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
Robin Lee25e26452015-06-02 09:56:29 -070019import android.annotation.NonNull;
20import android.annotation.Nullable;
Dianne Hackbornd6847842010-01-12 18:14:19 -080021import android.annotation.SdkConstant;
22import android.annotation.SdkConstant.SdkConstantType;
Justin Moreyb5deda72014-07-24 10:53:40 -050023import android.annotation.SystemApi;
Jason Monkd7b86212014-06-16 13:15:38 -040024import android.app.Activity;
Dianne Hackbornd6847842010-01-12 18:14:19 -080025import android.content.ComponentName;
26import android.content.Context;
Adam Connors010cfd42014-04-16 12:48:13 +010027import android.content.Intent;
Sander Alewijnsef475ca32014-02-17 15:13:58 +000028import android.content.IntentFilter;
Dianne Hackbornd6847842010-01-12 18:14:19 -080029import android.content.pm.ActivityInfo;
30import android.content.pm.PackageManager;
31import android.content.pm.ResolveInfo;
Julia Reynoldsfca04ca2015-02-17 13:39:12 -050032import android.graphics.Bitmap;
Jason Monk03bc9912014-05-13 09:44:57 -040033import android.net.ProxyInfo;
Robin Lee66e5d962014-04-09 16:44:21 +010034import android.os.Bundle;
Dianne Hackbornd6847842010-01-12 18:14:19 -080035import android.os.Handler;
Jim Millere303bf42014-08-26 17:12:29 -070036import android.os.PersistableBundle;
Adam Connors776c5552014-01-09 10:42:56 +000037import android.os.Process;
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080038import android.os.RemoteCallback;
Dianne Hackbornd6847842010-01-12 18:14:19 -080039import android.os.RemoteException;
40import android.os.ServiceManager;
Amith Yamasani599dd7c2012-09-14 23:20:08 -070041import android.os.UserHandle;
Julia Reynolds1e958392014-05-16 14:25:21 -040042import android.os.UserManager;
Julia Reynoldsda551652014-05-14 17:15:16 -040043import android.provider.Settings;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010044import android.security.Credentials;
Amith Yamasanid1d7c022014-08-19 17:03:41 -070045import android.service.restrictions.RestrictionsReceiver;
Dianne Hackbornd6847842010-01-12 18:14:19 -080046import android.util.Log;
47
Maggie Benthallda51e682013-08-08 22:35:44 -040048import com.android.org.conscrypt.TrustedCertificateStore;
49
Jessica Hummel91da58d2014-04-10 17:39:43 +010050import org.xmlpull.v1.XmlPullParserException;
51
Maggie Benthallda51e682013-08-08 22:35:44 -040052import java.io.ByteArrayInputStream;
Dianne Hackbornd6847842010-01-12 18:14:19 -080053import java.io.IOException;
Oscar Montemayor69238c62010-08-03 10:51:06 -070054import java.net.InetSocketAddress;
55import java.net.Proxy;
Robin Lee0d5ccb72014-09-12 17:41:44 +010056import java.security.KeyFactory;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010057import java.security.PrivateKey;
58import java.security.cert.Certificate;
Maggie Benthallda51e682013-08-08 22:35:44 -040059import java.security.cert.CertificateException;
60import java.security.cert.CertificateFactory;
61import java.security.cert.X509Certificate;
Robin Lee0d5ccb72014-09-12 17:41:44 +010062import java.security.spec.PKCS8EncodedKeySpec;
63import java.security.spec.InvalidKeySpecException;
64import java.security.NoSuchAlgorithmException;
Jim Miller604e7552014-07-18 19:00:02 -070065import java.util.ArrayList;
Svetoslav976e8bd2014-07-16 15:12:03 -070066import java.util.Collections;
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -080067import java.util.List;
Dianne Hackbornd6847842010-01-12 18:14:19 -080068
69/**
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000070 * Public interface for managing policies enforced on a device. Most clients of this class must be
71 * registered with the system as a
Benjamin Franz6cdb27e2015-02-26 12:26:53 +000072 * <a href="{@docRoot}guide/topics/admin/device-admin.html">device administrator</a>. Additionally,
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000073 * a device administrator may be registered as either a profile or device owner. A given method is
74 * accessible to all device administrators unless the documentation for that method specifies that
75 * it is restricted to either device or profile owners.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080076 *
77 * <div class="special reference">
78 * <h3>Developer Guides</h3>
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000079 * <p>For more information about managing policies for device administration, read the
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080080 * <a href="{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a>
Robin Lee25e26452015-06-02 09:56:29 -070081 * developer guide.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080082 * </div>
Dianne Hackbornd6847842010-01-12 18:14:19 -080083 */
84public class DevicePolicyManager {
85 private static String TAG = "DevicePolicyManager";
Dianne Hackbornd6847842010-01-12 18:14:19 -080086
87 private final Context mContext;
Dianne Hackbornd6847842010-01-12 18:14:19 -080088 private final IDevicePolicyManager mService;
Konstantin Lopyrev32558232010-05-20 16:18:05 -070089
Dianne Hackborn21f1bd12010-02-19 17:02:21 -080090 private DevicePolicyManager(Context context, Handler handler) {
Dianne Hackbornd6847842010-01-12 18:14:19 -080091 mContext = context;
Dianne Hackbornd6847842010-01-12 18:14:19 -080092 mService = IDevicePolicyManager.Stub.asInterface(
93 ServiceManager.getService(Context.DEVICE_POLICY_SERVICE));
94 }
95
Dianne Hackborn87bba1e2010-02-26 17:25:54 -080096 /** @hide */
97 public static DevicePolicyManager create(Context context, Handler handler) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -080098 DevicePolicyManager me = new DevicePolicyManager(context, handler);
99 return me.mService != null ? me : null;
100 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700101
Dianne Hackbornd6847842010-01-12 18:14:19 -0800102 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +0000103 * Activity action: Starts the provisioning flow which sets up a managed profile.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000104 *
Jessica Hummel9da60392014-05-21 12:32:57 +0100105 * <p>A managed profile allows data separation for example for the usage of a
106 * device as a personal and corporate device. The user which provisioning is started from and
107 * the managed profile share a launcher.
108 *
Andrew Solovay27f53372015-03-02 16:37:59 -0800109 * <p>This intent will typically be sent by a mobile device management application (MDM).
110 * Provisioning adds a managed profile and sets the MDM as the profile owner who has full
111 * control over the profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100112 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000113 * In version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this intent must contain the
114 * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}.
115 * As of {@link android.os.Build.VERSION_CODES#MNC}, it should contain the extra
116 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only
117 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000118 *
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000119 * <p> When managed provisioning has completed, broadcasts are sent to the application specified
120 * in the provisioning intent. The
121 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the
122 * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in
123 * the primary profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100124 *
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100125 * <p> If provisioning fails, the managedProfile is removed so the device returns to its
126 * previous state.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000127 */
128 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
129 public static final String ACTION_PROVISION_MANAGED_PROFILE
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100130 = "android.app.action.PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000131
132 /**
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100133 * Activity action: Starts the provisioning flow which sets up a managed device.
134 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
135 *
136 * <p> During device owner provisioning a device admin app is set as the owner of the device.
137 * A device owner has full control over the device. The device owner can not be modified by the
138 * user.
139 *
140 * <p> A typical use case would be a device that is owned by a company, but used by either an
141 * employee or client.
142 *
143 * <p> An intent with this action can be sent only on an unprovisioned device.
144 * It is possible to check if the device is provisioned or not by looking at
145 * {@link android.provider.Settings.Global#DEVICE_PROVISIONED}
146 *
147 * The intent contains the following extras:
148 * <ul>
149 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
150 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
151 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
152 * </ul>
153 *
154 * <p> When device owner provisioning has completed, an intent of the type
155 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
156 * device owner.
157 *
158 * <p> If provisioning fails, the device is factory reset.
159 *
160 */
161 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
162 public static final String ACTION_PROVISION_MANAGED_DEVICE
163 = "android.app.action.PROVISION_MANAGED_DEVICE";
164
165 /**
Brian Carlstromf1fe51b2014-09-03 08:55:05 -0700166 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that allows
167 * a mobile device management application that starts managed profile provisioning to pass data
168 * to itself on the managed profile when provisioning completes. The mobile device management
169 * application sends this extra in an intent with the action
170 * {@link #ACTION_PROVISION_MANAGED_PROFILE} and receives it in
171 * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action
172 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed
173 * during the managed profile provisioning.
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100174 */
175 public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE =
Esteban Talavera37f01842014-09-05 10:50:57 +0100176 "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE";
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100177
178 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100179 * A String extra holding the package name of the mobile device management application that
180 * will be set as the profile owner or device owner.
181 *
182 * <p>If an application starts provisioning directly via an intent with action
183 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
184 * application that started provisioning. The package will be set as profile owner in that case.
185 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000186 * <p>This package is set as device owner when device owner provisioning is started by an NFC
187 * message containing an NFC record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000188 *
189 * <p> When this extra is set, the application must have exactly one device admin receiver.
Robin Lee25e26452015-06-02 09:56:29 -0700190 * This receiver will be set as the profile or device owner and active admin.
Nicolas Prevot18440252015-03-09 14:07:17 +0000191
192 * @see DeviceAdminReceiver
193 * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still
194 * supported.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000195 */
Nicolas Prevot18440252015-03-09 14:07:17 +0000196 @Deprecated
Jessica Hummelf72078b2014-03-06 16:13:12 +0000197 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100198 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000199
200 /**
Nicolas Prevot18440252015-03-09 14:07:17 +0000201 * A ComponentName extra indicating the device admin receiver of the mobile device management
202 * application that will be set as the profile owner or device owner and active admin.
203 *
204 * <p>If an application starts provisioning directly via an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100205 * {@link #ACTION_PROVISION_MANAGED_PROFILE} or
206 * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this
207 * component has to match the package name of the application that started provisioning.
Nicolas Prevot18440252015-03-09 14:07:17 +0000208 *
209 * <p>This component is set as device owner and active admin when device owner provisioning is
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100210 * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC
211 * message containing an NFC record with MIME type
Rubin Xu44ef750b2015-03-23 16:51:33 +0000212 * {@link #MIME_TYPE_PROVISIONING_NFC_V2}. For the NFC record, the component name should be
213 * flattened to a string, via {@link ComponentName#flattenToShortString()}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000214 *
215 * @see DeviceAdminReceiver
216 */
217 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME
218 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME";
219
220 /**
Alexandra Gherghinaaaf2f3e2014-11-13 12:46:15 +0000221 * An {@link android.accounts.Account} extra holding the account to migrate during managed
222 * profile provisioning. If the account supplied is present in the primary user, it will be
223 * copied, along with its credentials to the managed profile and removed from the primary user.
224 *
225 * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}.
226 */
227
228 public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE
229 = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE";
230
231 /**
Jessica Hummele3da7902014-08-20 15:20:11 +0100232 * A String extra that, holds the email address of the account which a managed profile is
233 * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
234 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100235 *
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100236 * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}.
237 *
Jessica Hummele3da7902014-08-20 15:20:11 +0100238 * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning
239 * contains this extra, it is forwarded in the
240 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile
241 * device management application that was set as the profile owner during provisioning.
242 * It is usually used to avoid that the user has to enter their email address twice.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100243 */
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100244 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
245 = "android.app.extra.PROVISIONING_EMAIL_ADDRESS";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100246
247 /**
Sander Alewijnse8c411562014-11-12 18:03:11 +0000248 * A Boolean extra that can be used by the mobile device management application to skip the
Robin Lee25e26452015-06-02 09:56:29 -0700249 * disabling of system apps during provisioning when set to {@code true}.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000250 *
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100251 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
252 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000253 */
Sander Alewijnse5a144252014-11-18 13:25:04 +0000254 public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED =
255 "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED";
Sander Alewijnse8c411562014-11-12 18:03:11 +0000256
257 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100258 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
259 * will be set to.
260 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000261 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
262 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100263 */
264 public static final String EXTRA_PROVISIONING_TIME_ZONE
Esteban Talavera37f01842014-09-05 10:50:57 +0100265 = "android.app.extra.PROVISIONING_TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100266
267 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100268 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
269 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100270 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000271 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
272 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100273 */
274 public static final String EXTRA_PROVISIONING_LOCAL_TIME
Esteban Talavera37f01842014-09-05 10:50:57 +0100275 = "android.app.extra.PROVISIONING_LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100276
277 /**
278 * A String extra holding the {@link java.util.Locale} that the device will be set to.
279 * Format: xx_yy, where xx is the language code, and yy the country code.
280 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000281 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
282 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100283 */
284 public static final String EXTRA_PROVISIONING_LOCALE
Esteban Talavera37f01842014-09-05 10:50:57 +0100285 = "android.app.extra.PROVISIONING_LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100286
287 /**
288 * A String extra holding the ssid of the wifi network that should be used during nfc device
289 * owner provisioning for downloading the mobile device management application.
290 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000291 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
292 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100293 */
294 public static final String EXTRA_PROVISIONING_WIFI_SSID
Esteban Talavera37f01842014-09-05 10:50:57 +0100295 = "android.app.extra.PROVISIONING_WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100296
297 /**
298 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
299 * is hidden or not.
300 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000301 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
302 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100303 */
304 public static final String EXTRA_PROVISIONING_WIFI_HIDDEN
Esteban Talavera37f01842014-09-05 10:50:57 +0100305 = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100306
307 /**
308 * A String extra indicating the security type of the wifi network in
309 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
310 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000311 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
312 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100313 */
314 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
Esteban Talavera37f01842014-09-05 10:50:57 +0100315 = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100316
317 /**
318 * A String extra holding the password of the wifi network in
319 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
320 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000321 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
322 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100323 */
324 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talavera37f01842014-09-05 10:50:57 +0100325 = "android.app.extra.PROVISIONING_WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100326
327 /**
328 * A String extra holding the proxy host for the wifi network in
329 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
330 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000331 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
332 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100333 */
334 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
Esteban Talavera37f01842014-09-05 10:50:57 +0100335 = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100336
337 /**
338 * An int extra holding the proxy port for the wifi network in
339 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
340 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000341 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
342 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100343 */
344 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
Esteban Talavera37f01842014-09-05 10:50:57 +0100345 = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100346
347 /**
348 * A String extra holding the proxy bypass for the wifi network in
349 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
350 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000351 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
352 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100353 */
354 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
Esteban Talavera37f01842014-09-05 10:50:57 +0100355 = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100356
357 /**
358 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
359 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
360 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000361 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
362 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100363 */
364 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
Esteban Talavera37f01842014-09-05 10:50:57 +0100365 = "android.app.extra.PROVISIONING_WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100366
367 /**
368 * A String extra holding a url that specifies the download location of the device admin
369 * package. When not provided it is assumed that the device admin package is already installed.
370 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000371 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
372 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100373 */
374 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talavera37f01842014-09-05 10:50:57 +0100375 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100376
377 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400378 * An int extra holding a minimum required version code for the device admin package. If the
379 * device admin is already installed on the device, it will only be re-downloaded from
380 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the
381 * installed package is less than this version code.
382 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400383 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400384 * provisioning via an NFC bump.
385 */
386 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE
387 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE";
388
389 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100390 * A String extra holding a http cookie header which should be used in the http request to the
391 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
392 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000393 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
394 * provisioning via an NFC bump.
Sander Alewijnse681bce92014-07-24 16:46:26 +0100395 */
396 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talavera37f01842014-09-05 10:50:57 +0100397 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100398
399 /**
Rubin Xue30ab112015-03-24 11:22:28 +0000400 * A String extra holding the URL-safe base64 encoded SHA-1 checksum of the file at download
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100401 * location specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
402 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100403 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} should be
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100404 * present. The provided checksum should match the checksum of the file at the download
405 * location. If the checksum doesn't match an error will be shown to the user and the user will
406 * be asked to factory reset the device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100407 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000408 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
409 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100410 */
411 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100412 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100413
414 /**
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100415 * A String extra holding the URL-safe base64 encoded SHA-1 checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100416 * android package archive at the download location specified in {@link
417 * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
418 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100419 * <p>The signatures of an android package archive can be obtained using
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100420 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
421 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
422 *
423 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} should be
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100424 * present. The provided checksum should match the checksum of any signature of the file at
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100425 * the download location. If the checksum does not match an error will be shown to the user and
426 * the user will be asked to factory reset the device.
427 *
428 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
429 * provisioning via an NFC bump.
430 */
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100431 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM
432 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM";
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100433
434 /**
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000435 * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile
436 * has completed successfully.
437 *
438 * <p>The broadcast is limited to the primary profile, to the app specified in the provisioning
Nicolas Prevotebe2d992015-05-12 18:14:53 -0700439 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000440 *
Ying Wang7f38aab2015-02-20 11:50:09 -0800441 * <p>This intent will contain the extra {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE} which
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000442 * corresponds to the account requested to be migrated at provisioning time, if any.
443 */
444 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
445 public static final String ACTION_MANAGED_PROFILE_PROVISIONED
446 = "android.app.action.MANAGED_PROFILE_PROVISIONED";
447
448 /**
Julia Reynolds2f46d942015-05-05 11:44:20 -0400449 * A boolean extra indicating whether device encryption can be skipped as part of Device Owner
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500450 * provisioning.
451 *
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100452 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} or an intent with action
453 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500454 */
455 public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION =
456 "android.app.extra.PROVISIONING_SKIP_ENCRYPTION";
457
458 /**
Rubin Xu44ef750b2015-03-23 16:51:33 +0000459 * On devices managed by a device owner app, a {@link ComponentName} extra indicating the
460 * component of the application that is temporarily granted device owner privileges during
461 * device initialization and profile owner privileges during secondary user initialization.
Julia Reynolds20118f12015-02-11 12:34:08 -0500462 *
Rubin Xu44ef750b2015-03-23 16:51:33 +0000463 * <p>
Rubin Xu6a38e432015-03-26 14:47:45 +0000464 * It can also be used in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts
Rubin Xu44ef750b2015-03-23 16:51:33 +0000465 * device owner provisioning via an NFC bump. For the NFC record, it should be flattened to a
466 * string first.
467 *
468 * @see ComponentName#flattenToShortString()
Julia Reynolds20118f12015-02-11 12:34:08 -0500469 */
470 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_COMPONENT_NAME
471 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_COMPONENT_NAME";
472
473 /**
474 * A String extra holding an http url that specifies the download location of the device
475 * initializer package. When not provided it is assumed that the device initializer package is
476 * already installed.
477 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400478 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynolds20118f12015-02-11 12:34:08 -0500479 * provisioning via an NFC bump.
480 */
481 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION
482 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION";
483
484 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400485 * An int extra holding a minimum required version code for the device initializer package.
486 * If the initializer is already installed on the device, it will only be re-downloaded from
487 * {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION} if the version of
488 * the installed package is less than this version code.
489 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400490 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400491 * provisioning via an NFC bump.
492 */
493 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_MINIMUM_VERSION_CODE
494 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_MINIMUM_VERSION_CODE";
495
496 /**
Julia Reynolds20118f12015-02-11 12:34:08 -0500497 * A String extra holding a http cookie header which should be used in the http request to the
498 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION}.
499 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400500 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynolds20118f12015-02-11 12:34:08 -0500501 * provisioning via an NFC bump.
502 */
503 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_COOKIE_HEADER
504 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_COOKIE_HEADER";
505
506 /**
Rubin Xue30ab112015-03-24 11:22:28 +0000507 * A String extra holding the URL-safe base64 encoded SHA-1 checksum of the file at download
508 * location specified in
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100509 * {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION}.
510 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100511 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_SIGNATURE_CHECKSUM}
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100512 * should be present. The provided checksum should match the checksum of the file at the
513 * download location. If the checksum doesn't match an error will be shown to the user and the
514 * user will be asked to factory reset the device.
Julia Reynolds20118f12015-02-11 12:34:08 -0500515 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400516 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynolds20118f12015-02-11 12:34:08 -0500517 * provisioning via an NFC bump.
518 */
519 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM
520 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM";
521
522 /**
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100523 * A String extra holding the URL-safe base64 encoded SHA-1 checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100524 * android package archive at the download location specified in {@link
525 * #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION}.
526 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100527 * <p>The signatures of an android package archive can be obtained using
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100528 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
529 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
530 *
531 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM}
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100532 * should be present. The provided checksum should match the checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100533 * file at the download location. If the checksum doesn't match an error will be shown to the
534 * user and the user will be asked to factory reset the device.
535 *
536 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
537 * provisioning via an NFC bump.
538 */
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100539 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_SIGNATURE_CHECKSUM
540 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_SIGNATURE_CHECKSUM";
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100541
542 /**
Craig Lafayette8e27c4d2015-03-19 08:36:38 -0400543 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that
544 * holds data needed by the system to wipe factory reset protection. The data needed to wipe
545 * the device depend on the installed factory reset protection implementation. For example,
546 * if an account is needed to unlock a device, this extra may contain data used to
547 * authenticate that account.
548 *
549 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
550 * provisioning via an NFC bump.
551 */
552 public static final String EXTRA_PROVISIONING_RESET_PROTECTION_PARAMETERS
553 = "android.app.extra.PROVISIONING_RESET_PROTECTION_PARAMETERS";
554
Craig Lafayette97e473e2015-03-19 10:19:38 -0400555 /**
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400556 * This MIME type is used for starting the Device Owner provisioning that does not require
557 * provisioning features introduced in Android API level
558 * {@link android.os.Build.VERSION_CODES#MNC} or later levels.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100559 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400560 * <p>For more information about the provisioning process see
561 * {@link #MIME_TYPE_PROVISIONING_NFC_V2}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100562 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000563 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100564 * contains the following properties:
565 * <ul>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400566 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
567 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100568 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400569 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100570 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
571 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
572 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
573 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
574 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
575 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
576 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
577 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
578 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
579 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400580 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100581 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000582 * <p>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400583 * As of {@link android.os.Build.VERSION_CODES#MNC}, the properties should contain
584 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of
585 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only
586 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
587 *
588 * @see #MIME_TYPE_PROVISIONING_NFC_V2
589 *
590 */
591 public static final String MIME_TYPE_PROVISIONING_NFC
592 = "application/com.android.managedprovisioning";
593
594
595 /**
596 * This MIME type is used for starting the Device Owner provisioning that requires
597 * new provisioning features introduced in API version
598 * {@link android.os.Build.VERSION_CODES#MNC} in addition to those supported in earlier
599 * versions.
600 *
601 * <p>During device owner provisioning a device admin app is set as the owner of the device.
602 * A device owner has full control over the device. The device owner can not be modified by the
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100603 * user.
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400604 *
605 * <p> A typical use case would be a device that is owned by a company, but used by either an
606 * employee or client.
607 *
608 * <p> The NFC message should be sent to an unprovisioned device.
609 *
610 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
611 * contains the following properties in addition to properties listed at
612 * {@link #MIME_TYPE_PROVISIONING_NFC}:
613 * <ul>
614 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
615 * <li>{@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_COMPONENT_NAME}, optional</li>
616 * <li>{@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
617 * <li>{@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
618 * <li>{@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM}, optional</li>
619 * <li>{@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_MINIMUM_VERSION_CODE}, optional</li>
620 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}.
621 * Replaces {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}. The value of the property
622 * should be converted to a String via
623 * {@link android.content.ComponentName#flattenToString()}</li>
Craig Lafayette240e6482015-06-02 11:12:43 -0400624 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE}, optional</li></ul>
Nicolas Prevot18440252015-03-09 14:07:17 +0000625 *
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100626 * <p> When device owner provisioning has completed, an intent of the type
627 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcasted to the
628 * device owner.
629 *
630 * <p>
631 * If provisioning fails, the device is factory reset.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100632 */
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400633 public static final String MIME_TYPE_PROVISIONING_NFC_V2
634 = "application/com.android.managedprovisioning.v2";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100635
636 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800637 * Activity action: ask the user to add a new device administrator to the system.
638 * The desired policy is the ComponentName of the policy in the
639 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
640 * bring the user through adding the device administrator to the system (or
641 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700642 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800643 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
644 * field to provide the user with additional explanation (in addition
645 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800646 *
647 * <p>If your administrator is already active, this will ordinarily return immediately (without
648 * user intervention). However, if your administrator has been updated and is requesting
649 * additional uses-policy flags, the user will be presented with the new list. New policies
650 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800651 */
652 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
653 public static final String ACTION_ADD_DEVICE_ADMIN
654 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700655
Dianne Hackbornd6847842010-01-12 18:14:19 -0800656 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700657 * @hide
658 * Activity action: ask the user to add a new device administrator as the profile owner
Amith Yamasani814e9872015-03-23 14:04:53 -0700659 * for this user. Only system apps can launch this intent.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700660 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700661 * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN}
662 * extra field. This will invoke a UI to bring the user through adding the profile owner admin
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700663 * to remotely control restrictions on the user.
664 *
665 * <p>The intent must be invoked via {@link Activity#startActivityForResult()} to receive the
666 * result of whether or not the user approved the action. If approved, the result will
667 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
668 * as a profile owner.
669 *
670 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
671 * field to provide the user with additional explanation (in addition
672 * to your component's description) about what is being added.
673 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700674 * <p>If there is already a profile owner active or the caller is not a system app, the
675 * operation will return a failure result.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700676 */
677 @SystemApi
678 public static final String ACTION_SET_PROFILE_OWNER
679 = "android.app.action.SET_PROFILE_OWNER";
680
681 /**
682 * @hide
683 * Name of the profile owner admin that controls the user.
684 */
685 @SystemApi
686 public static final String EXTRA_PROFILE_OWNER_NAME
687 = "android.app.extra.PROFILE_OWNER_NAME";
688
689 /**
Jim Miller284b62e2010-06-08 14:27:42 -0700690 * Activity action: send when any policy admin changes a policy.
691 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700692 *
Jim Miller284b62e2010-06-08 14:27:42 -0700693 * @hide
694 */
695 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
696 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
697
698 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800699 * The ComponentName of the administrator component.
700 *
701 * @see #ACTION_ADD_DEVICE_ADMIN
702 */
703 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700704
Dianne Hackbornd6847842010-01-12 18:14:19 -0800705 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800706 * An optional CharSequence providing additional explanation for why the
707 * admin is being added.
708 *
709 * @see #ACTION_ADD_DEVICE_ADMIN
710 */
711 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700712
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800713 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700714 * Activity action: have the user enter a new password. This activity should
715 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
716 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
717 * enter a new password that meets the current requirements. You can use
718 * {@link #isActivePasswordSufficient()} to determine whether you need to
719 * have the user select a new password in order to meet the current
720 * constraints. Upon being resumed from this activity, you can check the new
721 * password characteristics to see if they are sufficient.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800722 */
723 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
724 public static final String ACTION_SET_NEW_PASSWORD
725 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700726
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000727 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000728 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
729 * the parent profile to access intents sent from the managed profile.
730 * That is, when an app in the managed profile calls
731 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
732 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000733 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100734 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000735
736 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000737 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
738 * the managed profile to access intents sent from the parent profile.
739 * That is, when an app in the parent profile calls
740 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
741 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000742 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100743 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700744
Dianne Hackbornd6847842010-01-12 18:14:19 -0800745 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +0100746 * Broadcast action: notify that a new local system update policy has been set by the device
747 * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}.
Rubin Xu8027a4f2015-03-10 17:52:37 +0000748 */
749 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Rubin Xu5faad8e2015-04-20 17:43:48 +0100750 public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED
751 = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED";
Rubin Xu8027a4f2015-03-10 17:52:37 +0000752
Amith Yamasanid49489b2015-04-28 14:00:26 -0700753 /**
754 * Permission policy to prompt user for new permission requests for runtime permissions.
755 * Already granted or denied permissions are not affected by this.
756 */
757 public static final int PERMISSION_POLICY_PROMPT = 0;
758
759 /**
760 * Permission policy to always grant new permission requests for runtime permissions.
761 * Already granted or denied permissions are not affected by this.
762 */
763 public static final int PERMISSION_POLICY_AUTO_GRANT = 1;
764
765 /**
766 * Permission policy to always deny new permission requests for runtime permissions.
767 * Already granted or denied permissions are not affected by this.
768 */
769 public static final int PERMISSION_POLICY_AUTO_DENY = 2;
770
Svet Ganovd8ecc5a2015-05-20 10:45:43 -0700771 /**
772 * Runtime permission state: The user can manage the permission
773 * through the UI.
774 */
775 public static final int PERMISSION_GRANT_STATE_DEFAULT = 0;
776
777 /**
778 * Runtime permission state: The permission is granted to the app
779 * and the user cannot manage the permission through the UI.
780 */
781 public static final int PERMISSION_GRANT_STATE_GRANTED = 1;
782
783 /**
784 * Runtime permission state: The permission is denied to the app
785 * and the user cannot manage the permission through the UI.
786 */
787 public static final int PERMISSION_GRANT_STATE_DENIED = 2;
Rubin Xu8027a4f2015-03-10 17:52:37 +0000788
789 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800790 * Return true if the given administrator component is currently
791 * active (enabled) in the system.
792 */
Robin Lee25e26452015-06-02 09:56:29 -0700793 public boolean isAdminActive(@NonNull ComponentName admin) {
794 return isAdminActiveAsUser(admin, UserHandle.myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100795 }
796
797 /**
798 * @see #isAdminActive(ComponentName)
799 * @hide
800 */
Robin Lee25e26452015-06-02 09:56:29 -0700801 public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800802 if (mService != null) {
803 try {
Robin Lee25e26452015-06-02 09:56:29 -0700804 return mService.isAdminActive(admin, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800805 } catch (RemoteException e) {
806 Log.w(TAG, "Failed talking with device policy service", e);
807 }
808 }
809 return false;
810 }
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800811 /**
812 * Return true if the given administrator component is currently being removed
813 * for the user.
814 * @hide
815 */
Robin Lee25e26452015-06-02 09:56:29 -0700816 public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) {
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800817 if (mService != null) {
818 try {
Robin Lee25e26452015-06-02 09:56:29 -0700819 return mService.isRemovingAdmin(admin, userId);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800820 } catch (RemoteException e) {
821 Log.w(TAG, "Failed talking with device policy service", e);
822 }
823 }
824 return false;
825 }
826
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700827
Dianne Hackbornd6847842010-01-12 18:14:19 -0800828 /**
Robin Lee25e26452015-06-02 09:56:29 -0700829 * Return a list of all currently active device administrators' component
830 * names. If there are no administrators {@code null} may be
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800831 * returned.
832 */
833 public List<ComponentName> getActiveAdmins() {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100834 return getActiveAdminsAsUser(UserHandle.myUserId());
835 }
836
837 /**
838 * @see #getActiveAdmins()
839 * @hide
840 */
841 public List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800842 if (mService != null) {
843 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100844 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800845 } catch (RemoteException e) {
846 Log.w(TAG, "Failed talking with device policy service", e);
847 }
848 }
849 return null;
850 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700851
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800852 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700853 * Used by package administration code to determine if a package can be stopped
854 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800855 * @hide
856 */
857 public boolean packageHasActiveAdmins(String packageName) {
858 if (mService != null) {
859 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700860 return mService.packageHasActiveAdmins(packageName, UserHandle.myUserId());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800861 } catch (RemoteException e) {
862 Log.w(TAG, "Failed talking with device policy service", e);
863 }
864 }
865 return false;
866 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700867
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800868 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800869 * Remove a current administration component. This can only be called
870 * by the application that owns the administration component; if you
871 * try to remove someone else's component, a security exception will be
872 * thrown.
873 */
Robin Lee25e26452015-06-02 09:56:29 -0700874 public void removeActiveAdmin(@NonNull ComponentName admin) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800875 if (mService != null) {
876 try {
Robin Lee25e26452015-06-02 09:56:29 -0700877 mService.removeActiveAdmin(admin, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800878 } catch (RemoteException e) {
879 Log.w(TAG, "Failed talking with device policy service", e);
880 }
881 }
882 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700883
Dianne Hackbornd6847842010-01-12 18:14:19 -0800884 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800885 * Returns true if an administrator has been granted a particular device policy. This can
Robin Lee25e26452015-06-02 09:56:29 -0700886 * be used to check whether the administrator was activated under an earlier set of policies,
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800887 * but requires additional policies after an upgrade.
888 *
889 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be
890 * an active administrator, or an exception will be thrown.
891 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
892 */
Robin Lee25e26452015-06-02 09:56:29 -0700893 public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) {
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800894 if (mService != null) {
895 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700896 return mService.hasGrantedPolicy(admin, usesPolicy, UserHandle.myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800897 } catch (RemoteException e) {
898 Log.w(TAG, "Failed talking with device policy service", e);
899 }
900 }
901 return false;
902 }
903
904 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800905 * Constant for {@link #setPasswordQuality}: the policy has no requirements
906 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800907 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800908 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800909 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700910
Dianne Hackbornd6847842010-01-12 18:14:19 -0800911 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700912 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
913 * recognition technology. This implies technologies that can recognize the identity of
914 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
915 * Note that quality constants are ordered so that higher values are more restrictive.
916 */
917 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
918
919 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800920 * Constant for {@link #setPasswordQuality}: the policy requires some kind
921 * of password, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800922 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800923 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800924 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700925
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800926 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800927 * Constant for {@link #setPasswordQuality}: the user must have entered a
928 * password containing at least numeric characters. Note that quality
929 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800930 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800931 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700932
Dianne Hackbornd6847842010-01-12 18:14:19 -0800933 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800934 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -0800935 * password containing at least numeric characters with no repeating (4444)
936 * or ordered (1234, 4321, 2468) sequences. Note that quality
937 * constants are ordered so that higher values are more restrictive.
938 */
939 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
940
941 /**
942 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700943 * password containing at least alphabetic (or other symbol) characters.
944 * Note that quality constants are ordered so that higher values are more
945 * restrictive.
946 */
947 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700948
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700949 /**
950 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800951 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700952 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800953 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800954 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700955 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700956
Dianne Hackbornd6847842010-01-12 18:14:19 -0800957 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700958 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700959 * password containing at least a letter, a numerical digit and a special
960 * symbol, by default. With this password quality, passwords can be
961 * restricted to contain various sets of characters, like at least an
962 * uppercase letter, etc. These are specified using various methods,
963 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
964 * that quality constants are ordered so that higher values are more
965 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700966 */
967 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
968
969 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800970 * Called by an application that is administering the device to set the
971 * password restrictions it is imposing. After setting this, the user
972 * will not be able to enter a new password that is not at least as
973 * restrictive as what has been set. Note that the current password
974 * will remain until the user has set a new one, so the change does not
975 * take place immediately. To prompt the user for a new password, use
976 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700977 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800978 * <p>Quality constants are ordered so that higher values are more restrictive;
979 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800980 * the user's preference, and any other considerations) is the one that
981 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700982 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800983 * <p>The calling device admin must have requested
984 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
985 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700986 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800987 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800988 * @param quality The new desired quality. One of
989 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Jim Miller85516d02014-01-31 17:08:37 -0800990 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
991 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}
992 * or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800993 */
Robin Lee25e26452015-06-02 09:56:29 -0700994 public void setPasswordQuality(@NonNull ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800995 if (mService != null) {
996 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -0800997 mService.setPasswordQuality(admin, quality);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800998 } catch (RemoteException e) {
999 Log.w(TAG, "Failed talking with device policy service", e);
1000 }
1001 }
1002 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001003
Dianne Hackbornd6847842010-01-12 18:14:19 -08001004 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001005 * Retrieve the current minimum password quality for all admins of this user
1006 * and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001007 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001008 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001009 */
Robin Lee25e26452015-06-02 09:56:29 -07001010 public int getPasswordQuality(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001011 return getPasswordQuality(admin, UserHandle.myUserId());
1012 }
1013
1014 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001015 public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001016 if (mService != null) {
1017 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001018 return mService.getPasswordQuality(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001019 } catch (RemoteException e) {
1020 Log.w(TAG, "Failed talking with device policy service", e);
1021 }
1022 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001023 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001024 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001025
Dianne Hackbornd6847842010-01-12 18:14:19 -08001026 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001027 * Called by an application that is administering the device to set the
1028 * minimum allowed password length. After setting this, the user
1029 * will not be able to enter a new password that is not at least as
1030 * restrictive as what has been set. Note that the current password
1031 * will remain until the user has set a new one, so the change does not
1032 * take place immediately. To prompt the user for a new password, use
1033 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1034 * constraint is only imposed if the administrator has also requested either
Jim Miller85516d02014-01-31 17:08:37 -08001035 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
1036 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC},
1037 * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001038 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001039 * <p>The calling device admin must have requested
1040 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1041 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001042 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001043 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001044 * @param length The new desired minimum password length. A value of 0
1045 * means there is no restriction.
1046 */
Robin Lee25e26452015-06-02 09:56:29 -07001047 public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001048 if (mService != null) {
1049 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001050 mService.setPasswordMinimumLength(admin, length);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001051 } catch (RemoteException e) {
1052 Log.w(TAG, "Failed talking with device policy service", e);
1053 }
1054 }
1055 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001056
Dianne Hackbornd6847842010-01-12 18:14:19 -08001057 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001058 * Retrieve the current minimum password length for all admins of this
1059 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001060 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001061 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001062 */
Robin Lee25e26452015-06-02 09:56:29 -07001063 public int getPasswordMinimumLength(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001064 return getPasswordMinimumLength(admin, UserHandle.myUserId());
1065 }
1066
1067 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001068 public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001069 if (mService != null) {
1070 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001071 return mService.getPasswordMinimumLength(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001072 } catch (RemoteException e) {
1073 Log.w(TAG, "Failed talking with device policy service", e);
1074 }
1075 }
1076 return 0;
1077 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001078
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001079 /**
1080 * Called by an application that is administering the device to set the
1081 * minimum number of upper case letters required in the password. After
1082 * setting this, the user will not be able to enter a new password that is
1083 * not at least as restrictive as what has been set. Note that the current
1084 * password will remain until the user has set a new one, so the change does
1085 * not take place immediately. To prompt the user for a new password, use
1086 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1087 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001088 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1089 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001090 * <p>
1091 * The calling device admin must have requested
1092 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1093 * this method; if it has not, a security exception will be thrown.
1094 *
1095 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1096 * with.
1097 * @param length The new desired minimum number of upper case letters
1098 * required in the password. A value of 0 means there is no
1099 * restriction.
1100 */
Robin Lee25e26452015-06-02 09:56:29 -07001101 public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001102 if (mService != null) {
1103 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001104 mService.setPasswordMinimumUpperCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001105 } catch (RemoteException e) {
1106 Log.w(TAG, "Failed talking with device policy service", e);
1107 }
1108 }
1109 }
1110
1111 /**
1112 * Retrieve the current number of upper case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001113 * password for all admins of this user and its profiles or a particular one.
1114 * This is the same value as set by
1115 * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001116 * and only applies when the password quality is
1117 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001118 *
Robin Lee25e26452015-06-02 09:56:29 -07001119 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001120 * aggregate all admins.
1121 * @return The minimum number of upper case letters required in the
1122 * password.
1123 */
Robin Lee25e26452015-06-02 09:56:29 -07001124 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001125 return getPasswordMinimumUpperCase(admin, UserHandle.myUserId());
1126 }
1127
1128 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001129 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001130 if (mService != null) {
1131 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001132 return mService.getPasswordMinimumUpperCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001133 } catch (RemoteException e) {
1134 Log.w(TAG, "Failed talking with device policy service", e);
1135 }
1136 }
1137 return 0;
1138 }
1139
1140 /**
1141 * Called by an application that is administering the device to set the
1142 * minimum number of lower case letters required in the password. After
1143 * setting this, the user will not be able to enter a new password that is
1144 * not at least as restrictive as what has been set. Note that the current
1145 * password will remain until the user has set a new one, so the change does
1146 * not take place immediately. To prompt the user for a new password, use
1147 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1148 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001149 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1150 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001151 * <p>
1152 * The calling device admin must have requested
1153 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1154 * this method; if it has not, a security exception will be thrown.
1155 *
1156 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1157 * with.
1158 * @param length The new desired minimum number of lower case letters
1159 * required in the password. A value of 0 means there is no
1160 * restriction.
1161 */
Robin Lee25e26452015-06-02 09:56:29 -07001162 public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001163 if (mService != null) {
1164 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001165 mService.setPasswordMinimumLowerCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001166 } catch (RemoteException e) {
1167 Log.w(TAG, "Failed talking with device policy service", e);
1168 }
1169 }
1170 }
1171
1172 /**
1173 * Retrieve the current number of lower case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001174 * password for all admins of this user and its profiles or a particular one.
1175 * This is the same value as set by
1176 * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001177 * and only applies when the password quality is
1178 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001179 *
Robin Lee25e26452015-06-02 09:56:29 -07001180 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001181 * aggregate all admins.
1182 * @return The minimum number of lower case letters required in the
1183 * password.
1184 */
Robin Lee25e26452015-06-02 09:56:29 -07001185 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001186 return getPasswordMinimumLowerCase(admin, UserHandle.myUserId());
1187 }
1188
1189 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001190 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001191 if (mService != null) {
1192 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001193 return mService.getPasswordMinimumLowerCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001194 } catch (RemoteException e) {
1195 Log.w(TAG, "Failed talking with device policy service", e);
1196 }
1197 }
1198 return 0;
1199 }
1200
1201 /**
1202 * Called by an application that is administering the device to set the
1203 * minimum number of letters required in the password. After setting this,
1204 * the user will not be able to enter a new password that is not at least as
1205 * restrictive as what has been set. Note that the current password will
1206 * remain until the user has set a new one, so the change does not take
1207 * place immediately. To prompt the user for a new password, use
1208 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1209 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001210 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1211 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001212 * <p>
1213 * The calling device admin must have requested
1214 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1215 * this method; if it has not, a security exception will be thrown.
1216 *
1217 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1218 * with.
1219 * @param length The new desired minimum number of letters required in the
1220 * password. A value of 0 means there is no restriction.
1221 */
Robin Lee25e26452015-06-02 09:56:29 -07001222 public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001223 if (mService != null) {
1224 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001225 mService.setPasswordMinimumLetters(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001226 } catch (RemoteException e) {
1227 Log.w(TAG, "Failed talking with device policy service", e);
1228 }
1229 }
1230 }
1231
1232 /**
1233 * Retrieve the current number of letters required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001234 * admins or a particular one. This is the same value as
1235 * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)}
1236 * and only applies when the password quality is
1237 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001238 *
Robin Lee25e26452015-06-02 09:56:29 -07001239 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001240 * aggregate all admins.
1241 * @return The minimum number of letters required in the password.
1242 */
Robin Lee25e26452015-06-02 09:56:29 -07001243 public int getPasswordMinimumLetters(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001244 return getPasswordMinimumLetters(admin, UserHandle.myUserId());
1245 }
1246
1247 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001248 public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001249 if (mService != null) {
1250 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001251 return mService.getPasswordMinimumLetters(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001252 } catch (RemoteException e) {
1253 Log.w(TAG, "Failed talking with device policy service", e);
1254 }
1255 }
1256 return 0;
1257 }
1258
1259 /**
1260 * Called by an application that is administering the device to set the
1261 * minimum number of numerical digits required in the password. After
1262 * setting this, the user will not be able to enter a new password that is
1263 * not at least as restrictive as what has been set. Note that the current
1264 * password will remain until the user has set a new one, so the change does
1265 * not take place immediately. To prompt the user for a new password, use
1266 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1267 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001268 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1269 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001270 * <p>
1271 * The calling device admin must have requested
1272 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1273 * this method; if it has not, a security exception will be thrown.
1274 *
1275 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1276 * with.
1277 * @param length The new desired minimum number of numerical digits required
1278 * in the password. A value of 0 means there is no restriction.
1279 */
Robin Lee25e26452015-06-02 09:56:29 -07001280 public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001281 if (mService != null) {
1282 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001283 mService.setPasswordMinimumNumeric(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001284 } catch (RemoteException e) {
1285 Log.w(TAG, "Failed talking with device policy service", e);
1286 }
1287 }
1288 }
1289
1290 /**
1291 * Retrieve the current number of numerical digits required in the password
Jessica Hummel91da58d2014-04-10 17:39:43 +01001292 * for all admins of this user and its profiles or a particular one.
1293 * This is the same value as set by
1294 * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001295 * and only applies when the password quality is
1296 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001297 *
Robin Lee25e26452015-06-02 09:56:29 -07001298 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001299 * aggregate all admins.
1300 * @return The minimum number of numerical digits required in the password.
1301 */
Robin Lee25e26452015-06-02 09:56:29 -07001302 public int getPasswordMinimumNumeric(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001303 return getPasswordMinimumNumeric(admin, UserHandle.myUserId());
1304 }
1305
1306 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001307 public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001308 if (mService != null) {
1309 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001310 return mService.getPasswordMinimumNumeric(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001311 } catch (RemoteException e) {
1312 Log.w(TAG, "Failed talking with device policy service", e);
1313 }
1314 }
1315 return 0;
1316 }
1317
1318 /**
1319 * Called by an application that is administering the device to set the
1320 * minimum number of symbols required in the password. After setting this,
1321 * the user will not be able to enter a new password that is not at least as
1322 * restrictive as what has been set. Note that the current password will
1323 * remain until the user has set a new one, so the change does not take
1324 * place immediately. To prompt the user for a new password, use
1325 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1326 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001327 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1328 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001329 * <p>
1330 * The calling device admin must have requested
1331 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1332 * this method; if it has not, a security exception will be thrown.
1333 *
1334 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1335 * with.
1336 * @param length The new desired minimum number of symbols required in the
1337 * password. A value of 0 means there is no restriction.
1338 */
Robin Lee25e26452015-06-02 09:56:29 -07001339 public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001340 if (mService != null) {
1341 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001342 mService.setPasswordMinimumSymbols(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001343 } catch (RemoteException e) {
1344 Log.w(TAG, "Failed talking with device policy service", e);
1345 }
1346 }
1347 }
1348
1349 /**
1350 * Retrieve the current number of symbols required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001351 * admins or a particular one. This is the same value as
1352 * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)}
1353 * and only applies when the password quality is
1354 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001355 *
Robin Lee25e26452015-06-02 09:56:29 -07001356 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001357 * aggregate all admins.
1358 * @return The minimum number of symbols required in the password.
1359 */
Robin Lee25e26452015-06-02 09:56:29 -07001360 public int getPasswordMinimumSymbols(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001361 return getPasswordMinimumSymbols(admin, UserHandle.myUserId());
1362 }
1363
1364 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001365 public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001366 if (mService != null) {
1367 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001368 return mService.getPasswordMinimumSymbols(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001369 } catch (RemoteException e) {
1370 Log.w(TAG, "Failed talking with device policy service", e);
1371 }
1372 }
1373 return 0;
1374 }
1375
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001376 /**
1377 * Called by an application that is administering the device to set the
1378 * minimum number of non-letter characters (numerical digits or symbols)
1379 * required in the password. After setting this, the user will not be able
1380 * to enter a new password that is not at least as restrictive as what has
1381 * been set. Note that the current password will remain until the user has
1382 * set a new one, so the change does not take place immediately. To prompt
1383 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after
1384 * setting this value. This constraint is only imposed if the administrator
1385 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1386 * {@link #setPasswordQuality}. The default value is 0.
1387 * <p>
1388 * The calling device admin must have requested
1389 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1390 * this method; if it has not, a security exception will be thrown.
1391 *
1392 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1393 * with.
1394 * @param length The new desired minimum number of letters required in the
1395 * password. A value of 0 means there is no restriction.
1396 */
Robin Lee25e26452015-06-02 09:56:29 -07001397 public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001398 if (mService != null) {
1399 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001400 mService.setPasswordMinimumNonLetter(admin, length);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001401 } catch (RemoteException e) {
1402 Log.w(TAG, "Failed talking with device policy service", e);
1403 }
1404 }
1405 }
1406
1407 /**
1408 * Retrieve the current number of non-letter characters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001409 * password for all admins of this user and its profiles or a particular one.
1410 * This is the same value as set by
1411 * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001412 * and only applies when the password quality is
1413 * {@link #PASSWORD_QUALITY_COMPLEX}.
1414 *
Robin Lee25e26452015-06-02 09:56:29 -07001415 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001416 * aggregate all admins.
1417 * @return The minimum number of letters required in the password.
1418 */
Robin Lee25e26452015-06-02 09:56:29 -07001419 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001420 return getPasswordMinimumNonLetter(admin, UserHandle.myUserId());
1421 }
1422
1423 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001424 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001425 if (mService != null) {
1426 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001427 return mService.getPasswordMinimumNonLetter(admin, userHandle);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001428 } catch (RemoteException e) {
1429 Log.w(TAG, "Failed talking with device policy service", e);
1430 }
1431 }
1432 return 0;
1433 }
1434
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001435 /**
1436 * Called by an application that is administering the device to set the length
1437 * of the password history. After setting this, the user will not be able to
1438 * enter a new password that is the same as any password in the history. Note
1439 * that the current password will remain until the user has set a new one, so
1440 * the change does not take place immediately. To prompt the user for a new
1441 * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
1442 * This constraint is only imposed if the administrator has also requested
Jim Miller85516d02014-01-31 17:08:37 -08001443 * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}
1444 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1445 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001446 *
1447 * <p>
1448 * The calling device admin must have requested
1449 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
1450 * method; if it has not, a security exception will be thrown.
1451 *
1452 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1453 * with.
1454 * @param length The new desired length of password history. A value of 0
1455 * means there is no restriction.
1456 */
Robin Lee25e26452015-06-02 09:56:29 -07001457 public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001458 if (mService != null) {
1459 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001460 mService.setPasswordHistoryLength(admin, length);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001461 } catch (RemoteException e) {
1462 Log.w(TAG, "Failed talking with device policy service", e);
1463 }
1464 }
1465 }
1466
1467 /**
Jim Millera4e28d12010-11-08 16:15:47 -08001468 * Called by a device admin to set the password expiration timeout. Calling this method
1469 * will restart the countdown for password expiration for the given admin, as will changing
1470 * the device password (for all admins).
1471 *
1472 * <p>The provided timeout is the time delta in ms and will be added to the current time.
1473 * For example, to have the password expire 5 days from now, timeout would be
1474 * 5 * 86400 * 1000 = 432000000 ms for timeout.
1475 *
1476 * <p>To disable password expiration, a value of 0 may be used for timeout.
1477 *
Jim Millera4e28d12010-11-08 16:15:47 -08001478 * <p>The calling device admin must have requested
1479 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
1480 * method; if it has not, a security exception will be thrown.
1481 *
Jessica Hummel9da60392014-05-21 12:32:57 +01001482 * <p> Note that setting the password will automatically reset the expiration time for all
1483 * active admins. Active admins do not need to explicitly call this method in that case.
1484 *
Jim Millera4e28d12010-11-08 16:15:47 -08001485 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1486 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
1487 * means there is no restriction (unlimited).
1488 */
Robin Lee25e26452015-06-02 09:56:29 -07001489 public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) {
Jim Millera4e28d12010-11-08 16:15:47 -08001490 if (mService != null) {
1491 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001492 mService.setPasswordExpirationTimeout(admin, timeout);
Jim Millera4e28d12010-11-08 16:15:47 -08001493 } catch (RemoteException e) {
1494 Log.w(TAG, "Failed talking with device policy service", e);
1495 }
1496 }
1497 }
1498
1499 /**
Jim Miller6b857682011-02-16 16:27:41 -08001500 * Get the password expiration timeout for the given admin. The expiration timeout is the
1501 * recurring expiration timeout provided in the call to
1502 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
Robin Lee25e26452015-06-02 09:56:29 -07001503 * aggregate of all policy administrators if {@code admin} is null.
Jim Millera4e28d12010-11-08 16:15:47 -08001504 *
Robin Lee25e26452015-06-02 09:56:29 -07001505 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001506 * @return The timeout for the given admin or the minimum of all timeouts
1507 */
Robin Lee25e26452015-06-02 09:56:29 -07001508 public long getPasswordExpirationTimeout(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001509 if (mService != null) {
1510 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001511 return mService.getPasswordExpirationTimeout(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001512 } catch (RemoteException e) {
1513 Log.w(TAG, "Failed talking with device policy service", e);
1514 }
1515 }
1516 return 0;
1517 }
1518
1519 /**
1520 * Get the current password expiration time for the given admin or an aggregate of
Jessica Hummel91da58d2014-04-10 17:39:43 +01001521 * all admins of this user and its profiles if admin is null. If the password is
1522 * expired, this will return the time since the password expired as a negative number.
1523 * If admin is null, then a composite of all expiration timeouts is returned
1524 * - which will be the minimum of all timeouts.
Jim Millera4e28d12010-11-08 16:15:47 -08001525 *
Robin Lee25e26452015-06-02 09:56:29 -07001526 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001527 * @return The password expiration time, in ms.
1528 */
Robin Lee25e26452015-06-02 09:56:29 -07001529 public long getPasswordExpiration(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001530 if (mService != null) {
1531 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001532 return mService.getPasswordExpiration(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001533 } catch (RemoteException e) {
1534 Log.w(TAG, "Failed talking with device policy service", e);
1535 }
1536 }
1537 return 0;
1538 }
1539
1540 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001541 * Retrieve the current password history length for all admins of this
1542 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001543 * @param admin The name of the admin component to check, or {@code null} to aggregate
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001544 * all admins.
1545 * @return The length of the password history
1546 */
Robin Lee25e26452015-06-02 09:56:29 -07001547 public int getPasswordHistoryLength(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001548 return getPasswordHistoryLength(admin, UserHandle.myUserId());
1549 }
1550
1551 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001552 public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001553 if (mService != null) {
1554 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001555 return mService.getPasswordHistoryLength(admin, userHandle);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001556 } catch (RemoteException e) {
1557 Log.w(TAG, "Failed talking with device policy service", e);
1558 }
1559 }
1560 return 0;
1561 }
1562
Dianne Hackbornd6847842010-01-12 18:14:19 -08001563 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001564 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001565 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08001566 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001567 * @return Returns the maximum length that the user can enter.
1568 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001569 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001570 // Kind-of arbitrary.
1571 return 16;
1572 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001573
Dianne Hackborn254cb442010-01-27 19:23:59 -08001574 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001575 * Determine whether the current password the user has set is sufficient
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001576 * to meet the policy requirements (quality, minimum length) that have been
Jessica Hummel91da58d2014-04-10 17:39:43 +01001577 * requested by the admins of this user and its profiles.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001578 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001579 * <p>The calling device admin must have requested
1580 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1581 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001582 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001583 * @return Returns true if the password meets the current requirements, else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001584 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001585 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001586 if (mService != null) {
1587 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001588 return mService.isActivePasswordSufficient(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001589 } catch (RemoteException e) {
1590 Log.w(TAG, "Failed talking with device policy service", e);
1591 }
1592 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001593 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001594 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001595
Dianne Hackbornd6847842010-01-12 18:14:19 -08001596 /**
1597 * Retrieve the number of times the user has failed at entering a
1598 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001599 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001600 * <p>The calling device admin must have requested
1601 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
1602 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001603 */
1604 public int getCurrentFailedPasswordAttempts() {
1605 if (mService != null) {
1606 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001607 return mService.getCurrentFailedPasswordAttempts(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001608 } catch (RemoteException e) {
1609 Log.w(TAG, "Failed talking with device policy service", e);
1610 }
1611 }
1612 return -1;
1613 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001614
1615 /**
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001616 * Queries whether {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001617 *
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001618 * @return true if RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001619 * @hide
1620 */
1621 public boolean getDoNotAskCredentialsOnBoot() {
1622 if (mService != null) {
1623 try {
1624 return mService.getDoNotAskCredentialsOnBoot();
1625 } catch (RemoteException e) {
1626 Log.w(TAG, "Failed to call getDoNotAskCredentialsOnBoot()", e);
1627 }
1628 }
1629 return false;
1630 }
1631
1632 /**
Andrew Stadler88209d12010-02-08 22:59:36 -08001633 * Setting this to a value greater than zero enables a built-in policy
1634 * that will perform a device wipe after too many incorrect
1635 * device-unlock passwords have been entered. This built-in policy combines
1636 * watching for failed passwords and wiping the device, and requires
1637 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001638 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001639 *
Andrew Stadler88209d12010-02-08 22:59:36 -08001640 * <p>To implement any other policy (e.g. wiping data for a particular
1641 * application only, erasing or revoking credentials, or reporting the
1642 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001643 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -08001644 * instead. Do not use this API, because if the maximum count is reached,
1645 * the device will be wiped immediately, and your callback will not be invoked.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001646 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001647 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001648 * @param num The number of failed password attempts at which point the
1649 * device will wipe its data.
1650 */
Robin Lee25e26452015-06-02 09:56:29 -07001651 public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001652 if (mService != null) {
1653 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001654 mService.setMaximumFailedPasswordsForWipe(admin, num);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001655 } catch (RemoteException e) {
1656 Log.w(TAG, "Failed talking with device policy service", e);
1657 }
1658 }
1659 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001660
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001661 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001662 * Retrieve the current maximum number of login attempts that are allowed
Jessica Hummel91da58d2014-04-10 17:39:43 +01001663 * before the device wipes itself, for all admins of this user and its profiles
Dianne Hackborn254cb442010-01-27 19:23:59 -08001664 * or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001665 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001666 * all admins.
1667 */
Robin Lee25e26452015-06-02 09:56:29 -07001668 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001669 return getMaximumFailedPasswordsForWipe(admin, UserHandle.myUserId());
1670 }
1671
1672 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001673 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001674 if (mService != null) {
1675 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001676 return mService.getMaximumFailedPasswordsForWipe(admin, userHandle);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001677 } catch (RemoteException e) {
1678 Log.w(TAG, "Failed talking with device policy service", e);
1679 }
1680 }
1681 return 0;
1682 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001683
Dianne Hackborn254cb442010-01-27 19:23:59 -08001684 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07001685 * Returns the profile with the smallest maximum failed passwords for wipe,
1686 * for the given user. So for primary user, it might return the primary or
1687 * a managed profile. For a secondary user, it would be the same as the
1688 * user passed in.
1689 * @hide Used only by Keyguard
1690 */
1691 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
1692 if (mService != null) {
1693 try {
1694 return mService.getProfileWithMinimumFailedPasswordsForWipe(userHandle);
1695 } catch (RemoteException e) {
1696 Log.w(TAG, "Failed talking with device policy service", e);
1697 }
1698 }
1699 return UserHandle.USER_NULL;
1700 }
1701
1702 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001703 * Flag for {@link #resetPassword}: don't allow other admins to change
1704 * the password again until the user has entered it.
1705 */
1706 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001707
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001708 /**
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001709 * Flag for {@link #resetPassword}: don't ask for user credentials on device boot.
1710 * If the flag is set, the device can be booted without asking for user password.
1711 * The absence of this flag does not change the current boot requirements. This flag
1712 * can be set by the device owner only. If the app is not the device owner, the flag
1713 * is ignored. Once the flag is set, it cannot be reverted back without resetting the
1714 * device to factory defaults.
1715 */
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001716 public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002;
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001717
1718 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001719 * Force a new device unlock password (the password needed to access the
1720 * entire device, not for individual accounts) on the user. This takes
1721 * effect immediately.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001722 * The given password must be sufficient for the
1723 * current password quality and length constraints as returned by
1724 * {@link #getPasswordQuality(ComponentName)} and
1725 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
1726 * these constraints, then it will be rejected and false returned. Note
1727 * that the password may be a stronger quality (containing alphanumeric
1728 * characters when the requested quality is only numeric), in which case
1729 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001730 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001731 * <p>Calling with a null or empty password will clear any existing PIN,
1732 * pattern or password if the current password constraints allow it.
1733 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001734 * <p>The calling device admin must have requested
1735 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
1736 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001737 *
Amith Yamasani242f4b12014-10-14 16:06:13 -07001738 * <p>Calling this from a managed profile will throw a security exception.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001739 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001740 * @param password The new password for the user. Null or empty clears the password.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001741 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001742 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001743 * @return Returns true if the password was applied, or false if it is
1744 * not acceptable for the current constraints.
1745 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001746 public boolean resetPassword(String password, int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001747 if (mService != null) {
1748 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001749 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001750 } catch (RemoteException e) {
1751 Log.w(TAG, "Failed talking with device policy service", e);
1752 }
1753 }
1754 return false;
1755 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001756
Dianne Hackbornd6847842010-01-12 18:14:19 -08001757 /**
1758 * Called by an application that is administering the device to set the
1759 * maximum time for user activity until the device will lock. This limits
1760 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001761 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001762 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -08001763 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001764 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001765 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001766 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001767 * @param timeMs The new desired maximum time to lock in milliseconds.
1768 * A value of 0 means there is no restriction.
1769 */
Robin Lee25e26452015-06-02 09:56:29 -07001770 public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001771 if (mService != null) {
1772 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001773 mService.setMaximumTimeToLock(admin, timeMs);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001774 } catch (RemoteException e) {
1775 Log.w(TAG, "Failed talking with device policy service", e);
1776 }
1777 }
1778 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001779
Dianne Hackbornd6847842010-01-12 18:14:19 -08001780 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001781 * Retrieve the current maximum time to unlock for all admins of this user
1782 * and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001783 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001784 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07001785 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07001786 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001787 */
Robin Lee25e26452015-06-02 09:56:29 -07001788 public long getMaximumTimeToLock(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001789 return getMaximumTimeToLock(admin, UserHandle.myUserId());
1790 }
1791
1792 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001793 public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001794 if (mService != null) {
1795 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001796 return mService.getMaximumTimeToLock(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001797 } catch (RemoteException e) {
1798 Log.w(TAG, "Failed talking with device policy service", e);
1799 }
1800 }
1801 return 0;
1802 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001803
Dianne Hackbornd6847842010-01-12 18:14:19 -08001804 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001805 * Make the device lock immediately, as if the lock screen timeout has
1806 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001807 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001808 * <p>The calling device admin must have requested
1809 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
1810 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001811 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001812 public void lockNow() {
1813 if (mService != null) {
1814 try {
1815 mService.lockNow();
1816 } catch (RemoteException e) {
1817 Log.w(TAG, "Failed talking with device policy service", e);
1818 }
1819 }
1820 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001821
Dianne Hackbornd6847842010-01-12 18:14:19 -08001822 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07001823 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001824 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07001825 */
1826 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
1827
1828 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001829 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
1830 * data.
1831 *
Paul Crowley2934b262014-12-02 11:21:13 +00001832 * <p>This flag may only be set by device owner admins; if it is set by
1833 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001834 */
1835 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
1836
1837 /**
Robin Lee85bd63f2015-02-10 11:51:00 +00001838 * Ask the user data be wiped. Wiping the primary user will cause the
1839 * device to reboot, erasing all user data while next booting up.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001840 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001841 * <p>The calling device admin must have requested
1842 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
1843 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001844 *
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001845 * @param flags Bit mask of additional options: currently supported flags
1846 * are {@link #WIPE_EXTERNAL_STORAGE} and
1847 * {@link #WIPE_RESET_PROTECTION_DATA}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001848 */
1849 public void wipeData(int flags) {
1850 if (mService != null) {
1851 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001852 mService.wipeData(flags, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001853 } catch (RemoteException e) {
1854 Log.w(TAG, "Failed talking with device policy service", e);
1855 }
1856 }
1857 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001858
Dianne Hackbornd6847842010-01-12 18:14:19 -08001859 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001860 * Called by an application that is administering the device to set the
1861 * global proxy and exclusion list.
1862 * <p>
1863 * The calling device admin must have requested
1864 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
1865 * this method; if it has not, a security exception will be thrown.
1866 * Only the first device admin can set the proxy. If a second admin attempts
1867 * to set the proxy, the {@link ComponentName} of the admin originally setting the
Robin Lee25e26452015-06-02 09:56:29 -07001868 * proxy will be returned. If successful in setting the proxy, {@code null} will
Oscar Montemayor69238c62010-08-03 10:51:06 -07001869 * be returned.
1870 * The method can be called repeatedly by the device admin alrady setting the
1871 * proxy to update the proxy and exclusion list.
1872 *
Robin Lee25e26452015-06-02 09:56:29 -07001873 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Oscar Montemayor69238c62010-08-03 10:51:06 -07001874 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
1875 * Pass Proxy.NO_PROXY to reset the proxy.
1876 * @param exclusionList a list of domains to be excluded from the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07001877 * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName}
1878 * of the device admin that sets the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08001879 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001880 */
Robin Lee25e26452015-06-02 09:56:29 -07001881 public ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec,
Oscar Montemayor69238c62010-08-03 10:51:06 -07001882 List<String> exclusionList ) {
1883 if (proxySpec == null) {
1884 throw new NullPointerException();
1885 }
1886 if (mService != null) {
1887 try {
1888 String hostSpec;
1889 String exclSpec;
1890 if (proxySpec.equals(Proxy.NO_PROXY)) {
1891 hostSpec = null;
1892 exclSpec = null;
1893 } else {
1894 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
1895 throw new IllegalArgumentException();
1896 }
1897 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
1898 String hostName = sa.getHostName();
1899 int port = sa.getPort();
1900 StringBuilder hostBuilder = new StringBuilder();
1901 hostSpec = hostBuilder.append(hostName)
1902 .append(":").append(Integer.toString(port)).toString();
1903 if (exclusionList == null) {
1904 exclSpec = "";
1905 } else {
1906 StringBuilder listBuilder = new StringBuilder();
1907 boolean firstDomain = true;
1908 for (String exclDomain : exclusionList) {
1909 if (!firstDomain) {
1910 listBuilder = listBuilder.append(",");
1911 } else {
1912 firstDomain = false;
1913 }
1914 listBuilder = listBuilder.append(exclDomain.trim());
1915 }
1916 exclSpec = listBuilder.toString();
1917 }
Yuhao Zheng90704842014-02-28 17:22:45 -08001918 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
1919 != android.net.Proxy.PROXY_VALID)
1920 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07001921 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001922 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07001923 } catch (RemoteException e) {
1924 Log.w(TAG, "Failed talking with device policy service", e);
1925 }
1926 }
1927 return null;
1928 }
1929
1930 /**
Jason Monk03bc9912014-05-13 09:44:57 -04001931 * Set a network-independent global HTTP proxy. This is not normally what you want
1932 * for typical HTTP proxies - they are generally network dependent. However if you're
1933 * doing something unusual like general internal filtering this may be useful. On
1934 * a private network where the proxy is not accessible, you may break HTTP using this.
1935 *
1936 * <p>This method requires the caller to be the device owner.
1937 *
1938 * <p>This proxy is only a recommendation and it is possible that some apps will ignore it.
1939 * @see ProxyInfo
1940 *
1941 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1942 * with.
1943 * @param proxyInfo The a {@link ProxyInfo} object defining the new global
1944 * HTTP proxy. A {@code null} value will clear the global HTTP proxy.
1945 */
Robin Lee25e26452015-06-02 09:56:29 -07001946 public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo
1947 proxyInfo) {
Jason Monk03bc9912014-05-13 09:44:57 -04001948 if (mService != null) {
1949 try {
1950 mService.setRecommendedGlobalProxy(admin, proxyInfo);
1951 } catch (RemoteException e) {
1952 Log.w(TAG, "Failed talking with device policy service", e);
1953 }
1954 }
1955 }
1956
1957 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001958 * Returns the component name setting the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07001959 * @return ComponentName object of the device admin that set the global proxy, or {@code null}
1960 * if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08001961 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001962 */
1963 public ComponentName getGlobalProxyAdmin() {
1964 if (mService != null) {
1965 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001966 return mService.getGlobalProxyAdmin(UserHandle.myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07001967 } catch (RemoteException e) {
1968 Log.w(TAG, "Failed talking with device policy service", e);
1969 }
1970 }
1971 return null;
1972 }
1973
1974 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001975 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001976 * indicating that encryption is not supported.
1977 */
1978 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
1979
1980 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001981 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001982 * indicating that encryption is supported, but is not currently active.
1983 */
1984 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
1985
1986 /**
Robin Lee3795fb02015-02-16 14:17:23 +00001987 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001988 * indicating that encryption is not currently active, but is currently
1989 * being activated. This is only reported by devices that support
1990 * encryption of data and only when the storage is currently
1991 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
1992 * to become encrypted will never return this value.
1993 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001994 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001995
1996 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001997 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001998 * indicating that encryption is active.
1999 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002000 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002001
2002 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002003 * Result code for {@link #getStorageEncryptionStatus}:
2004 * indicating that encryption is active, but an encryption key has not
2005 * been set by the user.
2006 */
2007 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
2008
2009 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002010 * Activity action: begin the process of encrypting data on the device. This activity should
2011 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
2012 * After resuming from this activity, use {@link #getStorageEncryption}
2013 * to check encryption status. However, on some devices this activity may never return, as
2014 * it may trigger a reboot and in some cases a complete data wipe of the device.
2015 */
2016 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
2017 public static final String ACTION_START_ENCRYPTION
2018 = "android.app.action.START_ENCRYPTION";
2019
2020 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07002021 * Widgets are enabled in keyguard
2022 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002023 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07002024
2025 /**
Jim Miller50e62182014-04-23 17:25:00 -07002026 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07002027 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002028 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
2029
2030 /**
2031 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
2032 */
2033 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
2034
2035 /**
Jim Miller50e62182014-04-23 17:25:00 -07002036 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2037 */
2038 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
2039
2040 /**
2041 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2042 */
2043 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
2044
2045 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02002046 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07002047 * (e.g. PIN/Pattern/Password).
2048 */
2049 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
2050
2051 /**
Jim Miller06e34502014-07-17 14:46:05 -07002052 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
2053 */
2054 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
2055
2056 /**
Jim Miller35207742012-11-02 15:33:20 -07002057 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07002058 */
2059 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07002060
2061 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002062 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002063 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002064 *
2065 * <p>When multiple device administrators attempt to control device
2066 * encryption, the most secure, supported setting will always be
2067 * used. If any device administrator requests device encryption,
2068 * it will be enabled; Conversely, if a device administrator
2069 * attempts to disable device encryption while another
2070 * device administrator has enabled it, the call to disable will
2071 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
2072 *
2073 * <p>This policy controls encryption of the secure (application data) storage area. Data
Andy Stadler50c294f2011-03-07 19:13:42 -08002074 * written to other storage areas may or may not be encrypted, and this policy does not require
2075 * or control the encryption of any other storage areas.
2076 * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is
2077 * {@code true}, then the directory returned by
2078 * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk
2079 * within the encrypted storage area.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002080 *
2081 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
2082 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
2083 * the encryption key may not be fully secured. For maximum security, the administrator should
2084 * also require (and check for) a pattern, PIN, or password.
2085 *
2086 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2087 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08002088 * @return the new request status (for all active admins) - will be one of
2089 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
2090 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
2091 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002092 */
Robin Lee25e26452015-06-02 09:56:29 -07002093 public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002094 if (mService != null) {
2095 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002096 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002097 } catch (RemoteException e) {
2098 Log.w(TAG, "Failed talking with device policy service", e);
2099 }
2100 }
2101 return ENCRYPTION_STATUS_UNSUPPORTED;
2102 }
2103
2104 /**
2105 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002106 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002107 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08002108 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
2109 * this will return the requested encryption setting as an aggregate of all active
2110 * administrators.
2111 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002112 */
Robin Lee25e26452015-06-02 09:56:29 -07002113 public boolean getStorageEncryption(@Nullable ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002114 if (mService != null) {
2115 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002116 return mService.getStorageEncryption(admin, UserHandle.myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002117 } catch (RemoteException e) {
2118 Log.w(TAG, "Failed talking with device policy service", e);
2119 }
2120 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08002121 return false;
2122 }
2123
2124 /**
2125 * Called by an application that is administering the device to
2126 * determine the current encryption status of the device.
2127 *
2128 * Depending on the returned status code, the caller may proceed in different
2129 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
2130 * storage system does not support encryption. If the
2131 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
2132 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00002133 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
2134 * storage system has enabled encryption but no password is set so further action
2135 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
Andy Stadler22dbfda2011-01-17 12:47:31 -08002136 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
2137 *
Robin Lee7e678712014-07-24 16:41:31 +01002138 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08002139 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00002140 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
2141 * or {@link #ENCRYPTION_STATUS_ACTIVE}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08002142 */
2143 public int getStorageEncryptionStatus() {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002144 return getStorageEncryptionStatus(UserHandle.myUserId());
2145 }
2146
2147 /** @hide per-user version */
2148 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08002149 if (mService != null) {
2150 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002151 return mService.getStorageEncryptionStatus(userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08002152 } catch (RemoteException e) {
2153 Log.w(TAG, "Failed talking with device policy service", e);
2154 }
2155 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002156 return ENCRYPTION_STATUS_UNSUPPORTED;
2157 }
2158
2159 /**
Robin Lee7e678712014-07-24 16:41:31 +01002160 * Installs the given certificate as a user CA.
2161 *
Robin Lee25e26452015-06-02 09:56:29 -07002162 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2163 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002164 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04002165 *
2166 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01002167 * interrupted, true otherwise.
Maggie Benthallda51e682013-08-08 22:35:44 -04002168 */
Robin Lee25e26452015-06-02 09:56:29 -07002169 public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002170 if (mService != null) {
2171 try {
Robin Lee7e678712014-07-24 16:41:31 +01002172 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04002173 } catch (RemoteException e) {
2174 Log.w(TAG, "Failed talking with device policy service", e);
2175 }
2176 }
2177 return false;
2178 }
2179
2180 /**
Robin Lee7e678712014-07-24 16:41:31 +01002181 * Uninstalls the given certificate from trusted user CAs, if present.
2182 *
Robin Lee25e26452015-06-02 09:56:29 -07002183 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2184 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002185 * @param certBuffer encoded form of the certificate to remove.
Maggie Benthallda51e682013-08-08 22:35:44 -04002186 */
Robin Lee25e26452015-06-02 09:56:29 -07002187 public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002188 if (mService != null) {
2189 try {
Robin Lee306fe082014-06-19 14:04:24 +00002190 final String alias = getCaCertAlias(certBuffer);
Robin Lee83881bd2015-06-09 16:04:38 -07002191 mService.uninstallCaCerts(admin, new String[] {alias});
Robin Lee306fe082014-06-19 14:04:24 +00002192 } catch (CertificateException e) {
2193 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002194 } catch (RemoteException e) {
2195 Log.w(TAG, "Failed talking with device policy service", e);
2196 }
2197 }
2198 }
2199
2200 /**
Robin Lee7e678712014-07-24 16:41:31 +01002201 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
2202 * If a user has installed any certificates by other means than device policy these will be
2203 * included too.
2204 *
Robin Lee25e26452015-06-02 09:56:29 -07002205 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2206 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002207 * @return a List of byte[] arrays, each encoding one user CA certificate.
Maggie Benthallda51e682013-08-08 22:35:44 -04002208 */
Robin Lee25e26452015-06-02 09:56:29 -07002209 public List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002210 List<byte[]> certs = new ArrayList<byte[]>();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002211 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01002212 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002213 mService.enforceCanManageCaCerts(admin);
2214 final TrustedCertificateStore certStore = new TrustedCertificateStore();
2215 for (String alias : certStore.userAliases()) {
2216 try {
2217 certs.add(certStore.getCertificate(alias).getEncoded());
2218 } catch (CertificateException ce) {
2219 Log.w(TAG, "Could not encode certificate: " + alias, ce);
2220 }
2221 }
2222 } catch (RemoteException re) {
2223 Log.w(TAG, "Failed talking with device policy service", re);
Robin Lee7e678712014-07-24 16:41:31 +01002224 }
2225 }
2226 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04002227 }
2228
2229 /**
Robin Lee7e678712014-07-24 16:41:31 +01002230 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
2231 * means other than device policy will also be removed, except for system CA certificates.
2232 *
Robin Lee25e26452015-06-02 09:56:29 -07002233 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2234 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002235 */
Robin Lee25e26452015-06-02 09:56:29 -07002236 public void uninstallAllUserCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002237 if (mService != null) {
Robin Lee83881bd2015-06-09 16:04:38 -07002238 try {
2239 mService.uninstallCaCerts(admin, new TrustedCertificateStore().userAliases()
2240 .toArray(new String[0]));
2241 } catch (RemoteException re) {
2242 Log.w(TAG, "Failed talking with device policy service", re);
Robin Lee7e678712014-07-24 16:41:31 +01002243 }
2244 }
2245 }
2246
2247 /**
2248 * Returns whether this certificate is installed as a trusted CA.
2249 *
Robin Lee25e26452015-06-02 09:56:29 -07002250 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2251 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002252 * @param certBuffer encoded form of the certificate to look up.
Maggie Benthallda51e682013-08-08 22:35:44 -04002253 */
Robin Lee25e26452015-06-02 09:56:29 -07002254 public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002255 if (mService != null) {
2256 try {
2257 mService.enforceCanManageCaCerts(admin);
2258 return getCaCertAlias(certBuffer) != null;
2259 } catch (RemoteException re) {
2260 Log.w(TAG, "Failed talking with device policy service", re);
2261 } catch (CertificateException ce) {
2262 Log.w(TAG, "Could not parse certificate", ce);
2263 }
Maggie Benthallda51e682013-08-08 22:35:44 -04002264 }
2265 return false;
2266 }
2267
2268 /**
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002269 * Called by a device or profile owner to install a certificate and private key pair. The
2270 * keypair will be visible to all apps within the profile.
2271 *
Robin Lee25e26452015-06-02 09:56:29 -07002272 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2273 * {@code null} if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002274 * @param privKey The private key to install.
2275 * @param cert The certificate to install.
2276 * @param alias The private key alias under which to install the certificate. If a certificate
2277 * with that alias already exists, it will be overwritten.
2278 * @return {@code true} if the keys were installed, {@code false} otherwise.
2279 */
Robin Lee25e26452015-06-02 09:56:29 -07002280 public boolean installKeyPair(@Nullable ComponentName admin, PrivateKey privKey, Certificate cert,
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002281 String alias) {
2282 try {
2283 final byte[] pemCert = Credentials.convertToPem(cert);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002284 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
2285 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
Robin Lee25e26452015-06-02 09:56:29 -07002286 return mService.installKeyPair(admin, pkcs8Key, pemCert, alias);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002287 } catch (RemoteException e) {
2288 Log.w(TAG, "Failed talking with device policy service", e);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002289 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
2290 Log.w(TAG, "Failed to obtain private key material", e);
2291 } catch (CertificateException | IOException e) {
2292 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002293 }
2294 return false;
2295 }
2296
2297 /**
Robin Lee25e26452015-06-02 09:56:29 -07002298 * @return the alias of a given CA certificate in the certificate store, or {@code null} if it
Robin Lee306fe082014-06-19 14:04:24 +00002299 * doesn't exist.
2300 */
2301 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
2302 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
2303 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
2304 new ByteArrayInputStream(certBuffer));
2305 return new TrustedCertificateStore().getCertificateAlias(cert);
2306 }
2307
2308 /**
Rubin Xuec32b562015-03-03 17:34:05 +00002309 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01002310 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00002311 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01002312 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00002313 * <p>
2314 * Delegated certificate installer is a per-user state. The delegated access is persistent until
2315 * it is later cleared by calling this method with a null value or uninstallling the certificate
2316 * installer.
2317 *
Robin Lee25e26452015-06-02 09:56:29 -07002318 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xuec32b562015-03-03 17:34:05 +00002319 * @param installerPackage The package name of the certificate installer which will be given
Robin Lee25e26452015-06-02 09:56:29 -07002320 * access. If {@code null} is given the current package will be cleared.
Rubin Xuec32b562015-03-03 17:34:05 +00002321 */
Robin Lee25e26452015-06-02 09:56:29 -07002322 public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String
2323 installerPackage) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002324 if (mService != null) {
2325 try {
Robin Lee25e26452015-06-02 09:56:29 -07002326 mService.setCertInstallerPackage(admin, installerPackage);
Rubin Xuec32b562015-03-03 17:34:05 +00002327 } catch (RemoteException e) {
2328 Log.w(TAG, "Failed talking with device policy service", e);
2329 }
2330 }
2331 }
2332
2333 /**
2334 * Called by a profile owner or device owner to retrieve the certificate installer for the
2335 * current user. null if none is set.
2336 *
Robin Lee25e26452015-06-02 09:56:29 -07002337 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2338 * @return The package name of the current delegated certificate installer, or {@code null}
Rubin Xuec32b562015-03-03 17:34:05 +00002339 * if none is set.
2340 */
Robin Lee25e26452015-06-02 09:56:29 -07002341 public String getCertInstallerPackage(@NonNull ComponentName admin) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002342 if (mService != null) {
2343 try {
Robin Lee25e26452015-06-02 09:56:29 -07002344 return mService.getCertInstallerPackage(admin);
Rubin Xuec32b562015-03-03 17:34:05 +00002345 } catch (RemoteException e) {
2346 Log.w(TAG, "Failed talking with device policy service", e);
2347 }
2348 }
2349 return null;
2350 }
2351
2352 /**
Ben Komalo2447edd2011-05-09 16:05:33 -07002353 * Called by an application that is administering the device to disable all cameras
Amith Yamasani242f4b12014-10-14 16:06:13 -07002354 * on the device, for this user. After setting this, no applications running as this user
2355 * will be able to access any cameras on the device.
Ben Komalo2447edd2011-05-09 16:05:33 -07002356 *
2357 * <p>The calling device admin must have requested
2358 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
2359 * this method; if it has not, a security exception will be thrown.
2360 *
2361 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2362 * @param disabled Whether or not the camera should be disabled.
2363 */
Robin Lee25e26452015-06-02 09:56:29 -07002364 public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002365 if (mService != null) {
2366 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002367 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07002368 } catch (RemoteException e) {
2369 Log.w(TAG, "Failed talking with device policy service", e);
2370 }
2371 }
2372 }
2373
2374 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07002375 * Determine whether or not the device's cameras have been disabled for this user,
2376 * either by the current admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002377 * @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 -07002378 * have disabled the camera
2379 */
Robin Lee25e26452015-06-02 09:56:29 -07002380 public boolean getCameraDisabled(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002381 return getCameraDisabled(admin, UserHandle.myUserId());
2382 }
2383
2384 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002385 public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002386 if (mService != null) {
2387 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002388 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07002389 } catch (RemoteException e) {
2390 Log.w(TAG, "Failed talking with device policy service", e);
2391 }
2392 }
2393 return false;
2394 }
2395
2396 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01002397 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
2398 * screen capture also prevents the content from being shown on display devices that do not have
2399 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
2400 * secure surfaces and secure displays.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002401 *
2402 * <p>The calling device admin must be a device or profile owner. If it is not, a
2403 * security exception will be thrown.
2404 *
2405 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002406 * @param disabled Whether screen capture is disabled or not.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002407 */
Robin Lee25e26452015-06-02 09:56:29 -07002408 public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002409 if (mService != null) {
2410 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002411 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002412 } catch (RemoteException e) {
2413 Log.w(TAG, "Failed talking with device policy service", e);
2414 }
2415 }
2416 }
2417
2418 /**
2419 * Determine whether or not screen capture has been disabled by the current
2420 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002421 * @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 +01002422 * have disabled screen capture.
2423 */
Robin Lee25e26452015-06-02 09:56:29 -07002424 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002425 return getScreenCaptureDisabled(admin, UserHandle.myUserId());
2426 }
2427
2428 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002429 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002430 if (mService != null) {
2431 try {
2432 return mService.getScreenCaptureDisabled(admin, userHandle);
2433 } catch (RemoteException e) {
2434 Log.w(TAG, "Failed talking with device policy service", e);
2435 }
2436 }
2437 return false;
2438 }
2439
2440 /**
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002441 * Called by a device owner to set whether auto time is required. If auto time is
2442 * required the user cannot set the date and time, but has to use network date and time.
2443 *
2444 * <p>Note: if auto time is required the user can still manually set the time zone.
2445 *
2446 * <p>The calling device admin must be a device owner. If it is not, a security exception will
2447 * be thrown.
2448 *
2449 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2450 * @param required Whether auto time is set required or not.
2451 */
Robin Lee25e26452015-06-02 09:56:29 -07002452 public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) {
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002453 if (mService != null) {
2454 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002455 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002456 } catch (RemoteException e) {
2457 Log.w(TAG, "Failed talking with device policy service", e);
2458 }
2459 }
2460 }
2461
2462 /**
2463 * @return true if auto time is required.
2464 */
2465 public boolean getAutoTimeRequired() {
2466 if (mService != null) {
2467 try {
2468 return mService.getAutoTimeRequired();
2469 } catch (RemoteException e) {
2470 Log.w(TAG, "Failed talking with device policy service", e);
2471 }
2472 }
2473 return false;
2474 }
2475
2476 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002477 * Called by an application that is administering the device to disable keyguard customizations,
2478 * such as widgets. After setting this, keyguard features will be disabled according to the
2479 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002480 *
2481 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07002482 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07002483 * this method; if it has not, a security exception will be thrown.
2484 *
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002485 * <p>Calling this from a managed profile before version
2486 * {@link android.os.Build.VERSION_CODES#MNC} will throw a security exception.
2487 *
2488 * <p>From version {@link android.os.Build.VERSION_CODES#MNC} a profile owner can set:
2489 * <ul>
2490 * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, {@link #KEYGUARD_DISABLE_FINGERPRINT}
2491 * these will affect the profile's parent user.
2492 * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} this will affect notifications
2493 * generated by applications in the managed profile.
2494 * </ul>
2495 * <p>Requests to disable other features on a managed profile will be ignored. The admin
2496 * can check which features have been disabled by calling
2497 * {@link #getKeyguardDisabledFeatures(ComponentName)}
Amith Yamasani242f4b12014-10-14 16:06:13 -07002498 *
Jim Millerb8ec4702012-08-31 17:19:10 -07002499 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07002500 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
2501 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
Jim Miller50e62182014-04-23 17:25:00 -07002502 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002503 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FINGERPRINT},
2504 * {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07002505 */
Robin Lee25e26452015-06-02 09:56:29 -07002506 public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002507 if (mService != null) {
2508 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002509 mService.setKeyguardDisabledFeatures(admin, which);
Jim Millerb8ec4702012-08-31 17:19:10 -07002510 } catch (RemoteException e) {
2511 Log.w(TAG, "Failed talking with device policy service", e);
2512 }
2513 }
2514 }
2515
2516 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002517 * Determine whether or not features have been disabled in keyguard either by the current
Jim Millerb8ec4702012-08-31 17:19:10 -07002518 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002519 * @param admin The name of the admin component to check, or {@code null} to check whether any admins
Jim Miller48b9b0d2012-09-19 23:16:50 -07002520 * have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07002521 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
2522 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002523 */
Robin Lee25e26452015-06-02 09:56:29 -07002524 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) {
Jim Miller48b9b0d2012-09-19 23:16:50 -07002525 return getKeyguardDisabledFeatures(admin, UserHandle.myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002526 }
2527
2528 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002529 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002530 if (mService != null) {
2531 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07002532 return mService.getKeyguardDisabledFeatures(admin, userHandle);
Jim Millerb8ec4702012-08-31 17:19:10 -07002533 } catch (RemoteException e) {
2534 Log.w(TAG, "Failed talking with device policy service", e);
2535 }
2536 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07002537 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07002538 }
2539
2540 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08002541 * @hide
2542 */
Robin Lee25e26452015-06-02 09:56:29 -07002543 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
2544 int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002545 if (mService != null) {
2546 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01002547 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002548 } catch (RemoteException e) {
2549 Log.w(TAG, "Failed talking with device policy service", e);
2550 }
2551 }
2552 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002553
Dianne Hackbornd6847842010-01-12 18:14:19 -08002554 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01002555 * @hide
2556 */
Robin Lee25e26452015-06-02 09:56:29 -07002557 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
Jessica Hummel6d36b602014-04-04 12:42:17 +01002558 setActiveAdmin(policyReceiver, refreshing, UserHandle.myUserId());
2559 }
2560
2561 /**
Robin Lee25e26452015-06-02 09:56:29 -07002562 * Returns the DeviceAdminInfo as defined by the administrator's package info &amp; meta-data
Dianne Hackbornd6847842010-01-12 18:14:19 -08002563 * @hide
2564 */
Robin Lee25e26452015-06-02 09:56:29 -07002565 public DeviceAdminInfo getAdminInfo(@NonNull ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002566 ActivityInfo ai;
2567 try {
2568 ai = mContext.getPackageManager().getReceiverInfo(cn,
2569 PackageManager.GET_META_DATA);
2570 } catch (PackageManager.NameNotFoundException e) {
2571 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
2572 return null;
2573 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002574
Dianne Hackbornd6847842010-01-12 18:14:19 -08002575 ResolveInfo ri = new ResolveInfo();
2576 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002577
Dianne Hackbornd6847842010-01-12 18:14:19 -08002578 try {
2579 return new DeviceAdminInfo(mContext, ri);
2580 } catch (XmlPullParserException e) {
2581 Log.w(TAG, "Unable to parse device policy " + cn, e);
2582 return null;
2583 } catch (IOException e) {
2584 Log.w(TAG, "Unable to parse device policy " + cn, e);
2585 return null;
2586 }
2587 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002588
Dianne Hackbornd6847842010-01-12 18:14:19 -08002589 /**
2590 * @hide
2591 */
Robin Lee25e26452015-06-02 09:56:29 -07002592 public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002593 if (mService != null) {
2594 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002595 mService.getRemoveWarning(admin, result, UserHandle.myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002596 } catch (RemoteException e) {
2597 Log.w(TAG, "Failed talking with device policy service", e);
2598 }
2599 }
2600 }
2601
2602 /**
2603 * @hide
2604 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002605 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002606 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002607 if (mService != null) {
2608 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002609 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002610 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002611 } catch (RemoteException e) {
2612 Log.w(TAG, "Failed talking with device policy service", e);
2613 }
2614 }
2615 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002616
Dianne Hackbornd6847842010-01-12 18:14:19 -08002617 /**
2618 * @hide
2619 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002620 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002621 if (mService != null) {
2622 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002623 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002624 } catch (RemoteException e) {
2625 Log.w(TAG, "Failed talking with device policy service", e);
2626 }
2627 }
2628 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002629
Dianne Hackbornd6847842010-01-12 18:14:19 -08002630 /**
2631 * @hide
2632 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002633 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002634 if (mService != null) {
2635 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002636 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002637 } catch (RemoteException e) {
2638 Log.w(TAG, "Failed talking with device policy service", e);
2639 }
2640 }
2641 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07002642
2643 /**
2644 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00002645 * Sets the given package as the device owner.
2646 * Same as {@link #setDeviceOwner(String, String)} but without setting a device owner name.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002647 * @param packageName the package name of the application to be registered as the device owner.
2648 * @return whether the package was successfully registered as the device owner.
2649 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00002650 * @throws IllegalStateException If the preconditions mentioned are not met.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002651 */
2652 public boolean setDeviceOwner(String packageName) throws IllegalArgumentException,
2653 IllegalStateException {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002654 return setDeviceOwner(packageName, null);
2655 }
2656
2657 /**
2658 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00002659 * Sets the given package as the device owner. The package must already be installed. There
2660 * must not already be a device owner.
2661 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
2662 * this method.
2663 * Calling this after the setup phase of the primary user has completed is allowed only if
2664 * the caller is the shell uid, and there are no additional users and no accounts.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002665 * @param packageName the package name of the application to be registered as the device owner.
2666 * @param ownerName the human readable name of the institution that owns this device.
2667 * @return whether the package was successfully registered as the device owner.
2668 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00002669 * @throws IllegalStateException If the preconditions mentioned are not met.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002670 */
2671 public boolean setDeviceOwner(String packageName, String ownerName)
2672 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002673 if (mService != null) {
2674 try {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002675 return mService.setDeviceOwner(packageName, ownerName);
Amith Yamasani71e6c692013-03-24 17:39:28 -07002676 } catch (RemoteException re) {
2677 Log.w(TAG, "Failed to set device owner");
2678 }
2679 }
2680 return false;
2681 }
2682
2683 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002684 * Used to determine if a particular package has been registered as a Device Owner app.
2685 * A device owner app is a special device admin that cannot be deactivated by the user, once
Robin Lee25e26452015-06-02 09:56:29 -07002686 * activated as a device admin. It also cannot be uninstalled. To check whether a particular
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002687 * package is currently registered as the device owner app, pass in the package name from
2688 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
Robin Lee25e26452015-06-02 09:56:29 -07002689 * admin apps that want to check whether they are also registered as the device owner app. The
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002690 * exact mechanism by which a device admin app is registered as a device owner app is defined by
2691 * the setup process.
2692 * @param packageName the package name of the app, to compare with the registered device owner
2693 * app, if any.
2694 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002695 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002696 public boolean isDeviceOwnerApp(String packageName) {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002697 if (mService != null) {
2698 try {
2699 return mService.isDeviceOwner(packageName);
2700 } catch (RemoteException re) {
2701 Log.w(TAG, "Failed to check device owner");
2702 }
2703 }
2704 return false;
2705 }
2706
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002707 /**
2708 * @hide
2709 * Redirect to isDeviceOwnerApp.
2710 */
2711 public boolean isDeviceOwner(String packageName) {
2712 return isDeviceOwnerApp(packageName);
2713 }
2714
Jason Monkb0dced82014-06-06 14:36:20 -04002715 /**
2716 * Clears the current device owner. The caller must be the device owner.
2717 *
2718 * This function should be used cautiously as once it is called it cannot
2719 * be undone. The device owner can only be set as a part of device setup
2720 * before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04002721 *
2722 * @param packageName The package name of the device owner.
Jason Monkb0dced82014-06-06 14:36:20 -04002723 */
Jason Monk94d2cf92014-06-18 09:53:34 -04002724 public void clearDeviceOwnerApp(String packageName) {
Jason Monkb0dced82014-06-06 14:36:20 -04002725 if (mService != null) {
2726 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04002727 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04002728 } catch (RemoteException re) {
2729 Log.w(TAG, "Failed to clear device owner");
2730 }
2731 }
2732 }
2733
Amith Yamasani71e6c692013-03-24 17:39:28 -07002734 /** @hide */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002735 @SystemApi
Amith Yamasani71e6c692013-03-24 17:39:28 -07002736 public String getDeviceOwner() {
2737 if (mService != null) {
2738 try {
2739 return mService.getDeviceOwner();
2740 } catch (RemoteException re) {
2741 Log.w(TAG, "Failed to get device owner");
2742 }
2743 }
2744 return null;
2745 }
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002746
2747 /** @hide */
2748 public String getDeviceOwnerName() {
2749 if (mService != null) {
2750 try {
2751 return mService.getDeviceOwnerName();
2752 } catch (RemoteException re) {
2753 Log.w(TAG, "Failed to get device owner");
2754 }
2755 }
2756 return null;
2757 }
Adam Connors776c5552014-01-09 10:42:56 +00002758
2759 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05002760 * Sets the given component as the device initializer. The package must already be installed and
2761 * set as an active device administrator, and there must not be an existing device initializer,
2762 * for this call to succeed. This method can only be called by an app holding the
2763 * MANAGE_DEVICE_ADMINS permission before the device is provisioned or by a device owner app. A
2764 * device initializer app is granted device owner privileges during device initialization and
2765 * profile owner privileges during secondary user initialization.
Robin Lee25e26452015-06-02 09:56:29 -07002766 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2767 * {@code null} if not called by the device owner.
Julia Reynolds20118f12015-02-11 12:34:08 -05002768 * @param initializer Which {@link DeviceAdminReceiver} to make device initializer.
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002769 * @return whether the component was successfully registered as the device initializer.
2770 * @throws IllegalArgumentException if the componentname is null or invalid
Julia Reynolds20118f12015-02-11 12:34:08 -05002771 * @throws IllegalStateException if the caller is not device owner or the device has
2772 * already been provisioned or a device initializer already exists.
2773 */
Robin Lee25e26452015-06-02 09:56:29 -07002774 public boolean setDeviceInitializer(@Nullable ComponentName admin,
2775 @NonNull ComponentName initializer)
Julia Reynolds731051e2015-05-11 15:52:08 -04002776 throws IllegalArgumentException, IllegalStateException {
Julia Reynolds20118f12015-02-11 12:34:08 -05002777 if (mService != null) {
2778 try {
Robin Lee25e26452015-06-02 09:56:29 -07002779 return mService.setDeviceInitializer(admin, initializer);
Julia Reynolds20118f12015-02-11 12:34:08 -05002780 } catch (RemoteException re) {
2781 Log.w(TAG, "Failed to set device initializer");
2782 }
2783 }
2784 return false;
2785 }
2786
2787 /**
2788 * Used to determine if a particular package has been registered as the device initializer.
2789 *
2790 * @param packageName the package name of the app, to compare with the registered device
2791 * initializer app, if any.
2792 * @return whether or not the caller is registered as the device initializer app.
2793 */
2794 public boolean isDeviceInitializerApp(String packageName) {
2795 if (mService != null) {
2796 try {
2797 return mService.isDeviceInitializer(packageName);
2798 } catch (RemoteException re) {
2799 Log.w(TAG, "Failed to check device initializer");
2800 }
2801 }
2802 return false;
2803 }
2804
2805 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05002806 * Removes the device initializer, so that it will not be invoked on user initialization for any
2807 * subsequently created users. This method can be called by either the device owner or device
Julia Reynolds1c3754a2015-03-05 10:06:41 -05002808 * initializer itself. The caller must be an active administrator.
2809 *
Robin Lee25e26452015-06-02 09:56:29 -07002810 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Julia Reynolds20118f12015-02-11 12:34:08 -05002811 */
Robin Lee25e26452015-06-02 09:56:29 -07002812 public void clearDeviceInitializerApp(@NonNull ComponentName admin) {
Julia Reynolds20118f12015-02-11 12:34:08 -05002813 if (mService != null) {
2814 try {
Robin Lee25e26452015-06-02 09:56:29 -07002815 mService.clearDeviceInitializer(admin);
Julia Reynolds20118f12015-02-11 12:34:08 -05002816 } catch (RemoteException re) {
2817 Log.w(TAG, "Failed to clear device initializer");
2818 }
2819 }
2820 }
2821
2822 /**
2823 * @hide
2824 * Gets the device initializer of the system.
2825 *
2826 * @return the package name of the device initializer.
2827 */
2828 @SystemApi
2829 public String getDeviceInitializerApp() {
2830 if (mService != null) {
2831 try {
2832 return mService.getDeviceInitializer();
2833 } catch (RemoteException re) {
2834 Log.w(TAG, "Failed to get device initializer");
2835 }
2836 }
2837 return null;
2838 }
2839
2840 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002841 * @hide
2842 * Gets the device initializer component of the system.
2843 *
2844 * @return the component name of the device initializer.
2845 */
2846 @SystemApi
2847 public ComponentName getDeviceInitializerComponent() {
2848 if (mService != null) {
2849 try {
2850 return mService.getDeviceInitializerComponent();
2851 } catch (RemoteException re) {
2852 Log.w(TAG, "Failed to get device initializer");
2853 }
2854 }
2855 return null;
2856 }
2857
2858
2859 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05002860 * Sets the enabled state of the user. A user should be enabled only once it is ready to
2861 * be used.
2862 *
2863 * <p>Device initializer must call this method to mark the user as functional.
2864 * Only the device initializer agent can call this.
2865 *
2866 * <p>When the user is enabled, if the device initializer is not also the device owner, the
2867 * device initializer will no longer have elevated permissions to call methods in this class.
2868 * Additionally, it will be removed as an active administrator and its
2869 * {@link DeviceAdminReceiver} will be disabled.
2870 *
2871 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2872 * @return whether the user is now enabled.
2873 */
Robin Lee25e26452015-06-02 09:56:29 -07002874 public boolean setUserEnabled(@NonNull ComponentName admin) {
Julia Reynolds20118f12015-02-11 12:34:08 -05002875 if (mService != null) {
2876 try {
2877 return mService.setUserEnabled(admin);
2878 } catch (RemoteException e) {
2879 Log.w(TAG, "Failed talking with device policy service", e);
2880 }
2881 }
2882 return false;
2883 }
2884
2885 /**
Adam Connors776c5552014-01-09 10:42:56 +00002886 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002887 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302888 * Sets the given component as an active admin and registers the package as the profile
2889 * owner for this user. The package must already be installed and there shouldn't be
2890 * an existing profile owner registered for this user. Also, this method must be called
2891 * before the user setup has been completed.
2892 * <p>
2893 * This method can only be called by system apps that hold MANAGE_USERS permission and
2894 * MANAGE_DEVICE_ADMINS permission.
2895 * @param admin The component to register as an active admin and profile owner.
2896 * @param ownerName The user-visible name of the entity that is managing this user.
2897 * @return whether the admin was successfully registered as the profile owner.
2898 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
2899 * the user has already been set up.
2900 */
Justin Morey80440cc2014-07-24 09:16:35 -05002901 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07002902 public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302903 throws IllegalArgumentException {
2904 if (mService != null) {
2905 try {
2906 final int myUserId = UserHandle.myUserId();
2907 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002908 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302909 } catch (RemoteException re) {
2910 Log.w(TAG, "Failed to set profile owner " + re);
2911 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2912 }
2913 }
2914 return false;
2915 }
2916
2917 /**
2918 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002919 * Clears the active profile owner and removes all user restrictions. The caller must
2920 * be from the same package as the active profile owner for this user, otherwise a
2921 * SecurityException will be thrown.
2922 *
2923 * @param admin The component to remove as the profile owner.
2924 * @return
2925 */
2926 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07002927 public void clearProfileOwner(@NonNull ComponentName admin) {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002928 if (mService != null) {
2929 try {
2930 mService.clearProfileOwner(admin);
2931 } catch (RemoteException re) {
2932 Log.w(TAG, "Failed to clear profile owner " + admin + re);
2933 }
2934 }
2935 }
2936
2937 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05002938 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07002939 * Checks whether the user was already setup.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002940 */
2941 public boolean hasUserSetupCompleted() {
2942 if (mService != null) {
2943 try {
2944 return mService.hasUserSetupCompleted();
2945 } catch (RemoteException re) {
Robin Lee25e26452015-06-02 09:56:29 -07002946 Log.w(TAG, "Failed to check whether user setup has completed");
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002947 }
2948 }
2949 return true;
2950 }
2951
2952 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002953 * @hide
2954 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00002955 * already be installed. There must not already be a profile owner for this user.
2956 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
2957 * this method.
2958 * Calling this after the setup phase of the specified user has completed is allowed only if:
2959 * - the caller is SYSTEM_UID.
2960 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002961 * @param admin the component name to be registered as profile owner.
2962 * @param ownerName the human readable name of the organisation associated with this DPM.
2963 * @param userHandle the userId to set the profile owner for.
2964 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00002965 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
2966 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002967 */
Robin Lee25e26452015-06-02 09:56:29 -07002968 public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName,
Robin Leeddd553f2015-04-30 14:18:22 +01002969 int userHandle) throws IllegalArgumentException {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002970 if (admin == null) {
2971 throw new NullPointerException("admin cannot be null");
2972 }
Adam Connors776c5552014-01-09 10:42:56 +00002973 if (mService != null) {
2974 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002975 if (ownerName == null) {
2976 ownerName = "";
2977 }
2978 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00002979 } catch (RemoteException re) {
2980 Log.w(TAG, "Failed to set profile owner", re);
2981 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2982 }
2983 }
2984 return false;
2985 }
2986
2987 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002988 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
2989 * be used. Only the profile owner can call this.
2990 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01002991 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002992 *
2993 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2994 */
Robin Lee25e26452015-06-02 09:56:29 -07002995 public void setProfileEnabled(@NonNull ComponentName admin) {
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002996 if (mService != null) {
2997 try {
2998 mService.setProfileEnabled(admin);
2999 } catch (RemoteException e) {
3000 Log.w(TAG, "Failed talking with device policy service", e);
3001 }
3002 }
3003 }
3004
3005 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003006 * Sets the name of the profile. In the device owner case it sets the name of the user
3007 * which it is called from. Only a profile owner or device owner can call this. If this is
Jessica Hummel1333ea12014-06-23 11:20:10 +01003008 * never called by the profile or device owner, the name will be set to default values.
3009 *
3010 * @see #isProfileOwnerApp
3011 * @see #isDeviceOwnerApp
3012 *
Robin Lee25e26452015-06-02 09:56:29 -07003013 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01003014 * @param profileName The name of the profile.
3015 */
Robin Lee25e26452015-06-02 09:56:29 -07003016 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Jessica Hummel1333ea12014-06-23 11:20:10 +01003017 if (mService != null) {
3018 try {
Robin Lee25e26452015-06-02 09:56:29 -07003019 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07003020 } catch (RemoteException e) {
3021 Log.w(TAG, "Failed talking with device policy service", e);
3022 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01003023 }
3024 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01003025
3026 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003027 * Used to determine if a particular package is registered as the profile owner for the
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003028 * current user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003029 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00003030 *
3031 * @param packageName The package name of the app to compare with the registered profile owner.
3032 * @return Whether or not the package is registered as the profile owner.
3033 */
3034 public boolean isProfileOwnerApp(String packageName) {
3035 if (mService != null) {
3036 try {
Nicolas Prevot90af6d72014-07-30 14:19:12 +01003037 ComponentName profileOwner = mService.getProfileOwner(
3038 Process.myUserHandle().getIdentifier());
3039 return profileOwner != null
3040 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00003041 } catch (RemoteException re) {
3042 Log.w(TAG, "Failed to check profile owner");
3043 }
3044 }
3045 return false;
3046 }
3047
3048 /**
3049 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003050 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00003051 * owner has been set for that user.
3052 * @throws IllegalArgumentException if the userId is invalid.
3053 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01003054 @SystemApi
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003055 public ComponentName getProfileOwner() throws IllegalArgumentException {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003056 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
3057 }
3058
3059 /**
3060 * @see #getProfileOwner()
3061 * @hide
3062 */
3063 public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00003064 if (mService != null) {
3065 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003066 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00003067 } catch (RemoteException re) {
3068 Log.w(TAG, "Failed to get profile owner");
3069 throw new IllegalArgumentException(
3070 "Requested profile owner for invalid userId", re);
3071 }
3072 }
3073 return null;
3074 }
3075
3076 /**
3077 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003078 * @return the human readable name of the organisation associated with this DPM or {@code null}
3079 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00003080 * @throws IllegalArgumentException if the userId is invalid.
3081 */
3082 public String getProfileOwnerName() throws IllegalArgumentException {
3083 if (mService != null) {
3084 try {
3085 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
3086 } catch (RemoteException re) {
3087 Log.w(TAG, "Failed to get profile owner");
3088 throw new IllegalArgumentException(
3089 "Requested profile owner for invalid userId", re);
3090 }
3091 }
3092 return null;
3093 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003094
3095 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07003096 * @hide
3097 * @param user The user for whom to fetch the profile owner name, if any.
3098 * @return the human readable name of the organisation associated with this profile owner or
3099 * null if one is not set.
3100 * @throws IllegalArgumentException if the userId is invalid.
3101 */
3102 @SystemApi
Selim Cinek24ac55e2014-08-27 12:51:45 +02003103 public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Amith Yamasani38f836b2014-08-20 14:51:15 -07003104 if (mService != null) {
3105 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02003106 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07003107 } catch (RemoteException re) {
3108 Log.w(TAG, "Failed to get profile owner");
3109 throw new IllegalArgumentException(
3110 "Requested profile owner for invalid userId", re);
3111 }
3112 }
3113 return null;
3114 }
3115
3116 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003117 * Called by a profile owner or device owner to add a default intent handler activity for
3118 * intents that match a certain intent filter. This activity will remain the default intent
3119 * handler even if the set of potential event handlers for the intent filter changes and if
3120 * the intent preferences are reset.
3121 *
3122 * <p>The default disambiguation mechanism takes over if the activity is not installed
3123 * (anymore). When the activity is (re)installed, it is automatically reset as default
3124 * intent handler for the filter.
3125 *
3126 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
3127 * security exception will be thrown.
3128 *
3129 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3130 * @param filter The IntentFilter for which a default handler is added.
3131 * @param activity The Activity that is added as default intent handler.
3132 */
Robin Lee25e26452015-06-02 09:56:29 -07003133 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
3134 @NonNull ComponentName activity) {
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003135 if (mService != null) {
3136 try {
3137 mService.addPersistentPreferredActivity(admin, filter, activity);
3138 } catch (RemoteException e) {
3139 Log.w(TAG, "Failed talking with device policy service", e);
3140 }
3141 }
3142 }
3143
3144 /**
3145 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00003146 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003147 *
3148 * <p>The calling device admin must be a profile owner. If it is not, a security
3149 * exception will be thrown.
3150 *
3151 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3152 * @param packageName The name of the package for which preferences are removed.
3153 */
Robin Lee25e26452015-06-02 09:56:29 -07003154 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003155 String packageName) {
3156 if (mService != null) {
3157 try {
3158 mService.clearPackagePersistentPreferredActivities(admin, packageName);
3159 } catch (RemoteException e) {
3160 Log.w(TAG, "Failed talking with device policy service", e);
3161 }
3162 }
3163 }
Robin Lee66e5d962014-04-09 16:44:21 +01003164
3165 /**
3166 * Called by a profile or device owner to set the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003167 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01003168 *
3169 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be
Kenny Guyd00cfc52014-09-18 16:24:31 +01003170 * boolean, int, String, or String[].
Robin Lee66e5d962014-04-09 16:44:21 +01003171 *
3172 * <p>The application restrictions are only made visible to the target application and the
3173 * profile or device owner.
3174 *
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003175 * <p>If the restrictions are not available yet, but may be applied in the near future,
3176 * the admin can notify the target application of that by adding
3177 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
3178 *
Robin Lee66e5d962014-04-09 16:44:21 +01003179 * <p>The calling device admin must be a profile or device owner; if it is not, a security
3180 * exception will be thrown.
3181 *
3182 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3183 * @param packageName The name of the package to update restricted settings for.
3184 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
3185 * set of active restrictions.
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003186 *
3187 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01003188 */
Robin Lee25e26452015-06-02 09:56:29 -07003189 public void setApplicationRestrictions(@NonNull ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01003190 Bundle settings) {
3191 if (mService != null) {
3192 try {
3193 mService.setApplicationRestrictions(admin, packageName, settings);
3194 } catch (RemoteException e) {
3195 Log.w(TAG, "Failed talking with device policy service", e);
3196 }
3197 }
3198 }
3199
3200 /**
Jim Millere303bf42014-08-26 17:12:29 -07003201 * Sets a list of configuration features to enable for a TrustAgent component. This is meant
3202 * to be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all
3203 * trust agents but those enabled by this function call. If flag
3204 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Jim Miller604e7552014-07-18 19:00:02 -07003205 *
3206 * <p>The calling device admin must have requested
3207 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millere303bf42014-08-26 17:12:29 -07003208 * this method; if not, a security exception will be thrown.
Jim Miller604e7552014-07-18 19:00:02 -07003209 *
3210 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07003211 * @param target Component name of the agent to be enabled.
Jim Millerb5db57a2015-01-14 18:17:19 -08003212 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent
Jim Millere303bf42014-08-26 17:12:29 -07003213 * will be strictly disabled according to the state of the
3214 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
3215 * <p>If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all admins,
3216 * then it's up to the TrustAgent itself to aggregate the values from all device admins.
3217 * <p>Consult documentation for the specific TrustAgent to determine legal options parameters.
Jim Miller604e7552014-07-18 19:00:02 -07003218 */
Robin Lee25e26452015-06-02 09:56:29 -07003219 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
3220 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07003221 if (mService != null) {
3222 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003223 mService.setTrustAgentConfiguration(admin, target, configuration);
Jim Miller604e7552014-07-18 19:00:02 -07003224 } catch (RemoteException e) {
3225 Log.w(TAG, "Failed talking with device policy service", e);
3226 }
3227 }
3228 }
3229
3230 /**
Jim Millere303bf42014-08-26 17:12:29 -07003231 * Gets configuration for the given trust agent based on aggregating all calls to
3232 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
3233 * all device admins.
Jim Miller604e7552014-07-18 19:00:02 -07003234 *
Jim Millerb5db57a2015-01-14 18:17:19 -08003235 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
3236 * this function returns a list of configurations for all admins that declare
3237 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
3238 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
3239 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
3240 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07003241 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07003242 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07003243 */
Robin Lee25e26452015-06-02 09:56:29 -07003244 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
3245 @NonNull ComponentName agent) {
Jim Millere303bf42014-08-26 17:12:29 -07003246 return getTrustAgentConfiguration(admin, agent, UserHandle.myUserId());
3247 }
3248
3249 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003250 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
3251 @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07003252 if (mService != null) {
3253 try {
Jim Millere303bf42014-08-26 17:12:29 -07003254 return mService.getTrustAgentConfiguration(admin, agent, userHandle);
Jim Miller604e7552014-07-18 19:00:02 -07003255 } catch (RemoteException e) {
3256 Log.w(TAG, "Failed talking with device policy service", e);
3257 }
3258 }
Jim Millere303bf42014-08-26 17:12:29 -07003259 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07003260 }
3261
3262 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003263 * Called by a profile owner of a managed profile to set whether caller-Id information from
3264 * the managed profile will be shown in the parent profile, for incoming calls.
Adam Connors210fe212014-07-17 15:41:43 +01003265 *
3266 * <p>The calling device admin must be a profile owner. If it is not, a
3267 * security exception will be thrown.
3268 *
Robin Lee25e26452015-06-02 09:56:29 -07003269 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01003270 * @param disabled If true caller-Id information in the managed profile is not displayed.
3271 */
Robin Lee25e26452015-06-02 09:56:29 -07003272 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Adam Connors210fe212014-07-17 15:41:43 +01003273 if (mService != null) {
3274 try {
Robin Lee25e26452015-06-02 09:56:29 -07003275 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01003276 } catch (RemoteException e) {
3277 Log.w(TAG, "Failed talking with device policy service", e);
3278 }
3279 }
3280 }
3281
3282 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003283 * Called by a profile owner of a managed profile to determine whether or not caller-Id
3284 * information has been disabled.
Adam Connors210fe212014-07-17 15:41:43 +01003285 *
3286 * <p>The calling device admin must be a profile owner. If it is not, a
3287 * security exception will be thrown.
3288 *
Robin Lee25e26452015-06-02 09:56:29 -07003289 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01003290 */
Robin Lee25e26452015-06-02 09:56:29 -07003291 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Adam Connors210fe212014-07-17 15:41:43 +01003292 if (mService != null) {
3293 try {
Robin Lee25e26452015-06-02 09:56:29 -07003294 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01003295 } catch (RemoteException e) {
3296 Log.w(TAG, "Failed talking with device policy service", e);
3297 }
3298 }
3299 return false;
3300 }
3301
3302 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07003303 * Determine whether or not caller-Id information has been disabled.
3304 *
3305 * @param userHandle The user for whom to check the caller-id permission
3306 * @hide
3307 */
3308 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
3309 if (mService != null) {
3310 try {
3311 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
3312 } catch (RemoteException e) {
3313 Log.w(TAG, "Failed talking with device policy service", e);
3314 }
3315 }
3316 return false;
3317 }
3318
3319 /**
Makoto Onuki1040da12015-03-19 11:24:00 -07003320 * Start Quick Contact on the managed profile for the current user, if the policy allows.
3321 * @hide
3322 */
3323 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
3324 Intent originalIntent) {
3325 if (mService != null) {
3326 try {
3327 mService.startManagedQuickContact(
3328 actualLookupKey, actualContactId, originalIntent);
3329 } catch (RemoteException e) {
3330 Log.w(TAG, "Failed talking with device policy service", e);
3331 }
3332 }
3333 }
3334
3335 /**
Ricky Wai778ba132015-03-31 14:21:22 +01003336 * Called by a profile owner of a managed profile to set whether bluetooth
3337 * devices can access enterprise contacts.
3338 * <p>
3339 * The calling device admin must be a profile owner. If it is not, a
3340 * security exception will be thrown.
3341 * <p>
3342 * This API works on managed profile only.
3343 *
Robin Lee25e26452015-06-02 09:56:29 -07003344 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01003345 * with.
3346 * @param disabled If true, bluetooth devices cannot access enterprise
3347 * contacts.
3348 */
Robin Lee25e26452015-06-02 09:56:29 -07003349 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Ricky Wai778ba132015-03-31 14:21:22 +01003350 if (mService != null) {
3351 try {
Robin Lee25e26452015-06-02 09:56:29 -07003352 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01003353 } catch (RemoteException e) {
3354 Log.w(TAG, "Failed talking with device policy service", e);
3355 }
3356 }
3357 }
3358
3359 /**
3360 * Called by a profile owner of a managed profile to determine whether or
3361 * not Bluetooth devices cannot access enterprise contacts.
3362 * <p>
3363 * The calling device admin must be a profile owner. If it is not, a
3364 * security exception will be thrown.
3365 * <p>
3366 * This API works on managed profile only.
3367 *
Robin Lee25e26452015-06-02 09:56:29 -07003368 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01003369 * with.
3370 */
Robin Lee25e26452015-06-02 09:56:29 -07003371 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Ricky Wai778ba132015-03-31 14:21:22 +01003372 if (mService != null) {
3373 try {
Robin Lee25e26452015-06-02 09:56:29 -07003374 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01003375 } catch (RemoteException e) {
3376 Log.w(TAG, "Failed talking with device policy service", e);
3377 }
3378 }
3379 return true;
3380 }
3381
3382 /**
3383 * Determine whether or not Bluetooth devices cannot access contacts.
3384 * <p>
3385 * This API works on managed profile UserHandle only.
3386 *
3387 * @param userHandle The user for whom to check the caller-id permission
3388 * @hide
3389 */
3390 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
3391 if (mService != null) {
3392 try {
3393 return mService.getBluetoothContactSharingDisabledForUser(userHandle
3394 .getIdentifier());
3395 } catch (RemoteException e) {
3396 Log.w(TAG, "Failed talking with device policy service", e);
3397 }
3398 }
3399 return true;
3400 }
3401
3402 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003403 * Called by the profile owner of a managed profile so that some intents sent in the managed
3404 * profile can also be resolved in the parent, or vice versa.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00003405 * Only activity intents are supported.
3406 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003407 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01003408 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
3409 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01003410 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
3411 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003412 */
Robin Lee25e26452015-06-02 09:56:29 -07003413 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003414 if (mService != null) {
3415 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003416 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003417 } catch (RemoteException e) {
3418 Log.w(TAG, "Failed talking with device policy service", e);
3419 }
3420 }
3421 }
3422
3423 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003424 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
3425 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01003426 * Only removes those that have been set by the profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003427 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3428 */
Robin Lee25e26452015-06-02 09:56:29 -07003429 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003430 if (mService != null) {
3431 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003432 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003433 } catch (RemoteException e) {
3434 Log.w(TAG, "Failed talking with device policy service", e);
3435 }
3436 }
3437 }
3438
3439 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003440 * Called by a profile or device owner to set the permitted accessibility services. When
3441 * set by a device owner or profile owner the restriction applies to all profiles of the
3442 * user the device owner or profile owner is an admin for.
Jim Millerb1474f42014-08-26 18:42:58 -07003443 *
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003444 * By default the user can use any accessiblity service. When zero or more packages have
3445 * been added, accessiblity services that are not in the list and not part of the system
Jim Millerb1474f42014-08-26 18:42:58 -07003446 * can not be enabled by the user.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003447 *
3448 * <p> Calling with a null value for the list disables the restriction so that all services
3449 * can be used, calling with an empty list only allows the builtin system's services.
3450 *
3451 * <p> System accesibility services are always available to the user the list can't modify
3452 * this.
3453 *
3454 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3455 * @param packageNames List of accessibility service package names.
3456 *
3457 * @return true if setting the restriction succeeded. It fail if there is
3458 * one or more non-system accessibility services enabled, that are not in the list.
3459 */
Robin Lee25e26452015-06-02 09:56:29 -07003460 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003461 List<String> packageNames) {
3462 if (mService != null) {
3463 try {
3464 return mService.setPermittedAccessibilityServices(admin, packageNames);
3465 } catch (RemoteException e) {
3466 Log.w(TAG, "Failed talking with device policy service", e);
3467 }
3468 }
3469 return false;
3470 }
3471
3472 /**
3473 * Returns the list of permitted accessibility services set by this device or profile owner.
3474 *
3475 * <p>An empty list means no accessibility services except system services are allowed.
3476 * Null means all accessibility services are allowed.
3477 *
3478 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3479 * @return List of accessiblity service package names.
3480 */
Robin Lee25e26452015-06-02 09:56:29 -07003481 public List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003482 if (mService != null) {
3483 try {
3484 return mService.getPermittedAccessibilityServices(admin);
3485 } catch (RemoteException e) {
3486 Log.w(TAG, "Failed talking with device policy service", e);
3487 }
3488 }
3489 return null;
3490 }
3491
3492 /**
3493 * Returns the list of accessibility services permitted by the device or profiles
3494 * owners of this user.
3495 *
3496 * <p>Null means all accessibility services are allowed, if a non-null list is returned
3497 * it will contain the intersection of the permitted lists for any device or profile
3498 * owners that apply to this user. It will also include any system accessibility services.
3499 *
3500 * @param userId which user to check for.
3501 * @return List of accessiblity service package names.
3502 * @hide
3503 */
3504 @SystemApi
3505 public List<String> getPermittedAccessibilityServices(int userId) {
3506 if (mService != null) {
3507 try {
3508 return mService.getPermittedAccessibilityServicesForUser(userId);
3509 } catch (RemoteException e) {
3510 Log.w(TAG, "Failed talking with device policy service", e);
3511 }
3512 }
3513 return null;
3514 }
3515
3516 /**
3517 * Called by a profile or device owner to set the permitted input methods services. When
3518 * set by a device owner or profile owner the restriction applies to all profiles of the
3519 * user the device owner or profile owner is an admin for.
3520 *
3521 * By default the user can use any input method. When zero or more packages have
3522 * been added, input method that are not in the list and not part of the system
3523 * can not be enabled by the user.
3524 *
3525 * This method will fail if it is called for a admin that is not for the foreground user
3526 * or a profile of the foreground user.
3527 *
3528 * <p> Calling with a null value for the list disables the restriction so that all input methods
3529 * can be used, calling with an empty list disables all but the system's own input methods.
3530 *
3531 * <p> System input methods are always available to the user this method can't modify this.
3532 *
3533 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3534 * @param packageNames List of input method package names.
Kenny Guy74a70242015-02-05 19:48:38 +00003535 * @return true if setting the restriction succeeded. It will fail if there are
3536 * one or more non-system input methods currently enabled that are not in
3537 * the packageNames list.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003538 */
Robin Lee25e26452015-06-02 09:56:29 -07003539 public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003540 if (mService != null) {
3541 try {
3542 return mService.setPermittedInputMethods(admin, packageNames);
3543 } catch (RemoteException e) {
3544 Log.w(TAG, "Failed talking with device policy service", e);
3545 }
3546 }
3547 return false;
3548 }
3549
3550
3551 /**
3552 * Returns the list of permitted input methods set by this device or profile owner.
3553 *
3554 * <p>An empty list means no input methods except system input methods are allowed.
3555 * Null means all input methods are allowed.
3556 *
3557 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3558 * @return List of input method package names.
3559 */
Robin Lee25e26452015-06-02 09:56:29 -07003560 public List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003561 if (mService != null) {
3562 try {
3563 return mService.getPermittedInputMethods(admin);
3564 } catch (RemoteException e) {
3565 Log.w(TAG, "Failed talking with device policy service", e);
3566 }
3567 }
3568 return null;
3569 }
3570
3571 /**
3572 * Returns the list of input methods permitted by the device or profiles
3573 * owners of the current user.
3574 *
3575 * <p>Null means all input methods are allowed, if a non-null list is returned
3576 * it will contain the intersection of the permitted lists for any device or profile
3577 * owners that apply to this user. It will also include any system input methods.
3578 *
3579 * @return List of input method package names.
3580 * @hide
3581 */
3582 @SystemApi
3583 public List<String> getPermittedInputMethodsForCurrentUser() {
3584 if (mService != null) {
3585 try {
3586 return mService.getPermittedInputMethodsForCurrentUser();
3587 } catch (RemoteException e) {
3588 Log.w(TAG, "Failed talking with device policy service", e);
3589 }
3590 }
3591 return null;
3592 }
3593
3594 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003595 * Called by a device owner to create a user with the specified name. The UserHandle returned
3596 * by this method should not be persisted as user handles are recycled as users are removed and
3597 * created. If you need to persist an identifier for this user, use
3598 * {@link UserManager#getSerialNumberForUser}.
3599 *
3600 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3601 * @param name the user's name
3602 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07003603 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
3604 * user could not be created.
Julia Reynolds1e958392014-05-16 14:25:21 -04003605 */
Robin Lee25e26452015-06-02 09:56:29 -07003606 public UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04003607 try {
3608 return mService.createUser(admin, name);
3609 } catch (RemoteException re) {
3610 Log.w(TAG, "Could not create a user", re);
3611 }
3612 return null;
3613 }
3614
3615 /**
Jason Monk03978a42014-06-10 15:05:30 -04003616 * Called by a device owner to create a user with the specified name. The UserHandle returned
3617 * by this method should not be persisted as user handles are recycled as users are removed and
3618 * created. If you need to persist an identifier for this user, use
3619 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
3620 * immediately.
3621 *
3622 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
3623 * as registered as an active admin on the new user. The profile owner package will be
3624 * installed on the new user if it already is installed on the device.
3625 *
3626 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
3627 * profileOwnerComponent when onEnable is called.
3628 *
3629 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3630 * @param name the user's name
3631 * @param ownerName the human readable name of the organisation associated with this DPM.
3632 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
3633 * the user.
3634 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
3635 * on the new user.
3636 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07003637 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
3638 * user could not be created.
Jason Monk03978a42014-06-10 15:05:30 -04003639 */
Robin Lee25e26452015-06-02 09:56:29 -07003640 public UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
3641 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04003642 try {
3643 return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent,
3644 adminExtras);
3645 } catch (RemoteException re) {
3646 Log.w(TAG, "Could not create a user", re);
3647 }
3648 return null;
3649 }
3650
3651 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003652 * Called by a device owner to remove a user and all associated data. The primary user can
3653 * not be removed.
3654 *
3655 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3656 * @param userHandle the user to remove.
3657 * @return {@code true} if the user was removed, {@code false} otherwise.
3658 */
Robin Lee25e26452015-06-02 09:56:29 -07003659 public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) {
Julia Reynolds1e958392014-05-16 14:25:21 -04003660 try {
3661 return mService.removeUser(admin, userHandle);
3662 } catch (RemoteException re) {
3663 Log.w(TAG, "Could not remove user ", re);
3664 return false;
3665 }
3666 }
3667
3668 /**
Jason Monk582d9112014-07-09 19:57:08 -04003669 * Called by a device owner to switch the specified user to the foreground.
3670 *
3671 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3672 * @param userHandle the user to switch to; null will switch to primary.
3673 * @return {@code true} if the switch was successful, {@code false} otherwise.
3674 *
3675 * @see Intent#ACTION_USER_FOREGROUND
3676 */
Robin Lee25e26452015-06-02 09:56:29 -07003677 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Jason Monk582d9112014-07-09 19:57:08 -04003678 try {
3679 return mService.switchUser(admin, userHandle);
3680 } catch (RemoteException re) {
3681 Log.w(TAG, "Could not switch user ", re);
3682 return false;
3683 }
3684 }
3685
3686 /**
Robin Lee66e5d962014-04-09 16:44:21 +01003687 * Called by a profile or device owner to get the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003688 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01003689 *
3690 * <p>The calling device admin must be a profile or device owner; if it is not, a security
3691 * exception will be thrown.
3692 *
3693 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3694 * @param packageName The name of the package to fetch restricted settings of.
3695 * @return {@link Bundle} of settings corresponding to what was set last time
3696 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
3697 * if no restrictions have been set.
3698 */
Robin Lee25e26452015-06-02 09:56:29 -07003699 public Bundle getApplicationRestrictions(@NonNull ComponentName admin, String packageName) {
Robin Lee66e5d962014-04-09 16:44:21 +01003700 if (mService != null) {
3701 try {
3702 return mService.getApplicationRestrictions(admin, packageName);
3703 } catch (RemoteException e) {
3704 Log.w(TAG, "Failed talking with device policy service", e);
3705 }
3706 }
3707 return null;
3708 }
Amith Yamasanibe465322014-04-24 13:45:17 -07003709
3710 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003711 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07003712 * <p>
3713 * The calling device admin must be a profile or device owner; if it is not,
3714 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003715 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003716 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3717 * with.
3718 * @param key The key of the restriction. See the constants in
3719 * {@link android.os.UserManager} for the list of keys.
3720 */
Robin Lee25e26452015-06-02 09:56:29 -07003721 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07003722 if (mService != null) {
3723 try {
3724 mService.setUserRestriction(admin, key, true);
3725 } catch (RemoteException e) {
3726 Log.w(TAG, "Failed talking with device policy service", e);
3727 }
3728 }
3729 }
3730
3731 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003732 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07003733 * <p>
3734 * The calling device admin must be a profile or device owner; if it is not,
3735 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003736 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003737 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3738 * with.
3739 * @param key The key of the restriction. See the constants in
3740 * {@link android.os.UserManager} for the list of keys.
3741 */
Robin Lee25e26452015-06-02 09:56:29 -07003742 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07003743 if (mService != null) {
3744 try {
3745 mService.setUserRestriction(admin, key, false);
3746 } catch (RemoteException e) {
3747 Log.w(TAG, "Failed talking with device policy service", e);
3748 }
3749 }
3750 }
Adam Connors010cfd42014-04-16 12:48:13 +01003751
3752 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003753 * Called by profile or device owners to hide or unhide packages. When a package is hidden it
Julia Reynolds966881e2014-05-14 12:23:08 -04003754 * is unavailable for use, but the data and actual package file remain.
3755 *
3756 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003757 * @param packageName The name of the package to hide or unhide.
3758 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
3759 * unhidden.
3760 * @return boolean Whether the hidden setting of the package was successfully updated.
Julia Reynolds966881e2014-05-14 12:23:08 -04003761 */
Robin Lee25e26452015-06-02 09:56:29 -07003762 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003763 boolean hidden) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003764 if (mService != null) {
3765 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003766 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04003767 } catch (RemoteException e) {
3768 Log.w(TAG, "Failed talking with device policy service", e);
3769 }
3770 }
3771 return false;
3772 }
3773
3774 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003775 * Called by profile or device owners to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04003776 *
3777 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003778 * @param packageName The name of the package to retrieve the hidden status of.
3779 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Julia Reynolds966881e2014-05-14 12:23:08 -04003780 */
Robin Lee25e26452015-06-02 09:56:29 -07003781 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003782 if (mService != null) {
3783 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003784 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04003785 } catch (RemoteException e) {
3786 Log.w(TAG, "Failed talking with device policy service", e);
3787 }
3788 }
3789 return false;
3790 }
3791
3792 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003793 * Called by profile or device owners to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003794 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003795 *
3796 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3797 * @param packageName The package to be re-enabled in the current profile.
3798 */
Robin Lee25e26452015-06-02 09:56:29 -07003799 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Adam Connors655be2a2014-07-14 09:01:25 +00003800 if (mService != null) {
3801 try {
3802 mService.enableSystemApp(admin, packageName);
3803 } catch (RemoteException e) {
3804 Log.w(TAG, "Failed to install package: " + packageName);
3805 }
3806 }
3807 }
3808
3809 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003810 * Called by profile or device owners to re-enable system apps by intent that were disabled
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003811 * by default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003812 *
3813 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3814 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
3815 * intent will be re-enabled in the current profile.
3816 * @return int The number of activities that matched the intent and were installed.
3817 */
Robin Lee25e26452015-06-02 09:56:29 -07003818 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Adam Connors655be2a2014-07-14 09:01:25 +00003819 if (mService != null) {
3820 try {
3821 return mService.enableSystemAppWithIntent(admin, intent);
3822 } catch (RemoteException e) {
3823 Log.w(TAG, "Failed to install packages matching filter: " + intent);
3824 }
3825 }
3826 return 0;
3827 }
3828
3829 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00003830 * Called by a device owner or profile owner to disable account management for a specific type
3831 * of account.
Sander Alewijnse650c3342014-05-08 18:00:50 +01003832 *
Sander Alewijnse112e0532014-10-29 13:28:49 +00003833 * <p>The calling device admin must be a device owner or profile owner. If it is not, a
Sander Alewijnse650c3342014-05-08 18:00:50 +01003834 * security exception will be thrown.
3835 *
3836 * <p>When account management is disabled for an account type, adding or removing an account
3837 * of that type will not be possible.
3838 *
3839 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3840 * @param accountType For which account management is disabled or enabled.
3841 * @param disabled The boolean indicating that account management will be disabled (true) or
3842 * enabled (false).
3843 */
Robin Lee25e26452015-06-02 09:56:29 -07003844 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01003845 boolean disabled) {
3846 if (mService != null) {
3847 try {
3848 mService.setAccountManagementDisabled(admin, accountType, disabled);
3849 } catch (RemoteException e) {
3850 Log.w(TAG, "Failed talking with device policy service", e);
3851 }
3852 }
3853 }
3854
3855 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003856 * Gets the array of accounts for which account management is disabled by the profile owner.
3857 *
3858 * <p> Account management can be disabled/enabled by calling
3859 * {@link #setAccountManagementDisabled}.
3860 *
3861 * @return a list of account types for which account management has been disabled.
3862 *
3863 * @see #setAccountManagementDisabled
3864 */
3865 public String[] getAccountTypesWithManagementDisabled() {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003866 return getAccountTypesWithManagementDisabledAsUser(UserHandle.myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003867 }
3868
3869 /**
3870 * @see #getAccountTypesWithManagementDisabled()
3871 * @hide
3872 */
3873 public String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003874 if (mService != null) {
3875 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003876 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003877 } catch (RemoteException e) {
3878 Log.w(TAG, "Failed talking with device policy service", e);
3879 }
3880 }
3881
3882 return null;
3883 }
justinzhang511e0d82014-03-24 16:09:24 -04003884
3885 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003886 * Sets which packages may enter lock task mode.
3887 *
3888 * <p>Any packages that shares uid with an allowed package will also be allowed
3889 * to activate lock task.
justinzhang511e0d82014-03-24 16:09:24 -04003890 *
Benjamin Franz469dd582015-06-09 14:24:36 +01003891 * From {@link android.os.Build.VERSION_CODES#MNC} removing packages from the lock task
3892 * package list results in locked tasks belonging to those packages to be finished.
3893 *
Jason Monkc5185f22014-06-24 11:12:42 -04003894 * This function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04003895 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04003896 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jason Monkd7b86212014-06-16 13:15:38 -04003897 *
3898 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00003899 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
3900 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04003901 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04003902 */
Robin Lee25e26452015-06-02 09:56:29 -07003903 public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04003904 throws SecurityException {
justinzhang511e0d82014-03-24 16:09:24 -04003905 if (mService != null) {
3906 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003907 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04003908 } catch (RemoteException e) {
3909 Log.w(TAG, "Failed talking with device policy service", e);
3910 }
3911 }
3912 }
3913
3914 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003915 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04003916 *
3917 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04003918 * @hide
3919 */
Robin Lee25e26452015-06-02 09:56:29 -07003920 public String[] getLockTaskPackages(@NonNull ComponentName admin) {
justinzhang511e0d82014-03-24 16:09:24 -04003921 if (mService != null) {
3922 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003923 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04003924 } catch (RemoteException e) {
3925 Log.w(TAG, "Failed talking with device policy service", e);
3926 }
3927 }
3928 return null;
3929 }
3930
3931 /**
3932 * This function lets the caller know whether the given component is allowed to start the
3933 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04003934 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04003935 */
Jason Monkd7b86212014-06-16 13:15:38 -04003936 public boolean isLockTaskPermitted(String pkg) {
justinzhang511e0d82014-03-24 16:09:24 -04003937 if (mService != null) {
3938 try {
Jason Monkd7b86212014-06-16 13:15:38 -04003939 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04003940 } catch (RemoteException e) {
3941 Log.w(TAG, "Failed talking with device policy service", e);
3942 }
3943 }
3944 return false;
3945 }
Julia Reynoldsda551652014-05-14 17:15:16 -04003946
3947 /**
3948 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
3949 * of the setting is in the correct form for the setting type should be performed by the caller.
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003950 * <p>The settings that can be updated with this method are:
3951 * <ul>
3952 * <li>{@link Settings.Global#ADB_ENABLED}</li>
3953 * <li>{@link Settings.Global#AUTO_TIME}</li>
3954 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Nicolas Prevot41916d42015-02-24 18:41:50 +00003955 * <li>{@link Settings.Global#BLUETOOTH_ON}
3956 * Changing this setting has not effect as of {@link android.os.Build.VERSION_CODES#MNC}. Use
3957 * {@link android.bluetooth.BluetoothAdapter#enable()} and
3958 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003959 * <li>{@link Settings.Global#DATA_ROAMING}</li>
3960 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
3961 * <li>{@link Settings.Global#MODE_RINGER}</li>
3962 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
3963 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Nicolas Prevot41916d42015-02-24 18:41:50 +00003964 * <li>{@link Settings.Global#WIFI_ON}
3965 * Changing this setting has not effect as of {@link android.os.Build.VERSION_CODES#MNC}. Use
3966 * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003967 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Benjamin Franz68cc4202015-03-11 15:43:06 +00003968 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN}
3969 * This setting is only available from {@link android.os.Build.VERSION_CODES#MNC} onwards
3970 * and can only be set if {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003971 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04003972 *
3973 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3974 * @param setting The name of the setting to update.
3975 * @param value The value to update the setting to.
3976 */
Robin Lee25e26452015-06-02 09:56:29 -07003977 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04003978 if (mService != null) {
3979 try {
3980 mService.setGlobalSetting(admin, setting, value);
3981 } catch (RemoteException e) {
3982 Log.w(TAG, "Failed talking with device policy service", e);
3983 }
3984 }
3985 }
3986
3987 /**
3988 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
3989 * that the value of the setting is in the correct form for the setting type should be performed
3990 * by the caller.
Julia Reynolds82735bc2014-09-04 16:43:30 -04003991 * <p>The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003992 * <ul>
3993 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07003994 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003995 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
3996 * </ul>
Julia Reynolds82735bc2014-09-04 16:43:30 -04003997 * <p>A device owner can additionally update the following settings:
3998 * <ul>
3999 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
4000 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04004001 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4002 * @param setting The name of the setting to update.
4003 * @param value The value to update the setting to.
4004 */
Robin Lee25e26452015-06-02 09:56:29 -07004005 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04004006 if (mService != null) {
4007 try {
4008 mService.setSecureSetting(admin, setting, value);
4009 } catch (RemoteException e) {
4010 Log.w(TAG, "Failed talking with device policy service", e);
4011 }
4012 }
4013 }
4014
Amith Yamasanif20d6402014-05-24 15:34:37 -07004015 /**
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004016 * Designates a specific service component as the provider for
Amith Yamasanif20d6402014-05-24 15:34:37 -07004017 * making permission requests of a local or remote administrator of the user.
4018 * <p/>
4019 * Only a profile owner can designate the restrictions provider.
4020 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004021 * @param provider The component name of the service that implements
Amith Yamasanid1d7c022014-08-19 17:03:41 -07004022 * {@link RestrictionsReceiver}. If this param is null,
Amith Yamasanif20d6402014-05-24 15:34:37 -07004023 * it removes the restrictions provider previously assigned.
4024 */
Robin Lee25e26452015-06-02 09:56:29 -07004025 public void setRestrictionsProvider(@NonNull ComponentName admin,
4026 @Nullable ComponentName provider) {
Amith Yamasanif20d6402014-05-24 15:34:37 -07004027 if (mService != null) {
4028 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004029 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07004030 } catch (RemoteException re) {
4031 Log.w(TAG, "Failed to set permission provider on device policy service");
4032 }
4033 }
4034 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04004035
4036 /**
4037 * Called by profile or device owners to set the master volume mute on or off.
4038 *
4039 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4040 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
4041 */
Robin Lee25e26452015-06-02 09:56:29 -07004042 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04004043 if (mService != null) {
4044 try {
4045 mService.setMasterVolumeMuted(admin, on);
4046 } catch (RemoteException re) {
4047 Log.w(TAG, "Failed to setMasterMute on device policy service");
4048 }
4049 }
4050 }
4051
4052 /**
4053 * Called by profile or device owners to check whether the master volume mute is on or off.
4054 *
4055 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4056 * @return {@code true} if master volume is muted, {@code false} if it's not.
4057 */
Robin Lee25e26452015-06-02 09:56:29 -07004058 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04004059 if (mService != null) {
4060 try {
4061 return mService.isMasterVolumeMuted(admin);
4062 } catch (RemoteException re) {
4063 Log.w(TAG, "Failed to get isMasterMute on device policy service");
4064 }
4065 }
4066 return false;
4067 }
Kenny Guyc13053b2014-05-29 14:17:17 +01004068
4069 /**
4070 * Called by profile or device owners to change whether a user can uninstall
4071 * a package.
4072 *
4073 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4074 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004075 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Kenny Guyc13053b2014-05-29 14:17:17 +01004076 */
Robin Lee25e26452015-06-02 09:56:29 -07004077 public void setUninstallBlocked(@NonNull ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004078 boolean uninstallBlocked) {
Kenny Guyc13053b2014-05-29 14:17:17 +01004079 if (mService != null) {
4080 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004081 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01004082 } catch (RemoteException re) {
4083 Log.w(TAG, "Failed to call block uninstall on device policy service");
4084 }
4085 }
4086 }
4087
4088 /**
Rubin Xua97855b2014-11-07 05:41:00 +00004089 * Check whether the current user has been blocked by device policy from uninstalling a package.
4090 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00004091 * <p>
4092 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Robin Lee25e26452015-06-02 09:56:29 -07004093 * behavior of this API is changed such that passing {@code null} as the {@code admin}
Rubin Xue1e6faa2015-03-10 10:51:59 +00004094 * parameter will return if any admin has blocked the uninstallation. Before L MR1, passing
Robin Lee25e26452015-06-02 09:56:29 -07004095 * {@code null} will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01004096 *
Robin Lee25e26452015-06-02 09:56:29 -07004097 * @param admin The name of the admin component whose blocking policy will be checked, or
4098 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01004099 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00004100 * @return true if uninstallation is blocked.
Kenny Guyc13053b2014-05-29 14:17:17 +01004101 */
Robin Lee25e26452015-06-02 09:56:29 -07004102 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Kenny Guyc13053b2014-05-29 14:17:17 +01004103 if (mService != null) {
4104 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01004105 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01004106 } catch (RemoteException re) {
4107 Log.w(TAG, "Failed to call block uninstall on device policy service");
4108 }
4109 }
4110 return false;
4111 }
Svetoslav976e8bd2014-07-16 15:12:03 -07004112
4113 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004114 * Called by the profile owner of a managed profile to enable widget providers from a
4115 * given package to be available in the parent profile. As a result the user will be able to
Svetoslav976e8bd2014-07-16 15:12:03 -07004116 * add widgets from the white-listed package running under the profile to a widget
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004117 * host which runs under the parent profile, for example the home screen. Note that
Svetoslav976e8bd2014-07-16 15:12:03 -07004118 * a package may have zero or more provider components, where each component
4119 * provides a different widget type.
4120 * <p>
4121 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07004122 *
4123 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4124 * @param packageName The package from which widget providers are white-listed.
4125 * @return Whether the package was added.
4126 *
4127 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4128 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4129 */
Robin Lee25e26452015-06-02 09:56:29 -07004130 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004131 if (mService != null) {
4132 try {
4133 return mService.addCrossProfileWidgetProvider(admin, packageName);
4134 } catch (RemoteException re) {
4135 Log.w(TAG, "Error calling addCrossProfileWidgetProvider", re);
4136 }
4137 }
4138 return false;
4139 }
4140
4141 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004142 * Called by the profile owner of a managed profile to disable widget providers from a given
4143 * package to be available in the parent profile. For this method to take effect the
Svetoslav976e8bd2014-07-16 15:12:03 -07004144 * package should have been added via {@link #addCrossProfileWidgetProvider(
4145 * android.content.ComponentName, String)}.
4146 * <p>
4147 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07004148 *
4149 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4150 * @param packageName The package from which widget providers are no longer
4151 * white-listed.
4152 * @return Whether the package was removed.
4153 *
4154 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
4155 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4156 */
Robin Lee25e26452015-06-02 09:56:29 -07004157 public boolean removeCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004158 if (mService != null) {
4159 try {
4160 return mService.removeCrossProfileWidgetProvider(admin, packageName);
4161 } catch (RemoteException re) {
4162 Log.w(TAG, "Error calling removeCrossProfileWidgetProvider", re);
4163 }
4164 }
4165 return false;
4166 }
4167
4168 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004169 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07004170 * available in the parent profile.
4171 *
4172 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4173 * @return The white-listed package list.
4174 *
4175 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
4176 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4177 */
Robin Lee25e26452015-06-02 09:56:29 -07004178 public List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004179 if (mService != null) {
4180 try {
4181 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
4182 if (providers != null) {
4183 return providers;
4184 }
4185 } catch (RemoteException re) {
4186 Log.w(TAG, "Error calling getCrossProfileWidgetProviders", re);
4187 }
4188 }
4189 return Collections.emptyList();
4190 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004191
4192 /**
4193 * Called by profile or device owners to set the current user's photo.
4194 *
4195 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4196 * @param icon the bitmap to set as the photo.
4197 */
Robin Lee25e26452015-06-02 09:56:29 -07004198 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004199 try {
4200 mService.setUserIcon(admin, icon);
4201 } catch (RemoteException re) {
4202 Log.w(TAG, "Could not set the user icon ", re);
4203 }
4204 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04004205
4206 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01004207 * Called by device owners to set a local system update policy. When a new policy is set,
4208 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004209 *
Robin Lee25e26452015-06-02 09:56:29 -07004210 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
4211 * components in the device owner package can set system update policies and the
4212 * most recent policy takes
Rubin Xu5faad8e2015-04-20 17:43:48 +01004213 * effect.
Robin Lee25e26452015-06-02 09:56:29 -07004214 * @param policy the new policy, or {@code null} to clear the current policy.
Rubin Xu5faad8e2015-04-20 17:43:48 +01004215 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00004216 */
Robin Lee25e26452015-06-02 09:56:29 -07004217 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Rubin Xu8027a4f2015-03-10 17:52:37 +00004218 if (mService != null) {
4219 try {
Robin Lee25e26452015-06-02 09:56:29 -07004220 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004221 } catch (RemoteException re) {
Rubin Xu5faad8e2015-04-20 17:43:48 +01004222 Log.w(TAG, "Error calling setSystemUpdatePolicy", re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004223 }
4224 }
4225 }
4226
4227 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01004228 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004229 *
Robin Lee25e26452015-06-02 09:56:29 -07004230 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004231 */
Rubin Xu5faad8e2015-04-20 17:43:48 +01004232 public SystemUpdatePolicy getSystemUpdatePolicy() {
Rubin Xu8027a4f2015-03-10 17:52:37 +00004233 if (mService != null) {
4234 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01004235 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00004236 } catch (RemoteException re) {
Rubin Xu5faad8e2015-04-20 17:43:48 +01004237 Log.w(TAG, "Error calling getSystemUpdatePolicy", re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004238 }
4239 }
4240 return null;
4241 }
Benjamin Franze36087e2015-04-07 16:40:34 +01004242
4243 /**
4244 * Called by a device owner to disable the keyguard altogether.
4245 *
4246 * <p>Setting the keyguard to disabled has the same effect as choosing "None" as the screen
4247 * lock type. However, this call has no effect if a password, pin or pattern is currently set.
4248 * If a password, pin or pattern is set after the keyguard was disabled, the keyguard stops
4249 * being disabled.
4250 *
4251 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01004252 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01004253 *
4254 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Benjamin Franzbece8062015-05-06 12:14:31 +01004255 * place. {@code true} otherwise.
Benjamin Franze36087e2015-04-07 16:40:34 +01004256 */
Robin Lee25e26452015-06-02 09:56:29 -07004257 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franze36087e2015-04-07 16:40:34 +01004258 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01004259 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01004260 } catch (RemoteException re) {
4261 Log.w(TAG, "Failed talking with device policy service", re);
4262 return false;
4263 }
4264 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00004265
4266 /**
Benjamin Franzbece8062015-05-06 12:14:31 +01004267 * Called by device owner to disable the status bar. Disabling the status bar blocks
4268 * notifications, quick settings and other screen overlays that allow escaping from
Benjamin Franzea2ec972015-03-16 17:18:09 +00004269 * a single use device.
4270 *
4271 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01004272 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
4273 *
4274 * @return {@code false} if attempting to disable the status bar failed.
4275 * {@code true} otherwise.
Benjamin Franzea2ec972015-03-16 17:18:09 +00004276 */
Robin Lee25e26452015-06-02 09:56:29 -07004277 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzea2ec972015-03-16 17:18:09 +00004278 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01004279 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00004280 } catch (RemoteException re) {
4281 Log.w(TAG, "Failed talking with device policy service", re);
Benjamin Franzbece8062015-05-06 12:14:31 +01004282 return false;
Benjamin Franzea2ec972015-03-16 17:18:09 +00004283 }
4284 }
Rubin Xudc105cc2015-04-14 23:38:01 +01004285
4286 /**
4287 * Callable by the system update service to notify device owners about pending updates.
4288 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
4289 * permission.
4290 *
4291 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating
4292 * when the current pending update was first available. -1 if no update is available.
4293 * @hide
4294 */
4295 @SystemApi
4296 public void notifyPendingSystemUpdate(long updateReceivedTime) {
4297 if (mService != null) {
4298 try {
4299 mService.notifyPendingSystemUpdate(updateReceivedTime);
4300 } catch (RemoteException re) {
4301 Log.w(TAG, "Could not notify device owner about pending system update", re);
4302 }
4303 }
4304 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04004305
4306 /**
Amith Yamasanid49489b2015-04-28 14:00:26 -07004307 * Called by profile or device owners to set the default response for future runtime permission
4308 * requests by applications. The policy can allow for normal operation which prompts the
4309 * user to grant a permission, or can allow automatic granting or denying of runtime
4310 * permission requests by an application. This also applies to new permissions declared by app
4311 * updates.
4312 * @param admin Which profile or device owner this request is associated with.
4313 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
4314 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
4315 */
Robin Lee25e26452015-06-02 09:56:29 -07004316 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004317 try {
4318 mService.setPermissionPolicy(admin, policy);
4319 } catch (RemoteException re) {
4320 Log.w(TAG, "Failed talking with device policy service", re);
4321 }
4322 }
4323
4324 /**
4325 * Returns the current runtime permission policy set by the device or profile owner. The
4326 * default is {@link #PERMISSION_POLICY_PROMPT}.
4327 * @param admin Which profile or device owner this request is associated with.
4328 * @return the current policy for future permission requests.
4329 */
Robin Lee25e26452015-06-02 09:56:29 -07004330 public int getPermissionPolicy(@NonNull ComponentName admin) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004331 try {
4332 return mService.getPermissionPolicy(admin);
4333 } catch (RemoteException re) {
4334 return PERMISSION_POLICY_PROMPT;
4335 }
4336 }
4337
4338 /**
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004339 * Sets the grant state of a runtime permission for a specific application. The state
4340 * can be {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it
4341 * through the UI, {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission
4342 * is denied and the user cannot manage it through the UI, and {@link
4343 * #PERMISSION_GRANT_STATE_GRANTED granted} in which the permission is granted and the
4344 * user cannot manage it through the UI. This might affect all permissions in a
4345 * group that the runtime permission belongs to. This method can only be called
4346 * by a profile or device owner.
4347 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07004348 * @param admin Which profile or device owner this request is associated with.
4349 * @param packageName The application to grant or revoke a permission to.
4350 * @param permission The permission to grant or revoke.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004351 * @param grantState The permission grant state which is one of {@link
4352 * #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
4353 * {@link #PERMISSION_GRANT_STATE_GRANTED},
4354 * @return whether the permission was successfully granted or revoked.
4355 *
4356 * @see #PERMISSION_GRANT_STATE_DENIED
4357 * @see #PERMISSION_GRANT_STATE_DEFAULT
4358 * @see #PERMISSION_GRANT_STATE_GRANTED
Amith Yamasanid49489b2015-04-28 14:00:26 -07004359 */
Robin Lee25e26452015-06-02 09:56:29 -07004360 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004361 String permission, int grantState) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004362 try {
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004363 return mService.setPermissionGrantState(admin, packageName, permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07004364 } catch (RemoteException re) {
4365 Log.w(TAG, "Failed talking with device policy service", re);
4366 return false;
4367 }
4368 }
Amith Yamasani184b3752015-05-22 13:00:51 -07004369
4370 /**
4371 * Returns the current grant state of a runtime permission for a specific application.
4372 *
4373 * @param admin Which profile or device owner this request is associated with.
4374 * @param packageName The application to check the grant state for.
4375 * @param permission The permission to check for.
4376 * @return the current grant state specified by device policy. If the profile or device owner
4377 * has not set a grant state, the return value is {@link #PERMISSION_GRANT_STATE_DEFAULT}.
4378 * This does not indicate whether or not the permission is currently granted for the package.
4379 *
4380 * <p/>If a grant state was set by the profile or device owner, then the return value will
4381 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or {@link #PERMISSION_GRANT_STATE_GRANTED},
4382 * which indicates if the permission is currently denied or granted.
4383 *
4384 * @see #setPermissionGrantState(ComponentName, String, String, int)
4385 * @see PackageManager#checkPermission(String, String)
4386 */
Robin Lee25e26452015-06-02 09:56:29 -07004387 public int getPermissionGrantState(@NonNull ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07004388 String permission) {
4389 try {
4390 return mService.getPermissionGrantState(admin, packageName, permission);
4391 } catch (RemoteException re) {
4392 Log.w(TAG, "Failed talking with device policy service", re);
4393 return PERMISSION_GRANT_STATE_DEFAULT;
4394 }
4395 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08004396}