blob: 6a3f8e61e45856a77913f2d4669e3472111c8db7 [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 *
Makoto Onuki759a7632015-10-28 16:43:10 -07002274 * <p>If the caller is device owner, then the restriction will be applied to all users.
2275 *
Ben Komalo2447edd2011-05-09 16:05:33 -07002276 * <p>The calling device admin must have requested
2277 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
2278 * this method; if it has not, a security exception will be thrown.
2279 *
2280 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2281 * @param disabled Whether or not the camera should be disabled.
2282 */
Robin Lee25e26452015-06-02 09:56:29 -07002283 public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002284 if (mService != null) {
2285 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002286 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07002287 } catch (RemoteException e) {
2288 Log.w(TAG, "Failed talking with device policy service", e);
2289 }
2290 }
2291 }
2292
2293 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07002294 * Determine whether or not the device's cameras have been disabled for this user,
2295 * either by the current admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002296 * @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 -07002297 * have disabled the camera
2298 */
Robin Lee25e26452015-06-02 09:56:29 -07002299 public boolean getCameraDisabled(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002300 return getCameraDisabled(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002301 }
2302
2303 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002304 public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002305 if (mService != null) {
2306 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002307 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07002308 } catch (RemoteException e) {
2309 Log.w(TAG, "Failed talking with device policy service", e);
2310 }
2311 }
2312 return false;
2313 }
2314
2315 /**
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07002316 * Determine whether or not creating a guest user has been disabled for the device
2317 *
2318 * @hide
2319 */
2320 public boolean getGuestUserDisabled(@Nullable ComponentName admin) {
2321 // Currently guest users can always be created if multi-user is enabled
2322 // TODO introduce a policy for guest user creation
2323 return false;
2324 }
2325
2326 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01002327 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
2328 * screen capture also prevents the content from being shown on display devices that do not have
2329 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
2330 * secure surfaces and secure displays.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002331 *
2332 * <p>The calling device admin must be a device or profile owner. If it is not, a
2333 * security exception will be thrown.
2334 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002335 * <p>From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also
Benjamin Franzc200f442015-06-25 18:20:04 +01002336 * blocks assist requests for all activities of the relevant user.
2337 *
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002338 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002339 * @param disabled Whether screen capture is disabled or not.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002340 */
Robin Lee25e26452015-06-02 09:56:29 -07002341 public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002342 if (mService != null) {
2343 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002344 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002345 } catch (RemoteException e) {
2346 Log.w(TAG, "Failed talking with device policy service", e);
2347 }
2348 }
2349 }
2350
2351 /**
2352 * Determine whether or not screen capture has been disabled by the current
2353 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002354 * @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 +01002355 * have disabled screen capture.
2356 */
Robin Lee25e26452015-06-02 09:56:29 -07002357 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002358 return getScreenCaptureDisabled(admin, myUserId());
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002359 }
2360
2361 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002362 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002363 if (mService != null) {
2364 try {
2365 return mService.getScreenCaptureDisabled(admin, userHandle);
2366 } catch (RemoteException e) {
2367 Log.w(TAG, "Failed talking with device policy service", e);
2368 }
2369 }
2370 return false;
2371 }
2372
2373 /**
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002374 * Called by a device owner to set whether auto time is required. If auto time is
2375 * required the user cannot set the date and time, but has to use network date and time.
2376 *
2377 * <p>Note: if auto time is required the user can still manually set the time zone.
2378 *
2379 * <p>The calling device admin must be a device owner. If it is not, a security exception will
2380 * be thrown.
2381 *
2382 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2383 * @param required Whether auto time is set required or not.
2384 */
Robin Lee25e26452015-06-02 09:56:29 -07002385 public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) {
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002386 if (mService != null) {
2387 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002388 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002389 } catch (RemoteException e) {
2390 Log.w(TAG, "Failed talking with device policy service", e);
2391 }
2392 }
2393 }
2394
2395 /**
2396 * @return true if auto time is required.
2397 */
2398 public boolean getAutoTimeRequired() {
2399 if (mService != null) {
2400 try {
2401 return mService.getAutoTimeRequired();
2402 } catch (RemoteException e) {
2403 Log.w(TAG, "Failed talking with device policy service", e);
2404 }
2405 }
2406 return false;
2407 }
2408
2409 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002410 * Called by an application that is administering the device to disable keyguard customizations,
2411 * such as widgets. After setting this, keyguard features will be disabled according to the
2412 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002413 *
2414 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07002415 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07002416 * this method; if it has not, a security exception will be thrown.
2417 *
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002418 * <p>Calling this from a managed profile before version
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002419 * {@link android.os.Build.VERSION_CODES#M} will throw a security exception.
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002420 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002421 * <p>From version {@link android.os.Build.VERSION_CODES#M} a profile owner can set:
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002422 * <ul>
2423 * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, {@link #KEYGUARD_DISABLE_FINGERPRINT}
2424 * these will affect the profile's parent user.
2425 * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} this will affect notifications
2426 * generated by applications in the managed profile.
2427 * </ul>
2428 * <p>Requests to disable other features on a managed profile will be ignored. The admin
2429 * can check which features have been disabled by calling
2430 * {@link #getKeyguardDisabledFeatures(ComponentName)}
Amith Yamasani242f4b12014-10-14 16:06:13 -07002431 *
Jim Millerb8ec4702012-08-31 17:19:10 -07002432 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07002433 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
2434 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
Jim Miller50e62182014-04-23 17:25:00 -07002435 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002436 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FINGERPRINT},
2437 * {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07002438 */
Robin Lee25e26452015-06-02 09:56:29 -07002439 public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002440 if (mService != null) {
2441 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002442 mService.setKeyguardDisabledFeatures(admin, which);
Jim Millerb8ec4702012-08-31 17:19:10 -07002443 } catch (RemoteException e) {
2444 Log.w(TAG, "Failed talking with device policy service", e);
2445 }
2446 }
2447 }
2448
2449 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002450 * Determine whether or not features have been disabled in keyguard either by the current
Jim Millerb8ec4702012-08-31 17:19:10 -07002451 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002452 * @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 -07002453 * have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07002454 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
2455 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002456 */
Robin Lee25e26452015-06-02 09:56:29 -07002457 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002458 return getKeyguardDisabledFeatures(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002459 }
2460
2461 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002462 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002463 if (mService != null) {
2464 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07002465 return mService.getKeyguardDisabledFeatures(admin, userHandle);
Jim Millerb8ec4702012-08-31 17:19:10 -07002466 } catch (RemoteException e) {
2467 Log.w(TAG, "Failed talking with device policy service", e);
2468 }
2469 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07002470 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07002471 }
2472
2473 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08002474 * @hide
2475 */
Robin Lee25e26452015-06-02 09:56:29 -07002476 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
2477 int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002478 if (mService != null) {
2479 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01002480 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002481 } catch (RemoteException e) {
2482 Log.w(TAG, "Failed talking with device policy service", e);
2483 }
2484 }
2485 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002486
Dianne Hackbornd6847842010-01-12 18:14:19 -08002487 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01002488 * @hide
2489 */
Robin Lee25e26452015-06-02 09:56:29 -07002490 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002491 setActiveAdmin(policyReceiver, refreshing, myUserId());
Jessica Hummel6d36b602014-04-04 12:42:17 +01002492 }
2493
2494 /**
Robin Lee25e26452015-06-02 09:56:29 -07002495 * Returns the DeviceAdminInfo as defined by the administrator's package info &amp; meta-data
Dianne Hackbornd6847842010-01-12 18:14:19 -08002496 * @hide
2497 */
Robin Lee25e26452015-06-02 09:56:29 -07002498 public DeviceAdminInfo getAdminInfo(@NonNull ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002499 ActivityInfo ai;
2500 try {
2501 ai = mContext.getPackageManager().getReceiverInfo(cn,
2502 PackageManager.GET_META_DATA);
2503 } catch (PackageManager.NameNotFoundException e) {
2504 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
2505 return null;
2506 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002507
Dianne Hackbornd6847842010-01-12 18:14:19 -08002508 ResolveInfo ri = new ResolveInfo();
2509 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002510
Dianne Hackbornd6847842010-01-12 18:14:19 -08002511 try {
2512 return new DeviceAdminInfo(mContext, ri);
2513 } catch (XmlPullParserException e) {
2514 Log.w(TAG, "Unable to parse device policy " + cn, e);
2515 return null;
2516 } catch (IOException e) {
2517 Log.w(TAG, "Unable to parse device policy " + cn, e);
2518 return null;
2519 }
2520 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002521
Dianne Hackbornd6847842010-01-12 18:14:19 -08002522 /**
2523 * @hide
2524 */
Robin Lee25e26452015-06-02 09:56:29 -07002525 public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002526 if (mService != null) {
2527 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002528 mService.getRemoveWarning(admin, result, myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002529 } catch (RemoteException e) {
2530 Log.w(TAG, "Failed talking with device policy service", e);
2531 }
2532 }
2533 }
2534
2535 /**
2536 * @hide
2537 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002538 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002539 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002540 if (mService != null) {
2541 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002542 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002543 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002544 } catch (RemoteException e) {
2545 Log.w(TAG, "Failed talking with device policy service", e);
2546 }
2547 }
2548 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002549
Dianne Hackbornd6847842010-01-12 18:14:19 -08002550 /**
2551 * @hide
2552 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002553 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002554 if (mService != null) {
2555 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002556 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002557 } catch (RemoteException e) {
2558 Log.w(TAG, "Failed talking with device policy service", e);
2559 }
2560 }
2561 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002562
Dianne Hackbornd6847842010-01-12 18:14:19 -08002563 /**
2564 * @hide
2565 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002566 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002567 if (mService != null) {
2568 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002569 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002570 } catch (RemoteException e) {
2571 Log.w(TAG, "Failed talking with device policy service", e);
2572 }
2573 }
2574 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07002575
2576 /**
2577 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00002578 * Sets the given package as the device owner.
Makoto Onukia52562c2015-10-01 16:12:31 -07002579 * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name.
2580 * @param who the component name to be registered as device owner.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002581 * @return whether the package was successfully registered as the device owner.
2582 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00002583 * @throws IllegalStateException If the preconditions mentioned are not met.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002584 */
Makoto Onukia52562c2015-10-01 16:12:31 -07002585 public boolean setDeviceOwner(ComponentName who) {
2586 return setDeviceOwner(who, null);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002587 }
2588
2589 /**
2590 * @hide
Makoto Onuki58b684f2015-09-04 10:48:16 -07002591 */
Makoto Onukia52562c2015-10-01 16:12:31 -07002592 public boolean setDeviceOwner(ComponentName who, int userId) {
2593 return setDeviceOwner(who, null, userId);
Makoto Onuki58b684f2015-09-04 10:48:16 -07002594 }
2595
2596 /**
2597 * @hide
2598 */
Makoto Onukia52562c2015-10-01 16:12:31 -07002599 public boolean setDeviceOwner(ComponentName who, String ownerName) {
2600 return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM);
Makoto Onuki58b684f2015-09-04 10:48:16 -07002601 }
2602
2603 /**
2604 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00002605 * Sets the given package as the device owner. The package must already be installed. There
2606 * must not already be a device owner.
2607 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
2608 * this method.
2609 * Calling this after the setup phase of the primary user has completed is allowed only if
2610 * the caller is the shell uid, and there are no additional users and no accounts.
Makoto Onukia52562c2015-10-01 16:12:31 -07002611 * @param who the component name to be registered as device owner.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002612 * @param ownerName the human readable name of the institution that owns this device.
Makoto Onuki58b684f2015-09-04 10:48:16 -07002613 * @param userId ID of the user on which the device owner runs.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002614 * @return whether the package was successfully registered as the device owner.
2615 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00002616 * @throws IllegalStateException If the preconditions mentioned are not met.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002617 */
Makoto Onukia52562c2015-10-01 16:12:31 -07002618 public boolean setDeviceOwner(ComponentName who, String ownerName, int userId)
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002619 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002620 if (mService != null) {
2621 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07002622 return mService.setDeviceOwner(who, ownerName, userId);
Amith Yamasani71e6c692013-03-24 17:39:28 -07002623 } catch (RemoteException re) {
2624 Log.w(TAG, "Failed to set device owner");
2625 }
2626 }
2627 return false;
2628 }
2629
2630 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002631 * Used to determine if a particular package has been registered as a Device Owner app.
2632 * A device owner app is a special device admin that cannot be deactivated by the user, once
Robin Lee25e26452015-06-02 09:56:29 -07002633 * activated as a device admin. It also cannot be uninstalled. To check whether a particular
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002634 * package is currently registered as the device owner app, pass in the package name from
2635 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
Robin Lee25e26452015-06-02 09:56:29 -07002636 * admin apps that want to check whether they are also registered as the device owner app. The
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002637 * exact mechanism by which a device admin app is registered as a device owner app is defined by
2638 * the setup process.
2639 * @param packageName the package name of the app, to compare with the registered device owner
2640 * app, if any.
Makoto Onukia52562c2015-10-01 16:12:31 -07002641 * @return whether or not the package is registered as the device owner app. Note this method
2642 * does *not* check weather the device owner is actually running on the current user.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002643 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002644 public boolean isDeviceOwnerApp(String packageName) {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002645 if (mService != null) {
2646 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07002647 return mService.isDeviceOwnerPackage(packageName);
2648 } catch (RemoteException e) {
2649 Log.w(TAG, "Failed talking with device policy service", e);
Amith Yamasani71e6c692013-03-24 17:39:28 -07002650 }
2651 }
2652 return false;
2653 }
2654
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002655 /**
2656 * @hide
2657 * Redirect to isDeviceOwnerApp.
2658 */
2659 public boolean isDeviceOwner(String packageName) {
2660 return isDeviceOwnerApp(packageName);
2661 }
2662
Jason Monkb0dced82014-06-06 14:36:20 -04002663 /**
Makoto Onukia52562c2015-10-01 16:12:31 -07002664 * Check whether a given component is registered as a device owner.
2665 * Note this method does *not* check weather the device owner is actually running on the current
2666 * user.
2667 *
2668 * @hide
2669 */
2670 public boolean isDeviceOwner(ComponentName who) {
2671 return (who != null) && who.equals(getDeviceOwner());
2672 }
2673
2674 /**
Jason Monkb0dced82014-06-06 14:36:20 -04002675 * Clears the current device owner. The caller must be the device owner.
2676 *
2677 * This function should be used cautiously as once it is called it cannot
2678 * be undone. The device owner can only be set as a part of device setup
2679 * before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04002680 *
2681 * @param packageName The package name of the device owner.
Jason Monkb0dced82014-06-06 14:36:20 -04002682 */
Jason Monk94d2cf92014-06-18 09:53:34 -04002683 public void clearDeviceOwnerApp(String packageName) {
Jason Monkb0dced82014-06-06 14:36:20 -04002684 if (mService != null) {
2685 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04002686 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04002687 } catch (RemoteException re) {
2688 Log.w(TAG, "Failed to clear device owner");
2689 }
2690 }
2691 }
2692
Makoto Onukia52562c2015-10-01 16:12:31 -07002693 /**
2694 * Returns the device owner package name. Note this method will still return the device owner
2695 * package name even if it's running on a different user.
2696 *
2697 * @hide
2698 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002699 @SystemApi
Amith Yamasani71e6c692013-03-24 17:39:28 -07002700 public String getDeviceOwner() {
Makoto Onukia52562c2015-10-01 16:12:31 -07002701 final ComponentName componentName = getDeviceOwnerComponent();
2702 return componentName == null ? null : componentName.getPackageName();
2703 }
2704
2705 /**
2706 * Returns the device owner name. Note this method will still return the device owner
2707 * name even if it's running on a different user.
2708 *
2709 * @hide
2710 */
2711 public String getDeviceOwnerName() {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002712 if (mService != null) {
2713 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07002714 return mService.getDeviceOwnerName();
Amith Yamasani71e6c692013-03-24 17:39:28 -07002715 } catch (RemoteException re) {
2716 Log.w(TAG, "Failed to get device owner");
2717 }
2718 }
2719 return null;
2720 }
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002721
Makoto Onukia52562c2015-10-01 16:12:31 -07002722 /**
2723 * Returns the device owner component name. Note this method will still return the device owner
2724 * component name even if it's running on a different user.
2725 *
2726 * @hide
2727 */
2728 public ComponentName getDeviceOwnerComponent() {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002729 if (mService != null) {
2730 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07002731 return mService.getDeviceOwner();
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002732 } catch (RemoteException re) {
2733 Log.w(TAG, "Failed to get device owner");
2734 }
2735 }
2736 return null;
2737 }
Adam Connors776c5552014-01-09 10:42:56 +00002738
2739 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04002740 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04002741 * @deprecated Do not use
2742 * @removed
Julia Reynolds20118f12015-02-11 12:34:08 -05002743 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04002744 @Deprecated
Julia Reynolds20118f12015-02-11 12:34:08 -05002745 @SystemApi
2746 public String getDeviceInitializerApp() {
Julia Reynolds20118f12015-02-11 12:34:08 -05002747 return null;
2748 }
2749
2750 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002751 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04002752 * @deprecated Do not use
2753 * @removed
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002754 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04002755 @Deprecated
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002756 @SystemApi
2757 public ComponentName getDeviceInitializerComponent() {
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002758 return null;
2759 }
2760
Julia Reynolds20118f12015-02-11 12:34:08 -05002761 /**
Adam Connors776c5552014-01-09 10:42:56 +00002762 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002763 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302764 * Sets the given component as an active admin and registers the package as the profile
2765 * owner for this user. The package must already be installed and there shouldn't be
2766 * an existing profile owner registered for this user. Also, this method must be called
2767 * before the user setup has been completed.
2768 * <p>
2769 * This method can only be called by system apps that hold MANAGE_USERS permission and
2770 * MANAGE_DEVICE_ADMINS permission.
2771 * @param admin The component to register as an active admin and profile owner.
2772 * @param ownerName The user-visible name of the entity that is managing this user.
2773 * @return whether the admin was successfully registered as the profile owner.
2774 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
2775 * the user has already been set up.
2776 */
Justin Morey80440cc2014-07-24 09:16:35 -05002777 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07002778 public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302779 throws IllegalArgumentException {
2780 if (mService != null) {
2781 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002782 final int myUserId = myUserId();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302783 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002784 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302785 } catch (RemoteException re) {
2786 Log.w(TAG, "Failed to set profile owner " + re);
2787 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2788 }
2789 }
2790 return false;
2791 }
2792
2793 /**
2794 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002795 * Clears the active profile owner and removes all user restrictions. The caller must
2796 * be from the same package as the active profile owner for this user, otherwise a
2797 * SecurityException will be thrown.
2798 *
2799 * @param admin The component to remove as the profile owner.
2800 * @return
2801 */
2802 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07002803 public void clearProfileOwner(@NonNull ComponentName admin) {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002804 if (mService != null) {
2805 try {
2806 mService.clearProfileOwner(admin);
2807 } catch (RemoteException re) {
2808 Log.w(TAG, "Failed to clear profile owner " + admin + re);
2809 }
2810 }
2811 }
2812
2813 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05002814 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07002815 * Checks whether the user was already setup.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002816 */
2817 public boolean hasUserSetupCompleted() {
2818 if (mService != null) {
2819 try {
2820 return mService.hasUserSetupCompleted();
2821 } catch (RemoteException re) {
Robin Lee25e26452015-06-02 09:56:29 -07002822 Log.w(TAG, "Failed to check whether user setup has completed");
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002823 }
2824 }
2825 return true;
2826 }
2827
2828 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002829 * @hide
2830 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00002831 * already be installed. There must not already be a profile owner for this user.
2832 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
2833 * this method.
2834 * Calling this after the setup phase of the specified user has completed is allowed only if:
2835 * - the caller is SYSTEM_UID.
2836 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002837 * @param admin the component name to be registered as profile owner.
2838 * @param ownerName the human readable name of the organisation associated with this DPM.
2839 * @param userHandle the userId to set the profile owner for.
2840 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00002841 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
2842 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002843 */
Robin Lee25e26452015-06-02 09:56:29 -07002844 public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName,
Robin Leeddd553f2015-04-30 14:18:22 +01002845 int userHandle) throws IllegalArgumentException {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002846 if (admin == null) {
2847 throw new NullPointerException("admin cannot be null");
2848 }
Adam Connors776c5552014-01-09 10:42:56 +00002849 if (mService != null) {
2850 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002851 if (ownerName == null) {
2852 ownerName = "";
2853 }
2854 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00002855 } catch (RemoteException re) {
2856 Log.w(TAG, "Failed to set profile owner", re);
2857 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2858 }
2859 }
2860 return false;
2861 }
2862
2863 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002864 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
2865 * be used. Only the profile owner can call this.
2866 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01002867 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002868 *
2869 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2870 */
Robin Lee25e26452015-06-02 09:56:29 -07002871 public void setProfileEnabled(@NonNull ComponentName admin) {
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002872 if (mService != null) {
2873 try {
2874 mService.setProfileEnabled(admin);
2875 } catch (RemoteException e) {
2876 Log.w(TAG, "Failed talking with device policy service", e);
2877 }
2878 }
2879 }
2880
2881 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002882 * Sets the name of the profile. In the device owner case it sets the name of the user
2883 * 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 +01002884 * never called by the profile or device owner, the name will be set to default values.
2885 *
2886 * @see #isProfileOwnerApp
2887 * @see #isDeviceOwnerApp
2888 *
Robin Lee25e26452015-06-02 09:56:29 -07002889 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01002890 * @param profileName The name of the profile.
2891 */
Robin Lee25e26452015-06-02 09:56:29 -07002892 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Jessica Hummel1333ea12014-06-23 11:20:10 +01002893 if (mService != null) {
2894 try {
Robin Lee25e26452015-06-02 09:56:29 -07002895 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07002896 } catch (RemoteException e) {
2897 Log.w(TAG, "Failed talking with device policy service", e);
2898 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01002899 }
2900 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01002901
2902 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002903 * Used to determine if a particular package is registered as the profile owner for the
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002904 * current user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002905 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00002906 *
2907 * @param packageName The package name of the app to compare with the registered profile owner.
2908 * @return Whether or not the package is registered as the profile owner.
2909 */
2910 public boolean isProfileOwnerApp(String packageName) {
2911 if (mService != null) {
2912 try {
Nicolas Prevot90af6d72014-07-30 14:19:12 +01002913 ComponentName profileOwner = mService.getProfileOwner(
2914 Process.myUserHandle().getIdentifier());
2915 return profileOwner != null
2916 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00002917 } catch (RemoteException re) {
2918 Log.w(TAG, "Failed to check profile owner");
2919 }
2920 }
2921 return false;
2922 }
2923
2924 /**
2925 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07002926 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00002927 * owner has been set for that user.
2928 * @throws IllegalArgumentException if the userId is invalid.
2929 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002930 @SystemApi
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002931 public ComponentName getProfileOwner() throws IllegalArgumentException {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01002932 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
2933 }
2934
2935 /**
2936 * @see #getProfileOwner()
2937 * @hide
2938 */
2939 public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00002940 if (mService != null) {
2941 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01002942 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00002943 } catch (RemoteException re) {
2944 Log.w(TAG, "Failed to get profile owner");
2945 throw new IllegalArgumentException(
2946 "Requested profile owner for invalid userId", re);
2947 }
2948 }
2949 return null;
2950 }
2951
2952 /**
2953 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07002954 * @return the human readable name of the organisation associated with this DPM or {@code null}
2955 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00002956 * @throws IllegalArgumentException if the userId is invalid.
2957 */
2958 public String getProfileOwnerName() throws IllegalArgumentException {
2959 if (mService != null) {
2960 try {
2961 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
2962 } catch (RemoteException re) {
2963 Log.w(TAG, "Failed to get profile owner");
2964 throw new IllegalArgumentException(
2965 "Requested profile owner for invalid userId", re);
2966 }
2967 }
2968 return null;
2969 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002970
2971 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07002972 * @hide
2973 * @param user The user for whom to fetch the profile owner name, if any.
2974 * @return the human readable name of the organisation associated with this profile owner or
2975 * null if one is not set.
2976 * @throws IllegalArgumentException if the userId is invalid.
2977 */
2978 @SystemApi
Selim Cinek24ac55e2014-08-27 12:51:45 +02002979 public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Amith Yamasani38f836b2014-08-20 14:51:15 -07002980 if (mService != null) {
2981 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02002982 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07002983 } catch (RemoteException re) {
2984 Log.w(TAG, "Failed to get profile owner");
2985 throw new IllegalArgumentException(
2986 "Requested profile owner for invalid userId", re);
2987 }
2988 }
2989 return null;
2990 }
2991
2992 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002993 * Called by a profile owner or device owner to add a default intent handler activity for
2994 * intents that match a certain intent filter. This activity will remain the default intent
2995 * handler even if the set of potential event handlers for the intent filter changes and if
2996 * the intent preferences are reset.
2997 *
2998 * <p>The default disambiguation mechanism takes over if the activity is not installed
2999 * (anymore). When the activity is (re)installed, it is automatically reset as default
3000 * intent handler for the filter.
3001 *
3002 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
3003 * security exception will be thrown.
3004 *
3005 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3006 * @param filter The IntentFilter for which a default handler is added.
3007 * @param activity The Activity that is added as default intent handler.
3008 */
Robin Lee25e26452015-06-02 09:56:29 -07003009 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
3010 @NonNull ComponentName activity) {
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003011 if (mService != null) {
3012 try {
3013 mService.addPersistentPreferredActivity(admin, filter, activity);
3014 } catch (RemoteException e) {
3015 Log.w(TAG, "Failed talking with device policy service", e);
3016 }
3017 }
3018 }
3019
3020 /**
3021 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00003022 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003023 *
3024 * <p>The calling device admin must be a profile owner. If it is not, a security
3025 * exception will be thrown.
3026 *
3027 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3028 * @param packageName The name of the package for which preferences are removed.
3029 */
Robin Lee25e26452015-06-02 09:56:29 -07003030 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003031 String packageName) {
3032 if (mService != null) {
3033 try {
3034 mService.clearPackagePersistentPreferredActivities(admin, packageName);
3035 } catch (RemoteException e) {
3036 Log.w(TAG, "Failed talking with device policy service", e);
3037 }
3038 }
3039 }
Robin Lee66e5d962014-04-09 16:44:21 +01003040
3041 /**
3042 * Called by a profile or device owner to set the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003043 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01003044 *
Esteban Talavera6b8e0642015-08-10 17:26:04 +01003045 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be:
3046 * <ul>
3047 * <li>{@code boolean}
3048 * <li>{@code int}
3049 * <li>{@code String} or {@code String[]}
3050 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
3051 * </ul>
Robin Lee66e5d962014-04-09 16:44:21 +01003052 *
3053 * <p>The application restrictions are only made visible to the target application and the
3054 * profile or device owner.
3055 *
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003056 * <p>If the restrictions are not available yet, but may be applied in the near future,
3057 * the admin can notify the target application of that by adding
3058 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
3059 *
Robin Lee66e5d962014-04-09 16:44:21 +01003060 * <p>The calling device admin must be a profile or device owner; if it is not, a security
3061 * exception will be thrown.
3062 *
3063 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3064 * @param packageName The name of the package to update restricted settings for.
3065 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
3066 * set of active restrictions.
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003067 *
3068 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01003069 */
Robin Lee25e26452015-06-02 09:56:29 -07003070 public void setApplicationRestrictions(@NonNull ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01003071 Bundle settings) {
3072 if (mService != null) {
3073 try {
3074 mService.setApplicationRestrictions(admin, packageName, settings);
3075 } catch (RemoteException e) {
3076 Log.w(TAG, "Failed talking with device policy service", e);
3077 }
3078 }
3079 }
3080
3081 /**
Jim Millere303bf42014-08-26 17:12:29 -07003082 * Sets a list of configuration features to enable for a TrustAgent component. This is meant
3083 * to be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all
3084 * trust agents but those enabled by this function call. If flag
3085 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Jim Miller604e7552014-07-18 19:00:02 -07003086 *
3087 * <p>The calling device admin must have requested
3088 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millere303bf42014-08-26 17:12:29 -07003089 * this method; if not, a security exception will be thrown.
Jim Miller604e7552014-07-18 19:00:02 -07003090 *
3091 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07003092 * @param target Component name of the agent to be enabled.
Jim Millerb5db57a2015-01-14 18:17:19 -08003093 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent
Jim Millere303bf42014-08-26 17:12:29 -07003094 * will be strictly disabled according to the state of the
3095 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
3096 * <p>If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all admins,
3097 * then it's up to the TrustAgent itself to aggregate the values from all device admins.
3098 * <p>Consult documentation for the specific TrustAgent to determine legal options parameters.
Jim Miller604e7552014-07-18 19:00:02 -07003099 */
Robin Lee25e26452015-06-02 09:56:29 -07003100 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
3101 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07003102 if (mService != null) {
3103 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003104 mService.setTrustAgentConfiguration(admin, target, configuration);
Jim Miller604e7552014-07-18 19:00:02 -07003105 } catch (RemoteException e) {
3106 Log.w(TAG, "Failed talking with device policy service", e);
3107 }
3108 }
3109 }
3110
3111 /**
Jim Millere303bf42014-08-26 17:12:29 -07003112 * Gets configuration for the given trust agent based on aggregating all calls to
3113 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
3114 * all device admins.
Jim Miller604e7552014-07-18 19:00:02 -07003115 *
Jim Millerb5db57a2015-01-14 18:17:19 -08003116 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
3117 * this function returns a list of configurations for all admins that declare
3118 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
3119 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
3120 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
3121 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07003122 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07003123 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07003124 */
Robin Lee25e26452015-06-02 09:56:29 -07003125 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
3126 @NonNull ComponentName agent) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003127 return getTrustAgentConfiguration(admin, agent, myUserId());
Jim Millere303bf42014-08-26 17:12:29 -07003128 }
3129
3130 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003131 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
3132 @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07003133 if (mService != null) {
3134 try {
Jim Millere303bf42014-08-26 17:12:29 -07003135 return mService.getTrustAgentConfiguration(admin, agent, userHandle);
Jim Miller604e7552014-07-18 19:00:02 -07003136 } catch (RemoteException e) {
3137 Log.w(TAG, "Failed talking with device policy service", e);
3138 }
3139 }
Jim Millere303bf42014-08-26 17:12:29 -07003140 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07003141 }
3142
3143 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003144 * Called by a profile owner of a managed profile to set whether caller-Id information from
3145 * the managed profile will be shown in the parent profile, for incoming calls.
Adam Connors210fe212014-07-17 15:41:43 +01003146 *
3147 * <p>The calling device admin must be a profile owner. If it is not, a
3148 * security exception will be thrown.
3149 *
Robin Lee25e26452015-06-02 09:56:29 -07003150 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01003151 * @param disabled If true caller-Id information in the managed profile is not displayed.
3152 */
Robin Lee25e26452015-06-02 09:56:29 -07003153 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Adam Connors210fe212014-07-17 15:41:43 +01003154 if (mService != null) {
3155 try {
Robin Lee25e26452015-06-02 09:56:29 -07003156 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01003157 } catch (RemoteException e) {
3158 Log.w(TAG, "Failed talking with device policy service", e);
3159 }
3160 }
3161 }
3162
3163 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003164 * Called by a profile owner of a managed profile to determine whether or not caller-Id
3165 * information has been disabled.
Adam Connors210fe212014-07-17 15:41:43 +01003166 *
3167 * <p>The calling device admin must be a profile owner. If it is not, a
3168 * security exception will be thrown.
3169 *
Robin Lee25e26452015-06-02 09:56:29 -07003170 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01003171 */
Robin Lee25e26452015-06-02 09:56:29 -07003172 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Adam Connors210fe212014-07-17 15:41:43 +01003173 if (mService != null) {
3174 try {
Robin Lee25e26452015-06-02 09:56:29 -07003175 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01003176 } catch (RemoteException e) {
3177 Log.w(TAG, "Failed talking with device policy service", e);
3178 }
3179 }
3180 return false;
3181 }
3182
3183 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07003184 * Determine whether or not caller-Id information has been disabled.
3185 *
3186 * @param userHandle The user for whom to check the caller-id permission
3187 * @hide
3188 */
3189 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
3190 if (mService != null) {
3191 try {
3192 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
3193 } catch (RemoteException e) {
3194 Log.w(TAG, "Failed talking with device policy service", e);
3195 }
3196 }
3197 return false;
3198 }
3199
3200 /**
Makoto Onuki1040da12015-03-19 11:24:00 -07003201 * Start Quick Contact on the managed profile for the current user, if the policy allows.
3202 * @hide
3203 */
3204 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
3205 Intent originalIntent) {
3206 if (mService != null) {
3207 try {
3208 mService.startManagedQuickContact(
3209 actualLookupKey, actualContactId, originalIntent);
3210 } catch (RemoteException e) {
3211 Log.w(TAG, "Failed talking with device policy service", e);
3212 }
3213 }
3214 }
3215
3216 /**
Ricky Wai778ba132015-03-31 14:21:22 +01003217 * Called by a profile owner of a managed profile to set whether bluetooth
3218 * devices can access enterprise contacts.
3219 * <p>
3220 * The calling device admin must be a profile owner. If it is not, a
3221 * security exception will be thrown.
3222 * <p>
3223 * This API works on managed profile only.
3224 *
Robin Lee25e26452015-06-02 09:56:29 -07003225 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01003226 * with.
3227 * @param disabled If true, bluetooth devices cannot access enterprise
3228 * contacts.
3229 */
Robin Lee25e26452015-06-02 09:56:29 -07003230 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Ricky Wai778ba132015-03-31 14:21:22 +01003231 if (mService != null) {
3232 try {
Robin Lee25e26452015-06-02 09:56:29 -07003233 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01003234 } catch (RemoteException e) {
3235 Log.w(TAG, "Failed talking with device policy service", e);
3236 }
3237 }
3238 }
3239
3240 /**
3241 * Called by a profile owner of a managed profile to determine whether or
3242 * not Bluetooth devices cannot access enterprise contacts.
3243 * <p>
3244 * The calling device admin must be a profile owner. If it is not, a
3245 * security exception will be thrown.
3246 * <p>
3247 * This API works on managed profile only.
3248 *
Robin Lee25e26452015-06-02 09:56:29 -07003249 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01003250 * with.
3251 */
Robin Lee25e26452015-06-02 09:56:29 -07003252 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Ricky Wai778ba132015-03-31 14:21:22 +01003253 if (mService != null) {
3254 try {
Robin Lee25e26452015-06-02 09:56:29 -07003255 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01003256 } catch (RemoteException e) {
3257 Log.w(TAG, "Failed talking with device policy service", e);
3258 }
3259 }
3260 return true;
3261 }
3262
3263 /**
3264 * Determine whether or not Bluetooth devices cannot access contacts.
3265 * <p>
3266 * This API works on managed profile UserHandle only.
3267 *
3268 * @param userHandle The user for whom to check the caller-id permission
3269 * @hide
3270 */
3271 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
3272 if (mService != null) {
3273 try {
3274 return mService.getBluetoothContactSharingDisabledForUser(userHandle
3275 .getIdentifier());
3276 } catch (RemoteException e) {
3277 Log.w(TAG, "Failed talking with device policy service", e);
3278 }
3279 }
3280 return true;
3281 }
3282
3283 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003284 * Called by the profile owner of a managed profile so that some intents sent in the managed
3285 * profile can also be resolved in the parent, or vice versa.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00003286 * Only activity intents are supported.
3287 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003288 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01003289 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
3290 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01003291 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
3292 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003293 */
Robin Lee25e26452015-06-02 09:56:29 -07003294 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003295 if (mService != null) {
3296 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003297 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003298 } catch (RemoteException e) {
3299 Log.w(TAG, "Failed talking with device policy service", e);
3300 }
3301 }
3302 }
3303
3304 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003305 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
3306 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01003307 * Only removes those that have been set by the profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003308 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3309 */
Robin Lee25e26452015-06-02 09:56:29 -07003310 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003311 if (mService != null) {
3312 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003313 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003314 } catch (RemoteException e) {
3315 Log.w(TAG, "Failed talking with device policy service", e);
3316 }
3317 }
3318 }
3319
3320 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003321 * Called by a profile or device owner to set the permitted accessibility services. When
3322 * set by a device owner or profile owner the restriction applies to all profiles of the
3323 * user the device owner or profile owner is an admin for.
Jim Millerb1474f42014-08-26 18:42:58 -07003324 *
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003325 * By default the user can use any accessiblity service. When zero or more packages have
3326 * been added, accessiblity services that are not in the list and not part of the system
Jim Millerb1474f42014-08-26 18:42:58 -07003327 * can not be enabled by the user.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003328 *
3329 * <p> Calling with a null value for the list disables the restriction so that all services
3330 * can be used, calling with an empty list only allows the builtin system's services.
3331 *
3332 * <p> System accesibility services are always available to the user the list can't modify
3333 * this.
3334 *
3335 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3336 * @param packageNames List of accessibility service package names.
3337 *
3338 * @return true if setting the restriction succeeded. It fail if there is
3339 * one or more non-system accessibility services enabled, that are not in the list.
3340 */
Robin Lee25e26452015-06-02 09:56:29 -07003341 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003342 List<String> packageNames) {
3343 if (mService != null) {
3344 try {
3345 return mService.setPermittedAccessibilityServices(admin, packageNames);
3346 } catch (RemoteException e) {
3347 Log.w(TAG, "Failed talking with device policy service", e);
3348 }
3349 }
3350 return false;
3351 }
3352
3353 /**
3354 * Returns the list of permitted accessibility services set by this device or profile owner.
3355 *
3356 * <p>An empty list means no accessibility services except system services are allowed.
3357 * Null means all accessibility services are allowed.
3358 *
3359 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3360 * @return List of accessiblity service package names.
3361 */
Robin Lee25e26452015-06-02 09:56:29 -07003362 public List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003363 if (mService != null) {
3364 try {
3365 return mService.getPermittedAccessibilityServices(admin);
3366 } catch (RemoteException e) {
3367 Log.w(TAG, "Failed talking with device policy service", e);
3368 }
3369 }
3370 return null;
3371 }
3372
3373 /**
3374 * Returns the list of accessibility services permitted by the device or profiles
3375 * owners of this user.
3376 *
3377 * <p>Null means all accessibility services are allowed, if a non-null list is returned
3378 * it will contain the intersection of the permitted lists for any device or profile
3379 * owners that apply to this user. It will also include any system accessibility services.
3380 *
3381 * @param userId which user to check for.
3382 * @return List of accessiblity service package names.
3383 * @hide
3384 */
3385 @SystemApi
3386 public List<String> getPermittedAccessibilityServices(int userId) {
3387 if (mService != null) {
3388 try {
3389 return mService.getPermittedAccessibilityServicesForUser(userId);
3390 } catch (RemoteException e) {
3391 Log.w(TAG, "Failed talking with device policy service", e);
3392 }
3393 }
3394 return null;
3395 }
3396
3397 /**
3398 * Called by a profile or device owner to set the permitted input methods services. When
3399 * set by a device owner or profile owner the restriction applies to all profiles of the
3400 * user the device owner or profile owner is an admin for.
3401 *
3402 * By default the user can use any input method. When zero or more packages have
3403 * been added, input method that are not in the list and not part of the system
3404 * can not be enabled by the user.
3405 *
3406 * This method will fail if it is called for a admin that is not for the foreground user
3407 * or a profile of the foreground user.
3408 *
3409 * <p> Calling with a null value for the list disables the restriction so that all input methods
3410 * can be used, calling with an empty list disables all but the system's own input methods.
3411 *
3412 * <p> System input methods are always available to the user this method can't modify this.
3413 *
3414 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3415 * @param packageNames List of input method package names.
Kenny Guy74a70242015-02-05 19:48:38 +00003416 * @return true if setting the restriction succeeded. It will fail if there are
3417 * one or more non-system input methods currently enabled that are not in
3418 * the packageNames list.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003419 */
Robin Lee25e26452015-06-02 09:56:29 -07003420 public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003421 if (mService != null) {
3422 try {
3423 return mService.setPermittedInputMethods(admin, packageNames);
3424 } catch (RemoteException e) {
3425 Log.w(TAG, "Failed talking with device policy service", e);
3426 }
3427 }
3428 return false;
3429 }
3430
3431
3432 /**
3433 * Returns the list of permitted input methods set by this device or profile owner.
3434 *
3435 * <p>An empty list means no input methods except system input methods are allowed.
3436 * Null means all input methods are allowed.
3437 *
3438 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3439 * @return List of input method package names.
3440 */
Robin Lee25e26452015-06-02 09:56:29 -07003441 public List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003442 if (mService != null) {
3443 try {
3444 return mService.getPermittedInputMethods(admin);
3445 } catch (RemoteException e) {
3446 Log.w(TAG, "Failed talking with device policy service", e);
3447 }
3448 }
3449 return null;
3450 }
3451
3452 /**
3453 * Returns the list of input methods permitted by the device or profiles
3454 * owners of the current user.
3455 *
3456 * <p>Null means all input methods are allowed, if a non-null list is returned
3457 * it will contain the intersection of the permitted lists for any device or profile
3458 * owners that apply to this user. It will also include any system input methods.
3459 *
3460 * @return List of input method package names.
3461 * @hide
3462 */
3463 @SystemApi
3464 public List<String> getPermittedInputMethodsForCurrentUser() {
3465 if (mService != null) {
3466 try {
3467 return mService.getPermittedInputMethodsForCurrentUser();
3468 } catch (RemoteException e) {
3469 Log.w(TAG, "Failed talking with device policy service", e);
3470 }
3471 }
3472 return null;
3473 }
3474
3475 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003476 * Called by a device owner to create a user with the specified name. The UserHandle returned
3477 * by this method should not be persisted as user handles are recycled as users are removed and
3478 * created. If you need to persist an identifier for this user, use
3479 * {@link UserManager#getSerialNumberForUser}.
3480 *
3481 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3482 * @param name the user's name
3483 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07003484 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
3485 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01003486 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07003487 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
Julia Reynolds1e958392014-05-16 14:25:21 -04003488 */
Kenny Guy14f48e52015-06-29 15:12:36 +01003489 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07003490 public UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04003491 try {
3492 return mService.createUser(admin, name);
3493 } catch (RemoteException re) {
3494 Log.w(TAG, "Could not create a user", re);
3495 }
3496 return null;
3497 }
3498
3499 /**
Jason Monk03978a42014-06-10 15:05:30 -04003500 * Called by a device owner to create a user with the specified name. The UserHandle returned
3501 * by this method should not be persisted as user handles are recycled as users are removed and
3502 * created. If you need to persist an identifier for this user, use
3503 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
3504 * immediately.
3505 *
3506 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
3507 * as registered as an active admin on the new user. The profile owner package will be
3508 * installed on the new user if it already is installed on the device.
3509 *
3510 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
3511 * profileOwnerComponent when onEnable is called.
3512 *
3513 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3514 * @param name the user's name
3515 * @param ownerName the human readable name of the organisation associated with this DPM.
3516 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
3517 * the user.
3518 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
3519 * on the new user.
3520 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07003521 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
3522 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01003523 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07003524 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
Jason Monk03978a42014-06-10 15:05:30 -04003525 */
Kenny Guy14f48e52015-06-29 15:12:36 +01003526 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07003527 public UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
3528 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04003529 try {
3530 return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent,
3531 adminExtras);
3532 } catch (RemoteException re) {
3533 Log.w(TAG, "Could not create a user", re);
3534 }
3535 return null;
3536 }
3537
3538 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003539 * Called by a device owner to remove a user and all associated data. The primary user can
3540 * not be removed.
3541 *
3542 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3543 * @param userHandle the user to remove.
3544 * @return {@code true} if the user was removed, {@code false} otherwise.
3545 */
Robin Lee25e26452015-06-02 09:56:29 -07003546 public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) {
Julia Reynolds1e958392014-05-16 14:25:21 -04003547 try {
3548 return mService.removeUser(admin, userHandle);
3549 } catch (RemoteException re) {
3550 Log.w(TAG, "Could not remove user ", re);
3551 return false;
3552 }
3553 }
3554
3555 /**
Jason Monk582d9112014-07-09 19:57:08 -04003556 * Called by a device owner to switch the specified user to the foreground.
3557 *
3558 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3559 * @param userHandle the user to switch to; null will switch to primary.
3560 * @return {@code true} if the switch was successful, {@code false} otherwise.
3561 *
3562 * @see Intent#ACTION_USER_FOREGROUND
3563 */
Robin Lee25e26452015-06-02 09:56:29 -07003564 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Jason Monk582d9112014-07-09 19:57:08 -04003565 try {
3566 return mService.switchUser(admin, userHandle);
3567 } catch (RemoteException re) {
3568 Log.w(TAG, "Could not switch user ", re);
3569 return false;
3570 }
3571 }
3572
3573 /**
Robin Lee66e5d962014-04-09 16:44:21 +01003574 * Called by a profile or device owner to get the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003575 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01003576 *
3577 * <p>The calling device admin must be a profile or device owner; if it is not, a security
3578 * exception will be thrown.
3579 *
3580 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3581 * @param packageName The name of the package to fetch restricted settings of.
3582 * @return {@link Bundle} of settings corresponding to what was set last time
3583 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
3584 * if no restrictions have been set.
3585 */
Robin Lee25e26452015-06-02 09:56:29 -07003586 public Bundle getApplicationRestrictions(@NonNull ComponentName admin, String packageName) {
Robin Lee66e5d962014-04-09 16:44:21 +01003587 if (mService != null) {
3588 try {
3589 return mService.getApplicationRestrictions(admin, packageName);
3590 } catch (RemoteException e) {
3591 Log.w(TAG, "Failed talking with device policy service", e);
3592 }
3593 }
3594 return null;
3595 }
Amith Yamasanibe465322014-04-24 13:45:17 -07003596
3597 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003598 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07003599 * <p>
3600 * The calling device admin must be a profile or device owner; if it is not,
3601 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003602 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003603 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3604 * with.
3605 * @param key The key of the restriction. See the constants in
3606 * {@link android.os.UserManager} for the list of keys.
3607 */
Robin Lee25e26452015-06-02 09:56:29 -07003608 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07003609 if (mService != null) {
3610 try {
3611 mService.setUserRestriction(admin, key, true);
3612 } catch (RemoteException e) {
3613 Log.w(TAG, "Failed talking with device policy service", e);
3614 }
3615 }
3616 }
3617
3618 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003619 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07003620 * <p>
3621 * The calling device admin must be a profile or device owner; if it is not,
3622 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003623 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003624 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3625 * with.
3626 * @param key The key of the restriction. See the constants in
3627 * {@link android.os.UserManager} for the list of keys.
3628 */
Robin Lee25e26452015-06-02 09:56:29 -07003629 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07003630 if (mService != null) {
3631 try {
3632 mService.setUserRestriction(admin, key, false);
3633 } catch (RemoteException e) {
3634 Log.w(TAG, "Failed talking with device policy service", e);
3635 }
3636 }
3637 }
Adam Connors010cfd42014-04-16 12:48:13 +01003638
3639 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003640 * Called by profile or device owners to hide or unhide packages. When a package is hidden it
Julia Reynolds966881e2014-05-14 12:23:08 -04003641 * is unavailable for use, but the data and actual package file remain.
3642 *
3643 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003644 * @param packageName The name of the package to hide or unhide.
3645 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
3646 * unhidden.
3647 * @return boolean Whether the hidden setting of the package was successfully updated.
Julia Reynolds966881e2014-05-14 12:23:08 -04003648 */
Robin Lee25e26452015-06-02 09:56:29 -07003649 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003650 boolean hidden) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003651 if (mService != null) {
3652 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003653 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04003654 } catch (RemoteException e) {
3655 Log.w(TAG, "Failed talking with device policy service", e);
3656 }
3657 }
3658 return false;
3659 }
3660
3661 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003662 * Called by profile or device owners to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04003663 *
3664 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003665 * @param packageName The name of the package to retrieve the hidden status of.
3666 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Julia Reynolds966881e2014-05-14 12:23:08 -04003667 */
Robin Lee25e26452015-06-02 09:56:29 -07003668 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003669 if (mService != null) {
3670 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003671 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04003672 } catch (RemoteException e) {
3673 Log.w(TAG, "Failed talking with device policy service", e);
3674 }
3675 }
3676 return false;
3677 }
3678
3679 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003680 * Called by profile or device owners to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003681 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003682 *
3683 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3684 * @param packageName The package to be re-enabled in the current profile.
3685 */
Robin Lee25e26452015-06-02 09:56:29 -07003686 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Adam Connors655be2a2014-07-14 09:01:25 +00003687 if (mService != null) {
3688 try {
3689 mService.enableSystemApp(admin, packageName);
3690 } catch (RemoteException e) {
3691 Log.w(TAG, "Failed to install package: " + packageName);
3692 }
3693 }
3694 }
3695
3696 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003697 * Called by profile or device owners to re-enable system apps by intent that were disabled
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003698 * by default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003699 *
3700 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3701 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
3702 * intent will be re-enabled in the current profile.
3703 * @return int The number of activities that matched the intent and were installed.
3704 */
Robin Lee25e26452015-06-02 09:56:29 -07003705 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Adam Connors655be2a2014-07-14 09:01:25 +00003706 if (mService != null) {
3707 try {
3708 return mService.enableSystemAppWithIntent(admin, intent);
3709 } catch (RemoteException e) {
3710 Log.w(TAG, "Failed to install packages matching filter: " + intent);
3711 }
3712 }
3713 return 0;
3714 }
3715
3716 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00003717 * Called by a device owner or profile owner to disable account management for a specific type
3718 * of account.
Sander Alewijnse650c3342014-05-08 18:00:50 +01003719 *
Sander Alewijnse112e0532014-10-29 13:28:49 +00003720 * <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 +01003721 * security exception will be thrown.
3722 *
3723 * <p>When account management is disabled for an account type, adding or removing an account
3724 * of that type will not be possible.
3725 *
3726 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3727 * @param accountType For which account management is disabled or enabled.
3728 * @param disabled The boolean indicating that account management will be disabled (true) or
3729 * enabled (false).
3730 */
Robin Lee25e26452015-06-02 09:56:29 -07003731 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01003732 boolean disabled) {
3733 if (mService != null) {
3734 try {
3735 mService.setAccountManagementDisabled(admin, accountType, disabled);
3736 } catch (RemoteException e) {
3737 Log.w(TAG, "Failed talking with device policy service", e);
3738 }
3739 }
3740 }
3741
3742 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003743 * Gets the array of accounts for which account management is disabled by the profile owner.
3744 *
3745 * <p> Account management can be disabled/enabled by calling
3746 * {@link #setAccountManagementDisabled}.
3747 *
3748 * @return a list of account types for which account management has been disabled.
3749 *
3750 * @see #setAccountManagementDisabled
3751 */
3752 public String[] getAccountTypesWithManagementDisabled() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003753 return getAccountTypesWithManagementDisabledAsUser(myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003754 }
3755
3756 /**
3757 * @see #getAccountTypesWithManagementDisabled()
3758 * @hide
3759 */
3760 public String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003761 if (mService != null) {
3762 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003763 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003764 } catch (RemoteException e) {
3765 Log.w(TAG, "Failed talking with device policy service", e);
3766 }
3767 }
3768
3769 return null;
3770 }
justinzhang511e0d82014-03-24 16:09:24 -04003771
3772 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003773 * Sets which packages may enter lock task mode.
3774 *
3775 * <p>Any packages that shares uid with an allowed package will also be allowed
3776 * to activate lock task.
justinzhang511e0d82014-03-24 16:09:24 -04003777 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07003778 * From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task
Benjamin Franz469dd582015-06-09 14:24:36 +01003779 * package list results in locked tasks belonging to those packages to be finished.
3780 *
Jason Monkc5185f22014-06-24 11:12:42 -04003781 * This function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04003782 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04003783 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jason Monkd7b86212014-06-16 13:15:38 -04003784 *
3785 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00003786 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
3787 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04003788 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04003789 */
Robin Lee25e26452015-06-02 09:56:29 -07003790 public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04003791 throws SecurityException {
justinzhang511e0d82014-03-24 16:09:24 -04003792 if (mService != null) {
3793 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003794 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04003795 } catch (RemoteException e) {
3796 Log.w(TAG, "Failed talking with device policy service", e);
3797 }
3798 }
3799 }
3800
3801 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003802 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04003803 *
3804 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04003805 * @hide
3806 */
Robin Lee25e26452015-06-02 09:56:29 -07003807 public String[] getLockTaskPackages(@NonNull ComponentName admin) {
justinzhang511e0d82014-03-24 16:09:24 -04003808 if (mService != null) {
3809 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003810 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04003811 } catch (RemoteException e) {
3812 Log.w(TAG, "Failed talking with device policy service", e);
3813 }
3814 }
3815 return null;
3816 }
3817
3818 /**
3819 * This function lets the caller know whether the given component is allowed to start the
3820 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04003821 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04003822 */
Jason Monkd7b86212014-06-16 13:15:38 -04003823 public boolean isLockTaskPermitted(String pkg) {
justinzhang511e0d82014-03-24 16:09:24 -04003824 if (mService != null) {
3825 try {
Jason Monkd7b86212014-06-16 13:15:38 -04003826 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04003827 } catch (RemoteException e) {
3828 Log.w(TAG, "Failed talking with device policy service", e);
3829 }
3830 }
3831 return false;
3832 }
Julia Reynoldsda551652014-05-14 17:15:16 -04003833
3834 /**
3835 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
3836 * 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 -04003837 * <p>The settings that can be updated with this method are:
3838 * <ul>
3839 * <li>{@link Settings.Global#ADB_ENABLED}</li>
3840 * <li>{@link Settings.Global#AUTO_TIME}</li>
3841 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003842 * <li>{@link Settings.Global#DATA_ROAMING}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003843 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003844 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Benjamin Franz68cc4202015-03-11 15:43:06 +00003845 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN}
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07003846 * This setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards
Esteban Talavera656fa7f2015-06-29 17:41:39 +01003847 * and can only be set if {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
Zoltan Szatmary-Ban4045d242015-05-27 12:42:39 +01003848 * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07003849 * This setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards.
Zoltan Szatmary-Ban3c430952015-07-03 14:04:09 +01003850 * </li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003851 * </ul>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01003852 * <p>Changing the following settings has no effect as of
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07003853 * {@link android.os.Build.VERSION_CODES#M}:
Esteban Talavera656fa7f2015-06-29 17:41:39 +01003854 * <ul>
3855 * <li>{@link Settings.Global#BLUETOOTH_ON}.
3856 * Use {@link android.bluetooth.BluetoothAdapter#enable()} and
3857 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
3858 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
3859 * <li>{@link Settings.Global#MODE_RINGER}.
3860 * Use {@link android.media.AudioManager#setRingerMode(int)} instead.</li>
3861 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
3862 * <li>{@link Settings.Global#WIFI_ON}.
3863 * Use {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
3864 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04003865 *
3866 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3867 * @param setting The name of the setting to update.
3868 * @param value The value to update the setting to.
3869 */
Robin Lee25e26452015-06-02 09:56:29 -07003870 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04003871 if (mService != null) {
3872 try {
3873 mService.setGlobalSetting(admin, setting, value);
3874 } catch (RemoteException e) {
3875 Log.w(TAG, "Failed talking with device policy service", e);
3876 }
3877 }
3878 }
3879
3880 /**
3881 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
3882 * that the value of the setting is in the correct form for the setting type should be performed
3883 * by the caller.
Julia Reynolds82735bc2014-09-04 16:43:30 -04003884 * <p>The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003885 * <ul>
3886 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07003887 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003888 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
3889 * </ul>
Julia Reynolds82735bc2014-09-04 16:43:30 -04003890 * <p>A device owner can additionally update the following settings:
3891 * <ul>
3892 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
3893 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04003894 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3895 * @param setting The name of the setting to update.
3896 * @param value The value to update the setting to.
3897 */
Robin Lee25e26452015-06-02 09:56:29 -07003898 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04003899 if (mService != null) {
3900 try {
3901 mService.setSecureSetting(admin, setting, value);
3902 } catch (RemoteException e) {
3903 Log.w(TAG, "Failed talking with device policy service", e);
3904 }
3905 }
3906 }
3907
Amith Yamasanif20d6402014-05-24 15:34:37 -07003908 /**
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003909 * Designates a specific service component as the provider for
Amith Yamasanif20d6402014-05-24 15:34:37 -07003910 * making permission requests of a local or remote administrator of the user.
3911 * <p/>
3912 * Only a profile owner can designate the restrictions provider.
3913 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003914 * @param provider The component name of the service that implements
Amith Yamasanid1d7c022014-08-19 17:03:41 -07003915 * {@link RestrictionsReceiver}. If this param is null,
Amith Yamasanif20d6402014-05-24 15:34:37 -07003916 * it removes the restrictions provider previously assigned.
3917 */
Robin Lee25e26452015-06-02 09:56:29 -07003918 public void setRestrictionsProvider(@NonNull ComponentName admin,
3919 @Nullable ComponentName provider) {
Amith Yamasanif20d6402014-05-24 15:34:37 -07003920 if (mService != null) {
3921 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003922 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07003923 } catch (RemoteException re) {
3924 Log.w(TAG, "Failed to set permission provider on device policy service");
3925 }
3926 }
3927 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04003928
3929 /**
3930 * Called by profile or device owners to set the master volume mute on or off.
3931 *
3932 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3933 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
3934 */
Robin Lee25e26452015-06-02 09:56:29 -07003935 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04003936 if (mService != null) {
3937 try {
3938 mService.setMasterVolumeMuted(admin, on);
3939 } catch (RemoteException re) {
3940 Log.w(TAG, "Failed to setMasterMute on device policy service");
3941 }
3942 }
3943 }
3944
3945 /**
3946 * Called by profile or device owners to check whether the master volume mute is on or off.
3947 *
3948 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3949 * @return {@code true} if master volume is muted, {@code false} if it's not.
3950 */
Robin Lee25e26452015-06-02 09:56:29 -07003951 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04003952 if (mService != null) {
3953 try {
3954 return mService.isMasterVolumeMuted(admin);
3955 } catch (RemoteException re) {
3956 Log.w(TAG, "Failed to get isMasterMute on device policy service");
3957 }
3958 }
3959 return false;
3960 }
Kenny Guyc13053b2014-05-29 14:17:17 +01003961
3962 /**
3963 * Called by profile or device owners to change whether a user can uninstall
3964 * a package.
3965 *
3966 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3967 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003968 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Kenny Guyc13053b2014-05-29 14:17:17 +01003969 */
Robin Lee25e26452015-06-02 09:56:29 -07003970 public void setUninstallBlocked(@NonNull ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003971 boolean uninstallBlocked) {
Kenny Guyc13053b2014-05-29 14:17:17 +01003972 if (mService != null) {
3973 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003974 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01003975 } catch (RemoteException re) {
3976 Log.w(TAG, "Failed to call block uninstall on device policy service");
3977 }
3978 }
3979 }
3980
3981 /**
Rubin Xua97855b2014-11-07 05:41:00 +00003982 * Check whether the current user has been blocked by device policy from uninstalling a package.
3983 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00003984 * <p>
3985 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Robin Lee25e26452015-06-02 09:56:29 -07003986 * behavior of this API is changed such that passing {@code null} as the {@code admin}
Rubin Xue1e6faa2015-03-10 10:51:59 +00003987 * parameter will return if any admin has blocked the uninstallation. Before L MR1, passing
Robin Lee25e26452015-06-02 09:56:29 -07003988 * {@code null} will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01003989 *
Robin Lee25e26452015-06-02 09:56:29 -07003990 * @param admin The name of the admin component whose blocking policy will be checked, or
3991 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01003992 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00003993 * @return true if uninstallation is blocked.
Kenny Guyc13053b2014-05-29 14:17:17 +01003994 */
Robin Lee25e26452015-06-02 09:56:29 -07003995 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Kenny Guyc13053b2014-05-29 14:17:17 +01003996 if (mService != null) {
3997 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01003998 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01003999 } catch (RemoteException re) {
4000 Log.w(TAG, "Failed to call block uninstall on device policy service");
4001 }
4002 }
4003 return false;
4004 }
Svetoslav976e8bd2014-07-16 15:12:03 -07004005
4006 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004007 * Called by the profile owner of a managed profile to enable widget providers from a
4008 * given package to be available in the parent profile. As a result the user will be able to
Svetoslav976e8bd2014-07-16 15:12:03 -07004009 * add widgets from the white-listed package running under the profile to a widget
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004010 * host which runs under the parent profile, for example the home screen. Note that
Svetoslav976e8bd2014-07-16 15:12:03 -07004011 * a package may have zero or more provider components, where each component
4012 * provides a different widget type.
4013 * <p>
4014 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07004015 *
4016 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4017 * @param packageName The package from which widget providers are white-listed.
4018 * @return Whether the package was added.
4019 *
4020 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4021 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4022 */
Robin Lee25e26452015-06-02 09:56:29 -07004023 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004024 if (mService != null) {
4025 try {
4026 return mService.addCrossProfileWidgetProvider(admin, packageName);
4027 } catch (RemoteException re) {
4028 Log.w(TAG, "Error calling addCrossProfileWidgetProvider", re);
4029 }
4030 }
4031 return false;
4032 }
4033
4034 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004035 * Called by the profile owner of a managed profile to disable widget providers from a given
4036 * package to be available in the parent profile. For this method to take effect the
Svetoslav976e8bd2014-07-16 15:12:03 -07004037 * package should have been added via {@link #addCrossProfileWidgetProvider(
4038 * android.content.ComponentName, String)}.
4039 * <p>
4040 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07004041 *
4042 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4043 * @param packageName The package from which widget providers are no longer
4044 * white-listed.
4045 * @return Whether the package was removed.
4046 *
4047 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
4048 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4049 */
Robin Lee25e26452015-06-02 09:56:29 -07004050 public boolean removeCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004051 if (mService != null) {
4052 try {
4053 return mService.removeCrossProfileWidgetProvider(admin, packageName);
4054 } catch (RemoteException re) {
4055 Log.w(TAG, "Error calling removeCrossProfileWidgetProvider", re);
4056 }
4057 }
4058 return false;
4059 }
4060
4061 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004062 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07004063 * available in the parent profile.
4064 *
4065 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4066 * @return The white-listed package list.
4067 *
4068 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
4069 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4070 */
Robin Lee25e26452015-06-02 09:56:29 -07004071 public List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004072 if (mService != null) {
4073 try {
4074 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
4075 if (providers != null) {
4076 return providers;
4077 }
4078 } catch (RemoteException re) {
4079 Log.w(TAG, "Error calling getCrossProfileWidgetProviders", re);
4080 }
4081 }
4082 return Collections.emptyList();
4083 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004084
4085 /**
4086 * Called by profile or device owners to set the current user's photo.
4087 *
4088 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4089 * @param icon the bitmap to set as the photo.
4090 */
Robin Lee25e26452015-06-02 09:56:29 -07004091 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004092 try {
4093 mService.setUserIcon(admin, icon);
4094 } catch (RemoteException re) {
4095 Log.w(TAG, "Could not set the user icon ", re);
4096 }
4097 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04004098
4099 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01004100 * Called by device owners to set a local system update policy. When a new policy is set,
4101 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004102 *
Robin Lee25e26452015-06-02 09:56:29 -07004103 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
4104 * components in the device owner package can set system update policies and the
4105 * most recent policy takes
Rubin Xu5faad8e2015-04-20 17:43:48 +01004106 * effect.
Robin Lee25e26452015-06-02 09:56:29 -07004107 * @param policy the new policy, or {@code null} to clear the current policy.
Rubin Xu5faad8e2015-04-20 17:43:48 +01004108 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00004109 */
Robin Lee25e26452015-06-02 09:56:29 -07004110 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Rubin Xu8027a4f2015-03-10 17:52:37 +00004111 if (mService != null) {
4112 try {
Robin Lee25e26452015-06-02 09:56:29 -07004113 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004114 } catch (RemoteException re) {
Rubin Xu5faad8e2015-04-20 17:43:48 +01004115 Log.w(TAG, "Error calling setSystemUpdatePolicy", re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004116 }
4117 }
4118 }
4119
4120 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01004121 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004122 *
Robin Lee25e26452015-06-02 09:56:29 -07004123 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004124 */
Rubin Xu5faad8e2015-04-20 17:43:48 +01004125 public SystemUpdatePolicy getSystemUpdatePolicy() {
Rubin Xu8027a4f2015-03-10 17:52:37 +00004126 if (mService != null) {
4127 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01004128 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00004129 } catch (RemoteException re) {
Rubin Xu5faad8e2015-04-20 17:43:48 +01004130 Log.w(TAG, "Error calling getSystemUpdatePolicy", re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004131 }
4132 }
4133 return null;
4134 }
Benjamin Franze36087e2015-04-07 16:40:34 +01004135
4136 /**
4137 * Called by a device owner to disable the keyguard altogether.
4138 *
4139 * <p>Setting the keyguard to disabled has the same effect as choosing "None" as the screen
4140 * lock type. However, this call has no effect if a password, pin or pattern is currently set.
4141 * If a password, pin or pattern is set after the keyguard was disabled, the keyguard stops
4142 * being disabled.
4143 *
4144 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01004145 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01004146 *
4147 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Benjamin Franzbece8062015-05-06 12:14:31 +01004148 * place. {@code true} otherwise.
Benjamin Franze36087e2015-04-07 16:40:34 +01004149 */
Robin Lee25e26452015-06-02 09:56:29 -07004150 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franze36087e2015-04-07 16:40:34 +01004151 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01004152 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01004153 } catch (RemoteException re) {
4154 Log.w(TAG, "Failed talking with device policy service", re);
4155 return false;
4156 }
4157 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00004158
4159 /**
Benjamin Franzbece8062015-05-06 12:14:31 +01004160 * Called by device owner to disable the status bar. Disabling the status bar blocks
4161 * notifications, quick settings and other screen overlays that allow escaping from
Benjamin Franzea2ec972015-03-16 17:18:09 +00004162 * a single use device.
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 status bar, {@code false} reenables it.
4166 *
4167 * @return {@code false} if attempting to disable the status bar failed.
4168 * {@code true} otherwise.
Benjamin Franzea2ec972015-03-16 17:18:09 +00004169 */
Robin Lee25e26452015-06-02 09:56:29 -07004170 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzea2ec972015-03-16 17:18:09 +00004171 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01004172 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00004173 } catch (RemoteException re) {
4174 Log.w(TAG, "Failed talking with device policy service", re);
Benjamin Franzbece8062015-05-06 12:14:31 +01004175 return false;
Benjamin Franzea2ec972015-03-16 17:18:09 +00004176 }
4177 }
Rubin Xudc105cc2015-04-14 23:38:01 +01004178
4179 /**
4180 * Callable by the system update service to notify device owners about pending updates.
4181 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
4182 * permission.
4183 *
4184 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating
4185 * when the current pending update was first available. -1 if no update is available.
4186 * @hide
4187 */
4188 @SystemApi
4189 public void notifyPendingSystemUpdate(long updateReceivedTime) {
4190 if (mService != null) {
4191 try {
4192 mService.notifyPendingSystemUpdate(updateReceivedTime);
4193 } catch (RemoteException re) {
4194 Log.w(TAG, "Could not notify device owner about pending system update", re);
4195 }
4196 }
4197 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04004198
4199 /**
Amith Yamasanid49489b2015-04-28 14:00:26 -07004200 * Called by profile or device owners to set the default response for future runtime permission
4201 * requests by applications. The policy can allow for normal operation which prompts the
4202 * user to grant a permission, or can allow automatic granting or denying of runtime
4203 * permission requests by an application. This also applies to new permissions declared by app
Benjamin Franz45dd6662015-07-08 14:24:14 +01004204 * updates. When a permission is denied or granted this way, the effect is equivalent to setting
4205 * the permission grant state via {@link #setPermissionGrantState}.
4206 *
4207 * <p/>As this policy only acts on runtime permission requests, it only applies to applications
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004208 * built with a {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Benjamin Franz45dd6662015-07-08 14:24:14 +01004209 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07004210 * @param admin Which profile or device owner this request is associated with.
4211 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
4212 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
Benjamin Franz45dd6662015-07-08 14:24:14 +01004213 *
4214 * @see #setPermissionGrantState
Amith Yamasanid49489b2015-04-28 14:00:26 -07004215 */
Robin Lee25e26452015-06-02 09:56:29 -07004216 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004217 try {
4218 mService.setPermissionPolicy(admin, policy);
4219 } catch (RemoteException re) {
4220 Log.w(TAG, "Failed talking with device policy service", re);
4221 }
4222 }
4223
4224 /**
4225 * Returns the current runtime permission policy set by the device or profile owner. The
4226 * default is {@link #PERMISSION_POLICY_PROMPT}.
4227 * @param admin Which profile or device owner this request is associated with.
4228 * @return the current policy for future permission requests.
4229 */
Esteban Talavera28b95702015-06-24 15:23:42 +01004230 public int getPermissionPolicy(ComponentName admin) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004231 try {
4232 return mService.getPermissionPolicy(admin);
4233 } catch (RemoteException re) {
4234 return PERMISSION_POLICY_PROMPT;
4235 }
4236 }
4237
4238 /**
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004239 * Sets the grant state of a runtime permission for a specific application. The state
4240 * can be {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it
4241 * through the UI, {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission
4242 * is denied and the user cannot manage it through the UI, and {@link
4243 * #PERMISSION_GRANT_STATE_GRANTED granted} in which the permission is granted and the
4244 * user cannot manage it through the UI. This might affect all permissions in a
4245 * group that the runtime permission belongs to. This method can only be called
4246 * by a profile or device owner.
4247 *
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07004248 * <p/>Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not
4249 * revoke the permission. It retains the previous grant, if any.
4250 *
4251 * <p/>Permissions can be granted or revoked only for applications built with a
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004252 * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07004253 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07004254 * @param admin Which profile or device owner this request is associated with.
4255 * @param packageName The application to grant or revoke a permission to.
4256 * @param permission The permission to grant or revoke.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004257 * @param grantState The permission grant state which is one of {@link
4258 * #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
4259 * {@link #PERMISSION_GRANT_STATE_GRANTED},
4260 * @return whether the permission was successfully granted or revoked.
4261 *
4262 * @see #PERMISSION_GRANT_STATE_DENIED
4263 * @see #PERMISSION_GRANT_STATE_DEFAULT
4264 * @see #PERMISSION_GRANT_STATE_GRANTED
Amith Yamasanid49489b2015-04-28 14:00:26 -07004265 */
Robin Lee25e26452015-06-02 09:56:29 -07004266 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004267 String permission, int grantState) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004268 try {
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004269 return mService.setPermissionGrantState(admin, packageName, permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07004270 } catch (RemoteException re) {
4271 Log.w(TAG, "Failed talking with device policy service", re);
4272 return false;
4273 }
4274 }
Amith Yamasani184b3752015-05-22 13:00:51 -07004275
4276 /**
4277 * Returns the current grant state of a runtime permission for a specific application.
4278 *
4279 * @param admin Which profile or device owner this request is associated with.
4280 * @param packageName The application to check the grant state for.
4281 * @param permission The permission to check for.
4282 * @return the current grant state specified by device policy. If the profile or device owner
4283 * has not set a grant state, the return value is {@link #PERMISSION_GRANT_STATE_DEFAULT}.
4284 * This does not indicate whether or not the permission is currently granted for the package.
4285 *
4286 * <p/>If a grant state was set by the profile or device owner, then the return value will
4287 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or {@link #PERMISSION_GRANT_STATE_GRANTED},
4288 * which indicates if the permission is currently denied or granted.
4289 *
4290 * @see #setPermissionGrantState(ComponentName, String, String, int)
4291 * @see PackageManager#checkPermission(String, String)
4292 */
Robin Lee25e26452015-06-02 09:56:29 -07004293 public int getPermissionGrantState(@NonNull ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07004294 String permission) {
4295 try {
4296 return mService.getPermissionGrantState(admin, packageName, permission);
4297 } catch (RemoteException re) {
4298 Log.w(TAG, "Failed talking with device policy service", re);
4299 return PERMISSION_GRANT_STATE_DEFAULT;
4300 }
4301 }
Nicolas Prevot07387fe2015-10-30 17:53:30 +00004302
4303 /**
4304 * Returns if provisioning a managed profile or device is possible or not.
4305 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
4306 * {@link #ACTION_PROVISION_MANAGED_PROFILE}.
4307 * Note that even if this method returns true, there is a slight possibility that the
4308 * provisioning will not be allowed when it is actually initiated because some event has
4309 * happened in between.
4310 * @return if provisioning a managed profile or device is possible or not.
4311 * @throws IllegalArgumentException if the supplied action is not valid.
4312 */
4313 public boolean isProvisioningAllowed(String action) {
4314 try {
4315 return mService.isProvisioningAllowed(action);
4316 } catch (RemoteException re) {
4317 Log.w(TAG, "Failed talking with device policy service", re);
4318 return false;
4319 }
4320 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08004321}