blob: e6484e965ee06df5a589e1103ff5fc0daa1be60e [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;
Jim Millere303bf42014-08-26 17:12:29 -070035import android.os.PersistableBundle;
Adam Connors776c5552014-01-09 10:42:56 +000036import android.os.Process;
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080037import android.os.RemoteCallback;
Dianne Hackbornd6847842010-01-12 18:14:19 -080038import android.os.RemoteException;
39import android.os.ServiceManager;
Amith Yamasani599dd7c2012-09-14 23:20:08 -070040import android.os.UserHandle;
Julia Reynolds1e958392014-05-16 14:25:21 -040041import android.os.UserManager;
Julia Reynoldsda551652014-05-14 17:15:16 -040042import android.provider.Settings;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010043import android.security.Credentials;
Amith Yamasanid1d7c022014-08-19 17:03:41 -070044import android.service.restrictions.RestrictionsReceiver;
Dianne Hackbornd6847842010-01-12 18:14:19 -080045import android.util.Log;
46
Makoto Onukicc4bbeb2015-09-17 10:28:24 -070047import com.android.internal.annotations.VisibleForTesting;
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
Makoto Onukicc4bbeb2015-09-17 10:28:24 -070090 private DevicePolicyManager(Context context) {
91 this(context, IDevicePolicyManager.Stub.asInterface(
92 ServiceManager.getService(Context.DEVICE_POLICY_SERVICE)));
Dianne Hackbornd6847842010-01-12 18:14:19 -080093 }
94
Dianne Hackborn87bba1e2010-02-26 17:25:54 -080095 /** @hide */
Makoto Onukicc4bbeb2015-09-17 10:28:24 -070096 @VisibleForTesting
97 protected DevicePolicyManager(Context context, IDevicePolicyManager service) {
98 mContext = context;
99 mService = service;
100 }
101
102 /** @hide */
103 public static DevicePolicyManager create(Context context) {
104 DevicePolicyManager me = new DevicePolicyManager(context);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800105 return me.mService != null ? me : null;
106 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700107
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700108 /** @hide test will override it. */
109 @VisibleForTesting
110 protected int myUserId() {
111 return UserHandle.myUserId();
112 }
113
Dianne Hackbornd6847842010-01-12 18:14:19 -0800114 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +0000115 * Activity action: Starts the provisioning flow which sets up a managed profile.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000116 *
Jessica Hummel9da60392014-05-21 12:32:57 +0100117 * <p>A managed profile allows data separation for example for the usage of a
118 * device as a personal and corporate device. The user which provisioning is started from and
119 * the managed profile share a launcher.
120 *
Andrew Solovay27f53372015-03-02 16:37:59 -0800121 * <p>This intent will typically be sent by a mobile device management application (MDM).
122 * Provisioning adds a managed profile and sets the MDM as the profile owner who has full
123 * control over the profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100124 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000125 * In version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this intent must contain the
126 * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700127 * As of {@link android.os.Build.VERSION_CODES#M}, it should contain the extra
Nicolas Prevot18440252015-03-09 14:07:17 +0000128 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only
129 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000130 *
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000131 * <p> When managed provisioning has completed, broadcasts are sent to the application specified
132 * in the provisioning intent. The
133 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the
134 * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in
135 * the primary profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100136 *
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100137 * <p> If provisioning fails, the managedProfile is removed so the device returns to its
138 * previous state.
Alan Treadway4582f812015-07-28 11:49:35 +0100139 *
140 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
141 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
142 * the provisioning flow was successful, although this doesn't guarantee the full flow will
143 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
144 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000145 */
146 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
147 public static final String ACTION_PROVISION_MANAGED_PROFILE
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100148 = "android.app.action.PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000149
150 /**
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100151 * Activity action: Starts the provisioning flow which sets up a managed device.
152 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
153 *
154 * <p> During device owner provisioning a device admin app is set as the owner of the device.
155 * A device owner has full control over the device. The device owner can not be modified by the
156 * user.
157 *
158 * <p> A typical use case would be a device that is owned by a company, but used by either an
159 * employee or client.
160 *
161 * <p> An intent with this action can be sent only on an unprovisioned device.
162 * It is possible to check if the device is provisioned or not by looking at
163 * {@link android.provider.Settings.Global#DEVICE_PROVISIONED}
164 *
165 * The intent contains the following extras:
166 * <ul>
167 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
168 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
169 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
Rubin Xua4f9dc12015-06-12 13:27:59 +0100170 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100171 * </ul>
172 *
173 * <p> When device owner provisioning has completed, an intent of the type
174 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
175 * device owner.
176 *
177 * <p> If provisioning fails, the device is factory reset.
178 *
Alan Treadway4582f812015-07-28 11:49:35 +0100179 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
180 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
181 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
182 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100183 */
184 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
185 public static final String ACTION_PROVISION_MANAGED_DEVICE
186 = "android.app.action.PROVISION_MANAGED_DEVICE";
187
188 /**
Rubin Xua4f9dc12015-06-12 13:27:59 +0100189 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100190 * allows a mobile device management application or NFC programmer application which starts
191 * managed provisioning to pass data to the management application instance after provisioning.
Rubin Xua4f9dc12015-06-12 13:27:59 +0100192 * <p>
193 * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that
194 * sends the intent to pass data to itself on the newly created profile.
195 * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same
196 * instance of the app on the primary user.
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100197 * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with
198 * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC
199 * message should contain a stringified {@link java.util.Properties} instance, whose string
200 * properties will be converted into a {@link android.os.PersistableBundle} and passed to the
201 * management application after provisioning.
202 *
Rubin Xua4f9dc12015-06-12 13:27:59 +0100203 * <p>
204 * In both cases the application receives the data in
Brian Carlstromf1fe51b2014-09-03 08:55:05 -0700205 * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action
206 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed
Rubin Xua4f9dc12015-06-12 13:27:59 +0100207 * during the managed provisioning.
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100208 */
209 public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE =
Esteban Talavera37f01842014-09-05 10:50:57 +0100210 "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE";
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100211
212 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100213 * A String extra holding the package name of the mobile device management application that
214 * will be set as the profile owner or device owner.
215 *
216 * <p>If an application starts provisioning directly via an intent with action
217 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
218 * application that started provisioning. The package will be set as profile owner in that case.
219 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000220 * <p>This package is set as device owner when device owner provisioning is started by an NFC
221 * message containing an NFC record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000222 *
223 * <p> When this extra is set, the application must have exactly one device admin receiver.
Robin Lee25e26452015-06-02 09:56:29 -0700224 * This receiver will be set as the profile or device owner and active admin.
Nicolas Prevot18440252015-03-09 14:07:17 +0000225
226 * @see DeviceAdminReceiver
227 * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still
Nicolas Prevot8f78d6a2015-08-21 11:06:31 +0100228 * supported, but only if there is only one device admin receiver in the package that requires
229 * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000230 */
Nicolas Prevot18440252015-03-09 14:07:17 +0000231 @Deprecated
Jessica Hummelf72078b2014-03-06 16:13:12 +0000232 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100233 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000234
235 /**
Nicolas Prevot18440252015-03-09 14:07:17 +0000236 * A ComponentName extra indicating the device admin receiver of the mobile device management
237 * application that will be set as the profile owner or device owner and active admin.
238 *
239 * <p>If an application starts provisioning directly via an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100240 * {@link #ACTION_PROVISION_MANAGED_PROFILE} or
241 * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this
242 * component has to match the package name of the application that started provisioning.
Nicolas Prevot18440252015-03-09 14:07:17 +0000243 *
244 * <p>This component is set as device owner and active admin when device owner provisioning is
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100245 * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC
246 * message containing an NFC record with MIME type
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400247 * {@link #MIME_TYPE_PROVISIONING_NFC}. For the NFC record, the component name should be
Rubin Xu44ef750b2015-03-23 16:51:33 +0000248 * flattened to a string, via {@link ComponentName#flattenToShortString()}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000249 *
250 * @see DeviceAdminReceiver
251 */
252 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME
253 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME";
254
255 /**
Alexandra Gherghinaaaf2f3e2014-11-13 12:46:15 +0000256 * An {@link android.accounts.Account} extra holding the account to migrate during managed
257 * profile provisioning. If the account supplied is present in the primary user, it will be
258 * copied, along with its credentials to the managed profile and removed from the primary user.
259 *
260 * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}.
261 */
262
263 public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE
264 = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE";
265
266 /**
Jessica Hummele3da7902014-08-20 15:20:11 +0100267 * A String extra that, holds the email address of the account which a managed profile is
268 * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
269 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100270 *
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100271 * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}.
272 *
Jessica Hummele3da7902014-08-20 15:20:11 +0100273 * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning
274 * contains this extra, it is forwarded in the
275 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile
276 * device management application that was set as the profile owner during provisioning.
277 * It is usually used to avoid that the user has to enter their email address twice.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100278 */
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100279 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
280 = "android.app.extra.PROVISIONING_EMAIL_ADDRESS";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100281
282 /**
Sander Alewijnse8c411562014-11-12 18:03:11 +0000283 * A Boolean extra that can be used by the mobile device management application to skip the
Robin Lee25e26452015-06-02 09:56:29 -0700284 * disabling of system apps during provisioning when set to {@code true}.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000285 *
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100286 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
287 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000288 */
Sander Alewijnse5a144252014-11-18 13:25:04 +0000289 public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED =
290 "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED";
Sander Alewijnse8c411562014-11-12 18:03:11 +0000291
292 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100293 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
294 * will be set to.
295 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000296 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
297 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100298 */
299 public static final String EXTRA_PROVISIONING_TIME_ZONE
Esteban Talavera37f01842014-09-05 10:50:57 +0100300 = "android.app.extra.PROVISIONING_TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100301
302 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100303 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
304 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100305 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000306 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
307 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100308 */
309 public static final String EXTRA_PROVISIONING_LOCAL_TIME
Esteban Talavera37f01842014-09-05 10:50:57 +0100310 = "android.app.extra.PROVISIONING_LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100311
312 /**
313 * A String extra holding the {@link java.util.Locale} that the device will be set to.
314 * Format: xx_yy, where xx is the language code, and yy the country code.
315 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000316 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
317 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100318 */
319 public static final String EXTRA_PROVISIONING_LOCALE
Esteban Talavera37f01842014-09-05 10:50:57 +0100320 = "android.app.extra.PROVISIONING_LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100321
322 /**
323 * A String extra holding the ssid of the wifi network that should be used during nfc device
324 * owner provisioning for downloading the mobile device management application.
325 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000326 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
327 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100328 */
329 public static final String EXTRA_PROVISIONING_WIFI_SSID
Esteban Talavera37f01842014-09-05 10:50:57 +0100330 = "android.app.extra.PROVISIONING_WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100331
332 /**
333 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
334 * is hidden or not.
335 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000336 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
337 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100338 */
339 public static final String EXTRA_PROVISIONING_WIFI_HIDDEN
Esteban Talavera37f01842014-09-05 10:50:57 +0100340 = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100341
342 /**
343 * A String extra indicating the security type of the wifi network in
344 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
345 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000346 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
347 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100348 */
349 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
Esteban Talavera37f01842014-09-05 10:50:57 +0100350 = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100351
352 /**
353 * A String extra holding the password of the wifi network in
354 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
355 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000356 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
357 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100358 */
359 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talavera37f01842014-09-05 10:50:57 +0100360 = "android.app.extra.PROVISIONING_WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100361
362 /**
363 * A String extra holding the proxy host for the wifi network in
364 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
365 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000366 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
367 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100368 */
369 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
Esteban Talavera37f01842014-09-05 10:50:57 +0100370 = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100371
372 /**
373 * An int extra holding the proxy port for the wifi network in
374 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
375 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000376 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
377 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100378 */
379 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
Esteban Talavera37f01842014-09-05 10:50:57 +0100380 = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100381
382 /**
383 * A String extra holding the proxy bypass for the wifi network in
384 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
385 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000386 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
387 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100388 */
389 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
Esteban Talavera37f01842014-09-05 10:50:57 +0100390 = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100391
392 /**
393 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
394 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
395 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000396 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
397 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100398 */
399 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
Esteban Talavera37f01842014-09-05 10:50:57 +0100400 = "android.app.extra.PROVISIONING_WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100401
402 /**
403 * A String extra holding a url that specifies the download location of the device admin
404 * package. When not provided it is assumed that the device admin package is already installed.
405 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000406 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
407 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100408 */
409 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talavera37f01842014-09-05 10:50:57 +0100410 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100411
412 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400413 * An int extra holding a minimum required version code for the device admin package. If the
414 * device admin is already installed on the device, it will only be re-downloaded from
415 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the
416 * installed package is less than this version code.
417 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400418 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400419 * provisioning via an NFC bump.
420 */
421 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE
422 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE";
423
424 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100425 * A String extra holding a http cookie header which should be used in the http request to the
426 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
427 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000428 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
429 * provisioning via an NFC bump.
Sander Alewijnse681bce92014-07-24 16:46:26 +0100430 */
431 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talavera37f01842014-09-05 10:50:57 +0100432 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100433
434 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100435 * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of
436 * the file at download location specified in
437 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100438 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100439 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} should be
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100440 * present. The provided checksum should match the checksum of the file at the download
441 * location. If the checksum doesn't match an error will be shown to the user and the user will
442 * be asked to factory reset the device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100443 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000444 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
445 * provisioning via an NFC bump.
Rubin Xud92e7572015-05-18 17:01:13 +0100446 *
447 * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP}
448 * and {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1} only SHA-1 hash is supported.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700449 * Starting from {@link android.os.Build.VERSION_CODES#M}, this parameter accepts SHA-256 in
Rubin Xud92e7572015-05-18 17:01:13 +0100450 * addition to SHA-1. Support for SHA-1 is likely to be removed in future OS releases.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100451 */
452 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100453 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100454
455 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100456 * A String extra holding the URL-safe base64 encoded SHA-256 checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100457 * android package archive at the download location specified in {@link
458 * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
459 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100460 * <p>The signatures of an android package archive can be obtained using
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100461 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
462 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
463 *
464 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} should be
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100465 * present. The provided checksum should match the checksum of any signature of the file at
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100466 * the download location. If the checksum does not match an error will be shown to the user and
467 * the user will be asked to factory reset the device.
468 *
469 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
470 * provisioning via an NFC bump.
471 */
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100472 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM
473 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM";
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100474
475 /**
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000476 * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile
477 * has completed successfully.
478 *
479 * <p>The broadcast is limited to the primary profile, to the app specified in the provisioning
Nicolas Prevotebe2d992015-05-12 18:14:53 -0700480 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000481 *
Ying Wang7f38aab2015-02-20 11:50:09 -0800482 * <p>This intent will contain the extra {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE} which
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000483 * corresponds to the account requested to be migrated at provisioning time, if any.
484 */
485 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
486 public static final String ACTION_MANAGED_PROFILE_PROVISIONED
487 = "android.app.action.MANAGED_PROFILE_PROVISIONED";
488
489 /**
Julia Reynolds2f46d942015-05-05 11:44:20 -0400490 * A boolean extra indicating whether device encryption can be skipped as part of Device Owner
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500491 * provisioning.
492 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400493 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100494 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500495 */
496 public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION =
497 "android.app.extra.PROVISIONING_SKIP_ENCRYPTION";
498
499 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -0400500 * @hide
Rubin Xu44ef750b2015-03-23 16:51:33 +0000501 * On devices managed by a device owner app, a {@link ComponentName} extra indicating the
502 * component of the application that is temporarily granted device owner privileges during
503 * device initialization and profile owner privileges during secondary user initialization.
Julia Reynolds20118f12015-02-11 12:34:08 -0500504 *
Rubin Xu44ef750b2015-03-23 16:51:33 +0000505 * <p>
Rubin Xu6a38e432015-03-26 14:47:45 +0000506 * 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 +0000507 * device owner provisioning via an NFC bump. For the NFC record, it should be flattened to a
508 * string first.
509 *
510 * @see ComponentName#flattenToShortString()
Julia Reynolds20118f12015-02-11 12:34:08 -0500511 */
512 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_COMPONENT_NAME
513 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_COMPONENT_NAME";
514
515 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -0400516 * @hide
Julia Reynolds20118f12015-02-11 12:34:08 -0500517 * A String extra holding an http url that specifies the download location of the device
518 * initializer package. When not provided it is assumed that the device initializer package is
519 * already installed.
520 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400521 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynolds20118f12015-02-11 12:34:08 -0500522 * provisioning via an NFC bump.
523 */
524 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION
525 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION";
526
527 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -0400528 * @hide
Julia Reynoldsc1731742015-03-19 14:56:28 -0400529 * An int extra holding a minimum required version code for the device initializer package.
530 * If the initializer is already installed on the device, it will only be re-downloaded from
531 * {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION} if the version of
532 * the installed package is less than this version code.
533 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400534 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400535 * provisioning via an NFC bump.
536 */
537 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_MINIMUM_VERSION_CODE
538 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_MINIMUM_VERSION_CODE";
539
540 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -0400541 * @hide
Julia Reynolds20118f12015-02-11 12:34:08 -0500542 * A String extra holding a http cookie header which should be used in the http request to the
543 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION}.
544 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400545 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynolds20118f12015-02-11 12:34:08 -0500546 * provisioning via an NFC bump.
547 */
548 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_COOKIE_HEADER
549 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_COOKIE_HEADER";
550
551 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -0400552 * @hide
Rubin Xud92e7572015-05-18 17:01:13 +0100553 * A String extra holding the URL-safe base64 encoded SHA-256 checksum of the file at download
Rubin Xue30ab112015-03-24 11:22:28 +0000554 * location specified in
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100555 * {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION}.
556 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100557 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_SIGNATURE_CHECKSUM}
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100558 * should be present. The provided checksum should match the checksum of the file at the
559 * download location. If the checksum doesn't match an error will be shown to the user and the
560 * user will be asked to factory reset the device.
Julia Reynolds20118f12015-02-11 12:34:08 -0500561 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400562 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynolds20118f12015-02-11 12:34:08 -0500563 * provisioning via an NFC bump.
564 */
565 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM
566 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM";
567
568 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -0400569 * @hide
Rubin Xud92e7572015-05-18 17:01:13 +0100570 * A String extra holding the URL-safe base64 encoded SHA-256 checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100571 * android package archive at the download location specified in {@link
572 * #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION}.
573 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100574 * <p>The signatures of an android package archive can be obtained using
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100575 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
576 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
577 *
578 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM}
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100579 * should be present. The provided checksum should match the checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100580 * file at the download location. If the checksum doesn't match an error will be shown to the
581 * user and the user will be asked to factory reset the device.
582 *
583 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
584 * provisioning via an NFC bump.
585 */
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100586 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_SIGNATURE_CHECKSUM
587 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_SIGNATURE_CHECKSUM";
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100588
589 /**
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400590 * This MIME type is used for starting the Device Owner provisioning.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100591 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400592 * <p>During device owner provisioning a device admin app is set as the owner of the device.
593 * A device owner has full control over the device. The device owner can not be modified by the
594 * user and the only way of resetting the device is if the device owner app calls a factory
595 * reset.
596 *
597 * <p> A typical use case would be a device that is owned by a company, but used by either an
598 * employee or client.
599 *
600 * <p> The NFC message should be send to an unprovisioned device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100601 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000602 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100603 * contains the following properties:
604 * <ul>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400605 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
606 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100607 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400608 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100609 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
610 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
611 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
612 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
613 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
614 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
615 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
616 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
617 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
618 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100619 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
620 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from
621 * {@link android.os.Build.VERSION_CODES#M} </li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100622 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000623 * <p>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700624 * As of {@link android.os.Build.VERSION_CODES#M}, the properties should contain
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400625 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of
626 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only
627 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400628 */
629 public static final String MIME_TYPE_PROVISIONING_NFC
630 = "application/com.android.managedprovisioning";
631
632
633 /**
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400634 * @hide
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400635 * This MIME type is used for starting the Device Owner provisioning that requires
636 * new provisioning features introduced in API version
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700637 * {@link android.os.Build.VERSION_CODES#M} in addition to those supported in earlier
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400638 * versions.
639 *
640 * <p>During device owner provisioning a device admin app is set as the owner of the device.
641 * 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 +0100642 * user.
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400643 *
644 * <p> A typical use case would be a device that is owned by a company, but used by either an
645 * employee or client.
646 *
647 * <p> The NFC message should be sent to an unprovisioned device.
648 *
649 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
650 * contains the following properties in addition to properties listed at
651 * {@link #MIME_TYPE_PROVISIONING_NFC}:
652 * <ul>
653 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400654 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}.
655 * Replaces {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}. The value of the property
656 * should be converted to a String via
657 * {@link android.content.ComponentName#flattenToString()}</li>
Craig Lafayette240e6482015-06-02 11:12:43 -0400658 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE}, optional</li></ul>
Nicolas Prevot18440252015-03-09 14:07:17 +0000659 *
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100660 * <p> When device owner provisioning has completed, an intent of the type
661 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcasted to the
662 * device owner.
663 *
664 * <p>
665 * If provisioning fails, the device is factory reset.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100666 */
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400667 public static final String MIME_TYPE_PROVISIONING_NFC_V2
668 = "application/com.android.managedprovisioning.v2";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100669
670 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800671 * Activity action: ask the user to add a new device administrator to the system.
672 * The desired policy is the ComponentName of the policy in the
673 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
674 * bring the user through adding the device administrator to the system (or
675 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700676 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800677 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
678 * field to provide the user with additional explanation (in addition
679 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800680 *
681 * <p>If your administrator is already active, this will ordinarily return immediately (without
682 * user intervention). However, if your administrator has been updated and is requesting
683 * additional uses-policy flags, the user will be presented with the new list. New policies
684 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800685 */
686 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
687 public static final String ACTION_ADD_DEVICE_ADMIN
688 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700689
Dianne Hackbornd6847842010-01-12 18:14:19 -0800690 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700691 * @hide
692 * Activity action: ask the user to add a new device administrator as the profile owner
Amith Yamasani814e9872015-03-23 14:04:53 -0700693 * for this user. Only system apps can launch this intent.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700694 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700695 * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN}
696 * extra field. This will invoke a UI to bring the user through adding the profile owner admin
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700697 * to remotely control restrictions on the user.
698 *
699 * <p>The intent must be invoked via {@link Activity#startActivityForResult()} to receive the
700 * result of whether or not the user approved the action. If approved, the result will
701 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
702 * as a profile owner.
703 *
704 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
705 * field to provide the user with additional explanation (in addition
706 * to your component's description) about what is being added.
707 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700708 * <p>If there is already a profile owner active or the caller is not a system app, the
709 * operation will return a failure result.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700710 */
711 @SystemApi
712 public static final String ACTION_SET_PROFILE_OWNER
713 = "android.app.action.SET_PROFILE_OWNER";
714
715 /**
716 * @hide
717 * Name of the profile owner admin that controls the user.
718 */
719 @SystemApi
720 public static final String EXTRA_PROFILE_OWNER_NAME
721 = "android.app.extra.PROFILE_OWNER_NAME";
722
723 /**
Nicolas Prevot00799002015-07-27 18:15:20 +0100724 * Broadcast action: send when any policy admin changes a policy.
Jim Miller284b62e2010-06-08 14:27:42 -0700725 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700726 *
Jim Miller284b62e2010-06-08 14:27:42 -0700727 * @hide
728 */
729 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
730 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
731
732 /**
Nicolas Prevot00799002015-07-27 18:15:20 +0100733 * Broadcast action: sent when the device owner is set or changed.
734 *
735 * This broadcast is sent only to the primary user.
736 * @see #ACTION_PROVISION_MANAGED_DEVICE
737 */
738 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
739 public static final String ACTION_DEVICE_OWNER_CHANGED
740 = "android.app.action.DEVICE_OWNER_CHANGED";
741
742 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800743 * The ComponentName of the administrator component.
744 *
745 * @see #ACTION_ADD_DEVICE_ADMIN
746 */
747 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700748
Dianne Hackbornd6847842010-01-12 18:14:19 -0800749 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800750 * An optional CharSequence providing additional explanation for why the
751 * admin is being added.
752 *
753 * @see #ACTION_ADD_DEVICE_ADMIN
754 */
755 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700756
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800757 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700758 * Activity action: have the user enter a new password. This activity should
759 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
760 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
761 * enter a new password that meets the current requirements. You can use
762 * {@link #isActivePasswordSufficient()} to determine whether you need to
763 * have the user select a new password in order to meet the current
764 * constraints. Upon being resumed from this activity, you can check the new
765 * password characteristics to see if they are sufficient.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800766 */
767 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
768 public static final String ACTION_SET_NEW_PASSWORD
769 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700770
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000771 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000772 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
773 * the parent profile to access intents sent from the managed profile.
774 * That is, when an app in the managed profile calls
775 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
776 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000777 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100778 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000779
780 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000781 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
782 * the managed profile to access intents sent from the parent profile.
783 * That is, when an app in the parent profile calls
784 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
785 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000786 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100787 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700788
Dianne Hackbornd6847842010-01-12 18:14:19 -0800789 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +0100790 * Broadcast action: notify that a new local system update policy has been set by the device
791 * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}.
Rubin Xu8027a4f2015-03-10 17:52:37 +0000792 */
793 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Rubin Xu5faad8e2015-04-20 17:43:48 +0100794 public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED
795 = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED";
Rubin Xu8027a4f2015-03-10 17:52:37 +0000796
Amith Yamasanid49489b2015-04-28 14:00:26 -0700797 /**
798 * Permission policy to prompt user for 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_PROMPT = 0;
802
803 /**
804 * Permission policy to always grant new permission requests for runtime permissions.
805 * Already granted or denied permissions are not affected by this.
806 */
807 public static final int PERMISSION_POLICY_AUTO_GRANT = 1;
808
809 /**
810 * Permission policy to always deny new permission requests for runtime permissions.
811 * Already granted or denied permissions are not affected by this.
812 */
813 public static final int PERMISSION_POLICY_AUTO_DENY = 2;
814
Svet Ganovd8ecc5a2015-05-20 10:45:43 -0700815 /**
816 * Runtime permission state: The user can manage the permission
817 * through the UI.
818 */
819 public static final int PERMISSION_GRANT_STATE_DEFAULT = 0;
820
821 /**
822 * Runtime permission state: The permission is granted to the app
823 * and the user cannot manage the permission through the UI.
824 */
825 public static final int PERMISSION_GRANT_STATE_GRANTED = 1;
826
827 /**
828 * Runtime permission state: The permission is denied to the app
829 * and the user cannot manage the permission through the UI.
830 */
831 public static final int PERMISSION_GRANT_STATE_DENIED = 2;
Rubin Xu8027a4f2015-03-10 17:52:37 +0000832
833 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800834 * Return true if the given administrator component is currently
835 * active (enabled) in the system.
836 */
Robin Lee25e26452015-06-02 09:56:29 -0700837 public boolean isAdminActive(@NonNull ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700838 return isAdminActiveAsUser(admin, myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100839 }
840
841 /**
842 * @see #isAdminActive(ComponentName)
843 * @hide
844 */
Robin Lee25e26452015-06-02 09:56:29 -0700845 public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800846 if (mService != null) {
847 try {
Robin Lee25e26452015-06-02 09:56:29 -0700848 return mService.isAdminActive(admin, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800849 } catch (RemoteException e) {
850 Log.w(TAG, "Failed talking with device policy service", e);
851 }
852 }
853 return false;
854 }
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800855 /**
856 * Return true if the given administrator component is currently being removed
857 * for the user.
858 * @hide
859 */
Robin Lee25e26452015-06-02 09:56:29 -0700860 public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) {
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800861 if (mService != null) {
862 try {
Robin Lee25e26452015-06-02 09:56:29 -0700863 return mService.isRemovingAdmin(admin, userId);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800864 } catch (RemoteException e) {
865 Log.w(TAG, "Failed talking with device policy service", e);
866 }
867 }
868 return false;
869 }
870
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700871
Dianne Hackbornd6847842010-01-12 18:14:19 -0800872 /**
Robin Lee25e26452015-06-02 09:56:29 -0700873 * Return a list of all currently active device administrators' component
874 * names. If there are no administrators {@code null} may be
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800875 * returned.
876 */
877 public List<ComponentName> getActiveAdmins() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700878 return getActiveAdminsAsUser(myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100879 }
880
881 /**
882 * @see #getActiveAdmins()
883 * @hide
884 */
885 public List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800886 if (mService != null) {
887 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100888 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800889 } catch (RemoteException e) {
890 Log.w(TAG, "Failed talking with device policy service", e);
891 }
892 }
893 return null;
894 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700895
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800896 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700897 * Used by package administration code to determine if a package can be stopped
898 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800899 * @hide
900 */
901 public boolean packageHasActiveAdmins(String packageName) {
902 if (mService != null) {
903 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700904 return mService.packageHasActiveAdmins(packageName, myUserId());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800905 } catch (RemoteException e) {
906 Log.w(TAG, "Failed talking with device policy service", e);
907 }
908 }
909 return false;
910 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700911
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800912 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800913 * Remove a current administration component. This can only be called
914 * by the application that owns the administration component; if you
915 * try to remove someone else's component, a security exception will be
916 * thrown.
917 */
Robin Lee25e26452015-06-02 09:56:29 -0700918 public void removeActiveAdmin(@NonNull ComponentName admin) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800919 if (mService != null) {
920 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700921 mService.removeActiveAdmin(admin, myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800922 } catch (RemoteException e) {
923 Log.w(TAG, "Failed talking with device policy service", e);
924 }
925 }
926 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700927
Dianne Hackbornd6847842010-01-12 18:14:19 -0800928 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800929 * Returns true if an administrator has been granted a particular device policy. This can
Robin Lee25e26452015-06-02 09:56:29 -0700930 * be used to check whether the administrator was activated under an earlier set of policies,
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800931 * but requires additional policies after an upgrade.
932 *
933 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be
934 * an active administrator, or an exception will be thrown.
935 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
936 */
Robin Lee25e26452015-06-02 09:56:29 -0700937 public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) {
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800938 if (mService != null) {
939 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700940 return mService.hasGrantedPolicy(admin, usesPolicy, myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800941 } catch (RemoteException e) {
942 Log.w(TAG, "Failed talking with device policy service", e);
943 }
944 }
945 return false;
946 }
947
948 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800949 * Constant for {@link #setPasswordQuality}: the policy has no requirements
950 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800951 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800952 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800953 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700954
Dianne Hackbornd6847842010-01-12 18:14:19 -0800955 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700956 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
957 * recognition technology. This implies technologies that can recognize the identity of
958 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
959 * Note that quality constants are ordered so that higher values are more restrictive.
960 */
961 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
962
963 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800964 * Constant for {@link #setPasswordQuality}: the policy requires some kind
Benjamin Franzc6a96532015-06-16 11:23:38 +0100965 * of password or pattern, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800966 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800967 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800968 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700969
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800970 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800971 * Constant for {@link #setPasswordQuality}: the user must have entered a
972 * password containing at least numeric characters. Note that quality
973 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800974 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800975 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700976
Dianne Hackbornd6847842010-01-12 18:14:19 -0800977 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800978 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -0800979 * password containing at least numeric characters with no repeating (4444)
980 * or ordered (1234, 4321, 2468) sequences. Note that quality
981 * constants are ordered so that higher values are more restrictive.
982 */
983 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
984
985 /**
986 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700987 * password containing at least alphabetic (or other symbol) characters.
988 * Note that quality constants are ordered so that higher values are more
989 * restrictive.
990 */
991 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700992
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700993 /**
994 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800995 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700996 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800997 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800998 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700999 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001000
Dianne Hackbornd6847842010-01-12 18:14:19 -08001001 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001002 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001003 * password containing at least a letter, a numerical digit and a special
1004 * symbol, by default. With this password quality, passwords can be
1005 * restricted to contain various sets of characters, like at least an
1006 * uppercase letter, etc. These are specified using various methods,
1007 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
1008 * that quality constants are ordered so that higher values are more
1009 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001010 */
1011 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
1012
1013 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001014 * Called by an application that is administering the device to set the
1015 * password restrictions it is imposing. After setting this, the user
1016 * will not be able to enter a new password that is not at least as
1017 * restrictive as what has been set. Note that the current password
1018 * will remain until the user has set a new one, so the change does not
1019 * take place immediately. To prompt the user for a new password, use
1020 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001021 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001022 * <p>Quality constants are ordered so that higher values are more restrictive;
1023 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001024 * the user's preference, and any other considerations) is the one that
1025 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001026 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001027 * <p>The calling device admin must have requested
1028 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1029 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001030 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001031 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001032 * @param quality The new desired quality. One of
1033 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Jim Miller85516d02014-01-31 17:08:37 -08001034 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
1035 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1036 * or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001037 */
Robin Lee25e26452015-06-02 09:56:29 -07001038 public void setPasswordQuality(@NonNull ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001039 if (mService != null) {
1040 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001041 mService.setPasswordQuality(admin, quality);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001042 } catch (RemoteException e) {
1043 Log.w(TAG, "Failed talking with device policy service", e);
1044 }
1045 }
1046 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001047
Dianne Hackbornd6847842010-01-12 18:14:19 -08001048 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001049 * Retrieve the current minimum password quality for all admins of this user
1050 * and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001051 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001052 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001053 */
Robin Lee25e26452015-06-02 09:56:29 -07001054 public int getPasswordQuality(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001055 return getPasswordQuality(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001056 }
1057
1058 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001059 public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001060 if (mService != null) {
1061 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001062 return mService.getPasswordQuality(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001063 } catch (RemoteException e) {
1064 Log.w(TAG, "Failed talking with device policy service", e);
1065 }
1066 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001067 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001068 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001069
Dianne Hackbornd6847842010-01-12 18:14:19 -08001070 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001071 * Called by an application that is administering the device to set the
1072 * minimum allowed password length. After setting this, the user
1073 * will not be able to enter a new password that is not at least as
1074 * restrictive as what has been set. Note that the current password
1075 * will remain until the user has set a new one, so the change does not
1076 * take place immediately. To prompt the user for a new password, use
1077 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1078 * constraint is only imposed if the administrator has also requested either
Jim Miller85516d02014-01-31 17:08:37 -08001079 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
1080 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC},
1081 * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001082 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001083 * <p>The calling device admin must have requested
1084 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1085 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001086 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001087 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001088 * @param length The new desired minimum password length. A value of 0
1089 * means there is no restriction.
1090 */
Robin Lee25e26452015-06-02 09:56:29 -07001091 public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001092 if (mService != null) {
1093 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001094 mService.setPasswordMinimumLength(admin, length);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001095 } catch (RemoteException e) {
1096 Log.w(TAG, "Failed talking with device policy service", e);
1097 }
1098 }
1099 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001100
Dianne Hackbornd6847842010-01-12 18:14:19 -08001101 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001102 * Retrieve the current minimum password length for all admins of this
1103 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001104 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001105 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001106 */
Robin Lee25e26452015-06-02 09:56:29 -07001107 public int getPasswordMinimumLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001108 return getPasswordMinimumLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001109 }
1110
1111 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001112 public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001113 if (mService != null) {
1114 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001115 return mService.getPasswordMinimumLength(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001116 } catch (RemoteException e) {
1117 Log.w(TAG, "Failed talking with device policy service", e);
1118 }
1119 }
1120 return 0;
1121 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001122
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001123 /**
1124 * Called by an application that is administering the device to set the
1125 * minimum number of upper case letters required in the password. After
1126 * setting this, the user will not be able to enter a new password that is
1127 * not at least as restrictive as what has been set. Note that the current
1128 * password will remain until the user has set a new one, so the change does
1129 * not take place immediately. To prompt the user for a new password, use
1130 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1131 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001132 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1133 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001134 * <p>
1135 * The calling device admin must have requested
1136 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1137 * this method; if it has not, a security exception will be thrown.
1138 *
1139 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1140 * with.
1141 * @param length The new desired minimum number of upper case letters
1142 * required in the password. A value of 0 means there is no
1143 * restriction.
1144 */
Robin Lee25e26452015-06-02 09:56:29 -07001145 public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001146 if (mService != null) {
1147 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001148 mService.setPasswordMinimumUpperCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001149 } catch (RemoteException e) {
1150 Log.w(TAG, "Failed talking with device policy service", e);
1151 }
1152 }
1153 }
1154
1155 /**
1156 * Retrieve the current number of upper case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001157 * password for all admins of this user and its profiles or a particular one.
1158 * This is the same value as set by
1159 * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001160 * and only applies when the password quality is
1161 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001162 *
Robin Lee25e26452015-06-02 09:56:29 -07001163 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001164 * aggregate all admins.
1165 * @return The minimum number of upper case letters required in the
1166 * password.
1167 */
Robin Lee25e26452015-06-02 09:56:29 -07001168 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001169 return getPasswordMinimumUpperCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001170 }
1171
1172 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001173 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001174 if (mService != null) {
1175 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001176 return mService.getPasswordMinimumUpperCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001177 } catch (RemoteException e) {
1178 Log.w(TAG, "Failed talking with device policy service", e);
1179 }
1180 }
1181 return 0;
1182 }
1183
1184 /**
1185 * Called by an application that is administering the device to set the
1186 * minimum number of lower case letters required in the password. After
1187 * setting this, the user will not be able to enter a new password that is
1188 * not at least as restrictive as what has been set. Note that the current
1189 * password will remain until the user has set a new one, so the change does
1190 * not take place immediately. To prompt the user for a new password, use
1191 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1192 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001193 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1194 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001195 * <p>
1196 * The calling device admin must have requested
1197 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1198 * this method; if it has not, a security exception will be thrown.
1199 *
1200 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1201 * with.
1202 * @param length The new desired minimum number of lower case letters
1203 * required in the password. A value of 0 means there is no
1204 * restriction.
1205 */
Robin Lee25e26452015-06-02 09:56:29 -07001206 public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001207 if (mService != null) {
1208 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001209 mService.setPasswordMinimumLowerCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001210 } catch (RemoteException e) {
1211 Log.w(TAG, "Failed talking with device policy service", e);
1212 }
1213 }
1214 }
1215
1216 /**
1217 * Retrieve the current number of lower case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001218 * password for all admins of this user and its profiles or a particular one.
1219 * This is the same value as set by
1220 * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001221 * and only applies when the password quality is
1222 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001223 *
Robin Lee25e26452015-06-02 09:56:29 -07001224 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001225 * aggregate all admins.
1226 * @return The minimum number of lower case letters required in the
1227 * password.
1228 */
Robin Lee25e26452015-06-02 09:56:29 -07001229 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001230 return getPasswordMinimumLowerCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001231 }
1232
1233 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001234 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001235 if (mService != null) {
1236 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001237 return mService.getPasswordMinimumLowerCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001238 } catch (RemoteException e) {
1239 Log.w(TAG, "Failed talking with device policy service", e);
1240 }
1241 }
1242 return 0;
1243 }
1244
1245 /**
1246 * Called by an application that is administering the device to set the
1247 * minimum number of letters required in the password. After setting this,
1248 * the user will not be able to enter a new password that is not at least as
1249 * restrictive as what has been set. Note that the current password will
1250 * remain until the user has set a new one, so the change does not take
1251 * place immediately. To prompt the user for a new password, use
1252 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1253 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001254 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1255 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001256 * <p>
1257 * The calling device admin must have requested
1258 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1259 * this method; if it has not, a security exception will be thrown.
1260 *
1261 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1262 * with.
1263 * @param length The new desired minimum number of letters required in the
1264 * password. A value of 0 means there is no restriction.
1265 */
Robin Lee25e26452015-06-02 09:56:29 -07001266 public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001267 if (mService != null) {
1268 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001269 mService.setPasswordMinimumLetters(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001270 } catch (RemoteException e) {
1271 Log.w(TAG, "Failed talking with device policy service", e);
1272 }
1273 }
1274 }
1275
1276 /**
1277 * Retrieve the current number of letters required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001278 * admins or a particular one. This is the same value as
1279 * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)}
1280 * and only applies when the password quality is
1281 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001282 *
Robin Lee25e26452015-06-02 09:56:29 -07001283 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001284 * aggregate all admins.
1285 * @return The minimum number of letters required in the password.
1286 */
Robin Lee25e26452015-06-02 09:56:29 -07001287 public int getPasswordMinimumLetters(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001288 return getPasswordMinimumLetters(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001289 }
1290
1291 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001292 public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001293 if (mService != null) {
1294 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001295 return mService.getPasswordMinimumLetters(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001296 } catch (RemoteException e) {
1297 Log.w(TAG, "Failed talking with device policy service", e);
1298 }
1299 }
1300 return 0;
1301 }
1302
1303 /**
1304 * Called by an application that is administering the device to set the
1305 * minimum number of numerical digits required in the password. After
1306 * setting this, the user will not be able to enter a new password that is
1307 * not at least as restrictive as what has been set. Note that the current
1308 * password will remain until the user has set a new one, so the change does
1309 * not take place immediately. To prompt the user for a new password, use
1310 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1311 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001312 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1313 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001314 * <p>
1315 * The calling device admin must have requested
1316 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1317 * this method; if it has not, a security exception will be thrown.
1318 *
1319 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1320 * with.
1321 * @param length The new desired minimum number of numerical digits required
1322 * in the password. A value of 0 means there is no restriction.
1323 */
Robin Lee25e26452015-06-02 09:56:29 -07001324 public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001325 if (mService != null) {
1326 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001327 mService.setPasswordMinimumNumeric(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001328 } catch (RemoteException e) {
1329 Log.w(TAG, "Failed talking with device policy service", e);
1330 }
1331 }
1332 }
1333
1334 /**
1335 * Retrieve the current number of numerical digits required in the password
Jessica Hummel91da58d2014-04-10 17:39:43 +01001336 * for all admins of this user and its profiles or a particular one.
1337 * This is the same value as set by
1338 * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001339 * and only applies when the password quality is
1340 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001341 *
Robin Lee25e26452015-06-02 09:56:29 -07001342 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001343 * aggregate all admins.
1344 * @return The minimum number of numerical digits required in the password.
1345 */
Robin Lee25e26452015-06-02 09:56:29 -07001346 public int getPasswordMinimumNumeric(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001347 return getPasswordMinimumNumeric(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001348 }
1349
1350 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001351 public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001352 if (mService != null) {
1353 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001354 return mService.getPasswordMinimumNumeric(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001355 } catch (RemoteException e) {
1356 Log.w(TAG, "Failed talking with device policy service", e);
1357 }
1358 }
1359 return 0;
1360 }
1361
1362 /**
1363 * Called by an application that is administering the device to set the
1364 * minimum number of symbols required in the password. After setting this,
1365 * the user will not be able to enter a new password that is not at least as
1366 * restrictive as what has been set. Note that the current password will
1367 * remain until the user has set a new one, so the change does not take
1368 * place immediately. To prompt the user for a new password, use
1369 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1370 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001371 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1372 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001373 * <p>
1374 * The calling device admin must have requested
1375 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1376 * this method; if it has not, a security exception will be thrown.
1377 *
1378 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1379 * with.
1380 * @param length The new desired minimum number of symbols required in the
1381 * password. A value of 0 means there is no restriction.
1382 */
Robin Lee25e26452015-06-02 09:56:29 -07001383 public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001384 if (mService != null) {
1385 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001386 mService.setPasswordMinimumSymbols(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001387 } catch (RemoteException e) {
1388 Log.w(TAG, "Failed talking with device policy service", e);
1389 }
1390 }
1391 }
1392
1393 /**
1394 * Retrieve the current number of symbols required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001395 * admins or a particular one. This is the same value as
1396 * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)}
1397 * and only applies when the password quality is
1398 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001399 *
Robin Lee25e26452015-06-02 09:56:29 -07001400 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001401 * aggregate all admins.
1402 * @return The minimum number of symbols required in the password.
1403 */
Robin Lee25e26452015-06-02 09:56:29 -07001404 public int getPasswordMinimumSymbols(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001405 return getPasswordMinimumSymbols(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001406 }
1407
1408 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001409 public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001410 if (mService != null) {
1411 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001412 return mService.getPasswordMinimumSymbols(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001413 } catch (RemoteException e) {
1414 Log.w(TAG, "Failed talking with device policy service", e);
1415 }
1416 }
1417 return 0;
1418 }
1419
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001420 /**
1421 * Called by an application that is administering the device to set the
1422 * minimum number of non-letter characters (numerical digits or symbols)
1423 * required in the password. After setting this, the user will not be able
1424 * to enter a new password that is not at least as restrictive as what has
1425 * been set. Note that the current password will remain until the user has
1426 * set a new one, so the change does not take place immediately. To prompt
1427 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after
1428 * setting this value. This constraint is only imposed if the administrator
1429 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1430 * {@link #setPasswordQuality}. The default value is 0.
1431 * <p>
1432 * The calling device admin must have requested
1433 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1434 * this method; if it has not, a security exception will be thrown.
1435 *
1436 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1437 * with.
1438 * @param length The new desired minimum number of letters required in the
1439 * password. A value of 0 means there is no restriction.
1440 */
Robin Lee25e26452015-06-02 09:56:29 -07001441 public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001442 if (mService != null) {
1443 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001444 mService.setPasswordMinimumNonLetter(admin, length);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001445 } catch (RemoteException e) {
1446 Log.w(TAG, "Failed talking with device policy service", e);
1447 }
1448 }
1449 }
1450
1451 /**
1452 * Retrieve the current number of non-letter characters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001453 * password for all admins of this user and its profiles or a particular one.
1454 * This is the same value as set by
1455 * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001456 * and only applies when the password quality is
1457 * {@link #PASSWORD_QUALITY_COMPLEX}.
1458 *
Robin Lee25e26452015-06-02 09:56:29 -07001459 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001460 * aggregate all admins.
1461 * @return The minimum number of letters required in the password.
1462 */
Robin Lee25e26452015-06-02 09:56:29 -07001463 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001464 return getPasswordMinimumNonLetter(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001465 }
1466
1467 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001468 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001469 if (mService != null) {
1470 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001471 return mService.getPasswordMinimumNonLetter(admin, userHandle);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001472 } catch (RemoteException e) {
1473 Log.w(TAG, "Failed talking with device policy service", e);
1474 }
1475 }
1476 return 0;
1477 }
1478
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001479 /**
1480 * Called by an application that is administering the device to set the length
1481 * of the password history. After setting this, the user will not be able to
1482 * enter a new password that is the same as any password in the history. Note
1483 * that the current password will remain until the user has set a new one, so
1484 * the change does not take place immediately. To prompt the user for a new
1485 * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
1486 * This constraint is only imposed if the administrator has also requested
Jim Miller85516d02014-01-31 17:08:37 -08001487 * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}
1488 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1489 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001490 *
1491 * <p>
1492 * The calling device admin must have requested
1493 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
1494 * method; if it has not, a security exception will be thrown.
1495 *
1496 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1497 * with.
1498 * @param length The new desired length of password history. A value of 0
1499 * means there is no restriction.
1500 */
Robin Lee25e26452015-06-02 09:56:29 -07001501 public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001502 if (mService != null) {
1503 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001504 mService.setPasswordHistoryLength(admin, length);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001505 } catch (RemoteException e) {
1506 Log.w(TAG, "Failed talking with device policy service", e);
1507 }
1508 }
1509 }
1510
1511 /**
Jim Millera4e28d12010-11-08 16:15:47 -08001512 * Called by a device admin to set the password expiration timeout. Calling this method
1513 * will restart the countdown for password expiration for the given admin, as will changing
1514 * the device password (for all admins).
1515 *
1516 * <p>The provided timeout is the time delta in ms and will be added to the current time.
1517 * For example, to have the password expire 5 days from now, timeout would be
1518 * 5 * 86400 * 1000 = 432000000 ms for timeout.
1519 *
1520 * <p>To disable password expiration, a value of 0 may be used for timeout.
1521 *
Jim Millera4e28d12010-11-08 16:15:47 -08001522 * <p>The calling device admin must have requested
1523 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
1524 * method; if it has not, a security exception will be thrown.
1525 *
Jessica Hummel9da60392014-05-21 12:32:57 +01001526 * <p> Note that setting the password will automatically reset the expiration time for all
1527 * active admins. Active admins do not need to explicitly call this method in that case.
1528 *
Jim Millera4e28d12010-11-08 16:15:47 -08001529 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1530 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
1531 * means there is no restriction (unlimited).
1532 */
Robin Lee25e26452015-06-02 09:56:29 -07001533 public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) {
Jim Millera4e28d12010-11-08 16:15:47 -08001534 if (mService != null) {
1535 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001536 mService.setPasswordExpirationTimeout(admin, timeout);
Jim Millera4e28d12010-11-08 16:15:47 -08001537 } catch (RemoteException e) {
1538 Log.w(TAG, "Failed talking with device policy service", e);
1539 }
1540 }
1541 }
1542
1543 /**
Jim Miller6b857682011-02-16 16:27:41 -08001544 * Get the password expiration timeout for the given admin. The expiration timeout is the
1545 * recurring expiration timeout provided in the call to
1546 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
Robin Lee25e26452015-06-02 09:56:29 -07001547 * aggregate of all policy administrators if {@code admin} is null.
Jim Millera4e28d12010-11-08 16:15:47 -08001548 *
Robin Lee25e26452015-06-02 09:56:29 -07001549 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001550 * @return The timeout for the given admin or the minimum of all timeouts
1551 */
Robin Lee25e26452015-06-02 09:56:29 -07001552 public long getPasswordExpirationTimeout(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001553 if (mService != null) {
1554 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001555 return mService.getPasswordExpirationTimeout(admin, myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001556 } catch (RemoteException e) {
1557 Log.w(TAG, "Failed talking with device policy service", e);
1558 }
1559 }
1560 return 0;
1561 }
1562
1563 /**
1564 * Get the current password expiration time for the given admin or an aggregate of
Jessica Hummel91da58d2014-04-10 17:39:43 +01001565 * all admins of this user and its profiles if admin is null. If the password is
1566 * expired, this will return the time since the password expired as a negative number.
1567 * If admin is null, then a composite of all expiration timeouts is returned
1568 * - which will be the minimum of all timeouts.
Jim Millera4e28d12010-11-08 16:15:47 -08001569 *
Robin Lee25e26452015-06-02 09:56:29 -07001570 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001571 * @return The password expiration time, in ms.
1572 */
Robin Lee25e26452015-06-02 09:56:29 -07001573 public long getPasswordExpiration(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001574 if (mService != null) {
1575 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001576 return mService.getPasswordExpiration(admin, myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001577 } catch (RemoteException e) {
1578 Log.w(TAG, "Failed talking with device policy service", e);
1579 }
1580 }
1581 return 0;
1582 }
1583
1584 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001585 * Retrieve the current password history length for all admins of this
1586 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001587 * @param admin The name of the admin component to check, or {@code null} to aggregate
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001588 * all admins.
1589 * @return The length of the password history
1590 */
Robin Lee25e26452015-06-02 09:56:29 -07001591 public int getPasswordHistoryLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001592 return getPasswordHistoryLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001593 }
1594
1595 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001596 public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001597 if (mService != null) {
1598 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001599 return mService.getPasswordHistoryLength(admin, userHandle);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001600 } catch (RemoteException e) {
1601 Log.w(TAG, "Failed talking with device policy service", e);
1602 }
1603 }
1604 return 0;
1605 }
1606
Dianne Hackbornd6847842010-01-12 18:14:19 -08001607 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001608 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001609 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08001610 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001611 * @return Returns the maximum length that the user can enter.
1612 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001613 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001614 // Kind-of arbitrary.
1615 return 16;
1616 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001617
Dianne Hackborn254cb442010-01-27 19:23:59 -08001618 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001619 * Determine whether the current password the user has set is sufficient
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001620 * to meet the policy requirements (quality, minimum length) that have been
Jessica Hummel91da58d2014-04-10 17:39:43 +01001621 * requested by the admins of this user and its profiles.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001622 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001623 * <p>The calling device admin must have requested
1624 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1625 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001626 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001627 * @return Returns true if the password meets the current requirements, else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001628 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001629 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001630 if (mService != null) {
1631 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001632 return mService.isActivePasswordSufficient(myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001633 } catch (RemoteException e) {
1634 Log.w(TAG, "Failed talking with device policy service", e);
1635 }
1636 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001637 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001638 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001639
Dianne Hackbornd6847842010-01-12 18:14:19 -08001640 /**
1641 * Retrieve the number of times the user has failed at entering a
1642 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001643 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001644 * <p>The calling device admin must have requested
1645 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
1646 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001647 */
1648 public int getCurrentFailedPasswordAttempts() {
1649 if (mService != null) {
1650 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001651 return mService.getCurrentFailedPasswordAttempts(myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001652 } catch (RemoteException e) {
1653 Log.w(TAG, "Failed talking with device policy service", e);
1654 }
1655 }
1656 return -1;
1657 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001658
1659 /**
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001660 * Queries whether {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001661 *
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001662 * @return true if RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001663 * @hide
1664 */
1665 public boolean getDoNotAskCredentialsOnBoot() {
1666 if (mService != null) {
1667 try {
1668 return mService.getDoNotAskCredentialsOnBoot();
1669 } catch (RemoteException e) {
1670 Log.w(TAG, "Failed to call getDoNotAskCredentialsOnBoot()", e);
1671 }
1672 }
1673 return false;
1674 }
1675
1676 /**
Andrew Stadler88209d12010-02-08 22:59:36 -08001677 * Setting this to a value greater than zero enables a built-in policy
1678 * that will perform a device wipe after too many incorrect
1679 * device-unlock passwords have been entered. This built-in policy combines
1680 * watching for failed passwords and wiping the device, and requires
1681 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001682 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001683 *
Andrew Stadler88209d12010-02-08 22:59:36 -08001684 * <p>To implement any other policy (e.g. wiping data for a particular
1685 * application only, erasing or revoking credentials, or reporting the
1686 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001687 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -08001688 * instead. Do not use this API, because if the maximum count is reached,
1689 * the device will be wiped immediately, and your callback will not be invoked.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001690 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001691 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001692 * @param num The number of failed password attempts at which point the
1693 * device will wipe its data.
1694 */
Robin Lee25e26452015-06-02 09:56:29 -07001695 public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001696 if (mService != null) {
1697 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001698 mService.setMaximumFailedPasswordsForWipe(admin, num);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001699 } catch (RemoteException e) {
1700 Log.w(TAG, "Failed talking with device policy service", e);
1701 }
1702 }
1703 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001704
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001705 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001706 * Retrieve the current maximum number of login attempts that are allowed
Jessica Hummel91da58d2014-04-10 17:39:43 +01001707 * before the device wipes itself, for all admins of this user and its profiles
Dianne Hackborn254cb442010-01-27 19:23:59 -08001708 * or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001709 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001710 * all admins.
1711 */
Robin Lee25e26452015-06-02 09:56:29 -07001712 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001713 return getMaximumFailedPasswordsForWipe(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001714 }
1715
1716 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001717 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001718 if (mService != null) {
1719 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001720 return mService.getMaximumFailedPasswordsForWipe(admin, userHandle);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001721 } catch (RemoteException e) {
1722 Log.w(TAG, "Failed talking with device policy service", e);
1723 }
1724 }
1725 return 0;
1726 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001727
Dianne Hackborn254cb442010-01-27 19:23:59 -08001728 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07001729 * Returns the profile with the smallest maximum failed passwords for wipe,
1730 * for the given user. So for primary user, it might return the primary or
1731 * a managed profile. For a secondary user, it would be the same as the
1732 * user passed in.
1733 * @hide Used only by Keyguard
1734 */
1735 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
1736 if (mService != null) {
1737 try {
1738 return mService.getProfileWithMinimumFailedPasswordsForWipe(userHandle);
1739 } catch (RemoteException e) {
1740 Log.w(TAG, "Failed talking with device policy service", e);
1741 }
1742 }
1743 return UserHandle.USER_NULL;
1744 }
1745
1746 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001747 * Flag for {@link #resetPassword}: don't allow other admins to change
1748 * the password again until the user has entered it.
1749 */
1750 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001751
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001752 /**
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001753 * Flag for {@link #resetPassword}: don't ask for user credentials on device boot.
1754 * If the flag is set, the device can be booted without asking for user password.
1755 * The absence of this flag does not change the current boot requirements. This flag
1756 * can be set by the device owner only. If the app is not the device owner, the flag
1757 * is ignored. Once the flag is set, it cannot be reverted back without resetting the
1758 * device to factory defaults.
1759 */
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001760 public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002;
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001761
1762 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001763 * Force a new device unlock password (the password needed to access the
1764 * entire device, not for individual accounts) on the user. This takes
1765 * effect immediately.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001766 * The given password must be sufficient for the
1767 * current password quality and length constraints as returned by
1768 * {@link #getPasswordQuality(ComponentName)} and
1769 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
1770 * these constraints, then it will be rejected and false returned. Note
1771 * that the password may be a stronger quality (containing alphanumeric
1772 * characters when the requested quality is only numeric), in which case
1773 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001774 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001775 * <p>Calling with a null or empty password will clear any existing PIN,
1776 * pattern or password if the current password constraints allow it.
1777 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001778 * <p>The calling device admin must have requested
1779 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
1780 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001781 *
Amith Yamasani242f4b12014-10-14 16:06:13 -07001782 * <p>Calling this from a managed profile will throw a security exception.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001783 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001784 * @param password The new password for the user. Null or empty clears the password.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001785 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001786 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001787 * @return Returns true if the password was applied, or false if it is
1788 * not acceptable for the current constraints.
1789 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001790 public boolean resetPassword(String password, int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001791 if (mService != null) {
1792 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001793 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001794 } catch (RemoteException e) {
1795 Log.w(TAG, "Failed talking with device policy service", e);
1796 }
1797 }
1798 return false;
1799 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001800
Dianne Hackbornd6847842010-01-12 18:14:19 -08001801 /**
1802 * Called by an application that is administering the device to set the
1803 * maximum time for user activity until the device will lock. This limits
1804 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001805 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001806 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -08001807 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001808 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001809 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001810 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001811 * @param timeMs The new desired maximum time to lock in milliseconds.
1812 * A value of 0 means there is no restriction.
1813 */
Robin Lee25e26452015-06-02 09:56:29 -07001814 public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001815 if (mService != null) {
1816 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001817 mService.setMaximumTimeToLock(admin, timeMs);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001818 } catch (RemoteException e) {
1819 Log.w(TAG, "Failed talking with device policy service", e);
1820 }
1821 }
1822 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001823
Dianne Hackbornd6847842010-01-12 18:14:19 -08001824 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001825 * Retrieve the current maximum time to unlock for all admins of this user
1826 * and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001827 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001828 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07001829 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07001830 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001831 */
Robin Lee25e26452015-06-02 09:56:29 -07001832 public long getMaximumTimeToLock(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001833 return getMaximumTimeToLock(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001834 }
1835
1836 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001837 public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001838 if (mService != null) {
1839 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001840 return mService.getMaximumTimeToLock(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001841 } catch (RemoteException e) {
1842 Log.w(TAG, "Failed talking with device policy service", e);
1843 }
1844 }
1845 return 0;
1846 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001847
Dianne Hackbornd6847842010-01-12 18:14:19 -08001848 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001849 * Make the device lock immediately, as if the lock screen timeout has
1850 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001851 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001852 * <p>The calling device admin must have requested
1853 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
1854 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001855 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001856 public void lockNow() {
1857 if (mService != null) {
1858 try {
1859 mService.lockNow();
1860 } catch (RemoteException e) {
1861 Log.w(TAG, "Failed talking with device policy service", e);
1862 }
1863 }
1864 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001865
Dianne Hackbornd6847842010-01-12 18:14:19 -08001866 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07001867 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001868 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07001869 */
1870 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
1871
1872 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001873 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
1874 * data.
1875 *
Paul Crowley2934b262014-12-02 11:21:13 +00001876 * <p>This flag may only be set by device owner admins; if it is set by
1877 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001878 */
1879 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
1880
1881 /**
Robin Lee85bd63f2015-02-10 11:51:00 +00001882 * Ask the user data be wiped. Wiping the primary user will cause the
1883 * device to reboot, erasing all user data while next booting up.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001884 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001885 * <p>The calling device admin must have requested
1886 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
1887 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001888 *
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001889 * @param flags Bit mask of additional options: currently supported flags
1890 * are {@link #WIPE_EXTERNAL_STORAGE} and
1891 * {@link #WIPE_RESET_PROTECTION_DATA}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001892 */
1893 public void wipeData(int flags) {
1894 if (mService != null) {
1895 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001896 mService.wipeData(flags, myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001897 } catch (RemoteException e) {
1898 Log.w(TAG, "Failed talking with device policy service", e);
1899 }
1900 }
1901 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001902
Dianne Hackbornd6847842010-01-12 18:14:19 -08001903 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001904 * Called by an application that is administering the device to set the
1905 * global proxy and exclusion list.
1906 * <p>
1907 * The calling device admin must have requested
1908 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
1909 * this method; if it has not, a security exception will be thrown.
1910 * Only the first device admin can set the proxy. If a second admin attempts
1911 * to set the proxy, the {@link ComponentName} of the admin originally setting the
Robin Lee25e26452015-06-02 09:56:29 -07001912 * proxy will be returned. If successful in setting the proxy, {@code null} will
Oscar Montemayor69238c62010-08-03 10:51:06 -07001913 * be returned.
1914 * The method can be called repeatedly by the device admin alrady setting the
1915 * proxy to update the proxy and exclusion list.
1916 *
Robin Lee25e26452015-06-02 09:56:29 -07001917 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Oscar Montemayor69238c62010-08-03 10:51:06 -07001918 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
1919 * Pass Proxy.NO_PROXY to reset the proxy.
1920 * @param exclusionList a list of domains to be excluded from the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07001921 * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName}
1922 * of the device admin that sets the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08001923 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001924 */
Robin Lee25e26452015-06-02 09:56:29 -07001925 public ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec,
Oscar Montemayor69238c62010-08-03 10:51:06 -07001926 List<String> exclusionList ) {
1927 if (proxySpec == null) {
1928 throw new NullPointerException();
1929 }
1930 if (mService != null) {
1931 try {
1932 String hostSpec;
1933 String exclSpec;
1934 if (proxySpec.equals(Proxy.NO_PROXY)) {
1935 hostSpec = null;
1936 exclSpec = null;
1937 } else {
1938 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
1939 throw new IllegalArgumentException();
1940 }
1941 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
1942 String hostName = sa.getHostName();
1943 int port = sa.getPort();
1944 StringBuilder hostBuilder = new StringBuilder();
1945 hostSpec = hostBuilder.append(hostName)
1946 .append(":").append(Integer.toString(port)).toString();
1947 if (exclusionList == null) {
1948 exclSpec = "";
1949 } else {
1950 StringBuilder listBuilder = new StringBuilder();
1951 boolean firstDomain = true;
1952 for (String exclDomain : exclusionList) {
1953 if (!firstDomain) {
1954 listBuilder = listBuilder.append(",");
1955 } else {
1956 firstDomain = false;
1957 }
1958 listBuilder = listBuilder.append(exclDomain.trim());
1959 }
1960 exclSpec = listBuilder.toString();
1961 }
Yuhao Zheng90704842014-02-28 17:22:45 -08001962 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
1963 != android.net.Proxy.PROXY_VALID)
1964 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07001965 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001966 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07001967 } catch (RemoteException e) {
1968 Log.w(TAG, "Failed talking with device policy service", e);
1969 }
1970 }
1971 return null;
1972 }
1973
1974 /**
Jason Monk03bc9912014-05-13 09:44:57 -04001975 * Set a network-independent global HTTP proxy. This is not normally what you want
1976 * for typical HTTP proxies - they are generally network dependent. However if you're
1977 * doing something unusual like general internal filtering this may be useful. On
1978 * a private network where the proxy is not accessible, you may break HTTP using this.
1979 *
1980 * <p>This method requires the caller to be the device owner.
1981 *
1982 * <p>This proxy is only a recommendation and it is possible that some apps will ignore it.
1983 * @see ProxyInfo
1984 *
1985 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1986 * with.
1987 * @param proxyInfo The a {@link ProxyInfo} object defining the new global
1988 * HTTP proxy. A {@code null} value will clear the global HTTP proxy.
1989 */
Robin Lee25e26452015-06-02 09:56:29 -07001990 public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo
1991 proxyInfo) {
Jason Monk03bc9912014-05-13 09:44:57 -04001992 if (mService != null) {
1993 try {
1994 mService.setRecommendedGlobalProxy(admin, proxyInfo);
1995 } catch (RemoteException e) {
1996 Log.w(TAG, "Failed talking with device policy service", e);
1997 }
1998 }
1999 }
2000
2001 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07002002 * Returns the component name setting the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07002003 * @return ComponentName object of the device admin that set the global proxy, or {@code null}
2004 * if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08002005 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07002006 */
2007 public ComponentName getGlobalProxyAdmin() {
2008 if (mService != null) {
2009 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002010 return mService.getGlobalProxyAdmin(myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07002011 } catch (RemoteException e) {
2012 Log.w(TAG, "Failed talking with device policy service", e);
2013 }
2014 }
2015 return null;
2016 }
2017
2018 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002019 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002020 * indicating that encryption is not supported.
2021 */
2022 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
2023
2024 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002025 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002026 * indicating that encryption is supported, but is not currently active.
2027 */
2028 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
2029
2030 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002031 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002032 * indicating that encryption is not currently active, but is currently
2033 * being activated. This is only reported by devices that support
2034 * encryption of data and only when the storage is currently
2035 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
2036 * to become encrypted will never return this value.
2037 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002038 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002039
2040 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002041 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002042 * indicating that encryption is active.
2043 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002044 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002045
2046 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002047 * Result code for {@link #getStorageEncryptionStatus}:
2048 * indicating that encryption is active, but an encryption key has not
2049 * been set by the user.
2050 */
2051 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
2052
2053 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002054 * Activity action: begin the process of encrypting data on the device. This activity should
2055 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
2056 * After resuming from this activity, use {@link #getStorageEncryption}
2057 * to check encryption status. However, on some devices this activity may never return, as
2058 * it may trigger a reboot and in some cases a complete data wipe of the device.
2059 */
2060 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
2061 public static final String ACTION_START_ENCRYPTION
2062 = "android.app.action.START_ENCRYPTION";
2063
2064 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07002065 * Widgets are enabled in keyguard
2066 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002067 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07002068
2069 /**
Jim Miller50e62182014-04-23 17:25:00 -07002070 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07002071 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002072 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
2073
2074 /**
2075 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
2076 */
2077 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
2078
2079 /**
Jim Miller50e62182014-04-23 17:25:00 -07002080 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2081 */
2082 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
2083
2084 /**
2085 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2086 */
2087 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
2088
2089 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02002090 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07002091 * (e.g. PIN/Pattern/Password).
2092 */
2093 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
2094
2095 /**
Jim Miller06e34502014-07-17 14:46:05 -07002096 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
2097 */
2098 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
2099
2100 /**
Jim Miller35207742012-11-02 15:33:20 -07002101 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07002102 */
2103 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07002104
2105 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002106 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002107 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002108 *
2109 * <p>When multiple device administrators attempt to control device
2110 * encryption, the most secure, supported setting will always be
2111 * used. If any device administrator requests device encryption,
2112 * it will be enabled; Conversely, if a device administrator
2113 * attempts to disable device encryption while another
2114 * device administrator has enabled it, the call to disable will
2115 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
2116 *
2117 * <p>This policy controls encryption of the secure (application data) storage area. Data
Andy Stadler50c294f2011-03-07 19:13:42 -08002118 * written to other storage areas may or may not be encrypted, and this policy does not require
2119 * or control the encryption of any other storage areas.
2120 * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is
2121 * {@code true}, then the directory returned by
2122 * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk
2123 * within the encrypted storage area.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002124 *
2125 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
2126 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
2127 * the encryption key may not be fully secured. For maximum security, the administrator should
2128 * also require (and check for) a pattern, PIN, or password.
2129 *
2130 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2131 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08002132 * @return the new request status (for all active admins) - will be one of
2133 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
2134 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
2135 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002136 */
Robin Lee25e26452015-06-02 09:56:29 -07002137 public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002138 if (mService != null) {
2139 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002140 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002141 } catch (RemoteException e) {
2142 Log.w(TAG, "Failed talking with device policy service", e);
2143 }
2144 }
2145 return ENCRYPTION_STATUS_UNSUPPORTED;
2146 }
2147
2148 /**
2149 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002150 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002151 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08002152 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
2153 * this will return the requested encryption setting as an aggregate of all active
2154 * administrators.
2155 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002156 */
Robin Lee25e26452015-06-02 09:56:29 -07002157 public boolean getStorageEncryption(@Nullable ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002158 if (mService != null) {
2159 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002160 return mService.getStorageEncryption(admin, myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002161 } catch (RemoteException e) {
2162 Log.w(TAG, "Failed talking with device policy service", e);
2163 }
2164 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08002165 return false;
2166 }
2167
2168 /**
2169 * Called by an application that is administering the device to
2170 * determine the current encryption status of the device.
2171 *
2172 * Depending on the returned status code, the caller may proceed in different
2173 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
2174 * storage system does not support encryption. If the
2175 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
2176 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00002177 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
2178 * storage system has enabled encryption but no password is set so further action
2179 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
Andy Stadler22dbfda2011-01-17 12:47:31 -08002180 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
2181 *
Robin Lee7e678712014-07-24 16:41:31 +01002182 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08002183 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00002184 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
2185 * or {@link #ENCRYPTION_STATUS_ACTIVE}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08002186 */
2187 public int getStorageEncryptionStatus() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002188 return getStorageEncryptionStatus(myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002189 }
2190
2191 /** @hide per-user version */
2192 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08002193 if (mService != null) {
2194 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002195 return mService.getStorageEncryptionStatus(userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08002196 } catch (RemoteException e) {
2197 Log.w(TAG, "Failed talking with device policy service", e);
2198 }
2199 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002200 return ENCRYPTION_STATUS_UNSUPPORTED;
2201 }
2202
2203 /**
Robin Lee7e678712014-07-24 16:41:31 +01002204 * Installs the given certificate as a user CA.
2205 *
Robin Lee25e26452015-06-02 09:56:29 -07002206 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2207 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002208 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04002209 *
2210 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01002211 * interrupted, true otherwise.
Maggie Benthallda51e682013-08-08 22:35:44 -04002212 */
Robin Lee25e26452015-06-02 09:56:29 -07002213 public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002214 if (mService != null) {
2215 try {
Robin Lee7e678712014-07-24 16:41:31 +01002216 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04002217 } catch (RemoteException e) {
2218 Log.w(TAG, "Failed talking with device policy service", e);
2219 }
2220 }
2221 return false;
2222 }
2223
2224 /**
Robin Lee7e678712014-07-24 16:41:31 +01002225 * Uninstalls the given certificate from trusted user CAs, if present.
2226 *
Robin Lee25e26452015-06-02 09:56:29 -07002227 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2228 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002229 * @param certBuffer encoded form of the certificate to remove.
Maggie Benthallda51e682013-08-08 22:35:44 -04002230 */
Robin Lee25e26452015-06-02 09:56:29 -07002231 public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002232 if (mService != null) {
2233 try {
Robin Lee306fe082014-06-19 14:04:24 +00002234 final String alias = getCaCertAlias(certBuffer);
Robin Lee83881bd2015-06-09 16:04:38 -07002235 mService.uninstallCaCerts(admin, new String[] {alias});
Robin Lee306fe082014-06-19 14:04:24 +00002236 } catch (CertificateException e) {
2237 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002238 } catch (RemoteException e) {
2239 Log.w(TAG, "Failed talking with device policy service", e);
2240 }
2241 }
2242 }
2243
2244 /**
Robin Lee7e678712014-07-24 16:41:31 +01002245 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
2246 * If a user has installed any certificates by other means than device policy these will be
2247 * included too.
2248 *
Robin Lee25e26452015-06-02 09:56:29 -07002249 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2250 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002251 * @return a List of byte[] arrays, each encoding one user CA certificate.
Maggie Benthallda51e682013-08-08 22:35:44 -04002252 */
Robin Lee25e26452015-06-02 09:56:29 -07002253 public List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002254 List<byte[]> certs = new ArrayList<byte[]>();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002255 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01002256 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002257 mService.enforceCanManageCaCerts(admin);
2258 final TrustedCertificateStore certStore = new TrustedCertificateStore();
2259 for (String alias : certStore.userAliases()) {
2260 try {
2261 certs.add(certStore.getCertificate(alias).getEncoded());
2262 } catch (CertificateException ce) {
2263 Log.w(TAG, "Could not encode certificate: " + alias, ce);
2264 }
2265 }
2266 } catch (RemoteException re) {
2267 Log.w(TAG, "Failed talking with device policy service", re);
Robin Lee7e678712014-07-24 16:41:31 +01002268 }
2269 }
2270 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04002271 }
2272
2273 /**
Robin Lee7e678712014-07-24 16:41:31 +01002274 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
2275 * means other than device policy will also be removed, except for system CA certificates.
2276 *
Robin Lee25e26452015-06-02 09:56:29 -07002277 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2278 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002279 */
Robin Lee25e26452015-06-02 09:56:29 -07002280 public void uninstallAllUserCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002281 if (mService != null) {
Robin Lee83881bd2015-06-09 16:04:38 -07002282 try {
2283 mService.uninstallCaCerts(admin, new TrustedCertificateStore().userAliases()
2284 .toArray(new String[0]));
2285 } catch (RemoteException re) {
2286 Log.w(TAG, "Failed talking with device policy service", re);
Robin Lee7e678712014-07-24 16:41:31 +01002287 }
2288 }
2289 }
2290
2291 /**
2292 * Returns whether this certificate is installed as a trusted CA.
2293 *
Robin Lee25e26452015-06-02 09:56:29 -07002294 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2295 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002296 * @param certBuffer encoded form of the certificate to look up.
Maggie Benthallda51e682013-08-08 22:35:44 -04002297 */
Robin Lee25e26452015-06-02 09:56:29 -07002298 public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002299 if (mService != null) {
2300 try {
2301 mService.enforceCanManageCaCerts(admin);
2302 return getCaCertAlias(certBuffer) != null;
2303 } catch (RemoteException re) {
2304 Log.w(TAG, "Failed talking with device policy service", re);
2305 } catch (CertificateException ce) {
2306 Log.w(TAG, "Could not parse certificate", ce);
2307 }
Maggie Benthallda51e682013-08-08 22:35:44 -04002308 }
2309 return false;
2310 }
2311
2312 /**
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002313 * Called by a device or profile owner to install a certificate and private key pair. The
2314 * keypair will be visible to all apps within the profile.
2315 *
Robin Lee25e26452015-06-02 09:56:29 -07002316 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2317 * {@code null} if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002318 * @param privKey The private key to install.
2319 * @param cert The certificate to install.
2320 * @param alias The private key alias under which to install the certificate. If a certificate
2321 * with that alias already exists, it will be overwritten.
2322 * @return {@code true} if the keys were installed, {@code false} otherwise.
2323 */
Robin Lee25e26452015-06-02 09:56:29 -07002324 public boolean installKeyPair(@Nullable ComponentName admin, PrivateKey privKey, Certificate cert,
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002325 String alias) {
2326 try {
2327 final byte[] pemCert = Credentials.convertToPem(cert);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002328 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
2329 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
Robin Lee25e26452015-06-02 09:56:29 -07002330 return mService.installKeyPair(admin, pkcs8Key, pemCert, alias);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002331 } catch (RemoteException e) {
2332 Log.w(TAG, "Failed talking with device policy service", e);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002333 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
2334 Log.w(TAG, "Failed to obtain private key material", e);
2335 } catch (CertificateException | IOException e) {
2336 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002337 }
2338 return false;
2339 }
2340
2341 /**
Robin Lee25e26452015-06-02 09:56:29 -07002342 * @return the alias of a given CA certificate in the certificate store, or {@code null} if it
Robin Lee306fe082014-06-19 14:04:24 +00002343 * doesn't exist.
2344 */
2345 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
2346 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
2347 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
2348 new ByteArrayInputStream(certBuffer));
2349 return new TrustedCertificateStore().getCertificateAlias(cert);
2350 }
2351
2352 /**
Rubin Xuec32b562015-03-03 17:34:05 +00002353 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01002354 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00002355 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01002356 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00002357 * <p>
2358 * Delegated certificate installer is a per-user state. The delegated access is persistent until
2359 * it is later cleared by calling this method with a null value or uninstallling the certificate
2360 * installer.
2361 *
Robin Lee25e26452015-06-02 09:56:29 -07002362 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xuec32b562015-03-03 17:34:05 +00002363 * @param installerPackage The package name of the certificate installer which will be given
Robin Lee25e26452015-06-02 09:56:29 -07002364 * access. If {@code null} is given the current package will be cleared.
Rubin Xuec32b562015-03-03 17:34:05 +00002365 */
Robin Lee25e26452015-06-02 09:56:29 -07002366 public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String
2367 installerPackage) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002368 if (mService != null) {
2369 try {
Robin Lee25e26452015-06-02 09:56:29 -07002370 mService.setCertInstallerPackage(admin, installerPackage);
Rubin Xuec32b562015-03-03 17:34:05 +00002371 } catch (RemoteException e) {
2372 Log.w(TAG, "Failed talking with device policy service", e);
2373 }
2374 }
2375 }
2376
2377 /**
2378 * Called by a profile owner or device owner to retrieve the certificate installer for the
2379 * current user. null if none is set.
2380 *
Robin Lee25e26452015-06-02 09:56:29 -07002381 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2382 * @return The package name of the current delegated certificate installer, or {@code null}
Rubin Xuec32b562015-03-03 17:34:05 +00002383 * if none is set.
2384 */
Robin Lee25e26452015-06-02 09:56:29 -07002385 public String getCertInstallerPackage(@NonNull ComponentName admin) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002386 if (mService != null) {
2387 try {
Robin Lee25e26452015-06-02 09:56:29 -07002388 return mService.getCertInstallerPackage(admin);
Rubin Xuec32b562015-03-03 17:34:05 +00002389 } catch (RemoteException e) {
2390 Log.w(TAG, "Failed talking with device policy service", e);
2391 }
2392 }
2393 return null;
2394 }
2395
2396 /**
Ben Komalo2447edd2011-05-09 16:05:33 -07002397 * Called by an application that is administering the device to disable all cameras
Amith Yamasani242f4b12014-10-14 16:06:13 -07002398 * on the device, for this user. After setting this, no applications running as this user
2399 * will be able to access any cameras on the device.
Ben Komalo2447edd2011-05-09 16:05:33 -07002400 *
2401 * <p>The calling device admin must have requested
2402 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
2403 * this method; if it has not, a security exception will be thrown.
2404 *
2405 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2406 * @param disabled Whether or not the camera should be disabled.
2407 */
Robin Lee25e26452015-06-02 09:56:29 -07002408 public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002409 if (mService != null) {
2410 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002411 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07002412 } catch (RemoteException e) {
2413 Log.w(TAG, "Failed talking with device policy service", e);
2414 }
2415 }
2416 }
2417
2418 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07002419 * Determine whether or not the device's cameras have been disabled for this user,
2420 * either by the current admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002421 * @param admin The name of the admin component to check, or {@code null} to check whether any admins
Ben Komalo2447edd2011-05-09 16:05:33 -07002422 * have disabled the camera
2423 */
Robin Lee25e26452015-06-02 09:56:29 -07002424 public boolean getCameraDisabled(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002425 return getCameraDisabled(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002426 }
2427
2428 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002429 public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002430 if (mService != null) {
2431 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002432 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07002433 } catch (RemoteException e) {
2434 Log.w(TAG, "Failed talking with device policy service", e);
2435 }
2436 }
2437 return false;
2438 }
2439
2440 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01002441 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
2442 * screen capture also prevents the content from being shown on display devices that do not have
2443 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
2444 * secure surfaces and secure displays.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002445 *
2446 * <p>The calling device admin must be a device or profile owner. If it is not, a
2447 * security exception will be thrown.
2448 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002449 * <p>From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also
Benjamin Franzc200f442015-06-25 18:20:04 +01002450 * blocks assist requests for all activities of the relevant user.
2451 *
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002452 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002453 * @param disabled Whether screen capture is disabled or not.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002454 */
Robin Lee25e26452015-06-02 09:56:29 -07002455 public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002456 if (mService != null) {
2457 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002458 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002459 } catch (RemoteException e) {
2460 Log.w(TAG, "Failed talking with device policy service", e);
2461 }
2462 }
2463 }
2464
2465 /**
2466 * Determine whether or not screen capture has been disabled by the current
2467 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002468 * @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 +01002469 * have disabled screen capture.
2470 */
Robin Lee25e26452015-06-02 09:56:29 -07002471 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002472 return getScreenCaptureDisabled(admin, myUserId());
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002473 }
2474
2475 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002476 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002477 if (mService != null) {
2478 try {
2479 return mService.getScreenCaptureDisabled(admin, userHandle);
2480 } catch (RemoteException e) {
2481 Log.w(TAG, "Failed talking with device policy service", e);
2482 }
2483 }
2484 return false;
2485 }
2486
2487 /**
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002488 * Called by a device owner to set whether auto time is required. If auto time is
2489 * required the user cannot set the date and time, but has to use network date and time.
2490 *
2491 * <p>Note: if auto time is required the user can still manually set the time zone.
2492 *
2493 * <p>The calling device admin must be a device owner. If it is not, a security exception will
2494 * be thrown.
2495 *
2496 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2497 * @param required Whether auto time is set required or not.
2498 */
Robin Lee25e26452015-06-02 09:56:29 -07002499 public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) {
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002500 if (mService != null) {
2501 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002502 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002503 } catch (RemoteException e) {
2504 Log.w(TAG, "Failed talking with device policy service", e);
2505 }
2506 }
2507 }
2508
2509 /**
2510 * @return true if auto time is required.
2511 */
2512 public boolean getAutoTimeRequired() {
2513 if (mService != null) {
2514 try {
2515 return mService.getAutoTimeRequired();
2516 } catch (RemoteException e) {
2517 Log.w(TAG, "Failed talking with device policy service", e);
2518 }
2519 }
2520 return false;
2521 }
2522
2523 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002524 * Called by an application that is administering the device to disable keyguard customizations,
2525 * such as widgets. After setting this, keyguard features will be disabled according to the
2526 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002527 *
2528 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07002529 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07002530 * this method; if it has not, a security exception will be thrown.
2531 *
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002532 * <p>Calling this from a managed profile before version
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002533 * {@link android.os.Build.VERSION_CODES#M} will throw a security exception.
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002534 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002535 * <p>From version {@link android.os.Build.VERSION_CODES#M} a profile owner can set:
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002536 * <ul>
2537 * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, {@link #KEYGUARD_DISABLE_FINGERPRINT}
2538 * these will affect the profile's parent user.
2539 * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} this will affect notifications
2540 * generated by applications in the managed profile.
2541 * </ul>
2542 * <p>Requests to disable other features on a managed profile will be ignored. The admin
2543 * can check which features have been disabled by calling
2544 * {@link #getKeyguardDisabledFeatures(ComponentName)}
Amith Yamasani242f4b12014-10-14 16:06:13 -07002545 *
Jim Millerb8ec4702012-08-31 17:19:10 -07002546 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07002547 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
2548 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
Jim Miller50e62182014-04-23 17:25:00 -07002549 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002550 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FINGERPRINT},
2551 * {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07002552 */
Robin Lee25e26452015-06-02 09:56:29 -07002553 public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002554 if (mService != null) {
2555 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002556 mService.setKeyguardDisabledFeatures(admin, which);
Jim Millerb8ec4702012-08-31 17:19:10 -07002557 } catch (RemoteException e) {
2558 Log.w(TAG, "Failed talking with device policy service", e);
2559 }
2560 }
2561 }
2562
2563 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002564 * Determine whether or not features have been disabled in keyguard either by the current
Jim Millerb8ec4702012-08-31 17:19:10 -07002565 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002566 * @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 -07002567 * have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07002568 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
2569 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002570 */
Robin Lee25e26452015-06-02 09:56:29 -07002571 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002572 return getKeyguardDisabledFeatures(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002573 }
2574
2575 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002576 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002577 if (mService != null) {
2578 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07002579 return mService.getKeyguardDisabledFeatures(admin, userHandle);
Jim Millerb8ec4702012-08-31 17:19:10 -07002580 } catch (RemoteException e) {
2581 Log.w(TAG, "Failed talking with device policy service", e);
2582 }
2583 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07002584 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07002585 }
2586
2587 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08002588 * @hide
2589 */
Robin Lee25e26452015-06-02 09:56:29 -07002590 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
2591 int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002592 if (mService != null) {
2593 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01002594 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002595 } catch (RemoteException e) {
2596 Log.w(TAG, "Failed talking with device policy service", e);
2597 }
2598 }
2599 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002600
Dianne Hackbornd6847842010-01-12 18:14:19 -08002601 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01002602 * @hide
2603 */
Robin Lee25e26452015-06-02 09:56:29 -07002604 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002605 setActiveAdmin(policyReceiver, refreshing, myUserId());
Jessica Hummel6d36b602014-04-04 12:42:17 +01002606 }
2607
2608 /**
Robin Lee25e26452015-06-02 09:56:29 -07002609 * Returns the DeviceAdminInfo as defined by the administrator's package info &amp; meta-data
Dianne Hackbornd6847842010-01-12 18:14:19 -08002610 * @hide
2611 */
Robin Lee25e26452015-06-02 09:56:29 -07002612 public DeviceAdminInfo getAdminInfo(@NonNull ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002613 ActivityInfo ai;
2614 try {
2615 ai = mContext.getPackageManager().getReceiverInfo(cn,
2616 PackageManager.GET_META_DATA);
2617 } catch (PackageManager.NameNotFoundException e) {
2618 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
2619 return null;
2620 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002621
Dianne Hackbornd6847842010-01-12 18:14:19 -08002622 ResolveInfo ri = new ResolveInfo();
2623 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002624
Dianne Hackbornd6847842010-01-12 18:14:19 -08002625 try {
2626 return new DeviceAdminInfo(mContext, ri);
2627 } catch (XmlPullParserException e) {
2628 Log.w(TAG, "Unable to parse device policy " + cn, e);
2629 return null;
2630 } catch (IOException e) {
2631 Log.w(TAG, "Unable to parse device policy " + cn, e);
2632 return null;
2633 }
2634 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002635
Dianne Hackbornd6847842010-01-12 18:14:19 -08002636 /**
2637 * @hide
2638 */
Robin Lee25e26452015-06-02 09:56:29 -07002639 public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002640 if (mService != null) {
2641 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002642 mService.getRemoveWarning(admin, result, myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002643 } catch (RemoteException e) {
2644 Log.w(TAG, "Failed talking with device policy service", e);
2645 }
2646 }
2647 }
2648
2649 /**
2650 * @hide
2651 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002652 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002653 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002654 if (mService != null) {
2655 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002656 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002657 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002658 } catch (RemoteException e) {
2659 Log.w(TAG, "Failed talking with device policy service", e);
2660 }
2661 }
2662 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002663
Dianne Hackbornd6847842010-01-12 18:14:19 -08002664 /**
2665 * @hide
2666 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002667 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002668 if (mService != null) {
2669 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002670 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002671 } catch (RemoteException e) {
2672 Log.w(TAG, "Failed talking with device policy service", e);
2673 }
2674 }
2675 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002676
Dianne Hackbornd6847842010-01-12 18:14:19 -08002677 /**
2678 * @hide
2679 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002680 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002681 if (mService != null) {
2682 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002683 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002684 } catch (RemoteException e) {
2685 Log.w(TAG, "Failed talking with device policy service", e);
2686 }
2687 }
2688 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07002689
2690 /**
2691 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00002692 * Sets the given package as the device owner.
2693 * Same as {@link #setDeviceOwner(String, String)} but without setting a device owner name.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002694 * @param packageName the package name of the application to be registered as the device owner.
2695 * @return whether the package was successfully registered as the device owner.
2696 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00002697 * @throws IllegalStateException If the preconditions mentioned are not met.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002698 */
Makoto Onuki58b684f2015-09-04 10:48:16 -07002699 public boolean setDeviceOwner(String packageName) {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002700 return setDeviceOwner(packageName, null);
2701 }
2702
2703 /**
2704 * @hide
Makoto Onuki58b684f2015-09-04 10:48:16 -07002705 */
2706 public boolean setDeviceOwner(String packageName, int userId) {
2707 return setDeviceOwner(packageName, null, userId);
2708 }
2709
2710 /**
2711 * @hide
2712 */
2713 public boolean setDeviceOwner(String packageName, String ownerName) {
2714 return setDeviceOwner(packageName, ownerName, UserHandle.USER_SYSTEM);
2715 }
2716
2717 /**
2718 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00002719 * Sets the given package as the device owner. The package must already be installed. There
2720 * must not already be a device owner.
2721 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
2722 * this method.
2723 * Calling this after the setup phase of the primary user has completed is allowed only if
2724 * the caller is the shell uid, and there are no additional users and no accounts.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002725 * @param packageName the package name of the application to be registered as the device owner.
2726 * @param ownerName the human readable name of the institution that owns this device.
Makoto Onuki58b684f2015-09-04 10:48:16 -07002727 * @param userId ID of the user on which the device owner runs.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002728 * @return whether the package was successfully registered as the device owner.
2729 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00002730 * @throws IllegalStateException If the preconditions mentioned are not met.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002731 */
Makoto Onuki58b684f2015-09-04 10:48:16 -07002732 public boolean setDeviceOwner(String packageName, String ownerName, int userId)
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002733 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002734 if (mService != null) {
2735 try {
Makoto Onuki58b684f2015-09-04 10:48:16 -07002736 return mService.setDeviceOwner(packageName, ownerName, userId);
Amith Yamasani71e6c692013-03-24 17:39:28 -07002737 } catch (RemoteException re) {
2738 Log.w(TAG, "Failed to set device owner");
2739 }
2740 }
2741 return false;
2742 }
2743
2744 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002745 * Used to determine if a particular package has been registered as a Device Owner app.
2746 * A device owner app is a special device admin that cannot be deactivated by the user, once
Robin Lee25e26452015-06-02 09:56:29 -07002747 * activated as a device admin. It also cannot be uninstalled. To check whether a particular
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002748 * package is currently registered as the device owner app, pass in the package name from
2749 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
Robin Lee25e26452015-06-02 09:56:29 -07002750 * admin apps that want to check whether they are also registered as the device owner app. The
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002751 * exact mechanism by which a device admin app is registered as a device owner app is defined by
2752 * the setup process.
2753 * @param packageName the package name of the app, to compare with the registered device owner
2754 * app, if any.
2755 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002756 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002757 public boolean isDeviceOwnerApp(String packageName) {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002758 if (mService != null) {
2759 try {
2760 return mService.isDeviceOwner(packageName);
2761 } catch (RemoteException re) {
2762 Log.w(TAG, "Failed to check device owner");
2763 }
2764 }
2765 return false;
2766 }
2767
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002768 /**
2769 * @hide
2770 * Redirect to isDeviceOwnerApp.
2771 */
2772 public boolean isDeviceOwner(String packageName) {
2773 return isDeviceOwnerApp(packageName);
2774 }
2775
Jason Monkb0dced82014-06-06 14:36:20 -04002776 /**
2777 * Clears the current device owner. The caller must be the device owner.
2778 *
2779 * This function should be used cautiously as once it is called it cannot
2780 * be undone. The device owner can only be set as a part of device setup
2781 * before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04002782 *
2783 * @param packageName The package name of the device owner.
Jason Monkb0dced82014-06-06 14:36:20 -04002784 */
Jason Monk94d2cf92014-06-18 09:53:34 -04002785 public void clearDeviceOwnerApp(String packageName) {
Jason Monkb0dced82014-06-06 14:36:20 -04002786 if (mService != null) {
2787 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04002788 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04002789 } catch (RemoteException re) {
2790 Log.w(TAG, "Failed to clear device owner");
2791 }
2792 }
2793 }
2794
Amith Yamasani71e6c692013-03-24 17:39:28 -07002795 /** @hide */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002796 @SystemApi
Amith Yamasani71e6c692013-03-24 17:39:28 -07002797 public String getDeviceOwner() {
2798 if (mService != null) {
2799 try {
2800 return mService.getDeviceOwner();
2801 } catch (RemoteException re) {
2802 Log.w(TAG, "Failed to get device owner");
2803 }
2804 }
2805 return null;
2806 }
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002807
2808 /** @hide */
2809 public String getDeviceOwnerName() {
2810 if (mService != null) {
2811 try {
2812 return mService.getDeviceOwnerName();
2813 } catch (RemoteException re) {
2814 Log.w(TAG, "Failed to get device owner");
2815 }
2816 }
2817 return null;
2818 }
Adam Connors776c5552014-01-09 10:42:56 +00002819
2820 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04002821 * @hide
Julia Reynolds20118f12015-02-11 12:34:08 -05002822 * Sets the given component as the device initializer. The package must already be installed and
2823 * set as an active device administrator, and there must not be an existing device initializer,
2824 * for this call to succeed. This method can only be called by an app holding the
2825 * MANAGE_DEVICE_ADMINS permission before the device is provisioned or by a device owner app. A
2826 * device initializer app is granted device owner privileges during device initialization and
2827 * profile owner privileges during secondary user initialization.
Robin Lee25e26452015-06-02 09:56:29 -07002828 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2829 * {@code null} if not called by the device owner.
Julia Reynolds20118f12015-02-11 12:34:08 -05002830 * @param initializer Which {@link DeviceAdminReceiver} to make device initializer.
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002831 * @return whether the component was successfully registered as the device initializer.
2832 * @throws IllegalArgumentException if the componentname is null or invalid
Julia Reynolds20118f12015-02-11 12:34:08 -05002833 * @throws IllegalStateException if the caller is not device owner or the device has
2834 * already been provisioned or a device initializer already exists.
2835 */
Robin Lee25e26452015-06-02 09:56:29 -07002836 public boolean setDeviceInitializer(@Nullable ComponentName admin,
2837 @NonNull ComponentName initializer)
Julia Reynolds731051e2015-05-11 15:52:08 -04002838 throws IllegalArgumentException, IllegalStateException {
Julia Reynolds20118f12015-02-11 12:34:08 -05002839 if (mService != null) {
2840 try {
Robin Lee25e26452015-06-02 09:56:29 -07002841 return mService.setDeviceInitializer(admin, initializer);
Julia Reynolds20118f12015-02-11 12:34:08 -05002842 } catch (RemoteException re) {
2843 Log.w(TAG, "Failed to set device initializer");
2844 }
2845 }
2846 return false;
2847 }
2848
2849 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04002850 * @hide
Julia Reynolds20118f12015-02-11 12:34:08 -05002851 * Used to determine if a particular package has been registered as the device initializer.
2852 *
2853 * @param packageName the package name of the app, to compare with the registered device
2854 * initializer app, if any.
2855 * @return whether or not the caller is registered as the device initializer app.
2856 */
2857 public boolean isDeviceInitializerApp(String packageName) {
2858 if (mService != null) {
2859 try {
2860 return mService.isDeviceInitializer(packageName);
2861 } catch (RemoteException re) {
2862 Log.w(TAG, "Failed to check device initializer");
2863 }
2864 }
2865 return false;
2866 }
2867
2868 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04002869 * @hide
Julia Reynoldse9254402015-02-11 12:34:08 -05002870 * Removes the device initializer, so that it will not be invoked on user initialization for any
2871 * subsequently created users. This method can be called by either the device owner or device
Julia Reynolds1c3754a2015-03-05 10:06:41 -05002872 * initializer itself. The caller must be an active administrator.
2873 *
Robin Lee25e26452015-06-02 09:56:29 -07002874 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Julia Reynolds20118f12015-02-11 12:34:08 -05002875 */
Robin Lee25e26452015-06-02 09:56:29 -07002876 public void clearDeviceInitializerApp(@NonNull ComponentName admin) {
Julia Reynolds20118f12015-02-11 12:34:08 -05002877 if (mService != null) {
2878 try {
Robin Lee25e26452015-06-02 09:56:29 -07002879 mService.clearDeviceInitializer(admin);
Julia Reynolds20118f12015-02-11 12:34:08 -05002880 } catch (RemoteException re) {
2881 Log.w(TAG, "Failed to clear device initializer");
2882 }
2883 }
2884 }
2885
2886 /**
2887 * @hide
2888 * Gets the device initializer of the system.
2889 *
2890 * @return the package name of the device initializer.
2891 */
2892 @SystemApi
2893 public String getDeviceInitializerApp() {
2894 if (mService != null) {
2895 try {
2896 return mService.getDeviceInitializer();
2897 } catch (RemoteException re) {
2898 Log.w(TAG, "Failed to get device initializer");
2899 }
2900 }
2901 return null;
2902 }
2903
2904 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002905 * @hide
2906 * Gets the device initializer component of the system.
2907 *
2908 * @return the component name of the device initializer.
2909 */
2910 @SystemApi
2911 public ComponentName getDeviceInitializerComponent() {
2912 if (mService != null) {
2913 try {
2914 return mService.getDeviceInitializerComponent();
2915 } catch (RemoteException re) {
2916 Log.w(TAG, "Failed to get device initializer");
2917 }
2918 }
2919 return null;
2920 }
2921
2922
2923 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04002924 * @hide
Julia Reynolds20118f12015-02-11 12:34:08 -05002925 * Sets the enabled state of the user. A user should be enabled only once it is ready to
2926 * be used.
2927 *
2928 * <p>Device initializer must call this method to mark the user as functional.
2929 * Only the device initializer agent can call this.
2930 *
2931 * <p>When the user is enabled, if the device initializer is not also the device owner, the
2932 * device initializer will no longer have elevated permissions to call methods in this class.
2933 * Additionally, it will be removed as an active administrator and its
2934 * {@link DeviceAdminReceiver} will be disabled.
2935 *
2936 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2937 * @return whether the user is now enabled.
2938 */
Robin Lee25e26452015-06-02 09:56:29 -07002939 public boolean setUserEnabled(@NonNull ComponentName admin) {
Julia Reynolds20118f12015-02-11 12:34:08 -05002940 if (mService != null) {
2941 try {
2942 return mService.setUserEnabled(admin);
2943 } catch (RemoteException e) {
2944 Log.w(TAG, "Failed talking with device policy service", e);
2945 }
2946 }
2947 return false;
2948 }
2949
2950 /**
Adam Connors776c5552014-01-09 10:42:56 +00002951 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002952 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302953 * Sets the given component as an active admin and registers the package as the profile
2954 * owner for this user. The package must already be installed and there shouldn't be
2955 * an existing profile owner registered for this user. Also, this method must be called
2956 * before the user setup has been completed.
2957 * <p>
2958 * This method can only be called by system apps that hold MANAGE_USERS permission and
2959 * MANAGE_DEVICE_ADMINS permission.
2960 * @param admin The component to register as an active admin and profile owner.
2961 * @param ownerName The user-visible name of the entity that is managing this user.
2962 * @return whether the admin was successfully registered as the profile owner.
2963 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
2964 * the user has already been set up.
2965 */
Justin Morey80440cc2014-07-24 09:16:35 -05002966 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07002967 public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302968 throws IllegalArgumentException {
2969 if (mService != null) {
2970 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002971 final int myUserId = myUserId();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302972 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002973 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302974 } catch (RemoteException re) {
2975 Log.w(TAG, "Failed to set profile owner " + re);
2976 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2977 }
2978 }
2979 return false;
2980 }
2981
2982 /**
2983 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002984 * Clears the active profile owner and removes all user restrictions. The caller must
2985 * be from the same package as the active profile owner for this user, otherwise a
2986 * SecurityException will be thrown.
2987 *
2988 * @param admin The component to remove as the profile owner.
2989 * @return
2990 */
2991 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07002992 public void clearProfileOwner(@NonNull ComponentName admin) {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002993 if (mService != null) {
2994 try {
2995 mService.clearProfileOwner(admin);
2996 } catch (RemoteException re) {
2997 Log.w(TAG, "Failed to clear profile owner " + admin + re);
2998 }
2999 }
3000 }
3001
3002 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05003003 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003004 * Checks whether the user was already setup.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003005 */
3006 public boolean hasUserSetupCompleted() {
3007 if (mService != null) {
3008 try {
3009 return mService.hasUserSetupCompleted();
3010 } catch (RemoteException re) {
Robin Lee25e26452015-06-02 09:56:29 -07003011 Log.w(TAG, "Failed to check whether user setup has completed");
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003012 }
3013 }
3014 return true;
3015 }
3016
3017 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003018 * @hide
3019 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00003020 * already be installed. There must not already be a profile owner for this user.
3021 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
3022 * this method.
3023 * Calling this after the setup phase of the specified user has completed is allowed only if:
3024 * - the caller is SYSTEM_UID.
3025 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003026 * @param admin the component name to be registered as profile owner.
3027 * @param ownerName the human readable name of the organisation associated with this DPM.
3028 * @param userHandle the userId to set the profile owner for.
3029 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00003030 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
3031 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003032 */
Robin Lee25e26452015-06-02 09:56:29 -07003033 public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName,
Robin Leeddd553f2015-04-30 14:18:22 +01003034 int userHandle) throws IllegalArgumentException {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003035 if (admin == null) {
3036 throw new NullPointerException("admin cannot be null");
3037 }
Adam Connors776c5552014-01-09 10:42:56 +00003038 if (mService != null) {
3039 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003040 if (ownerName == null) {
3041 ownerName = "";
3042 }
3043 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00003044 } catch (RemoteException re) {
3045 Log.w(TAG, "Failed to set profile owner", re);
3046 throw new IllegalArgumentException("Couldn't set profile owner.", re);
3047 }
3048 }
3049 return false;
3050 }
3051
3052 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003053 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
3054 * be used. Only the profile owner can call this.
3055 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01003056 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003057 *
3058 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3059 */
Robin Lee25e26452015-06-02 09:56:29 -07003060 public void setProfileEnabled(@NonNull ComponentName admin) {
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003061 if (mService != null) {
3062 try {
3063 mService.setProfileEnabled(admin);
3064 } catch (RemoteException e) {
3065 Log.w(TAG, "Failed talking with device policy service", e);
3066 }
3067 }
3068 }
3069
3070 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003071 * Sets the name of the profile. In the device owner case it sets the name of the user
3072 * 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 +01003073 * never called by the profile or device owner, the name will be set to default values.
3074 *
3075 * @see #isProfileOwnerApp
3076 * @see #isDeviceOwnerApp
3077 *
Robin Lee25e26452015-06-02 09:56:29 -07003078 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01003079 * @param profileName The name of the profile.
3080 */
Robin Lee25e26452015-06-02 09:56:29 -07003081 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Jessica Hummel1333ea12014-06-23 11:20:10 +01003082 if (mService != null) {
3083 try {
Robin Lee25e26452015-06-02 09:56:29 -07003084 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07003085 } catch (RemoteException e) {
3086 Log.w(TAG, "Failed talking with device policy service", e);
3087 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01003088 }
3089 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01003090
3091 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003092 * Used to determine if a particular package is registered as the profile owner for the
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003093 * current user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003094 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00003095 *
3096 * @param packageName The package name of the app to compare with the registered profile owner.
3097 * @return Whether or not the package is registered as the profile owner.
3098 */
3099 public boolean isProfileOwnerApp(String packageName) {
3100 if (mService != null) {
3101 try {
Nicolas Prevot90af6d72014-07-30 14:19:12 +01003102 ComponentName profileOwner = mService.getProfileOwner(
3103 Process.myUserHandle().getIdentifier());
3104 return profileOwner != null
3105 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00003106 } catch (RemoteException re) {
3107 Log.w(TAG, "Failed to check profile owner");
3108 }
3109 }
3110 return false;
3111 }
3112
3113 /**
3114 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003115 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00003116 * owner has been set for that user.
3117 * @throws IllegalArgumentException if the userId is invalid.
3118 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01003119 @SystemApi
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003120 public ComponentName getProfileOwner() throws IllegalArgumentException {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003121 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
3122 }
3123
3124 /**
3125 * @see #getProfileOwner()
3126 * @hide
3127 */
3128 public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00003129 if (mService != null) {
3130 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003131 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00003132 } catch (RemoteException re) {
3133 Log.w(TAG, "Failed to get profile owner");
3134 throw new IllegalArgumentException(
3135 "Requested profile owner for invalid userId", re);
3136 }
3137 }
3138 return null;
3139 }
3140
3141 /**
3142 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003143 * @return the human readable name of the organisation associated with this DPM or {@code null}
3144 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00003145 * @throws IllegalArgumentException if the userId is invalid.
3146 */
3147 public String getProfileOwnerName() throws IllegalArgumentException {
3148 if (mService != null) {
3149 try {
3150 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
3151 } catch (RemoteException re) {
3152 Log.w(TAG, "Failed to get profile owner");
3153 throw new IllegalArgumentException(
3154 "Requested profile owner for invalid userId", re);
3155 }
3156 }
3157 return null;
3158 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003159
3160 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07003161 * @hide
3162 * @param user The user for whom to fetch the profile owner name, if any.
3163 * @return the human readable name of the organisation associated with this profile owner or
3164 * null if one is not set.
3165 * @throws IllegalArgumentException if the userId is invalid.
3166 */
3167 @SystemApi
Selim Cinek24ac55e2014-08-27 12:51:45 +02003168 public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Amith Yamasani38f836b2014-08-20 14:51:15 -07003169 if (mService != null) {
3170 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02003171 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07003172 } catch (RemoteException re) {
3173 Log.w(TAG, "Failed to get profile owner");
3174 throw new IllegalArgumentException(
3175 "Requested profile owner for invalid userId", re);
3176 }
3177 }
3178 return null;
3179 }
3180
3181 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003182 * Called by a profile owner or device owner to add a default intent handler activity for
3183 * intents that match a certain intent filter. This activity will remain the default intent
3184 * handler even if the set of potential event handlers for the intent filter changes and if
3185 * the intent preferences are reset.
3186 *
3187 * <p>The default disambiguation mechanism takes over if the activity is not installed
3188 * (anymore). When the activity is (re)installed, it is automatically reset as default
3189 * intent handler for the filter.
3190 *
3191 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
3192 * security exception will be thrown.
3193 *
3194 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3195 * @param filter The IntentFilter for which a default handler is added.
3196 * @param activity The Activity that is added as default intent handler.
3197 */
Robin Lee25e26452015-06-02 09:56:29 -07003198 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
3199 @NonNull ComponentName activity) {
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003200 if (mService != null) {
3201 try {
3202 mService.addPersistentPreferredActivity(admin, filter, activity);
3203 } catch (RemoteException e) {
3204 Log.w(TAG, "Failed talking with device policy service", e);
3205 }
3206 }
3207 }
3208
3209 /**
3210 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00003211 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003212 *
3213 * <p>The calling device admin must be a profile owner. If it is not, a security
3214 * exception will be thrown.
3215 *
3216 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3217 * @param packageName The name of the package for which preferences are removed.
3218 */
Robin Lee25e26452015-06-02 09:56:29 -07003219 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003220 String packageName) {
3221 if (mService != null) {
3222 try {
3223 mService.clearPackagePersistentPreferredActivities(admin, packageName);
3224 } catch (RemoteException e) {
3225 Log.w(TAG, "Failed talking with device policy service", e);
3226 }
3227 }
3228 }
Robin Lee66e5d962014-04-09 16:44:21 +01003229
3230 /**
3231 * Called by a profile or device owner to set the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003232 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01003233 *
Esteban Talavera6b8e0642015-08-10 17:26:04 +01003234 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be:
3235 * <ul>
3236 * <li>{@code boolean}
3237 * <li>{@code int}
3238 * <li>{@code String} or {@code String[]}
3239 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
3240 * </ul>
Robin Lee66e5d962014-04-09 16:44:21 +01003241 *
3242 * <p>The application restrictions are only made visible to the target application and the
3243 * profile or device owner.
3244 *
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003245 * <p>If the restrictions are not available yet, but may be applied in the near future,
3246 * the admin can notify the target application of that by adding
3247 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
3248 *
Robin Lee66e5d962014-04-09 16:44:21 +01003249 * <p>The calling device admin must be a profile or device owner; if it is not, a security
3250 * exception will be thrown.
3251 *
3252 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3253 * @param packageName The name of the package to update restricted settings for.
3254 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
3255 * set of active restrictions.
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003256 *
3257 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01003258 */
Robin Lee25e26452015-06-02 09:56:29 -07003259 public void setApplicationRestrictions(@NonNull ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01003260 Bundle settings) {
3261 if (mService != null) {
3262 try {
3263 mService.setApplicationRestrictions(admin, packageName, settings);
3264 } catch (RemoteException e) {
3265 Log.w(TAG, "Failed talking with device policy service", e);
3266 }
3267 }
3268 }
3269
3270 /**
Jim Millere303bf42014-08-26 17:12:29 -07003271 * Sets a list of configuration features to enable for a TrustAgent component. This is meant
3272 * to be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all
3273 * trust agents but those enabled by this function call. If flag
3274 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Jim Miller604e7552014-07-18 19:00:02 -07003275 *
3276 * <p>The calling device admin must have requested
3277 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millere303bf42014-08-26 17:12:29 -07003278 * this method; if not, a security exception will be thrown.
Jim Miller604e7552014-07-18 19:00:02 -07003279 *
3280 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07003281 * @param target Component name of the agent to be enabled.
Jim Millerb5db57a2015-01-14 18:17:19 -08003282 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent
Jim Millere303bf42014-08-26 17:12:29 -07003283 * will be strictly disabled according to the state of the
3284 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
3285 * <p>If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all admins,
3286 * then it's up to the TrustAgent itself to aggregate the values from all device admins.
3287 * <p>Consult documentation for the specific TrustAgent to determine legal options parameters.
Jim Miller604e7552014-07-18 19:00:02 -07003288 */
Robin Lee25e26452015-06-02 09:56:29 -07003289 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
3290 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07003291 if (mService != null) {
3292 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003293 mService.setTrustAgentConfiguration(admin, target, configuration);
Jim Miller604e7552014-07-18 19:00:02 -07003294 } catch (RemoteException e) {
3295 Log.w(TAG, "Failed talking with device policy service", e);
3296 }
3297 }
3298 }
3299
3300 /**
Jim Millere303bf42014-08-26 17:12:29 -07003301 * Gets configuration for the given trust agent based on aggregating all calls to
3302 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
3303 * all device admins.
Jim Miller604e7552014-07-18 19:00:02 -07003304 *
Jim Millerb5db57a2015-01-14 18:17:19 -08003305 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
3306 * this function returns a list of configurations for all admins that declare
3307 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
3308 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
3309 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
3310 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07003311 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07003312 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07003313 */
Robin Lee25e26452015-06-02 09:56:29 -07003314 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
3315 @NonNull ComponentName agent) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003316 return getTrustAgentConfiguration(admin, agent, myUserId());
Jim Millere303bf42014-08-26 17:12:29 -07003317 }
3318
3319 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003320 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
3321 @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07003322 if (mService != null) {
3323 try {
Jim Millere303bf42014-08-26 17:12:29 -07003324 return mService.getTrustAgentConfiguration(admin, agent, userHandle);
Jim Miller604e7552014-07-18 19:00:02 -07003325 } catch (RemoteException e) {
3326 Log.w(TAG, "Failed talking with device policy service", e);
3327 }
3328 }
Jim Millere303bf42014-08-26 17:12:29 -07003329 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07003330 }
3331
3332 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003333 * Called by a profile owner of a managed profile to set whether caller-Id information from
3334 * the managed profile will be shown in the parent profile, for incoming calls.
Adam Connors210fe212014-07-17 15:41:43 +01003335 *
3336 * <p>The calling device admin must be a profile owner. If it is not, a
3337 * security exception will be thrown.
3338 *
Robin Lee25e26452015-06-02 09:56:29 -07003339 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01003340 * @param disabled If true caller-Id information in the managed profile is not displayed.
3341 */
Robin Lee25e26452015-06-02 09:56:29 -07003342 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Adam Connors210fe212014-07-17 15:41:43 +01003343 if (mService != null) {
3344 try {
Robin Lee25e26452015-06-02 09:56:29 -07003345 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01003346 } catch (RemoteException e) {
3347 Log.w(TAG, "Failed talking with device policy service", e);
3348 }
3349 }
3350 }
3351
3352 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003353 * Called by a profile owner of a managed profile to determine whether or not caller-Id
3354 * information has been disabled.
Adam Connors210fe212014-07-17 15:41:43 +01003355 *
3356 * <p>The calling device admin must be a profile owner. If it is not, a
3357 * security exception will be thrown.
3358 *
Robin Lee25e26452015-06-02 09:56:29 -07003359 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01003360 */
Robin Lee25e26452015-06-02 09:56:29 -07003361 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Adam Connors210fe212014-07-17 15:41:43 +01003362 if (mService != null) {
3363 try {
Robin Lee25e26452015-06-02 09:56:29 -07003364 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01003365 } catch (RemoteException e) {
3366 Log.w(TAG, "Failed talking with device policy service", e);
3367 }
3368 }
3369 return false;
3370 }
3371
3372 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07003373 * Determine whether or not caller-Id information has been disabled.
3374 *
3375 * @param userHandle The user for whom to check the caller-id permission
3376 * @hide
3377 */
3378 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
3379 if (mService != null) {
3380 try {
3381 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
3382 } catch (RemoteException e) {
3383 Log.w(TAG, "Failed talking with device policy service", e);
3384 }
3385 }
3386 return false;
3387 }
3388
3389 /**
Makoto Onuki1040da12015-03-19 11:24:00 -07003390 * Start Quick Contact on the managed profile for the current user, if the policy allows.
3391 * @hide
3392 */
3393 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
3394 Intent originalIntent) {
3395 if (mService != null) {
3396 try {
3397 mService.startManagedQuickContact(
3398 actualLookupKey, actualContactId, originalIntent);
3399 } catch (RemoteException e) {
3400 Log.w(TAG, "Failed talking with device policy service", e);
3401 }
3402 }
3403 }
3404
3405 /**
Ricky Wai778ba132015-03-31 14:21:22 +01003406 * Called by a profile owner of a managed profile to set whether bluetooth
3407 * devices can access enterprise contacts.
3408 * <p>
3409 * The calling device admin must be a profile owner. If it is not, a
3410 * security exception will be thrown.
3411 * <p>
3412 * This API works on managed profile only.
3413 *
Robin Lee25e26452015-06-02 09:56:29 -07003414 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01003415 * with.
3416 * @param disabled If true, bluetooth devices cannot access enterprise
3417 * contacts.
3418 */
Robin Lee25e26452015-06-02 09:56:29 -07003419 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Ricky Wai778ba132015-03-31 14:21:22 +01003420 if (mService != null) {
3421 try {
Robin Lee25e26452015-06-02 09:56:29 -07003422 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01003423 } catch (RemoteException e) {
3424 Log.w(TAG, "Failed talking with device policy service", e);
3425 }
3426 }
3427 }
3428
3429 /**
3430 * Called by a profile owner of a managed profile to determine whether or
3431 * not Bluetooth devices cannot access enterprise contacts.
3432 * <p>
3433 * The calling device admin must be a profile owner. If it is not, a
3434 * security exception will be thrown.
3435 * <p>
3436 * This API works on managed profile only.
3437 *
Robin Lee25e26452015-06-02 09:56:29 -07003438 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01003439 * with.
3440 */
Robin Lee25e26452015-06-02 09:56:29 -07003441 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Ricky Wai778ba132015-03-31 14:21:22 +01003442 if (mService != null) {
3443 try {
Robin Lee25e26452015-06-02 09:56:29 -07003444 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01003445 } catch (RemoteException e) {
3446 Log.w(TAG, "Failed talking with device policy service", e);
3447 }
3448 }
3449 return true;
3450 }
3451
3452 /**
3453 * Determine whether or not Bluetooth devices cannot access contacts.
3454 * <p>
3455 * This API works on managed profile UserHandle only.
3456 *
3457 * @param userHandle The user for whom to check the caller-id permission
3458 * @hide
3459 */
3460 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
3461 if (mService != null) {
3462 try {
3463 return mService.getBluetoothContactSharingDisabledForUser(userHandle
3464 .getIdentifier());
3465 } catch (RemoteException e) {
3466 Log.w(TAG, "Failed talking with device policy service", e);
3467 }
3468 }
3469 return true;
3470 }
3471
3472 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003473 * Called by the profile owner of a managed profile so that some intents sent in the managed
3474 * profile can also be resolved in the parent, or vice versa.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00003475 * Only activity intents are supported.
3476 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003477 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01003478 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
3479 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01003480 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
3481 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003482 */
Robin Lee25e26452015-06-02 09:56:29 -07003483 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003484 if (mService != null) {
3485 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003486 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003487 } catch (RemoteException e) {
3488 Log.w(TAG, "Failed talking with device policy service", e);
3489 }
3490 }
3491 }
3492
3493 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003494 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
3495 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01003496 * Only removes those that have been set by the profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003497 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3498 */
Robin Lee25e26452015-06-02 09:56:29 -07003499 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003500 if (mService != null) {
3501 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003502 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003503 } catch (RemoteException e) {
3504 Log.w(TAG, "Failed talking with device policy service", e);
3505 }
3506 }
3507 }
3508
3509 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003510 * Called by a profile or device owner to set the permitted accessibility services. When
3511 * set by a device owner or profile owner the restriction applies to all profiles of the
3512 * user the device owner or profile owner is an admin for.
Jim Millerb1474f42014-08-26 18:42:58 -07003513 *
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003514 * By default the user can use any accessiblity service. When zero or more packages have
3515 * been added, accessiblity services that are not in the list and not part of the system
Jim Millerb1474f42014-08-26 18:42:58 -07003516 * can not be enabled by the user.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003517 *
3518 * <p> Calling with a null value for the list disables the restriction so that all services
3519 * can be used, calling with an empty list only allows the builtin system's services.
3520 *
3521 * <p> System accesibility services are always available to the user the list can't modify
3522 * this.
3523 *
3524 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3525 * @param packageNames List of accessibility service package names.
3526 *
3527 * @return true if setting the restriction succeeded. It fail if there is
3528 * one or more non-system accessibility services enabled, that are not in the list.
3529 */
Robin Lee25e26452015-06-02 09:56:29 -07003530 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003531 List<String> packageNames) {
3532 if (mService != null) {
3533 try {
3534 return mService.setPermittedAccessibilityServices(admin, packageNames);
3535 } catch (RemoteException e) {
3536 Log.w(TAG, "Failed talking with device policy service", e);
3537 }
3538 }
3539 return false;
3540 }
3541
3542 /**
3543 * Returns the list of permitted accessibility services set by this device or profile owner.
3544 *
3545 * <p>An empty list means no accessibility services except system services are allowed.
3546 * Null means all accessibility services are allowed.
3547 *
3548 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3549 * @return List of accessiblity service package names.
3550 */
Robin Lee25e26452015-06-02 09:56:29 -07003551 public List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003552 if (mService != null) {
3553 try {
3554 return mService.getPermittedAccessibilityServices(admin);
3555 } catch (RemoteException e) {
3556 Log.w(TAG, "Failed talking with device policy service", e);
3557 }
3558 }
3559 return null;
3560 }
3561
3562 /**
3563 * Returns the list of accessibility services permitted by the device or profiles
3564 * owners of this user.
3565 *
3566 * <p>Null means all accessibility services are allowed, if a non-null list is returned
3567 * it will contain the intersection of the permitted lists for any device or profile
3568 * owners that apply to this user. It will also include any system accessibility services.
3569 *
3570 * @param userId which user to check for.
3571 * @return List of accessiblity service package names.
3572 * @hide
3573 */
3574 @SystemApi
3575 public List<String> getPermittedAccessibilityServices(int userId) {
3576 if (mService != null) {
3577 try {
3578 return mService.getPermittedAccessibilityServicesForUser(userId);
3579 } catch (RemoteException e) {
3580 Log.w(TAG, "Failed talking with device policy service", e);
3581 }
3582 }
3583 return null;
3584 }
3585
3586 /**
3587 * Called by a profile or device owner to set the permitted input methods services. When
3588 * set by a device owner or profile owner the restriction applies to all profiles of the
3589 * user the device owner or profile owner is an admin for.
3590 *
3591 * By default the user can use any input method. When zero or more packages have
3592 * been added, input method that are not in the list and not part of the system
3593 * can not be enabled by the user.
3594 *
3595 * This method will fail if it is called for a admin that is not for the foreground user
3596 * or a profile of the foreground user.
3597 *
3598 * <p> Calling with a null value for the list disables the restriction so that all input methods
3599 * can be used, calling with an empty list disables all but the system's own input methods.
3600 *
3601 * <p> System input methods are always available to the user this method can't modify this.
3602 *
3603 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3604 * @param packageNames List of input method package names.
Kenny Guy74a70242015-02-05 19:48:38 +00003605 * @return true if setting the restriction succeeded. It will fail if there are
3606 * one or more non-system input methods currently enabled that are not in
3607 * the packageNames list.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003608 */
Robin Lee25e26452015-06-02 09:56:29 -07003609 public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003610 if (mService != null) {
3611 try {
3612 return mService.setPermittedInputMethods(admin, packageNames);
3613 } catch (RemoteException e) {
3614 Log.w(TAG, "Failed talking with device policy service", e);
3615 }
3616 }
3617 return false;
3618 }
3619
3620
3621 /**
3622 * Returns the list of permitted input methods set by this device or profile owner.
3623 *
3624 * <p>An empty list means no input methods except system input methods are allowed.
3625 * Null means all input methods are allowed.
3626 *
3627 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3628 * @return List of input method package names.
3629 */
Robin Lee25e26452015-06-02 09:56:29 -07003630 public List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003631 if (mService != null) {
3632 try {
3633 return mService.getPermittedInputMethods(admin);
3634 } catch (RemoteException e) {
3635 Log.w(TAG, "Failed talking with device policy service", e);
3636 }
3637 }
3638 return null;
3639 }
3640
3641 /**
3642 * Returns the list of input methods permitted by the device or profiles
3643 * owners of the current user.
3644 *
3645 * <p>Null means all input methods are allowed, if a non-null list is returned
3646 * it will contain the intersection of the permitted lists for any device or profile
3647 * owners that apply to this user. It will also include any system input methods.
3648 *
3649 * @return List of input method package names.
3650 * @hide
3651 */
3652 @SystemApi
3653 public List<String> getPermittedInputMethodsForCurrentUser() {
3654 if (mService != null) {
3655 try {
3656 return mService.getPermittedInputMethodsForCurrentUser();
3657 } catch (RemoteException e) {
3658 Log.w(TAG, "Failed talking with device policy service", e);
3659 }
3660 }
3661 return null;
3662 }
3663
3664 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003665 * Called by a device owner to create a user with the specified name. The UserHandle returned
3666 * by this method should not be persisted as user handles are recycled as users are removed and
3667 * created. If you need to persist an identifier for this user, use
3668 * {@link UserManager#getSerialNumberForUser}.
3669 *
3670 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3671 * @param name the user's name
3672 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07003673 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
3674 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01003675 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07003676 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
Julia Reynolds1e958392014-05-16 14:25:21 -04003677 */
Kenny Guy14f48e52015-06-29 15:12:36 +01003678 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07003679 public UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04003680 try {
3681 return mService.createUser(admin, name);
3682 } catch (RemoteException re) {
3683 Log.w(TAG, "Could not create a user", re);
3684 }
3685 return null;
3686 }
3687
3688 /**
Jason Monk03978a42014-06-10 15:05:30 -04003689 * Called by a device owner to create a user with the specified name. The UserHandle returned
3690 * by this method should not be persisted as user handles are recycled as users are removed and
3691 * created. If you need to persist an identifier for this user, use
3692 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
3693 * immediately.
3694 *
3695 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
3696 * as registered as an active admin on the new user. The profile owner package will be
3697 * installed on the new user if it already is installed on the device.
3698 *
3699 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
3700 * profileOwnerComponent when onEnable is called.
3701 *
3702 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3703 * @param name the user's name
3704 * @param ownerName the human readable name of the organisation associated with this DPM.
3705 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
3706 * the user.
3707 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
3708 * on the new user.
3709 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07003710 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
3711 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01003712 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07003713 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
Jason Monk03978a42014-06-10 15:05:30 -04003714 */
Kenny Guy14f48e52015-06-29 15:12:36 +01003715 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07003716 public UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
3717 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04003718 try {
3719 return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent,
3720 adminExtras);
3721 } catch (RemoteException re) {
3722 Log.w(TAG, "Could not create a user", re);
3723 }
3724 return null;
3725 }
3726
3727 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003728 * Called by a device owner to remove a user and all associated data. The primary user can
3729 * not be removed.
3730 *
3731 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3732 * @param userHandle the user to remove.
3733 * @return {@code true} if the user was removed, {@code false} otherwise.
3734 */
Robin Lee25e26452015-06-02 09:56:29 -07003735 public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) {
Julia Reynolds1e958392014-05-16 14:25:21 -04003736 try {
3737 return mService.removeUser(admin, userHandle);
3738 } catch (RemoteException re) {
3739 Log.w(TAG, "Could not remove user ", re);
3740 return false;
3741 }
3742 }
3743
3744 /**
Jason Monk582d9112014-07-09 19:57:08 -04003745 * Called by a device owner to switch the specified user to the foreground.
3746 *
3747 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3748 * @param userHandle the user to switch to; null will switch to primary.
3749 * @return {@code true} if the switch was successful, {@code false} otherwise.
3750 *
3751 * @see Intent#ACTION_USER_FOREGROUND
3752 */
Robin Lee25e26452015-06-02 09:56:29 -07003753 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Jason Monk582d9112014-07-09 19:57:08 -04003754 try {
3755 return mService.switchUser(admin, userHandle);
3756 } catch (RemoteException re) {
3757 Log.w(TAG, "Could not switch user ", re);
3758 return false;
3759 }
3760 }
3761
3762 /**
Robin Lee66e5d962014-04-09 16:44:21 +01003763 * Called by a profile or device owner to get the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003764 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01003765 *
3766 * <p>The calling device admin must be a profile or device owner; if it is not, a security
3767 * exception will be thrown.
3768 *
3769 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3770 * @param packageName The name of the package to fetch restricted settings of.
3771 * @return {@link Bundle} of settings corresponding to what was set last time
3772 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
3773 * if no restrictions have been set.
3774 */
Robin Lee25e26452015-06-02 09:56:29 -07003775 public Bundle getApplicationRestrictions(@NonNull ComponentName admin, String packageName) {
Robin Lee66e5d962014-04-09 16:44:21 +01003776 if (mService != null) {
3777 try {
3778 return mService.getApplicationRestrictions(admin, packageName);
3779 } catch (RemoteException e) {
3780 Log.w(TAG, "Failed talking with device policy service", e);
3781 }
3782 }
3783 return null;
3784 }
Amith Yamasanibe465322014-04-24 13:45:17 -07003785
3786 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003787 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07003788 * <p>
3789 * The calling device admin must be a profile or device owner; if it is not,
3790 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003791 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003792 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3793 * with.
3794 * @param key The key of the restriction. See the constants in
3795 * {@link android.os.UserManager} for the list of keys.
3796 */
Robin Lee25e26452015-06-02 09:56:29 -07003797 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07003798 if (mService != null) {
3799 try {
3800 mService.setUserRestriction(admin, key, true);
3801 } catch (RemoteException e) {
3802 Log.w(TAG, "Failed talking with device policy service", e);
3803 }
3804 }
3805 }
3806
3807 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003808 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07003809 * <p>
3810 * The calling device admin must be a profile or device owner; if it is not,
3811 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003812 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003813 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3814 * with.
3815 * @param key The key of the restriction. See the constants in
3816 * {@link android.os.UserManager} for the list of keys.
3817 */
Robin Lee25e26452015-06-02 09:56:29 -07003818 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07003819 if (mService != null) {
3820 try {
3821 mService.setUserRestriction(admin, key, false);
3822 } catch (RemoteException e) {
3823 Log.w(TAG, "Failed talking with device policy service", e);
3824 }
3825 }
3826 }
Adam Connors010cfd42014-04-16 12:48:13 +01003827
3828 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003829 * Called by profile or device owners to hide or unhide packages. When a package is hidden it
Julia Reynolds966881e2014-05-14 12:23:08 -04003830 * is unavailable for use, but the data and actual package file remain.
3831 *
3832 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003833 * @param packageName The name of the package to hide or unhide.
3834 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
3835 * unhidden.
3836 * @return boolean Whether the hidden setting of the package was successfully updated.
Julia Reynolds966881e2014-05-14 12:23:08 -04003837 */
Robin Lee25e26452015-06-02 09:56:29 -07003838 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003839 boolean hidden) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003840 if (mService != null) {
3841 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003842 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04003843 } catch (RemoteException e) {
3844 Log.w(TAG, "Failed talking with device policy service", e);
3845 }
3846 }
3847 return false;
3848 }
3849
3850 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003851 * Called by profile or device owners to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04003852 *
3853 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003854 * @param packageName The name of the package to retrieve the hidden status of.
3855 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Julia Reynolds966881e2014-05-14 12:23:08 -04003856 */
Robin Lee25e26452015-06-02 09:56:29 -07003857 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003858 if (mService != null) {
3859 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003860 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04003861 } catch (RemoteException e) {
3862 Log.w(TAG, "Failed talking with device policy service", e);
3863 }
3864 }
3865 return false;
3866 }
3867
3868 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003869 * Called by profile or device owners to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003870 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003871 *
3872 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3873 * @param packageName The package to be re-enabled in the current profile.
3874 */
Robin Lee25e26452015-06-02 09:56:29 -07003875 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Adam Connors655be2a2014-07-14 09:01:25 +00003876 if (mService != null) {
3877 try {
3878 mService.enableSystemApp(admin, packageName);
3879 } catch (RemoteException e) {
3880 Log.w(TAG, "Failed to install package: " + packageName);
3881 }
3882 }
3883 }
3884
3885 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003886 * Called by profile or device owners to re-enable system apps by intent that were disabled
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003887 * by default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003888 *
3889 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3890 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
3891 * intent will be re-enabled in the current profile.
3892 * @return int The number of activities that matched the intent and were installed.
3893 */
Robin Lee25e26452015-06-02 09:56:29 -07003894 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Adam Connors655be2a2014-07-14 09:01:25 +00003895 if (mService != null) {
3896 try {
3897 return mService.enableSystemAppWithIntent(admin, intent);
3898 } catch (RemoteException e) {
3899 Log.w(TAG, "Failed to install packages matching filter: " + intent);
3900 }
3901 }
3902 return 0;
3903 }
3904
3905 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00003906 * Called by a device owner or profile owner to disable account management for a specific type
3907 * of account.
Sander Alewijnse650c3342014-05-08 18:00:50 +01003908 *
Sander Alewijnse112e0532014-10-29 13:28:49 +00003909 * <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 +01003910 * security exception will be thrown.
3911 *
3912 * <p>When account management is disabled for an account type, adding or removing an account
3913 * of that type will not be possible.
3914 *
3915 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3916 * @param accountType For which account management is disabled or enabled.
3917 * @param disabled The boolean indicating that account management will be disabled (true) or
3918 * enabled (false).
3919 */
Robin Lee25e26452015-06-02 09:56:29 -07003920 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01003921 boolean disabled) {
3922 if (mService != null) {
3923 try {
3924 mService.setAccountManagementDisabled(admin, accountType, disabled);
3925 } catch (RemoteException e) {
3926 Log.w(TAG, "Failed talking with device policy service", e);
3927 }
3928 }
3929 }
3930
3931 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003932 * Gets the array of accounts for which account management is disabled by the profile owner.
3933 *
3934 * <p> Account management can be disabled/enabled by calling
3935 * {@link #setAccountManagementDisabled}.
3936 *
3937 * @return a list of account types for which account management has been disabled.
3938 *
3939 * @see #setAccountManagementDisabled
3940 */
3941 public String[] getAccountTypesWithManagementDisabled() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003942 return getAccountTypesWithManagementDisabledAsUser(myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003943 }
3944
3945 /**
3946 * @see #getAccountTypesWithManagementDisabled()
3947 * @hide
3948 */
3949 public String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003950 if (mService != null) {
3951 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003952 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003953 } catch (RemoteException e) {
3954 Log.w(TAG, "Failed talking with device policy service", e);
3955 }
3956 }
3957
3958 return null;
3959 }
justinzhang511e0d82014-03-24 16:09:24 -04003960
3961 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003962 * Sets which packages may enter lock task mode.
3963 *
3964 * <p>Any packages that shares uid with an allowed package will also be allowed
3965 * to activate lock task.
justinzhang511e0d82014-03-24 16:09:24 -04003966 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07003967 * From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task
Benjamin Franz469dd582015-06-09 14:24:36 +01003968 * package list results in locked tasks belonging to those packages to be finished.
3969 *
Jason Monkc5185f22014-06-24 11:12:42 -04003970 * This function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04003971 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04003972 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jason Monkd7b86212014-06-16 13:15:38 -04003973 *
3974 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00003975 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
3976 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04003977 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04003978 */
Robin Lee25e26452015-06-02 09:56:29 -07003979 public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04003980 throws SecurityException {
justinzhang511e0d82014-03-24 16:09:24 -04003981 if (mService != null) {
3982 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003983 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04003984 } catch (RemoteException e) {
3985 Log.w(TAG, "Failed talking with device policy service", e);
3986 }
3987 }
3988 }
3989
3990 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003991 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04003992 *
3993 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04003994 * @hide
3995 */
Robin Lee25e26452015-06-02 09:56:29 -07003996 public String[] getLockTaskPackages(@NonNull ComponentName admin) {
justinzhang511e0d82014-03-24 16:09:24 -04003997 if (mService != null) {
3998 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003999 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04004000 } catch (RemoteException e) {
4001 Log.w(TAG, "Failed talking with device policy service", e);
4002 }
4003 }
4004 return null;
4005 }
4006
4007 /**
4008 * This function lets the caller know whether the given component is allowed to start the
4009 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04004010 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04004011 */
Jason Monkd7b86212014-06-16 13:15:38 -04004012 public boolean isLockTaskPermitted(String pkg) {
justinzhang511e0d82014-03-24 16:09:24 -04004013 if (mService != null) {
4014 try {
Jason Monkd7b86212014-06-16 13:15:38 -04004015 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04004016 } catch (RemoteException e) {
4017 Log.w(TAG, "Failed talking with device policy service", e);
4018 }
4019 }
4020 return false;
4021 }
Julia Reynoldsda551652014-05-14 17:15:16 -04004022
4023 /**
4024 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
4025 * 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 -04004026 * <p>The settings that can be updated with this method are:
4027 * <ul>
4028 * <li>{@link Settings.Global#ADB_ENABLED}</li>
4029 * <li>{@link Settings.Global#AUTO_TIME}</li>
4030 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004031 * <li>{@link Settings.Global#DATA_ROAMING}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004032 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004033 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Benjamin Franz68cc4202015-03-11 15:43:06 +00004034 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN}
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004035 * This setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards
Esteban Talavera656fa7f2015-06-29 17:41:39 +01004036 * and can only be set if {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
Zoltan Szatmary-Ban4045d242015-05-27 12:42:39 +01004037 * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004038 * This setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards.
Zoltan Szatmary-Ban3c430952015-07-03 14:04:09 +01004039 * </li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004040 * </ul>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01004041 * <p>Changing the following settings has no effect as of
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004042 * {@link android.os.Build.VERSION_CODES#M}:
Esteban Talavera656fa7f2015-06-29 17:41:39 +01004043 * <ul>
4044 * <li>{@link Settings.Global#BLUETOOTH_ON}.
4045 * Use {@link android.bluetooth.BluetoothAdapter#enable()} and
4046 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
4047 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
4048 * <li>{@link Settings.Global#MODE_RINGER}.
4049 * Use {@link android.media.AudioManager#setRingerMode(int)} instead.</li>
4050 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
4051 * <li>{@link Settings.Global#WIFI_ON}.
4052 * Use {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
4053 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04004054 *
4055 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4056 * @param setting The name of the setting to update.
4057 * @param value The value to update the setting to.
4058 */
Robin Lee25e26452015-06-02 09:56:29 -07004059 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04004060 if (mService != null) {
4061 try {
4062 mService.setGlobalSetting(admin, setting, value);
4063 } catch (RemoteException e) {
4064 Log.w(TAG, "Failed talking with device policy service", e);
4065 }
4066 }
4067 }
4068
4069 /**
4070 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
4071 * that the value of the setting is in the correct form for the setting type should be performed
4072 * by the caller.
Julia Reynolds82735bc2014-09-04 16:43:30 -04004073 * <p>The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004074 * <ul>
4075 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07004076 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004077 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
4078 * </ul>
Julia Reynolds82735bc2014-09-04 16:43:30 -04004079 * <p>A device owner can additionally update the following settings:
4080 * <ul>
4081 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
4082 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04004083 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4084 * @param setting The name of the setting to update.
4085 * @param value The value to update the setting to.
4086 */
Robin Lee25e26452015-06-02 09:56:29 -07004087 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04004088 if (mService != null) {
4089 try {
4090 mService.setSecureSetting(admin, setting, value);
4091 } catch (RemoteException e) {
4092 Log.w(TAG, "Failed talking with device policy service", e);
4093 }
4094 }
4095 }
4096
Amith Yamasanif20d6402014-05-24 15:34:37 -07004097 /**
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004098 * Designates a specific service component as the provider for
Amith Yamasanif20d6402014-05-24 15:34:37 -07004099 * making permission requests of a local or remote administrator of the user.
4100 * <p/>
4101 * Only a profile owner can designate the restrictions provider.
4102 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004103 * @param provider The component name of the service that implements
Amith Yamasanid1d7c022014-08-19 17:03:41 -07004104 * {@link RestrictionsReceiver}. If this param is null,
Amith Yamasanif20d6402014-05-24 15:34:37 -07004105 * it removes the restrictions provider previously assigned.
4106 */
Robin Lee25e26452015-06-02 09:56:29 -07004107 public void setRestrictionsProvider(@NonNull ComponentName admin,
4108 @Nullable ComponentName provider) {
Amith Yamasanif20d6402014-05-24 15:34:37 -07004109 if (mService != null) {
4110 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004111 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07004112 } catch (RemoteException re) {
4113 Log.w(TAG, "Failed to set permission provider on device policy service");
4114 }
4115 }
4116 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04004117
4118 /**
4119 * Called by profile or device owners to set the master volume mute on or off.
4120 *
4121 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4122 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
4123 */
Robin Lee25e26452015-06-02 09:56:29 -07004124 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04004125 if (mService != null) {
4126 try {
4127 mService.setMasterVolumeMuted(admin, on);
4128 } catch (RemoteException re) {
4129 Log.w(TAG, "Failed to setMasterMute on device policy service");
4130 }
4131 }
4132 }
4133
4134 /**
4135 * Called by profile or device owners to check whether the master volume mute is on or off.
4136 *
4137 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4138 * @return {@code true} if master volume is muted, {@code false} if it's not.
4139 */
Robin Lee25e26452015-06-02 09:56:29 -07004140 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04004141 if (mService != null) {
4142 try {
4143 return mService.isMasterVolumeMuted(admin);
4144 } catch (RemoteException re) {
4145 Log.w(TAG, "Failed to get isMasterMute on device policy service");
4146 }
4147 }
4148 return false;
4149 }
Kenny Guyc13053b2014-05-29 14:17:17 +01004150
4151 /**
4152 * Called by profile or device owners to change whether a user can uninstall
4153 * a package.
4154 *
4155 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4156 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004157 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Kenny Guyc13053b2014-05-29 14:17:17 +01004158 */
Robin Lee25e26452015-06-02 09:56:29 -07004159 public void setUninstallBlocked(@NonNull ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004160 boolean uninstallBlocked) {
Kenny Guyc13053b2014-05-29 14:17:17 +01004161 if (mService != null) {
4162 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004163 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01004164 } catch (RemoteException re) {
4165 Log.w(TAG, "Failed to call block uninstall on device policy service");
4166 }
4167 }
4168 }
4169
4170 /**
Rubin Xua97855b2014-11-07 05:41:00 +00004171 * Check whether the current user has been blocked by device policy from uninstalling a package.
4172 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00004173 * <p>
4174 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Robin Lee25e26452015-06-02 09:56:29 -07004175 * behavior of this API is changed such that passing {@code null} as the {@code admin}
Rubin Xue1e6faa2015-03-10 10:51:59 +00004176 * parameter will return if any admin has blocked the uninstallation. Before L MR1, passing
Robin Lee25e26452015-06-02 09:56:29 -07004177 * {@code null} will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01004178 *
Robin Lee25e26452015-06-02 09:56:29 -07004179 * @param admin The name of the admin component whose blocking policy will be checked, or
4180 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01004181 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00004182 * @return true if uninstallation is blocked.
Kenny Guyc13053b2014-05-29 14:17:17 +01004183 */
Robin Lee25e26452015-06-02 09:56:29 -07004184 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Kenny Guyc13053b2014-05-29 14:17:17 +01004185 if (mService != null) {
4186 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01004187 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01004188 } catch (RemoteException re) {
4189 Log.w(TAG, "Failed to call block uninstall on device policy service");
4190 }
4191 }
4192 return false;
4193 }
Svetoslav976e8bd2014-07-16 15:12:03 -07004194
4195 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004196 * Called by the profile owner of a managed profile to enable widget providers from a
4197 * given package to be available in the parent profile. As a result the user will be able to
Svetoslav976e8bd2014-07-16 15:12:03 -07004198 * add widgets from the white-listed package running under the profile to a widget
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004199 * host which runs under the parent profile, for example the home screen. Note that
Svetoslav976e8bd2014-07-16 15:12:03 -07004200 * a package may have zero or more provider components, where each component
4201 * provides a different widget type.
4202 * <p>
4203 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07004204 *
4205 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4206 * @param packageName The package from which widget providers are white-listed.
4207 * @return Whether the package was added.
4208 *
4209 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4210 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4211 */
Robin Lee25e26452015-06-02 09:56:29 -07004212 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004213 if (mService != null) {
4214 try {
4215 return mService.addCrossProfileWidgetProvider(admin, packageName);
4216 } catch (RemoteException re) {
4217 Log.w(TAG, "Error calling addCrossProfileWidgetProvider", re);
4218 }
4219 }
4220 return false;
4221 }
4222
4223 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004224 * Called by the profile owner of a managed profile to disable widget providers from a given
4225 * package to be available in the parent profile. For this method to take effect the
Svetoslav976e8bd2014-07-16 15:12:03 -07004226 * package should have been added via {@link #addCrossProfileWidgetProvider(
4227 * android.content.ComponentName, String)}.
4228 * <p>
4229 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07004230 *
4231 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4232 * @param packageName The package from which widget providers are no longer
4233 * white-listed.
4234 * @return Whether the package was removed.
4235 *
4236 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
4237 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4238 */
Robin Lee25e26452015-06-02 09:56:29 -07004239 public boolean removeCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004240 if (mService != null) {
4241 try {
4242 return mService.removeCrossProfileWidgetProvider(admin, packageName);
4243 } catch (RemoteException re) {
4244 Log.w(TAG, "Error calling removeCrossProfileWidgetProvider", re);
4245 }
4246 }
4247 return false;
4248 }
4249
4250 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004251 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07004252 * available in the parent profile.
4253 *
4254 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4255 * @return The white-listed package list.
4256 *
4257 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
4258 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4259 */
Robin Lee25e26452015-06-02 09:56:29 -07004260 public List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004261 if (mService != null) {
4262 try {
4263 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
4264 if (providers != null) {
4265 return providers;
4266 }
4267 } catch (RemoteException re) {
4268 Log.w(TAG, "Error calling getCrossProfileWidgetProviders", re);
4269 }
4270 }
4271 return Collections.emptyList();
4272 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004273
4274 /**
4275 * Called by profile or device owners to set the current user's photo.
4276 *
4277 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4278 * @param icon the bitmap to set as the photo.
4279 */
Robin Lee25e26452015-06-02 09:56:29 -07004280 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004281 try {
4282 mService.setUserIcon(admin, icon);
4283 } catch (RemoteException re) {
4284 Log.w(TAG, "Could not set the user icon ", re);
4285 }
4286 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04004287
4288 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01004289 * Called by device owners to set a local system update policy. When a new policy is set,
4290 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004291 *
Robin Lee25e26452015-06-02 09:56:29 -07004292 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
4293 * components in the device owner package can set system update policies and the
4294 * most recent policy takes
Rubin Xu5faad8e2015-04-20 17:43:48 +01004295 * effect.
Robin Lee25e26452015-06-02 09:56:29 -07004296 * @param policy the new policy, or {@code null} to clear the current policy.
Rubin Xu5faad8e2015-04-20 17:43:48 +01004297 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00004298 */
Robin Lee25e26452015-06-02 09:56:29 -07004299 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Rubin Xu8027a4f2015-03-10 17:52:37 +00004300 if (mService != null) {
4301 try {
Robin Lee25e26452015-06-02 09:56:29 -07004302 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004303 } catch (RemoteException re) {
Rubin Xu5faad8e2015-04-20 17:43:48 +01004304 Log.w(TAG, "Error calling setSystemUpdatePolicy", re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004305 }
4306 }
4307 }
4308
4309 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01004310 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004311 *
Robin Lee25e26452015-06-02 09:56:29 -07004312 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004313 */
Rubin Xu5faad8e2015-04-20 17:43:48 +01004314 public SystemUpdatePolicy getSystemUpdatePolicy() {
Rubin Xu8027a4f2015-03-10 17:52:37 +00004315 if (mService != null) {
4316 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01004317 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00004318 } catch (RemoteException re) {
Rubin Xu5faad8e2015-04-20 17:43:48 +01004319 Log.w(TAG, "Error calling getSystemUpdatePolicy", re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004320 }
4321 }
4322 return null;
4323 }
Benjamin Franze36087e2015-04-07 16:40:34 +01004324
4325 /**
4326 * Called by a device owner to disable the keyguard altogether.
4327 *
4328 * <p>Setting the keyguard to disabled has the same effect as choosing "None" as the screen
4329 * lock type. However, this call has no effect if a password, pin or pattern is currently set.
4330 * If a password, pin or pattern is set after the keyguard was disabled, the keyguard stops
4331 * being disabled.
4332 *
4333 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01004334 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01004335 *
4336 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Benjamin Franzbece8062015-05-06 12:14:31 +01004337 * place. {@code true} otherwise.
Benjamin Franze36087e2015-04-07 16:40:34 +01004338 */
Robin Lee25e26452015-06-02 09:56:29 -07004339 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franze36087e2015-04-07 16:40:34 +01004340 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01004341 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01004342 } catch (RemoteException re) {
4343 Log.w(TAG, "Failed talking with device policy service", re);
4344 return false;
4345 }
4346 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00004347
4348 /**
Benjamin Franzbece8062015-05-06 12:14:31 +01004349 * Called by device owner to disable the status bar. Disabling the status bar blocks
4350 * notifications, quick settings and other screen overlays that allow escaping from
Benjamin Franzea2ec972015-03-16 17:18:09 +00004351 * a single use device.
4352 *
4353 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01004354 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
4355 *
4356 * @return {@code false} if attempting to disable the status bar failed.
4357 * {@code true} otherwise.
Benjamin Franzea2ec972015-03-16 17:18:09 +00004358 */
Robin Lee25e26452015-06-02 09:56:29 -07004359 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzea2ec972015-03-16 17:18:09 +00004360 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01004361 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00004362 } catch (RemoteException re) {
4363 Log.w(TAG, "Failed talking with device policy service", re);
Benjamin Franzbece8062015-05-06 12:14:31 +01004364 return false;
Benjamin Franzea2ec972015-03-16 17:18:09 +00004365 }
4366 }
Rubin Xudc105cc2015-04-14 23:38:01 +01004367
4368 /**
4369 * Callable by the system update service to notify device owners about pending updates.
4370 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
4371 * permission.
4372 *
4373 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating
4374 * when the current pending update was first available. -1 if no update is available.
4375 * @hide
4376 */
4377 @SystemApi
4378 public void notifyPendingSystemUpdate(long updateReceivedTime) {
4379 if (mService != null) {
4380 try {
4381 mService.notifyPendingSystemUpdate(updateReceivedTime);
4382 } catch (RemoteException re) {
4383 Log.w(TAG, "Could not notify device owner about pending system update", re);
4384 }
4385 }
4386 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04004387
4388 /**
Amith Yamasanid49489b2015-04-28 14:00:26 -07004389 * Called by profile or device owners to set the default response for future runtime permission
4390 * requests by applications. The policy can allow for normal operation which prompts the
4391 * user to grant a permission, or can allow automatic granting or denying of runtime
4392 * permission requests by an application. This also applies to new permissions declared by app
Benjamin Franz45dd6662015-07-08 14:24:14 +01004393 * updates. When a permission is denied or granted this way, the effect is equivalent to setting
4394 * the permission grant state via {@link #setPermissionGrantState}.
4395 *
4396 * <p/>As this policy only acts on runtime permission requests, it only applies to applications
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004397 * built with a {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Benjamin Franz45dd6662015-07-08 14:24:14 +01004398 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07004399 * @param admin Which profile or device owner this request is associated with.
4400 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
4401 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
Benjamin Franz45dd6662015-07-08 14:24:14 +01004402 *
4403 * @see #setPermissionGrantState
Amith Yamasanid49489b2015-04-28 14:00:26 -07004404 */
Robin Lee25e26452015-06-02 09:56:29 -07004405 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004406 try {
4407 mService.setPermissionPolicy(admin, policy);
4408 } catch (RemoteException re) {
4409 Log.w(TAG, "Failed talking with device policy service", re);
4410 }
4411 }
4412
4413 /**
4414 * Returns the current runtime permission policy set by the device or profile owner. The
4415 * default is {@link #PERMISSION_POLICY_PROMPT}.
4416 * @param admin Which profile or device owner this request is associated with.
4417 * @return the current policy for future permission requests.
4418 */
Esteban Talavera28b95702015-06-24 15:23:42 +01004419 public int getPermissionPolicy(ComponentName admin) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004420 try {
4421 return mService.getPermissionPolicy(admin);
4422 } catch (RemoteException re) {
4423 return PERMISSION_POLICY_PROMPT;
4424 }
4425 }
4426
4427 /**
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004428 * Sets the grant state of a runtime permission for a specific application. The state
4429 * can be {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it
4430 * through the UI, {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission
4431 * is denied and the user cannot manage it through the UI, and {@link
4432 * #PERMISSION_GRANT_STATE_GRANTED granted} in which the permission is granted and the
4433 * user cannot manage it through the UI. This might affect all permissions in a
4434 * group that the runtime permission belongs to. This method can only be called
4435 * by a profile or device owner.
4436 *
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07004437 * <p/>Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not
4438 * revoke the permission. It retains the previous grant, if any.
4439 *
4440 * <p/>Permissions can be granted or revoked only for applications built with a
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004441 * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07004442 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07004443 * @param admin Which profile or device owner this request is associated with.
4444 * @param packageName The application to grant or revoke a permission to.
4445 * @param permission The permission to grant or revoke.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004446 * @param grantState The permission grant state which is one of {@link
4447 * #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
4448 * {@link #PERMISSION_GRANT_STATE_GRANTED},
4449 * @return whether the permission was successfully granted or revoked.
4450 *
4451 * @see #PERMISSION_GRANT_STATE_DENIED
4452 * @see #PERMISSION_GRANT_STATE_DEFAULT
4453 * @see #PERMISSION_GRANT_STATE_GRANTED
Amith Yamasanid49489b2015-04-28 14:00:26 -07004454 */
Robin Lee25e26452015-06-02 09:56:29 -07004455 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004456 String permission, int grantState) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004457 try {
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004458 return mService.setPermissionGrantState(admin, packageName, permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07004459 } catch (RemoteException re) {
4460 Log.w(TAG, "Failed talking with device policy service", re);
4461 return false;
4462 }
4463 }
Amith Yamasani184b3752015-05-22 13:00:51 -07004464
4465 /**
4466 * Returns the current grant state of a runtime permission for a specific application.
4467 *
4468 * @param admin Which profile or device owner this request is associated with.
4469 * @param packageName The application to check the grant state for.
4470 * @param permission The permission to check for.
4471 * @return the current grant state specified by device policy. If the profile or device owner
4472 * has not set a grant state, the return value is {@link #PERMISSION_GRANT_STATE_DEFAULT}.
4473 * This does not indicate whether or not the permission is currently granted for the package.
4474 *
4475 * <p/>If a grant state was set by the profile or device owner, then the return value will
4476 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or {@link #PERMISSION_GRANT_STATE_GRANTED},
4477 * which indicates if the permission is currently denied or granted.
4478 *
4479 * @see #setPermissionGrantState(ComponentName, String, String, int)
4480 * @see PackageManager#checkPermission(String, String)
4481 */
Robin Lee25e26452015-06-02 09:56:29 -07004482 public int getPermissionGrantState(@NonNull ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07004483 String permission) {
4484 try {
4485 return mService.getPermissionGrantState(admin, packageName, permission);
4486 } catch (RemoteException re) {
4487 Log.w(TAG, "Failed talking with device policy service", re);
4488 return PERMISSION_GRANT_STATE_DEFAULT;
4489 }
4490 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08004491}