blob: 83e06d6c9805d105f934d6b7e04600e942e55e9d [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 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -0400471 * @hide
Rubin Xu44ef750b2015-03-23 16:51:33 +0000472 * On devices managed by a device owner app, a {@link ComponentName} extra indicating the
473 * component of the application that is temporarily granted device owner privileges during
474 * device initialization and profile owner privileges during secondary user initialization.
Julia Reynolds20118f12015-02-11 12:34:08 -0500475 *
Rubin Xu44ef750b2015-03-23 16:51:33 +0000476 * <p>
Rubin Xu6a38e432015-03-26 14:47:45 +0000477 * It can also be used in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts
Rubin Xu44ef750b2015-03-23 16:51:33 +0000478 * device owner provisioning via an NFC bump. For the NFC record, it should be flattened to a
479 * string first.
480 *
481 * @see ComponentName#flattenToShortString()
Julia Reynolds20118f12015-02-11 12:34:08 -0500482 */
483 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_COMPONENT_NAME
484 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_COMPONENT_NAME";
485
486 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -0400487 * @hide
Julia Reynolds20118f12015-02-11 12:34:08 -0500488 * A String extra holding an http url that specifies the download location of the device
489 * initializer package. When not provided it is assumed that the device initializer package is
490 * already installed.
491 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400492 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynolds20118f12015-02-11 12:34:08 -0500493 * provisioning via an NFC bump.
494 */
495 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION
496 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION";
497
498 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -0400499 * @hide
Julia Reynoldsc1731742015-03-19 14:56:28 -0400500 * An int extra holding a minimum required version code for the device initializer package.
501 * If the initializer is already installed on the device, it will only be re-downloaded from
502 * {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION} if the version of
503 * the installed package is less than this version code.
504 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400505 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400506 * provisioning via an NFC bump.
507 */
508 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_MINIMUM_VERSION_CODE
509 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_MINIMUM_VERSION_CODE";
510
511 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -0400512 * @hide
Julia Reynolds20118f12015-02-11 12:34:08 -0500513 * A String extra holding a http cookie header which should be used in the http request to the
514 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION}.
515 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400516 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynolds20118f12015-02-11 12:34:08 -0500517 * provisioning via an NFC bump.
518 */
519 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_COOKIE_HEADER
520 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_COOKIE_HEADER";
521
522 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -0400523 * @hide
Rubin Xud92e7572015-05-18 17:01:13 +0100524 * A String extra holding the URL-safe base64 encoded SHA-256 checksum of the file at download
Rubin Xue30ab112015-03-24 11:22:28 +0000525 * location specified in
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100526 * {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION}.
527 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100528 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_SIGNATURE_CHECKSUM}
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100529 * should be present. The provided checksum should match the checksum of the file at the
530 * download location. If the checksum doesn't match an error will be shown to the user and the
531 * user will be asked to factory reset the device.
Julia Reynolds20118f12015-02-11 12:34:08 -0500532 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400533 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynolds20118f12015-02-11 12:34:08 -0500534 * provisioning via an NFC bump.
535 */
536 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM
537 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM";
538
539 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -0400540 * @hide
Rubin Xud92e7572015-05-18 17:01:13 +0100541 * A String extra holding the URL-safe base64 encoded SHA-256 checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100542 * android package archive at the download location specified in {@link
543 * #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION}.
544 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100545 * <p>The signatures of an android package archive can be obtained using
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100546 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
547 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
548 *
549 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM}
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100550 * should be present. The provided checksum should match the checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100551 * file at the download location. If the checksum doesn't match an error will be shown to the
552 * user and the user will be asked to factory reset the device.
553 *
554 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
555 * provisioning via an NFC bump.
556 */
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100557 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_SIGNATURE_CHECKSUM
558 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_SIGNATURE_CHECKSUM";
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100559
560 /**
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400561 * This MIME type is used for starting the Device Owner provisioning that does not require
562 * provisioning features introduced in Android API level
563 * {@link android.os.Build.VERSION_CODES#MNC} or later levels.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100564 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400565 * <p>For more information about the provisioning process see
566 * {@link #MIME_TYPE_PROVISIONING_NFC_V2}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100567 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000568 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100569 * contains the following properties:
570 * <ul>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400571 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
572 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100573 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400574 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100575 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
576 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
577 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
578 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
579 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
580 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
581 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
582 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
583 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
584 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400585 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100586 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000587 * <p>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400588 * As of {@link android.os.Build.VERSION_CODES#MNC}, the properties should contain
589 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of
590 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only
591 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
592 *
593 * @see #MIME_TYPE_PROVISIONING_NFC_V2
594 *
595 */
596 public static final String MIME_TYPE_PROVISIONING_NFC
597 = "application/com.android.managedprovisioning";
598
599
600 /**
601 * This MIME type is used for starting the Device Owner provisioning that requires
602 * new provisioning features introduced in API version
603 * {@link android.os.Build.VERSION_CODES#MNC} in addition to those supported in earlier
604 * versions.
605 *
606 * <p>During device owner provisioning a device admin app is set as the owner of the device.
607 * 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 +0100608 * user.
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400609 *
610 * <p> A typical use case would be a device that is owned by a company, but used by either an
611 * employee or client.
612 *
613 * <p> The NFC message should be sent to an unprovisioned device.
614 *
615 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
616 * contains the following properties in addition to properties listed at
617 * {@link #MIME_TYPE_PROVISIONING_NFC}:
618 * <ul>
619 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400620 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}.
621 * Replaces {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}. The value of the property
622 * should be converted to a String via
623 * {@link android.content.ComponentName#flattenToString()}</li>
Craig Lafayette240e6482015-06-02 11:12:43 -0400624 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE}, optional</li></ul>
Nicolas Prevot18440252015-03-09 14:07:17 +0000625 *
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100626 * <p> When device owner provisioning has completed, an intent of the type
627 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcasted to the
628 * device owner.
629 *
630 * <p>
631 * If provisioning fails, the device is factory reset.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100632 */
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400633 public static final String MIME_TYPE_PROVISIONING_NFC_V2
634 = "application/com.android.managedprovisioning.v2";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100635
636 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800637 * Activity action: ask the user to add a new device administrator to the system.
638 * The desired policy is the ComponentName of the policy in the
639 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
640 * bring the user through adding the device administrator to the system (or
641 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700642 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800643 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
644 * field to provide the user with additional explanation (in addition
645 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800646 *
647 * <p>If your administrator is already active, this will ordinarily return immediately (without
648 * user intervention). However, if your administrator has been updated and is requesting
649 * additional uses-policy flags, the user will be presented with the new list. New policies
650 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800651 */
652 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
653 public static final String ACTION_ADD_DEVICE_ADMIN
654 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700655
Dianne Hackbornd6847842010-01-12 18:14:19 -0800656 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700657 * @hide
658 * Activity action: ask the user to add a new device administrator as the profile owner
Amith Yamasani814e9872015-03-23 14:04:53 -0700659 * for this user. Only system apps can launch this intent.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700660 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700661 * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN}
662 * extra field. This will invoke a UI to bring the user through adding the profile owner admin
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700663 * to remotely control restrictions on the user.
664 *
665 * <p>The intent must be invoked via {@link Activity#startActivityForResult()} to receive the
666 * result of whether or not the user approved the action. If approved, the result will
667 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
668 * as a profile owner.
669 *
670 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
671 * field to provide the user with additional explanation (in addition
672 * to your component's description) about what is being added.
673 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700674 * <p>If there is already a profile owner active or the caller is not a system app, the
675 * operation will return a failure result.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700676 */
677 @SystemApi
678 public static final String ACTION_SET_PROFILE_OWNER
679 = "android.app.action.SET_PROFILE_OWNER";
680
681 /**
682 * @hide
683 * Name of the profile owner admin that controls the user.
684 */
685 @SystemApi
686 public static final String EXTRA_PROFILE_OWNER_NAME
687 = "android.app.extra.PROFILE_OWNER_NAME";
688
689 /**
Jim Miller284b62e2010-06-08 14:27:42 -0700690 * Activity action: send when any policy admin changes a policy.
691 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700692 *
Jim Miller284b62e2010-06-08 14:27:42 -0700693 * @hide
694 */
695 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
696 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
697
698 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800699 * The ComponentName of the administrator component.
700 *
701 * @see #ACTION_ADD_DEVICE_ADMIN
702 */
703 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700704
Dianne Hackbornd6847842010-01-12 18:14:19 -0800705 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800706 * An optional CharSequence providing additional explanation for why the
707 * admin is being added.
708 *
709 * @see #ACTION_ADD_DEVICE_ADMIN
710 */
711 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700712
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800713 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700714 * Activity action: have the user enter a new password. This activity should
715 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
716 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
717 * enter a new password that meets the current requirements. You can use
718 * {@link #isActivePasswordSufficient()} to determine whether you need to
719 * have the user select a new password in order to meet the current
720 * constraints. Upon being resumed from this activity, you can check the new
721 * password characteristics to see if they are sufficient.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800722 */
723 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
724 public static final String ACTION_SET_NEW_PASSWORD
725 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700726
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000727 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000728 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
729 * the parent profile to access intents sent from the managed profile.
730 * That is, when an app in the managed profile calls
731 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
732 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000733 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100734 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000735
736 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000737 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
738 * the managed profile to access intents sent from the parent profile.
739 * That is, when an app in the parent profile calls
740 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
741 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000742 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100743 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700744
Dianne Hackbornd6847842010-01-12 18:14:19 -0800745 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +0100746 * Broadcast action: notify that a new local system update policy has been set by the device
747 * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}.
Rubin Xu8027a4f2015-03-10 17:52:37 +0000748 */
749 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Rubin Xu5faad8e2015-04-20 17:43:48 +0100750 public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED
751 = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED";
Rubin Xu8027a4f2015-03-10 17:52:37 +0000752
Amith Yamasanid49489b2015-04-28 14:00:26 -0700753 /**
754 * Permission policy to prompt user for new permission requests for runtime permissions.
755 * Already granted or denied permissions are not affected by this.
756 */
757 public static final int PERMISSION_POLICY_PROMPT = 0;
758
759 /**
760 * Permission policy to always grant new permission requests for runtime permissions.
761 * Already granted or denied permissions are not affected by this.
762 */
763 public static final int PERMISSION_POLICY_AUTO_GRANT = 1;
764
765 /**
766 * Permission policy to always deny new permission requests for runtime permissions.
767 * Already granted or denied permissions are not affected by this.
768 */
769 public static final int PERMISSION_POLICY_AUTO_DENY = 2;
770
Svet Ganovd8ecc5a2015-05-20 10:45:43 -0700771 /**
772 * Runtime permission state: The user can manage the permission
773 * through the UI.
774 */
775 public static final int PERMISSION_GRANT_STATE_DEFAULT = 0;
776
777 /**
778 * Runtime permission state: The permission is granted to the app
779 * and the user cannot manage the permission through the UI.
780 */
781 public static final int PERMISSION_GRANT_STATE_GRANTED = 1;
782
783 /**
784 * Runtime permission state: The permission is denied to the app
785 * and the user cannot manage the permission through the UI.
786 */
787 public static final int PERMISSION_GRANT_STATE_DENIED = 2;
Rubin Xu8027a4f2015-03-10 17:52:37 +0000788
789 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800790 * Return true if the given administrator component is currently
791 * active (enabled) in the system.
792 */
Robin Lee25e26452015-06-02 09:56:29 -0700793 public boolean isAdminActive(@NonNull ComponentName admin) {
794 return isAdminActiveAsUser(admin, UserHandle.myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100795 }
796
797 /**
798 * @see #isAdminActive(ComponentName)
799 * @hide
800 */
Robin Lee25e26452015-06-02 09:56:29 -0700801 public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800802 if (mService != null) {
803 try {
Robin Lee25e26452015-06-02 09:56:29 -0700804 return mService.isAdminActive(admin, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800805 } catch (RemoteException e) {
806 Log.w(TAG, "Failed talking with device policy service", e);
807 }
808 }
809 return false;
810 }
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800811 /**
812 * Return true if the given administrator component is currently being removed
813 * for the user.
814 * @hide
815 */
Robin Lee25e26452015-06-02 09:56:29 -0700816 public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) {
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800817 if (mService != null) {
818 try {
Robin Lee25e26452015-06-02 09:56:29 -0700819 return mService.isRemovingAdmin(admin, userId);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800820 } catch (RemoteException e) {
821 Log.w(TAG, "Failed talking with device policy service", e);
822 }
823 }
824 return false;
825 }
826
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700827
Dianne Hackbornd6847842010-01-12 18:14:19 -0800828 /**
Robin Lee25e26452015-06-02 09:56:29 -0700829 * Return a list of all currently active device administrators' component
830 * names. If there are no administrators {@code null} may be
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800831 * returned.
832 */
833 public List<ComponentName> getActiveAdmins() {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100834 return getActiveAdminsAsUser(UserHandle.myUserId());
835 }
836
837 /**
838 * @see #getActiveAdmins()
839 * @hide
840 */
841 public List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800842 if (mService != null) {
843 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100844 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800845 } catch (RemoteException e) {
846 Log.w(TAG, "Failed talking with device policy service", e);
847 }
848 }
849 return null;
850 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700851
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800852 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700853 * Used by package administration code to determine if a package can be stopped
854 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800855 * @hide
856 */
857 public boolean packageHasActiveAdmins(String packageName) {
858 if (mService != null) {
859 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700860 return mService.packageHasActiveAdmins(packageName, UserHandle.myUserId());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800861 } catch (RemoteException e) {
862 Log.w(TAG, "Failed talking with device policy service", e);
863 }
864 }
865 return false;
866 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700867
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800868 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800869 * Remove a current administration component. This can only be called
870 * by the application that owns the administration component; if you
871 * try to remove someone else's component, a security exception will be
872 * thrown.
873 */
Robin Lee25e26452015-06-02 09:56:29 -0700874 public void removeActiveAdmin(@NonNull ComponentName admin) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800875 if (mService != null) {
876 try {
Robin Lee25e26452015-06-02 09:56:29 -0700877 mService.removeActiveAdmin(admin, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800878 } catch (RemoteException e) {
879 Log.w(TAG, "Failed talking with device policy service", e);
880 }
881 }
882 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700883
Dianne Hackbornd6847842010-01-12 18:14:19 -0800884 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800885 * Returns true if an administrator has been granted a particular device policy. This can
Robin Lee25e26452015-06-02 09:56:29 -0700886 * be used to check whether the administrator was activated under an earlier set of policies,
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800887 * but requires additional policies after an upgrade.
888 *
889 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be
890 * an active administrator, or an exception will be thrown.
891 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
892 */
Robin Lee25e26452015-06-02 09:56:29 -0700893 public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) {
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800894 if (mService != null) {
895 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700896 return mService.hasGrantedPolicy(admin, usesPolicy, UserHandle.myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800897 } catch (RemoteException e) {
898 Log.w(TAG, "Failed talking with device policy service", e);
899 }
900 }
901 return false;
902 }
903
904 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800905 * Constant for {@link #setPasswordQuality}: the policy has no requirements
906 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800907 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800908 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800909 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700910
Dianne Hackbornd6847842010-01-12 18:14:19 -0800911 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700912 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
913 * recognition technology. This implies technologies that can recognize the identity of
914 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
915 * Note that quality constants are ordered so that higher values are more restrictive.
916 */
917 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
918
919 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800920 * Constant for {@link #setPasswordQuality}: the policy requires some kind
Benjamin Franzc6a96532015-06-16 11:23:38 +0100921 * of password or pattern, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800922 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800923 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800924 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700925
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800926 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800927 * Constant for {@link #setPasswordQuality}: the user must have entered a
928 * password containing at least numeric characters. Note that quality
929 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800930 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800931 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700932
Dianne Hackbornd6847842010-01-12 18:14:19 -0800933 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800934 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -0800935 * password containing at least numeric characters with no repeating (4444)
936 * or ordered (1234, 4321, 2468) sequences. Note that quality
937 * constants are ordered so that higher values are more restrictive.
938 */
939 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
940
941 /**
942 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700943 * password containing at least alphabetic (or other symbol) characters.
944 * Note that quality constants are ordered so that higher values are more
945 * restrictive.
946 */
947 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700948
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700949 /**
950 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800951 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700952 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800953 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800954 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700955 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700956
Dianne Hackbornd6847842010-01-12 18:14:19 -0800957 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700958 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700959 * password containing at least a letter, a numerical digit and a special
960 * symbol, by default. With this password quality, passwords can be
961 * restricted to contain various sets of characters, like at least an
962 * uppercase letter, etc. These are specified using various methods,
963 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
964 * that quality constants are ordered so that higher values are more
965 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700966 */
967 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
968
969 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800970 * Called by an application that is administering the device to set the
971 * password restrictions it is imposing. After setting this, the user
972 * will not be able to enter a new password that is not at least as
973 * restrictive as what has been set. Note that the current password
974 * will remain until the user has set a new one, so the change does not
975 * take place immediately. To prompt the user for a new password, use
976 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700977 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800978 * <p>Quality constants are ordered so that higher values are more restrictive;
979 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800980 * the user's preference, and any other considerations) is the one that
981 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700982 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800983 * <p>The calling device admin must have requested
984 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
985 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700986 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800987 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800988 * @param quality The new desired quality. One of
989 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Jim Miller85516d02014-01-31 17:08:37 -0800990 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
991 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}
992 * or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800993 */
Robin Lee25e26452015-06-02 09:56:29 -0700994 public void setPasswordQuality(@NonNull ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800995 if (mService != null) {
996 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -0800997 mService.setPasswordQuality(admin, quality);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800998 } catch (RemoteException e) {
999 Log.w(TAG, "Failed talking with device policy service", e);
1000 }
1001 }
1002 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001003
Dianne Hackbornd6847842010-01-12 18:14:19 -08001004 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001005 * Retrieve the current minimum password quality for all admins of this user
1006 * and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001007 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001008 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001009 */
Robin Lee25e26452015-06-02 09:56:29 -07001010 public int getPasswordQuality(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001011 return getPasswordQuality(admin, UserHandle.myUserId());
1012 }
1013
1014 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001015 public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001016 if (mService != null) {
1017 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001018 return mService.getPasswordQuality(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001019 } catch (RemoteException e) {
1020 Log.w(TAG, "Failed talking with device policy service", e);
1021 }
1022 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001023 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001024 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001025
Dianne Hackbornd6847842010-01-12 18:14:19 -08001026 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001027 * Called by an application that is administering the device to set the
1028 * minimum allowed password length. After setting this, the user
1029 * will not be able to enter a new password that is not at least as
1030 * restrictive as what has been set. Note that the current password
1031 * will remain until the user has set a new one, so the change does not
1032 * take place immediately. To prompt the user for a new password, use
1033 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1034 * constraint is only imposed if the administrator has also requested either
Jim Miller85516d02014-01-31 17:08:37 -08001035 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
1036 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC},
1037 * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001038 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001039 * <p>The calling device admin must have requested
1040 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1041 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001042 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001043 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001044 * @param length The new desired minimum password length. A value of 0
1045 * means there is no restriction.
1046 */
Robin Lee25e26452015-06-02 09:56:29 -07001047 public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001048 if (mService != null) {
1049 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001050 mService.setPasswordMinimumLength(admin, length);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001051 } catch (RemoteException e) {
1052 Log.w(TAG, "Failed talking with device policy service", e);
1053 }
1054 }
1055 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001056
Dianne Hackbornd6847842010-01-12 18:14:19 -08001057 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001058 * Retrieve the current minimum password length for all admins of this
1059 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001060 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001061 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001062 */
Robin Lee25e26452015-06-02 09:56:29 -07001063 public int getPasswordMinimumLength(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001064 return getPasswordMinimumLength(admin, UserHandle.myUserId());
1065 }
1066
1067 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001068 public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001069 if (mService != null) {
1070 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001071 return mService.getPasswordMinimumLength(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001072 } catch (RemoteException e) {
1073 Log.w(TAG, "Failed talking with device policy service", e);
1074 }
1075 }
1076 return 0;
1077 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001078
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001079 /**
1080 * Called by an application that is administering the device to set the
1081 * minimum number of upper case letters required in the password. After
1082 * setting this, the user will not be able to enter a new password that is
1083 * not at least as restrictive as what has been set. Note that the current
1084 * password will remain until the user has set a new one, so the change does
1085 * not take place immediately. To prompt the user for a new password, use
1086 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1087 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001088 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1089 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001090 * <p>
1091 * The calling device admin must have requested
1092 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1093 * this method; if it has not, a security exception will be thrown.
1094 *
1095 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1096 * with.
1097 * @param length The new desired minimum number of upper case letters
1098 * required in the password. A value of 0 means there is no
1099 * restriction.
1100 */
Robin Lee25e26452015-06-02 09:56:29 -07001101 public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001102 if (mService != null) {
1103 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001104 mService.setPasswordMinimumUpperCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001105 } catch (RemoteException e) {
1106 Log.w(TAG, "Failed talking with device policy service", e);
1107 }
1108 }
1109 }
1110
1111 /**
1112 * Retrieve the current number of upper case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001113 * password for all admins of this user and its profiles or a particular one.
1114 * This is the same value as set by
1115 * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001116 * and only applies when the password quality is
1117 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001118 *
Robin Lee25e26452015-06-02 09:56:29 -07001119 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001120 * aggregate all admins.
1121 * @return The minimum number of upper case letters required in the
1122 * password.
1123 */
Robin Lee25e26452015-06-02 09:56:29 -07001124 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001125 return getPasswordMinimumUpperCase(admin, UserHandle.myUserId());
1126 }
1127
1128 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001129 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001130 if (mService != null) {
1131 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001132 return mService.getPasswordMinimumUpperCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001133 } catch (RemoteException e) {
1134 Log.w(TAG, "Failed talking with device policy service", e);
1135 }
1136 }
1137 return 0;
1138 }
1139
1140 /**
1141 * Called by an application that is administering the device to set the
1142 * minimum number of lower case letters required in the password. After
1143 * setting this, the user will not be able to enter a new password that is
1144 * not at least as restrictive as what has been set. Note that the current
1145 * password will remain until the user has set a new one, so the change does
1146 * not take place immediately. To prompt the user for a new password, use
1147 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1148 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001149 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1150 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001151 * <p>
1152 * The calling device admin must have requested
1153 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1154 * this method; if it has not, a security exception will be thrown.
1155 *
1156 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1157 * with.
1158 * @param length The new desired minimum number of lower case letters
1159 * required in the password. A value of 0 means there is no
1160 * restriction.
1161 */
Robin Lee25e26452015-06-02 09:56:29 -07001162 public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001163 if (mService != null) {
1164 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001165 mService.setPasswordMinimumLowerCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001166 } catch (RemoteException e) {
1167 Log.w(TAG, "Failed talking with device policy service", e);
1168 }
1169 }
1170 }
1171
1172 /**
1173 * Retrieve the current number of lower case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001174 * password for all admins of this user and its profiles or a particular one.
1175 * This is the same value as set by
1176 * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001177 * and only applies when the password quality is
1178 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001179 *
Robin Lee25e26452015-06-02 09:56:29 -07001180 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001181 * aggregate all admins.
1182 * @return The minimum number of lower case letters required in the
1183 * password.
1184 */
Robin Lee25e26452015-06-02 09:56:29 -07001185 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001186 return getPasswordMinimumLowerCase(admin, UserHandle.myUserId());
1187 }
1188
1189 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001190 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001191 if (mService != null) {
1192 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001193 return mService.getPasswordMinimumLowerCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001194 } catch (RemoteException e) {
1195 Log.w(TAG, "Failed talking with device policy service", e);
1196 }
1197 }
1198 return 0;
1199 }
1200
1201 /**
1202 * Called by an application that is administering the device to set the
1203 * minimum number of letters required in the password. After setting this,
1204 * the user will not be able to enter a new password that is not at least as
1205 * restrictive as what has been set. Note that the current password will
1206 * remain until the user has set a new one, so the change does not take
1207 * place immediately. To prompt the user for a new password, use
1208 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1209 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001210 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1211 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001212 * <p>
1213 * The calling device admin must have requested
1214 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1215 * this method; if it has not, a security exception will be thrown.
1216 *
1217 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1218 * with.
1219 * @param length The new desired minimum number of letters required in the
1220 * password. A value of 0 means there is no restriction.
1221 */
Robin Lee25e26452015-06-02 09:56:29 -07001222 public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001223 if (mService != null) {
1224 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001225 mService.setPasswordMinimumLetters(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001226 } catch (RemoteException e) {
1227 Log.w(TAG, "Failed talking with device policy service", e);
1228 }
1229 }
1230 }
1231
1232 /**
1233 * Retrieve the current number of letters required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001234 * admins or a particular one. This is the same value as
1235 * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)}
1236 * and only applies when the password quality is
1237 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001238 *
Robin Lee25e26452015-06-02 09:56:29 -07001239 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001240 * aggregate all admins.
1241 * @return The minimum number of letters required in the password.
1242 */
Robin Lee25e26452015-06-02 09:56:29 -07001243 public int getPasswordMinimumLetters(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001244 return getPasswordMinimumLetters(admin, UserHandle.myUserId());
1245 }
1246
1247 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001248 public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001249 if (mService != null) {
1250 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001251 return mService.getPasswordMinimumLetters(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001252 } catch (RemoteException e) {
1253 Log.w(TAG, "Failed talking with device policy service", e);
1254 }
1255 }
1256 return 0;
1257 }
1258
1259 /**
1260 * Called by an application that is administering the device to set the
1261 * minimum number of numerical digits required in the password. After
1262 * setting this, the user will not be able to enter a new password that is
1263 * not at least as restrictive as what has been set. Note that the current
1264 * password will remain until the user has set a new one, so the change does
1265 * not take place immediately. To prompt the user for a new password, use
1266 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1267 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001268 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1269 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001270 * <p>
1271 * The calling device admin must have requested
1272 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1273 * this method; if it has not, a security exception will be thrown.
1274 *
1275 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1276 * with.
1277 * @param length The new desired minimum number of numerical digits required
1278 * in the password. A value of 0 means there is no restriction.
1279 */
Robin Lee25e26452015-06-02 09:56:29 -07001280 public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001281 if (mService != null) {
1282 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001283 mService.setPasswordMinimumNumeric(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001284 } catch (RemoteException e) {
1285 Log.w(TAG, "Failed talking with device policy service", e);
1286 }
1287 }
1288 }
1289
1290 /**
1291 * Retrieve the current number of numerical digits required in the password
Jessica Hummel91da58d2014-04-10 17:39:43 +01001292 * for all admins of this user and its profiles or a particular one.
1293 * This is the same value as set by
1294 * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001295 * and only applies when the password quality is
1296 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001297 *
Robin Lee25e26452015-06-02 09:56:29 -07001298 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001299 * aggregate all admins.
1300 * @return The minimum number of numerical digits required in the password.
1301 */
Robin Lee25e26452015-06-02 09:56:29 -07001302 public int getPasswordMinimumNumeric(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001303 return getPasswordMinimumNumeric(admin, UserHandle.myUserId());
1304 }
1305
1306 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001307 public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001308 if (mService != null) {
1309 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001310 return mService.getPasswordMinimumNumeric(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001311 } catch (RemoteException e) {
1312 Log.w(TAG, "Failed talking with device policy service", e);
1313 }
1314 }
1315 return 0;
1316 }
1317
1318 /**
1319 * Called by an application that is administering the device to set the
1320 * minimum number of symbols required in the password. After setting this,
1321 * the user will not be able to enter a new password that is not at least as
1322 * restrictive as what has been set. Note that the current password will
1323 * remain until the user has set a new one, so the change does not take
1324 * place immediately. To prompt the user for a new password, use
1325 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1326 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001327 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1328 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001329 * <p>
1330 * The calling device admin must have requested
1331 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1332 * this method; if it has not, a security exception will be thrown.
1333 *
1334 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1335 * with.
1336 * @param length The new desired minimum number of symbols required in the
1337 * password. A value of 0 means there is no restriction.
1338 */
Robin Lee25e26452015-06-02 09:56:29 -07001339 public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001340 if (mService != null) {
1341 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001342 mService.setPasswordMinimumSymbols(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001343 } catch (RemoteException e) {
1344 Log.w(TAG, "Failed talking with device policy service", e);
1345 }
1346 }
1347 }
1348
1349 /**
1350 * Retrieve the current number of symbols required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001351 * admins or a particular one. This is the same value as
1352 * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)}
1353 * and only applies when the password quality is
1354 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001355 *
Robin Lee25e26452015-06-02 09:56:29 -07001356 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001357 * aggregate all admins.
1358 * @return The minimum number of symbols required in the password.
1359 */
Robin Lee25e26452015-06-02 09:56:29 -07001360 public int getPasswordMinimumSymbols(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001361 return getPasswordMinimumSymbols(admin, UserHandle.myUserId());
1362 }
1363
1364 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001365 public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001366 if (mService != null) {
1367 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001368 return mService.getPasswordMinimumSymbols(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001369 } catch (RemoteException e) {
1370 Log.w(TAG, "Failed talking with device policy service", e);
1371 }
1372 }
1373 return 0;
1374 }
1375
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001376 /**
1377 * Called by an application that is administering the device to set the
1378 * minimum number of non-letter characters (numerical digits or symbols)
1379 * required in the password. After setting this, the user will not be able
1380 * to enter a new password that is not at least as restrictive as what has
1381 * been set. Note that the current password will remain until the user has
1382 * set a new one, so the change does not take place immediately. To prompt
1383 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after
1384 * setting this value. This constraint is only imposed if the administrator
1385 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1386 * {@link #setPasswordQuality}. The default value is 0.
1387 * <p>
1388 * The calling device admin must have requested
1389 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1390 * this method; if it has not, a security exception will be thrown.
1391 *
1392 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1393 * with.
1394 * @param length The new desired minimum number of letters required in the
1395 * password. A value of 0 means there is no restriction.
1396 */
Robin Lee25e26452015-06-02 09:56:29 -07001397 public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001398 if (mService != null) {
1399 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001400 mService.setPasswordMinimumNonLetter(admin, length);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001401 } catch (RemoteException e) {
1402 Log.w(TAG, "Failed talking with device policy service", e);
1403 }
1404 }
1405 }
1406
1407 /**
1408 * Retrieve the current number of non-letter characters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001409 * password for all admins of this user and its profiles or a particular one.
1410 * This is the same value as set by
1411 * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001412 * and only applies when the password quality is
1413 * {@link #PASSWORD_QUALITY_COMPLEX}.
1414 *
Robin Lee25e26452015-06-02 09:56:29 -07001415 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001416 * aggregate all admins.
1417 * @return The minimum number of letters required in the password.
1418 */
Robin Lee25e26452015-06-02 09:56:29 -07001419 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001420 return getPasswordMinimumNonLetter(admin, UserHandle.myUserId());
1421 }
1422
1423 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001424 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001425 if (mService != null) {
1426 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001427 return mService.getPasswordMinimumNonLetter(admin, userHandle);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001428 } catch (RemoteException e) {
1429 Log.w(TAG, "Failed talking with device policy service", e);
1430 }
1431 }
1432 return 0;
1433 }
1434
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001435 /**
1436 * Called by an application that is administering the device to set the length
1437 * of the password history. After setting this, the user will not be able to
1438 * enter a new password that is the same as any password in the history. Note
1439 * that the current password will remain until the user has set a new one, so
1440 * the change does not take place immediately. To prompt the user for a new
1441 * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
1442 * This constraint is only imposed if the administrator has also requested
Jim Miller85516d02014-01-31 17:08:37 -08001443 * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}
1444 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1445 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001446 *
1447 * <p>
1448 * The calling device admin must have requested
1449 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
1450 * method; if it has not, a security exception will be thrown.
1451 *
1452 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1453 * with.
1454 * @param length The new desired length of password history. A value of 0
1455 * means there is no restriction.
1456 */
Robin Lee25e26452015-06-02 09:56:29 -07001457 public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001458 if (mService != null) {
1459 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001460 mService.setPasswordHistoryLength(admin, length);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001461 } catch (RemoteException e) {
1462 Log.w(TAG, "Failed talking with device policy service", e);
1463 }
1464 }
1465 }
1466
1467 /**
Jim Millera4e28d12010-11-08 16:15:47 -08001468 * Called by a device admin to set the password expiration timeout. Calling this method
1469 * will restart the countdown for password expiration for the given admin, as will changing
1470 * the device password (for all admins).
1471 *
1472 * <p>The provided timeout is the time delta in ms and will be added to the current time.
1473 * For example, to have the password expire 5 days from now, timeout would be
1474 * 5 * 86400 * 1000 = 432000000 ms for timeout.
1475 *
1476 * <p>To disable password expiration, a value of 0 may be used for timeout.
1477 *
Jim Millera4e28d12010-11-08 16:15:47 -08001478 * <p>The calling device admin must have requested
1479 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
1480 * method; if it has not, a security exception will be thrown.
1481 *
Jessica Hummel9da60392014-05-21 12:32:57 +01001482 * <p> Note that setting the password will automatically reset the expiration time for all
1483 * active admins. Active admins do not need to explicitly call this method in that case.
1484 *
Jim Millera4e28d12010-11-08 16:15:47 -08001485 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1486 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
1487 * means there is no restriction (unlimited).
1488 */
Robin Lee25e26452015-06-02 09:56:29 -07001489 public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) {
Jim Millera4e28d12010-11-08 16:15:47 -08001490 if (mService != null) {
1491 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001492 mService.setPasswordExpirationTimeout(admin, timeout);
Jim Millera4e28d12010-11-08 16:15:47 -08001493 } catch (RemoteException e) {
1494 Log.w(TAG, "Failed talking with device policy service", e);
1495 }
1496 }
1497 }
1498
1499 /**
Jim Miller6b857682011-02-16 16:27:41 -08001500 * Get the password expiration timeout for the given admin. The expiration timeout is the
1501 * recurring expiration timeout provided in the call to
1502 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
Robin Lee25e26452015-06-02 09:56:29 -07001503 * aggregate of all policy administrators if {@code admin} is null.
Jim Millera4e28d12010-11-08 16:15:47 -08001504 *
Robin Lee25e26452015-06-02 09:56:29 -07001505 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001506 * @return The timeout for the given admin or the minimum of all timeouts
1507 */
Robin Lee25e26452015-06-02 09:56:29 -07001508 public long getPasswordExpirationTimeout(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001509 if (mService != null) {
1510 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001511 return mService.getPasswordExpirationTimeout(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001512 } catch (RemoteException e) {
1513 Log.w(TAG, "Failed talking with device policy service", e);
1514 }
1515 }
1516 return 0;
1517 }
1518
1519 /**
1520 * Get the current password expiration time for the given admin or an aggregate of
Jessica Hummel91da58d2014-04-10 17:39:43 +01001521 * all admins of this user and its profiles if admin is null. If the password is
1522 * expired, this will return the time since the password expired as a negative number.
1523 * If admin is null, then a composite of all expiration timeouts is returned
1524 * - which will be the minimum of all timeouts.
Jim Millera4e28d12010-11-08 16:15:47 -08001525 *
Robin Lee25e26452015-06-02 09:56:29 -07001526 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001527 * @return The password expiration time, in ms.
1528 */
Robin Lee25e26452015-06-02 09:56:29 -07001529 public long getPasswordExpiration(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001530 if (mService != null) {
1531 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001532 return mService.getPasswordExpiration(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001533 } catch (RemoteException e) {
1534 Log.w(TAG, "Failed talking with device policy service", e);
1535 }
1536 }
1537 return 0;
1538 }
1539
1540 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001541 * Retrieve the current password history length for all admins of this
1542 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001543 * @param admin The name of the admin component to check, or {@code null} to aggregate
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001544 * all admins.
1545 * @return The length of the password history
1546 */
Robin Lee25e26452015-06-02 09:56:29 -07001547 public int getPasswordHistoryLength(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001548 return getPasswordHistoryLength(admin, UserHandle.myUserId());
1549 }
1550
1551 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001552 public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001553 if (mService != null) {
1554 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001555 return mService.getPasswordHistoryLength(admin, userHandle);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001556 } catch (RemoteException e) {
1557 Log.w(TAG, "Failed talking with device policy service", e);
1558 }
1559 }
1560 return 0;
1561 }
1562
Dianne Hackbornd6847842010-01-12 18:14:19 -08001563 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001564 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001565 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08001566 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001567 * @return Returns the maximum length that the user can enter.
1568 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001569 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001570 // Kind-of arbitrary.
1571 return 16;
1572 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001573
Dianne Hackborn254cb442010-01-27 19:23:59 -08001574 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001575 * Determine whether the current password the user has set is sufficient
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001576 * to meet the policy requirements (quality, minimum length) that have been
Jessica Hummel91da58d2014-04-10 17:39:43 +01001577 * requested by the admins of this user and its profiles.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001578 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001579 * <p>The calling device admin must have requested
1580 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1581 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001582 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001583 * @return Returns true if the password meets the current requirements, else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001584 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001585 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001586 if (mService != null) {
1587 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001588 return mService.isActivePasswordSufficient(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001589 } catch (RemoteException e) {
1590 Log.w(TAG, "Failed talking with device policy service", e);
1591 }
1592 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001593 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001594 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001595
Dianne Hackbornd6847842010-01-12 18:14:19 -08001596 /**
1597 * Retrieve the number of times the user has failed at entering a
1598 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001599 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001600 * <p>The calling device admin must have requested
1601 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
1602 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001603 */
1604 public int getCurrentFailedPasswordAttempts() {
1605 if (mService != null) {
1606 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001607 return mService.getCurrentFailedPasswordAttempts(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001608 } catch (RemoteException e) {
1609 Log.w(TAG, "Failed talking with device policy service", e);
1610 }
1611 }
1612 return -1;
1613 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001614
1615 /**
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001616 * Queries whether {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001617 *
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001618 * @return true if RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001619 * @hide
1620 */
1621 public boolean getDoNotAskCredentialsOnBoot() {
1622 if (mService != null) {
1623 try {
1624 return mService.getDoNotAskCredentialsOnBoot();
1625 } catch (RemoteException e) {
1626 Log.w(TAG, "Failed to call getDoNotAskCredentialsOnBoot()", e);
1627 }
1628 }
1629 return false;
1630 }
1631
1632 /**
Andrew Stadler88209d12010-02-08 22:59:36 -08001633 * Setting this to a value greater than zero enables a built-in policy
1634 * that will perform a device wipe after too many incorrect
1635 * device-unlock passwords have been entered. This built-in policy combines
1636 * watching for failed passwords and wiping the device, and requires
1637 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001638 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001639 *
Andrew Stadler88209d12010-02-08 22:59:36 -08001640 * <p>To implement any other policy (e.g. wiping data for a particular
1641 * application only, erasing or revoking credentials, or reporting the
1642 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001643 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -08001644 * instead. Do not use this API, because if the maximum count is reached,
1645 * the device will be wiped immediately, and your callback will not be invoked.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001646 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001647 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001648 * @param num The number of failed password attempts at which point the
1649 * device will wipe its data.
1650 */
Robin Lee25e26452015-06-02 09:56:29 -07001651 public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001652 if (mService != null) {
1653 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001654 mService.setMaximumFailedPasswordsForWipe(admin, num);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001655 } catch (RemoteException e) {
1656 Log.w(TAG, "Failed talking with device policy service", e);
1657 }
1658 }
1659 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001660
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001661 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001662 * Retrieve the current maximum number of login attempts that are allowed
Jessica Hummel91da58d2014-04-10 17:39:43 +01001663 * before the device wipes itself, for all admins of this user and its profiles
Dianne Hackborn254cb442010-01-27 19:23:59 -08001664 * or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001665 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001666 * all admins.
1667 */
Robin Lee25e26452015-06-02 09:56:29 -07001668 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001669 return getMaximumFailedPasswordsForWipe(admin, UserHandle.myUserId());
1670 }
1671
1672 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001673 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001674 if (mService != null) {
1675 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001676 return mService.getMaximumFailedPasswordsForWipe(admin, userHandle);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001677 } catch (RemoteException e) {
1678 Log.w(TAG, "Failed talking with device policy service", e);
1679 }
1680 }
1681 return 0;
1682 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001683
Dianne Hackborn254cb442010-01-27 19:23:59 -08001684 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07001685 * Returns the profile with the smallest maximum failed passwords for wipe,
1686 * for the given user. So for primary user, it might return the primary or
1687 * a managed profile. For a secondary user, it would be the same as the
1688 * user passed in.
1689 * @hide Used only by Keyguard
1690 */
1691 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
1692 if (mService != null) {
1693 try {
1694 return mService.getProfileWithMinimumFailedPasswordsForWipe(userHandle);
1695 } catch (RemoteException e) {
1696 Log.w(TAG, "Failed talking with device policy service", e);
1697 }
1698 }
1699 return UserHandle.USER_NULL;
1700 }
1701
1702 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001703 * Flag for {@link #resetPassword}: don't allow other admins to change
1704 * the password again until the user has entered it.
1705 */
1706 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001707
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001708 /**
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001709 * Flag for {@link #resetPassword}: don't ask for user credentials on device boot.
1710 * If the flag is set, the device can be booted without asking for user password.
1711 * The absence of this flag does not change the current boot requirements. This flag
1712 * can be set by the device owner only. If the app is not the device owner, the flag
1713 * is ignored. Once the flag is set, it cannot be reverted back without resetting the
1714 * device to factory defaults.
1715 */
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001716 public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002;
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001717
1718 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001719 * Force a new device unlock password (the password needed to access the
1720 * entire device, not for individual accounts) on the user. This takes
1721 * effect immediately.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001722 * The given password must be sufficient for the
1723 * current password quality and length constraints as returned by
1724 * {@link #getPasswordQuality(ComponentName)} and
1725 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
1726 * these constraints, then it will be rejected and false returned. Note
1727 * that the password may be a stronger quality (containing alphanumeric
1728 * characters when the requested quality is only numeric), in which case
1729 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001730 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001731 * <p>Calling with a null or empty password will clear any existing PIN,
1732 * pattern or password if the current password constraints allow it.
1733 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001734 * <p>The calling device admin must have requested
1735 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
1736 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001737 *
Amith Yamasani242f4b12014-10-14 16:06:13 -07001738 * <p>Calling this from a managed profile will throw a security exception.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001739 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001740 * @param password The new password for the user. Null or empty clears the password.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001741 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001742 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001743 * @return Returns true if the password was applied, or false if it is
1744 * not acceptable for the current constraints.
1745 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001746 public boolean resetPassword(String password, int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001747 if (mService != null) {
1748 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001749 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001750 } catch (RemoteException e) {
1751 Log.w(TAG, "Failed talking with device policy service", e);
1752 }
1753 }
1754 return false;
1755 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001756
Dianne Hackbornd6847842010-01-12 18:14:19 -08001757 /**
1758 * Called by an application that is administering the device to set the
1759 * maximum time for user activity until the device will lock. This limits
1760 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001761 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001762 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -08001763 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001764 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001765 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001766 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001767 * @param timeMs The new desired maximum time to lock in milliseconds.
1768 * A value of 0 means there is no restriction.
1769 */
Robin Lee25e26452015-06-02 09:56:29 -07001770 public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001771 if (mService != null) {
1772 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001773 mService.setMaximumTimeToLock(admin, timeMs);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001774 } catch (RemoteException e) {
1775 Log.w(TAG, "Failed talking with device policy service", e);
1776 }
1777 }
1778 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001779
Dianne Hackbornd6847842010-01-12 18:14:19 -08001780 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001781 * Retrieve the current maximum time to unlock for all admins of this user
1782 * and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001783 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001784 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07001785 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07001786 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001787 */
Robin Lee25e26452015-06-02 09:56:29 -07001788 public long getMaximumTimeToLock(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001789 return getMaximumTimeToLock(admin, UserHandle.myUserId());
1790 }
1791
1792 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001793 public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001794 if (mService != null) {
1795 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001796 return mService.getMaximumTimeToLock(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001797 } catch (RemoteException e) {
1798 Log.w(TAG, "Failed talking with device policy service", e);
1799 }
1800 }
1801 return 0;
1802 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001803
Dianne Hackbornd6847842010-01-12 18:14:19 -08001804 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001805 * Make the device lock immediately, as if the lock screen timeout has
1806 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001807 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001808 * <p>The calling device admin must have requested
1809 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
1810 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001811 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001812 public void lockNow() {
1813 if (mService != null) {
1814 try {
1815 mService.lockNow();
1816 } catch (RemoteException e) {
1817 Log.w(TAG, "Failed talking with device policy service", e);
1818 }
1819 }
1820 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001821
Dianne Hackbornd6847842010-01-12 18:14:19 -08001822 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07001823 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001824 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07001825 */
1826 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
1827
1828 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001829 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
1830 * data.
1831 *
Paul Crowley2934b262014-12-02 11:21:13 +00001832 * <p>This flag may only be set by device owner admins; if it is set by
1833 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001834 */
1835 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
1836
1837 /**
Robin Lee85bd63f2015-02-10 11:51:00 +00001838 * Ask the user data be wiped. Wiping the primary user will cause the
1839 * device to reboot, erasing all user data while next booting up.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001840 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001841 * <p>The calling device admin must have requested
1842 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
1843 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001844 *
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001845 * @param flags Bit mask of additional options: currently supported flags
1846 * are {@link #WIPE_EXTERNAL_STORAGE} and
1847 * {@link #WIPE_RESET_PROTECTION_DATA}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001848 */
1849 public void wipeData(int flags) {
1850 if (mService != null) {
1851 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001852 mService.wipeData(flags, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001853 } catch (RemoteException e) {
1854 Log.w(TAG, "Failed talking with device policy service", e);
1855 }
1856 }
1857 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001858
Dianne Hackbornd6847842010-01-12 18:14:19 -08001859 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001860 * Called by an application that is administering the device to set the
1861 * global proxy and exclusion list.
1862 * <p>
1863 * The calling device admin must have requested
1864 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
1865 * this method; if it has not, a security exception will be thrown.
1866 * Only the first device admin can set the proxy. If a second admin attempts
1867 * to set the proxy, the {@link ComponentName} of the admin originally setting the
Robin Lee25e26452015-06-02 09:56:29 -07001868 * proxy will be returned. If successful in setting the proxy, {@code null} will
Oscar Montemayor69238c62010-08-03 10:51:06 -07001869 * be returned.
1870 * The method can be called repeatedly by the device admin alrady setting the
1871 * proxy to update the proxy and exclusion list.
1872 *
Robin Lee25e26452015-06-02 09:56:29 -07001873 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Oscar Montemayor69238c62010-08-03 10:51:06 -07001874 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
1875 * Pass Proxy.NO_PROXY to reset the proxy.
1876 * @param exclusionList a list of domains to be excluded from the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07001877 * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName}
1878 * of the device admin that sets the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08001879 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001880 */
Robin Lee25e26452015-06-02 09:56:29 -07001881 public ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec,
Oscar Montemayor69238c62010-08-03 10:51:06 -07001882 List<String> exclusionList ) {
1883 if (proxySpec == null) {
1884 throw new NullPointerException();
1885 }
1886 if (mService != null) {
1887 try {
1888 String hostSpec;
1889 String exclSpec;
1890 if (proxySpec.equals(Proxy.NO_PROXY)) {
1891 hostSpec = null;
1892 exclSpec = null;
1893 } else {
1894 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
1895 throw new IllegalArgumentException();
1896 }
1897 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
1898 String hostName = sa.getHostName();
1899 int port = sa.getPort();
1900 StringBuilder hostBuilder = new StringBuilder();
1901 hostSpec = hostBuilder.append(hostName)
1902 .append(":").append(Integer.toString(port)).toString();
1903 if (exclusionList == null) {
1904 exclSpec = "";
1905 } else {
1906 StringBuilder listBuilder = new StringBuilder();
1907 boolean firstDomain = true;
1908 for (String exclDomain : exclusionList) {
1909 if (!firstDomain) {
1910 listBuilder = listBuilder.append(",");
1911 } else {
1912 firstDomain = false;
1913 }
1914 listBuilder = listBuilder.append(exclDomain.trim());
1915 }
1916 exclSpec = listBuilder.toString();
1917 }
Yuhao Zheng90704842014-02-28 17:22:45 -08001918 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
1919 != android.net.Proxy.PROXY_VALID)
1920 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07001921 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001922 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07001923 } catch (RemoteException e) {
1924 Log.w(TAG, "Failed talking with device policy service", e);
1925 }
1926 }
1927 return null;
1928 }
1929
1930 /**
Jason Monk03bc9912014-05-13 09:44:57 -04001931 * Set a network-independent global HTTP proxy. This is not normally what you want
1932 * for typical HTTP proxies - they are generally network dependent. However if you're
1933 * doing something unusual like general internal filtering this may be useful. On
1934 * a private network where the proxy is not accessible, you may break HTTP using this.
1935 *
1936 * <p>This method requires the caller to be the device owner.
1937 *
1938 * <p>This proxy is only a recommendation and it is possible that some apps will ignore it.
1939 * @see ProxyInfo
1940 *
1941 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1942 * with.
1943 * @param proxyInfo The a {@link ProxyInfo} object defining the new global
1944 * HTTP proxy. A {@code null} value will clear the global HTTP proxy.
1945 */
Robin Lee25e26452015-06-02 09:56:29 -07001946 public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo
1947 proxyInfo) {
Jason Monk03bc9912014-05-13 09:44:57 -04001948 if (mService != null) {
1949 try {
1950 mService.setRecommendedGlobalProxy(admin, proxyInfo);
1951 } catch (RemoteException e) {
1952 Log.w(TAG, "Failed talking with device policy service", e);
1953 }
1954 }
1955 }
1956
1957 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001958 * Returns the component name setting the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07001959 * @return ComponentName object of the device admin that set the global proxy, or {@code null}
1960 * if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08001961 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001962 */
1963 public ComponentName getGlobalProxyAdmin() {
1964 if (mService != null) {
1965 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001966 return mService.getGlobalProxyAdmin(UserHandle.myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07001967 } catch (RemoteException e) {
1968 Log.w(TAG, "Failed talking with device policy service", e);
1969 }
1970 }
1971 return null;
1972 }
1973
1974 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001975 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001976 * indicating that encryption is not supported.
1977 */
1978 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
1979
1980 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001981 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001982 * indicating that encryption is supported, but is not currently active.
1983 */
1984 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
1985
1986 /**
Robin Lee3795fb02015-02-16 14:17:23 +00001987 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001988 * indicating that encryption is not currently active, but is currently
1989 * being activated. This is only reported by devices that support
1990 * encryption of data and only when the storage is currently
1991 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
1992 * to become encrypted will never return this value.
1993 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001994 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001995
1996 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001997 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001998 * indicating that encryption is active.
1999 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002000 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002001
2002 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002003 * Result code for {@link #getStorageEncryptionStatus}:
2004 * indicating that encryption is active, but an encryption key has not
2005 * been set by the user.
2006 */
2007 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
2008
2009 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002010 * Activity action: begin the process of encrypting data on the device. This activity should
2011 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
2012 * After resuming from this activity, use {@link #getStorageEncryption}
2013 * to check encryption status. However, on some devices this activity may never return, as
2014 * it may trigger a reboot and in some cases a complete data wipe of the device.
2015 */
2016 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
2017 public static final String ACTION_START_ENCRYPTION
2018 = "android.app.action.START_ENCRYPTION";
2019
2020 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07002021 * Widgets are enabled in keyguard
2022 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002023 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07002024
2025 /**
Jim Miller50e62182014-04-23 17:25:00 -07002026 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07002027 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002028 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
2029
2030 /**
2031 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
2032 */
2033 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
2034
2035 /**
Jim Miller50e62182014-04-23 17:25:00 -07002036 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2037 */
2038 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
2039
2040 /**
2041 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2042 */
2043 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
2044
2045 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02002046 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07002047 * (e.g. PIN/Pattern/Password).
2048 */
2049 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
2050
2051 /**
Jim Miller06e34502014-07-17 14:46:05 -07002052 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
2053 */
2054 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
2055
2056 /**
Jim Miller35207742012-11-02 15:33:20 -07002057 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07002058 */
2059 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07002060
2061 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002062 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002063 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002064 *
2065 * <p>When multiple device administrators attempt to control device
2066 * encryption, the most secure, supported setting will always be
2067 * used. If any device administrator requests device encryption,
2068 * it will be enabled; Conversely, if a device administrator
2069 * attempts to disable device encryption while another
2070 * device administrator has enabled it, the call to disable will
2071 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
2072 *
2073 * <p>This policy controls encryption of the secure (application data) storage area. Data
Andy Stadler50c294f2011-03-07 19:13:42 -08002074 * written to other storage areas may or may not be encrypted, and this policy does not require
2075 * or control the encryption of any other storage areas.
2076 * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is
2077 * {@code true}, then the directory returned by
2078 * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk
2079 * within the encrypted storage area.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002080 *
2081 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
2082 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
2083 * the encryption key may not be fully secured. For maximum security, the administrator should
2084 * also require (and check for) a pattern, PIN, or password.
2085 *
2086 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2087 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08002088 * @return the new request status (for all active admins) - will be one of
2089 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
2090 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
2091 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002092 */
Robin Lee25e26452015-06-02 09:56:29 -07002093 public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002094 if (mService != null) {
2095 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002096 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002097 } catch (RemoteException e) {
2098 Log.w(TAG, "Failed talking with device policy service", e);
2099 }
2100 }
2101 return ENCRYPTION_STATUS_UNSUPPORTED;
2102 }
2103
2104 /**
2105 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002106 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002107 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08002108 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
2109 * this will return the requested encryption setting as an aggregate of all active
2110 * administrators.
2111 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002112 */
Robin Lee25e26452015-06-02 09:56:29 -07002113 public boolean getStorageEncryption(@Nullable ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002114 if (mService != null) {
2115 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002116 return mService.getStorageEncryption(admin, UserHandle.myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002117 } catch (RemoteException e) {
2118 Log.w(TAG, "Failed talking with device policy service", e);
2119 }
2120 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08002121 return false;
2122 }
2123
2124 /**
2125 * Called by an application that is administering the device to
2126 * determine the current encryption status of the device.
2127 *
2128 * Depending on the returned status code, the caller may proceed in different
2129 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
2130 * storage system does not support encryption. If the
2131 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
2132 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00002133 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
2134 * storage system has enabled encryption but no password is set so further action
2135 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
Andy Stadler22dbfda2011-01-17 12:47:31 -08002136 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
2137 *
Robin Lee7e678712014-07-24 16:41:31 +01002138 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08002139 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00002140 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
2141 * or {@link #ENCRYPTION_STATUS_ACTIVE}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08002142 */
2143 public int getStorageEncryptionStatus() {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002144 return getStorageEncryptionStatus(UserHandle.myUserId());
2145 }
2146
2147 /** @hide per-user version */
2148 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08002149 if (mService != null) {
2150 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002151 return mService.getStorageEncryptionStatus(userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08002152 } catch (RemoteException e) {
2153 Log.w(TAG, "Failed talking with device policy service", e);
2154 }
2155 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002156 return ENCRYPTION_STATUS_UNSUPPORTED;
2157 }
2158
2159 /**
Robin Lee7e678712014-07-24 16:41:31 +01002160 * Installs the given certificate as a user CA.
2161 *
Robin Lee25e26452015-06-02 09:56:29 -07002162 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2163 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002164 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04002165 *
2166 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01002167 * interrupted, true otherwise.
Maggie Benthallda51e682013-08-08 22:35:44 -04002168 */
Robin Lee25e26452015-06-02 09:56:29 -07002169 public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002170 if (mService != null) {
2171 try {
Robin Lee7e678712014-07-24 16:41:31 +01002172 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04002173 } catch (RemoteException e) {
2174 Log.w(TAG, "Failed talking with device policy service", e);
2175 }
2176 }
2177 return false;
2178 }
2179
2180 /**
Robin Lee7e678712014-07-24 16:41:31 +01002181 * Uninstalls the given certificate from trusted user CAs, if present.
2182 *
Robin Lee25e26452015-06-02 09:56:29 -07002183 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2184 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002185 * @param certBuffer encoded form of the certificate to remove.
Maggie Benthallda51e682013-08-08 22:35:44 -04002186 */
Robin Lee25e26452015-06-02 09:56:29 -07002187 public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002188 if (mService != null) {
2189 try {
Robin Lee306fe082014-06-19 14:04:24 +00002190 final String alias = getCaCertAlias(certBuffer);
Robin Lee83881bd2015-06-09 16:04:38 -07002191 mService.uninstallCaCerts(admin, new String[] {alias});
Robin Lee306fe082014-06-19 14:04:24 +00002192 } catch (CertificateException e) {
2193 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002194 } catch (RemoteException e) {
2195 Log.w(TAG, "Failed talking with device policy service", e);
2196 }
2197 }
2198 }
2199
2200 /**
Robin Lee7e678712014-07-24 16:41:31 +01002201 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
2202 * If a user has installed any certificates by other means than device policy these will be
2203 * included too.
2204 *
Robin Lee25e26452015-06-02 09:56:29 -07002205 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2206 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002207 * @return a List of byte[] arrays, each encoding one user CA certificate.
Maggie Benthallda51e682013-08-08 22:35:44 -04002208 */
Robin Lee25e26452015-06-02 09:56:29 -07002209 public List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002210 List<byte[]> certs = new ArrayList<byte[]>();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002211 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01002212 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002213 mService.enforceCanManageCaCerts(admin);
2214 final TrustedCertificateStore certStore = new TrustedCertificateStore();
2215 for (String alias : certStore.userAliases()) {
2216 try {
2217 certs.add(certStore.getCertificate(alias).getEncoded());
2218 } catch (CertificateException ce) {
2219 Log.w(TAG, "Could not encode certificate: " + alias, ce);
2220 }
2221 }
2222 } catch (RemoteException re) {
2223 Log.w(TAG, "Failed talking with device policy service", re);
Robin Lee7e678712014-07-24 16:41:31 +01002224 }
2225 }
2226 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04002227 }
2228
2229 /**
Robin Lee7e678712014-07-24 16:41:31 +01002230 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
2231 * means other than device policy will also be removed, except for system CA certificates.
2232 *
Robin Lee25e26452015-06-02 09:56:29 -07002233 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2234 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002235 */
Robin Lee25e26452015-06-02 09:56:29 -07002236 public void uninstallAllUserCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002237 if (mService != null) {
Robin Lee83881bd2015-06-09 16:04:38 -07002238 try {
2239 mService.uninstallCaCerts(admin, new TrustedCertificateStore().userAliases()
2240 .toArray(new String[0]));
2241 } catch (RemoteException re) {
2242 Log.w(TAG, "Failed talking with device policy service", re);
Robin Lee7e678712014-07-24 16:41:31 +01002243 }
2244 }
2245 }
2246
2247 /**
2248 * Returns whether this certificate is installed as a trusted CA.
2249 *
Robin Lee25e26452015-06-02 09:56:29 -07002250 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2251 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002252 * @param certBuffer encoded form of the certificate to look up.
Maggie Benthallda51e682013-08-08 22:35:44 -04002253 */
Robin Lee25e26452015-06-02 09:56:29 -07002254 public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002255 if (mService != null) {
2256 try {
2257 mService.enforceCanManageCaCerts(admin);
2258 return getCaCertAlias(certBuffer) != null;
2259 } catch (RemoteException re) {
2260 Log.w(TAG, "Failed talking with device policy service", re);
2261 } catch (CertificateException ce) {
2262 Log.w(TAG, "Could not parse certificate", ce);
2263 }
Maggie Benthallda51e682013-08-08 22:35:44 -04002264 }
2265 return false;
2266 }
2267
2268 /**
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002269 * Called by a device or profile owner to install a certificate and private key pair. The
2270 * keypair will be visible to all apps within the profile.
2271 *
Robin Lee25e26452015-06-02 09:56:29 -07002272 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2273 * {@code null} if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002274 * @param privKey The private key to install.
2275 * @param cert The certificate to install.
2276 * @param alias The private key alias under which to install the certificate. If a certificate
2277 * with that alias already exists, it will be overwritten.
2278 * @return {@code true} if the keys were installed, {@code false} otherwise.
2279 */
Robin Lee25e26452015-06-02 09:56:29 -07002280 public boolean installKeyPair(@Nullable ComponentName admin, PrivateKey privKey, Certificate cert,
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002281 String alias) {
2282 try {
2283 final byte[] pemCert = Credentials.convertToPem(cert);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002284 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
2285 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
Robin Lee25e26452015-06-02 09:56:29 -07002286 return mService.installKeyPair(admin, pkcs8Key, pemCert, alias);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002287 } catch (RemoteException e) {
2288 Log.w(TAG, "Failed talking with device policy service", e);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002289 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
2290 Log.w(TAG, "Failed to obtain private key material", e);
2291 } catch (CertificateException | IOException e) {
2292 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002293 }
2294 return false;
2295 }
2296
2297 /**
Robin Lee25e26452015-06-02 09:56:29 -07002298 * @return the alias of a given CA certificate in the certificate store, or {@code null} if it
Robin Lee306fe082014-06-19 14:04:24 +00002299 * doesn't exist.
2300 */
2301 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
2302 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
2303 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
2304 new ByteArrayInputStream(certBuffer));
2305 return new TrustedCertificateStore().getCertificateAlias(cert);
2306 }
2307
2308 /**
Rubin Xuec32b562015-03-03 17:34:05 +00002309 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01002310 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00002311 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01002312 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00002313 * <p>
2314 * Delegated certificate installer is a per-user state. The delegated access is persistent until
2315 * it is later cleared by calling this method with a null value or uninstallling the certificate
2316 * installer.
2317 *
Robin Lee25e26452015-06-02 09:56:29 -07002318 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xuec32b562015-03-03 17:34:05 +00002319 * @param installerPackage The package name of the certificate installer which will be given
Robin Lee25e26452015-06-02 09:56:29 -07002320 * access. If {@code null} is given the current package will be cleared.
Rubin Xuec32b562015-03-03 17:34:05 +00002321 */
Robin Lee25e26452015-06-02 09:56:29 -07002322 public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String
2323 installerPackage) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002324 if (mService != null) {
2325 try {
Robin Lee25e26452015-06-02 09:56:29 -07002326 mService.setCertInstallerPackage(admin, installerPackage);
Rubin Xuec32b562015-03-03 17:34:05 +00002327 } catch (RemoteException e) {
2328 Log.w(TAG, "Failed talking with device policy service", e);
2329 }
2330 }
2331 }
2332
2333 /**
2334 * Called by a profile owner or device owner to retrieve the certificate installer for the
2335 * current user. null if none is set.
2336 *
Robin Lee25e26452015-06-02 09:56:29 -07002337 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2338 * @return The package name of the current delegated certificate installer, or {@code null}
Rubin Xuec32b562015-03-03 17:34:05 +00002339 * if none is set.
2340 */
Robin Lee25e26452015-06-02 09:56:29 -07002341 public String getCertInstallerPackage(@NonNull ComponentName admin) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002342 if (mService != null) {
2343 try {
Robin Lee25e26452015-06-02 09:56:29 -07002344 return mService.getCertInstallerPackage(admin);
Rubin Xuec32b562015-03-03 17:34:05 +00002345 } catch (RemoteException e) {
2346 Log.w(TAG, "Failed talking with device policy service", e);
2347 }
2348 }
2349 return null;
2350 }
2351
2352 /**
Ben Komalo2447edd2011-05-09 16:05:33 -07002353 * Called by an application that is administering the device to disable all cameras
Amith Yamasani242f4b12014-10-14 16:06:13 -07002354 * on the device, for this user. After setting this, no applications running as this user
2355 * will be able to access any cameras on the device.
Ben Komalo2447edd2011-05-09 16:05:33 -07002356 *
2357 * <p>The calling device admin must have requested
2358 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
2359 * this method; if it has not, a security exception will be thrown.
2360 *
2361 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2362 * @param disabled Whether or not the camera should be disabled.
2363 */
Robin Lee25e26452015-06-02 09:56:29 -07002364 public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002365 if (mService != null) {
2366 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002367 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07002368 } catch (RemoteException e) {
2369 Log.w(TAG, "Failed talking with device policy service", e);
2370 }
2371 }
2372 }
2373
2374 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07002375 * Determine whether or not the device's cameras have been disabled for this user,
2376 * either by the current admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002377 * @param admin The name of the admin component to check, or {@code null} to check whether any admins
Ben Komalo2447edd2011-05-09 16:05:33 -07002378 * have disabled the camera
2379 */
Robin Lee25e26452015-06-02 09:56:29 -07002380 public boolean getCameraDisabled(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002381 return getCameraDisabled(admin, UserHandle.myUserId());
2382 }
2383
2384 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002385 public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002386 if (mService != null) {
2387 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002388 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07002389 } catch (RemoteException e) {
2390 Log.w(TAG, "Failed talking with device policy service", e);
2391 }
2392 }
2393 return false;
2394 }
2395
2396 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01002397 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
2398 * screen capture also prevents the content from being shown on display devices that do not have
2399 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
2400 * secure surfaces and secure displays.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002401 *
2402 * <p>The calling device admin must be a device or profile owner. If it is not, a
2403 * security exception will be thrown.
2404 *
2405 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002406 * @param disabled Whether screen capture is disabled or not.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002407 */
Robin Lee25e26452015-06-02 09:56:29 -07002408 public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002409 if (mService != null) {
2410 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002411 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002412 } catch (RemoteException e) {
2413 Log.w(TAG, "Failed talking with device policy service", e);
2414 }
2415 }
2416 }
2417
2418 /**
2419 * Determine whether or not screen capture has been disabled by the current
2420 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002421 * @param admin The name of the admin component to check, or {@code null} to check whether any admins
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002422 * have disabled screen capture.
2423 */
Robin Lee25e26452015-06-02 09:56:29 -07002424 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002425 return getScreenCaptureDisabled(admin, UserHandle.myUserId());
2426 }
2427
2428 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002429 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002430 if (mService != null) {
2431 try {
2432 return mService.getScreenCaptureDisabled(admin, userHandle);
2433 } catch (RemoteException e) {
2434 Log.w(TAG, "Failed talking with device policy service", e);
2435 }
2436 }
2437 return false;
2438 }
2439
2440 /**
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002441 * Called by a device owner to set whether auto time is required. If auto time is
2442 * required the user cannot set the date and time, but has to use network date and time.
2443 *
2444 * <p>Note: if auto time is required the user can still manually set the time zone.
2445 *
2446 * <p>The calling device admin must be a device owner. If it is not, a security exception will
2447 * be thrown.
2448 *
2449 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2450 * @param required Whether auto time is set required or not.
2451 */
Robin Lee25e26452015-06-02 09:56:29 -07002452 public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) {
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002453 if (mService != null) {
2454 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002455 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002456 } catch (RemoteException e) {
2457 Log.w(TAG, "Failed talking with device policy service", e);
2458 }
2459 }
2460 }
2461
2462 /**
2463 * @return true if auto time is required.
2464 */
2465 public boolean getAutoTimeRequired() {
2466 if (mService != null) {
2467 try {
2468 return mService.getAutoTimeRequired();
2469 } catch (RemoteException e) {
2470 Log.w(TAG, "Failed talking with device policy service", e);
2471 }
2472 }
2473 return false;
2474 }
2475
2476 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002477 * Called by an application that is administering the device to disable keyguard customizations,
2478 * such as widgets. After setting this, keyguard features will be disabled according to the
2479 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002480 *
2481 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07002482 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07002483 * this method; if it has not, a security exception will be thrown.
2484 *
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002485 * <p>Calling this from a managed profile before version
2486 * {@link android.os.Build.VERSION_CODES#MNC} will throw a security exception.
2487 *
2488 * <p>From version {@link android.os.Build.VERSION_CODES#MNC} a profile owner can set:
2489 * <ul>
2490 * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, {@link #KEYGUARD_DISABLE_FINGERPRINT}
2491 * these will affect the profile's parent user.
2492 * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} this will affect notifications
2493 * generated by applications in the managed profile.
2494 * </ul>
2495 * <p>Requests to disable other features on a managed profile will be ignored. The admin
2496 * can check which features have been disabled by calling
2497 * {@link #getKeyguardDisabledFeatures(ComponentName)}
Amith Yamasani242f4b12014-10-14 16:06:13 -07002498 *
Jim Millerb8ec4702012-08-31 17:19:10 -07002499 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07002500 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
2501 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
Jim Miller50e62182014-04-23 17:25:00 -07002502 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002503 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FINGERPRINT},
2504 * {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07002505 */
Robin Lee25e26452015-06-02 09:56:29 -07002506 public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002507 if (mService != null) {
2508 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002509 mService.setKeyguardDisabledFeatures(admin, which);
Jim Millerb8ec4702012-08-31 17:19:10 -07002510 } catch (RemoteException e) {
2511 Log.w(TAG, "Failed talking with device policy service", e);
2512 }
2513 }
2514 }
2515
2516 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002517 * Determine whether or not features have been disabled in keyguard either by the current
Jim Millerb8ec4702012-08-31 17:19:10 -07002518 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002519 * @param admin The name of the admin component to check, or {@code null} to check whether any admins
Jim Miller48b9b0d2012-09-19 23:16:50 -07002520 * have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07002521 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
2522 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002523 */
Robin Lee25e26452015-06-02 09:56:29 -07002524 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) {
Jim Miller48b9b0d2012-09-19 23:16:50 -07002525 return getKeyguardDisabledFeatures(admin, UserHandle.myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002526 }
2527
2528 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002529 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002530 if (mService != null) {
2531 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07002532 return mService.getKeyguardDisabledFeatures(admin, userHandle);
Jim Millerb8ec4702012-08-31 17:19:10 -07002533 } catch (RemoteException e) {
2534 Log.w(TAG, "Failed talking with device policy service", e);
2535 }
2536 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07002537 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07002538 }
2539
2540 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08002541 * @hide
2542 */
Robin Lee25e26452015-06-02 09:56:29 -07002543 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
2544 int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002545 if (mService != null) {
2546 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01002547 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002548 } catch (RemoteException e) {
2549 Log.w(TAG, "Failed talking with device policy service", e);
2550 }
2551 }
2552 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002553
Dianne Hackbornd6847842010-01-12 18:14:19 -08002554 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01002555 * @hide
2556 */
Robin Lee25e26452015-06-02 09:56:29 -07002557 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
Jessica Hummel6d36b602014-04-04 12:42:17 +01002558 setActiveAdmin(policyReceiver, refreshing, UserHandle.myUserId());
2559 }
2560
2561 /**
Robin Lee25e26452015-06-02 09:56:29 -07002562 * Returns the DeviceAdminInfo as defined by the administrator's package info &amp; meta-data
Dianne Hackbornd6847842010-01-12 18:14:19 -08002563 * @hide
2564 */
Robin Lee25e26452015-06-02 09:56:29 -07002565 public DeviceAdminInfo getAdminInfo(@NonNull ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002566 ActivityInfo ai;
2567 try {
2568 ai = mContext.getPackageManager().getReceiverInfo(cn,
2569 PackageManager.GET_META_DATA);
2570 } catch (PackageManager.NameNotFoundException e) {
2571 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
2572 return null;
2573 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002574
Dianne Hackbornd6847842010-01-12 18:14:19 -08002575 ResolveInfo ri = new ResolveInfo();
2576 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002577
Dianne Hackbornd6847842010-01-12 18:14:19 -08002578 try {
2579 return new DeviceAdminInfo(mContext, ri);
2580 } catch (XmlPullParserException e) {
2581 Log.w(TAG, "Unable to parse device policy " + cn, e);
2582 return null;
2583 } catch (IOException e) {
2584 Log.w(TAG, "Unable to parse device policy " + cn, e);
2585 return null;
2586 }
2587 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002588
Dianne Hackbornd6847842010-01-12 18:14:19 -08002589 /**
2590 * @hide
2591 */
Robin Lee25e26452015-06-02 09:56:29 -07002592 public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002593 if (mService != null) {
2594 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002595 mService.getRemoveWarning(admin, result, UserHandle.myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002596 } catch (RemoteException e) {
2597 Log.w(TAG, "Failed talking with device policy service", e);
2598 }
2599 }
2600 }
2601
2602 /**
2603 * @hide
2604 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002605 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002606 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002607 if (mService != null) {
2608 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002609 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002610 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002611 } catch (RemoteException e) {
2612 Log.w(TAG, "Failed talking with device policy service", e);
2613 }
2614 }
2615 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002616
Dianne Hackbornd6847842010-01-12 18:14:19 -08002617 /**
2618 * @hide
2619 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002620 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002621 if (mService != null) {
2622 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002623 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002624 } catch (RemoteException e) {
2625 Log.w(TAG, "Failed talking with device policy service", e);
2626 }
2627 }
2628 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002629
Dianne Hackbornd6847842010-01-12 18:14:19 -08002630 /**
2631 * @hide
2632 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002633 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002634 if (mService != null) {
2635 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002636 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002637 } catch (RemoteException e) {
2638 Log.w(TAG, "Failed talking with device policy service", e);
2639 }
2640 }
2641 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07002642
2643 /**
2644 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00002645 * Sets the given package as the device owner.
2646 * Same as {@link #setDeviceOwner(String, String)} but without setting a device owner name.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002647 * @param packageName the package name of the application to be registered as the device owner.
2648 * @return whether the package was successfully registered as the device owner.
2649 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00002650 * @throws IllegalStateException If the preconditions mentioned are not met.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002651 */
2652 public boolean setDeviceOwner(String packageName) throws IllegalArgumentException,
2653 IllegalStateException {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002654 return setDeviceOwner(packageName, null);
2655 }
2656
2657 /**
2658 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00002659 * Sets the given package as the device owner. The package must already be installed. There
2660 * must not already be a device owner.
2661 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
2662 * this method.
2663 * Calling this after the setup phase of the primary user has completed is allowed only if
2664 * the caller is the shell uid, and there are no additional users and no accounts.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002665 * @param packageName the package name of the application to be registered as the device owner.
2666 * @param ownerName the human readable name of the institution that owns this device.
2667 * @return whether the package was successfully registered as the device owner.
2668 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00002669 * @throws IllegalStateException If the preconditions mentioned are not met.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002670 */
2671 public boolean setDeviceOwner(String packageName, String ownerName)
2672 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002673 if (mService != null) {
2674 try {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002675 return mService.setDeviceOwner(packageName, ownerName);
Amith Yamasani71e6c692013-03-24 17:39:28 -07002676 } catch (RemoteException re) {
2677 Log.w(TAG, "Failed to set device owner");
2678 }
2679 }
2680 return false;
2681 }
2682
2683 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002684 * Used to determine if a particular package has been registered as a Device Owner app.
2685 * A device owner app is a special device admin that cannot be deactivated by the user, once
Robin Lee25e26452015-06-02 09:56:29 -07002686 * activated as a device admin. It also cannot be uninstalled. To check whether a particular
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002687 * package is currently registered as the device owner app, pass in the package name from
2688 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
Robin Lee25e26452015-06-02 09:56:29 -07002689 * admin apps that want to check whether they are also registered as the device owner app. The
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002690 * exact mechanism by which a device admin app is registered as a device owner app is defined by
2691 * the setup process.
2692 * @param packageName the package name of the app, to compare with the registered device owner
2693 * app, if any.
2694 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002695 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002696 public boolean isDeviceOwnerApp(String packageName) {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002697 if (mService != null) {
2698 try {
2699 return mService.isDeviceOwner(packageName);
2700 } catch (RemoteException re) {
2701 Log.w(TAG, "Failed to check device owner");
2702 }
2703 }
2704 return false;
2705 }
2706
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002707 /**
2708 * @hide
2709 * Redirect to isDeviceOwnerApp.
2710 */
2711 public boolean isDeviceOwner(String packageName) {
2712 return isDeviceOwnerApp(packageName);
2713 }
2714
Jason Monkb0dced82014-06-06 14:36:20 -04002715 /**
2716 * Clears the current device owner. The caller must be the device owner.
2717 *
2718 * This function should be used cautiously as once it is called it cannot
2719 * be undone. The device owner can only be set as a part of device setup
2720 * before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04002721 *
2722 * @param packageName The package name of the device owner.
Jason Monkb0dced82014-06-06 14:36:20 -04002723 */
Jason Monk94d2cf92014-06-18 09:53:34 -04002724 public void clearDeviceOwnerApp(String packageName) {
Jason Monkb0dced82014-06-06 14:36:20 -04002725 if (mService != null) {
2726 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04002727 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04002728 } catch (RemoteException re) {
2729 Log.w(TAG, "Failed to clear device owner");
2730 }
2731 }
2732 }
2733
Amith Yamasani71e6c692013-03-24 17:39:28 -07002734 /** @hide */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002735 @SystemApi
Amith Yamasani71e6c692013-03-24 17:39:28 -07002736 public String getDeviceOwner() {
2737 if (mService != null) {
2738 try {
2739 return mService.getDeviceOwner();
2740 } catch (RemoteException re) {
2741 Log.w(TAG, "Failed to get device owner");
2742 }
2743 }
2744 return null;
2745 }
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002746
2747 /** @hide */
2748 public String getDeviceOwnerName() {
2749 if (mService != null) {
2750 try {
2751 return mService.getDeviceOwnerName();
2752 } catch (RemoteException re) {
2753 Log.w(TAG, "Failed to get device owner");
2754 }
2755 }
2756 return null;
2757 }
Adam Connors776c5552014-01-09 10:42:56 +00002758
2759 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04002760 * @hide
Julia Reynolds20118f12015-02-11 12:34:08 -05002761 * Sets the given component as the device initializer. The package must already be installed and
2762 * set as an active device administrator, and there must not be an existing device initializer,
2763 * for this call to succeed. This method can only be called by an app holding the
2764 * MANAGE_DEVICE_ADMINS permission before the device is provisioned or by a device owner app. A
2765 * device initializer app is granted device owner privileges during device initialization and
2766 * profile owner privileges during secondary user initialization.
Robin Lee25e26452015-06-02 09:56:29 -07002767 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2768 * {@code null} if not called by the device owner.
Julia Reynolds20118f12015-02-11 12:34:08 -05002769 * @param initializer Which {@link DeviceAdminReceiver} to make device initializer.
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002770 * @return whether the component was successfully registered as the device initializer.
2771 * @throws IllegalArgumentException if the componentname is null or invalid
Julia Reynolds20118f12015-02-11 12:34:08 -05002772 * @throws IllegalStateException if the caller is not device owner or the device has
2773 * already been provisioned or a device initializer already exists.
2774 */
Robin Lee25e26452015-06-02 09:56:29 -07002775 public boolean setDeviceInitializer(@Nullable ComponentName admin,
2776 @NonNull ComponentName initializer)
Julia Reynolds731051e2015-05-11 15:52:08 -04002777 throws IllegalArgumentException, IllegalStateException {
Julia Reynolds20118f12015-02-11 12:34:08 -05002778 if (mService != null) {
2779 try {
Robin Lee25e26452015-06-02 09:56:29 -07002780 return mService.setDeviceInitializer(admin, initializer);
Julia Reynolds20118f12015-02-11 12:34:08 -05002781 } catch (RemoteException re) {
2782 Log.w(TAG, "Failed to set device initializer");
2783 }
2784 }
2785 return false;
2786 }
2787
2788 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04002789 * @hide
Julia Reynolds20118f12015-02-11 12:34:08 -05002790 * Used to determine if a particular package has been registered as the device initializer.
2791 *
2792 * @param packageName the package name of the app, to compare with the registered device
2793 * initializer app, if any.
2794 * @return whether or not the caller is registered as the device initializer app.
2795 */
2796 public boolean isDeviceInitializerApp(String packageName) {
2797 if (mService != null) {
2798 try {
2799 return mService.isDeviceInitializer(packageName);
2800 } catch (RemoteException re) {
2801 Log.w(TAG, "Failed to check device initializer");
2802 }
2803 }
2804 return false;
2805 }
2806
2807 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04002808 * @hide
Julia Reynoldse9254402015-02-11 12:34:08 -05002809 * Removes the device initializer, so that it will not be invoked on user initialization for any
2810 * subsequently created users. This method can be called by either the device owner or device
Julia Reynolds1c3754a2015-03-05 10:06:41 -05002811 * initializer itself. The caller must be an active administrator.
2812 *
Robin Lee25e26452015-06-02 09:56:29 -07002813 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Julia Reynolds20118f12015-02-11 12:34:08 -05002814 */
Robin Lee25e26452015-06-02 09:56:29 -07002815 public void clearDeviceInitializerApp(@NonNull ComponentName admin) {
Julia Reynolds20118f12015-02-11 12:34:08 -05002816 if (mService != null) {
2817 try {
Robin Lee25e26452015-06-02 09:56:29 -07002818 mService.clearDeviceInitializer(admin);
Julia Reynolds20118f12015-02-11 12:34:08 -05002819 } catch (RemoteException re) {
2820 Log.w(TAG, "Failed to clear device initializer");
2821 }
2822 }
2823 }
2824
2825 /**
2826 * @hide
2827 * Gets the device initializer of the system.
2828 *
2829 * @return the package name of the device initializer.
2830 */
2831 @SystemApi
2832 public String getDeviceInitializerApp() {
2833 if (mService != null) {
2834 try {
2835 return mService.getDeviceInitializer();
2836 } catch (RemoteException re) {
2837 Log.w(TAG, "Failed to get device initializer");
2838 }
2839 }
2840 return null;
2841 }
2842
2843 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002844 * @hide
2845 * Gets the device initializer component of the system.
2846 *
2847 * @return the component name of the device initializer.
2848 */
2849 @SystemApi
2850 public ComponentName getDeviceInitializerComponent() {
2851 if (mService != null) {
2852 try {
2853 return mService.getDeviceInitializerComponent();
2854 } catch (RemoteException re) {
2855 Log.w(TAG, "Failed to get device initializer");
2856 }
2857 }
2858 return null;
2859 }
2860
2861
2862 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04002863 * @hide
Julia Reynolds20118f12015-02-11 12:34:08 -05002864 * Sets the enabled state of the user. A user should be enabled only once it is ready to
2865 * be used.
2866 *
2867 * <p>Device initializer must call this method to mark the user as functional.
2868 * Only the device initializer agent can call this.
2869 *
2870 * <p>When the user is enabled, if the device initializer is not also the device owner, the
2871 * device initializer will no longer have elevated permissions to call methods in this class.
2872 * Additionally, it will be removed as an active administrator and its
2873 * {@link DeviceAdminReceiver} will be disabled.
2874 *
2875 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2876 * @return whether the user is now enabled.
2877 */
Robin Lee25e26452015-06-02 09:56:29 -07002878 public boolean setUserEnabled(@NonNull ComponentName admin) {
Julia Reynolds20118f12015-02-11 12:34:08 -05002879 if (mService != null) {
2880 try {
2881 return mService.setUserEnabled(admin);
2882 } catch (RemoteException e) {
2883 Log.w(TAG, "Failed talking with device policy service", e);
2884 }
2885 }
2886 return false;
2887 }
2888
2889 /**
Adam Connors776c5552014-01-09 10:42:56 +00002890 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002891 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302892 * Sets the given component as an active admin and registers the package as the profile
2893 * owner for this user. The package must already be installed and there shouldn't be
2894 * an existing profile owner registered for this user. Also, this method must be called
2895 * before the user setup has been completed.
2896 * <p>
2897 * This method can only be called by system apps that hold MANAGE_USERS permission and
2898 * MANAGE_DEVICE_ADMINS permission.
2899 * @param admin The component to register as an active admin and profile owner.
2900 * @param ownerName The user-visible name of the entity that is managing this user.
2901 * @return whether the admin was successfully registered as the profile owner.
2902 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
2903 * the user has already been set up.
2904 */
Justin Morey80440cc2014-07-24 09:16:35 -05002905 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07002906 public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302907 throws IllegalArgumentException {
2908 if (mService != null) {
2909 try {
2910 final int myUserId = UserHandle.myUserId();
2911 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002912 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302913 } catch (RemoteException re) {
2914 Log.w(TAG, "Failed to set profile owner " + re);
2915 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2916 }
2917 }
2918 return false;
2919 }
2920
2921 /**
2922 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002923 * Clears the active profile owner and removes all user restrictions. The caller must
2924 * be from the same package as the active profile owner for this user, otherwise a
2925 * SecurityException will be thrown.
2926 *
2927 * @param admin The component to remove as the profile owner.
2928 * @return
2929 */
2930 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07002931 public void clearProfileOwner(@NonNull ComponentName admin) {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002932 if (mService != null) {
2933 try {
2934 mService.clearProfileOwner(admin);
2935 } catch (RemoteException re) {
2936 Log.w(TAG, "Failed to clear profile owner " + admin + re);
2937 }
2938 }
2939 }
2940
2941 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05002942 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07002943 * Checks whether the user was already setup.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002944 */
2945 public boolean hasUserSetupCompleted() {
2946 if (mService != null) {
2947 try {
2948 return mService.hasUserSetupCompleted();
2949 } catch (RemoteException re) {
Robin Lee25e26452015-06-02 09:56:29 -07002950 Log.w(TAG, "Failed to check whether user setup has completed");
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002951 }
2952 }
2953 return true;
2954 }
2955
2956 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002957 * @hide
2958 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00002959 * already be installed. There must not already be a profile owner for this user.
2960 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
2961 * this method.
2962 * Calling this after the setup phase of the specified user has completed is allowed only if:
2963 * - the caller is SYSTEM_UID.
2964 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002965 * @param admin the component name to be registered as profile owner.
2966 * @param ownerName the human readable name of the organisation associated with this DPM.
2967 * @param userHandle the userId to set the profile owner for.
2968 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00002969 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
2970 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002971 */
Robin Lee25e26452015-06-02 09:56:29 -07002972 public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName,
Robin Leeddd553f2015-04-30 14:18:22 +01002973 int userHandle) throws IllegalArgumentException {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002974 if (admin == null) {
2975 throw new NullPointerException("admin cannot be null");
2976 }
Adam Connors776c5552014-01-09 10:42:56 +00002977 if (mService != null) {
2978 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002979 if (ownerName == null) {
2980 ownerName = "";
2981 }
2982 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00002983 } catch (RemoteException re) {
2984 Log.w(TAG, "Failed to set profile owner", re);
2985 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2986 }
2987 }
2988 return false;
2989 }
2990
2991 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002992 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
2993 * be used. Only the profile owner can call this.
2994 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01002995 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002996 *
2997 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2998 */
Robin Lee25e26452015-06-02 09:56:29 -07002999 public void setProfileEnabled(@NonNull ComponentName admin) {
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003000 if (mService != null) {
3001 try {
3002 mService.setProfileEnabled(admin);
3003 } catch (RemoteException e) {
3004 Log.w(TAG, "Failed talking with device policy service", e);
3005 }
3006 }
3007 }
3008
3009 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003010 * Sets the name of the profile. In the device owner case it sets the name of the user
3011 * 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 +01003012 * never called by the profile or device owner, the name will be set to default values.
3013 *
3014 * @see #isProfileOwnerApp
3015 * @see #isDeviceOwnerApp
3016 *
Robin Lee25e26452015-06-02 09:56:29 -07003017 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01003018 * @param profileName The name of the profile.
3019 */
Robin Lee25e26452015-06-02 09:56:29 -07003020 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Jessica Hummel1333ea12014-06-23 11:20:10 +01003021 if (mService != null) {
3022 try {
Robin Lee25e26452015-06-02 09:56:29 -07003023 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07003024 } catch (RemoteException e) {
3025 Log.w(TAG, "Failed talking with device policy service", e);
3026 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01003027 }
3028 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01003029
3030 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003031 * Used to determine if a particular package is registered as the profile owner for the
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003032 * current user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003033 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00003034 *
3035 * @param packageName The package name of the app to compare with the registered profile owner.
3036 * @return Whether or not the package is registered as the profile owner.
3037 */
3038 public boolean isProfileOwnerApp(String packageName) {
3039 if (mService != null) {
3040 try {
Nicolas Prevot90af6d72014-07-30 14:19:12 +01003041 ComponentName profileOwner = mService.getProfileOwner(
3042 Process.myUserHandle().getIdentifier());
3043 return profileOwner != null
3044 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00003045 } catch (RemoteException re) {
3046 Log.w(TAG, "Failed to check profile owner");
3047 }
3048 }
3049 return false;
3050 }
3051
3052 /**
3053 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003054 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00003055 * owner has been set for that user.
3056 * @throws IllegalArgumentException if the userId is invalid.
3057 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01003058 @SystemApi
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003059 public ComponentName getProfileOwner() throws IllegalArgumentException {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003060 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
3061 }
3062
3063 /**
3064 * @see #getProfileOwner()
3065 * @hide
3066 */
3067 public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00003068 if (mService != null) {
3069 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003070 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00003071 } catch (RemoteException re) {
3072 Log.w(TAG, "Failed to get profile owner");
3073 throw new IllegalArgumentException(
3074 "Requested profile owner for invalid userId", re);
3075 }
3076 }
3077 return null;
3078 }
3079
3080 /**
3081 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003082 * @return the human readable name of the organisation associated with this DPM or {@code null}
3083 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00003084 * @throws IllegalArgumentException if the userId is invalid.
3085 */
3086 public String getProfileOwnerName() throws IllegalArgumentException {
3087 if (mService != null) {
3088 try {
3089 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
3090 } catch (RemoteException re) {
3091 Log.w(TAG, "Failed to get profile owner");
3092 throw new IllegalArgumentException(
3093 "Requested profile owner for invalid userId", re);
3094 }
3095 }
3096 return null;
3097 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003098
3099 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07003100 * @hide
3101 * @param user The user for whom to fetch the profile owner name, if any.
3102 * @return the human readable name of the organisation associated with this profile owner or
3103 * null if one is not set.
3104 * @throws IllegalArgumentException if the userId is invalid.
3105 */
3106 @SystemApi
Selim Cinek24ac55e2014-08-27 12:51:45 +02003107 public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Amith Yamasani38f836b2014-08-20 14:51:15 -07003108 if (mService != null) {
3109 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02003110 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07003111 } catch (RemoteException re) {
3112 Log.w(TAG, "Failed to get profile owner");
3113 throw new IllegalArgumentException(
3114 "Requested profile owner for invalid userId", re);
3115 }
3116 }
3117 return null;
3118 }
3119
3120 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003121 * Called by a profile owner or device owner to add a default intent handler activity for
3122 * intents that match a certain intent filter. This activity will remain the default intent
3123 * handler even if the set of potential event handlers for the intent filter changes and if
3124 * the intent preferences are reset.
3125 *
3126 * <p>The default disambiguation mechanism takes over if the activity is not installed
3127 * (anymore). When the activity is (re)installed, it is automatically reset as default
3128 * intent handler for the filter.
3129 *
3130 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
3131 * security exception will be thrown.
3132 *
3133 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3134 * @param filter The IntentFilter for which a default handler is added.
3135 * @param activity The Activity that is added as default intent handler.
3136 */
Robin Lee25e26452015-06-02 09:56:29 -07003137 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
3138 @NonNull ComponentName activity) {
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003139 if (mService != null) {
3140 try {
3141 mService.addPersistentPreferredActivity(admin, filter, activity);
3142 } catch (RemoteException e) {
3143 Log.w(TAG, "Failed talking with device policy service", e);
3144 }
3145 }
3146 }
3147
3148 /**
3149 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00003150 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003151 *
3152 * <p>The calling device admin must be a profile owner. If it is not, a security
3153 * exception will be thrown.
3154 *
3155 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3156 * @param packageName The name of the package for which preferences are removed.
3157 */
Robin Lee25e26452015-06-02 09:56:29 -07003158 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003159 String packageName) {
3160 if (mService != null) {
3161 try {
3162 mService.clearPackagePersistentPreferredActivities(admin, packageName);
3163 } catch (RemoteException e) {
3164 Log.w(TAG, "Failed talking with device policy service", e);
3165 }
3166 }
3167 }
Robin Lee66e5d962014-04-09 16:44:21 +01003168
3169 /**
3170 * Called by a profile or device owner to set the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003171 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01003172 *
3173 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be
Kenny Guyd00cfc52014-09-18 16:24:31 +01003174 * boolean, int, String, or String[].
Robin Lee66e5d962014-04-09 16:44:21 +01003175 *
3176 * <p>The application restrictions are only made visible to the target application and the
3177 * profile or device owner.
3178 *
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003179 * <p>If the restrictions are not available yet, but may be applied in the near future,
3180 * the admin can notify the target application of that by adding
3181 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
3182 *
Robin Lee66e5d962014-04-09 16:44:21 +01003183 * <p>The calling device admin must be a profile or device owner; if it is not, a security
3184 * exception will be thrown.
3185 *
3186 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3187 * @param packageName The name of the package to update restricted settings for.
3188 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
3189 * set of active restrictions.
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003190 *
3191 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01003192 */
Robin Lee25e26452015-06-02 09:56:29 -07003193 public void setApplicationRestrictions(@NonNull ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01003194 Bundle settings) {
3195 if (mService != null) {
3196 try {
3197 mService.setApplicationRestrictions(admin, packageName, settings);
3198 } catch (RemoteException e) {
3199 Log.w(TAG, "Failed talking with device policy service", e);
3200 }
3201 }
3202 }
3203
3204 /**
Jim Millere303bf42014-08-26 17:12:29 -07003205 * Sets a list of configuration features to enable for a TrustAgent component. This is meant
3206 * to be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all
3207 * trust agents but those enabled by this function call. If flag
3208 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Jim Miller604e7552014-07-18 19:00:02 -07003209 *
3210 * <p>The calling device admin must have requested
3211 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millere303bf42014-08-26 17:12:29 -07003212 * this method; if not, a security exception will be thrown.
Jim Miller604e7552014-07-18 19:00:02 -07003213 *
3214 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07003215 * @param target Component name of the agent to be enabled.
Jim Millerb5db57a2015-01-14 18:17:19 -08003216 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent
Jim Millere303bf42014-08-26 17:12:29 -07003217 * will be strictly disabled according to the state of the
3218 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
3219 * <p>If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all admins,
3220 * then it's up to the TrustAgent itself to aggregate the values from all device admins.
3221 * <p>Consult documentation for the specific TrustAgent to determine legal options parameters.
Jim Miller604e7552014-07-18 19:00:02 -07003222 */
Robin Lee25e26452015-06-02 09:56:29 -07003223 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
3224 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07003225 if (mService != null) {
3226 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003227 mService.setTrustAgentConfiguration(admin, target, configuration);
Jim Miller604e7552014-07-18 19:00:02 -07003228 } catch (RemoteException e) {
3229 Log.w(TAG, "Failed talking with device policy service", e);
3230 }
3231 }
3232 }
3233
3234 /**
Jim Millere303bf42014-08-26 17:12:29 -07003235 * Gets configuration for the given trust agent based on aggregating all calls to
3236 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
3237 * all device admins.
Jim Miller604e7552014-07-18 19:00:02 -07003238 *
Jim Millerb5db57a2015-01-14 18:17:19 -08003239 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
3240 * this function returns a list of configurations for all admins that declare
3241 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
3242 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
3243 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
3244 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07003245 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07003246 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07003247 */
Robin Lee25e26452015-06-02 09:56:29 -07003248 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
3249 @NonNull ComponentName agent) {
Jim Millere303bf42014-08-26 17:12:29 -07003250 return getTrustAgentConfiguration(admin, agent, UserHandle.myUserId());
3251 }
3252
3253 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003254 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
3255 @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07003256 if (mService != null) {
3257 try {
Jim Millere303bf42014-08-26 17:12:29 -07003258 return mService.getTrustAgentConfiguration(admin, agent, userHandle);
Jim Miller604e7552014-07-18 19:00:02 -07003259 } catch (RemoteException e) {
3260 Log.w(TAG, "Failed talking with device policy service", e);
3261 }
3262 }
Jim Millere303bf42014-08-26 17:12:29 -07003263 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07003264 }
3265
3266 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003267 * Called by a profile owner of a managed profile to set whether caller-Id information from
3268 * the managed profile will be shown in the parent profile, for incoming calls.
Adam Connors210fe212014-07-17 15:41:43 +01003269 *
3270 * <p>The calling device admin must be a profile owner. If it is not, a
3271 * security exception will be thrown.
3272 *
Robin Lee25e26452015-06-02 09:56:29 -07003273 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01003274 * @param disabled If true caller-Id information in the managed profile is not displayed.
3275 */
Robin Lee25e26452015-06-02 09:56:29 -07003276 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Adam Connors210fe212014-07-17 15:41:43 +01003277 if (mService != null) {
3278 try {
Robin Lee25e26452015-06-02 09:56:29 -07003279 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01003280 } catch (RemoteException e) {
3281 Log.w(TAG, "Failed talking with device policy service", e);
3282 }
3283 }
3284 }
3285
3286 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003287 * Called by a profile owner of a managed profile to determine whether or not caller-Id
3288 * information has been disabled.
Adam Connors210fe212014-07-17 15:41:43 +01003289 *
3290 * <p>The calling device admin must be a profile owner. If it is not, a
3291 * security exception will be thrown.
3292 *
Robin Lee25e26452015-06-02 09:56:29 -07003293 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01003294 */
Robin Lee25e26452015-06-02 09:56:29 -07003295 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Adam Connors210fe212014-07-17 15:41:43 +01003296 if (mService != null) {
3297 try {
Robin Lee25e26452015-06-02 09:56:29 -07003298 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01003299 } catch (RemoteException e) {
3300 Log.w(TAG, "Failed talking with device policy service", e);
3301 }
3302 }
3303 return false;
3304 }
3305
3306 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07003307 * Determine whether or not caller-Id information has been disabled.
3308 *
3309 * @param userHandle The user for whom to check the caller-id permission
3310 * @hide
3311 */
3312 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
3313 if (mService != null) {
3314 try {
3315 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
3316 } catch (RemoteException e) {
3317 Log.w(TAG, "Failed talking with device policy service", e);
3318 }
3319 }
3320 return false;
3321 }
3322
3323 /**
Makoto Onuki1040da12015-03-19 11:24:00 -07003324 * Start Quick Contact on the managed profile for the current user, if the policy allows.
3325 * @hide
3326 */
3327 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
3328 Intent originalIntent) {
3329 if (mService != null) {
3330 try {
3331 mService.startManagedQuickContact(
3332 actualLookupKey, actualContactId, originalIntent);
3333 } catch (RemoteException e) {
3334 Log.w(TAG, "Failed talking with device policy service", e);
3335 }
3336 }
3337 }
3338
3339 /**
Ricky Wai778ba132015-03-31 14:21:22 +01003340 * Called by a profile owner of a managed profile to set whether bluetooth
3341 * devices can access enterprise contacts.
3342 * <p>
3343 * The calling device admin must be a profile owner. If it is not, a
3344 * security exception will be thrown.
3345 * <p>
3346 * This API works on managed profile only.
3347 *
Robin Lee25e26452015-06-02 09:56:29 -07003348 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01003349 * with.
3350 * @param disabled If true, bluetooth devices cannot access enterprise
3351 * contacts.
3352 */
Robin Lee25e26452015-06-02 09:56:29 -07003353 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Ricky Wai778ba132015-03-31 14:21:22 +01003354 if (mService != null) {
3355 try {
Robin Lee25e26452015-06-02 09:56:29 -07003356 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01003357 } catch (RemoteException e) {
3358 Log.w(TAG, "Failed talking with device policy service", e);
3359 }
3360 }
3361 }
3362
3363 /**
3364 * Called by a profile owner of a managed profile to determine whether or
3365 * not Bluetooth devices cannot access enterprise contacts.
3366 * <p>
3367 * The calling device admin must be a profile owner. If it is not, a
3368 * security exception will be thrown.
3369 * <p>
3370 * This API works on managed profile only.
3371 *
Robin Lee25e26452015-06-02 09:56:29 -07003372 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01003373 * with.
3374 */
Robin Lee25e26452015-06-02 09:56:29 -07003375 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Ricky Wai778ba132015-03-31 14:21:22 +01003376 if (mService != null) {
3377 try {
Robin Lee25e26452015-06-02 09:56:29 -07003378 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01003379 } catch (RemoteException e) {
3380 Log.w(TAG, "Failed talking with device policy service", e);
3381 }
3382 }
3383 return true;
3384 }
3385
3386 /**
3387 * Determine whether or not Bluetooth devices cannot access contacts.
3388 * <p>
3389 * This API works on managed profile UserHandle only.
3390 *
3391 * @param userHandle The user for whom to check the caller-id permission
3392 * @hide
3393 */
3394 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
3395 if (mService != null) {
3396 try {
3397 return mService.getBluetoothContactSharingDisabledForUser(userHandle
3398 .getIdentifier());
3399 } catch (RemoteException e) {
3400 Log.w(TAG, "Failed talking with device policy service", e);
3401 }
3402 }
3403 return true;
3404 }
3405
3406 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003407 * Called by the profile owner of a managed profile so that some intents sent in the managed
3408 * profile can also be resolved in the parent, or vice versa.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00003409 * Only activity intents are supported.
3410 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003411 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01003412 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
3413 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01003414 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
3415 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003416 */
Robin Lee25e26452015-06-02 09:56:29 -07003417 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003418 if (mService != null) {
3419 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003420 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003421 } catch (RemoteException e) {
3422 Log.w(TAG, "Failed talking with device policy service", e);
3423 }
3424 }
3425 }
3426
3427 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003428 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
3429 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01003430 * Only removes those that have been set by the profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003431 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3432 */
Robin Lee25e26452015-06-02 09:56:29 -07003433 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003434 if (mService != null) {
3435 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003436 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003437 } catch (RemoteException e) {
3438 Log.w(TAG, "Failed talking with device policy service", e);
3439 }
3440 }
3441 }
3442
3443 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003444 * Called by a profile or device owner to set the permitted accessibility services. When
3445 * set by a device owner or profile owner the restriction applies to all profiles of the
3446 * user the device owner or profile owner is an admin for.
Jim Millerb1474f42014-08-26 18:42:58 -07003447 *
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003448 * By default the user can use any accessiblity service. When zero or more packages have
3449 * been added, accessiblity services that are not in the list and not part of the system
Jim Millerb1474f42014-08-26 18:42:58 -07003450 * can not be enabled by the user.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003451 *
3452 * <p> Calling with a null value for the list disables the restriction so that all services
3453 * can be used, calling with an empty list only allows the builtin system's services.
3454 *
3455 * <p> System accesibility services are always available to the user the list can't modify
3456 * this.
3457 *
3458 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3459 * @param packageNames List of accessibility service package names.
3460 *
3461 * @return true if setting the restriction succeeded. It fail if there is
3462 * one or more non-system accessibility services enabled, that are not in the list.
3463 */
Robin Lee25e26452015-06-02 09:56:29 -07003464 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003465 List<String> packageNames) {
3466 if (mService != null) {
3467 try {
3468 return mService.setPermittedAccessibilityServices(admin, packageNames);
3469 } catch (RemoteException e) {
3470 Log.w(TAG, "Failed talking with device policy service", e);
3471 }
3472 }
3473 return false;
3474 }
3475
3476 /**
3477 * Returns the list of permitted accessibility services set by this device or profile owner.
3478 *
3479 * <p>An empty list means no accessibility services except system services are allowed.
3480 * Null means all accessibility services are allowed.
3481 *
3482 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3483 * @return List of accessiblity service package names.
3484 */
Robin Lee25e26452015-06-02 09:56:29 -07003485 public List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003486 if (mService != null) {
3487 try {
3488 return mService.getPermittedAccessibilityServices(admin);
3489 } catch (RemoteException e) {
3490 Log.w(TAG, "Failed talking with device policy service", e);
3491 }
3492 }
3493 return null;
3494 }
3495
3496 /**
3497 * Returns the list of accessibility services permitted by the device or profiles
3498 * owners of this user.
3499 *
3500 * <p>Null means all accessibility services are allowed, if a non-null list is returned
3501 * it will contain the intersection of the permitted lists for any device or profile
3502 * owners that apply to this user. It will also include any system accessibility services.
3503 *
3504 * @param userId which user to check for.
3505 * @return List of accessiblity service package names.
3506 * @hide
3507 */
3508 @SystemApi
3509 public List<String> getPermittedAccessibilityServices(int userId) {
3510 if (mService != null) {
3511 try {
3512 return mService.getPermittedAccessibilityServicesForUser(userId);
3513 } catch (RemoteException e) {
3514 Log.w(TAG, "Failed talking with device policy service", e);
3515 }
3516 }
3517 return null;
3518 }
3519
3520 /**
3521 * Called by a profile or device owner to set the permitted input methods services. When
3522 * set by a device owner or profile owner the restriction applies to all profiles of the
3523 * user the device owner or profile owner is an admin for.
3524 *
3525 * By default the user can use any input method. When zero or more packages have
3526 * been added, input method that are not in the list and not part of the system
3527 * can not be enabled by the user.
3528 *
3529 * This method will fail if it is called for a admin that is not for the foreground user
3530 * or a profile of the foreground user.
3531 *
3532 * <p> Calling with a null value for the list disables the restriction so that all input methods
3533 * can be used, calling with an empty list disables all but the system's own input methods.
3534 *
3535 * <p> System input methods are always available to the user this method can't modify this.
3536 *
3537 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3538 * @param packageNames List of input method package names.
Kenny Guy74a70242015-02-05 19:48:38 +00003539 * @return true if setting the restriction succeeded. It will fail if there are
3540 * one or more non-system input methods currently enabled that are not in
3541 * the packageNames list.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003542 */
Robin Lee25e26452015-06-02 09:56:29 -07003543 public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003544 if (mService != null) {
3545 try {
3546 return mService.setPermittedInputMethods(admin, packageNames);
3547 } catch (RemoteException e) {
3548 Log.w(TAG, "Failed talking with device policy service", e);
3549 }
3550 }
3551 return false;
3552 }
3553
3554
3555 /**
3556 * Returns the list of permitted input methods set by this device or profile owner.
3557 *
3558 * <p>An empty list means no input methods except system input methods are allowed.
3559 * Null means all input methods are allowed.
3560 *
3561 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3562 * @return List of input method package names.
3563 */
Robin Lee25e26452015-06-02 09:56:29 -07003564 public List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003565 if (mService != null) {
3566 try {
3567 return mService.getPermittedInputMethods(admin);
3568 } catch (RemoteException e) {
3569 Log.w(TAG, "Failed talking with device policy service", e);
3570 }
3571 }
3572 return null;
3573 }
3574
3575 /**
3576 * Returns the list of input methods permitted by the device or profiles
3577 * owners of the current user.
3578 *
3579 * <p>Null means all input methods are allowed, if a non-null list is returned
3580 * it will contain the intersection of the permitted lists for any device or profile
3581 * owners that apply to this user. It will also include any system input methods.
3582 *
3583 * @return List of input method package names.
3584 * @hide
3585 */
3586 @SystemApi
3587 public List<String> getPermittedInputMethodsForCurrentUser() {
3588 if (mService != null) {
3589 try {
3590 return mService.getPermittedInputMethodsForCurrentUser();
3591 } catch (RemoteException e) {
3592 Log.w(TAG, "Failed talking with device policy service", e);
3593 }
3594 }
3595 return null;
3596 }
3597
3598 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003599 * Called by a device owner to create a user with the specified name. The UserHandle returned
3600 * by this method should not be persisted as user handles are recycled as users are removed and
3601 * created. If you need to persist an identifier for this user, use
3602 * {@link UserManager#getSerialNumberForUser}.
3603 *
3604 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3605 * @param name the user's name
3606 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07003607 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
3608 * user could not be created.
Julia Reynolds1e958392014-05-16 14:25:21 -04003609 */
Robin Lee25e26452015-06-02 09:56:29 -07003610 public UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04003611 try {
3612 return mService.createUser(admin, name);
3613 } catch (RemoteException re) {
3614 Log.w(TAG, "Could not create a user", re);
3615 }
3616 return null;
3617 }
3618
3619 /**
Jason Monk03978a42014-06-10 15:05:30 -04003620 * Called by a device owner to create a user with the specified name. The UserHandle returned
3621 * by this method should not be persisted as user handles are recycled as users are removed and
3622 * created. If you need to persist an identifier for this user, use
3623 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
3624 * immediately.
3625 *
3626 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
3627 * as registered as an active admin on the new user. The profile owner package will be
3628 * installed on the new user if it already is installed on the device.
3629 *
3630 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
3631 * profileOwnerComponent when onEnable is called.
3632 *
3633 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3634 * @param name the user's name
3635 * @param ownerName the human readable name of the organisation associated with this DPM.
3636 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
3637 * the user.
3638 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
3639 * on the new user.
3640 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07003641 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
3642 * user could not be created.
Jason Monk03978a42014-06-10 15:05:30 -04003643 */
Robin Lee25e26452015-06-02 09:56:29 -07003644 public UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
3645 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04003646 try {
3647 return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent,
3648 adminExtras);
3649 } catch (RemoteException re) {
3650 Log.w(TAG, "Could not create a user", re);
3651 }
3652 return null;
3653 }
3654
3655 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003656 * Called by a device owner to remove a user and all associated data. The primary user can
3657 * not be removed.
3658 *
3659 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3660 * @param userHandle the user to remove.
3661 * @return {@code true} if the user was removed, {@code false} otherwise.
3662 */
Robin Lee25e26452015-06-02 09:56:29 -07003663 public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) {
Julia Reynolds1e958392014-05-16 14:25:21 -04003664 try {
3665 return mService.removeUser(admin, userHandle);
3666 } catch (RemoteException re) {
3667 Log.w(TAG, "Could not remove user ", re);
3668 return false;
3669 }
3670 }
3671
3672 /**
Jason Monk582d9112014-07-09 19:57:08 -04003673 * Called by a device owner to switch the specified user to the foreground.
3674 *
3675 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3676 * @param userHandle the user to switch to; null will switch to primary.
3677 * @return {@code true} if the switch was successful, {@code false} otherwise.
3678 *
3679 * @see Intent#ACTION_USER_FOREGROUND
3680 */
Robin Lee25e26452015-06-02 09:56:29 -07003681 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Jason Monk582d9112014-07-09 19:57:08 -04003682 try {
3683 return mService.switchUser(admin, userHandle);
3684 } catch (RemoteException re) {
3685 Log.w(TAG, "Could not switch user ", re);
3686 return false;
3687 }
3688 }
3689
3690 /**
Robin Lee66e5d962014-04-09 16:44:21 +01003691 * Called by a profile or device owner to get the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003692 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01003693 *
3694 * <p>The calling device admin must be a profile or device owner; if it is not, a security
3695 * exception will be thrown.
3696 *
3697 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3698 * @param packageName The name of the package to fetch restricted settings of.
3699 * @return {@link Bundle} of settings corresponding to what was set last time
3700 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
3701 * if no restrictions have been set.
3702 */
Robin Lee25e26452015-06-02 09:56:29 -07003703 public Bundle getApplicationRestrictions(@NonNull ComponentName admin, String packageName) {
Robin Lee66e5d962014-04-09 16:44:21 +01003704 if (mService != null) {
3705 try {
3706 return mService.getApplicationRestrictions(admin, packageName);
3707 } catch (RemoteException e) {
3708 Log.w(TAG, "Failed talking with device policy service", e);
3709 }
3710 }
3711 return null;
3712 }
Amith Yamasanibe465322014-04-24 13:45:17 -07003713
3714 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003715 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07003716 * <p>
3717 * The calling device admin must be a profile or device owner; if it is not,
3718 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003719 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003720 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3721 * with.
3722 * @param key The key of the restriction. See the constants in
3723 * {@link android.os.UserManager} for the list of keys.
3724 */
Robin Lee25e26452015-06-02 09:56:29 -07003725 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07003726 if (mService != null) {
3727 try {
3728 mService.setUserRestriction(admin, key, true);
3729 } catch (RemoteException e) {
3730 Log.w(TAG, "Failed talking with device policy service", e);
3731 }
3732 }
3733 }
3734
3735 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003736 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07003737 * <p>
3738 * The calling device admin must be a profile or device owner; if it is not,
3739 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003740 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003741 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3742 * with.
3743 * @param key The key of the restriction. See the constants in
3744 * {@link android.os.UserManager} for the list of keys.
3745 */
Robin Lee25e26452015-06-02 09:56:29 -07003746 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07003747 if (mService != null) {
3748 try {
3749 mService.setUserRestriction(admin, key, false);
3750 } catch (RemoteException e) {
3751 Log.w(TAG, "Failed talking with device policy service", e);
3752 }
3753 }
3754 }
Adam Connors010cfd42014-04-16 12:48:13 +01003755
3756 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003757 * Called by profile or device owners to hide or unhide packages. When a package is hidden it
Julia Reynolds966881e2014-05-14 12:23:08 -04003758 * is unavailable for use, but the data and actual package file remain.
3759 *
3760 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003761 * @param packageName The name of the package to hide or unhide.
3762 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
3763 * unhidden.
3764 * @return boolean Whether the hidden setting of the package was successfully updated.
Julia Reynolds966881e2014-05-14 12:23:08 -04003765 */
Robin Lee25e26452015-06-02 09:56:29 -07003766 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003767 boolean hidden) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003768 if (mService != null) {
3769 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003770 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04003771 } catch (RemoteException e) {
3772 Log.w(TAG, "Failed talking with device policy service", e);
3773 }
3774 }
3775 return false;
3776 }
3777
3778 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003779 * Called by profile or device owners to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04003780 *
3781 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003782 * @param packageName The name of the package to retrieve the hidden status of.
3783 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Julia Reynolds966881e2014-05-14 12:23:08 -04003784 */
Robin Lee25e26452015-06-02 09:56:29 -07003785 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003786 if (mService != null) {
3787 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003788 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04003789 } catch (RemoteException e) {
3790 Log.w(TAG, "Failed talking with device policy service", e);
3791 }
3792 }
3793 return false;
3794 }
3795
3796 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003797 * Called by profile or device owners to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003798 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003799 *
3800 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3801 * @param packageName The package to be re-enabled in the current profile.
3802 */
Robin Lee25e26452015-06-02 09:56:29 -07003803 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Adam Connors655be2a2014-07-14 09:01:25 +00003804 if (mService != null) {
3805 try {
3806 mService.enableSystemApp(admin, packageName);
3807 } catch (RemoteException e) {
3808 Log.w(TAG, "Failed to install package: " + packageName);
3809 }
3810 }
3811 }
3812
3813 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003814 * Called by profile or device owners to re-enable system apps by intent that were disabled
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003815 * by default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003816 *
3817 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3818 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
3819 * intent will be re-enabled in the current profile.
3820 * @return int The number of activities that matched the intent and were installed.
3821 */
Robin Lee25e26452015-06-02 09:56:29 -07003822 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Adam Connors655be2a2014-07-14 09:01:25 +00003823 if (mService != null) {
3824 try {
3825 return mService.enableSystemAppWithIntent(admin, intent);
3826 } catch (RemoteException e) {
3827 Log.w(TAG, "Failed to install packages matching filter: " + intent);
3828 }
3829 }
3830 return 0;
3831 }
3832
3833 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00003834 * Called by a device owner or profile owner to disable account management for a specific type
3835 * of account.
Sander Alewijnse650c3342014-05-08 18:00:50 +01003836 *
Sander Alewijnse112e0532014-10-29 13:28:49 +00003837 * <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 +01003838 * security exception will be thrown.
3839 *
3840 * <p>When account management is disabled for an account type, adding or removing an account
3841 * of that type will not be possible.
3842 *
3843 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3844 * @param accountType For which account management is disabled or enabled.
3845 * @param disabled The boolean indicating that account management will be disabled (true) or
3846 * enabled (false).
3847 */
Robin Lee25e26452015-06-02 09:56:29 -07003848 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01003849 boolean disabled) {
3850 if (mService != null) {
3851 try {
3852 mService.setAccountManagementDisabled(admin, accountType, disabled);
3853 } catch (RemoteException e) {
3854 Log.w(TAG, "Failed talking with device policy service", e);
3855 }
3856 }
3857 }
3858
3859 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003860 * Gets the array of accounts for which account management is disabled by the profile owner.
3861 *
3862 * <p> Account management can be disabled/enabled by calling
3863 * {@link #setAccountManagementDisabled}.
3864 *
3865 * @return a list of account types for which account management has been disabled.
3866 *
3867 * @see #setAccountManagementDisabled
3868 */
3869 public String[] getAccountTypesWithManagementDisabled() {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003870 return getAccountTypesWithManagementDisabledAsUser(UserHandle.myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003871 }
3872
3873 /**
3874 * @see #getAccountTypesWithManagementDisabled()
3875 * @hide
3876 */
3877 public String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003878 if (mService != null) {
3879 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003880 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003881 } catch (RemoteException e) {
3882 Log.w(TAG, "Failed talking with device policy service", e);
3883 }
3884 }
3885
3886 return null;
3887 }
justinzhang511e0d82014-03-24 16:09:24 -04003888
3889 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003890 * Sets which packages may enter lock task mode.
3891 *
3892 * <p>Any packages that shares uid with an allowed package will also be allowed
3893 * to activate lock task.
justinzhang511e0d82014-03-24 16:09:24 -04003894 *
Benjamin Franz469dd582015-06-09 14:24:36 +01003895 * From {@link android.os.Build.VERSION_CODES#MNC} removing packages from the lock task
3896 * package list results in locked tasks belonging to those packages to be finished.
3897 *
Jason Monkc5185f22014-06-24 11:12:42 -04003898 * This function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04003899 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04003900 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jason Monkd7b86212014-06-16 13:15:38 -04003901 *
3902 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00003903 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
3904 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04003905 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04003906 */
Robin Lee25e26452015-06-02 09:56:29 -07003907 public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04003908 throws SecurityException {
justinzhang511e0d82014-03-24 16:09:24 -04003909 if (mService != null) {
3910 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003911 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04003912 } catch (RemoteException e) {
3913 Log.w(TAG, "Failed talking with device policy service", e);
3914 }
3915 }
3916 }
3917
3918 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003919 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04003920 *
3921 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04003922 * @hide
3923 */
Robin Lee25e26452015-06-02 09:56:29 -07003924 public String[] getLockTaskPackages(@NonNull ComponentName admin) {
justinzhang511e0d82014-03-24 16:09:24 -04003925 if (mService != null) {
3926 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003927 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04003928 } catch (RemoteException e) {
3929 Log.w(TAG, "Failed talking with device policy service", e);
3930 }
3931 }
3932 return null;
3933 }
3934
3935 /**
3936 * This function lets the caller know whether the given component is allowed to start the
3937 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04003938 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04003939 */
Jason Monkd7b86212014-06-16 13:15:38 -04003940 public boolean isLockTaskPermitted(String pkg) {
justinzhang511e0d82014-03-24 16:09:24 -04003941 if (mService != null) {
3942 try {
Jason Monkd7b86212014-06-16 13:15:38 -04003943 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04003944 } catch (RemoteException e) {
3945 Log.w(TAG, "Failed talking with device policy service", e);
3946 }
3947 }
3948 return false;
3949 }
Julia Reynoldsda551652014-05-14 17:15:16 -04003950
3951 /**
3952 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
3953 * 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 -04003954 * <p>The settings that can be updated with this method are:
3955 * <ul>
3956 * <li>{@link Settings.Global#ADB_ENABLED}</li>
3957 * <li>{@link Settings.Global#AUTO_TIME}</li>
3958 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Nicolas Prevot41916d42015-02-24 18:41:50 +00003959 * <li>{@link Settings.Global#BLUETOOTH_ON}
3960 * Changing this setting has not effect as of {@link android.os.Build.VERSION_CODES#MNC}. Use
3961 * {@link android.bluetooth.BluetoothAdapter#enable()} and
3962 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003963 * <li>{@link Settings.Global#DATA_ROAMING}</li>
3964 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
3965 * <li>{@link Settings.Global#MODE_RINGER}</li>
3966 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
3967 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Nicolas Prevot41916d42015-02-24 18:41:50 +00003968 * <li>{@link Settings.Global#WIFI_ON}
3969 * Changing this setting has not effect as of {@link android.os.Build.VERSION_CODES#MNC}. Use
3970 * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003971 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Benjamin Franz68cc4202015-03-11 15:43:06 +00003972 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN}
3973 * This setting is only available from {@link android.os.Build.VERSION_CODES#MNC} onwards
3974 * and can only be set if {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
Zoltan Szatmary-Ban4045d242015-05-27 12:42:39 +01003975 * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003976 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04003977 *
3978 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3979 * @param setting The name of the setting to update.
3980 * @param value The value to update the setting to.
3981 */
Robin Lee25e26452015-06-02 09:56:29 -07003982 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04003983 if (mService != null) {
3984 try {
3985 mService.setGlobalSetting(admin, setting, value);
3986 } catch (RemoteException e) {
3987 Log.w(TAG, "Failed talking with device policy service", e);
3988 }
3989 }
3990 }
3991
3992 /**
3993 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
3994 * that the value of the setting is in the correct form for the setting type should be performed
3995 * by the caller.
Julia Reynolds82735bc2014-09-04 16:43:30 -04003996 * <p>The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003997 * <ul>
3998 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07003999 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004000 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
4001 * </ul>
Julia Reynolds82735bc2014-09-04 16:43:30 -04004002 * <p>A device owner can additionally update the following settings:
4003 * <ul>
4004 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
4005 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04004006 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4007 * @param setting The name of the setting to update.
4008 * @param value The value to update the setting to.
4009 */
Robin Lee25e26452015-06-02 09:56:29 -07004010 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04004011 if (mService != null) {
4012 try {
4013 mService.setSecureSetting(admin, setting, value);
4014 } catch (RemoteException e) {
4015 Log.w(TAG, "Failed talking with device policy service", e);
4016 }
4017 }
4018 }
4019
Amith Yamasanif20d6402014-05-24 15:34:37 -07004020 /**
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004021 * Designates a specific service component as the provider for
Amith Yamasanif20d6402014-05-24 15:34:37 -07004022 * making permission requests of a local or remote administrator of the user.
4023 * <p/>
4024 * Only a profile owner can designate the restrictions provider.
4025 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004026 * @param provider The component name of the service that implements
Amith Yamasanid1d7c022014-08-19 17:03:41 -07004027 * {@link RestrictionsReceiver}. If this param is null,
Amith Yamasanif20d6402014-05-24 15:34:37 -07004028 * it removes the restrictions provider previously assigned.
4029 */
Robin Lee25e26452015-06-02 09:56:29 -07004030 public void setRestrictionsProvider(@NonNull ComponentName admin,
4031 @Nullable ComponentName provider) {
Amith Yamasanif20d6402014-05-24 15:34:37 -07004032 if (mService != null) {
4033 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004034 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07004035 } catch (RemoteException re) {
4036 Log.w(TAG, "Failed to set permission provider on device policy service");
4037 }
4038 }
4039 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04004040
4041 /**
4042 * Called by profile or device owners to set the master volume mute on or off.
4043 *
4044 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4045 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
4046 */
Robin Lee25e26452015-06-02 09:56:29 -07004047 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04004048 if (mService != null) {
4049 try {
4050 mService.setMasterVolumeMuted(admin, on);
4051 } catch (RemoteException re) {
4052 Log.w(TAG, "Failed to setMasterMute on device policy service");
4053 }
4054 }
4055 }
4056
4057 /**
4058 * Called by profile or device owners to check whether the master volume mute is on or off.
4059 *
4060 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4061 * @return {@code true} if master volume is muted, {@code false} if it's not.
4062 */
Robin Lee25e26452015-06-02 09:56:29 -07004063 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04004064 if (mService != null) {
4065 try {
4066 return mService.isMasterVolumeMuted(admin);
4067 } catch (RemoteException re) {
4068 Log.w(TAG, "Failed to get isMasterMute on device policy service");
4069 }
4070 }
4071 return false;
4072 }
Kenny Guyc13053b2014-05-29 14:17:17 +01004073
4074 /**
4075 * Called by profile or device owners to change whether a user can uninstall
4076 * a package.
4077 *
4078 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4079 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004080 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Kenny Guyc13053b2014-05-29 14:17:17 +01004081 */
Robin Lee25e26452015-06-02 09:56:29 -07004082 public void setUninstallBlocked(@NonNull ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004083 boolean uninstallBlocked) {
Kenny Guyc13053b2014-05-29 14:17:17 +01004084 if (mService != null) {
4085 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004086 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01004087 } catch (RemoteException re) {
4088 Log.w(TAG, "Failed to call block uninstall on device policy service");
4089 }
4090 }
4091 }
4092
4093 /**
Rubin Xua97855b2014-11-07 05:41:00 +00004094 * Check whether the current user has been blocked by device policy from uninstalling a package.
4095 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00004096 * <p>
4097 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Robin Lee25e26452015-06-02 09:56:29 -07004098 * behavior of this API is changed such that passing {@code null} as the {@code admin}
Rubin Xue1e6faa2015-03-10 10:51:59 +00004099 * parameter will return if any admin has blocked the uninstallation. Before L MR1, passing
Robin Lee25e26452015-06-02 09:56:29 -07004100 * {@code null} will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01004101 *
Robin Lee25e26452015-06-02 09:56:29 -07004102 * @param admin The name of the admin component whose blocking policy will be checked, or
4103 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01004104 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00004105 * @return true if uninstallation is blocked.
Kenny Guyc13053b2014-05-29 14:17:17 +01004106 */
Robin Lee25e26452015-06-02 09:56:29 -07004107 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Kenny Guyc13053b2014-05-29 14:17:17 +01004108 if (mService != null) {
4109 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01004110 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01004111 } catch (RemoteException re) {
4112 Log.w(TAG, "Failed to call block uninstall on device policy service");
4113 }
4114 }
4115 return false;
4116 }
Svetoslav976e8bd2014-07-16 15:12:03 -07004117
4118 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004119 * Called by the profile owner of a managed profile to enable widget providers from a
4120 * given package to be available in the parent profile. As a result the user will be able to
Svetoslav976e8bd2014-07-16 15:12:03 -07004121 * add widgets from the white-listed package running under the profile to a widget
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004122 * host which runs under the parent profile, for example the home screen. Note that
Svetoslav976e8bd2014-07-16 15:12:03 -07004123 * a package may have zero or more provider components, where each component
4124 * provides a different widget type.
4125 * <p>
4126 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07004127 *
4128 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4129 * @param packageName The package from which widget providers are white-listed.
4130 * @return Whether the package was added.
4131 *
4132 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4133 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4134 */
Robin Lee25e26452015-06-02 09:56:29 -07004135 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004136 if (mService != null) {
4137 try {
4138 return mService.addCrossProfileWidgetProvider(admin, packageName);
4139 } catch (RemoteException re) {
4140 Log.w(TAG, "Error calling addCrossProfileWidgetProvider", re);
4141 }
4142 }
4143 return false;
4144 }
4145
4146 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004147 * Called by the profile owner of a managed profile to disable widget providers from a given
4148 * package to be available in the parent profile. For this method to take effect the
Svetoslav976e8bd2014-07-16 15:12:03 -07004149 * package should have been added via {@link #addCrossProfileWidgetProvider(
4150 * android.content.ComponentName, String)}.
4151 * <p>
4152 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07004153 *
4154 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4155 * @param packageName The package from which widget providers are no longer
4156 * white-listed.
4157 * @return Whether the package was removed.
4158 *
4159 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
4160 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4161 */
Robin Lee25e26452015-06-02 09:56:29 -07004162 public boolean removeCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004163 if (mService != null) {
4164 try {
4165 return mService.removeCrossProfileWidgetProvider(admin, packageName);
4166 } catch (RemoteException re) {
4167 Log.w(TAG, "Error calling removeCrossProfileWidgetProvider", re);
4168 }
4169 }
4170 return false;
4171 }
4172
4173 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004174 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07004175 * available in the parent profile.
4176 *
4177 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4178 * @return The white-listed package list.
4179 *
4180 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
4181 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4182 */
Robin Lee25e26452015-06-02 09:56:29 -07004183 public List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004184 if (mService != null) {
4185 try {
4186 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
4187 if (providers != null) {
4188 return providers;
4189 }
4190 } catch (RemoteException re) {
4191 Log.w(TAG, "Error calling getCrossProfileWidgetProviders", re);
4192 }
4193 }
4194 return Collections.emptyList();
4195 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004196
4197 /**
4198 * Called by profile or device owners to set the current user's photo.
4199 *
4200 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4201 * @param icon the bitmap to set as the photo.
4202 */
Robin Lee25e26452015-06-02 09:56:29 -07004203 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004204 try {
4205 mService.setUserIcon(admin, icon);
4206 } catch (RemoteException re) {
4207 Log.w(TAG, "Could not set the user icon ", re);
4208 }
4209 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04004210
4211 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01004212 * Called by device owners to set a local system update policy. When a new policy is set,
4213 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004214 *
Robin Lee25e26452015-06-02 09:56:29 -07004215 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
4216 * components in the device owner package can set system update policies and the
4217 * most recent policy takes
Rubin Xu5faad8e2015-04-20 17:43:48 +01004218 * effect.
Robin Lee25e26452015-06-02 09:56:29 -07004219 * @param policy the new policy, or {@code null} to clear the current policy.
Rubin Xu5faad8e2015-04-20 17:43:48 +01004220 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00004221 */
Robin Lee25e26452015-06-02 09:56:29 -07004222 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Rubin Xu8027a4f2015-03-10 17:52:37 +00004223 if (mService != null) {
4224 try {
Robin Lee25e26452015-06-02 09:56:29 -07004225 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004226 } catch (RemoteException re) {
Rubin Xu5faad8e2015-04-20 17:43:48 +01004227 Log.w(TAG, "Error calling setSystemUpdatePolicy", re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004228 }
4229 }
4230 }
4231
4232 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01004233 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004234 *
Robin Lee25e26452015-06-02 09:56:29 -07004235 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004236 */
Rubin Xu5faad8e2015-04-20 17:43:48 +01004237 public SystemUpdatePolicy getSystemUpdatePolicy() {
Rubin Xu8027a4f2015-03-10 17:52:37 +00004238 if (mService != null) {
4239 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01004240 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00004241 } catch (RemoteException re) {
Rubin Xu5faad8e2015-04-20 17:43:48 +01004242 Log.w(TAG, "Error calling getSystemUpdatePolicy", re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004243 }
4244 }
4245 return null;
4246 }
Benjamin Franze36087e2015-04-07 16:40:34 +01004247
4248 /**
4249 * Called by a device owner to disable the keyguard altogether.
4250 *
4251 * <p>Setting the keyguard to disabled has the same effect as choosing "None" as the screen
4252 * lock type. However, this call has no effect if a password, pin or pattern is currently set.
4253 * If a password, pin or pattern is set after the keyguard was disabled, the keyguard stops
4254 * being disabled.
4255 *
4256 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01004257 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01004258 *
4259 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Benjamin Franzbece8062015-05-06 12:14:31 +01004260 * place. {@code true} otherwise.
Benjamin Franze36087e2015-04-07 16:40:34 +01004261 */
Robin Lee25e26452015-06-02 09:56:29 -07004262 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franze36087e2015-04-07 16:40:34 +01004263 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01004264 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01004265 } catch (RemoteException re) {
4266 Log.w(TAG, "Failed talking with device policy service", re);
4267 return false;
4268 }
4269 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00004270
4271 /**
Benjamin Franzbece8062015-05-06 12:14:31 +01004272 * Called by device owner to disable the status bar. Disabling the status bar blocks
4273 * notifications, quick settings and other screen overlays that allow escaping from
Benjamin Franzea2ec972015-03-16 17:18:09 +00004274 * a single use device.
4275 *
4276 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01004277 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
4278 *
4279 * @return {@code false} if attempting to disable the status bar failed.
4280 * {@code true} otherwise.
Benjamin Franzea2ec972015-03-16 17:18:09 +00004281 */
Robin Lee25e26452015-06-02 09:56:29 -07004282 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzea2ec972015-03-16 17:18:09 +00004283 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01004284 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00004285 } catch (RemoteException re) {
4286 Log.w(TAG, "Failed talking with device policy service", re);
Benjamin Franzbece8062015-05-06 12:14:31 +01004287 return false;
Benjamin Franzea2ec972015-03-16 17:18:09 +00004288 }
4289 }
Rubin Xudc105cc2015-04-14 23:38:01 +01004290
4291 /**
4292 * Callable by the system update service to notify device owners about pending updates.
4293 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
4294 * permission.
4295 *
4296 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating
4297 * when the current pending update was first available. -1 if no update is available.
4298 * @hide
4299 */
4300 @SystemApi
4301 public void notifyPendingSystemUpdate(long updateReceivedTime) {
4302 if (mService != null) {
4303 try {
4304 mService.notifyPendingSystemUpdate(updateReceivedTime);
4305 } catch (RemoteException re) {
4306 Log.w(TAG, "Could not notify device owner about pending system update", re);
4307 }
4308 }
4309 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04004310
4311 /**
Amith Yamasanid49489b2015-04-28 14:00:26 -07004312 * Called by profile or device owners to set the default response for future runtime permission
4313 * requests by applications. The policy can allow for normal operation which prompts the
4314 * user to grant a permission, or can allow automatic granting or denying of runtime
4315 * permission requests by an application. This also applies to new permissions declared by app
4316 * updates.
4317 * @param admin Which profile or device owner this request is associated with.
4318 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
4319 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
4320 */
Robin Lee25e26452015-06-02 09:56:29 -07004321 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004322 try {
4323 mService.setPermissionPolicy(admin, policy);
4324 } catch (RemoteException re) {
4325 Log.w(TAG, "Failed talking with device policy service", re);
4326 }
4327 }
4328
4329 /**
4330 * Returns the current runtime permission policy set by the device or profile owner. The
4331 * default is {@link #PERMISSION_POLICY_PROMPT}.
4332 * @param admin Which profile or device owner this request is associated with.
4333 * @return the current policy for future permission requests.
4334 */
Esteban Talavera28b95702015-06-24 15:23:42 +01004335 public int getPermissionPolicy(ComponentName admin) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004336 try {
4337 return mService.getPermissionPolicy(admin);
4338 } catch (RemoteException re) {
4339 return PERMISSION_POLICY_PROMPT;
4340 }
4341 }
4342
4343 /**
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004344 * Sets the grant state of a runtime permission for a specific application. The state
4345 * can be {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it
4346 * through the UI, {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission
4347 * is denied and the user cannot manage it through the UI, and {@link
4348 * #PERMISSION_GRANT_STATE_GRANTED granted} in which the permission is granted and the
4349 * user cannot manage it through the UI. This might affect all permissions in a
4350 * group that the runtime permission belongs to. This method can only be called
4351 * by a profile or device owner.
4352 *
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07004353 * <p/>Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not
4354 * revoke the permission. It retains the previous grant, if any.
4355 *
4356 * <p/>Permissions can be granted or revoked only for applications built with a
4357 * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#MNC} or later.
4358 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07004359 * @param admin Which profile or device owner this request is associated with.
4360 * @param packageName The application to grant or revoke a permission to.
4361 * @param permission The permission to grant or revoke.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004362 * @param grantState The permission grant state which is one of {@link
4363 * #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
4364 * {@link #PERMISSION_GRANT_STATE_GRANTED},
4365 * @return whether the permission was successfully granted or revoked.
4366 *
4367 * @see #PERMISSION_GRANT_STATE_DENIED
4368 * @see #PERMISSION_GRANT_STATE_DEFAULT
4369 * @see #PERMISSION_GRANT_STATE_GRANTED
Amith Yamasanid49489b2015-04-28 14:00:26 -07004370 */
Robin Lee25e26452015-06-02 09:56:29 -07004371 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004372 String permission, int grantState) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004373 try {
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004374 return mService.setPermissionGrantState(admin, packageName, permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07004375 } catch (RemoteException re) {
4376 Log.w(TAG, "Failed talking with device policy service", re);
4377 return false;
4378 }
4379 }
Amith Yamasani184b3752015-05-22 13:00:51 -07004380
4381 /**
4382 * Returns the current grant state of a runtime permission for a specific application.
4383 *
4384 * @param admin Which profile or device owner this request is associated with.
4385 * @param packageName The application to check the grant state for.
4386 * @param permission The permission to check for.
4387 * @return the current grant state specified by device policy. If the profile or device owner
4388 * has not set a grant state, the return value is {@link #PERMISSION_GRANT_STATE_DEFAULT}.
4389 * This does not indicate whether or not the permission is currently granted for the package.
4390 *
4391 * <p/>If a grant state was set by the profile or device owner, then the return value will
4392 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or {@link #PERMISSION_GRANT_STATE_GRANTED},
4393 * which indicates if the permission is currently denied or granted.
4394 *
4395 * @see #setPermissionGrantState(ComponentName, String, String, int)
4396 * @see PackageManager#checkPermission(String, String)
4397 */
Robin Lee25e26452015-06-02 09:56:29 -07004398 public int getPermissionGrantState(@NonNull ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07004399 String permission) {
4400 try {
4401 return mService.getPermissionGrantState(admin, packageName, permission);
4402 } catch (RemoteException re) {
4403 Log.w(TAG, "Failed talking with device policy service", re);
4404 return PERMISSION_GRANT_STATE_DEFAULT;
4405 }
4406 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08004407}