blob: 8257cc688ebfde2319f7f73f1b1bdc2947a12c04 [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
Rubin Xu44ef750b2015-03-23 16:51:33 +0000218 * {@link #MIME_TYPE_PROVISIONING_NFC_V2}. For the NFC record, the component name should be
219 * 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 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400389 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} 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 *
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100464 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} or an intent with action
465 * {@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 /**
Rubin Xu44ef750b2015-03-23 16:51:33 +0000471 * On devices managed by a device owner app, a {@link ComponentName} extra indicating the
472 * component of the application that is temporarily granted device owner privileges during
473 * device initialization and profile owner privileges during secondary user initialization.
Julia Reynolds20118f12015-02-11 12:34:08 -0500474 *
Rubin Xu44ef750b2015-03-23 16:51:33 +0000475 * <p>
Rubin Xu6a38e432015-03-26 14:47:45 +0000476 * 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 +0000477 * device owner provisioning via an NFC bump. For the NFC record, it should be flattened to a
478 * string first.
479 *
480 * @see ComponentName#flattenToShortString()
Julia Reynolds20118f12015-02-11 12:34:08 -0500481 */
482 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_COMPONENT_NAME
483 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_COMPONENT_NAME";
484
485 /**
486 * A String extra holding an http url that specifies the download location of the device
487 * initializer package. When not provided it is assumed that the device initializer package is
488 * already installed.
489 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400490 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynolds20118f12015-02-11 12:34:08 -0500491 * provisioning via an NFC bump.
492 */
493 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION
494 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION";
495
496 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400497 * An int extra holding a minimum required version code for the device initializer package.
498 * If the initializer is already installed on the device, it will only be re-downloaded from
499 * {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION} if the version of
500 * the installed package is less than this version code.
501 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400502 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400503 * provisioning via an NFC bump.
504 */
505 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_MINIMUM_VERSION_CODE
506 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_MINIMUM_VERSION_CODE";
507
508 /**
Julia Reynolds20118f12015-02-11 12:34:08 -0500509 * A String extra holding a http cookie header which should be used in the http request to the
510 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION}.
511 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400512 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynolds20118f12015-02-11 12:34:08 -0500513 * provisioning via an NFC bump.
514 */
515 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_COOKIE_HEADER
516 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_COOKIE_HEADER";
517
518 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100519 * A String extra holding the URL-safe base64 encoded SHA-256 checksum of the file at download
Rubin Xue30ab112015-03-24 11:22:28 +0000520 * location specified in
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100521 * {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION}.
522 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100523 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_SIGNATURE_CHECKSUM}
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100524 * should be present. The provided checksum should match the checksum of the file at the
525 * download location. If the checksum doesn't match an error will be shown to the user and the
526 * user will be asked to factory reset the device.
Julia Reynolds20118f12015-02-11 12:34:08 -0500527 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400528 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynolds20118f12015-02-11 12:34:08 -0500529 * provisioning via an NFC bump.
530 */
531 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM
532 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM";
533
534 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100535 * A String extra holding the URL-safe base64 encoded SHA-256 checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100536 * android package archive at the download location specified in {@link
537 * #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION}.
538 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100539 * <p>The signatures of an android package archive can be obtained using
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100540 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
541 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
542 *
543 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM}
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100544 * should be present. The provided checksum should match the checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100545 * file at the download location. If the checksum doesn't match an error will be shown to the
546 * user and the user will be asked to factory reset the device.
547 *
548 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
549 * provisioning via an NFC bump.
550 */
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100551 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_SIGNATURE_CHECKSUM
552 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_SIGNATURE_CHECKSUM";
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100553
554 /**
Craig Lafayette8e27c4d2015-03-19 08:36:38 -0400555 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that
556 * holds data needed by the system to wipe factory reset protection. The data needed to wipe
557 * the device depend on the installed factory reset protection implementation. For example,
558 * if an account is needed to unlock a device, this extra may contain data used to
559 * authenticate that account.
560 *
561 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
562 * provisioning via an NFC bump.
563 */
564 public static final String EXTRA_PROVISIONING_RESET_PROTECTION_PARAMETERS
565 = "android.app.extra.PROVISIONING_RESET_PROTECTION_PARAMETERS";
566
Craig Lafayette97e473e2015-03-19 10:19:38 -0400567 /**
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400568 * This MIME type is used for starting the Device Owner provisioning that does not require
569 * provisioning features introduced in Android API level
570 * {@link android.os.Build.VERSION_CODES#MNC} or later levels.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100571 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400572 * <p>For more information about the provisioning process see
573 * {@link #MIME_TYPE_PROVISIONING_NFC_V2}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100574 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000575 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100576 * contains the following properties:
577 * <ul>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400578 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
579 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100580 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400581 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100582 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
583 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
584 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
585 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
586 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
587 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
588 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
589 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
590 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
591 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400592 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100593 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000594 * <p>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400595 * As of {@link android.os.Build.VERSION_CODES#MNC}, the properties should contain
596 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of
597 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only
598 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
599 *
600 * @see #MIME_TYPE_PROVISIONING_NFC_V2
601 *
602 */
603 public static final String MIME_TYPE_PROVISIONING_NFC
604 = "application/com.android.managedprovisioning";
605
606
607 /**
608 * This MIME type is used for starting the Device Owner provisioning that requires
609 * new provisioning features introduced in API version
610 * {@link android.os.Build.VERSION_CODES#MNC} in addition to those supported in earlier
611 * versions.
612 *
613 * <p>During device owner provisioning a device admin app is set as the owner of the device.
614 * 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 +0100615 * user.
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400616 *
617 * <p> A typical use case would be a device that is owned by a company, but used by either an
618 * employee or client.
619 *
620 * <p> The NFC message should be sent to an unprovisioned device.
621 *
622 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
623 * contains the following properties in addition to properties listed at
624 * {@link #MIME_TYPE_PROVISIONING_NFC}:
625 * <ul>
626 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
627 * <li>{@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_COMPONENT_NAME}, optional</li>
628 * <li>{@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
629 * <li>{@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
630 * <li>{@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM}, optional</li>
631 * <li>{@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_MINIMUM_VERSION_CODE}, optional</li>
632 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}.
633 * Replaces {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}. The value of the property
634 * should be converted to a String via
635 * {@link android.content.ComponentName#flattenToString()}</li>
Craig Lafayette240e6482015-06-02 11:12:43 -0400636 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE}, optional</li></ul>
Nicolas Prevot18440252015-03-09 14:07:17 +0000637 *
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100638 * <p> When device owner provisioning has completed, an intent of the type
639 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcasted to the
640 * device owner.
641 *
642 * <p>
643 * If provisioning fails, the device is factory reset.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100644 */
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400645 public static final String MIME_TYPE_PROVISIONING_NFC_V2
646 = "application/com.android.managedprovisioning.v2";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100647
648 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800649 * Activity action: ask the user to add a new device administrator to the system.
650 * The desired policy is the ComponentName of the policy in the
651 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
652 * bring the user through adding the device administrator to the system (or
653 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700654 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800655 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
656 * field to provide the user with additional explanation (in addition
657 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800658 *
659 * <p>If your administrator is already active, this will ordinarily return immediately (without
660 * user intervention). However, if your administrator has been updated and is requesting
661 * additional uses-policy flags, the user will be presented with the new list. New policies
662 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800663 */
664 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
665 public static final String ACTION_ADD_DEVICE_ADMIN
666 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700667
Dianne Hackbornd6847842010-01-12 18:14:19 -0800668 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700669 * @hide
670 * Activity action: ask the user to add a new device administrator as the profile owner
Amith Yamasani814e9872015-03-23 14:04:53 -0700671 * for this user. Only system apps can launch this intent.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700672 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700673 * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN}
674 * extra field. This will invoke a UI to bring the user through adding the profile owner admin
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700675 * to remotely control restrictions on the user.
676 *
677 * <p>The intent must be invoked via {@link Activity#startActivityForResult()} to receive the
678 * result of whether or not the user approved the action. If approved, the result will
679 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
680 * as a profile owner.
681 *
682 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
683 * field to provide the user with additional explanation (in addition
684 * to your component's description) about what is being added.
685 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700686 * <p>If there is already a profile owner active or the caller is not a system app, the
687 * operation will return a failure result.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700688 */
689 @SystemApi
690 public static final String ACTION_SET_PROFILE_OWNER
691 = "android.app.action.SET_PROFILE_OWNER";
692
693 /**
694 * @hide
695 * Name of the profile owner admin that controls the user.
696 */
697 @SystemApi
698 public static final String EXTRA_PROFILE_OWNER_NAME
699 = "android.app.extra.PROFILE_OWNER_NAME";
700
701 /**
Jim Miller284b62e2010-06-08 14:27:42 -0700702 * Activity action: send when any policy admin changes a policy.
703 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700704 *
Jim Miller284b62e2010-06-08 14:27:42 -0700705 * @hide
706 */
707 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
708 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
709
710 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800711 * The ComponentName of the administrator component.
712 *
713 * @see #ACTION_ADD_DEVICE_ADMIN
714 */
715 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700716
Dianne Hackbornd6847842010-01-12 18:14:19 -0800717 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800718 * An optional CharSequence providing additional explanation for why the
719 * admin is being added.
720 *
721 * @see #ACTION_ADD_DEVICE_ADMIN
722 */
723 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700724
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800725 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700726 * Activity action: have the user enter a new password. This activity should
727 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
728 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
729 * enter a new password that meets the current requirements. You can use
730 * {@link #isActivePasswordSufficient()} to determine whether you need to
731 * have the user select a new password in order to meet the current
732 * constraints. Upon being resumed from this activity, you can check the new
733 * password characteristics to see if they are sufficient.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800734 */
735 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
736 public static final String ACTION_SET_NEW_PASSWORD
737 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700738
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000739 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000740 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
741 * the parent profile to access intents sent from the managed profile.
742 * That is, when an app in the managed profile calls
743 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
744 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000745 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100746 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000747
748 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000749 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
750 * the managed profile to access intents sent from the parent profile.
751 * That is, when an app in the parent profile calls
752 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
753 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000754 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100755 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700756
Dianne Hackbornd6847842010-01-12 18:14:19 -0800757 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +0100758 * Broadcast action: notify that a new local system update policy has been set by the device
759 * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}.
Rubin Xu8027a4f2015-03-10 17:52:37 +0000760 */
761 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Rubin Xu5faad8e2015-04-20 17:43:48 +0100762 public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED
763 = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED";
Rubin Xu8027a4f2015-03-10 17:52:37 +0000764
Amith Yamasanid49489b2015-04-28 14:00:26 -0700765 /**
766 * Permission policy to prompt user for new permission requests for runtime permissions.
767 * Already granted or denied permissions are not affected by this.
768 */
769 public static final int PERMISSION_POLICY_PROMPT = 0;
770
771 /**
772 * Permission policy to always grant new permission requests for runtime permissions.
773 * Already granted or denied permissions are not affected by this.
774 */
775 public static final int PERMISSION_POLICY_AUTO_GRANT = 1;
776
777 /**
778 * Permission policy to always deny new permission requests for runtime permissions.
779 * Already granted or denied permissions are not affected by this.
780 */
781 public static final int PERMISSION_POLICY_AUTO_DENY = 2;
782
Svet Ganovd8ecc5a2015-05-20 10:45:43 -0700783 /**
784 * Runtime permission state: The user can manage the permission
785 * through the UI.
786 */
787 public static final int PERMISSION_GRANT_STATE_DEFAULT = 0;
788
789 /**
790 * Runtime permission state: The permission is granted to the app
791 * and the user cannot manage the permission through the UI.
792 */
793 public static final int PERMISSION_GRANT_STATE_GRANTED = 1;
794
795 /**
796 * Runtime permission state: The permission is denied to the app
797 * and the user cannot manage the permission through the UI.
798 */
799 public static final int PERMISSION_GRANT_STATE_DENIED = 2;
Rubin Xu8027a4f2015-03-10 17:52:37 +0000800
801 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800802 * Return true if the given administrator component is currently
803 * active (enabled) in the system.
804 */
Robin Lee25e26452015-06-02 09:56:29 -0700805 public boolean isAdminActive(@NonNull ComponentName admin) {
806 return isAdminActiveAsUser(admin, UserHandle.myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100807 }
808
809 /**
810 * @see #isAdminActive(ComponentName)
811 * @hide
812 */
Robin Lee25e26452015-06-02 09:56:29 -0700813 public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800814 if (mService != null) {
815 try {
Robin Lee25e26452015-06-02 09:56:29 -0700816 return mService.isAdminActive(admin, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800817 } catch (RemoteException e) {
818 Log.w(TAG, "Failed talking with device policy service", e);
819 }
820 }
821 return false;
822 }
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800823 /**
824 * Return true if the given administrator component is currently being removed
825 * for the user.
826 * @hide
827 */
Robin Lee25e26452015-06-02 09:56:29 -0700828 public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) {
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800829 if (mService != null) {
830 try {
Robin Lee25e26452015-06-02 09:56:29 -0700831 return mService.isRemovingAdmin(admin, userId);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800832 } catch (RemoteException e) {
833 Log.w(TAG, "Failed talking with device policy service", e);
834 }
835 }
836 return false;
837 }
838
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700839
Dianne Hackbornd6847842010-01-12 18:14:19 -0800840 /**
Robin Lee25e26452015-06-02 09:56:29 -0700841 * Return a list of all currently active device administrators' component
842 * names. If there are no administrators {@code null} may be
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800843 * returned.
844 */
845 public List<ComponentName> getActiveAdmins() {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100846 return getActiveAdminsAsUser(UserHandle.myUserId());
847 }
848
849 /**
850 * @see #getActiveAdmins()
851 * @hide
852 */
853 public List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800854 if (mService != null) {
855 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100856 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800857 } catch (RemoteException e) {
858 Log.w(TAG, "Failed talking with device policy service", e);
859 }
860 }
861 return null;
862 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700863
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800864 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700865 * Used by package administration code to determine if a package can be stopped
866 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800867 * @hide
868 */
869 public boolean packageHasActiveAdmins(String packageName) {
870 if (mService != null) {
871 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700872 return mService.packageHasActiveAdmins(packageName, UserHandle.myUserId());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800873 } catch (RemoteException e) {
874 Log.w(TAG, "Failed talking with device policy service", e);
875 }
876 }
877 return false;
878 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700879
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800880 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800881 * Remove a current administration component. This can only be called
882 * by the application that owns the administration component; if you
883 * try to remove someone else's component, a security exception will be
884 * thrown.
885 */
Robin Lee25e26452015-06-02 09:56:29 -0700886 public void removeActiveAdmin(@NonNull ComponentName admin) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800887 if (mService != null) {
888 try {
Robin Lee25e26452015-06-02 09:56:29 -0700889 mService.removeActiveAdmin(admin, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800890 } catch (RemoteException e) {
891 Log.w(TAG, "Failed talking with device policy service", e);
892 }
893 }
894 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700895
Dianne Hackbornd6847842010-01-12 18:14:19 -0800896 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800897 * Returns true if an administrator has been granted a particular device policy. This can
Robin Lee25e26452015-06-02 09:56:29 -0700898 * be used to check whether the administrator was activated under an earlier set of policies,
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800899 * but requires additional policies after an upgrade.
900 *
901 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be
902 * an active administrator, or an exception will be thrown.
903 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
904 */
Robin Lee25e26452015-06-02 09:56:29 -0700905 public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) {
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800906 if (mService != null) {
907 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700908 return mService.hasGrantedPolicy(admin, usesPolicy, UserHandle.myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800909 } catch (RemoteException e) {
910 Log.w(TAG, "Failed talking with device policy service", e);
911 }
912 }
913 return false;
914 }
915
916 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800917 * Constant for {@link #setPasswordQuality}: the policy has no requirements
918 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800919 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800920 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800921 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700922
Dianne Hackbornd6847842010-01-12 18:14:19 -0800923 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700924 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
925 * recognition technology. This implies technologies that can recognize the identity of
926 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
927 * Note that quality constants are ordered so that higher values are more restrictive.
928 */
929 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
930
931 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800932 * Constant for {@link #setPasswordQuality}: the policy requires some kind
933 * of password, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800934 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800935 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800936 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700937
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800938 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800939 * Constant for {@link #setPasswordQuality}: the user must have entered a
940 * password containing at least numeric characters. Note that quality
941 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800942 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800943 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700944
Dianne Hackbornd6847842010-01-12 18:14:19 -0800945 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800946 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -0800947 * password containing at least numeric characters with no repeating (4444)
948 * or ordered (1234, 4321, 2468) sequences. Note that quality
949 * constants are ordered so that higher values are more restrictive.
950 */
951 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
952
953 /**
954 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700955 * password containing at least alphabetic (or other symbol) characters.
956 * Note that quality constants are ordered so that higher values are more
957 * restrictive.
958 */
959 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700960
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700961 /**
962 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800963 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700964 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800965 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800966 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700967 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700968
Dianne Hackbornd6847842010-01-12 18:14:19 -0800969 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700970 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700971 * password containing at least a letter, a numerical digit and a special
972 * symbol, by default. With this password quality, passwords can be
973 * restricted to contain various sets of characters, like at least an
974 * uppercase letter, etc. These are specified using various methods,
975 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
976 * that quality constants are ordered so that higher values are more
977 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700978 */
979 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
980
981 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800982 * Called by an application that is administering the device to set the
983 * password restrictions it is imposing. After setting this, the user
984 * will not be able to enter a new password that is not at least as
985 * restrictive as what has been set. Note that the current password
986 * will remain until the user has set a new one, so the change does not
987 * take place immediately. To prompt the user for a new password, use
988 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700989 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800990 * <p>Quality constants are ordered so that higher values are more restrictive;
991 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800992 * the user's preference, and any other considerations) is the one that
993 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700994 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800995 * <p>The calling device admin must have requested
996 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
997 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700998 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800999 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001000 * @param quality The new desired quality. One of
1001 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Jim Miller85516d02014-01-31 17:08:37 -08001002 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
1003 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1004 * or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001005 */
Robin Lee25e26452015-06-02 09:56:29 -07001006 public void setPasswordQuality(@NonNull ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001007 if (mService != null) {
1008 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001009 mService.setPasswordQuality(admin, quality);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001010 } catch (RemoteException e) {
1011 Log.w(TAG, "Failed talking with device policy service", e);
1012 }
1013 }
1014 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001015
Dianne Hackbornd6847842010-01-12 18:14:19 -08001016 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001017 * Retrieve the current minimum password quality for all admins of this user
1018 * and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001019 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001020 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001021 */
Robin Lee25e26452015-06-02 09:56:29 -07001022 public int getPasswordQuality(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001023 return getPasswordQuality(admin, UserHandle.myUserId());
1024 }
1025
1026 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001027 public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001028 if (mService != null) {
1029 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001030 return mService.getPasswordQuality(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001031 } catch (RemoteException e) {
1032 Log.w(TAG, "Failed talking with device policy service", e);
1033 }
1034 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001035 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001036 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001037
Dianne Hackbornd6847842010-01-12 18:14:19 -08001038 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001039 * Called by an application that is administering the device to set the
1040 * minimum allowed password length. After setting this, the user
1041 * will not be able to enter a new password that is not at least as
1042 * restrictive as what has been set. Note that the current password
1043 * will remain until the user has set a new one, so the change does not
1044 * take place immediately. To prompt the user for a new password, use
1045 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1046 * constraint is only imposed if the administrator has also requested either
Jim Miller85516d02014-01-31 17:08:37 -08001047 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
1048 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC},
1049 * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001050 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001051 * <p>The calling device admin must have requested
1052 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1053 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001054 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001055 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001056 * @param length The new desired minimum password length. A value of 0
1057 * means there is no restriction.
1058 */
Robin Lee25e26452015-06-02 09:56:29 -07001059 public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001060 if (mService != null) {
1061 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001062 mService.setPasswordMinimumLength(admin, length);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001063 } catch (RemoteException e) {
1064 Log.w(TAG, "Failed talking with device policy service", e);
1065 }
1066 }
1067 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001068
Dianne Hackbornd6847842010-01-12 18:14:19 -08001069 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001070 * Retrieve the current minimum password length for all admins of this
1071 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001072 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001073 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001074 */
Robin Lee25e26452015-06-02 09:56:29 -07001075 public int getPasswordMinimumLength(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001076 return getPasswordMinimumLength(admin, UserHandle.myUserId());
1077 }
1078
1079 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001080 public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001081 if (mService != null) {
1082 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001083 return mService.getPasswordMinimumLength(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001084 } catch (RemoteException e) {
1085 Log.w(TAG, "Failed talking with device policy service", e);
1086 }
1087 }
1088 return 0;
1089 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001090
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001091 /**
1092 * Called by an application that is administering the device to set the
1093 * minimum number of upper case letters required in the password. After
1094 * setting this, the user will not be able to enter a new password that is
1095 * not at least as restrictive as what has been set. Note that the current
1096 * password will remain until the user has set a new one, so the change does
1097 * not take place immediately. To prompt the user for a new password, use
1098 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1099 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001100 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1101 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001102 * <p>
1103 * The calling device admin must have requested
1104 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1105 * this method; if it has not, a security exception will be thrown.
1106 *
1107 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1108 * with.
1109 * @param length The new desired minimum number of upper case letters
1110 * required in the password. A value of 0 means there is no
1111 * restriction.
1112 */
Robin Lee25e26452015-06-02 09:56:29 -07001113 public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001114 if (mService != null) {
1115 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001116 mService.setPasswordMinimumUpperCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001117 } catch (RemoteException e) {
1118 Log.w(TAG, "Failed talking with device policy service", e);
1119 }
1120 }
1121 }
1122
1123 /**
1124 * Retrieve the current number of upper case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001125 * password for all admins of this user and its profiles or a particular one.
1126 * This is the same value as set by
1127 * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001128 * and only applies when the password quality is
1129 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001130 *
Robin Lee25e26452015-06-02 09:56:29 -07001131 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001132 * aggregate all admins.
1133 * @return The minimum number of upper case letters required in the
1134 * password.
1135 */
Robin Lee25e26452015-06-02 09:56:29 -07001136 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001137 return getPasswordMinimumUpperCase(admin, UserHandle.myUserId());
1138 }
1139
1140 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001141 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001142 if (mService != null) {
1143 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001144 return mService.getPasswordMinimumUpperCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001145 } catch (RemoteException e) {
1146 Log.w(TAG, "Failed talking with device policy service", e);
1147 }
1148 }
1149 return 0;
1150 }
1151
1152 /**
1153 * Called by an application that is administering the device to set the
1154 * minimum number of lower case letters required in the password. After
1155 * setting this, the user will not be able to enter a new password that is
1156 * not at least as restrictive as what has been set. Note that the current
1157 * password will remain until the user has set a new one, so the change does
1158 * not take place immediately. To prompt the user for a new password, use
1159 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1160 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001161 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1162 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001163 * <p>
1164 * The calling device admin must have requested
1165 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1166 * this method; if it has not, a security exception will be thrown.
1167 *
1168 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1169 * with.
1170 * @param length The new desired minimum number of lower case letters
1171 * required in the password. A value of 0 means there is no
1172 * restriction.
1173 */
Robin Lee25e26452015-06-02 09:56:29 -07001174 public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001175 if (mService != null) {
1176 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001177 mService.setPasswordMinimumLowerCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001178 } catch (RemoteException e) {
1179 Log.w(TAG, "Failed talking with device policy service", e);
1180 }
1181 }
1182 }
1183
1184 /**
1185 * Retrieve the current number of lower case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001186 * password for all admins of this user and its profiles or a particular one.
1187 * This is the same value as set by
1188 * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001189 * and only applies when the password quality is
1190 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001191 *
Robin Lee25e26452015-06-02 09:56:29 -07001192 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001193 * aggregate all admins.
1194 * @return The minimum number of lower case letters required in the
1195 * password.
1196 */
Robin Lee25e26452015-06-02 09:56:29 -07001197 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001198 return getPasswordMinimumLowerCase(admin, UserHandle.myUserId());
1199 }
1200
1201 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001202 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001203 if (mService != null) {
1204 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001205 return mService.getPasswordMinimumLowerCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001206 } catch (RemoteException e) {
1207 Log.w(TAG, "Failed talking with device policy service", e);
1208 }
1209 }
1210 return 0;
1211 }
1212
1213 /**
1214 * Called by an application that is administering the device to set the
1215 * minimum number of letters required in the password. After setting this,
1216 * the user will not be able to enter a new password that is not at least as
1217 * restrictive as what has been set. Note that the current password will
1218 * remain until the user has set a new one, so the change does not take
1219 * place immediately. To prompt the user for a new password, use
1220 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1221 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001222 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1223 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001224 * <p>
1225 * The calling device admin must have requested
1226 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1227 * this method; if it has not, a security exception will be thrown.
1228 *
1229 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1230 * with.
1231 * @param length The new desired minimum number of letters required in the
1232 * password. A value of 0 means there is no restriction.
1233 */
Robin Lee25e26452015-06-02 09:56:29 -07001234 public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001235 if (mService != null) {
1236 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001237 mService.setPasswordMinimumLetters(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001238 } catch (RemoteException e) {
1239 Log.w(TAG, "Failed talking with device policy service", e);
1240 }
1241 }
1242 }
1243
1244 /**
1245 * Retrieve the current number of letters required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001246 * admins or a particular one. This is the same value as
1247 * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)}
1248 * and only applies when the password quality is
1249 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001250 *
Robin Lee25e26452015-06-02 09:56:29 -07001251 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001252 * aggregate all admins.
1253 * @return The minimum number of letters required in the password.
1254 */
Robin Lee25e26452015-06-02 09:56:29 -07001255 public int getPasswordMinimumLetters(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001256 return getPasswordMinimumLetters(admin, UserHandle.myUserId());
1257 }
1258
1259 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001260 public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001261 if (mService != null) {
1262 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001263 return mService.getPasswordMinimumLetters(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001264 } catch (RemoteException e) {
1265 Log.w(TAG, "Failed talking with device policy service", e);
1266 }
1267 }
1268 return 0;
1269 }
1270
1271 /**
1272 * Called by an application that is administering the device to set the
1273 * minimum number of numerical digits required in the password. After
1274 * setting this, the user will not be able to enter a new password that is
1275 * not at least as restrictive as what has been set. Note that the current
1276 * password will remain until the user has set a new one, so the change does
1277 * not take place immediately. To prompt the user for a new password, use
1278 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1279 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001280 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1281 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001282 * <p>
1283 * The calling device admin must have requested
1284 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1285 * this method; if it has not, a security exception will be thrown.
1286 *
1287 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1288 * with.
1289 * @param length The new desired minimum number of numerical digits required
1290 * in the password. A value of 0 means there is no restriction.
1291 */
Robin Lee25e26452015-06-02 09:56:29 -07001292 public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001293 if (mService != null) {
1294 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001295 mService.setPasswordMinimumNumeric(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001296 } catch (RemoteException e) {
1297 Log.w(TAG, "Failed talking with device policy service", e);
1298 }
1299 }
1300 }
1301
1302 /**
1303 * Retrieve the current number of numerical digits required in the password
Jessica Hummel91da58d2014-04-10 17:39:43 +01001304 * for all admins of this user and its profiles or a particular one.
1305 * This is the same value as set by
1306 * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001307 * and only applies when the password quality is
1308 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001309 *
Robin Lee25e26452015-06-02 09:56:29 -07001310 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001311 * aggregate all admins.
1312 * @return The minimum number of numerical digits required in the password.
1313 */
Robin Lee25e26452015-06-02 09:56:29 -07001314 public int getPasswordMinimumNumeric(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001315 return getPasswordMinimumNumeric(admin, UserHandle.myUserId());
1316 }
1317
1318 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001319 public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001320 if (mService != null) {
1321 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001322 return mService.getPasswordMinimumNumeric(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001323 } catch (RemoteException e) {
1324 Log.w(TAG, "Failed talking with device policy service", e);
1325 }
1326 }
1327 return 0;
1328 }
1329
1330 /**
1331 * Called by an application that is administering the device to set the
1332 * minimum number of symbols required in the password. After setting this,
1333 * the user will not be able to enter a new password that is not at least as
1334 * restrictive as what has been set. Note that the current password will
1335 * remain until the user has set a new one, so the change does not take
1336 * place immediately. To prompt the user for a new password, use
1337 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1338 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001339 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1340 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001341 * <p>
1342 * The calling device admin must have requested
1343 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1344 * this method; if it has not, a security exception will be thrown.
1345 *
1346 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1347 * with.
1348 * @param length The new desired minimum number of symbols required in the
1349 * password. A value of 0 means there is no restriction.
1350 */
Robin Lee25e26452015-06-02 09:56:29 -07001351 public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001352 if (mService != null) {
1353 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001354 mService.setPasswordMinimumSymbols(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001355 } catch (RemoteException e) {
1356 Log.w(TAG, "Failed talking with device policy service", e);
1357 }
1358 }
1359 }
1360
1361 /**
1362 * Retrieve the current number of symbols required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001363 * admins or a particular one. This is the same value as
1364 * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)}
1365 * and only applies when the password quality is
1366 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001367 *
Robin Lee25e26452015-06-02 09:56:29 -07001368 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001369 * aggregate all admins.
1370 * @return The minimum number of symbols required in the password.
1371 */
Robin Lee25e26452015-06-02 09:56:29 -07001372 public int getPasswordMinimumSymbols(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001373 return getPasswordMinimumSymbols(admin, UserHandle.myUserId());
1374 }
1375
1376 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001377 public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001378 if (mService != null) {
1379 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001380 return mService.getPasswordMinimumSymbols(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001381 } catch (RemoteException e) {
1382 Log.w(TAG, "Failed talking with device policy service", e);
1383 }
1384 }
1385 return 0;
1386 }
1387
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001388 /**
1389 * Called by an application that is administering the device to set the
1390 * minimum number of non-letter characters (numerical digits or symbols)
1391 * required in the password. After setting this, the user will not be able
1392 * to enter a new password that is not at least as restrictive as what has
1393 * been set. Note that the current password will remain until the user has
1394 * set a new one, so the change does not take place immediately. To prompt
1395 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after
1396 * setting this value. This constraint is only imposed if the administrator
1397 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1398 * {@link #setPasswordQuality}. The default value is 0.
1399 * <p>
1400 * The calling device admin must have requested
1401 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1402 * this method; if it has not, a security exception will be thrown.
1403 *
1404 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1405 * with.
1406 * @param length The new desired minimum number of letters required in the
1407 * password. A value of 0 means there is no restriction.
1408 */
Robin Lee25e26452015-06-02 09:56:29 -07001409 public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001410 if (mService != null) {
1411 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001412 mService.setPasswordMinimumNonLetter(admin, length);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001413 } catch (RemoteException e) {
1414 Log.w(TAG, "Failed talking with device policy service", e);
1415 }
1416 }
1417 }
1418
1419 /**
1420 * Retrieve the current number of non-letter characters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001421 * password for all admins of this user and its profiles or a particular one.
1422 * This is the same value as set by
1423 * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001424 * and only applies when the password quality is
1425 * {@link #PASSWORD_QUALITY_COMPLEX}.
1426 *
Robin Lee25e26452015-06-02 09:56:29 -07001427 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001428 * aggregate all admins.
1429 * @return The minimum number of letters required in the password.
1430 */
Robin Lee25e26452015-06-02 09:56:29 -07001431 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001432 return getPasswordMinimumNonLetter(admin, UserHandle.myUserId());
1433 }
1434
1435 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001436 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001437 if (mService != null) {
1438 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001439 return mService.getPasswordMinimumNonLetter(admin, userHandle);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001440 } catch (RemoteException e) {
1441 Log.w(TAG, "Failed talking with device policy service", e);
1442 }
1443 }
1444 return 0;
1445 }
1446
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001447 /**
1448 * Called by an application that is administering the device to set the length
1449 * of the password history. After setting this, the user will not be able to
1450 * enter a new password that is the same as any password in the history. Note
1451 * that the current password will remain until the user has set a new one, so
1452 * the change does not take place immediately. To prompt the user for a new
1453 * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
1454 * This constraint is only imposed if the administrator has also requested
Jim Miller85516d02014-01-31 17:08:37 -08001455 * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}
1456 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1457 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001458 *
1459 * <p>
1460 * The calling device admin must have requested
1461 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
1462 * method; if it has not, a security exception will be thrown.
1463 *
1464 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1465 * with.
1466 * @param length The new desired length of password history. A value of 0
1467 * means there is no restriction.
1468 */
Robin Lee25e26452015-06-02 09:56:29 -07001469 public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001470 if (mService != null) {
1471 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001472 mService.setPasswordHistoryLength(admin, length);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001473 } catch (RemoteException e) {
1474 Log.w(TAG, "Failed talking with device policy service", e);
1475 }
1476 }
1477 }
1478
1479 /**
Jim Millera4e28d12010-11-08 16:15:47 -08001480 * Called by a device admin to set the password expiration timeout. Calling this method
1481 * will restart the countdown for password expiration for the given admin, as will changing
1482 * the device password (for all admins).
1483 *
1484 * <p>The provided timeout is the time delta in ms and will be added to the current time.
1485 * For example, to have the password expire 5 days from now, timeout would be
1486 * 5 * 86400 * 1000 = 432000000 ms for timeout.
1487 *
1488 * <p>To disable password expiration, a value of 0 may be used for timeout.
1489 *
Jim Millera4e28d12010-11-08 16:15:47 -08001490 * <p>The calling device admin must have requested
1491 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
1492 * method; if it has not, a security exception will be thrown.
1493 *
Jessica Hummel9da60392014-05-21 12:32:57 +01001494 * <p> Note that setting the password will automatically reset the expiration time for all
1495 * active admins. Active admins do not need to explicitly call this method in that case.
1496 *
Jim Millera4e28d12010-11-08 16:15:47 -08001497 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1498 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
1499 * means there is no restriction (unlimited).
1500 */
Robin Lee25e26452015-06-02 09:56:29 -07001501 public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) {
Jim Millera4e28d12010-11-08 16:15:47 -08001502 if (mService != null) {
1503 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001504 mService.setPasswordExpirationTimeout(admin, timeout);
Jim Millera4e28d12010-11-08 16:15:47 -08001505 } catch (RemoteException e) {
1506 Log.w(TAG, "Failed talking with device policy service", e);
1507 }
1508 }
1509 }
1510
1511 /**
Jim Miller6b857682011-02-16 16:27:41 -08001512 * Get the password expiration timeout for the given admin. The expiration timeout is the
1513 * recurring expiration timeout provided in the call to
1514 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
Robin Lee25e26452015-06-02 09:56:29 -07001515 * aggregate of all policy administrators if {@code admin} is null.
Jim Millera4e28d12010-11-08 16:15:47 -08001516 *
Robin Lee25e26452015-06-02 09:56:29 -07001517 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001518 * @return The timeout for the given admin or the minimum of all timeouts
1519 */
Robin Lee25e26452015-06-02 09:56:29 -07001520 public long getPasswordExpirationTimeout(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001521 if (mService != null) {
1522 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001523 return mService.getPasswordExpirationTimeout(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001524 } catch (RemoteException e) {
1525 Log.w(TAG, "Failed talking with device policy service", e);
1526 }
1527 }
1528 return 0;
1529 }
1530
1531 /**
1532 * Get the current password expiration time for the given admin or an aggregate of
Jessica Hummel91da58d2014-04-10 17:39:43 +01001533 * all admins of this user and its profiles if admin is null. If the password is
1534 * expired, this will return the time since the password expired as a negative number.
1535 * If admin is null, then a composite of all expiration timeouts is returned
1536 * - which will be the minimum of all timeouts.
Jim Millera4e28d12010-11-08 16:15:47 -08001537 *
Robin Lee25e26452015-06-02 09:56:29 -07001538 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001539 * @return The password expiration time, in ms.
1540 */
Robin Lee25e26452015-06-02 09:56:29 -07001541 public long getPasswordExpiration(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001542 if (mService != null) {
1543 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001544 return mService.getPasswordExpiration(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001545 } catch (RemoteException e) {
1546 Log.w(TAG, "Failed talking with device policy service", e);
1547 }
1548 }
1549 return 0;
1550 }
1551
1552 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001553 * Retrieve the current password history length for all admins of this
1554 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001555 * @param admin The name of the admin component to check, or {@code null} to aggregate
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001556 * all admins.
1557 * @return The length of the password history
1558 */
Robin Lee25e26452015-06-02 09:56:29 -07001559 public int getPasswordHistoryLength(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001560 return getPasswordHistoryLength(admin, UserHandle.myUserId());
1561 }
1562
1563 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001564 public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001565 if (mService != null) {
1566 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001567 return mService.getPasswordHistoryLength(admin, userHandle);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001568 } catch (RemoteException e) {
1569 Log.w(TAG, "Failed talking with device policy service", e);
1570 }
1571 }
1572 return 0;
1573 }
1574
Dianne Hackbornd6847842010-01-12 18:14:19 -08001575 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001576 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001577 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08001578 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001579 * @return Returns the maximum length that the user can enter.
1580 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001581 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001582 // Kind-of arbitrary.
1583 return 16;
1584 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001585
Dianne Hackborn254cb442010-01-27 19:23:59 -08001586 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001587 * Determine whether the current password the user has set is sufficient
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001588 * to meet the policy requirements (quality, minimum length) that have been
Jessica Hummel91da58d2014-04-10 17:39:43 +01001589 * requested by the admins of this user and its profiles.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001590 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001591 * <p>The calling device admin must have requested
1592 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1593 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001594 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001595 * @return Returns true if the password meets the current requirements, else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001596 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001597 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001598 if (mService != null) {
1599 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001600 return mService.isActivePasswordSufficient(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001601 } catch (RemoteException e) {
1602 Log.w(TAG, "Failed talking with device policy service", e);
1603 }
1604 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001605 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001606 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001607
Dianne Hackbornd6847842010-01-12 18:14:19 -08001608 /**
1609 * Retrieve the number of times the user has failed at entering a
1610 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001611 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001612 * <p>The calling device admin must have requested
1613 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
1614 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001615 */
1616 public int getCurrentFailedPasswordAttempts() {
1617 if (mService != null) {
1618 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001619 return mService.getCurrentFailedPasswordAttempts(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001620 } catch (RemoteException e) {
1621 Log.w(TAG, "Failed talking with device policy service", e);
1622 }
1623 }
1624 return -1;
1625 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001626
1627 /**
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001628 * Queries whether {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001629 *
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001630 * @return true if RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001631 * @hide
1632 */
1633 public boolean getDoNotAskCredentialsOnBoot() {
1634 if (mService != null) {
1635 try {
1636 return mService.getDoNotAskCredentialsOnBoot();
1637 } catch (RemoteException e) {
1638 Log.w(TAG, "Failed to call getDoNotAskCredentialsOnBoot()", e);
1639 }
1640 }
1641 return false;
1642 }
1643
1644 /**
Andrew Stadler88209d12010-02-08 22:59:36 -08001645 * Setting this to a value greater than zero enables a built-in policy
1646 * that will perform a device wipe after too many incorrect
1647 * device-unlock passwords have been entered. This built-in policy combines
1648 * watching for failed passwords and wiping the device, and requires
1649 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001650 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001651 *
Andrew Stadler88209d12010-02-08 22:59:36 -08001652 * <p>To implement any other policy (e.g. wiping data for a particular
1653 * application only, erasing or revoking credentials, or reporting the
1654 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001655 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -08001656 * instead. Do not use this API, because if the maximum count is reached,
1657 * the device will be wiped immediately, and your callback will not be invoked.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001658 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001659 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001660 * @param num The number of failed password attempts at which point the
1661 * device will wipe its data.
1662 */
Robin Lee25e26452015-06-02 09:56:29 -07001663 public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001664 if (mService != null) {
1665 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001666 mService.setMaximumFailedPasswordsForWipe(admin, num);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001667 } catch (RemoteException e) {
1668 Log.w(TAG, "Failed talking with device policy service", e);
1669 }
1670 }
1671 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001672
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001673 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001674 * Retrieve the current maximum number of login attempts that are allowed
Jessica Hummel91da58d2014-04-10 17:39:43 +01001675 * before the device wipes itself, for all admins of this user and its profiles
Dianne Hackborn254cb442010-01-27 19:23:59 -08001676 * or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001677 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001678 * all admins.
1679 */
Robin Lee25e26452015-06-02 09:56:29 -07001680 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001681 return getMaximumFailedPasswordsForWipe(admin, UserHandle.myUserId());
1682 }
1683
1684 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001685 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001686 if (mService != null) {
1687 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001688 return mService.getMaximumFailedPasswordsForWipe(admin, userHandle);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001689 } catch (RemoteException e) {
1690 Log.w(TAG, "Failed talking with device policy service", e);
1691 }
1692 }
1693 return 0;
1694 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001695
Dianne Hackborn254cb442010-01-27 19:23:59 -08001696 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07001697 * Returns the profile with the smallest maximum failed passwords for wipe,
1698 * for the given user. So for primary user, it might return the primary or
1699 * a managed profile. For a secondary user, it would be the same as the
1700 * user passed in.
1701 * @hide Used only by Keyguard
1702 */
1703 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
1704 if (mService != null) {
1705 try {
1706 return mService.getProfileWithMinimumFailedPasswordsForWipe(userHandle);
1707 } catch (RemoteException e) {
1708 Log.w(TAG, "Failed talking with device policy service", e);
1709 }
1710 }
1711 return UserHandle.USER_NULL;
1712 }
1713
1714 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001715 * Flag for {@link #resetPassword}: don't allow other admins to change
1716 * the password again until the user has entered it.
1717 */
1718 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001719
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001720 /**
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001721 * Flag for {@link #resetPassword}: don't ask for user credentials on device boot.
1722 * If the flag is set, the device can be booted without asking for user password.
1723 * The absence of this flag does not change the current boot requirements. This flag
1724 * can be set by the device owner only. If the app is not the device owner, the flag
1725 * is ignored. Once the flag is set, it cannot be reverted back without resetting the
1726 * device to factory defaults.
1727 */
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001728 public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002;
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001729
1730 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001731 * Force a new device unlock password (the password needed to access the
1732 * entire device, not for individual accounts) on the user. This takes
1733 * effect immediately.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001734 * The given password must be sufficient for the
1735 * current password quality and length constraints as returned by
1736 * {@link #getPasswordQuality(ComponentName)} and
1737 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
1738 * these constraints, then it will be rejected and false returned. Note
1739 * that the password may be a stronger quality (containing alphanumeric
1740 * characters when the requested quality is only numeric), in which case
1741 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001742 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001743 * <p>Calling with a null or empty password will clear any existing PIN,
1744 * pattern or password if the current password constraints allow it.
1745 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001746 * <p>The calling device admin must have requested
1747 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
1748 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001749 *
Amith Yamasani242f4b12014-10-14 16:06:13 -07001750 * <p>Calling this from a managed profile will throw a security exception.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001751 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001752 * @param password The new password for the user. Null or empty clears the password.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001753 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001754 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001755 * @return Returns true if the password was applied, or false if it is
1756 * not acceptable for the current constraints.
1757 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001758 public boolean resetPassword(String password, int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001759 if (mService != null) {
1760 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001761 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001762 } catch (RemoteException e) {
1763 Log.w(TAG, "Failed talking with device policy service", e);
1764 }
1765 }
1766 return false;
1767 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001768
Dianne Hackbornd6847842010-01-12 18:14:19 -08001769 /**
1770 * Called by an application that is administering the device to set the
1771 * maximum time for user activity until the device will lock. This limits
1772 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001773 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001774 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -08001775 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001776 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001777 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001778 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001779 * @param timeMs The new desired maximum time to lock in milliseconds.
1780 * A value of 0 means there is no restriction.
1781 */
Robin Lee25e26452015-06-02 09:56:29 -07001782 public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001783 if (mService != null) {
1784 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001785 mService.setMaximumTimeToLock(admin, timeMs);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001786 } catch (RemoteException e) {
1787 Log.w(TAG, "Failed talking with device policy service", e);
1788 }
1789 }
1790 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001791
Dianne Hackbornd6847842010-01-12 18:14:19 -08001792 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001793 * Retrieve the current maximum time to unlock for all admins of this user
1794 * and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001795 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001796 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07001797 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07001798 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001799 */
Robin Lee25e26452015-06-02 09:56:29 -07001800 public long getMaximumTimeToLock(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001801 return getMaximumTimeToLock(admin, UserHandle.myUserId());
1802 }
1803
1804 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001805 public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001806 if (mService != null) {
1807 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001808 return mService.getMaximumTimeToLock(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001809 } catch (RemoteException e) {
1810 Log.w(TAG, "Failed talking with device policy service", e);
1811 }
1812 }
1813 return 0;
1814 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001815
Dianne Hackbornd6847842010-01-12 18:14:19 -08001816 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001817 * Make the device lock immediately, as if the lock screen timeout has
1818 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001819 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001820 * <p>The calling device admin must have requested
1821 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
1822 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001823 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001824 public void lockNow() {
1825 if (mService != null) {
1826 try {
1827 mService.lockNow();
1828 } catch (RemoteException e) {
1829 Log.w(TAG, "Failed talking with device policy service", e);
1830 }
1831 }
1832 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001833
Dianne Hackbornd6847842010-01-12 18:14:19 -08001834 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07001835 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001836 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07001837 */
1838 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
1839
1840 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001841 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
1842 * data.
1843 *
Paul Crowley2934b262014-12-02 11:21:13 +00001844 * <p>This flag may only be set by device owner admins; if it is set by
1845 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001846 */
1847 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
1848
1849 /**
Robin Lee85bd63f2015-02-10 11:51:00 +00001850 * Ask the user data be wiped. Wiping the primary user will cause the
1851 * device to reboot, erasing all user data while next booting up.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001852 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001853 * <p>The calling device admin must have requested
1854 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
1855 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001856 *
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001857 * @param flags Bit mask of additional options: currently supported flags
1858 * are {@link #WIPE_EXTERNAL_STORAGE} and
1859 * {@link #WIPE_RESET_PROTECTION_DATA}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001860 */
1861 public void wipeData(int flags) {
1862 if (mService != null) {
1863 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001864 mService.wipeData(flags, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001865 } catch (RemoteException e) {
1866 Log.w(TAG, "Failed talking with device policy service", e);
1867 }
1868 }
1869 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001870
Dianne Hackbornd6847842010-01-12 18:14:19 -08001871 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001872 * Called by an application that is administering the device to set the
1873 * global proxy and exclusion list.
1874 * <p>
1875 * The calling device admin must have requested
1876 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
1877 * this method; if it has not, a security exception will be thrown.
1878 * Only the first device admin can set the proxy. If a second admin attempts
1879 * to set the proxy, the {@link ComponentName} of the admin originally setting the
Robin Lee25e26452015-06-02 09:56:29 -07001880 * proxy will be returned. If successful in setting the proxy, {@code null} will
Oscar Montemayor69238c62010-08-03 10:51:06 -07001881 * be returned.
1882 * The method can be called repeatedly by the device admin alrady setting the
1883 * proxy to update the proxy and exclusion list.
1884 *
Robin Lee25e26452015-06-02 09:56:29 -07001885 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Oscar Montemayor69238c62010-08-03 10:51:06 -07001886 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
1887 * Pass Proxy.NO_PROXY to reset the proxy.
1888 * @param exclusionList a list of domains to be excluded from the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07001889 * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName}
1890 * of the device admin that sets the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08001891 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001892 */
Robin Lee25e26452015-06-02 09:56:29 -07001893 public ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec,
Oscar Montemayor69238c62010-08-03 10:51:06 -07001894 List<String> exclusionList ) {
1895 if (proxySpec == null) {
1896 throw new NullPointerException();
1897 }
1898 if (mService != null) {
1899 try {
1900 String hostSpec;
1901 String exclSpec;
1902 if (proxySpec.equals(Proxy.NO_PROXY)) {
1903 hostSpec = null;
1904 exclSpec = null;
1905 } else {
1906 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
1907 throw new IllegalArgumentException();
1908 }
1909 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
1910 String hostName = sa.getHostName();
1911 int port = sa.getPort();
1912 StringBuilder hostBuilder = new StringBuilder();
1913 hostSpec = hostBuilder.append(hostName)
1914 .append(":").append(Integer.toString(port)).toString();
1915 if (exclusionList == null) {
1916 exclSpec = "";
1917 } else {
1918 StringBuilder listBuilder = new StringBuilder();
1919 boolean firstDomain = true;
1920 for (String exclDomain : exclusionList) {
1921 if (!firstDomain) {
1922 listBuilder = listBuilder.append(",");
1923 } else {
1924 firstDomain = false;
1925 }
1926 listBuilder = listBuilder.append(exclDomain.trim());
1927 }
1928 exclSpec = listBuilder.toString();
1929 }
Yuhao Zheng90704842014-02-28 17:22:45 -08001930 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
1931 != android.net.Proxy.PROXY_VALID)
1932 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07001933 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001934 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07001935 } catch (RemoteException e) {
1936 Log.w(TAG, "Failed talking with device policy service", e);
1937 }
1938 }
1939 return null;
1940 }
1941
1942 /**
Jason Monk03bc9912014-05-13 09:44:57 -04001943 * Set a network-independent global HTTP proxy. This is not normally what you want
1944 * for typical HTTP proxies - they are generally network dependent. However if you're
1945 * doing something unusual like general internal filtering this may be useful. On
1946 * a private network where the proxy is not accessible, you may break HTTP using this.
1947 *
1948 * <p>This method requires the caller to be the device owner.
1949 *
1950 * <p>This proxy is only a recommendation and it is possible that some apps will ignore it.
1951 * @see ProxyInfo
1952 *
1953 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1954 * with.
1955 * @param proxyInfo The a {@link ProxyInfo} object defining the new global
1956 * HTTP proxy. A {@code null} value will clear the global HTTP proxy.
1957 */
Robin Lee25e26452015-06-02 09:56:29 -07001958 public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo
1959 proxyInfo) {
Jason Monk03bc9912014-05-13 09:44:57 -04001960 if (mService != null) {
1961 try {
1962 mService.setRecommendedGlobalProxy(admin, proxyInfo);
1963 } catch (RemoteException e) {
1964 Log.w(TAG, "Failed talking with device policy service", e);
1965 }
1966 }
1967 }
1968
1969 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001970 * Returns the component name setting the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07001971 * @return ComponentName object of the device admin that set the global proxy, or {@code null}
1972 * if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08001973 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001974 */
1975 public ComponentName getGlobalProxyAdmin() {
1976 if (mService != null) {
1977 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001978 return mService.getGlobalProxyAdmin(UserHandle.myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07001979 } catch (RemoteException e) {
1980 Log.w(TAG, "Failed talking with device policy service", e);
1981 }
1982 }
1983 return null;
1984 }
1985
1986 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001987 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001988 * indicating that encryption is not supported.
1989 */
1990 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
1991
1992 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001993 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001994 * indicating that encryption is supported, but is not currently active.
1995 */
1996 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
1997
1998 /**
Robin Lee3795fb02015-02-16 14:17:23 +00001999 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002000 * indicating that encryption is not currently active, but is currently
2001 * being activated. This is only reported by devices that support
2002 * encryption of data and only when the storage is currently
2003 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
2004 * to become encrypted will never return this value.
2005 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002006 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002007
2008 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002009 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002010 * indicating that encryption is active.
2011 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002012 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002013
2014 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002015 * Result code for {@link #getStorageEncryptionStatus}:
2016 * indicating that encryption is active, but an encryption key has not
2017 * been set by the user.
2018 */
2019 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
2020
2021 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002022 * Activity action: begin the process of encrypting data on the device. This activity should
2023 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
2024 * After resuming from this activity, use {@link #getStorageEncryption}
2025 * to check encryption status. However, on some devices this activity may never return, as
2026 * it may trigger a reboot and in some cases a complete data wipe of the device.
2027 */
2028 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
2029 public static final String ACTION_START_ENCRYPTION
2030 = "android.app.action.START_ENCRYPTION";
2031
2032 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07002033 * Widgets are enabled in keyguard
2034 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002035 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07002036
2037 /**
Jim Miller50e62182014-04-23 17:25:00 -07002038 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07002039 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002040 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
2041
2042 /**
2043 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
2044 */
2045 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
2046
2047 /**
Jim Miller50e62182014-04-23 17:25:00 -07002048 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2049 */
2050 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
2051
2052 /**
2053 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2054 */
2055 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
2056
2057 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02002058 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07002059 * (e.g. PIN/Pattern/Password).
2060 */
2061 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
2062
2063 /**
Jim Miller06e34502014-07-17 14:46:05 -07002064 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
2065 */
2066 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
2067
2068 /**
Jim Miller35207742012-11-02 15:33:20 -07002069 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07002070 */
2071 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07002072
2073 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002074 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002075 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002076 *
2077 * <p>When multiple device administrators attempt to control device
2078 * encryption, the most secure, supported setting will always be
2079 * used. If any device administrator requests device encryption,
2080 * it will be enabled; Conversely, if a device administrator
2081 * attempts to disable device encryption while another
2082 * device administrator has enabled it, the call to disable will
2083 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
2084 *
2085 * <p>This policy controls encryption of the secure (application data) storage area. Data
Andy Stadler50c294f2011-03-07 19:13:42 -08002086 * written to other storage areas may or may not be encrypted, and this policy does not require
2087 * or control the encryption of any other storage areas.
2088 * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is
2089 * {@code true}, then the directory returned by
2090 * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk
2091 * within the encrypted storage area.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002092 *
2093 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
2094 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
2095 * the encryption key may not be fully secured. For maximum security, the administrator should
2096 * also require (and check for) a pattern, PIN, or password.
2097 *
2098 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2099 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08002100 * @return the new request status (for all active admins) - will be one of
2101 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
2102 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
2103 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002104 */
Robin Lee25e26452015-06-02 09:56:29 -07002105 public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002106 if (mService != null) {
2107 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002108 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002109 } catch (RemoteException e) {
2110 Log.w(TAG, "Failed talking with device policy service", e);
2111 }
2112 }
2113 return ENCRYPTION_STATUS_UNSUPPORTED;
2114 }
2115
2116 /**
2117 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002118 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002119 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08002120 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
2121 * this will return the requested encryption setting as an aggregate of all active
2122 * administrators.
2123 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002124 */
Robin Lee25e26452015-06-02 09:56:29 -07002125 public boolean getStorageEncryption(@Nullable ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002126 if (mService != null) {
2127 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002128 return mService.getStorageEncryption(admin, UserHandle.myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002129 } catch (RemoteException e) {
2130 Log.w(TAG, "Failed talking with device policy service", e);
2131 }
2132 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08002133 return false;
2134 }
2135
2136 /**
2137 * Called by an application that is administering the device to
2138 * determine the current encryption status of the device.
2139 *
2140 * Depending on the returned status code, the caller may proceed in different
2141 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
2142 * storage system does not support encryption. If the
2143 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
2144 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00002145 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
2146 * storage system has enabled encryption but no password is set so further action
2147 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
Andy Stadler22dbfda2011-01-17 12:47:31 -08002148 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
2149 *
Robin Lee7e678712014-07-24 16:41:31 +01002150 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08002151 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00002152 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
2153 * or {@link #ENCRYPTION_STATUS_ACTIVE}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08002154 */
2155 public int getStorageEncryptionStatus() {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002156 return getStorageEncryptionStatus(UserHandle.myUserId());
2157 }
2158
2159 /** @hide per-user version */
2160 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08002161 if (mService != null) {
2162 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002163 return mService.getStorageEncryptionStatus(userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08002164 } catch (RemoteException e) {
2165 Log.w(TAG, "Failed talking with device policy service", e);
2166 }
2167 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002168 return ENCRYPTION_STATUS_UNSUPPORTED;
2169 }
2170
2171 /**
Robin Lee7e678712014-07-24 16:41:31 +01002172 * Installs the given certificate as a user CA.
2173 *
Robin Lee25e26452015-06-02 09:56:29 -07002174 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2175 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002176 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04002177 *
2178 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01002179 * interrupted, true otherwise.
Maggie Benthallda51e682013-08-08 22:35:44 -04002180 */
Robin Lee25e26452015-06-02 09:56:29 -07002181 public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002182 if (mService != null) {
2183 try {
Robin Lee7e678712014-07-24 16:41:31 +01002184 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04002185 } catch (RemoteException e) {
2186 Log.w(TAG, "Failed talking with device policy service", e);
2187 }
2188 }
2189 return false;
2190 }
2191
2192 /**
Robin Lee7e678712014-07-24 16:41:31 +01002193 * Uninstalls the given certificate from trusted user CAs, if present.
2194 *
Robin Lee25e26452015-06-02 09:56:29 -07002195 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2196 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002197 * @param certBuffer encoded form of the certificate to remove.
Maggie Benthallda51e682013-08-08 22:35:44 -04002198 */
Robin Lee25e26452015-06-02 09:56:29 -07002199 public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002200 if (mService != null) {
2201 try {
Robin Lee306fe082014-06-19 14:04:24 +00002202 final String alias = getCaCertAlias(certBuffer);
Robin Lee83881bd2015-06-09 16:04:38 -07002203 mService.uninstallCaCerts(admin, new String[] {alias});
Robin Lee306fe082014-06-19 14:04:24 +00002204 } catch (CertificateException e) {
2205 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002206 } catch (RemoteException e) {
2207 Log.w(TAG, "Failed talking with device policy service", e);
2208 }
2209 }
2210 }
2211
2212 /**
Robin Lee7e678712014-07-24 16:41:31 +01002213 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
2214 * If a user has installed any certificates by other means than device policy these will be
2215 * included too.
2216 *
Robin Lee25e26452015-06-02 09:56:29 -07002217 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2218 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002219 * @return a List of byte[] arrays, each encoding one user CA certificate.
Maggie Benthallda51e682013-08-08 22:35:44 -04002220 */
Robin Lee25e26452015-06-02 09:56:29 -07002221 public List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002222 List<byte[]> certs = new ArrayList<byte[]>();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002223 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01002224 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002225 mService.enforceCanManageCaCerts(admin);
2226 final TrustedCertificateStore certStore = new TrustedCertificateStore();
2227 for (String alias : certStore.userAliases()) {
2228 try {
2229 certs.add(certStore.getCertificate(alias).getEncoded());
2230 } catch (CertificateException ce) {
2231 Log.w(TAG, "Could not encode certificate: " + alias, ce);
2232 }
2233 }
2234 } catch (RemoteException re) {
2235 Log.w(TAG, "Failed talking with device policy service", re);
Robin Lee7e678712014-07-24 16:41:31 +01002236 }
2237 }
2238 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04002239 }
2240
2241 /**
Robin Lee7e678712014-07-24 16:41:31 +01002242 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
2243 * means other than device policy will also be removed, except for system CA certificates.
2244 *
Robin Lee25e26452015-06-02 09:56:29 -07002245 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2246 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002247 */
Robin Lee25e26452015-06-02 09:56:29 -07002248 public void uninstallAllUserCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002249 if (mService != null) {
Robin Lee83881bd2015-06-09 16:04:38 -07002250 try {
2251 mService.uninstallCaCerts(admin, new TrustedCertificateStore().userAliases()
2252 .toArray(new String[0]));
2253 } catch (RemoteException re) {
2254 Log.w(TAG, "Failed talking with device policy service", re);
Robin Lee7e678712014-07-24 16:41:31 +01002255 }
2256 }
2257 }
2258
2259 /**
2260 * Returns whether this certificate is installed as a trusted CA.
2261 *
Robin Lee25e26452015-06-02 09:56:29 -07002262 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2263 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002264 * @param certBuffer encoded form of the certificate to look up.
Maggie Benthallda51e682013-08-08 22:35:44 -04002265 */
Robin Lee25e26452015-06-02 09:56:29 -07002266 public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002267 if (mService != null) {
2268 try {
2269 mService.enforceCanManageCaCerts(admin);
2270 return getCaCertAlias(certBuffer) != null;
2271 } catch (RemoteException re) {
2272 Log.w(TAG, "Failed talking with device policy service", re);
2273 } catch (CertificateException ce) {
2274 Log.w(TAG, "Could not parse certificate", ce);
2275 }
Maggie Benthallda51e682013-08-08 22:35:44 -04002276 }
2277 return false;
2278 }
2279
2280 /**
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002281 * Called by a device or profile owner to install a certificate and private key pair. The
2282 * keypair will be visible to all apps within the profile.
2283 *
Robin Lee25e26452015-06-02 09:56:29 -07002284 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2285 * {@code null} if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002286 * @param privKey The private key to install.
2287 * @param cert The certificate to install.
2288 * @param alias The private key alias under which to install the certificate. If a certificate
2289 * with that alias already exists, it will be overwritten.
2290 * @return {@code true} if the keys were installed, {@code false} otherwise.
2291 */
Robin Lee25e26452015-06-02 09:56:29 -07002292 public boolean installKeyPair(@Nullable ComponentName admin, PrivateKey privKey, Certificate cert,
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002293 String alias) {
2294 try {
2295 final byte[] pemCert = Credentials.convertToPem(cert);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002296 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
2297 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
Robin Lee25e26452015-06-02 09:56:29 -07002298 return mService.installKeyPair(admin, pkcs8Key, pemCert, alias);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002299 } catch (RemoteException e) {
2300 Log.w(TAG, "Failed talking with device policy service", e);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002301 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
2302 Log.w(TAG, "Failed to obtain private key material", e);
2303 } catch (CertificateException | IOException e) {
2304 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002305 }
2306 return false;
2307 }
2308
2309 /**
Robin Lee25e26452015-06-02 09:56:29 -07002310 * @return the alias of a given CA certificate in the certificate store, or {@code null} if it
Robin Lee306fe082014-06-19 14:04:24 +00002311 * doesn't exist.
2312 */
2313 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
2314 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
2315 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
2316 new ByteArrayInputStream(certBuffer));
2317 return new TrustedCertificateStore().getCertificateAlias(cert);
2318 }
2319
2320 /**
Rubin Xuec32b562015-03-03 17:34:05 +00002321 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01002322 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00002323 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01002324 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00002325 * <p>
2326 * Delegated certificate installer is a per-user state. The delegated access is persistent until
2327 * it is later cleared by calling this method with a null value or uninstallling the certificate
2328 * installer.
2329 *
Robin Lee25e26452015-06-02 09:56:29 -07002330 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xuec32b562015-03-03 17:34:05 +00002331 * @param installerPackage The package name of the certificate installer which will be given
Robin Lee25e26452015-06-02 09:56:29 -07002332 * access. If {@code null} is given the current package will be cleared.
Rubin Xuec32b562015-03-03 17:34:05 +00002333 */
Robin Lee25e26452015-06-02 09:56:29 -07002334 public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String
2335 installerPackage) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002336 if (mService != null) {
2337 try {
Robin Lee25e26452015-06-02 09:56:29 -07002338 mService.setCertInstallerPackage(admin, installerPackage);
Rubin Xuec32b562015-03-03 17:34:05 +00002339 } catch (RemoteException e) {
2340 Log.w(TAG, "Failed talking with device policy service", e);
2341 }
2342 }
2343 }
2344
2345 /**
2346 * Called by a profile owner or device owner to retrieve the certificate installer for the
2347 * current user. null if none is set.
2348 *
Robin Lee25e26452015-06-02 09:56:29 -07002349 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2350 * @return The package name of the current delegated certificate installer, or {@code null}
Rubin Xuec32b562015-03-03 17:34:05 +00002351 * if none is set.
2352 */
Robin Lee25e26452015-06-02 09:56:29 -07002353 public String getCertInstallerPackage(@NonNull ComponentName admin) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002354 if (mService != null) {
2355 try {
Robin Lee25e26452015-06-02 09:56:29 -07002356 return mService.getCertInstallerPackage(admin);
Rubin Xuec32b562015-03-03 17:34:05 +00002357 } catch (RemoteException e) {
2358 Log.w(TAG, "Failed talking with device policy service", e);
2359 }
2360 }
2361 return null;
2362 }
2363
2364 /**
Ben Komalo2447edd2011-05-09 16:05:33 -07002365 * Called by an application that is administering the device to disable all cameras
Amith Yamasani242f4b12014-10-14 16:06:13 -07002366 * on the device, for this user. After setting this, no applications running as this user
2367 * will be able to access any cameras on the device.
Ben Komalo2447edd2011-05-09 16:05:33 -07002368 *
2369 * <p>The calling device admin must have requested
2370 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
2371 * this method; if it has not, a security exception will be thrown.
2372 *
2373 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2374 * @param disabled Whether or not the camera should be disabled.
2375 */
Robin Lee25e26452015-06-02 09:56:29 -07002376 public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002377 if (mService != null) {
2378 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002379 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07002380 } catch (RemoteException e) {
2381 Log.w(TAG, "Failed talking with device policy service", e);
2382 }
2383 }
2384 }
2385
2386 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07002387 * Determine whether or not the device's cameras have been disabled for this user,
2388 * either by the current admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002389 * @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 -07002390 * have disabled the camera
2391 */
Robin Lee25e26452015-06-02 09:56:29 -07002392 public boolean getCameraDisabled(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002393 return getCameraDisabled(admin, UserHandle.myUserId());
2394 }
2395
2396 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002397 public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002398 if (mService != null) {
2399 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002400 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07002401 } catch (RemoteException e) {
2402 Log.w(TAG, "Failed talking with device policy service", e);
2403 }
2404 }
2405 return false;
2406 }
2407
2408 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01002409 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
2410 * screen capture also prevents the content from being shown on display devices that do not have
2411 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
2412 * secure surfaces and secure displays.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002413 *
2414 * <p>The calling device admin must be a device or profile owner. If it is not, a
2415 * security exception will be thrown.
2416 *
2417 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002418 * @param disabled Whether screen capture is disabled or not.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002419 */
Robin Lee25e26452015-06-02 09:56:29 -07002420 public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002421 if (mService != null) {
2422 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002423 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002424 } catch (RemoteException e) {
2425 Log.w(TAG, "Failed talking with device policy service", e);
2426 }
2427 }
2428 }
2429
2430 /**
2431 * Determine whether or not screen capture has been disabled by the current
2432 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002433 * @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 +01002434 * have disabled screen capture.
2435 */
Robin Lee25e26452015-06-02 09:56:29 -07002436 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002437 return getScreenCaptureDisabled(admin, UserHandle.myUserId());
2438 }
2439
2440 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002441 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002442 if (mService != null) {
2443 try {
2444 return mService.getScreenCaptureDisabled(admin, userHandle);
2445 } catch (RemoteException e) {
2446 Log.w(TAG, "Failed talking with device policy service", e);
2447 }
2448 }
2449 return false;
2450 }
2451
2452 /**
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002453 * Called by a device owner to set whether auto time is required. If auto time is
2454 * required the user cannot set the date and time, but has to use network date and time.
2455 *
2456 * <p>Note: if auto time is required the user can still manually set the time zone.
2457 *
2458 * <p>The calling device admin must be a device owner. If it is not, a security exception will
2459 * be thrown.
2460 *
2461 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2462 * @param required Whether auto time is set required or not.
2463 */
Robin Lee25e26452015-06-02 09:56:29 -07002464 public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) {
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002465 if (mService != null) {
2466 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002467 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002468 } catch (RemoteException e) {
2469 Log.w(TAG, "Failed talking with device policy service", e);
2470 }
2471 }
2472 }
2473
2474 /**
2475 * @return true if auto time is required.
2476 */
2477 public boolean getAutoTimeRequired() {
2478 if (mService != null) {
2479 try {
2480 return mService.getAutoTimeRequired();
2481 } catch (RemoteException e) {
2482 Log.w(TAG, "Failed talking with device policy service", e);
2483 }
2484 }
2485 return false;
2486 }
2487
2488 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002489 * Called by an application that is administering the device to disable keyguard customizations,
2490 * such as widgets. After setting this, keyguard features will be disabled according to the
2491 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002492 *
2493 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07002494 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07002495 * this method; if it has not, a security exception will be thrown.
2496 *
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002497 * <p>Calling this from a managed profile before version
2498 * {@link android.os.Build.VERSION_CODES#MNC} will throw a security exception.
2499 *
2500 * <p>From version {@link android.os.Build.VERSION_CODES#MNC} a profile owner can set:
2501 * <ul>
2502 * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, {@link #KEYGUARD_DISABLE_FINGERPRINT}
2503 * these will affect the profile's parent user.
2504 * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} this will affect notifications
2505 * generated by applications in the managed profile.
2506 * </ul>
2507 * <p>Requests to disable other features on a managed profile will be ignored. The admin
2508 * can check which features have been disabled by calling
2509 * {@link #getKeyguardDisabledFeatures(ComponentName)}
Amith Yamasani242f4b12014-10-14 16:06:13 -07002510 *
Jim Millerb8ec4702012-08-31 17:19:10 -07002511 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07002512 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
2513 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
Jim Miller50e62182014-04-23 17:25:00 -07002514 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002515 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FINGERPRINT},
2516 * {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07002517 */
Robin Lee25e26452015-06-02 09:56:29 -07002518 public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002519 if (mService != null) {
2520 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002521 mService.setKeyguardDisabledFeatures(admin, which);
Jim Millerb8ec4702012-08-31 17:19:10 -07002522 } catch (RemoteException e) {
2523 Log.w(TAG, "Failed talking with device policy service", e);
2524 }
2525 }
2526 }
2527
2528 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002529 * Determine whether or not features have been disabled in keyguard either by the current
Jim Millerb8ec4702012-08-31 17:19:10 -07002530 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002531 * @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 -07002532 * have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07002533 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
2534 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002535 */
Robin Lee25e26452015-06-02 09:56:29 -07002536 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) {
Jim Miller48b9b0d2012-09-19 23:16:50 -07002537 return getKeyguardDisabledFeatures(admin, UserHandle.myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002538 }
2539
2540 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002541 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002542 if (mService != null) {
2543 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07002544 return mService.getKeyguardDisabledFeatures(admin, userHandle);
Jim Millerb8ec4702012-08-31 17:19:10 -07002545 } catch (RemoteException e) {
2546 Log.w(TAG, "Failed talking with device policy service", e);
2547 }
2548 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07002549 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07002550 }
2551
2552 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08002553 * @hide
2554 */
Robin Lee25e26452015-06-02 09:56:29 -07002555 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
2556 int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002557 if (mService != null) {
2558 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01002559 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002560 } catch (RemoteException e) {
2561 Log.w(TAG, "Failed talking with device policy service", e);
2562 }
2563 }
2564 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002565
Dianne Hackbornd6847842010-01-12 18:14:19 -08002566 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01002567 * @hide
2568 */
Robin Lee25e26452015-06-02 09:56:29 -07002569 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
Jessica Hummel6d36b602014-04-04 12:42:17 +01002570 setActiveAdmin(policyReceiver, refreshing, UserHandle.myUserId());
2571 }
2572
2573 /**
Robin Lee25e26452015-06-02 09:56:29 -07002574 * Returns the DeviceAdminInfo as defined by the administrator's package info &amp; meta-data
Dianne Hackbornd6847842010-01-12 18:14:19 -08002575 * @hide
2576 */
Robin Lee25e26452015-06-02 09:56:29 -07002577 public DeviceAdminInfo getAdminInfo(@NonNull ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002578 ActivityInfo ai;
2579 try {
2580 ai = mContext.getPackageManager().getReceiverInfo(cn,
2581 PackageManager.GET_META_DATA);
2582 } catch (PackageManager.NameNotFoundException e) {
2583 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
2584 return null;
2585 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002586
Dianne Hackbornd6847842010-01-12 18:14:19 -08002587 ResolveInfo ri = new ResolveInfo();
2588 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002589
Dianne Hackbornd6847842010-01-12 18:14:19 -08002590 try {
2591 return new DeviceAdminInfo(mContext, ri);
2592 } catch (XmlPullParserException e) {
2593 Log.w(TAG, "Unable to parse device policy " + cn, e);
2594 return null;
2595 } catch (IOException e) {
2596 Log.w(TAG, "Unable to parse device policy " + cn, e);
2597 return null;
2598 }
2599 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002600
Dianne Hackbornd6847842010-01-12 18:14:19 -08002601 /**
2602 * @hide
2603 */
Robin Lee25e26452015-06-02 09:56:29 -07002604 public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002605 if (mService != null) {
2606 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002607 mService.getRemoveWarning(admin, result, UserHandle.myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002608 } catch (RemoteException e) {
2609 Log.w(TAG, "Failed talking with device policy service", e);
2610 }
2611 }
2612 }
2613
2614 /**
2615 * @hide
2616 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002617 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002618 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002619 if (mService != null) {
2620 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002621 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002622 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002623 } catch (RemoteException e) {
2624 Log.w(TAG, "Failed talking with device policy service", e);
2625 }
2626 }
2627 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002628
Dianne Hackbornd6847842010-01-12 18:14:19 -08002629 /**
2630 * @hide
2631 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002632 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002633 if (mService != null) {
2634 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002635 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002636 } catch (RemoteException e) {
2637 Log.w(TAG, "Failed talking with device policy service", e);
2638 }
2639 }
2640 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002641
Dianne Hackbornd6847842010-01-12 18:14:19 -08002642 /**
2643 * @hide
2644 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002645 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002646 if (mService != null) {
2647 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002648 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002649 } catch (RemoteException e) {
2650 Log.w(TAG, "Failed talking with device policy service", e);
2651 }
2652 }
2653 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07002654
2655 /**
2656 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00002657 * Sets the given package as the device owner.
2658 * Same as {@link #setDeviceOwner(String, String)} but without setting a device owner name.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002659 * @param packageName the package name of the application to be registered as the device owner.
2660 * @return whether the package was successfully registered as the device owner.
2661 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00002662 * @throws IllegalStateException If the preconditions mentioned are not met.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002663 */
2664 public boolean setDeviceOwner(String packageName) throws IllegalArgumentException,
2665 IllegalStateException {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002666 return setDeviceOwner(packageName, null);
2667 }
2668
2669 /**
2670 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00002671 * Sets the given package as the device owner. The package must already be installed. There
2672 * must not already be a device owner.
2673 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
2674 * this method.
2675 * Calling this after the setup phase of the primary user has completed is allowed only if
2676 * the caller is the shell uid, and there are no additional users and no accounts.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002677 * @param packageName the package name of the application to be registered as the device owner.
2678 * @param ownerName the human readable name of the institution that owns this device.
2679 * @return whether the package was successfully registered as the device owner.
2680 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00002681 * @throws IllegalStateException If the preconditions mentioned are not met.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002682 */
2683 public boolean setDeviceOwner(String packageName, String ownerName)
2684 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002685 if (mService != null) {
2686 try {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002687 return mService.setDeviceOwner(packageName, ownerName);
Amith Yamasani71e6c692013-03-24 17:39:28 -07002688 } catch (RemoteException re) {
2689 Log.w(TAG, "Failed to set device owner");
2690 }
2691 }
2692 return false;
2693 }
2694
2695 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002696 * Used to determine if a particular package has been registered as a Device Owner app.
2697 * A device owner app is a special device admin that cannot be deactivated by the user, once
Robin Lee25e26452015-06-02 09:56:29 -07002698 * activated as a device admin. It also cannot be uninstalled. To check whether a particular
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002699 * package is currently registered as the device owner app, pass in the package name from
2700 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
Robin Lee25e26452015-06-02 09:56:29 -07002701 * admin apps that want to check whether they are also registered as the device owner app. The
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002702 * exact mechanism by which a device admin app is registered as a device owner app is defined by
2703 * the setup process.
2704 * @param packageName the package name of the app, to compare with the registered device owner
2705 * app, if any.
2706 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002707 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002708 public boolean isDeviceOwnerApp(String packageName) {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002709 if (mService != null) {
2710 try {
2711 return mService.isDeviceOwner(packageName);
2712 } catch (RemoteException re) {
2713 Log.w(TAG, "Failed to check device owner");
2714 }
2715 }
2716 return false;
2717 }
2718
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002719 /**
2720 * @hide
2721 * Redirect to isDeviceOwnerApp.
2722 */
2723 public boolean isDeviceOwner(String packageName) {
2724 return isDeviceOwnerApp(packageName);
2725 }
2726
Jason Monkb0dced82014-06-06 14:36:20 -04002727 /**
2728 * Clears the current device owner. The caller must be the device owner.
2729 *
2730 * This function should be used cautiously as once it is called it cannot
2731 * be undone. The device owner can only be set as a part of device setup
2732 * before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04002733 *
2734 * @param packageName The package name of the device owner.
Jason Monkb0dced82014-06-06 14:36:20 -04002735 */
Jason Monk94d2cf92014-06-18 09:53:34 -04002736 public void clearDeviceOwnerApp(String packageName) {
Jason Monkb0dced82014-06-06 14:36:20 -04002737 if (mService != null) {
2738 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04002739 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04002740 } catch (RemoteException re) {
2741 Log.w(TAG, "Failed to clear device owner");
2742 }
2743 }
2744 }
2745
Amith Yamasani71e6c692013-03-24 17:39:28 -07002746 /** @hide */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002747 @SystemApi
Amith Yamasani71e6c692013-03-24 17:39:28 -07002748 public String getDeviceOwner() {
2749 if (mService != null) {
2750 try {
2751 return mService.getDeviceOwner();
2752 } catch (RemoteException re) {
2753 Log.w(TAG, "Failed to get device owner");
2754 }
2755 }
2756 return null;
2757 }
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002758
2759 /** @hide */
2760 public String getDeviceOwnerName() {
2761 if (mService != null) {
2762 try {
2763 return mService.getDeviceOwnerName();
2764 } catch (RemoteException re) {
2765 Log.w(TAG, "Failed to get device owner");
2766 }
2767 }
2768 return null;
2769 }
Adam Connors776c5552014-01-09 10:42:56 +00002770
2771 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05002772 * Sets the given component as the device initializer. The package must already be installed and
2773 * set as an active device administrator, and there must not be an existing device initializer,
2774 * for this call to succeed. This method can only be called by an app holding the
2775 * MANAGE_DEVICE_ADMINS permission before the device is provisioned or by a device owner app. A
2776 * device initializer app is granted device owner privileges during device initialization and
2777 * profile owner privileges during secondary user initialization.
Robin Lee25e26452015-06-02 09:56:29 -07002778 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2779 * {@code null} if not called by the device owner.
Julia Reynolds20118f12015-02-11 12:34:08 -05002780 * @param initializer Which {@link DeviceAdminReceiver} to make device initializer.
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002781 * @return whether the component was successfully registered as the device initializer.
2782 * @throws IllegalArgumentException if the componentname is null or invalid
Julia Reynolds20118f12015-02-11 12:34:08 -05002783 * @throws IllegalStateException if the caller is not device owner or the device has
2784 * already been provisioned or a device initializer already exists.
2785 */
Robin Lee25e26452015-06-02 09:56:29 -07002786 public boolean setDeviceInitializer(@Nullable ComponentName admin,
2787 @NonNull ComponentName initializer)
Julia Reynolds731051e2015-05-11 15:52:08 -04002788 throws IllegalArgumentException, IllegalStateException {
Julia Reynolds20118f12015-02-11 12:34:08 -05002789 if (mService != null) {
2790 try {
Robin Lee25e26452015-06-02 09:56:29 -07002791 return mService.setDeviceInitializer(admin, initializer);
Julia Reynolds20118f12015-02-11 12:34:08 -05002792 } catch (RemoteException re) {
2793 Log.w(TAG, "Failed to set device initializer");
2794 }
2795 }
2796 return false;
2797 }
2798
2799 /**
2800 * Used to determine if a particular package has been registered as the device initializer.
2801 *
2802 * @param packageName the package name of the app, to compare with the registered device
2803 * initializer app, if any.
2804 * @return whether or not the caller is registered as the device initializer app.
2805 */
2806 public boolean isDeviceInitializerApp(String packageName) {
2807 if (mService != null) {
2808 try {
2809 return mService.isDeviceInitializer(packageName);
2810 } catch (RemoteException re) {
2811 Log.w(TAG, "Failed to check device initializer");
2812 }
2813 }
2814 return false;
2815 }
2816
2817 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05002818 * Removes the device initializer, so that it will not be invoked on user initialization for any
2819 * subsequently created users. This method can be called by either the device owner or device
Julia Reynolds1c3754a2015-03-05 10:06:41 -05002820 * initializer itself. The caller must be an active administrator.
2821 *
Robin Lee25e26452015-06-02 09:56:29 -07002822 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Julia Reynolds20118f12015-02-11 12:34:08 -05002823 */
Robin Lee25e26452015-06-02 09:56:29 -07002824 public void clearDeviceInitializerApp(@NonNull ComponentName admin) {
Julia Reynolds20118f12015-02-11 12:34:08 -05002825 if (mService != null) {
2826 try {
Robin Lee25e26452015-06-02 09:56:29 -07002827 mService.clearDeviceInitializer(admin);
Julia Reynolds20118f12015-02-11 12:34:08 -05002828 } catch (RemoteException re) {
2829 Log.w(TAG, "Failed to clear device initializer");
2830 }
2831 }
2832 }
2833
2834 /**
2835 * @hide
2836 * Gets the device initializer of the system.
2837 *
2838 * @return the package name of the device initializer.
2839 */
2840 @SystemApi
2841 public String getDeviceInitializerApp() {
2842 if (mService != null) {
2843 try {
2844 return mService.getDeviceInitializer();
2845 } catch (RemoteException re) {
2846 Log.w(TAG, "Failed to get device initializer");
2847 }
2848 }
2849 return null;
2850 }
2851
2852 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002853 * @hide
2854 * Gets the device initializer component of the system.
2855 *
2856 * @return the component name of the device initializer.
2857 */
2858 @SystemApi
2859 public ComponentName getDeviceInitializerComponent() {
2860 if (mService != null) {
2861 try {
2862 return mService.getDeviceInitializerComponent();
2863 } catch (RemoteException re) {
2864 Log.w(TAG, "Failed to get device initializer");
2865 }
2866 }
2867 return null;
2868 }
2869
2870
2871 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05002872 * Sets the enabled state of the user. A user should be enabled only once it is ready to
2873 * be used.
2874 *
2875 * <p>Device initializer must call this method to mark the user as functional.
2876 * Only the device initializer agent can call this.
2877 *
2878 * <p>When the user is enabled, if the device initializer is not also the device owner, the
2879 * device initializer will no longer have elevated permissions to call methods in this class.
2880 * Additionally, it will be removed as an active administrator and its
2881 * {@link DeviceAdminReceiver} will be disabled.
2882 *
2883 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2884 * @return whether the user is now enabled.
2885 */
Robin Lee25e26452015-06-02 09:56:29 -07002886 public boolean setUserEnabled(@NonNull ComponentName admin) {
Julia Reynolds20118f12015-02-11 12:34:08 -05002887 if (mService != null) {
2888 try {
2889 return mService.setUserEnabled(admin);
2890 } catch (RemoteException e) {
2891 Log.w(TAG, "Failed talking with device policy service", e);
2892 }
2893 }
2894 return false;
2895 }
2896
2897 /**
Adam Connors776c5552014-01-09 10:42:56 +00002898 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002899 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302900 * Sets the given component as an active admin and registers the package as the profile
2901 * owner for this user. The package must already be installed and there shouldn't be
2902 * an existing profile owner registered for this user. Also, this method must be called
2903 * before the user setup has been completed.
2904 * <p>
2905 * This method can only be called by system apps that hold MANAGE_USERS permission and
2906 * MANAGE_DEVICE_ADMINS permission.
2907 * @param admin The component to register as an active admin and profile owner.
2908 * @param ownerName The user-visible name of the entity that is managing this user.
2909 * @return whether the admin was successfully registered as the profile owner.
2910 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
2911 * the user has already been set up.
2912 */
Justin Morey80440cc2014-07-24 09:16:35 -05002913 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07002914 public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302915 throws IllegalArgumentException {
2916 if (mService != null) {
2917 try {
2918 final int myUserId = UserHandle.myUserId();
2919 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002920 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302921 } catch (RemoteException re) {
2922 Log.w(TAG, "Failed to set profile owner " + re);
2923 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2924 }
2925 }
2926 return false;
2927 }
2928
2929 /**
2930 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002931 * Clears the active profile owner and removes all user restrictions. The caller must
2932 * be from the same package as the active profile owner for this user, otherwise a
2933 * SecurityException will be thrown.
2934 *
2935 * @param admin The component to remove as the profile owner.
2936 * @return
2937 */
2938 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07002939 public void clearProfileOwner(@NonNull ComponentName admin) {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002940 if (mService != null) {
2941 try {
2942 mService.clearProfileOwner(admin);
2943 } catch (RemoteException re) {
2944 Log.w(TAG, "Failed to clear profile owner " + admin + re);
2945 }
2946 }
2947 }
2948
2949 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05002950 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07002951 * Checks whether the user was already setup.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002952 */
2953 public boolean hasUserSetupCompleted() {
2954 if (mService != null) {
2955 try {
2956 return mService.hasUserSetupCompleted();
2957 } catch (RemoteException re) {
Robin Lee25e26452015-06-02 09:56:29 -07002958 Log.w(TAG, "Failed to check whether user setup has completed");
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002959 }
2960 }
2961 return true;
2962 }
2963
2964 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002965 * @hide
2966 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00002967 * already be installed. There must not already be a profile owner for this user.
2968 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
2969 * this method.
2970 * Calling this after the setup phase of the specified user has completed is allowed only if:
2971 * - the caller is SYSTEM_UID.
2972 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002973 * @param admin the component name to be registered as profile owner.
2974 * @param ownerName the human readable name of the organisation associated with this DPM.
2975 * @param userHandle the userId to set the profile owner for.
2976 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00002977 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
2978 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002979 */
Robin Lee25e26452015-06-02 09:56:29 -07002980 public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName,
Robin Leeddd553f2015-04-30 14:18:22 +01002981 int userHandle) throws IllegalArgumentException {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002982 if (admin == null) {
2983 throw new NullPointerException("admin cannot be null");
2984 }
Adam Connors776c5552014-01-09 10:42:56 +00002985 if (mService != null) {
2986 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002987 if (ownerName == null) {
2988 ownerName = "";
2989 }
2990 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00002991 } catch (RemoteException re) {
2992 Log.w(TAG, "Failed to set profile owner", re);
2993 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2994 }
2995 }
2996 return false;
2997 }
2998
2999 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003000 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
3001 * be used. Only the profile owner can call this.
3002 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01003003 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003004 *
3005 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3006 */
Robin Lee25e26452015-06-02 09:56:29 -07003007 public void setProfileEnabled(@NonNull ComponentName admin) {
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003008 if (mService != null) {
3009 try {
3010 mService.setProfileEnabled(admin);
3011 } catch (RemoteException e) {
3012 Log.w(TAG, "Failed talking with device policy service", e);
3013 }
3014 }
3015 }
3016
3017 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003018 * Sets the name of the profile. In the device owner case it sets the name of the user
3019 * 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 +01003020 * never called by the profile or device owner, the name will be set to default values.
3021 *
3022 * @see #isProfileOwnerApp
3023 * @see #isDeviceOwnerApp
3024 *
Robin Lee25e26452015-06-02 09:56:29 -07003025 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01003026 * @param profileName The name of the profile.
3027 */
Robin Lee25e26452015-06-02 09:56:29 -07003028 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Jessica Hummel1333ea12014-06-23 11:20:10 +01003029 if (mService != null) {
3030 try {
Robin Lee25e26452015-06-02 09:56:29 -07003031 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07003032 } catch (RemoteException e) {
3033 Log.w(TAG, "Failed talking with device policy service", e);
3034 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01003035 }
3036 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01003037
3038 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003039 * Used to determine if a particular package is registered as the profile owner for the
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003040 * current user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003041 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00003042 *
3043 * @param packageName The package name of the app to compare with the registered profile owner.
3044 * @return Whether or not the package is registered as the profile owner.
3045 */
3046 public boolean isProfileOwnerApp(String packageName) {
3047 if (mService != null) {
3048 try {
Nicolas Prevot90af6d72014-07-30 14:19:12 +01003049 ComponentName profileOwner = mService.getProfileOwner(
3050 Process.myUserHandle().getIdentifier());
3051 return profileOwner != null
3052 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00003053 } catch (RemoteException re) {
3054 Log.w(TAG, "Failed to check profile owner");
3055 }
3056 }
3057 return false;
3058 }
3059
3060 /**
3061 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003062 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00003063 * owner has been set for that user.
3064 * @throws IllegalArgumentException if the userId is invalid.
3065 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01003066 @SystemApi
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003067 public ComponentName getProfileOwner() throws IllegalArgumentException {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003068 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
3069 }
3070
3071 /**
3072 * @see #getProfileOwner()
3073 * @hide
3074 */
3075 public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00003076 if (mService != null) {
3077 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003078 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00003079 } catch (RemoteException re) {
3080 Log.w(TAG, "Failed to get profile owner");
3081 throw new IllegalArgumentException(
3082 "Requested profile owner for invalid userId", re);
3083 }
3084 }
3085 return null;
3086 }
3087
3088 /**
3089 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003090 * @return the human readable name of the organisation associated with this DPM or {@code null}
3091 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00003092 * @throws IllegalArgumentException if the userId is invalid.
3093 */
3094 public String getProfileOwnerName() throws IllegalArgumentException {
3095 if (mService != null) {
3096 try {
3097 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
3098 } catch (RemoteException re) {
3099 Log.w(TAG, "Failed to get profile owner");
3100 throw new IllegalArgumentException(
3101 "Requested profile owner for invalid userId", re);
3102 }
3103 }
3104 return null;
3105 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003106
3107 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07003108 * @hide
3109 * @param user The user for whom to fetch the profile owner name, if any.
3110 * @return the human readable name of the organisation associated with this profile owner or
3111 * null if one is not set.
3112 * @throws IllegalArgumentException if the userId is invalid.
3113 */
3114 @SystemApi
Selim Cinek24ac55e2014-08-27 12:51:45 +02003115 public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Amith Yamasani38f836b2014-08-20 14:51:15 -07003116 if (mService != null) {
3117 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02003118 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07003119 } catch (RemoteException re) {
3120 Log.w(TAG, "Failed to get profile owner");
3121 throw new IllegalArgumentException(
3122 "Requested profile owner for invalid userId", re);
3123 }
3124 }
3125 return null;
3126 }
3127
3128 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003129 * Called by a profile owner or device owner to add a default intent handler activity for
3130 * intents that match a certain intent filter. This activity will remain the default intent
3131 * handler even if the set of potential event handlers for the intent filter changes and if
3132 * the intent preferences are reset.
3133 *
3134 * <p>The default disambiguation mechanism takes over if the activity is not installed
3135 * (anymore). When the activity is (re)installed, it is automatically reset as default
3136 * intent handler for the filter.
3137 *
3138 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
3139 * security exception will be thrown.
3140 *
3141 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3142 * @param filter The IntentFilter for which a default handler is added.
3143 * @param activity The Activity that is added as default intent handler.
3144 */
Robin Lee25e26452015-06-02 09:56:29 -07003145 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
3146 @NonNull ComponentName activity) {
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003147 if (mService != null) {
3148 try {
3149 mService.addPersistentPreferredActivity(admin, filter, activity);
3150 } catch (RemoteException e) {
3151 Log.w(TAG, "Failed talking with device policy service", e);
3152 }
3153 }
3154 }
3155
3156 /**
3157 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00003158 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003159 *
3160 * <p>The calling device admin must be a profile owner. If it is not, a security
3161 * exception will be thrown.
3162 *
3163 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3164 * @param packageName The name of the package for which preferences are removed.
3165 */
Robin Lee25e26452015-06-02 09:56:29 -07003166 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003167 String packageName) {
3168 if (mService != null) {
3169 try {
3170 mService.clearPackagePersistentPreferredActivities(admin, packageName);
3171 } catch (RemoteException e) {
3172 Log.w(TAG, "Failed talking with device policy service", e);
3173 }
3174 }
3175 }
Robin Lee66e5d962014-04-09 16:44:21 +01003176
3177 /**
3178 * Called by a profile or device owner to set the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003179 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01003180 *
3181 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be
Kenny Guyd00cfc52014-09-18 16:24:31 +01003182 * boolean, int, String, or String[].
Robin Lee66e5d962014-04-09 16:44:21 +01003183 *
3184 * <p>The application restrictions are only made visible to the target application and the
3185 * profile or device owner.
3186 *
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003187 * <p>If the restrictions are not available yet, but may be applied in the near future,
3188 * the admin can notify the target application of that by adding
3189 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
3190 *
Robin Lee66e5d962014-04-09 16:44:21 +01003191 * <p>The calling device admin must be a profile or device owner; if it is not, a security
3192 * exception will be thrown.
3193 *
3194 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3195 * @param packageName The name of the package to update restricted settings for.
3196 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
3197 * set of active restrictions.
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003198 *
3199 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01003200 */
Robin Lee25e26452015-06-02 09:56:29 -07003201 public void setApplicationRestrictions(@NonNull ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01003202 Bundle settings) {
3203 if (mService != null) {
3204 try {
3205 mService.setApplicationRestrictions(admin, packageName, settings);
3206 } catch (RemoteException e) {
3207 Log.w(TAG, "Failed talking with device policy service", e);
3208 }
3209 }
3210 }
3211
3212 /**
Jim Millere303bf42014-08-26 17:12:29 -07003213 * Sets a list of configuration features to enable for a TrustAgent component. This is meant
3214 * to be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all
3215 * trust agents but those enabled by this function call. If flag
3216 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Jim Miller604e7552014-07-18 19:00:02 -07003217 *
3218 * <p>The calling device admin must have requested
3219 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millere303bf42014-08-26 17:12:29 -07003220 * this method; if not, a security exception will be thrown.
Jim Miller604e7552014-07-18 19:00:02 -07003221 *
3222 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07003223 * @param target Component name of the agent to be enabled.
Jim Millerb5db57a2015-01-14 18:17:19 -08003224 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent
Jim Millere303bf42014-08-26 17:12:29 -07003225 * will be strictly disabled according to the state of the
3226 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
3227 * <p>If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all admins,
3228 * then it's up to the TrustAgent itself to aggregate the values from all device admins.
3229 * <p>Consult documentation for the specific TrustAgent to determine legal options parameters.
Jim Miller604e7552014-07-18 19:00:02 -07003230 */
Robin Lee25e26452015-06-02 09:56:29 -07003231 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
3232 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07003233 if (mService != null) {
3234 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003235 mService.setTrustAgentConfiguration(admin, target, configuration);
Jim Miller604e7552014-07-18 19:00:02 -07003236 } catch (RemoteException e) {
3237 Log.w(TAG, "Failed talking with device policy service", e);
3238 }
3239 }
3240 }
3241
3242 /**
Jim Millere303bf42014-08-26 17:12:29 -07003243 * Gets configuration for the given trust agent based on aggregating all calls to
3244 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
3245 * all device admins.
Jim Miller604e7552014-07-18 19:00:02 -07003246 *
Jim Millerb5db57a2015-01-14 18:17:19 -08003247 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
3248 * this function returns a list of configurations for all admins that declare
3249 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
3250 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
3251 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
3252 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07003253 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07003254 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07003255 */
Robin Lee25e26452015-06-02 09:56:29 -07003256 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
3257 @NonNull ComponentName agent) {
Jim Millere303bf42014-08-26 17:12:29 -07003258 return getTrustAgentConfiguration(admin, agent, UserHandle.myUserId());
3259 }
3260
3261 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003262 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
3263 @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07003264 if (mService != null) {
3265 try {
Jim Millere303bf42014-08-26 17:12:29 -07003266 return mService.getTrustAgentConfiguration(admin, agent, userHandle);
Jim Miller604e7552014-07-18 19:00:02 -07003267 } catch (RemoteException e) {
3268 Log.w(TAG, "Failed talking with device policy service", e);
3269 }
3270 }
Jim Millere303bf42014-08-26 17:12:29 -07003271 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07003272 }
3273
3274 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003275 * Called by a profile owner of a managed profile to set whether caller-Id information from
3276 * the managed profile will be shown in the parent profile, for incoming calls.
Adam Connors210fe212014-07-17 15:41:43 +01003277 *
3278 * <p>The calling device admin must be a profile owner. If it is not, a
3279 * security exception will be thrown.
3280 *
Robin Lee25e26452015-06-02 09:56:29 -07003281 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01003282 * @param disabled If true caller-Id information in the managed profile is not displayed.
3283 */
Robin Lee25e26452015-06-02 09:56:29 -07003284 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Adam Connors210fe212014-07-17 15:41:43 +01003285 if (mService != null) {
3286 try {
Robin Lee25e26452015-06-02 09:56:29 -07003287 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01003288 } catch (RemoteException e) {
3289 Log.w(TAG, "Failed talking with device policy service", e);
3290 }
3291 }
3292 }
3293
3294 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003295 * Called by a profile owner of a managed profile to determine whether or not caller-Id
3296 * information has been disabled.
Adam Connors210fe212014-07-17 15:41:43 +01003297 *
3298 * <p>The calling device admin must be a profile owner. If it is not, a
3299 * security exception will be thrown.
3300 *
Robin Lee25e26452015-06-02 09:56:29 -07003301 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01003302 */
Robin Lee25e26452015-06-02 09:56:29 -07003303 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Adam Connors210fe212014-07-17 15:41:43 +01003304 if (mService != null) {
3305 try {
Robin Lee25e26452015-06-02 09:56:29 -07003306 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01003307 } catch (RemoteException e) {
3308 Log.w(TAG, "Failed talking with device policy service", e);
3309 }
3310 }
3311 return false;
3312 }
3313
3314 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07003315 * Determine whether or not caller-Id information has been disabled.
3316 *
3317 * @param userHandle The user for whom to check the caller-id permission
3318 * @hide
3319 */
3320 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
3321 if (mService != null) {
3322 try {
3323 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
3324 } catch (RemoteException e) {
3325 Log.w(TAG, "Failed talking with device policy service", e);
3326 }
3327 }
3328 return false;
3329 }
3330
3331 /**
Makoto Onuki1040da12015-03-19 11:24:00 -07003332 * Start Quick Contact on the managed profile for the current user, if the policy allows.
3333 * @hide
3334 */
3335 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
3336 Intent originalIntent) {
3337 if (mService != null) {
3338 try {
3339 mService.startManagedQuickContact(
3340 actualLookupKey, actualContactId, originalIntent);
3341 } catch (RemoteException e) {
3342 Log.w(TAG, "Failed talking with device policy service", e);
3343 }
3344 }
3345 }
3346
3347 /**
Ricky Wai778ba132015-03-31 14:21:22 +01003348 * Called by a profile owner of a managed profile to set whether bluetooth
3349 * devices can access enterprise contacts.
3350 * <p>
3351 * The calling device admin must be a profile owner. If it is not, a
3352 * security exception will be thrown.
3353 * <p>
3354 * This API works on managed profile only.
3355 *
Robin Lee25e26452015-06-02 09:56:29 -07003356 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01003357 * with.
3358 * @param disabled If true, bluetooth devices cannot access enterprise
3359 * contacts.
3360 */
Robin Lee25e26452015-06-02 09:56:29 -07003361 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Ricky Wai778ba132015-03-31 14:21:22 +01003362 if (mService != null) {
3363 try {
Robin Lee25e26452015-06-02 09:56:29 -07003364 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01003365 } catch (RemoteException e) {
3366 Log.w(TAG, "Failed talking with device policy service", e);
3367 }
3368 }
3369 }
3370
3371 /**
3372 * Called by a profile owner of a managed profile to determine whether or
3373 * not Bluetooth devices cannot access enterprise contacts.
3374 * <p>
3375 * The calling device admin must be a profile owner. If it is not, a
3376 * security exception will be thrown.
3377 * <p>
3378 * This API works on managed profile only.
3379 *
Robin Lee25e26452015-06-02 09:56:29 -07003380 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01003381 * with.
3382 */
Robin Lee25e26452015-06-02 09:56:29 -07003383 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Ricky Wai778ba132015-03-31 14:21:22 +01003384 if (mService != null) {
3385 try {
Robin Lee25e26452015-06-02 09:56:29 -07003386 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01003387 } catch (RemoteException e) {
3388 Log.w(TAG, "Failed talking with device policy service", e);
3389 }
3390 }
3391 return true;
3392 }
3393
3394 /**
3395 * Determine whether or not Bluetooth devices cannot access contacts.
3396 * <p>
3397 * This API works on managed profile UserHandle only.
3398 *
3399 * @param userHandle The user for whom to check the caller-id permission
3400 * @hide
3401 */
3402 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
3403 if (mService != null) {
3404 try {
3405 return mService.getBluetoothContactSharingDisabledForUser(userHandle
3406 .getIdentifier());
3407 } catch (RemoteException e) {
3408 Log.w(TAG, "Failed talking with device policy service", e);
3409 }
3410 }
3411 return true;
3412 }
3413
3414 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003415 * Called by the profile owner of a managed profile so that some intents sent in the managed
3416 * profile can also be resolved in the parent, or vice versa.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00003417 * Only activity intents are supported.
3418 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003419 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01003420 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
3421 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01003422 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
3423 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003424 */
Robin Lee25e26452015-06-02 09:56:29 -07003425 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003426 if (mService != null) {
3427 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003428 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003429 } catch (RemoteException e) {
3430 Log.w(TAG, "Failed talking with device policy service", e);
3431 }
3432 }
3433 }
3434
3435 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003436 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
3437 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01003438 * Only removes those that have been set by the profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003439 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3440 */
Robin Lee25e26452015-06-02 09:56:29 -07003441 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003442 if (mService != null) {
3443 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003444 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003445 } catch (RemoteException e) {
3446 Log.w(TAG, "Failed talking with device policy service", e);
3447 }
3448 }
3449 }
3450
3451 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003452 * Called by a profile or device owner to set the permitted accessibility services. When
3453 * set by a device owner or profile owner the restriction applies to all profiles of the
3454 * user the device owner or profile owner is an admin for.
Jim Millerb1474f42014-08-26 18:42:58 -07003455 *
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003456 * By default the user can use any accessiblity service. When zero or more packages have
3457 * been added, accessiblity services that are not in the list and not part of the system
Jim Millerb1474f42014-08-26 18:42:58 -07003458 * can not be enabled by the user.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003459 *
3460 * <p> Calling with a null value for the list disables the restriction so that all services
3461 * can be used, calling with an empty list only allows the builtin system's services.
3462 *
3463 * <p> System accesibility services are always available to the user the list can't modify
3464 * this.
3465 *
3466 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3467 * @param packageNames List of accessibility service package names.
3468 *
3469 * @return true if setting the restriction succeeded. It fail if there is
3470 * one or more non-system accessibility services enabled, that are not in the list.
3471 */
Robin Lee25e26452015-06-02 09:56:29 -07003472 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003473 List<String> packageNames) {
3474 if (mService != null) {
3475 try {
3476 return mService.setPermittedAccessibilityServices(admin, packageNames);
3477 } catch (RemoteException e) {
3478 Log.w(TAG, "Failed talking with device policy service", e);
3479 }
3480 }
3481 return false;
3482 }
3483
3484 /**
3485 * Returns the list of permitted accessibility services set by this device or profile owner.
3486 *
3487 * <p>An empty list means no accessibility services except system services are allowed.
3488 * Null means all accessibility services are allowed.
3489 *
3490 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3491 * @return List of accessiblity service package names.
3492 */
Robin Lee25e26452015-06-02 09:56:29 -07003493 public List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003494 if (mService != null) {
3495 try {
3496 return mService.getPermittedAccessibilityServices(admin);
3497 } catch (RemoteException e) {
3498 Log.w(TAG, "Failed talking with device policy service", e);
3499 }
3500 }
3501 return null;
3502 }
3503
3504 /**
3505 * Returns the list of accessibility services permitted by the device or profiles
3506 * owners of this user.
3507 *
3508 * <p>Null means all accessibility services are allowed, if a non-null list is returned
3509 * it will contain the intersection of the permitted lists for any device or profile
3510 * owners that apply to this user. It will also include any system accessibility services.
3511 *
3512 * @param userId which user to check for.
3513 * @return List of accessiblity service package names.
3514 * @hide
3515 */
3516 @SystemApi
3517 public List<String> getPermittedAccessibilityServices(int userId) {
3518 if (mService != null) {
3519 try {
3520 return mService.getPermittedAccessibilityServicesForUser(userId);
3521 } catch (RemoteException e) {
3522 Log.w(TAG, "Failed talking with device policy service", e);
3523 }
3524 }
3525 return null;
3526 }
3527
3528 /**
3529 * Called by a profile or device owner to set the permitted input methods services. When
3530 * set by a device owner or profile owner the restriction applies to all profiles of the
3531 * user the device owner or profile owner is an admin for.
3532 *
3533 * By default the user can use any input method. When zero or more packages have
3534 * been added, input method that are not in the list and not part of the system
3535 * can not be enabled by the user.
3536 *
3537 * This method will fail if it is called for a admin that is not for the foreground user
3538 * or a profile of the foreground user.
3539 *
3540 * <p> Calling with a null value for the list disables the restriction so that all input methods
3541 * can be used, calling with an empty list disables all but the system's own input methods.
3542 *
3543 * <p> System input methods are always available to the user this method can't modify this.
3544 *
3545 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3546 * @param packageNames List of input method package names.
Kenny Guy74a70242015-02-05 19:48:38 +00003547 * @return true if setting the restriction succeeded. It will fail if there are
3548 * one or more non-system input methods currently enabled that are not in
3549 * the packageNames list.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003550 */
Robin Lee25e26452015-06-02 09:56:29 -07003551 public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003552 if (mService != null) {
3553 try {
3554 return mService.setPermittedInputMethods(admin, packageNames);
3555 } catch (RemoteException e) {
3556 Log.w(TAG, "Failed talking with device policy service", e);
3557 }
3558 }
3559 return false;
3560 }
3561
3562
3563 /**
3564 * Returns the list of permitted input methods set by this device or profile owner.
3565 *
3566 * <p>An empty list means no input methods except system input methods are allowed.
3567 * Null means all input methods are allowed.
3568 *
3569 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3570 * @return List of input method package names.
3571 */
Robin Lee25e26452015-06-02 09:56:29 -07003572 public List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003573 if (mService != null) {
3574 try {
3575 return mService.getPermittedInputMethods(admin);
3576 } catch (RemoteException e) {
3577 Log.w(TAG, "Failed talking with device policy service", e);
3578 }
3579 }
3580 return null;
3581 }
3582
3583 /**
3584 * Returns the list of input methods permitted by the device or profiles
3585 * owners of the current user.
3586 *
3587 * <p>Null means all input methods are allowed, if a non-null list is returned
3588 * it will contain the intersection of the permitted lists for any device or profile
3589 * owners that apply to this user. It will also include any system input methods.
3590 *
3591 * @return List of input method package names.
3592 * @hide
3593 */
3594 @SystemApi
3595 public List<String> getPermittedInputMethodsForCurrentUser() {
3596 if (mService != null) {
3597 try {
3598 return mService.getPermittedInputMethodsForCurrentUser();
3599 } catch (RemoteException e) {
3600 Log.w(TAG, "Failed talking with device policy service", e);
3601 }
3602 }
3603 return null;
3604 }
3605
3606 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003607 * Called by a device owner to create a user with the specified name. The UserHandle returned
3608 * by this method should not be persisted as user handles are recycled as users are removed and
3609 * created. If you need to persist an identifier for this user, use
3610 * {@link UserManager#getSerialNumberForUser}.
3611 *
3612 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3613 * @param name the user's name
3614 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07003615 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
3616 * user could not be created.
Julia Reynolds1e958392014-05-16 14:25:21 -04003617 */
Robin Lee25e26452015-06-02 09:56:29 -07003618 public UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04003619 try {
3620 return mService.createUser(admin, name);
3621 } catch (RemoteException re) {
3622 Log.w(TAG, "Could not create a user", re);
3623 }
3624 return null;
3625 }
3626
3627 /**
Jason Monk03978a42014-06-10 15:05:30 -04003628 * Called by a device owner to create a user with the specified name. The UserHandle returned
3629 * by this method should not be persisted as user handles are recycled as users are removed and
3630 * created. If you need to persist an identifier for this user, use
3631 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
3632 * immediately.
3633 *
3634 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
3635 * as registered as an active admin on the new user. The profile owner package will be
3636 * installed on the new user if it already is installed on the device.
3637 *
3638 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
3639 * profileOwnerComponent when onEnable is called.
3640 *
3641 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3642 * @param name the user's name
3643 * @param ownerName the human readable name of the organisation associated with this DPM.
3644 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
3645 * the user.
3646 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
3647 * on the new user.
3648 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07003649 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
3650 * user could not be created.
Jason Monk03978a42014-06-10 15:05:30 -04003651 */
Robin Lee25e26452015-06-02 09:56:29 -07003652 public UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
3653 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04003654 try {
3655 return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent,
3656 adminExtras);
3657 } catch (RemoteException re) {
3658 Log.w(TAG, "Could not create a user", re);
3659 }
3660 return null;
3661 }
3662
3663 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003664 * Called by a device owner to remove a user and all associated data. The primary user can
3665 * not be removed.
3666 *
3667 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3668 * @param userHandle the user to remove.
3669 * @return {@code true} if the user was removed, {@code false} otherwise.
3670 */
Robin Lee25e26452015-06-02 09:56:29 -07003671 public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) {
Julia Reynolds1e958392014-05-16 14:25:21 -04003672 try {
3673 return mService.removeUser(admin, userHandle);
3674 } catch (RemoteException re) {
3675 Log.w(TAG, "Could not remove user ", re);
3676 return false;
3677 }
3678 }
3679
3680 /**
Jason Monk582d9112014-07-09 19:57:08 -04003681 * Called by a device owner to switch the specified user to the foreground.
3682 *
3683 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3684 * @param userHandle the user to switch to; null will switch to primary.
3685 * @return {@code true} if the switch was successful, {@code false} otherwise.
3686 *
3687 * @see Intent#ACTION_USER_FOREGROUND
3688 */
Robin Lee25e26452015-06-02 09:56:29 -07003689 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Jason Monk582d9112014-07-09 19:57:08 -04003690 try {
3691 return mService.switchUser(admin, userHandle);
3692 } catch (RemoteException re) {
3693 Log.w(TAG, "Could not switch user ", re);
3694 return false;
3695 }
3696 }
3697
3698 /**
Robin Lee66e5d962014-04-09 16:44:21 +01003699 * Called by a profile or device owner to get the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003700 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01003701 *
3702 * <p>The calling device admin must be a profile or device owner; if it is not, a security
3703 * exception will be thrown.
3704 *
3705 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3706 * @param packageName The name of the package to fetch restricted settings of.
3707 * @return {@link Bundle} of settings corresponding to what was set last time
3708 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
3709 * if no restrictions have been set.
3710 */
Robin Lee25e26452015-06-02 09:56:29 -07003711 public Bundle getApplicationRestrictions(@NonNull ComponentName admin, String packageName) {
Robin Lee66e5d962014-04-09 16:44:21 +01003712 if (mService != null) {
3713 try {
3714 return mService.getApplicationRestrictions(admin, packageName);
3715 } catch (RemoteException e) {
3716 Log.w(TAG, "Failed talking with device policy service", e);
3717 }
3718 }
3719 return null;
3720 }
Amith Yamasanibe465322014-04-24 13:45:17 -07003721
3722 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003723 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07003724 * <p>
3725 * The calling device admin must be a profile or device owner; if it is not,
3726 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003727 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003728 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3729 * with.
3730 * @param key The key of the restriction. See the constants in
3731 * {@link android.os.UserManager} for the list of keys.
3732 */
Robin Lee25e26452015-06-02 09:56:29 -07003733 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07003734 if (mService != null) {
3735 try {
3736 mService.setUserRestriction(admin, key, true);
3737 } catch (RemoteException e) {
3738 Log.w(TAG, "Failed talking with device policy service", e);
3739 }
3740 }
3741 }
3742
3743 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003744 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07003745 * <p>
3746 * The calling device admin must be a profile or device owner; if it is not,
3747 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003748 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003749 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3750 * with.
3751 * @param key The key of the restriction. See the constants in
3752 * {@link android.os.UserManager} for the list of keys.
3753 */
Robin Lee25e26452015-06-02 09:56:29 -07003754 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07003755 if (mService != null) {
3756 try {
3757 mService.setUserRestriction(admin, key, false);
3758 } catch (RemoteException e) {
3759 Log.w(TAG, "Failed talking with device policy service", e);
3760 }
3761 }
3762 }
Adam Connors010cfd42014-04-16 12:48:13 +01003763
3764 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003765 * Called by profile or device owners to hide or unhide packages. When a package is hidden it
Julia Reynolds966881e2014-05-14 12:23:08 -04003766 * is unavailable for use, but the data and actual package file remain.
3767 *
3768 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003769 * @param packageName The name of the package to hide or unhide.
3770 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
3771 * unhidden.
3772 * @return boolean Whether the hidden setting of the package was successfully updated.
Julia Reynolds966881e2014-05-14 12:23:08 -04003773 */
Robin Lee25e26452015-06-02 09:56:29 -07003774 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003775 boolean hidden) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003776 if (mService != null) {
3777 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003778 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04003779 } catch (RemoteException e) {
3780 Log.w(TAG, "Failed talking with device policy service", e);
3781 }
3782 }
3783 return false;
3784 }
3785
3786 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003787 * Called by profile or device owners to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04003788 *
3789 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003790 * @param packageName The name of the package to retrieve the hidden status of.
3791 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Julia Reynolds966881e2014-05-14 12:23:08 -04003792 */
Robin Lee25e26452015-06-02 09:56:29 -07003793 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003794 if (mService != null) {
3795 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003796 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04003797 } catch (RemoteException e) {
3798 Log.w(TAG, "Failed talking with device policy service", e);
3799 }
3800 }
3801 return false;
3802 }
3803
3804 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003805 * Called by profile or device owners to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003806 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003807 *
3808 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3809 * @param packageName The package to be re-enabled in the current profile.
3810 */
Robin Lee25e26452015-06-02 09:56:29 -07003811 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Adam Connors655be2a2014-07-14 09:01:25 +00003812 if (mService != null) {
3813 try {
3814 mService.enableSystemApp(admin, packageName);
3815 } catch (RemoteException e) {
3816 Log.w(TAG, "Failed to install package: " + packageName);
3817 }
3818 }
3819 }
3820
3821 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003822 * Called by profile or device owners to re-enable system apps by intent that were disabled
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003823 * by default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003824 *
3825 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3826 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
3827 * intent will be re-enabled in the current profile.
3828 * @return int The number of activities that matched the intent and were installed.
3829 */
Robin Lee25e26452015-06-02 09:56:29 -07003830 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Adam Connors655be2a2014-07-14 09:01:25 +00003831 if (mService != null) {
3832 try {
3833 return mService.enableSystemAppWithIntent(admin, intent);
3834 } catch (RemoteException e) {
3835 Log.w(TAG, "Failed to install packages matching filter: " + intent);
3836 }
3837 }
3838 return 0;
3839 }
3840
3841 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00003842 * Called by a device owner or profile owner to disable account management for a specific type
3843 * of account.
Sander Alewijnse650c3342014-05-08 18:00:50 +01003844 *
Sander Alewijnse112e0532014-10-29 13:28:49 +00003845 * <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 +01003846 * security exception will be thrown.
3847 *
3848 * <p>When account management is disabled for an account type, adding or removing an account
3849 * of that type will not be possible.
3850 *
3851 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3852 * @param accountType For which account management is disabled or enabled.
3853 * @param disabled The boolean indicating that account management will be disabled (true) or
3854 * enabled (false).
3855 */
Robin Lee25e26452015-06-02 09:56:29 -07003856 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01003857 boolean disabled) {
3858 if (mService != null) {
3859 try {
3860 mService.setAccountManagementDisabled(admin, accountType, disabled);
3861 } catch (RemoteException e) {
3862 Log.w(TAG, "Failed talking with device policy service", e);
3863 }
3864 }
3865 }
3866
3867 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003868 * Gets the array of accounts for which account management is disabled by the profile owner.
3869 *
3870 * <p> Account management can be disabled/enabled by calling
3871 * {@link #setAccountManagementDisabled}.
3872 *
3873 * @return a list of account types for which account management has been disabled.
3874 *
3875 * @see #setAccountManagementDisabled
3876 */
3877 public String[] getAccountTypesWithManagementDisabled() {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003878 return getAccountTypesWithManagementDisabledAsUser(UserHandle.myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003879 }
3880
3881 /**
3882 * @see #getAccountTypesWithManagementDisabled()
3883 * @hide
3884 */
3885 public String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003886 if (mService != null) {
3887 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003888 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003889 } catch (RemoteException e) {
3890 Log.w(TAG, "Failed talking with device policy service", e);
3891 }
3892 }
3893
3894 return null;
3895 }
justinzhang511e0d82014-03-24 16:09:24 -04003896
3897 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003898 * Sets which packages may enter lock task mode.
3899 *
3900 * <p>Any packages that shares uid with an allowed package will also be allowed
3901 * to activate lock task.
justinzhang511e0d82014-03-24 16:09:24 -04003902 *
Benjamin Franz469dd582015-06-09 14:24:36 +01003903 * From {@link android.os.Build.VERSION_CODES#MNC} removing packages from the lock task
3904 * package list results in locked tasks belonging to those packages to be finished.
3905 *
Jason Monkc5185f22014-06-24 11:12:42 -04003906 * This function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04003907 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04003908 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jason Monkd7b86212014-06-16 13:15:38 -04003909 *
3910 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00003911 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
3912 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04003913 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04003914 */
Robin Lee25e26452015-06-02 09:56:29 -07003915 public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04003916 throws SecurityException {
justinzhang511e0d82014-03-24 16:09:24 -04003917 if (mService != null) {
3918 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003919 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04003920 } catch (RemoteException e) {
3921 Log.w(TAG, "Failed talking with device policy service", e);
3922 }
3923 }
3924 }
3925
3926 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003927 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04003928 *
3929 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04003930 * @hide
3931 */
Robin Lee25e26452015-06-02 09:56:29 -07003932 public String[] getLockTaskPackages(@NonNull ComponentName admin) {
justinzhang511e0d82014-03-24 16:09:24 -04003933 if (mService != null) {
3934 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003935 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04003936 } catch (RemoteException e) {
3937 Log.w(TAG, "Failed talking with device policy service", e);
3938 }
3939 }
3940 return null;
3941 }
3942
3943 /**
3944 * This function lets the caller know whether the given component is allowed to start the
3945 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04003946 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04003947 */
Jason Monkd7b86212014-06-16 13:15:38 -04003948 public boolean isLockTaskPermitted(String pkg) {
justinzhang511e0d82014-03-24 16:09:24 -04003949 if (mService != null) {
3950 try {
Jason Monkd7b86212014-06-16 13:15:38 -04003951 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04003952 } catch (RemoteException e) {
3953 Log.w(TAG, "Failed talking with device policy service", e);
3954 }
3955 }
3956 return false;
3957 }
Julia Reynoldsda551652014-05-14 17:15:16 -04003958
3959 /**
3960 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
3961 * 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 -04003962 * <p>The settings that can be updated with this method are:
3963 * <ul>
3964 * <li>{@link Settings.Global#ADB_ENABLED}</li>
3965 * <li>{@link Settings.Global#AUTO_TIME}</li>
3966 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Nicolas Prevot41916d42015-02-24 18:41:50 +00003967 * <li>{@link Settings.Global#BLUETOOTH_ON}
3968 * Changing this setting has not effect as of {@link android.os.Build.VERSION_CODES#MNC}. Use
3969 * {@link android.bluetooth.BluetoothAdapter#enable()} and
3970 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003971 * <li>{@link Settings.Global#DATA_ROAMING}</li>
3972 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
3973 * <li>{@link Settings.Global#MODE_RINGER}</li>
3974 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
3975 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Nicolas Prevot41916d42015-02-24 18:41:50 +00003976 * <li>{@link Settings.Global#WIFI_ON}
3977 * Changing this setting has not effect as of {@link android.os.Build.VERSION_CODES#MNC}. Use
3978 * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003979 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Benjamin Franz68cc4202015-03-11 15:43:06 +00003980 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN}
3981 * This setting is only available from {@link android.os.Build.VERSION_CODES#MNC} onwards
3982 * and can only be set if {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003983 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04003984 *
3985 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3986 * @param setting The name of the setting to update.
3987 * @param value The value to update the setting to.
3988 */
Robin Lee25e26452015-06-02 09:56:29 -07003989 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04003990 if (mService != null) {
3991 try {
3992 mService.setGlobalSetting(admin, setting, value);
3993 } catch (RemoteException e) {
3994 Log.w(TAG, "Failed talking with device policy service", e);
3995 }
3996 }
3997 }
3998
3999 /**
4000 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
4001 * that the value of the setting is in the correct form for the setting type should be performed
4002 * by the caller.
Julia Reynolds82735bc2014-09-04 16:43:30 -04004003 * <p>The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004004 * <ul>
4005 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07004006 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004007 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
4008 * </ul>
Julia Reynolds82735bc2014-09-04 16:43:30 -04004009 * <p>A device owner can additionally update the following settings:
4010 * <ul>
4011 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
4012 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04004013 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4014 * @param setting The name of the setting to update.
4015 * @param value The value to update the setting to.
4016 */
Robin Lee25e26452015-06-02 09:56:29 -07004017 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04004018 if (mService != null) {
4019 try {
4020 mService.setSecureSetting(admin, setting, value);
4021 } catch (RemoteException e) {
4022 Log.w(TAG, "Failed talking with device policy service", e);
4023 }
4024 }
4025 }
4026
Amith Yamasanif20d6402014-05-24 15:34:37 -07004027 /**
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004028 * Designates a specific service component as the provider for
Amith Yamasanif20d6402014-05-24 15:34:37 -07004029 * making permission requests of a local or remote administrator of the user.
4030 * <p/>
4031 * Only a profile owner can designate the restrictions provider.
4032 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004033 * @param provider The component name of the service that implements
Amith Yamasanid1d7c022014-08-19 17:03:41 -07004034 * {@link RestrictionsReceiver}. If this param is null,
Amith Yamasanif20d6402014-05-24 15:34:37 -07004035 * it removes the restrictions provider previously assigned.
4036 */
Robin Lee25e26452015-06-02 09:56:29 -07004037 public void setRestrictionsProvider(@NonNull ComponentName admin,
4038 @Nullable ComponentName provider) {
Amith Yamasanif20d6402014-05-24 15:34:37 -07004039 if (mService != null) {
4040 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004041 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07004042 } catch (RemoteException re) {
4043 Log.w(TAG, "Failed to set permission provider on device policy service");
4044 }
4045 }
4046 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04004047
4048 /**
4049 * Called by profile or device owners to set the master volume mute on or off.
4050 *
4051 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4052 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
4053 */
Robin Lee25e26452015-06-02 09:56:29 -07004054 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04004055 if (mService != null) {
4056 try {
4057 mService.setMasterVolumeMuted(admin, on);
4058 } catch (RemoteException re) {
4059 Log.w(TAG, "Failed to setMasterMute on device policy service");
4060 }
4061 }
4062 }
4063
4064 /**
4065 * Called by profile or device owners to check whether the master volume mute is on or off.
4066 *
4067 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4068 * @return {@code true} if master volume is muted, {@code false} if it's not.
4069 */
Robin Lee25e26452015-06-02 09:56:29 -07004070 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04004071 if (mService != null) {
4072 try {
4073 return mService.isMasterVolumeMuted(admin);
4074 } catch (RemoteException re) {
4075 Log.w(TAG, "Failed to get isMasterMute on device policy service");
4076 }
4077 }
4078 return false;
4079 }
Kenny Guyc13053b2014-05-29 14:17:17 +01004080
4081 /**
4082 * Called by profile or device owners to change whether a user can uninstall
4083 * a package.
4084 *
4085 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4086 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004087 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Kenny Guyc13053b2014-05-29 14:17:17 +01004088 */
Robin Lee25e26452015-06-02 09:56:29 -07004089 public void setUninstallBlocked(@NonNull ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004090 boolean uninstallBlocked) {
Kenny Guyc13053b2014-05-29 14:17:17 +01004091 if (mService != null) {
4092 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004093 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01004094 } catch (RemoteException re) {
4095 Log.w(TAG, "Failed to call block uninstall on device policy service");
4096 }
4097 }
4098 }
4099
4100 /**
Rubin Xua97855b2014-11-07 05:41:00 +00004101 * Check whether the current user has been blocked by device policy from uninstalling a package.
4102 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00004103 * <p>
4104 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Robin Lee25e26452015-06-02 09:56:29 -07004105 * behavior of this API is changed such that passing {@code null} as the {@code admin}
Rubin Xue1e6faa2015-03-10 10:51:59 +00004106 * parameter will return if any admin has blocked the uninstallation. Before L MR1, passing
Robin Lee25e26452015-06-02 09:56:29 -07004107 * {@code null} will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01004108 *
Robin Lee25e26452015-06-02 09:56:29 -07004109 * @param admin The name of the admin component whose blocking policy will be checked, or
4110 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01004111 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00004112 * @return true if uninstallation is blocked.
Kenny Guyc13053b2014-05-29 14:17:17 +01004113 */
Robin Lee25e26452015-06-02 09:56:29 -07004114 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Kenny Guyc13053b2014-05-29 14:17:17 +01004115 if (mService != null) {
4116 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01004117 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01004118 } catch (RemoteException re) {
4119 Log.w(TAG, "Failed to call block uninstall on device policy service");
4120 }
4121 }
4122 return false;
4123 }
Svetoslav976e8bd2014-07-16 15:12:03 -07004124
4125 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004126 * Called by the profile owner of a managed profile to enable widget providers from a
4127 * given package to be available in the parent profile. As a result the user will be able to
Svetoslav976e8bd2014-07-16 15:12:03 -07004128 * add widgets from the white-listed package running under the profile to a widget
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004129 * host which runs under the parent profile, for example the home screen. Note that
Svetoslav976e8bd2014-07-16 15:12:03 -07004130 * a package may have zero or more provider components, where each component
4131 * provides a different widget type.
4132 * <p>
4133 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07004134 *
4135 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4136 * @param packageName The package from which widget providers are white-listed.
4137 * @return Whether the package was added.
4138 *
4139 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4140 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4141 */
Robin Lee25e26452015-06-02 09:56:29 -07004142 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004143 if (mService != null) {
4144 try {
4145 return mService.addCrossProfileWidgetProvider(admin, packageName);
4146 } catch (RemoteException re) {
4147 Log.w(TAG, "Error calling addCrossProfileWidgetProvider", re);
4148 }
4149 }
4150 return false;
4151 }
4152
4153 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004154 * Called by the profile owner of a managed profile to disable widget providers from a given
4155 * package to be available in the parent profile. For this method to take effect the
Svetoslav976e8bd2014-07-16 15:12:03 -07004156 * package should have been added via {@link #addCrossProfileWidgetProvider(
4157 * android.content.ComponentName, String)}.
4158 * <p>
4159 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07004160 *
4161 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4162 * @param packageName The package from which widget providers are no longer
4163 * white-listed.
4164 * @return Whether the package was removed.
4165 *
4166 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
4167 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4168 */
Robin Lee25e26452015-06-02 09:56:29 -07004169 public boolean removeCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004170 if (mService != null) {
4171 try {
4172 return mService.removeCrossProfileWidgetProvider(admin, packageName);
4173 } catch (RemoteException re) {
4174 Log.w(TAG, "Error calling removeCrossProfileWidgetProvider", re);
4175 }
4176 }
4177 return false;
4178 }
4179
4180 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004181 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07004182 * available in the parent profile.
4183 *
4184 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4185 * @return The white-listed package list.
4186 *
4187 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
4188 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4189 */
Robin Lee25e26452015-06-02 09:56:29 -07004190 public List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004191 if (mService != null) {
4192 try {
4193 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
4194 if (providers != null) {
4195 return providers;
4196 }
4197 } catch (RemoteException re) {
4198 Log.w(TAG, "Error calling getCrossProfileWidgetProviders", re);
4199 }
4200 }
4201 return Collections.emptyList();
4202 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004203
4204 /**
4205 * Called by profile or device owners to set the current user's photo.
4206 *
4207 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4208 * @param icon the bitmap to set as the photo.
4209 */
Robin Lee25e26452015-06-02 09:56:29 -07004210 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004211 try {
4212 mService.setUserIcon(admin, icon);
4213 } catch (RemoteException re) {
4214 Log.w(TAG, "Could not set the user icon ", re);
4215 }
4216 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04004217
4218 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01004219 * Called by device owners to set a local system update policy. When a new policy is set,
4220 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004221 *
Robin Lee25e26452015-06-02 09:56:29 -07004222 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
4223 * components in the device owner package can set system update policies and the
4224 * most recent policy takes
Rubin Xu5faad8e2015-04-20 17:43:48 +01004225 * effect.
Robin Lee25e26452015-06-02 09:56:29 -07004226 * @param policy the new policy, or {@code null} to clear the current policy.
Rubin Xu5faad8e2015-04-20 17:43:48 +01004227 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00004228 */
Robin Lee25e26452015-06-02 09:56:29 -07004229 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Rubin Xu8027a4f2015-03-10 17:52:37 +00004230 if (mService != null) {
4231 try {
Robin Lee25e26452015-06-02 09:56:29 -07004232 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004233 } catch (RemoteException re) {
Rubin Xu5faad8e2015-04-20 17:43:48 +01004234 Log.w(TAG, "Error calling setSystemUpdatePolicy", re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004235 }
4236 }
4237 }
4238
4239 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01004240 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004241 *
Robin Lee25e26452015-06-02 09:56:29 -07004242 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004243 */
Rubin Xu5faad8e2015-04-20 17:43:48 +01004244 public SystemUpdatePolicy getSystemUpdatePolicy() {
Rubin Xu8027a4f2015-03-10 17:52:37 +00004245 if (mService != null) {
4246 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01004247 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00004248 } catch (RemoteException re) {
Rubin Xu5faad8e2015-04-20 17:43:48 +01004249 Log.w(TAG, "Error calling getSystemUpdatePolicy", re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004250 }
4251 }
4252 return null;
4253 }
Benjamin Franze36087e2015-04-07 16:40:34 +01004254
4255 /**
4256 * Called by a device owner to disable the keyguard altogether.
4257 *
4258 * <p>Setting the keyguard to disabled has the same effect as choosing "None" as the screen
4259 * lock type. However, this call has no effect if a password, pin or pattern is currently set.
4260 * If a password, pin or pattern is set after the keyguard was disabled, the keyguard stops
4261 * being disabled.
4262 *
4263 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01004264 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01004265 *
4266 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Benjamin Franzbece8062015-05-06 12:14:31 +01004267 * place. {@code true} otherwise.
Benjamin Franze36087e2015-04-07 16:40:34 +01004268 */
Robin Lee25e26452015-06-02 09:56:29 -07004269 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franze36087e2015-04-07 16:40:34 +01004270 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01004271 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01004272 } catch (RemoteException re) {
4273 Log.w(TAG, "Failed talking with device policy service", re);
4274 return false;
4275 }
4276 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00004277
4278 /**
Benjamin Franzbece8062015-05-06 12:14:31 +01004279 * Called by device owner to disable the status bar. Disabling the status bar blocks
4280 * notifications, quick settings and other screen overlays that allow escaping from
Benjamin Franzea2ec972015-03-16 17:18:09 +00004281 * a single use device.
4282 *
4283 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01004284 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
4285 *
4286 * @return {@code false} if attempting to disable the status bar failed.
4287 * {@code true} otherwise.
Benjamin Franzea2ec972015-03-16 17:18:09 +00004288 */
Robin Lee25e26452015-06-02 09:56:29 -07004289 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzea2ec972015-03-16 17:18:09 +00004290 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01004291 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00004292 } catch (RemoteException re) {
4293 Log.w(TAG, "Failed talking with device policy service", re);
Benjamin Franzbece8062015-05-06 12:14:31 +01004294 return false;
Benjamin Franzea2ec972015-03-16 17:18:09 +00004295 }
4296 }
Rubin Xudc105cc2015-04-14 23:38:01 +01004297
4298 /**
4299 * Callable by the system update service to notify device owners about pending updates.
4300 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
4301 * permission.
4302 *
4303 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating
4304 * when the current pending update was first available. -1 if no update is available.
4305 * @hide
4306 */
4307 @SystemApi
4308 public void notifyPendingSystemUpdate(long updateReceivedTime) {
4309 if (mService != null) {
4310 try {
4311 mService.notifyPendingSystemUpdate(updateReceivedTime);
4312 } catch (RemoteException re) {
4313 Log.w(TAG, "Could not notify device owner about pending system update", re);
4314 }
4315 }
4316 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04004317
4318 /**
Amith Yamasanid49489b2015-04-28 14:00:26 -07004319 * Called by profile or device owners to set the default response for future runtime permission
4320 * requests by applications. The policy can allow for normal operation which prompts the
4321 * user to grant a permission, or can allow automatic granting or denying of runtime
4322 * permission requests by an application. This also applies to new permissions declared by app
4323 * updates.
4324 * @param admin Which profile or device owner this request is associated with.
4325 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
4326 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
4327 */
Robin Lee25e26452015-06-02 09:56:29 -07004328 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004329 try {
4330 mService.setPermissionPolicy(admin, policy);
4331 } catch (RemoteException re) {
4332 Log.w(TAG, "Failed talking with device policy service", re);
4333 }
4334 }
4335
4336 /**
4337 * Returns the current runtime permission policy set by the device or profile owner. The
4338 * default is {@link #PERMISSION_POLICY_PROMPT}.
4339 * @param admin Which profile or device owner this request is associated with.
4340 * @return the current policy for future permission requests.
4341 */
Robin Lee25e26452015-06-02 09:56:29 -07004342 public int getPermissionPolicy(@NonNull ComponentName admin) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004343 try {
4344 return mService.getPermissionPolicy(admin);
4345 } catch (RemoteException re) {
4346 return PERMISSION_POLICY_PROMPT;
4347 }
4348 }
4349
4350 /**
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004351 * Sets the grant state of a runtime permission for a specific application. The state
4352 * can be {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it
4353 * through the UI, {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission
4354 * is denied and the user cannot manage it through the UI, and {@link
4355 * #PERMISSION_GRANT_STATE_GRANTED granted} in which the permission is granted and the
4356 * user cannot manage it through the UI. This might affect all permissions in a
4357 * group that the runtime permission belongs to. This method can only be called
4358 * by a profile or device owner.
4359 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07004360 * @param admin Which profile or device owner this request is associated with.
4361 * @param packageName The application to grant or revoke a permission to.
4362 * @param permission The permission to grant or revoke.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004363 * @param grantState The permission grant state which is one of {@link
4364 * #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
4365 * {@link #PERMISSION_GRANT_STATE_GRANTED},
4366 * @return whether the permission was successfully granted or revoked.
4367 *
4368 * @see #PERMISSION_GRANT_STATE_DENIED
4369 * @see #PERMISSION_GRANT_STATE_DEFAULT
4370 * @see #PERMISSION_GRANT_STATE_GRANTED
Amith Yamasanid49489b2015-04-28 14:00:26 -07004371 */
Robin Lee25e26452015-06-02 09:56:29 -07004372 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004373 String permission, int grantState) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004374 try {
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004375 return mService.setPermissionGrantState(admin, packageName, permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07004376 } catch (RemoteException re) {
4377 Log.w(TAG, "Failed talking with device policy service", re);
4378 return false;
4379 }
4380 }
Amith Yamasani184b3752015-05-22 13:00:51 -07004381
4382 /**
4383 * Returns the current grant state of a runtime permission for a specific application.
4384 *
4385 * @param admin Which profile or device owner this request is associated with.
4386 * @param packageName The application to check the grant state for.
4387 * @param permission The permission to check for.
4388 * @return the current grant state specified by device policy. If the profile or device owner
4389 * has not set a grant state, the return value is {@link #PERMISSION_GRANT_STATE_DEFAULT}.
4390 * This does not indicate whether or not the permission is currently granted for the package.
4391 *
4392 * <p/>If a grant state was set by the profile or device owner, then the return value will
4393 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or {@link #PERMISSION_GRANT_STATE_GRANTED},
4394 * which indicates if the permission is currently denied or granted.
4395 *
4396 * @see #setPermissionGrantState(ComponentName, String, String, int)
4397 * @see PackageManager#checkPermission(String, String)
4398 */
Robin Lee25e26452015-06-02 09:56:29 -07004399 public int getPermissionGrantState(@NonNull ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07004400 String permission) {
4401 try {
4402 return mService.getPermissionGrantState(admin, packageName, permission);
4403 } catch (RemoteException re) {
4404 Log.w(TAG, "Failed talking with device policy service", re);
4405 return PERMISSION_GRANT_STATE_DEFAULT;
4406 }
4407 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08004408}