blob: aa8bf53d5e562b472206b0ac7cc0df268dd5ed12 [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
Mahaver Chopra76b08a92015-10-08 17:58:45 +0100344 * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or
345 * {@code WEP}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100346 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000347 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
348 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100349 */
350 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
Esteban Talavera37f01842014-09-05 10:50:57 +0100351 = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100352
353 /**
354 * A String extra holding the password of the wifi network in
355 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
356 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000357 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
358 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100359 */
360 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talavera37f01842014-09-05 10:50:57 +0100361 = "android.app.extra.PROVISIONING_WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100362
363 /**
364 * A String extra holding the proxy host for the wifi network in
365 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
366 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000367 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
368 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100369 */
370 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
Esteban Talavera37f01842014-09-05 10:50:57 +0100371 = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100372
373 /**
374 * An int extra holding the proxy port for the wifi network in
375 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
376 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000377 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
378 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100379 */
380 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
Esteban Talavera37f01842014-09-05 10:50:57 +0100381 = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100382
383 /**
384 * A String extra holding the proxy bypass for the wifi network in
385 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
386 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000387 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
388 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100389 */
390 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
Esteban Talavera37f01842014-09-05 10:50:57 +0100391 = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100392
393 /**
394 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
395 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
396 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000397 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
398 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100399 */
400 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
Esteban Talavera37f01842014-09-05 10:50:57 +0100401 = "android.app.extra.PROVISIONING_WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100402
403 /**
404 * A String extra holding a url that specifies the download location of the device admin
405 * package. When not provided it is assumed that the device admin package is already installed.
406 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000407 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
408 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100409 */
410 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talavera37f01842014-09-05 10:50:57 +0100411 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100412
413 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400414 * An int extra holding a minimum required version code for the device admin package. If the
415 * device admin is already installed on the device, it will only be re-downloaded from
416 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the
417 * installed package is less than this version code.
418 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400419 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400420 * provisioning via an NFC bump.
421 */
422 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE
423 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE";
424
425 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100426 * A String extra holding a http cookie header which should be used in the http request to the
427 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
428 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000429 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
430 * provisioning via an NFC bump.
Sander Alewijnse681bce92014-07-24 16:46:26 +0100431 */
432 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talavera37f01842014-09-05 10:50:57 +0100433 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100434
435 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100436 * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of
437 * the file at download location specified in
438 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100439 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100440 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} should be
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100441 * present. The provided checksum should match the checksum of the file at the download
442 * location. If the checksum doesn't match an error will be shown to the user and the user will
443 * be asked to factory reset the device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100444 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000445 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
446 * provisioning via an NFC bump.
Rubin Xud92e7572015-05-18 17:01:13 +0100447 *
448 * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP}
449 * and {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1} only SHA-1 hash is supported.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700450 * Starting from {@link android.os.Build.VERSION_CODES#M}, this parameter accepts SHA-256 in
Rubin Xud92e7572015-05-18 17:01:13 +0100451 * addition to SHA-1. Support for SHA-1 is likely to be removed in future OS releases.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100452 */
453 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100454 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100455
456 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100457 * A String extra holding the URL-safe base64 encoded SHA-256 checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100458 * android package archive at the download location specified in {@link
459 * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
460 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100461 * <p>The signatures of an android package archive can be obtained using
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100462 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
463 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
464 *
465 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} should be
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100466 * present. The provided checksum should match the checksum of any signature of the file at
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100467 * the download location. If the checksum does not match an error will be shown to the user and
468 * the user will be asked to factory reset the device.
469 *
470 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
471 * provisioning via an NFC bump.
472 */
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100473 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM
474 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM";
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100475
476 /**
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000477 * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile
478 * has completed successfully.
479 *
480 * <p>The broadcast is limited to the primary profile, to the app specified in the provisioning
Nicolas Prevotebe2d992015-05-12 18:14:53 -0700481 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000482 *
Ying Wang7f38aab2015-02-20 11:50:09 -0800483 * <p>This intent will contain the extra {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE} which
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000484 * corresponds to the account requested to be migrated at provisioning time, if any.
485 */
486 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
487 public static final String ACTION_MANAGED_PROFILE_PROVISIONED
488 = "android.app.action.MANAGED_PROFILE_PROVISIONED";
489
490 /**
Julia Reynolds2f46d942015-05-05 11:44:20 -0400491 * A boolean extra indicating whether device encryption can be skipped as part of Device Owner
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500492 * provisioning.
493 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400494 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100495 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500496 */
497 public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION =
498 "android.app.extra.PROVISIONING_SKIP_ENCRYPTION";
499
500 /**
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400501 * This MIME type is used for starting the Device Owner provisioning.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100502 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400503 * <p>During device owner provisioning a device admin app is set as the owner of the device.
504 * A device owner has full control over the device. The device owner can not be modified by the
505 * user and the only way of resetting the device is if the device owner app calls a factory
506 * reset.
507 *
508 * <p> A typical use case would be a device that is owned by a company, but used by either an
509 * employee or client.
510 *
511 * <p> The NFC message should be send to an unprovisioned device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100512 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000513 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100514 * contains the following properties:
515 * <ul>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400516 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
517 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100518 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400519 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100520 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
521 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
522 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
523 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
524 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
525 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
526 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
527 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
528 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
529 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100530 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
531 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from
532 * {@link android.os.Build.VERSION_CODES#M} </li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100533 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000534 * <p>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700535 * As of {@link android.os.Build.VERSION_CODES#M}, the properties should contain
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400536 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of
537 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only
538 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400539 */
540 public static final String MIME_TYPE_PROVISIONING_NFC
541 = "application/com.android.managedprovisioning";
542
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100543 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800544 * Activity action: ask the user to add a new device administrator to the system.
545 * The desired policy is the ComponentName of the policy in the
546 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
547 * bring the user through adding the device administrator to the system (or
548 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700549 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800550 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
551 * field to provide the user with additional explanation (in addition
552 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800553 *
554 * <p>If your administrator is already active, this will ordinarily return immediately (without
555 * user intervention). However, if your administrator has been updated and is requesting
556 * additional uses-policy flags, the user will be presented with the new list. New policies
557 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800558 */
559 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
560 public static final String ACTION_ADD_DEVICE_ADMIN
561 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700562
Dianne Hackbornd6847842010-01-12 18:14:19 -0800563 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700564 * @hide
565 * Activity action: ask the user to add a new device administrator as the profile owner
Amith Yamasani814e9872015-03-23 14:04:53 -0700566 * for this user. Only system apps can launch this intent.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700567 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700568 * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN}
569 * extra field. This will invoke a UI to bring the user through adding the profile owner admin
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700570 * to remotely control restrictions on the user.
571 *
572 * <p>The intent must be invoked via {@link Activity#startActivityForResult()} to receive the
573 * result of whether or not the user approved the action. If approved, the result will
574 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
575 * as a profile owner.
576 *
577 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
578 * field to provide the user with additional explanation (in addition
579 * to your component's description) about what is being added.
580 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700581 * <p>If there is already a profile owner active or the caller is not a system app, the
582 * operation will return a failure result.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700583 */
584 @SystemApi
585 public static final String ACTION_SET_PROFILE_OWNER
586 = "android.app.action.SET_PROFILE_OWNER";
587
588 /**
589 * @hide
590 * Name of the profile owner admin that controls the user.
591 */
592 @SystemApi
593 public static final String EXTRA_PROFILE_OWNER_NAME
594 = "android.app.extra.PROFILE_OWNER_NAME";
595
596 /**
Nicolas Prevot00799002015-07-27 18:15:20 +0100597 * Broadcast action: send when any policy admin changes a policy.
Jim Miller284b62e2010-06-08 14:27:42 -0700598 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700599 *
Jim Miller284b62e2010-06-08 14:27:42 -0700600 * @hide
601 */
602 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
603 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
604
605 /**
Nicolas Prevot00799002015-07-27 18:15:20 +0100606 * Broadcast action: sent when the device owner is set or changed.
607 *
608 * This broadcast is sent only to the primary user.
609 * @see #ACTION_PROVISION_MANAGED_DEVICE
610 */
611 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
612 public static final String ACTION_DEVICE_OWNER_CHANGED
613 = "android.app.action.DEVICE_OWNER_CHANGED";
614
615 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800616 * The ComponentName of the administrator component.
617 *
618 * @see #ACTION_ADD_DEVICE_ADMIN
619 */
620 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700621
Dianne Hackbornd6847842010-01-12 18:14:19 -0800622 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800623 * An optional CharSequence providing additional explanation for why the
624 * admin is being added.
625 *
626 * @see #ACTION_ADD_DEVICE_ADMIN
627 */
628 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700629
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800630 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700631 * Activity action: have the user enter a new password. This activity should
632 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
633 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
634 * enter a new password that meets the current requirements. You can use
635 * {@link #isActivePasswordSufficient()} to determine whether you need to
636 * have the user select a new password in order to meet the current
637 * constraints. Upon being resumed from this activity, you can check the new
638 * password characteristics to see if they are sufficient.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800639 */
640 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
641 public static final String ACTION_SET_NEW_PASSWORD
642 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700643
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000644 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000645 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
646 * the parent profile to access intents sent from the managed profile.
647 * That is, when an app in the managed profile calls
648 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
649 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000650 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100651 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000652
653 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000654 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
655 * the managed profile to access intents sent from the parent profile.
656 * That is, when an app in the parent profile calls
657 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
658 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000659 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100660 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700661
Dianne Hackbornd6847842010-01-12 18:14:19 -0800662 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +0100663 * Broadcast action: notify that a new local system update policy has been set by the device
664 * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}.
Rubin Xu8027a4f2015-03-10 17:52:37 +0000665 */
666 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Rubin Xu5faad8e2015-04-20 17:43:48 +0100667 public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED
668 = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED";
Rubin Xu8027a4f2015-03-10 17:52:37 +0000669
Amith Yamasanid49489b2015-04-28 14:00:26 -0700670 /**
671 * Permission policy to prompt user for new permission requests for runtime permissions.
672 * Already granted or denied permissions are not affected by this.
673 */
674 public static final int PERMISSION_POLICY_PROMPT = 0;
675
676 /**
677 * Permission policy to always grant new permission requests for runtime permissions.
678 * Already granted or denied permissions are not affected by this.
679 */
680 public static final int PERMISSION_POLICY_AUTO_GRANT = 1;
681
682 /**
683 * Permission policy to always deny new permission requests for runtime permissions.
684 * Already granted or denied permissions are not affected by this.
685 */
686 public static final int PERMISSION_POLICY_AUTO_DENY = 2;
687
Svet Ganovd8ecc5a2015-05-20 10:45:43 -0700688 /**
689 * Runtime permission state: The user can manage the permission
690 * through the UI.
691 */
692 public static final int PERMISSION_GRANT_STATE_DEFAULT = 0;
693
694 /**
695 * Runtime permission state: The permission is granted to the app
696 * and the user cannot manage the permission through the UI.
697 */
698 public static final int PERMISSION_GRANT_STATE_GRANTED = 1;
699
700 /**
701 * Runtime permission state: The permission is denied to the app
702 * and the user cannot manage the permission through the UI.
703 */
704 public static final int PERMISSION_GRANT_STATE_DENIED = 2;
Rubin Xu8027a4f2015-03-10 17:52:37 +0000705
706 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800707 * Return true if the given administrator component is currently
708 * active (enabled) in the system.
709 */
Robin Lee25e26452015-06-02 09:56:29 -0700710 public boolean isAdminActive(@NonNull ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700711 return isAdminActiveAsUser(admin, myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100712 }
713
714 /**
715 * @see #isAdminActive(ComponentName)
716 * @hide
717 */
Robin Lee25e26452015-06-02 09:56:29 -0700718 public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800719 if (mService != null) {
720 try {
Robin Lee25e26452015-06-02 09:56:29 -0700721 return mService.isAdminActive(admin, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800722 } catch (RemoteException e) {
723 Log.w(TAG, "Failed talking with device policy service", e);
724 }
725 }
726 return false;
727 }
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800728 /**
729 * Return true if the given administrator component is currently being removed
730 * for the user.
731 * @hide
732 */
Robin Lee25e26452015-06-02 09:56:29 -0700733 public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) {
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800734 if (mService != null) {
735 try {
Robin Lee25e26452015-06-02 09:56:29 -0700736 return mService.isRemovingAdmin(admin, userId);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800737 } catch (RemoteException e) {
738 Log.w(TAG, "Failed talking with device policy service", e);
739 }
740 }
741 return false;
742 }
743
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700744
Dianne Hackbornd6847842010-01-12 18:14:19 -0800745 /**
Robin Lee25e26452015-06-02 09:56:29 -0700746 * Return a list of all currently active device administrators' component
747 * names. If there are no administrators {@code null} may be
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800748 * returned.
749 */
750 public List<ComponentName> getActiveAdmins() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700751 return getActiveAdminsAsUser(myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100752 }
753
754 /**
755 * @see #getActiveAdmins()
756 * @hide
757 */
758 public List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800759 if (mService != null) {
760 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100761 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800762 } catch (RemoteException e) {
763 Log.w(TAG, "Failed talking with device policy service", e);
764 }
765 }
766 return null;
767 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700768
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800769 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700770 * Used by package administration code to determine if a package can be stopped
771 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800772 * @hide
773 */
774 public boolean packageHasActiveAdmins(String packageName) {
775 if (mService != null) {
776 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700777 return mService.packageHasActiveAdmins(packageName, myUserId());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800778 } catch (RemoteException e) {
779 Log.w(TAG, "Failed talking with device policy service", e);
780 }
781 }
782 return false;
783 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700784
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800785 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800786 * Remove a current administration component. This can only be called
787 * by the application that owns the administration component; if you
788 * try to remove someone else's component, a security exception will be
789 * thrown.
790 */
Robin Lee25e26452015-06-02 09:56:29 -0700791 public void removeActiveAdmin(@NonNull ComponentName admin) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800792 if (mService != null) {
793 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700794 mService.removeActiveAdmin(admin, myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800795 } catch (RemoteException e) {
796 Log.w(TAG, "Failed talking with device policy service", e);
797 }
798 }
799 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700800
Dianne Hackbornd6847842010-01-12 18:14:19 -0800801 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800802 * Returns true if an administrator has been granted a particular device policy. This can
Robin Lee25e26452015-06-02 09:56:29 -0700803 * be used to check whether the administrator was activated under an earlier set of policies,
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800804 * but requires additional policies after an upgrade.
805 *
806 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be
807 * an active administrator, or an exception will be thrown.
808 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
809 */
Robin Lee25e26452015-06-02 09:56:29 -0700810 public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) {
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800811 if (mService != null) {
812 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700813 return mService.hasGrantedPolicy(admin, usesPolicy, myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800814 } catch (RemoteException e) {
815 Log.w(TAG, "Failed talking with device policy service", e);
816 }
817 }
818 return false;
819 }
820
821 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800822 * Constant for {@link #setPasswordQuality}: the policy has no requirements
823 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800824 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800825 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800826 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700827
Dianne Hackbornd6847842010-01-12 18:14:19 -0800828 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700829 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
830 * recognition technology. This implies technologies that can recognize the identity of
831 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
832 * Note that quality constants are ordered so that higher values are more restrictive.
833 */
834 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
835
836 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800837 * Constant for {@link #setPasswordQuality}: the policy requires some kind
Benjamin Franzc6a96532015-06-16 11:23:38 +0100838 * of password or pattern, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800839 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800840 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800841 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700842
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800843 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800844 * Constant for {@link #setPasswordQuality}: the user must have entered a
845 * password containing at least numeric characters. Note that quality
846 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800847 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800848 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700849
Dianne Hackbornd6847842010-01-12 18:14:19 -0800850 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800851 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -0800852 * password containing at least numeric characters with no repeating (4444)
853 * or ordered (1234, 4321, 2468) sequences. Note that quality
854 * constants are ordered so that higher values are more restrictive.
855 */
856 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
857
858 /**
859 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700860 * password containing at least alphabetic (or other symbol) characters.
861 * Note that quality constants are ordered so that higher values are more
862 * restrictive.
863 */
864 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700865
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700866 /**
867 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800868 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700869 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800870 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800871 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700872 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700873
Dianne Hackbornd6847842010-01-12 18:14:19 -0800874 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700875 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700876 * password containing at least a letter, a numerical digit and a special
877 * symbol, by default. With this password quality, passwords can be
878 * restricted to contain various sets of characters, like at least an
879 * uppercase letter, etc. These are specified using various methods,
880 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
881 * that quality constants are ordered so that higher values are more
882 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700883 */
884 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
885
886 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800887 * Called by an application that is administering the device to set the
888 * password restrictions it is imposing. After setting this, the user
889 * will not be able to enter a new password that is not at least as
890 * restrictive as what has been set. Note that the current password
891 * will remain until the user has set a new one, so the change does not
892 * take place immediately. To prompt the user for a new password, use
893 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700894 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800895 * <p>Quality constants are ordered so that higher values are more restrictive;
896 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800897 * the user's preference, and any other considerations) is the one that
898 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700899 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800900 * <p>The calling device admin must have requested
901 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
902 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700903 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800904 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800905 * @param quality The new desired quality. One of
906 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Jim Miller85516d02014-01-31 17:08:37 -0800907 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
908 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}
909 * or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800910 */
Robin Lee25e26452015-06-02 09:56:29 -0700911 public void setPasswordQuality(@NonNull ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800912 if (mService != null) {
913 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -0800914 mService.setPasswordQuality(admin, quality);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800915 } catch (RemoteException e) {
916 Log.w(TAG, "Failed talking with device policy service", e);
917 }
918 }
919 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700920
Dianne Hackbornd6847842010-01-12 18:14:19 -0800921 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +0100922 * Retrieve the current minimum password quality for all admins of this user
923 * and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -0700924 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -0800925 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800926 */
Robin Lee25e26452015-06-02 09:56:29 -0700927 public int getPasswordQuality(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700928 return getPasswordQuality(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700929 }
930
931 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -0700932 public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800933 if (mService != null) {
934 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700935 return mService.getPasswordQuality(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800936 } catch (RemoteException e) {
937 Log.w(TAG, "Failed talking with device policy service", e);
938 }
939 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800940 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800941 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700942
Dianne Hackbornd6847842010-01-12 18:14:19 -0800943 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800944 * Called by an application that is administering the device to set the
945 * minimum allowed password length. After setting this, the user
946 * will not be able to enter a new password that is not at least as
947 * restrictive as what has been set. Note that the current password
948 * will remain until the user has set a new one, so the change does not
949 * take place immediately. To prompt the user for a new password, use
950 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
951 * constraint is only imposed if the administrator has also requested either
Jim Miller85516d02014-01-31 17:08:37 -0800952 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
953 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC},
954 * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700955 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800956 * <p>The calling device admin must have requested
957 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
958 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700959 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800960 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800961 * @param length The new desired minimum password length. A value of 0
962 * means there is no restriction.
963 */
Robin Lee25e26452015-06-02 09:56:29 -0700964 public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800965 if (mService != null) {
966 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -0800967 mService.setPasswordMinimumLength(admin, length);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800968 } catch (RemoteException e) {
969 Log.w(TAG, "Failed talking with device policy service", e);
970 }
971 }
972 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700973
Dianne Hackbornd6847842010-01-12 18:14:19 -0800974 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +0100975 * Retrieve the current minimum password length for all admins of this
976 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -0700977 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -0800978 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800979 */
Robin Lee25e26452015-06-02 09:56:29 -0700980 public int getPasswordMinimumLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700981 return getPasswordMinimumLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700982 }
983
984 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -0700985 public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800986 if (mService != null) {
987 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700988 return mService.getPasswordMinimumLength(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800989 } catch (RemoteException e) {
990 Log.w(TAG, "Failed talking with device policy service", e);
991 }
992 }
993 return 0;
994 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700995
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700996 /**
997 * Called by an application that is administering the device to set the
998 * minimum number of upper case letters required in the password. After
999 * setting this, the user will not be able to enter a new password that is
1000 * not at least as restrictive as what has been set. Note that the current
1001 * password will remain until the user has set a new one, so the change does
1002 * not take place immediately. To prompt the user for a new password, use
1003 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1004 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001005 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1006 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001007 * <p>
1008 * The calling device admin must have requested
1009 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1010 * this method; if it has not, a security exception will be thrown.
1011 *
1012 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1013 * with.
1014 * @param length The new desired minimum number of upper case letters
1015 * required in the password. A value of 0 means there is no
1016 * restriction.
1017 */
Robin Lee25e26452015-06-02 09:56:29 -07001018 public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001019 if (mService != null) {
1020 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001021 mService.setPasswordMinimumUpperCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001022 } catch (RemoteException e) {
1023 Log.w(TAG, "Failed talking with device policy service", e);
1024 }
1025 }
1026 }
1027
1028 /**
1029 * Retrieve the current number of upper case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001030 * password for all admins of this user and its profiles or a particular one.
1031 * This is the same value as set by
1032 * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001033 * and only applies when the password quality is
1034 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001035 *
Robin Lee25e26452015-06-02 09:56:29 -07001036 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001037 * aggregate all admins.
1038 * @return The minimum number of upper case letters required in the
1039 * password.
1040 */
Robin Lee25e26452015-06-02 09:56:29 -07001041 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001042 return getPasswordMinimumUpperCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001043 }
1044
1045 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001046 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001047 if (mService != null) {
1048 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001049 return mService.getPasswordMinimumUpperCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001050 } catch (RemoteException e) {
1051 Log.w(TAG, "Failed talking with device policy service", e);
1052 }
1053 }
1054 return 0;
1055 }
1056
1057 /**
1058 * Called by an application that is administering the device to set the
1059 * minimum number of lower case letters required in the password. After
1060 * setting this, the user will not be able to enter a new password that is
1061 * not at least as restrictive as what has been set. Note that the current
1062 * password will remain until the user has set a new one, so the change does
1063 * not take place immediately. To prompt the user for a new password, use
1064 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1065 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001066 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1067 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001068 * <p>
1069 * The calling device admin must have requested
1070 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1071 * this method; if it has not, a security exception will be thrown.
1072 *
1073 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1074 * with.
1075 * @param length The new desired minimum number of lower case letters
1076 * required in the password. A value of 0 means there is no
1077 * restriction.
1078 */
Robin Lee25e26452015-06-02 09:56:29 -07001079 public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001080 if (mService != null) {
1081 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001082 mService.setPasswordMinimumLowerCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001083 } catch (RemoteException e) {
1084 Log.w(TAG, "Failed talking with device policy service", e);
1085 }
1086 }
1087 }
1088
1089 /**
1090 * Retrieve the current number of lower case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001091 * password for all admins of this user and its profiles or a particular one.
1092 * This is the same value as set by
1093 * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001094 * and only applies when the password quality is
1095 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001096 *
Robin Lee25e26452015-06-02 09:56:29 -07001097 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001098 * aggregate all admins.
1099 * @return The minimum number of lower case letters required in the
1100 * password.
1101 */
Robin Lee25e26452015-06-02 09:56:29 -07001102 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001103 return getPasswordMinimumLowerCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001104 }
1105
1106 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001107 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001108 if (mService != null) {
1109 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001110 return mService.getPasswordMinimumLowerCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001111 } catch (RemoteException e) {
1112 Log.w(TAG, "Failed talking with device policy service", e);
1113 }
1114 }
1115 return 0;
1116 }
1117
1118 /**
1119 * Called by an application that is administering the device to set the
1120 * minimum number of letters required in the password. After setting this,
1121 * the user will not be able to enter a new password that is not at least as
1122 * restrictive as what has been set. Note that the current password will
1123 * remain until the user has set a new one, so the change does not take
1124 * place immediately. To prompt the user for a new password, use
1125 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1126 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001127 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1128 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001129 * <p>
1130 * The calling device admin must have requested
1131 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1132 * this method; if it has not, a security exception will be thrown.
1133 *
1134 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1135 * with.
1136 * @param length The new desired minimum number of letters required in the
1137 * password. A value of 0 means there is no restriction.
1138 */
Robin Lee25e26452015-06-02 09:56:29 -07001139 public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001140 if (mService != null) {
1141 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001142 mService.setPasswordMinimumLetters(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001143 } catch (RemoteException e) {
1144 Log.w(TAG, "Failed talking with device policy service", e);
1145 }
1146 }
1147 }
1148
1149 /**
1150 * Retrieve the current number of letters required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001151 * admins or a particular one. This is the same value as
1152 * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)}
1153 * and only applies when the password quality is
1154 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001155 *
Robin Lee25e26452015-06-02 09:56:29 -07001156 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001157 * aggregate all admins.
1158 * @return The minimum number of letters required in the password.
1159 */
Robin Lee25e26452015-06-02 09:56:29 -07001160 public int getPasswordMinimumLetters(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001161 return getPasswordMinimumLetters(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001162 }
1163
1164 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001165 public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001166 if (mService != null) {
1167 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001168 return mService.getPasswordMinimumLetters(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001169 } catch (RemoteException e) {
1170 Log.w(TAG, "Failed talking with device policy service", e);
1171 }
1172 }
1173 return 0;
1174 }
1175
1176 /**
1177 * Called by an application that is administering the device to set the
1178 * minimum number of numerical digits required in the password. After
1179 * setting this, the user will not be able to enter a new password that is
1180 * not at least as restrictive as what has been set. Note that the current
1181 * password will remain until the user has set a new one, so the change does
1182 * not take place immediately. To prompt the user for a new password, use
1183 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1184 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001185 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1186 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001187 * <p>
1188 * The calling device admin must have requested
1189 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1190 * this method; if it has not, a security exception will be thrown.
1191 *
1192 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1193 * with.
1194 * @param length The new desired minimum number of numerical digits required
1195 * in the password. A value of 0 means there is no restriction.
1196 */
Robin Lee25e26452015-06-02 09:56:29 -07001197 public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001198 if (mService != null) {
1199 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001200 mService.setPasswordMinimumNumeric(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001201 } catch (RemoteException e) {
1202 Log.w(TAG, "Failed talking with device policy service", e);
1203 }
1204 }
1205 }
1206
1207 /**
1208 * Retrieve the current number of numerical digits required in the password
Jessica Hummel91da58d2014-04-10 17:39:43 +01001209 * for all admins of this user and its profiles or a particular one.
1210 * This is the same value as set by
1211 * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001212 * and only applies when the password quality is
1213 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001214 *
Robin Lee25e26452015-06-02 09:56:29 -07001215 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001216 * aggregate all admins.
1217 * @return The minimum number of numerical digits required in the password.
1218 */
Robin Lee25e26452015-06-02 09:56:29 -07001219 public int getPasswordMinimumNumeric(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001220 return getPasswordMinimumNumeric(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001221 }
1222
1223 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001224 public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001225 if (mService != null) {
1226 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001227 return mService.getPasswordMinimumNumeric(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001228 } catch (RemoteException e) {
1229 Log.w(TAG, "Failed talking with device policy service", e);
1230 }
1231 }
1232 return 0;
1233 }
1234
1235 /**
1236 * Called by an application that is administering the device to set the
1237 * minimum number of symbols required in the password. After setting this,
1238 * the user will not be able to enter a new password that is not at least as
1239 * restrictive as what has been set. Note that the current password will
1240 * remain until the user has set a new one, so the change does not take
1241 * place immediately. To prompt the user for a new password, use
1242 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1243 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001244 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1245 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001246 * <p>
1247 * The calling device admin must have requested
1248 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1249 * this method; if it has not, a security exception will be thrown.
1250 *
1251 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1252 * with.
1253 * @param length The new desired minimum number of symbols required in the
1254 * password. A value of 0 means there is no restriction.
1255 */
Robin Lee25e26452015-06-02 09:56:29 -07001256 public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001257 if (mService != null) {
1258 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001259 mService.setPasswordMinimumSymbols(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001260 } catch (RemoteException e) {
1261 Log.w(TAG, "Failed talking with device policy service", e);
1262 }
1263 }
1264 }
1265
1266 /**
1267 * Retrieve the current number of symbols required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001268 * admins or a particular one. This is the same value as
1269 * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)}
1270 * and only applies when the password quality is
1271 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001272 *
Robin Lee25e26452015-06-02 09:56:29 -07001273 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001274 * aggregate all admins.
1275 * @return The minimum number of symbols required in the password.
1276 */
Robin Lee25e26452015-06-02 09:56:29 -07001277 public int getPasswordMinimumSymbols(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001278 return getPasswordMinimumSymbols(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001279 }
1280
1281 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001282 public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001283 if (mService != null) {
1284 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001285 return mService.getPasswordMinimumSymbols(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001286 } catch (RemoteException e) {
1287 Log.w(TAG, "Failed talking with device policy service", e);
1288 }
1289 }
1290 return 0;
1291 }
1292
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001293 /**
1294 * Called by an application that is administering the device to set the
1295 * minimum number of non-letter characters (numerical digits or symbols)
1296 * required in the password. After setting this, the user will not be able
1297 * to enter a new password that is not at least as restrictive as what has
1298 * been set. Note that the current password will remain until the user has
1299 * set a new one, so the change does not take place immediately. To prompt
1300 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after
1301 * setting this value. This constraint is only imposed if the administrator
1302 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1303 * {@link #setPasswordQuality}. The default value is 0.
1304 * <p>
1305 * The calling device admin must have requested
1306 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1307 * this method; if it has not, a security exception will be thrown.
1308 *
1309 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1310 * with.
1311 * @param length The new desired minimum number of letters required in the
1312 * password. A value of 0 means there is no restriction.
1313 */
Robin Lee25e26452015-06-02 09:56:29 -07001314 public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001315 if (mService != null) {
1316 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001317 mService.setPasswordMinimumNonLetter(admin, length);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001318 } catch (RemoteException e) {
1319 Log.w(TAG, "Failed talking with device policy service", e);
1320 }
1321 }
1322 }
1323
1324 /**
1325 * Retrieve the current number of non-letter characters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001326 * password for all admins of this user and its profiles or a particular one.
1327 * This is the same value as set by
1328 * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001329 * and only applies when the password quality is
1330 * {@link #PASSWORD_QUALITY_COMPLEX}.
1331 *
Robin Lee25e26452015-06-02 09:56:29 -07001332 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001333 * aggregate all admins.
1334 * @return The minimum number of letters required in the password.
1335 */
Robin Lee25e26452015-06-02 09:56:29 -07001336 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001337 return getPasswordMinimumNonLetter(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001338 }
1339
1340 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001341 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001342 if (mService != null) {
1343 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001344 return mService.getPasswordMinimumNonLetter(admin, userHandle);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001345 } catch (RemoteException e) {
1346 Log.w(TAG, "Failed talking with device policy service", e);
1347 }
1348 }
1349 return 0;
1350 }
1351
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001352 /**
1353 * Called by an application that is administering the device to set the length
1354 * of the password history. After setting this, the user will not be able to
1355 * enter a new password that is the same as any password in the history. Note
1356 * that the current password will remain until the user has set a new one, so
1357 * the change does not take place immediately. To prompt the user for a new
1358 * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
1359 * This constraint is only imposed if the administrator has also requested
Jim Miller85516d02014-01-31 17:08:37 -08001360 * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}
1361 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1362 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001363 *
1364 * <p>
1365 * The calling device admin must have requested
1366 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
1367 * method; if it has not, a security exception will be thrown.
1368 *
1369 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1370 * with.
1371 * @param length The new desired length of password history. A value of 0
1372 * means there is no restriction.
1373 */
Robin Lee25e26452015-06-02 09:56:29 -07001374 public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001375 if (mService != null) {
1376 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001377 mService.setPasswordHistoryLength(admin, length);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001378 } catch (RemoteException e) {
1379 Log.w(TAG, "Failed talking with device policy service", e);
1380 }
1381 }
1382 }
1383
1384 /**
Jim Millera4e28d12010-11-08 16:15:47 -08001385 * Called by a device admin to set the password expiration timeout. Calling this method
1386 * will restart the countdown for password expiration for the given admin, as will changing
1387 * the device password (for all admins).
1388 *
1389 * <p>The provided timeout is the time delta in ms and will be added to the current time.
1390 * For example, to have the password expire 5 days from now, timeout would be
1391 * 5 * 86400 * 1000 = 432000000 ms for timeout.
1392 *
1393 * <p>To disable password expiration, a value of 0 may be used for timeout.
1394 *
Jim Millera4e28d12010-11-08 16:15:47 -08001395 * <p>The calling device admin must have requested
1396 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
1397 * method; if it has not, a security exception will be thrown.
1398 *
Jessica Hummel9da60392014-05-21 12:32:57 +01001399 * <p> Note that setting the password will automatically reset the expiration time for all
1400 * active admins. Active admins do not need to explicitly call this method in that case.
1401 *
Jim Millera4e28d12010-11-08 16:15:47 -08001402 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1403 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
1404 * means there is no restriction (unlimited).
1405 */
Robin Lee25e26452015-06-02 09:56:29 -07001406 public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) {
Jim Millera4e28d12010-11-08 16:15:47 -08001407 if (mService != null) {
1408 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001409 mService.setPasswordExpirationTimeout(admin, timeout);
Jim Millera4e28d12010-11-08 16:15:47 -08001410 } catch (RemoteException e) {
1411 Log.w(TAG, "Failed talking with device policy service", e);
1412 }
1413 }
1414 }
1415
1416 /**
Jim Miller6b857682011-02-16 16:27:41 -08001417 * Get the password expiration timeout for the given admin. The expiration timeout is the
1418 * recurring expiration timeout provided in the call to
1419 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
Robin Lee25e26452015-06-02 09:56:29 -07001420 * aggregate of all policy administrators if {@code admin} is null.
Jim Millera4e28d12010-11-08 16:15:47 -08001421 *
Robin Lee25e26452015-06-02 09:56:29 -07001422 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001423 * @return The timeout for the given admin or the minimum of all timeouts
1424 */
Robin Lee25e26452015-06-02 09:56:29 -07001425 public long getPasswordExpirationTimeout(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001426 if (mService != null) {
1427 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001428 return mService.getPasswordExpirationTimeout(admin, myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001429 } catch (RemoteException e) {
1430 Log.w(TAG, "Failed talking with device policy service", e);
1431 }
1432 }
1433 return 0;
1434 }
1435
1436 /**
1437 * Get the current password expiration time for the given admin or an aggregate of
Jessica Hummel91da58d2014-04-10 17:39:43 +01001438 * all admins of this user and its profiles if admin is null. If the password is
1439 * expired, this will return the time since the password expired as a negative number.
1440 * If admin is null, then a composite of all expiration timeouts is returned
1441 * - which will be the minimum of all timeouts.
Jim Millera4e28d12010-11-08 16:15:47 -08001442 *
Robin Lee25e26452015-06-02 09:56:29 -07001443 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001444 * @return The password expiration time, in ms.
1445 */
Robin Lee25e26452015-06-02 09:56:29 -07001446 public long getPasswordExpiration(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001447 if (mService != null) {
1448 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001449 return mService.getPasswordExpiration(admin, myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001450 } catch (RemoteException e) {
1451 Log.w(TAG, "Failed talking with device policy service", e);
1452 }
1453 }
1454 return 0;
1455 }
1456
1457 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001458 * Retrieve the current password history length for all admins of this
1459 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001460 * @param admin The name of the admin component to check, or {@code null} to aggregate
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001461 * all admins.
1462 * @return The length of the password history
1463 */
Robin Lee25e26452015-06-02 09:56:29 -07001464 public int getPasswordHistoryLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001465 return getPasswordHistoryLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001466 }
1467
1468 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001469 public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001470 if (mService != null) {
1471 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001472 return mService.getPasswordHistoryLength(admin, userHandle);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001473 } catch (RemoteException e) {
1474 Log.w(TAG, "Failed talking with device policy service", e);
1475 }
1476 }
1477 return 0;
1478 }
1479
Dianne Hackbornd6847842010-01-12 18:14:19 -08001480 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001481 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001482 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08001483 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001484 * @return Returns the maximum length that the user can enter.
1485 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001486 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001487 // Kind-of arbitrary.
1488 return 16;
1489 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001490
Dianne Hackborn254cb442010-01-27 19:23:59 -08001491 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001492 * Determine whether the current password the user has set is sufficient
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001493 * to meet the policy requirements (quality, minimum length) that have been
Jessica Hummel91da58d2014-04-10 17:39:43 +01001494 * requested by the admins of this user and its profiles.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001495 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001496 * <p>The calling device admin must have requested
1497 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1498 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001499 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001500 * @return Returns true if the password meets the current requirements, else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001501 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001502 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001503 if (mService != null) {
1504 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001505 return mService.isActivePasswordSufficient(myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001506 } catch (RemoteException e) {
1507 Log.w(TAG, "Failed talking with device policy service", e);
1508 }
1509 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001510 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001511 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001512
Dianne Hackbornd6847842010-01-12 18:14:19 -08001513 /**
1514 * Retrieve the number of times the user has failed at entering a
1515 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001516 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001517 * <p>The calling device admin must have requested
1518 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
1519 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001520 */
1521 public int getCurrentFailedPasswordAttempts() {
1522 if (mService != null) {
1523 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001524 return mService.getCurrentFailedPasswordAttempts(myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001525 } catch (RemoteException e) {
1526 Log.w(TAG, "Failed talking with device policy service", e);
1527 }
1528 }
1529 return -1;
1530 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001531
1532 /**
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001533 * Queries whether {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001534 *
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001535 * @return true if RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001536 * @hide
1537 */
1538 public boolean getDoNotAskCredentialsOnBoot() {
1539 if (mService != null) {
1540 try {
1541 return mService.getDoNotAskCredentialsOnBoot();
1542 } catch (RemoteException e) {
1543 Log.w(TAG, "Failed to call getDoNotAskCredentialsOnBoot()", e);
1544 }
1545 }
1546 return false;
1547 }
1548
1549 /**
Andrew Stadler88209d12010-02-08 22:59:36 -08001550 * Setting this to a value greater than zero enables a built-in policy
1551 * that will perform a device wipe after too many incorrect
1552 * device-unlock passwords have been entered. This built-in policy combines
1553 * watching for failed passwords and wiping the device, and requires
1554 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001555 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001556 *
Andrew Stadler88209d12010-02-08 22:59:36 -08001557 * <p>To implement any other policy (e.g. wiping data for a particular
1558 * application only, erasing or revoking credentials, or reporting the
1559 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001560 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -08001561 * instead. Do not use this API, because if the maximum count is reached,
1562 * the device will be wiped immediately, and your callback will not be invoked.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001563 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001564 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001565 * @param num The number of failed password attempts at which point the
1566 * device will wipe its data.
1567 */
Robin Lee25e26452015-06-02 09:56:29 -07001568 public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001569 if (mService != null) {
1570 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001571 mService.setMaximumFailedPasswordsForWipe(admin, num);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001572 } catch (RemoteException e) {
1573 Log.w(TAG, "Failed talking with device policy service", e);
1574 }
1575 }
1576 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001577
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001578 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001579 * Retrieve the current maximum number of login attempts that are allowed
Jessica Hummel91da58d2014-04-10 17:39:43 +01001580 * before the device wipes itself, for all admins of this user and its profiles
Dianne Hackborn254cb442010-01-27 19:23:59 -08001581 * or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001582 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001583 * all admins.
1584 */
Robin Lee25e26452015-06-02 09:56:29 -07001585 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001586 return getMaximumFailedPasswordsForWipe(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001587 }
1588
1589 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001590 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001591 if (mService != null) {
1592 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001593 return mService.getMaximumFailedPasswordsForWipe(admin, userHandle);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001594 } catch (RemoteException e) {
1595 Log.w(TAG, "Failed talking with device policy service", e);
1596 }
1597 }
1598 return 0;
1599 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001600
Dianne Hackborn254cb442010-01-27 19:23:59 -08001601 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07001602 * Returns the profile with the smallest maximum failed passwords for wipe,
1603 * for the given user. So for primary user, it might return the primary or
1604 * a managed profile. For a secondary user, it would be the same as the
1605 * user passed in.
1606 * @hide Used only by Keyguard
1607 */
1608 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
1609 if (mService != null) {
1610 try {
1611 return mService.getProfileWithMinimumFailedPasswordsForWipe(userHandle);
1612 } catch (RemoteException e) {
1613 Log.w(TAG, "Failed talking with device policy service", e);
1614 }
1615 }
1616 return UserHandle.USER_NULL;
1617 }
1618
1619 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001620 * Flag for {@link #resetPassword}: don't allow other admins to change
1621 * the password again until the user has entered it.
1622 */
1623 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001624
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001625 /**
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001626 * Flag for {@link #resetPassword}: don't ask for user credentials on device boot.
1627 * If the flag is set, the device can be booted without asking for user password.
1628 * The absence of this flag does not change the current boot requirements. This flag
1629 * can be set by the device owner only. If the app is not the device owner, the flag
1630 * is ignored. Once the flag is set, it cannot be reverted back without resetting the
1631 * device to factory defaults.
1632 */
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001633 public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002;
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001634
1635 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001636 * Force a new device unlock password (the password needed to access the
1637 * entire device, not for individual accounts) on the user. This takes
1638 * effect immediately.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001639 * The given password must be sufficient for the
1640 * current password quality and length constraints as returned by
1641 * {@link #getPasswordQuality(ComponentName)} and
1642 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
1643 * these constraints, then it will be rejected and false returned. Note
1644 * that the password may be a stronger quality (containing alphanumeric
1645 * characters when the requested quality is only numeric), in which case
1646 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001647 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001648 * <p>Calling with a null or empty password will clear any existing PIN,
1649 * pattern or password if the current password constraints allow it.
1650 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001651 * <p>The calling device admin must have requested
1652 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
1653 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001654 *
Amith Yamasani242f4b12014-10-14 16:06:13 -07001655 * <p>Calling this from a managed profile will throw a security exception.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001656 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001657 * @param password The new password for the user. Null or empty clears the password.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001658 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001659 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001660 * @return Returns true if the password was applied, or false if it is
1661 * not acceptable for the current constraints.
1662 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001663 public boolean resetPassword(String password, int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001664 if (mService != null) {
1665 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001666 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001667 } catch (RemoteException e) {
1668 Log.w(TAG, "Failed talking with device policy service", e);
1669 }
1670 }
1671 return false;
1672 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001673
Dianne Hackbornd6847842010-01-12 18:14:19 -08001674 /**
1675 * Called by an application that is administering the device to set the
1676 * maximum time for user activity until the device will lock. This limits
1677 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001678 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001679 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -08001680 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001681 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001682 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001683 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001684 * @param timeMs The new desired maximum time to lock in milliseconds.
1685 * A value of 0 means there is no restriction.
1686 */
Robin Lee25e26452015-06-02 09:56:29 -07001687 public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001688 if (mService != null) {
1689 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001690 mService.setMaximumTimeToLock(admin, timeMs);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001691 } catch (RemoteException e) {
1692 Log.w(TAG, "Failed talking with device policy service", e);
1693 }
1694 }
1695 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001696
Dianne Hackbornd6847842010-01-12 18:14:19 -08001697 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001698 * Retrieve the current maximum time to unlock for all admins of this user
1699 * and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001700 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001701 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07001702 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07001703 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001704 */
Robin Lee25e26452015-06-02 09:56:29 -07001705 public long getMaximumTimeToLock(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001706 return getMaximumTimeToLock(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001707 }
1708
1709 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001710 public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001711 if (mService != null) {
1712 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001713 return mService.getMaximumTimeToLock(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001714 } catch (RemoteException e) {
1715 Log.w(TAG, "Failed talking with device policy service", e);
1716 }
1717 }
1718 return 0;
1719 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001720
Dianne Hackbornd6847842010-01-12 18:14:19 -08001721 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001722 * Make the device lock immediately, as if the lock screen timeout has
1723 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001724 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001725 * <p>The calling device admin must have requested
1726 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
1727 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001728 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001729 public void lockNow() {
1730 if (mService != null) {
1731 try {
1732 mService.lockNow();
1733 } catch (RemoteException e) {
1734 Log.w(TAG, "Failed talking with device policy service", e);
1735 }
1736 }
1737 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001738
Dianne Hackbornd6847842010-01-12 18:14:19 -08001739 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07001740 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001741 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07001742 */
1743 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
1744
1745 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001746 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
1747 * data.
1748 *
Paul Crowley2934b262014-12-02 11:21:13 +00001749 * <p>This flag may only be set by device owner admins; if it is set by
1750 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001751 */
1752 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
1753
1754 /**
Robin Lee85bd63f2015-02-10 11:51:00 +00001755 * Ask the user data be wiped. Wiping the primary user will cause the
1756 * device to reboot, erasing all user data while next booting up.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001757 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001758 * <p>The calling device admin must have requested
1759 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
1760 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001761 *
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001762 * @param flags Bit mask of additional options: currently supported flags
1763 * are {@link #WIPE_EXTERNAL_STORAGE} and
1764 * {@link #WIPE_RESET_PROTECTION_DATA}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001765 */
1766 public void wipeData(int flags) {
1767 if (mService != null) {
1768 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001769 mService.wipeData(flags, myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001770 } catch (RemoteException e) {
1771 Log.w(TAG, "Failed talking with device policy service", e);
1772 }
1773 }
1774 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001775
Dianne Hackbornd6847842010-01-12 18:14:19 -08001776 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001777 * Called by an application that is administering the device to set the
1778 * global proxy and exclusion list.
1779 * <p>
1780 * The calling device admin must have requested
1781 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
1782 * this method; if it has not, a security exception will be thrown.
1783 * Only the first device admin can set the proxy. If a second admin attempts
1784 * to set the proxy, the {@link ComponentName} of the admin originally setting the
Robin Lee25e26452015-06-02 09:56:29 -07001785 * proxy will be returned. If successful in setting the proxy, {@code null} will
Oscar Montemayor69238c62010-08-03 10:51:06 -07001786 * be returned.
1787 * The method can be called repeatedly by the device admin alrady setting the
1788 * proxy to update the proxy and exclusion list.
1789 *
Robin Lee25e26452015-06-02 09:56:29 -07001790 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Oscar Montemayor69238c62010-08-03 10:51:06 -07001791 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
1792 * Pass Proxy.NO_PROXY to reset the proxy.
1793 * @param exclusionList a list of domains to be excluded from the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07001794 * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName}
1795 * of the device admin that sets the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08001796 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001797 */
Robin Lee25e26452015-06-02 09:56:29 -07001798 public ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec,
Oscar Montemayor69238c62010-08-03 10:51:06 -07001799 List<String> exclusionList ) {
1800 if (proxySpec == null) {
1801 throw new NullPointerException();
1802 }
1803 if (mService != null) {
1804 try {
1805 String hostSpec;
1806 String exclSpec;
1807 if (proxySpec.equals(Proxy.NO_PROXY)) {
1808 hostSpec = null;
1809 exclSpec = null;
1810 } else {
1811 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
1812 throw new IllegalArgumentException();
1813 }
1814 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
1815 String hostName = sa.getHostName();
1816 int port = sa.getPort();
1817 StringBuilder hostBuilder = new StringBuilder();
1818 hostSpec = hostBuilder.append(hostName)
1819 .append(":").append(Integer.toString(port)).toString();
1820 if (exclusionList == null) {
1821 exclSpec = "";
1822 } else {
1823 StringBuilder listBuilder = new StringBuilder();
1824 boolean firstDomain = true;
1825 for (String exclDomain : exclusionList) {
1826 if (!firstDomain) {
1827 listBuilder = listBuilder.append(",");
1828 } else {
1829 firstDomain = false;
1830 }
1831 listBuilder = listBuilder.append(exclDomain.trim());
1832 }
1833 exclSpec = listBuilder.toString();
1834 }
Yuhao Zheng90704842014-02-28 17:22:45 -08001835 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
1836 != android.net.Proxy.PROXY_VALID)
1837 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07001838 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001839 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07001840 } catch (RemoteException e) {
1841 Log.w(TAG, "Failed talking with device policy service", e);
1842 }
1843 }
1844 return null;
1845 }
1846
1847 /**
Jason Monk03bc9912014-05-13 09:44:57 -04001848 * Set a network-independent global HTTP proxy. This is not normally what you want
1849 * for typical HTTP proxies - they are generally network dependent. However if you're
1850 * doing something unusual like general internal filtering this may be useful. On
1851 * a private network where the proxy is not accessible, you may break HTTP using this.
1852 *
1853 * <p>This method requires the caller to be the device owner.
1854 *
1855 * <p>This proxy is only a recommendation and it is possible that some apps will ignore it.
1856 * @see ProxyInfo
1857 *
1858 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1859 * with.
1860 * @param proxyInfo The a {@link ProxyInfo} object defining the new global
1861 * HTTP proxy. A {@code null} value will clear the global HTTP proxy.
1862 */
Robin Lee25e26452015-06-02 09:56:29 -07001863 public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo
1864 proxyInfo) {
Jason Monk03bc9912014-05-13 09:44:57 -04001865 if (mService != null) {
1866 try {
1867 mService.setRecommendedGlobalProxy(admin, proxyInfo);
1868 } catch (RemoteException e) {
1869 Log.w(TAG, "Failed talking with device policy service", e);
1870 }
1871 }
1872 }
1873
1874 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001875 * Returns the component name setting the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07001876 * @return ComponentName object of the device admin that set the global proxy, or {@code null}
1877 * if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08001878 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001879 */
1880 public ComponentName getGlobalProxyAdmin() {
1881 if (mService != null) {
1882 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001883 return mService.getGlobalProxyAdmin(myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07001884 } catch (RemoteException e) {
1885 Log.w(TAG, "Failed talking with device policy service", e);
1886 }
1887 }
1888 return null;
1889 }
1890
1891 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001892 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001893 * indicating that encryption is not supported.
1894 */
1895 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
1896
1897 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001898 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001899 * indicating that encryption is supported, but is not currently active.
1900 */
1901 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
1902
1903 /**
Robin Lee3795fb02015-02-16 14:17:23 +00001904 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001905 * indicating that encryption is not currently active, but is currently
1906 * being activated. This is only reported by devices that support
1907 * encryption of data and only when the storage is currently
1908 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
1909 * to become encrypted will never return this value.
1910 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001911 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001912
1913 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001914 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001915 * indicating that encryption is active.
1916 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001917 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001918
1919 /**
Robin Lee3795fb02015-02-16 14:17:23 +00001920 * Result code for {@link #getStorageEncryptionStatus}:
1921 * indicating that encryption is active, but an encryption key has not
1922 * been set by the user.
1923 */
1924 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
1925
1926 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001927 * Activity action: begin the process of encrypting data on the device. This activity should
1928 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
1929 * After resuming from this activity, use {@link #getStorageEncryption}
1930 * to check encryption status. However, on some devices this activity may never return, as
1931 * it may trigger a reboot and in some cases a complete data wipe of the device.
1932 */
1933 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1934 public static final String ACTION_START_ENCRYPTION
1935 = "android.app.action.START_ENCRYPTION";
1936
1937 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07001938 * Widgets are enabled in keyguard
1939 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001940 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07001941
1942 /**
Jim Miller50e62182014-04-23 17:25:00 -07001943 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07001944 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001945 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
1946
1947 /**
1948 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
1949 */
1950 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
1951
1952 /**
Jim Miller50e62182014-04-23 17:25:00 -07001953 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
1954 */
1955 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
1956
1957 /**
1958 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
1959 */
1960 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
1961
1962 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02001963 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07001964 * (e.g. PIN/Pattern/Password).
1965 */
1966 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
1967
1968 /**
Jim Miller06e34502014-07-17 14:46:05 -07001969 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
1970 */
1971 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
1972
1973 /**
Jim Miller35207742012-11-02 15:33:20 -07001974 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07001975 */
1976 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07001977
1978 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001979 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08001980 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001981 *
1982 * <p>When multiple device administrators attempt to control device
1983 * encryption, the most secure, supported setting will always be
1984 * used. If any device administrator requests device encryption,
1985 * it will be enabled; Conversely, if a device administrator
1986 * attempts to disable device encryption while another
1987 * device administrator has enabled it, the call to disable will
1988 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
1989 *
1990 * <p>This policy controls encryption of the secure (application data) storage area. Data
Andy Stadler50c294f2011-03-07 19:13:42 -08001991 * written to other storage areas may or may not be encrypted, and this policy does not require
1992 * or control the encryption of any other storage areas.
1993 * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is
1994 * {@code true}, then the directory returned by
1995 * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk
1996 * within the encrypted storage area.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001997 *
1998 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
1999 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
2000 * the encryption key may not be fully secured. For maximum security, the administrator should
2001 * also require (and check for) a pattern, PIN, or password.
2002 *
2003 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2004 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08002005 * @return the new request status (for all active admins) - will be one of
2006 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
2007 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
2008 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002009 */
Robin Lee25e26452015-06-02 09:56:29 -07002010 public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002011 if (mService != null) {
2012 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002013 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002014 } catch (RemoteException e) {
2015 Log.w(TAG, "Failed talking with device policy service", e);
2016 }
2017 }
2018 return ENCRYPTION_STATUS_UNSUPPORTED;
2019 }
2020
2021 /**
2022 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002023 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002024 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08002025 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
2026 * this will return the requested encryption setting as an aggregate of all active
2027 * administrators.
2028 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002029 */
Robin Lee25e26452015-06-02 09:56:29 -07002030 public boolean getStorageEncryption(@Nullable ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002031 if (mService != null) {
2032 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002033 return mService.getStorageEncryption(admin, myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002034 } catch (RemoteException e) {
2035 Log.w(TAG, "Failed talking with device policy service", e);
2036 }
2037 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08002038 return false;
2039 }
2040
2041 /**
2042 * Called by an application that is administering the device to
2043 * determine the current encryption status of the device.
2044 *
2045 * Depending on the returned status code, the caller may proceed in different
2046 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
2047 * storage system does not support encryption. If the
2048 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
2049 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00002050 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
2051 * storage system has enabled encryption but no password is set so further action
2052 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
Andy Stadler22dbfda2011-01-17 12:47:31 -08002053 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
2054 *
Robin Lee7e678712014-07-24 16:41:31 +01002055 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08002056 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00002057 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
2058 * or {@link #ENCRYPTION_STATUS_ACTIVE}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08002059 */
2060 public int getStorageEncryptionStatus() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002061 return getStorageEncryptionStatus(myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002062 }
2063
2064 /** @hide per-user version */
2065 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08002066 if (mService != null) {
2067 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002068 return mService.getStorageEncryptionStatus(userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08002069 } catch (RemoteException e) {
2070 Log.w(TAG, "Failed talking with device policy service", e);
2071 }
2072 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002073 return ENCRYPTION_STATUS_UNSUPPORTED;
2074 }
2075
2076 /**
Robin Lee7e678712014-07-24 16:41:31 +01002077 * Installs the given certificate as a user CA.
2078 *
Robin Lee25e26452015-06-02 09:56:29 -07002079 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2080 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002081 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04002082 *
2083 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01002084 * interrupted, true otherwise.
Maggie Benthallda51e682013-08-08 22:35:44 -04002085 */
Robin Lee25e26452015-06-02 09:56:29 -07002086 public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002087 if (mService != null) {
2088 try {
Robin Lee7e678712014-07-24 16:41:31 +01002089 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04002090 } catch (RemoteException e) {
2091 Log.w(TAG, "Failed talking with device policy service", e);
2092 }
2093 }
2094 return false;
2095 }
2096
2097 /**
Robin Lee7e678712014-07-24 16:41:31 +01002098 * Uninstalls the given certificate from trusted user CAs, if present.
2099 *
Robin Lee25e26452015-06-02 09:56:29 -07002100 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2101 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002102 * @param certBuffer encoded form of the certificate to remove.
Maggie Benthallda51e682013-08-08 22:35:44 -04002103 */
Robin Lee25e26452015-06-02 09:56:29 -07002104 public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002105 if (mService != null) {
2106 try {
Robin Lee306fe082014-06-19 14:04:24 +00002107 final String alias = getCaCertAlias(certBuffer);
Robin Lee83881bd2015-06-09 16:04:38 -07002108 mService.uninstallCaCerts(admin, new String[] {alias});
Robin Lee306fe082014-06-19 14:04:24 +00002109 } catch (CertificateException e) {
2110 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002111 } catch (RemoteException e) {
2112 Log.w(TAG, "Failed talking with device policy service", e);
2113 }
2114 }
2115 }
2116
2117 /**
Robin Lee7e678712014-07-24 16:41:31 +01002118 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
2119 * If a user has installed any certificates by other means than device policy these will be
2120 * included too.
2121 *
Robin Lee25e26452015-06-02 09:56:29 -07002122 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2123 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002124 * @return a List of byte[] arrays, each encoding one user CA certificate.
Maggie Benthallda51e682013-08-08 22:35:44 -04002125 */
Robin Lee25e26452015-06-02 09:56:29 -07002126 public List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002127 List<byte[]> certs = new ArrayList<byte[]>();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002128 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01002129 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002130 mService.enforceCanManageCaCerts(admin);
2131 final TrustedCertificateStore certStore = new TrustedCertificateStore();
2132 for (String alias : certStore.userAliases()) {
2133 try {
2134 certs.add(certStore.getCertificate(alias).getEncoded());
2135 } catch (CertificateException ce) {
2136 Log.w(TAG, "Could not encode certificate: " + alias, ce);
2137 }
2138 }
2139 } catch (RemoteException re) {
2140 Log.w(TAG, "Failed talking with device policy service", re);
Robin Lee7e678712014-07-24 16:41:31 +01002141 }
2142 }
2143 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04002144 }
2145
2146 /**
Robin Lee7e678712014-07-24 16:41:31 +01002147 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
2148 * means other than device policy will also be removed, except for system CA certificates.
2149 *
Robin Lee25e26452015-06-02 09:56:29 -07002150 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2151 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002152 */
Robin Lee25e26452015-06-02 09:56:29 -07002153 public void uninstallAllUserCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002154 if (mService != null) {
Robin Lee83881bd2015-06-09 16:04:38 -07002155 try {
2156 mService.uninstallCaCerts(admin, new TrustedCertificateStore().userAliases()
2157 .toArray(new String[0]));
2158 } catch (RemoteException re) {
2159 Log.w(TAG, "Failed talking with device policy service", re);
Robin Lee7e678712014-07-24 16:41:31 +01002160 }
2161 }
2162 }
2163
2164 /**
2165 * Returns whether this certificate is installed as a trusted CA.
2166 *
Robin Lee25e26452015-06-02 09:56:29 -07002167 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2168 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002169 * @param certBuffer encoded form of the certificate to look up.
Maggie Benthallda51e682013-08-08 22:35:44 -04002170 */
Robin Lee25e26452015-06-02 09:56:29 -07002171 public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002172 if (mService != null) {
2173 try {
2174 mService.enforceCanManageCaCerts(admin);
2175 return getCaCertAlias(certBuffer) != null;
2176 } catch (RemoteException re) {
2177 Log.w(TAG, "Failed talking with device policy service", re);
2178 } catch (CertificateException ce) {
2179 Log.w(TAG, "Could not parse certificate", ce);
2180 }
Maggie Benthallda51e682013-08-08 22:35:44 -04002181 }
2182 return false;
2183 }
2184
2185 /**
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002186 * Called by a device or profile owner to install a certificate and private key pair. The
2187 * keypair will be visible to all apps within the profile.
2188 *
Robin Lee25e26452015-06-02 09:56:29 -07002189 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2190 * {@code null} if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002191 * @param privKey The private key to install.
2192 * @param cert The certificate to install.
2193 * @param alias The private key alias under which to install the certificate. If a certificate
2194 * with that alias already exists, it will be overwritten.
2195 * @return {@code true} if the keys were installed, {@code false} otherwise.
2196 */
Robin Lee25e26452015-06-02 09:56:29 -07002197 public boolean installKeyPair(@Nullable ComponentName admin, PrivateKey privKey, Certificate cert,
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002198 String alias) {
2199 try {
2200 final byte[] pemCert = Credentials.convertToPem(cert);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002201 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
2202 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
Robin Lee25e26452015-06-02 09:56:29 -07002203 return mService.installKeyPair(admin, pkcs8Key, pemCert, alias);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002204 } catch (RemoteException e) {
2205 Log.w(TAG, "Failed talking with device policy service", e);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002206 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
2207 Log.w(TAG, "Failed to obtain private key material", e);
2208 } catch (CertificateException | IOException e) {
2209 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002210 }
2211 return false;
2212 }
2213
2214 /**
Robin Lee25e26452015-06-02 09:56:29 -07002215 * @return the alias of a given CA certificate in the certificate store, or {@code null} if it
Robin Lee306fe082014-06-19 14:04:24 +00002216 * doesn't exist.
2217 */
2218 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
2219 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
2220 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
2221 new ByteArrayInputStream(certBuffer));
2222 return new TrustedCertificateStore().getCertificateAlias(cert);
2223 }
2224
2225 /**
Rubin Xuec32b562015-03-03 17:34:05 +00002226 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01002227 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00002228 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01002229 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00002230 * <p>
2231 * Delegated certificate installer is a per-user state. The delegated access is persistent until
2232 * it is later cleared by calling this method with a null value or uninstallling the certificate
2233 * installer.
2234 *
Robin Lee25e26452015-06-02 09:56:29 -07002235 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xuec32b562015-03-03 17:34:05 +00002236 * @param installerPackage The package name of the certificate installer which will be given
Robin Lee25e26452015-06-02 09:56:29 -07002237 * access. If {@code null} is given the current package will be cleared.
Rubin Xuec32b562015-03-03 17:34:05 +00002238 */
Robin Lee25e26452015-06-02 09:56:29 -07002239 public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String
2240 installerPackage) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002241 if (mService != null) {
2242 try {
Robin Lee25e26452015-06-02 09:56:29 -07002243 mService.setCertInstallerPackage(admin, installerPackage);
Rubin Xuec32b562015-03-03 17:34:05 +00002244 } catch (RemoteException e) {
2245 Log.w(TAG, "Failed talking with device policy service", e);
2246 }
2247 }
2248 }
2249
2250 /**
2251 * Called by a profile owner or device owner to retrieve the certificate installer for the
2252 * current user. null if none is set.
2253 *
Robin Lee25e26452015-06-02 09:56:29 -07002254 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2255 * @return The package name of the current delegated certificate installer, or {@code null}
Rubin Xuec32b562015-03-03 17:34:05 +00002256 * if none is set.
2257 */
Robin Lee25e26452015-06-02 09:56:29 -07002258 public String getCertInstallerPackage(@NonNull ComponentName admin) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002259 if (mService != null) {
2260 try {
Robin Lee25e26452015-06-02 09:56:29 -07002261 return mService.getCertInstallerPackage(admin);
Rubin Xuec32b562015-03-03 17:34:05 +00002262 } catch (RemoteException e) {
2263 Log.w(TAG, "Failed talking with device policy service", e);
2264 }
2265 }
2266 return null;
2267 }
2268
2269 /**
Ben Komalo2447edd2011-05-09 16:05:33 -07002270 * Called by an application that is administering the device to disable all cameras
Amith Yamasani242f4b12014-10-14 16:06:13 -07002271 * on the device, for this user. After setting this, no applications running as this user
2272 * will be able to access any cameras on the device.
Ben Komalo2447edd2011-05-09 16:05:33 -07002273 *
2274 * <p>The calling device admin must have requested
2275 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
2276 * this method; if it has not, a security exception will be thrown.
2277 *
2278 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2279 * @param disabled Whether or not the camera should be disabled.
2280 */
Robin Lee25e26452015-06-02 09:56:29 -07002281 public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002282 if (mService != null) {
2283 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002284 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07002285 } catch (RemoteException e) {
2286 Log.w(TAG, "Failed talking with device policy service", e);
2287 }
2288 }
2289 }
2290
2291 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07002292 * Determine whether or not the device's cameras have been disabled for this user,
2293 * either by the current admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002294 * @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 -07002295 * have disabled the camera
2296 */
Robin Lee25e26452015-06-02 09:56:29 -07002297 public boolean getCameraDisabled(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002298 return getCameraDisabled(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002299 }
2300
2301 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002302 public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002303 if (mService != null) {
2304 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002305 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07002306 } catch (RemoteException e) {
2307 Log.w(TAG, "Failed talking with device policy service", e);
2308 }
2309 }
2310 return false;
2311 }
2312
2313 /**
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07002314 * Determine whether or not creating a guest user has been disabled for the device
2315 *
2316 * @hide
2317 */
2318 public boolean getGuestUserDisabled(@Nullable ComponentName admin) {
2319 // Currently guest users can always be created if multi-user is enabled
2320 // TODO introduce a policy for guest user creation
2321 return false;
2322 }
2323
2324 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01002325 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
2326 * screen capture also prevents the content from being shown on display devices that do not have
2327 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
2328 * secure surfaces and secure displays.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002329 *
2330 * <p>The calling device admin must be a device or profile owner. If it is not, a
2331 * security exception will be thrown.
2332 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002333 * <p>From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also
Benjamin Franzc200f442015-06-25 18:20:04 +01002334 * blocks assist requests for all activities of the relevant user.
2335 *
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002336 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002337 * @param disabled Whether screen capture is disabled or not.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002338 */
Robin Lee25e26452015-06-02 09:56:29 -07002339 public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002340 if (mService != null) {
2341 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002342 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002343 } catch (RemoteException e) {
2344 Log.w(TAG, "Failed talking with device policy service", e);
2345 }
2346 }
2347 }
2348
2349 /**
2350 * Determine whether or not screen capture has been disabled by the current
2351 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002352 * @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 +01002353 * have disabled screen capture.
2354 */
Robin Lee25e26452015-06-02 09:56:29 -07002355 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002356 return getScreenCaptureDisabled(admin, myUserId());
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002357 }
2358
2359 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002360 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002361 if (mService != null) {
2362 try {
2363 return mService.getScreenCaptureDisabled(admin, userHandle);
2364 } catch (RemoteException e) {
2365 Log.w(TAG, "Failed talking with device policy service", e);
2366 }
2367 }
2368 return false;
2369 }
2370
2371 /**
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002372 * Called by a device owner to set whether auto time is required. If auto time is
2373 * required the user cannot set the date and time, but has to use network date and time.
2374 *
2375 * <p>Note: if auto time is required the user can still manually set the time zone.
2376 *
2377 * <p>The calling device admin must be a device owner. If it is not, a security exception will
2378 * be thrown.
2379 *
2380 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2381 * @param required Whether auto time is set required or not.
2382 */
Robin Lee25e26452015-06-02 09:56:29 -07002383 public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) {
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002384 if (mService != null) {
2385 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002386 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002387 } catch (RemoteException e) {
2388 Log.w(TAG, "Failed talking with device policy service", e);
2389 }
2390 }
2391 }
2392
2393 /**
2394 * @return true if auto time is required.
2395 */
2396 public boolean getAutoTimeRequired() {
2397 if (mService != null) {
2398 try {
2399 return mService.getAutoTimeRequired();
2400 } catch (RemoteException e) {
2401 Log.w(TAG, "Failed talking with device policy service", e);
2402 }
2403 }
2404 return false;
2405 }
2406
2407 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002408 * Called by an application that is administering the device to disable keyguard customizations,
2409 * such as widgets. After setting this, keyguard features will be disabled according to the
2410 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002411 *
2412 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07002413 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07002414 * this method; if it has not, a security exception will be thrown.
2415 *
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002416 * <p>Calling this from a managed profile before version
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002417 * {@link android.os.Build.VERSION_CODES#M} will throw a security exception.
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002418 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002419 * <p>From version {@link android.os.Build.VERSION_CODES#M} a profile owner can set:
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002420 * <ul>
2421 * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, {@link #KEYGUARD_DISABLE_FINGERPRINT}
2422 * these will affect the profile's parent user.
2423 * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} this will affect notifications
2424 * generated by applications in the managed profile.
2425 * </ul>
2426 * <p>Requests to disable other features on a managed profile will be ignored. The admin
2427 * can check which features have been disabled by calling
2428 * {@link #getKeyguardDisabledFeatures(ComponentName)}
Amith Yamasani242f4b12014-10-14 16:06:13 -07002429 *
Jim Millerb8ec4702012-08-31 17:19:10 -07002430 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07002431 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
2432 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
Jim Miller50e62182014-04-23 17:25:00 -07002433 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002434 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FINGERPRINT},
2435 * {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07002436 */
Robin Lee25e26452015-06-02 09:56:29 -07002437 public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002438 if (mService != null) {
2439 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002440 mService.setKeyguardDisabledFeatures(admin, which);
Jim Millerb8ec4702012-08-31 17:19:10 -07002441 } catch (RemoteException e) {
2442 Log.w(TAG, "Failed talking with device policy service", e);
2443 }
2444 }
2445 }
2446
2447 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002448 * Determine whether or not features have been disabled in keyguard either by the current
Jim Millerb8ec4702012-08-31 17:19:10 -07002449 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002450 * @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 -07002451 * have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07002452 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
2453 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002454 */
Robin Lee25e26452015-06-02 09:56:29 -07002455 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002456 return getKeyguardDisabledFeatures(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002457 }
2458
2459 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002460 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002461 if (mService != null) {
2462 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07002463 return mService.getKeyguardDisabledFeatures(admin, userHandle);
Jim Millerb8ec4702012-08-31 17:19:10 -07002464 } catch (RemoteException e) {
2465 Log.w(TAG, "Failed talking with device policy service", e);
2466 }
2467 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07002468 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07002469 }
2470
2471 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08002472 * @hide
2473 */
Robin Lee25e26452015-06-02 09:56:29 -07002474 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
2475 int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002476 if (mService != null) {
2477 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01002478 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002479 } catch (RemoteException e) {
2480 Log.w(TAG, "Failed talking with device policy service", e);
2481 }
2482 }
2483 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002484
Dianne Hackbornd6847842010-01-12 18:14:19 -08002485 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01002486 * @hide
2487 */
Robin Lee25e26452015-06-02 09:56:29 -07002488 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002489 setActiveAdmin(policyReceiver, refreshing, myUserId());
Jessica Hummel6d36b602014-04-04 12:42:17 +01002490 }
2491
2492 /**
Robin Lee25e26452015-06-02 09:56:29 -07002493 * Returns the DeviceAdminInfo as defined by the administrator's package info &amp; meta-data
Dianne Hackbornd6847842010-01-12 18:14:19 -08002494 * @hide
2495 */
Robin Lee25e26452015-06-02 09:56:29 -07002496 public DeviceAdminInfo getAdminInfo(@NonNull ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002497 ActivityInfo ai;
2498 try {
2499 ai = mContext.getPackageManager().getReceiverInfo(cn,
2500 PackageManager.GET_META_DATA);
2501 } catch (PackageManager.NameNotFoundException e) {
2502 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
2503 return null;
2504 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002505
Dianne Hackbornd6847842010-01-12 18:14:19 -08002506 ResolveInfo ri = new ResolveInfo();
2507 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002508
Dianne Hackbornd6847842010-01-12 18:14:19 -08002509 try {
2510 return new DeviceAdminInfo(mContext, ri);
2511 } catch (XmlPullParserException e) {
2512 Log.w(TAG, "Unable to parse device policy " + cn, e);
2513 return null;
2514 } catch (IOException e) {
2515 Log.w(TAG, "Unable to parse device policy " + cn, e);
2516 return null;
2517 }
2518 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002519
Dianne Hackbornd6847842010-01-12 18:14:19 -08002520 /**
2521 * @hide
2522 */
Robin Lee25e26452015-06-02 09:56:29 -07002523 public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002524 if (mService != null) {
2525 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002526 mService.getRemoveWarning(admin, result, myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002527 } catch (RemoteException e) {
2528 Log.w(TAG, "Failed talking with device policy service", e);
2529 }
2530 }
2531 }
2532
2533 /**
2534 * @hide
2535 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002536 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002537 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002538 if (mService != null) {
2539 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002540 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002541 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002542 } catch (RemoteException e) {
2543 Log.w(TAG, "Failed talking with device policy service", e);
2544 }
2545 }
2546 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002547
Dianne Hackbornd6847842010-01-12 18:14:19 -08002548 /**
2549 * @hide
2550 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002551 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002552 if (mService != null) {
2553 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002554 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002555 } catch (RemoteException e) {
2556 Log.w(TAG, "Failed talking with device policy service", e);
2557 }
2558 }
2559 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002560
Dianne Hackbornd6847842010-01-12 18:14:19 -08002561 /**
2562 * @hide
2563 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002564 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002565 if (mService != null) {
2566 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002567 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002568 } catch (RemoteException e) {
2569 Log.w(TAG, "Failed talking with device policy service", e);
2570 }
2571 }
2572 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07002573
2574 /**
2575 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00002576 * Sets the given package as the device owner.
Makoto Onukia52562c2015-10-01 16:12:31 -07002577 * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name.
2578 * @param who the component name to be registered as device owner.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002579 * @return whether the package was successfully registered as the device owner.
2580 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00002581 * @throws IllegalStateException If the preconditions mentioned are not met.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002582 */
Makoto Onukia52562c2015-10-01 16:12:31 -07002583 public boolean setDeviceOwner(ComponentName who) {
2584 return setDeviceOwner(who, null);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002585 }
2586
2587 /**
2588 * @hide
Makoto Onuki58b684f2015-09-04 10:48:16 -07002589 */
Makoto Onukia52562c2015-10-01 16:12:31 -07002590 public boolean setDeviceOwner(ComponentName who, int userId) {
2591 return setDeviceOwner(who, null, userId);
Makoto Onuki58b684f2015-09-04 10:48:16 -07002592 }
2593
2594 /**
2595 * @hide
2596 */
Makoto Onukia52562c2015-10-01 16:12:31 -07002597 public boolean setDeviceOwner(ComponentName who, String ownerName) {
2598 return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM);
Makoto Onuki58b684f2015-09-04 10:48:16 -07002599 }
2600
2601 /**
2602 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00002603 * Sets the given package as the device owner. The package must already be installed. There
2604 * must not already be a device owner.
2605 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
2606 * this method.
2607 * Calling this after the setup phase of the primary user has completed is allowed only if
2608 * the caller is the shell uid, and there are no additional users and no accounts.
Makoto Onukia52562c2015-10-01 16:12:31 -07002609 * @param who the component name to be registered as device owner.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002610 * @param ownerName the human readable name of the institution that owns this device.
Makoto Onuki58b684f2015-09-04 10:48:16 -07002611 * @param userId ID of the user on which the device owner runs.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002612 * @return whether the package was successfully registered as the device owner.
2613 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00002614 * @throws IllegalStateException If the preconditions mentioned are not met.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002615 */
Makoto Onukia52562c2015-10-01 16:12:31 -07002616 public boolean setDeviceOwner(ComponentName who, String ownerName, int userId)
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002617 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002618 if (mService != null) {
2619 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07002620 return mService.setDeviceOwner(who, ownerName, userId);
Amith Yamasani71e6c692013-03-24 17:39:28 -07002621 } catch (RemoteException re) {
2622 Log.w(TAG, "Failed to set device owner");
2623 }
2624 }
2625 return false;
2626 }
2627
2628 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002629 * Used to determine if a particular package has been registered as a Device Owner app.
2630 * A device owner app is a special device admin that cannot be deactivated by the user, once
Robin Lee25e26452015-06-02 09:56:29 -07002631 * activated as a device admin. It also cannot be uninstalled. To check whether a particular
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002632 * package is currently registered as the device owner app, pass in the package name from
2633 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
Robin Lee25e26452015-06-02 09:56:29 -07002634 * admin apps that want to check whether they are also registered as the device owner app. The
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002635 * exact mechanism by which a device admin app is registered as a device owner app is defined by
2636 * the setup process.
2637 * @param packageName the package name of the app, to compare with the registered device owner
2638 * app, if any.
Makoto Onukia52562c2015-10-01 16:12:31 -07002639 * @return whether or not the package is registered as the device owner app. Note this method
2640 * does *not* check weather the device owner is actually running on the current user.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002641 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002642 public boolean isDeviceOwnerApp(String packageName) {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002643 if (mService != null) {
2644 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07002645 return mService.isDeviceOwnerPackage(packageName);
2646 } catch (RemoteException e) {
2647 Log.w(TAG, "Failed talking with device policy service", e);
Amith Yamasani71e6c692013-03-24 17:39:28 -07002648 }
2649 }
2650 return false;
2651 }
2652
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002653 /**
2654 * @hide
2655 * Redirect to isDeviceOwnerApp.
2656 */
2657 public boolean isDeviceOwner(String packageName) {
2658 return isDeviceOwnerApp(packageName);
2659 }
2660
Jason Monkb0dced82014-06-06 14:36:20 -04002661 /**
Makoto Onukia52562c2015-10-01 16:12:31 -07002662 * Check whether a given component is registered as a device owner.
2663 * Note this method does *not* check weather the device owner is actually running on the current
2664 * user.
2665 *
2666 * @hide
2667 */
2668 public boolean isDeviceOwner(ComponentName who) {
2669 return (who != null) && who.equals(getDeviceOwner());
2670 }
2671
2672 /**
Jason Monkb0dced82014-06-06 14:36:20 -04002673 * Clears the current device owner. The caller must be the device owner.
2674 *
2675 * This function should be used cautiously as once it is called it cannot
2676 * be undone. The device owner can only be set as a part of device setup
2677 * before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04002678 *
2679 * @param packageName The package name of the device owner.
Jason Monkb0dced82014-06-06 14:36:20 -04002680 */
Jason Monk94d2cf92014-06-18 09:53:34 -04002681 public void clearDeviceOwnerApp(String packageName) {
Jason Monkb0dced82014-06-06 14:36:20 -04002682 if (mService != null) {
2683 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04002684 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04002685 } catch (RemoteException re) {
2686 Log.w(TAG, "Failed to clear device owner");
2687 }
2688 }
2689 }
2690
Makoto Onukia52562c2015-10-01 16:12:31 -07002691 /**
2692 * Returns the device owner package name. Note this method will still return the device owner
2693 * package name even if it's running on a different user.
2694 *
2695 * @hide
2696 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002697 @SystemApi
Amith Yamasani71e6c692013-03-24 17:39:28 -07002698 public String getDeviceOwner() {
Makoto Onukia52562c2015-10-01 16:12:31 -07002699 final ComponentName componentName = getDeviceOwnerComponent();
2700 return componentName == null ? null : componentName.getPackageName();
2701 }
2702
2703 /**
2704 * Returns the device owner name. Note this method will still return the device owner
2705 * name even if it's running on a different user.
2706 *
2707 * @hide
2708 */
2709 public String getDeviceOwnerName() {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002710 if (mService != null) {
2711 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07002712 return mService.getDeviceOwnerName();
Amith Yamasani71e6c692013-03-24 17:39:28 -07002713 } catch (RemoteException re) {
2714 Log.w(TAG, "Failed to get device owner");
2715 }
2716 }
2717 return null;
2718 }
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002719
Makoto Onukia52562c2015-10-01 16:12:31 -07002720 /**
2721 * Returns the device owner component name. Note this method will still return the device owner
2722 * component name even if it's running on a different user.
2723 *
2724 * @hide
2725 */
2726 public ComponentName getDeviceOwnerComponent() {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002727 if (mService != null) {
2728 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07002729 return mService.getDeviceOwner();
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002730 } catch (RemoteException re) {
2731 Log.w(TAG, "Failed to get device owner");
2732 }
2733 }
2734 return null;
2735 }
Adam Connors776c5552014-01-09 10:42:56 +00002736
2737 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04002738 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04002739 * @deprecated Do not use
2740 * @removed
Julia Reynolds20118f12015-02-11 12:34:08 -05002741 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04002742 @Deprecated
Julia Reynolds20118f12015-02-11 12:34:08 -05002743 @SystemApi
2744 public String getDeviceInitializerApp() {
Julia Reynolds20118f12015-02-11 12:34:08 -05002745 return null;
2746 }
2747
2748 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002749 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04002750 * @deprecated Do not use
2751 * @removed
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002752 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04002753 @Deprecated
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002754 @SystemApi
2755 public ComponentName getDeviceInitializerComponent() {
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002756 return null;
2757 }
2758
Julia Reynolds20118f12015-02-11 12:34:08 -05002759 /**
Adam Connors776c5552014-01-09 10:42:56 +00002760 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002761 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302762 * Sets the given component as an active admin and registers the package as the profile
2763 * owner for this user. The package must already be installed and there shouldn't be
2764 * an existing profile owner registered for this user. Also, this method must be called
2765 * before the user setup has been completed.
2766 * <p>
2767 * This method can only be called by system apps that hold MANAGE_USERS permission and
2768 * MANAGE_DEVICE_ADMINS permission.
2769 * @param admin The component to register as an active admin and profile owner.
2770 * @param ownerName The user-visible name of the entity that is managing this user.
2771 * @return whether the admin was successfully registered as the profile owner.
2772 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
2773 * the user has already been set up.
2774 */
Justin Morey80440cc2014-07-24 09:16:35 -05002775 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07002776 public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302777 throws IllegalArgumentException {
2778 if (mService != null) {
2779 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002780 final int myUserId = myUserId();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302781 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002782 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302783 } catch (RemoteException re) {
2784 Log.w(TAG, "Failed to set profile owner " + re);
2785 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2786 }
2787 }
2788 return false;
2789 }
2790
2791 /**
2792 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002793 * Clears the active profile owner and removes all user restrictions. The caller must
2794 * be from the same package as the active profile owner for this user, otherwise a
2795 * SecurityException will be thrown.
2796 *
2797 * @param admin The component to remove as the profile owner.
2798 * @return
2799 */
2800 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07002801 public void clearProfileOwner(@NonNull ComponentName admin) {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002802 if (mService != null) {
2803 try {
2804 mService.clearProfileOwner(admin);
2805 } catch (RemoteException re) {
2806 Log.w(TAG, "Failed to clear profile owner " + admin + re);
2807 }
2808 }
2809 }
2810
2811 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05002812 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07002813 * Checks whether the user was already setup.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002814 */
2815 public boolean hasUserSetupCompleted() {
2816 if (mService != null) {
2817 try {
2818 return mService.hasUserSetupCompleted();
2819 } catch (RemoteException re) {
Robin Lee25e26452015-06-02 09:56:29 -07002820 Log.w(TAG, "Failed to check whether user setup has completed");
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002821 }
2822 }
2823 return true;
2824 }
2825
2826 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002827 * @hide
2828 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00002829 * already be installed. There must not already be a profile owner for this user.
2830 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
2831 * this method.
2832 * Calling this after the setup phase of the specified user has completed is allowed only if:
2833 * - the caller is SYSTEM_UID.
2834 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002835 * @param admin the component name to be registered as profile owner.
2836 * @param ownerName the human readable name of the organisation associated with this DPM.
2837 * @param userHandle the userId to set the profile owner for.
2838 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00002839 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
2840 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002841 */
Robin Lee25e26452015-06-02 09:56:29 -07002842 public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName,
Robin Leeddd553f2015-04-30 14:18:22 +01002843 int userHandle) throws IllegalArgumentException {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002844 if (admin == null) {
2845 throw new NullPointerException("admin cannot be null");
2846 }
Adam Connors776c5552014-01-09 10:42:56 +00002847 if (mService != null) {
2848 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002849 if (ownerName == null) {
2850 ownerName = "";
2851 }
2852 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00002853 } catch (RemoteException re) {
2854 Log.w(TAG, "Failed to set profile owner", re);
2855 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2856 }
2857 }
2858 return false;
2859 }
2860
2861 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002862 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
2863 * be used. Only the profile owner can call this.
2864 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01002865 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002866 *
2867 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2868 */
Robin Lee25e26452015-06-02 09:56:29 -07002869 public void setProfileEnabled(@NonNull ComponentName admin) {
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002870 if (mService != null) {
2871 try {
2872 mService.setProfileEnabled(admin);
2873 } catch (RemoteException e) {
2874 Log.w(TAG, "Failed talking with device policy service", e);
2875 }
2876 }
2877 }
2878
2879 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002880 * Sets the name of the profile. In the device owner case it sets the name of the user
2881 * 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 +01002882 * never called by the profile or device owner, the name will be set to default values.
2883 *
2884 * @see #isProfileOwnerApp
2885 * @see #isDeviceOwnerApp
2886 *
Robin Lee25e26452015-06-02 09:56:29 -07002887 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01002888 * @param profileName The name of the profile.
2889 */
Robin Lee25e26452015-06-02 09:56:29 -07002890 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Jessica Hummel1333ea12014-06-23 11:20:10 +01002891 if (mService != null) {
2892 try {
Robin Lee25e26452015-06-02 09:56:29 -07002893 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07002894 } catch (RemoteException e) {
2895 Log.w(TAG, "Failed talking with device policy service", e);
2896 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01002897 }
2898 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01002899
2900 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002901 * Used to determine if a particular package is registered as the profile owner for the
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002902 * current user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002903 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00002904 *
2905 * @param packageName The package name of the app to compare with the registered profile owner.
2906 * @return Whether or not the package is registered as the profile owner.
2907 */
2908 public boolean isProfileOwnerApp(String packageName) {
2909 if (mService != null) {
2910 try {
Nicolas Prevot90af6d72014-07-30 14:19:12 +01002911 ComponentName profileOwner = mService.getProfileOwner(
2912 Process.myUserHandle().getIdentifier());
2913 return profileOwner != null
2914 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00002915 } catch (RemoteException re) {
2916 Log.w(TAG, "Failed to check profile owner");
2917 }
2918 }
2919 return false;
2920 }
2921
2922 /**
2923 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07002924 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00002925 * owner has been set for that user.
2926 * @throws IllegalArgumentException if the userId is invalid.
2927 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002928 @SystemApi
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002929 public ComponentName getProfileOwner() throws IllegalArgumentException {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01002930 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
2931 }
2932
2933 /**
2934 * @see #getProfileOwner()
2935 * @hide
2936 */
2937 public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00002938 if (mService != null) {
2939 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01002940 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00002941 } catch (RemoteException re) {
2942 Log.w(TAG, "Failed to get profile owner");
2943 throw new IllegalArgumentException(
2944 "Requested profile owner for invalid userId", re);
2945 }
2946 }
2947 return null;
2948 }
2949
2950 /**
2951 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07002952 * @return the human readable name of the organisation associated with this DPM or {@code null}
2953 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00002954 * @throws IllegalArgumentException if the userId is invalid.
2955 */
2956 public String getProfileOwnerName() throws IllegalArgumentException {
2957 if (mService != null) {
2958 try {
2959 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
2960 } catch (RemoteException re) {
2961 Log.w(TAG, "Failed to get profile owner");
2962 throw new IllegalArgumentException(
2963 "Requested profile owner for invalid userId", re);
2964 }
2965 }
2966 return null;
2967 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002968
2969 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07002970 * @hide
2971 * @param user The user for whom to fetch the profile owner name, if any.
2972 * @return the human readable name of the organisation associated with this profile owner or
2973 * null if one is not set.
2974 * @throws IllegalArgumentException if the userId is invalid.
2975 */
2976 @SystemApi
Selim Cinek24ac55e2014-08-27 12:51:45 +02002977 public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Amith Yamasani38f836b2014-08-20 14:51:15 -07002978 if (mService != null) {
2979 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02002980 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07002981 } catch (RemoteException re) {
2982 Log.w(TAG, "Failed to get profile owner");
2983 throw new IllegalArgumentException(
2984 "Requested profile owner for invalid userId", re);
2985 }
2986 }
2987 return null;
2988 }
2989
2990 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002991 * Called by a profile owner or device owner to add a default intent handler activity for
2992 * intents that match a certain intent filter. This activity will remain the default intent
2993 * handler even if the set of potential event handlers for the intent filter changes and if
2994 * the intent preferences are reset.
2995 *
2996 * <p>The default disambiguation mechanism takes over if the activity is not installed
2997 * (anymore). When the activity is (re)installed, it is automatically reset as default
2998 * intent handler for the filter.
2999 *
3000 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
3001 * security exception will be thrown.
3002 *
3003 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3004 * @param filter The IntentFilter for which a default handler is added.
3005 * @param activity The Activity that is added as default intent handler.
3006 */
Robin Lee25e26452015-06-02 09:56:29 -07003007 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
3008 @NonNull ComponentName activity) {
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003009 if (mService != null) {
3010 try {
3011 mService.addPersistentPreferredActivity(admin, filter, activity);
3012 } catch (RemoteException e) {
3013 Log.w(TAG, "Failed talking with device policy service", e);
3014 }
3015 }
3016 }
3017
3018 /**
3019 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00003020 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003021 *
3022 * <p>The calling device admin must be a profile owner. If it is not, a security
3023 * exception will be thrown.
3024 *
3025 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3026 * @param packageName The name of the package for which preferences are removed.
3027 */
Robin Lee25e26452015-06-02 09:56:29 -07003028 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003029 String packageName) {
3030 if (mService != null) {
3031 try {
3032 mService.clearPackagePersistentPreferredActivities(admin, packageName);
3033 } catch (RemoteException e) {
3034 Log.w(TAG, "Failed talking with device policy service", e);
3035 }
3036 }
3037 }
Robin Lee66e5d962014-04-09 16:44:21 +01003038
3039 /**
3040 * Called by a profile or device owner to set the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003041 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01003042 *
Esteban Talavera6b8e0642015-08-10 17:26:04 +01003043 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be:
3044 * <ul>
3045 * <li>{@code boolean}
3046 * <li>{@code int}
3047 * <li>{@code String} or {@code String[]}
3048 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
3049 * </ul>
Robin Lee66e5d962014-04-09 16:44:21 +01003050 *
3051 * <p>The application restrictions are only made visible to the target application and the
3052 * profile or device owner.
3053 *
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003054 * <p>If the restrictions are not available yet, but may be applied in the near future,
3055 * the admin can notify the target application of that by adding
3056 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
3057 *
Robin Lee66e5d962014-04-09 16:44:21 +01003058 * <p>The calling device admin must be a profile or device owner; if it is not, a security
3059 * exception will be thrown.
3060 *
3061 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3062 * @param packageName The name of the package to update restricted settings for.
3063 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
3064 * set of active restrictions.
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003065 *
3066 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01003067 */
Robin Lee25e26452015-06-02 09:56:29 -07003068 public void setApplicationRestrictions(@NonNull ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01003069 Bundle settings) {
3070 if (mService != null) {
3071 try {
3072 mService.setApplicationRestrictions(admin, packageName, settings);
3073 } catch (RemoteException e) {
3074 Log.w(TAG, "Failed talking with device policy service", e);
3075 }
3076 }
3077 }
3078
3079 /**
Jim Millere303bf42014-08-26 17:12:29 -07003080 * Sets a list of configuration features to enable for a TrustAgent component. This is meant
3081 * to be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all
3082 * trust agents but those enabled by this function call. If flag
3083 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Jim Miller604e7552014-07-18 19:00:02 -07003084 *
3085 * <p>The calling device admin must have requested
3086 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millere303bf42014-08-26 17:12:29 -07003087 * this method; if not, a security exception will be thrown.
Jim Miller604e7552014-07-18 19:00:02 -07003088 *
3089 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07003090 * @param target Component name of the agent to be enabled.
Jim Millerb5db57a2015-01-14 18:17:19 -08003091 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent
Jim Millere303bf42014-08-26 17:12:29 -07003092 * will be strictly disabled according to the state of the
3093 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
3094 * <p>If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all admins,
3095 * then it's up to the TrustAgent itself to aggregate the values from all device admins.
3096 * <p>Consult documentation for the specific TrustAgent to determine legal options parameters.
Jim Miller604e7552014-07-18 19:00:02 -07003097 */
Robin Lee25e26452015-06-02 09:56:29 -07003098 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
3099 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07003100 if (mService != null) {
3101 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003102 mService.setTrustAgentConfiguration(admin, target, configuration);
Jim Miller604e7552014-07-18 19:00:02 -07003103 } catch (RemoteException e) {
3104 Log.w(TAG, "Failed talking with device policy service", e);
3105 }
3106 }
3107 }
3108
3109 /**
Jim Millere303bf42014-08-26 17:12:29 -07003110 * Gets configuration for the given trust agent based on aggregating all calls to
3111 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
3112 * all device admins.
Jim Miller604e7552014-07-18 19:00:02 -07003113 *
Jim Millerb5db57a2015-01-14 18:17:19 -08003114 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
3115 * this function returns a list of configurations for all admins that declare
3116 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
3117 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
3118 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
3119 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07003120 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07003121 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07003122 */
Robin Lee25e26452015-06-02 09:56:29 -07003123 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
3124 @NonNull ComponentName agent) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003125 return getTrustAgentConfiguration(admin, agent, myUserId());
Jim Millere303bf42014-08-26 17:12:29 -07003126 }
3127
3128 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003129 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
3130 @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07003131 if (mService != null) {
3132 try {
Jim Millere303bf42014-08-26 17:12:29 -07003133 return mService.getTrustAgentConfiguration(admin, agent, userHandle);
Jim Miller604e7552014-07-18 19:00:02 -07003134 } catch (RemoteException e) {
3135 Log.w(TAG, "Failed talking with device policy service", e);
3136 }
3137 }
Jim Millere303bf42014-08-26 17:12:29 -07003138 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07003139 }
3140
3141 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003142 * Called by a profile owner of a managed profile to set whether caller-Id information from
3143 * the managed profile will be shown in the parent profile, for incoming calls.
Adam Connors210fe212014-07-17 15:41:43 +01003144 *
3145 * <p>The calling device admin must be a profile owner. If it is not, a
3146 * security exception will be thrown.
3147 *
Robin Lee25e26452015-06-02 09:56:29 -07003148 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01003149 * @param disabled If true caller-Id information in the managed profile is not displayed.
3150 */
Robin Lee25e26452015-06-02 09:56:29 -07003151 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Adam Connors210fe212014-07-17 15:41:43 +01003152 if (mService != null) {
3153 try {
Robin Lee25e26452015-06-02 09:56:29 -07003154 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01003155 } catch (RemoteException e) {
3156 Log.w(TAG, "Failed talking with device policy service", e);
3157 }
3158 }
3159 }
3160
3161 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003162 * Called by a profile owner of a managed profile to determine whether or not caller-Id
3163 * information has been disabled.
Adam Connors210fe212014-07-17 15:41:43 +01003164 *
3165 * <p>The calling device admin must be a profile owner. If it is not, a
3166 * security exception will be thrown.
3167 *
Robin Lee25e26452015-06-02 09:56:29 -07003168 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01003169 */
Robin Lee25e26452015-06-02 09:56:29 -07003170 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Adam Connors210fe212014-07-17 15:41:43 +01003171 if (mService != null) {
3172 try {
Robin Lee25e26452015-06-02 09:56:29 -07003173 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01003174 } catch (RemoteException e) {
3175 Log.w(TAG, "Failed talking with device policy service", e);
3176 }
3177 }
3178 return false;
3179 }
3180
3181 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07003182 * Determine whether or not caller-Id information has been disabled.
3183 *
3184 * @param userHandle The user for whom to check the caller-id permission
3185 * @hide
3186 */
3187 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
3188 if (mService != null) {
3189 try {
3190 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
3191 } catch (RemoteException e) {
3192 Log.w(TAG, "Failed talking with device policy service", e);
3193 }
3194 }
3195 return false;
3196 }
3197
3198 /**
Makoto Onuki1040da12015-03-19 11:24:00 -07003199 * Start Quick Contact on the managed profile for the current user, if the policy allows.
3200 * @hide
3201 */
3202 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
3203 Intent originalIntent) {
3204 if (mService != null) {
3205 try {
3206 mService.startManagedQuickContact(
3207 actualLookupKey, actualContactId, originalIntent);
3208 } catch (RemoteException e) {
3209 Log.w(TAG, "Failed talking with device policy service", e);
3210 }
3211 }
3212 }
3213
3214 /**
Ricky Wai778ba132015-03-31 14:21:22 +01003215 * Called by a profile owner of a managed profile to set whether bluetooth
3216 * devices can access enterprise contacts.
3217 * <p>
3218 * The calling device admin must be a profile owner. If it is not, a
3219 * security exception will be thrown.
3220 * <p>
3221 * This API works on managed profile only.
3222 *
Robin Lee25e26452015-06-02 09:56:29 -07003223 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01003224 * with.
3225 * @param disabled If true, bluetooth devices cannot access enterprise
3226 * contacts.
3227 */
Robin Lee25e26452015-06-02 09:56:29 -07003228 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Ricky Wai778ba132015-03-31 14:21:22 +01003229 if (mService != null) {
3230 try {
Robin Lee25e26452015-06-02 09:56:29 -07003231 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01003232 } catch (RemoteException e) {
3233 Log.w(TAG, "Failed talking with device policy service", e);
3234 }
3235 }
3236 }
3237
3238 /**
3239 * Called by a profile owner of a managed profile to determine whether or
3240 * not Bluetooth devices cannot access enterprise contacts.
3241 * <p>
3242 * The calling device admin must be a profile owner. If it is not, a
3243 * security exception will be thrown.
3244 * <p>
3245 * This API works on managed profile only.
3246 *
Robin Lee25e26452015-06-02 09:56:29 -07003247 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01003248 * with.
3249 */
Robin Lee25e26452015-06-02 09:56:29 -07003250 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Ricky Wai778ba132015-03-31 14:21:22 +01003251 if (mService != null) {
3252 try {
Robin Lee25e26452015-06-02 09:56:29 -07003253 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01003254 } catch (RemoteException e) {
3255 Log.w(TAG, "Failed talking with device policy service", e);
3256 }
3257 }
3258 return true;
3259 }
3260
3261 /**
3262 * Determine whether or not Bluetooth devices cannot access contacts.
3263 * <p>
3264 * This API works on managed profile UserHandle only.
3265 *
3266 * @param userHandle The user for whom to check the caller-id permission
3267 * @hide
3268 */
3269 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
3270 if (mService != null) {
3271 try {
3272 return mService.getBluetoothContactSharingDisabledForUser(userHandle
3273 .getIdentifier());
3274 } catch (RemoteException e) {
3275 Log.w(TAG, "Failed talking with device policy service", e);
3276 }
3277 }
3278 return true;
3279 }
3280
3281 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003282 * Called by the profile owner of a managed profile so that some intents sent in the managed
3283 * profile can also be resolved in the parent, or vice versa.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00003284 * Only activity intents are supported.
3285 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003286 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01003287 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
3288 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01003289 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
3290 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003291 */
Robin Lee25e26452015-06-02 09:56:29 -07003292 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003293 if (mService != null) {
3294 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003295 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003296 } catch (RemoteException e) {
3297 Log.w(TAG, "Failed talking with device policy service", e);
3298 }
3299 }
3300 }
3301
3302 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003303 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
3304 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01003305 * Only removes those that have been set by the profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003306 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3307 */
Robin Lee25e26452015-06-02 09:56:29 -07003308 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003309 if (mService != null) {
3310 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003311 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003312 } catch (RemoteException e) {
3313 Log.w(TAG, "Failed talking with device policy service", e);
3314 }
3315 }
3316 }
3317
3318 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003319 * Called by a profile or device owner to set the permitted accessibility services. When
3320 * set by a device owner or profile owner the restriction applies to all profiles of the
3321 * user the device owner or profile owner is an admin for.
Jim Millerb1474f42014-08-26 18:42:58 -07003322 *
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003323 * By default the user can use any accessiblity service. When zero or more packages have
3324 * been added, accessiblity services that are not in the list and not part of the system
Jim Millerb1474f42014-08-26 18:42:58 -07003325 * can not be enabled by the user.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003326 *
3327 * <p> Calling with a null value for the list disables the restriction so that all services
3328 * can be used, calling with an empty list only allows the builtin system's services.
3329 *
3330 * <p> System accesibility services are always available to the user the list can't modify
3331 * this.
3332 *
3333 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3334 * @param packageNames List of accessibility service package names.
3335 *
3336 * @return true if setting the restriction succeeded. It fail if there is
3337 * one or more non-system accessibility services enabled, that are not in the list.
3338 */
Robin Lee25e26452015-06-02 09:56:29 -07003339 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003340 List<String> packageNames) {
3341 if (mService != null) {
3342 try {
3343 return mService.setPermittedAccessibilityServices(admin, packageNames);
3344 } catch (RemoteException e) {
3345 Log.w(TAG, "Failed talking with device policy service", e);
3346 }
3347 }
3348 return false;
3349 }
3350
3351 /**
3352 * Returns the list of permitted accessibility services set by this device or profile owner.
3353 *
3354 * <p>An empty list means no accessibility services except system services are allowed.
3355 * Null means all accessibility services are allowed.
3356 *
3357 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3358 * @return List of accessiblity service package names.
3359 */
Robin Lee25e26452015-06-02 09:56:29 -07003360 public List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003361 if (mService != null) {
3362 try {
3363 return mService.getPermittedAccessibilityServices(admin);
3364 } catch (RemoteException e) {
3365 Log.w(TAG, "Failed talking with device policy service", e);
3366 }
3367 }
3368 return null;
3369 }
3370
3371 /**
3372 * Returns the list of accessibility services permitted by the device or profiles
3373 * owners of this user.
3374 *
3375 * <p>Null means all accessibility services are allowed, if a non-null list is returned
3376 * it will contain the intersection of the permitted lists for any device or profile
3377 * owners that apply to this user. It will also include any system accessibility services.
3378 *
3379 * @param userId which user to check for.
3380 * @return List of accessiblity service package names.
3381 * @hide
3382 */
3383 @SystemApi
3384 public List<String> getPermittedAccessibilityServices(int userId) {
3385 if (mService != null) {
3386 try {
3387 return mService.getPermittedAccessibilityServicesForUser(userId);
3388 } catch (RemoteException e) {
3389 Log.w(TAG, "Failed talking with device policy service", e);
3390 }
3391 }
3392 return null;
3393 }
3394
3395 /**
3396 * Called by a profile or device owner to set the permitted input methods services. When
3397 * set by a device owner or profile owner the restriction applies to all profiles of the
3398 * user the device owner or profile owner is an admin for.
3399 *
3400 * By default the user can use any input method. When zero or more packages have
3401 * been added, input method that are not in the list and not part of the system
3402 * can not be enabled by the user.
3403 *
3404 * This method will fail if it is called for a admin that is not for the foreground user
3405 * or a profile of the foreground user.
3406 *
3407 * <p> Calling with a null value for the list disables the restriction so that all input methods
3408 * can be used, calling with an empty list disables all but the system's own input methods.
3409 *
3410 * <p> System input methods are always available to the user this method can't modify this.
3411 *
3412 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3413 * @param packageNames List of input method package names.
Kenny Guy74a70242015-02-05 19:48:38 +00003414 * @return true if setting the restriction succeeded. It will fail if there are
3415 * one or more non-system input methods currently enabled that are not in
3416 * the packageNames list.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003417 */
Robin Lee25e26452015-06-02 09:56:29 -07003418 public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003419 if (mService != null) {
3420 try {
3421 return mService.setPermittedInputMethods(admin, packageNames);
3422 } catch (RemoteException e) {
3423 Log.w(TAG, "Failed talking with device policy service", e);
3424 }
3425 }
3426 return false;
3427 }
3428
3429
3430 /**
3431 * Returns the list of permitted input methods set by this device or profile owner.
3432 *
3433 * <p>An empty list means no input methods except system input methods are allowed.
3434 * Null means all input methods are allowed.
3435 *
3436 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3437 * @return List of input method package names.
3438 */
Robin Lee25e26452015-06-02 09:56:29 -07003439 public List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003440 if (mService != null) {
3441 try {
3442 return mService.getPermittedInputMethods(admin);
3443 } catch (RemoteException e) {
3444 Log.w(TAG, "Failed talking with device policy service", e);
3445 }
3446 }
3447 return null;
3448 }
3449
3450 /**
3451 * Returns the list of input methods permitted by the device or profiles
3452 * owners of the current user.
3453 *
3454 * <p>Null means all input methods are allowed, if a non-null list is returned
3455 * it will contain the intersection of the permitted lists for any device or profile
3456 * owners that apply to this user. It will also include any system input methods.
3457 *
3458 * @return List of input method package names.
3459 * @hide
3460 */
3461 @SystemApi
3462 public List<String> getPermittedInputMethodsForCurrentUser() {
3463 if (mService != null) {
3464 try {
3465 return mService.getPermittedInputMethodsForCurrentUser();
3466 } catch (RemoteException e) {
3467 Log.w(TAG, "Failed talking with device policy service", e);
3468 }
3469 }
3470 return null;
3471 }
3472
3473 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003474 * Called by a device owner to create a user with the specified name. The UserHandle returned
3475 * by this method should not be persisted as user handles are recycled as users are removed and
3476 * created. If you need to persist an identifier for this user, use
3477 * {@link UserManager#getSerialNumberForUser}.
3478 *
3479 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3480 * @param name the user's name
3481 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07003482 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
3483 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01003484 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07003485 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
Julia Reynolds1e958392014-05-16 14:25:21 -04003486 */
Kenny Guy14f48e52015-06-29 15:12:36 +01003487 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07003488 public UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04003489 try {
3490 return mService.createUser(admin, name);
3491 } catch (RemoteException re) {
3492 Log.w(TAG, "Could not create a user", re);
3493 }
3494 return null;
3495 }
3496
3497 /**
Jason Monk03978a42014-06-10 15:05:30 -04003498 * Called by a device owner to create a user with the specified name. The UserHandle returned
3499 * by this method should not be persisted as user handles are recycled as users are removed and
3500 * created. If you need to persist an identifier for this user, use
3501 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
3502 * immediately.
3503 *
3504 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
3505 * as registered as an active admin on the new user. The profile owner package will be
3506 * installed on the new user if it already is installed on the device.
3507 *
3508 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
3509 * profileOwnerComponent when onEnable is called.
3510 *
3511 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3512 * @param name the user's name
3513 * @param ownerName the human readable name of the organisation associated with this DPM.
3514 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
3515 * the user.
3516 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
3517 * on the new user.
3518 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07003519 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
3520 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01003521 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07003522 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
Jason Monk03978a42014-06-10 15:05:30 -04003523 */
Kenny Guy14f48e52015-06-29 15:12:36 +01003524 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07003525 public UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
3526 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04003527 try {
3528 return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent,
3529 adminExtras);
3530 } catch (RemoteException re) {
3531 Log.w(TAG, "Could not create a user", re);
3532 }
3533 return null;
3534 }
3535
3536 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003537 * Called by a device owner to remove a user and all associated data. The primary user can
3538 * not be removed.
3539 *
3540 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3541 * @param userHandle the user to remove.
3542 * @return {@code true} if the user was removed, {@code false} otherwise.
3543 */
Robin Lee25e26452015-06-02 09:56:29 -07003544 public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) {
Julia Reynolds1e958392014-05-16 14:25:21 -04003545 try {
3546 return mService.removeUser(admin, userHandle);
3547 } catch (RemoteException re) {
3548 Log.w(TAG, "Could not remove user ", re);
3549 return false;
3550 }
3551 }
3552
3553 /**
Jason Monk582d9112014-07-09 19:57:08 -04003554 * Called by a device owner to switch the specified user to the foreground.
3555 *
3556 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3557 * @param userHandle the user to switch to; null will switch to primary.
3558 * @return {@code true} if the switch was successful, {@code false} otherwise.
3559 *
3560 * @see Intent#ACTION_USER_FOREGROUND
3561 */
Robin Lee25e26452015-06-02 09:56:29 -07003562 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Jason Monk582d9112014-07-09 19:57:08 -04003563 try {
3564 return mService.switchUser(admin, userHandle);
3565 } catch (RemoteException re) {
3566 Log.w(TAG, "Could not switch user ", re);
3567 return false;
3568 }
3569 }
3570
3571 /**
Robin Lee66e5d962014-04-09 16:44:21 +01003572 * Called by a profile or device owner to get the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003573 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01003574 *
3575 * <p>The calling device admin must be a profile or device owner; if it is not, a security
3576 * exception will be thrown.
3577 *
3578 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3579 * @param packageName The name of the package to fetch restricted settings of.
3580 * @return {@link Bundle} of settings corresponding to what was set last time
3581 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
3582 * if no restrictions have been set.
3583 */
Robin Lee25e26452015-06-02 09:56:29 -07003584 public Bundle getApplicationRestrictions(@NonNull ComponentName admin, String packageName) {
Robin Lee66e5d962014-04-09 16:44:21 +01003585 if (mService != null) {
3586 try {
3587 return mService.getApplicationRestrictions(admin, packageName);
3588 } catch (RemoteException e) {
3589 Log.w(TAG, "Failed talking with device policy service", e);
3590 }
3591 }
3592 return null;
3593 }
Amith Yamasanibe465322014-04-24 13:45:17 -07003594
3595 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003596 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07003597 * <p>
3598 * The calling device admin must be a profile or device owner; if it is not,
3599 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003600 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003601 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3602 * with.
3603 * @param key The key of the restriction. See the constants in
3604 * {@link android.os.UserManager} for the list of keys.
3605 */
Robin Lee25e26452015-06-02 09:56:29 -07003606 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07003607 if (mService != null) {
3608 try {
3609 mService.setUserRestriction(admin, key, true);
3610 } catch (RemoteException e) {
3611 Log.w(TAG, "Failed talking with device policy service", e);
3612 }
3613 }
3614 }
3615
3616 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003617 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07003618 * <p>
3619 * The calling device admin must be a profile or device owner; if it is not,
3620 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003621 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003622 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3623 * with.
3624 * @param key The key of the restriction. See the constants in
3625 * {@link android.os.UserManager} for the list of keys.
3626 */
Robin Lee25e26452015-06-02 09:56:29 -07003627 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07003628 if (mService != null) {
3629 try {
3630 mService.setUserRestriction(admin, key, false);
3631 } catch (RemoteException e) {
3632 Log.w(TAG, "Failed talking with device policy service", e);
3633 }
3634 }
3635 }
Adam Connors010cfd42014-04-16 12:48:13 +01003636
3637 /**
Makoto Onuki3a3092f2015-10-30 11:07:51 -07003638 * Called by a profile or device owner to get user restrictions set with
3639 * {@link #addUserRestriction(ComponentName, String)}.
3640 * <p>
3641 * The target user may have more restrictions set by the system or other device owner / profile
3642 * owner. To get all the user restrictions currently set, use
3643 * {@link UserManager#getUserRestrictions()}.
3644 *
3645 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3646 */
3647 public Bundle getUserRestrictions(@NonNull ComponentName admin) {
3648 Bundle ret = null;
3649 if (mService != null) {
3650 try {
3651 ret = mService.getUserRestrictions(admin);
3652 } catch (RemoteException e) {
3653 Log.w(TAG, "Failed talking with device policy service", e);
3654 }
3655 }
3656 return ret == null ? new Bundle() : ret;
3657 }
3658
3659 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003660 * Called by profile or device owners to hide or unhide packages. When a package is hidden it
Julia Reynolds966881e2014-05-14 12:23:08 -04003661 * is unavailable for use, but the data and actual package file remain.
3662 *
3663 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003664 * @param packageName The name of the package to hide or unhide.
3665 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
3666 * unhidden.
3667 * @return boolean Whether the hidden setting of the package was successfully updated.
Julia Reynolds966881e2014-05-14 12:23:08 -04003668 */
Robin Lee25e26452015-06-02 09:56:29 -07003669 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003670 boolean hidden) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003671 if (mService != null) {
3672 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003673 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04003674 } catch (RemoteException e) {
3675 Log.w(TAG, "Failed talking with device policy service", e);
3676 }
3677 }
3678 return false;
3679 }
3680
3681 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003682 * Called by profile or device owners to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04003683 *
3684 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003685 * @param packageName The name of the package to retrieve the hidden status of.
3686 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Julia Reynolds966881e2014-05-14 12:23:08 -04003687 */
Robin Lee25e26452015-06-02 09:56:29 -07003688 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003689 if (mService != null) {
3690 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003691 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04003692 } catch (RemoteException e) {
3693 Log.w(TAG, "Failed talking with device policy service", e);
3694 }
3695 }
3696 return false;
3697 }
3698
3699 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003700 * Called by profile or device owners to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003701 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003702 *
3703 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3704 * @param packageName The package to be re-enabled in the current profile.
3705 */
Robin Lee25e26452015-06-02 09:56:29 -07003706 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Adam Connors655be2a2014-07-14 09:01:25 +00003707 if (mService != null) {
3708 try {
3709 mService.enableSystemApp(admin, packageName);
3710 } catch (RemoteException e) {
3711 Log.w(TAG, "Failed to install package: " + packageName);
3712 }
3713 }
3714 }
3715
3716 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003717 * Called by profile or device owners to re-enable system apps by intent that were disabled
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003718 * by default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003719 *
3720 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3721 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
3722 * intent will be re-enabled in the current profile.
3723 * @return int The number of activities that matched the intent and were installed.
3724 */
Robin Lee25e26452015-06-02 09:56:29 -07003725 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Adam Connors655be2a2014-07-14 09:01:25 +00003726 if (mService != null) {
3727 try {
3728 return mService.enableSystemAppWithIntent(admin, intent);
3729 } catch (RemoteException e) {
3730 Log.w(TAG, "Failed to install packages matching filter: " + intent);
3731 }
3732 }
3733 return 0;
3734 }
3735
3736 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00003737 * Called by a device owner or profile owner to disable account management for a specific type
3738 * of account.
Sander Alewijnse650c3342014-05-08 18:00:50 +01003739 *
Sander Alewijnse112e0532014-10-29 13:28:49 +00003740 * <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 +01003741 * security exception will be thrown.
3742 *
3743 * <p>When account management is disabled for an account type, adding or removing an account
3744 * of that type will not be possible.
3745 *
3746 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3747 * @param accountType For which account management is disabled or enabled.
3748 * @param disabled The boolean indicating that account management will be disabled (true) or
3749 * enabled (false).
3750 */
Robin Lee25e26452015-06-02 09:56:29 -07003751 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01003752 boolean disabled) {
3753 if (mService != null) {
3754 try {
3755 mService.setAccountManagementDisabled(admin, accountType, disabled);
3756 } catch (RemoteException e) {
3757 Log.w(TAG, "Failed talking with device policy service", e);
3758 }
3759 }
3760 }
3761
3762 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003763 * Gets the array of accounts for which account management is disabled by the profile owner.
3764 *
3765 * <p> Account management can be disabled/enabled by calling
3766 * {@link #setAccountManagementDisabled}.
3767 *
3768 * @return a list of account types for which account management has been disabled.
3769 *
3770 * @see #setAccountManagementDisabled
3771 */
3772 public String[] getAccountTypesWithManagementDisabled() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003773 return getAccountTypesWithManagementDisabledAsUser(myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003774 }
3775
3776 /**
3777 * @see #getAccountTypesWithManagementDisabled()
3778 * @hide
3779 */
3780 public String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003781 if (mService != null) {
3782 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003783 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003784 } catch (RemoteException e) {
3785 Log.w(TAG, "Failed talking with device policy service", e);
3786 }
3787 }
3788
3789 return null;
3790 }
justinzhang511e0d82014-03-24 16:09:24 -04003791
3792 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003793 * Sets which packages may enter lock task mode.
3794 *
3795 * <p>Any packages that shares uid with an allowed package will also be allowed
3796 * to activate lock task.
justinzhang511e0d82014-03-24 16:09:24 -04003797 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07003798 * From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task
Benjamin Franz469dd582015-06-09 14:24:36 +01003799 * package list results in locked tasks belonging to those packages to be finished.
3800 *
Jason Monkc5185f22014-06-24 11:12:42 -04003801 * This function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04003802 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04003803 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jason Monkd7b86212014-06-16 13:15:38 -04003804 *
3805 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00003806 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
3807 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04003808 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04003809 */
Robin Lee25e26452015-06-02 09:56:29 -07003810 public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04003811 throws SecurityException {
justinzhang511e0d82014-03-24 16:09:24 -04003812 if (mService != null) {
3813 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003814 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04003815 } catch (RemoteException e) {
3816 Log.w(TAG, "Failed talking with device policy service", e);
3817 }
3818 }
3819 }
3820
3821 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003822 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04003823 *
3824 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04003825 * @hide
3826 */
Robin Lee25e26452015-06-02 09:56:29 -07003827 public String[] getLockTaskPackages(@NonNull ComponentName admin) {
justinzhang511e0d82014-03-24 16:09:24 -04003828 if (mService != null) {
3829 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003830 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04003831 } catch (RemoteException e) {
3832 Log.w(TAG, "Failed talking with device policy service", e);
3833 }
3834 }
3835 return null;
3836 }
3837
3838 /**
3839 * This function lets the caller know whether the given component is allowed to start the
3840 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04003841 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04003842 */
Jason Monkd7b86212014-06-16 13:15:38 -04003843 public boolean isLockTaskPermitted(String pkg) {
justinzhang511e0d82014-03-24 16:09:24 -04003844 if (mService != null) {
3845 try {
Jason Monkd7b86212014-06-16 13:15:38 -04003846 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04003847 } catch (RemoteException e) {
3848 Log.w(TAG, "Failed talking with device policy service", e);
3849 }
3850 }
3851 return false;
3852 }
Julia Reynoldsda551652014-05-14 17:15:16 -04003853
3854 /**
3855 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
3856 * 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 -04003857 * <p>The settings that can be updated with this method are:
3858 * <ul>
3859 * <li>{@link Settings.Global#ADB_ENABLED}</li>
3860 * <li>{@link Settings.Global#AUTO_TIME}</li>
3861 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003862 * <li>{@link Settings.Global#DATA_ROAMING}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003863 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003864 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Benjamin Franz68cc4202015-03-11 15:43:06 +00003865 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN}
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07003866 * This setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards
Esteban Talavera656fa7f2015-06-29 17:41:39 +01003867 * and can only be set if {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
Zoltan Szatmary-Ban4045d242015-05-27 12:42:39 +01003868 * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07003869 * This setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards.
Zoltan Szatmary-Ban3c430952015-07-03 14:04:09 +01003870 * </li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003871 * </ul>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01003872 * <p>Changing the following settings has no effect as of
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07003873 * {@link android.os.Build.VERSION_CODES#M}:
Esteban Talavera656fa7f2015-06-29 17:41:39 +01003874 * <ul>
3875 * <li>{@link Settings.Global#BLUETOOTH_ON}.
3876 * Use {@link android.bluetooth.BluetoothAdapter#enable()} and
3877 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
3878 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
3879 * <li>{@link Settings.Global#MODE_RINGER}.
3880 * Use {@link android.media.AudioManager#setRingerMode(int)} instead.</li>
3881 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
3882 * <li>{@link Settings.Global#WIFI_ON}.
3883 * Use {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
3884 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04003885 *
3886 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3887 * @param setting The name of the setting to update.
3888 * @param value The value to update the setting to.
3889 */
Robin Lee25e26452015-06-02 09:56:29 -07003890 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04003891 if (mService != null) {
3892 try {
3893 mService.setGlobalSetting(admin, setting, value);
3894 } catch (RemoteException e) {
3895 Log.w(TAG, "Failed talking with device policy service", e);
3896 }
3897 }
3898 }
3899
3900 /**
3901 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
3902 * that the value of the setting is in the correct form for the setting type should be performed
3903 * by the caller.
Julia Reynolds82735bc2014-09-04 16:43:30 -04003904 * <p>The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003905 * <ul>
3906 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07003907 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003908 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
3909 * </ul>
Julia Reynolds82735bc2014-09-04 16:43:30 -04003910 * <p>A device owner can additionally update the following settings:
3911 * <ul>
3912 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
3913 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04003914 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3915 * @param setting The name of the setting to update.
3916 * @param value The value to update the setting to.
3917 */
Robin Lee25e26452015-06-02 09:56:29 -07003918 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04003919 if (mService != null) {
3920 try {
3921 mService.setSecureSetting(admin, setting, value);
3922 } catch (RemoteException e) {
3923 Log.w(TAG, "Failed talking with device policy service", e);
3924 }
3925 }
3926 }
3927
Amith Yamasanif20d6402014-05-24 15:34:37 -07003928 /**
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003929 * Designates a specific service component as the provider for
Amith Yamasanif20d6402014-05-24 15:34:37 -07003930 * making permission requests of a local or remote administrator of the user.
3931 * <p/>
3932 * Only a profile owner can designate the restrictions provider.
3933 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003934 * @param provider The component name of the service that implements
Amith Yamasanid1d7c022014-08-19 17:03:41 -07003935 * {@link RestrictionsReceiver}. If this param is null,
Amith Yamasanif20d6402014-05-24 15:34:37 -07003936 * it removes the restrictions provider previously assigned.
3937 */
Robin Lee25e26452015-06-02 09:56:29 -07003938 public void setRestrictionsProvider(@NonNull ComponentName admin,
3939 @Nullable ComponentName provider) {
Amith Yamasanif20d6402014-05-24 15:34:37 -07003940 if (mService != null) {
3941 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003942 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07003943 } catch (RemoteException re) {
3944 Log.w(TAG, "Failed to set permission provider on device policy service");
3945 }
3946 }
3947 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04003948
3949 /**
3950 * Called by profile or device owners to set the master volume mute on or off.
3951 *
3952 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3953 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
3954 */
Robin Lee25e26452015-06-02 09:56:29 -07003955 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04003956 if (mService != null) {
3957 try {
3958 mService.setMasterVolumeMuted(admin, on);
3959 } catch (RemoteException re) {
3960 Log.w(TAG, "Failed to setMasterMute on device policy service");
3961 }
3962 }
3963 }
3964
3965 /**
3966 * Called by profile or device owners to check whether the master volume mute is on or off.
3967 *
3968 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3969 * @return {@code true} if master volume is muted, {@code false} if it's not.
3970 */
Robin Lee25e26452015-06-02 09:56:29 -07003971 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04003972 if (mService != null) {
3973 try {
3974 return mService.isMasterVolumeMuted(admin);
3975 } catch (RemoteException re) {
3976 Log.w(TAG, "Failed to get isMasterMute on device policy service");
3977 }
3978 }
3979 return false;
3980 }
Kenny Guyc13053b2014-05-29 14:17:17 +01003981
3982 /**
3983 * Called by profile or device owners to change whether a user can uninstall
3984 * a package.
3985 *
3986 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3987 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003988 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Kenny Guyc13053b2014-05-29 14:17:17 +01003989 */
Robin Lee25e26452015-06-02 09:56:29 -07003990 public void setUninstallBlocked(@NonNull ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003991 boolean uninstallBlocked) {
Kenny Guyc13053b2014-05-29 14:17:17 +01003992 if (mService != null) {
3993 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003994 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01003995 } catch (RemoteException re) {
3996 Log.w(TAG, "Failed to call block uninstall on device policy service");
3997 }
3998 }
3999 }
4000
4001 /**
Rubin Xua97855b2014-11-07 05:41:00 +00004002 * Check whether the current user has been blocked by device policy from uninstalling a package.
4003 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00004004 * <p>
4005 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Robin Lee25e26452015-06-02 09:56:29 -07004006 * behavior of this API is changed such that passing {@code null} as the {@code admin}
Rubin Xue1e6faa2015-03-10 10:51:59 +00004007 * parameter will return if any admin has blocked the uninstallation. Before L MR1, passing
Robin Lee25e26452015-06-02 09:56:29 -07004008 * {@code null} will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01004009 *
Robin Lee25e26452015-06-02 09:56:29 -07004010 * @param admin The name of the admin component whose blocking policy will be checked, or
4011 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01004012 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00004013 * @return true if uninstallation is blocked.
Kenny Guyc13053b2014-05-29 14:17:17 +01004014 */
Robin Lee25e26452015-06-02 09:56:29 -07004015 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Kenny Guyc13053b2014-05-29 14:17:17 +01004016 if (mService != null) {
4017 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01004018 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01004019 } catch (RemoteException re) {
4020 Log.w(TAG, "Failed to call block uninstall on device policy service");
4021 }
4022 }
4023 return false;
4024 }
Svetoslav976e8bd2014-07-16 15:12:03 -07004025
4026 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004027 * Called by the profile owner of a managed profile to enable widget providers from a
4028 * given package to be available in the parent profile. As a result the user will be able to
Svetoslav976e8bd2014-07-16 15:12:03 -07004029 * add widgets from the white-listed package running under the profile to a widget
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004030 * host which runs under the parent profile, for example the home screen. Note that
Svetoslav976e8bd2014-07-16 15:12:03 -07004031 * a package may have zero or more provider components, where each component
4032 * provides a different widget type.
4033 * <p>
4034 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07004035 *
4036 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4037 * @param packageName The package from which widget providers are white-listed.
4038 * @return Whether the package was added.
4039 *
4040 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4041 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4042 */
Robin Lee25e26452015-06-02 09:56:29 -07004043 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004044 if (mService != null) {
4045 try {
4046 return mService.addCrossProfileWidgetProvider(admin, packageName);
4047 } catch (RemoteException re) {
4048 Log.w(TAG, "Error calling addCrossProfileWidgetProvider", re);
4049 }
4050 }
4051 return false;
4052 }
4053
4054 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004055 * Called by the profile owner of a managed profile to disable widget providers from a given
4056 * package to be available in the parent profile. For this method to take effect the
Svetoslav976e8bd2014-07-16 15:12:03 -07004057 * package should have been added via {@link #addCrossProfileWidgetProvider(
4058 * android.content.ComponentName, String)}.
4059 * <p>
4060 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07004061 *
4062 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4063 * @param packageName The package from which widget providers are no longer
4064 * white-listed.
4065 * @return Whether the package was removed.
4066 *
4067 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
4068 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4069 */
Robin Lee25e26452015-06-02 09:56:29 -07004070 public boolean removeCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004071 if (mService != null) {
4072 try {
4073 return mService.removeCrossProfileWidgetProvider(admin, packageName);
4074 } catch (RemoteException re) {
4075 Log.w(TAG, "Error calling removeCrossProfileWidgetProvider", re);
4076 }
4077 }
4078 return false;
4079 }
4080
4081 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004082 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07004083 * available in the parent profile.
4084 *
4085 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4086 * @return The white-listed package list.
4087 *
4088 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
4089 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4090 */
Robin Lee25e26452015-06-02 09:56:29 -07004091 public List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004092 if (mService != null) {
4093 try {
4094 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
4095 if (providers != null) {
4096 return providers;
4097 }
4098 } catch (RemoteException re) {
4099 Log.w(TAG, "Error calling getCrossProfileWidgetProviders", re);
4100 }
4101 }
4102 return Collections.emptyList();
4103 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004104
4105 /**
4106 * Called by profile or device owners to set the current user's photo.
4107 *
4108 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4109 * @param icon the bitmap to set as the photo.
4110 */
Robin Lee25e26452015-06-02 09:56:29 -07004111 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004112 try {
4113 mService.setUserIcon(admin, icon);
4114 } catch (RemoteException re) {
4115 Log.w(TAG, "Could not set the user icon ", re);
4116 }
4117 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04004118
4119 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01004120 * Called by device owners to set a local system update policy. When a new policy is set,
4121 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004122 *
Robin Lee25e26452015-06-02 09:56:29 -07004123 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
4124 * components in the device owner package can set system update policies and the
4125 * most recent policy takes
Rubin Xu5faad8e2015-04-20 17:43:48 +01004126 * effect.
Robin Lee25e26452015-06-02 09:56:29 -07004127 * @param policy the new policy, or {@code null} to clear the current policy.
Rubin Xu5faad8e2015-04-20 17:43:48 +01004128 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00004129 */
Robin Lee25e26452015-06-02 09:56:29 -07004130 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Rubin Xu8027a4f2015-03-10 17:52:37 +00004131 if (mService != null) {
4132 try {
Robin Lee25e26452015-06-02 09:56:29 -07004133 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004134 } catch (RemoteException re) {
Rubin Xu5faad8e2015-04-20 17:43:48 +01004135 Log.w(TAG, "Error calling setSystemUpdatePolicy", re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004136 }
4137 }
4138 }
4139
4140 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01004141 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004142 *
Robin Lee25e26452015-06-02 09:56:29 -07004143 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004144 */
Rubin Xu5faad8e2015-04-20 17:43:48 +01004145 public SystemUpdatePolicy getSystemUpdatePolicy() {
Rubin Xu8027a4f2015-03-10 17:52:37 +00004146 if (mService != null) {
4147 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01004148 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00004149 } catch (RemoteException re) {
Rubin Xu5faad8e2015-04-20 17:43:48 +01004150 Log.w(TAG, "Error calling getSystemUpdatePolicy", re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004151 }
4152 }
4153 return null;
4154 }
Benjamin Franze36087e2015-04-07 16:40:34 +01004155
4156 /**
4157 * Called by a device owner to disable the keyguard altogether.
4158 *
4159 * <p>Setting the keyguard to disabled has the same effect as choosing "None" as the screen
4160 * lock type. However, this call has no effect if a password, pin or pattern is currently set.
4161 * If a password, pin or pattern is set after the keyguard was disabled, the keyguard stops
4162 * being disabled.
4163 *
4164 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01004165 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01004166 *
4167 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Benjamin Franzbece8062015-05-06 12:14:31 +01004168 * place. {@code true} otherwise.
Benjamin Franze36087e2015-04-07 16:40:34 +01004169 */
Robin Lee25e26452015-06-02 09:56:29 -07004170 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franze36087e2015-04-07 16:40:34 +01004171 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01004172 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01004173 } catch (RemoteException re) {
4174 Log.w(TAG, "Failed talking with device policy service", re);
4175 return false;
4176 }
4177 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00004178
4179 /**
Benjamin Franzbece8062015-05-06 12:14:31 +01004180 * Called by device owner to disable the status bar. Disabling the status bar blocks
4181 * notifications, quick settings and other screen overlays that allow escaping from
Benjamin Franzea2ec972015-03-16 17:18:09 +00004182 * a single use device.
4183 *
4184 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01004185 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
4186 *
4187 * @return {@code false} if attempting to disable the status bar failed.
4188 * {@code true} otherwise.
Benjamin Franzea2ec972015-03-16 17:18:09 +00004189 */
Robin Lee25e26452015-06-02 09:56:29 -07004190 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzea2ec972015-03-16 17:18:09 +00004191 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01004192 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00004193 } catch (RemoteException re) {
4194 Log.w(TAG, "Failed talking with device policy service", re);
Benjamin Franzbece8062015-05-06 12:14:31 +01004195 return false;
Benjamin Franzea2ec972015-03-16 17:18:09 +00004196 }
4197 }
Rubin Xudc105cc2015-04-14 23:38:01 +01004198
4199 /**
4200 * Callable by the system update service to notify device owners about pending updates.
4201 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
4202 * permission.
4203 *
4204 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating
4205 * when the current pending update was first available. -1 if no update is available.
4206 * @hide
4207 */
4208 @SystemApi
4209 public void notifyPendingSystemUpdate(long updateReceivedTime) {
4210 if (mService != null) {
4211 try {
4212 mService.notifyPendingSystemUpdate(updateReceivedTime);
4213 } catch (RemoteException re) {
4214 Log.w(TAG, "Could not notify device owner about pending system update", re);
4215 }
4216 }
4217 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04004218
4219 /**
Amith Yamasanid49489b2015-04-28 14:00:26 -07004220 * Called by profile or device owners to set the default response for future runtime permission
4221 * requests by applications. The policy can allow for normal operation which prompts the
4222 * user to grant a permission, or can allow automatic granting or denying of runtime
4223 * permission requests by an application. This also applies to new permissions declared by app
Benjamin Franz45dd6662015-07-08 14:24:14 +01004224 * updates. When a permission is denied or granted this way, the effect is equivalent to setting
4225 * the permission grant state via {@link #setPermissionGrantState}.
4226 *
4227 * <p/>As this policy only acts on runtime permission requests, it only applies to applications
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004228 * built with a {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Benjamin Franz45dd6662015-07-08 14:24:14 +01004229 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07004230 * @param admin Which profile or device owner this request is associated with.
4231 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
4232 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
Benjamin Franz45dd6662015-07-08 14:24:14 +01004233 *
4234 * @see #setPermissionGrantState
Amith Yamasanid49489b2015-04-28 14:00:26 -07004235 */
Robin Lee25e26452015-06-02 09:56:29 -07004236 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004237 try {
4238 mService.setPermissionPolicy(admin, policy);
4239 } catch (RemoteException re) {
4240 Log.w(TAG, "Failed talking with device policy service", re);
4241 }
4242 }
4243
4244 /**
4245 * Returns the current runtime permission policy set by the device or profile owner. The
4246 * default is {@link #PERMISSION_POLICY_PROMPT}.
4247 * @param admin Which profile or device owner this request is associated with.
4248 * @return the current policy for future permission requests.
4249 */
Esteban Talavera28b95702015-06-24 15:23:42 +01004250 public int getPermissionPolicy(ComponentName admin) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004251 try {
4252 return mService.getPermissionPolicy(admin);
4253 } catch (RemoteException re) {
4254 return PERMISSION_POLICY_PROMPT;
4255 }
4256 }
4257
4258 /**
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004259 * Sets the grant state of a runtime permission for a specific application. The state
4260 * can be {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it
4261 * through the UI, {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission
4262 * is denied and the user cannot manage it through the UI, and {@link
4263 * #PERMISSION_GRANT_STATE_GRANTED granted} in which the permission is granted and the
4264 * user cannot manage it through the UI. This might affect all permissions in a
4265 * group that the runtime permission belongs to. This method can only be called
4266 * by a profile or device owner.
4267 *
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07004268 * <p/>Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not
4269 * revoke the permission. It retains the previous grant, if any.
4270 *
4271 * <p/>Permissions can be granted or revoked only for applications built with a
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004272 * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07004273 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07004274 * @param admin Which profile or device owner this request is associated with.
4275 * @param packageName The application to grant or revoke a permission to.
4276 * @param permission The permission to grant or revoke.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004277 * @param grantState The permission grant state which is one of {@link
4278 * #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
4279 * {@link #PERMISSION_GRANT_STATE_GRANTED},
4280 * @return whether the permission was successfully granted or revoked.
4281 *
4282 * @see #PERMISSION_GRANT_STATE_DENIED
4283 * @see #PERMISSION_GRANT_STATE_DEFAULT
4284 * @see #PERMISSION_GRANT_STATE_GRANTED
Amith Yamasanid49489b2015-04-28 14:00:26 -07004285 */
Robin Lee25e26452015-06-02 09:56:29 -07004286 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004287 String permission, int grantState) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004288 try {
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004289 return mService.setPermissionGrantState(admin, packageName, permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07004290 } catch (RemoteException re) {
4291 Log.w(TAG, "Failed talking with device policy service", re);
4292 return false;
4293 }
4294 }
Amith Yamasani184b3752015-05-22 13:00:51 -07004295
4296 /**
4297 * Returns the current grant state of a runtime permission for a specific application.
4298 *
4299 * @param admin Which profile or device owner this request is associated with.
4300 * @param packageName The application to check the grant state for.
4301 * @param permission The permission to check for.
4302 * @return the current grant state specified by device policy. If the profile or device owner
4303 * has not set a grant state, the return value is {@link #PERMISSION_GRANT_STATE_DEFAULT}.
4304 * This does not indicate whether or not the permission is currently granted for the package.
4305 *
4306 * <p/>If a grant state was set by the profile or device owner, then the return value will
4307 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or {@link #PERMISSION_GRANT_STATE_GRANTED},
4308 * which indicates if the permission is currently denied or granted.
4309 *
4310 * @see #setPermissionGrantState(ComponentName, String, String, int)
4311 * @see PackageManager#checkPermission(String, String)
4312 */
Robin Lee25e26452015-06-02 09:56:29 -07004313 public int getPermissionGrantState(@NonNull ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07004314 String permission) {
4315 try {
4316 return mService.getPermissionGrantState(admin, packageName, permission);
4317 } catch (RemoteException re) {
4318 Log.w(TAG, "Failed talking with device policy service", re);
4319 return PERMISSION_GRANT_STATE_DEFAULT;
4320 }
4321 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08004322}