blob: dcb48904cad5f97426fb52f0043e07bb94782516 [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>
Rubin Xua4f9dc12015-06-12 13:27:59 +0100152 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100153 * </ul>
154 *
155 * <p> When device owner provisioning has completed, an intent of the type
156 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
157 * device owner.
158 *
159 * <p> If provisioning fails, the device is factory reset.
160 *
161 */
162 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
163 public static final String ACTION_PROVISION_MANAGED_DEVICE
164 = "android.app.action.PROVISION_MANAGED_DEVICE";
165
166 /**
Rubin Xua4f9dc12015-06-12 13:27:59 +0100167 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that
168 * allows a mobile device management application which starts managed provisioning to pass data
169 * to itself.
170 * <p>
171 * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that
172 * sends the intent to pass data to itself on the newly created profile.
173 * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same
174 * instance of the app on the primary user.
175 * <p>
176 * In both cases the application receives the data in
Brian Carlstromf1fe51b2014-09-03 08:55:05 -0700177 * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action
178 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed
Rubin Xua4f9dc12015-06-12 13:27:59 +0100179 * during the managed provisioning.
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100180 */
181 public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE =
Esteban Talavera37f01842014-09-05 10:50:57 +0100182 "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE";
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100183
184 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100185 * A String extra holding the package name of the mobile device management application that
186 * will be set as the profile owner or device owner.
187 *
188 * <p>If an application starts provisioning directly via an intent with action
189 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
190 * application that started provisioning. The package will be set as profile owner in that case.
191 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000192 * <p>This package is set as device owner when device owner provisioning is started by an NFC
193 * message containing an NFC record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000194 *
195 * <p> When this extra is set, the application must have exactly one device admin receiver.
Robin Lee25e26452015-06-02 09:56:29 -0700196 * This receiver will be set as the profile or device owner and active admin.
Nicolas Prevot18440252015-03-09 14:07:17 +0000197
198 * @see DeviceAdminReceiver
199 * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still
200 * supported.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000201 */
Nicolas Prevot18440252015-03-09 14:07:17 +0000202 @Deprecated
Jessica Hummelf72078b2014-03-06 16:13:12 +0000203 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100204 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000205
206 /**
Nicolas Prevot18440252015-03-09 14:07:17 +0000207 * A ComponentName extra indicating the device admin receiver of the mobile device management
208 * application that will be set as the profile owner or device owner and active admin.
209 *
210 * <p>If an application starts provisioning directly via an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100211 * {@link #ACTION_PROVISION_MANAGED_PROFILE} or
212 * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this
213 * component has to match the package name of the application that started provisioning.
Nicolas Prevot18440252015-03-09 14:07:17 +0000214 *
215 * <p>This component is set as device owner and active admin when device owner provisioning is
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100216 * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC
217 * message containing an NFC record with MIME type
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400218 * {@link #MIME_TYPE_PROVISIONING_NFC}. For the NFC record, the component name should be
Rubin Xu44ef750b2015-03-23 16:51:33 +0000219 * flattened to a string, via {@link ComponentName#flattenToShortString()}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000220 *
221 * @see DeviceAdminReceiver
222 */
223 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME
224 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME";
225
226 /**
Alexandra Gherghinaaaf2f3e2014-11-13 12:46:15 +0000227 * An {@link android.accounts.Account} extra holding the account to migrate during managed
228 * profile provisioning. If the account supplied is present in the primary user, it will be
229 * copied, along with its credentials to the managed profile and removed from the primary user.
230 *
231 * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}.
232 */
233
234 public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE
235 = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE";
236
237 /**
Jessica Hummele3da7902014-08-20 15:20:11 +0100238 * A String extra that, holds the email address of the account which a managed profile is
239 * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
240 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100241 *
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100242 * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}.
243 *
Jessica Hummele3da7902014-08-20 15:20:11 +0100244 * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning
245 * contains this extra, it is forwarded in the
246 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile
247 * device management application that was set as the profile owner during provisioning.
248 * It is usually used to avoid that the user has to enter their email address twice.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100249 */
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100250 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
251 = "android.app.extra.PROVISIONING_EMAIL_ADDRESS";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100252
253 /**
Sander Alewijnse8c411562014-11-12 18:03:11 +0000254 * A Boolean extra that can be used by the mobile device management application to skip the
Robin Lee25e26452015-06-02 09:56:29 -0700255 * disabling of system apps during provisioning when set to {@code true}.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000256 *
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100257 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
258 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000259 */
Sander Alewijnse5a144252014-11-18 13:25:04 +0000260 public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED =
261 "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED";
Sander Alewijnse8c411562014-11-12 18:03:11 +0000262
263 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100264 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
265 * will be set to.
266 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000267 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
268 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100269 */
270 public static final String EXTRA_PROVISIONING_TIME_ZONE
Esteban Talavera37f01842014-09-05 10:50:57 +0100271 = "android.app.extra.PROVISIONING_TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100272
273 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100274 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
275 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100276 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000277 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
278 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100279 */
280 public static final String EXTRA_PROVISIONING_LOCAL_TIME
Esteban Talavera37f01842014-09-05 10:50:57 +0100281 = "android.app.extra.PROVISIONING_LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100282
283 /**
284 * A String extra holding the {@link java.util.Locale} that the device will be set to.
285 * Format: xx_yy, where xx is the language code, and yy the country code.
286 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000287 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
288 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100289 */
290 public static final String EXTRA_PROVISIONING_LOCALE
Esteban Talavera37f01842014-09-05 10:50:57 +0100291 = "android.app.extra.PROVISIONING_LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100292
293 /**
294 * A String extra holding the ssid of the wifi network that should be used during nfc device
295 * owner provisioning for downloading the mobile device management application.
296 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000297 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
298 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100299 */
300 public static final String EXTRA_PROVISIONING_WIFI_SSID
Esteban Talavera37f01842014-09-05 10:50:57 +0100301 = "android.app.extra.PROVISIONING_WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100302
303 /**
304 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
305 * is hidden or not.
306 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000307 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
308 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100309 */
310 public static final String EXTRA_PROVISIONING_WIFI_HIDDEN
Esteban Talavera37f01842014-09-05 10:50:57 +0100311 = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100312
313 /**
314 * A String extra indicating the security type of the wifi network in
315 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
316 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000317 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
318 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100319 */
320 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
Esteban Talavera37f01842014-09-05 10:50:57 +0100321 = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100322
323 /**
324 * A String extra holding the password of the wifi network in
325 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
326 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000327 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
328 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100329 */
330 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talavera37f01842014-09-05 10:50:57 +0100331 = "android.app.extra.PROVISIONING_WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100332
333 /**
334 * A String extra holding the proxy host for the wifi network in
335 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
336 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000337 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
338 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100339 */
340 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
Esteban Talavera37f01842014-09-05 10:50:57 +0100341 = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100342
343 /**
344 * An int extra holding the proxy port for the wifi network in
345 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
346 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000347 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
348 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100349 */
350 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
Esteban Talavera37f01842014-09-05 10:50:57 +0100351 = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100352
353 /**
354 * A String extra holding the proxy bypass for the wifi network in
355 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
356 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000357 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
358 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100359 */
360 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
Esteban Talavera37f01842014-09-05 10:50:57 +0100361 = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100362
363 /**
364 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
365 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
366 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000367 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
368 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100369 */
370 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
Esteban Talavera37f01842014-09-05 10:50:57 +0100371 = "android.app.extra.PROVISIONING_WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100372
373 /**
374 * A String extra holding a url that specifies the download location of the device admin
375 * package. When not provided it is assumed that the device admin package is already installed.
376 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000377 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
378 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100379 */
380 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talavera37f01842014-09-05 10:50:57 +0100381 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100382
383 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400384 * An int extra holding a minimum required version code for the device admin package. If the
385 * device admin is already installed on the device, it will only be re-downloaded from
386 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the
387 * installed package is less than this version code.
388 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400389 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400390 * provisioning via an NFC bump.
391 */
392 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE
393 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE";
394
395 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100396 * A String extra holding a http cookie header which should be used in the http request to the
397 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
398 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000399 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
400 * provisioning via an NFC bump.
Sander Alewijnse681bce92014-07-24 16:46:26 +0100401 */
402 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talavera37f01842014-09-05 10:50:57 +0100403 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100404
405 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100406 * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of
407 * the file at download location specified in
408 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100409 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100410 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} should be
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100411 * present. The provided checksum should match the checksum of the file at the download
412 * location. If the checksum doesn't match an error will be shown to the user and the user will
413 * be asked to factory reset the device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100414 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000415 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
416 * provisioning via an NFC bump.
Rubin Xud92e7572015-05-18 17:01:13 +0100417 *
418 * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP}
419 * and {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1} only SHA-1 hash is supported.
420 * Starting from {@link android.os.Build.VERSION_CODES#MNC}, this parameter accepts SHA-256 in
421 * addition to SHA-1. Support for SHA-1 is likely to be removed in future OS releases.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100422 */
423 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100424 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100425
426 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100427 * A String extra holding the URL-safe base64 encoded SHA-256 checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100428 * android package archive at the download location specified in {@link
429 * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
430 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100431 * <p>The signatures of an android package archive can be obtained using
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100432 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
433 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
434 *
435 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} should be
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100436 * present. The provided checksum should match the checksum of any signature of the file at
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100437 * the download location. If the checksum does not match an error will be shown to the user and
438 * the user will be asked to factory reset the device.
439 *
440 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
441 * provisioning via an NFC bump.
442 */
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100443 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM
444 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM";
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100445
446 /**
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000447 * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile
448 * has completed successfully.
449 *
450 * <p>The broadcast is limited to the primary profile, to the app specified in the provisioning
Nicolas Prevotebe2d992015-05-12 18:14:53 -0700451 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000452 *
Ying Wang7f38aab2015-02-20 11:50:09 -0800453 * <p>This intent will contain the extra {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE} which
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000454 * corresponds to the account requested to be migrated at provisioning time, if any.
455 */
456 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
457 public static final String ACTION_MANAGED_PROFILE_PROVISIONED
458 = "android.app.action.MANAGED_PROFILE_PROVISIONED";
459
460 /**
Julia Reynolds2f46d942015-05-05 11:44:20 -0400461 * A boolean extra indicating whether device encryption can be skipped as part of Device Owner
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500462 * provisioning.
463 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400464 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100465 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500466 */
467 public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION =
468 "android.app.extra.PROVISIONING_SKIP_ENCRYPTION";
469
470 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -0400471 * @hide
Rubin Xu44ef750b2015-03-23 16:51:33 +0000472 * On devices managed by a device owner app, a {@link ComponentName} extra indicating the
473 * component of the application that is temporarily granted device owner privileges during
474 * device initialization and profile owner privileges during secondary user initialization.
Julia Reynolds20118f12015-02-11 12:34:08 -0500475 *
Rubin Xu44ef750b2015-03-23 16:51:33 +0000476 * <p>
Rubin Xu6a38e432015-03-26 14:47:45 +0000477 * 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 +0000478 * device owner provisioning via an NFC bump. For the NFC record, it should be flattened to a
479 * string first.
480 *
481 * @see ComponentName#flattenToShortString()
Julia Reynolds20118f12015-02-11 12:34:08 -0500482 */
483 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_COMPONENT_NAME
484 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_COMPONENT_NAME";
485
486 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -0400487 * @hide
Julia Reynolds20118f12015-02-11 12:34:08 -0500488 * A String extra holding an http url that specifies the download location of the device
489 * initializer package. When not provided it is assumed that the device initializer package is
490 * already installed.
491 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400492 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynolds20118f12015-02-11 12:34:08 -0500493 * provisioning via an NFC bump.
494 */
495 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION
496 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION";
497
498 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -0400499 * @hide
Julia Reynoldsc1731742015-03-19 14:56:28 -0400500 * An int extra holding a minimum required version code for the device initializer package.
501 * If the initializer is already installed on the device, it will only be re-downloaded from
502 * {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION} if the version of
503 * the installed package is less than this version code.
504 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400505 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400506 * provisioning via an NFC bump.
507 */
508 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_MINIMUM_VERSION_CODE
509 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_MINIMUM_VERSION_CODE";
510
511 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -0400512 * @hide
Julia Reynolds20118f12015-02-11 12:34:08 -0500513 * A String extra holding a http cookie header which should be used in the http request to the
514 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION}.
515 *
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_DOWNLOAD_COOKIE_HEADER
520 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_COOKIE_HEADER";
521
522 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -0400523 * @hide
Rubin Xud92e7572015-05-18 17:01:13 +0100524 * A String extra holding the URL-safe base64 encoded SHA-256 checksum of the file at download
Rubin Xue30ab112015-03-24 11:22:28 +0000525 * location specified in
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100526 * {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION}.
527 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100528 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_SIGNATURE_CHECKSUM}
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100529 * should be present. The provided checksum should match the checksum of the file at the
530 * download location. If the checksum doesn't match an error will be shown to the user and the
531 * user will be asked to factory reset the device.
Julia Reynolds20118f12015-02-11 12:34:08 -0500532 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400533 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynolds20118f12015-02-11 12:34:08 -0500534 * provisioning via an NFC bump.
535 */
536 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM
537 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM";
538
539 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -0400540 * @hide
Rubin Xud92e7572015-05-18 17:01:13 +0100541 * A String extra holding the URL-safe base64 encoded SHA-256 checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100542 * android package archive at the download location specified in {@link
543 * #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION}.
544 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100545 * <p>The signatures of an android package archive can be obtained using
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100546 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
547 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
548 *
549 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM}
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100550 * should be present. The provided checksum should match the checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100551 * file at the download location. If the checksum doesn't match an error will be shown to the
552 * user and the user will be asked to factory reset the device.
553 *
554 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
555 * provisioning via an NFC bump.
556 */
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100557 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_SIGNATURE_CHECKSUM
558 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_SIGNATURE_CHECKSUM";
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100559
560 /**
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400561 * This MIME type is used for starting the Device Owner provisioning.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100562 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400563 * <p>During device owner provisioning a device admin app is set as the owner of the device.
564 * A device owner has full control over the device. The device owner can not be modified by the
565 * user and the only way of resetting the device is if the device owner app calls a factory
566 * reset.
567 *
568 * <p> A typical use case would be a device that is owned by a company, but used by either an
569 * employee or client.
570 *
571 * <p> The NFC message should be send to an unprovisioned device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100572 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000573 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100574 * contains the following properties:
575 * <ul>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400576 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
577 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100578 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400579 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100580 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
581 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
582 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
583 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
584 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
585 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
586 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
587 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
588 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
589 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400590 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100591 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000592 * <p>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400593 * As of {@link android.os.Build.VERSION_CODES#MNC}, the properties should contain
594 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of
595 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only
596 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400597 */
598 public static final String MIME_TYPE_PROVISIONING_NFC
599 = "application/com.android.managedprovisioning";
600
601
602 /**
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400603 * @hide
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400604 * This MIME type is used for starting the Device Owner provisioning that requires
605 * new provisioning features introduced in API version
606 * {@link android.os.Build.VERSION_CODES#MNC} in addition to those supported in earlier
607 * versions.
608 *
609 * <p>During device owner provisioning a device admin app is set as the owner of the device.
610 * 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 +0100611 * user.
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400612 *
613 * <p> A typical use case would be a device that is owned by a company, but used by either an
614 * employee or client.
615 *
616 * <p> The NFC message should be sent to an unprovisioned device.
617 *
618 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
619 * contains the following properties in addition to properties listed at
620 * {@link #MIME_TYPE_PROVISIONING_NFC}:
621 * <ul>
622 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400623 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}.
624 * Replaces {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}. The value of the property
625 * should be converted to a String via
626 * {@link android.content.ComponentName#flattenToString()}</li>
Craig Lafayette240e6482015-06-02 11:12:43 -0400627 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE}, optional</li></ul>
Nicolas Prevot18440252015-03-09 14:07:17 +0000628 *
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100629 * <p> When device owner provisioning has completed, an intent of the type
630 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcasted to the
631 * device owner.
632 *
633 * <p>
634 * If provisioning fails, the device is factory reset.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100635 */
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400636 public static final String MIME_TYPE_PROVISIONING_NFC_V2
637 = "application/com.android.managedprovisioning.v2";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100638
639 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800640 * Activity action: ask the user to add a new device administrator to the system.
641 * The desired policy is the ComponentName of the policy in the
642 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
643 * bring the user through adding the device administrator to the system (or
644 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700645 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800646 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
647 * field to provide the user with additional explanation (in addition
648 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800649 *
650 * <p>If your administrator is already active, this will ordinarily return immediately (without
651 * user intervention). However, if your administrator has been updated and is requesting
652 * additional uses-policy flags, the user will be presented with the new list. New policies
653 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800654 */
655 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
656 public static final String ACTION_ADD_DEVICE_ADMIN
657 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700658
Dianne Hackbornd6847842010-01-12 18:14:19 -0800659 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700660 * @hide
661 * Activity action: ask the user to add a new device administrator as the profile owner
Amith Yamasani814e9872015-03-23 14:04:53 -0700662 * for this user. Only system apps can launch this intent.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700663 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700664 * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN}
665 * extra field. This will invoke a UI to bring the user through adding the profile owner admin
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700666 * to remotely control restrictions on the user.
667 *
668 * <p>The intent must be invoked via {@link Activity#startActivityForResult()} to receive the
669 * result of whether or not the user approved the action. If approved, the result will
670 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
671 * as a profile owner.
672 *
673 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
674 * field to provide the user with additional explanation (in addition
675 * to your component's description) about what is being added.
676 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700677 * <p>If there is already a profile owner active or the caller is not a system app, the
678 * operation will return a failure result.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700679 */
680 @SystemApi
681 public static final String ACTION_SET_PROFILE_OWNER
682 = "android.app.action.SET_PROFILE_OWNER";
683
684 /**
685 * @hide
686 * Name of the profile owner admin that controls the user.
687 */
688 @SystemApi
689 public static final String EXTRA_PROFILE_OWNER_NAME
690 = "android.app.extra.PROFILE_OWNER_NAME";
691
692 /**
Jim Miller284b62e2010-06-08 14:27:42 -0700693 * Activity action: send when any policy admin changes a policy.
694 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700695 *
Jim Miller284b62e2010-06-08 14:27:42 -0700696 * @hide
697 */
698 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
699 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
700
701 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800702 * The ComponentName of the administrator component.
703 *
704 * @see #ACTION_ADD_DEVICE_ADMIN
705 */
706 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700707
Dianne Hackbornd6847842010-01-12 18:14:19 -0800708 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800709 * An optional CharSequence providing additional explanation for why the
710 * admin is being added.
711 *
712 * @see #ACTION_ADD_DEVICE_ADMIN
713 */
714 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700715
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800716 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700717 * Activity action: have the user enter a new password. This activity should
718 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
719 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
720 * enter a new password that meets the current requirements. You can use
721 * {@link #isActivePasswordSufficient()} to determine whether you need to
722 * have the user select a new password in order to meet the current
723 * constraints. Upon being resumed from this activity, you can check the new
724 * password characteristics to see if they are sufficient.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800725 */
726 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
727 public static final String ACTION_SET_NEW_PASSWORD
728 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700729
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000730 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000731 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
732 * the parent profile to access intents sent from the managed profile.
733 * That is, when an app in the managed profile calls
734 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
735 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000736 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100737 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000738
739 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000740 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
741 * the managed profile to access intents sent from the parent profile.
742 * That is, when an app in the parent profile calls
743 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
744 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000745 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100746 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700747
Dianne Hackbornd6847842010-01-12 18:14:19 -0800748 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +0100749 * Broadcast action: notify that a new local system update policy has been set by the device
750 * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}.
Rubin Xu8027a4f2015-03-10 17:52:37 +0000751 */
752 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Rubin Xu5faad8e2015-04-20 17:43:48 +0100753 public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED
754 = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED";
Rubin Xu8027a4f2015-03-10 17:52:37 +0000755
Amith Yamasanid49489b2015-04-28 14:00:26 -0700756 /**
757 * Permission policy to prompt user for new permission requests for runtime permissions.
758 * Already granted or denied permissions are not affected by this.
759 */
760 public static final int PERMISSION_POLICY_PROMPT = 0;
761
762 /**
763 * Permission policy to always grant new permission requests for runtime permissions.
764 * Already granted or denied permissions are not affected by this.
765 */
766 public static final int PERMISSION_POLICY_AUTO_GRANT = 1;
767
768 /**
769 * Permission policy to always deny new permission requests for runtime permissions.
770 * Already granted or denied permissions are not affected by this.
771 */
772 public static final int PERMISSION_POLICY_AUTO_DENY = 2;
773
Svet Ganovd8ecc5a2015-05-20 10:45:43 -0700774 /**
775 * Runtime permission state: The user can manage the permission
776 * through the UI.
777 */
778 public static final int PERMISSION_GRANT_STATE_DEFAULT = 0;
779
780 /**
781 * Runtime permission state: The permission is granted to the app
782 * and the user cannot manage the permission through the UI.
783 */
784 public static final int PERMISSION_GRANT_STATE_GRANTED = 1;
785
786 /**
787 * Runtime permission state: The permission is denied to the app
788 * and the user cannot manage the permission through the UI.
789 */
790 public static final int PERMISSION_GRANT_STATE_DENIED = 2;
Rubin Xu8027a4f2015-03-10 17:52:37 +0000791
792 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800793 * Return true if the given administrator component is currently
794 * active (enabled) in the system.
795 */
Robin Lee25e26452015-06-02 09:56:29 -0700796 public boolean isAdminActive(@NonNull ComponentName admin) {
797 return isAdminActiveAsUser(admin, UserHandle.myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100798 }
799
800 /**
801 * @see #isAdminActive(ComponentName)
802 * @hide
803 */
Robin Lee25e26452015-06-02 09:56:29 -0700804 public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800805 if (mService != null) {
806 try {
Robin Lee25e26452015-06-02 09:56:29 -0700807 return mService.isAdminActive(admin, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800808 } catch (RemoteException e) {
809 Log.w(TAG, "Failed talking with device policy service", e);
810 }
811 }
812 return false;
813 }
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800814 /**
815 * Return true if the given administrator component is currently being removed
816 * for the user.
817 * @hide
818 */
Robin Lee25e26452015-06-02 09:56:29 -0700819 public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) {
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800820 if (mService != null) {
821 try {
Robin Lee25e26452015-06-02 09:56:29 -0700822 return mService.isRemovingAdmin(admin, userId);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800823 } catch (RemoteException e) {
824 Log.w(TAG, "Failed talking with device policy service", e);
825 }
826 }
827 return false;
828 }
829
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700830
Dianne Hackbornd6847842010-01-12 18:14:19 -0800831 /**
Robin Lee25e26452015-06-02 09:56:29 -0700832 * Return a list of all currently active device administrators' component
833 * names. If there are no administrators {@code null} may be
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800834 * returned.
835 */
836 public List<ComponentName> getActiveAdmins() {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100837 return getActiveAdminsAsUser(UserHandle.myUserId());
838 }
839
840 /**
841 * @see #getActiveAdmins()
842 * @hide
843 */
844 public List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800845 if (mService != null) {
846 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100847 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800848 } catch (RemoteException e) {
849 Log.w(TAG, "Failed talking with device policy service", e);
850 }
851 }
852 return null;
853 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700854
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800855 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700856 * Used by package administration code to determine if a package can be stopped
857 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800858 * @hide
859 */
860 public boolean packageHasActiveAdmins(String packageName) {
861 if (mService != null) {
862 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700863 return mService.packageHasActiveAdmins(packageName, UserHandle.myUserId());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800864 } catch (RemoteException e) {
865 Log.w(TAG, "Failed talking with device policy service", e);
866 }
867 }
868 return false;
869 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700870
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800871 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800872 * Remove a current administration component. This can only be called
873 * by the application that owns the administration component; if you
874 * try to remove someone else's component, a security exception will be
875 * thrown.
876 */
Robin Lee25e26452015-06-02 09:56:29 -0700877 public void removeActiveAdmin(@NonNull ComponentName admin) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800878 if (mService != null) {
879 try {
Robin Lee25e26452015-06-02 09:56:29 -0700880 mService.removeActiveAdmin(admin, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800881 } catch (RemoteException e) {
882 Log.w(TAG, "Failed talking with device policy service", e);
883 }
884 }
885 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700886
Dianne Hackbornd6847842010-01-12 18:14:19 -0800887 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800888 * Returns true if an administrator has been granted a particular device policy. This can
Robin Lee25e26452015-06-02 09:56:29 -0700889 * be used to check whether the administrator was activated under an earlier set of policies,
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800890 * but requires additional policies after an upgrade.
891 *
892 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be
893 * an active administrator, or an exception will be thrown.
894 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
895 */
Robin Lee25e26452015-06-02 09:56:29 -0700896 public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) {
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800897 if (mService != null) {
898 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700899 return mService.hasGrantedPolicy(admin, usesPolicy, UserHandle.myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800900 } catch (RemoteException e) {
901 Log.w(TAG, "Failed talking with device policy service", e);
902 }
903 }
904 return false;
905 }
906
907 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800908 * Constant for {@link #setPasswordQuality}: the policy has no requirements
909 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800910 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800911 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800912 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700913
Dianne Hackbornd6847842010-01-12 18:14:19 -0800914 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700915 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
916 * recognition technology. This implies technologies that can recognize the identity of
917 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
918 * Note that quality constants are ordered so that higher values are more restrictive.
919 */
920 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
921
922 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800923 * Constant for {@link #setPasswordQuality}: the policy requires some kind
Benjamin Franzc6a96532015-06-16 11:23:38 +0100924 * of password or pattern, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800925 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800926 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800927 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700928
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800929 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800930 * Constant for {@link #setPasswordQuality}: the user must have entered a
931 * password containing at least numeric characters. Note that quality
932 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800933 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800934 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700935
Dianne Hackbornd6847842010-01-12 18:14:19 -0800936 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800937 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -0800938 * password containing at least numeric characters with no repeating (4444)
939 * or ordered (1234, 4321, 2468) sequences. Note that quality
940 * constants are ordered so that higher values are more restrictive.
941 */
942 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
943
944 /**
945 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700946 * password containing at least alphabetic (or other symbol) characters.
947 * Note that quality constants are ordered so that higher values are more
948 * restrictive.
949 */
950 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700951
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700952 /**
953 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800954 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700955 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800956 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800957 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700958 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700959
Dianne Hackbornd6847842010-01-12 18:14:19 -0800960 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700961 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700962 * password containing at least a letter, a numerical digit and a special
963 * symbol, by default. With this password quality, passwords can be
964 * restricted to contain various sets of characters, like at least an
965 * uppercase letter, etc. These are specified using various methods,
966 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
967 * that quality constants are ordered so that higher values are more
968 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700969 */
970 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
971
972 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800973 * Called by an application that is administering the device to set the
974 * password restrictions it is imposing. After setting this, the user
975 * will not be able to enter a new password that is not at least as
976 * restrictive as what has been set. Note that the current password
977 * will remain until the user has set a new one, so the change does not
978 * take place immediately. To prompt the user for a new password, use
979 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700980 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800981 * <p>Quality constants are ordered so that higher values are more restrictive;
982 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800983 * the user's preference, and any other considerations) is the one that
984 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700985 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800986 * <p>The calling device admin must have requested
987 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
988 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700989 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800990 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800991 * @param quality The new desired quality. One of
992 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Jim Miller85516d02014-01-31 17:08:37 -0800993 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
994 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}
995 * or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800996 */
Robin Lee25e26452015-06-02 09:56:29 -0700997 public void setPasswordQuality(@NonNull ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800998 if (mService != null) {
999 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001000 mService.setPasswordQuality(admin, quality);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001001 } catch (RemoteException e) {
1002 Log.w(TAG, "Failed talking with device policy service", e);
1003 }
1004 }
1005 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001006
Dianne Hackbornd6847842010-01-12 18:14:19 -08001007 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001008 * Retrieve the current minimum password quality for all admins of this user
1009 * and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001010 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001011 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001012 */
Robin Lee25e26452015-06-02 09:56:29 -07001013 public int getPasswordQuality(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001014 return getPasswordQuality(admin, UserHandle.myUserId());
1015 }
1016
1017 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001018 public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001019 if (mService != null) {
1020 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001021 return mService.getPasswordQuality(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001022 } catch (RemoteException e) {
1023 Log.w(TAG, "Failed talking with device policy service", e);
1024 }
1025 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001026 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001027 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001028
Dianne Hackbornd6847842010-01-12 18:14:19 -08001029 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001030 * Called by an application that is administering the device to set the
1031 * minimum allowed password length. After setting this, the user
1032 * will not be able to enter a new password that is not at least as
1033 * restrictive as what has been set. Note that the current password
1034 * will remain until the user has set a new one, so the change does not
1035 * take place immediately. To prompt the user for a new password, use
1036 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1037 * constraint is only imposed if the administrator has also requested either
Jim Miller85516d02014-01-31 17:08:37 -08001038 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
1039 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC},
1040 * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001041 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001042 * <p>The calling device admin must have requested
1043 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1044 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001045 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001046 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001047 * @param length The new desired minimum password length. A value of 0
1048 * means there is no restriction.
1049 */
Robin Lee25e26452015-06-02 09:56:29 -07001050 public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001051 if (mService != null) {
1052 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001053 mService.setPasswordMinimumLength(admin, length);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001054 } catch (RemoteException e) {
1055 Log.w(TAG, "Failed talking with device policy service", e);
1056 }
1057 }
1058 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001059
Dianne Hackbornd6847842010-01-12 18:14:19 -08001060 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001061 * Retrieve the current minimum password length for all admins of this
1062 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001063 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001064 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001065 */
Robin Lee25e26452015-06-02 09:56:29 -07001066 public int getPasswordMinimumLength(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001067 return getPasswordMinimumLength(admin, UserHandle.myUserId());
1068 }
1069
1070 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001071 public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001072 if (mService != null) {
1073 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001074 return mService.getPasswordMinimumLength(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001075 } catch (RemoteException e) {
1076 Log.w(TAG, "Failed talking with device policy service", e);
1077 }
1078 }
1079 return 0;
1080 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001081
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001082 /**
1083 * Called by an application that is administering the device to set the
1084 * minimum number of upper case letters required in the password. After
1085 * setting this, the user will not be able to enter a new password that is
1086 * not at least as restrictive as what has been set. Note that the current
1087 * password will remain until the user has set a new one, so the change does
1088 * not take place immediately. To prompt the user for a new password, use
1089 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1090 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001091 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1092 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001093 * <p>
1094 * The calling device admin must have requested
1095 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1096 * this method; if it has not, a security exception will be thrown.
1097 *
1098 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1099 * with.
1100 * @param length The new desired minimum number of upper case letters
1101 * required in the password. A value of 0 means there is no
1102 * restriction.
1103 */
Robin Lee25e26452015-06-02 09:56:29 -07001104 public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001105 if (mService != null) {
1106 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001107 mService.setPasswordMinimumUpperCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001108 } catch (RemoteException e) {
1109 Log.w(TAG, "Failed talking with device policy service", e);
1110 }
1111 }
1112 }
1113
1114 /**
1115 * Retrieve the current number of upper case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001116 * password for all admins of this user and its profiles or a particular one.
1117 * This is the same value as set by
1118 * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001119 * and only applies when the password quality is
1120 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001121 *
Robin Lee25e26452015-06-02 09:56:29 -07001122 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001123 * aggregate all admins.
1124 * @return The minimum number of upper case letters required in the
1125 * password.
1126 */
Robin Lee25e26452015-06-02 09:56:29 -07001127 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001128 return getPasswordMinimumUpperCase(admin, UserHandle.myUserId());
1129 }
1130
1131 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001132 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001133 if (mService != null) {
1134 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001135 return mService.getPasswordMinimumUpperCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001136 } catch (RemoteException e) {
1137 Log.w(TAG, "Failed talking with device policy service", e);
1138 }
1139 }
1140 return 0;
1141 }
1142
1143 /**
1144 * Called by an application that is administering the device to set the
1145 * minimum number of lower case letters required in the password. After
1146 * setting this, the user will not be able to enter a new password that is
1147 * not at least as restrictive as what has been set. Note that the current
1148 * password will remain until the user has set a new one, so the change does
1149 * not take place immediately. To prompt the user for a new password, use
1150 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1151 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001152 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1153 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001154 * <p>
1155 * The calling device admin must have requested
1156 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1157 * this method; if it has not, a security exception will be thrown.
1158 *
1159 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1160 * with.
1161 * @param length The new desired minimum number of lower case letters
1162 * required in the password. A value of 0 means there is no
1163 * restriction.
1164 */
Robin Lee25e26452015-06-02 09:56:29 -07001165 public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001166 if (mService != null) {
1167 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001168 mService.setPasswordMinimumLowerCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001169 } catch (RemoteException e) {
1170 Log.w(TAG, "Failed talking with device policy service", e);
1171 }
1172 }
1173 }
1174
1175 /**
1176 * Retrieve the current number of lower case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001177 * password for all admins of this user and its profiles or a particular one.
1178 * This is the same value as set by
1179 * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001180 * and only applies when the password quality is
1181 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001182 *
Robin Lee25e26452015-06-02 09:56:29 -07001183 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001184 * aggregate all admins.
1185 * @return The minimum number of lower case letters required in the
1186 * password.
1187 */
Robin Lee25e26452015-06-02 09:56:29 -07001188 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001189 return getPasswordMinimumLowerCase(admin, UserHandle.myUserId());
1190 }
1191
1192 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001193 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001194 if (mService != null) {
1195 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001196 return mService.getPasswordMinimumLowerCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001197 } catch (RemoteException e) {
1198 Log.w(TAG, "Failed talking with device policy service", e);
1199 }
1200 }
1201 return 0;
1202 }
1203
1204 /**
1205 * Called by an application that is administering the device to set the
1206 * minimum number of letters required in the password. After setting this,
1207 * the user will not be able to enter a new password that is not at least as
1208 * restrictive as what has been set. Note that the current password will
1209 * remain until the user has set a new one, so the change does not take
1210 * place immediately. To prompt the user for a new password, use
1211 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1212 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001213 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1214 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001215 * <p>
1216 * The calling device admin must have requested
1217 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1218 * this method; if it has not, a security exception will be thrown.
1219 *
1220 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1221 * with.
1222 * @param length The new desired minimum number of letters required in the
1223 * password. A value of 0 means there is no restriction.
1224 */
Robin Lee25e26452015-06-02 09:56:29 -07001225 public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001226 if (mService != null) {
1227 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001228 mService.setPasswordMinimumLetters(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001229 } catch (RemoteException e) {
1230 Log.w(TAG, "Failed talking with device policy service", e);
1231 }
1232 }
1233 }
1234
1235 /**
1236 * Retrieve the current number of letters required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001237 * admins or a particular one. This is the same value as
1238 * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)}
1239 * and only applies when the password quality is
1240 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001241 *
Robin Lee25e26452015-06-02 09:56:29 -07001242 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001243 * aggregate all admins.
1244 * @return The minimum number of letters required in the password.
1245 */
Robin Lee25e26452015-06-02 09:56:29 -07001246 public int getPasswordMinimumLetters(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001247 return getPasswordMinimumLetters(admin, UserHandle.myUserId());
1248 }
1249
1250 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001251 public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001252 if (mService != null) {
1253 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001254 return mService.getPasswordMinimumLetters(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001255 } catch (RemoteException e) {
1256 Log.w(TAG, "Failed talking with device policy service", e);
1257 }
1258 }
1259 return 0;
1260 }
1261
1262 /**
1263 * Called by an application that is administering the device to set the
1264 * minimum number of numerical digits required in the password. After
1265 * setting this, the user will not be able to enter a new password that is
1266 * not at least as restrictive as what has been set. Note that the current
1267 * password will remain until the user has set a new one, so the change does
1268 * not take place immediately. To prompt the user for a new password, use
1269 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1270 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001271 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1272 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001273 * <p>
1274 * The calling device admin must have requested
1275 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1276 * this method; if it has not, a security exception will be thrown.
1277 *
1278 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1279 * with.
1280 * @param length The new desired minimum number of numerical digits required
1281 * in the password. A value of 0 means there is no restriction.
1282 */
Robin Lee25e26452015-06-02 09:56:29 -07001283 public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001284 if (mService != null) {
1285 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001286 mService.setPasswordMinimumNumeric(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001287 } catch (RemoteException e) {
1288 Log.w(TAG, "Failed talking with device policy service", e);
1289 }
1290 }
1291 }
1292
1293 /**
1294 * Retrieve the current number of numerical digits required in the password
Jessica Hummel91da58d2014-04-10 17:39:43 +01001295 * for all admins of this user and its profiles or a particular one.
1296 * This is the same value as set by
1297 * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001298 * and only applies when the password quality is
1299 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001300 *
Robin Lee25e26452015-06-02 09:56:29 -07001301 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001302 * aggregate all admins.
1303 * @return The minimum number of numerical digits required in the password.
1304 */
Robin Lee25e26452015-06-02 09:56:29 -07001305 public int getPasswordMinimumNumeric(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001306 return getPasswordMinimumNumeric(admin, UserHandle.myUserId());
1307 }
1308
1309 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001310 public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001311 if (mService != null) {
1312 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001313 return mService.getPasswordMinimumNumeric(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001314 } catch (RemoteException e) {
1315 Log.w(TAG, "Failed talking with device policy service", e);
1316 }
1317 }
1318 return 0;
1319 }
1320
1321 /**
1322 * Called by an application that is administering the device to set the
1323 * minimum number of symbols required in the password. After setting this,
1324 * the user will not be able to enter a new password that is not at least as
1325 * restrictive as what has been set. Note that the current password will
1326 * remain until the user has set a new one, so the change does not take
1327 * place immediately. To prompt the user for a new password, use
1328 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1329 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001330 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1331 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001332 * <p>
1333 * The calling device admin must have requested
1334 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1335 * this method; if it has not, a security exception will be thrown.
1336 *
1337 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1338 * with.
1339 * @param length The new desired minimum number of symbols required in the
1340 * password. A value of 0 means there is no restriction.
1341 */
Robin Lee25e26452015-06-02 09:56:29 -07001342 public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001343 if (mService != null) {
1344 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001345 mService.setPasswordMinimumSymbols(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001346 } catch (RemoteException e) {
1347 Log.w(TAG, "Failed talking with device policy service", e);
1348 }
1349 }
1350 }
1351
1352 /**
1353 * Retrieve the current number of symbols required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001354 * admins or a particular one. This is the same value as
1355 * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)}
1356 * and only applies when the password quality is
1357 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001358 *
Robin Lee25e26452015-06-02 09:56:29 -07001359 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001360 * aggregate all admins.
1361 * @return The minimum number of symbols required in the password.
1362 */
Robin Lee25e26452015-06-02 09:56:29 -07001363 public int getPasswordMinimumSymbols(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001364 return getPasswordMinimumSymbols(admin, UserHandle.myUserId());
1365 }
1366
1367 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001368 public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001369 if (mService != null) {
1370 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001371 return mService.getPasswordMinimumSymbols(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001372 } catch (RemoteException e) {
1373 Log.w(TAG, "Failed talking with device policy service", e);
1374 }
1375 }
1376 return 0;
1377 }
1378
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001379 /**
1380 * Called by an application that is administering the device to set the
1381 * minimum number of non-letter characters (numerical digits or symbols)
1382 * required in the password. After setting this, the user will not be able
1383 * to enter a new password that is not at least as restrictive as what has
1384 * been set. Note that the current password will remain until the user has
1385 * set a new one, so the change does not take place immediately. To prompt
1386 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after
1387 * setting this value. This constraint is only imposed if the administrator
1388 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1389 * {@link #setPasswordQuality}. The default value is 0.
1390 * <p>
1391 * The calling device admin must have requested
1392 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1393 * this method; if it has not, a security exception will be thrown.
1394 *
1395 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1396 * with.
1397 * @param length The new desired minimum number of letters required in the
1398 * password. A value of 0 means there is no restriction.
1399 */
Robin Lee25e26452015-06-02 09:56:29 -07001400 public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001401 if (mService != null) {
1402 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001403 mService.setPasswordMinimumNonLetter(admin, length);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001404 } catch (RemoteException e) {
1405 Log.w(TAG, "Failed talking with device policy service", e);
1406 }
1407 }
1408 }
1409
1410 /**
1411 * Retrieve the current number of non-letter characters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001412 * password for all admins of this user and its profiles or a particular one.
1413 * This is the same value as set by
1414 * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001415 * and only applies when the password quality is
1416 * {@link #PASSWORD_QUALITY_COMPLEX}.
1417 *
Robin Lee25e26452015-06-02 09:56:29 -07001418 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001419 * aggregate all admins.
1420 * @return The minimum number of letters required in the password.
1421 */
Robin Lee25e26452015-06-02 09:56:29 -07001422 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001423 return getPasswordMinimumNonLetter(admin, UserHandle.myUserId());
1424 }
1425
1426 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001427 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001428 if (mService != null) {
1429 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001430 return mService.getPasswordMinimumNonLetter(admin, userHandle);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001431 } catch (RemoteException e) {
1432 Log.w(TAG, "Failed talking with device policy service", e);
1433 }
1434 }
1435 return 0;
1436 }
1437
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001438 /**
1439 * Called by an application that is administering the device to set the length
1440 * of the password history. After setting this, the user will not be able to
1441 * enter a new password that is the same as any password in the history. Note
1442 * that the current password will remain until the user has set a new one, so
1443 * the change does not take place immediately. To prompt the user for a new
1444 * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
1445 * This constraint is only imposed if the administrator has also requested
Jim Miller85516d02014-01-31 17:08:37 -08001446 * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}
1447 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1448 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001449 *
1450 * <p>
1451 * The calling device admin must have requested
1452 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
1453 * method; if it has not, a security exception will be thrown.
1454 *
1455 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1456 * with.
1457 * @param length The new desired length of password history. A value of 0
1458 * means there is no restriction.
1459 */
Robin Lee25e26452015-06-02 09:56:29 -07001460 public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001461 if (mService != null) {
1462 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001463 mService.setPasswordHistoryLength(admin, length);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001464 } catch (RemoteException e) {
1465 Log.w(TAG, "Failed talking with device policy service", e);
1466 }
1467 }
1468 }
1469
1470 /**
Jim Millera4e28d12010-11-08 16:15:47 -08001471 * Called by a device admin to set the password expiration timeout. Calling this method
1472 * will restart the countdown for password expiration for the given admin, as will changing
1473 * the device password (for all admins).
1474 *
1475 * <p>The provided timeout is the time delta in ms and will be added to the current time.
1476 * For example, to have the password expire 5 days from now, timeout would be
1477 * 5 * 86400 * 1000 = 432000000 ms for timeout.
1478 *
1479 * <p>To disable password expiration, a value of 0 may be used for timeout.
1480 *
Jim Millera4e28d12010-11-08 16:15:47 -08001481 * <p>The calling device admin must have requested
1482 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
1483 * method; if it has not, a security exception will be thrown.
1484 *
Jessica Hummel9da60392014-05-21 12:32:57 +01001485 * <p> Note that setting the password will automatically reset the expiration time for all
1486 * active admins. Active admins do not need to explicitly call this method in that case.
1487 *
Jim Millera4e28d12010-11-08 16:15:47 -08001488 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1489 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
1490 * means there is no restriction (unlimited).
1491 */
Robin Lee25e26452015-06-02 09:56:29 -07001492 public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) {
Jim Millera4e28d12010-11-08 16:15:47 -08001493 if (mService != null) {
1494 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001495 mService.setPasswordExpirationTimeout(admin, timeout);
Jim Millera4e28d12010-11-08 16:15:47 -08001496 } catch (RemoteException e) {
1497 Log.w(TAG, "Failed talking with device policy service", e);
1498 }
1499 }
1500 }
1501
1502 /**
Jim Miller6b857682011-02-16 16:27:41 -08001503 * Get the password expiration timeout for the given admin. The expiration timeout is the
1504 * recurring expiration timeout provided in the call to
1505 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
Robin Lee25e26452015-06-02 09:56:29 -07001506 * aggregate of all policy administrators if {@code admin} is null.
Jim Millera4e28d12010-11-08 16:15:47 -08001507 *
Robin Lee25e26452015-06-02 09:56:29 -07001508 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001509 * @return The timeout for the given admin or the minimum of all timeouts
1510 */
Robin Lee25e26452015-06-02 09:56:29 -07001511 public long getPasswordExpirationTimeout(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001512 if (mService != null) {
1513 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001514 return mService.getPasswordExpirationTimeout(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001515 } catch (RemoteException e) {
1516 Log.w(TAG, "Failed talking with device policy service", e);
1517 }
1518 }
1519 return 0;
1520 }
1521
1522 /**
1523 * Get the current password expiration time for the given admin or an aggregate of
Jessica Hummel91da58d2014-04-10 17:39:43 +01001524 * all admins of this user and its profiles if admin is null. If the password is
1525 * expired, this will return the time since the password expired as a negative number.
1526 * If admin is null, then a composite of all expiration timeouts is returned
1527 * - which will be the minimum of all timeouts.
Jim Millera4e28d12010-11-08 16:15:47 -08001528 *
Robin Lee25e26452015-06-02 09:56:29 -07001529 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001530 * @return The password expiration time, in ms.
1531 */
Robin Lee25e26452015-06-02 09:56:29 -07001532 public long getPasswordExpiration(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001533 if (mService != null) {
1534 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001535 return mService.getPasswordExpiration(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001536 } catch (RemoteException e) {
1537 Log.w(TAG, "Failed talking with device policy service", e);
1538 }
1539 }
1540 return 0;
1541 }
1542
1543 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001544 * Retrieve the current password history length for all admins of this
1545 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001546 * @param admin The name of the admin component to check, or {@code null} to aggregate
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001547 * all admins.
1548 * @return The length of the password history
1549 */
Robin Lee25e26452015-06-02 09:56:29 -07001550 public int getPasswordHistoryLength(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001551 return getPasswordHistoryLength(admin, UserHandle.myUserId());
1552 }
1553
1554 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001555 public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001556 if (mService != null) {
1557 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001558 return mService.getPasswordHistoryLength(admin, userHandle);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001559 } catch (RemoteException e) {
1560 Log.w(TAG, "Failed talking with device policy service", e);
1561 }
1562 }
1563 return 0;
1564 }
1565
Dianne Hackbornd6847842010-01-12 18:14:19 -08001566 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001567 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001568 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08001569 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001570 * @return Returns the maximum length that the user can enter.
1571 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001572 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001573 // Kind-of arbitrary.
1574 return 16;
1575 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001576
Dianne Hackborn254cb442010-01-27 19:23:59 -08001577 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001578 * Determine whether the current password the user has set is sufficient
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001579 * to meet the policy requirements (quality, minimum length) that have been
Jessica Hummel91da58d2014-04-10 17:39:43 +01001580 * requested by the admins of this user and its profiles.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001581 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001582 * <p>The calling device admin must have requested
1583 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1584 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001585 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001586 * @return Returns true if the password meets the current requirements, else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001587 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001588 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001589 if (mService != null) {
1590 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001591 return mService.isActivePasswordSufficient(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001592 } catch (RemoteException e) {
1593 Log.w(TAG, "Failed talking with device policy service", e);
1594 }
1595 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001596 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001597 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001598
Dianne Hackbornd6847842010-01-12 18:14:19 -08001599 /**
1600 * Retrieve the number of times the user has failed at entering a
1601 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001602 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001603 * <p>The calling device admin must have requested
1604 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
1605 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001606 */
1607 public int getCurrentFailedPasswordAttempts() {
1608 if (mService != null) {
1609 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001610 return mService.getCurrentFailedPasswordAttempts(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001611 } catch (RemoteException e) {
1612 Log.w(TAG, "Failed talking with device policy service", e);
1613 }
1614 }
1615 return -1;
1616 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001617
1618 /**
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001619 * Queries whether {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001620 *
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001621 * @return true if RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001622 * @hide
1623 */
1624 public boolean getDoNotAskCredentialsOnBoot() {
1625 if (mService != null) {
1626 try {
1627 return mService.getDoNotAskCredentialsOnBoot();
1628 } catch (RemoteException e) {
1629 Log.w(TAG, "Failed to call getDoNotAskCredentialsOnBoot()", e);
1630 }
1631 }
1632 return false;
1633 }
1634
1635 /**
Andrew Stadler88209d12010-02-08 22:59:36 -08001636 * Setting this to a value greater than zero enables a built-in policy
1637 * that will perform a device wipe after too many incorrect
1638 * device-unlock passwords have been entered. This built-in policy combines
1639 * watching for failed passwords and wiping the device, and requires
1640 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001641 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001642 *
Andrew Stadler88209d12010-02-08 22:59:36 -08001643 * <p>To implement any other policy (e.g. wiping data for a particular
1644 * application only, erasing or revoking credentials, or reporting the
1645 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001646 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -08001647 * instead. Do not use this API, because if the maximum count is reached,
1648 * the device will be wiped immediately, and your callback will not be invoked.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001649 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001650 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001651 * @param num The number of failed password attempts at which point the
1652 * device will wipe its data.
1653 */
Robin Lee25e26452015-06-02 09:56:29 -07001654 public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001655 if (mService != null) {
1656 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001657 mService.setMaximumFailedPasswordsForWipe(admin, num);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001658 } catch (RemoteException e) {
1659 Log.w(TAG, "Failed talking with device policy service", e);
1660 }
1661 }
1662 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001663
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001664 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001665 * Retrieve the current maximum number of login attempts that are allowed
Jessica Hummel91da58d2014-04-10 17:39:43 +01001666 * before the device wipes itself, for all admins of this user and its profiles
Dianne Hackborn254cb442010-01-27 19:23:59 -08001667 * or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001668 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001669 * all admins.
1670 */
Robin Lee25e26452015-06-02 09:56:29 -07001671 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001672 return getMaximumFailedPasswordsForWipe(admin, UserHandle.myUserId());
1673 }
1674
1675 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001676 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001677 if (mService != null) {
1678 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001679 return mService.getMaximumFailedPasswordsForWipe(admin, userHandle);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001680 } catch (RemoteException e) {
1681 Log.w(TAG, "Failed talking with device policy service", e);
1682 }
1683 }
1684 return 0;
1685 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001686
Dianne Hackborn254cb442010-01-27 19:23:59 -08001687 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07001688 * Returns the profile with the smallest maximum failed passwords for wipe,
1689 * for the given user. So for primary user, it might return the primary or
1690 * a managed profile. For a secondary user, it would be the same as the
1691 * user passed in.
1692 * @hide Used only by Keyguard
1693 */
1694 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
1695 if (mService != null) {
1696 try {
1697 return mService.getProfileWithMinimumFailedPasswordsForWipe(userHandle);
1698 } catch (RemoteException e) {
1699 Log.w(TAG, "Failed talking with device policy service", e);
1700 }
1701 }
1702 return UserHandle.USER_NULL;
1703 }
1704
1705 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001706 * Flag for {@link #resetPassword}: don't allow other admins to change
1707 * the password again until the user has entered it.
1708 */
1709 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001710
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001711 /**
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001712 * Flag for {@link #resetPassword}: don't ask for user credentials on device boot.
1713 * If the flag is set, the device can be booted without asking for user password.
1714 * The absence of this flag does not change the current boot requirements. This flag
1715 * can be set by the device owner only. If the app is not the device owner, the flag
1716 * is ignored. Once the flag is set, it cannot be reverted back without resetting the
1717 * device to factory defaults.
1718 */
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001719 public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002;
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001720
1721 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001722 * Force a new device unlock password (the password needed to access the
1723 * entire device, not for individual accounts) on the user. This takes
1724 * effect immediately.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001725 * The given password must be sufficient for the
1726 * current password quality and length constraints as returned by
1727 * {@link #getPasswordQuality(ComponentName)} and
1728 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
1729 * these constraints, then it will be rejected and false returned. Note
1730 * that the password may be a stronger quality (containing alphanumeric
1731 * characters when the requested quality is only numeric), in which case
1732 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001733 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001734 * <p>Calling with a null or empty password will clear any existing PIN,
1735 * pattern or password if the current password constraints allow it.
1736 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001737 * <p>The calling device admin must have requested
1738 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
1739 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001740 *
Amith Yamasani242f4b12014-10-14 16:06:13 -07001741 * <p>Calling this from a managed profile will throw a security exception.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001742 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001743 * @param password The new password for the user. Null or empty clears the password.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001744 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001745 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001746 * @return Returns true if the password was applied, or false if it is
1747 * not acceptable for the current constraints.
1748 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001749 public boolean resetPassword(String password, int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001750 if (mService != null) {
1751 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001752 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001753 } catch (RemoteException e) {
1754 Log.w(TAG, "Failed talking with device policy service", e);
1755 }
1756 }
1757 return false;
1758 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001759
Dianne Hackbornd6847842010-01-12 18:14:19 -08001760 /**
1761 * Called by an application that is administering the device to set the
1762 * maximum time for user activity until the device will lock. This limits
1763 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001764 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001765 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -08001766 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001767 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001768 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001769 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001770 * @param timeMs The new desired maximum time to lock in milliseconds.
1771 * A value of 0 means there is no restriction.
1772 */
Robin Lee25e26452015-06-02 09:56:29 -07001773 public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001774 if (mService != null) {
1775 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001776 mService.setMaximumTimeToLock(admin, timeMs);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001777 } catch (RemoteException e) {
1778 Log.w(TAG, "Failed talking with device policy service", e);
1779 }
1780 }
1781 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001782
Dianne Hackbornd6847842010-01-12 18:14:19 -08001783 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001784 * Retrieve the current maximum time to unlock for all admins of this user
1785 * and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001786 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001787 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07001788 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07001789 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001790 */
Robin Lee25e26452015-06-02 09:56:29 -07001791 public long getMaximumTimeToLock(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001792 return getMaximumTimeToLock(admin, UserHandle.myUserId());
1793 }
1794
1795 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001796 public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001797 if (mService != null) {
1798 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001799 return mService.getMaximumTimeToLock(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001800 } catch (RemoteException e) {
1801 Log.w(TAG, "Failed talking with device policy service", e);
1802 }
1803 }
1804 return 0;
1805 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001806
Dianne Hackbornd6847842010-01-12 18:14:19 -08001807 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001808 * Make the device lock immediately, as if the lock screen timeout has
1809 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001810 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001811 * <p>The calling device admin must have requested
1812 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
1813 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001814 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001815 public void lockNow() {
1816 if (mService != null) {
1817 try {
1818 mService.lockNow();
1819 } catch (RemoteException e) {
1820 Log.w(TAG, "Failed talking with device policy service", e);
1821 }
1822 }
1823 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001824
Dianne Hackbornd6847842010-01-12 18:14:19 -08001825 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07001826 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001827 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07001828 */
1829 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
1830
1831 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001832 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
1833 * data.
1834 *
Paul Crowley2934b262014-12-02 11:21:13 +00001835 * <p>This flag may only be set by device owner admins; if it is set by
1836 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001837 */
1838 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
1839
1840 /**
Robin Lee85bd63f2015-02-10 11:51:00 +00001841 * Ask the user data be wiped. Wiping the primary user will cause the
1842 * device to reboot, erasing all user data while next booting up.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001843 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001844 * <p>The calling device admin must have requested
1845 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
1846 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001847 *
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001848 * @param flags Bit mask of additional options: currently supported flags
1849 * are {@link #WIPE_EXTERNAL_STORAGE} and
1850 * {@link #WIPE_RESET_PROTECTION_DATA}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001851 */
1852 public void wipeData(int flags) {
1853 if (mService != null) {
1854 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001855 mService.wipeData(flags, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001856 } catch (RemoteException e) {
1857 Log.w(TAG, "Failed talking with device policy service", e);
1858 }
1859 }
1860 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001861
Dianne Hackbornd6847842010-01-12 18:14:19 -08001862 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001863 * Called by an application that is administering the device to set the
1864 * global proxy and exclusion list.
1865 * <p>
1866 * The calling device admin must have requested
1867 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
1868 * this method; if it has not, a security exception will be thrown.
1869 * Only the first device admin can set the proxy. If a second admin attempts
1870 * to set the proxy, the {@link ComponentName} of the admin originally setting the
Robin Lee25e26452015-06-02 09:56:29 -07001871 * proxy will be returned. If successful in setting the proxy, {@code null} will
Oscar Montemayor69238c62010-08-03 10:51:06 -07001872 * be returned.
1873 * The method can be called repeatedly by the device admin alrady setting the
1874 * proxy to update the proxy and exclusion list.
1875 *
Robin Lee25e26452015-06-02 09:56:29 -07001876 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Oscar Montemayor69238c62010-08-03 10:51:06 -07001877 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
1878 * Pass Proxy.NO_PROXY to reset the proxy.
1879 * @param exclusionList a list of domains to be excluded from the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07001880 * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName}
1881 * of the device admin that sets the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08001882 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001883 */
Robin Lee25e26452015-06-02 09:56:29 -07001884 public ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec,
Oscar Montemayor69238c62010-08-03 10:51:06 -07001885 List<String> exclusionList ) {
1886 if (proxySpec == null) {
1887 throw new NullPointerException();
1888 }
1889 if (mService != null) {
1890 try {
1891 String hostSpec;
1892 String exclSpec;
1893 if (proxySpec.equals(Proxy.NO_PROXY)) {
1894 hostSpec = null;
1895 exclSpec = null;
1896 } else {
1897 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
1898 throw new IllegalArgumentException();
1899 }
1900 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
1901 String hostName = sa.getHostName();
1902 int port = sa.getPort();
1903 StringBuilder hostBuilder = new StringBuilder();
1904 hostSpec = hostBuilder.append(hostName)
1905 .append(":").append(Integer.toString(port)).toString();
1906 if (exclusionList == null) {
1907 exclSpec = "";
1908 } else {
1909 StringBuilder listBuilder = new StringBuilder();
1910 boolean firstDomain = true;
1911 for (String exclDomain : exclusionList) {
1912 if (!firstDomain) {
1913 listBuilder = listBuilder.append(",");
1914 } else {
1915 firstDomain = false;
1916 }
1917 listBuilder = listBuilder.append(exclDomain.trim());
1918 }
1919 exclSpec = listBuilder.toString();
1920 }
Yuhao Zheng90704842014-02-28 17:22:45 -08001921 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
1922 != android.net.Proxy.PROXY_VALID)
1923 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07001924 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001925 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07001926 } catch (RemoteException e) {
1927 Log.w(TAG, "Failed talking with device policy service", e);
1928 }
1929 }
1930 return null;
1931 }
1932
1933 /**
Jason Monk03bc9912014-05-13 09:44:57 -04001934 * Set a network-independent global HTTP proxy. This is not normally what you want
1935 * for typical HTTP proxies - they are generally network dependent. However if you're
1936 * doing something unusual like general internal filtering this may be useful. On
1937 * a private network where the proxy is not accessible, you may break HTTP using this.
1938 *
1939 * <p>This method requires the caller to be the device owner.
1940 *
1941 * <p>This proxy is only a recommendation and it is possible that some apps will ignore it.
1942 * @see ProxyInfo
1943 *
1944 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1945 * with.
1946 * @param proxyInfo The a {@link ProxyInfo} object defining the new global
1947 * HTTP proxy. A {@code null} value will clear the global HTTP proxy.
1948 */
Robin Lee25e26452015-06-02 09:56:29 -07001949 public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo
1950 proxyInfo) {
Jason Monk03bc9912014-05-13 09:44:57 -04001951 if (mService != null) {
1952 try {
1953 mService.setRecommendedGlobalProxy(admin, proxyInfo);
1954 } catch (RemoteException e) {
1955 Log.w(TAG, "Failed talking with device policy service", e);
1956 }
1957 }
1958 }
1959
1960 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001961 * Returns the component name setting the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07001962 * @return ComponentName object of the device admin that set the global proxy, or {@code null}
1963 * if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08001964 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001965 */
1966 public ComponentName getGlobalProxyAdmin() {
1967 if (mService != null) {
1968 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001969 return mService.getGlobalProxyAdmin(UserHandle.myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07001970 } catch (RemoteException e) {
1971 Log.w(TAG, "Failed talking with device policy service", e);
1972 }
1973 }
1974 return null;
1975 }
1976
1977 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001978 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001979 * indicating that encryption is not supported.
1980 */
1981 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
1982
1983 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001984 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001985 * indicating that encryption is supported, but is not currently active.
1986 */
1987 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
1988
1989 /**
Robin Lee3795fb02015-02-16 14:17:23 +00001990 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001991 * indicating that encryption is not currently active, but is currently
1992 * being activated. This is only reported by devices that support
1993 * encryption of data and only when the storage is currently
1994 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
1995 * to become encrypted will never return this value.
1996 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001997 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001998
1999 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002000 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002001 * indicating that encryption is active.
2002 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002003 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002004
2005 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002006 * Result code for {@link #getStorageEncryptionStatus}:
2007 * indicating that encryption is active, but an encryption key has not
2008 * been set by the user.
2009 */
2010 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
2011
2012 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002013 * Activity action: begin the process of encrypting data on the device. This activity should
2014 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
2015 * After resuming from this activity, use {@link #getStorageEncryption}
2016 * to check encryption status. However, on some devices this activity may never return, as
2017 * it may trigger a reboot and in some cases a complete data wipe of the device.
2018 */
2019 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
2020 public static final String ACTION_START_ENCRYPTION
2021 = "android.app.action.START_ENCRYPTION";
2022
2023 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07002024 * Widgets are enabled in keyguard
2025 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002026 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07002027
2028 /**
Jim Miller50e62182014-04-23 17:25:00 -07002029 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07002030 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002031 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
2032
2033 /**
2034 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
2035 */
2036 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
2037
2038 /**
Jim Miller50e62182014-04-23 17:25:00 -07002039 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2040 */
2041 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
2042
2043 /**
2044 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2045 */
2046 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
2047
2048 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02002049 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07002050 * (e.g. PIN/Pattern/Password).
2051 */
2052 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
2053
2054 /**
Jim Miller06e34502014-07-17 14:46:05 -07002055 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
2056 */
2057 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
2058
2059 /**
Jim Miller35207742012-11-02 15:33:20 -07002060 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07002061 */
2062 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07002063
2064 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002065 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002066 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002067 *
2068 * <p>When multiple device administrators attempt to control device
2069 * encryption, the most secure, supported setting will always be
2070 * used. If any device administrator requests device encryption,
2071 * it will be enabled; Conversely, if a device administrator
2072 * attempts to disable device encryption while another
2073 * device administrator has enabled it, the call to disable will
2074 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
2075 *
2076 * <p>This policy controls encryption of the secure (application data) storage area. Data
Andy Stadler50c294f2011-03-07 19:13:42 -08002077 * written to other storage areas may or may not be encrypted, and this policy does not require
2078 * or control the encryption of any other storage areas.
2079 * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is
2080 * {@code true}, then the directory returned by
2081 * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk
2082 * within the encrypted storage area.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002083 *
2084 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
2085 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
2086 * the encryption key may not be fully secured. For maximum security, the administrator should
2087 * also require (and check for) a pattern, PIN, or password.
2088 *
2089 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2090 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08002091 * @return the new request status (for all active admins) - will be one of
2092 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
2093 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
2094 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002095 */
Robin Lee25e26452015-06-02 09:56:29 -07002096 public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002097 if (mService != null) {
2098 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002099 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002100 } catch (RemoteException e) {
2101 Log.w(TAG, "Failed talking with device policy service", e);
2102 }
2103 }
2104 return ENCRYPTION_STATUS_UNSUPPORTED;
2105 }
2106
2107 /**
2108 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002109 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002110 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08002111 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
2112 * this will return the requested encryption setting as an aggregate of all active
2113 * administrators.
2114 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002115 */
Robin Lee25e26452015-06-02 09:56:29 -07002116 public boolean getStorageEncryption(@Nullable ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002117 if (mService != null) {
2118 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002119 return mService.getStorageEncryption(admin, UserHandle.myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002120 } catch (RemoteException e) {
2121 Log.w(TAG, "Failed talking with device policy service", e);
2122 }
2123 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08002124 return false;
2125 }
2126
2127 /**
2128 * Called by an application that is administering the device to
2129 * determine the current encryption status of the device.
2130 *
2131 * Depending on the returned status code, the caller may proceed in different
2132 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
2133 * storage system does not support encryption. If the
2134 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
2135 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00002136 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
2137 * storage system has enabled encryption but no password is set so further action
2138 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
Andy Stadler22dbfda2011-01-17 12:47:31 -08002139 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
2140 *
Robin Lee7e678712014-07-24 16:41:31 +01002141 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08002142 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00002143 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
2144 * or {@link #ENCRYPTION_STATUS_ACTIVE}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08002145 */
2146 public int getStorageEncryptionStatus() {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002147 return getStorageEncryptionStatus(UserHandle.myUserId());
2148 }
2149
2150 /** @hide per-user version */
2151 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08002152 if (mService != null) {
2153 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002154 return mService.getStorageEncryptionStatus(userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08002155 } catch (RemoteException e) {
2156 Log.w(TAG, "Failed talking with device policy service", e);
2157 }
2158 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002159 return ENCRYPTION_STATUS_UNSUPPORTED;
2160 }
2161
2162 /**
Robin Lee7e678712014-07-24 16:41:31 +01002163 * Installs the given certificate as a user CA.
2164 *
Robin Lee25e26452015-06-02 09:56:29 -07002165 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2166 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002167 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04002168 *
2169 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01002170 * interrupted, true otherwise.
Maggie Benthallda51e682013-08-08 22:35:44 -04002171 */
Robin Lee25e26452015-06-02 09:56:29 -07002172 public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002173 if (mService != null) {
2174 try {
Robin Lee7e678712014-07-24 16:41:31 +01002175 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04002176 } catch (RemoteException e) {
2177 Log.w(TAG, "Failed talking with device policy service", e);
2178 }
2179 }
2180 return false;
2181 }
2182
2183 /**
Robin Lee7e678712014-07-24 16:41:31 +01002184 * Uninstalls the given certificate from trusted user CAs, if present.
2185 *
Robin Lee25e26452015-06-02 09:56:29 -07002186 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2187 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002188 * @param certBuffer encoded form of the certificate to remove.
Maggie Benthallda51e682013-08-08 22:35:44 -04002189 */
Robin Lee25e26452015-06-02 09:56:29 -07002190 public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002191 if (mService != null) {
2192 try {
Robin Lee306fe082014-06-19 14:04:24 +00002193 final String alias = getCaCertAlias(certBuffer);
Robin Lee83881bd2015-06-09 16:04:38 -07002194 mService.uninstallCaCerts(admin, new String[] {alias});
Robin Lee306fe082014-06-19 14:04:24 +00002195 } catch (CertificateException e) {
2196 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002197 } catch (RemoteException e) {
2198 Log.w(TAG, "Failed talking with device policy service", e);
2199 }
2200 }
2201 }
2202
2203 /**
Robin Lee7e678712014-07-24 16:41:31 +01002204 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
2205 * If a user has installed any certificates by other means than device policy these will be
2206 * included too.
2207 *
Robin Lee25e26452015-06-02 09:56:29 -07002208 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2209 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002210 * @return a List of byte[] arrays, each encoding one user CA certificate.
Maggie Benthallda51e682013-08-08 22:35:44 -04002211 */
Robin Lee25e26452015-06-02 09:56:29 -07002212 public List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002213 List<byte[]> certs = new ArrayList<byte[]>();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002214 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01002215 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002216 mService.enforceCanManageCaCerts(admin);
2217 final TrustedCertificateStore certStore = new TrustedCertificateStore();
2218 for (String alias : certStore.userAliases()) {
2219 try {
2220 certs.add(certStore.getCertificate(alias).getEncoded());
2221 } catch (CertificateException ce) {
2222 Log.w(TAG, "Could not encode certificate: " + alias, ce);
2223 }
2224 }
2225 } catch (RemoteException re) {
2226 Log.w(TAG, "Failed talking with device policy service", re);
Robin Lee7e678712014-07-24 16:41:31 +01002227 }
2228 }
2229 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04002230 }
2231
2232 /**
Robin Lee7e678712014-07-24 16:41:31 +01002233 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
2234 * means other than device policy will also be removed, except for system CA certificates.
2235 *
Robin Lee25e26452015-06-02 09:56:29 -07002236 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2237 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002238 */
Robin Lee25e26452015-06-02 09:56:29 -07002239 public void uninstallAllUserCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002240 if (mService != null) {
Robin Lee83881bd2015-06-09 16:04:38 -07002241 try {
2242 mService.uninstallCaCerts(admin, new TrustedCertificateStore().userAliases()
2243 .toArray(new String[0]));
2244 } catch (RemoteException re) {
2245 Log.w(TAG, "Failed talking with device policy service", re);
Robin Lee7e678712014-07-24 16:41:31 +01002246 }
2247 }
2248 }
2249
2250 /**
2251 * Returns whether this certificate is installed as a trusted CA.
2252 *
Robin Lee25e26452015-06-02 09:56:29 -07002253 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2254 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002255 * @param certBuffer encoded form of the certificate to look up.
Maggie Benthallda51e682013-08-08 22:35:44 -04002256 */
Robin Lee25e26452015-06-02 09:56:29 -07002257 public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002258 if (mService != null) {
2259 try {
2260 mService.enforceCanManageCaCerts(admin);
2261 return getCaCertAlias(certBuffer) != null;
2262 } catch (RemoteException re) {
2263 Log.w(TAG, "Failed talking with device policy service", re);
2264 } catch (CertificateException ce) {
2265 Log.w(TAG, "Could not parse certificate", ce);
2266 }
Maggie Benthallda51e682013-08-08 22:35:44 -04002267 }
2268 return false;
2269 }
2270
2271 /**
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002272 * Called by a device or profile owner to install a certificate and private key pair. The
2273 * keypair will be visible to all apps within the profile.
2274 *
Robin Lee25e26452015-06-02 09:56:29 -07002275 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2276 * {@code null} if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002277 * @param privKey The private key to install.
2278 * @param cert The certificate to install.
2279 * @param alias The private key alias under which to install the certificate. If a certificate
2280 * with that alias already exists, it will be overwritten.
2281 * @return {@code true} if the keys were installed, {@code false} otherwise.
2282 */
Robin Lee25e26452015-06-02 09:56:29 -07002283 public boolean installKeyPair(@Nullable ComponentName admin, PrivateKey privKey, Certificate cert,
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002284 String alias) {
2285 try {
2286 final byte[] pemCert = Credentials.convertToPem(cert);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002287 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
2288 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
Robin Lee25e26452015-06-02 09:56:29 -07002289 return mService.installKeyPair(admin, pkcs8Key, pemCert, alias);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002290 } catch (RemoteException e) {
2291 Log.w(TAG, "Failed talking with device policy service", e);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002292 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
2293 Log.w(TAG, "Failed to obtain private key material", e);
2294 } catch (CertificateException | IOException e) {
2295 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002296 }
2297 return false;
2298 }
2299
2300 /**
Robin Lee25e26452015-06-02 09:56:29 -07002301 * @return the alias of a given CA certificate in the certificate store, or {@code null} if it
Robin Lee306fe082014-06-19 14:04:24 +00002302 * doesn't exist.
2303 */
2304 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
2305 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
2306 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
2307 new ByteArrayInputStream(certBuffer));
2308 return new TrustedCertificateStore().getCertificateAlias(cert);
2309 }
2310
2311 /**
Rubin Xuec32b562015-03-03 17:34:05 +00002312 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01002313 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00002314 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01002315 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00002316 * <p>
2317 * Delegated certificate installer is a per-user state. The delegated access is persistent until
2318 * it is later cleared by calling this method with a null value or uninstallling the certificate
2319 * installer.
2320 *
Robin Lee25e26452015-06-02 09:56:29 -07002321 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xuec32b562015-03-03 17:34:05 +00002322 * @param installerPackage The package name of the certificate installer which will be given
Robin Lee25e26452015-06-02 09:56:29 -07002323 * access. If {@code null} is given the current package will be cleared.
Rubin Xuec32b562015-03-03 17:34:05 +00002324 */
Robin Lee25e26452015-06-02 09:56:29 -07002325 public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String
2326 installerPackage) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002327 if (mService != null) {
2328 try {
Robin Lee25e26452015-06-02 09:56:29 -07002329 mService.setCertInstallerPackage(admin, installerPackage);
Rubin Xuec32b562015-03-03 17:34:05 +00002330 } catch (RemoteException e) {
2331 Log.w(TAG, "Failed talking with device policy service", e);
2332 }
2333 }
2334 }
2335
2336 /**
2337 * Called by a profile owner or device owner to retrieve the certificate installer for the
2338 * current user. null if none is set.
2339 *
Robin Lee25e26452015-06-02 09:56:29 -07002340 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2341 * @return The package name of the current delegated certificate installer, or {@code null}
Rubin Xuec32b562015-03-03 17:34:05 +00002342 * if none is set.
2343 */
Robin Lee25e26452015-06-02 09:56:29 -07002344 public String getCertInstallerPackage(@NonNull ComponentName admin) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002345 if (mService != null) {
2346 try {
Robin Lee25e26452015-06-02 09:56:29 -07002347 return mService.getCertInstallerPackage(admin);
Rubin Xuec32b562015-03-03 17:34:05 +00002348 } catch (RemoteException e) {
2349 Log.w(TAG, "Failed talking with device policy service", e);
2350 }
2351 }
2352 return null;
2353 }
2354
2355 /**
Ben Komalo2447edd2011-05-09 16:05:33 -07002356 * Called by an application that is administering the device to disable all cameras
Amith Yamasani242f4b12014-10-14 16:06:13 -07002357 * on the device, for this user. After setting this, no applications running as this user
2358 * will be able to access any cameras on the device.
Ben Komalo2447edd2011-05-09 16:05:33 -07002359 *
2360 * <p>The calling device admin must have requested
2361 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
2362 * this method; if it has not, a security exception will be thrown.
2363 *
2364 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2365 * @param disabled Whether or not the camera should be disabled.
2366 */
Robin Lee25e26452015-06-02 09:56:29 -07002367 public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002368 if (mService != null) {
2369 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002370 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07002371 } catch (RemoteException e) {
2372 Log.w(TAG, "Failed talking with device policy service", e);
2373 }
2374 }
2375 }
2376
2377 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07002378 * Determine whether or not the device's cameras have been disabled for this user,
2379 * either by the current admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002380 * @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 -07002381 * have disabled the camera
2382 */
Robin Lee25e26452015-06-02 09:56:29 -07002383 public boolean getCameraDisabled(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002384 return getCameraDisabled(admin, UserHandle.myUserId());
2385 }
2386
2387 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002388 public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002389 if (mService != null) {
2390 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002391 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07002392 } catch (RemoteException e) {
2393 Log.w(TAG, "Failed talking with device policy service", e);
2394 }
2395 }
2396 return false;
2397 }
2398
2399 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01002400 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
2401 * screen capture also prevents the content from being shown on display devices that do not have
2402 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
2403 * secure surfaces and secure displays.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002404 *
2405 * <p>The calling device admin must be a device or profile owner. If it is not, a
2406 * security exception will be thrown.
2407 *
2408 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002409 * @param disabled Whether screen capture is disabled or not.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002410 */
Robin Lee25e26452015-06-02 09:56:29 -07002411 public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002412 if (mService != null) {
2413 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002414 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002415 } catch (RemoteException e) {
2416 Log.w(TAG, "Failed talking with device policy service", e);
2417 }
2418 }
2419 }
2420
2421 /**
2422 * Determine whether or not screen capture has been disabled by the current
2423 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002424 * @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 +01002425 * have disabled screen capture.
2426 */
Robin Lee25e26452015-06-02 09:56:29 -07002427 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002428 return getScreenCaptureDisabled(admin, UserHandle.myUserId());
2429 }
2430
2431 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002432 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002433 if (mService != null) {
2434 try {
2435 return mService.getScreenCaptureDisabled(admin, userHandle);
2436 } catch (RemoteException e) {
2437 Log.w(TAG, "Failed talking with device policy service", e);
2438 }
2439 }
2440 return false;
2441 }
2442
2443 /**
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002444 * Called by a device owner to set whether auto time is required. If auto time is
2445 * required the user cannot set the date and time, but has to use network date and time.
2446 *
2447 * <p>Note: if auto time is required the user can still manually set the time zone.
2448 *
2449 * <p>The calling device admin must be a device owner. If it is not, a security exception will
2450 * be thrown.
2451 *
2452 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2453 * @param required Whether auto time is set required or not.
2454 */
Robin Lee25e26452015-06-02 09:56:29 -07002455 public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) {
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002456 if (mService != null) {
2457 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002458 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002459 } catch (RemoteException e) {
2460 Log.w(TAG, "Failed talking with device policy service", e);
2461 }
2462 }
2463 }
2464
2465 /**
2466 * @return true if auto time is required.
2467 */
2468 public boolean getAutoTimeRequired() {
2469 if (mService != null) {
2470 try {
2471 return mService.getAutoTimeRequired();
2472 } catch (RemoteException e) {
2473 Log.w(TAG, "Failed talking with device policy service", e);
2474 }
2475 }
2476 return false;
2477 }
2478
2479 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002480 * Called by an application that is administering the device to disable keyguard customizations,
2481 * such as widgets. After setting this, keyguard features will be disabled according to the
2482 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002483 *
2484 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07002485 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07002486 * this method; if it has not, a security exception will be thrown.
2487 *
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002488 * <p>Calling this from a managed profile before version
2489 * {@link android.os.Build.VERSION_CODES#MNC} will throw a security exception.
2490 *
2491 * <p>From version {@link android.os.Build.VERSION_CODES#MNC} a profile owner can set:
2492 * <ul>
2493 * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, {@link #KEYGUARD_DISABLE_FINGERPRINT}
2494 * these will affect the profile's parent user.
2495 * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} this will affect notifications
2496 * generated by applications in the managed profile.
2497 * </ul>
2498 * <p>Requests to disable other features on a managed profile will be ignored. The admin
2499 * can check which features have been disabled by calling
2500 * {@link #getKeyguardDisabledFeatures(ComponentName)}
Amith Yamasani242f4b12014-10-14 16:06:13 -07002501 *
Jim Millerb8ec4702012-08-31 17:19:10 -07002502 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07002503 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
2504 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
Jim Miller50e62182014-04-23 17:25:00 -07002505 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002506 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FINGERPRINT},
2507 * {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07002508 */
Robin Lee25e26452015-06-02 09:56:29 -07002509 public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002510 if (mService != null) {
2511 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002512 mService.setKeyguardDisabledFeatures(admin, which);
Jim Millerb8ec4702012-08-31 17:19:10 -07002513 } catch (RemoteException e) {
2514 Log.w(TAG, "Failed talking with device policy service", e);
2515 }
2516 }
2517 }
2518
2519 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002520 * Determine whether or not features have been disabled in keyguard either by the current
Jim Millerb8ec4702012-08-31 17:19:10 -07002521 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002522 * @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 -07002523 * have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07002524 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
2525 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002526 */
Robin Lee25e26452015-06-02 09:56:29 -07002527 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) {
Jim Miller48b9b0d2012-09-19 23:16:50 -07002528 return getKeyguardDisabledFeatures(admin, UserHandle.myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002529 }
2530
2531 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002532 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002533 if (mService != null) {
2534 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07002535 return mService.getKeyguardDisabledFeatures(admin, userHandle);
Jim Millerb8ec4702012-08-31 17:19:10 -07002536 } catch (RemoteException e) {
2537 Log.w(TAG, "Failed talking with device policy service", e);
2538 }
2539 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07002540 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07002541 }
2542
2543 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08002544 * @hide
2545 */
Robin Lee25e26452015-06-02 09:56:29 -07002546 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
2547 int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002548 if (mService != null) {
2549 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01002550 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002551 } catch (RemoteException e) {
2552 Log.w(TAG, "Failed talking with device policy service", e);
2553 }
2554 }
2555 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002556
Dianne Hackbornd6847842010-01-12 18:14:19 -08002557 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01002558 * @hide
2559 */
Robin Lee25e26452015-06-02 09:56:29 -07002560 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
Jessica Hummel6d36b602014-04-04 12:42:17 +01002561 setActiveAdmin(policyReceiver, refreshing, UserHandle.myUserId());
2562 }
2563
2564 /**
Robin Lee25e26452015-06-02 09:56:29 -07002565 * Returns the DeviceAdminInfo as defined by the administrator's package info &amp; meta-data
Dianne Hackbornd6847842010-01-12 18:14:19 -08002566 * @hide
2567 */
Robin Lee25e26452015-06-02 09:56:29 -07002568 public DeviceAdminInfo getAdminInfo(@NonNull ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002569 ActivityInfo ai;
2570 try {
2571 ai = mContext.getPackageManager().getReceiverInfo(cn,
2572 PackageManager.GET_META_DATA);
2573 } catch (PackageManager.NameNotFoundException e) {
2574 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
2575 return null;
2576 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002577
Dianne Hackbornd6847842010-01-12 18:14:19 -08002578 ResolveInfo ri = new ResolveInfo();
2579 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002580
Dianne Hackbornd6847842010-01-12 18:14:19 -08002581 try {
2582 return new DeviceAdminInfo(mContext, ri);
2583 } catch (XmlPullParserException e) {
2584 Log.w(TAG, "Unable to parse device policy " + cn, e);
2585 return null;
2586 } catch (IOException e) {
2587 Log.w(TAG, "Unable to parse device policy " + cn, e);
2588 return null;
2589 }
2590 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002591
Dianne Hackbornd6847842010-01-12 18:14:19 -08002592 /**
2593 * @hide
2594 */
Robin Lee25e26452015-06-02 09:56:29 -07002595 public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002596 if (mService != null) {
2597 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002598 mService.getRemoveWarning(admin, result, UserHandle.myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002599 } catch (RemoteException e) {
2600 Log.w(TAG, "Failed talking with device policy service", e);
2601 }
2602 }
2603 }
2604
2605 /**
2606 * @hide
2607 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002608 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002609 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002610 if (mService != null) {
2611 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002612 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002613 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002614 } catch (RemoteException e) {
2615 Log.w(TAG, "Failed talking with device policy service", e);
2616 }
2617 }
2618 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002619
Dianne Hackbornd6847842010-01-12 18:14:19 -08002620 /**
2621 * @hide
2622 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002623 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002624 if (mService != null) {
2625 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002626 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002627 } catch (RemoteException e) {
2628 Log.w(TAG, "Failed talking with device policy service", e);
2629 }
2630 }
2631 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002632
Dianne Hackbornd6847842010-01-12 18:14:19 -08002633 /**
2634 * @hide
2635 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002636 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002637 if (mService != null) {
2638 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002639 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002640 } catch (RemoteException e) {
2641 Log.w(TAG, "Failed talking with device policy service", e);
2642 }
2643 }
2644 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07002645
2646 /**
2647 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00002648 * Sets the given package as the device owner.
2649 * Same as {@link #setDeviceOwner(String, String)} but without setting a device owner name.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002650 * @param packageName the package name of the application to be registered as the device owner.
2651 * @return whether the package was successfully registered as the device owner.
2652 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00002653 * @throws IllegalStateException If the preconditions mentioned are not met.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002654 */
2655 public boolean setDeviceOwner(String packageName) throws IllegalArgumentException,
2656 IllegalStateException {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002657 return setDeviceOwner(packageName, null);
2658 }
2659
2660 /**
2661 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00002662 * Sets the given package as the device owner. The package must already be installed. There
2663 * must not already be a device owner.
2664 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
2665 * this method.
2666 * Calling this after the setup phase of the primary user has completed is allowed only if
2667 * the caller is the shell uid, and there are no additional users and no accounts.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002668 * @param packageName the package name of the application to be registered as the device owner.
2669 * @param ownerName the human readable name of the institution that owns this device.
2670 * @return whether the package was successfully registered as the device owner.
2671 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00002672 * @throws IllegalStateException If the preconditions mentioned are not met.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002673 */
2674 public boolean setDeviceOwner(String packageName, String ownerName)
2675 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002676 if (mService != null) {
2677 try {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002678 return mService.setDeviceOwner(packageName, ownerName);
Amith Yamasani71e6c692013-03-24 17:39:28 -07002679 } catch (RemoteException re) {
2680 Log.w(TAG, "Failed to set device owner");
2681 }
2682 }
2683 return false;
2684 }
2685
2686 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002687 * Used to determine if a particular package has been registered as a Device Owner app.
2688 * A device owner app is a special device admin that cannot be deactivated by the user, once
Robin Lee25e26452015-06-02 09:56:29 -07002689 * activated as a device admin. It also cannot be uninstalled. To check whether a particular
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002690 * package is currently registered as the device owner app, pass in the package name from
2691 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
Robin Lee25e26452015-06-02 09:56:29 -07002692 * admin apps that want to check whether they are also registered as the device owner app. The
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002693 * exact mechanism by which a device admin app is registered as a device owner app is defined by
2694 * the setup process.
2695 * @param packageName the package name of the app, to compare with the registered device owner
2696 * app, if any.
2697 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002698 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002699 public boolean isDeviceOwnerApp(String packageName) {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002700 if (mService != null) {
2701 try {
2702 return mService.isDeviceOwner(packageName);
2703 } catch (RemoteException re) {
2704 Log.w(TAG, "Failed to check device owner");
2705 }
2706 }
2707 return false;
2708 }
2709
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002710 /**
2711 * @hide
2712 * Redirect to isDeviceOwnerApp.
2713 */
2714 public boolean isDeviceOwner(String packageName) {
2715 return isDeviceOwnerApp(packageName);
2716 }
2717
Jason Monkb0dced82014-06-06 14:36:20 -04002718 /**
2719 * Clears the current device owner. The caller must be the device owner.
2720 *
2721 * This function should be used cautiously as once it is called it cannot
2722 * be undone. The device owner can only be set as a part of device setup
2723 * before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04002724 *
2725 * @param packageName The package name of the device owner.
Jason Monkb0dced82014-06-06 14:36:20 -04002726 */
Jason Monk94d2cf92014-06-18 09:53:34 -04002727 public void clearDeviceOwnerApp(String packageName) {
Jason Monkb0dced82014-06-06 14:36:20 -04002728 if (mService != null) {
2729 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04002730 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04002731 } catch (RemoteException re) {
2732 Log.w(TAG, "Failed to clear device owner");
2733 }
2734 }
2735 }
2736
Amith Yamasani71e6c692013-03-24 17:39:28 -07002737 /** @hide */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002738 @SystemApi
Amith Yamasani71e6c692013-03-24 17:39:28 -07002739 public String getDeviceOwner() {
2740 if (mService != null) {
2741 try {
2742 return mService.getDeviceOwner();
2743 } catch (RemoteException re) {
2744 Log.w(TAG, "Failed to get device owner");
2745 }
2746 }
2747 return null;
2748 }
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002749
2750 /** @hide */
2751 public String getDeviceOwnerName() {
2752 if (mService != null) {
2753 try {
2754 return mService.getDeviceOwnerName();
2755 } catch (RemoteException re) {
2756 Log.w(TAG, "Failed to get device owner");
2757 }
2758 }
2759 return null;
2760 }
Adam Connors776c5552014-01-09 10:42:56 +00002761
2762 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04002763 * @hide
Julia Reynolds20118f12015-02-11 12:34:08 -05002764 * Sets the given component as the device initializer. The package must already be installed and
2765 * set as an active device administrator, and there must not be an existing device initializer,
2766 * for this call to succeed. This method can only be called by an app holding the
2767 * MANAGE_DEVICE_ADMINS permission before the device is provisioned or by a device owner app. A
2768 * device initializer app is granted device owner privileges during device initialization and
2769 * profile owner privileges during secondary user initialization.
Robin Lee25e26452015-06-02 09:56:29 -07002770 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2771 * {@code null} if not called by the device owner.
Julia Reynolds20118f12015-02-11 12:34:08 -05002772 * @param initializer Which {@link DeviceAdminReceiver} to make device initializer.
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002773 * @return whether the component was successfully registered as the device initializer.
2774 * @throws IllegalArgumentException if the componentname is null or invalid
Julia Reynolds20118f12015-02-11 12:34:08 -05002775 * @throws IllegalStateException if the caller is not device owner or the device has
2776 * already been provisioned or a device initializer already exists.
2777 */
Robin Lee25e26452015-06-02 09:56:29 -07002778 public boolean setDeviceInitializer(@Nullable ComponentName admin,
2779 @NonNull ComponentName initializer)
Julia Reynolds731051e2015-05-11 15:52:08 -04002780 throws IllegalArgumentException, IllegalStateException {
Julia Reynolds20118f12015-02-11 12:34:08 -05002781 if (mService != null) {
2782 try {
Robin Lee25e26452015-06-02 09:56:29 -07002783 return mService.setDeviceInitializer(admin, initializer);
Julia Reynolds20118f12015-02-11 12:34:08 -05002784 } catch (RemoteException re) {
2785 Log.w(TAG, "Failed to set device initializer");
2786 }
2787 }
2788 return false;
2789 }
2790
2791 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04002792 * @hide
Julia Reynolds20118f12015-02-11 12:34:08 -05002793 * Used to determine if a particular package has been registered as the device initializer.
2794 *
2795 * @param packageName the package name of the app, to compare with the registered device
2796 * initializer app, if any.
2797 * @return whether or not the caller is registered as the device initializer app.
2798 */
2799 public boolean isDeviceInitializerApp(String packageName) {
2800 if (mService != null) {
2801 try {
2802 return mService.isDeviceInitializer(packageName);
2803 } catch (RemoteException re) {
2804 Log.w(TAG, "Failed to check device initializer");
2805 }
2806 }
2807 return false;
2808 }
2809
2810 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04002811 * @hide
Julia Reynoldse9254402015-02-11 12:34:08 -05002812 * Removes the device initializer, so that it will not be invoked on user initialization for any
2813 * subsequently created users. This method can be called by either the device owner or device
Julia Reynolds1c3754a2015-03-05 10:06:41 -05002814 * initializer itself. The caller must be an active administrator.
2815 *
Robin Lee25e26452015-06-02 09:56:29 -07002816 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Julia Reynolds20118f12015-02-11 12:34:08 -05002817 */
Robin Lee25e26452015-06-02 09:56:29 -07002818 public void clearDeviceInitializerApp(@NonNull ComponentName admin) {
Julia Reynolds20118f12015-02-11 12:34:08 -05002819 if (mService != null) {
2820 try {
Robin Lee25e26452015-06-02 09:56:29 -07002821 mService.clearDeviceInitializer(admin);
Julia Reynolds20118f12015-02-11 12:34:08 -05002822 } catch (RemoteException re) {
2823 Log.w(TAG, "Failed to clear device initializer");
2824 }
2825 }
2826 }
2827
2828 /**
2829 * @hide
2830 * Gets the device initializer of the system.
2831 *
2832 * @return the package name of the device initializer.
2833 */
2834 @SystemApi
2835 public String getDeviceInitializerApp() {
2836 if (mService != null) {
2837 try {
2838 return mService.getDeviceInitializer();
2839 } catch (RemoteException re) {
2840 Log.w(TAG, "Failed to get device initializer");
2841 }
2842 }
2843 return null;
2844 }
2845
2846 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002847 * @hide
2848 * Gets the device initializer component of the system.
2849 *
2850 * @return the component name of the device initializer.
2851 */
2852 @SystemApi
2853 public ComponentName getDeviceInitializerComponent() {
2854 if (mService != null) {
2855 try {
2856 return mService.getDeviceInitializerComponent();
2857 } catch (RemoteException re) {
2858 Log.w(TAG, "Failed to get device initializer");
2859 }
2860 }
2861 return null;
2862 }
2863
2864
2865 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04002866 * @hide
Julia Reynolds20118f12015-02-11 12:34:08 -05002867 * Sets the enabled state of the user. A user should be enabled only once it is ready to
2868 * be used.
2869 *
2870 * <p>Device initializer must call this method to mark the user as functional.
2871 * Only the device initializer agent can call this.
2872 *
2873 * <p>When the user is enabled, if the device initializer is not also the device owner, the
2874 * device initializer will no longer have elevated permissions to call methods in this class.
2875 * Additionally, it will be removed as an active administrator and its
2876 * {@link DeviceAdminReceiver} will be disabled.
2877 *
2878 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2879 * @return whether the user is now enabled.
2880 */
Robin Lee25e26452015-06-02 09:56:29 -07002881 public boolean setUserEnabled(@NonNull ComponentName admin) {
Julia Reynolds20118f12015-02-11 12:34:08 -05002882 if (mService != null) {
2883 try {
2884 return mService.setUserEnabled(admin);
2885 } catch (RemoteException e) {
2886 Log.w(TAG, "Failed talking with device policy service", e);
2887 }
2888 }
2889 return false;
2890 }
2891
2892 /**
Adam Connors776c5552014-01-09 10:42:56 +00002893 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002894 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302895 * Sets the given component as an active admin and registers the package as the profile
2896 * owner for this user. The package must already be installed and there shouldn't be
2897 * an existing profile owner registered for this user. Also, this method must be called
2898 * before the user setup has been completed.
2899 * <p>
2900 * This method can only be called by system apps that hold MANAGE_USERS permission and
2901 * MANAGE_DEVICE_ADMINS permission.
2902 * @param admin The component to register as an active admin and profile owner.
2903 * @param ownerName The user-visible name of the entity that is managing this user.
2904 * @return whether the admin was successfully registered as the profile owner.
2905 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
2906 * the user has already been set up.
2907 */
Justin Morey80440cc2014-07-24 09:16:35 -05002908 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07002909 public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302910 throws IllegalArgumentException {
2911 if (mService != null) {
2912 try {
2913 final int myUserId = UserHandle.myUserId();
2914 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002915 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302916 } catch (RemoteException re) {
2917 Log.w(TAG, "Failed to set profile owner " + re);
2918 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2919 }
2920 }
2921 return false;
2922 }
2923
2924 /**
2925 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002926 * Clears the active profile owner and removes all user restrictions. The caller must
2927 * be from the same package as the active profile owner for this user, otherwise a
2928 * SecurityException will be thrown.
2929 *
2930 * @param admin The component to remove as the profile owner.
2931 * @return
2932 */
2933 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07002934 public void clearProfileOwner(@NonNull ComponentName admin) {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002935 if (mService != null) {
2936 try {
2937 mService.clearProfileOwner(admin);
2938 } catch (RemoteException re) {
2939 Log.w(TAG, "Failed to clear profile owner " + admin + re);
2940 }
2941 }
2942 }
2943
2944 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05002945 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07002946 * Checks whether the user was already setup.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002947 */
2948 public boolean hasUserSetupCompleted() {
2949 if (mService != null) {
2950 try {
2951 return mService.hasUserSetupCompleted();
2952 } catch (RemoteException re) {
Robin Lee25e26452015-06-02 09:56:29 -07002953 Log.w(TAG, "Failed to check whether user setup has completed");
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002954 }
2955 }
2956 return true;
2957 }
2958
2959 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002960 * @hide
2961 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00002962 * already be installed. There must not already be a profile owner for this user.
2963 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
2964 * this method.
2965 * Calling this after the setup phase of the specified user has completed is allowed only if:
2966 * - the caller is SYSTEM_UID.
2967 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002968 * @param admin the component name to be registered as profile owner.
2969 * @param ownerName the human readable name of the organisation associated with this DPM.
2970 * @param userHandle the userId to set the profile owner for.
2971 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00002972 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
2973 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002974 */
Robin Lee25e26452015-06-02 09:56:29 -07002975 public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName,
Robin Leeddd553f2015-04-30 14:18:22 +01002976 int userHandle) throws IllegalArgumentException {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002977 if (admin == null) {
2978 throw new NullPointerException("admin cannot be null");
2979 }
Adam Connors776c5552014-01-09 10:42:56 +00002980 if (mService != null) {
2981 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002982 if (ownerName == null) {
2983 ownerName = "";
2984 }
2985 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00002986 } catch (RemoteException re) {
2987 Log.w(TAG, "Failed to set profile owner", re);
2988 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2989 }
2990 }
2991 return false;
2992 }
2993
2994 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002995 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
2996 * be used. Only the profile owner can call this.
2997 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01002998 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002999 *
3000 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3001 */
Robin Lee25e26452015-06-02 09:56:29 -07003002 public void setProfileEnabled(@NonNull ComponentName admin) {
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003003 if (mService != null) {
3004 try {
3005 mService.setProfileEnabled(admin);
3006 } catch (RemoteException e) {
3007 Log.w(TAG, "Failed talking with device policy service", e);
3008 }
3009 }
3010 }
3011
3012 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003013 * Sets the name of the profile. In the device owner case it sets the name of the user
3014 * 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 +01003015 * never called by the profile or device owner, the name will be set to default values.
3016 *
3017 * @see #isProfileOwnerApp
3018 * @see #isDeviceOwnerApp
3019 *
Robin Lee25e26452015-06-02 09:56:29 -07003020 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01003021 * @param profileName The name of the profile.
3022 */
Robin Lee25e26452015-06-02 09:56:29 -07003023 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Jessica Hummel1333ea12014-06-23 11:20:10 +01003024 if (mService != null) {
3025 try {
Robin Lee25e26452015-06-02 09:56:29 -07003026 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07003027 } catch (RemoteException e) {
3028 Log.w(TAG, "Failed talking with device policy service", e);
3029 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01003030 }
3031 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01003032
3033 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003034 * Used to determine if a particular package is registered as the profile owner for the
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003035 * current user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003036 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00003037 *
3038 * @param packageName The package name of the app to compare with the registered profile owner.
3039 * @return Whether or not the package is registered as the profile owner.
3040 */
3041 public boolean isProfileOwnerApp(String packageName) {
3042 if (mService != null) {
3043 try {
Nicolas Prevot90af6d72014-07-30 14:19:12 +01003044 ComponentName profileOwner = mService.getProfileOwner(
3045 Process.myUserHandle().getIdentifier());
3046 return profileOwner != null
3047 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00003048 } catch (RemoteException re) {
3049 Log.w(TAG, "Failed to check profile owner");
3050 }
3051 }
3052 return false;
3053 }
3054
3055 /**
3056 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003057 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00003058 * owner has been set for that user.
3059 * @throws IllegalArgumentException if the userId is invalid.
3060 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01003061 @SystemApi
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003062 public ComponentName getProfileOwner() throws IllegalArgumentException {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003063 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
3064 }
3065
3066 /**
3067 * @see #getProfileOwner()
3068 * @hide
3069 */
3070 public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00003071 if (mService != null) {
3072 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003073 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00003074 } catch (RemoteException re) {
3075 Log.w(TAG, "Failed to get profile owner");
3076 throw new IllegalArgumentException(
3077 "Requested profile owner for invalid userId", re);
3078 }
3079 }
3080 return null;
3081 }
3082
3083 /**
3084 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003085 * @return the human readable name of the organisation associated with this DPM or {@code null}
3086 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00003087 * @throws IllegalArgumentException if the userId is invalid.
3088 */
3089 public String getProfileOwnerName() throws IllegalArgumentException {
3090 if (mService != null) {
3091 try {
3092 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
3093 } catch (RemoteException re) {
3094 Log.w(TAG, "Failed to get profile owner");
3095 throw new IllegalArgumentException(
3096 "Requested profile owner for invalid userId", re);
3097 }
3098 }
3099 return null;
3100 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003101
3102 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07003103 * @hide
3104 * @param user The user for whom to fetch the profile owner name, if any.
3105 * @return the human readable name of the organisation associated with this profile owner or
3106 * null if one is not set.
3107 * @throws IllegalArgumentException if the userId is invalid.
3108 */
3109 @SystemApi
Selim Cinek24ac55e2014-08-27 12:51:45 +02003110 public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Amith Yamasani38f836b2014-08-20 14:51:15 -07003111 if (mService != null) {
3112 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02003113 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07003114 } catch (RemoteException re) {
3115 Log.w(TAG, "Failed to get profile owner");
3116 throw new IllegalArgumentException(
3117 "Requested profile owner for invalid userId", re);
3118 }
3119 }
3120 return null;
3121 }
3122
3123 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003124 * Called by a profile owner or device owner to add a default intent handler activity for
3125 * intents that match a certain intent filter. This activity will remain the default intent
3126 * handler even if the set of potential event handlers for the intent filter changes and if
3127 * the intent preferences are reset.
3128 *
3129 * <p>The default disambiguation mechanism takes over if the activity is not installed
3130 * (anymore). When the activity is (re)installed, it is automatically reset as default
3131 * intent handler for the filter.
3132 *
3133 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
3134 * security exception will be thrown.
3135 *
3136 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3137 * @param filter The IntentFilter for which a default handler is added.
3138 * @param activity The Activity that is added as default intent handler.
3139 */
Robin Lee25e26452015-06-02 09:56:29 -07003140 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
3141 @NonNull ComponentName activity) {
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003142 if (mService != null) {
3143 try {
3144 mService.addPersistentPreferredActivity(admin, filter, activity);
3145 } catch (RemoteException e) {
3146 Log.w(TAG, "Failed talking with device policy service", e);
3147 }
3148 }
3149 }
3150
3151 /**
3152 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00003153 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003154 *
3155 * <p>The calling device admin must be a profile owner. If it is not, a security
3156 * exception will be thrown.
3157 *
3158 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3159 * @param packageName The name of the package for which preferences are removed.
3160 */
Robin Lee25e26452015-06-02 09:56:29 -07003161 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003162 String packageName) {
3163 if (mService != null) {
3164 try {
3165 mService.clearPackagePersistentPreferredActivities(admin, packageName);
3166 } catch (RemoteException e) {
3167 Log.w(TAG, "Failed talking with device policy service", e);
3168 }
3169 }
3170 }
Robin Lee66e5d962014-04-09 16:44:21 +01003171
3172 /**
3173 * Called by a profile or device owner to set the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003174 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01003175 *
3176 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be
Kenny Guyd00cfc52014-09-18 16:24:31 +01003177 * boolean, int, String, or String[].
Robin Lee66e5d962014-04-09 16:44:21 +01003178 *
3179 * <p>The application restrictions are only made visible to the target application and the
3180 * profile or device owner.
3181 *
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003182 * <p>If the restrictions are not available yet, but may be applied in the near future,
3183 * the admin can notify the target application of that by adding
3184 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
3185 *
Robin Lee66e5d962014-04-09 16:44:21 +01003186 * <p>The calling device admin must be a profile or device owner; if it is not, a security
3187 * exception will be thrown.
3188 *
3189 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3190 * @param packageName The name of the package to update restricted settings for.
3191 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
3192 * set of active restrictions.
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003193 *
3194 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01003195 */
Robin Lee25e26452015-06-02 09:56:29 -07003196 public void setApplicationRestrictions(@NonNull ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01003197 Bundle settings) {
3198 if (mService != null) {
3199 try {
3200 mService.setApplicationRestrictions(admin, packageName, settings);
3201 } catch (RemoteException e) {
3202 Log.w(TAG, "Failed talking with device policy service", e);
3203 }
3204 }
3205 }
3206
3207 /**
Jim Millere303bf42014-08-26 17:12:29 -07003208 * Sets a list of configuration features to enable for a TrustAgent component. This is meant
3209 * to be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all
3210 * trust agents but those enabled by this function call. If flag
3211 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Jim Miller604e7552014-07-18 19:00:02 -07003212 *
3213 * <p>The calling device admin must have requested
3214 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millere303bf42014-08-26 17:12:29 -07003215 * this method; if not, a security exception will be thrown.
Jim Miller604e7552014-07-18 19:00:02 -07003216 *
3217 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07003218 * @param target Component name of the agent to be enabled.
Jim Millerb5db57a2015-01-14 18:17:19 -08003219 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent
Jim Millere303bf42014-08-26 17:12:29 -07003220 * will be strictly disabled according to the state of the
3221 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
3222 * <p>If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all admins,
3223 * then it's up to the TrustAgent itself to aggregate the values from all device admins.
3224 * <p>Consult documentation for the specific TrustAgent to determine legal options parameters.
Jim Miller604e7552014-07-18 19:00:02 -07003225 */
Robin Lee25e26452015-06-02 09:56:29 -07003226 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
3227 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07003228 if (mService != null) {
3229 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003230 mService.setTrustAgentConfiguration(admin, target, configuration);
Jim Miller604e7552014-07-18 19:00:02 -07003231 } catch (RemoteException e) {
3232 Log.w(TAG, "Failed talking with device policy service", e);
3233 }
3234 }
3235 }
3236
3237 /**
Jim Millere303bf42014-08-26 17:12:29 -07003238 * Gets configuration for the given trust agent based on aggregating all calls to
3239 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
3240 * all device admins.
Jim Miller604e7552014-07-18 19:00:02 -07003241 *
Jim Millerb5db57a2015-01-14 18:17:19 -08003242 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
3243 * this function returns a list of configurations for all admins that declare
3244 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
3245 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
3246 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
3247 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07003248 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07003249 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07003250 */
Robin Lee25e26452015-06-02 09:56:29 -07003251 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
3252 @NonNull ComponentName agent) {
Jim Millere303bf42014-08-26 17:12:29 -07003253 return getTrustAgentConfiguration(admin, agent, UserHandle.myUserId());
3254 }
3255
3256 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003257 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
3258 @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07003259 if (mService != null) {
3260 try {
Jim Millere303bf42014-08-26 17:12:29 -07003261 return mService.getTrustAgentConfiguration(admin, agent, userHandle);
Jim Miller604e7552014-07-18 19:00:02 -07003262 } catch (RemoteException e) {
3263 Log.w(TAG, "Failed talking with device policy service", e);
3264 }
3265 }
Jim Millere303bf42014-08-26 17:12:29 -07003266 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07003267 }
3268
3269 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003270 * Called by a profile owner of a managed profile to set whether caller-Id information from
3271 * the managed profile will be shown in the parent profile, for incoming calls.
Adam Connors210fe212014-07-17 15:41:43 +01003272 *
3273 * <p>The calling device admin must be a profile owner. If it is not, a
3274 * security exception will be thrown.
3275 *
Robin Lee25e26452015-06-02 09:56:29 -07003276 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01003277 * @param disabled If true caller-Id information in the managed profile is not displayed.
3278 */
Robin Lee25e26452015-06-02 09:56:29 -07003279 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Adam Connors210fe212014-07-17 15:41:43 +01003280 if (mService != null) {
3281 try {
Robin Lee25e26452015-06-02 09:56:29 -07003282 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01003283 } catch (RemoteException e) {
3284 Log.w(TAG, "Failed talking with device policy service", e);
3285 }
3286 }
3287 }
3288
3289 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003290 * Called by a profile owner of a managed profile to determine whether or not caller-Id
3291 * information has been disabled.
Adam Connors210fe212014-07-17 15:41:43 +01003292 *
3293 * <p>The calling device admin must be a profile owner. If it is not, a
3294 * security exception will be thrown.
3295 *
Robin Lee25e26452015-06-02 09:56:29 -07003296 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01003297 */
Robin Lee25e26452015-06-02 09:56:29 -07003298 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Adam Connors210fe212014-07-17 15:41:43 +01003299 if (mService != null) {
3300 try {
Robin Lee25e26452015-06-02 09:56:29 -07003301 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01003302 } catch (RemoteException e) {
3303 Log.w(TAG, "Failed talking with device policy service", e);
3304 }
3305 }
3306 return false;
3307 }
3308
3309 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07003310 * Determine whether or not caller-Id information has been disabled.
3311 *
3312 * @param userHandle The user for whom to check the caller-id permission
3313 * @hide
3314 */
3315 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
3316 if (mService != null) {
3317 try {
3318 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
3319 } catch (RemoteException e) {
3320 Log.w(TAG, "Failed talking with device policy service", e);
3321 }
3322 }
3323 return false;
3324 }
3325
3326 /**
Makoto Onuki1040da12015-03-19 11:24:00 -07003327 * Start Quick Contact on the managed profile for the current user, if the policy allows.
3328 * @hide
3329 */
3330 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
3331 Intent originalIntent) {
3332 if (mService != null) {
3333 try {
3334 mService.startManagedQuickContact(
3335 actualLookupKey, actualContactId, originalIntent);
3336 } catch (RemoteException e) {
3337 Log.w(TAG, "Failed talking with device policy service", e);
3338 }
3339 }
3340 }
3341
3342 /**
Ricky Wai778ba132015-03-31 14:21:22 +01003343 * Called by a profile owner of a managed profile to set whether bluetooth
3344 * devices can access enterprise contacts.
3345 * <p>
3346 * The calling device admin must be a profile owner. If it is not, a
3347 * security exception will be thrown.
3348 * <p>
3349 * This API works on managed profile only.
3350 *
Robin Lee25e26452015-06-02 09:56:29 -07003351 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01003352 * with.
3353 * @param disabled If true, bluetooth devices cannot access enterprise
3354 * contacts.
3355 */
Robin Lee25e26452015-06-02 09:56:29 -07003356 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Ricky Wai778ba132015-03-31 14:21:22 +01003357 if (mService != null) {
3358 try {
Robin Lee25e26452015-06-02 09:56:29 -07003359 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01003360 } catch (RemoteException e) {
3361 Log.w(TAG, "Failed talking with device policy service", e);
3362 }
3363 }
3364 }
3365
3366 /**
3367 * Called by a profile owner of a managed profile to determine whether or
3368 * not Bluetooth devices cannot access enterprise contacts.
3369 * <p>
3370 * The calling device admin must be a profile owner. If it is not, a
3371 * security exception will be thrown.
3372 * <p>
3373 * This API works on managed profile only.
3374 *
Robin Lee25e26452015-06-02 09:56:29 -07003375 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01003376 * with.
3377 */
Robin Lee25e26452015-06-02 09:56:29 -07003378 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Ricky Wai778ba132015-03-31 14:21:22 +01003379 if (mService != null) {
3380 try {
Robin Lee25e26452015-06-02 09:56:29 -07003381 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01003382 } catch (RemoteException e) {
3383 Log.w(TAG, "Failed talking with device policy service", e);
3384 }
3385 }
3386 return true;
3387 }
3388
3389 /**
3390 * Determine whether or not Bluetooth devices cannot access contacts.
3391 * <p>
3392 * This API works on managed profile UserHandle only.
3393 *
3394 * @param userHandle The user for whom to check the caller-id permission
3395 * @hide
3396 */
3397 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
3398 if (mService != null) {
3399 try {
3400 return mService.getBluetoothContactSharingDisabledForUser(userHandle
3401 .getIdentifier());
3402 } catch (RemoteException e) {
3403 Log.w(TAG, "Failed talking with device policy service", e);
3404 }
3405 }
3406 return true;
3407 }
3408
3409 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003410 * Called by the profile owner of a managed profile so that some intents sent in the managed
3411 * profile can also be resolved in the parent, or vice versa.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00003412 * Only activity intents are supported.
3413 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003414 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01003415 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
3416 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01003417 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
3418 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003419 */
Robin Lee25e26452015-06-02 09:56:29 -07003420 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003421 if (mService != null) {
3422 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003423 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003424 } catch (RemoteException e) {
3425 Log.w(TAG, "Failed talking with device policy service", e);
3426 }
3427 }
3428 }
3429
3430 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003431 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
3432 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01003433 * Only removes those that have been set by the profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003434 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3435 */
Robin Lee25e26452015-06-02 09:56:29 -07003436 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003437 if (mService != null) {
3438 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003439 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003440 } catch (RemoteException e) {
3441 Log.w(TAG, "Failed talking with device policy service", e);
3442 }
3443 }
3444 }
3445
3446 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003447 * Called by a profile or device owner to set the permitted accessibility services. When
3448 * set by a device owner or profile owner the restriction applies to all profiles of the
3449 * user the device owner or profile owner is an admin for.
Jim Millerb1474f42014-08-26 18:42:58 -07003450 *
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003451 * By default the user can use any accessiblity service. When zero or more packages have
3452 * been added, accessiblity services that are not in the list and not part of the system
Jim Millerb1474f42014-08-26 18:42:58 -07003453 * can not be enabled by the user.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003454 *
3455 * <p> Calling with a null value for the list disables the restriction so that all services
3456 * can be used, calling with an empty list only allows the builtin system's services.
3457 *
3458 * <p> System accesibility services are always available to the user the list can't modify
3459 * this.
3460 *
3461 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3462 * @param packageNames List of accessibility service package names.
3463 *
3464 * @return true if setting the restriction succeeded. It fail if there is
3465 * one or more non-system accessibility services enabled, that are not in the list.
3466 */
Robin Lee25e26452015-06-02 09:56:29 -07003467 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003468 List<String> packageNames) {
3469 if (mService != null) {
3470 try {
3471 return mService.setPermittedAccessibilityServices(admin, packageNames);
3472 } catch (RemoteException e) {
3473 Log.w(TAG, "Failed talking with device policy service", e);
3474 }
3475 }
3476 return false;
3477 }
3478
3479 /**
3480 * Returns the list of permitted accessibility services set by this device or profile owner.
3481 *
3482 * <p>An empty list means no accessibility services except system services are allowed.
3483 * Null means all accessibility services are allowed.
3484 *
3485 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3486 * @return List of accessiblity service package names.
3487 */
Robin Lee25e26452015-06-02 09:56:29 -07003488 public List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003489 if (mService != null) {
3490 try {
3491 return mService.getPermittedAccessibilityServices(admin);
3492 } catch (RemoteException e) {
3493 Log.w(TAG, "Failed talking with device policy service", e);
3494 }
3495 }
3496 return null;
3497 }
3498
3499 /**
3500 * Returns the list of accessibility services permitted by the device or profiles
3501 * owners of this user.
3502 *
3503 * <p>Null means all accessibility services are allowed, if a non-null list is returned
3504 * it will contain the intersection of the permitted lists for any device or profile
3505 * owners that apply to this user. It will also include any system accessibility services.
3506 *
3507 * @param userId which user to check for.
3508 * @return List of accessiblity service package names.
3509 * @hide
3510 */
3511 @SystemApi
3512 public List<String> getPermittedAccessibilityServices(int userId) {
3513 if (mService != null) {
3514 try {
3515 return mService.getPermittedAccessibilityServicesForUser(userId);
3516 } catch (RemoteException e) {
3517 Log.w(TAG, "Failed talking with device policy service", e);
3518 }
3519 }
3520 return null;
3521 }
3522
3523 /**
3524 * Called by a profile or device owner to set the permitted input methods services. When
3525 * set by a device owner or profile owner the restriction applies to all profiles of the
3526 * user the device owner or profile owner is an admin for.
3527 *
3528 * By default the user can use any input method. When zero or more packages have
3529 * been added, input method that are not in the list and not part of the system
3530 * can not be enabled by the user.
3531 *
3532 * This method will fail if it is called for a admin that is not for the foreground user
3533 * or a profile of the foreground user.
3534 *
3535 * <p> Calling with a null value for the list disables the restriction so that all input methods
3536 * can be used, calling with an empty list disables all but the system's own input methods.
3537 *
3538 * <p> System input methods are always available to the user this method can't modify this.
3539 *
3540 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3541 * @param packageNames List of input method package names.
Kenny Guy74a70242015-02-05 19:48:38 +00003542 * @return true if setting the restriction succeeded. It will fail if there are
3543 * one or more non-system input methods currently enabled that are not in
3544 * the packageNames list.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003545 */
Robin Lee25e26452015-06-02 09:56:29 -07003546 public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003547 if (mService != null) {
3548 try {
3549 return mService.setPermittedInputMethods(admin, packageNames);
3550 } catch (RemoteException e) {
3551 Log.w(TAG, "Failed talking with device policy service", e);
3552 }
3553 }
3554 return false;
3555 }
3556
3557
3558 /**
3559 * Returns the list of permitted input methods set by this device or profile owner.
3560 *
3561 * <p>An empty list means no input methods except system input methods are allowed.
3562 * Null means all input methods are allowed.
3563 *
3564 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3565 * @return List of input method package names.
3566 */
Robin Lee25e26452015-06-02 09:56:29 -07003567 public List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003568 if (mService != null) {
3569 try {
3570 return mService.getPermittedInputMethods(admin);
3571 } catch (RemoteException e) {
3572 Log.w(TAG, "Failed talking with device policy service", e);
3573 }
3574 }
3575 return null;
3576 }
3577
3578 /**
3579 * Returns the list of input methods permitted by the device or profiles
3580 * owners of the current user.
3581 *
3582 * <p>Null means all input methods are allowed, if a non-null list is returned
3583 * it will contain the intersection of the permitted lists for any device or profile
3584 * owners that apply to this user. It will also include any system input methods.
3585 *
3586 * @return List of input method package names.
3587 * @hide
3588 */
3589 @SystemApi
3590 public List<String> getPermittedInputMethodsForCurrentUser() {
3591 if (mService != null) {
3592 try {
3593 return mService.getPermittedInputMethodsForCurrentUser();
3594 } catch (RemoteException e) {
3595 Log.w(TAG, "Failed talking with device policy service", e);
3596 }
3597 }
3598 return null;
3599 }
3600
3601 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003602 * Called by a device owner to create a user with the specified name. The UserHandle returned
3603 * by this method should not be persisted as user handles are recycled as users are removed and
3604 * created. If you need to persist an identifier for this user, use
3605 * {@link UserManager#getSerialNumberForUser}.
3606 *
3607 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3608 * @param name the user's name
3609 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07003610 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
3611 * user could not be created.
Julia Reynolds1e958392014-05-16 14:25:21 -04003612 */
Robin Lee25e26452015-06-02 09:56:29 -07003613 public UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04003614 try {
3615 return mService.createUser(admin, name);
3616 } catch (RemoteException re) {
3617 Log.w(TAG, "Could not create a user", re);
3618 }
3619 return null;
3620 }
3621
3622 /**
Jason Monk03978a42014-06-10 15:05:30 -04003623 * Called by a device owner to create a user with the specified name. The UserHandle returned
3624 * by this method should not be persisted as user handles are recycled as users are removed and
3625 * created. If you need to persist an identifier for this user, use
3626 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
3627 * immediately.
3628 *
3629 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
3630 * as registered as an active admin on the new user. The profile owner package will be
3631 * installed on the new user if it already is installed on the device.
3632 *
3633 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
3634 * profileOwnerComponent when onEnable is called.
3635 *
3636 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3637 * @param name the user's name
3638 * @param ownerName the human readable name of the organisation associated with this DPM.
3639 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
3640 * the user.
3641 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
3642 * on the new user.
3643 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07003644 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
3645 * user could not be created.
Jason Monk03978a42014-06-10 15:05:30 -04003646 */
Robin Lee25e26452015-06-02 09:56:29 -07003647 public UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
3648 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04003649 try {
3650 return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent,
3651 adminExtras);
3652 } catch (RemoteException re) {
3653 Log.w(TAG, "Could not create a user", re);
3654 }
3655 return null;
3656 }
3657
3658 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003659 * Called by a device owner to remove a user and all associated data. The primary user can
3660 * not be removed.
3661 *
3662 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3663 * @param userHandle the user to remove.
3664 * @return {@code true} if the user was removed, {@code false} otherwise.
3665 */
Robin Lee25e26452015-06-02 09:56:29 -07003666 public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) {
Julia Reynolds1e958392014-05-16 14:25:21 -04003667 try {
3668 return mService.removeUser(admin, userHandle);
3669 } catch (RemoteException re) {
3670 Log.w(TAG, "Could not remove user ", re);
3671 return false;
3672 }
3673 }
3674
3675 /**
Jason Monk582d9112014-07-09 19:57:08 -04003676 * Called by a device owner to switch the specified user to the foreground.
3677 *
3678 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3679 * @param userHandle the user to switch to; null will switch to primary.
3680 * @return {@code true} if the switch was successful, {@code false} otherwise.
3681 *
3682 * @see Intent#ACTION_USER_FOREGROUND
3683 */
Robin Lee25e26452015-06-02 09:56:29 -07003684 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Jason Monk582d9112014-07-09 19:57:08 -04003685 try {
3686 return mService.switchUser(admin, userHandle);
3687 } catch (RemoteException re) {
3688 Log.w(TAG, "Could not switch user ", re);
3689 return false;
3690 }
3691 }
3692
3693 /**
Robin Lee66e5d962014-04-09 16:44:21 +01003694 * Called by a profile or device owner to get the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003695 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01003696 *
3697 * <p>The calling device admin must be a profile or device owner; if it is not, a security
3698 * exception will be thrown.
3699 *
3700 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3701 * @param packageName The name of the package to fetch restricted settings of.
3702 * @return {@link Bundle} of settings corresponding to what was set last time
3703 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
3704 * if no restrictions have been set.
3705 */
Robin Lee25e26452015-06-02 09:56:29 -07003706 public Bundle getApplicationRestrictions(@NonNull ComponentName admin, String packageName) {
Robin Lee66e5d962014-04-09 16:44:21 +01003707 if (mService != null) {
3708 try {
3709 return mService.getApplicationRestrictions(admin, packageName);
3710 } catch (RemoteException e) {
3711 Log.w(TAG, "Failed talking with device policy service", e);
3712 }
3713 }
3714 return null;
3715 }
Amith Yamasanibe465322014-04-24 13:45:17 -07003716
3717 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003718 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07003719 * <p>
3720 * The calling device admin must be a profile or device owner; if it is not,
3721 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003722 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003723 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3724 * with.
3725 * @param key The key of the restriction. See the constants in
3726 * {@link android.os.UserManager} for the list of keys.
3727 */
Robin Lee25e26452015-06-02 09:56:29 -07003728 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07003729 if (mService != null) {
3730 try {
3731 mService.setUserRestriction(admin, key, true);
3732 } catch (RemoteException e) {
3733 Log.w(TAG, "Failed talking with device policy service", e);
3734 }
3735 }
3736 }
3737
3738 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003739 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07003740 * <p>
3741 * The calling device admin must be a profile or device owner; if it is not,
3742 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003743 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003744 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3745 * with.
3746 * @param key The key of the restriction. See the constants in
3747 * {@link android.os.UserManager} for the list of keys.
3748 */
Robin Lee25e26452015-06-02 09:56:29 -07003749 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07003750 if (mService != null) {
3751 try {
3752 mService.setUserRestriction(admin, key, false);
3753 } catch (RemoteException e) {
3754 Log.w(TAG, "Failed talking with device policy service", e);
3755 }
3756 }
3757 }
Adam Connors010cfd42014-04-16 12:48:13 +01003758
3759 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003760 * Called by profile or device owners to hide or unhide packages. When a package is hidden it
Julia Reynolds966881e2014-05-14 12:23:08 -04003761 * is unavailable for use, but the data and actual package file remain.
3762 *
3763 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003764 * @param packageName The name of the package to hide or unhide.
3765 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
3766 * unhidden.
3767 * @return boolean Whether the hidden setting of the package was successfully updated.
Julia Reynolds966881e2014-05-14 12:23:08 -04003768 */
Robin Lee25e26452015-06-02 09:56:29 -07003769 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003770 boolean hidden) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003771 if (mService != null) {
3772 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003773 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04003774 } catch (RemoteException e) {
3775 Log.w(TAG, "Failed talking with device policy service", e);
3776 }
3777 }
3778 return false;
3779 }
3780
3781 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003782 * Called by profile or device owners to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04003783 *
3784 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003785 * @param packageName The name of the package to retrieve the hidden status of.
3786 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Julia Reynolds966881e2014-05-14 12:23:08 -04003787 */
Robin Lee25e26452015-06-02 09:56:29 -07003788 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003789 if (mService != null) {
3790 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003791 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04003792 } catch (RemoteException e) {
3793 Log.w(TAG, "Failed talking with device policy service", e);
3794 }
3795 }
3796 return false;
3797 }
3798
3799 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003800 * Called by profile or device owners to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003801 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003802 *
3803 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3804 * @param packageName The package to be re-enabled in the current profile.
3805 */
Robin Lee25e26452015-06-02 09:56:29 -07003806 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Adam Connors655be2a2014-07-14 09:01:25 +00003807 if (mService != null) {
3808 try {
3809 mService.enableSystemApp(admin, packageName);
3810 } catch (RemoteException e) {
3811 Log.w(TAG, "Failed to install package: " + packageName);
3812 }
3813 }
3814 }
3815
3816 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003817 * Called by profile or device owners to re-enable system apps by intent that were disabled
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003818 * by default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003819 *
3820 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3821 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
3822 * intent will be re-enabled in the current profile.
3823 * @return int The number of activities that matched the intent and were installed.
3824 */
Robin Lee25e26452015-06-02 09:56:29 -07003825 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Adam Connors655be2a2014-07-14 09:01:25 +00003826 if (mService != null) {
3827 try {
3828 return mService.enableSystemAppWithIntent(admin, intent);
3829 } catch (RemoteException e) {
3830 Log.w(TAG, "Failed to install packages matching filter: " + intent);
3831 }
3832 }
3833 return 0;
3834 }
3835
3836 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00003837 * Called by a device owner or profile owner to disable account management for a specific type
3838 * of account.
Sander Alewijnse650c3342014-05-08 18:00:50 +01003839 *
Sander Alewijnse112e0532014-10-29 13:28:49 +00003840 * <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 +01003841 * security exception will be thrown.
3842 *
3843 * <p>When account management is disabled for an account type, adding or removing an account
3844 * of that type will not be possible.
3845 *
3846 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3847 * @param accountType For which account management is disabled or enabled.
3848 * @param disabled The boolean indicating that account management will be disabled (true) or
3849 * enabled (false).
3850 */
Robin Lee25e26452015-06-02 09:56:29 -07003851 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01003852 boolean disabled) {
3853 if (mService != null) {
3854 try {
3855 mService.setAccountManagementDisabled(admin, accountType, disabled);
3856 } catch (RemoteException e) {
3857 Log.w(TAG, "Failed talking with device policy service", e);
3858 }
3859 }
3860 }
3861
3862 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003863 * Gets the array of accounts for which account management is disabled by the profile owner.
3864 *
3865 * <p> Account management can be disabled/enabled by calling
3866 * {@link #setAccountManagementDisabled}.
3867 *
3868 * @return a list of account types for which account management has been disabled.
3869 *
3870 * @see #setAccountManagementDisabled
3871 */
3872 public String[] getAccountTypesWithManagementDisabled() {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003873 return getAccountTypesWithManagementDisabledAsUser(UserHandle.myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003874 }
3875
3876 /**
3877 * @see #getAccountTypesWithManagementDisabled()
3878 * @hide
3879 */
3880 public String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003881 if (mService != null) {
3882 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003883 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003884 } catch (RemoteException e) {
3885 Log.w(TAG, "Failed talking with device policy service", e);
3886 }
3887 }
3888
3889 return null;
3890 }
justinzhang511e0d82014-03-24 16:09:24 -04003891
3892 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003893 * Sets which packages may enter lock task mode.
3894 *
3895 * <p>Any packages that shares uid with an allowed package will also be allowed
3896 * to activate lock task.
justinzhang511e0d82014-03-24 16:09:24 -04003897 *
Benjamin Franz469dd582015-06-09 14:24:36 +01003898 * From {@link android.os.Build.VERSION_CODES#MNC} removing packages from the lock task
3899 * package list results in locked tasks belonging to those packages to be finished.
3900 *
Jason Monkc5185f22014-06-24 11:12:42 -04003901 * This function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04003902 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04003903 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jason Monkd7b86212014-06-16 13:15:38 -04003904 *
3905 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00003906 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
3907 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04003908 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04003909 */
Robin Lee25e26452015-06-02 09:56:29 -07003910 public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04003911 throws SecurityException {
justinzhang511e0d82014-03-24 16:09:24 -04003912 if (mService != null) {
3913 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003914 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04003915 } catch (RemoteException e) {
3916 Log.w(TAG, "Failed talking with device policy service", e);
3917 }
3918 }
3919 }
3920
3921 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003922 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04003923 *
3924 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04003925 * @hide
3926 */
Robin Lee25e26452015-06-02 09:56:29 -07003927 public String[] getLockTaskPackages(@NonNull ComponentName admin) {
justinzhang511e0d82014-03-24 16:09:24 -04003928 if (mService != null) {
3929 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003930 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04003931 } catch (RemoteException e) {
3932 Log.w(TAG, "Failed talking with device policy service", e);
3933 }
3934 }
3935 return null;
3936 }
3937
3938 /**
3939 * This function lets the caller know whether the given component is allowed to start the
3940 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04003941 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04003942 */
Jason Monkd7b86212014-06-16 13:15:38 -04003943 public boolean isLockTaskPermitted(String pkg) {
justinzhang511e0d82014-03-24 16:09:24 -04003944 if (mService != null) {
3945 try {
Jason Monkd7b86212014-06-16 13:15:38 -04003946 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04003947 } catch (RemoteException e) {
3948 Log.w(TAG, "Failed talking with device policy service", e);
3949 }
3950 }
3951 return false;
3952 }
Julia Reynoldsda551652014-05-14 17:15:16 -04003953
3954 /**
3955 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
3956 * 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 -04003957 * <p>The settings that can be updated with this method are:
3958 * <ul>
3959 * <li>{@link Settings.Global#ADB_ENABLED}</li>
3960 * <li>{@link Settings.Global#AUTO_TIME}</li>
3961 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Nicolas Prevot41916d42015-02-24 18:41:50 +00003962 * <li>{@link Settings.Global#BLUETOOTH_ON}
3963 * Changing this setting has not effect as of {@link android.os.Build.VERSION_CODES#MNC}. Use
3964 * {@link android.bluetooth.BluetoothAdapter#enable()} and
3965 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003966 * <li>{@link Settings.Global#DATA_ROAMING}</li>
3967 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
3968 * <li>{@link Settings.Global#MODE_RINGER}</li>
3969 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
3970 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Nicolas Prevot41916d42015-02-24 18:41:50 +00003971 * <li>{@link Settings.Global#WIFI_ON}
3972 * Changing this setting has not effect as of {@link android.os.Build.VERSION_CODES#MNC}. Use
3973 * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003974 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Benjamin Franz68cc4202015-03-11 15:43:06 +00003975 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN}
3976 * This setting is only available from {@link android.os.Build.VERSION_CODES#MNC} onwards
3977 * and can only be set if {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
Zoltan Szatmary-Ban4045d242015-05-27 12:42:39 +01003978 * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003979 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04003980 *
3981 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3982 * @param setting The name of the setting to update.
3983 * @param value The value to update the setting to.
3984 */
Robin Lee25e26452015-06-02 09:56:29 -07003985 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04003986 if (mService != null) {
3987 try {
3988 mService.setGlobalSetting(admin, setting, value);
3989 } catch (RemoteException e) {
3990 Log.w(TAG, "Failed talking with device policy service", e);
3991 }
3992 }
3993 }
3994
3995 /**
3996 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
3997 * that the value of the setting is in the correct form for the setting type should be performed
3998 * by the caller.
Julia Reynolds82735bc2014-09-04 16:43:30 -04003999 * <p>The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004000 * <ul>
4001 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07004002 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004003 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
4004 * </ul>
Julia Reynolds82735bc2014-09-04 16:43:30 -04004005 * <p>A device owner can additionally update the following settings:
4006 * <ul>
4007 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
4008 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04004009 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4010 * @param setting The name of the setting to update.
4011 * @param value The value to update the setting to.
4012 */
Robin Lee25e26452015-06-02 09:56:29 -07004013 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04004014 if (mService != null) {
4015 try {
4016 mService.setSecureSetting(admin, setting, value);
4017 } catch (RemoteException e) {
4018 Log.w(TAG, "Failed talking with device policy service", e);
4019 }
4020 }
4021 }
4022
Amith Yamasanif20d6402014-05-24 15:34:37 -07004023 /**
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004024 * Designates a specific service component as the provider for
Amith Yamasanif20d6402014-05-24 15:34:37 -07004025 * making permission requests of a local or remote administrator of the user.
4026 * <p/>
4027 * Only a profile owner can designate the restrictions provider.
4028 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004029 * @param provider The component name of the service that implements
Amith Yamasanid1d7c022014-08-19 17:03:41 -07004030 * {@link RestrictionsReceiver}. If this param is null,
Amith Yamasanif20d6402014-05-24 15:34:37 -07004031 * it removes the restrictions provider previously assigned.
4032 */
Robin Lee25e26452015-06-02 09:56:29 -07004033 public void setRestrictionsProvider(@NonNull ComponentName admin,
4034 @Nullable ComponentName provider) {
Amith Yamasanif20d6402014-05-24 15:34:37 -07004035 if (mService != null) {
4036 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004037 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07004038 } catch (RemoteException re) {
4039 Log.w(TAG, "Failed to set permission provider on device policy service");
4040 }
4041 }
4042 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04004043
4044 /**
4045 * Called by profile or device owners to set the master volume mute on or off.
4046 *
4047 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4048 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
4049 */
Robin Lee25e26452015-06-02 09:56:29 -07004050 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04004051 if (mService != null) {
4052 try {
4053 mService.setMasterVolumeMuted(admin, on);
4054 } catch (RemoteException re) {
4055 Log.w(TAG, "Failed to setMasterMute on device policy service");
4056 }
4057 }
4058 }
4059
4060 /**
4061 * Called by profile or device owners to check whether the master volume mute is on or off.
4062 *
4063 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4064 * @return {@code true} if master volume is muted, {@code false} if it's not.
4065 */
Robin Lee25e26452015-06-02 09:56:29 -07004066 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04004067 if (mService != null) {
4068 try {
4069 return mService.isMasterVolumeMuted(admin);
4070 } catch (RemoteException re) {
4071 Log.w(TAG, "Failed to get isMasterMute on device policy service");
4072 }
4073 }
4074 return false;
4075 }
Kenny Guyc13053b2014-05-29 14:17:17 +01004076
4077 /**
4078 * Called by profile or device owners to change whether a user can uninstall
4079 * a package.
4080 *
4081 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4082 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004083 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Kenny Guyc13053b2014-05-29 14:17:17 +01004084 */
Robin Lee25e26452015-06-02 09:56:29 -07004085 public void setUninstallBlocked(@NonNull ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004086 boolean uninstallBlocked) {
Kenny Guyc13053b2014-05-29 14:17:17 +01004087 if (mService != null) {
4088 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004089 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01004090 } catch (RemoteException re) {
4091 Log.w(TAG, "Failed to call block uninstall on device policy service");
4092 }
4093 }
4094 }
4095
4096 /**
Rubin Xua97855b2014-11-07 05:41:00 +00004097 * Check whether the current user has been blocked by device policy from uninstalling a package.
4098 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00004099 * <p>
4100 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Robin Lee25e26452015-06-02 09:56:29 -07004101 * behavior of this API is changed such that passing {@code null} as the {@code admin}
Rubin Xue1e6faa2015-03-10 10:51:59 +00004102 * parameter will return if any admin has blocked the uninstallation. Before L MR1, passing
Robin Lee25e26452015-06-02 09:56:29 -07004103 * {@code null} will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01004104 *
Robin Lee25e26452015-06-02 09:56:29 -07004105 * @param admin The name of the admin component whose blocking policy will be checked, or
4106 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01004107 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00004108 * @return true if uninstallation is blocked.
Kenny Guyc13053b2014-05-29 14:17:17 +01004109 */
Robin Lee25e26452015-06-02 09:56:29 -07004110 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Kenny Guyc13053b2014-05-29 14:17:17 +01004111 if (mService != null) {
4112 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01004113 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01004114 } catch (RemoteException re) {
4115 Log.w(TAG, "Failed to call block uninstall on device policy service");
4116 }
4117 }
4118 return false;
4119 }
Svetoslav976e8bd2014-07-16 15:12:03 -07004120
4121 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004122 * Called by the profile owner of a managed profile to enable widget providers from a
4123 * given package to be available in the parent profile. As a result the user will be able to
Svetoslav976e8bd2014-07-16 15:12:03 -07004124 * add widgets from the white-listed package running under the profile to a widget
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004125 * host which runs under the parent profile, for example the home screen. Note that
Svetoslav976e8bd2014-07-16 15:12:03 -07004126 * a package may have zero or more provider components, where each component
4127 * provides a different widget type.
4128 * <p>
4129 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07004130 *
4131 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4132 * @param packageName The package from which widget providers are white-listed.
4133 * @return Whether the package was added.
4134 *
4135 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4136 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4137 */
Robin Lee25e26452015-06-02 09:56:29 -07004138 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004139 if (mService != null) {
4140 try {
4141 return mService.addCrossProfileWidgetProvider(admin, packageName);
4142 } catch (RemoteException re) {
4143 Log.w(TAG, "Error calling addCrossProfileWidgetProvider", re);
4144 }
4145 }
4146 return false;
4147 }
4148
4149 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004150 * Called by the profile owner of a managed profile to disable widget providers from a given
4151 * package to be available in the parent profile. For this method to take effect the
Svetoslav976e8bd2014-07-16 15:12:03 -07004152 * package should have been added via {@link #addCrossProfileWidgetProvider(
4153 * android.content.ComponentName, String)}.
4154 * <p>
4155 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07004156 *
4157 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4158 * @param packageName The package from which widget providers are no longer
4159 * white-listed.
4160 * @return Whether the package was removed.
4161 *
4162 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
4163 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4164 */
Robin Lee25e26452015-06-02 09:56:29 -07004165 public boolean removeCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004166 if (mService != null) {
4167 try {
4168 return mService.removeCrossProfileWidgetProvider(admin, packageName);
4169 } catch (RemoteException re) {
4170 Log.w(TAG, "Error calling removeCrossProfileWidgetProvider", re);
4171 }
4172 }
4173 return false;
4174 }
4175
4176 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004177 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07004178 * available in the parent profile.
4179 *
4180 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4181 * @return The white-listed package list.
4182 *
4183 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
4184 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4185 */
Robin Lee25e26452015-06-02 09:56:29 -07004186 public List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004187 if (mService != null) {
4188 try {
4189 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
4190 if (providers != null) {
4191 return providers;
4192 }
4193 } catch (RemoteException re) {
4194 Log.w(TAG, "Error calling getCrossProfileWidgetProviders", re);
4195 }
4196 }
4197 return Collections.emptyList();
4198 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004199
4200 /**
4201 * Called by profile or device owners to set the current user's photo.
4202 *
4203 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4204 * @param icon the bitmap to set as the photo.
4205 */
Robin Lee25e26452015-06-02 09:56:29 -07004206 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004207 try {
4208 mService.setUserIcon(admin, icon);
4209 } catch (RemoteException re) {
4210 Log.w(TAG, "Could not set the user icon ", re);
4211 }
4212 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04004213
4214 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01004215 * Called by device owners to set a local system update policy. When a new policy is set,
4216 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004217 *
Robin Lee25e26452015-06-02 09:56:29 -07004218 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
4219 * components in the device owner package can set system update policies and the
4220 * most recent policy takes
Rubin Xu5faad8e2015-04-20 17:43:48 +01004221 * effect.
Robin Lee25e26452015-06-02 09:56:29 -07004222 * @param policy the new policy, or {@code null} to clear the current policy.
Rubin Xu5faad8e2015-04-20 17:43:48 +01004223 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00004224 */
Robin Lee25e26452015-06-02 09:56:29 -07004225 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Rubin Xu8027a4f2015-03-10 17:52:37 +00004226 if (mService != null) {
4227 try {
Robin Lee25e26452015-06-02 09:56:29 -07004228 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004229 } catch (RemoteException re) {
Rubin Xu5faad8e2015-04-20 17:43:48 +01004230 Log.w(TAG, "Error calling setSystemUpdatePolicy", re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004231 }
4232 }
4233 }
4234
4235 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01004236 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004237 *
Robin Lee25e26452015-06-02 09:56:29 -07004238 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004239 */
Rubin Xu5faad8e2015-04-20 17:43:48 +01004240 public SystemUpdatePolicy getSystemUpdatePolicy() {
Rubin Xu8027a4f2015-03-10 17:52:37 +00004241 if (mService != null) {
4242 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01004243 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00004244 } catch (RemoteException re) {
Rubin Xu5faad8e2015-04-20 17:43:48 +01004245 Log.w(TAG, "Error calling getSystemUpdatePolicy", re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004246 }
4247 }
4248 return null;
4249 }
Benjamin Franze36087e2015-04-07 16:40:34 +01004250
4251 /**
4252 * Called by a device owner to disable the keyguard altogether.
4253 *
4254 * <p>Setting the keyguard to disabled has the same effect as choosing "None" as the screen
4255 * lock type. However, this call has no effect if a password, pin or pattern is currently set.
4256 * If a password, pin or pattern is set after the keyguard was disabled, the keyguard stops
4257 * being disabled.
4258 *
4259 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01004260 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01004261 *
4262 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Benjamin Franzbece8062015-05-06 12:14:31 +01004263 * place. {@code true} otherwise.
Benjamin Franze36087e2015-04-07 16:40:34 +01004264 */
Robin Lee25e26452015-06-02 09:56:29 -07004265 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franze36087e2015-04-07 16:40:34 +01004266 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01004267 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01004268 } catch (RemoteException re) {
4269 Log.w(TAG, "Failed talking with device policy service", re);
4270 return false;
4271 }
4272 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00004273
4274 /**
Benjamin Franzbece8062015-05-06 12:14:31 +01004275 * Called by device owner to disable the status bar. Disabling the status bar blocks
4276 * notifications, quick settings and other screen overlays that allow escaping from
Benjamin Franzea2ec972015-03-16 17:18:09 +00004277 * a single use device.
4278 *
4279 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01004280 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
4281 *
4282 * @return {@code false} if attempting to disable the status bar failed.
4283 * {@code true} otherwise.
Benjamin Franzea2ec972015-03-16 17:18:09 +00004284 */
Robin Lee25e26452015-06-02 09:56:29 -07004285 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzea2ec972015-03-16 17:18:09 +00004286 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01004287 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00004288 } catch (RemoteException re) {
4289 Log.w(TAG, "Failed talking with device policy service", re);
Benjamin Franzbece8062015-05-06 12:14:31 +01004290 return false;
Benjamin Franzea2ec972015-03-16 17:18:09 +00004291 }
4292 }
Rubin Xudc105cc2015-04-14 23:38:01 +01004293
4294 /**
4295 * Callable by the system update service to notify device owners about pending updates.
4296 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
4297 * permission.
4298 *
4299 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating
4300 * when the current pending update was first available. -1 if no update is available.
4301 * @hide
4302 */
4303 @SystemApi
4304 public void notifyPendingSystemUpdate(long updateReceivedTime) {
4305 if (mService != null) {
4306 try {
4307 mService.notifyPendingSystemUpdate(updateReceivedTime);
4308 } catch (RemoteException re) {
4309 Log.w(TAG, "Could not notify device owner about pending system update", re);
4310 }
4311 }
4312 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04004313
4314 /**
Amith Yamasanid49489b2015-04-28 14:00:26 -07004315 * Called by profile or device owners to set the default response for future runtime permission
4316 * requests by applications. The policy can allow for normal operation which prompts the
4317 * user to grant a permission, or can allow automatic granting or denying of runtime
4318 * permission requests by an application. This also applies to new permissions declared by app
4319 * updates.
4320 * @param admin Which profile or device owner this request is associated with.
4321 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
4322 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
4323 */
Robin Lee25e26452015-06-02 09:56:29 -07004324 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004325 try {
4326 mService.setPermissionPolicy(admin, policy);
4327 } catch (RemoteException re) {
4328 Log.w(TAG, "Failed talking with device policy service", re);
4329 }
4330 }
4331
4332 /**
4333 * Returns the current runtime permission policy set by the device or profile owner. The
4334 * default is {@link #PERMISSION_POLICY_PROMPT}.
4335 * @param admin Which profile or device owner this request is associated with.
4336 * @return the current policy for future permission requests.
4337 */
Esteban Talavera28b95702015-06-24 15:23:42 +01004338 public int getPermissionPolicy(ComponentName admin) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004339 try {
4340 return mService.getPermissionPolicy(admin);
4341 } catch (RemoteException re) {
4342 return PERMISSION_POLICY_PROMPT;
4343 }
4344 }
4345
4346 /**
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004347 * Sets the grant state of a runtime permission for a specific application. The state
4348 * can be {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it
4349 * through the UI, {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission
4350 * is denied and the user cannot manage it through the UI, and {@link
4351 * #PERMISSION_GRANT_STATE_GRANTED granted} in which the permission is granted and the
4352 * user cannot manage it through the UI. This might affect all permissions in a
4353 * group that the runtime permission belongs to. This method can only be called
4354 * by a profile or device owner.
4355 *
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07004356 * <p/>Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not
4357 * revoke the permission. It retains the previous grant, if any.
4358 *
4359 * <p/>Permissions can be granted or revoked only for applications built with a
4360 * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#MNC} or later.
4361 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07004362 * @param admin Which profile or device owner this request is associated with.
4363 * @param packageName The application to grant or revoke a permission to.
4364 * @param permission The permission to grant or revoke.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004365 * @param grantState The permission grant state which is one of {@link
4366 * #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
4367 * {@link #PERMISSION_GRANT_STATE_GRANTED},
4368 * @return whether the permission was successfully granted or revoked.
4369 *
4370 * @see #PERMISSION_GRANT_STATE_DENIED
4371 * @see #PERMISSION_GRANT_STATE_DEFAULT
4372 * @see #PERMISSION_GRANT_STATE_GRANTED
Amith Yamasanid49489b2015-04-28 14:00:26 -07004373 */
Robin Lee25e26452015-06-02 09:56:29 -07004374 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004375 String permission, int grantState) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004376 try {
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004377 return mService.setPermissionGrantState(admin, packageName, permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07004378 } catch (RemoteException re) {
4379 Log.w(TAG, "Failed talking with device policy service", re);
4380 return false;
4381 }
4382 }
Amith Yamasani184b3752015-05-22 13:00:51 -07004383
4384 /**
4385 * Returns the current grant state of a runtime permission for a specific application.
4386 *
4387 * @param admin Which profile or device owner this request is associated with.
4388 * @param packageName The application to check the grant state for.
4389 * @param permission The permission to check for.
4390 * @return the current grant state specified by device policy. If the profile or device owner
4391 * has not set a grant state, the return value is {@link #PERMISSION_GRANT_STATE_DEFAULT}.
4392 * This does not indicate whether or not the permission is currently granted for the package.
4393 *
4394 * <p/>If a grant state was set by the profile or device owner, then the return value will
4395 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or {@link #PERMISSION_GRANT_STATE_GRANTED},
4396 * which indicates if the permission is currently denied or granted.
4397 *
4398 * @see #setPermissionGrantState(ComponentName, String, String, int)
4399 * @see PackageManager#checkPermission(String, String)
4400 */
Robin Lee25e26452015-06-02 09:56:29 -07004401 public int getPermissionGrantState(@NonNull ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07004402 String permission) {
4403 try {
4404 return mService.getPermissionGrantState(admin, packageName, permission);
4405 } catch (RemoteException re) {
4406 Log.w(TAG, "Failed talking with device policy service", re);
4407 return PERMISSION_GRANT_STATE_DEFAULT;
4408 }
4409 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08004410}