blob: ac50699ca110d0c37ee8163f92ed8cfe9b8ed7be [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}.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700115 * As of {@link android.os.Build.VERSION_CODES#M}, it should contain the extra
Nicolas Prevot18440252015-03-09 14:07:17 +0000116 * {@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.
Alan Treadway4582f812015-07-28 11:49:35 +0100127 *
128 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
129 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
130 * the provisioning flow was successful, although this doesn't guarantee the full flow will
131 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
132 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000133 */
134 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
135 public static final String ACTION_PROVISION_MANAGED_PROFILE
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100136 = "android.app.action.PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000137
138 /**
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100139 * Activity action: Starts the provisioning flow which sets up a managed device.
140 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
141 *
142 * <p> During device owner provisioning a device admin app is set as the owner of the device.
143 * A device owner has full control over the device. The device owner can not be modified by the
144 * user.
145 *
146 * <p> A typical use case would be a device that is owned by a company, but used by either an
147 * employee or client.
148 *
149 * <p> An intent with this action can be sent only on an unprovisioned device.
150 * It is possible to check if the device is provisioned or not by looking at
151 * {@link android.provider.Settings.Global#DEVICE_PROVISIONED}
152 *
153 * The intent contains the following extras:
154 * <ul>
155 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
156 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
157 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
Rubin Xua4f9dc12015-06-12 13:27:59 +0100158 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100159 * </ul>
160 *
161 * <p> When device owner provisioning has completed, an intent of the type
162 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
163 * device owner.
164 *
165 * <p> If provisioning fails, the device is factory reset.
166 *
Alan Treadway4582f812015-07-28 11:49:35 +0100167 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
168 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
169 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
170 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100171 */
172 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
173 public static final String ACTION_PROVISION_MANAGED_DEVICE
174 = "android.app.action.PROVISION_MANAGED_DEVICE";
175
176 /**
Rubin Xua4f9dc12015-06-12 13:27:59 +0100177 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100178 * allows a mobile device management application or NFC programmer application which starts
179 * managed provisioning to pass data to the management application instance after provisioning.
Rubin Xua4f9dc12015-06-12 13:27:59 +0100180 * <p>
181 * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that
182 * sends the intent to pass data to itself on the newly created profile.
183 * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same
184 * instance of the app on the primary user.
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100185 * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with
186 * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC
187 * message should contain a stringified {@link java.util.Properties} instance, whose string
188 * properties will be converted into a {@link android.os.PersistableBundle} and passed to the
189 * management application after provisioning.
190 *
Rubin Xua4f9dc12015-06-12 13:27:59 +0100191 * <p>
192 * In both cases the application receives the data in
Brian Carlstromf1fe51b2014-09-03 08:55:05 -0700193 * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action
194 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed
Rubin Xua4f9dc12015-06-12 13:27:59 +0100195 * during the managed provisioning.
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100196 */
197 public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE =
Esteban Talavera37f01842014-09-05 10:50:57 +0100198 "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE";
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100199
200 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100201 * A String extra holding the package name of the mobile device management application that
202 * will be set as the profile owner or device owner.
203 *
204 * <p>If an application starts provisioning directly via an intent with action
205 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
206 * application that started provisioning. The package will be set as profile owner in that case.
207 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000208 * <p>This package is set as device owner when device owner provisioning is started by an NFC
209 * message containing an NFC record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000210 *
211 * <p> When this extra is set, the application must have exactly one device admin receiver.
Robin Lee25e26452015-06-02 09:56:29 -0700212 * This receiver will be set as the profile or device owner and active admin.
Nicolas Prevot18440252015-03-09 14:07:17 +0000213
214 * @see DeviceAdminReceiver
215 * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still
Nicolas Prevot8f78d6a2015-08-21 11:06:31 +0100216 * supported, but only if there is only one device admin receiver in the package that requires
217 * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000218 */
Nicolas Prevot18440252015-03-09 14:07:17 +0000219 @Deprecated
Jessica Hummelf72078b2014-03-06 16:13:12 +0000220 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100221 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000222
223 /**
Nicolas Prevot18440252015-03-09 14:07:17 +0000224 * A ComponentName extra indicating the device admin receiver of the mobile device management
225 * application that will be set as the profile owner or device owner and active admin.
226 *
227 * <p>If an application starts provisioning directly via an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100228 * {@link #ACTION_PROVISION_MANAGED_PROFILE} or
229 * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this
230 * component has to match the package name of the application that started provisioning.
Nicolas Prevot18440252015-03-09 14:07:17 +0000231 *
232 * <p>This component is set as device owner and active admin when device owner provisioning is
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100233 * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC
234 * message containing an NFC record with MIME type
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400235 * {@link #MIME_TYPE_PROVISIONING_NFC}. For the NFC record, the component name should be
Rubin Xu44ef750b2015-03-23 16:51:33 +0000236 * flattened to a string, via {@link ComponentName#flattenToShortString()}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000237 *
238 * @see DeviceAdminReceiver
239 */
240 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME
241 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME";
242
243 /**
Alexandra Gherghinaaaf2f3e2014-11-13 12:46:15 +0000244 * An {@link android.accounts.Account} extra holding the account to migrate during managed
245 * profile provisioning. If the account supplied is present in the primary user, it will be
246 * copied, along with its credentials to the managed profile and removed from the primary user.
247 *
248 * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}.
249 */
250
251 public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE
252 = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE";
253
254 /**
Jessica Hummele3da7902014-08-20 15:20:11 +0100255 * A String extra that, holds the email address of the account which a managed profile is
256 * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
257 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100258 *
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100259 * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}.
260 *
Jessica Hummele3da7902014-08-20 15:20:11 +0100261 * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning
262 * contains this extra, it is forwarded in the
263 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile
264 * device management application that was set as the profile owner during provisioning.
265 * It is usually used to avoid that the user has to enter their email address twice.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100266 */
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100267 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
268 = "android.app.extra.PROVISIONING_EMAIL_ADDRESS";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100269
270 /**
Sander Alewijnse8c411562014-11-12 18:03:11 +0000271 * A Boolean extra that can be used by the mobile device management application to skip the
Robin Lee25e26452015-06-02 09:56:29 -0700272 * disabling of system apps during provisioning when set to {@code true}.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000273 *
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100274 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
275 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000276 */
Sander Alewijnse5a144252014-11-18 13:25:04 +0000277 public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED =
278 "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED";
Sander Alewijnse8c411562014-11-12 18:03:11 +0000279
280 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100281 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
282 * will be set to.
283 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000284 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
285 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100286 */
287 public static final String EXTRA_PROVISIONING_TIME_ZONE
Esteban Talavera37f01842014-09-05 10:50:57 +0100288 = "android.app.extra.PROVISIONING_TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100289
290 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100291 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
292 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100293 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000294 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
295 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100296 */
297 public static final String EXTRA_PROVISIONING_LOCAL_TIME
Esteban Talavera37f01842014-09-05 10:50:57 +0100298 = "android.app.extra.PROVISIONING_LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100299
300 /**
301 * A String extra holding the {@link java.util.Locale} that the device will be set to.
302 * Format: xx_yy, where xx is the language code, and yy the country code.
303 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000304 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
305 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100306 */
307 public static final String EXTRA_PROVISIONING_LOCALE
Esteban Talavera37f01842014-09-05 10:50:57 +0100308 = "android.app.extra.PROVISIONING_LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100309
310 /**
311 * A String extra holding the ssid of the wifi network that should be used during nfc device
312 * owner provisioning for downloading the mobile device management application.
313 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000314 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
315 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100316 */
317 public static final String EXTRA_PROVISIONING_WIFI_SSID
Esteban Talavera37f01842014-09-05 10:50:57 +0100318 = "android.app.extra.PROVISIONING_WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100319
320 /**
321 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
322 * is hidden or not.
323 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000324 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
325 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100326 */
327 public static final String EXTRA_PROVISIONING_WIFI_HIDDEN
Esteban Talavera37f01842014-09-05 10:50:57 +0100328 = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100329
330 /**
331 * A String extra indicating the security type of the wifi network in
332 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
333 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000334 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
335 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100336 */
337 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
Esteban Talavera37f01842014-09-05 10:50:57 +0100338 = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100339
340 /**
341 * A String extra holding the password of the wifi network in
342 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
343 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000344 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
345 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100346 */
347 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talavera37f01842014-09-05 10:50:57 +0100348 = "android.app.extra.PROVISIONING_WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100349
350 /**
351 * A String extra holding the proxy host for the wifi network in
352 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
353 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000354 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
355 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100356 */
357 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
Esteban Talavera37f01842014-09-05 10:50:57 +0100358 = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100359
360 /**
361 * An int extra holding the proxy port for the wifi network in
362 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
363 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000364 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
365 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100366 */
367 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
Esteban Talavera37f01842014-09-05 10:50:57 +0100368 = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100369
370 /**
371 * A String extra holding the proxy bypass for the wifi network in
372 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
373 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000374 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
375 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100376 */
377 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
Esteban Talavera37f01842014-09-05 10:50:57 +0100378 = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100379
380 /**
381 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
382 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
383 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000384 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
385 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100386 */
387 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
Esteban Talavera37f01842014-09-05 10:50:57 +0100388 = "android.app.extra.PROVISIONING_WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100389
390 /**
391 * A String extra holding a url that specifies the download location of the device admin
392 * package. When not provided it is assumed that the device admin package is already installed.
393 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000394 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
395 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100396 */
397 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talavera37f01842014-09-05 10:50:57 +0100398 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100399
400 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400401 * An int extra holding a minimum required version code for the device admin package. If the
402 * device admin is already installed on the device, it will only be re-downloaded from
403 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the
404 * installed package is less than this version code.
405 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400406 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400407 * provisioning via an NFC bump.
408 */
409 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE
410 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE";
411
412 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100413 * A String extra holding a http cookie header which should be used in the http request to the
414 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
415 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000416 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
417 * provisioning via an NFC bump.
Sander Alewijnse681bce92014-07-24 16:46:26 +0100418 */
419 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talavera37f01842014-09-05 10:50:57 +0100420 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100421
422 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100423 * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of
424 * the file at download location specified in
425 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100426 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100427 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} should be
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100428 * present. The provided checksum should match the checksum of the file at the download
429 * location. If the checksum doesn't match an error will be shown to the user and the user will
430 * be asked to factory reset the device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100431 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000432 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
433 * provisioning via an NFC bump.
Rubin Xud92e7572015-05-18 17:01:13 +0100434 *
435 * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP}
436 * and {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1} only SHA-1 hash is supported.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700437 * Starting from {@link android.os.Build.VERSION_CODES#M}, this parameter accepts SHA-256 in
Rubin Xud92e7572015-05-18 17:01:13 +0100438 * addition to SHA-1. Support for SHA-1 is likely to be removed in future OS releases.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100439 */
440 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100441 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100442
443 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100444 * A String extra holding the URL-safe base64 encoded SHA-256 checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100445 * android package archive at the download location specified in {@link
446 * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
447 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100448 * <p>The signatures of an android package archive can be obtained using
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100449 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
450 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
451 *
452 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} should be
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100453 * present. The provided checksum should match the checksum of any signature of the file at
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100454 * the download location. If the checksum does not match an error will be shown to the user and
455 * the user will be asked to factory reset the device.
456 *
457 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
458 * provisioning via an NFC bump.
459 */
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100460 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM
461 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM";
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100462
463 /**
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000464 * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile
465 * has completed successfully.
466 *
467 * <p>The broadcast is limited to the primary profile, to the app specified in the provisioning
Nicolas Prevotebe2d992015-05-12 18:14:53 -0700468 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000469 *
Ying Wang7f38aab2015-02-20 11:50:09 -0800470 * <p>This intent will contain the extra {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE} which
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000471 * corresponds to the account requested to be migrated at provisioning time, if any.
472 */
473 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
474 public static final String ACTION_MANAGED_PROFILE_PROVISIONED
475 = "android.app.action.MANAGED_PROFILE_PROVISIONED";
476
477 /**
Julia Reynolds2f46d942015-05-05 11:44:20 -0400478 * A boolean extra indicating whether device encryption can be skipped as part of Device Owner
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500479 * provisioning.
480 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400481 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100482 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500483 */
484 public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION =
485 "android.app.extra.PROVISIONING_SKIP_ENCRYPTION";
486
487 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -0400488 * @hide
Rubin Xu44ef750b2015-03-23 16:51:33 +0000489 * On devices managed by a device owner app, a {@link ComponentName} extra indicating the
490 * component of the application that is temporarily granted device owner privileges during
491 * device initialization and profile owner privileges during secondary user initialization.
Julia Reynolds20118f12015-02-11 12:34:08 -0500492 *
Rubin Xu44ef750b2015-03-23 16:51:33 +0000493 * <p>
Rubin Xu6a38e432015-03-26 14:47:45 +0000494 * 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 +0000495 * device owner provisioning via an NFC bump. For the NFC record, it should be flattened to a
496 * string first.
497 *
498 * @see ComponentName#flattenToShortString()
Julia Reynolds20118f12015-02-11 12:34:08 -0500499 */
500 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_COMPONENT_NAME
501 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_COMPONENT_NAME";
502
503 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -0400504 * @hide
Julia Reynolds20118f12015-02-11 12:34:08 -0500505 * A String extra holding an http url that specifies the download location of the device
506 * initializer package. When not provided it is assumed that the device initializer package is
507 * already installed.
508 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400509 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynolds20118f12015-02-11 12:34:08 -0500510 * provisioning via an NFC bump.
511 */
512 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION
513 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION";
514
515 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -0400516 * @hide
Julia Reynoldsc1731742015-03-19 14:56:28 -0400517 * An int extra holding a minimum required version code for the device initializer package.
518 * If the initializer is already installed on the device, it will only be re-downloaded from
519 * {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION} if the version of
520 * the installed package is less than this version code.
521 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400522 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400523 * provisioning via an NFC bump.
524 */
525 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_MINIMUM_VERSION_CODE
526 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_MINIMUM_VERSION_CODE";
527
528 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -0400529 * @hide
Julia Reynolds20118f12015-02-11 12:34:08 -0500530 * A String extra holding a http cookie header which should be used in the http request to the
531 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION}.
532 *
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_DOWNLOAD_COOKIE_HEADER
537 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_COOKIE_HEADER";
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 the file at download
Rubin Xue30ab112015-03-24 11:22:28 +0000542 * location specified in
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100543 * {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION}.
544 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100545 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_SIGNATURE_CHECKSUM}
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100546 * should be present. The provided checksum should match the checksum of the file at the
547 * download location. If the checksum doesn't match an error will be shown to the user and the
548 * user will be asked to factory reset the device.
Julia Reynolds20118f12015-02-11 12:34:08 -0500549 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400550 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynolds20118f12015-02-11 12:34:08 -0500551 * provisioning via an NFC bump.
552 */
553 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM
554 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM";
555
556 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -0400557 * @hide
Rubin Xud92e7572015-05-18 17:01:13 +0100558 * A String extra holding the URL-safe base64 encoded SHA-256 checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100559 * android package archive at the download location specified in {@link
560 * #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION}.
561 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100562 * <p>The signatures of an android package archive can be obtained using
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100563 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
564 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
565 *
566 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM}
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100567 * should be present. The provided checksum should match the checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100568 * file at the download location. If the checksum doesn't match an error will be shown to the
569 * user and the user will be asked to factory reset the device.
570 *
571 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
572 * provisioning via an NFC bump.
573 */
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100574 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_SIGNATURE_CHECKSUM
575 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_SIGNATURE_CHECKSUM";
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100576
577 /**
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400578 * This MIME type is used for starting the Device Owner provisioning.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100579 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400580 * <p>During device owner provisioning a device admin app is set as the owner of the device.
581 * A device owner has full control over the device. The device owner can not be modified by the
582 * user and the only way of resetting the device is if the device owner app calls a factory
583 * reset.
584 *
585 * <p> A typical use case would be a device that is owned by a company, but used by either an
586 * employee or client.
587 *
588 * <p> The NFC message should be send to an unprovisioned device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100589 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000590 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100591 * contains the following properties:
592 * <ul>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400593 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
594 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100595 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400596 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100597 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
598 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
599 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
600 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
601 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
602 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
603 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
604 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
605 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
606 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100607 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
608 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from
609 * {@link android.os.Build.VERSION_CODES#M} </li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100610 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000611 * <p>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700612 * As of {@link android.os.Build.VERSION_CODES#M}, the properties should contain
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400613 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of
614 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only
615 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400616 */
617 public static final String MIME_TYPE_PROVISIONING_NFC
618 = "application/com.android.managedprovisioning";
619
620
621 /**
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400622 * @hide
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400623 * This MIME type is used for starting the Device Owner provisioning that requires
624 * new provisioning features introduced in API version
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700625 * {@link android.os.Build.VERSION_CODES#M} in addition to those supported in earlier
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400626 * versions.
627 *
628 * <p>During device owner provisioning a device admin app is set as the owner of the device.
629 * 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 +0100630 * user.
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400631 *
632 * <p> A typical use case would be a device that is owned by a company, but used by either an
633 * employee or client.
634 *
635 * <p> The NFC message should be sent to an unprovisioned device.
636 *
637 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
638 * contains the following properties in addition to properties listed at
639 * {@link #MIME_TYPE_PROVISIONING_NFC}:
640 * <ul>
641 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400642 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}.
643 * Replaces {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}. The value of the property
644 * should be converted to a String via
645 * {@link android.content.ComponentName#flattenToString()}</li>
Craig Lafayette240e6482015-06-02 11:12:43 -0400646 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE}, optional</li></ul>
Nicolas Prevot18440252015-03-09 14:07:17 +0000647 *
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100648 * <p> When device owner provisioning has completed, an intent of the type
649 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcasted to the
650 * device owner.
651 *
652 * <p>
653 * If provisioning fails, the device is factory reset.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100654 */
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400655 public static final String MIME_TYPE_PROVISIONING_NFC_V2
656 = "application/com.android.managedprovisioning.v2";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100657
658 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800659 * Activity action: ask the user to add a new device administrator to the system.
660 * The desired policy is the ComponentName of the policy in the
661 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
662 * bring the user through adding the device administrator to the system (or
663 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700664 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800665 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
666 * field to provide the user with additional explanation (in addition
667 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800668 *
669 * <p>If your administrator is already active, this will ordinarily return immediately (without
670 * user intervention). However, if your administrator has been updated and is requesting
671 * additional uses-policy flags, the user will be presented with the new list. New policies
672 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800673 */
674 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
675 public static final String ACTION_ADD_DEVICE_ADMIN
676 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700677
Dianne Hackbornd6847842010-01-12 18:14:19 -0800678 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700679 * @hide
680 * Activity action: ask the user to add a new device administrator as the profile owner
Amith Yamasani814e9872015-03-23 14:04:53 -0700681 * for this user. Only system apps can launch this intent.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700682 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700683 * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN}
684 * extra field. This will invoke a UI to bring the user through adding the profile owner admin
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700685 * to remotely control restrictions on the user.
686 *
687 * <p>The intent must be invoked via {@link Activity#startActivityForResult()} to receive the
688 * result of whether or not the user approved the action. If approved, the result will
689 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
690 * as a profile owner.
691 *
692 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
693 * field to provide the user with additional explanation (in addition
694 * to your component's description) about what is being added.
695 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700696 * <p>If there is already a profile owner active or the caller is not a system app, the
697 * operation will return a failure result.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700698 */
699 @SystemApi
700 public static final String ACTION_SET_PROFILE_OWNER
701 = "android.app.action.SET_PROFILE_OWNER";
702
703 /**
704 * @hide
705 * Name of the profile owner admin that controls the user.
706 */
707 @SystemApi
708 public static final String EXTRA_PROFILE_OWNER_NAME
709 = "android.app.extra.PROFILE_OWNER_NAME";
710
711 /**
Nicolas Prevot00799002015-07-27 18:15:20 +0100712 * Broadcast action: send when any policy admin changes a policy.
Jim Miller284b62e2010-06-08 14:27:42 -0700713 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700714 *
Jim Miller284b62e2010-06-08 14:27:42 -0700715 * @hide
716 */
717 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
718 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
719
720 /**
Nicolas Prevot00799002015-07-27 18:15:20 +0100721 * Broadcast action: sent when the device owner is set or changed.
722 *
723 * This broadcast is sent only to the primary user.
724 * @see #ACTION_PROVISION_MANAGED_DEVICE
725 */
726 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
727 public static final String ACTION_DEVICE_OWNER_CHANGED
728 = "android.app.action.DEVICE_OWNER_CHANGED";
729
730 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800731 * The ComponentName of the administrator component.
732 *
733 * @see #ACTION_ADD_DEVICE_ADMIN
734 */
735 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700736
Dianne Hackbornd6847842010-01-12 18:14:19 -0800737 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800738 * An optional CharSequence providing additional explanation for why the
739 * admin is being added.
740 *
741 * @see #ACTION_ADD_DEVICE_ADMIN
742 */
743 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700744
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800745 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700746 * Activity action: have the user enter a new password. This activity should
747 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
748 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
749 * enter a new password that meets the current requirements. You can use
750 * {@link #isActivePasswordSufficient()} to determine whether you need to
751 * have the user select a new password in order to meet the current
752 * constraints. Upon being resumed from this activity, you can check the new
753 * password characteristics to see if they are sufficient.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800754 */
755 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
756 public static final String ACTION_SET_NEW_PASSWORD
757 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700758
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000759 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000760 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
761 * the parent profile to access intents sent from the managed profile.
762 * That is, when an app in the managed profile calls
763 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
764 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000765 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100766 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000767
768 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000769 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
770 * the managed profile to access intents sent from the parent profile.
771 * That is, when an app in the parent profile calls
772 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
773 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000774 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100775 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700776
Dianne Hackbornd6847842010-01-12 18:14:19 -0800777 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +0100778 * Broadcast action: notify that a new local system update policy has been set by the device
779 * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}.
Rubin Xu8027a4f2015-03-10 17:52:37 +0000780 */
781 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Rubin Xu5faad8e2015-04-20 17:43:48 +0100782 public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED
783 = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED";
Rubin Xu8027a4f2015-03-10 17:52:37 +0000784
Amith Yamasanid49489b2015-04-28 14:00:26 -0700785 /**
786 * Permission policy to prompt user for new permission requests for runtime permissions.
787 * Already granted or denied permissions are not affected by this.
788 */
789 public static final int PERMISSION_POLICY_PROMPT = 0;
790
791 /**
792 * Permission policy to always grant new permission requests for runtime permissions.
793 * Already granted or denied permissions are not affected by this.
794 */
795 public static final int PERMISSION_POLICY_AUTO_GRANT = 1;
796
797 /**
798 * Permission policy to always deny new permission requests for runtime permissions.
799 * Already granted or denied permissions are not affected by this.
800 */
801 public static final int PERMISSION_POLICY_AUTO_DENY = 2;
802
Svet Ganovd8ecc5a2015-05-20 10:45:43 -0700803 /**
804 * Runtime permission state: The user can manage the permission
805 * through the UI.
806 */
807 public static final int PERMISSION_GRANT_STATE_DEFAULT = 0;
808
809 /**
810 * Runtime permission state: The permission is granted to the app
811 * and the user cannot manage the permission through the UI.
812 */
813 public static final int PERMISSION_GRANT_STATE_GRANTED = 1;
814
815 /**
816 * Runtime permission state: The permission is denied to the app
817 * and the user cannot manage the permission through the UI.
818 */
819 public static final int PERMISSION_GRANT_STATE_DENIED = 2;
Rubin Xu8027a4f2015-03-10 17:52:37 +0000820
821 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800822 * Return true if the given administrator component is currently
823 * active (enabled) in the system.
824 */
Robin Lee25e26452015-06-02 09:56:29 -0700825 public boolean isAdminActive(@NonNull ComponentName admin) {
826 return isAdminActiveAsUser(admin, UserHandle.myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100827 }
828
829 /**
830 * @see #isAdminActive(ComponentName)
831 * @hide
832 */
Robin Lee25e26452015-06-02 09:56:29 -0700833 public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800834 if (mService != null) {
835 try {
Robin Lee25e26452015-06-02 09:56:29 -0700836 return mService.isAdminActive(admin, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800837 } catch (RemoteException e) {
838 Log.w(TAG, "Failed talking with device policy service", e);
839 }
840 }
841 return false;
842 }
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800843 /**
844 * Return true if the given administrator component is currently being removed
845 * for the user.
846 * @hide
847 */
Robin Lee25e26452015-06-02 09:56:29 -0700848 public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) {
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800849 if (mService != null) {
850 try {
Robin Lee25e26452015-06-02 09:56:29 -0700851 return mService.isRemovingAdmin(admin, userId);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800852 } catch (RemoteException e) {
853 Log.w(TAG, "Failed talking with device policy service", e);
854 }
855 }
856 return false;
857 }
858
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700859
Dianne Hackbornd6847842010-01-12 18:14:19 -0800860 /**
Robin Lee25e26452015-06-02 09:56:29 -0700861 * Return a list of all currently active device administrators' component
862 * names. If there are no administrators {@code null} may be
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800863 * returned.
864 */
865 public List<ComponentName> getActiveAdmins() {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100866 return getActiveAdminsAsUser(UserHandle.myUserId());
867 }
868
869 /**
870 * @see #getActiveAdmins()
871 * @hide
872 */
873 public List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800874 if (mService != null) {
875 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100876 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800877 } catch (RemoteException e) {
878 Log.w(TAG, "Failed talking with device policy service", e);
879 }
880 }
881 return null;
882 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700883
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800884 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700885 * Used by package administration code to determine if a package can be stopped
886 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800887 * @hide
888 */
889 public boolean packageHasActiveAdmins(String packageName) {
890 if (mService != null) {
891 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700892 return mService.packageHasActiveAdmins(packageName, UserHandle.myUserId());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800893 } catch (RemoteException e) {
894 Log.w(TAG, "Failed talking with device policy service", e);
895 }
896 }
897 return false;
898 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700899
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800900 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800901 * Remove a current administration component. This can only be called
902 * by the application that owns the administration component; if you
903 * try to remove someone else's component, a security exception will be
904 * thrown.
905 */
Robin Lee25e26452015-06-02 09:56:29 -0700906 public void removeActiveAdmin(@NonNull ComponentName admin) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800907 if (mService != null) {
908 try {
Robin Lee25e26452015-06-02 09:56:29 -0700909 mService.removeActiveAdmin(admin, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800910 } catch (RemoteException e) {
911 Log.w(TAG, "Failed talking with device policy service", e);
912 }
913 }
914 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700915
Dianne Hackbornd6847842010-01-12 18:14:19 -0800916 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800917 * Returns true if an administrator has been granted a particular device policy. This can
Robin Lee25e26452015-06-02 09:56:29 -0700918 * be used to check whether the administrator was activated under an earlier set of policies,
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800919 * but requires additional policies after an upgrade.
920 *
921 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be
922 * an active administrator, or an exception will be thrown.
923 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
924 */
Robin Lee25e26452015-06-02 09:56:29 -0700925 public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) {
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800926 if (mService != null) {
927 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700928 return mService.hasGrantedPolicy(admin, usesPolicy, UserHandle.myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800929 } catch (RemoteException e) {
930 Log.w(TAG, "Failed talking with device policy service", e);
931 }
932 }
933 return false;
934 }
935
936 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800937 * Constant for {@link #setPasswordQuality}: the policy has no requirements
938 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800939 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800940 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800941 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700942
Dianne Hackbornd6847842010-01-12 18:14:19 -0800943 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700944 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
945 * recognition technology. This implies technologies that can recognize the identity of
946 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
947 * Note that quality constants are ordered so that higher values are more restrictive.
948 */
949 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
950
951 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800952 * Constant for {@link #setPasswordQuality}: the policy requires some kind
Benjamin Franzc6a96532015-06-16 11:23:38 +0100953 * of password or pattern, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800954 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800955 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800956 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700957
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800958 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800959 * Constant for {@link #setPasswordQuality}: the user must have entered a
960 * password containing at least numeric characters. Note that quality
961 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800962 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800963 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700964
Dianne Hackbornd6847842010-01-12 18:14:19 -0800965 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800966 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -0800967 * password containing at least numeric characters with no repeating (4444)
968 * or ordered (1234, 4321, 2468) sequences. Note that quality
969 * constants are ordered so that higher values are more restrictive.
970 */
971 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
972
973 /**
974 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700975 * password containing at least alphabetic (or other symbol) characters.
976 * Note that quality constants are ordered so that higher values are more
977 * restrictive.
978 */
979 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700980
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700981 /**
982 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800983 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700984 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800985 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800986 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700987 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700988
Dianne Hackbornd6847842010-01-12 18:14:19 -0800989 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700990 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700991 * password containing at least a letter, a numerical digit and a special
992 * symbol, by default. With this password quality, passwords can be
993 * restricted to contain various sets of characters, like at least an
994 * uppercase letter, etc. These are specified using various methods,
995 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
996 * that quality constants are ordered so that higher values are more
997 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700998 */
999 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
1000
1001 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001002 * Called by an application that is administering the device to set the
1003 * password restrictions it is imposing. After setting this, the user
1004 * will not be able to enter a new password that is not at least as
1005 * restrictive as what has been set. Note that the current password
1006 * will remain until the user has set a new one, so the change does not
1007 * take place immediately. To prompt the user for a new password, use
1008 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001009 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001010 * <p>Quality constants are ordered so that higher values are more restrictive;
1011 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001012 * the user's preference, and any other considerations) is the one that
1013 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001014 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001015 * <p>The calling device admin must have requested
1016 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1017 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001018 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001019 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001020 * @param quality The new desired quality. One of
1021 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Jim Miller85516d02014-01-31 17:08:37 -08001022 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
1023 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1024 * or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001025 */
Robin Lee25e26452015-06-02 09:56:29 -07001026 public void setPasswordQuality(@NonNull ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001027 if (mService != null) {
1028 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001029 mService.setPasswordQuality(admin, quality);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001030 } catch (RemoteException e) {
1031 Log.w(TAG, "Failed talking with device policy service", e);
1032 }
1033 }
1034 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001035
Dianne Hackbornd6847842010-01-12 18:14:19 -08001036 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001037 * Retrieve the current minimum password quality for all admins of this user
1038 * and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001039 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001040 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001041 */
Robin Lee25e26452015-06-02 09:56:29 -07001042 public int getPasswordQuality(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001043 return getPasswordQuality(admin, UserHandle.myUserId());
1044 }
1045
1046 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001047 public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001048 if (mService != null) {
1049 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001050 return mService.getPasswordQuality(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001051 } catch (RemoteException e) {
1052 Log.w(TAG, "Failed talking with device policy service", e);
1053 }
1054 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001055 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001056 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001057
Dianne Hackbornd6847842010-01-12 18:14:19 -08001058 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001059 * Called by an application that is administering the device to set the
1060 * minimum allowed password length. After setting this, the user
1061 * will not be able to enter a new password that is not at least as
1062 * restrictive as what has been set. Note that the current password
1063 * will remain until the user has set a new one, so the change does not
1064 * take place immediately. To prompt the user for a new password, use
1065 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1066 * constraint is only imposed if the administrator has also requested either
Jim Miller85516d02014-01-31 17:08:37 -08001067 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
1068 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC},
1069 * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001070 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001071 * <p>The calling device admin must have requested
1072 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1073 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001074 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001075 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001076 * @param length The new desired minimum password length. A value of 0
1077 * means there is no restriction.
1078 */
Robin Lee25e26452015-06-02 09:56:29 -07001079 public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001080 if (mService != null) {
1081 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001082 mService.setPasswordMinimumLength(admin, length);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001083 } catch (RemoteException e) {
1084 Log.w(TAG, "Failed talking with device policy service", e);
1085 }
1086 }
1087 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001088
Dianne Hackbornd6847842010-01-12 18:14:19 -08001089 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001090 * Retrieve the current minimum password length for all admins of this
1091 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001092 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001093 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001094 */
Robin Lee25e26452015-06-02 09:56:29 -07001095 public int getPasswordMinimumLength(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001096 return getPasswordMinimumLength(admin, UserHandle.myUserId());
1097 }
1098
1099 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001100 public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001101 if (mService != null) {
1102 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001103 return mService.getPasswordMinimumLength(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001104 } catch (RemoteException e) {
1105 Log.w(TAG, "Failed talking with device policy service", e);
1106 }
1107 }
1108 return 0;
1109 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001110
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001111 /**
1112 * Called by an application that is administering the device to set the
1113 * minimum number of upper case letters required in the password. After
1114 * setting this, the user will not be able to enter a new password that is
1115 * not at least as restrictive as what has been set. Note that the current
1116 * password will remain until the user has set a new one, so the change does
1117 * not take place immediately. To prompt the user for a new password, use
1118 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1119 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001120 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1121 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001122 * <p>
1123 * The calling device admin must have requested
1124 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1125 * this method; if it has not, a security exception will be thrown.
1126 *
1127 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1128 * with.
1129 * @param length The new desired minimum number of upper case letters
1130 * required in the password. A value of 0 means there is no
1131 * restriction.
1132 */
Robin Lee25e26452015-06-02 09:56:29 -07001133 public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001134 if (mService != null) {
1135 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001136 mService.setPasswordMinimumUpperCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001137 } catch (RemoteException e) {
1138 Log.w(TAG, "Failed talking with device policy service", e);
1139 }
1140 }
1141 }
1142
1143 /**
1144 * Retrieve the current number of upper case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001145 * password for all admins of this user and its profiles or a particular one.
1146 * This is the same value as set by
1147 * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001148 * and only applies when the password quality is
1149 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001150 *
Robin Lee25e26452015-06-02 09:56:29 -07001151 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001152 * aggregate all admins.
1153 * @return The minimum number of upper case letters required in the
1154 * password.
1155 */
Robin Lee25e26452015-06-02 09:56:29 -07001156 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001157 return getPasswordMinimumUpperCase(admin, UserHandle.myUserId());
1158 }
1159
1160 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001161 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001162 if (mService != null) {
1163 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001164 return mService.getPasswordMinimumUpperCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001165 } catch (RemoteException e) {
1166 Log.w(TAG, "Failed talking with device policy service", e);
1167 }
1168 }
1169 return 0;
1170 }
1171
1172 /**
1173 * Called by an application that is administering the device to set the
1174 * minimum number of lower case letters required in the password. After
1175 * setting this, the user will not be able to enter a new password that is
1176 * not at least as restrictive as what has been set. Note that the current
1177 * password will remain until the user has set a new one, so the change does
1178 * not take place immediately. To prompt the user for a new password, use
1179 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1180 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001181 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1182 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001183 * <p>
1184 * The calling device admin must have requested
1185 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1186 * this method; if it has not, a security exception will be thrown.
1187 *
1188 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1189 * with.
1190 * @param length The new desired minimum number of lower case letters
1191 * required in the password. A value of 0 means there is no
1192 * restriction.
1193 */
Robin Lee25e26452015-06-02 09:56:29 -07001194 public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001195 if (mService != null) {
1196 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001197 mService.setPasswordMinimumLowerCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001198 } catch (RemoteException e) {
1199 Log.w(TAG, "Failed talking with device policy service", e);
1200 }
1201 }
1202 }
1203
1204 /**
1205 * Retrieve the current number of lower case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001206 * password for all admins of this user and its profiles or a particular one.
1207 * This is the same value as set by
1208 * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001209 * and only applies when the password quality is
1210 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001211 *
Robin Lee25e26452015-06-02 09:56:29 -07001212 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001213 * aggregate all admins.
1214 * @return The minimum number of lower case letters required in the
1215 * password.
1216 */
Robin Lee25e26452015-06-02 09:56:29 -07001217 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001218 return getPasswordMinimumLowerCase(admin, UserHandle.myUserId());
1219 }
1220
1221 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001222 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001223 if (mService != null) {
1224 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001225 return mService.getPasswordMinimumLowerCase(admin, userHandle);
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 return 0;
1231 }
1232
1233 /**
1234 * Called by an application that is administering the device to set the
1235 * minimum number of letters required in the password. After setting this,
1236 * the user will not be able to enter a new password that is not at least as
1237 * restrictive as what has been set. Note that the current password will
1238 * remain until the user has set a new one, so the change does not take
1239 * place immediately. To prompt the user for a new password, use
1240 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1241 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001242 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1243 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001244 * <p>
1245 * The calling device admin must have requested
1246 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1247 * this method; if it has not, a security exception will be thrown.
1248 *
1249 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1250 * with.
1251 * @param length The new desired minimum number of letters required in the
1252 * password. A value of 0 means there is no restriction.
1253 */
Robin Lee25e26452015-06-02 09:56:29 -07001254 public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001255 if (mService != null) {
1256 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001257 mService.setPasswordMinimumLetters(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001258 } catch (RemoteException e) {
1259 Log.w(TAG, "Failed talking with device policy service", e);
1260 }
1261 }
1262 }
1263
1264 /**
1265 * Retrieve the current number of letters required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001266 * admins or a particular one. This is the same value as
1267 * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)}
1268 * and only applies when the password quality is
1269 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001270 *
Robin Lee25e26452015-06-02 09:56:29 -07001271 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001272 * aggregate all admins.
1273 * @return The minimum number of letters required in the password.
1274 */
Robin Lee25e26452015-06-02 09:56:29 -07001275 public int getPasswordMinimumLetters(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001276 return getPasswordMinimumLetters(admin, UserHandle.myUserId());
1277 }
1278
1279 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001280 public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001281 if (mService != null) {
1282 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001283 return mService.getPasswordMinimumLetters(admin, userHandle);
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 return 0;
1289 }
1290
1291 /**
1292 * Called by an application that is administering the device to set the
1293 * minimum number of numerical digits required in the password. After
1294 * setting this, the user will not be able to enter a new password that is
1295 * not at least as restrictive as what has been set. Note that the current
1296 * password will remain until the user has set a new one, so the change does
1297 * not take place immediately. To prompt the user for a new password, use
1298 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1299 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001300 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1301 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001302 * <p>
1303 * The calling device admin must have requested
1304 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1305 * this method; if it has not, a security exception will be thrown.
1306 *
1307 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1308 * with.
1309 * @param length The new desired minimum number of numerical digits required
1310 * in the password. A value of 0 means there is no restriction.
1311 */
Robin Lee25e26452015-06-02 09:56:29 -07001312 public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001313 if (mService != null) {
1314 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001315 mService.setPasswordMinimumNumeric(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001316 } catch (RemoteException e) {
1317 Log.w(TAG, "Failed talking with device policy service", e);
1318 }
1319 }
1320 }
1321
1322 /**
1323 * Retrieve the current number of numerical digits required in the password
Jessica Hummel91da58d2014-04-10 17:39:43 +01001324 * for all admins of this user and its profiles or a particular one.
1325 * This is the same value as set by
1326 * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001327 * and only applies when the password quality is
1328 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001329 *
Robin Lee25e26452015-06-02 09:56:29 -07001330 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001331 * aggregate all admins.
1332 * @return The minimum number of numerical digits required in the password.
1333 */
Robin Lee25e26452015-06-02 09:56:29 -07001334 public int getPasswordMinimumNumeric(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001335 return getPasswordMinimumNumeric(admin, UserHandle.myUserId());
1336 }
1337
1338 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001339 public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001340 if (mService != null) {
1341 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001342 return mService.getPasswordMinimumNumeric(admin, userHandle);
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 return 0;
1348 }
1349
1350 /**
1351 * Called by an application that is administering the device to set the
1352 * minimum number of symbols required in the password. After setting this,
1353 * the user will not be able to enter a new password that is not at least as
1354 * restrictive as what has been set. Note that the current password will
1355 * remain until the user has set a new one, so the change does not take
1356 * place immediately. To prompt the user for a new password, use
1357 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1358 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001359 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1360 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001361 * <p>
1362 * The calling device admin must have requested
1363 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1364 * this method; if it has not, a security exception will be thrown.
1365 *
1366 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1367 * with.
1368 * @param length The new desired minimum number of symbols required in the
1369 * password. A value of 0 means there is no restriction.
1370 */
Robin Lee25e26452015-06-02 09:56:29 -07001371 public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001372 if (mService != null) {
1373 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001374 mService.setPasswordMinimumSymbols(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001375 } catch (RemoteException e) {
1376 Log.w(TAG, "Failed talking with device policy service", e);
1377 }
1378 }
1379 }
1380
1381 /**
1382 * Retrieve the current number of symbols required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001383 * admins or a particular one. This is the same value as
1384 * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)}
1385 * and only applies when the password quality is
1386 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001387 *
Robin Lee25e26452015-06-02 09:56:29 -07001388 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001389 * aggregate all admins.
1390 * @return The minimum number of symbols required in the password.
1391 */
Robin Lee25e26452015-06-02 09:56:29 -07001392 public int getPasswordMinimumSymbols(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001393 return getPasswordMinimumSymbols(admin, UserHandle.myUserId());
1394 }
1395
1396 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001397 public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001398 if (mService != null) {
1399 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001400 return mService.getPasswordMinimumSymbols(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001401 } catch (RemoteException e) {
1402 Log.w(TAG, "Failed talking with device policy service", e);
1403 }
1404 }
1405 return 0;
1406 }
1407
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001408 /**
1409 * Called by an application that is administering the device to set the
1410 * minimum number of non-letter characters (numerical digits or symbols)
1411 * required in the password. After setting this, the user will not be able
1412 * to enter a new password that is not at least as restrictive as what has
1413 * been set. Note that the current password will remain until the user has
1414 * set a new one, so the change does not take place immediately. To prompt
1415 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after
1416 * setting this value. This constraint is only imposed if the administrator
1417 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1418 * {@link #setPasswordQuality}. The default value is 0.
1419 * <p>
1420 * The calling device admin must have requested
1421 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1422 * this method; if it has not, a security exception will be thrown.
1423 *
1424 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1425 * with.
1426 * @param length The new desired minimum number of letters required in the
1427 * password. A value of 0 means there is no restriction.
1428 */
Robin Lee25e26452015-06-02 09:56:29 -07001429 public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001430 if (mService != null) {
1431 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001432 mService.setPasswordMinimumNonLetter(admin, length);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001433 } catch (RemoteException e) {
1434 Log.w(TAG, "Failed talking with device policy service", e);
1435 }
1436 }
1437 }
1438
1439 /**
1440 * Retrieve the current number of non-letter characters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001441 * password for all admins of this user and its profiles or a particular one.
1442 * This is the same value as set by
1443 * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001444 * and only applies when the password quality is
1445 * {@link #PASSWORD_QUALITY_COMPLEX}.
1446 *
Robin Lee25e26452015-06-02 09:56:29 -07001447 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001448 * aggregate all admins.
1449 * @return The minimum number of letters required in the password.
1450 */
Robin Lee25e26452015-06-02 09:56:29 -07001451 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001452 return getPasswordMinimumNonLetter(admin, UserHandle.myUserId());
1453 }
1454
1455 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001456 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001457 if (mService != null) {
1458 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001459 return mService.getPasswordMinimumNonLetter(admin, userHandle);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001460 } catch (RemoteException e) {
1461 Log.w(TAG, "Failed talking with device policy service", e);
1462 }
1463 }
1464 return 0;
1465 }
1466
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001467 /**
1468 * Called by an application that is administering the device to set the length
1469 * of the password history. After setting this, the user will not be able to
1470 * enter a new password that is the same as any password in the history. Note
1471 * that the current password will remain until the user has set a new one, so
1472 * the change does not take place immediately. To prompt the user for a new
1473 * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
1474 * This constraint is only imposed if the administrator has also requested
Jim Miller85516d02014-01-31 17:08:37 -08001475 * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}
1476 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1477 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001478 *
1479 * <p>
1480 * The calling device admin must have requested
1481 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
1482 * method; if it has not, a security exception will be thrown.
1483 *
1484 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1485 * with.
1486 * @param length The new desired length of password history. A value of 0
1487 * means there is no restriction.
1488 */
Robin Lee25e26452015-06-02 09:56:29 -07001489 public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001490 if (mService != null) {
1491 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001492 mService.setPasswordHistoryLength(admin, length);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001493 } catch (RemoteException e) {
1494 Log.w(TAG, "Failed talking with device policy service", e);
1495 }
1496 }
1497 }
1498
1499 /**
Jim Millera4e28d12010-11-08 16:15:47 -08001500 * Called by a device admin to set the password expiration timeout. Calling this method
1501 * will restart the countdown for password expiration for the given admin, as will changing
1502 * the device password (for all admins).
1503 *
1504 * <p>The provided timeout is the time delta in ms and will be added to the current time.
1505 * For example, to have the password expire 5 days from now, timeout would be
1506 * 5 * 86400 * 1000 = 432000000 ms for timeout.
1507 *
1508 * <p>To disable password expiration, a value of 0 may be used for timeout.
1509 *
Jim Millera4e28d12010-11-08 16:15:47 -08001510 * <p>The calling device admin must have requested
1511 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
1512 * method; if it has not, a security exception will be thrown.
1513 *
Jessica Hummel9da60392014-05-21 12:32:57 +01001514 * <p> Note that setting the password will automatically reset the expiration time for all
1515 * active admins. Active admins do not need to explicitly call this method in that case.
1516 *
Jim Millera4e28d12010-11-08 16:15:47 -08001517 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1518 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
1519 * means there is no restriction (unlimited).
1520 */
Robin Lee25e26452015-06-02 09:56:29 -07001521 public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) {
Jim Millera4e28d12010-11-08 16:15:47 -08001522 if (mService != null) {
1523 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001524 mService.setPasswordExpirationTimeout(admin, timeout);
Jim Millera4e28d12010-11-08 16:15:47 -08001525 } catch (RemoteException e) {
1526 Log.w(TAG, "Failed talking with device policy service", e);
1527 }
1528 }
1529 }
1530
1531 /**
Jim Miller6b857682011-02-16 16:27:41 -08001532 * Get the password expiration timeout for the given admin. The expiration timeout is the
1533 * recurring expiration timeout provided in the call to
1534 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
Robin Lee25e26452015-06-02 09:56:29 -07001535 * aggregate of all policy administrators if {@code admin} is null.
Jim Millera4e28d12010-11-08 16:15:47 -08001536 *
Robin Lee25e26452015-06-02 09:56:29 -07001537 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001538 * @return The timeout for the given admin or the minimum of all timeouts
1539 */
Robin Lee25e26452015-06-02 09:56:29 -07001540 public long getPasswordExpirationTimeout(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001541 if (mService != null) {
1542 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001543 return mService.getPasswordExpirationTimeout(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001544 } catch (RemoteException e) {
1545 Log.w(TAG, "Failed talking with device policy service", e);
1546 }
1547 }
1548 return 0;
1549 }
1550
1551 /**
1552 * Get the current password expiration time for the given admin or an aggregate of
Jessica Hummel91da58d2014-04-10 17:39:43 +01001553 * all admins of this user and its profiles if admin is null. If the password is
1554 * expired, this will return the time since the password expired as a negative number.
1555 * If admin is null, then a composite of all expiration timeouts is returned
1556 * - which will be the minimum of all timeouts.
Jim Millera4e28d12010-11-08 16:15:47 -08001557 *
Robin Lee25e26452015-06-02 09:56:29 -07001558 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001559 * @return The password expiration time, in ms.
1560 */
Robin Lee25e26452015-06-02 09:56:29 -07001561 public long getPasswordExpiration(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001562 if (mService != null) {
1563 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001564 return mService.getPasswordExpiration(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001565 } catch (RemoteException e) {
1566 Log.w(TAG, "Failed talking with device policy service", e);
1567 }
1568 }
1569 return 0;
1570 }
1571
1572 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001573 * Retrieve the current password history length for all admins of this
1574 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001575 * @param admin The name of the admin component to check, or {@code null} to aggregate
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001576 * all admins.
1577 * @return The length of the password history
1578 */
Robin Lee25e26452015-06-02 09:56:29 -07001579 public int getPasswordHistoryLength(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001580 return getPasswordHistoryLength(admin, UserHandle.myUserId());
1581 }
1582
1583 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001584 public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001585 if (mService != null) {
1586 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001587 return mService.getPasswordHistoryLength(admin, userHandle);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001588 } catch (RemoteException e) {
1589 Log.w(TAG, "Failed talking with device policy service", e);
1590 }
1591 }
1592 return 0;
1593 }
1594
Dianne Hackbornd6847842010-01-12 18:14:19 -08001595 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001596 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001597 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08001598 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001599 * @return Returns the maximum length that the user can enter.
1600 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001601 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001602 // Kind-of arbitrary.
1603 return 16;
1604 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001605
Dianne Hackborn254cb442010-01-27 19:23:59 -08001606 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001607 * Determine whether the current password the user has set is sufficient
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001608 * to meet the policy requirements (quality, minimum length) that have been
Jessica Hummel91da58d2014-04-10 17:39:43 +01001609 * requested by the admins of this user and its profiles.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001610 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001611 * <p>The calling device admin must have requested
1612 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1613 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001614 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001615 * @return Returns true if the password meets the current requirements, else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001616 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001617 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001618 if (mService != null) {
1619 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001620 return mService.isActivePasswordSufficient(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001621 } catch (RemoteException e) {
1622 Log.w(TAG, "Failed talking with device policy service", e);
1623 }
1624 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001625 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001626 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001627
Dianne Hackbornd6847842010-01-12 18:14:19 -08001628 /**
1629 * Retrieve the number of times the user has failed at entering a
1630 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001631 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001632 * <p>The calling device admin must have requested
1633 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
1634 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001635 */
1636 public int getCurrentFailedPasswordAttempts() {
1637 if (mService != null) {
1638 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001639 return mService.getCurrentFailedPasswordAttempts(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001640 } catch (RemoteException e) {
1641 Log.w(TAG, "Failed talking with device policy service", e);
1642 }
1643 }
1644 return -1;
1645 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001646
1647 /**
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001648 * Queries whether {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001649 *
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001650 * @return true if RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001651 * @hide
1652 */
1653 public boolean getDoNotAskCredentialsOnBoot() {
1654 if (mService != null) {
1655 try {
1656 return mService.getDoNotAskCredentialsOnBoot();
1657 } catch (RemoteException e) {
1658 Log.w(TAG, "Failed to call getDoNotAskCredentialsOnBoot()", e);
1659 }
1660 }
1661 return false;
1662 }
1663
1664 /**
Andrew Stadler88209d12010-02-08 22:59:36 -08001665 * Setting this to a value greater than zero enables a built-in policy
1666 * that will perform a device wipe after too many incorrect
1667 * device-unlock passwords have been entered. This built-in policy combines
1668 * watching for failed passwords and wiping the device, and requires
1669 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001670 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001671 *
Andrew Stadler88209d12010-02-08 22:59:36 -08001672 * <p>To implement any other policy (e.g. wiping data for a particular
1673 * application only, erasing or revoking credentials, or reporting the
1674 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001675 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -08001676 * instead. Do not use this API, because if the maximum count is reached,
1677 * the device will be wiped immediately, and your callback will not be invoked.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001678 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001679 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001680 * @param num The number of failed password attempts at which point the
1681 * device will wipe its data.
1682 */
Robin Lee25e26452015-06-02 09:56:29 -07001683 public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001684 if (mService != null) {
1685 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001686 mService.setMaximumFailedPasswordsForWipe(admin, num);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001687 } catch (RemoteException e) {
1688 Log.w(TAG, "Failed talking with device policy service", e);
1689 }
1690 }
1691 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001692
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001693 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001694 * Retrieve the current maximum number of login attempts that are allowed
Jessica Hummel91da58d2014-04-10 17:39:43 +01001695 * before the device wipes itself, for all admins of this user and its profiles
Dianne Hackborn254cb442010-01-27 19:23:59 -08001696 * or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001697 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001698 * all admins.
1699 */
Robin Lee25e26452015-06-02 09:56:29 -07001700 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001701 return getMaximumFailedPasswordsForWipe(admin, UserHandle.myUserId());
1702 }
1703
1704 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001705 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001706 if (mService != null) {
1707 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001708 return mService.getMaximumFailedPasswordsForWipe(admin, userHandle);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001709 } catch (RemoteException e) {
1710 Log.w(TAG, "Failed talking with device policy service", e);
1711 }
1712 }
1713 return 0;
1714 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001715
Dianne Hackborn254cb442010-01-27 19:23:59 -08001716 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07001717 * Returns the profile with the smallest maximum failed passwords for wipe,
1718 * for the given user. So for primary user, it might return the primary or
1719 * a managed profile. For a secondary user, it would be the same as the
1720 * user passed in.
1721 * @hide Used only by Keyguard
1722 */
1723 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
1724 if (mService != null) {
1725 try {
1726 return mService.getProfileWithMinimumFailedPasswordsForWipe(userHandle);
1727 } catch (RemoteException e) {
1728 Log.w(TAG, "Failed talking with device policy service", e);
1729 }
1730 }
1731 return UserHandle.USER_NULL;
1732 }
1733
1734 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001735 * Flag for {@link #resetPassword}: don't allow other admins to change
1736 * the password again until the user has entered it.
1737 */
1738 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001739
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001740 /**
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001741 * Flag for {@link #resetPassword}: don't ask for user credentials on device boot.
1742 * If the flag is set, the device can be booted without asking for user password.
1743 * The absence of this flag does not change the current boot requirements. This flag
1744 * can be set by the device owner only. If the app is not the device owner, the flag
1745 * is ignored. Once the flag is set, it cannot be reverted back without resetting the
1746 * device to factory defaults.
1747 */
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001748 public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002;
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001749
1750 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001751 * Force a new device unlock password (the password needed to access the
1752 * entire device, not for individual accounts) on the user. This takes
1753 * effect immediately.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001754 * The given password must be sufficient for the
1755 * current password quality and length constraints as returned by
1756 * {@link #getPasswordQuality(ComponentName)} and
1757 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
1758 * these constraints, then it will be rejected and false returned. Note
1759 * that the password may be a stronger quality (containing alphanumeric
1760 * characters when the requested quality is only numeric), in which case
1761 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001762 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001763 * <p>Calling with a null or empty password will clear any existing PIN,
1764 * pattern or password if the current password constraints allow it.
1765 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001766 * <p>The calling device admin must have requested
1767 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
1768 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001769 *
Amith Yamasani242f4b12014-10-14 16:06:13 -07001770 * <p>Calling this from a managed profile will throw a security exception.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001771 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001772 * @param password The new password for the user. Null or empty clears the password.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001773 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001774 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001775 * @return Returns true if the password was applied, or false if it is
1776 * not acceptable for the current constraints.
1777 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001778 public boolean resetPassword(String password, int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001779 if (mService != null) {
1780 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001781 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001782 } catch (RemoteException e) {
1783 Log.w(TAG, "Failed talking with device policy service", e);
1784 }
1785 }
1786 return false;
1787 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001788
Dianne Hackbornd6847842010-01-12 18:14:19 -08001789 /**
1790 * Called by an application that is administering the device to set the
1791 * maximum time for user activity until the device will lock. This limits
1792 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001793 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001794 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -08001795 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001796 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001797 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001798 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001799 * @param timeMs The new desired maximum time to lock in milliseconds.
1800 * A value of 0 means there is no restriction.
1801 */
Robin Lee25e26452015-06-02 09:56:29 -07001802 public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001803 if (mService != null) {
1804 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001805 mService.setMaximumTimeToLock(admin, timeMs);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001806 } catch (RemoteException e) {
1807 Log.w(TAG, "Failed talking with device policy service", e);
1808 }
1809 }
1810 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001811
Dianne Hackbornd6847842010-01-12 18:14:19 -08001812 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001813 * Retrieve the current maximum time to unlock for all admins of this user
1814 * and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001815 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001816 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07001817 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07001818 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001819 */
Robin Lee25e26452015-06-02 09:56:29 -07001820 public long getMaximumTimeToLock(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001821 return getMaximumTimeToLock(admin, UserHandle.myUserId());
1822 }
1823
1824 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001825 public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001826 if (mService != null) {
1827 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001828 return mService.getMaximumTimeToLock(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001829 } catch (RemoteException e) {
1830 Log.w(TAG, "Failed talking with device policy service", e);
1831 }
1832 }
1833 return 0;
1834 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001835
Dianne Hackbornd6847842010-01-12 18:14:19 -08001836 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001837 * Make the device lock immediately, as if the lock screen timeout has
1838 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001839 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001840 * <p>The calling device admin must have requested
1841 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
1842 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001843 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001844 public void lockNow() {
1845 if (mService != null) {
1846 try {
1847 mService.lockNow();
1848 } catch (RemoteException e) {
1849 Log.w(TAG, "Failed talking with device policy service", e);
1850 }
1851 }
1852 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001853
Dianne Hackbornd6847842010-01-12 18:14:19 -08001854 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07001855 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001856 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07001857 */
1858 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
1859
1860 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001861 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
1862 * data.
1863 *
Paul Crowley2934b262014-12-02 11:21:13 +00001864 * <p>This flag may only be set by device owner admins; if it is set by
1865 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001866 */
1867 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
1868
1869 /**
Robin Lee85bd63f2015-02-10 11:51:00 +00001870 * Ask the user data be wiped. Wiping the primary user will cause the
1871 * device to reboot, erasing all user data while next booting up.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001872 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001873 * <p>The calling device admin must have requested
1874 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
1875 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001876 *
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001877 * @param flags Bit mask of additional options: currently supported flags
1878 * are {@link #WIPE_EXTERNAL_STORAGE} and
1879 * {@link #WIPE_RESET_PROTECTION_DATA}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001880 */
1881 public void wipeData(int flags) {
1882 if (mService != null) {
1883 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001884 mService.wipeData(flags, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001885 } catch (RemoteException e) {
1886 Log.w(TAG, "Failed talking with device policy service", e);
1887 }
1888 }
1889 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001890
Dianne Hackbornd6847842010-01-12 18:14:19 -08001891 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001892 * Called by an application that is administering the device to set the
1893 * global proxy and exclusion list.
1894 * <p>
1895 * The calling device admin must have requested
1896 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
1897 * this method; if it has not, a security exception will be thrown.
1898 * Only the first device admin can set the proxy. If a second admin attempts
1899 * to set the proxy, the {@link ComponentName} of the admin originally setting the
Robin Lee25e26452015-06-02 09:56:29 -07001900 * proxy will be returned. If successful in setting the proxy, {@code null} will
Oscar Montemayor69238c62010-08-03 10:51:06 -07001901 * be returned.
1902 * The method can be called repeatedly by the device admin alrady setting the
1903 * proxy to update the proxy and exclusion list.
1904 *
Robin Lee25e26452015-06-02 09:56:29 -07001905 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Oscar Montemayor69238c62010-08-03 10:51:06 -07001906 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
1907 * Pass Proxy.NO_PROXY to reset the proxy.
1908 * @param exclusionList a list of domains to be excluded from the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07001909 * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName}
1910 * of the device admin that sets the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08001911 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001912 */
Robin Lee25e26452015-06-02 09:56:29 -07001913 public ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec,
Oscar Montemayor69238c62010-08-03 10:51:06 -07001914 List<String> exclusionList ) {
1915 if (proxySpec == null) {
1916 throw new NullPointerException();
1917 }
1918 if (mService != null) {
1919 try {
1920 String hostSpec;
1921 String exclSpec;
1922 if (proxySpec.equals(Proxy.NO_PROXY)) {
1923 hostSpec = null;
1924 exclSpec = null;
1925 } else {
1926 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
1927 throw new IllegalArgumentException();
1928 }
1929 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
1930 String hostName = sa.getHostName();
1931 int port = sa.getPort();
1932 StringBuilder hostBuilder = new StringBuilder();
1933 hostSpec = hostBuilder.append(hostName)
1934 .append(":").append(Integer.toString(port)).toString();
1935 if (exclusionList == null) {
1936 exclSpec = "";
1937 } else {
1938 StringBuilder listBuilder = new StringBuilder();
1939 boolean firstDomain = true;
1940 for (String exclDomain : exclusionList) {
1941 if (!firstDomain) {
1942 listBuilder = listBuilder.append(",");
1943 } else {
1944 firstDomain = false;
1945 }
1946 listBuilder = listBuilder.append(exclDomain.trim());
1947 }
1948 exclSpec = listBuilder.toString();
1949 }
Yuhao Zheng90704842014-02-28 17:22:45 -08001950 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
1951 != android.net.Proxy.PROXY_VALID)
1952 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07001953 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001954 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07001955 } catch (RemoteException e) {
1956 Log.w(TAG, "Failed talking with device policy service", e);
1957 }
1958 }
1959 return null;
1960 }
1961
1962 /**
Jason Monk03bc9912014-05-13 09:44:57 -04001963 * Set a network-independent global HTTP proxy. This is not normally what you want
1964 * for typical HTTP proxies - they are generally network dependent. However if you're
1965 * doing something unusual like general internal filtering this may be useful. On
1966 * a private network where the proxy is not accessible, you may break HTTP using this.
1967 *
1968 * <p>This method requires the caller to be the device owner.
1969 *
1970 * <p>This proxy is only a recommendation and it is possible that some apps will ignore it.
1971 * @see ProxyInfo
1972 *
1973 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1974 * with.
1975 * @param proxyInfo The a {@link ProxyInfo} object defining the new global
1976 * HTTP proxy. A {@code null} value will clear the global HTTP proxy.
1977 */
Robin Lee25e26452015-06-02 09:56:29 -07001978 public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo
1979 proxyInfo) {
Jason Monk03bc9912014-05-13 09:44:57 -04001980 if (mService != null) {
1981 try {
1982 mService.setRecommendedGlobalProxy(admin, proxyInfo);
1983 } catch (RemoteException e) {
1984 Log.w(TAG, "Failed talking with device policy service", e);
1985 }
1986 }
1987 }
1988
1989 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001990 * Returns the component name setting the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07001991 * @return ComponentName object of the device admin that set the global proxy, or {@code null}
1992 * if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08001993 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001994 */
1995 public ComponentName getGlobalProxyAdmin() {
1996 if (mService != null) {
1997 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001998 return mService.getGlobalProxyAdmin(UserHandle.myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07001999 } catch (RemoteException e) {
2000 Log.w(TAG, "Failed talking with device policy service", e);
2001 }
2002 }
2003 return null;
2004 }
2005
2006 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002007 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002008 * indicating that encryption is not supported.
2009 */
2010 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
2011
2012 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002013 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002014 * indicating that encryption is supported, but is not currently active.
2015 */
2016 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
2017
2018 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002019 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002020 * indicating that encryption is not currently active, but is currently
2021 * being activated. This is only reported by devices that support
2022 * encryption of data and only when the storage is currently
2023 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
2024 * to become encrypted will never return this value.
2025 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002026 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002027
2028 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002029 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002030 * indicating that encryption is active.
2031 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002032 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002033
2034 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002035 * Result code for {@link #getStorageEncryptionStatus}:
2036 * indicating that encryption is active, but an encryption key has not
2037 * been set by the user.
2038 */
2039 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
2040
2041 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002042 * Activity action: begin the process of encrypting data on the device. This activity should
2043 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
2044 * After resuming from this activity, use {@link #getStorageEncryption}
2045 * to check encryption status. However, on some devices this activity may never return, as
2046 * it may trigger a reboot and in some cases a complete data wipe of the device.
2047 */
2048 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
2049 public static final String ACTION_START_ENCRYPTION
2050 = "android.app.action.START_ENCRYPTION";
2051
2052 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07002053 * Widgets are enabled in keyguard
2054 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002055 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07002056
2057 /**
Jim Miller50e62182014-04-23 17:25:00 -07002058 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07002059 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002060 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
2061
2062 /**
2063 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
2064 */
2065 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
2066
2067 /**
Jim Miller50e62182014-04-23 17:25:00 -07002068 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2069 */
2070 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
2071
2072 /**
2073 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2074 */
2075 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
2076
2077 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02002078 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07002079 * (e.g. PIN/Pattern/Password).
2080 */
2081 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
2082
2083 /**
Jim Miller06e34502014-07-17 14:46:05 -07002084 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
2085 */
2086 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
2087
2088 /**
Jim Miller35207742012-11-02 15:33:20 -07002089 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07002090 */
2091 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07002092
2093 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002094 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002095 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002096 *
2097 * <p>When multiple device administrators attempt to control device
2098 * encryption, the most secure, supported setting will always be
2099 * used. If any device administrator requests device encryption,
2100 * it will be enabled; Conversely, if a device administrator
2101 * attempts to disable device encryption while another
2102 * device administrator has enabled it, the call to disable will
2103 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
2104 *
2105 * <p>This policy controls encryption of the secure (application data) storage area. Data
Andy Stadler50c294f2011-03-07 19:13:42 -08002106 * written to other storage areas may or may not be encrypted, and this policy does not require
2107 * or control the encryption of any other storage areas.
2108 * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is
2109 * {@code true}, then the directory returned by
2110 * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk
2111 * within the encrypted storage area.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002112 *
2113 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
2114 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
2115 * the encryption key may not be fully secured. For maximum security, the administrator should
2116 * also require (and check for) a pattern, PIN, or password.
2117 *
2118 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2119 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08002120 * @return the new request status (for all active admins) - will be one of
2121 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
2122 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
2123 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002124 */
Robin Lee25e26452015-06-02 09:56:29 -07002125 public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002126 if (mService != null) {
2127 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002128 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002129 } catch (RemoteException e) {
2130 Log.w(TAG, "Failed talking with device policy service", e);
2131 }
2132 }
2133 return ENCRYPTION_STATUS_UNSUPPORTED;
2134 }
2135
2136 /**
2137 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002138 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002139 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08002140 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
2141 * this will return the requested encryption setting as an aggregate of all active
2142 * administrators.
2143 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002144 */
Robin Lee25e26452015-06-02 09:56:29 -07002145 public boolean getStorageEncryption(@Nullable ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002146 if (mService != null) {
2147 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002148 return mService.getStorageEncryption(admin, UserHandle.myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002149 } catch (RemoteException e) {
2150 Log.w(TAG, "Failed talking with device policy service", e);
2151 }
2152 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08002153 return false;
2154 }
2155
2156 /**
2157 * Called by an application that is administering the device to
2158 * determine the current encryption status of the device.
2159 *
2160 * Depending on the returned status code, the caller may proceed in different
2161 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
2162 * storage system does not support encryption. If the
2163 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
2164 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00002165 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
2166 * storage system has enabled encryption but no password is set so further action
2167 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
Andy Stadler22dbfda2011-01-17 12:47:31 -08002168 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
2169 *
Robin Lee7e678712014-07-24 16:41:31 +01002170 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08002171 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00002172 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
2173 * or {@link #ENCRYPTION_STATUS_ACTIVE}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08002174 */
2175 public int getStorageEncryptionStatus() {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002176 return getStorageEncryptionStatus(UserHandle.myUserId());
2177 }
2178
2179 /** @hide per-user version */
2180 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08002181 if (mService != null) {
2182 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002183 return mService.getStorageEncryptionStatus(userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08002184 } catch (RemoteException e) {
2185 Log.w(TAG, "Failed talking with device policy service", e);
2186 }
2187 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002188 return ENCRYPTION_STATUS_UNSUPPORTED;
2189 }
2190
2191 /**
Robin Lee7e678712014-07-24 16:41:31 +01002192 * Installs the given certificate as a user CA.
2193 *
Robin Lee25e26452015-06-02 09:56:29 -07002194 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2195 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002196 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04002197 *
2198 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01002199 * interrupted, true otherwise.
Maggie Benthallda51e682013-08-08 22:35:44 -04002200 */
Robin Lee25e26452015-06-02 09:56:29 -07002201 public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002202 if (mService != null) {
2203 try {
Robin Lee7e678712014-07-24 16:41:31 +01002204 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04002205 } catch (RemoteException e) {
2206 Log.w(TAG, "Failed talking with device policy service", e);
2207 }
2208 }
2209 return false;
2210 }
2211
2212 /**
Robin Lee7e678712014-07-24 16:41:31 +01002213 * Uninstalls the given certificate from trusted user CAs, if present.
2214 *
Robin Lee25e26452015-06-02 09:56:29 -07002215 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2216 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002217 * @param certBuffer encoded form of the certificate to remove.
Maggie Benthallda51e682013-08-08 22:35:44 -04002218 */
Robin Lee25e26452015-06-02 09:56:29 -07002219 public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002220 if (mService != null) {
2221 try {
Robin Lee306fe082014-06-19 14:04:24 +00002222 final String alias = getCaCertAlias(certBuffer);
Robin Lee83881bd2015-06-09 16:04:38 -07002223 mService.uninstallCaCerts(admin, new String[] {alias});
Robin Lee306fe082014-06-19 14:04:24 +00002224 } catch (CertificateException e) {
2225 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002226 } catch (RemoteException e) {
2227 Log.w(TAG, "Failed talking with device policy service", e);
2228 }
2229 }
2230 }
2231
2232 /**
Robin Lee7e678712014-07-24 16:41:31 +01002233 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
2234 * If a user has installed any certificates by other means than device policy these will be
2235 * included too.
2236 *
Robin Lee25e26452015-06-02 09:56:29 -07002237 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2238 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002239 * @return a List of byte[] arrays, each encoding one user CA certificate.
Maggie Benthallda51e682013-08-08 22:35:44 -04002240 */
Robin Lee25e26452015-06-02 09:56:29 -07002241 public List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002242 List<byte[]> certs = new ArrayList<byte[]>();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002243 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01002244 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002245 mService.enforceCanManageCaCerts(admin);
2246 final TrustedCertificateStore certStore = new TrustedCertificateStore();
2247 for (String alias : certStore.userAliases()) {
2248 try {
2249 certs.add(certStore.getCertificate(alias).getEncoded());
2250 } catch (CertificateException ce) {
2251 Log.w(TAG, "Could not encode certificate: " + alias, ce);
2252 }
2253 }
2254 } catch (RemoteException re) {
2255 Log.w(TAG, "Failed talking with device policy service", re);
Robin Lee7e678712014-07-24 16:41:31 +01002256 }
2257 }
2258 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04002259 }
2260
2261 /**
Robin Lee7e678712014-07-24 16:41:31 +01002262 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
2263 * means other than device policy will also be removed, except for system CA certificates.
2264 *
Robin Lee25e26452015-06-02 09:56:29 -07002265 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2266 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002267 */
Robin Lee25e26452015-06-02 09:56:29 -07002268 public void uninstallAllUserCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002269 if (mService != null) {
Robin Lee83881bd2015-06-09 16:04:38 -07002270 try {
2271 mService.uninstallCaCerts(admin, new TrustedCertificateStore().userAliases()
2272 .toArray(new String[0]));
2273 } catch (RemoteException re) {
2274 Log.w(TAG, "Failed talking with device policy service", re);
Robin Lee7e678712014-07-24 16:41:31 +01002275 }
2276 }
2277 }
2278
2279 /**
2280 * Returns whether this certificate is installed as a trusted CA.
2281 *
Robin Lee25e26452015-06-02 09:56:29 -07002282 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2283 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002284 * @param certBuffer encoded form of the certificate to look up.
Maggie Benthallda51e682013-08-08 22:35:44 -04002285 */
Robin Lee25e26452015-06-02 09:56:29 -07002286 public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002287 if (mService != null) {
2288 try {
2289 mService.enforceCanManageCaCerts(admin);
2290 return getCaCertAlias(certBuffer) != null;
2291 } catch (RemoteException re) {
2292 Log.w(TAG, "Failed talking with device policy service", re);
2293 } catch (CertificateException ce) {
2294 Log.w(TAG, "Could not parse certificate", ce);
2295 }
Maggie Benthallda51e682013-08-08 22:35:44 -04002296 }
2297 return false;
2298 }
2299
2300 /**
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002301 * Called by a device or profile owner to install a certificate and private key pair. The
2302 * keypair will be visible to all apps within the profile.
2303 *
Robin Lee25e26452015-06-02 09:56:29 -07002304 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2305 * {@code null} if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002306 * @param privKey The private key to install.
2307 * @param cert The certificate to install.
2308 * @param alias The private key alias under which to install the certificate. If a certificate
2309 * with that alias already exists, it will be overwritten.
2310 * @return {@code true} if the keys were installed, {@code false} otherwise.
2311 */
Robin Lee25e26452015-06-02 09:56:29 -07002312 public boolean installKeyPair(@Nullable ComponentName admin, PrivateKey privKey, Certificate cert,
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002313 String alias) {
2314 try {
2315 final byte[] pemCert = Credentials.convertToPem(cert);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002316 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
2317 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
Robin Lee25e26452015-06-02 09:56:29 -07002318 return mService.installKeyPair(admin, pkcs8Key, pemCert, alias);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002319 } catch (RemoteException e) {
2320 Log.w(TAG, "Failed talking with device policy service", e);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002321 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
2322 Log.w(TAG, "Failed to obtain private key material", e);
2323 } catch (CertificateException | IOException e) {
2324 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002325 }
2326 return false;
2327 }
2328
2329 /**
Robin Lee25e26452015-06-02 09:56:29 -07002330 * @return the alias of a given CA certificate in the certificate store, or {@code null} if it
Robin Lee306fe082014-06-19 14:04:24 +00002331 * doesn't exist.
2332 */
2333 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
2334 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
2335 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
2336 new ByteArrayInputStream(certBuffer));
2337 return new TrustedCertificateStore().getCertificateAlias(cert);
2338 }
2339
2340 /**
Rubin Xuec32b562015-03-03 17:34:05 +00002341 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01002342 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00002343 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01002344 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00002345 * <p>
2346 * Delegated certificate installer is a per-user state. The delegated access is persistent until
2347 * it is later cleared by calling this method with a null value or uninstallling the certificate
2348 * installer.
2349 *
Robin Lee25e26452015-06-02 09:56:29 -07002350 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xuec32b562015-03-03 17:34:05 +00002351 * @param installerPackage The package name of the certificate installer which will be given
Robin Lee25e26452015-06-02 09:56:29 -07002352 * access. If {@code null} is given the current package will be cleared.
Rubin Xuec32b562015-03-03 17:34:05 +00002353 */
Robin Lee25e26452015-06-02 09:56:29 -07002354 public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String
2355 installerPackage) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002356 if (mService != null) {
2357 try {
Robin Lee25e26452015-06-02 09:56:29 -07002358 mService.setCertInstallerPackage(admin, installerPackage);
Rubin Xuec32b562015-03-03 17:34:05 +00002359 } catch (RemoteException e) {
2360 Log.w(TAG, "Failed talking with device policy service", e);
2361 }
2362 }
2363 }
2364
2365 /**
2366 * Called by a profile owner or device owner to retrieve the certificate installer for the
2367 * current user. null if none is set.
2368 *
Robin Lee25e26452015-06-02 09:56:29 -07002369 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2370 * @return The package name of the current delegated certificate installer, or {@code null}
Rubin Xuec32b562015-03-03 17:34:05 +00002371 * if none is set.
2372 */
Robin Lee25e26452015-06-02 09:56:29 -07002373 public String getCertInstallerPackage(@NonNull ComponentName admin) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002374 if (mService != null) {
2375 try {
Robin Lee25e26452015-06-02 09:56:29 -07002376 return mService.getCertInstallerPackage(admin);
Rubin Xuec32b562015-03-03 17:34:05 +00002377 } catch (RemoteException e) {
2378 Log.w(TAG, "Failed talking with device policy service", e);
2379 }
2380 }
2381 return null;
2382 }
2383
2384 /**
Ben Komalo2447edd2011-05-09 16:05:33 -07002385 * Called by an application that is administering the device to disable all cameras
Amith Yamasani242f4b12014-10-14 16:06:13 -07002386 * on the device, for this user. After setting this, no applications running as this user
2387 * will be able to access any cameras on the device.
Ben Komalo2447edd2011-05-09 16:05:33 -07002388 *
2389 * <p>The calling device admin must have requested
2390 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
2391 * this method; if it has not, a security exception will be thrown.
2392 *
2393 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2394 * @param disabled Whether or not the camera should be disabled.
2395 */
Robin Lee25e26452015-06-02 09:56:29 -07002396 public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002397 if (mService != null) {
2398 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002399 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07002400 } catch (RemoteException e) {
2401 Log.w(TAG, "Failed talking with device policy service", e);
2402 }
2403 }
2404 }
2405
2406 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07002407 * Determine whether or not the device's cameras have been disabled for this user,
2408 * either by the current admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002409 * @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 -07002410 * have disabled the camera
2411 */
Robin Lee25e26452015-06-02 09:56:29 -07002412 public boolean getCameraDisabled(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002413 return getCameraDisabled(admin, UserHandle.myUserId());
2414 }
2415
2416 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002417 public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002418 if (mService != null) {
2419 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002420 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07002421 } catch (RemoteException e) {
2422 Log.w(TAG, "Failed talking with device policy service", e);
2423 }
2424 }
2425 return false;
2426 }
2427
2428 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01002429 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
2430 * screen capture also prevents the content from being shown on display devices that do not have
2431 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
2432 * secure surfaces and secure displays.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002433 *
2434 * <p>The calling device admin must be a device or profile owner. If it is not, a
2435 * security exception will be thrown.
2436 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002437 * <p>From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also
Benjamin Franzc200f442015-06-25 18:20:04 +01002438 * blocks assist requests for all activities of the relevant user.
2439 *
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002440 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002441 * @param disabled Whether screen capture is disabled or not.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002442 */
Robin Lee25e26452015-06-02 09:56:29 -07002443 public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002444 if (mService != null) {
2445 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002446 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002447 } catch (RemoteException e) {
2448 Log.w(TAG, "Failed talking with device policy service", e);
2449 }
2450 }
2451 }
2452
2453 /**
2454 * Determine whether or not screen capture has been disabled by the current
2455 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002456 * @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 +01002457 * have disabled screen capture.
2458 */
Robin Lee25e26452015-06-02 09:56:29 -07002459 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002460 return getScreenCaptureDisabled(admin, UserHandle.myUserId());
2461 }
2462
2463 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002464 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002465 if (mService != null) {
2466 try {
2467 return mService.getScreenCaptureDisabled(admin, userHandle);
2468 } catch (RemoteException e) {
2469 Log.w(TAG, "Failed talking with device policy service", e);
2470 }
2471 }
2472 return false;
2473 }
2474
2475 /**
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002476 * Called by a device owner to set whether auto time is required. If auto time is
2477 * required the user cannot set the date and time, but has to use network date and time.
2478 *
2479 * <p>Note: if auto time is required the user can still manually set the time zone.
2480 *
2481 * <p>The calling device admin must be a device owner. If it is not, a security exception will
2482 * be thrown.
2483 *
2484 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2485 * @param required Whether auto time is set required or not.
2486 */
Robin Lee25e26452015-06-02 09:56:29 -07002487 public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) {
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002488 if (mService != null) {
2489 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002490 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002491 } catch (RemoteException e) {
2492 Log.w(TAG, "Failed talking with device policy service", e);
2493 }
2494 }
2495 }
2496
2497 /**
2498 * @return true if auto time is required.
2499 */
2500 public boolean getAutoTimeRequired() {
2501 if (mService != null) {
2502 try {
2503 return mService.getAutoTimeRequired();
2504 } catch (RemoteException e) {
2505 Log.w(TAG, "Failed talking with device policy service", e);
2506 }
2507 }
2508 return false;
2509 }
2510
2511 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002512 * Called by an application that is administering the device to disable keyguard customizations,
2513 * such as widgets. After setting this, keyguard features will be disabled according to the
2514 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002515 *
2516 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07002517 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07002518 * this method; if it has not, a security exception will be thrown.
2519 *
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002520 * <p>Calling this from a managed profile before version
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002521 * {@link android.os.Build.VERSION_CODES#M} will throw a security exception.
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002522 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002523 * <p>From version {@link android.os.Build.VERSION_CODES#M} a profile owner can set:
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002524 * <ul>
2525 * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, {@link #KEYGUARD_DISABLE_FINGERPRINT}
2526 * these will affect the profile's parent user.
2527 * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} this will affect notifications
2528 * generated by applications in the managed profile.
2529 * </ul>
2530 * <p>Requests to disable other features on a managed profile will be ignored. The admin
2531 * can check which features have been disabled by calling
2532 * {@link #getKeyguardDisabledFeatures(ComponentName)}
Amith Yamasani242f4b12014-10-14 16:06:13 -07002533 *
Jim Millerb8ec4702012-08-31 17:19:10 -07002534 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07002535 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
2536 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
Jim Miller50e62182014-04-23 17:25:00 -07002537 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002538 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FINGERPRINT},
2539 * {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07002540 */
Robin Lee25e26452015-06-02 09:56:29 -07002541 public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002542 if (mService != null) {
2543 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002544 mService.setKeyguardDisabledFeatures(admin, which);
Jim Millerb8ec4702012-08-31 17:19:10 -07002545 } catch (RemoteException e) {
2546 Log.w(TAG, "Failed talking with device policy service", e);
2547 }
2548 }
2549 }
2550
2551 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002552 * Determine whether or not features have been disabled in keyguard either by the current
Jim Millerb8ec4702012-08-31 17:19:10 -07002553 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002554 * @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 -07002555 * have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07002556 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
2557 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002558 */
Robin Lee25e26452015-06-02 09:56:29 -07002559 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) {
Jim Miller48b9b0d2012-09-19 23:16:50 -07002560 return getKeyguardDisabledFeatures(admin, UserHandle.myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002561 }
2562
2563 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002564 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002565 if (mService != null) {
2566 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07002567 return mService.getKeyguardDisabledFeatures(admin, userHandle);
Jim Millerb8ec4702012-08-31 17:19:10 -07002568 } catch (RemoteException e) {
2569 Log.w(TAG, "Failed talking with device policy service", e);
2570 }
2571 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07002572 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07002573 }
2574
2575 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08002576 * @hide
2577 */
Robin Lee25e26452015-06-02 09:56:29 -07002578 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
2579 int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002580 if (mService != null) {
2581 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01002582 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002583 } catch (RemoteException e) {
2584 Log.w(TAG, "Failed talking with device policy service", e);
2585 }
2586 }
2587 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002588
Dianne Hackbornd6847842010-01-12 18:14:19 -08002589 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01002590 * @hide
2591 */
Robin Lee25e26452015-06-02 09:56:29 -07002592 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
Jessica Hummel6d36b602014-04-04 12:42:17 +01002593 setActiveAdmin(policyReceiver, refreshing, UserHandle.myUserId());
2594 }
2595
2596 /**
Robin Lee25e26452015-06-02 09:56:29 -07002597 * Returns the DeviceAdminInfo as defined by the administrator's package info &amp; meta-data
Dianne Hackbornd6847842010-01-12 18:14:19 -08002598 * @hide
2599 */
Robin Lee25e26452015-06-02 09:56:29 -07002600 public DeviceAdminInfo getAdminInfo(@NonNull ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002601 ActivityInfo ai;
2602 try {
2603 ai = mContext.getPackageManager().getReceiverInfo(cn,
2604 PackageManager.GET_META_DATA);
2605 } catch (PackageManager.NameNotFoundException e) {
2606 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
2607 return null;
2608 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002609
Dianne Hackbornd6847842010-01-12 18:14:19 -08002610 ResolveInfo ri = new ResolveInfo();
2611 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002612
Dianne Hackbornd6847842010-01-12 18:14:19 -08002613 try {
2614 return new DeviceAdminInfo(mContext, ri);
2615 } catch (XmlPullParserException e) {
2616 Log.w(TAG, "Unable to parse device policy " + cn, e);
2617 return null;
2618 } catch (IOException e) {
2619 Log.w(TAG, "Unable to parse device policy " + cn, e);
2620 return null;
2621 }
2622 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002623
Dianne Hackbornd6847842010-01-12 18:14:19 -08002624 /**
2625 * @hide
2626 */
Robin Lee25e26452015-06-02 09:56:29 -07002627 public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002628 if (mService != null) {
2629 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002630 mService.getRemoveWarning(admin, result, UserHandle.myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002631 } catch (RemoteException e) {
2632 Log.w(TAG, "Failed talking with device policy service", e);
2633 }
2634 }
2635 }
2636
2637 /**
2638 * @hide
2639 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002640 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002641 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002642 if (mService != null) {
2643 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002644 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002645 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002646 } catch (RemoteException e) {
2647 Log.w(TAG, "Failed talking with device policy service", e);
2648 }
2649 }
2650 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002651
Dianne Hackbornd6847842010-01-12 18:14:19 -08002652 /**
2653 * @hide
2654 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002655 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002656 if (mService != null) {
2657 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002658 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002659 } catch (RemoteException e) {
2660 Log.w(TAG, "Failed talking with device policy service", e);
2661 }
2662 }
2663 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002664
Dianne Hackbornd6847842010-01-12 18:14:19 -08002665 /**
2666 * @hide
2667 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002668 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002669 if (mService != null) {
2670 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002671 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002672 } catch (RemoteException e) {
2673 Log.w(TAG, "Failed talking with device policy service", e);
2674 }
2675 }
2676 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07002677
2678 /**
2679 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00002680 * Sets the given package as the device owner.
2681 * Same as {@link #setDeviceOwner(String, String)} but without setting a device owner name.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002682 * @param packageName the package name of the application to be registered as the device owner.
2683 * @return whether the package was successfully registered as the device owner.
2684 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00002685 * @throws IllegalStateException If the preconditions mentioned are not met.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002686 */
Makoto Onuki58b684f2015-09-04 10:48:16 -07002687 public boolean setDeviceOwner(String packageName) {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002688 return setDeviceOwner(packageName, null);
2689 }
2690
2691 /**
2692 * @hide
Makoto Onuki58b684f2015-09-04 10:48:16 -07002693 */
2694 public boolean setDeviceOwner(String packageName, int userId) {
2695 return setDeviceOwner(packageName, null, userId);
2696 }
2697
2698 /**
2699 * @hide
2700 */
2701 public boolean setDeviceOwner(String packageName, String ownerName) {
2702 return setDeviceOwner(packageName, ownerName, UserHandle.USER_SYSTEM);
2703 }
2704
2705 /**
2706 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00002707 * Sets the given package as the device owner. The package must already be installed. There
2708 * must not already be a device owner.
2709 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
2710 * this method.
2711 * Calling this after the setup phase of the primary user has completed is allowed only if
2712 * the caller is the shell uid, and there are no additional users and no accounts.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002713 * @param packageName the package name of the application to be registered as the device owner.
2714 * @param ownerName the human readable name of the institution that owns this device.
Makoto Onuki58b684f2015-09-04 10:48:16 -07002715 * @param userId ID of the user on which the device owner runs.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002716 * @return whether the package was successfully registered as the device owner.
2717 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00002718 * @throws IllegalStateException If the preconditions mentioned are not met.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002719 */
Makoto Onuki58b684f2015-09-04 10:48:16 -07002720 public boolean setDeviceOwner(String packageName, String ownerName, int userId)
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002721 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002722 if (mService != null) {
2723 try {
Makoto Onuki58b684f2015-09-04 10:48:16 -07002724 return mService.setDeviceOwner(packageName, ownerName, userId);
Amith Yamasani71e6c692013-03-24 17:39:28 -07002725 } catch (RemoteException re) {
2726 Log.w(TAG, "Failed to set device owner");
2727 }
2728 }
2729 return false;
2730 }
2731
2732 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002733 * Used to determine if a particular package has been registered as a Device Owner app.
2734 * A device owner app is a special device admin that cannot be deactivated by the user, once
Robin Lee25e26452015-06-02 09:56:29 -07002735 * activated as a device admin. It also cannot be uninstalled. To check whether a particular
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002736 * package is currently registered as the device owner app, pass in the package name from
2737 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
Robin Lee25e26452015-06-02 09:56:29 -07002738 * admin apps that want to check whether they are also registered as the device owner app. The
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002739 * exact mechanism by which a device admin app is registered as a device owner app is defined by
2740 * the setup process.
2741 * @param packageName the package name of the app, to compare with the registered device owner
2742 * app, if any.
2743 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002744 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002745 public boolean isDeviceOwnerApp(String packageName) {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002746 if (mService != null) {
2747 try {
2748 return mService.isDeviceOwner(packageName);
2749 } catch (RemoteException re) {
2750 Log.w(TAG, "Failed to check device owner");
2751 }
2752 }
2753 return false;
2754 }
2755
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002756 /**
2757 * @hide
2758 * Redirect to isDeviceOwnerApp.
2759 */
2760 public boolean isDeviceOwner(String packageName) {
2761 return isDeviceOwnerApp(packageName);
2762 }
2763
Jason Monkb0dced82014-06-06 14:36:20 -04002764 /**
2765 * Clears the current device owner. The caller must be the device owner.
2766 *
2767 * This function should be used cautiously as once it is called it cannot
2768 * be undone. The device owner can only be set as a part of device setup
2769 * before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04002770 *
2771 * @param packageName The package name of the device owner.
Jason Monkb0dced82014-06-06 14:36:20 -04002772 */
Jason Monk94d2cf92014-06-18 09:53:34 -04002773 public void clearDeviceOwnerApp(String packageName) {
Jason Monkb0dced82014-06-06 14:36:20 -04002774 if (mService != null) {
2775 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04002776 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04002777 } catch (RemoteException re) {
2778 Log.w(TAG, "Failed to clear device owner");
2779 }
2780 }
2781 }
2782
Amith Yamasani71e6c692013-03-24 17:39:28 -07002783 /** @hide */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002784 @SystemApi
Amith Yamasani71e6c692013-03-24 17:39:28 -07002785 public String getDeviceOwner() {
2786 if (mService != null) {
2787 try {
2788 return mService.getDeviceOwner();
2789 } catch (RemoteException re) {
2790 Log.w(TAG, "Failed to get device owner");
2791 }
2792 }
2793 return null;
2794 }
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002795
2796 /** @hide */
2797 public String getDeviceOwnerName() {
2798 if (mService != null) {
2799 try {
2800 return mService.getDeviceOwnerName();
2801 } catch (RemoteException re) {
2802 Log.w(TAG, "Failed to get device owner");
2803 }
2804 }
2805 return null;
2806 }
Adam Connors776c5552014-01-09 10:42:56 +00002807
2808 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04002809 * @hide
Julia Reynolds20118f12015-02-11 12:34:08 -05002810 * Sets the given component as the device initializer. The package must already be installed and
2811 * set as an active device administrator, and there must not be an existing device initializer,
2812 * for this call to succeed. This method can only be called by an app holding the
2813 * MANAGE_DEVICE_ADMINS permission before the device is provisioned or by a device owner app. A
2814 * device initializer app is granted device owner privileges during device initialization and
2815 * profile owner privileges during secondary user initialization.
Robin Lee25e26452015-06-02 09:56:29 -07002816 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2817 * {@code null} if not called by the device owner.
Julia Reynolds20118f12015-02-11 12:34:08 -05002818 * @param initializer Which {@link DeviceAdminReceiver} to make device initializer.
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002819 * @return whether the component was successfully registered as the device initializer.
2820 * @throws IllegalArgumentException if the componentname is null or invalid
Julia Reynolds20118f12015-02-11 12:34:08 -05002821 * @throws IllegalStateException if the caller is not device owner or the device has
2822 * already been provisioned or a device initializer already exists.
2823 */
Robin Lee25e26452015-06-02 09:56:29 -07002824 public boolean setDeviceInitializer(@Nullable ComponentName admin,
2825 @NonNull ComponentName initializer)
Julia Reynolds731051e2015-05-11 15:52:08 -04002826 throws IllegalArgumentException, IllegalStateException {
Julia Reynolds20118f12015-02-11 12:34:08 -05002827 if (mService != null) {
2828 try {
Robin Lee25e26452015-06-02 09:56:29 -07002829 return mService.setDeviceInitializer(admin, initializer);
Julia Reynolds20118f12015-02-11 12:34:08 -05002830 } catch (RemoteException re) {
2831 Log.w(TAG, "Failed to set device initializer");
2832 }
2833 }
2834 return false;
2835 }
2836
2837 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04002838 * @hide
Julia Reynolds20118f12015-02-11 12:34:08 -05002839 * Used to determine if a particular package has been registered as the device initializer.
2840 *
2841 * @param packageName the package name of the app, to compare with the registered device
2842 * initializer app, if any.
2843 * @return whether or not the caller is registered as the device initializer app.
2844 */
2845 public boolean isDeviceInitializerApp(String packageName) {
2846 if (mService != null) {
2847 try {
2848 return mService.isDeviceInitializer(packageName);
2849 } catch (RemoteException re) {
2850 Log.w(TAG, "Failed to check device initializer");
2851 }
2852 }
2853 return false;
2854 }
2855
2856 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04002857 * @hide
Julia Reynoldse9254402015-02-11 12:34:08 -05002858 * Removes the device initializer, so that it will not be invoked on user initialization for any
2859 * subsequently created users. This method can be called by either the device owner or device
Julia Reynolds1c3754a2015-03-05 10:06:41 -05002860 * initializer itself. The caller must be an active administrator.
2861 *
Robin Lee25e26452015-06-02 09:56:29 -07002862 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Julia Reynolds20118f12015-02-11 12:34:08 -05002863 */
Robin Lee25e26452015-06-02 09:56:29 -07002864 public void clearDeviceInitializerApp(@NonNull ComponentName admin) {
Julia Reynolds20118f12015-02-11 12:34:08 -05002865 if (mService != null) {
2866 try {
Robin Lee25e26452015-06-02 09:56:29 -07002867 mService.clearDeviceInitializer(admin);
Julia Reynolds20118f12015-02-11 12:34:08 -05002868 } catch (RemoteException re) {
2869 Log.w(TAG, "Failed to clear device initializer");
2870 }
2871 }
2872 }
2873
2874 /**
2875 * @hide
2876 * Gets the device initializer of the system.
2877 *
2878 * @return the package name of the device initializer.
2879 */
2880 @SystemApi
2881 public String getDeviceInitializerApp() {
2882 if (mService != null) {
2883 try {
2884 return mService.getDeviceInitializer();
2885 } catch (RemoteException re) {
2886 Log.w(TAG, "Failed to get device initializer");
2887 }
2888 }
2889 return null;
2890 }
2891
2892 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002893 * @hide
2894 * Gets the device initializer component of the system.
2895 *
2896 * @return the component name of the device initializer.
2897 */
2898 @SystemApi
2899 public ComponentName getDeviceInitializerComponent() {
2900 if (mService != null) {
2901 try {
2902 return mService.getDeviceInitializerComponent();
2903 } catch (RemoteException re) {
2904 Log.w(TAG, "Failed to get device initializer");
2905 }
2906 }
2907 return null;
2908 }
2909
2910
2911 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04002912 * @hide
Julia Reynolds20118f12015-02-11 12:34:08 -05002913 * Sets the enabled state of the user. A user should be enabled only once it is ready to
2914 * be used.
2915 *
2916 * <p>Device initializer must call this method to mark the user as functional.
2917 * Only the device initializer agent can call this.
2918 *
2919 * <p>When the user is enabled, if the device initializer is not also the device owner, the
2920 * device initializer will no longer have elevated permissions to call methods in this class.
2921 * Additionally, it will be removed as an active administrator and its
2922 * {@link DeviceAdminReceiver} will be disabled.
2923 *
2924 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2925 * @return whether the user is now enabled.
2926 */
Robin Lee25e26452015-06-02 09:56:29 -07002927 public boolean setUserEnabled(@NonNull ComponentName admin) {
Julia Reynolds20118f12015-02-11 12:34:08 -05002928 if (mService != null) {
2929 try {
2930 return mService.setUserEnabled(admin);
2931 } catch (RemoteException e) {
2932 Log.w(TAG, "Failed talking with device policy service", e);
2933 }
2934 }
2935 return false;
2936 }
2937
2938 /**
Adam Connors776c5552014-01-09 10:42:56 +00002939 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002940 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302941 * Sets the given component as an active admin and registers the package as the profile
2942 * owner for this user. The package must already be installed and there shouldn't be
2943 * an existing profile owner registered for this user. Also, this method must be called
2944 * before the user setup has been completed.
2945 * <p>
2946 * This method can only be called by system apps that hold MANAGE_USERS permission and
2947 * MANAGE_DEVICE_ADMINS permission.
2948 * @param admin The component to register as an active admin and profile owner.
2949 * @param ownerName The user-visible name of the entity that is managing this user.
2950 * @return whether the admin was successfully registered as the profile owner.
2951 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
2952 * the user has already been set up.
2953 */
Justin Morey80440cc2014-07-24 09:16:35 -05002954 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07002955 public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302956 throws IllegalArgumentException {
2957 if (mService != null) {
2958 try {
2959 final int myUserId = UserHandle.myUserId();
2960 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002961 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302962 } catch (RemoteException re) {
2963 Log.w(TAG, "Failed to set profile owner " + re);
2964 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2965 }
2966 }
2967 return false;
2968 }
2969
2970 /**
2971 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002972 * Clears the active profile owner and removes all user restrictions. The caller must
2973 * be from the same package as the active profile owner for this user, otherwise a
2974 * SecurityException will be thrown.
2975 *
2976 * @param admin The component to remove as the profile owner.
2977 * @return
2978 */
2979 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07002980 public void clearProfileOwner(@NonNull ComponentName admin) {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002981 if (mService != null) {
2982 try {
2983 mService.clearProfileOwner(admin);
2984 } catch (RemoteException re) {
2985 Log.w(TAG, "Failed to clear profile owner " + admin + re);
2986 }
2987 }
2988 }
2989
2990 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05002991 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07002992 * Checks whether the user was already setup.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002993 */
2994 public boolean hasUserSetupCompleted() {
2995 if (mService != null) {
2996 try {
2997 return mService.hasUserSetupCompleted();
2998 } catch (RemoteException re) {
Robin Lee25e26452015-06-02 09:56:29 -07002999 Log.w(TAG, "Failed to check whether user setup has completed");
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003000 }
3001 }
3002 return true;
3003 }
3004
3005 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003006 * @hide
3007 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00003008 * already be installed. There must not already be a profile owner for this user.
3009 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
3010 * this method.
3011 * Calling this after the setup phase of the specified user has completed is allowed only if:
3012 * - the caller is SYSTEM_UID.
3013 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003014 * @param admin the component name to be registered as profile owner.
3015 * @param ownerName the human readable name of the organisation associated with this DPM.
3016 * @param userHandle the userId to set the profile owner for.
3017 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00003018 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
3019 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003020 */
Robin Lee25e26452015-06-02 09:56:29 -07003021 public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName,
Robin Leeddd553f2015-04-30 14:18:22 +01003022 int userHandle) throws IllegalArgumentException {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003023 if (admin == null) {
3024 throw new NullPointerException("admin cannot be null");
3025 }
Adam Connors776c5552014-01-09 10:42:56 +00003026 if (mService != null) {
3027 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003028 if (ownerName == null) {
3029 ownerName = "";
3030 }
3031 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00003032 } catch (RemoteException re) {
3033 Log.w(TAG, "Failed to set profile owner", re);
3034 throw new IllegalArgumentException("Couldn't set profile owner.", re);
3035 }
3036 }
3037 return false;
3038 }
3039
3040 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003041 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
3042 * be used. Only the profile owner can call this.
3043 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01003044 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003045 *
3046 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3047 */
Robin Lee25e26452015-06-02 09:56:29 -07003048 public void setProfileEnabled(@NonNull ComponentName admin) {
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003049 if (mService != null) {
3050 try {
3051 mService.setProfileEnabled(admin);
3052 } catch (RemoteException e) {
3053 Log.w(TAG, "Failed talking with device policy service", e);
3054 }
3055 }
3056 }
3057
3058 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003059 * Sets the name of the profile. In the device owner case it sets the name of the user
3060 * 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 +01003061 * never called by the profile or device owner, the name will be set to default values.
3062 *
3063 * @see #isProfileOwnerApp
3064 * @see #isDeviceOwnerApp
3065 *
Robin Lee25e26452015-06-02 09:56:29 -07003066 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01003067 * @param profileName The name of the profile.
3068 */
Robin Lee25e26452015-06-02 09:56:29 -07003069 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Jessica Hummel1333ea12014-06-23 11:20:10 +01003070 if (mService != null) {
3071 try {
Robin Lee25e26452015-06-02 09:56:29 -07003072 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07003073 } catch (RemoteException e) {
3074 Log.w(TAG, "Failed talking with device policy service", e);
3075 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01003076 }
3077 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01003078
3079 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003080 * Used to determine if a particular package is registered as the profile owner for the
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003081 * current user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003082 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00003083 *
3084 * @param packageName The package name of the app to compare with the registered profile owner.
3085 * @return Whether or not the package is registered as the profile owner.
3086 */
3087 public boolean isProfileOwnerApp(String packageName) {
3088 if (mService != null) {
3089 try {
Nicolas Prevot90af6d72014-07-30 14:19:12 +01003090 ComponentName profileOwner = mService.getProfileOwner(
3091 Process.myUserHandle().getIdentifier());
3092 return profileOwner != null
3093 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00003094 } catch (RemoteException re) {
3095 Log.w(TAG, "Failed to check profile owner");
3096 }
3097 }
3098 return false;
3099 }
3100
3101 /**
3102 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003103 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00003104 * owner has been set for that user.
3105 * @throws IllegalArgumentException if the userId is invalid.
3106 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01003107 @SystemApi
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003108 public ComponentName getProfileOwner() throws IllegalArgumentException {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003109 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
3110 }
3111
3112 /**
3113 * @see #getProfileOwner()
3114 * @hide
3115 */
3116 public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00003117 if (mService != null) {
3118 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003119 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00003120 } catch (RemoteException re) {
3121 Log.w(TAG, "Failed to get profile owner");
3122 throw new IllegalArgumentException(
3123 "Requested profile owner for invalid userId", re);
3124 }
3125 }
3126 return null;
3127 }
3128
3129 /**
3130 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003131 * @return the human readable name of the organisation associated with this DPM or {@code null}
3132 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00003133 * @throws IllegalArgumentException if the userId is invalid.
3134 */
3135 public String getProfileOwnerName() throws IllegalArgumentException {
3136 if (mService != null) {
3137 try {
3138 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
3139 } catch (RemoteException re) {
3140 Log.w(TAG, "Failed to get profile owner");
3141 throw new IllegalArgumentException(
3142 "Requested profile owner for invalid userId", re);
3143 }
3144 }
3145 return null;
3146 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003147
3148 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07003149 * @hide
3150 * @param user The user for whom to fetch the profile owner name, if any.
3151 * @return the human readable name of the organisation associated with this profile owner or
3152 * null if one is not set.
3153 * @throws IllegalArgumentException if the userId is invalid.
3154 */
3155 @SystemApi
Selim Cinek24ac55e2014-08-27 12:51:45 +02003156 public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Amith Yamasani38f836b2014-08-20 14:51:15 -07003157 if (mService != null) {
3158 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02003159 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07003160 } catch (RemoteException re) {
3161 Log.w(TAG, "Failed to get profile owner");
3162 throw new IllegalArgumentException(
3163 "Requested profile owner for invalid userId", re);
3164 }
3165 }
3166 return null;
3167 }
3168
3169 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003170 * Called by a profile owner or device owner to add a default intent handler activity for
3171 * intents that match a certain intent filter. This activity will remain the default intent
3172 * handler even if the set of potential event handlers for the intent filter changes and if
3173 * the intent preferences are reset.
3174 *
3175 * <p>The default disambiguation mechanism takes over if the activity is not installed
3176 * (anymore). When the activity is (re)installed, it is automatically reset as default
3177 * intent handler for the filter.
3178 *
3179 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
3180 * security exception will be thrown.
3181 *
3182 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3183 * @param filter The IntentFilter for which a default handler is added.
3184 * @param activity The Activity that is added as default intent handler.
3185 */
Robin Lee25e26452015-06-02 09:56:29 -07003186 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
3187 @NonNull ComponentName activity) {
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003188 if (mService != null) {
3189 try {
3190 mService.addPersistentPreferredActivity(admin, filter, activity);
3191 } catch (RemoteException e) {
3192 Log.w(TAG, "Failed talking with device policy service", e);
3193 }
3194 }
3195 }
3196
3197 /**
3198 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00003199 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003200 *
3201 * <p>The calling device admin must be a profile owner. If it is not, a security
3202 * exception will be thrown.
3203 *
3204 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3205 * @param packageName The name of the package for which preferences are removed.
3206 */
Robin Lee25e26452015-06-02 09:56:29 -07003207 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003208 String packageName) {
3209 if (mService != null) {
3210 try {
3211 mService.clearPackagePersistentPreferredActivities(admin, packageName);
3212 } catch (RemoteException e) {
3213 Log.w(TAG, "Failed talking with device policy service", e);
3214 }
3215 }
3216 }
Robin Lee66e5d962014-04-09 16:44:21 +01003217
3218 /**
3219 * Called by a profile or device owner to set the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003220 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01003221 *
Esteban Talavera6b8e0642015-08-10 17:26:04 +01003222 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be:
3223 * <ul>
3224 * <li>{@code boolean}
3225 * <li>{@code int}
3226 * <li>{@code String} or {@code String[]}
3227 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
3228 * </ul>
Robin Lee66e5d962014-04-09 16:44:21 +01003229 *
3230 * <p>The application restrictions are only made visible to the target application and the
3231 * profile or device owner.
3232 *
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003233 * <p>If the restrictions are not available yet, but may be applied in the near future,
3234 * the admin can notify the target application of that by adding
3235 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
3236 *
Robin Lee66e5d962014-04-09 16:44:21 +01003237 * <p>The calling device admin must be a profile or device owner; if it is not, a security
3238 * exception will be thrown.
3239 *
3240 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3241 * @param packageName The name of the package to update restricted settings for.
3242 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
3243 * set of active restrictions.
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003244 *
3245 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01003246 */
Robin Lee25e26452015-06-02 09:56:29 -07003247 public void setApplicationRestrictions(@NonNull ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01003248 Bundle settings) {
3249 if (mService != null) {
3250 try {
3251 mService.setApplicationRestrictions(admin, packageName, settings);
3252 } catch (RemoteException e) {
3253 Log.w(TAG, "Failed talking with device policy service", e);
3254 }
3255 }
3256 }
3257
3258 /**
Jim Millere303bf42014-08-26 17:12:29 -07003259 * Sets a list of configuration features to enable for a TrustAgent component. This is meant
3260 * to be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all
3261 * trust agents but those enabled by this function call. If flag
3262 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Jim Miller604e7552014-07-18 19:00:02 -07003263 *
3264 * <p>The calling device admin must have requested
3265 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millere303bf42014-08-26 17:12:29 -07003266 * this method; if not, a security exception will be thrown.
Jim Miller604e7552014-07-18 19:00:02 -07003267 *
3268 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07003269 * @param target Component name of the agent to be enabled.
Jim Millerb5db57a2015-01-14 18:17:19 -08003270 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent
Jim Millere303bf42014-08-26 17:12:29 -07003271 * will be strictly disabled according to the state of the
3272 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
3273 * <p>If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all admins,
3274 * then it's up to the TrustAgent itself to aggregate the values from all device admins.
3275 * <p>Consult documentation for the specific TrustAgent to determine legal options parameters.
Jim Miller604e7552014-07-18 19:00:02 -07003276 */
Robin Lee25e26452015-06-02 09:56:29 -07003277 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
3278 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07003279 if (mService != null) {
3280 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003281 mService.setTrustAgentConfiguration(admin, target, configuration);
Jim Miller604e7552014-07-18 19:00:02 -07003282 } catch (RemoteException e) {
3283 Log.w(TAG, "Failed talking with device policy service", e);
3284 }
3285 }
3286 }
3287
3288 /**
Jim Millere303bf42014-08-26 17:12:29 -07003289 * Gets configuration for the given trust agent based on aggregating all calls to
3290 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
3291 * all device admins.
Jim Miller604e7552014-07-18 19:00:02 -07003292 *
Jim Millerb5db57a2015-01-14 18:17:19 -08003293 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
3294 * this function returns a list of configurations for all admins that declare
3295 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
3296 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
3297 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
3298 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07003299 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07003300 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07003301 */
Robin Lee25e26452015-06-02 09:56:29 -07003302 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
3303 @NonNull ComponentName agent) {
Jim Millere303bf42014-08-26 17:12:29 -07003304 return getTrustAgentConfiguration(admin, agent, UserHandle.myUserId());
3305 }
3306
3307 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003308 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
3309 @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07003310 if (mService != null) {
3311 try {
Jim Millere303bf42014-08-26 17:12:29 -07003312 return mService.getTrustAgentConfiguration(admin, agent, userHandle);
Jim Miller604e7552014-07-18 19:00:02 -07003313 } catch (RemoteException e) {
3314 Log.w(TAG, "Failed talking with device policy service", e);
3315 }
3316 }
Jim Millere303bf42014-08-26 17:12:29 -07003317 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07003318 }
3319
3320 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003321 * Called by a profile owner of a managed profile to set whether caller-Id information from
3322 * the managed profile will be shown in the parent profile, for incoming calls.
Adam Connors210fe212014-07-17 15:41:43 +01003323 *
3324 * <p>The calling device admin must be a profile owner. If it is not, a
3325 * security exception will be thrown.
3326 *
Robin Lee25e26452015-06-02 09:56:29 -07003327 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01003328 * @param disabled If true caller-Id information in the managed profile is not displayed.
3329 */
Robin Lee25e26452015-06-02 09:56:29 -07003330 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Adam Connors210fe212014-07-17 15:41:43 +01003331 if (mService != null) {
3332 try {
Robin Lee25e26452015-06-02 09:56:29 -07003333 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01003334 } catch (RemoteException e) {
3335 Log.w(TAG, "Failed talking with device policy service", e);
3336 }
3337 }
3338 }
3339
3340 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003341 * Called by a profile owner of a managed profile to determine whether or not caller-Id
3342 * information has been disabled.
Adam Connors210fe212014-07-17 15:41:43 +01003343 *
3344 * <p>The calling device admin must be a profile owner. If it is not, a
3345 * security exception will be thrown.
3346 *
Robin Lee25e26452015-06-02 09:56:29 -07003347 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01003348 */
Robin Lee25e26452015-06-02 09:56:29 -07003349 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Adam Connors210fe212014-07-17 15:41:43 +01003350 if (mService != null) {
3351 try {
Robin Lee25e26452015-06-02 09:56:29 -07003352 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01003353 } catch (RemoteException e) {
3354 Log.w(TAG, "Failed talking with device policy service", e);
3355 }
3356 }
3357 return false;
3358 }
3359
3360 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07003361 * Determine whether or not caller-Id information has been disabled.
3362 *
3363 * @param userHandle The user for whom to check the caller-id permission
3364 * @hide
3365 */
3366 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
3367 if (mService != null) {
3368 try {
3369 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
3370 } catch (RemoteException e) {
3371 Log.w(TAG, "Failed talking with device policy service", e);
3372 }
3373 }
3374 return false;
3375 }
3376
3377 /**
Makoto Onuki1040da12015-03-19 11:24:00 -07003378 * Start Quick Contact on the managed profile for the current user, if the policy allows.
3379 * @hide
3380 */
3381 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
3382 Intent originalIntent) {
3383 if (mService != null) {
3384 try {
3385 mService.startManagedQuickContact(
3386 actualLookupKey, actualContactId, originalIntent);
3387 } catch (RemoteException e) {
3388 Log.w(TAG, "Failed talking with device policy service", e);
3389 }
3390 }
3391 }
3392
3393 /**
Ricky Wai778ba132015-03-31 14:21:22 +01003394 * Called by a profile owner of a managed profile to set whether bluetooth
3395 * devices can access enterprise contacts.
3396 * <p>
3397 * The calling device admin must be a profile owner. If it is not, a
3398 * security exception will be thrown.
3399 * <p>
3400 * This API works on managed profile only.
3401 *
Robin Lee25e26452015-06-02 09:56:29 -07003402 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01003403 * with.
3404 * @param disabled If true, bluetooth devices cannot access enterprise
3405 * contacts.
3406 */
Robin Lee25e26452015-06-02 09:56:29 -07003407 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Ricky Wai778ba132015-03-31 14:21:22 +01003408 if (mService != null) {
3409 try {
Robin Lee25e26452015-06-02 09:56:29 -07003410 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01003411 } catch (RemoteException e) {
3412 Log.w(TAG, "Failed talking with device policy service", e);
3413 }
3414 }
3415 }
3416
3417 /**
3418 * Called by a profile owner of a managed profile to determine whether or
3419 * not Bluetooth devices cannot access enterprise contacts.
3420 * <p>
3421 * The calling device admin must be a profile owner. If it is not, a
3422 * security exception will be thrown.
3423 * <p>
3424 * This API works on managed profile only.
3425 *
Robin Lee25e26452015-06-02 09:56:29 -07003426 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01003427 * with.
3428 */
Robin Lee25e26452015-06-02 09:56:29 -07003429 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Ricky Wai778ba132015-03-31 14:21:22 +01003430 if (mService != null) {
3431 try {
Robin Lee25e26452015-06-02 09:56:29 -07003432 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01003433 } catch (RemoteException e) {
3434 Log.w(TAG, "Failed talking with device policy service", e);
3435 }
3436 }
3437 return true;
3438 }
3439
3440 /**
3441 * Determine whether or not Bluetooth devices cannot access contacts.
3442 * <p>
3443 * This API works on managed profile UserHandle only.
3444 *
3445 * @param userHandle The user for whom to check the caller-id permission
3446 * @hide
3447 */
3448 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
3449 if (mService != null) {
3450 try {
3451 return mService.getBluetoothContactSharingDisabledForUser(userHandle
3452 .getIdentifier());
3453 } catch (RemoteException e) {
3454 Log.w(TAG, "Failed talking with device policy service", e);
3455 }
3456 }
3457 return true;
3458 }
3459
3460 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003461 * Called by the profile owner of a managed profile so that some intents sent in the managed
3462 * profile can also be resolved in the parent, or vice versa.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00003463 * Only activity intents are supported.
3464 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003465 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01003466 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
3467 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01003468 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
3469 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003470 */
Robin Lee25e26452015-06-02 09:56:29 -07003471 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003472 if (mService != null) {
3473 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003474 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003475 } catch (RemoteException e) {
3476 Log.w(TAG, "Failed talking with device policy service", e);
3477 }
3478 }
3479 }
3480
3481 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003482 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
3483 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01003484 * Only removes those that have been set by the profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003485 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3486 */
Robin Lee25e26452015-06-02 09:56:29 -07003487 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003488 if (mService != null) {
3489 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003490 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003491 } catch (RemoteException e) {
3492 Log.w(TAG, "Failed talking with device policy service", e);
3493 }
3494 }
3495 }
3496
3497 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003498 * Called by a profile or device owner to set the permitted accessibility services. When
3499 * set by a device owner or profile owner the restriction applies to all profiles of the
3500 * user the device owner or profile owner is an admin for.
Jim Millerb1474f42014-08-26 18:42:58 -07003501 *
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003502 * By default the user can use any accessiblity service. When zero or more packages have
3503 * been added, accessiblity services that are not in the list and not part of the system
Jim Millerb1474f42014-08-26 18:42:58 -07003504 * can not be enabled by the user.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003505 *
3506 * <p> Calling with a null value for the list disables the restriction so that all services
3507 * can be used, calling with an empty list only allows the builtin system's services.
3508 *
3509 * <p> System accesibility services are always available to the user the list can't modify
3510 * this.
3511 *
3512 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3513 * @param packageNames List of accessibility service package names.
3514 *
3515 * @return true if setting the restriction succeeded. It fail if there is
3516 * one or more non-system accessibility services enabled, that are not in the list.
3517 */
Robin Lee25e26452015-06-02 09:56:29 -07003518 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003519 List<String> packageNames) {
3520 if (mService != null) {
3521 try {
3522 return mService.setPermittedAccessibilityServices(admin, packageNames);
3523 } catch (RemoteException e) {
3524 Log.w(TAG, "Failed talking with device policy service", e);
3525 }
3526 }
3527 return false;
3528 }
3529
3530 /**
3531 * Returns the list of permitted accessibility services set by this device or profile owner.
3532 *
3533 * <p>An empty list means no accessibility services except system services are allowed.
3534 * Null means all accessibility services are allowed.
3535 *
3536 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3537 * @return List of accessiblity service package names.
3538 */
Robin Lee25e26452015-06-02 09:56:29 -07003539 public List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003540 if (mService != null) {
3541 try {
3542 return mService.getPermittedAccessibilityServices(admin);
3543 } catch (RemoteException e) {
3544 Log.w(TAG, "Failed talking with device policy service", e);
3545 }
3546 }
3547 return null;
3548 }
3549
3550 /**
3551 * Returns the list of accessibility services permitted by the device or profiles
3552 * owners of this user.
3553 *
3554 * <p>Null means all accessibility services are allowed, if a non-null list is returned
3555 * it will contain the intersection of the permitted lists for any device or profile
3556 * owners that apply to this user. It will also include any system accessibility services.
3557 *
3558 * @param userId which user to check for.
3559 * @return List of accessiblity service package names.
3560 * @hide
3561 */
3562 @SystemApi
3563 public List<String> getPermittedAccessibilityServices(int userId) {
3564 if (mService != null) {
3565 try {
3566 return mService.getPermittedAccessibilityServicesForUser(userId);
3567 } catch (RemoteException e) {
3568 Log.w(TAG, "Failed talking with device policy service", e);
3569 }
3570 }
3571 return null;
3572 }
3573
3574 /**
3575 * Called by a profile or device owner to set the permitted input methods services. When
3576 * set by a device owner or profile owner the restriction applies to all profiles of the
3577 * user the device owner or profile owner is an admin for.
3578 *
3579 * By default the user can use any input method. When zero or more packages have
3580 * been added, input method that are not in the list and not part of the system
3581 * can not be enabled by the user.
3582 *
3583 * This method will fail if it is called for a admin that is not for the foreground user
3584 * or a profile of the foreground user.
3585 *
3586 * <p> Calling with a null value for the list disables the restriction so that all input methods
3587 * can be used, calling with an empty list disables all but the system's own input methods.
3588 *
3589 * <p> System input methods are always available to the user this method can't modify this.
3590 *
3591 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3592 * @param packageNames List of input method package names.
Kenny Guy74a70242015-02-05 19:48:38 +00003593 * @return true if setting the restriction succeeded. It will fail if there are
3594 * one or more non-system input methods currently enabled that are not in
3595 * the packageNames list.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003596 */
Robin Lee25e26452015-06-02 09:56:29 -07003597 public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003598 if (mService != null) {
3599 try {
3600 return mService.setPermittedInputMethods(admin, packageNames);
3601 } catch (RemoteException e) {
3602 Log.w(TAG, "Failed talking with device policy service", e);
3603 }
3604 }
3605 return false;
3606 }
3607
3608
3609 /**
3610 * Returns the list of permitted input methods set by this device or profile owner.
3611 *
3612 * <p>An empty list means no input methods except system input methods are allowed.
3613 * Null means all input methods are allowed.
3614 *
3615 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3616 * @return List of input method package names.
3617 */
Robin Lee25e26452015-06-02 09:56:29 -07003618 public List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003619 if (mService != null) {
3620 try {
3621 return mService.getPermittedInputMethods(admin);
3622 } catch (RemoteException e) {
3623 Log.w(TAG, "Failed talking with device policy service", e);
3624 }
3625 }
3626 return null;
3627 }
3628
3629 /**
3630 * Returns the list of input methods permitted by the device or profiles
3631 * owners of the current user.
3632 *
3633 * <p>Null means all input methods are allowed, if a non-null list is returned
3634 * it will contain the intersection of the permitted lists for any device or profile
3635 * owners that apply to this user. It will also include any system input methods.
3636 *
3637 * @return List of input method package names.
3638 * @hide
3639 */
3640 @SystemApi
3641 public List<String> getPermittedInputMethodsForCurrentUser() {
3642 if (mService != null) {
3643 try {
3644 return mService.getPermittedInputMethodsForCurrentUser();
3645 } catch (RemoteException e) {
3646 Log.w(TAG, "Failed talking with device policy service", e);
3647 }
3648 }
3649 return null;
3650 }
3651
3652 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003653 * Called by a device owner to create a user with the specified name. The UserHandle returned
3654 * by this method should not be persisted as user handles are recycled as users are removed and
3655 * created. If you need to persist an identifier for this user, use
3656 * {@link UserManager#getSerialNumberForUser}.
3657 *
3658 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3659 * @param name the user's name
3660 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07003661 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
3662 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01003663 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07003664 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
Julia Reynolds1e958392014-05-16 14:25:21 -04003665 */
Kenny Guy14f48e52015-06-29 15:12:36 +01003666 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07003667 public UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04003668 try {
3669 return mService.createUser(admin, name);
3670 } catch (RemoteException re) {
3671 Log.w(TAG, "Could not create a user", re);
3672 }
3673 return null;
3674 }
3675
3676 /**
Jason Monk03978a42014-06-10 15:05:30 -04003677 * Called by a device owner to create a user with the specified name. The UserHandle returned
3678 * by this method should not be persisted as user handles are recycled as users are removed and
3679 * created. If you need to persist an identifier for this user, use
3680 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
3681 * immediately.
3682 *
3683 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
3684 * as registered as an active admin on the new user. The profile owner package will be
3685 * installed on the new user if it already is installed on the device.
3686 *
3687 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
3688 * profileOwnerComponent when onEnable is called.
3689 *
3690 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3691 * @param name the user's name
3692 * @param ownerName the human readable name of the organisation associated with this DPM.
3693 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
3694 * the user.
3695 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
3696 * on the new user.
3697 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07003698 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
3699 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01003700 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07003701 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
Jason Monk03978a42014-06-10 15:05:30 -04003702 */
Kenny Guy14f48e52015-06-29 15:12:36 +01003703 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07003704 public UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
3705 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04003706 try {
3707 return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent,
3708 adminExtras);
3709 } catch (RemoteException re) {
3710 Log.w(TAG, "Could not create a user", re);
3711 }
3712 return null;
3713 }
3714
3715 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003716 * Called by a device owner to remove a user and all associated data. The primary user can
3717 * not be removed.
3718 *
3719 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3720 * @param userHandle the user to remove.
3721 * @return {@code true} if the user was removed, {@code false} otherwise.
3722 */
Robin Lee25e26452015-06-02 09:56:29 -07003723 public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) {
Julia Reynolds1e958392014-05-16 14:25:21 -04003724 try {
3725 return mService.removeUser(admin, userHandle);
3726 } catch (RemoteException re) {
3727 Log.w(TAG, "Could not remove user ", re);
3728 return false;
3729 }
3730 }
3731
3732 /**
Jason Monk582d9112014-07-09 19:57:08 -04003733 * Called by a device owner to switch the specified user to the foreground.
3734 *
3735 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3736 * @param userHandle the user to switch to; null will switch to primary.
3737 * @return {@code true} if the switch was successful, {@code false} otherwise.
3738 *
3739 * @see Intent#ACTION_USER_FOREGROUND
3740 */
Robin Lee25e26452015-06-02 09:56:29 -07003741 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Jason Monk582d9112014-07-09 19:57:08 -04003742 try {
3743 return mService.switchUser(admin, userHandle);
3744 } catch (RemoteException re) {
3745 Log.w(TAG, "Could not switch user ", re);
3746 return false;
3747 }
3748 }
3749
3750 /**
Robin Lee66e5d962014-04-09 16:44:21 +01003751 * Called by a profile or device owner to get the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003752 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01003753 *
3754 * <p>The calling device admin must be a profile or device owner; if it is not, a security
3755 * exception will be thrown.
3756 *
3757 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3758 * @param packageName The name of the package to fetch restricted settings of.
3759 * @return {@link Bundle} of settings corresponding to what was set last time
3760 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
3761 * if no restrictions have been set.
3762 */
Robin Lee25e26452015-06-02 09:56:29 -07003763 public Bundle getApplicationRestrictions(@NonNull ComponentName admin, String packageName) {
Robin Lee66e5d962014-04-09 16:44:21 +01003764 if (mService != null) {
3765 try {
3766 return mService.getApplicationRestrictions(admin, packageName);
3767 } catch (RemoteException e) {
3768 Log.w(TAG, "Failed talking with device policy service", e);
3769 }
3770 }
3771 return null;
3772 }
Amith Yamasanibe465322014-04-24 13:45:17 -07003773
3774 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003775 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07003776 * <p>
3777 * The calling device admin must be a profile or device owner; if it is not,
3778 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003779 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003780 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3781 * with.
3782 * @param key The key of the restriction. See the constants in
3783 * {@link android.os.UserManager} for the list of keys.
3784 */
Robin Lee25e26452015-06-02 09:56:29 -07003785 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07003786 if (mService != null) {
3787 try {
3788 mService.setUserRestriction(admin, key, true);
3789 } catch (RemoteException e) {
3790 Log.w(TAG, "Failed talking with device policy service", e);
3791 }
3792 }
3793 }
3794
3795 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003796 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07003797 * <p>
3798 * The calling device admin must be a profile or device owner; if it is not,
3799 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003800 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003801 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3802 * with.
3803 * @param key The key of the restriction. See the constants in
3804 * {@link android.os.UserManager} for the list of keys.
3805 */
Robin Lee25e26452015-06-02 09:56:29 -07003806 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07003807 if (mService != null) {
3808 try {
3809 mService.setUserRestriction(admin, key, false);
3810 } catch (RemoteException e) {
3811 Log.w(TAG, "Failed talking with device policy service", e);
3812 }
3813 }
3814 }
Adam Connors010cfd42014-04-16 12:48:13 +01003815
3816 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003817 * Called by profile or device owners to hide or unhide packages. When a package is hidden it
Julia Reynolds966881e2014-05-14 12:23:08 -04003818 * is unavailable for use, but the data and actual package file remain.
3819 *
3820 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003821 * @param packageName The name of the package to hide or unhide.
3822 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
3823 * unhidden.
3824 * @return boolean Whether the hidden setting of the package was successfully updated.
Julia Reynolds966881e2014-05-14 12:23:08 -04003825 */
Robin Lee25e26452015-06-02 09:56:29 -07003826 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003827 boolean hidden) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003828 if (mService != null) {
3829 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003830 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04003831 } catch (RemoteException e) {
3832 Log.w(TAG, "Failed talking with device policy service", e);
3833 }
3834 }
3835 return false;
3836 }
3837
3838 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003839 * Called by profile or device owners to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04003840 *
3841 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003842 * @param packageName The name of the package to retrieve the hidden status of.
3843 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Julia Reynolds966881e2014-05-14 12:23:08 -04003844 */
Robin Lee25e26452015-06-02 09:56:29 -07003845 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003846 if (mService != null) {
3847 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003848 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04003849 } catch (RemoteException e) {
3850 Log.w(TAG, "Failed talking with device policy service", e);
3851 }
3852 }
3853 return false;
3854 }
3855
3856 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003857 * Called by profile or device owners to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003858 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003859 *
3860 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3861 * @param packageName The package to be re-enabled in the current profile.
3862 */
Robin Lee25e26452015-06-02 09:56:29 -07003863 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Adam Connors655be2a2014-07-14 09:01:25 +00003864 if (mService != null) {
3865 try {
3866 mService.enableSystemApp(admin, packageName);
3867 } catch (RemoteException e) {
3868 Log.w(TAG, "Failed to install package: " + packageName);
3869 }
3870 }
3871 }
3872
3873 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003874 * Called by profile or device owners to re-enable system apps by intent that were disabled
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003875 * by default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003876 *
3877 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3878 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
3879 * intent will be re-enabled in the current profile.
3880 * @return int The number of activities that matched the intent and were installed.
3881 */
Robin Lee25e26452015-06-02 09:56:29 -07003882 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Adam Connors655be2a2014-07-14 09:01:25 +00003883 if (mService != null) {
3884 try {
3885 return mService.enableSystemAppWithIntent(admin, intent);
3886 } catch (RemoteException e) {
3887 Log.w(TAG, "Failed to install packages matching filter: " + intent);
3888 }
3889 }
3890 return 0;
3891 }
3892
3893 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00003894 * Called by a device owner or profile owner to disable account management for a specific type
3895 * of account.
Sander Alewijnse650c3342014-05-08 18:00:50 +01003896 *
Sander Alewijnse112e0532014-10-29 13:28:49 +00003897 * <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 +01003898 * security exception will be thrown.
3899 *
3900 * <p>When account management is disabled for an account type, adding or removing an account
3901 * of that type will not be possible.
3902 *
3903 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3904 * @param accountType For which account management is disabled or enabled.
3905 * @param disabled The boolean indicating that account management will be disabled (true) or
3906 * enabled (false).
3907 */
Robin Lee25e26452015-06-02 09:56:29 -07003908 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01003909 boolean disabled) {
3910 if (mService != null) {
3911 try {
3912 mService.setAccountManagementDisabled(admin, accountType, disabled);
3913 } catch (RemoteException e) {
3914 Log.w(TAG, "Failed talking with device policy service", e);
3915 }
3916 }
3917 }
3918
3919 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003920 * Gets the array of accounts for which account management is disabled by the profile owner.
3921 *
3922 * <p> Account management can be disabled/enabled by calling
3923 * {@link #setAccountManagementDisabled}.
3924 *
3925 * @return a list of account types for which account management has been disabled.
3926 *
3927 * @see #setAccountManagementDisabled
3928 */
3929 public String[] getAccountTypesWithManagementDisabled() {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003930 return getAccountTypesWithManagementDisabledAsUser(UserHandle.myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003931 }
3932
3933 /**
3934 * @see #getAccountTypesWithManagementDisabled()
3935 * @hide
3936 */
3937 public String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003938 if (mService != null) {
3939 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003940 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003941 } catch (RemoteException e) {
3942 Log.w(TAG, "Failed talking with device policy service", e);
3943 }
3944 }
3945
3946 return null;
3947 }
justinzhang511e0d82014-03-24 16:09:24 -04003948
3949 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003950 * Sets which packages may enter lock task mode.
3951 *
3952 * <p>Any packages that shares uid with an allowed package will also be allowed
3953 * to activate lock task.
justinzhang511e0d82014-03-24 16:09:24 -04003954 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07003955 * From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task
Benjamin Franz469dd582015-06-09 14:24:36 +01003956 * package list results in locked tasks belonging to those packages to be finished.
3957 *
Jason Monkc5185f22014-06-24 11:12:42 -04003958 * This function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04003959 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04003960 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jason Monkd7b86212014-06-16 13:15:38 -04003961 *
3962 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00003963 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
3964 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04003965 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04003966 */
Robin Lee25e26452015-06-02 09:56:29 -07003967 public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04003968 throws SecurityException {
justinzhang511e0d82014-03-24 16:09:24 -04003969 if (mService != null) {
3970 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003971 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04003972 } catch (RemoteException e) {
3973 Log.w(TAG, "Failed talking with device policy service", e);
3974 }
3975 }
3976 }
3977
3978 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003979 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04003980 *
3981 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04003982 * @hide
3983 */
Robin Lee25e26452015-06-02 09:56:29 -07003984 public String[] getLockTaskPackages(@NonNull ComponentName admin) {
justinzhang511e0d82014-03-24 16:09:24 -04003985 if (mService != null) {
3986 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003987 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04003988 } catch (RemoteException e) {
3989 Log.w(TAG, "Failed talking with device policy service", e);
3990 }
3991 }
3992 return null;
3993 }
3994
3995 /**
3996 * This function lets the caller know whether the given component is allowed to start the
3997 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04003998 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04003999 */
Jason Monkd7b86212014-06-16 13:15:38 -04004000 public boolean isLockTaskPermitted(String pkg) {
justinzhang511e0d82014-03-24 16:09:24 -04004001 if (mService != null) {
4002 try {
Jason Monkd7b86212014-06-16 13:15:38 -04004003 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04004004 } catch (RemoteException e) {
4005 Log.w(TAG, "Failed talking with device policy service", e);
4006 }
4007 }
4008 return false;
4009 }
Julia Reynoldsda551652014-05-14 17:15:16 -04004010
4011 /**
4012 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
4013 * 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 -04004014 * <p>The settings that can be updated with this method are:
4015 * <ul>
4016 * <li>{@link Settings.Global#ADB_ENABLED}</li>
4017 * <li>{@link Settings.Global#AUTO_TIME}</li>
4018 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004019 * <li>{@link Settings.Global#DATA_ROAMING}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004020 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004021 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Benjamin Franz68cc4202015-03-11 15:43:06 +00004022 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN}
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004023 * This setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards
Esteban Talavera656fa7f2015-06-29 17:41:39 +01004024 * and can only be set if {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
Zoltan Szatmary-Ban4045d242015-05-27 12:42:39 +01004025 * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004026 * This setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards.
Zoltan Szatmary-Ban3c430952015-07-03 14:04:09 +01004027 * </li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004028 * </ul>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01004029 * <p>Changing the following settings has no effect as of
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004030 * {@link android.os.Build.VERSION_CODES#M}:
Esteban Talavera656fa7f2015-06-29 17:41:39 +01004031 * <ul>
4032 * <li>{@link Settings.Global#BLUETOOTH_ON}.
4033 * Use {@link android.bluetooth.BluetoothAdapter#enable()} and
4034 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
4035 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
4036 * <li>{@link Settings.Global#MODE_RINGER}.
4037 * Use {@link android.media.AudioManager#setRingerMode(int)} instead.</li>
4038 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
4039 * <li>{@link Settings.Global#WIFI_ON}.
4040 * Use {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
4041 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04004042 *
4043 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4044 * @param setting The name of the setting to update.
4045 * @param value The value to update the setting to.
4046 */
Robin Lee25e26452015-06-02 09:56:29 -07004047 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04004048 if (mService != null) {
4049 try {
4050 mService.setGlobalSetting(admin, setting, value);
4051 } catch (RemoteException e) {
4052 Log.w(TAG, "Failed talking with device policy service", e);
4053 }
4054 }
4055 }
4056
4057 /**
4058 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
4059 * that the value of the setting is in the correct form for the setting type should be performed
4060 * by the caller.
Julia Reynolds82735bc2014-09-04 16:43:30 -04004061 * <p>The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004062 * <ul>
4063 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07004064 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004065 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
4066 * </ul>
Julia Reynolds82735bc2014-09-04 16:43:30 -04004067 * <p>A device owner can additionally update the following settings:
4068 * <ul>
4069 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
4070 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04004071 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4072 * @param setting The name of the setting to update.
4073 * @param value The value to update the setting to.
4074 */
Robin Lee25e26452015-06-02 09:56:29 -07004075 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04004076 if (mService != null) {
4077 try {
4078 mService.setSecureSetting(admin, setting, value);
4079 } catch (RemoteException e) {
4080 Log.w(TAG, "Failed talking with device policy service", e);
4081 }
4082 }
4083 }
4084
Amith Yamasanif20d6402014-05-24 15:34:37 -07004085 /**
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004086 * Designates a specific service component as the provider for
Amith Yamasanif20d6402014-05-24 15:34:37 -07004087 * making permission requests of a local or remote administrator of the user.
4088 * <p/>
4089 * Only a profile owner can designate the restrictions provider.
4090 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004091 * @param provider The component name of the service that implements
Amith Yamasanid1d7c022014-08-19 17:03:41 -07004092 * {@link RestrictionsReceiver}. If this param is null,
Amith Yamasanif20d6402014-05-24 15:34:37 -07004093 * it removes the restrictions provider previously assigned.
4094 */
Robin Lee25e26452015-06-02 09:56:29 -07004095 public void setRestrictionsProvider(@NonNull ComponentName admin,
4096 @Nullable ComponentName provider) {
Amith Yamasanif20d6402014-05-24 15:34:37 -07004097 if (mService != null) {
4098 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004099 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07004100 } catch (RemoteException re) {
4101 Log.w(TAG, "Failed to set permission provider on device policy service");
4102 }
4103 }
4104 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04004105
4106 /**
4107 * Called by profile or device owners to set the master volume mute on or off.
4108 *
4109 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4110 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
4111 */
Robin Lee25e26452015-06-02 09:56:29 -07004112 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04004113 if (mService != null) {
4114 try {
4115 mService.setMasterVolumeMuted(admin, on);
4116 } catch (RemoteException re) {
4117 Log.w(TAG, "Failed to setMasterMute on device policy service");
4118 }
4119 }
4120 }
4121
4122 /**
4123 * Called by profile or device owners to check whether the master volume mute is on or off.
4124 *
4125 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4126 * @return {@code true} if master volume is muted, {@code false} if it's not.
4127 */
Robin Lee25e26452015-06-02 09:56:29 -07004128 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04004129 if (mService != null) {
4130 try {
4131 return mService.isMasterVolumeMuted(admin);
4132 } catch (RemoteException re) {
4133 Log.w(TAG, "Failed to get isMasterMute on device policy service");
4134 }
4135 }
4136 return false;
4137 }
Kenny Guyc13053b2014-05-29 14:17:17 +01004138
4139 /**
4140 * Called by profile or device owners to change whether a user can uninstall
4141 * a package.
4142 *
4143 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4144 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004145 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Kenny Guyc13053b2014-05-29 14:17:17 +01004146 */
Robin Lee25e26452015-06-02 09:56:29 -07004147 public void setUninstallBlocked(@NonNull ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004148 boolean uninstallBlocked) {
Kenny Guyc13053b2014-05-29 14:17:17 +01004149 if (mService != null) {
4150 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004151 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01004152 } catch (RemoteException re) {
4153 Log.w(TAG, "Failed to call block uninstall on device policy service");
4154 }
4155 }
4156 }
4157
4158 /**
Rubin Xua97855b2014-11-07 05:41:00 +00004159 * Check whether the current user has been blocked by device policy from uninstalling a package.
4160 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00004161 * <p>
4162 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Robin Lee25e26452015-06-02 09:56:29 -07004163 * behavior of this API is changed such that passing {@code null} as the {@code admin}
Rubin Xue1e6faa2015-03-10 10:51:59 +00004164 * parameter will return if any admin has blocked the uninstallation. Before L MR1, passing
Robin Lee25e26452015-06-02 09:56:29 -07004165 * {@code null} will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01004166 *
Robin Lee25e26452015-06-02 09:56:29 -07004167 * @param admin The name of the admin component whose blocking policy will be checked, or
4168 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01004169 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00004170 * @return true if uninstallation is blocked.
Kenny Guyc13053b2014-05-29 14:17:17 +01004171 */
Robin Lee25e26452015-06-02 09:56:29 -07004172 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Kenny Guyc13053b2014-05-29 14:17:17 +01004173 if (mService != null) {
4174 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01004175 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01004176 } catch (RemoteException re) {
4177 Log.w(TAG, "Failed to call block uninstall on device policy service");
4178 }
4179 }
4180 return false;
4181 }
Svetoslav976e8bd2014-07-16 15:12:03 -07004182
4183 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004184 * Called by the profile owner of a managed profile to enable widget providers from a
4185 * given package to be available in the parent profile. As a result the user will be able to
Svetoslav976e8bd2014-07-16 15:12:03 -07004186 * add widgets from the white-listed package running under the profile to a widget
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004187 * host which runs under the parent profile, for example the home screen. Note that
Svetoslav976e8bd2014-07-16 15:12:03 -07004188 * a package may have zero or more provider components, where each component
4189 * provides a different widget type.
4190 * <p>
4191 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07004192 *
4193 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4194 * @param packageName The package from which widget providers are white-listed.
4195 * @return Whether the package was added.
4196 *
4197 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4198 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4199 */
Robin Lee25e26452015-06-02 09:56:29 -07004200 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004201 if (mService != null) {
4202 try {
4203 return mService.addCrossProfileWidgetProvider(admin, packageName);
4204 } catch (RemoteException re) {
4205 Log.w(TAG, "Error calling addCrossProfileWidgetProvider", re);
4206 }
4207 }
4208 return false;
4209 }
4210
4211 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004212 * Called by the profile owner of a managed profile to disable widget providers from a given
4213 * package to be available in the parent profile. For this method to take effect the
Svetoslav976e8bd2014-07-16 15:12:03 -07004214 * package should have been added via {@link #addCrossProfileWidgetProvider(
4215 * android.content.ComponentName, String)}.
4216 * <p>
4217 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07004218 *
4219 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4220 * @param packageName The package from which widget providers are no longer
4221 * white-listed.
4222 * @return Whether the package was removed.
4223 *
4224 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
4225 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4226 */
Robin Lee25e26452015-06-02 09:56:29 -07004227 public boolean removeCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004228 if (mService != null) {
4229 try {
4230 return mService.removeCrossProfileWidgetProvider(admin, packageName);
4231 } catch (RemoteException re) {
4232 Log.w(TAG, "Error calling removeCrossProfileWidgetProvider", re);
4233 }
4234 }
4235 return false;
4236 }
4237
4238 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004239 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07004240 * available in the parent profile.
4241 *
4242 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4243 * @return The white-listed package list.
4244 *
4245 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
4246 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4247 */
Robin Lee25e26452015-06-02 09:56:29 -07004248 public List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004249 if (mService != null) {
4250 try {
4251 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
4252 if (providers != null) {
4253 return providers;
4254 }
4255 } catch (RemoteException re) {
4256 Log.w(TAG, "Error calling getCrossProfileWidgetProviders", re);
4257 }
4258 }
4259 return Collections.emptyList();
4260 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004261
4262 /**
4263 * Called by profile or device owners to set the current user's photo.
4264 *
4265 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4266 * @param icon the bitmap to set as the photo.
4267 */
Robin Lee25e26452015-06-02 09:56:29 -07004268 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004269 try {
4270 mService.setUserIcon(admin, icon);
4271 } catch (RemoteException re) {
4272 Log.w(TAG, "Could not set the user icon ", re);
4273 }
4274 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04004275
4276 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01004277 * Called by device owners to set a local system update policy. When a new policy is set,
4278 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004279 *
Robin Lee25e26452015-06-02 09:56:29 -07004280 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
4281 * components in the device owner package can set system update policies and the
4282 * most recent policy takes
Rubin Xu5faad8e2015-04-20 17:43:48 +01004283 * effect.
Robin Lee25e26452015-06-02 09:56:29 -07004284 * @param policy the new policy, or {@code null} to clear the current policy.
Rubin Xu5faad8e2015-04-20 17:43:48 +01004285 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00004286 */
Robin Lee25e26452015-06-02 09:56:29 -07004287 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Rubin Xu8027a4f2015-03-10 17:52:37 +00004288 if (mService != null) {
4289 try {
Robin Lee25e26452015-06-02 09:56:29 -07004290 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004291 } catch (RemoteException re) {
Rubin Xu5faad8e2015-04-20 17:43:48 +01004292 Log.w(TAG, "Error calling setSystemUpdatePolicy", re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004293 }
4294 }
4295 }
4296
4297 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01004298 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004299 *
Robin Lee25e26452015-06-02 09:56:29 -07004300 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004301 */
Rubin Xu5faad8e2015-04-20 17:43:48 +01004302 public SystemUpdatePolicy getSystemUpdatePolicy() {
Rubin Xu8027a4f2015-03-10 17:52:37 +00004303 if (mService != null) {
4304 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01004305 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00004306 } catch (RemoteException re) {
Rubin Xu5faad8e2015-04-20 17:43:48 +01004307 Log.w(TAG, "Error calling getSystemUpdatePolicy", re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004308 }
4309 }
4310 return null;
4311 }
Benjamin Franze36087e2015-04-07 16:40:34 +01004312
4313 /**
4314 * Called by a device owner to disable the keyguard altogether.
4315 *
4316 * <p>Setting the keyguard to disabled has the same effect as choosing "None" as the screen
4317 * lock type. However, this call has no effect if a password, pin or pattern is currently set.
4318 * If a password, pin or pattern is set after the keyguard was disabled, the keyguard stops
4319 * being disabled.
4320 *
4321 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01004322 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01004323 *
4324 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Benjamin Franzbece8062015-05-06 12:14:31 +01004325 * place. {@code true} otherwise.
Benjamin Franze36087e2015-04-07 16:40:34 +01004326 */
Robin Lee25e26452015-06-02 09:56:29 -07004327 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franze36087e2015-04-07 16:40:34 +01004328 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01004329 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01004330 } catch (RemoteException re) {
4331 Log.w(TAG, "Failed talking with device policy service", re);
4332 return false;
4333 }
4334 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00004335
4336 /**
Benjamin Franzbece8062015-05-06 12:14:31 +01004337 * Called by device owner to disable the status bar. Disabling the status bar blocks
4338 * notifications, quick settings and other screen overlays that allow escaping from
Benjamin Franzea2ec972015-03-16 17:18:09 +00004339 * a single use device.
4340 *
4341 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01004342 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
4343 *
4344 * @return {@code false} if attempting to disable the status bar failed.
4345 * {@code true} otherwise.
Benjamin Franzea2ec972015-03-16 17:18:09 +00004346 */
Robin Lee25e26452015-06-02 09:56:29 -07004347 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzea2ec972015-03-16 17:18:09 +00004348 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01004349 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00004350 } catch (RemoteException re) {
4351 Log.w(TAG, "Failed talking with device policy service", re);
Benjamin Franzbece8062015-05-06 12:14:31 +01004352 return false;
Benjamin Franzea2ec972015-03-16 17:18:09 +00004353 }
4354 }
Rubin Xudc105cc2015-04-14 23:38:01 +01004355
4356 /**
4357 * Callable by the system update service to notify device owners about pending updates.
4358 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
4359 * permission.
4360 *
4361 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating
4362 * when the current pending update was first available. -1 if no update is available.
4363 * @hide
4364 */
4365 @SystemApi
4366 public void notifyPendingSystemUpdate(long updateReceivedTime) {
4367 if (mService != null) {
4368 try {
4369 mService.notifyPendingSystemUpdate(updateReceivedTime);
4370 } catch (RemoteException re) {
4371 Log.w(TAG, "Could not notify device owner about pending system update", re);
4372 }
4373 }
4374 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04004375
4376 /**
Amith Yamasanid49489b2015-04-28 14:00:26 -07004377 * Called by profile or device owners to set the default response for future runtime permission
4378 * requests by applications. The policy can allow for normal operation which prompts the
4379 * user to grant a permission, or can allow automatic granting or denying of runtime
4380 * permission requests by an application. This also applies to new permissions declared by app
Benjamin Franz45dd6662015-07-08 14:24:14 +01004381 * updates. When a permission is denied or granted this way, the effect is equivalent to setting
4382 * the permission grant state via {@link #setPermissionGrantState}.
4383 *
4384 * <p/>As this policy only acts on runtime permission requests, it only applies to applications
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004385 * built with a {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Benjamin Franz45dd6662015-07-08 14:24:14 +01004386 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07004387 * @param admin Which profile or device owner this request is associated with.
4388 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
4389 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
Benjamin Franz45dd6662015-07-08 14:24:14 +01004390 *
4391 * @see #setPermissionGrantState
Amith Yamasanid49489b2015-04-28 14:00:26 -07004392 */
Robin Lee25e26452015-06-02 09:56:29 -07004393 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004394 try {
4395 mService.setPermissionPolicy(admin, policy);
4396 } catch (RemoteException re) {
4397 Log.w(TAG, "Failed talking with device policy service", re);
4398 }
4399 }
4400
4401 /**
4402 * Returns the current runtime permission policy set by the device or profile owner. The
4403 * default is {@link #PERMISSION_POLICY_PROMPT}.
4404 * @param admin Which profile or device owner this request is associated with.
4405 * @return the current policy for future permission requests.
4406 */
Esteban Talavera28b95702015-06-24 15:23:42 +01004407 public int getPermissionPolicy(ComponentName admin) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004408 try {
4409 return mService.getPermissionPolicy(admin);
4410 } catch (RemoteException re) {
4411 return PERMISSION_POLICY_PROMPT;
4412 }
4413 }
4414
4415 /**
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004416 * Sets the grant state of a runtime permission for a specific application. The state
4417 * can be {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it
4418 * through the UI, {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission
4419 * is denied and the user cannot manage it through the UI, and {@link
4420 * #PERMISSION_GRANT_STATE_GRANTED granted} in which the permission is granted and the
4421 * user cannot manage it through the UI. This might affect all permissions in a
4422 * group that the runtime permission belongs to. This method can only be called
4423 * by a profile or device owner.
4424 *
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07004425 * <p/>Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not
4426 * revoke the permission. It retains the previous grant, if any.
4427 *
4428 * <p/>Permissions can be granted or revoked only for applications built with a
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004429 * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07004430 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07004431 * @param admin Which profile or device owner this request is associated with.
4432 * @param packageName The application to grant or revoke a permission to.
4433 * @param permission The permission to grant or revoke.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004434 * @param grantState The permission grant state which is one of {@link
4435 * #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
4436 * {@link #PERMISSION_GRANT_STATE_GRANTED},
4437 * @return whether the permission was successfully granted or revoked.
4438 *
4439 * @see #PERMISSION_GRANT_STATE_DENIED
4440 * @see #PERMISSION_GRANT_STATE_DEFAULT
4441 * @see #PERMISSION_GRANT_STATE_GRANTED
Amith Yamasanid49489b2015-04-28 14:00:26 -07004442 */
Robin Lee25e26452015-06-02 09:56:29 -07004443 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004444 String permission, int grantState) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004445 try {
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004446 return mService.setPermissionGrantState(admin, packageName, permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07004447 } catch (RemoteException re) {
4448 Log.w(TAG, "Failed talking with device policy service", re);
4449 return false;
4450 }
4451 }
Amith Yamasani184b3752015-05-22 13:00:51 -07004452
4453 /**
4454 * Returns the current grant state of a runtime permission for a specific application.
4455 *
4456 * @param admin Which profile or device owner this request is associated with.
4457 * @param packageName The application to check the grant state for.
4458 * @param permission The permission to check for.
4459 * @return the current grant state specified by device policy. If the profile or device owner
4460 * has not set a grant state, the return value is {@link #PERMISSION_GRANT_STATE_DEFAULT}.
4461 * This does not indicate whether or not the permission is currently granted for the package.
4462 *
4463 * <p/>If a grant state was set by the profile or device owner, then the return value will
4464 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or {@link #PERMISSION_GRANT_STATE_GRANTED},
4465 * which indicates if the permission is currently denied or granted.
4466 *
4467 * @see #setPermissionGrantState(ComponentName, String, String, int)
4468 * @see PackageManager#checkPermission(String, String)
4469 */
Robin Lee25e26452015-06-02 09:56:29 -07004470 public int getPermissionGrantState(@NonNull ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07004471 String permission) {
4472 try {
4473 return mService.getPermissionGrantState(admin, packageName, permission);
4474 } catch (RemoteException re) {
4475 Log.w(TAG, "Failed talking with device policy service", re);
4476 return PERMISSION_GRANT_STATE_DEFAULT;
4477 }
4478 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08004479}